/* =========================================================================
   FacturSCI — feuille de style (design moderne)
   Palette bordeaux + or, surfaces claires, ombres douces, transitions fluides.
   ========================================================================= */
:root {
  --bordeaux: #8a2436;
  --bordeaux-fonce: #611722;
  --bordeaux-clair: #a83b4d;
  --or: #c9a24b;
  --or-clair: #e3c98a;

  --bg: #f5f6f9;
  --surface: #ffffff;
  --surface-2: #fafbfc;
  --border: #e7e9ef;
  --border-fort: #d8dce4;

  --texte: #1d2230;
  --texte-doux: #6b7280;
  --texte-faible: #9aa1ad;

  --vert: #15924f;
  --rouge: #d23b46;
  --orange: #e08a1e;
  --bleu: #2f6fd6;

  --radius: 14px;
  --radius-sm: 9px;
  --radius-xs: 7px;

  --sh-sm: 0 1px 2px rgba(16,24,40,.05);
  --sh: 0 1px 3px rgba(16,24,40,.07), 0 1px 2px rgba(16,24,40,.04);
  --sh-md: 0 4px 14px rgba(16,24,40,.08), 0 2px 5px rgba(16,24,40,.04);
  --sh-lg: 0 18px 45px rgba(16,24,40,.18);
  --ring: 0 0 0 3.5px rgba(138,36,54,.14);

  /* Variables qui basculent en mode sombre */
  --lien: var(--bordeaux);
  --lien-hover: var(--bordeaux-fonce);
  --topbar-bg: rgba(255,255,255,.82);
  --border-faible: #eef0f4;
  --row-hover: rgba(138,36,54,.035);
  --ghost-hover: rgba(16,24,40,.05);

  --t: .18s cubic-bezier(.4,0,.2,1);
}

/* ============================== MODE SOMBRE ==============================
   Appliqué soit par choix explicite (html[data-theme="dark"]), soit selon la
   préférence système quand aucun choix n'est enregistré. */
html[data-theme="dark"] {
  --bordeaux: #9e2d40; --bordeaux-fonce: #7c2231; --bordeaux-clair: #c0506280;
  --bg: #14161c; --surface: #1c1f27; --surface-2: #232733;
  --border: #2b303b; --border-fort: #3a4150; --border-faible: #262b36;
  --texte: #e8eaef; --texte-doux: #9aa2ae; --texte-faible: #6f7787;
  --lien: #ef9aac; --lien-hover: #f4b6c3;
  --topbar-bg: rgba(20,22,28,.82);
  --row-hover: rgba(255,255,255,.045);
  --ghost-hover: rgba(255,255,255,.08);
  --ring: 0 0 0 3.5px rgba(214,90,110,.22);
  --sh-sm: 0 1px 2px rgba(0,0,0,.45);
  --sh: 0 1px 3px rgba(0,0,0,.45);
  --sh-md: 0 4px 16px rgba(0,0,0,.5);
  --sh-lg: 0 18px 50px rgba(0,0,0,.6);
}
@media (prefers-color-scheme: dark) {
  html:not([data-theme]) {
    --bordeaux: #9e2d40; --bordeaux-fonce: #7c2231; --bordeaux-clair: #c0506280;
    --bg: #14161c; --surface: #1c1f27; --surface-2: #232733;
    --border: #2b303b; --border-fort: #3a4150; --border-faible: #262b36;
    --texte: #e8eaef; --texte-doux: #9aa2ae; --texte-faible: #6f7787;
    --lien: #ef9aac; --lien-hover: #f4b6c3;
    --topbar-bg: rgba(20,22,28,.82);
    --row-hover: rgba(255,255,255,.045);
    --ghost-hover: rgba(255,255,255,.08);
    --ring: 0 0 0 3.5px rgba(214,90,110,.22);
    --sh-sm: 0 1px 2px rgba(0,0,0,.45);
    --sh: 0 1px 3px rgba(0,0,0,.45);
    --sh-md: 0 4px 16px rgba(0,0,0,.5);
    --sh-lg: 0 18px 50px rgba(0,0,0,.6);
  }
}

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

html { -webkit-text-size-adjust: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--texte);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
a { color: var(--lien); text-decoration: none; transition: color var(--t); }
a:hover { color: var(--lien-hover); text-decoration: underline; }
::selection { background: rgba(138,36,54,.16); }

/* ---- Layout ---- */
.app { display: flex; min-height: 100vh; }

.sidebar {
  width: 248px; color: #fff; position: fixed; height: 100vh;
  display: flex; flex-direction: column;
  background: linear-gradient(184deg, #8a2436 0%, #6c1b28 55%, #561420 100%);
  box-shadow: inset -1px 0 0 rgba(255,255,255,.05);
}
.sidebar .brand {
  padding: 20px 20px; font-size: 18px; font-weight: 700; letter-spacing: .2px;
  border-bottom: 1px solid rgba(255,255,255,.10);
  display: flex; align-items: center; gap: 11px;
}
.sidebar .brand .logo {
  background: linear-gradient(160deg, var(--or-clair), var(--or));
  color: var(--bordeaux-fonce); width: 34px; height: 34px;
  border-radius: 10px; display: grid; place-items: center; font-weight: 800; font-size: 16px;
  box-shadow: 0 2px 6px rgba(0,0,0,.2);
}
.sidebar nav { padding: 14px 12px; flex: 1; display: flex; flex-direction: column; gap: 2px; }
.sidebar nav a {
  display: flex; align-items: center; gap: 12px; color: #f3e1e4;
  padding: 10px 14px; font-weight: 500; font-size: 14px; border-radius: 10px;
  position: relative; transition: background var(--t), color var(--t);
}
.sidebar nav a:hover { background: rgba(255,255,255,.10); color: #fff; text-decoration: none; }
.sidebar nav a.actif { background: rgba(255,255,255,.14); color: #fff; font-weight: 600; }
.sidebar nav a.actif::before {
  content: ""; position: absolute; left: 0; top: 50%; transform: translateY(-50%);
  width: 3px; height: 20px; border-radius: 0 3px 3px 0; background: var(--or);
}
.sidebar nav a .ico { width: 20px; text-align: center; opacity: .92; font-size: 15px; }
.sidebar .bas {
  padding: 14px 16px; border-top: 1px solid rgba(255,255,255,.10);
  font-size: 13px; color: #f0d9dc; display: flex; flex-direction: column; gap: 12px;
}
.sidebar .bas-user { padding: 0 4px; }
.sidebar .bas a { color: #fff; opacity: .85; }
.sidebar .bas a:hover { opacity: 1; }
.theme-toggle {
  background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.16);
  color: #f6e7ea; border-radius: 10px; padding: 9px 12px; width: 100%;
  font: inherit; font-size: 13px; font-weight: 600; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  transition: background var(--t), border-color var(--t);
}
.theme-toggle:hover { background: rgba(255,255,255,.16); border-color: rgba(255,255,255,.28); }

.main { margin-left: 248px; flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  background: var(--topbar-bg); backdrop-filter: saturate(180%) blur(10px);
  border-bottom: 1px solid var(--border); padding: 14px 30px;
  display: flex; align-items: center; justify-content: space-between;
  position: sticky; top: 0; z-index: 20;
}
.topbar h1 { font-size: 19px; font-weight: 700; letter-spacing: -.2px; }
.content { padding: 28px 30px; max-width: 1200px; width: 100%; }

/* ---- Boutons ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 9px 16px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-fort); background: var(--surface); color: var(--texte);
  font-size: 13.5px; font-weight: 600; cursor: pointer; white-space: nowrap;
  box-shadow: var(--sh-sm);
  transition: transform var(--t), box-shadow var(--t), background var(--t), border-color var(--t), color var(--t);
}
.btn:hover { text-decoration: none; box-shadow: var(--sh-md); transform: translateY(-1px); }
.btn:active { transform: translateY(0); box-shadow: var(--sh-sm); }
.btn:disabled, .btn[disabled] { opacity: .5; cursor: not-allowed; transform: none; box-shadow: none; }
.btn-primary { background: var(--bordeaux); color: #fff; border-color: var(--bordeaux); }
.btn-primary:hover { background: var(--bordeaux-fonce); border-color: var(--bordeaux-fonce); color: #fff; }
.btn-or { background: linear-gradient(160deg, #d4ad55, var(--or)); color: #3c2e10; border-color: var(--or); }
.btn-or:hover { color: #3c2e10; filter: brightness(1.03); }
.btn-danger { background: var(--surface); color: var(--rouge); border-color: #f0c4c7; }
.btn-danger:hover { background: var(--rouge); color: #fff; border-color: var(--rouge); }
.btn-sm { padding: 5px 11px; font-size: 12.5px; border-radius: var(--radius-xs); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--texte-doux); box-shadow: none; }
.btn-ghost:hover { background: var(--ghost-hover); box-shadow: none; transform: none; }

/* ---- Cartes / stats ---- */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px,1fr)); gap: 18px; margin-bottom: 26px; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px 22px; box-shadow: var(--sh); position: relative; overflow: hidden;
  transition: box-shadow var(--t), transform var(--t);
}
.card:hover { box-shadow: var(--sh-md); transform: translateY(-2px); }
.card .label { color: var(--texte-doux); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .5px; }
.card .valeur { font-size: 29px; font-weight: 760; margin-top: 8px; letter-spacing: -.5px; }
.card .sub { font-size: 12.5px; color: var(--texte-doux); margin-top: 4px; }
.card.accent, .card.warn, .card.ok { border-left: none; }
.card.accent::before, .card.warn::before, .card.ok::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px;
}
.card.accent::before { background: var(--bordeaux); }
.card.warn::before { background: var(--orange); }
.card.ok::before { background: var(--vert); }

/* ---- Panneaux / tableaux ---- */
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--sh); margin-bottom: 24px; overflow: hidden; }
.panel-head { padding: 16px 22px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.panel-head h2 { font-size: 15.5px; font-weight: 680; letter-spacing: -.1px; }
.panel-body { padding: 20px 22px; }
table { width: 100%; border-collapse: collapse; }
thead th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .5px;
  color: var(--texte-doux); font-weight: 650; padding: 12px 18px;
  border-bottom: 1px solid var(--border); background: var(--surface-2);
}
tbody td { padding: 13px 18px; border-bottom: 1px solid var(--border-faible); }
tbody tr:last-child td { border-bottom: none; }
tbody tr { transition: background var(--t); }
tbody tr:hover { background: var(--row-hover); }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.muted { color: var(--texte-doux); }
.strong { font-weight: 650; }

/* ---- Badges statut ---- */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 11px 3px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 650; line-height: 1.7;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .85; }
.b-brouillon { background: #eef0f4; color: #5b6472; }
.b-envoyee { background: #e7f0fc; color: #2563a8; }
.b-payee { background: #e2f5ec; color: #157a4a; }
.b-annulee { background: #f4e7e9; color: #93414a; }
.b-retard { background: #fce8e3; color: #b3392b; }

/* ---- Formulaires ---- */
form .grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px 22px; }
form .grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px 22px; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 4px; }
.field.full { grid-column: 1 / -1; }
.field label { font-size: 12.5px; font-weight: 600; color: #3b4250; }
.field input[type=text], .field input[type=email], .field input[type=password],
.field input[type=number], .field input[type=date], .field select, .field textarea {
  padding: 10px 12px; border: 1px solid var(--border-fort); border-radius: var(--radius-sm);
  font-size: 14px; font-family: inherit; background: var(--surface); width: 100%; color: var(--texte);
  transition: border-color var(--t), box-shadow var(--t), background var(--t);
}
.field input::placeholder, .field textarea::placeholder { color: var(--texte-faible); }
.field input:hover, .field select:hover, .field textarea:hover { border-color: #c4c9d2; }
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--bordeaux-clair); box-shadow: var(--ring); background: #fff;
}
.field .check { display: flex; align-items: center; gap: 9px; font-weight: 500; cursor: pointer; }
.field .check input { width: 16px; height: 16px; accent-color: var(--bordeaux); }
.form-actions { display: flex; gap: 10px; margin-top: 22px; padding-top: 20px; border-top: 1px solid var(--border); }
.hint { font-size: 12px; color: var(--texte-doux); line-height: 1.5; }
.hint code { background: var(--surface-2); border: 1px solid var(--border); border-radius: 5px; padding: 1px 5px; font-size: 11.5px; }

/* ---- Lignes facture dynamiques ---- */
.lignes-table input { padding: 8px 10px; }
.lignes-table td { padding: 6px 8px; }
.lignes-table .col-des { width: 45%; }

/* ---- Flash ---- */
.flashes { margin-bottom: 18px; display: flex; flex-direction: column; gap: 10px; }
.flash {
  padding: 12px 16px; border-radius: var(--radius-sm); font-weight: 500;
  border: 1px solid; box-shadow: var(--sh-sm); animation: flash-in .3s ease;
}
@keyframes flash-in { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }
.flash.success { background: #e7f7ef; color: #115b3a; border-color: #b6e3cb; }
.flash.danger { background: #fdecec; color: #99272d; border-color: #f3c4c4; }
.flash.info { background: #eaf1fc; color: #28527d; border-color: #c6d9f2; }
.flash.warning { background: #fdf4e4; color: #855413; border-color: #f0dcae; }

/* ---- Login ---- */
.login-wrap {
  min-height: 100vh; display: grid; place-items: center; padding: 20px;
  background: radial-gradient(1200px 600px at 20% -10%, #a8324a 0%, transparent 55%),
              linear-gradient(135deg, var(--bordeaux) 0%, var(--bordeaux-fonce) 100%);
}
.login-card {
  background: var(--surface); padding: 42px 40px; border-radius: 20px; width: 400px; max-width: 100%;
  box-shadow: var(--sh-lg); border: 1px solid rgba(255,255,255,.5);
}
.login-card .brand { font-size: 26px; font-weight: 780; color: var(--bordeaux); text-align: center; margin-bottom: 4px; letter-spacing: -.4px; }
.login-card .sub { text-align: center; color: var(--texte-doux); margin-bottom: 28px; font-size: 13px; }
.login-card .btn { width: 100%; margin-top: 10px; padding: 11px; }

.empty { text-align: center; padding: 54px 20px; color: var(--texte-doux); }
.empty .big { font-size: 40px; margin-bottom: 12px; opacity: .8; }

.toolbar { display: flex; gap: 12px; align-items: center; margin-bottom: 20px; flex-wrap: wrap; }
.tabs { display: flex; gap: 7px; flex-wrap: wrap; }
.tabs a {
  padding: 7px 15px; border-radius: 999px; font-size: 13px; font-weight: 600;
  color: var(--texte-doux); background: var(--surface); border: 1px solid var(--border);
  transition: all var(--t);
}
.tabs a:hover { border-color: var(--border-fort); color: var(--texte); text-decoration: none; }
.tabs a.actif { background: var(--bordeaux); color: #fff; border-color: var(--bordeaux); }

.dl { display: grid; grid-template-columns: 165px 1fr; gap: 9px 16px; }
.dl dt { color: var(--texte-doux); font-weight: 600; }

/* ---- Liste d'e-mails (une case par adresse) ---- */
.email-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 8px; }
.email-row { display: flex; gap: 8px; align-items: center; }
.email-row input { flex: 1; }

/* ---- Mises en page à deux colonnes ---- */
.split-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; align-items: start; }
.split-21 { display: grid; grid-template-columns: 2fr 1fr; gap: 24px; align-items: start; }

/* ---- Navigation mobile (cachée sur desktop) ---- */
.menu-toggle { display: none; background: none; border: none; font-size: 23px; line-height: 1; cursor: pointer; color: var(--texte); padding: 2px 6px; }
.topbar-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.nav-overlay { display: none; }

/* =========================== RESPONSIVE =========================== */
@media (max-width: 820px) {
  .sidebar { transform: translateX(-100%); transition: transform .25s ease; z-index: 60; width: 270px; box-shadow: 2px 0 30px rgba(0,0,0,.3); }
  .sidebar.open { transform: translateX(0); }
  .nav-overlay.show { display: block; position: fixed; inset: 0; background: rgba(15,18,28,.5); z-index: 50; animation: flash-in .2s ease; }
  .menu-toggle { display: inline-flex; padding: 8px 10px; }
  .main { margin-left: 0; }

  .topbar { padding: 11px 16px; gap: 10px; flex-wrap: wrap; }
  .topbar h1 { font-size: 16px; flex: 1; min-width: 0; }
  .content { padding: 18px 15px; max-width: 100%; }
  .login-wrap { padding: 16px; }

  form .grid, form .grid3, .split-2, .split-21 { grid-template-columns: 1fr; gap: 16px; }

  /* Champs à 16px minimum : iOS ne zoome plus automatiquement au focus. */
  .field input[type=text], .field input[type=email], .field input[type=password],
  .field input[type=number], .field input[type=date], .field select, .field textarea {
    font-size: 16px; padding: 11px 12px;
  }
  /* Boutons d'action de formulaire : pleine largeur, cible tactile confortable. */
  .form-actions { flex-wrap: wrap; }
  .form-actions .btn { flex: 1 1 auto; padding: 12px 16px; }

  table { display: block; overflow-x: auto; white-space: nowrap; -webkit-overflow-scrolling: touch; }

  /* Tableaux-cartes : les listes principales s'empilent verticalement au lieu
     de défiler horizontalement. Chaque cellule porte son intitulé (data-l). */
  table.cartes { display: block; white-space: normal; overflow: visible; }
  table.cartes thead { display: none; }
  table.cartes tbody { display: block; }
  table.cartes tbody tr { display: block; padding: 12px 4px; border-bottom: 1px solid var(--border); }
  table.cartes tbody tr:last-child { border-bottom: none; }
  table.cartes tbody td { display: block; border: none; padding: 2px 14px; text-align: left; }
  table.cartes td[data-l]::before {
    content: attr(data-l); display: inline-block; min-width: 96px;
    font-size: 10.5px; text-transform: uppercase; letter-spacing: .5px;
    color: var(--texte-doux); font-weight: 650; margin-right: 8px;
  }
  table.cartes td.actions { display: flex; flex-wrap: wrap; gap: 8px; padding-top: 10px; }
  table.cartes td.actions .btn { padding: 9px 14px; font-size: 13px; }

  .dl { grid-template-columns: 1fr; gap: 1px 0; }
  .dl dt { margin-top: 10px; }

  .panel-head { flex-wrap: wrap; gap: 6px; }
  .login-card { padding: 32px 24px; }
}
@media (max-width: 480px) {
  .btn { padding: 9px 13px; }
  .card .valeur { font-size: 25px; }
  .content { padding: 15px 12px; }
  .cards { gap: 12px; }
}
