/* ============ DESIGN SYSTEM — CLARTY ============ */
/* Charte de marque Clarty (Brand Guidelines) : fintech premium + SaaS
   minimaliste. Le violet guide l'attention, il ne remplit pas l'écran. */
:root {
  --primary: #633CFF;        /* Violet Clarty — CTA, liens actifs */
  --primary-dark: #38208F;   /* Violet profond — titres, éléments premium */
  --primary-light: #A997FF;  /* Lavande — accents, graphiques */
  --primary-soft: #F1EEFF;   /* Lavande claire — fonds de cartes */
  --accent: #A997FF;

  /* Couleurs fonctionnelles : états produit, sans concurrencer le violet */
  --success: #1F9D6A;
  --success-soft: #E4F5EE;
  --warning: #E6A23C;
  --warning-soft: #FDF3E4;
  --danger: #D94A64;
  --danger-soft: #FBEAEE;
  --info: #4A78E6;
  --info-soft: #E8EEFC;

  --bg: #FAFAFC;             /* Fond général */
  --surface: #ffffff;
  --border: #E9E6F0;         /* Bordures 1 px discrètes */
  --text: #17151F;           /* Encre */
  --text-light: #716D7A;     /* Gris secondaire */
  --muted: #9C98A6;

  --sidebar-bg: #17151F;     /* Encre : la sidebar reprend le texte principal */
  --sidebar-border: #2A2735;
  --sidebar-text: #A39FB0;
  --sidebar-text-active: #ffffff;

  --radius: 12px;            /* Boutons 10–12 px */
  --radius-lg: 16px;         /* Cartes 12–16 px */
  --radius-pill: 999px;
  /* Ombres presque imperceptibles, diffusion large */
  --shadow-sm: 0 1px 2px rgba(23, 21, 31, 0.04);
  --shadow: 0 2px 10px rgba(99, 60, 255, 0.05), 0 1px 3px rgba(23, 21, 31, 0.04);
  --shadow-lg: 0 12px 32px rgba(99, 60, 255, 0.10);
  --transition: all 0.18s ease;  /* 150–250 ms, sans rebond */
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  font-family: "Manrope", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ============ LAYOUT ============ */
.app-shell {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

/* Sur desktop, l'enveloppe logo+burger est transparente pour la mise en page
   (le logo garde exactement sa place dans la colonne) ; le burger n'apparaît
   qu'en mobile, où .sidebar-head devient la barre du haut. */
.sidebar-head { display: contents; }
.sidebar-nav { display: contents; }

.nav-burger {
  display: none;
  background: transparent;
  border: none;
  color: var(--sidebar-text);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  padding: 6px 10px;
  border-radius: 8px;
  font-family: inherit;
}
.nav-burger:hover { background: rgba(255, 255, 255, 0.08); color: white; }

.sidebar .logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px 20px;
  font-size: 18px;
  font-weight: 700;
  color: var(--sidebar-text-active);
}

/* Emblème seul : à cette taille le mot-symbole serait illisible */
.sidebar .logo-mark {
  width: 32px;
  height: 32px;
  display: block;
}

/* Mot-symbole « clarty » : toujours en bas de casse */
.sidebar .logo-word {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.02em;
  text-transform: lowercase;
}

/* Chiffres tabulaires : les colonnes de montants s'alignent proprement */
.stat-value, .amount, table td, table th {
  font-variant-numeric: tabular-nums;
}

.sidebar .nav-group-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: #716D7A;
  padding: 12px 14px 6px;
  font-weight: 600;
}

.sidebar .nav-btn {
  background: transparent;
  border: none;
  padding: 11px 14px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 14px;
  color: var(--sidebar-text);
  font-weight: 500;
  text-align: left;
  display: flex;
  align-items: center;
  gap: 12px;
  transition: var(--transition);
  font-family: inherit;
  width: 100%;
}

.sidebar .nav-btn:hover { background: rgba(255, 255, 255, 0.04); color: white; }

.sidebar .nav-btn.active {
  background: var(--primary);
  color: white;
  box-shadow: 0 6px 16px rgba(99, 60, 255, 0.22);
}

.sidebar .nav-icon { font-size: 16px; width: 20px; text-align: center; }

.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 32px;
  background: transparent;
  gap: 24px;
}

.topbar .page-title { font-size: 22px; font-weight: 700; color: var(--text); }

.search-box {
  display: flex;
  align-items: center;
  background: var(--surface);
  border-radius: var(--radius-pill);
  padding: 8px 16px;
  gap: 10px;
  min-width: 280px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
}

.search-box input {
  flex: 1;
  border: none;
  outline: none;
  font-size: 14px;
  background: transparent;
  font-family: inherit;
  color: var(--text);
}

.search-box input::placeholder { color: var(--muted); }

.content {
  padding: 8px 32px 32px;
  flex: 1;
}

/* ============ HERO BANNER ============ */
.hero {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
  color: white;
  padding: 32px;
  border-radius: var(--radius-lg);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  position: relative;
  overflow: hidden;
  box-shadow: 0 10px 40px rgba(99, 60, 255, 0.16);
  margin-bottom: 24px;
}

.hero::before {
  content: '';
  position: absolute;
  top: -50%;
  right: -10%;
  width: 60%;
  height: 200%;
  background: radial-gradient(circle, rgba(255,255,255,0.15) 0%, transparent 60%);
  pointer-events: none;
}

.hero-content { z-index: 1; max-width: 60%; }
.hero-eyebrow { font-size: 14px; opacity: 0.9; margin-bottom: 8px; }
.hero-title { font-size: 32px; font-weight: 800; line-height: 1.15; margin-bottom: 20px; }
.hero-cta {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: white;
  color: var(--primary-dark);
  padding: 12px 22px;
  border-radius: var(--radius-pill);
  font-weight: 600;
  font-size: 14px;
  border: none;
  cursor: pointer;
  text-decoration: none;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
  transition: var(--transition);
}
.hero-cta:hover { transform: translateY(-1px); box-shadow: 0 8px 20px rgba(0,0,0,0.15); }

.hero-illustration {
  font-size: 100px;
  z-index: 1;
  filter: drop-shadow(0 8px 16px rgba(0,0,0,0.2));
  animation: floaty 4s ease-in-out infinite;
}
@keyframes floaty { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-10px); } }

/* ============ DASHBOARD GRID ============ */
.dashboard-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 320px;
  gap: 20px;
}
.dashboard-grid .col-span-3 { grid-column: span 3; }
.dashboard-grid .row-span-2 { grid-row: span 2; }

/* ============ CARDS ============ */
.card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 22px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}
.card-title { font-size: 16px; font-weight: 600; color: var(--text); }
.card-subtitle { font-size: 13px; color: var(--muted); }

/* Stat card */
.stat-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 22px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  position: relative;
  overflow: hidden;
}
.stat-card .stat-label {
  font-size: 13px;
  color: var(--muted);
  font-weight: 500;
  margin-bottom: 8px;
}
.stat-card .stat-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 4px;
}
.stat-card .stat-trend {
  font-size: 13px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-top: 2px;
  font-weight: 600;
}
.stat-trend.up { color: var(--success); }
.stat-trend.down { color: var(--danger); }
.stat-trend.flat { color: var(--muted); }
.stat-card .spark { margin-top: 14px; }

/* ============ BUTTONS ============ */
.btn {
  background: var(--primary);
  color: white;
  border: none;
  padding: 10px 18px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  transition: var(--transition);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.btn:hover { background: var(--primary-dark); transform: translateY(-1px); box-shadow: 0 6px 14px rgba(99, 60, 255, 0.20); }
.btn-secondary { background: var(--primary-soft); color: var(--primary-dark); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--primary-soft); color: var(--primary-dark); border-color: var(--primary); box-shadow: none; transform: none; }
.btn-danger { background: var(--danger); }
.btn-danger:hover { background: #C13E56; box-shadow: 0 6px 14px rgba(217, 74, 100, 0.28); }
.btn-success { background: var(--success); }
.btn-success:hover { background: #187F56; box-shadow: 0 6px 14px rgba(31, 157, 106, 0.28); }
.btn-sm { padding: 6px 12px; font-size: 13px; border-radius: 8px; }

/* ============ PAGE HEADER (autres vues) ============ */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}
.page-header h2 { font-size: 22px; font-weight: 700; }

/* ============ TABLES ============ */
table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}
th, td {
  text-align: left;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
th {
  background: var(--primary-soft);
  font-weight: 600;
  color: var(--primary-dark);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--bg); }

/* ============ BADGES ============ */
.badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  font-size: 12px;
  font-weight: 600;
}
.badge-success { background: var(--success-soft); color: #047857; }
.badge-warning { background: var(--warning-soft); color: #b45309; }
.badge-danger { background: var(--danger-soft); color: #b91c1c; }
.badge-info { background: var(--info-soft); color: #1e40af; }

.actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* ============ FORMS ============ */
.form-group { margin-bottom: 16px; }
.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text);
}
.form-group input, .form-group select, .form-group textarea {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  font-family: inherit;
  background: var(--surface);
  transition: var(--transition);
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(99,102,241,0.12);
}
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

/* ============ MODAL ============ */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}
.modal.hidden { display: none; }
.modal-content {
  background: var(--surface);
  border-radius: var(--radius-lg);
  max-width: 820px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  padding: 32px;
  position: relative;
  box-shadow: 0 25px 50px rgba(0,0,0,0.25);
}
.modal-close {
  position: absolute;
  top: 16px;
  right: 16px;
  background: var(--bg);
  border: none;
  font-size: 16px;
  cursor: pointer;
  color: var(--text-light);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  transition: var(--transition);
}
.modal-close:hover { background: var(--danger-soft); color: var(--danger); }
.modal h3 { margin-bottom: 20px; font-size: 20px; }

/* ============ EMPTY STATE ============ */
.empty-state {
  text-align: center;
  padding: 56px 24px;
  color: var(--muted);
}
.empty-state .empty-icon {
  font-size: 56px;
  margin-bottom: 12px;
  opacity: 0.5;
}
.empty-state p { margin-bottom: 18px; }

/* ============ INVOICE LINES ============ */
.invoice-lines {
  margin-top: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.invoice-lines table { box-shadow: none; border-radius: 0; border: none; }
.invoice-lines input, .invoice-lines select {
  border: none;
  padding: 8px 10px;
  background: transparent;
  width: 100%;
  font-size: 13px;
  font-family: inherit;
}
.invoice-lines input:focus { background: var(--bg); outline: none; box-shadow: none; }

.totals { margin-top: 20px; display: flex; justify-content: flex-end; }
.totals-box {
  min-width: 300px;
  padding: 18px;
  background: var(--primary-soft);
  border-radius: var(--radius);
}
.totals-line { display: flex; justify-content: space-between; padding: 4px 0; font-size: 14px; }
.totals-line.total {
  font-size: 18px;
  font-weight: 700;
  border-top: 1px solid var(--primary-light);
  margin-top: 8px;
  padding-top: 12px;
  color: var(--primary-dark);
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

/* ============ TOAST ============ */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--text);
  color: white;
  padding: 14px 22px;
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0,0,0,0.2);
  z-index: 200;
  font-size: 14px;
  font-weight: 500;
}
.toast.hidden { display: none; }
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }

/* ============ CHAT (Assistant) ============ */
.chat-wrap {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 180px);
  /* dvh = hauteur RÉELLE du viewport mobile (100vh ignore la barre d'URL) */
  height: calc(100dvh - 180px);
  background: var(--surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.chat-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}
.chat-suggestions button {
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 7px 14px;
  border-radius: var(--radius-pill);
  font-size: 13px;
  cursor: pointer;
  color: var(--text);
  font-family: inherit;
  transition: var(--transition);
  font-weight: 500;
}
.chat-suggestions button:hover { background: var(--primary); color: white; border-color: var(--primary); }

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.chat-msg {
  max-width: 75%;
  padding: 12px 16px;
  border-radius: var(--radius-lg);
  font-size: 14px;
  white-space: pre-wrap;
  word-wrap: break-word;
  line-height: 1.5;
}
.chat-msg.bot {
  background: var(--primary-soft);
  align-self: flex-start;
  border-bottom-left-radius: 4px;
  color: var(--text);
}
.chat-msg.user {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: white;
  align-self: flex-end;
  border-bottom-right-radius: 4px;
}
.chat-msg.bot::before {
  content: "✨ Assistant";
  display: block;
  font-size: 11px;
  color: var(--primary-dark);
  font-weight: 700;
  margin-bottom: 6px;
}
.chat-input {
  display: flex;
  gap: 10px;
  padding: 14px 18px;
  border-top: 1px solid var(--border);
  background: var(--surface);
  position: relative; /* la barre d'écoute se superpose à la rangée */
}

/* ---- Barre d'écoute (mode voiture) façon WhatsApp ---- */
.voice-bar {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  padding: 0 14px;
  z-index: 5;
}
.voice-waves { display: flex; align-items: center; gap: 3px; height: 26px; flex: 0 0 auto; }
.voice-waves span {
  width: 4px;
  height: 8px;
  border-radius: 2px;
  background: var(--primary);
  animation: voice-wave 1.1s ease-in-out infinite;
}
.voice-waves span:nth-child(2) { animation-delay: 0.15s; }
.voice-waves span:nth-child(3) { animation-delay: 0.3s; }
.voice-waves span:nth-child(4) { animation-delay: 0.45s; }
.voice-waves span:nth-child(5) { animation-delay: 0.6s; }
@keyframes voice-wave {
  0%, 100% { height: 8px; opacity: 0.6; }
  50% { height: 24px; opacity: 1; }
}
.voice-live {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
  color: var(--text-light);
  font-style: italic;
}
.voice-cancel, .voice-send {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: var(--radius-pill);
  cursor: pointer;
  font-size: 17px;
  font-family: inherit;
}
/* Spécificité : .chat-input button (générique) peint tout en violet — on le bat */
.chat-input .voice-cancel { background: var(--danger-soft); color: var(--danger); padding: 0; }
.chat-input .voice-cancel:hover { background: var(--danger); color: white; }
.chat-input .voice-send { background: var(--primary); color: white; padding: 0; }

/* ---- Réécoute : petit 🔊 discret dans chaque bulle ---- */
.chat-msg .msg-say {
  display: inline-block;
  margin-left: 8px;
  background: transparent;
  border: none;
  cursor: pointer;
  font-size: 13px;
  opacity: 0.45;
  padding: 0 2px;
  vertical-align: middle;
}
.chat-msg .msg-say:hover { opacity: 1; }
.chat-msg.user .msg-say { filter: brightness(3); }
.chat-input input {
  flex: 1;
  min-width: 0; /* autorise le champ à se comprimer (sinon le micro fait déborder la rangée) */
  padding: 12px 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  font-size: 14px;
  font-family: inherit;
}
.chat-input input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(99,102,241,0.12);
}
.chat-input button {
  background: var(--primary);
  color: white;
  border: none;
  padding: 0 22px;
  border-radius: var(--radius-pill);
  cursor: pointer;
  font-weight: 600;
  font-family: inherit;
}
.chat-input button:hover { background: var(--primary-dark); }
/* Bouton micro (mode voiture) : rond, neutre au repos, pulse quand il écoute */
#chat-mic {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0 14px;
  font-size: 18px;
}
#chat-mic:hover { background: var(--primary-soft); }
#chat-mic.listening {
  background: #e53e3e;
  border-color: #e53e3e;
  animation: mic-pulse 1.2s ease-in-out infinite;
}
@keyframes mic-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(229, 62, 62, 0.45); }
  50% { box-shadow: 0 0 0 10px rgba(229, 62, 62, 0); }
}
.chat-suggestions button.voice-on {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}
.chat-welcome {
  text-align: center;
  color: var(--muted);
  padding: 40px;
  font-size: 14px;
  line-height: 1.7;
}

/* ============ CALENDAR ============ */
.calendar {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}
.calendar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}
.calendar-nav { display: flex; gap: 4px; }
.calendar-nav button {
  background: var(--primary-soft);
  border: none;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  cursor: pointer;
  color: var(--primary-dark);
  font-weight: 600;
  font-size: 14px;
}
.calendar-nav button:hover { background: var(--primary); color: white; }

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  font-size: 12px;
}
.calendar-grid .day-name {
  text-align: center;
  font-weight: 600;
  color: var(--muted);
  padding: 6px 0;
  text-transform: uppercase;
  font-size: 10px;
}
.calendar-grid .day {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  cursor: default;
  color: var(--text);
  position: relative;
}
.calendar-grid .day.outside { color: var(--muted); opacity: 0.4; }
.calendar-grid .day.today { background: var(--primary); color: white; font-weight: 700; }
.calendar-grid .day.has-event::after {
  content: '';
  position: absolute;
  bottom: 4px;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--accent);
}
.calendar-grid .day.today.has-event::after { background: white; }

/* ============ NEXT ACTIONS ============ */
.actions-list { display: flex; flex-direction: column; gap: 10px; }
.action-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: var(--bg);
  border-radius: var(--radius);
  font-size: 13px;
}
.action-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 16px;
}
.action-icon.late { background: var(--danger-soft); color: var(--danger); }
.action-icon.due { background: var(--warning-soft); color: var(--warning); }
.action-icon.ok { background: var(--success-soft); color: var(--success); }
.action-content { flex: 1; min-width: 0; }
.action-title { font-weight: 600; color: var(--text); margin-bottom: 2px; }
.action-meta { font-size: 12px; color: var(--muted); }
.action-item .btn { padding: 4px 10px; font-size: 12px; }

/* ============ AI / KEY STATUS ============ */
.key-status-ok { font-size: 13px; font-weight: 600; margin-top: 6px; color: var(--success); }

/* ============ PDF VIEWER OVERLAY ============ */
#pdf-viewer-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
}
.pdfv-backdrop { position: absolute; inset: 0; background: rgba(15, 23, 42, 0.7); }
.pdfv-window {
  position: relative;
  width: 92vw;
  height: 92vh;
  max-width: 1200px;
  background: var(--surface);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 25px 80px rgba(0,0,0,0.4);
}
.pdfv-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  gap: 12px;
}
.pdfv-title { font-weight: 600; font-size: 15px; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pdfv-actions { display: flex; gap: 6px; flex-shrink: 0; }
.pdfv-actions .btn-secondary { text-decoration: none; display: inline-flex; align-items: center; }
.pdfv-frame { flex: 1; border: 0; width: 100%; background: #525659; }
.pdfv-fallback { padding: 32px; text-align: center; color: var(--muted); background: white; }

/* ============ MISC ============ */
.text-right { text-align: right; }
.text-muted { color: var(--muted); }
.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }
.mb-2 { margin-bottom: 8px; }

/* Sparkline SVG */
.spark svg { display: block; width: 100%; height: auto; }

/* Bar chart container */
.bar-chart-wrap { position: relative; height: 280px; }

/* ============ RESPONSIVE ============ */
@media (max-width: 1100px) {
  .dashboard-grid { grid-template-columns: 1fr 1fr; }
  .dashboard-grid .col-span-3 { grid-column: span 2; }
}

@media (max-width: 768px) {
  .app-shell { grid-template-columns: 1fr; }
  /* Menu déroulant mobile : la barre du haut montre logo + burger ☰ ;
     les vues se déplient en liste verticale quand .sidebar porte .open
     (géré dans app.js — le menu se replie après chaque choix). */
  .sidebar {
    position: sticky;
    top: 0;
    z-index: 100;
    height: auto;
    overflow: visible;
    padding: 10px 14px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.18);
  }
  .sidebar-head { display: flex; align-items: center; justify-content: space-between; }
  .sidebar .logo { padding: 0; font-size: 17px; }
  .nav-burger { display: block; }
  .sidebar .nav-group-label { display: none; }
  /* Le menu SE SUPERPOSE à la page (position absolue sous la barre),
     il ne pousse pas le contenu vers le bas. */
  .sidebar-nav {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    flex-direction: column;
    gap: 4px;
    background: var(--sidebar-bg);
    padding: 6px 14px 14px;
    border-radius: 0 0 16px 16px;
    box-shadow: 0 16px 32px rgba(0, 0, 0, 0.28);
  }
  .sidebar.open .sidebar-nav { display: flex; }
  .topbar { padding: 12px 16px; flex-direction: column; align-items: stretch; }
  .search-box { min-width: 0; }
  .content { padding: 8px 16px 24px; }
  .dashboard-grid { grid-template-columns: 1fr; }
  .dashboard-grid .col-span-3 { grid-column: span 1; }
  .hero { flex-direction: column; text-align: center; padding: 24px; }
  .hero-content { max-width: 100%; }
  .hero-title { font-size: 24px; }
  .form-row { grid-template-columns: 1fr; }

  /* ---- Chat plein écran (vue Assistant, exposée via body[data-view]) ---- */
  /* La barre de recherche disparaît : le chat récupère tout l'écran. */
  body[data-view="assistant"] .topbar { display: none; }
  /* La page ne défile JAMAIS dans cette vue (tout tient à l'écran) : sans ça,
     iOS fait défiler la page à l'ouverture du clavier et on perd soit les
     messages, soit le champ de saisie (constaté sur l'iPhone d'Andy). */
  body[data-view="assistant"] { overflow: hidden; height: 100dvh; }
  body[data-view="assistant"] .content { overflow: hidden; }
  body[data-view="assistant"] .content { padding: 8px 10px 10px; }
  body[data-view="assistant"] .page-header { margin-bottom: 8px; }
  body[data-view="assistant"] .page-header h2 { font-size: 17px; }
  /* Repli avant que le JS n'ajuste au clavier (110px ≈ barre du menu + en-tête) */
  .chat-wrap { height: calc(100dvh - 110px); }
  /* Suggestions : UNE ligne défilable au lieu de 4 lignes qui mangent l'écran */
  .chat-suggestions {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding: 10px 12px;
  }
  .chat-suggestions::-webkit-scrollbar { display: none; }
  .chat-suggestions button { flex: 0 0 auto; }
  .chat-messages { padding: 14px 12px; }
  .chat-msg { max-width: 90%; }
  /* 16px minimum : en dessous, iOS zoome la page à la prise de focus */
  .chat-input input { font-size: 16px; padding: 12px 14px; }
  .chat-input { gap: 8px; padding-left: 12px; padding-right: 12px; }
  .chat-input button[type="submit"] { padding: 0 16px; }
  /* PWA installée plein écran (viewport-fit=cover) : ne pas passer sous la
     barre du geste d'accueil iPhone */
  .chat-input { padding-bottom: calc(14px + env(safe-area-inset-bottom, 0px)); }
}
