:root {
  --bg: #eef2f7;
  --card: #ffffff;
  --text: #17202b;
  --muted: #5d6b7c;
  --line: #dbe2ea;
  --accent: #1f6feb;
  --accent-soft: #e3edfd;
  --warm: #e8590c;
  --cold: #1c7ed6;
  --rain: #3b82f6;
  --snow: #8a63d2;
  --alert-red: #c92a2a;
  --alert-orange: #e8590c;
  --alert-yellow: #f2c200;
  --alert-grey: #868e96;
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f141a;
    --card: #19212b;
    --text: #e7edf4;
    --muted: #94a3b4;
    --line: #2a3542;
    --accent: #5b9bff;
    --accent-soft: #1d2c44;
    --warm: #ff8a4c;
    --cold: #5cb3ff;
    --rain: #60a5fa;
    --snow: #b197fc;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f141a; --card: #19212b; --text: #e7edf4; --muted: #94a3b4; --line: #2a3542;
  --accent: #5b9bff; --accent-soft: #1d2c44; --warm: #ff8a4c; --cold: #5cb3ff;
  --rain: #60a5fa; --snow: #b197fc; color-scheme: dark;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); }
small, .muted { color: var(--muted); font-weight: 400; }

.topbar {
  position: sticky; top: 0; z-index: 1000;
  display: flex; flex-wrap: wrap; gap: 8px; justify-content: space-between; align-items: center;
  padding: 10px 16px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}
.city-picker, .status { display: flex; gap: 6px; align-items: center; }
.status { color: var(--muted); font-size: 13px; }
select, input[type="search"] {
  font: inherit; color: var(--text); background: var(--bg);
  border: 1px solid var(--line); border-radius: 10px; padding: 7px 10px;
}
select { font-weight: 600; min-width: 0; max-width: 60vw; }
.btn {
  font: inherit; cursor: pointer;
  border: 1px solid var(--accent); background: var(--accent); color: #fff;
  border-radius: 10px; padding: 6px 12px;
}
.btn.ghost { background: transparent; color: var(--text); border-color: var(--line); }
.btn:hover { filter: brightness(1.08); }

main { max-width: 1040px; margin: 0 auto; padding: 16px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; }
.card {
  background: var(--card); border-radius: var(--radius);
  border: 1px solid var(--line); padding: 16px; min-width: 0;
}
h2 { font-size: 16px; margin: 0 0 12px; }
h2 small { font-size: 12px; margin-left: 6px; }
.skeleton { color: var(--muted); padding: 24px 0; }
.error { color: var(--alert-red); }

/* Alertes */
#alerts { display: grid; gap: 8px; }
#alerts:empty { display: none; }
.alert {
  display: flex; gap: 10px; align-items: center; cursor: pointer; text-align: left;
  border: 0; border-left: 6px solid var(--alert-yellow); border-radius: 10px;
  background: var(--card); color: var(--text); font: inherit; padding: 10px 14px; width: 100%;
  box-shadow: 0 0 0 1px var(--line) inset;
}
.alert.rouge { border-left-color: var(--alert-red); }
.alert.orange { border-left-color: var(--alert-orange); }
.alert.jaune { border-left-color: var(--alert-yellow); }
.alert.gris, .alert.statement { border-left-color: var(--alert-grey); }
.alert .more { margin-left: auto; color: var(--muted); font-size: 13px; white-space: nowrap; }
.alert-text { white-space: pre-line; }

/* Maintenant */
.now { display: grid; grid-template-columns: auto 1fr; gap: 8px 28px; align-items: center; }
.now .place { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: baseline; }
.now .place h1 { font-size: 22px; margin: 0; }
.now .main { display: flex; align-items: center; gap: 14px; }
.now .icon { font-size: 64px; line-height: 1; }
.now .temp { font-size: 64px; font-weight: 700; letter-spacing: -2px; line-height: 1; }
.now .cond { font-size: 17px; font-weight: 600; }
.now .feels { color: var(--muted); }
.now .stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px 16px; }
.stat .label { font-size: 12px; color: var(--muted); }
.stat .value { font-weight: 600; }
.now .src { grid-column: 1 / -1; font-size: 12px; color: var(--muted); }
@media (max-width: 640px) {
  .now { grid-template-columns: minmax(0, 1fr); }
  .now .temp, .now .icon { font-size: 52px; }
}

/* Horaire */
.hourly-scroll { overflow-x: auto; padding-bottom: 6px; }
.hourly-inner { position: relative; }
.hourly-inner svg { position: absolute; left: 0; top: 52px; pointer-events: none; }
.hourly-cols { display: flex; }
.hcol { flex: 0 0 58px; text-align: center; font-size: 13px; display: flex; flex-direction: column; align-items: center; }
.hcol .h { color: var(--muted); font-size: 12px; height: 18px; }
.hcol .h.day { color: var(--text); font-weight: 700; }
.hcol .ic { font-size: 22px; height: 32px; }
.hcol .spacer { height: 70px; }
.hcol .t { font-weight: 700; height: 20px; }
.hcol .pop { color: var(--rain); height: 18px; }
.hcol .amt { color: var(--muted); font-size: 11px; height: 16px; }
.hcol .w { color: var(--muted); font-size: 11px; height: 16px; }

/* 7 jours */
.daily { display: grid; gap: 4px; }
.drow {
  display: grid; grid-template-columns: 92px 36px 1fr 64px 92px; gap: 10px; align-items: center;
  padding: 6px 4px; border-bottom: 1px solid var(--line);
}
.drow:last-child { border-bottom: 0; }
.drow .day { font-weight: 600; }
.drow .day small { display: block; font-size: 11px; }
.drow .ic { font-size: 24px; text-align: center; }
.range { position: relative; height: 8px; background: var(--line); border-radius: 4px; }
.range .bar { position: absolute; top: 0; bottom: 0; border-radius: 4px; background: linear-gradient(90deg, var(--cold), var(--warm)); }
.range .lo, .range .hi { position: absolute; top: -18px; font-size: 13px; }
.range .lo { color: var(--muted); }
.range .hi { font-weight: 700; }
.drow .pop { color: var(--rain); font-size: 13px; text-align: right; }
.drow .amt { color: var(--muted); font-size: 12px; text-align: right; }
@media (max-width: 560px) {
  .drow { grid-template-columns: 70px 30px 1fr 52px; }
  .drow .amt { display: none; }
}

/* Prévisions texte */
.text-forecast { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 10px; }
.tf { background: var(--bg); border-radius: 10px; padding: 10px 12px; }
.tf .name { font-weight: 700; display: flex; justify-content: space-between; gap: 8px; }
.tf .name span { font-size: 20px; }
.tf p { margin: 4px 0 0; font-size: 14px; }

/* Radar */
.radar-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 10px; }
.radar-head h2 { margin: 0; }
.radar-controls { display: flex; gap: 8px; align-items: center; }
.radar-time { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 13px; min-width: 120px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg button { font: inherit; border: 0; background: transparent; color: var(--text); padding: 6px 12px; cursor: pointer; }
.seg button.on { background: var(--accent); color: #fff; }
#radarMap { height: 440px; border-radius: 10px; }
@media (max-width: 640px) { #radarMap { height: 340px; } }

/* Boîtes de dialogue */
dialog {
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--card); color: var(--text); padding: 0; width: min(520px, calc(100vw - 32px));
}
dialog::backdrop { background: rgba(0, 0, 0, .45); }
.dialog-body { padding: 18px; display: grid; gap: 10px; }
.dialog-body h3 { margin: 0; }
.dialog-actions { display: flex; justify-content: flex-end; }
.results { list-style: none; margin: 0; padding: 0; max-height: 50vh; overflow: auto; }
.results li { display: flex; align-items: center; gap: 8px; padding: 8px; border-bottom: 1px solid var(--line); }
.results li.pick { cursor: pointer; }
.results li.pick:hover { background: var(--accent-soft); }
.results li .grow { flex: 1; }

footer { text-align: center; color: var(--muted); font-size: 12px; padding: 8px 16px 24px; }

/* ===== Onglets ===== */
.topbar { padding: 0; display: block; }
.topbar .bar {
  display: flex; flex-wrap: wrap; gap: 8px; justify-content: space-between; align-items: center;
  padding: 10px 16px 6px; max-width: 1072px; margin: 0 auto;
}
.tabs { display: flex; gap: 4px; padding: 0 16px; max-width: 1072px; margin: 0 auto; overflow-x: auto; }
.tabs a {
  padding: 8px 16px 10px; color: var(--muted); text-decoration: none; font-weight: 600;
  border-bottom: 3px solid transparent; white-space: nowrap;
}
.tabs a:hover { color: var(--text); }
.tabs a.on { color: var(--accent); border-bottom-color: var(--accent); }
.tab-panel { display: grid; gap: 16px; min-width: 0; }
.tab-panel[hidden] { display: none; }
[hidden] { display: none !important; }

.small { font-size: 12px; }
.note { margin: -4px 0 12px; font-size: 13px; }

/* Niveaux (UV, qualité de l'air, confiance) */
.lvl { display: inline-block; font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 999px; vertical-align: 1px; }
.lvl-low { background: #d3f9d8; color: #2b8a3e; }
.lvl-mod { background: #fff3bf; color: #946200; }
.lvl-high { background: #ffe8cc; color: #c2410c; }
.lvl-vhigh { background: #ffe3e3; color: #c92a2a; }
.lvl-ext { background: #f3d9fa; color: #862e9c; }

/* Maintenant : extras */
.range-today { margin-top: 4px; font-size: 14px; }
.now .stats { grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); }

/* À retenir */
.highlights { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.highlights li {
  display: flex; gap: 10px; align-items: center; padding: 8px 12px; border-radius: 10px;
  background: var(--bg); border-left: 4px solid var(--line);
}
.highlights li.good { border-left-color: #40c057; }
.highlights li.warn { border-left-color: var(--alert-orange); }
.highlights li.danger { border-left-color: var(--alert-red); font-weight: 600; }
.hi-icon { font-size: 20px; }

/* Aujourd'hui : texte + radar côte à côte */
.split { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 3fr); gap: 16px; align-items: start; }
@media (max-width: 860px) { .split { grid-template-columns: minmax(0, 1fr); } }
.today-text { display: grid; gap: 10px; }
.today-text .small { margin: 0; }
.tf-temp { font-size: 13px; font-weight: 700; margin-top: 2px; }
.tf-temp.hi, .hi { color: var(--warm); }
.tf-temp.lo, .lo { color: var(--cold); }
.radar-card #radarMap { height: 420px; }

/* Légendes */
.legend { font-size: 12px; margin-top: 6px; display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.sw { display: inline-block; width: 14px; height: 4px; border-radius: 2px; margin: 0 2px 0 6px; vertical-align: middle; }
.sw.warm { background: var(--warm); }
.sw.cold { background: var(--cold); }
.sw.rain { background: var(--rain); height: 10px; }
.sw.snow { background: var(--snow); height: 10px; }
.sw.dash { background: repeating-linear-gradient(90deg, var(--muted) 0 3px, transparent 3px 6px); }
.sw.zone { background: var(--accent-soft); height: 10px; border: 1px solid var(--line); }

/* Graphiques SVG */
.chart-scroll { overflow-x: auto; }
.chart { display: block; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .zero { stroke: var(--cold); stroke-width: 1; stroke-dasharray: 4 3; opacity: .6; }
.chart .sep { stroke: var(--line); stroke-width: 1; }
.chart .normal { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 5 4; }
.chart .axis { fill: var(--muted); font-size: 11px; }
.chart .day-lbl { fill: var(--text); font-size: 12px; font-weight: 700; }
.chart .val { font-size: 11px; font-weight: 700; }
.chart .val.hi { fill: var(--warm); }
.chart .val.lo { fill: var(--cold); }
.chart .trend-zone { fill: var(--accent-soft); opacity: .6; }

/* 7 jours : cartes */
.week-days { display: grid; gap: 12px; }
.day-card { display: grid; gap: 10px; }
.day-head { display: grid; grid-template-columns: 120px 48px auto 1fr; gap: 12px; align-items: center; }
.day-name { font-weight: 700; font-size: 17px; }
.day-name small { display: block; font-size: 12px; font-weight: 400; }
.day-icon { font-size: 36px; text-align: center; }
.day-temps { display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; }
.day-temps .hi { font-size: 24px; font-weight: 700; }
.day-temps .lo { font-size: 18px; font-weight: 600; }
.day-cond { color: var(--muted); font-weight: 600; }
.dev { font-size: 11px; font-weight: 700; padding: 1px 6px; border-radius: 999px; }
.dev.warm { background: #ffe8cc; color: #c2410c; }
.dev.cold { background: #d0ebff; color: #1864ab; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { background: var(--bg); border-radius: 999px; padding: 3px 10px; font-size: 13px; }
.official { border-top: 1px solid var(--line); padding-top: 8px; font-size: 14px; }
.official p { margin: 2px 0; }
@media (max-width: 640px) {
  .day-head { grid-template-columns: 1fr auto auto; }
  .day-cond { grid-column: 1 / -1; }
}

/* 14 jours : tableau */
.ens-table { display: grid; }
.ens-row {
  display: grid; grid-template-columns: 110px 34px 1.3fr 1.2fr 1.2fr 1fr 90px; gap: 8px; align-items: center;
  padding: 7px 4px; border-bottom: 1px solid var(--line); font-size: 14px;
}
.ens-row.head { font-size: 12px; color: var(--muted); font-weight: 600; }
.ens-row.trend-start { border-top: 2px dashed var(--accent); }
.ens-row .d { font-weight: 600; }
.ens-row .d small { display: block; font-size: 11px; font-weight: 400; }
.ens-row .ic { font-size: 22px; text-align: center; }
.pp { display: flex; align-items: center; gap: 6px; }
.pbar { flex: 0 0 50px; height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; }
.pbar span { display: block; height: 100%; background: var(--rain); }
@media (max-width: 640px) {
  .ens-row { grid-template-columns: 76px 28px 1fr 1fr 70px; font-size: 13px; }
  .hide-sm { display: none; }
  .pbar { flex-basis: 24px; }
}

/* ===== Application installée (plein écran) ===== */
.topbar { padding-top: env(safe-area-inset-top); }
.topbar .bar, .tabs { padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right)); }
footer { padding-bottom: max(24px, env(safe-area-inset-bottom)); }
#installBtn { white-space: nowrap; }
.steps { margin: 0; padding-left: 20px; display: grid; gap: 8px; }
.ios-share { display: inline-block; border: 1px solid var(--line); border-radius: 6px; padding: 0 6px; }
@media (display-mode: standalone) {
  /* Pas de sélection de texte ni de surbrillance au toucher, comme une application */
  body { -webkit-tap-highlight-color: transparent; overscroll-behavior-y: none; }
}
