/* ---------- Tokens ---------- */
:root {
  --bg: #14130f;
  --surface: #1d1c17;
  --surface-2: #26241e;
  --line: #34312a;
  --text: #f1ede4;
  --muted: #9b968a;
  --accent: #f2b544;          /* warm lamplicht */
  --accent-ink: #2a1d05;
  --cool: #6fb4d8;            /* klimaat */
  --green: #7cc189;           /* zon / ok */
  --red: #e4705d;             /* alarm / open */
  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 1px 0 rgba(255,255,255,.03) inset, 0 8px 24px rgba(0,0,0,.25);
  --font: "SF Pro Text", -apple-system, BlinkMacSystemFont, "Segoe UI Variable", "Segoe UI", Inter, Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, monospace;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f1ea;
    --surface: #fffdf8;
    --surface-2: #efebe2;
    --line: #e1dbcf;
    --text: #1f1d18;
    --muted: #716b5f;
    --accent: #d8920f;
    --accent-ink: #fff8ea;
    --cool: #2f86b5;
    --green: #3f9152;
    --red: #c94b37;
    --shadow: 0 1px 2px rgba(60,45,20,.06), 0 8px 24px rgba(60,45,20,.06);
    color-scheme: light;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.muted { color: var(--muted); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.num { font-variant-numeric: tabular-nums; }

/* ---------- Topbar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(14px + env(safe-area-inset-top)) 16px 10px;
  max-width: 1280px; margin: 0 auto;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; font-size: 17px; letter-spacing: -.01em; }
.brand-mark { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 11px; background: var(--accent); color: var(--accent-ink); }
.brand-mark svg { width: 19px; height: 19px; stroke-width: 2.1; }
.topbar-right { display: flex; align-items: center; gap: 8px; }
.conn { display: inline-flex; align-items: center; gap: 7px; font-size: 13px; color: var(--muted); }
.conn i { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.conn[data-state="ok"] i { background: var(--green); }
.conn[data-state="ok"] span { display: none; }
.conn[data-state="down"] i { background: var(--red); }
.icon-btn {
  display: grid; place-items: center; width: 38px; height: 38px;
  border: 0; border-radius: 12px; background: transparent; color: var(--muted);
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

/* ---------- Tabs (onderaan op mobiel, bovenaan op desktop) ---------- */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(5, 1fr);
  padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
}
.tabs button {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 7px 2px; border: 0; background: none; color: var(--muted);
  font-size: 11px; border-radius: 12px;
}
.tabs button.active { color: var(--text); }
.tabs button.active svg { color: var(--accent); }
@media (min-width: 820px) {
  body { padding-bottom: 32px; }
  .tabs {
    position: sticky; top: 0; bottom: auto;
    display: flex; gap: 4px; justify-content: flex-start;
    max-width: 1280px; margin: 0 auto; padding: 6px 16px 10px;
    border-top: 0; background: var(--bg);
  }
  .tabs button { flex-direction: row; gap: 8px; font-size: 14px; padding: 8px 14px; }
  .tabs button svg { width: 18px; height: 18px; }
  .tabs button.active { background: var(--surface-2); }
}

/* ---------- Layout ---------- */
.view { max-width: 1280px; margin: 0 auto; padding: 4px 16px 24px; }
.section { margin-top: 22px; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin: 0 2px 10px; }
.section-head h2 { margin: 0; font-size: 15px; font-weight: 620; letter-spacing: -.005em; }
.section-head .meta { font-size: 13px; color: var(--muted); }
.link-btn { border: 0; background: none; color: var(--muted); font-size: 13px; padding: 4px 6px; border-radius: 8px; }
.link-btn:hover { color: var(--text); background: var(--surface-2); }
.grid { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(158px, 1fr)); }
.grid.wide { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.empty {
  padding: 28px 18px; text-align: center; color: var(--muted);
  border: 1px dashed var(--line); border-radius: var(--radius);
}
.hero { margin: 10px 2px 4px; }
.hero h1 { margin: 0; font-size: clamp(26px, 5vw, 34px); font-weight: 680; letter-spacing: -.025em; }
.hero p { margin: 4px 0 0; color: var(--muted); }

/* ---------- Kaarten ---------- */
.card {
  background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 14px;
}

/* Stat-chips in het overzicht */
.stats { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); margin-top: 18px; }
.stat {
  text-align: left; border: 0; background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 14px; display: flex; flex-direction: column; gap: 10px;
}
.stat .stat-icon { width: 34px; height: 34px; border-radius: 11px; display: grid; place-items: center; background: var(--surface-2); color: var(--muted); }
.stat .stat-icon svg { width: 18px; height: 18px; }
.stat .stat-value { font-size: 24px; font-weight: 650; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stat .stat-label { font-size: 13px; color: var(--muted); margin-top: -8px; }
.stat.warm .stat-icon { background: color-mix(in srgb, var(--accent) 20%, transparent); color: var(--accent); }
.stat.cool .stat-icon { background: color-mix(in srgb, var(--cool) 20%, transparent); color: var(--cool); }
.stat.good .stat-icon { background: color-mix(in srgb, var(--green) 20%, transparent); color: var(--green); }
.stat.alert .stat-icon { background: color-mix(in srgb, var(--red) 20%, transparent); color: var(--red); }

/* Ruimtekaarten */
.room { display: flex; flex-direction: column; gap: 8px; }
.room-name { font-weight: 620; }
.room-facts { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 13px; color: var(--muted); }
.room-facts b { color: var(--text); font-weight: 600; }

/* ---------- Schakel-tegels ---------- */
.tile {
  position: relative; display: flex; flex-direction: column; gap: 12px;
  min-height: 118px; padding: 14px; text-align: left;
  background: var(--surface); border: 0; border-radius: var(--radius); box-shadow: var(--shadow);
  transition: background .2s, transform .1s;
  -webkit-tap-highlight-color: transparent; user-select: none;
}
.tile:active { transform: scale(.98); }
.tile-icon { width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; background: var(--surface-2); color: var(--muted); transition: inherit; }
.tile-name { font-weight: 600; font-size: 14px; line-height: 1.25; margin-top: auto; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.tile-state { font-size: 13px; color: var(--muted); }
.tile.on { background: color-mix(in srgb, var(--accent) 16%, var(--surface)); }
.tile.on .tile-icon { background: var(--accent); color: var(--accent-ink); }
.tile.unavailable { opacity: .5; }
.tile.pending .tile-icon { animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .45; } }
.tile-extra { display: flex; align-items: center; gap: 8px; }
.tile-color {
  position: absolute; top: 14px; right: 14px; width: 26px; height: 26px; padding: 0;
  border: 2px solid var(--surface); border-radius: 50%; overflow: hidden; cursor: pointer;
  box-shadow: 0 0 0 1px var(--line);
}
.tile-color::-webkit-color-swatch-wrapper { padding: 0; }
.tile-color::-webkit-color-swatch { border: 0; border-radius: 50%; }
.tile-color::-moz-color-swatch { border: 0; border-radius: 50%; }

input[type="range"] {
  -webkit-appearance: none; appearance: none; width: 100%; height: 26px; background: transparent; margin: 0;
}
input[type="range"]::-webkit-slider-runnable-track { height: 6px; border-radius: 6px; background: linear-gradient(to right, var(--accent) var(--pct, 0%), var(--line) var(--pct, 0%)); }
input[type="range"]::-moz-range-track { height: 6px; border-radius: 6px; background: var(--line); }
input[type="range"]::-moz-range-progress { height: 6px; border-radius: 6px; background: var(--accent); }
input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 20px; height: 20px; margin-top: -7px; border-radius: 50%; background: var(--text); border: 0; box-shadow: 0 1px 4px rgba(0,0,0,.3); }
input[type="range"]::-moz-range-thumb { width: 20px; height: 20px; border-radius: 50%; background: var(--text); border: 0; }

/* Scènes */
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.chip {
  flex: none; border: 1px solid var(--line); background: var(--surface); border-radius: 999px;
  padding: 8px 14px; font-size: 14px; white-space: nowrap;
}
.chip:hover { border-color: var(--accent); }

/* ---------- Klimaat ---------- */
.thermo { display: flex; flex-direction: column; gap: 14px; }
.thermo-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.thermo-name { font-weight: 620; }
.thermo-action { font-size: 13px; color: var(--muted); }
.thermo-action.heating { color: var(--accent); }
.thermo-action.cooling { color: var(--cool); }
.thermo-main { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.thermo-target { font-size: 44px; font-weight: 600; letter-spacing: -.04em; line-height: 1; font-variant-numeric: tabular-nums; }
.thermo-target sup { font-size: 18px; color: var(--muted); font-weight: 500; letter-spacing: 0; }
.thermo-current { font-size: 13px; color: var(--muted); margin-top: 6px; }
.stepper { display: flex; flex-direction: column; gap: 8px; }
.stepper button {
  width: 46px; height: 46px; border-radius: 14px; border: 0;
  background: var(--surface-2); font-size: 22px; line-height: 1;
}
.stepper button:hover { background: var(--line); }
.modes { display: flex; gap: 6px; flex-wrap: wrap; }
.mode {
  border: 1px solid var(--line); background: transparent; border-radius: 999px;
  padding: 6px 12px; font-size: 13px; color: var(--muted);
}
.mode.active { background: var(--text); color: var(--bg); border-color: var(--text); }
.sensor-room { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.sensor-room .vals { display: flex; gap: 16px; font-variant-numeric: tabular-nums; }
.sensor-room .big { font-size: 22px; font-weight: 620; letter-spacing: -.02em; }
.sensor-room .small { font-size: 13px; color: var(--muted); }

/* ---------- Energie ---------- */
.rows { display: flex; flex-direction: column; }
.row {
  display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; align-items: center;
  padding: 11px 4px; border: 0; border-bottom: 1px solid var(--line); background: none; text-align: left;
}
.row:last-child { border-bottom: 0; }
.row:hover { background: color-mix(in srgb, var(--surface-2) 60%, transparent); }
.row-name { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-val { font-variant-numeric: tabular-nums; font-weight: 600; }
.bar { grid-column: 1 / -1; height: 4px; border-radius: 4px; background: var(--surface-2); overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--accent); border-radius: 4px; }
.bar.neg i { background: var(--green); }
.energy-hero { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.energy-hero .big { font-size: 40px; font-weight: 650; letter-spacing: -.035em; line-height: 1; font-variant-numeric: tabular-nums; }
.energy-hero .big small { font-size: 18px; color: var(--muted); font-weight: 500; margin-left: 4px; letter-spacing: 0; }
.chart { width: 100%; height: 180px; display: block; margin-top: 14px; }
.chart svg { width: 100%; height: 100%; stroke: none; }
.chart .area { fill: color-mix(in srgb, var(--accent) 22%, transparent); }
.chart .line { fill: none; stroke: var(--accent); stroke-width: 2; vector-effect: non-scaling-stroke; }
.chart .axis { fill: var(--muted); font-size: 11px; }
.chart .gridline { stroke: var(--line); stroke-width: 1; vector-effect: non-scaling-stroke; }

/* ---------- Beveiliging ---------- */
.alarm { display: flex; flex-direction: column; gap: 14px; }
.alarm-state { display: flex; align-items: center; gap: 12px; }
.alarm-badge { width: 44px; height: 44px; border-radius: 14px; display: grid; place-items: center; background: var(--surface-2); color: var(--muted); }
.alarm.armed .alarm-badge { background: color-mix(in srgb, var(--green) 22%, transparent); color: var(--green); }
.alarm.triggered .alarm-badge { background: var(--red); color: #fff; }
.alarm-title { font-weight: 620; }
.alarm-sub { font-size: 13px; color: var(--muted); }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.btn {
  border: 1px solid var(--line); background: var(--surface-2); border-radius: 12px;
  padding: 9px 14px; font-size: 14px; font-weight: 550;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--text); color: var(--bg); border-color: var(--text); }
.code-input {
  width: 100%; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface-2); font-family: var(--mono); letter-spacing: .2em;
}
.status-list .row { grid-template-columns: auto 1fr auto; cursor: default; }
.status-list .row:hover { background: none; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--line); }
.dot.alert { background: var(--red); box-shadow: 0 0 0 4px color-mix(in srgb, var(--red) 22%, transparent); }
.dot.ok { background: var(--green); }
.status-text { font-size: 13px; color: var(--muted); }
.status-text.alert { color: var(--red); font-weight: 600; }

.cams { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.cam {
  position: relative; aspect-ratio: 16 / 9; border-radius: var(--radius); overflow: hidden;
  background: var(--surface-2); border: 0; padding: 0;
}
.cam img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cam-label {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 22px 12px 10px;
  background: linear-gradient(transparent, rgba(0,0,0,.65)); color: #fff;
  font-size: 13px; font-weight: 600; text-align: left;
}
.cam.offline::after { content: "Geen beeld"; position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); font-size: 13px; }

/* ---------- Modal & toast ---------- */
.modal {
  width: min(960px, calc(100vw - 24px)); max-height: calc(100dvh - 24px);
  border: 0; border-radius: 22px; padding: 14px; background: var(--surface); color: var(--text);
}
.modal::backdrop { background: rgba(0,0,0,.6); backdrop-filter: blur(4px); }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin: 0 2px 10px; }
.modal-head h2 { margin: 0; font-size: 16px; }
.modal img { width: 100%; border-radius: 14px; display: block; }
.toast {
  position: fixed; left: 50%; bottom: calc(92px + env(safe-area-inset-bottom)); z-index: 50;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px;
  font-size: 14px; transition: .25s; max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
@media (min-width: 820px) { .toast { bottom: 28px; } }

/* ---------- Login ---------- */
.login-page { display: grid; place-items: center; padding: 16px; }
.login-card {
  width: min(360px, 100%); display: flex; flex-direction: column; gap: 12px;
  background: var(--surface); padding: 28px 22px; border-radius: 24px; box-shadow: var(--shadow);
}
.login-card h1 { margin: 6px 0 0; font-size: 24px; letter-spacing: -.02em; }
.login-card p { margin: 0 0 6px; }
.login-mark { width: 46px; height: 46px; border-radius: 14px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; }
.login-card input {
  padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface-2);
}
.login-card input:focus, .code-input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.btn-primary { padding: 12px; border: 0; border-radius: 12px; background: var(--accent); color: var(--accent-ink); font-weight: 650; }
.login-error { color: var(--red); min-height: 1.4em; font-size: 14px; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* ---------- Detailpaneel ---------- */
.hint { color: var(--muted); }
@media (hover: hover) and (pointer: fine) { .hint { display: none; } }
.tile { -webkit-touch-callout: none; }
.clickable { cursor: pointer; }
button.card.sensor-room { width: 100%; border: 0; color: inherit; text-align: left; }
button.card.sensor-room:hover { background: color-mix(in srgb, var(--surface-2) 50%, var(--surface)); }
.status-list .row.clickable { width: 100%; color: inherit; cursor: pointer; }
.status-list .row.clickable:hover { background: color-mix(in srgb, var(--surface-2) 60%, transparent); }

.modal { width: min(640px, calc(100vw - 24px)); }
.modal:has(.cam-full) { width: min(960px, calc(100vw - 24px)); }
.detail { display: flex; flex-direction: column; gap: 14px; }
.detail-head { margin: -4px 2px 0; }
.detail-state { font-size: 34px; font-weight: 650; letter-spacing: -.03em; line-height: 1.1; font-variant-numeric: tabular-nums; }
.detail-meta { font-size: 13px; color: var(--muted); margin-top: 4px; }
.detail-control .tile { min-height: 0; box-shadow: none; background: var(--surface-2); }
.detail-control .tile.on { background: color-mix(in srgb, var(--accent) 18%, var(--surface-2)); }
.detail-control .card { box-shadow: none; background: var(--surface-2); }
.detail-control .code-input, .detail-control .stepper button { background: var(--surface); }
.detail-sub { margin: 6px 2px 0; font-size: 13px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.detail-history .chart { margin-top: 4px; }
.chart-msg { padding: 40px 0; text-align: center; color: var(--muted); font-size: 14px; }
.detail-stats { display: flex; gap: 10px; margin-top: 12px; }
.detail-stats > div { flex: 1; background: var(--surface-2); border-radius: var(--radius-sm); padding: 10px 12px; display: flex; flex-direction: column; gap: 2px; }
.detail-stats span { font-size: 12px; color: var(--muted); }
.detail-stats b { font-size: 17px; font-weight: 640; font-variant-numeric: tabular-nums; }
.timeline { position: relative; height: 34px; border-radius: 10px; background: var(--surface-2); overflow: hidden; margin-top: 4px; }
.timeline i { position: absolute; top: 0; bottom: 0; min-width: 2px; }
.timeline i.on { background: var(--accent); }
.timeline i.alert { background: var(--red); }
.timeline i.na { background: repeating-linear-gradient(45deg, var(--line) 0 4px, transparent 4px 8px); }
.timeline-axis { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); margin-top: 6px; font-variant-numeric: tabular-nums; }
.change-list .row { grid-template-columns: 1fr auto; padding: 9px 4px; }

/* ---------- Kioskmodus ---------- */
body.kiosk #logout { display: none; }
body.kiosk { user-select: none; -webkit-user-select: none; }
body.no-nav .tabs { display: none; }
body.no-nav { padding-bottom: 24px; }

.saver {
  position: fixed; inset: 0; z-index: 100; display: grid; place-items: center;
  background: #000; color: #e9e4d8; cursor: none; opacity: 0; transition: opacity .8s;
}
.saver.show { opacity: 1; }
.saver-inner { display: flex; flex-direction: column; align-items: center; gap: 10px; transition: transform 4s ease-in-out; padding: 24px; }
.saver-time { font-size: clamp(72px, 18vw, 180px); font-weight: 250; letter-spacing: -.04em; line-height: 1; }
.saver-date { font-size: clamp(16px, 2.6vw, 24px); color: #8f897c; }
.saver-facts { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px 26px; margin-top: 18px; font-size: clamp(15px, 2.2vw, 20px); color: #b9b3a5; font-variant-numeric: tabular-nums; }
.saver-facts span { display: inline-flex; align-items: center; gap: 8px; }
.saver-facts svg { width: 20px; height: 20px; opacity: .7; }
.saver-facts .warn { color: var(--red); }
.saver-cam { width: min(520px, 80vw); aspect-ratio: 16 / 9; object-fit: cover; border-radius: 16px; margin-top: 22px; opacity: .85; }
/* In het detailpaneel staan naam en status al in de kop: compacte tegel met icoon + schuif */
.detail-control .tile { flex-direction: row; align-items: center; gap: 14px; padding: 12px 14px; }
.detail-control .tile .tile-name, .detail-control .tile .tile-state { display: none; }
.detail-control .tile .tile-extra { flex: 1; }
.detail-control .tile .tile-color { position: static; flex: none; }
.detail-control .tile:not(:has(.tile-extra))::after { content: "Tik om te schakelen"; color: var(--muted); font-size: 14px; }

/* ---------- Verbindingsmelding ---------- */
.banner {
  max-width: 1248px; margin: 0 16px 8px; padding: 12px 14px; border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--red) 14%, var(--surface)); border: 1px solid color-mix(in srgb, var(--red) 40%, transparent);
  font-size: 14px;
}
@media (min-width: 1280px) { .banner { margin: 0 auto 8px; } }
.banner[hidden] { display: none; }
.banner b { color: var(--red); font-weight: 650; }
.banner p { margin: 4px 0 0; }
.banner .banner-retry { color: var(--muted); font-size: 13px; }
