/* ===========================================================================
   WOLF BMS — SCADA theme + layout
   =========================================================================== */
:root {
  --canvas-w: 2560px;
  --canvas-h: 1440px;
  --accent: 184; /* hue for accent (oklch) */
  --r: 4px;
  --gap: 14px;
}

/* ---- THEME: Dark Industrial (default) ---- */
[data-theme="dark"] {
  --bg0: #0a0d12;
  --bg1: #11151c;
  --bg2: #171c25;
  --bg3: #1e2430;
  --panel: #12161e;
  --panel-h: #161c26;
  --line: #28303d;
  --line-soft: #1d2430;
  --t0: #e9eef5;
  --t1: #9aa7b8;
  --t2: #647082;
  --t3: #44505f;
  --accent-c: oklch(0.74 0.13 var(--accent));
  --accent-dim: oklch(0.46 0.08 var(--accent));
  --accent-ink: oklch(0.16 0.03 var(--accent));
  --ok: oklch(0.76 0.16 152);
  --ok-dim: oklch(0.42 0.09 152);
  --warn: oklch(0.80 0.15 78);
  --warn-dim: oklch(0.46 0.09 78);
  --alarm: oklch(0.66 0.21 26);
  --alarm-dim: oklch(0.42 0.13 26);
  --info: oklch(0.74 0.12 230);
  --idle: #4a5666;
  --grid-line: rgba(255, 255, 255, 0.035);
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
  --inset: inset 0 1px 0 rgba(255, 255, 255, 0.03);
}

/* ---- THEME: Blueprint (light technical) ---- */
[data-theme="blueprint"] {
  --bg0: #dfe6ef;
  --bg1: #e9eef5;
  --bg2: #f2f5f9;
  --bg3: #ffffff;
  --panel: #f5f8fc;
  --panel-h: #ffffff;
  --line: #b9c6d8;
  --line-soft: #cdd8e6;
  --t0: #122033;
  --t1: #41526a;
  --t2: #66788f;
  --t3: #8c9bb0;
  --accent-c: oklch(0.52 0.15 245);
  --accent-dim: oklch(0.74 0.07 245);
  --accent-ink: oklch(0.97 0.01 245);
  --ok: oklch(0.55 0.15 152);
  --ok-dim: oklch(0.80 0.08 152);
  --warn: oklch(0.62 0.15 70);
  --warn-dim: oklch(0.82 0.09 70);
  --alarm: oklch(0.55 0.20 26);
  --alarm-dim: oklch(0.82 0.10 26);
  --info: oklch(0.52 0.13 245);
  --idle: #9aa9bd;
  --grid-line: rgba(40, 80, 140, 0.06);
  --shadow: 0 2px 10px rgba(40, 70, 110, 0.10);
  --inset: inset 0 1px 0 rgba(255, 255, 255, 0.6);
}

/* ---- THEME: Hybrid (dark warm) ---- */
[data-theme="hybrid"] {
  --bg0: #0d0c0f;
  --bg1: #16141a;
  --bg2: #1d1a22;
  --bg3: #251f2c;
  --panel: #17141b;
  --panel-h: #1c1822;
  --line: #322b3a;
  --line-soft: #241f2b;
  --t0: #efe9f2;
  --t1: #a99fb3;
  --t2: #6f6679;
  --t3: #4e4756;
  --accent-c: oklch(0.74 0.14 var(--accent));
  --accent-dim: oklch(0.46 0.09 var(--accent));
  --accent-ink: oklch(0.16 0.03 var(--accent));
  --ok: oklch(0.76 0.15 158);
  --ok-dim: oklch(0.44 0.09 158);
  --warn: oklch(0.81 0.15 80);
  --warn-dim: oklch(0.48 0.10 80);
  --alarm: oklch(0.67 0.21 22);
  --alarm-dim: oklch(0.44 0.13 22);
  --info: oklch(0.74 0.12 280);
  --idle: #564f60;
  --grid-line: rgba(255, 255, 255, 0.03);
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
  --inset: inset 0 1px 0 rgba(255, 255, 255, 0.03);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  width: 100%; height: 100%;
  background: #000;
  overflow: hidden;
  font-family: "IBM Plex Sans", "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

#stage {
  position: fixed; inset: 0;
  background: var(--bg0, #000);
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
#canvas {
  width: var(--canvas-w); height: var(--canvas-h);
  flex: 0 0 auto;            /* never let the flex stage shrink the fixed canvas */
  transform-origin: center center;
  background: var(--bg0);
  color: var(--t0);
  position: relative;
  display: grid;
  grid-template-columns: 264px minmax(0, 1fr);
  grid-template-rows: 66px minmax(0, 1fr) 34px;
  grid-template-areas: "logo topbar" "nav main" "nav status";
  font-size: 15px;
}

.mono { font-family: "IBM Plex Mono", "SFMono-Regular", monospace; font-feature-settings: "tnum" 1; }
.up { text-transform: uppercase; letter-spacing: 0.08em; }

/* ====================== TOP BAR ====================== */
.brand {
  grid-area: logo;
  background: var(--bg1);
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 12px;
  padding: 0 18px;
}
.brand .mark {
  width: 38px; height: 38px; border-radius: 5px;
  background: var(--accent-c); color: var(--accent-ink);
  display: grid; place-items: center;
  font-weight: 700; font-size: 20px; letter-spacing: -0.04em;
  box-shadow: var(--inset);
  position: relative; overflow: hidden;
}
.brand .mark::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(135deg, transparent 60%, rgba(0,0,0,0.18));
}
.brand .name { font-weight: 700; font-size: 18px; letter-spacing: 0.02em; color: var(--t0); line-height: 1; }
.brand .sub { font-size: 10.5px; color: var(--t2); letter-spacing: 0.16em; margin-top: 3px; }

.topbar {
  grid-area: topbar;
  background: var(--bg1);
  border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 10px;
  padding: 0 16px 0 8px;
}
.proj-tabs { display: flex; gap: 4px; height: 100%; align-items: stretch; }
.proj-tab {
  display: flex; flex-direction: column; justify-content: center;
  padding: 0 18px; border: none; background: none; cursor: pointer;
  border-bottom: 2px solid transparent; color: var(--t2);
  font-family: inherit; gap: 2px; min-width: 150px; position: relative;
}
.proj-tab:hover { background: var(--bg2); color: var(--t1); }
.proj-tab.active { color: var(--t0); border-bottom-color: var(--accent-c); background: var(--bg2); }
.proj-tab .pt-name { font-size: 14px; font-weight: 600; }
.proj-tab .pt-kind { font-size: 10.5px; color: var(--t2); letter-spacing: 0.08em; }
.proj-tab .pt-dot { position: absolute; top: 12px; right: 12px; width: 7px; height: 7px; border-radius: 50%; }

.topbar .spacer { flex: 1; }
.tb-stat { display: flex; flex-direction: column; align-items: flex-end; padding: 0 14px; border-left: 1px solid var(--line-soft); height: 44px; justify-content: center; white-space: nowrap; }
.tb-stat .v { font-size: 16px; font-weight: 600; }
.tb-stat .l { font-size: 9.5px; color: var(--t2); letter-spacing: 0.12em; text-transform: uppercase; }
.tb-clock { text-align: right; padding-left: 14px; }
.tb-clock .time { font-size: 19px; font-weight: 600; }
.tb-clock .date { font-size: 10.5px; color: var(--t2); letter-spacing: 0.1em; white-space: nowrap; }

.conn { display: flex; align-items: center; gap: 7px; padding: 5px 11px; border: 1px solid var(--line); border-radius: 100px; }
.conn .led { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 8px var(--ok); animation: pulse 2.4s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.4; } }
.conn .txt { font-size: 11px; color: var(--t1); letter-spacing: 0.06em; white-space: nowrap; }

.user-chip { display: flex; align-items: center; gap: 9px; padding-left: 6px; }
.user-chip .av { width: 32px; height: 32px; border-radius: 50%; background: var(--bg3); border: 1px solid var(--line); display: grid; place-items: center; font-size: 12px; font-weight: 600; color: var(--t1); }

/* ====================== NAV ====================== */
.nav {
  grid-area: nav;
  background: var(--bg1);
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
  overflow: hidden;
}
.nav-proj { padding: 16px 18px 14px; border-bottom: 1px solid var(--line); }
.nav-proj .np-name { font-size: 16px; font-weight: 700; }
.nav-proj .np-loc { font-size: 11px; color: var(--t2); margin-top: 3px; letter-spacing: 0.04em; }
.nav-proj .np-meta { display: flex; gap: 6px; margin-top: 11px; flex-wrap: wrap; }
.chip { font-size: 10px; padding: 3px 8px; border-radius: 3px; background: var(--bg3); color: var(--t1); border: 1px solid var(--line-soft); letter-spacing: 0.04em; }
.chip.proto { color: var(--accent-c); border-color: var(--accent-dim); }

.nav-sec { padding: 14px 12px 4px 18px; font-size: 10px; letter-spacing: 0.16em; color: var(--t3); text-transform: uppercase; }
.nav-list { display: flex; flex-direction: column; gap: 1px; padding: 0 8px; }
.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; border-radius: var(--r); cursor: pointer;
  color: var(--t1); border: none; background: none; font-family: inherit;
  font-size: 13.5px; text-align: left; width: 100%; position: relative;
}
.nav-item:hover { background: var(--bg2); color: var(--t0); }
.nav-item.active { background: var(--accent-ink); color: var(--accent-c); }
.nav-item.active::before { content: ""; position: absolute; left: 0; top: 8px; bottom: 8px; width: 3px; border-radius: 2px; background: var(--accent-c); }
.nav-item .ico { width: 18px; height: 18px; flex: 0 0 18px; display: grid; place-items: center; }
.nav-item .lbl { flex: 1; }
.nav-item .badge { font-size: 10px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; display: grid; place-items: center; background: var(--alarm); color: #fff; font-weight: 600; }
.nav-item .badge.warn { background: var(--warn); color: #1a1400; }

.nav-foot { margin-top: auto; padding: 14px 18px; border-top: 1px solid var(--line); }
.nav-foot .sim { display: flex; align-items: center; gap: 8px; font-size: 11px; color: var(--t2); }

/* ====================== MAIN ====================== */
.main {
  grid-area: main;
  min-width: 0; min-height: 0;
  background: var(--bg0);
  background-image: linear-gradient(var(--grid-line) 1px, transparent 1px), linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
  background-size: 32px 32px;
  overflow: auto; position: relative;
}
.view { padding: 18px; min-height: 100%; }
.view-head { display: flex; align-items: flex-end; justify-content: space-between; margin-bottom: 16px; }
.view-head h1 { font-size: 22px; font-weight: 700; letter-spacing: 0.01em; }
.view-head .sub { font-size: 12px; color: var(--t2); margin-top: 3px; letter-spacing: 0.04em; }
.view-tools { display: flex; gap: 8px; align-items: center; }

/* panels */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--inset); }
.panel-h { padding: 11px 15px; border-bottom: 1px solid var(--line-soft); display: flex; align-items: center; justify-content: space-between; }
.panel-h .pt { font-size: 11px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--t2); font-weight: 600; }
.panel-h .pa { font-size: 11px; color: var(--t2); display: flex; gap: 8px; align-items: center; }
.panel-b { padding: 15px; }

/* status dot */
.sdot { width: 9px; height: 9px; border-radius: 50%; flex: 0 0 9px; }
.sdot.ok { background: var(--ok); box-shadow: 0 0 6px var(--ok-dim); }
.sdot.warn { background: var(--warn); box-shadow: 0 0 6px var(--warn-dim); }
.sdot.alarm { background: var(--alarm); box-shadow: 0 0 7px var(--alarm); animation: pulse 1.1s infinite; }
.sdot.idle { background: var(--idle); }
.sdot.info { background: var(--info); }

/* generic buttons */
.btn { font-family: inherit; font-size: 12px; padding: 7px 13px; border-radius: var(--r); border: 1px solid var(--line); background: var(--bg2); color: var(--t1); cursor: pointer; display: inline-flex; align-items: center; gap: 7px; letter-spacing: 0.02em; }
.btn:hover { background: var(--bg3); color: var(--t0); border-color: var(--accent-dim); }
.btn.pri { background: var(--accent-c); color: var(--accent-ink); border-color: transparent; font-weight: 600; }
.btn.pri:hover { filter: brightness(1.08); }
.btn.sm { padding: 5px 10px; font-size: 11px; }
.btn.danger { color: var(--alarm); border-color: var(--alarm-dim); }
.btn.danger:hover { background: var(--alarm-dim); color: #fff; }
.btn.active { background: var(--accent-ink); color: var(--accent-c); border-color: var(--accent-dim); }

.seg { display: inline-flex; border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; }
.seg button { font-family: inherit; font-size: 11.5px; padding: 6px 12px; background: var(--bg1); color: var(--t2); border: none; cursor: pointer; border-right: 1px solid var(--line); }
.seg button:last-child { border-right: none; }
.seg button.on { background: var(--accent-ink); color: var(--accent-c); }
.seg button:hover:not(.on) { background: var(--bg2); color: var(--t1); }

/* toggle switch */
.tgl { width: 42px; height: 23px; border-radius: 13px; background: var(--bg3); border: 1px solid var(--line); position: relative; cursor: pointer; transition: background 0.15s; flex: 0 0 42px; }
.tgl::after { content: ""; position: absolute; top: 2px; left: 2px; width: 17px; height: 17px; border-radius: 50%; background: var(--t2); transition: 0.15s; }
.tgl.on { background: var(--accent-dim); border-color: var(--accent-c); }
.tgl.on::after { left: 21px; background: var(--accent-c); }

/* range slider */
.rng { -webkit-appearance: none; appearance: none; width: 100%; height: 6px; border-radius: 3px; background: var(--bg3); outline: none; cursor: pointer; }
.rng::-webkit-slider-thumb { -webkit-appearance: none; width: 16px; height: 16px; border-radius: 50%; background: var(--accent-c); border: 2px solid var(--bg1); box-shadow: 0 0 0 1px var(--accent-dim); }
.rng::-moz-range-thumb { width: 16px; height: 16px; border-radius: 50%; background: var(--accent-c); border: 2px solid var(--bg1); }

/* KPI strip */
.kpi-row { display: grid; grid-template-columns: repeat(6, 1fr); gap: var(--gap); margin-bottom: var(--gap); }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 14px 16px; position: relative; overflow: hidden; box-shadow: var(--inset); }
.kpi .k-l { font-size: 10.5px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--t2); display: flex; align-items: center; gap: 7px; }
.kpi .k-v { font-size: 30px; font-weight: 600; margin-top: 8px; letter-spacing: -0.01em; line-height: 1; }
.kpi .k-v small { font-size: 14px; color: var(--t2); font-weight: 500; margin-left: 3px; }
.kpi .k-d { font-size: 11px; margin-top: 7px; display: flex; align-items: center; gap: 6px; color: var(--t2); }
.kpi.accent { border-color: var(--accent-dim); }
.kpi.accent .k-v { color: var(--accent-c); }
.kpi.savings { background: linear-gradient(160deg, var(--accent-ink), var(--panel)); border-color: var(--accent-dim); }
.kpi.savings .k-v { color: var(--ok); }
.kpi .spark { position: absolute; right: 12px; bottom: 10px; opacity: 0.8; }
.delta-up { color: var(--ok); }
.delta-dn { color: var(--alarm); }

/* grids */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--gap); }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--gap); }
.cols-main { display: grid; grid-template-columns: 1.7fr 1fr; gap: var(--gap); }

/* status bar (bottom) */
.statusbar {
  grid-area: status;
  background: var(--bg1);
  border-top: 1px solid var(--line);
  display: flex; align-items: center; gap: 0; font-size: 11px; color: var(--t2);
  padding: 0;
}
.statusbar .sb { padding: 0 14px; height: 100%; display: flex; align-items: center; gap: 7px; border-right: 1px solid var(--line-soft); letter-spacing: 0.04em; }
.statusbar .sb.scroll { flex: 1; overflow: hidden; border-right: none; }
.ticker { display: inline-flex; gap: 40px; white-space: nowrap; animation: tick 38s linear infinite; }
@keyframes tick { from { transform: translateX(0); } to { transform: translateX(-50%); } }
.ticker span { color: var(--t1); }

/* subsystem tile */
.sys-tile { padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.sys-tile .st-h { display: flex; align-items: center; justify-content: space-between; }
.sys-tile .st-name { font-size: 13px; font-weight: 600; display: flex; gap: 9px; align-items: center; }
.sys-tile .st-val { font-size: 24px; font-weight: 600; }
.sys-tile .st-sub { font-size: 11px; color: var(--t2); }
.sys-tile .bar { height: 5px; border-radius: 3px; background: var(--bg3); overflow: hidden; }
.sys-tile .bar i { display: block; height: 100%; border-radius: 3px; }

/* tables */
table.tbl { width: 100%; border-collapse: collapse; font-size: 12.5px; }
table.tbl th { text-align: left; font-size: 10px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--t2); font-weight: 600; padding: 9px 12px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--panel); }
table.tbl td { padding: 10px 12px; border-bottom: 1px solid var(--line-soft); color: var(--t1); }
table.tbl tr:hover td { background: var(--bg2); }
.prio-pill { font-size: 9.5px; font-weight: 700; padding: 2px 7px; border-radius: 3px; letter-spacing: 0.08em; text-transform: uppercase; }
.prio-high { background: var(--alarm); color: #fff; }
.prio-med { background: var(--warn); color: #1a1400; }
.prio-low { background: var(--bg3); color: var(--t1); border: 1px solid var(--line); }
.st-tag { font-size: 10px; padding: 2px 8px; border-radius: 3px; text-transform: uppercase; letter-spacing: 0.06em; }
.st-active { color: var(--alarm); border: 1px solid var(--alarm-dim); }
.st-ack { color: var(--warn); border: 1px solid var(--warn-dim); }
.st-cleared { color: var(--t2); border: 1px solid var(--line); }

/* floorplan */
.fp-wrap { position: relative; width: 100%; background: var(--bg1); border-radius: var(--r); overflow: hidden; }
.fp-room { position: absolute; border: 1px solid var(--line); border-radius: 2px; cursor: pointer; overflow: hidden; transition: outline 0.1s; background: var(--bg2); }
.fp-room:hover { outline: 2px solid var(--accent-c); z-index: 4; }
.fp-room.sel { outline: 2px solid var(--accent-c); z-index: 3; }
.fp-room .rl { position: absolute; top: 6px; left: 8px; font-size: 11px; font-weight: 600; color: var(--t0); text-shadow: 0 1px 2px rgba(0,0,0,0.5); }
.fp-room .rv { position: absolute; bottom: 6px; left: 8px; font-size: 13px; white-space: nowrap; }
.fp-room .ri { position: absolute; top: 6px; right: 7px; display: flex; gap: 4px; }
.fp-corr { position: absolute; background: var(--bg0); border: 1px dashed var(--line); display: grid; place-items: center; color: var(--t3); font-size: 10px; letter-spacing: 0.2em; }
.fp-legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 11px; color: var(--t1); }
.fp-legend .lg { display: flex; align-items: center; gap: 6px; }

.mini-room-ico { width: 14px; height: 14px; display: grid; place-items: center; border-radius: 2px; font-size: 9px; }

/* room detail */
.rd-grid { display: grid; grid-template-columns: 320px 1fr; gap: var(--gap); }
.ctrl-row { display: flex; align-items: center; justify-content: space-between; padding: 13px 0; border-bottom: 1px solid var(--line-soft); }
.ctrl-row:last-child { border-bottom: none; }
.ctrl-row .cl { font-size: 13px; color: var(--t1); }
.ctrl-row .cl small { display: block; font-size: 10.5px; color: var(--t3); margin-top: 2px; }
.big-num { font-size: 46px; font-weight: 600; letter-spacing: -0.02em; }
.setpoint-ctl { display: flex; align-items: center; gap: 14px; }
.step-btn { width: 38px; height: 38px; border-radius: var(--r); border: 1px solid var(--line); background: var(--bg2); color: var(--t0); font-size: 20px; cursor: pointer; display: grid; place-items: center; }
.step-btn:hover { border-color: var(--accent-c); color: var(--accent-c); }

/* scheduler */
.sched-grid { display: grid; grid-template-columns: 120px repeat(7, 1fr); border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; }
.sched-grid .sh { background: var(--bg2); padding: 9px; font-size: 11px; text-align: center; color: var(--t2); border-bottom: 1px solid var(--line); border-right: 1px solid var(--line-soft); letter-spacing: 0.04em; }
.sched-grid .rh { background: var(--bg1); padding: 10px 12px; font-size: 12px; color: var(--t1); border-bottom: 1px solid var(--line-soft); border-right: 1px solid var(--line); display: flex; flex-direction: column; gap: 2px; }
.sched-cell { position: relative; height: 46px; border-bottom: 1px solid var(--line-soft); border-right: 1px solid var(--line-soft); background: var(--bg0); }
.sched-block { position: absolute; top: 5px; bottom: 5px; border-radius: 3px; font-size: 9px; color: var(--accent-ink); display: grid; place-items: center; overflow: hidden; cursor: pointer; }

/* trending */
.legend-row { display: flex; gap: 16px; flex-wrap: wrap; align-items: center; }
.lg-item { display: flex; align-items: center; gap: 7px; font-size: 12px; color: var(--t1); cursor: pointer; user-select: none; }
.lg-item .sw { width: 22px; height: 3px; border-radius: 2px; }
.lg-item.off { opacity: 0.38; }
.lg-item.off .sw { background: var(--t3) !important; }

/* energy bars */
.ebar-row { display: grid; grid-template-columns: 130px 1fr 80px; gap: 12px; align-items: center; padding: 9px 0; }
.ebar-row .en { font-size: 12.5px; color: var(--t1); }
.ebar-track { height: 18px; background: var(--bg0); border-radius: 3px; overflow: hidden; display: flex; position: relative; border: 1px solid var(--line-soft); }
.ebar-track .real { background: var(--accent-c); height: 100%; }
.ebar-track .saved { background: var(--ok-dim); height: 100%; opacity: 0.55; }
.ebar-row .ev { font-size: 12.5px; text-align: right; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--bg0); }
::-webkit-scrollbar-thumb { background: var(--line); border-radius: 5px; border: 2px solid var(--bg0); }
::-webkit-scrollbar-thumb:hover { background: var(--t3); }

.flash { animation: flash 0.6s ease; }
@keyframes flash { 0% { background: var(--accent-ink); } 100% { background: transparent; } }
