:root {
  color-scheme: light;
  --bg: #f4f4f2; --surface: #fcfcfb; --surface-2: #f0efec; --border: #e2e1dc;
  --text: #0b0b0b; --text-2: #52514e; --muted: #8a8984;
  --accent: #2a78d6;
  --s-cons: #2a78d6; --s-pv: #eb6834; --s-grid: #1baf7a; --s-soc: #2a78d6; --s-target: #e87ba4; --s-dess: #eda100;
  --hc-band: rgba(42, 120, 214, .07);
  --t-bleu: #2a78d6; --t-blanc: #f7f7f5; --t-blanc-ink: #3a3936; --t-rouge: #d63b3a;
  --good: #0a7f3f; --warn: #b26b00; --bad: #c62828;
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121211; --surface: #1a1a19; --surface-2: #232321; --border: #2e2e2b;
    --text: #f0efec; --text-2: #c3c2b7; --muted: #8d8c85;
    --accent: #3987e5;
    --s-cons: #3987e5; --s-pv: #d95926; --s-grid: #199e70; --s-soc: #3987e5; --s-target: #d55181; --s-dess: #c98500;
    --hc-band: rgba(57, 135, 229, .10);
    --t-bleu: #3987e5; --t-blanc: #e9e8e4; --t-blanc-ink: #1a1a19; --t-rouge: #e66767;
    --good: #3fbf72; --warn: #e0a030; --bad: #ef6b6b;
  }
}
:root[data-theme="dark"] {
    color-scheme: dark;
    --bg: #121211; --surface: #1a1a19; --surface-2: #232321; --border: #2e2e2b;
    --text: #f0efec; --text-2: #c3c2b7; --muted: #8d8c85;
    --accent: #3987e5;
    --s-cons: #3987e5; --s-pv: #d95926; --s-grid: #199e70; --s-soc: #3987e5; --s-target: #d55181; --s-dess: #c98500;
    --hc-band: rgba(57, 135, 229, .10);
    --t-bleu: #3987e5; --t-blanc: #e9e8e4; --t-blanc-ink: #1a1a19; --t-rouge: #e66767;
    --good: #3fbf72; --warn: #e0a030; --bad: #ef6b6b;
}
* { box-sizing: border-box; }
body { margin: 0; font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
header { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; padding: 12px 20px; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5; }
header h1 { font-size: 17px; margin: 0 12px 0 0; letter-spacing: -.01em; }
header .spacer { flex: 1; }
nav { display: flex; gap: 2px; }
nav button { background: none; border: 0; padding: 7px 12px; border-radius: 7px; color: var(--text-2); font: inherit; cursor: pointer; }
nav button.active { background: var(--surface-2); color: var(--text); font-weight: 600; }
main { max-width: 1240px; margin: 0 auto; padding: 18px 20px 60px; }
.tab { display: none; } .tab.active { display: block; }
h2 { font-size: 15px; margin: 0 0 10px; }
h3 { font-size: 13px; margin: 0 0 8px; color: var(--text-2); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.grid { display: grid; gap: 12px; }
.kpis { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); margin-bottom: 12px; }
.kpi .label { color: var(--text-2); font-size: 12px; }
.kpi .value { font-size: 26px; font-weight: 650; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.kpi .value small { font-size: 14px; font-weight: 500; color: var(--text-2); margin-left: 2px; }
.kpi .sub { color: var(--muted); font-size: 12px; min-height: 17px; }
.kpi .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; vertical-align: 1px; }
.socbar { height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; margin-top: 6px; }
.socbar > div { height: 100%; background: var(--s-soc); border-radius: 3px; }
.two { grid-template-columns: 2fr 1fr; } @media (max-width: 900px) { .two { grid-template-columns: 1fr; } }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.muted { color: var(--muted); } .small { font-size: 12px; }
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; border: 1px solid transparent; white-space: nowrap; }
.badge.bleu { background: var(--t-bleu); color: #fff; }
.badge.blanc { background: var(--t-blanc); color: var(--t-blanc-ink); border-color: var(--border); }
.badge.rouge { background: var(--t-rouge); color: #fff; }
.badge.unknown { background: transparent; color: var(--text-2); border: 1px dashed var(--muted); }
.badge.est { opacity: .8; border-style: dashed; border-color: var(--muted); }
.badge.sim { background: #6250d6; color: #fff; }
.badge.ok { color: var(--good); border-color: currentColor; } .badge.off { color: var(--bad); border-color: currentColor; }
button.btn, select, input { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 7px; padding: 6px 10px; }
button.btn { cursor: pointer; } button.btn:hover { background: var(--surface-2); }
button.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.btn.danger { color: var(--bad); }
input[type=number] { width: 90px; }
.pilot { display: flex; align-items: center; gap: 8px; padding: 4px 4px 4px 12px; border: 1px solid var(--border); border-radius: 999px; }
.pilot.on { border-color: var(--good); }
.chart { position: relative; }
.chart svg { display: block; width: 100%; overflow: visible; }
.chart .axis text { fill: var(--muted); font-size: 11px; }
.chart .gridline { stroke: var(--border); stroke-width: 1; }
.chart .zero { stroke: var(--muted); stroke-width: 1; }
.tooltip { position: absolute; pointer-events: none; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px; font-size: 12px; box-shadow: 0 4px 14px rgba(0,0,0,.12); white-space: nowrap; z-index: 3; display: none; }
.tooltip .tt-row { display: flex; align-items: center; gap: 6px; } .tooltip .tt-row b { margin-left: auto; padding-left: 12px; font-variant-numeric: tabular-nums; }
.tooltip .sw { width: 10px; height: 3px; border-radius: 2px; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--text-2); margin-bottom: 6px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 14px; height: 3px; border-radius: 2px; display: inline-block; }
.legend i.dash { background: repeating-linear-gradient(90deg, currentColor 0 4px, transparent 4px 7px) !important; height: 2px; }
.days { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.day { display: flex; flex-direction: column; gap: 8px; }
.day.next { outline: 2px solid var(--accent); outline-offset: -1px; }
.day.past { opacity: .6; }
.day .head { display: flex; justify-content: space-between; align-items: center; }
.day .date { font-weight: 650; }
.day .target { font-size: 30px; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.day .target.none { font-size: 16px; color: var(--muted); font-weight: 500; padding: 9px 0; }
.day dl { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; margin: 0; font-size: 12.5px; }
.day dt { color: var(--text-2); } .day dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
.day .reason { font-size: 12px; color: var(--text-2); min-height: 34px; }
.day .ctrl { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; } .day .ctrl select, .day .ctrl input { width: 100%; padding: 4px 6px; font-size: 12.5px; }
.tag { font-size: 11px; color: var(--accent); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: right; padding: 6px 8px; border-bottom: 1px solid var(--border); font-variant-numeric: tabular-nums; }
th:first-child, td:first-child { text-align: left; } th { color: var(--text-2); font-weight: 600; font-size: 12px; }
.events { max-height: 560px; overflow: auto; font-size: 12.5px; }
.events div { padding: 5px 0; border-bottom: 1px solid var(--border); display: flex; gap: 10px; }
.events time { color: var(--muted); flex: none; font-variant-numeric: tabular-nums; }
.events .warn { color: var(--warn); } .events .error { color: var(--bad); } .events .action { color: var(--accent); }
.form { grid-template-columns: repeat(auto-fit, minmax(330px, 1fr)); align-items: start; }
.field { display: grid; grid-template-columns: 1fr 150px; gap: 8px; align-items: center; padding: 4px 0; }
.field label { color: var(--text-2); font-size: 13px; } .field input, .field select { width: 100%; }
.field .hint { grid-column: 1 / -1; font-size: 11.5px; color: var(--muted); margin-top: -4px; }
.arrays .arr { display: grid; grid-template-columns: 1.4fr 1fr 1fr 1fr auto; gap: 6px; margin-bottom: 6px; } .arrays input { width: 100%; }
.notice { border-left: 3px solid var(--warn); background: var(--surface-2); padding: 8px 12px; border-radius: 6px; font-size: 13px; margin-bottom: 12px; }
.mt { margin-top: 12px; }

#theme-btn { padding: 5px 10px; border-radius: 999px; font-size: 12.5px; }

.test-res { font-size: 12.5px; margin-top: 8px; }
.test-res .test { font-weight: 650; margin-bottom: 4px; }
.test-res .step { padding: 2px 0; word-break: break-word; }
.good { color: var(--good); } .bad { color: var(--bad); }

.chart-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 6px; }
.chart-head h2 { margin: 0; }
.seg { display: inline-flex; background: var(--surface-2); border-radius: 8px; padding: 2px; gap: 2px; }
.seg button { border: 0; background: none; color: var(--text-2); font: inherit; font-size: 12px; padding: 3px 8px; border-radius: 6px; cursor: pointer; }
.seg button.on { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,.12); }

/* Téléphone */
@media (max-width: 700px) {
  header { position: static; padding: 10px 12px; gap: 8px; }
  header h1 { font-size: 16px; }
  header .spacer { display: none; }
  nav { order: 10; width: 100%; overflow-x: auto; scrollbar-width: none; }
  nav button { white-space: nowrap; padding: 6px 10px; }
  .pilot { padding-left: 10px; }
  .pilot .small { font-size: 11.5px; }
  main { padding: 12px 10px 40px; }
  .kpis { grid-template-columns: 1fr 1fr; gap: 8px; }
  .kpi .value { font-size: 22px; }
  .card { padding: 12px; }
  .seg { overflow-x: auto; max-width: 100%; }
  .field { grid-template-columns: 1fr 130px; }
}

/* Légendes et axes plus lisibles (téléphone compris) */
.legend { font-size: 13px; gap: 6px 16px; color: var(--text); }
.legend i { width: 18px; height: 4px; }
.legend i.dash { height: 3px; background: repeating-linear-gradient(90deg, currentColor 0 6px, transparent 6px 10px) !important; }
@media (max-width: 700px) {
  .chart .axis text { font-size: 12px; }
  .legend { font-size: 12.5px; gap: 4px 12px; }
}

/* Fenêtre de conflit */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 50; }
.modal[hidden] { display: none; }
.modal-box { width: 100%; max-width: 520px; max-height: 90vh; overflow: auto; border-left: 4px solid var(--warn); }
.modal-box h2 { color: var(--warn); }
.cf { padding: 10px 0; border-top: 1px solid var(--border); }
.cf:first-child { border-top: 0; }
.cf-title { font-weight: 650; margin-bottom: 6px; }
.cf dl { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 0 0 8px; font-size: 13px; }
.cf dt { color: var(--text-2); } .cf dd { margin: 0; }
.cf .row { gap: 8px; } .cf .btn { flex: 1 1 200px; }

.tooltip .tt-diff { border-top: 1px solid var(--border); margin-top: 3px; padding-top: 3px; }

/* Météo du planning */
.wx { display: inline-flex; align-items: center; gap: 4px; margin-left: auto; margin-right: 8px; font-size: 12.5px; color: var(--text-2); white-space: nowrap; }
.wx-ico { font-size: 22px; line-height: 1; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* Comptes en lecture seule */
.ro .admin-only { display: none !important; }
body:not(.ro) .ro-only { display: none; }
.badge.user { background: var(--surface-2); color: var(--text-2); }

/* Journal d'audit */
table.audit td, table.audit th { text-align: left; vertical-align: top; }
table.audit td:first-child { white-space: nowrap; }
