:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #dfe3e8;
  --text: #1c2430;
  --muted: #637083;
  --accent: #2563eb;
  --accent-soft: #e3ecfd;
  --accent-text: #ffffff;
  --history: #334155;
  --fitted: #94a3b8;
  --forecast: #2563eb;
  --statistical: #f59e0b;
  --cleaned: #0d9488;
  --band: rgba(37, 99, 235, 0.13);
  --good: #15803d;
  --warn: #b45309;
  --bad: #b91c1c;
  --override: #fff4d6;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f141b; --surface: #171d26; --surface-2: #1e2632; --border: #2b3543; --text: #e4e9f0; --muted: #8f9bad;
    --accent: #5b8cff; --accent-soft: #1f2d4d; --history: #cbd5e1; --fitted: #64748b; --forecast: #6d9bff;
    --statistical: #fbbf24; --cleaned: #2dd4bf; --band: rgba(109, 155, 255, 0.16); --good: #4ade80; --warn: #fbbf24; --bad: #f87171;
    --override: #3b3015; --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f141b; --surface: #171d26; --surface-2: #1e2632; --border: #2b3543; --text: #e4e9f0; --muted: #8f9bad;
  --accent: #5b8cff; --accent-soft: #1f2d4d; --history: #cbd5e1; --fitted: #64748b; --forecast: #6d9bff;
  --statistical: #fbbf24; --cleaned: #2dd4bf; --band: rgba(109, 155, 255, 0.16); --good: #4ade80; --warn: #fbbf24; --bad: #f87171;
  --override: #3b3015; --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex; flex-direction: column;
}
button, input, select { font: inherit; color: inherit; }
code, pre { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: 12.5px; }
[hidden] { display: none !important; }

.topbar {
  display: flex; align-items: center; gap: 12px; padding: 10px 16px; flex-wrap: wrap;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 17px; letter-spacing: -.01em; color: inherit; text-decoration: none; }
.brand svg { width: 26px; height: 26px; }
.brand svg rect { fill: var(--accent); }
.brand svg path { stroke: #fff; stroke-width: 3; fill: none; stroke-linecap: round; stroke-linejoin: round; }
#project-select { min-width: 220px; max-width: 320px; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; flex: 1; }
#btn-new { margin-inline-start: auto; }

.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 7px;
  border: 1px solid var(--border); background: var(--surface); cursor: pointer; text-decoration: none;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { border-color: transparent; }
.btn.small { padding: 3px 8px; font-size: 12.5px; }
select, input[type="number"], input[type="text"], input[type="search"], input[type="email"], input[type="password"], input:not([type]) {
  padding: 6px 8px; border: 1px solid var(--border); border-radius: 7px; background: var(--surface);
}


.workspace { flex: 1; display: grid; grid-template-columns: 290px 1fr; min-height: 0; }
.sidebar {
  background: var(--surface); border-inline-end: 1px solid var(--border); display: flex; flex-direction: column;
  min-height: 0; padding: 12px; gap: 10px;
}
.tree { flex: 1; overflow: auto; font-size: 13.5px; }
.tree ul { list-style: none; margin: 0; padding-inline-start: 14px; }
.tree > ul { padding-inline-start: 0; }
.tree-row {
  display: flex; align-items: center; gap: 4px; padding: 3px 6px; border-radius: 6px; cursor: pointer;
  white-space: nowrap;
}
.tree-row:hover { background: var(--surface-2); }
.tree-row.selected { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.tree-toggle { width: 16px; text-align: center; color: var(--muted); flex: none; font-size: 10px; }
.tree-name { overflow: hidden; text-overflow: ellipsis; flex: 1; }
.tree-badge { font-size: 10.5px; color: var(--muted); border: 1px solid var(--border); border-radius: 4px; padding: 0 4px; }
.tree-row.selected .tree-badge { color: var(--accent); border-color: currentColor; }
.sidebar-foot { font-size: 12px; color: var(--muted); border-top: 1px solid var(--border); padding-top: 8px; }

.content { overflow: auto; padding: 16px 20px 32px; display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.node-header { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; }
.breadcrumb { font-size: 12.5px; color: var(--muted); }
.breadcrumb a { color: inherit; text-decoration: none; cursor: pointer; }
.breadcrumb a:hover { color: var(--accent); }
.node-header h2 { margin: 2px 0 6px; font-size: 21px; letter-spacing: -.01em; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { font-size: 12px; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.chip.accent { background: var(--accent-soft); color: var(--accent); }
.chip.warn { background: var(--override); color: var(--warn); }
.model-picker { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); }
.model-picker select { min-width: 280px; color: var(--text); }

.chart-card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; box-shadow: var(--shadow); }
.chart-legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 12.5px; color: var(--muted); margin-bottom: 6px; }
.chart-legend span { display: inline-flex; align-items: center; gap: 6px; }
.chart-legend i { width: 18px; height: 3px; border-radius: 2px; display: inline-block; }
.chart-legend i.band { height: 10px; background: var(--band); }
.chart-legend i.dashed { background: repeating-linear-gradient(90deg, var(--fitted) 0 4px, transparent 4px 7px); }
.chart-box { position: relative; height: 340px; }

.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); overflow-x: auto; }
.tabs button {
  border: none; background: none; padding: 8px 14px; cursor: pointer; color: var(--muted);
  border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap;
}
.tabs button.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.tab-panel { display: flex; flex-direction: column; gap: 14px; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; box-shadow: var(--shadow); }
.card h4 { margin: 0 0 10px; font-size: 14px; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 14px; }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.toolbar input { width: 80px; }
.toolbar input[type="checkbox"] { width: auto; margin: 0; }
.hint { color: var(--muted); font-size: 12.5px; margin: 0; }

.table-scroll { overflow-x: auto; }
table.grid { border-collapse: collapse; width: 100%; font-size: 13px; font-variant-numeric: tabular-nums; }
table.grid th, table.grid td { padding: 6px 8px; border-bottom: 1px solid var(--border); text-align: end; white-space: nowrap; }
table.grid th:first-child, table.grid td:first-child { text-align: start; position: sticky; inset-inline-start: 0; background: var(--surface); }
table.grid thead th { color: var(--muted); font-weight: 600; font-size: 12px; }
table.grid tr.strong td { font-weight: 650; }
table.grid tr.muted td { color: var(--muted); }
table.grid td.text, table.grid th.text { text-align: start; }
table.grid tbody tr.clickable { cursor: pointer; }
table.grid tbody tr.clickable:hover td { background: var(--surface-2); }
table.grid tr.selected-row td { background: var(--accent-soft); }
.override-input {
  width: 84px; text-align: end; padding: 3px 6px; border: 1px solid var(--border); border-radius: 5px;
  background: var(--surface); font-variant-numeric: tabular-nums;
}
.override-input.set { background: var(--override); border-color: var(--warn); font-weight: 600; }
.notes { margin: 0; padding-inline-start: 18px; }
.notes li { margin: 4px 0; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 16px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; text-align: end; font-variant-numeric: tabular-nums; }
.good { color: var(--good); }
.warn-text { color: var(--warn); }
.bad { color: var(--bad); }
.bar-cell { display: flex; align-items: center; gap: 8px; justify-content: flex-end; }
.bar { height: 8px; background: var(--accent); border-radius: 4px; opacity: .75; }
.empty { color: var(--muted); padding: 24px; text-align: center; }

dialog { border: none; border-radius: 14px; padding: 0; background: var(--surface); color: var(--text); box-shadow: 0 20px 50px rgba(0,0,0,.25); max-width: calc(100vw - 32px); max-height: calc(100dvh - 32px); overflow-y: auto; }
dialog::backdrop { background: rgba(15, 20, 27, .45); }
.dialog { padding: 20px 22px; display: flex; flex-direction: column; gap: 12px; width: 440px; max-width: 100%; }
.dialog.wide { width: 720px; }
.dialog h3 { margin: 0; }
.dialog label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.dialog label > input, .dialog label > select { color: var(--text); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }
.events-table input, .events-table select { width: 100%; }
.drivers-table select { max-width: 220px; }
.tab-badge {
  display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px;
  background: var(--override); color: var(--warn); font-size: 11.5px; font-weight: 700;
}
.tab-badge.high { background: var(--bad); color: #fff; }
.alert-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 12px; }
.alert-card { display: flex; flex-direction: column; gap: 10px; }
.alert-card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.alert-card-head strong { font-size: 15px; }
.alert-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; font-size: 13.5px; }
.alert-list li { display: flex; gap: 8px; align-items: baseline; }
.sev-dot { flex: none; width: 9px; height: 9px; border-radius: 50%; background: var(--muted); transform: translateY(1px); }
.sev-high .sev-dot { background: var(--bad); }
.sev-medium .sev-dot { background: var(--warn); }
.sev-low .sev-dot { background: var(--fitted); }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); cursor: pointer; }
.field-group { border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px 12px; margin: 4px 0 0; display: flex; flex-direction: column; gap: 10px; }
.field-group legend { padding: 0 6px; font-size: 13px; font-weight: 600; color: var(--text); }
.dialog-actions.spread { justify-content: space-between; flex-wrap: wrap; }
.dialog-actions-end { display: flex; gap: 8px; margin-inline-start: auto; }

.busy {
  position: fixed; inset: 0; background: rgba(15, 20, 27, .35); display: flex; align-items: center;
  justify-content: center; gap: 12px; color: #fff; font-weight: 600; z-index: 50;
}
.spinner { width: 28px; height: 28px; border: 3px solid rgba(255,255,255,.35); border-top-color: #fff; border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.toasts { position: fixed; bottom: 16px; inset-inline-end: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 60; }
.toast { background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 8px; max-width: 380px; box-shadow: var(--shadow); }
.toast.error { background: var(--bad); color: #fff; }

/* ------------------------------------------------------------ page d'accueil */
.landing { flex: 1; overflow-y: auto; scroll-behavior: smooth; background: var(--bg); }
.lp-container { max-width: 1140px; margin: 0 auto; padding: 0 24px; }

.lp-nav {
  position: sticky; top: 0; z-index: 10; background: color-mix(in srgb, var(--surface) 86%, transparent);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--border);
}
.lp-nav-inner { display: flex; align-items: center; gap: 20px; height: 60px; }
.lp-links { display: flex; gap: 4px; margin-inline-start: auto; }
.lp-link {
  background: none; border: none; padding: 6px 12px; border-radius: 7px; color: var(--muted); cursor: pointer;
}
.lp-link:hover { color: var(--text); background: var(--surface-2); }

.lp-hero {
  padding: 72px 0 64px;
  background:
    radial-gradient(900px 420px at 85% 10%, var(--accent-soft), transparent 70%),
    radial-gradient(600px 300px at 0% 100%, color-mix(in srgb, var(--statistical) 10%, transparent), transparent 70%);
}
.lp-hero-grid { display: grid; grid-template-columns: 1.05fr 1fr; gap: 56px; align-items: center; }
.lp-eyebrow {
  margin: 0 0 14px; color: var(--accent); font-weight: 650; font-size: 13px; letter-spacing: .08em; text-transform: uppercase;
}
.lp-hero h1 {
  margin: 0; font-size: clamp(32px, 4.4vw, 50px); line-height: 1.08; letter-spacing: -.03em; text-wrap: balance;
}
.lp-lead { margin: 20px 0 0; font-size: 17.5px; line-height: 1.6; color: var(--muted); max-width: 560px; }
.lp-cta { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 30px; }
.btn.lg { padding: 11px 20px; font-size: 15px; border-radius: 9px; font-weight: 600; }
.lp-note { margin: 16px 0 0; color: var(--muted); font-size: 13px; }

.lp-visual { position: relative; margin: 0; padding: 0 8px 36px; }
.lp-visual-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px; overflow: hidden;
  box-shadow: 0 24px 60px -20px rgba(16, 24, 40, .28), var(--shadow);
}
.lp-visual-head { display: flex; align-items: center; gap: 6px; padding: 10px 14px; border-bottom: 1px solid var(--border); background: var(--surface-2); }
.lp-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--border); }
.lp-visual-title { margin-inline-start: 10px; font-size: 12.5px; color: var(--muted); }
#hero-chart { display: block; width: 100%; height: 280px; }
.lp-float {
  position: absolute; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 10px 14px;
  box-shadow: 0 12px 30px -12px rgba(16, 24, 40, .3); display: flex; flex-direction: column; gap: 1px; font-size: 13px;
}
.lp-float strong { font-size: 15px; }
.lp-float-label { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.lp-float-sub { color: var(--muted); font-size: 12px; }
.lp-float-a { top: 40%; inset-inline-start: -34px; }
.lp-float-b { bottom: 0; inset-inline-end: -10px; }
.lp-good { color: var(--good); }

.lp-stats { border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); background: var(--surface); }
.lp-stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); }
.lp-stats-grid div { padding: 26px 16px; display: flex; flex-direction: column; gap: 2px; text-align: center; }
.lp-stats-grid div + div { border-inline-start: 1px solid var(--border); }
.lp-stats-grid strong { font-size: 30px; letter-spacing: -.02em; color: var(--accent); }
.lp-stats-grid span { color: var(--muted); font-size: 13.5px; }

.lp-section { padding: 80px 0; }
.lp-alt { background: var(--surface); border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); }
.lp-section-head { text-align: center; max-width: 680px; margin: 0 auto 40px; }
.lp-section-head.left { text-align: start; margin: 0 0 24px; }
.lp-section-head h2 { margin: 0; font-size: clamp(25px, 3vw, 34px); letter-spacing: -.02em; line-height: 1.15; text-wrap: balance; }
.lp-section-head p { margin: 12px 0 0; color: var(--muted); font-size: 16px; line-height: 1.6; }

.lp-features { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; }
.lp-feature {
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 24px;
  transition: transform .15s, box-shadow .15s;
}
.lp-feature:hover { transform: translateY(-2px); box-shadow: 0 14px 30px -18px rgba(16, 24, 40, .35); }
.lp-feature h3 { margin: 16px 0 8px; font-size: 16.5px; }
.lp-feature p { margin: 0; color: var(--muted); line-height: 1.6; }
.lp-icon {
  width: 42px; height: 42px; border-radius: 11px; background: var(--accent-soft); display: grid; place-items: center;
}
.lp-icon svg { width: 22px; height: 22px; fill: none; stroke: var(--accent); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.lp-methods { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 32px; }
.lp-methods span {
  padding: 5px 12px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface);
  color: var(--muted); font-size: 13px;
}

.lp-steps { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(3, 1fr); gap: 28px; counter-reset: none; }
.lp-steps li { position: relative; padding-top: 4px; }
.lp-step-num {
  display: grid; place-items: center; width: 36px; height: 36px; border-radius: 50%; background: var(--accent);
  color: var(--accent-text); font-weight: 700;
}
.lp-steps h3 { margin: 16px 0 8px; font-size: 17px; }
.lp-steps p { margin: 0; color: var(--muted); line-height: 1.6; }

.lp-data-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 56px; align-items: center; }
.lp-checks { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.lp-checks li { position: relative; padding-inline-start: 30px; line-height: 1.55; }
.lp-checks li::before {
  content: "✓"; position: absolute; inset-inline-start: 0; top: 1px; width: 20px; height: 20px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-size: 12px; font-weight: 700;
}
.lp-table-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px; overflow: hidden;
  box-shadow: 0 20px 50px -24px rgba(16, 24, 40, .3); font-variant-numeric: tabular-nums;
}
.lp-table-card table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.lp-table-card th { background: #1d6f42; color: #fff; font-weight: 600; text-align: start; padding: 9px 12px; }
.lp-table-card td { padding: 9px 12px; border-top: 1px solid var(--border); }
.lp-table-card td:nth-child(n+3), .lp-table-card th:nth-child(n+3) { text-align: end; }


.lp-start { padding-top: 40px; }
.lp-start-card {
  max-width: 760px; margin: 0 auto; background: var(--surface); border: 1px solid var(--border); border-radius: 18px;
  padding: 40px; box-shadow: 0 24px 60px -30px rgba(16, 24, 40, .3); display: flex; flex-direction: column; gap: 18px;
}
.lp-start-card .lp-section-head { margin-bottom: 8px; }
.lp-start-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.dropzone {
  border: 2px dashed var(--border); border-radius: 14px; padding: 32px; display: flex; flex-direction: column;
  align-items: center; gap: 12px; color: var(--muted); transition: .15s;
}
.dropzone svg { width: 34px; height: 34px; fill: none; stroke: var(--accent); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.dropzone strong { color: var(--text); }
.dropzone.over { border-color: var(--accent); background: var(--accent-soft); }
.format-help summary { cursor: pointer; color: var(--accent); }
.format-help pre { background: var(--surface-2); padding: 10px; border-radius: 8px; overflow-x: auto; }
.format-help li { margin: 4px 0; }

.lp-footer { border-top: 1px solid var(--border); padding: 28px 0; color: var(--muted); font-size: 13px; }
.lp-footer-inner { display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap; }
.brand.small { font-size: 14px; color: var(--text); }
.brand.small svg { width: 20px; height: 20px; }

@media (max-width: 960px) {
  .lp-hero { padding: 44px 0 40px; }
  .lp-hero-grid, .lp-data-grid { grid-template-columns: 1fr; gap: 36px; }
  .lp-features { grid-template-columns: 1fr 1fr; }
  .lp-steps { grid-template-columns: 1fr; gap: 24px; }
  .lp-float-a { inset-inline-start: -6px; }
  .lp-float-b { inset-inline-end: 0; }
}
@media (max-width: 640px) {
  .lp-container { padding: 0 16px; }
  .lp-links { display: none; }
  .lp-nav-inner { gap: 10px; }
  .lp-nav-inner .btn { padding: 6px 10px; }
  .lp-nav-inner .lang-switch svg, .auth-top .lang-switch svg { display: none; }
  .lang-switch { margin-inline-start: auto; }
  .lp-features { grid-template-columns: 1fr; }
  .lp-stats-grid { grid-template-columns: 1fr 1fr; }
  .lp-stats-grid div:nth-child(3) { border-inline-start: none; }
  .lp-stats-grid div:nth-child(n+3) { border-top: 1px solid var(--border); }
  .lp-section { padding: 56px 0; }
  .lp-start-card { padding: 24px 18px; }
  .lp-float { position: static; margin-top: 10px; }
  .lp-visual { padding: 0; }
  #hero-chart { height: 220px; }
  .btn.lg { width: 100%; justify-content: center; white-space: normal; }
}

/* ------------------------------------------------------------ nettoyage de l'historique */
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px 16px; flex-wrap: wrap; margin-bottom: 10px; }
.card-head h4 { margin: 0; }
.link-btn { border: none; background: none; color: var(--accent); cursor: pointer; padding: 0 4px; font: inherit; }
.link-btn:hover { text-decoration: underline; }
.chip-link { border: none; cursor: pointer; font: inherit; font-size: 12px; }
.chip-link:hover { filter: brightness(0.96); text-decoration: underline; }
table.grid td.changed { color: var(--cleaned); font-weight: 650; }
.actions-cell { display: flex; gap: 6px; flex-wrap: wrap; }
.chart-legend i.dot { width: 9px; height: 9px; border-radius: 50%; }
.table-scroll.spaced { margin-top: 10px; }

/* ------------------------------------------------------------ commandes mobiles */
.icon-btn {
  flex: none; width: 36px; height: 36px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface);
  display: grid; place-items: center; cursor: pointer; color: var(--text); padding: 0;
}
.icon-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
.icon-btn circle { fill: currentColor; stroke: none; }
.mobile-only { display: none; }
.drawer-backdrop { display: none; }

/* Tablette et smartphone */
@media (max-width: 860px) {
  .mobile-only { display: grid; }
  .topbar { flex-wrap: nowrap; gap: 8px; padding: 8px 12px; position: relative; }
  .topbar .brand span { display: none; }
  #project-select { min-width: 0; flex: 1; max-width: none; }
  #btn-new { display: none; }
  .actions {
    display: none; position: absolute; top: calc(100% + 4px); inset-inline-end: 12px; z-index: 40; flex-direction: column;
    align-items: stretch; gap: 4px; padding: 8px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
    box-shadow: 0 16px 40px -12px rgba(16, 24, 40, .35); min-width: 230px; flex: none;
  }
  .actions.open { display: flex; }
  .actions .btn { justify-content: flex-start; }

  .workspace { grid-template-columns: 1fr; position: relative; }
  .sidebar {
    position: fixed; top: 0; bottom: 0; inset-inline-start: 0; z-index: 45; width: min(320px, 86vw);
    border-inline-end: 1px solid var(--border); box-shadow: 0 0 40px rgba(16, 24, 40, .25);
    transform: translateX(-105%); transition: transform .2s ease; visibility: hidden;
  }
  [dir="rtl"] .sidebar { transform: translateX(105%); }
  body.drawer-open .sidebar { transform: none; visibility: visible; }
  .drawer-backdrop { display: block; position: fixed; inset: 0; z-index: 44; background: rgba(15, 20, 27, .4); }
  .drawer-backdrop[hidden] { display: none !important; }

  .content { padding: 14px 16px 28px; }
  .node-header h2 { font-size: 19px; }
  .model-picker select { min-width: 0; width: 100%; }
  .model-picker { width: 100%; }
  .chart-box { height: 260px; }
  .cards { grid-template-columns: 1fr; }
  .dialog.wide { width: 100%; }
}

/* Smartphone : les tableaux de liste deviennent des cartes empilées */
@media (max-width: 640px) {
  .alert-grid { grid-template-columns: 1fr; }
  .chart-box { height: 220px; }
  .chart-card, .card { padding: 12px; }
  .toolbar .hint { flex-basis: 100%; }
  table.grid.stack thead { display: none; }
  table.grid.stack, table.grid.stack tbody { display: block; }
  table.grid.stack tr {
    display: block; border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px; margin-bottom: 8px;
  }
  table.grid.stack td {
    display: flex; justify-content: space-between; align-items: center; gap: 12px; border: none; padding: 4px 0;
    position: static; white-space: normal; text-align: end; background: none;
  }
  table.grid.stack td::before { content: attr(data-label); color: var(--muted); font-size: 12px; text-align: start; }
  table.grid.stack td.row-title { font-weight: 650; padding-inline-start: 0 !important; }
  table.grid.stack td.row-title::before { content: none; }
  table.grid.stack td.actions-cell { justify-content: flex-end; flex-wrap: wrap; }
  table.grid.stack tr.selected-row td, table.grid.stack tr.clickable:hover td { background: none; }
  table.grid.stack tr.selected-row { border-color: var(--accent); background: var(--accent-soft); }
  .tabs button { padding: 8px 10px; }
  .dialog { padding: 16px; }
}

/* ------------------------------------------------------------ i18n, RTL et profil */
body.i18n-pending { visibility: hidden; }
.profile-btn {
  flex: none; width: 34px; height: 34px; border-radius: 50%; border: 1px solid var(--border); background: var(--surface);
  display: grid; place-items: center; cursor: pointer; color: var(--muted); padding: 0;
}
.profile-btn:hover { border-color: var(--accent); color: var(--accent); }
.profile-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
.profile-btn .avatar { font-size: 12px; font-weight: 700; color: var(--accent); }
.crumb-sep { margin: 0 6px; display: inline-block; }
.tree-toggle.closed { transform: rotate(-90deg); }
.kv-spaced { margin-top: 10px; }
.hint.spaced { margin-top: 8px; }
.meta-delete { margin-top: 6px; }
/* En écriture de droite à gauche, les flèches et chevrons pointent dans l'autre sens. */
[dir="rtl"] .crumb-sep, [dir="rtl"] .dir-arrow { transform: scaleX(-1); }
[dir="rtl"] .tree-toggle.closed { transform: rotate(90deg); }

/* Sélecteur de langue (page d'accueil) */
.lang-switch {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 8px; border-radius: 7px; color: var(--muted);
  cursor: pointer;
}
.lang-switch:hover, .lang-switch:focus-within { color: var(--text); background: var(--surface-2); }
.lang-switch svg { width: 17px; height: 17px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.6; }
.lang-switch select {
  border: none; background: transparent; padding: 2px 0; color: inherit; cursor: pointer; font-weight: 500;
}
.lang-switch select:focus { outline: none; }
.lang-switch:focus-within { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ------------------------------------------------------------ comptes et organisation */
/* Visibilité selon l'état : visiteur, connecté, lecture seule (rôle lecteur), administrateur */
.is-anon .auth-only, .is-authed .anon-only { display: none !important; }
.read-only .edit-only, body:not(.is-admin) .admin-only { display: none !important; }
.read-only .override-input:disabled { border-color: transparent; background: transparent; }
.hint.center { text-align: center; }

.auth { flex: 1; overflow-y: auto; display: flex; flex-direction: column; align-items: center; padding: 20px 16px 40px;
  background: radial-gradient(800px 380px at 80% 0%, var(--accent-soft), transparent 70%), var(--bg); }
.auth-top { width: 100%; max-width: 960px; display: flex; justify-content: space-between; align-items: center; margin-bottom: 6vh; }
.auth-card {
  width: 100%; max-width: 420px; background: var(--surface); border: 1px solid var(--border); border-radius: 16px;
  padding: 28px; box-shadow: 0 24px 60px -30px rgba(16, 24, 40, .35); display: flex; flex-direction: column; gap: 14px;
}
.auth-card h1 { margin: 0; font-size: 24px; letter-spacing: -.02em; }
.auth-card .lead { margin: 0; color: var(--muted); }
.auth-form { display: flex; flex-direction: column; gap: 12px; }
.auth-form label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.auth-form input { padding: 9px 10px; font-size: 15px; color: var(--text); }
.auth-form input[readonly] { background: var(--surface-2); }
.auth-form .btn.lg { justify-content: center; margin-top: 4px; }
.auth-error { margin: 0; padding: 8px 10px; border-radius: 8px; background: color-mix(in srgb, var(--bad) 12%, transparent); color: var(--bad); font-size: 13px; }
.auth-links { display: flex; flex-direction: column; gap: 6px; font-size: 13.5px; }
.auth-links a { color: var(--accent); text-decoration: none; }
.auth-links a:hover { text-decoration: underline; }

.menu {
  position: fixed; z-index: 70; min-width: 240px; max-width: calc(100vw - 24px); background: var(--surface);
  border: 1px solid var(--border); border-radius: 12px; padding: 6px; box-shadow: 0 16px 40px -12px rgba(16, 24, 40, .35);
  display: flex; flex-direction: column;
}
.menu[hidden] { display: none; }
.menu-head { display: flex; flex-direction: column; gap: 2px; padding: 8px 10px 10px; border-bottom: 1px solid var(--border); margin-bottom: 4px; font-size: 12.5px; color: var(--muted); }
.menu-head strong { color: var(--text); font-size: 14px; }
.menu button { text-align: start; background: none; border: none; padding: 8px 10px; border-radius: 8px; cursor: pointer; }
.menu button:hover { background: var(--surface-2); }
.is-anon .menu [data-menu="organization"], .is-anon .menu [data-menu="logout"] { display: none; }

.org-section { display: flex; flex-direction: column; gap: 10px; padding-top: 12px; border-top: 1px solid var(--border); }
.org-section:first-child { border-top: none; padding-top: 0; }
.org-section h4 { margin: 0; }
.org-section label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.invite-form { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; align-items: end; }
.invite-form select, .invite-form input { min-width: 0; width: 100%; }
.invite-form > .btn { grid-column: 1 / -1; justify-self: start; }
.copy-row { display: flex; gap: 8px; }
.copy-row input { flex: 1; min-width: 0; }
@media (max-width: 640px) {
  .invite-form { grid-template-columns: 1fr; }
  .auth-card { padding: 20px 16px; }
  .auth-top { margin-bottom: 24px; }
}

/* ------------------------------------------------------------ accueil de l'application (connecté) */
.home { flex: 1; overflow-y: auto; background: var(--bg); }
.home-inner { max-width: 1140px; margin: 0 auto; padding: 32px 24px 48px; display: flex; flex-direction: column; gap: 32px; }
.home-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px 24px; flex-wrap: wrap; }
.home-head h1 { margin: 0; font-size: clamp(24px, 3vw, 32px); letter-spacing: -.02em; }
.home-head .lp-eyebrow { margin-bottom: 6px; }
.home-lead { margin: 8px 0 0; color: var(--muted); max-width: 620px; }
.home-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.home-section-title { margin: 0 0 14px; font-size: 17px; }
.home-projects { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.home-project {
  text-align: start; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 18px 20px;
  cursor: pointer; display: flex; flex-direction: column; gap: 6px; transition: border-color .15s, transform .15s; font: inherit; color: inherit;
}
.home-project:hover { border-color: var(--accent); transform: translateY(-2px); }
.home-project strong { font-size: 16px; }
.home-project > span { color: var(--muted); font-size: 13px; }
.home-project .home-alerts {
  align-self: flex-start; margin-top: 6px; padding: 2px 10px; border-radius: 999px; font-size: 12.5px; font-weight: 600;
}
.home-alerts.high { background: color-mix(in srgb, var(--bad) 14%, transparent); color: var(--bad); }
.home-alerts.medium { background: var(--override); color: var(--warn); }
.home-alerts.none { background: color-mix(in srgb, var(--good) 12%, transparent); color: var(--good); }
.home-empty { display: flex; flex-direction: column; gap: 4px; }
.home-empty p { margin: 0; }
.home-start .dropzone .hint { margin: 0; }
@media (max-width: 640px) {
  .home-inner { padding: 20px 16px 32px; gap: 24px; }
  .home-actions { width: 100%; }
  .home-actions .btn { flex: 1; justify-content: center; }
  .home-projects { grid-template-columns: 1fr; }
}

/* Très petits écrans (moins de 380 px) : le logo seul suffit dans la barre de la vitrine */
@media (max-width: 380px) {
  .lp-nav .brand span { display: none; }
}

/* Champ mot de passe avec bouton œil, options de connexion */
.password-field { position: relative; display: flex; }
.password-field input { flex: 1; min-width: 0; padding-inline-end: 42px; }
.pw-toggle {
  position: absolute; inset-inline-end: 4px; top: 50%; transform: translateY(-50%); width: 34px; height: 30px;
  display: grid; place-items: center; border: none; background: none; border-radius: 6px; color: var(--muted); cursor: pointer; padding: 0;
}
.pw-toggle:hover { color: var(--text); background: var(--surface-2); }
.pw-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.pw-toggle svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.auth-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 13.5px; }
.auth-row a { color: var(--accent); text-decoration: none; }
.auth-row a:hover { text-decoration: underline; }
.auth-links span { color: var(--muted); }
/* Case à cocher dans les formulaires d'authentification : sur la même ligne que son libellé */
.auth-form label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--text); font-size: 13.5px; }
.auth-form input[type="checkbox"] { width: 16px; height: 16px; padding: 0; margin: 0; accent-color: var(--accent); }

/* ------------------------------------------------------------ administration de la plateforme */
body:not(.is-platform-admin) .platform-only { display: none !important; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.stat-tile { display: flex; flex-direction: column; gap: 6px; }
.stat-tile span { color: var(--muted); font-size: 13px; }
.stat-tile strong { font-size: 28px; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.platform-search { width: 100%; }
.status-pill { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 12.5px; font-weight: 600; }
.status-pill.ok { background: color-mix(in srgb, var(--good) 12%, transparent); color: var(--good); }
.status-pill.ko { background: color-mix(in srgb, var(--bad) 14%, transparent); color: var(--bad); }
#platform .tabs { margin-top: -8px; }
@media (max-width: 640px) {
  .stat-grid { grid-template-columns: 1fr 1fr; }
  .stat-tile strong { font-size: 22px; }
}

/* Page 404 */
.not-found { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  padding: 32px 16px; text-align: center; }
.not-found .brand { margin-bottom: 12px; }
.not-found-code { margin: 0; font-size: 64px; font-weight: 800; letter-spacing: -.04em; color: var(--accent); line-height: 1; }
.not-found h1 { margin: 0; font-size: 24px; }
.not-found .lead { max-width: 440px; }

/* Bandeau de vérification de l'adresse e-mail */
.banner { display: flex; gap: 10px 16px; align-items: center; justify-content: center; flex-wrap: wrap; padding: 8px 16px;
  background: var(--override); color: var(--warn); font-size: 13.5px; border-bottom: 1px solid var(--border); text-align: center; }
#app-topbar[hidden] ~ #verify-banner { display: none !important; }

/* Robustesse du mot de passe */
.pw-meter { display: flex; align-items: center; gap: 10px; margin-top: 2px; }
.pw-meter[hidden] { display: none; }
.pw-bar { flex: 0 0 120px; height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; }
.pw-bar i { display: block; height: 100%; width: 25%; background: var(--bad); transition: width .2s, background .2s; }
.pw-meter[data-level="1"] .pw-bar i { width: 50%; background: var(--warn); }
.pw-meter[data-level="2"] .pw-bar i { width: 75%; background: var(--accent); }
.pw-meter[data-level="3"] .pw-bar i { width: 100%; background: var(--good); }
.pw-meter small { color: var(--muted); font-size: 12px; }

/* Double authentification et sessions (profil) */
#two-factor-body { display: flex; flex-direction: column; gap: 10px; align-items: flex-start; }
#two-factor-body label { width: 100%; }
.qr { padding: 8px; background: #fff; border-radius: 8px; line-height: 0; }
.qr:empty { display: none; }
code.secret { font-size: 13px; padding: 2px 6px; background: var(--surface-2); border-radius: 4px; word-break: break-all; }
.recovery-codes { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px 16px; margin: 0; padding: 10px 12px;
  list-style: none; background: var(--surface-2); border-radius: 8px; font-size: 14px; }
.session-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.session-list li { display: flex; justify-content: space-between; align-items: center; gap: 12px; font-size: 13.5px; }

/* Organisations du membre (menu du compte) */
.menu-orgs { display: flex; flex-direction: column; border-bottom: 1px solid var(--border); margin-bottom: 4px; padding-bottom: 4px; }
.menu-label { padding: 6px 10px 2px; font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.menu-orgs [data-switch-org] { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.menu-orgs [data-switch-org] small { color: var(--muted); }
.menu-orgs [aria-checked="true"] { font-weight: 600; color: var(--accent); }
.menu-orgs [aria-checked="true"]::before { content: "✓"; margin-inline-end: 6px; }
.menu-orgs [aria-checked="true"] span { margin-inline-end: auto; }

/* Actions sensibles */
.btn.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 45%, var(--border)); }
.btn.danger:hover { background: color-mix(in srgb, var(--bad) 10%, transparent); }
.danger-zone { border-color: color-mix(in srgb, var(--bad) 35%, var(--border)); }
.danger-zone legend { color: var(--bad); }
.inline-form { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.inline-form label { flex: 1 1 240px; }
.activity-log { max-height: 320px; overflow-y: auto; }
.danger-section h4 { color: var(--bad); }
a.btn { text-decoration: none; display: inline-flex; align-items: center; width: fit-content; }
.field-group > .btn, .org-section > .btn { align-self: flex-start; width: auto; }
a.btn { color: var(--text); }
a.btn:hover { text-decoration: none; }

/* Prévisions pas encore calculées (calcul en tâche de fond en cours, ou échoué) */
.content.uncomputed > :not(.compute-state) { display: none; }
.compute-state { display: flex; flex-direction: column; align-items: flex-start; gap: 10px; }
.compute-state h3 { margin: 0; }
