:root {
  --ground: #eef0f6; --surface: #ffffff; --surface-2: #f4f6fb;
  --ink: #151b2c; --ink-2: #4b5468; --muted: #8992a8;
  --hairline: #e3e6f0; --rule: #eef0f6;
  --accent: #28376a; --accent-2: #35488f; --accent-wash: #e9edf8; --on-accent: #fff;
  --gold: #a67f2e; --gold-soft: #b8963f; --gold-wash: #f6efda;
  --good: #0ca30c; --good-ink: #127a41; --good-wash: #e5f3ea;
  --warn-ink: #8a5e15; --warn-wash: #fbf0d5;
  --crit-ink: #a83636; --crit-wash: #fbe9e9;
  --shadow: 0 1px 2px rgba(21,27,44,.05), 0 6px 20px -10px rgba(21,27,44,.14);
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  /* Palette catégorielle produits, tons doux (validée dataviz — mode clair) */
  --prod-arbre:#3d9c67; --prod-puits:#5385c8; --prod-aumone:#d67a45; --prod-aqiqah:#c9a72f; --prod-aid:#c56f92;
}
@media (prefers-color-scheme: dark) {
  :root {
    --ground:#0a0e1a; --surface:#131a2b; --surface-2:#1a2338;
    --ink:#e9ecf6; --ink-2:#a7aec5; --muted:#7b8399;
    --hairline:#26304a; --rule:#1a2338;
    --accent:#8298dd; --accent-2:#a0b2ea; --accent-wash:#1b2648; --on-accent:#0a0e1a;
    --gold:#d6b45e; --gold-soft:#cbab55; --gold-wash:#2b2410;
    --good-ink:#4dc47e; --good-wash:#102a1b;
    --warn-ink:#e0b24a; --warn-wash:#2b2410;
    --crit-ink:#ef7c7c; --crit-wash:#331616;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px -12px rgba(0,0,0,.6);
    /* Palette catégorielle produits, tons doux (validée dataviz — mode sombre) */
    --prod-arbre:#2f9f74; --prod-puits:#5f8ccb; --prod-aumone:#cf7a45; --prod-aqiqah:#b28929; --prod-aid:#cd6f98;
  }
}
* { box-sizing: border-box; }
body { margin:0; background:var(--ground); color:var(--ink); font-family:var(--sans); font-size:14px; line-height:1.5; -webkit-font-smoothing:antialiased; }
h2 { margin:0; font-size:14.5px; font-weight:660; letter-spacing:-.005em; }
.muted { color:var(--muted); font-size:12.5px; }
code { font-family:var(--mono); font-size:11px; background:var(--surface-2); padding:1px 5px; border-radius:4px; }

/* ── Topbar & marque ── */
.topbar { display:flex; align-items:center; gap:14px; padding:13px 24px; background:var(--surface); border-bottom:1px solid var(--hairline); position:sticky; top:0; z-index:5; }
.brand { display:flex; align-items:center; gap:12px; }
.brand-logo { height:30px; width:auto; display:block; }
.brand-sub { font-family:var(--mono); font-size:10px; text-transform:uppercase; letter-spacing:.14em; color:var(--muted); padding-left:12px; border-left:1px solid var(--hairline); }
.topbar-actions { margin-left:auto; display:flex; align-items:center; gap:9px; }

.wrap { max-width:1680px; margin:0 auto; padding:22px 22px 64px; display:flex; flex-direction:column; gap:18px; }

/* ── Boutons ── */
.btn { display:inline-flex; align-items:center; gap:6px; border-radius:8px; padding:8px 14px; font:inherit; font-size:13px; font-weight:560; border:1px solid var(--hairline); background:var(--surface); color:var(--ink); cursor:pointer; transition:background .12s, border-color .12s; }
.btn:hover { background:var(--surface-2); }
.btn-primary { background:var(--accent); border-color:var(--accent); color:var(--on-accent); }
.btn-primary:hover { background:var(--accent-2); border-color:var(--accent-2); }
.btn-ghost { border-color:transparent; background:none; color:var(--ink-2); }
.btn-ghost:hover { background:var(--surface-2); color:var(--ink); }
.btn-sm { padding:5px 11px; font-size:12px; border-radius:7px; }
.btn[disabled] { opacity:.5; cursor:default; }
.btn:focus-visible { outline:2px solid var(--accent-2); outline-offset:2px; }

/* ── Tuiles de chiffres ── */
.kpis { display:grid; grid-template-columns:repeat(auto-fit, minmax(155px, 1fr)); gap:12px; }
.kpi { background:var(--surface); border:1px solid var(--hairline); border-radius:13px; padding:15px 16px; box-shadow:var(--shadow); cursor:pointer; transition:transform .12s, box-shadow .12s, border-color .12s; }
.kpi:hover { transform:translateY(-1px); }
.kpi[aria-pressed="true"] { border-color:var(--gold-soft); box-shadow:0 0 0 1px var(--gold-soft), var(--shadow); }
.kpi .k-val { font-size:29px; font-weight:680; letter-spacing:-.03em; line-height:1; font-variant-numeric:tabular-nums; }
.kpi .k-lab { font-size:11.5px; color:var(--ink-2); margin-top:9px; line-height:1.3; }
.kpi.act { border-color:color-mix(in srgb, var(--accent) 28%, var(--hairline)); }
.kpi.act .k-val { color:var(--accent); }
.kpi.late .k-val { color:var(--crit-ink); }
.wait { font-size:10.5px; color:var(--muted); margin-top:3px; }
.wait.is-late { color:var(--crit-ink); font-weight:650; }

/* ── Cartes ── */
.card { background:var(--surface); border:1px solid var(--hairline); border-radius:14px; box-shadow:var(--shadow); overflow:hidden; }
.card-head { display:flex; align-items:center; gap:12px; padding:15px 18px; border-bottom:1px solid var(--rule); flex-wrap:wrap; }

/* ── Import WhatsApp ── */
.import-body { padding:16px 18px; display:flex; flex-direction:column; gap:11px; }
textarea#wa-text { width:100%; min-height:120px; resize:vertical; border:1px solid var(--hairline); border-radius:9px; padding:12px; font-family:var(--mono); font-size:12px; background:var(--surface-2); color:var(--ink); line-height:1.5; }
textarea#wa-text:focus { outline:2px solid var(--accent-2); outline-offset:1px; }
.import-actions { display:flex; gap:8px; flex-wrap:wrap; }
.file-btn { position:relative; }
.import-result { margin:0 18px 16px; padding:12px 14px; border-radius:9px; font-size:12.5px; line-height:1.55; background:var(--surface-2); border:1px solid var(--rule); }
.import-result .tag { display:inline-block; font-family:var(--mono); font-size:11px; padding:1px 7px; border-radius:5px; margin:2px 3px 0 0; }
.tag-ok { background:var(--good-wash); color:var(--good-ink); }
.tag-unknown { background:var(--warn-wash); color:var(--warn-ink); }
.res-ok { background:var(--good-wash); color:var(--good-ink); border-color:transparent; }
.res-warn { background:var(--warn-wash); color:var(--warn-ink); border-color:transparent; }

/* ── Recherche & filtres ── */
.search-input { border:1px solid var(--hairline); background:var(--surface-2); color:var(--ink); border-radius:9px; padding:7px 12px; font:inherit; font-size:12.5px; min-width:240px; }
.search-input:focus { outline:2px solid var(--accent-2); outline-offset:1px; }
.filters { margin-left:auto; display:flex; gap:6px; flex-wrap:wrap; }
.chip { border:1px solid var(--hairline); background:var(--surface); color:var(--ink-2); border-radius:20px; padding:5px 12px; font:inherit; font-size:12.5px; cursor:pointer; transition:background .12s; }
.chip:hover { background:var(--surface-2); }
.chip[aria-pressed="true"] { background:var(--accent); border-color:var(--accent); color:var(--on-accent); font-weight:600; }
.chip .n { font-family:var(--mono); opacity:.7; margin-left:5px; font-variant-numeric:tabular-nums; }
.chip[aria-pressed="true"] .n { opacity:.85; }

/* ── Tableau ── */
.table-wrap { overflow-x:auto; }
table { border-collapse:collapse; width:100%; min-width:900px; font-size:13px; }
thead th { text-align:left; font-size:10.5px; font-weight:650; text-transform:uppercase; letter-spacing:.07em; color:var(--muted); padding:11px 14px; border-bottom:1px solid var(--hairline); background:var(--surface-2); white-space:nowrap; }
tbody td { padding:12px 14px; border-bottom:1px solid var(--rule); vertical-align:middle; }
tbody tr:last-child td { border-bottom:0; }
tbody tr:hover { background:var(--surface-2); }
.right { text-align:right; }
.ordno { font-family:var(--mono); font-weight:650; font-size:13.5px; }
.mono { font-family:var(--mono); font-variant-numeric:tabular-nums; }
.prod-tag { display:inline-flex; align-items:center; gap:5px; font-size:12px; background:var(--surface-2); border:1px solid var(--hairline); border-radius:7px; padding:3px 9px; margin:1px 2px 1px 0; }
.qty { color:var(--muted); font-family:var(--mono); }

/* ── Pastilles de statut ── */
.pill { display:inline-flex; align-items:center; gap:6px; font-size:11.5px; font-weight:640; padding:4px 11px 4px 9px; border-radius:20px; white-space:nowrap; }
.pill::before { content:""; width:6px; height:6px; border-radius:50%; background:currentColor; }
.p-en_attente { background:var(--surface-2); color:var(--ink-2); }
.p-preuve_recue { background:var(--accent-wash); color:var(--accent); }
.p-partiel { background:var(--gold-wash); color:var(--gold); }
.p-envoye { background:var(--good-wash); color:var(--good-ink); }

/* ── Actions & unités (puits) ── */
.act-cell { text-align:right; }
.row-actions { display:flex; gap:7px; justify-content:flex-end; align-items:center; }
.sent-at { font-size:11px; color:var(--muted); font-family:var(--mono); }
.units { display:flex; flex-direction:column; gap:7px; align-items:stretch; min-width:250px; }
.unit-row { display:flex; align-items:center; gap:10px; }
.unit-name { font-size:12px; color:var(--ink-2); text-align:left; flex:1; }
.unit-name b { color:var(--ink); font-weight:600; }
.unit-act { display:flex; gap:6px; align-items:center; justify-content:flex-end; flex:none; }

/* ── Statut modifiable (menu déroulant en forme de pastille) ── */
.status-select {
  appearance:none; -webkit-appearance:none;
  border:1px solid transparent; border-radius:20px;
  padding:4px 24px 4px 11px; font:inherit; font-size:11.5px; font-weight:640;
  cursor:pointer; line-height:1.5; max-width:100%;
  background-repeat:no-repeat; background-position:right 8px center; background-size:9px;
  background-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 10 10'%3E%3Cpath d='M2 3.5L5 6.5L8 3.5' stroke='%23999' fill='none' stroke-width='1.4'/%3E%3C/svg%3E");
}
.status-select:hover { filter:brightness(0.98); }
.status-select:focus-visible { outline:2px solid var(--accent-2); outline-offset:1px; }
.status-select.s-en_attente { background-color:var(--surface-2); color:var(--ink-2); }
.status-select.s-preuve_recue { background-color:var(--accent-wash); color:var(--accent); }
.status-select.s-partiel { background-color:var(--gold-wash); color:var(--gold); }
.status-select.s-envoye { background-color:var(--good-wash); color:var(--good-ink); }
.status-select.s-probleme { background-color:var(--crit-wash); color:var(--crit-ink); }
.status-select option { color:var(--ink); background:var(--surface); }
.note-line { margin-top:4px; max-width:220px; font-size:11px; color:var(--ink-2); cursor:pointer; line-height:1.35; overflow:hidden; text-overflow:ellipsis; display:-webkit-box; -webkit-line-clamp:2; -webkit-box-orient:vertical; }
.note-line:hover { color:var(--accent); }
.note-line.is-problem { color:var(--crit-ink); }

/* ── Téléphone corrigeable ── */
.phone-cell { cursor:pointer; white-space:nowrap; }
.phone-cell .edit-pencil { opacity:0; font-size:11px; transition:opacity .12s; }
.phone-cell:hover { color:var(--accent); }
.phone-cell:hover .edit-pencil { opacity:.55; }
.edited-badge { font-family:var(--sans); font-size:10px; font-weight:600; color:var(--accent); background:var(--accent-wash); padding:1px 6px; border-radius:5px; vertical-align:middle; }

.empty { padding:28px; text-align:center; color:var(--muted); }

/* ── Fenêtres modales ── */
.modal { position:fixed; inset:0; background:rgba(8,12,24,.5); display:grid; place-items:center; padding:20px; z-index:20; }
.modal[hidden] { display:none; }
.modal-box { background:var(--surface); border:1px solid var(--hairline); border-radius:16px; box-shadow:var(--shadow); width:min(640px,100%); max-height:88vh; overflow-y:auto; padding:20px; }
.modal-head { display:flex; align-items:center; margin-bottom:6px; }
.modal-head .close { margin-left:auto; }
.modal-foot { margin-top:16px; display:flex; justify-content:flex-end; }
.tpl-field { margin-top:14px; }
.tpl-field label { font-size:12.5px; font-weight:600; display:block; margin-bottom:5px; }
.tpl-field textarea { width:100%; min-height:110px; resize:vertical; border:1px solid var(--hairline); border-radius:9px; padding:11px; font-family:var(--sans); font-size:13px; background:var(--surface-2); color:var(--ink); line-height:1.5; }
.field { display:block; margin-top:14px; }
.field > span { display:block; font-size:12.5px; font-weight:600; margin-bottom:5px; }
.field input { width:100%; border:1px solid var(--hairline); border-radius:9px; padding:9px 12px; font:inherit; font-size:13px; background:var(--surface-2); color:var(--ink); }
.field input:focus { outline:2px solid var(--accent-2); outline-offset:1px; }
.field.checkbox { display:flex; align-items:center; gap:9px; }
.field.checkbox > span { margin:0; font-weight:400; }
.field.checkbox input { width:auto; }

.toast { position:fixed; bottom:24px; left:50%; transform:translateX(-50%); background:var(--ink); color:var(--ground); padding:11px 18px; border-radius:10px; font-size:13px; z-index:30; box-shadow:var(--shadow); display:inline-flex; align-items:center; gap:14px; }
.toast-action { background:none; border:none; color:var(--gold-soft); font:inherit; font-size:13px; font-weight:650; cursor:pointer; padding:2px 4px; border-radius:6px; }
.toast-action:hover { color:var(--gold); text-decoration:underline; }
.toast[hidden] { display:none; }

/* ── Onglets ── */
.tabnav { background:var(--surface); border-bottom:1px solid var(--hairline); }
.tabnav-inner { max-width:1680px; margin:0 auto; padding:0 22px; display:flex; gap:2px; }
.tab { border:0; background:none; font:inherit; font-size:13.5px; font-weight:640; color:var(--ink-2); padding:13px 16px 12px; cursor:pointer; border-bottom:2px solid transparent; }
.tab:hover { color:var(--ink); }
.tab[aria-current="true"] { color:var(--accent); border-bottom-color:var(--accent); }
.view { display:flex; flex-direction:column; gap:18px; }
.view[hidden] { display:none; }
.period-bar { display:flex; align-items:center; flex-wrap:wrap; gap:8px 12px; padding:14px 18px; }
.pb-label { font-size:11px; font-weight:650; text-transform:uppercase; letter-spacing:.06em; color:var(--muted); }
.pb-chips { display:flex; gap:6px; flex-wrap:wrap; }
.pb-sep { width:1px; height:20px; background:var(--hairline); }
.pb-arrow { color:var(--muted); font-size:12px; }
.date-input { border:1px solid var(--hairline); background:var(--surface-2); color:var(--ink); border-radius:7px; padding:4px 9px; font:inherit; font-size:12.5px; color-scheme:light dark; }
.date-input:focus { outline:2px solid var(--accent-2); outline-offset:1px; }
.prod-grid { display:grid; grid-template-columns:repeat(4,1fr); gap:12px; padding:16px; }
@media (max-width:720px){ .prod-grid { grid-template-columns:repeat(2,1fr); } }

/* ── Statistiques ── */
.stats-chart { padding:16px 18px 12px; display:flex; flex-direction:column; gap:12px; }
.chart-legend { display:flex; flex-wrap:wrap; gap:8px 16px; font-size:12px; }
.lg { display:inline-flex; align-items:center; gap:6px; color:var(--ink-2); }
.lg::before { content:""; width:11px; height:11px; border-radius:3px; background:var(--c); flex:none; }
.linechart { width:100%; height:auto; display:block; overflow:visible; }
.linechart .grid { stroke:var(--hairline); stroke-width:1; }
.linechart .line { fill:none; stroke:currentColor; stroke-width:2; stroke-linejoin:round; stroke-linecap:round; }
.linechart .dot { fill:currentColor; stroke:var(--surface); stroke-width:1.5; transition:r .1s; }
.linechart .hit { fill:transparent; cursor:pointer; }
.linechart .val { opacity:0; text-anchor:middle; font-size:11px; font-weight:700; fill:var(--ink); paint-order:stroke; stroke:var(--surface); stroke-width:3px; stroke-linejoin:round; pointer-events:none; transition:opacity .1s; }
.linechart .pt:hover .dot { r:4.5; }
.linechart .pt:hover .val { opacity:1; }
.linechart .ax { fill:var(--muted); font-size:11px; }
.linechart .ax-y { text-anchor:end; font-variant-numeric:tabular-nums; }
.linechart .ax-x { text-anchor:middle; text-transform:capitalize; }
.prodtab { width:100%; border-collapse:collapse; font-size:13px; }
.prodtab th { text-align:left; font-size:10.5px; font-weight:650; text-transform:uppercase; letter-spacing:.06em; color:var(--muted); padding:10px 16px; border-bottom:1px solid var(--rule); white-space:nowrap; }
.prodtab td { padding:11px 16px; border-bottom:1px solid var(--rule); }
.prodtab tr:last-child td { border-bottom:0; }
.prodtab .muted-cell { color:var(--muted); }
.prodtab .right { text-align:right; }
.profit-cell { cursor:pointer; white-space:nowrap; font-family:var(--mono); font-variant-numeric:tabular-nums; }
.profit-cell:hover { color:var(--accent); }
tfoot td { padding:12px 14px; border-top:2px solid var(--hairline); font-weight:680; font-variant-numeric:tabular-nums; }
.stats-money { font-family:var(--mono); font-variant-numeric:tabular-nums; }

/* ── Logo sur plaque claire en mode sombre (le marine du logo se lirait mal sinon) ── */
@media (prefers-color-scheme: dark) {
  .brand-logo { background:#fff; padding:5px 9px; border-radius:9px; height:26px; box-sizing:content-box; }
}

@media (max-width:720px) {
  .kpis { grid-template-columns:repeat(2,1fr); }
  .topbar { padding:12px 16px; }
  .wrap { padding:16px 14px 48px; }
  .brand-sub { display:none; }
}
