/* Zebri Hjem: a Grafana-style dashboard. Dark, dense panels on a 24-column grid, collapsible rows,
   one time picker and one room filter for the whole page. Fonts are system fonts: the site CSP
   allows no font host. */
* { margin: 0; padding: 0; box-sizing: border-box; }
:root {
  color-scheme: dark;
  --canvas: #111217;
  --panel: #181B1F;
  --panel-2: #22252B;
  --line: rgba(204, 204, 220, 0.10);
  --line-2: rgba(204, 204, 220, 0.20);
  --text: #CCCCDC;
  --text-2: rgba(204, 204, 220, 0.65);
  --text-3: rgba(204, 204, 220, 0.45);
  --accent: #3D71D9;
  --blue: #5794F2;
  --orange: #FF9830;
  --green: #73BF69;
  --purple: #B877D9;
  --yellow: #FADE2A;
  --red: #F2495C;
  --lamp-1: #8F4A10;
  --ui: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
body { font: 13px/1.45 var(--ui); background: var(--canvas); color: var(--text); }
.hidden { display: none !important; }
.muted { color: var(--text-2); }
.small { font-size: 12px; }
.error { color: var(--red); margin: 8px 0; }
.num, td.num { font-variant-numeric: tabular-nums; }
button, select, input { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ---------------------------------------------------------------- buttons, inputs */
.btn { display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 10px; background: var(--panel-2);
  border: 1px solid var(--line-2); border-radius: 4px; font-weight: 500; font-size: 12.5px; white-space: nowrap; }
.btn:hover { border-color: var(--text-3); }
.btn svg { width: 14px; height: 14px; stroke: currentColor; fill: none; stroke-width: 1.8; flex: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.on { border-color: var(--blue); color: var(--blue); }
input[type="date"], input[type="search"], select { background: var(--canvas); border: 1px solid var(--line-2); border-radius: 4px; height: 30px; padding: 0 8px; }
.link { background: none; border: 0; color: var(--blue); }

/* ---------------------------------------------------------------- login */
.login { max-width: 360px; margin: 18vh auto; padding: 24px; display: grid; gap: 14px; text-align: center;
  background: var(--panel); border: 1px solid var(--line); border-radius: 4px; }
.login h1 { font-size: 20px; font-weight: 500; }
.login .btn { justify-self: center; height: 36px; padding: 0 18px; }

/* ---------------------------------------------------------------- top bar + variables */
#app { max-width: 1600px; margin: 0 auto; padding: 0 16px 48px; }
.topbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; padding: 10px 0;
  border-bottom: 1px solid var(--line); position: sticky; top: env(safe-area-inset-top, 0px); background: var(--canvas); z-index: 20; }
.crumbs { display: flex; gap: 8px; align-items: center; min-width: 0; }
.crumbs .logo { width: 28px; height: 28px; border-radius: 4px; background: var(--panel-2); display: grid; place-items: center; flex: none; }
.crumbs .logo svg { width: 16px; height: 16px; stroke: var(--orange); fill: none; stroke-width: 1.8; }
.crumbs .sep { color: var(--text-3); }
.crumbs h1 { font-size: 15px; font-weight: 500; white-space: nowrap; }
.tools { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.picker { position: relative; }
.pop { position: absolute; right: 0; top: 36px; z-index: 30; width: min(320px, calc(100vw - 32px)); background: var(--panel-2);
  border: 1px solid var(--line-2); border-radius: 4px; padding: 10px; display: grid; gap: 10px; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45); }
.pop-presets { display: grid; gap: 2px; }
.pop-presets button { text-align: left; background: none; border: 0; border-radius: 3px; padding: 6px 8px; }
.pop-presets button:hover { background: rgba(204, 204, 220, 0.08); }
.pop-presets button.on { background: rgba(61, 113, 217, 0.18); color: var(--text); }
.pop-custom { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; border-top: 1px solid var(--line); padding-top: 10px; }
.pop-custom label { display: grid; gap: 3px; font-size: 11.5px; color: var(--text-2); }
.pop-custom input { width: 100%; }
.pop-custom .btn { grid-column: 1 / -1; justify-content: center; }
.who-btn #who { color: var(--text-2); font-weight: 400; max-width: 22ch; overflow: hidden; text-overflow: ellipsis; }

.vars { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 10px 0 4px; }
.var { display: inline-flex; height: 30px; border: 1px solid var(--line-2); border-radius: 4px; overflow: hidden; }
.var .k { display: grid; align-items: center; padding: 0 9px; background: var(--panel-2); color: var(--text-2); border-right: 1px solid var(--line-2); }
.var select { border: 0; border-radius: 0; height: 28px; }
#status { margin-left: auto; }
.banner { background: rgba(242, 73, 92, 0.12); color: var(--red); border: 1px solid rgba(242, 73, 92, 0.5); border-radius: 4px; padding: 8px 12px; margin: 8px 0; }

/* ---------------------------------------------------------------- rows + panels */
.row { margin-top: 12px; }
.row-h { display: flex; align-items: baseline; gap: 8px; width: 100%; background: none; border: 0; padding: 6px 0; font-size: 14px; font-weight: 500; text-align: left; }
.row-h::before { content: "▾"; color: var(--text-2); width: 12px; display: inline-block; transition: transform .15s; }
.row-h[aria-expanded="false"]::before { transform: rotate(-90deg); }
.row-h small { color: var(--text-3); font-weight: 400; font-size: 12px; }
.row-h[aria-expanded="false"] + .row-b { display: none; }
.grid { display: grid; grid-template-columns: repeat(24, minmax(0, 1fr)); gap: 8px; align-items: stretch; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 3px; display: flex; flex-direction: column; min-width: 0; }
.ph { display: flex; align-items: center; gap: 8px; min-height: 32px; padding: 4px 10px; flex-wrap: wrap; }
.ph h2 { font-size: 13px; font-weight: 500; }
.ph .hint { color: var(--text-3); font-size: 11.5px; }
.ph .right { margin-left: auto; display: flex; gap: 6px; align-items: center; }
.pb { padding: 2px 10px 10px; flex: 1; display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.s4 { grid-column: span 4; } .s6 { grid-column: span 6; } .s8 { grid-column: span 8; } .s12 { grid-column: span 12; }
.s16 { grid-column: span 16; } .s24 { grid-column: span 24; }
.stack { display: grid; gap: 8px; align-content: start; }
@media (max-width: 1100px) {
  .s4 { grid-column: span 8; } .s6 { grid-column: span 12; } .s8, .s12, .s16 { grid-column: span 24; }
  .s8.half { grid-column: span 12; }
}
@media (max-width: 640px) {
  .s4, .s6 { grid-column: span 12; } .s8.half { grid-column: span 24; }
  #status { margin-left: 0; width: 100%; }
  .crumbs .muted, .crumbs .sep { display: none; }
}
.nodata { color: var(--text-3); padding: 18px 0; text-align: center; }
.empty { color: var(--text-3); padding: 10px 0; }

.chart { width: 100%; height: 280px; }
.chart.short { height: 220px; }
.chart.tall { height: 320px; }

/* ---------------------------------------------------------------- stat */
.stat { position: relative; overflow: hidden; min-height: 92px; }
.stat .pb { justify-content: center; gap: 2px; position: relative; z-index: 1; }
.stat .val { font-size: 28px; font-weight: 500; line-height: 1.1; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat .sub { color: var(--text-2); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat svg.spark { position: absolute; left: 0; right: 0; bottom: 0; width: 100%; height: 40px; }
.stat.ok-fill { background: #23461F; border-color: #37702F; }
.stat.bad-fill { background: #5A1E26; border-color: #8A2C38; }
.stat.ok-fill .val, .stat.bad-fill .val { color: #fff; }
.stat.ok-fill .sub, .stat.bad-fill .sub { color: rgba(255, 255, 255, 0.72); }
.people { display: flex; gap: 6px; flex-wrap: wrap; }
.person { font-size: 13px; font-weight: 500; border-radius: 3px; padding: 2px 8px; }
.person.in { background: rgba(115, 191, 105, 0.18); color: var(--green); }
.person.out { background: rgba(204, 204, 220, 0.06); color: var(--text-3); }

/* ---------------------------------------------------------------- tables */
.table-wrap { overflow: auto; max-height: 70vh; }
table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
th { text-align: left; color: var(--blue); font-weight: 500; position: sticky; top: 0; background: var(--panel); z-index: 1; }
th, td { padding: 5px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th.num, td.num { text-align: right; }
td.wrap { white-space: normal; }
td.cold { color: var(--blue); font-weight: 600; }
td.warn { color: var(--yellow); font-weight: 600; }
td.bad { color: var(--red); font-weight: 600; }
td.ok { color: var(--green); }
td.lit { color: var(--orange); }
tr.day td { background: var(--panel-2); color: var(--text-2); font-weight: 500; }
tbody tr:hover td { background: rgba(204, 204, 220, 0.03); }
.legend-table tr { cursor: pointer; }
.legend-table tr.off td { opacity: 0.4; }
.sw { display: inline-block; width: 14px; height: 4px; border-radius: 2px; margin-right: 7px; vertical-align: middle; }

/* ---------------------------------------------------------------- bar gauge */
.gauges { display: grid; gap: 9px; }
.gauge { display: grid; gap: 3px; }
.gauge-top { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; color: var(--text-2); }
.gauge-top b { font-weight: 500; font-variant-numeric: tabular-nums; }
.gauge-bar { height: 14px; background: rgba(204, 204, 220, 0.06); border-radius: 2px; overflow: hidden; }
.gauge-bar i { display: block; height: 100%; border-radius: 2px; }

/* ---------------------------------------------------------------- alert list */
.alerts { display: grid; }
.alerts li { list-style: none; display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 10px; align-items: center; padding: 7px 0; border-top: 1px solid var(--line); }
.alerts li:first-child { border-top: 0; }
.state { font-size: 10.5px; font-weight: 600; border-radius: 3px; padding: 2px 7px; text-transform: uppercase; letter-spacing: .03em; white-space: nowrap; }
.state.fire { background: rgba(242, 73, 92, 0.18); color: var(--red); }
.state.pend { background: rgba(250, 222, 42, 0.14); color: var(--yellow); }
.state.ok { background: rgba(115, 191, 105, 0.14); color: var(--green); }
.alerts .name { min-width: 0; }
.alerts .name small { display: block; color: var(--text-3); font-size: 11.5px; }
.alerts .age { color: var(--text-3); font-size: 11.5px; white-space: nowrap; }

/* ---------------------------------------------------------------- logs */
.logs { list-style: none; display: grid; font-family: var(--mono); font-size: 12px; overflow: auto; max-height: 70vh; }
.logs li { display: grid; grid-template-columns: 3px auto minmax(0, 1fr) auto; gap: 10px; align-items: center; padding: 3px 4px 3px 0; }
.logs li:hover { background: rgba(204, 204, 220, 0.04); }
.logs .lv { align-self: stretch; border-radius: 2px; background: var(--text-3); }
.logs .t { color: var(--text-3); white-space: nowrap; }
.logs .msg { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.logs .msg .z { color: var(--text-3); }
.logs .lbl { font-family: var(--ui); font-size: 11px; color: var(--text-2); background: var(--panel-2); border-radius: 3px; padding: 1px 6px; white-space: nowrap; }
.logs .lbl b { font-weight: 500; color: var(--text); }
.logs .daysep { display: block; font-family: var(--ui); color: var(--text-2); font-weight: 500; padding: 8px 0 3px; border-bottom: 1px solid var(--line); margin-bottom: 2px; }
.logs .daysep:first-child { padding-top: 0; }
.lv.light { background: var(--orange); } .lv.scene { background: var(--yellow); } .lv.person { background: var(--green); }
.lv.lock { background: var(--red); } .lv.flow { background: var(--purple); } .lv.climate { background: var(--blue); }
@media (max-width: 640px) {
  .logs li { grid-template-columns: 3px auto minmax(0, 1fr); }
  .logs .lbl { grid-column: 3; justify-self: start; }
}
#filter { min-width: 200px; }
@media (max-width: 640px) { #filter { min-width: 0; width: 100%; } .ph .right { width: 100%; margin-left: 0; } }

/* ---------------------------------------------------------------- Nå: rooms table, running list */
.list { list-style: none; display: grid; gap: 6px; }
.list li { display: flex; justify-content: space-between; gap: 10px; }
.list .warn { color: var(--yellow); font-weight: 600; }
.list .bad { color: var(--red); font-weight: 600; }
.bulbs { display: inline-flex; gap: 3px; vertical-align: middle; margin-right: 6px; }
.bulbs i { width: 8px; height: 8px; border-radius: 50%; background: rgba(204, 204, 220, 0.14); display: block; }
.foot { color: var(--text-3); font-size: 11.5px; }

/* ---------------------------------------------------------------- Døgnet: state timeline */
.timeline { display: grid; gap: 3px; min-width: 520px; }
.tl-scroll { overflow-x: auto; }
.tl-row { display: grid; grid-template-columns: 84px minmax(0, 1fr); align-items: center; gap: 8px; }
.tl-label { font-size: 12px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tl-person .tl-label, .tl-door .tl-label { color: var(--text); }
.tl-track { position: relative; height: 22px; background: rgba(204, 204, 220, 0.05); border-radius: 2px; overflow: hidden; }
.tl-axis .tl-track { background: none; height: 16px; overflow: visible; }
.tl-hour { position: absolute; top: 0; transform: translateX(-50%); font-size: 11px; color: var(--text-3); font-variant-numeric: tabular-nums; }
.tl-hour:first-child { transform: none; }
.tl-grid { position: absolute; top: 0; bottom: 0; width: 1px; background: var(--line); }
.tl-band { position: absolute; top: 0; bottom: 0; border-radius: 2px; cursor: pointer; border-right: 1px solid var(--panel); }
.tl-band.light { background: var(--orange); }
.tl-band.home { background: var(--green); }
.tl-band.sleep { background: var(--purple); }
.tl-band.unlocked { background: var(--red); }
.tl-tick { position: absolute; top: 2px; bottom: 2px; width: 2px; margin-left: -1px; cursor: pointer; }
.tl-tick.motion { background: var(--text-2); opacity: .6; top: 13px; bottom: 2px; }
.tl-tick.scene { width: 8px; height: 8px; margin-left: -4px; top: 7px; border-radius: 50%; background: var(--yellow); box-shadow: 0 0 0 2px var(--panel); }
.tl-tick.lock, .tl-tick.unlock { width: 2px; background: var(--text); }
.tl-nodata { position: absolute; top: 0; bottom: 0; background: repeating-linear-gradient(135deg, var(--line) 0 4px, transparent 4px 8px); }
.tl-now { position: absolute; top: 0; bottom: 0; width: 0; border-left: 1px dashed var(--red); }
.tl-person + .tl-room, .tl-door + .tl-room { margin-top: 6px; }
.tl-info { min-height: 1.4em; font-size: 12.5px; }
.tl-legend { display: flex; gap: 14px; flex-wrap: wrap; align-items: center; }
.tl-legend span { display: inline-flex; align-items: center; gap: 5px; }
.tl-legend .sw { position: static; display: inline-block; width: 12px; height: 10px; margin: 0; top: auto; bottom: auto; border: 0; }
.tl-legend .tl-tick.motion.sw { width: 2px; height: 10px; }
.tl-legend .tl-tick.scene.sw { width: 8px; height: 8px; box-shadow: none; }
.seg { display: inline-flex; border: 1px solid var(--line-2); border-radius: 4px; overflow: hidden; }
.seg button { background: var(--panel-2); border: 0; padding: 3px 10px; font-size: 12px; }
.seg button + button { border-left: 1px solid var(--line-2); }
.seg button.active { background: rgba(61, 113, 217, 0.25); color: var(--text); }
@media (max-width: 760px) {
  .tl-row { grid-template-columns: 64px minmax(0, 1fr); gap: 6px; }
}
