/* demo-bms. Desaturated industrial palette, semantic status colors, tabular figures for values. */

:root {
  --bg: #e6e9ec;
  --panel: #f6f7f8;
  --panel-2: #eef0f2;
  --border: #c7cdd3;
  --border-strong: #a9b1b9;
  --text: #1c232a;
  --muted: #5b6672;
  --accent: #3b6d8f;
  --accent-ink: #ffffff;

  --ok: #3d8457;
  --ok-bg: #dcebe0;
  --warn: #a8701a;
  --warn-bg: #f3e6cc;
  --alarm: #b23a3a;
  --alarm-bg: #f3d9d7;
  --off: #8a939b;
  --off-bg: #e3e6e9;

  --pipe-chws: #2f6d9c;
  --pipe-chwr: #7fa6c4;
  --pipe-cws: #3b8a80;
  --pipe-cwr: #a0866a;
  --equip: #dfe3e7;
  --equip-stroke: #6c7782;

  --chart-a: #2f6d9c;
  --chart-b: #c0632e;
  --chart-grid: #d6dbe0;

  --banner-bg: #f0d58a;
  --banner-ink: #3a2c05;

  --sans: 'IBM Plex Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --mono: 'IBM Plex Mono', ui-monospace, 'SF Mono', Menlo, monospace;
  --radius: 4px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #13171b;
    --panel: #1b2025;
    --panel-2: #20262c;
    --border: #2e353c;
    --border-strong: #46505a;
    --text: #d5dbe0;
    --muted: #8a959f;
    --accent: #5d93b8;
    --accent-ink: #0d1114;

    --ok: #5fae7a;
    --ok-bg: #1d3326;
    --warn: #d8a547;
    --warn-bg: #3a2f17;
    --alarm: #e06666;
    --alarm-bg: #3f1f1f;
    --off: #7c868f;
    --off-bg: #262c32;

    --pipe-chws: #4f8fc0;
    --pipe-chwr: #6f90aa;
    --pipe-cws: #4fa79b;
    --pipe-cwr: #a68c70;
    --equip: #262d34;
    --equip-stroke: #7c8892;

    --chart-a: #5c9bd0;
    --chart-b: #e08547;
    --chart-grid: #2b3238;

    --banner-bg: #5a4612;
    --banner-ink: #f6e7b8;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 13px/1.4 var(--sans);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
h1, h2 { margin: 0; font-weight: 600; }
h1 { font-size: 16px; }
h2 { font-size: 14px; }
.muted { color: var(--muted); }
/* .pill sets display, which would otherwise beat the hidden attribute. */
[hidden] { display: none !important; }
.num, .mono, .stat-v, td.num, .val { font-family: var(--mono); font-variant-numeric: tabular-nums; }

/* Persistent: repo rule says simulated data is labeled at the top. */
.sim-banner {
  flex: none;
  background: var(--banner-bg);
  color: var(--banner-ink);
  text-align: center;
  font-size: 12px;
  padding: 4px 16px;
  letter-spacing: 0.02em;
}

.topbar {
  flex: none;
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 8px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark { width: 22px; height: 22px; border-radius: 3px; background: linear-gradient(135deg, var(--pipe-chws), var(--pipe-cws)); flex: none; }
.brand-name { font-weight: 600; font-size: 14px; white-space: nowrap; }
.brand-sub { color: var(--muted); font-size: 11px; white-space: nowrap; }
/* Site names vary a lot in length; truncate rather than push the header stats off screen. */
.brand > div { min-width: 0; }
.brand-name, .brand-sub { overflow: hidden; text-overflow: ellipsis; }
.site-pick { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.site-pick select { max-width: 260px; }
.topbar-stats { display: flex; gap: 20px; margin-left: auto; }
.stat { display: flex; flex-direction: column; align-items: flex-end; }
.stat-k { font-size: 10px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.stat-v { font-size: 13px; }

.btn {
  font: inherit;
  font-size: 12px;
  border: 1px solid var(--border-strong);
  background: var(--panel-2);
  color: var(--text);
  border-radius: var(--radius);
  padding: 4px 10px;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { border-color: var(--accent); }
.btn:focus-visible, .nav-item:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.btn-ask { color: var(--accent); border-color: var(--accent); background: transparent; }
.btn-ask:hover { background: var(--accent); color: var(--accent-ink); }
.btn-genie { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; }
.btn-genie[aria-expanded="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.genie-dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; opacity: 0.8; }

.shell {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 160px minmax(0, 1fr) 380px;
}
.shell.genie-hidden { grid-template-columns: 160px minmax(0, 1fr) 0; }
.shell.genie-hidden .genie-dock { display: none; }

.sidenav {
  background: var(--panel);
  border-right: 1px solid var(--border);
  padding: 8px 0;
  display: flex;
  flex-direction: column;
}
.nav-item {
  font: inherit;
  text-align: left;
  background: none;
  border: 0;
  border-left: 3px solid transparent;
  color: var(--text);
  padding: 8px 14px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.nav-item:hover { background: var(--panel-2); }
.nav-item.active { border-left-color: var(--accent); background: var(--panel-2); font-weight: 600; }
.nav-badge:not(:empty) { background: var(--alarm); color: #fff; border-radius: 9px; font: 11px/1 var(--mono); padding: 3px 6px; }

.main { overflow: auto; padding: 14px 16px 24px; }
.view { display: none; }
.view.active { display: block; }
.view-head { display: flex; align-items: baseline; gap: 12px; margin: 4px 0 10px; }
.view-head h2 { margin-top: 10px; }

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

/* Schematic */
.schematic-panel { padding: 8px; margin-bottom: 12px; }
#schematic svg { display: block; width: 100%; height: auto; }
.sch-label { font: 500 11px var(--sans); fill: var(--muted); }
.sch-tag { font: 600 12px var(--sans); fill: var(--text); }
.sch-val { font: 12px var(--mono); fill: var(--text); }
.sch-equip { fill: var(--equip); stroke: var(--equip-stroke); stroke-width: 1.2; }
.sch-equip.alarm { stroke: var(--alarm); stroke-width: 2; }
.pipe { fill: none; stroke-width: 5; stroke-linecap: round; stroke-linejoin: round; }
.pipe.chws { stroke: var(--pipe-chws); }
.pipe.chwr { stroke: var(--pipe-chwr); }
.pipe.cws { stroke: var(--pipe-cws); }
.pipe.cwr { stroke: var(--pipe-cwr); }
.flow { stroke-dasharray: 2 14; stroke: var(--panel); stroke-width: 2; fill: none; animation: flow 1.6s linear infinite; opacity: 0.7; }
@keyframes flow { to { stroke-dashoffset: -32; } }
@media (prefers-reduced-motion: reduce) { .flow { animation: none; } }
.dot-ok { fill: var(--ok); }
.dot-off { fill: var(--off); }
.dot-alarm { fill: var(--alarm); }

/* Chiller tiles */
.chiller-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 12px; }
.tile { padding: 10px 12px; display: flex; flex-direction: column; gap: 8px; border-top: 3px solid var(--ok); }
.tile.alarm { border-top-color: var(--alarm); }
.tile-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.tile-title { font-weight: 600; font-size: 14px; }
.tile-sub { color: var(--muted); font-size: 11px; }
.tile-serial { font-family: var(--mono); font-size: 12px; }
.kv { display: grid; grid-template-columns: 1fr auto; gap: 3px 12px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; text-align: right; font-family: var(--mono); font-variant-numeric: tabular-nums; }
.kv dd.bad { color: var(--alarm); font-weight: 500; }
/* Expected range as Genie words it, so the tile and the Genie card line up. */
.kv dt .band { font-size: 11px; opacity: 0.8; }
.tile-pills { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.tile-note { color: var(--muted); font-size: 11px; }
.tile-foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }

.pill { display: inline-flex; align-items: center; gap: 5px; font-size: 11px; padding: 2px 8px; border-radius: 10px; white-space: nowrap; }
.pill::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill.ok { background: var(--ok-bg); color: var(--ok); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.alarm { background: var(--alarm-bg); color: var(--alarm); }
.pill.off { background: var(--off-bg); color: var(--off); }
.alarm-msg { color: var(--alarm); font-size: 12px; font-weight: 500; }

/* Air side */
.ahu-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; margin-bottom: 8px; }
.bar { height: 6px; background: var(--panel-2); border: 1px solid var(--border); border-radius: 3px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--accent); }

/* Tables */
.grid-table { width: 100%; border-collapse: collapse; }
.grid-table th, .grid-table td { padding: 6px 10px; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; }
.grid-table th { font-size: 11px; font-weight: 500; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); background: var(--panel-2); position: sticky; top: 0; }
.grid-table td.num, .grid-table th.num { text-align: right; }
.grid-table tr:last-child td { border-bottom: 0; }
.grid-table tr.unacked td:first-child { box-shadow: inset 3px 0 0 var(--alarm); }
.grid-table tr.acked { color: var(--muted); }
.grid-table td.msg { white-space: normal; min-width: 200px; }
.grid-table .actions { display: flex; gap: 6px; justify-content: flex-end; }
.panel:has(.grid-table) { overflow-x: auto; }

/* Trends */
.select-wrap { margin-left: auto; display: flex; gap: 8px; align-items: center; color: var(--muted); }
select { font: inherit; color: var(--text); background: var(--panel); border: 1px solid var(--border-strong); border-radius: var(--radius); padding: 3px 6px; }
.trend-panel { padding: 10px 12px; }
.trend-legend { display: flex; gap: 18px; flex-wrap: wrap; margin-bottom: 6px; font-size: 12px; }
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.legend-swatch { width: 14px; height: 3px; border-radius: 2px; }
.legend-swatch.dash { background: none; border-top: 2px dashed var(--alarm); height: 0; }
#trend-chart svg { display: block; width: 100%; height: auto; }
.ax { font: 11px var(--mono); fill: var(--muted); }
.ax-title { font: 11px var(--sans); fill: var(--muted); }
.gridline { stroke: var(--chart-grid); stroke-width: 1; }
.axisline { stroke: var(--border-strong); stroke-width: 1; }

/* Genie dock. The panel styles its own contents; we only give it a box. */
.genie-dock {
  border-left: 1px solid var(--border);
  background: var(--panel);
  min-height: 0;
  height: 100%;
  width: 380px;
  overflow: hidden;
  position: relative;
}
.genie-missing { padding: 16px; color: var(--muted); }
.genie-missing strong { color: var(--text); display: block; margin-bottom: 6px; }
.genie-missing .q { margin-top: 12px; padding: 8px 10px; border: 1px dashed var(--border-strong); border-radius: var(--radius); font-size: 12px; color: var(--text); }

@media (max-width: 1100px) {
  .topbar-stats .stat:nth-child(2) { display: none; }
  .shell { grid-template-columns: 140px minmax(0, 1fr) 340px; }
  .genie-dock { width: 340px; }
}
/* Phone is not a target, but nothing should overflow. Genie overlays the content there. */
@media (max-width: 760px) {
  body { overflow: auto; }
  .topbar { flex-wrap: wrap; gap: 10px; }
  .topbar-stats { order: 3; width: 100%; margin-left: 0; justify-content: space-between; }
  .stat { align-items: flex-start; }
  .shell, .shell.genie-hidden { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .sidenav { flex-direction: row; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--border); padding: 0; }
  .nav-item { border-left: 0; border-bottom: 3px solid transparent; }
  .nav-item.active { border-bottom-color: var(--accent); }
  .genie-dock { position: fixed; right: 0; top: 0; bottom: 0; width: min(380px, 100vw); z-index: 10; box-shadow: -4px 0 16px rgba(0,0,0,0.2); }
}
