/* ═══════════════════════════════════════════════════════════════
   Hargassner Pilot — feuille de style
   Cible : iPhone en mode « ajouté à l'écran d'accueil ».
   Thème : clair par défaut, sombre sous prefers-color-scheme,
           le bouton de thème ([data-theme]) prime dans les deux sens.
   ═══════════════════════════════════════════════════════════════ */

:root {
  color-scheme: light;

  /* surfaces & encre */
  --plane:        #f2f2f7;
  --surface:      #ffffff;
  --surface-2:    #f7f7f9;
  --ink:          #0b0b0b;
  --ink-2:        #52514e;
  --muted:        #898781;
  --grid:         #e1e0d9;
  --separator:    rgba(11, 11, 11, 0.09);
  --ring:         rgba(11, 11, 11, 0.10);
  --shadow:       0 1px 2px rgba(11, 11, 11, .05), 0 8px 24px rgba(11, 11, 11, .06);
  --blur-bg:      rgba(242, 242, 247, 0.82);

  /* marque */
  --accent:       #cc0d1e;
  --accent-ink:   #ffffff;
  --accent-soft:  rgba(204, 13, 30, 0.10);
  --warm-a:       #ff8a3d;
  --warm-b:       #cc0d1e;

  /* état */
  --good:         #0ca30c;
  --warning:      #fab219;
  --critical:     #d03b3b;

  /* séries de courbes (slots 1-3 + 4, validés) */
  --series-1:     #2a78d6;  /* chaudière   */
  --series-2:     #eb6834;  /* ballon      */
  --series-3:     #1baf7a;  /* départ zone */
  --series-4:     #eda100;  /* stock       */

  --radius:       18px;
  --radius-sm:    12px;
  --tabbar-h:     58px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --plane:      #000000;
    --surface:    #1c1c1e;
    --surface-2:  #2c2c2e;
    --ink:        #ffffff;
    --ink-2:      #c3c2b7;
    --muted:      #898781;
    --grid:       #2c2c2a;
    --separator:  rgba(255, 255, 255, 0.11);
    --ring:       rgba(255, 255, 255, 0.10);
    --shadow:     0 1px 2px rgba(0, 0, 0, .5);
    --blur-bg:    rgba(0, 0, 0, 0.72);
    --accent:     #ff5b52;
    --accent-ink: #1a0405;
    --accent-soft: rgba(255, 91, 82, 0.14);
    --warm-a:     #ffa05c;
    --warm-b:     #ff5b52;
    --series-1:   #3987e5;
    --series-2:   #d95926;
    --series-3:   #199e70;
    --series-4:   #c98500;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --plane:      #000000;
  --surface:    #1c1c1e;
  --surface-2:  #2c2c2e;
  --ink:        #ffffff;
  --ink-2:      #c3c2b7;
  --muted:      #898781;
  --grid:       #2c2c2a;
  --separator:  rgba(255, 255, 255, 0.11);
  --ring:       rgba(255, 255, 255, 0.10);
  --shadow:     0 1px 2px rgba(0, 0, 0, .5);
  --blur-bg:    rgba(0, 0, 0, 0.72);
  --accent:     #ff5b52;
  --accent-ink: #1a0405;
  --accent-soft: rgba(255, 91, 82, 0.14);
  --warm-a:     #ffa05c;
  --warm-b:     #ff5b52;
  --series-1:   #3987e5;
  --series-2:   #d95926;
  --series-3:   #199e70;
  --series-4:   #c98500;
}

/* ───────────────────────── base ───────────────────────── */

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--plane);
  color: var(--ink);
  font-family: system-ui, -apple-system, "SF Pro Text", "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.45;
  overscroll-behavior-y: none;
}

body { min-height: 100dvh; }

h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -0.015em; }

button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }

[hidden] { display: none !important; }

/* ───────────────────────── écran de code ───────────────────────── */

.lock {
  position: fixed; inset: 0; z-index: 50;
  display: grid; place-items: center;
  background: var(--plane);
  padding: env(safe-area-inset-top) 24px env(safe-area-inset-bottom);
}
.lock-inner { width: 100%; max-width: 320px; text-align: center; }
.lock-flame { color: var(--accent); margin-bottom: 8px; }
.lock h1 { font-size: 28px; }
.lock-sub { color: var(--ink-2); margin: 6px 0 26px; font-size: 15px; }
.pin-input {
  width: 100%; text-align: center; font-size: 26px; letter-spacing: .5em;
  padding: 14px 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--separator); background: var(--surface); color: var(--ink);
  margin-bottom: 12px;
}
.pin-input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.lock-error { color: var(--critical); min-height: 20px; font-size: 14px; margin: 12px 0 0; }

.btn {
  display: block; width: 100%; padding: 14px 16px;
  border-radius: var(--radius-sm); font-weight: 620; font-size: 16px;
  transition: transform .08s ease, opacity .15s ease;
}
.btn:active { transform: scale(.975); }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-ghost { background: var(--surface-2); color: var(--ink); margin-top: 8px; }
.btn[disabled] { opacity: .5; pointer-events: none; }

/* ───────────────────────── barre du haut ───────────────────────── */

.topbar {
  position: sticky; top: 0; z-index: 20;
  padding-top: env(safe-area-inset-top);
  background: var(--blur-bg);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--separator);
}
.topbar-inner {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 10px 16px;
}
.topbar-title h1 { font-size: 20px; line-height: 1.2; }
.sync { display: block; font-size: 12px; color: var(--muted); }
.topbar-actions { display: flex; gap: 6px; }
.icon-btn {
  width: 36px; height: 36px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--surface-2); color: var(--ink-2);
}
.icon-btn:active { transform: scale(.92); }
.ico-moon { display: none; }
:root[data-theme="dark"] .ico-sun,
:root:not([data-theme="light"]) .ico-sun { }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .ico-sun { display: none; }
  :root:not([data-theme="light"]) .ico-moon { display: block; }
}
:root[data-theme="dark"] .ico-sun { display: none; }
:root[data-theme="dark"] .ico-moon { display: block; }
:root[data-theme="light"] .ico-sun { display: block; }
:root[data-theme="light"] .ico-moon { display: none; }

.spin { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.banner {
  padding: 10px 16px; font-size: 14px; font-weight: 560;
  display: flex; gap: 8px; align-items: center;
}
.banner.is-warn { background: rgba(250, 178, 25, .16); color: var(--ink); }
.banner.is-error { background: rgba(208, 59, 59, .16); color: var(--ink); }
.banner.is-info { background: var(--accent-soft); color: var(--ink); }

/* ───────────────────────── mise en page ───────────────────────── */

main {
  padding: 14px 16px calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 24px);
  max-width: 720px; margin: 0 auto;
}

.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 14px;
}
.card-title {
  font-size: 13px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted); font-weight: 650; margin-bottom: 12px;
}

/* ───────────────────────── cadran d'accueil ───────────────────────── */

.hero { display: grid; justify-items: center; padding: 22px 16px 18px; }
.hero-dial { position: relative; width: 210px; height: 210px; }
.dial { width: 100%; height: 100%; transform: rotate(135deg); }
.dial circle { fill: none; stroke-linecap: round; stroke-width: 14; }
.dial-track { stroke: var(--surface-2); stroke-dasharray: 396 528; }
.dial-arc {
  stroke: url(#warm); stroke-dasharray: 0 528;
  transition: stroke-dasharray .6s cubic-bezier(.22,.61,.36,1);
}
.hero-readout {
  position: absolute; inset: 0; display: grid; place-content: center; text-align: center;
}
.hero-temp { font-size: 58px; font-weight: 300; letter-spacing: -.03em; line-height: 1; }
.hero-temp i { font-style: normal; font-size: 30px; color: var(--muted); }
.hero-label { display: block; margin-top: 6px; font-size: 13px; color: var(--muted);
  text-transform: uppercase; letter-spacing: .06em; }
.hero-meta { display: flex; gap: 8px; margin-top: 16px; flex-wrap: wrap; justify-content: center; }

.pill {
  font-size: 13px; font-weight: 600; padding: 5px 12px; border-radius: 999px;
  background: var(--accent-soft); color: var(--ink);
}
.pill-ghost { background: var(--surface-2); color: var(--ink-2); }
.pill.is-good { background: rgba(12, 163, 12, .14); }
.pill.is-bad  { background: rgba(208, 59, 59, .16); }

/* ───────────────────────── tuiles ───────────────────────── */

.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 14px; }
.tile {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 14px;
}
.tile-label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.tile-value { font-size: 26px; font-weight: 500; letter-spacing: -.02em; margin-top: 4px; }
.tile-value small { font-size: 14px; color: var(--muted); font-weight: 500; }
.tile-sub { font-size: 12px; color: var(--ink-2); margin-top: 2px; }

/* ───────────────────────── raccourcis ───────────────────────── */

.quick { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.quick-btn {
  background: var(--surface-2); border-radius: var(--radius-sm);
  padding: 12px 6px; display: grid; gap: 6px; justify-items: center;
  transition: transform .08s ease;
}
.quick-btn:active { transform: scale(.94); }
.quick-ico { font-size: 22px; line-height: 1; }
.quick-label { font-size: 11px; line-height: 1.2; color: var(--ink-2); text-align: center; }

/* ───────────────────────── contrôles ───────────────────────── */

.row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--separator);
}
.row:last-child { border-bottom: 0; padding-bottom: 0; }
.row:first-of-type { padding-top: 0; }
/* Contrôle placé sous son libellé (sélecteurs à plusieurs choix). */
.row.is-stacked { display: block; }
.row.is-stacked > *:last-child { margin-top: 10px; }
.row-label { font-size: 15px; }
.row-hint { font-size: 12px; color: var(--muted); margin-top: 2px; }
.row-value { font-size: 15px; color: var(--ink-2); font-variant-numeric: tabular-nums; }

.segmented {
  display: flex; gap: 3px; padding: 3px; border-radius: 10px;
  background: var(--surface-2); overflow-x: auto; scrollbar-width: none;
}
.segmented::-webkit-scrollbar { display: none; }
.seg {
  flex: 1 0 auto; padding: 8px 12px; border-radius: 8px; font-size: 13px;
  font-weight: 580; color: var(--ink-2); white-space: nowrap; text-align: center;
}
.seg.is-active { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
/* Au-delà de 4 choix : grille 2 colonnes plutôt qu'une bande qui déborde. */
.segmented.is-grid { display: grid; grid-template-columns: repeat(2, 1fr); overflow: visible; }
.segmented.is-grid .seg { white-space: normal; }

.stepper { display: flex; align-items: center; gap: 12px; }
.stepper-btn {
  width: 38px; height: 38px; border-radius: 50%; background: var(--surface-2);
  display: grid; place-items: center; font-size: 22px; font-weight: 400; color: var(--ink);
}
.stepper-btn:active { transform: scale(.9); }
.stepper { flex: 0 0 auto; }
.stepper-val { min-width: 96px; text-align: center; font-size: 20px; font-weight: 560;
  font-variant-numeric: tabular-nums; white-space: nowrap; }

input[type="range"] {
  -webkit-appearance: none; appearance: none; width: 100%; height: 28px; background: none;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 6px; border-radius: 3px; background: var(--surface-2);
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 26px; height: 26px; border-radius: 50%;
  background: var(--surface); box-shadow: 0 1px 4px rgba(0,0,0,.3); margin-top: -10px;
  border: 1px solid var(--ring);
}

.switch { position: relative; width: 51px; height: 31px; flex: 0 0 auto; }
.switch input { opacity: 0; width: 100%; height: 100%; margin: 0; }
.switch span {
  position: absolute; inset: 0; border-radius: 999px; background: var(--surface-2);
  transition: background .2s ease; pointer-events: none;
}
.switch span::after {
  content: ''; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px;
  border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.3);
  transition: transform .2s ease;
}
.switch input:checked + span { background: var(--good); }
.switch input:checked + span::after { transform: translateX(20px); }

.big-action {
  width: 100%; padding: 18px; border-radius: var(--radius);
  background: linear-gradient(135deg, var(--warm-a), var(--warm-b));
  color: #fff; font-size: 17px; font-weight: 650;
  display: flex; align-items: center; justify-content: center; gap: 10px;
  box-shadow: 0 6px 20px rgba(204, 13, 30, .25);
}
.big-action:active { transform: scale(.98); }

.hint { font-size: 12.5px; color: var(--muted); margin: 10px 0 0; }

/* ───────────────────────── courbes ───────────────────────── */

.chart-card { background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px; margin-bottom: 14px; }
.chart-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.chart-title { font-size: 15px; font-weight: 620; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 10px 14px; margin-top: 10px; }
.legend-item { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--ink-2); }
.legend-swatch { width: 10px; height: 10px; border-radius: 3px; flex: 0 0 auto; }
.chart-svg { width: 100%; height: auto; display: block; margin-top: 6px; touch-action: pan-y; }
.chart-grid { stroke: var(--grid); stroke-width: 1; }
.chart-axis { fill: var(--muted); font-size: 10px; font-variant-numeric: tabular-nums; }
.chart-line { fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.chart-endlabel { font-size: 10.5px; font-weight: 650; font-variant-numeric: tabular-nums; }
.chart-cursor { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 3; }
.chart-readout { display: flex; flex-wrap: wrap; gap: 8px 16px; margin-top: 8px;
  font-size: 12.5px; color: var(--ink-2); min-height: 18px; font-variant-numeric: tabular-nums; }
.chart-empty { color: var(--muted); font-size: 14px; padding: 22px 0; text-align: center; }

table.data-table { width: 100%; border-collapse: collapse; font-size: 12.5px;
  font-variant-numeric: tabular-nums; margin-top: 10px; }
table.data-table th, table.data-table td {
  text-align: right; padding: 5px 6px; border-bottom: 1px solid var(--separator); }
table.data-table th:first-child, table.data-table td:first-child { text-align: left; }
table.data-table th { color: var(--muted); font-weight: 600; }
details.table-toggle summary { font-size: 12.5px; color: var(--muted); cursor: pointer;
  margin-top: 10px; list-style: none; }
details.table-toggle summary::-webkit-details-marker { display: none; }
details.table-toggle summary::before { content: '▸ '; }
details.table-toggle[open] summary::before { content: '▾ '; }
.table-scroll { max-height: 260px; overflow: auto; }

/* ───────────────────────── barre d'onglets ───────────────────────── */

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(5, 1fr);
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--blur-bg);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-top: 1px solid var(--separator);
}
.tab {
  height: var(--tabbar-h); display: grid; place-items: center; gap: 2px;
  color: var(--muted); font-size: 10px; font-weight: 550;
}
.tab svg { width: 22px; height: 22px; }
.tab.is-active { color: var(--accent); }

/* ───────────────────────── toast & feuille ───────────────────────── */

.toast {
  position: fixed; left: 50%; transform: translate(-50%, 24px);
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px);
  z-index: 40; max-width: min(92vw, 420px);
  padding: 11px 18px; border-radius: 999px;
  background: rgba(28,28,30,.94); color: #fff; font-size: 14px; font-weight: 550;
  opacity: 0; pointer-events: none; transition: opacity .2s ease, transform .2s ease;
  text-align: center;
}
.toast.is-on { opacity: 1; transform: translate(-50%, 0); }
.toast.is-error { background: var(--critical); }

.sheet-backdrop {
  position: fixed; inset: 0; z-index: 45; background: rgba(0,0,0,.4);
  display: flex; align-items: flex-end; justify-content: center;
  padding: 16px calc(16px + env(safe-area-inset-left)) calc(16px + env(safe-area-inset-bottom));
}
.sheet {
  width: 100%; max-width: 420px; background: var(--surface);
  border-radius: 22px; padding: 20px; box-shadow: var(--shadow);
  animation: rise .22s cubic-bezier(.22,.61,.36,1);
}
@keyframes rise { from { transform: translateY(24px); opacity: 0; } }
.sheet h3 { font-size: 18px; margin-bottom: 6px; }
.sheet p { color: var(--ink-2); font-size: 14.5px; margin: 0 0 18px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}

/* ── Programmes horaires ────────────────────────────────────────────
   Une plage se lit « 05:15 → 07:30 ». Les jours à gauche, en gras et de
   largeur fixe, pour que l'œil descende la colonne sans la relire. */
.schedule {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 4px 0 2px;
}

.schedule-line {
  display: flex;
  align-items: baseline;
  gap: 10px;
  font-size: 15px;
}

.schedule-days {
  flex: 0 0 auto;
  min-width: 6.5em;
  font-weight: 600;
  color: var(--ink);
}

.schedule-times {
  color: var(--ink-2);
  font-variant-numeric: tabular-nums;
}
