:root {
  color-scheme: light;
  --bg: #F7F2EA;
  --surface: #FFFFFF;
  --surface-2: #F5EEE4;
  --line: #ECE3D7;
  --grid: #F0E9DF;
  --text: #2B1F1A;
  --text-2: #6B5E57;
  --text-3: #978A82;
  --coral: #F26B4E;
  --coral-soft: #FDE7E0;
  /* Séries des graphiques (palette validée : daltonisme, contraste). */
  --series-1: #E8593C;
  --series-2: #2a78d6;
  --series-neutral: #CFC6BC;
  --good: #2E7D32;
  --bad: #C62828;
  --radius: 18px;
  --gap: 24px;
  --shadow: 0 1px 2px rgba(92, 64, 51, 0.05), 0 4px 16px rgba(92, 64, 51, 0.05);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #161210;
    --surface: #211B18;
    --surface-2: #2B2320;
    --line: #382F2A;
    --grid: #2F2723;
    --text: #F3ECE7;
    --text-2: #C3B6AE;
    --text-3: #8F827A;
    --coral-soft: #4A2A22;
    --series-1: #E2603F;
    --series-2: #3987e5;
    --series-neutral: #5E534D;
    --good: #66BB6A;
    --bad: #EF6C6C;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #161210;
  --surface: #211B18;
  --surface-2: #2B2320;
  --line: #382F2A;
  --grid: #2F2723;
  --text: #F3ECE7;
  --text-2: #C3B6AE;
  --text-3: #8F827A;
  --coral-soft: #4A2A22;
  --series-1: #E2603F;
  --series-2: #3987e5;
  --series-neutral: #5E534D;
  --good: #66BB6A;
  --bad: #EF6C6C;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.5 'Plus Jakarta Sans', system-ui, sans-serif; -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { margin: 0; letter-spacing: -0.3px; }
.muted { color: var(--text-2); }
.wordmark { font-weight: 800; font-size: 26px; letter-spacing: -1px; color: var(--coral); line-height: 1; }
.btn {
  background: var(--coral); color: #fff; border: 0; border-radius: 12px; padding: 12px 20px;
  font: inherit; font-weight: 700; cursor: pointer;
}
.btn:hover { filter: brightness(0.96); }
.btn:disabled { opacity: .6; cursor: default; }
.link-btn { background: none; border: 0; color: var(--text-2); font: inherit; font-weight: 600; cursor: pointer; padding: 6px 0; }
.link-btn:hover { color: var(--text); }
.msg { font-size: 14px; color: var(--text-2); margin: 0; }
input, select {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 12px; min-width: 0;
}
input:focus, select:focus { outline: 2px solid color-mix(in srgb, var(--coral) 40%, transparent); outline-offset: 1px; border-color: var(--coral); }

/* ---------- Connexion ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card { background: var(--surface); border-radius: 24px; padding: 36px; width: min(420px, 100%); box-shadow: var(--shadow); }
.login-card h1 { margin: 14px 0 4px; font-size: 28px; }
.login-card form { display: grid; gap: 10px; margin-top: 20px; }
.login-card .msg { margin-top: 12px; }
.hint { color: var(--text-3); font-size: 12.5px; margin: -4px 0 0 4px; }

/* ---------- Structure : menu latéral + contenu ---------- */
.shell { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 28px;
  padding: 28px 18px; background: var(--surface); border-right: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; padding: 0 10px; }
.brand .tag { background: var(--coral-soft); color: var(--coral); font-weight: 800; font-size: 12px; padding: 3px 9px; border-radius: 999px; }
.nav { display: grid; gap: 4px; }
.nav button {
  display: flex; align-items: center; gap: 12px; width: 100%; padding: 11px 12px; border: 0; border-radius: 12px;
  background: none; color: var(--text-2); font: inherit; font-weight: 650; font-size: 15px; text-align: left; cursor: pointer;
}
.nav button:hover { background: var(--surface-2); color: var(--text); }
.nav button[aria-current="page"] { background: var(--coral-soft); color: var(--coral); }
.nav svg { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.sidebar-foot { margin-top: auto; display: grid; gap: 8px; padding: 0 10px; }
.live { display: flex; align-items: flex-start; gap: 8px; margin: 0; color: var(--text-3); font-size: 12.5px; line-height: 1.45; }
.live-dot { width: 8px; height: 8px; margin-top: 5px; border-radius: 50%; background: var(--good); flex: none;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--good) 22%, transparent); }

.content { min-width: 0; padding: 32px 40px 56px; max-width: 1320px; width: 100%; }
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 16px 24px; margin-bottom: var(--gap); }
.page-head h1 { font-size: 30px; letter-spacing: -0.8px; }
.page-head p { margin: 4px 0 0; font-size: 14.5px; }
.controls { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.seg { display: inline-flex; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 3px; }
.seg button { border: 0; background: none; font: inherit; font-weight: 700; font-size: 14px; color: var(--text-2); padding: 7px 14px; border-radius: 9px; cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--coral-soft); color: var(--coral); }
select { padding-right: 32px; font-weight: 600; font-size: 14px; }
.custom { display: inline-flex; align-items: center; gap: 6px; }
.icon-btn { display: grid; place-items: center; width: 42px; height: 42px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); color: var(--text-2); cursor: pointer; }
.icon-btn:hover { color: var(--text); }
.icon-btn.spin svg { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.view { display: grid; gap: var(--gap); }

/* ---------- Indicateurs ---------- */
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.kpi { background: var(--surface); border-radius: var(--radius); padding: 20px 22px; box-shadow: var(--shadow); display: grid; gap: 6px; align-content: start; }
.kpi .label { color: var(--text-2); font-size: 14px; font-weight: 650; }
.kpi .value { font-size: 32px; font-weight: 800; letter-spacing: -1px; line-height: 1.1; font-variant-numeric: tabular-nums; }
.kpi .value.neg { color: var(--bad); }
.kpi .value.dim { color: var(--text-3); }
.kpi .sub { color: var(--text-3); font-size: 13px; line-height: 1.4; }

/* ---------- Panneaux ---------- */
.grid { display: grid; gap: var(--gap); }
.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.panel { background: var(--surface); border-radius: var(--radius); padding: 24px; box-shadow: var(--shadow); min-width: 0; }
.panel-head { margin-bottom: 20px; }
.panel-head h2 { font-size: 18px; }
.panel-head p { margin: 4px 0 0; color: var(--text-2); font-size: 14px; }

.chart { position: relative; height: 280px; }
.chart svg { display: block; width: 100%; height: 100%; overflow: visible; }
.legend { display: flex; flex-wrap: wrap; gap: 16px; font-size: 13px; color: var(--text-2); margin-bottom: 10px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 7px; vertical-align: -1px; }
.axis text { fill: var(--text-3); font-size: 11.5px; font-variant-numeric: tabular-nums; }
.gridline { stroke: var(--grid); stroke-width: 1; }
.baseline { stroke: var(--line); stroke-width: 1; }

/* État vide : explique pourquoi il n'y a rien et ce qui remplira le bloc. */
.empty {
  display: grid; place-items: center; align-content: center; text-align: center; gap: 6px; height: 100%; min-height: 160px;
  padding: 24px; border-radius: 14px; background: var(--surface-2); color: var(--text-2);
}
.empty b { color: var(--text); font-size: 15px; }
.empty span { font-size: 13.5px; max-width: 380px; }
.chart .empty { position: absolute; inset: 0; }

/* Infobulle */
.tooltip {
  position: fixed; z-index: 50; pointer-events: none; background: var(--text); color: var(--bg);
  border-radius: 10px; padding: 9px 11px; font-size: 13px; line-height: 1.5; min-width: 150px;
  box-shadow: 0 8px 24px rgba(0,0,0,.18);
}
.tooltip b { display: block; margin-bottom: 2px; }
.tooltip .row { display: flex; justify-content: space-between; gap: 16px; }
.tooltip i { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 6px; }

/* ---------- Tableaux ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; color: var(--text-3); font-weight: 700; font-size: 12.5px; padding: 0 10px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 12px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
th:first-child, td:first-child { padding-left: 0; }
th:last-child, td:last-child { padding-right: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.email { max-width: 220px; overflow: hidden; text-overflow: ellipsis; }
.pill { display: inline-block; border-radius: 999px; padding: 2px 9px; font-size: 12px; font-weight: 700; }
.pill.ok { background: color-mix(in srgb, var(--good) 14%, transparent); color: var(--good); }
.pill.err { background: color-mix(in srgb, var(--bad) 14%, transparent); color: var(--bad); }

/* Barres horizontales simples (réseaux, formules, appareils) */
.bars { display: grid; gap: 14px; }
.bars h3 { font-size: 14px; color: var(--text-2); margin-top: 8px; }
.hbar { display: grid; grid-template-columns: 110px 1fr 56px; align-items: center; gap: 14px; font-weight: 650; }
.hbar .track { height: 12px; border-radius: 0 6px 6px 0; background: var(--surface-2); overflow: hidden; }
.hbar .fill { height: 100%; border-radius: 0 6px 6px 0; background: var(--series-1); }
.hbar .fill.alt { background: var(--series-2); }
.hbar .num { text-align: right; font-variant-numeric: tabular-nums; color: var(--text-2); }

.lifetime { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin: 0; }
.lifetime div { background: var(--surface-2); border-radius: 14px; padding: 16px 18px; }
.lifetime dt { color: var(--text-2); font-size: 13.5px; }
.lifetime dd { margin: 4px 0 0; font-size: 28px; font-weight: 800; letter-spacing: -0.6px; }

/* ---------- Tunnel ---------- */
.insight { display: flex; gap: 12px; align-items: flex-start; background: var(--coral-soft); border-radius: 14px; padding: 14px 16px; margin-bottom: 22px; font-size: 14px; }
.insight svg { flex: none; width: 20px; height: 20px; margin-top: 1px; fill: none; stroke: var(--coral); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.insight ul { margin: 4px 0 0; padding-left: 18px; }
.insight .bad { color: var(--bad); }
.funnel-group { margin: 26px 0 10px; font-size: 12px; font-weight: 800; letter-spacing: .8px; text-transform: uppercase; color: var(--text-3); }
.step-head + .funnel-group { margin-top: 0; }
.step { display: grid; grid-template-columns: minmax(180px, 260px) minmax(0, 1fr) 70px 64px 52px; align-items: center; gap: 16px; padding: 7px 0; }
.step .name { font-weight: 600; font-size: 14.5px; }
.step .track { height: 26px; border-radius: 0 7px 7px 0; background: var(--surface-2); overflow: hidden; }
.step .fill { height: 100%; border-radius: 0 7px 7px 0; background: var(--series-1); min-width: 3px; }
.step .count { text-align: right; font-weight: 800; font-size: 15px; font-variant-numeric: tabular-nums; }
.step .pc { text-align: right; color: var(--text-2); font-size: 14px; font-variant-numeric: tabular-nums; }
.step .drop { text-align: right; font-size: 13px; font-weight: 700; color: var(--text-3); font-variant-numeric: tabular-nums; }
.step .drop.big { color: var(--bad); }
.step-head { color: var(--text-3); font-size: 12.5px; font-weight: 700; padding: 0 0 10px; border-bottom: 1px solid var(--line); margin-bottom: 18px; }
.step-head > span:nth-child(n+3) { text-align: right; }
.note { background: var(--surface-2); border-radius: 14px; padding: 16px 18px; font-size: 14px; color: var(--text-2); line-height: 1.55; margin: 0; }

/* ---------- Réglages ---------- */
.settings { display: grid; gap: var(--gap); max-width: 820px; }
.form-table { display: grid; gap: 10px; }
.form-row { display: grid; align-items: center; gap: 12px; }
#prices .form-row { grid-template-columns: minmax(0, 1fr) 150px 150px; }
#fixed .form-row { grid-template-columns: minmax(0, 1fr) 170px 40px; }
.form-row.head { color: var(--text-3); font-size: 12.5px; font-weight: 700; padding-bottom: 2px; }
.form-row .model { font-weight: 650; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13.5px; }
.unit { position: relative; }
.unit input { width: 100%; padding-right: 62px; text-align: right; font-variant-numeric: tabular-nums; }
.unit::after { content: attr(data-unit); position: absolute; right: 12px; top: 50%; transform: translateY(-50%); color: var(--text-3); font-size: 13px; pointer-events: none; }
.form-row > input { width: 100%; }
.remove { width: 40px; height: 40px; border-radius: 10px; border: 1px solid var(--line); background: none; color: var(--text-3); cursor: pointer; font-size: 18px; line-height: 1; }
.remove:hover { color: var(--bad); border-color: currentColor; }
.add { margin-top: 14px; color: var(--coral); }
.save-bar { display: flex; align-items: center; gap: 16px; }

.sources { margin-top: 40px; color: var(--text-3); font-size: 13px; }
.sources summary { cursor: pointer; font-weight: 650; color: var(--text-2); }
.sources div { margin-top: 10px; line-height: 1.7; max-width: 900px; }

/* ---------- Écrans plus petits ---------- */
@media (max-width: 1180px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 1000px) {
  .grid.two { grid-template-columns: 1fr; }
  .content { padding: 28px 28px 48px; }
}
@media (max-width: 860px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: sticky; z-index: 20; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; gap: 12px;
    padding: 12px 16px; border-right: 0; border-bottom: 1px solid var(--line);
  }
  .brand { padding: 0; }
  .nav { display: flex; overflow-x: auto; order: 3; width: 100%; min-width: 0; gap: 6px; scrollbar-width: none; }
  .nav button { width: auto; flex: none; }
  .nav button { padding: 8px 12px; white-space: nowrap; font-size: 14px; }
  .nav svg { display: none; }
  .sidebar-foot { margin: 0 0 0 auto; padding: 0; display: flex; align-items: center; gap: 12px; }
  .live { display: none; }
  .content { padding: 20px 16px 40px; }
  .controls { width: 100%; }
  .controls .seg { flex: 1 1 100%; }
  .controls .seg button { flex: 1; }
  .controls select { flex: 1; }
  .step { grid-template-columns: minmax(0, 1fr) 52px 48px; gap: 10px; }
  .step .track { grid-column: 1 / -1; grid-row: 2; height: 14px; }
  .step .drop { display: none; }
  .step-head { display: none; }
}
@media (max-width: 560px) {
  .kpis { gap: 12px; }
  .kpi { padding: 16px; }
  .kpi .value { font-size: 26px; }
  .page-head h1 { font-size: 25px; }
  .lifetime { grid-template-columns: 1fr; }
  #prices .form-row { grid-template-columns: 1fr 1fr; }
  #prices .form-row .model { grid-column: 1 / -1; }
  #prices .form-row.head { display: none; }
  #fixed .form-row { grid-template-columns: minmax(0, 1fr) 120px 40px; }
}

.sidebar-foot .link-btn { text-align: left; }

/* ---------- Petits éléments de formulaire, dessinés plutôt que laissés au navigateur ---------- */
:root { --chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M2.5 4.5 6 8l3.5-3.5' fill='none' stroke='%236B5E57' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E"); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M2.5 4.5 6 8l3.5-3.5' fill='none' stroke='%23C3B6AE' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E"); }
}
:root[data-theme="dark"] { --chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M2.5 4.5 6 8l3.5-3.5' fill='none' stroke='%23C3B6AE' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E"); }

/* Menu déroulant : flèche à 14 px du bord, centrée verticalement, même hauteur que les boutons voisins. */
select {
  -webkit-appearance: none; appearance: none; cursor: pointer;
  height: 42px; padding: 0 40px 0 14px; line-height: 40px;
  background: var(--surface) var(--chevron) no-repeat right 14px center / 12px 12px;
}

/* Champs numériques : pas de flèches du navigateur (elles chevauchaient l'unité). */
input[type="number"] { -moz-appearance: textfield; appearance: textfield; }
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }

/* Dates de la période personnalisée : même hauteur, icône calendrier espacée et discrète. */
input[type="date"] { height: 42px; padding: 0 12px; }
input[type="date"]::-webkit-calendar-picker-indicator { opacity: .55; cursor: pointer; margin-left: 8px; }
input[type="date"]::-webkit-calendar-picker-indicator:hover { opacity: 1; }

/* « D'où viennent ces chiffres ? » : chevron dessiné, qui tourne à l'ouverture. */
.sources summary { list-style: none; display: inline-flex; align-items: center; gap: 8px; }
.sources summary::-webkit-details-marker { display: none; }
.sources summary::before {
  content: ''; width: 12px; height: 12px; flex: none;
  background: var(--chevron) no-repeat center / 12px 12px; transform: rotate(-90deg); transition: transform .15s;
}
.sources[open] summary::before { transform: none; }

/* Bouton de suppression d'un coût fixe : croix dessinée, parfaitement centrée. */
.remove { display: grid; place-items: center; padding: 0; height: 42px; width: 42px; }
.remove svg { width: 14px; height: 14px; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; fill: none; }
.form-row input, .unit input { height: 42px; }
#fixed .form-row { grid-template-columns: minmax(0, 1fr) 170px 42px; }

/* Unité plus longue (€ / mois) : on lui laisse plus de place pour que le chiffre ne la touche pas. */
.unit.wide input { padding-right: 84px; }
.unit input { padding-right: 58px; }

/* Mémoire des recettes */
.memory { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.memory div { background: var(--surface-2); border-radius: 14px; padding: 16px 18px; }
.memory dt { color: var(--text-2); font-size: 13.5px; }
.memory dd { margin: 4px 0 0; font-size: 28px; font-weight: 800; letter-spacing: -0.6px; font-variant-numeric: tabular-nums; }
.memory small { display: block; color: var(--text-3); font-size: 12.5px; margin-top: 2px; }
.pill.mem { background: color-mix(in srgb, var(--series-2) 14%, transparent); color: var(--series-2); }
@media (max-width: 560px) { .memory { grid-template-columns: 1fr; } }

/* Limites d'import */
#limits .form-row { grid-template-columns: minmax(0, 1fr) 190px; }
#limits .form-row label:first-child b { display: block; font-weight: 650; }
#limits .form-row label:first-child span { display: block; color: var(--text-3); font-size: 13px; }
.blocked { margin: 16px 0 0; color: var(--text-2); font-size: 13.5px; }
@media (max-width: 560px) { #limits .form-row { grid-template-columns: 1fr; } }
