/* demo-dcim. Dark operations-room palette by default, light under prefers-color-scheme. */
:root {
  --bg: #0d1117;
  --panel: #141a22;
  --panel-2: #1a212b;
  --line: #263041;
  --line-soft: #1f2734;
  --text: #d8dfe9;
  --muted: #8794a6;
  --accent: #4ea1ff;
  --ok: #3fb37f;
  --warn: #e3a53a;
  --crit: #ef5350;
  --minor: #c9b458;
  --info: #5aa2e8;
  --standby: #8794a6;
  --ok-bg: rgba(63, 179, 127, 0.14);
  --warn-bg: rgba(227, 165, 58, 0.16);
  --crit-bg: rgba(239, 83, 80, 0.18);
  --minor-bg: rgba(201, 180, 88, 0.14);
  --info-bg: rgba(90, 162, 232, 0.14);
  --banner-bg: #3a2b07;
  --banner-fg: #ffd47a;
  --cold: rgba(78, 161, 255, 0.07);
  --hot: rgba(239, 83, 80, 0.07);
  --genie-w: 380px;
  --rail-w: 188px;
  --sans: 'IBM Plex Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --mono: 'IBM Plex Mono', ui-monospace, 'SF Mono', Menlo, monospace;
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #eef1f5;
    --panel: #ffffff;
    --panel-2: #f6f8fa;
    --line: #d5dce5;
    --line-soft: #e4e9ef;
    --text: #18202b;
    --muted: #5a6677;
    --accent: #1f6fd1;
    --ok: #1d8a58;
    --warn: #a86d10;
    --crit: #c9302c;
    --minor: #8a7614;
    --info: #1f6fd1;
    --standby: #5a6677;
    --ok-bg: rgba(29, 138, 88, 0.11);
    --warn-bg: rgba(200, 130, 20, 0.14);
    --crit-bg: rgba(201, 48, 44, 0.11);
    --minor-bg: rgba(160, 140, 30, 0.13);
    --info-bg: rgba(31, 111, 209, 0.1);
    --banner-bg: #fff1c7;
    --banner-fg: #5c4300;
    --cold: rgba(31, 111, 209, 0.06);
    --hot: rgba(201, 48, 44, 0.06);
    color-scheme: light;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 13px/1.45 var(--sans);
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
}
.mono, .num, td.r, .clock { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
h1, h2 { margin: 0; font-weight: 600; }
h1 { font-size: 18px; }
h2 { font-size: 13px; letter-spacing: 0.02em; }
a { color: var(--accent); }

/* Persistent notice: simulated data must be stated at the top, not only in a footer. */
.sim-banner {
  flex: none;
  background: var(--banner-bg);
  color: var(--banner-fg);
  padding: 5px 16px;
  font-size: 12px;
  text-align: center;
  border-bottom: 1px solid color-mix(in srgb, var(--banner-fg) 30%, transparent);
}
.sim-banner strong { letter-spacing: 0.06em; }

/* Header */
.topbar {
  flex: none;
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 8px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.brand-mark {
  width: 16px; height: 16px; border-radius: 3px;
  background: linear-gradient(135deg, var(--accent), var(--ok));
}
.brand-name { font-family: var(--mono); font-size: 13px; }
.site { display: flex; flex-direction: column; line-height: 1.2; padding-left: 16px; border-left: 1px solid var(--line); }
.site-name { font-weight: 600; font-size: 14px; }
.site-meta { color: var(--muted); font-size: 11px; }
.topbar-status { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.sum-pill {
  font-size: 12px; padding: 2px 8px; border-radius: 10px; white-space: nowrap;
  border: 1px solid var(--line);
}
.sum-pill span { font-family: var(--mono); font-weight: 600; }
.sum-pill[data-sev="critical"] { background: var(--crit-bg); color: var(--crit); border-color: transparent; }
.sum-pill[data-sev="warning"] { background: var(--warn-bg); color: var(--warn); border-color: transparent; }
.sum-pill[data-sev="minor"] { background: var(--minor-bg); color: var(--minor); border-color: transparent; }
.sum-pill.zero { background: none; color: var(--muted); border-color: var(--line); }
.clock { color: var(--muted); font-size: 12px; min-width: 64px; text-align: right; }

.btn {
  font: 500 12px var(--sans);
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 5px 10px;
  cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px;
}
.btn:hover { border-color: var(--accent); }
.btn:focus-visible, .rail a:focus-visible, .rack:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn-sm { padding: 3px 8px; }
.btn-link { background: none; border: none; color: var(--accent); padding: 0 2px; }
.btn-genie[aria-expanded="true"] { background: color-mix(in srgb, var(--accent) 18%, var(--panel-2)); border-color: var(--accent); }
.btn-ask { color: var(--accent); white-space: nowrap; }
.genie-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #9fd0ff, var(--accent));
  flex: none;
}

/* Shell: rail | main | genie */
.shell {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: var(--rail-w) minmax(0, 1fr) 0;
}
body.genie-open .shell { grid-template-columns: var(--rail-w) minmax(0, 1fr) var(--genie-w); }

.rail {
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 10px 8px;
  display: flex; flex-direction: column; gap: 2px;
}
.rail a {
  color: var(--text); text-decoration: none;
  padding: 7px 10px; border-radius: 4px;
  display: flex; align-items: center; justify-content: space-between;
  border-left: 2px solid transparent;
}
.rail a:hover { background: var(--panel-2); }
.rail a[aria-current="page"] { background: var(--panel-2); border-left-color: var(--accent); font-weight: 600; }
.badge {
  font: 600 11px var(--mono); background: var(--crit-bg); color: var(--crit);
  border-radius: 8px; padding: 0 6px;
}
.rail-foot { margin-top: auto; color: var(--muted); font-size: 11px; padding: 8px 10px; line-height: 1.6; }

main { overflow: auto; padding: 16px; outline: none; }
.view { display: flex; flex-direction: column; gap: 14px; max-width: 1500px; }
.view[hidden] { display: none; }
.view-head { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.view-head .sub { color: var(--muted); font-size: 12px; }

.genie {
  overflow: hidden;
  height: 100%;
  min-height: 0;
  background: var(--panel);
  border-left: 1px solid var(--line);
  display: none;
}
body.genie-open .genie { display: block; }
.genie-missing { padding: 20px 18px; color: var(--muted); }
.gm-title { color: var(--text); font-weight: 600; margin-bottom: 6px; }

/* Cards and tables */
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 12px 14px;
  min-width: 0;
}
.card.flush { padding: 0; overflow-x: auto; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.link { font-size: 12px; text-decoration: none; }
.link:hover { text-decoration: underline; }

.tbl { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.tbl th {
  text-align: left; font-weight: 500; color: var(--muted); font-size: 11px;
  text-transform: uppercase; letter-spacing: 0.04em;
  padding: 6px 8px; border-bottom: 1px solid var(--line);
}
.tbl td { padding: 7px 8px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: none; }
.tbl .r { text-align: right; }
.tbl.compact td { padding: 5px 8px; }
.tbl.alerts tr.acked td { color: var(--muted); }
.tbl.alerts tr[data-sev="critical"]:not(.acked) td:first-child { box-shadow: inset 3px 0 0 var(--crit); }
.tbl.alerts tr[data-sev="warning"]:not(.acked) td:first-child { box-shadow: inset 3px 0 0 var(--warn); }
.tbl.alerts tr[data-sev="minor"]:not(.acked) td:first-child { box-shadow: inset 3px 0 0 var(--minor); }
.acked-label { color: var(--ok); }

.pill {
  display: inline-block; font-size: 11.5px; font-weight: 500; line-height: 1.5;
  padding: 0 8px; border-radius: 10px; white-space: nowrap;
}
.pill[data-sev="normal"] { background: var(--ok-bg); color: var(--ok); }
.pill[data-sev="warning"] { background: var(--warn-bg); color: var(--warn); }
.pill[data-sev="critical"] { background: var(--crit-bg); color: var(--crit); }
.pill[data-sev="minor"] { background: var(--minor-bg); color: var(--minor); }
.pill[data-sev="info"] { background: var(--info-bg); color: var(--info); }

.chip {
  display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px;
  padding: 0 7px; border-radius: 3px; border: 1px solid var(--line); white-space: nowrap;
}
.chip::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: var(--standby); }
.chip[data-state="running"]::before { background: var(--ok); }

.bar { height: 4px; background: var(--line-soft); border-radius: 2px; overflow: hidden; margin-top: 6px; }
.bar-fill { height: 100%; width: 0; background: var(--ok); transition: width 0.6s ease; }
.bar-fill[data-sev="warning"] { background: var(--warn); }
.bar-fill[data-sev="critical"] { background: var(--crit); }

/* Overview */
.kpis { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 10px; }
.kpi {
  background: var(--panel); border: 1px solid var(--line); border-radius: 6px;
  padding: 10px 12px; position: relative; min-width: 0;
}
.kpi[data-sev="warning"] { border-top: 2px solid var(--warn); }
.kpi[data-sev="critical"] { border-top: 2px solid var(--crit); }
.kpi-label { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; }
.kpi-value { display: flex; align-items: baseline; gap: 4px; margin: 2px 0; }
.kpi-value .num { font-size: 26px; font-weight: 500; }
.unit { color: var(--muted); font-size: 12px; margin-left: 3px; }
.kpi-sub { color: var(--muted); font-size: 11.5px; }
.spark { width: 100%; height: 28px; margin-top: 6px; display: block; }
.spark polyline { fill: none; stroke: var(--accent); stroke-width: 1.5; vector-effect: non-scaling-stroke; }
.kpi[data-sev="warning"] .spark polyline { stroke: var(--warn); }

.ov-grid { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); gap: 14px; align-items: start; }
.ov-col { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.redundancy-line { margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--line-soft); display: flex; gap: 8px; align-items: center; flex-wrap: wrap; font-size: 12px; }

.events { display: flex; flex-direction: column; max-height: 560px; }
.feed { list-style: none; margin: 0; padding: 0; overflow: auto; }
.feed li {
  display: grid; grid-template-columns: 64px 10px 1fr; gap: 8px; align-items: baseline;
  padding: 6px 2px; border-bottom: 1px solid var(--line-soft); font-size: 12.5px;
}
.feed time { color: var(--muted); font-size: 11.5px; }
.sev-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--info); align-self: center; }
.feed li[data-sev="critical"] .sev-dot { background: var(--crit); }
.feed li[data-sev="warning"] .sev-dot { background: var(--warn); }
.feed li[data-sev="minor"] .sev-dot { background: var(--minor); }
.feed li:first-child { animation: flash 1.2s ease-out; }
@keyframes flash { from { background: var(--info-bg); } to { background: transparent; } }

/* Data hall */
.hall-grid { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 14px; align-items: start; }
.floor-wrap { overflow-x: auto; }
#floor { width: 100%; min-width: 640px; height: auto; display: block; font-family: var(--sans); }
#floor .room { fill: var(--panel-2); stroke: var(--line); stroke-width: 1.5; }
#floor .room-label { fill: var(--muted); font-size: 11px; }
#floor .aisle.cold { fill: var(--cold); }
#floor .aisle.hot { fill: var(--hot); }
#floor .aisle-label { fill: var(--muted); font-size: 10px; letter-spacing: 0.2em; text-anchor: middle; opacity: 0.8; }
#floor .row-label { fill: var(--text); font-size: 12px; font-weight: 600; text-anchor: end; }
#floor .door { stroke: var(--bg); stroke-width: 4; }
#floor .rack { cursor: pointer; outline: none; }
#floor .rack rect { stroke: rgba(0, 0, 0, 0.25); stroke-width: 1; transition: fill 0.8s ease; }
#floor .rack:hover rect { stroke: var(--text); stroke-width: 1.5; }
#floor .rack.sel rect { stroke: var(--text); stroke-width: 2.5; }
#floor .rack:focus-visible rect { stroke: var(--accent); stroke-width: 2.5; }
#floor .rk-id { font-size: 10px; font-weight: 600; text-anchor: middle; pointer-events: none; }
#floor .rk-t { font-size: 13px; font-family: var(--mono); text-anchor: middle; pointer-events: none; }
#floor .crah rect { fill: var(--panel); stroke: var(--line); stroke-width: 1.5; }
#floor .crah[data-sev="warning"] rect { stroke: var(--warn); fill: var(--warn-bg); }
#floor .crah text { text-anchor: middle; fill: var(--text); }
#floor .cr-id { font-size: 10.5px; font-weight: 600; }
#floor .cr-l { font-size: 9px; fill: var(--muted) !important; }
#floor .cr-t { font-size: 11px; font-family: var(--mono); }

.legend { display: flex; align-items: center; gap: 12px; margin-top: 8px; flex-wrap: wrap; }
.legend-title { color: var(--muted); font-size: 12px; }
.legend-svg { max-width: 100%; height: auto; font-family: var(--sans); }
.legend-svg .band { fill: none; stroke: var(--ok); stroke-width: 1.5; }
.legend-svg .band-label { fill: var(--ok); font-size: 10px; text-anchor: middle; }
.legend-svg .ticks line { stroke: var(--muted); }
.legend-svg .ticks text { fill: var(--muted); font-size: 10px; text-anchor: middle; font-family: var(--mono); }

.rd-meta { margin: -4px 0 10px; }
.rd { margin: 0; display: flex; flex-direction: column; gap: 12px; }
.rd dt { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; }
.rd dd { margin: 2px 0 0; }
.rd .big { font-size: 22px; font-weight: 500; }
.hint { color: var(--muted); font-size: 11.5px; }
.callout {
  margin-top: 14px; padding: 10px 12px; border-radius: 4px;
  background: var(--warn-bg); border-left: 3px solid var(--warn);
}
.callout p { margin: 0 0 8px; }

/* Cooling plant */
.plant-strip { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)) minmax(0, 2fr); gap: 10px; }
.ptile { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 10px 12px; min-width: 0; }
.ptile[data-sev="warning"] { border-top: 2px solid var(--warn); }
.ptile[data-sev="critical"] { border-top: 2px solid var(--crit); }
.ptile-val { font-size: 20px; margin: 2px 0; }
.ptile-val .pill { font-size: 13px; }

.chillers { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.chiller {
  background: var(--panel); border: 1px solid var(--line); border-radius: 6px;
  display: flex; flex-direction: column; min-width: 0;
  border-top: 3px solid var(--ok);
}
.chiller[data-sev="warning"] { border-top-color: var(--warn); }
.chiller[data-sev="critical"] { border-top-color: var(--crit); }
.ch-head { display: flex; justify-content: space-between; gap: 10px; padding: 12px 14px 8px; }
.ch-label { color: var(--muted); font-size: 11.5px; }
.ch-serial { font-size: 18px; font-weight: 600; word-break: break-all; }
.ch-badges { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.ch-alarm { margin: 0 14px; padding: 6px 10px; border-radius: 4px; font-size: 12.5px; background: var(--panel-2); color: var(--muted); }
.chiller[data-sev="warning"] .ch-alarm { background: var(--warn-bg); color: var(--warn); }
.chiller[data-sev="critical"] .ch-alarm { background: var(--crit-bg); color: var(--crit); font-weight: 500; }
.ch-metrics { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; padding: 12px 14px; }
.m-label { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; }
.m-val { font-size: 18px; }
.m-sub { color: var(--muted); font-size: 11.5px; }
.ch-foot {
  margin-top: auto; display: flex; justify-content: space-between; align-items: center;
  padding: 10px 14px; border-top: 1px solid var(--line-soft);
}

/* Alerts */
.toolbar { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.check { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--panel-2); color: var(--text); border: 1px solid var(--line);
  padding: 8px 14px; border-radius: 4px; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3); z-index: 50;
}
.toast[hidden] { display: none; }

/* Narrower desktops: let the grids wrap before they crush. */
@media (max-width: 1400px) {
  .plant-strip { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .ptile-wide { grid-column: span 3; }
}
@media (max-width: 1280px) {
  .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .chillers { grid-template-columns: 1fr; }
  .hall-grid { grid-template-columns: 1fr; }
  .ov-grid { grid-template-columns: 1fr; }
}

/* Phone: rail turns into a tab strip, Genie overlays the content. */
@media (max-width: 760px) {
  .topbar { flex-wrap: wrap; gap: 8px 12px; }
  .site { border-left: none; padding-left: 0; }
  .topbar-status { margin-left: 0; order: 3; width: 100%; flex-wrap: wrap; }
  .clock { margin-left: auto; }
  .btn-genie { margin-left: auto; }
  .shell, body.genie-open .shell { grid-template-columns: 1fr; grid-template-rows: auto minmax(0, 1fr); position: relative; }
  .rail { flex-direction: row; overflow-x: auto; border-right: none; border-bottom: 1px solid var(--line); padding: 6px 8px; }
  .rail a { white-space: nowrap; border-left: none; border-bottom: 2px solid transparent; gap: 6px; }
  .rail a[aria-current="page"] { border-bottom-color: var(--accent); }
  .rail-foot { display: none; }
  main { padding: 12px 16px; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .plant-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .ptile-wide { grid-column: span 2; }
  .genie { position: absolute; inset: 0; z-index: 20; border-left: none; }
  .card.flush, .card:has(> .tbl) { overflow-x: auto; }
}

/* Simulated chillers are marked on the tile so nobody asks Genie about a chiller it does not know. */
.chip-sim { color: var(--muted); border-style: dashed; }
.chip-sim::before { display: none; }
.ch-since { font-weight: 400; opacity: 0.85; white-space: nowrap; }
.m-state[data-sev="critical"] { color: var(--crit); }
.m-state[data-sev="warning"] { color: var(--warn); }
