  /* ===========================================================
     THEME TOKENS
     =========================================================== */
  :root {
    --bg:        oklch(0.972 0.008 95);
    --surface:   #ffffff;
    --surface-2: oklch(0.985 0.006 95);
    --ink:       oklch(0.30 0.018 200);
    --ink-soft:  oklch(0.54 0.018 200);
    --ink-faint: oklch(0.68 0.015 200);
    --line:      oklch(0.91 0.008 200);
    --line-soft: oklch(0.94 0.006 200);

    --accent:    oklch(0.55 0.085 195);
    --good:      oklch(0.60 0.13 155);
    --warn:      oklch(0.70 0.14 70);
    --bad:       oklch(0.585 0.17 27);

    --temp:      oklch(0.64 0.17 45);
    --hum:       oklch(0.60 0.11 235);
    --solar:     oklch(0.74 0.15 85);
    --sun:       oklch(76.71% 0.15603 85.372);
    --moon:      oklch(73.419% 0.11981 115.471 / 0.923);
    --sg-prod:   oklch(0.62 0.15 150);   /* opgewekt — green */
    --sg-self:   oklch(0.60 0.11 220);   /* zelf gebruikt — blue/teal */
    --sg-import: oklch(0.585 0.18 27);   /* afname — red */

    --chart-line:  oklch(0.91 0.008 200);
    --chart-label: oklch(0.62 0.015 200);

    --shadow:   0 1px 2px rgba(20,30,30,0.04), 0 10px 28px -18px rgba(20,40,40,0.22);
    --shadow-lg:0 2px 6px rgba(20,30,30,0.05), 0 22px 48px -24px rgba(20,40,40,0.30);
    --radius: 20px;
  }
  html.dark {
    --bg:        oklch(0.185 0.012 200);
    --surface:   oklch(0.225 0.014 200);
    --surface-2: oklch(0.255 0.014 200);
    --ink:       oklch(0.94 0.01 200);
    --ink-soft:  oklch(0.74 0.012 200);
    --ink-faint: oklch(0.60 0.012 200);
    --line:      oklch(0.32 0.014 200);
    --line-soft: oklch(0.28 0.012 200);

    --accent:    oklch(0.70 0.10 195);
    --good:      oklch(0.72 0.14 155);
    --warn:      oklch(0.78 0.14 75);
    --bad:       oklch(0.68 0.16 27);

    --temp:      oklch(0.72 0.16 50);
    --hum:       oklch(0.70 0.12 235);
    --solar:     oklch(0.80 0.14 90);
    --sun:       oklch(82.041% 0.16829 84.128);
    --moon:      oklch(83.985% 0.08484 110.35 / 0.904);
    --sg-prod:   oklch(0.70 0.15 150);
    --sg-self:   oklch(0.68 0.11 220);
    --sg-import: oklch(0.66 0.17 27);

    --chart-line:  oklch(0.32 0.014 200);
    --chart-label: oklch(0.62 0.014 200);

    --shadow:   0 1px 2px rgba(0,0,0,0.3), 0 12px 30px -20px rgba(0,0,0,0.6);
    --shadow-lg:0 2px 8px rgba(0,0,0,0.35), 0 26px 54px -26px rgba(0,0,0,0.7);
  }

  * { box-sizing: border-box; }
  html, body { margin: 0; padding: 0; }
  body {
    font-family: 'Hanken Grotesk', system-ui, sans-serif;
    background: var(--bg);
    color: var(--ink);
    -webkit-font-smoothing: antialiased;
    font-feature-settings: 'tnum' 1, 'cv11' 1;
    -webkit-user-select: none;
    user-select: none;
    transition: background 0.4s ease, color 0.4s ease;
  }
  input, textarea, select {
    -webkit-user-select: text;
    user-select: text;
  }
  h1, h2, h3 { margin: 0; font-weight: 600; }

  /* ===========================================================
     SHELL — fluid, iPad → 2K → 4K
     =========================================================== */
  .wrap {
    width: 100%;
    max-width: 2040px;
    margin: 0 auto;
    padding: clamp(20px, 2.4vw, 48px) clamp(18px, 2.6vw, 56px) 96px;
  }

  /* top bar */
  .topbar {
    display: flex;
    align-items: baseline;
    gap: 18px;
    flex-wrap: wrap;
    margin-bottom: clamp(22px, 2.4vw, 40px);
  }
  .brand {
    font-size: clamp(22px, 1.9vw, 30px);
    font-weight: 700;
    letter-spacing: -0.01em;
  }
  .brand .dot { color: var(--accent); }
  #clock {
    font-size: clamp(14px, 1.05vw, 17px);
    color: var(--ink-soft);
    font-weight: 500;
  }
  .topbar .spacer { flex: 1; }
  .theme-btn {
    border: 1px solid var(--line);
    background: var(--surface);
    color: var(--ink-soft);
    border-radius: 999px;
    padding: 8px 16px;
    font: inherit;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    box-shadow: var(--shadow);
    transition: background 0.2s, color 0.2s, border-color 0.2s;
  }
  .theme-btn:hover { border-color: var(--accent); color: var(--ink); }
  .theme-btn .ico-sun, .theme-btn .ico-moon { width: 16px; height: 16px; display: inline-block; }
  html:not(.dark) .theme-btn .ico-moon { display: none; }
  html.dark .theme-btn .ico-sun { display: none; }

  /* section headers */
  .section-head {
    display: flex;
    align-items: baseline;
    gap: 16px;
    margin: clamp(30px, 3vw, 52px) 2px clamp(14px, 1.4vw, 22px);
  }
  .section-head:first-of-type { margin-top: 0; }
  .section-head h2 {
    font-size: clamp(17px, 1.35vw, 22px);
    font-weight: 600;
    letter-spacing: -0.01em;
  }
  .section-head .hint {
    font-size: clamp(13px, 0.95vw, 15px);
    color: var(--ink-faint);
    font-weight: 400;
  }
  .section-head .rule { flex: 1; height: 1px; background: var(--line); align-self: center; }

  /* ===========================================================
     CARDS
     =========================================================== */
  .card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    transition: background 0.4s ease, border-color 0.4s ease, box-shadow 0.3s ease;
  }

  .family-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: clamp(16px, 1.5vw, 26px);
  }
  .metric {
    padding: clamp(20px, 1.7vw, 30px);
    display: flex;
    flex-direction: column;
    min-height: 220px;
  }
  .metric-top {
    display: flex; align-items: center; justify-content: space-between;
    gap: 10px; min-height: 2.5em;
  }
  .metric-label {
    font-size: clamp(13px, 1vw, 15px);
    font-weight: 600;
    color: var(--ink-soft);
    text-transform: uppercase;
    letter-spacing: 0.045em;
    line-height: 1.25;
  }
  .loc {
    font-size: 12px; font-weight: 500; color: var(--ink-faint);
    display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
  }
  .loc::before {
    content: ''; width: 7px; height: 7px; border-radius: 50%;
    background: var(--ink-faint); transition: background 0.3s;
  }
  .loc.is-live::before { background: var(--good); box-shadow: 0 0 0 3px color-mix(in oklch, var(--good) 22%, transparent); }
  .metric-value {
    font-size: clamp(40px, 4.2vw, 64px);
    font-weight: 300;
    line-height: 1;
    letter-spacing: -0.02em;
    margin: 14px 0 0;
  }
  .metric-value .unit {
    font-size: 0.36em;
    font-weight: 500;
    color: var(--ink-soft);
    letter-spacing: 0;
    display: inline-block;
    margin-left: 2px;
    position: relative;
    top: -0.22em;
  }
  .tag {
    display: flex; align-items: center; gap: 8px;
    font-size: clamp(14px, 1.05vw, 16px);
    font-weight: 600;
    margin-top: 12px;
  }
  .tag .bullet {
    width: 9px; height: 9px; border-radius: 50%;
    background: currentColor; flex: none;
  }
  .metric-foot { margin-top: auto; padding-top: 16px; }
  .src { font-size: 13px; color: var(--ink-faint); }

  /* ===========================================================
     INDICATORS (comfort bars)
     =========================================================== */
  .indicator {
    margin-top: 14px;
  }
  .indicator .rail {
    height: 14px;
    border-radius: 999px;
    background: var(--rail, linear-gradient(90deg,
      color-mix(in oklch, var(--bad) 92%, transparent),
      color-mix(in oklch, var(--warn) 92%, transparent) 18%,
      color-mix(in oklch, var(--good) 92%, transparent) 48%,
      color-mix(in oklch, var(--warn) 92%, transparent) 72%,
      color-mix(in oklch, var(--bad) 92%, transparent)
    ));
    position: relative;
    overflow: visible;
  }

  /* Temperature comfort: cold (blue) → ideal (green) → warm (red) */
  .indicator.temp { --rail: linear-gradient(90deg,
      color-mix(in oklch, var(--hum) 92%, transparent),
      color-mix(in oklch, var(--good) 92%, transparent) 45%,
      color-mix(in oklch, var(--warn) 92%, transparent) 70%,
      color-mix(in oklch, var(--bad) 92%, transparent)
    ); }

  /* CO₂: low is fine (green), high becomes bad (red) */
  .indicator.co2 { --rail: linear-gradient(90deg,
      color-mix(in oklch, var(--good) 92%, transparent),
      color-mix(in oklch, var(--good) 92%, transparent) 30%,
      color-mix(in oklch, var(--warn) 92%, transparent) 65%,
      color-mix(in oklch, var(--bad) 92%, transparent)
    ); }
  .indicator .marker {
    position: absolute;
    left: calc(var(--pos, 0.5) * 100%);
    top: 50%;
    transform: translate(-50%, -50%);
    width: 5px;
    height: 22px;
    border-radius: 4px;
    background: var(--ink);
    box-shadow: 0 0 0 2px color-mix(in oklch, var(--surface) 92%, transparent);
  }
  .indicator .labels {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    margin-top: 10px;
    font-size: 13px;
    color: var(--ink-faint);
    font-weight: 500;
  }
  .indicator .labels .mid {
    color: var(--ink-soft);
    text-align: center;
    flex: 1;
  }

  /* Velux sensor — restart control + stale/offline status */
  .icon-btn {
    flex: none; width: 34px; height: 34px; border-radius: 10px;
    border: 1px solid var(--line); background: var(--surface-2); color: var(--ink-soft);
    display: grid; place-items: center; cursor: pointer; padding: 0;
    transition: background 0.2s, color 0.2s, border-color 0.2s, transform 0.2s;
  }
  .icon-btn svg { width: 17px; height: 17px; }
  .icon-btn:hover { color: var(--ink); border-color: var(--accent); }
  .icon-btn:disabled { cursor: default; opacity: 0.7; }
  .icon-btn.spin svg { animation: hm-spin 0.9s linear infinite; }
  @keyframes hm-spin { to { transform: rotate(360deg); } }

  .metric.is-stale { border-color: color-mix(in oklch, var(--warn) 55%, var(--line)); }
  .metric.is-stale .icon-btn {
    border-color: var(--warn); color: var(--warn);
    background: color-mix(in oklch, var(--warn) 12%, var(--surface));
  }
  .metric.is-stale .metric-value { color: var(--ink-soft); }

  .velux-status {
    font-size: 12.5px; font-weight: 500; line-height: 1.35;
    margin-top: 10px; display: flex; align-items: flex-start; gap: 7px;
  }
  .velux-status[hidden] { display: none; }
  .velux-status::before {
    content: ''; width: 7px; height: 7px; border-radius: 50%; margin-top: 4px; flex: none;
    background: currentColor;
  }
  .velux-status.warn { color: var(--warn); }
  .velux-status.ok   { color: var(--good); }
  .velux-status.fail { color: var(--bad); }
  .velux-status.pending { color: var(--ink-soft); }

  /* rainwater meter */
  .meter {
    height: 9px; border-radius: 6px; overflow: hidden;
    background: var(--line-soft);
  }
  .meter span {
    display: block; height: 100%; border-radius: 6px;
    background: linear-gradient(90deg, color-mix(in oklch, var(--accent) 70%, white), var(--accent));
  }

  /* comfort scales */
  .scale {
    position: relative; height: 9px; border-radius: 6px;
  }
  .scale.co2 {
    background: linear-gradient(90deg,
      oklch(0.64 0.15 150), oklch(0.78 0.14 110), oklch(0.74 0.15 70), oklch(0.60 0.17 28));
  }
  .scale.sleep {
    background: linear-gradient(90deg,
      oklch(0.60 0.17 28) 0%, oklch(0.74 0.15 70) 14%, oklch(0.82 0.14 120) 30%,
      oklch(0.64 0.15 150) 46%, oklch(0.82 0.14 120) 64%, oklch(0.74 0.15 70) 80%, oklch(0.60 0.17 28) 100%);
  }
  .scale-mark {
    position: absolute; top: -4px; width: 4px; height: 17px; border-radius: 3px;
    background: var(--ink); box-shadow: 0 0 0 2.5px var(--surface);
    transform: translateX(-2px);
  }
  .scale-ends {
    display: flex; justify-content: space-between;
    font-size: 11.5px; color: var(--ink-faint); margin-top: 9px;
  }

  /* ===========================================================
     ENERGY HERO
     =========================================================== */
  .hero {
    padding: clamp(22px, 2vw, 36px) clamp(24px, 2.4vw, 44px);
    display: flex; align-items: center; justify-content: space-between;
    gap: 36px; flex-wrap: wrap;
    border-left: 6px solid var(--good);
    box-shadow: var(--shadow-lg);
  }
  .hero.deficit { border-left-color: var(--bad); }
  .hero-label {
    font-size: clamp(14px, 1.1vw, 17px); font-weight: 600; color: var(--ink-soft);
    text-transform: uppercase; letter-spacing: 0.04em;
  }
  .hero-label span { color: var(--ink); }
  .hero-value {
    font-size: clamp(46px, 5.4vw, 78px); font-weight: 300; line-height: 1;
    letter-spacing: -0.03em; margin: 8px 0 6px;
  }
  .hero-value .unit {
    font-size: 0.3em;
    font-weight: 500;
    color: var(--ink-soft);
    display: inline-block;
    margin-left: 6px;
    position: relative;
    top: -0.22em;
  }
  .hero-word { font-size: clamp(15px, 1.15vw, 18px); color: var(--ink-soft); }

  .hero-flow { display: flex; align-items: center; gap: 6px; }
  .hero-flow .node {
    display: flex; flex-direction: column; align-items: center; gap: 4px;
    min-width: 92px;
  }
  .hero-flow .node.is-inactive .node-ic { opacity: 0.45; }
  .hero-flow .node span {
    font-size: 12px; color: var(--ink-soft); text-transform: uppercase; letter-spacing: 0.04em; font-weight: 600;
  }
  .hero-flow .node b { font-size: 16px; font-weight: 600; }
  .node-ic {
    width: 40px; height: 40px; border-radius: 12px;
    background: var(--surface-2); border: 1px solid var(--line);
    display: grid; place-items: center; margin-bottom: 2px;
    position: relative;
  }
  .node-ic::before { content: ''; position: absolute; inset: 0; margin: auto; }
  .node-ic.sun::before { width: 16px; height: 16px; border-radius: 50%; background: var(--solar); box-shadow: 0 0 0 3px color-mix(in oklch, var(--solar) 30%, transparent); }
  .node-ic.home::before { width: 18px; height: 14px; background: var(--accent); clip-path: polygon(50% 0, 100% 42%, 100% 100%, 0 100%, 0 42%); }
  .node-ic.grid::before { width: 14px; height: 16px; background: var(--ink-soft); clip-path: polygon(60% 0, 0 58%, 42% 58%, 30% 100%, 100% 38%, 56% 38%); }
  .hero-flow .link {
    width: clamp(20px, 2.2vw, 44px); height: 2px; background: var(--line);
    position: relative;
    opacity: 1;
  }
  .hero-flow .link.on, .hero-flow .link.out { background: var(--good); opacity: 1; }
  .hero-flow .link.in { background: var(--bad); opacity: 1; }
  .hero-flow .link.out::after, .hero-flow .link.on::after {
    content: ''; position: absolute; right: -1px; top: 50%; transform: translateY(-50%);
    border-left: 7px solid var(--good); border-top: 5px solid transparent; border-bottom: 5px solid transparent;
  }
  .hero-flow .link.in::after {
    content: ''; position: absolute; left: -1px; top: 50%; transform: translateY(-50%);
    border-right: 7px solid var(--bad); border-top: 5px solid transparent; border-bottom: 5px solid transparent;
  }

  /* ===========================================================
     CONTEXT MINIS + CHARTS
     =========================================================== */
  .context-grid {
    display: grid; grid-template-columns: repeat(3, 1fr);
    gap: clamp(16px, 1.5vw, 26px);
    margin-bottom: clamp(16px, 1.5vw, 26px);
  }
  .mini { padding: clamp(16px, 1.4vw, 24px); }
  .mini .metric-label { min-height: 0; }
  .mini-value { font-size: clamp(28px, 2.6vw, 40px); font-weight: 300; line-height: 1; margin: 12px 0 6px; letter-spacing: -0.02em; }
  .mini-value .unit {
    font-size: 0.38em;
    font-weight: 500;
    color: var(--ink-soft);
    display: inline-block;
    margin-left: 2px;
    position: relative;
    top: -0.20em;
  }
  .mini-sub { font-size: 13px; color: var(--ink-faint); }

  .charts-row {
    display: grid; grid-template-columns: 1.4fr 1fr;
    gap: clamp(16px, 1.5vw, 26px);
  }
  .chart-card { padding: clamp(18px, 1.5vw, 26px); }
  .chart-card .ch-head {
    display: flex; align-items: baseline; justify-content: space-between; gap: 12px;
    margin-bottom: 10px;
  }
  .chart-card h3 { font-size: clamp(14px, 1.05vw, 16px); font-weight: 600; }
  .legend { display: flex; gap: 16px; font-size: 12.5px; font-weight: 600; color: var(--ink-soft); }
  .legend i { font-style: normal; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
  .legend .sw { width: 14px; height: 3px; border-radius: 2px; display: inline-block; }
  .legend .sw.dash { background: repeating-linear-gradient(90deg, var(--hum) 0 3px, transparent 3px 6px); }
  .chart { width: 100%; }
  .chart svg { display: block; width: 100%; height: auto; }

  /* ===========================================================
     DETAIL WIDGETS
     =========================================================== */
  #widgets { display: flex; flex-direction: column; gap: clamp(14px, 1.3vw, 22px); }
  .widget {
    background: var(--surface); border: 1px solid var(--line);
    border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden;
  }
  .widget > summary {
    list-style: none; cursor: pointer; user-select: none;
    display: flex; align-items: center; gap: 14px;
    padding: clamp(16px, 1.4vw, 22px) clamp(18px, 1.6vw, 28px);
  }
  .widget > summary::-webkit-details-marker { display: none; }
  .w-num {
    width: 26px; height: 26px; border-radius: 8px; flex: none;
    background: var(--surface-2); border: 1px solid var(--line);
    display: grid; place-items: center;
    font-size: 13px; font-weight: 700; color: var(--ink-soft);
  }
  .w-name { font-size: clamp(15px, 1.2vw, 18px); font-weight: 600; flex: 1; }
  .chev { width: 10px; height: 10px; border-right: 2px solid var(--ink-faint); border-bottom: 2px solid var(--ink-faint); transform: rotate(45deg); transition: transform 0.25s; }
  .widget[open] .chev { transform: rotate(-135deg); }
  .widget-body { padding: 0 clamp(18px, 1.6vw, 28px) clamp(18px, 1.6vw, 28px); }

  .tiles { display: grid; gap: clamp(14px, 1.3vw, 22px); }
  .tiles.three { grid-template-columns: repeat(3, 1fr); }
  .tiles.four { grid-template-columns: repeat(4, 1fr); }
  .tile {
    background: var(--surface-2); border: 1px solid var(--line-soft);
    border-radius: 14px; padding: 16px 18px;
  }
  .tile-label { font-size: 12.5px; font-weight: 600; color: var(--ink-soft); text-transform: uppercase; letter-spacing: 0.04em; display: inline-flex; align-items: center; gap: 6px; }
  .tile-label--with-icons { width: 100%; justify-content: space-between; }
  .tariff-icons { display: inline-flex; align-items: center; gap: 8px; }
  .tariff-ico { width: 14px; height: 14px; display: inline-flex; color: var(--ink-soft); }
  .tariff-ico svg { width: 14px; height: 14px; display: block; }
  .tariff-ico.is-dim { opacity: 0.35; }
  .tariff-ico.is-active { opacity: 1; }
  .tariff-ico.is-sun.is-active { color: var(--sun); }
  .tariff-ico.is-moon.is-active { color: var(--moon); }
  .tile-label-ic { width: 14px; height: 14px; display: inline-flex; }
  .tile-label-ic svg { width: 14px; height: 14px; display: block; }
  .tile-value { font-size: clamp(22px, 2vw, 30px); font-weight: 400; margin: 8px 0 4px; letter-spacing: -0.01em; }
  .tile-sub { font-size: 12.5px; color: var(--ink-faint); }
  .chart-wrap { margin-top: clamp(14px, 1.3vw, 22px); }

  /* Gas/water subtitles are often verbose; keep the tiles compact. */
  .widget--gas .tile-sub,
  .widget--water .tile-sub { display: none; }

  /* ===========================================================
     RESPONSIVE  (iPhone is explicitly out of scope)
     =========================================================== */
  @media (max-width: 1100px) {
    /* Keep 4-up on iPad landscape; collapse later */
    .family-grid { grid-template-columns: repeat(4, 1fr); }
    .charts-row { grid-template-columns: 1fr; }
    .hero { gap: 20px; }
    .hero-flow { order: 2; width: 100%; justify-content: space-between; }
  }
  @media (max-width: 900px) {
    .family-grid { grid-template-columns: repeat(2, 1fr); }
  }
  @media (max-width: 720px) {
    .context-grid { grid-template-columns: 1fr; }
    .tiles.three { grid-template-columns: 1fr; }
    .tiles.four { grid-template-columns: 1fr; }
    .hero-flow { flex-wrap: wrap; }
  }
  /* very large / 4K wall screens: a touch more air */
  @media (min-width: 2400px) {
    .wrap { max-width: 2600px; }
  }
