:root {
  --font-mono: ui-monospace, 'SF Mono', 'Cascadia Code', 'Roboto Mono', 'JetBrains Mono', Consolas, Menlo, monospace;
  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
}

/* ── Thème A · Command center (sombre froid, historique) ── */
body.theme-a {
  --bg: #0a0e14; --bg-elev: #131922; --bg-elev-2: #1a2230; --bg-deep: #060910;
  --border: #1f2937; --border-strong: #30363d;
  --text: #e6edf3; --text-dim: #8b949e; --text-muted: #6e7681;
  --accent: #56d4dd; --accent-dim: #1f6e7a; --accent-bg: rgba(86, 212, 221, 0.08);
  --success: #3fb950; --success-dim: #1f5c2a; --warning: #d29922;
  --danger: #f85149; --danger-dim: #6e1f1f;
  --chart-1: #56d4dd; --chart-2: #f85149; --chart-3: #3fb950; --chart-4: #d29922;
  --radius: 2px; --shadow: none;
  --font-display: var(--font-mono);
  --glow-1: rgba(86, 212, 221, 0.05); --glow-2: rgba(86, 212, 221, 0.03);
}

/* ── Thème B · Ambre (sombre réchauffé, défaut) ── */
body.theme-b {
  --bg: #16151a; --bg-elev: #1e1d24; --bg-elev-2: #28262f; --bg-deep: #111014;
  --border: #2c2a34; --border-strong: #3a3742;
  --text: #ece8e0; --text-dim: #a59f93; --text-muted: #7d7869;
  --accent: #e0a94e; --accent-dim: #8a6526; --accent-bg: rgba(224, 169, 78, 0.09);
  --success: #4cc38a; --success-dim: #2a6b4d; --warning: #d9a13c;
  --danger: #e8706b; --danger-dim: #7a3a37;
  --chart-1: #6fd3d9; --chart-2: #e8706b; --chart-3: #4cc38a; --chart-4: #e0a94e;
  --radius: 3px; --shadow: none;
  --font-display: var(--font-mono);
  --glow-1: rgba(224, 169, 78, 0.06); --glow-2: rgba(111, 211, 217, 0.04);
}

/* ── Thème C · Éditorial (clair crème, défaut clair) ── */
body.theme-c {
  --bg: #f5f2ea; --bg-elev: #fdfbf5; --bg-elev-2: #ece8db; --bg-deep: #faf7ef;
  --border: #e0dac9; --border-strong: #c9c2ad;
  --text: #22262e; --text-dim: #5d6068; --text-muted: #8a8c92;
  --accent: #19655c; --accent-dim: #6ea49d; --accent-bg: rgba(25, 101, 92, 0.07);
  --success: #2e7d4f; --success-dim: #9cc3aa; --warning: #9a6d1d;
  --danger: #b3432f; --danger-dim: #d8a79c;
  --chart-1: #19655c; --chart-2: #b3432f; --chart-3: #2e7d4f; --chart-4: #9a6d1d;
  --radius: 3px; --shadow: 0 1px 2px rgba(60, 50, 20, 0.05);
  --font-display: Georgia, 'Iowan Old Style', 'Times New Roman', serif;
  --glow-1: rgba(25, 101, 92, 0.04); --glow-2: rgba(154, 109, 29, 0.04);
}

/* ── Thème D · Fintech (clair moderne, optionnel) ── */
body.theme-d {
  --bg: #f4f5f8; --bg-elev: #ffffff; --bg-elev-2: #eef0f5; --bg-deep: #fafbfd;
  --border: #e5e8ef; --border-strong: #cfd4e0;
  --text: #171a21; --text-dim: #5b6271; --text-muted: #8d93a3;
  --accent: #4f56d6; --accent-dim: #9aa0ea; --accent-bg: rgba(79, 86, 214, 0.07);
  --success: #18a05c; --success-dim: #9ed4b8; --warning: #c98a14;
  --danger: #dc4040; --danger-dim: #efb1b1;
  --chart-1: #4f56d6; --chart-2: #dc4040; --chart-3: #18a05c; --chart-4: #c98a14;
  --radius: 10px; --shadow: 0 1px 3px rgba(16, 24, 40, 0.06), 0 4px 14px rgba(16, 24, 40, 0.05);
  --font-display: var(--font-sans);
  --glow-1: rgba(79, 86, 214, 0.04); --glow-2: rgba(24, 160, 92, 0.03);
}

/* Ajustements par thème */
body.theme-c .view-title::before, body.theme-d .view-title::before { content: ''; }
body.theme-d .btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
body.theme-d .btn.primary:hover { opacity: 0.88; color: #fff; }
body.theme-d .kpi-grid { gap: 12px; background: transparent; border: none; }
body.theme-d .kpi { border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }

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

html, body { height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
  background-image:
    radial-gradient(circle at 15% 5%, var(--glow-1) 0%, transparent 45%),
    radial-gradient(circle at 85% 95%, var(--glow-2) 0%, transparent 45%),
    linear-gradient(to bottom, transparent 0%, rgba(0,0,0,0.2) 100%);
  -webkit-font-smoothing: antialiased;
}

/* ============= HEADER ============= */
.app-header {
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 14px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 24px;
  flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: 14px; }

.brand-mark {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.2em;
  color: var(--accent);
  padding: 4px 8px;
  border: 1px solid var(--accent-dim);
  border-radius: var(--radius);
  font-weight: 500;
}

.brand-info { display: flex; flex-direction: column; gap: 2px; }
.brand-name {
  font-family: var(--font-display);
  font-size: 13px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text);
  font-weight: 500;
}
.brand-sub { font-size: 11px; color: var(--text-muted); letter-spacing: 0.04em; }

.tabs { display: flex; gap: 2px; flex-wrap: wrap; }

.tab {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-dim);
  background: transparent;
  border: 1px solid transparent;
  padding: 8px 14px;
  cursor: pointer;
  border-radius: var(--radius);
  transition: all 0.15s;
  font-weight: 500;
}
.tab:hover { color: var(--text); background: var(--bg-elev); }
.tab.active {
  color: var(--accent);
  border-color: var(--accent-dim);
  background: var(--accent-bg);
}

/* ============= MAIN ============= */
main {
  max-width: 1400px;
  margin: 0 auto;
  padding: 28px 24px 60px;
}

.view { display: none; animation: fadeIn 0.2s ease-out; }
.view.active { display: block; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.view-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 24px;
  gap: 16px;
  flex-wrap: wrap;
}

.view-title {
  font-family: var(--font-display);
  font-size: 12px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--text);
  font-weight: 500;
}

.view-title::before {
  content: '▸ ';
  color: var(--accent);
}

.view-sub {
  font-size: 12px;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

/* ============= KPI GRID ============= */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1px;
  background: var(--border);
  border: 1px solid var(--border);
  margin-bottom: 28px;
}

.kpi {
  background: var(--bg-elev);
  padding: 18px 20px;
  position: relative;
  overflow: hidden;
}

.kpi::before {
  content: '';
  position: absolute;
  top: 0; left: 0;
  width: 2px; height: 100%;
  background: var(--accent-dim);
  opacity: 0;
  transition: opacity 0.2s;
}

.kpi:hover::before { opacity: 1; }

.kpi-label {
  font-family: var(--font-mono);
  font-size: 9.5px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.kpi-value {
  font-family: var(--font-mono);
  font-size: 22px;
  font-weight: 500;
  color: var(--text);
  letter-spacing: -0.01em;
  line-height: 1.1;
}

.kpi-value.positive { color: var(--success); }
.kpi-value.negative { color: var(--danger); }
.kpi-value.accent { color: var(--accent); }

.kpi-sub {
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 8px;
  font-family: var(--font-mono);
}

.kpi-sub.positive { color: var(--success); }
.kpi-sub.negative { color: var(--danger); }

/* ============= SECTIONS ============= */
section {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  margin-bottom: 24px;
  border-radius: var(--radius);
}

.section-header {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.section-title {
  font-family: var(--font-display);
  font-size: 11px;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--text);
  font-weight: 500;
}

.section-meta {
  font-size: 11px;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

.section-body { padding: 20px; }
.section-body.flush { padding: 0; }

/* ============= BUTTONS ============= */
.btn {
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  padding: 8px 14px;
  background: var(--bg-elev-2);
  border: 1px solid var(--border-strong);
  color: var(--text);
  cursor: pointer;
  border-radius: var(--radius);
  transition: all 0.15s;
  font-weight: 500;
  white-space: nowrap;
}
.btn:hover { border-color: var(--accent-dim); color: var(--accent); }
.btn.primary { background: var(--accent-bg); border-color: var(--accent-dim); color: var(--accent); }
.btn.primary:hover { background: color-mix(in srgb, var(--accent) 16%, transparent); }
.btn.danger { color: var(--danger); }
.btn.danger:hover { border-color: var(--danger); background: rgba(248, 81, 73, 0.06); }
.btn.small { padding: 5px 10px; font-size: 9.5px; }
.btn.ghost { background: transparent; border-color: transparent; padding: 5px 8px; }
.btn.ghost:hover { background: var(--bg-elev-2); border-color: var(--border-strong); }

.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

/* ============= FORMS ============= */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
}

.field { display: flex; flex-direction: column; gap: 6px; }

.field label {
  font-family: var(--font-mono);
  font-size: 9.5px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-muted);
  font-weight: 500;
}

.field input, .field select, .field textarea {
  background: var(--bg);
  border: 1px solid var(--border-strong);
  color: var(--text);
  padding: 10px 12px;
  font-family: var(--font-mono);
  font-size: 13px;
  border-radius: var(--radius);
  transition: border 0.15s;
  width: 100%;
}

.field input:focus, .field select:focus, .field textarea:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--bg-deep);
}

.field-hint {
  font-size: 10px;
  color: var(--text-muted);
  font-family: var(--font-mono);
  margin-top: 2px;
}

.help-box {
  background: var(--accent-bg);
  border-left: 2px solid var(--accent-dim);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin: 0 0 16px;
  font-size: 12px;
  line-height: 1.55;
  color: var(--text-dim);
}
.help-box strong { color: var(--text); font-weight: 500; }
.help-box .help-title {
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-size: 10px;
  color: var(--accent);
  display: block;
  margin-bottom: 6px;
}
.help-box ul { margin: 6px 0 0; padding-left: 18px; }
.help-box li { margin: 3px 0; }

details.help-box > summary {
  cursor: pointer;
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-size: 10px;
  color: var(--accent);
  user-select: none;
}
details.help-box > summary:hover { color: var(--text); }
details.help-box[open] > summary { margin-bottom: 8px; }

/* ============= BANDEAU SAUVEGARDE ============= */
.banner {
  background: color-mix(in srgb, var(--warning) 9%, var(--bg));
  border-bottom: 1px solid color-mix(in srgb, var(--warning) 35%, transparent);
  padding: 9px 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--text-dim);
  flex-wrap: wrap;
}
.banner strong { color: var(--warning); font-weight: 500; letter-spacing: 0.08em; }
.banner .btn { padding: 4px 10px; font-size: 9.5px; }
.banner-close {
  background: none; border: none; cursor: pointer;
  color: var(--text-muted); font-size: 14px; padding: 2px 6px;
}
.banner-close:hover { color: var(--text); }

/* ============= SECTIONS REPLIABLES ============= */
section.collapsible > .section-header { cursor: pointer; user-select: none; }
section.collapsible > .section-header::after {
  content: '▾';
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
  margin-left: 8px;
}
section.collapsible.collapsed > .section-header::after { content: '▸'; }
section.collapsible.collapsed > *:not(.section-header) { display: none; }
section.collapsible > .section-header:hover .section-title { color: var(--accent); }

/* ============= TOOLTIP GRAPHIQUE ============= */
.chart-wrap { position: relative; }
.chart-tooltip {
  position: absolute;
  display: none;
  background: var(--bg-elev-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 8px 11px;
  font-family: var(--font-mono);
  font-size: 11px;
  line-height: 1.6;
  color: var(--text);
  pointer-events: none;
  z-index: 60;
  white-space: nowrap;
}
.chart-tooltip .tt-date { color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.1em; font-size: 9.5px; margin-bottom: 3px; }
.chart-tooltip .tt-row { display: flex; justify-content: space-between; gap: 16px; }
.chart-tooltip .tt-row .sw { display:inline-block; width:8px; height:2px; margin-right:6px; vertical-align:middle; }

.field-suffix {
  position: relative;
}
.field-suffix::after {
  content: attr(data-suffix);
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
  pointer-events: none;
}
.field-suffix input { padding-right: 36px; }

/* ============= TABLES ============= */
.table-wrap { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--font-mono);
  font-size: 12px;
}

th {
  text-align: left;
  padding: 12px 16px;
  font-family: var(--font-mono);
  font-size: 9.5px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  font-weight: 500;
  white-space: nowrap;
}

td {
  padding: 11px 16px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  vertical-align: middle;
}

tbody tr { transition: background 0.1s; }
tbody tr:hover td { background: color-mix(in srgb, var(--accent) 4%, transparent); }
tbody tr:last-child td { border-bottom: none; }

.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.num.positive { color: var(--success); }
.num.negative { color: var(--danger); }
.num.accent { color: var(--accent); }
.dim { color: var(--text-dim); }

td .badge {
  font-size: 9.5px;
  letter-spacing: 0.1em;
  padding: 2px 6px;
  border-radius: var(--radius);
  background: var(--bg-elev-2);
  color: var(--text-dim);
  text-transform: uppercase;
}
td .badge.success { background: color-mix(in srgb, var(--success) 12%, transparent); color: var(--success); }
td .badge.warning { background: color-mix(in srgb, var(--warning) 12%, transparent); color: var(--warning); }

/* ============= CHART ============= */
.chart-wrap {
  background: var(--bg-deep);
  padding: 24px;
  border-top: 1px solid var(--border);
}

.chart-legend {
  display: flex;
  gap: 20px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-dim);
}

.legend-swatch { width: 14px; height: 2px; }
.legend-swatch.dashed { background-image: linear-gradient(to right, currentColor 50%, transparent 50%); background-size: 4px 100%; height: 2px; }

svg.chart { display: block; width: 100%; height: auto; max-height: 380px; }
svg.chart text { font-family: var(--font-mono); fill: var(--text-muted); font-size: 10px; }
svg.chart .axis-line { stroke: var(--border-strong); stroke-width: 1; }
svg.chart .grid-line { stroke: var(--border); stroke-width: 1; stroke-dasharray: 2 4; }
svg.chart .today-line { stroke: var(--text-dim); stroke-width: 1; stroke-dasharray: 3 3; }
svg.chart .today-label { fill: var(--text-dim); font-size: 9.5px; letter-spacing: 0.1em; text-transform: uppercase; }

/* ============= TOAST ============= */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--bg-elev-2);
  border: 1px solid var(--accent-dim);
  color: var(--text);
  padding: 12px 18px;
  font-family: var(--font-mono);
  font-size: 12px;
  border-radius: var(--radius);
  opacity: 0;
  transform: translateY(20px);
  transition: all 0.25s;
  pointer-events: none;
  z-index: 1000;
  max-width: 360px;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.danger { border-color: var(--danger); }
.toast.success { border-color: var(--success); }

/* ============= EMPTY STATE ============= */
.empty {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-muted);
  font-size: 13px;
  font-family: var(--font-mono);
}
.empty::before {
  content: '▢';
  display: block;
  font-size: 32px;
  margin-bottom: 12px;
  color: var(--border-strong);
}

/* ============= MODAL ============= */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(6, 9, 16, 0.7);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 20px;
}
.modal-backdrop.show { display: flex; animation: fadeIn 0.15s; }

.modal {
  background: var(--bg-elev);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  max-width: 560px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-title {
  font-family: var(--font-display);
  font-size: 11px;
  letter-spacing: 0.15em;
  text-transform: uppercase;
}

.modal-body { padding: 20px; }

.modal-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* ============= MISC ============= */
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.row.right { justify-content: flex-end; }
.spacer { flex: 1; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mb-16 { margin-bottom: 16px; }
.text-dim { color: var(--text-dim); }
.text-muted { color: var(--text-muted); }
.text-mono { font-family: var(--font-mono); }
.text-xs { font-size: 11px; }

.divider { height: 1px; background: var(--border); margin: 16px 0; }

.scpi-card {
  border: 1px solid var(--border);
  margin-bottom: 16px;
  background: var(--bg-elev);
  border-radius: var(--radius);
}
.scpi-card-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
}
.scpi-card-title {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--accent);
  letter-spacing: 0.05em;
}
.scpi-card-meta {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-dim);
}

.action-link {
  background: none;
  border: none;
  color: var(--text-dim);
  font-family: var(--font-mono);
  font-size: 10.5px;
  cursor: pointer;
  padding: 4px 8px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  transition: color 0.15s;
}
.action-link:hover { color: var(--accent); }
.action-link.danger:hover { color: var(--danger); }

/* ============= RESPONSIVE ============= */
@media (max-width: 768px) {
  .header-inner { padding: 12px 16px; }
  .tabs { width: 100%; overflow-x: auto; padding-bottom: 4px; }
  .tab { font-size: 10px; padding: 6px 10px; }
  .kpi-value { font-size: 18px; }
  .kpi { padding: 14px 16px; }
  main { padding: 20px 12px 40px; }
  .section-body { padding: 16px; }
  th, td { padding: 10px 12px; font-size: 11px; }
}

/* ============= UTIL ============= */
.checkbox-inline {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-dim);
}
.checkbox-inline input { width: auto; }

/* ── v3 · écran de session ── */
.login-screen {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 500;
  padding: 20px;
}
.login-screen.show { display: flex; }
.login-card {
  background: var(--bg-elev);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 28px;
  width: 100%;
  max-width: 380px;
}
