/* Dashboard : mobile d'abord. Couleurs vives, cartes blanches, chiffres en gras (goût du CEO, pas de beige). */

:root {
  color-scheme: light;
  --bg: #f3f4fa;
  --surface: #ffffff;
  --surface-2: #f6f7fc;
  --border: #e3e6f0;
  --text: #0f1222;
  --text-2: #424760;
  --muted: #6a6f87;
  --brand-1: #6d4aff;
  --brand-2: #2a78d6;
  --brand-grad: linear-gradient(135deg, #6d4aff 0%, #4f5df5 45%, #2a78d6 100%);
  --accent: #4f46e5;
  --accent-ink: #ffffff;
  --series-1: #2a78d6;
  --series-1-soft: rgba(42, 120, 214, 0.14);
  --grid: #e8eaf2;
  --good: #0a7d3e;
  --good-bg: #e6f6ec;
  --bad: #c42b2b;
  --bad-bg: #fdecec;
  --warn: #9a5b00;
  --warn-bg: #fff4dc;
  --info-bg: #eef0ff;
  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 1px 2px rgba(16, 20, 50, 0.05), 0 6px 20px rgba(16, 20, 50, 0.06);
  --bar-h: 64px;
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme='light'])) {
    color-scheme: dark;
    --bg: #0e1016;
    --surface: #1a1c24;
    --surface-2: #22242e;
    --border: #2e3140;
    --text: #f0f1f5;
    --text-2: #c7c9d6;
    --muted: #9a9db0;
    --accent: #8b84ff;
    --accent-ink: #0e1016;
    --series-1: #3987e5;
    --series-1-soft: rgba(57, 135, 229, 0.22);
    --grid: #2a2d3a;
    --good: #4cc77f;
    --good-bg: #13301f;
    --bad: #ff7b7b;
    --bad-bg: #3a1717;
    --warn: #f0b44c;
    --warn-bg: #33270f;
    --info-bg: #23244a;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font-size: 16px; line-height: 1.45; }
body.with-bar { padding-bottom: calc(var(--bar-h) + env(safe-area-inset-bottom)); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; letter-spacing: -0.01em; }
h1 { font-size: 1.6rem; font-weight: 800; }
h2 { font-size: 1.08rem; font-weight: 800; }
h3 { font-size: 0.98rem; font-weight: 700; margin-bottom: 8px; }
.muted { color: var(--muted); }
.icon { flex: none; }

/* Bandeau de démonstration */
.demo-banner { background: #ffd23f; color: #241a00; text-align: center; font-weight: 700; font-size: 0.85rem; padding: 6px 12px; }

/* En-tête */
.top { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 10px; padding: 10px 16px; padding-top: calc(10px + env(safe-area-inset-top)); background: var(--brand-grad); color: #fff; }
.brand { display: flex; align-items: center; gap: 8px; color: #fff; font-weight: 800; }
.brand:hover { text-decoration: none; }
.brand-mark { display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 9px; background: rgba(255, 255, 255, 0.22); color: #fff; font-weight: 900; }
.brand-name { display: none; }
.app-switch { display: flex; gap: 6px; overflow-x: auto; flex: 1; }
.app-chip { padding: 5px 12px; border-radius: 999px; background: rgba(255, 255, 255, 0.16); color: #fff; font-weight: 700; font-size: 0.9rem; white-space: nowrap; }
.app-chip.on { background: #fff; color: #3a2fd0; }
.app-chip:hover { text-decoration: none; }
.top-menu { color: #fff; display: grid; place-items: center; width: 40px; height: 40px; border-radius: 12px; }
.top-menu:hover { background: rgba(255, 255, 255, 0.16); }

/* Mise en page */
.shell { display: block; }
.side { display: none; }
.main { max-width: 1100px; margin: 0 auto; padding: 14px 16px 28px; }

/* Barre du bas (téléphone) */
.bar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: grid; grid-template-columns: repeat(5, 1fr); height: calc(var(--bar-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom); background: var(--surface); border-top: 1px solid var(--border); }
.bar-item { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; color: var(--muted); font-size: 0.68rem; font-weight: 600; }
.bar-item:hover { text-decoration: none; }
.bar-item.on { color: var(--accent); }

@media (min-width: 900px) {
  body.with-bar { padding-bottom: 0; }
  .bar, .top-menu { display: none; }
  .brand-name { display: inline; }
  .shell { display: grid; grid-template-columns: 240px 1fr; min-height: calc(100vh - 56px); }
  .side { display: flex; flex-direction: column; gap: 2px; padding: 16px 12px; border-right: 1px solid var(--border); background: var(--surface); position: sticky; top: 56px; height: calc(100vh - 56px); }
  .main { padding: 22px 28px 40px; width: 100%; }
}
.side-item { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 12px; color: var(--text-2); font-weight: 600; font-size: 0.95rem; }
.side-item:hover { background: var(--surface-2); text-decoration: none; }
.side-item.on { background: var(--info-bg); color: var(--accent); }
.side-logout { margin-top: auto; }
.linklike { width: 100%; border: 0; background: none; cursor: pointer; font: inherit; text-align: left; }
.soon { margin-left: auto; font-size: 0.7rem; font-weight: 700; color: var(--muted); background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; padding: 1px 7px; }

/* Filtres partagés */
.filters { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 0 0 14px; }
.seg { display: inline-flex; background: var(--surface); border: 1px solid var(--border); border-radius: 999px; padding: 3px; }
.seg-wrap { flex-wrap: wrap; margin-bottom: 12px; }
.seg-item { padding: 6px 13px; border-radius: 999px; color: var(--text-2); font-weight: 700; font-size: 0.88rem; }
.seg-item:hover { text-decoration: none; background: var(--surface-2); }
.seg-item.on { background: var(--accent); color: var(--accent-ink); }
.chip-static { padding: 7px 13px; border-radius: 999px; background: var(--surface); border: 1px dashed var(--border); color: var(--muted); font-weight: 600; font-size: 0.85rem; }

/* Titres, sections, cartes */
.page-title { margin: 4px 0 14px; }
.page-title .subtitle { margin: 4px 0 0; color: var(--muted); }
.back { display: inline-block; margin-bottom: 6px; font-weight: 600; font-size: 0.9rem; }
.section { margin: 22px 0; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.section-aside { color: var(--muted); font-size: 0.85rem; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.card + .card { margin-top: 10px; }
.card-link { display: block; color: inherit; }
.card-link:hover { text-decoration: none; border-color: var(--accent); }
.pill { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 0.75rem; font-weight: 700; background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border); }
.pill-good { background: var(--good-bg); color: var(--good); border-color: transparent; }
.pill-bad { background: var(--bad-bg); color: var(--bad); border-color: transparent; }
.pill-warn { background: var(--warn-bg); color: var(--warn); border-color: transparent; }

/* Messages */
.notice { border-radius: var(--radius-sm); padding: 11px 14px; margin: 10px 0; font-size: 0.93rem; background: var(--info-bg); }
.notice-good { background: var(--good-bg); color: var(--good); }
.notice-warning { background: var(--warn-bg); color: var(--warn); }
.notice-danger { background: var(--bad-bg); color: var(--bad); }

/* Chiffres clés */
.figs { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
@media (min-width: 900px) { .figs { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 899px) { .figs > .fig:last-child:nth-child(odd) { grid-column: 1 / -1; min-height: 0; } }
.figs + .table-wrap, .figs + .section, .figs + .card { margin-top: 10px; }
.fig { display: flex; flex-direction: column; gap: 3px; min-height: 124px; }
.fig + .fig { margin-top: 0; }
.fig-label { color: var(--text-2); font-size: 0.82rem; font-weight: 700; }
.fig-value { font-size: 1.75rem; font-weight: 850; letter-spacing: -0.02em; line-height: 1.1; font-variant-numeric: tabular-nums; }
.fig-delta { font-size: 0.8rem; }
.fig-note { color: var(--muted); font-size: 0.76rem; }
.fig-source { margin-top: auto; color: var(--muted); font-size: 0.72rem; }
.delta { display: inline-flex; align-items: center; gap: 3px; font-weight: 700; }
.delta-good { color: var(--good); }
.delta-bad { color: var(--bad); }
.delta-flat, .delta-none { color: var(--muted); font-weight: 600; }

/* Alertes */
.alerts { display: grid; gap: 8px; margin-bottom: 6px; }
.alert { display: flex; gap: 10px; align-items: flex-start; border-radius: var(--radius-sm); padding: 11px 14px; background: var(--bad-bg); color: var(--bad); font-weight: 600; font-size: 0.92rem; }
.alert-warning { background: var(--warn-bg); color: var(--warn); }
.alert small { display: block; font-weight: 500; opacity: 0.9; }

/* Onglets */
.tabs { display: flex; gap: 2px; overflow-x: auto; margin: 0 0 14px; border-bottom: 1px solid var(--border); }
.tab { flex: 1 0 auto; text-align: center; padding: 9px 8px; color: var(--muted); font-weight: 700; font-size: 0.88rem; white-space: nowrap; border-bottom: 3px solid transparent; }
@media (min-width: 900px) { .tab { flex: 0 0 auto; padding: 9px 14px; font-size: 0.95rem; } }
.tab:hover { text-decoration: none; color: var(--text); }
.tab.on { color: var(--accent); border-bottom-color: var(--accent); }

/* Tableaux et listes */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.table { width: 100%; border-collapse: collapse; font-size: 0.9rem; font-variant-numeric: tabular-nums; }
.table th, .table td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table th { color: var(--muted); font-weight: 700; font-size: 0.78rem; }
.table tr:last-child td { border-bottom: 0; }
.table td.num, .table th.num { text-align: right; }
.table tr.changed td { background: var(--warn-bg); }
.list.changes li { flex-direction: column; align-items: flex-start; gap: 2px; }
.list.changes li.changed { background: var(--warn-bg); margin: 0 -10px; padding: 10px; border-radius: 10px; }
.changes .change { font-variant-numeric: tabular-nums; }
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.list li:last-child { border-bottom: 0; }
.card.list { padding: 4px 16px; }
.menu-list a { display: flex; align-items: center; gap: 12px; width: 100%; color: var(--text); font-weight: 700; padding: 6px 0; }
.journal-row { display: flex; flex-direction: column; gap: 2px; width: 100%; color: var(--text); }
.journal-row:hover { text-decoration: none; }
.journal-meta { color: var(--muted); font-size: 0.8rem; }
.fields { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 8px 14px; margin: 0; }
.fields dt { color: var(--muted); font-weight: 600; }
.fields dd { margin: 0; }
.diff { display: grid; gap: 10px; margin-top: 10px; }
@media (min-width: 900px) { .diff { grid-template-columns: 1fr 1fr; } }
.diff .card + .card { margin-top: 0; }
pre { margin: 0; white-space: pre-wrap; word-break: break-word; font-size: 0.8rem; }
.tiles { display: grid; gap: 10px; }
@media (min-width: 700px) { .tiles { grid-template-columns: 1fr 1fr; } }
.tile { display: flex; flex-direction: column; gap: 4px; }
.tile + .tile { margin-top: 0; }
.tile span { color: var(--muted); font-size: 0.9rem; }
.planned ul { margin: 10px 0 0; padding-left: 20px; display: grid; gap: 6px; }
.planned p { margin: 0; }
.missing { margin: 18px 0 0; color: var(--muted); font-size: 0.85rem; }
.missing-title { font-weight: 700; }
.missing ul { margin: 6px 0 0; padding-left: 18px; }
.missing li { margin: 3px 0; }
.missing .soon { margin-left: 4px; }

/* Formulaires */
.form { display: grid; gap: 12px; }
.form p { margin: 0; }
label { display: grid; gap: 5px; font-weight: 600; font-size: 0.9rem; color: var(--text-2); }
input[type='text'], input[type='email'], input[type='password'], input[type='number'] { font: inherit; font-size: 16px; padding: 11px 12px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); width: 100%; }
input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; font: inherit; font-weight: 700; padding: 11px 16px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer; }
.btn:hover { text-decoration: none; border-color: var(--accent); }
.btn-primary { background: var(--brand-grad); color: #fff; border: 0; }
.btn-ghost { background: transparent; }
.btn-small { padding: 6px 10px; font-size: 0.85rem; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.preview { border-color: var(--accent); }
.history summary { cursor: pointer; font-weight: 700; }
.secret code { font-size: 1.05rem; letter-spacing: 0.06em; word-break: break-all; }

/* Connexion */
body.bare { min-height: 100vh; background: var(--brand-grad); }
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card { width: 100%; max-width: 380px; display: grid; gap: 10px; }
.login-brand { display: flex; align-items: center; gap: 10px; }
.login-brand .brand-mark { background: var(--brand-grad); }
.login .subtitle { margin: 0; color: var(--muted); }

/* Graphiques */
.chart { position: relative; margin: 0; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .grid line { stroke: var(--grid); stroke-width: 1; }
.chart .axis text, .chart .lbl { fill: var(--muted); font-size: 10px; font-variant-numeric: tabular-nums; }
.chart .line { fill: none; stroke: var(--series-1); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .area { fill: var(--series-1-soft); }
.chart .bar-mark { fill: var(--series-1); }
.chart .hit { fill: transparent; }
.chart .cross { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 3; }
.chart .dot { fill: var(--series-1); stroke: var(--surface); stroke-width: 2; }
.chart-data { margin-top: 8px; font-size: 0.85rem; }
.chart-data summary { cursor: pointer; color: var(--muted); font-weight: 600; }
.chart-data .table-wrap { margin-top: 8px; max-height: 260px; overflow-y: auto; box-shadow: none; }
.chart + .chart { margin-top: 10px; }
.chart-caption { margin: 8px 0 0; color: var(--muted); font-size: 0.82rem; }
.chart-title { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 6px; }
.chart-title strong { font-size: 0.95rem; }
.chart-title span { color: var(--muted); font-size: 0.8rem; }
.tip { position: absolute; z-index: 5; pointer-events: none; background: var(--text); color: var(--surface); padding: 6px 9px; border-radius: 8px; font-size: 0.8rem; font-weight: 600; white-space: nowrap; transform: translate(-50%, calc(-100% - 10px)); opacity: 0; transition: opacity 0.08s; }
.tip.show { opacity: 1; }

/* Entonnoir */
.funnel { display: grid; gap: 8px; }
.funnel-step { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; align-items: center; }
.funnel-label { font-weight: 700; font-size: 0.9rem; }
.funnel-num { font-weight: 800; font-variant-numeric: tabular-nums; }
.funnel-track { grid-column: 1 / -1; display: block; width: 100%; height: 10px; border-radius: 999px; background: var(--surface-2); }
.funnel-fill { fill: var(--series-1); }
.funnel-sub { grid-column: 1 / -1; color: var(--muted); font-size: 0.78rem; }

/* Cohortes */
.cohort th, .cohort td { padding: 9px 6px; font-size: 0.85rem; }
.cohort th:first-child, .cohort td:first-child { padding-left: 12px; }
.cohort th.cell, .cohort td.cell { text-align: center; font-weight: 700; }
.cohort .heat-0 { background: transparent; }
.cohort .heat-1 { background: rgba(42, 120, 214, 0.12); }
.cohort .heat-2 { background: rgba(42, 120, 214, 0.26); }
.cohort .heat-3 { background: rgba(42, 120, 214, 0.42); }
.cohort .heat-4 { background: rgba(42, 120, 214, 0.6); color: #fff; }
.todo li { align-items: flex-start; }
.todo .when { color: var(--muted); font-size: 0.85rem; white-space: nowrap; }
.read-at { color: var(--muted); font-size: 0.78rem; margin-top: 18px; }

/* Liste à deux niveaux (tableau trop large pour un téléphone) */
.stacked li { flex-direction: column; align-items: flex-start; gap: 3px; }
.stacked .row-title { font-weight: 700; }
.stacked .row-meta { display: flex; flex-wrap: wrap; gap: 4px 14px; color: var(--muted); font-size: 0.85rem; }
.stacked .row-meta b { color: var(--text-2); font-weight: 700; }
.spaced { margin-top: 10px; }

/* Journal */
.journal-filters { display: grid; gap: 8px; margin-bottom: 14px; }
.journal-filters .seg-wrap { margin-bottom: 0; flex-wrap: nowrap; overflow-x: auto; max-width: 100%; }
.journal-filters .seg-item { padding: 6px 11px; white-space: nowrap; }
.search { display: flex; gap: 8px; }
.search input[type='search'] { flex: 1; min-width: 0; font: inherit; font-size: 16px; padding: 8px 12px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface); color: var(--text); }
.journal-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.journal-tools .btn { margin-left: auto; }
.chip-toggle { padding: 6px 12px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); color: var(--text-2); font-weight: 700; font-size: 0.85rem; }
.chip-toggle:hover { text-decoration: none; border-color: var(--accent); }
.chip-toggle.on { background: var(--bad-bg); color: var(--bad); border-color: transparent; }
.journal-day + .journal-day { margin-top: 14px; }
.day-head { margin: 0 0 6px; font-size: 0.85rem; color: var(--muted); font-weight: 700; text-transform: none; }
.raw { margin-top: 16px; }

/* Ventes */
.seg-scroll { flex-wrap: nowrap; overflow-x: auto; max-width: 100%; }
.seg-scroll .seg-item { white-space: nowrap; padding: 6px 9px; font-size: 0.82rem; }
.table td.wrap { white-space: normal; }
.orders li { align-items: flex-start; }
.order-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.order-meta { color: var(--muted); font-size: 0.8rem; }
.order-link { font-size: 0.8rem; font-weight: 600; }
.order-side { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.pager { align-items: center; justify-content: space-between; }
.small { font-size: 0.82rem; }
.products li.product { flex-direction: column; align-items: stretch; gap: 4px; }
.product-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.product-figs { display: flex; flex-direction: column; gap: 2px; font-size: 0.88rem; }
.product-figs .muted { font-size: 0.8rem; }
.product-links { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 0.82rem; font-weight: 600; }
.btn-danger { background: var(--bad); color: #fff; border: 0; }
.btn-danger:hover { filter: brightness(1.08); }
.danger-link { color: var(--bad); }
.fields dd { min-width: 0; overflow-wrap: anywhere; }
.fields dd code { word-break: break-all; }

/* Communication */
.intro { margin: -4px 0 14px; }
.reasons li > span { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.reasons li.sub { padding-left: 14px; color: var(--muted); font-size: 0.9rem; }
.reasons li.sub b { font-weight: 600; }
.sent-list li { flex-direction: column; align-items: flex-start; gap: 2px; }
.sent-meta { color: var(--muted); font-size: 0.8rem; }
