:root {
  --bg: #f4f5f2;
  --surface: #ffffff;
  --surface-2: #eef0ec;
  --text: #1b1f1d;
  --muted: #5f6763;
  --border: #dcdfda;
  --ok: #2f8a57;
  --ok-bg: #e3f2e8;
  --warn: #c27a00;
  --warn-bg: #fdf0d6;
  --alert: #c8352b;
  --alert-bg: #fbe2df;
  --rain: #3b7dd8;
  --grid: #e3e6e1;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 2px 8px rgba(0,0,0,.04);
  --radius: 12px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121514; --surface: #1b1f1d; --surface-2: #232826; --text: #e7ebe8; --muted: #9aa39e;
    --border: #2d3330; --ok: #5cc28a; --ok-bg: #1d3427; --warn: #f0a93a; --warn-bg: #3a2e14;
    --alert: #f2675b; --alert-bg: #3d1f1c; --rain: #6aa5ff; --grid: #2a302d; --shadow: none;
  }
}
:root[data-theme="dark"] {
  --bg: #121514; --surface: #1b1f1d; --surface-2: #232826; --text: #e7ebe8; --muted: #9aa39e;
  --border: #2d3330; --ok: #5cc28a; --ok-bg: #1d3427; --warn: #f0a93a; --warn-bg: #3a2e14;
  --alert: #f2675b; --alert-bg: #3d1f1c; --rain: #6aa5ff; --grid: #2a302d; --shadow: none;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); line-height: 1.45; font-size: 15px; }
main, .top, footer { max-width: 1100px; margin: 0 auto; padding: 0 16px; }

.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-top: 20px; padding-bottom: 8px; }
h1 { font-size: 1.5rem; margin: 0; letter-spacing: -.02em; }
.sub { margin: 2px 0 0; color: var(--muted); font-size: .9rem; }
.theme {
  width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font-size: 1.1rem; cursor: pointer;
}
h2 { font-size: 1.05rem; margin: 28px 0 12px; }
h2 small { color: var(--muted); font-weight: 400; }
.h2row { display: flex; align-items: baseline; justify-content: space-between; }
.json { font-size: .85rem; color: var(--muted); }

/* Bandeaux */
.banner { border-radius: var(--radius); padding: 12px 14px; margin: 12px 0; border: 1px solid; font-size: .92rem; }
.banner.alert { background: var(--alert-bg); border-color: var(--alert); }
.banner.warn  { background: var(--warn-bg);  border-color: var(--warn); }
.banner ul { margin: 6px 0 0; padding-left: 18px; }
.banner b { font-weight: 600; }

/* Vue d'ensemble */
.overview { display: grid; grid-template-columns: 1.4fr 1fr; gap: 16px; margin-top: 8px; }
.map { height: 340px; border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface-2); z-index: 0; }
.summary { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 6px 0; }
.srow { display: grid; grid-template-columns: 12px 1fr auto; align-items: center; gap: 10px; padding: 8px 14px; color: inherit; text-decoration: none; }
.srow + .srow { border-top: 1px solid var(--border); }
.srow:hover { background: var(--surface-2); }
.srow .n { font-weight: 500; }
.srow .v { font-variant-numeric: tabular-nums; color: var(--muted); font-size: .9rem; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--ok); }
.dot.l1 { background: var(--warn); } .dot.l2 { background: var(--alert); } .dot.err { background: var(--muted); }

/* Cartes site */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 14px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; scroll-margin-top: 16px; }
.card.l1 { border-color: var(--warn); } .card.l2 { border-color: var(--alert); }
.card.flash { animation: flash 1.6s ease-out; }
@keyframes flash { 0% { box-shadow: 0 0 0 4px var(--warn); } 100% { box-shadow: var(--shadow); } }
.chead { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.chead h3 { margin: 0; font-size: 1.05rem; }
.chead .meta { color: var(--muted); font-size: .8rem; }
.pill { font-size: .75rem; font-weight: 600; padding: 3px 9px; border-radius: 999px; white-space: nowrap; background: var(--ok-bg); color: var(--ok); }
.pill.l1 { background: var(--warn-bg); color: var(--warn); }
.pill.l2 { background: var(--alert-bg); color: var(--alert); }
.pill.err { background: var(--surface-2); color: var(--muted); }

.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 4px 0 6px; }
.kpi { background: var(--surface-2); border-radius: 8px; padding: 7px 9px; }
.kpi .k { font-size: .72rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.kpi .val { font-size: 1.15rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.kpi .val small { font-size: .72rem; font-weight: 400; color: var(--muted); }
.kpi.l1 .val { color: var(--warn); } .kpi.l2 .val { color: var(--alert); }
.note { font-size: .85rem; color: var(--muted); margin: 6px 0 0; }
.note b { color: var(--text); font-weight: 600; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chip { font-size: .75rem; padding: 2px 8px; border-radius: 6px; border: 1px solid var(--border); }
.chip.c2 { background: #fff3a8; color: #5c4a00; border-color: #e6cf3c; }
.chip.c3 { background: #ffc58a; color: #5a2b00; border-color: #e9934a; }
.chip.c4 { background: #ff9c9c; color: #5a0000; border-color: #d94a4a; }

.chart { width: 100%; height: auto; display: block; margin-top: 10px; }
.chart text { fill: var(--muted); font-size: 10px; }
.chart .gridl { stroke: var(--grid); }
.chart .tw { stroke: var(--warn); stroke-dasharray: 3 3; }
.chart .ta { stroke: var(--alert); stroke-dasharray: 3 3; }
.chart .b0 { fill: var(--muted); opacity: .35; }
.chart .b1 { fill: var(--warn); }
.chart .b2 { fill: var(--alert); }
.chart .r { fill: var(--rain); opacity: .8; }
.chart .now { stroke: var(--text); opacity: .35; }
.legend { display: flex; gap: 14px; font-size: .75rem; color: var(--muted); margin-top: 4px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 4px; vertical-align: -1px; }

/* Historique */
.hist { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.hrow { display: grid; grid-template-columns: 130px 22px 150px 1fr; gap: 10px; padding: 9px 14px; font-size: .88rem; align-items: baseline; }
.hrow + .hrow { border-top: 1px solid var(--border); }
.hrow.hl { background: var(--warn-bg); }
.hrow .d { color: var(--muted); font-variant-numeric: tabular-nums; }
.hrow .s { font-weight: 500; }
.empty { color: var(--muted); padding: 16px; text-align: center; }
.more { display: block; width: 100%; padding: 10px; border: 0; border-top: 1px solid var(--border); background: transparent; color: var(--muted); cursor: pointer; font: inherit; }

footer { color: var(--muted); font-size: .78rem; padding-top: 28px; padding-bottom: 28px; }

/* Leaflet en sombre : fond OSM assombri par filtre */
:root[data-theme="dark"] .mm-tiles { filter: invert(1) hue-rotate(180deg) brightness(.85) contrast(.9); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .mm-tiles { filter: invert(1) hue-rotate(180deg) brightness(.85) contrast(.9); } }
.leaflet-container { background: var(--surface-2); font: inherit; }
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--surface); color: var(--text); }
.leaflet-control-attribution { font-size: 10px; }

@media (max-width: 760px) {
  .overview { grid-template-columns: 1fr; }
  .map { height: 260px; }
  .grid { grid-template-columns: 1fr; }
  .hrow { grid-template-columns: 22px 1fr; gap: 2px 10px; }
  .hrow .d { grid-column: 2; order: -1; font-size: .78rem; }
  .hrow .i { grid-row: span 3; }
  .hrow .s, .hrow .t { grid-column: 2; }
}
