:root {
  --bg: #070b10;
  --bg-2: #0b1118;
  --panel: #0e151d;
  --panel-2: #121b25;
  --line: #1c2834;
  --line-2: #26364a;
  --text: #d6dee8;
  --text-2: #9aa9b9;
  --muted: #6c7c8e;
  --c-pv: #f2b544;
  --c-bat: #3ddc97;
  --c-load: #38c6f4;
  --c-grid: #9b8cff;
  --c-alarm: #ff5d5d;
  --c-warn: #f5a524;
  --c-ok: #3ddc97;
  --c-curt: #ff7a59;
  --accent: #38c6f4;
  --font-body: 'Geist', 'Segoe UI', system-ui, sans-serif;
  --font-mono: 'Geist Mono', ui-monospace, 'Consolas', monospace;
  --r: 8px;
  --side-w: 340px;
  --top-h: 58px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
.mono, .num { font-family: var(--font-mono); font-variant-numeric: tabular-nums lining-nums; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
a { color: var(--accent); }
button { font-family: inherit; }

/* ---------- Top bar ---------- */
.topbar {
  height: var(--top-h);
  display: flex; align-items: center; gap: 20px;
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #0c131b, #0a1016);
  position: relative; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--accent); min-width: 0; }
.brand-name { font-weight: 700; letter-spacing: .08em; font-size: 15px; color: var(--text); }
.brand-sub { font-size: 12px; color: var(--muted); white-space: nowrap; }
.mode-switch { display: flex; background: var(--bg); border: 1px solid var(--line-2); border-radius: 8px; padding: 3px; gap: 3px; }
.mode-switch button {
  display: flex; align-items: center; gap: 7px;
  background: transparent; color: var(--text-2); border: 0; border-radius: 6px;
  padding: 7px 14px; font-size: 13px; font-weight: 600; cursor: pointer; transition: background .18s, color .18s;
}
.mode-switch button:hover { color: var(--text); }
.mode-switch button.active { background: var(--panel-2); color: var(--accent); box-shadow: inset 0 0 0 1px var(--line-2); }
.status-bar { margin-left: auto; display: flex; gap: 8px; align-items: center; min-width: 0; }
.chip {
  display: inline-flex; align-items: center; gap: 7px; padding: 5px 10px; border-radius: 6px;
  border: 1px solid var(--line); background: var(--bg-2); color: var(--text-2); font-size: 12px; white-space: nowrap; max-width: 260px; overflow: hidden; text-overflow: ellipsis;
}
.led { width: 7px; height: 7px; border-radius: 50%; background: var(--c-ok); box-shadow: 0 0 6px var(--c-ok); flex: none; }
.led.warn { background: var(--c-warn); box-shadow: 0 0 6px var(--c-warn); }
.led.off { background: var(--muted); box-shadow: none; }
.led.blink { animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: .25; } }

.btn {
  border: 1px solid var(--line-2); background: var(--panel-2); color: var(--text);
  border-radius: 6px; padding: 7px 12px; font-size: 13px; cursor: pointer; transition: border-color .15s, background .15s;
}
.btn:hover { border-color: var(--accent); }
.btn.ghost { background: transparent; }
.btn.small { padding: 4px 9px; font-size: 12px; }
.btn.icon { width: 34px; height: 34px; padding: 0; display: grid; place-items: center; color: var(--accent); }
.btn:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.only-mobile { display: none; }

/* ---------- Shell ---------- */
.shell { display: grid; grid-template-columns: var(--side-w) 1fr; height: calc(100dvh - var(--top-h)); }
.sidebar {
  border-right: 1px solid var(--line); background: var(--bg-2);
  overflow-y: auto; overscroll-behavior: contain; padding-bottom: 40px;
}
.side-head {
  position: sticky; top: 0; z-index: 3; display: flex; justify-content: space-between; align-items: center;
  padding: 12px 14px; background: var(--bg-2); border-bottom: 1px solid var(--line);
  font-size: 12px; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); font-weight: 600;
}
.main { overflow-y: auto; overscroll-behavior: contain; padding: 14px; display: flex; flex-direction: column; gap: 14px; }

/* ---------- Form groups ---------- */
.grp { border-bottom: 1px solid var(--line); }
.grp > summary {
  list-style: none; cursor: pointer; display: flex; align-items: center; gap: 10px;
  padding: 11px 14px; font-weight: 600; font-size: 13px; color: var(--text); user-select: none;
}
.grp > summary::-webkit-details-marker { display: none; }
.grp > summary .gi { width: 22px; height: 22px; display: grid; place-items: center; border-radius: 5px; background: var(--panel-2); border: 1px solid var(--line-2); flex: none; }
.grp > summary .gsum { margin-left: auto; font-family: var(--font-mono); font-size: 12px; color: var(--muted); font-weight: 500; }
.grp > summary .chev { width: 10px; height: 10px; border-right: 1.5px solid var(--muted); border-bottom: 1.5px solid var(--muted); transform: rotate(-45deg); transition: transform .2s; flex: none; }
.grp[open] > summary .chev { transform: rotate(45deg); }
.grp-body { padding: 4px 14px 14px; display: flex; flex-direction: column; gap: 9px; }
.field { display: grid; grid-template-columns: 1fr 112px; align-items: center; gap: 8px; }
.field label { font-size: 12.5px; color: var(--text-2); }
.field .help { display: block; font-size: 11.5px; color: var(--muted); }
.inp { position: relative; display: flex; align-items: center; }
.inp input, .inp select, .full-inp {
  width: 100%; background: var(--bg); border: 1px solid var(--line-2); color: var(--text);
  border-radius: 5px; padding: 6px 8px; font-family: var(--font-mono); font-size: 13px; font-variant-numeric: tabular-nums;
}
.inp input { padding-right: 40px; text-align: right; }
.inp select { font-family: var(--font-body); font-size: 12.5px; }
.inp .unit { position: absolute; right: 7px; font-size: 11px; color: var(--muted); pointer-events: none; font-family: var(--font-mono); }
.field.range { grid-template-columns: 1fr 112px; }
.field.range input[type=range] { grid-column: 1 / -1; }
input[type=range] { -webkit-appearance: none; appearance: none; width: 100%; height: 18px; background: transparent; }
input[type=range]::-webkit-slider-runnable-track { height: 4px; border-radius: 2px; background: linear-gradient(90deg, var(--accent) var(--p, 50%), var(--line-2) var(--p, 50%)); }
input[type=range]::-moz-range-track { height: 4px; border-radius: 2px; background: var(--line-2); }
input[type=range]::-moz-range-progress { height: 4px; background: var(--accent); }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 14px; height: 14px; border-radius: 50%; background: var(--bg); border: 2px solid var(--accent); margin-top: -5px; }
input[type=range]::-moz-range-thumb { width: 12px; height: 12px; border-radius: 50%; background: var(--bg); border: 2px solid var(--accent); }
.toggle { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 12.5px; color: var(--text-2); }
.switch { position: relative; width: 36px; height: 20px; flex: none; }
.switch input { opacity: 0; width: 100%; height: 100%; position: absolute; margin: 0; cursor: pointer; z-index: 1; }
.switch span { position: absolute; inset: 0; border-radius: 10px; background: var(--line-2); transition: background .2s; }
.switch span::after { content: ''; position: absolute; top: 3px; left: 3px; width: 14px; height: 14px; border-radius: 50%; background: var(--text-2); transition: transform .2s, background .2s; }
.switch input:checked + span { background: rgba(56, 198, 244, .35); }
.switch input:checked + span::after { transform: translateX(16px); background: var(--accent); }
.subhead { font-size: 11px; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); margin-top: 6px; padding-top: 8px; border-top: 1px dashed var(--line); }
.month-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.month-grid label { font-size: 11px; color: var(--muted); display: block; margin-bottom: 2px; }
.month-grid input { width: 100%; background: var(--bg); border: 1px solid var(--line-2); color: var(--text); border-radius: 5px; padding: 5px 6px; font-family: var(--font-mono); font-size: 12px; text-align: right; }
.loc-search { display: flex; gap: 6px; }
.loc-results { display: flex; flex-direction: column; gap: 2px; }
.loc-results button { text-align: left; background: var(--panel); border: 1px solid var(--line); color: var(--text-2); padding: 6px 8px; border-radius: 5px; font-size: 12px; cursor: pointer; }
.loc-results button:hover { border-color: var(--accent); color: var(--text); }
.presets { display: flex; flex-wrap: wrap; gap: 5px; }
.presets button { background: var(--bg); border: 1px solid var(--line-2); color: var(--text-2); border-radius: 12px; padding: 3px 9px; font-size: 11.5px; cursor: pointer; }
.presets button:hover { color: var(--text); border-color: var(--accent); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }

/* ---------- Panels ---------- */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); min-width: 0; }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 9px 12px; border-bottom: 1px solid var(--line); min-height: 42px; }
.ph-title { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 13px; }
.ph-tools { display: flex; gap: 6px; flex-wrap: wrap; }
.tag { font-family: var(--font-mono); font-size: 10.5px; padding: 2px 6px; border-radius: 4px; background: rgba(56,198,244,.12); color: var(--accent); border: 1px solid rgba(56,198,244,.25); letter-spacing: .05em; }
.tag.warn { background: rgba(245,165,36,.12); color: var(--c-warn); border-color: rgba(245,165,36,.3); }
.legend-pill { display: inline-flex; align-items: center; gap: 6px; font-size: 11.5px; color: var(--text-2); }
.legend-pill i { width: 14px; height: 3px; border-radius: 2px; display: inline-block; }

/* KPI */
.kpis { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 10px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 11px 13px; position: relative; overflow: hidden; min-width: 0; }
.kpi::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--kc, var(--accent)); }
.kpi .k-l { font-size: 11.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi .k-v { font-family: var(--font-mono); font-size: 22px; font-weight: 600; margin-top: 3px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.kpi .k-v small { font-size: 12px; color: var(--text-2); font-weight: 500; margin-left: 3px; }
.kpi .k-s { font-size: 12px; color: var(--text-2); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* SCADA */
.scada-row { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 14px; }
.side-stack { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.diagram-wrap {
  background:
    linear-gradient(rgba(56,198,244,.035) 1px, transparent 1px) 0 0 / 20px 20px,
    linear-gradient(90deg, rgba(56,198,244,.035) 1px, transparent 1px) 0 0 / 20px 20px,
    radial-gradient(ellipse at 40% 20%, #0f1c28 0%, #090e14 70%);
  border-bottom: 1px solid var(--line);
}
#diagram { display: block; width: 100%; height: auto; }
.transport { display: flex; gap: 14px; align-items: center; padding: 10px 12px; flex-wrap: wrap; }
.months { display: flex; gap: 3px; flex-wrap: wrap; }
.months button { background: var(--bg); border: 1px solid var(--line); color: var(--text-2); font-family: var(--font-mono); font-size: 11.5px; padding: 5px 7px; border-radius: 4px; cursor: pointer; min-width: 36px; }
.months button.active { color: var(--bg); background: var(--accent); border-color: var(--accent); font-weight: 600; }
.hourctl { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 240px; }
.hourctl input { flex: 1; }
.hour-read { font-size: 15px; color: var(--accent); min-width: 48px; text-align: right; }

table.kv { width: 100%; border-collapse: collapse; font-size: 12.5px; }
table.kv td { padding: 5px 12px; border-bottom: 1px solid var(--line); }
table.kv tr:last-child td { border-bottom: 0; }
table.kv td:first-child { color: var(--text-2); }
table.kv td:last-child { text-align: right; font-family: var(--font-mono); font-variant-numeric: tabular-nums; white-space: nowrap; }
table.kv i.sw { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 7px; vertical-align: 0; }

.alarms { list-style: none; margin: 0; padding: 4px 0; max-height: 300px; overflow-y: auto; overscroll-behavior: contain; }
.alarms li { display: grid; grid-template-columns: 62px 1fr; gap: 8px; padding: 7px 12px; font-size: 12.5px; border-bottom: 1px solid var(--line); }
.alarms li:last-child { border-bottom: 0; }
.alarms .lv { font-family: var(--font-mono); font-size: 10.5px; padding: 2px 5px; border-radius: 3px; text-align: center; height: fit-content; font-weight: 600; }
.alarms .alarm .lv { background: rgba(255,93,93,.15); color: var(--c-alarm); border: 1px solid rgba(255,93,93,.4); }
.alarms .warn .lv { background: rgba(245,165,36,.13); color: var(--c-warn); border: 1px solid rgba(245,165,36,.35); }
.alarms .info .lv { background: rgba(56,198,244,.1); color: var(--accent); border: 1px solid rgba(56,198,244,.3); }
.alarms .ok .lv { background: rgba(61,220,151,.1); color: var(--c-ok); border: 1px solid rgba(61,220,151,.3); }
.alarms .code { font-family: var(--font-mono); color: var(--muted); font-size: 11px; margin-right: 6px; }

/* Charts */
.charts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.charts .wide { grid-column: 1 / -1; }
.chart-box { position: relative; height: 270px; padding: 10px; }
.chart-box.tall { height: 290px; }

/* Tech */
.tech { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }

/* Table */
.table-scroll { overflow-x: auto; }
table.data { border-collapse: collapse; width: 100%; font-size: 12px; min-width: 1400px; }
table.data th, table.data td { padding: 6px 9px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
table.data th { position: sticky; top: 0; background: var(--panel-2); color: var(--text-2); font-family: var(--font-body); font-weight: 600; font-size: 11.5px; vertical-align: bottom; line-height: 1.25; }
table.data th span { display: block; color: var(--muted); font-weight: 400; font-size: 10.5px; }
table.data td:first-child, table.data th:first-child { text-align: left; font-family: var(--font-body); position: sticky; left: 0; background: var(--panel); }
table.data th:first-child { background: var(--panel-2); z-index: 1; }
table.data tbody tr:hover td { background: #131e29; }
table.data tr.total td { font-weight: 600; color: var(--text); background: var(--panel-2); border-top: 1px solid var(--line-2); }
table.data tr.sel td { background: rgba(56,198,244,.07); }
.pos { color: var(--c-bat); } .neg { color: var(--c-curt); }

.method-body { padding: 4px 14px 10px; font-size: 13px; color: var(--text-2); max-width: 1100px; }
.method-body p { margin: 8px 0; }
.method-body b { color: var(--text); font-weight: 600; }
.foot { text-align: center; padding: 6px 0 14px; }

/* ---------- SVG diagram ---------- */
.flow { fill: none; stroke-linecap: round; stroke-linejoin: round; }
.flow-base { fill: none; stroke: #1d2a37; stroke-width: 7; stroke-linecap: round; stroke-linejoin: round; }
.flow-anim { fill: none; stroke-dasharray: 2 12; stroke-linecap: round; stroke-linejoin: round; animation: dash var(--dur, 1.2s) linear infinite; }
.flow-anim.rev { animation-direction: reverse; }
.flow-anim.idle { opacity: 0; animation: none; }
@keyframes dash { from { stroke-dashoffset: 28; } to { stroke-dashoffset: 0; } }
.fp-box { fill: #0c141c; stroke: var(--line-2); stroke-width: 1.2; }
.fp-title { fill: var(--text-2); font: 600 11px var(--font-body); letter-spacing: .06em; text-transform: uppercase; }
.fp-val { fill: var(--text); font: 600 17px var(--font-mono); }
.fp-sub { fill: var(--muted); font: 500 10.5px var(--font-mono); }
.svg-label { fill: var(--muted); font: 500 10.5px var(--font-mono); }
.svg-label-b { fill: var(--text-2); font: 600 11px var(--font-body); letter-spacing: .05em; }
@media (prefers-reduced-motion: reduce) { .flow-anim { animation: none; stroke-dasharray: none; opacity: .8; } .led.blink { animation: none; } }

/* ---------- Responsive ---------- */
@media (max-width: 1500px) { .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); } .tech { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 1280px) { .scada-row { grid-template-columns: 1fr; } .side-stack { display: grid; grid-template-columns: 1fr 1fr; } }
@media (max-width: 1100px) {
  body { overflow: auto; }
  .shell { display: block; height: auto; }
  .main { overflow: visible; }
  .only-mobile { display: inline-block; }
  .sidebar { position: fixed; top: var(--top-h); left: 0; bottom: 0; width: min(360px, 92vw); z-index: 30; transform: translateX(-102%); transition: transform .25s ease; }
  .sidebar.open { transform: none; box-shadow: 10px 0 40px rgba(0,0,0,.5); }
  .scrim { position: fixed; inset: var(--top-h) 0 0 0; background: rgba(0,0,0,.5); z-index: 25; opacity: 0; pointer-events: none; transition: opacity .2s; }
  .scrim.show { opacity: 1; pointer-events: auto; }
  .topbar { position: sticky; top: 0; }
  #chipLoc, #clock { display: none; }
}
@media (max-width: 760px) {
  .topbar { gap: 8px; padding: 0 10px; }
  .brand-sub, #chipData { display: none; }
  .brand-name { font-size: 13px; }
  .mode-switch button { padding: 6px 9px; font-size: 12px; }
  .mode-switch button svg { display: none; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi .k-v { font-size: 18px; }
  .side-stack, .charts, .tech { grid-template-columns: 1fr; }
  .main { padding: 10px; gap: 10px; }
  .ph-tools { display: none; }
  .chart-box { height: 240px; }
}
.brand-name { white-space: nowrap; }
@media (max-width: 760px) {
  .diagram-wrap { overflow-x: auto; overscroll-behavior-x: contain; }
  #diagram { min-width: 700px; }
  .brand svg { display: none; }
}

.field.sel { grid-template-columns: 1fr; gap: 4px; }
.field.sel select { width: 100%; }
