/* EPC web - design tokens, layout, components.  No external fonts or CDNs (private network). */
:root {
  color-scheme: light;
  --bg: #e9eef0;
  --surface: #ffffff;
  --surface-2: #f4f7f8;
  --line: #d3dcdf;
  --ink: #101c1e;
  --ink-2: #43555a;
  --ink-3: #6b7d82;
  --brand: #0e5a5c;
  --brand-ink: #ffffff;
  --brand-soft: #d8ecec;
  --rail: #0f2326;
  --rail-ink: #c9dadb;
  --rail-ink-2: #7f9a9d;
  --rail-active: #1b3a3e;
  --amber: #b45f06;
  --amber-soft: #fbe8cf;
  --good: #1f7a3d;
  --good-soft: #d9f0e0;
  --bad: #c02a2a;
  --bad-soft: #f8dcdc;
  --focus: #1971c2;
  --c1: #2a78d6; --c2: #eb6834; --c3: #1baf7a; --c4: #eda100;
  --c5: #e87ba4; --c6: #008300; --c7: #6250d6; --c8: #e34948;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --r: 6px;
  --gap: 16px;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --bg: #0b1213; --surface: #131d1f; --surface-2: #192528; --line: #26363a;
    --ink: #e3eced; --ink-2: #a9bcbf; --ink-3: #7f9498;
    --brand: #4fb5b0; --brand-ink: #07201f; --brand-soft: #173436;
    --rail: #091011; --rail-active: #14272a;
    --amber: #f0a23b; --amber-soft: #3a2a10; --good: #55c27a; --good-soft: #14301e;
    --bad: #ef6a6a; --bad-soft: #3b1a1a; --focus: #6aa9f0;
    --c1: #3987e5; --c2: #d95926; --c3: #199e70; --c4: #c98500;
    --c5: #d55181; --c6: #008300; --c7: #9085e9; --c8: #e66767;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b1213; --surface: #131d1f; --surface-2: #192528; --line: #26363a;
  --ink: #e3eced; --ink-2: #a9bcbf; --ink-3: #7f9498;
  --brand: #4fb5b0; --brand-ink: #07201f; --brand-soft: #173436;
  --rail: #091011; --rail-active: #14272a;
  --amber: #f0a23b; --amber-soft: #3a2a10; --good: #55c27a; --good-soft: #14301e;
  --bad: #ef6a6a; --bad-soft: #3b1a1a; --focus: #6aa9f0;
  --c1: #3987e5; --c2: #d95926; --c3: #199e70; --c4: #c98500;
  --c5: #d55181; --c6: #008300; --c7: #9085e9; --c8: #e66767;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.5 var(--font); -webkit-font-smoothing: antialiased;
  font-variant-numeric: tabular-nums;
}
h1, h2, h3 { line-height: 1.2; margin: 0; font-weight: 650; letter-spacing: -0.01em; }
h1 { font-size: 1.5rem; } h2 { font-size: 1.1rem; } h3 { font-size: 0.95rem; }
p { margin: 0 0 .6em; }
a { color: var(--brand); text-underline-offset: 2px; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 3px; }
button, input, select, textarea { font: inherit; color: inherit; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--ink-3); } .mono { font-family: var(--mono); }
.hide { display: none !important; }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: 236px minmax(0, 1fr); min-height: 100vh; }
.rail {
  position: sticky; top: 0; height: 100vh; overflow-y: auto; background: var(--rail); color: var(--rail-ink);
  display: flex; flex-direction: column; padding: 18px 12px 14px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 2px 8px 16px; color: #fff; text-decoration: none; }
.brand-mark { width: 30px; height: 30px; border-radius: 6px; background: var(--brand); display: grid; place-items: center; color: var(--brand-ink); flex: none; }
.brand b { font-size: 1rem; letter-spacing: -0.01em; display: block; line-height: 1.15; }
.brand small { color: var(--rail-ink-2); font-size: .74rem; }
.rail-group { margin: 14px 0 4px; padding: 0 10px; font-size: .74rem; color: var(--rail-ink-2); }
.rail a.nav {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: var(--r);
  color: var(--rail-ink); text-decoration: none; font-size: .93rem; min-height: 38px;
}
.rail a.nav:hover { background: var(--rail-active); }
.rail a.nav[aria-current="page"] { background: var(--rail-active); color: #fff; box-shadow: inset 3px 0 0 var(--brand); }
.rail a.nav svg { width: 18px; height: 18px; flex: none; opacity: .9; }
.rail a.nav .lamp { margin-left: auto; }
.rail-foot { margin-top: auto; padding: 14px 8px 0; font-size: .74rem; color: var(--rail-ink-2); }

/* status lamp: the feed-freshness indicator */
.lamp { width: 9px; height: 9px; border-radius: 50%; background: #5d7377; flex: none; }
.lamp.ok { background: #3ecf72; box-shadow: 0 0 0 3px rgba(62,207,114,.18); }
.lamp.stale { background: #f0a23b; box-shadow: 0 0 0 3px rgba(240,162,59,.2); }
.lamp.missing { background: #5d7377; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 12px; padding: 14px 24px; border-bottom: 1px solid var(--line);
  background: var(--surface); position: sticky; top: 0; z-index: 20;
}
.topbar h1 { font-size: 1.15rem; }
.topbar .spacer { flex: 1; }
.icon-btn {
  width: 38px; height: 38px; border-radius: var(--r); border: 1px solid var(--line); background: var(--surface);
  display: grid; place-items: center; cursor: pointer; color: var(--ink-2);
}
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }
.icon-btn svg { width: 18px; height: 18px; }
.page { padding: 22px 24px 48px; max-width: 1360px; width: 100%; margin: 0 auto; }
.mobile-brand, .tabbar, .sheet, .sheet-bg { display: none; }

/* ---------- components ---------- */
.grid { display: grid; gap: var(--gap); }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.g-side { grid-template-columns: minmax(280px, 380px) minmax(0, 1fr); align-items: start; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 16px; min-width: 0; }
.card > h2, .card-head h2 { margin-bottom: 2px; }
.card-head { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.card-head .spacer { flex: 1; }
.sub { color: var(--ink-3); font-size: .86rem; }

.kpi { background: var(--surface-2); border-radius: var(--r); padding: 11px 13px; min-width: 0; }
.kpi .k { color: var(--ink-3); font-size: .8rem; }
.kpi .v { font: 600 1.35rem/1.25 var(--mono); letter-spacing: -0.02em; overflow-wrap: anywhere; }
.kpi .u { font: 400 .78rem var(--font); color: var(--ink-3); margin-left: 4px; }
.kpi .d { font-size: .82rem; margin-top: 2px; }
.kpi.accent { background: var(--brand-soft); }
.up { color: var(--good); } .down { color: var(--bad); }

.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field > label, .lbl { font-size: .82rem; color: var(--ink-2); font-weight: 550; }
input[type=text], input[type=password], input[type=number], input[type=date], input[type=search], select, textarea {
  width: 100%; min-height: 40px; padding: 7px 10px; border: 1px solid var(--line); border-radius: var(--r);
  background: var(--surface); font-size: 16px; /* 16px stops iOS zooming on focus */
}
input[type=number], .num { font-family: var(--mono); }
input:disabled { opacity: .55; }
.form-row { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.btn {
  min-height: 40px; padding: 8px 14px; border-radius: var(--r); border: 1px solid var(--line);
  background: var(--surface); cursor: pointer; font-weight: 550; display: inline-flex; align-items: center; gap: 8px; justify-content: center;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.small { min-height: 32px; padding: 4px 10px; font-size: .86rem; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; background: var(--surface); max-width: 100%; }
.seg button { border: 0; background: transparent; padding: 7px 13px; min-height: 38px; cursor: pointer; color: var(--ink-2); font-weight: 550; white-space: nowrap; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button[aria-pressed="true"], .seg button[aria-selected="true"] { background: var(--brand); color: var(--brand-ink); }
.tabs { display: flex; gap: 2px; overflow-x: auto; border-bottom: 1px solid var(--line); margin: 0 -16px 14px; padding: 0 16px; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs button { border: 0; background: none; padding: 10px 14px; cursor: pointer; color: var(--ink-3); font-weight: 600; white-space: nowrap; border-bottom: 2px solid transparent; margin-bottom: -1px; min-height: 44px; }
.tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--brand); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 3px 4px 3px 10px; border: 1px solid var(--line); border-radius: 999px; font-size: .84rem; background: var(--surface-2); max-width: 100%; }
.chip .sw { width: 10px; height: 10px; border-radius: 2px; flex: none; }
.chip span.t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip select { width: auto; min-height: 28px; padding: 0 4px; font-size: .8rem; border-radius: 999px; }
.chip button { border: 0; background: none; cursor: pointer; width: 26px; height: 26px; border-radius: 50%; color: var(--ink-3); font-size: 1rem; line-height: 1; }
.chip button:hover { background: var(--line); color: var(--ink); }
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: .78rem; font-weight: 600; background: var(--surface-2); color: var(--ink-2); }
.badge.ok { background: var(--good-soft); color: var(--good); }
.badge.stale { background: var(--amber-soft); color: var(--amber); }
.badge.missing { background: var(--surface-2); color: var(--ink-3); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.alert { padding: 10px 13px; border-radius: var(--r); border: 1px solid var(--line); background: var(--surface-2); font-size: .92rem; }
.alert.warn { background: var(--amber-soft); border-color: transparent; color: var(--ink); }
.alert.bad { background: var(--bad-soft); border-color: transparent; }
.empty { padding: 34px 18px; text-align: center; color: var(--ink-2); border: 1px dashed var(--line); border-radius: var(--r); background: var(--surface); }
.empty b { display: block; color: var(--ink); margin-bottom: 4px; }

.table-wrap { overflow-x: auto; margin: 0 -16px; padding: 0 16px; }
table { border-collapse: collapse; width: 100%; font-size: .9rem; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-weight: 600; color: var(--ink-3); font-size: .8rem; white-space: nowrap; background: var(--surface); position: sticky; top: 0; }
td.n, th.n { text-align: right; font-family: var(--mono); white-space: nowrap; }
tbody tr:hover { background: var(--surface-2); }

.plot { width: 100%; min-height: 320px; }
.plot.tall { min-height: 440px; }
.loading { color: var(--ink-3); padding: 28px 0; text-align: center; }
.spin { display: inline-block; width: 14px; height: 14px; border: 2px solid var(--line); border-top-color: var(--brand); border-radius: 50%; animation: spin .8s linear infinite; vertical-align: -2px; margin-right: 6px; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spin { animation-duration: 3s; } * { scroll-behavior: auto !important; } }

/* home */
.feed-grid { display: grid; gap: var(--gap); grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); }
.tile { display: flex; gap: 12px; align-items: flex-start; padding: 15px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); text-decoration: none; color: inherit; }
.tile:hover { border-color: var(--brand); }
.tile .ico { width: 38px; height: 38px; border-radius: var(--r); background: var(--brand-soft); color: var(--brand); display: grid; place-items: center; flex: none; }
.tile .ico svg { width: 20px; height: 20px; }
.tile b { display: block; margin-bottom: 1px; }
.tile .sub { line-height: 1.35; }
.tile .foot { margin-top: 7px; display: flex; align-items: center; gap: 7px; font-size: .78rem; color: var(--ink-3); }
.section-title { margin: 26px 0 10px; font-size: 1rem; color: var(--ink-2); font-weight: 600; }
.glance { display: grid; gap: var(--gap); grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }

/* gas mix list */
.gas-list { max-height: 560px; overflow-y: auto; border: 1px solid var(--line); border-radius: var(--r); }
.gas-row { display: grid; grid-template-columns: minmax(0, 1fr) 96px; gap: 10px; align-items: center; padding: 6px 10px; border-bottom: 1px solid var(--line); }
.gas-row:last-child { border-bottom: 0; }
.gas-row .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gas-row .nm small { color: var(--ink-3); margin-left: 6px; font-family: var(--mono); }
.gas-row input { min-height: 36px; text-align: right; }
.gas-row.on { background: var(--brand-soft); }
.totalbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

/* analytics picker */
.picker { border: 1px solid var(--line); border-radius: var(--r); max-height: 230px; overflow-y: auto; background: var(--surface); }
.picker button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 8px 10px; cursor: pointer; border-bottom: 1px solid var(--line); font-size: .88rem; font-family: var(--mono); overflow-wrap: anywhere; }
.picker button:hover { background: var(--surface-2); }
.picker .grp { padding: 5px 10px; font-size: .75rem; color: var(--ink-3); background: var(--surface-2); position: sticky; top: 0; }
.weather-day { text-align: center; padding: 12px 8px; background: var(--surface-2); border-radius: var(--r); }
.weather-day .em { font-size: 1.8rem; line-height: 1.3; }

/* ---------- tablet / phone ---------- */
@media (max-width: 1100px) {
  .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .g3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 899px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .rail { display: none; }
  .topbar { padding: 10px 16px; }
  .mobile-brand { display: grid; width: 30px; height: 30px; border-radius: 6px; background: var(--brand); color: var(--brand-ink); place-items: center; }
  .page { padding: 16px 16px calc(84px + env(safe-area-inset-bottom)); }
  .g-side, .g2, .g3 { grid-template-columns: minmax(0, 1fr); }
  .tabbar {
    display: grid; grid-template-columns: repeat(4, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
    background: var(--surface); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
  }
  .tabbar a, .tabbar button {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-height: 58px;
    border: 0; background: none; color: var(--ink-3); text-decoration: none; font-size: .72rem; font-weight: 600; cursor: pointer;
  }
  .tabbar svg { width: 22px; height: 22px; }
  .tabbar [aria-current="page"], .tabbar [aria-expanded="true"] { color: var(--brand); }
  .sheet-bg { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 50; }
  .sheet {
    display: block; position: fixed; left: 0; right: 0; bottom: 0; z-index: 60; background: var(--surface);
    border-radius: 14px 14px 0 0; padding: 8px 10px calc(14px + env(safe-area-inset-bottom)); max-height: 78vh; overflow-y: auto;
  }
  .sheet[hidden], .sheet-bg[hidden] { display: none; }
  .sheet .grab { width: 38px; height: 4px; border-radius: 2px; background: var(--line); margin: 4px auto 10px; }
  .sheet a { display: flex; align-items: center; gap: 12px; padding: 12px 10px; border-radius: var(--r); color: var(--ink); text-decoration: none; min-height: 48px; }
  .sheet a:hover, .sheet a[aria-current="page"] { background: var(--surface-2); }
  .sheet a svg { width: 20px; height: 20px; color: var(--brand); flex: none; }
  .sheet a small { display: block; color: var(--ink-3); font-size: .8rem; line-height: 1.3; }
  .sheet a .lamp { margin-left: auto; }
  .plot { min-height: 280px; } .plot.tall { min-height: 360px; }
  h1 { font-size: 1.3rem; }
  .gas-list { max-height: 420px; }
}
@media (max-width: 520px) {
  .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .glance { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .kpi .v { font-size: 1.15rem; }
  .card { padding: 13px; }
  .table-wrap { margin: 0 -13px; padding: 0 13px; }
  .tabs { margin: 0 -13px 12px; padding: 0 13px; }
  .seg button { padding: 7px 10px; }
}
@media print { .rail, .tabbar, .topbar .icon-btn { display: none; } .shell { display: block; } }

#quick { display: flex; width: 100%; }
#quick button { flex: 1; padding-left: 6px; padding-right: 6px; }

/* gauge panel */
.gauge-grid { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
.gauge { background: var(--surface-2); border-radius: var(--r); padding: 10px 8px 10px; text-align: center; min-width: 0; }
.gauge .gl { font-size: .84rem; font-weight: 600; color: var(--ink-2); }
.gauge svg { width: 100%; max-width: 190px; height: auto; display: block; margin: 2px auto 0; }
.gauge .g-track, .gauge .g-band, .gauge .g-val { fill: none; stroke-width: 12; }
.gauge .g-track { stroke: var(--line); }
.gauge .g-band { stroke: var(--good-soft); }
.gauge .g-val { stroke: var(--c1); stroke-linecap: round; }
.gauge .g-val.ok { stroke: var(--good); } .gauge .g-val.warn { stroke: var(--amber); } .gauge .g-val.bad { stroke: var(--bad); }
.gauge .g-mark { stroke: var(--ink); stroke-width: 3; stroke-linecap: round; }
.gauge .g-num { font: 600 28px var(--mono); fill: var(--ink); text-anchor: middle; letter-spacing: -0.03em; }
.gauge .g-unit, .gauge .g-end { font: 400 11px var(--font); fill: var(--ink-3); text-anchor: middle; }
.gauge .gs { min-height: 1.5em; font-size: .78rem; color: var(--ink-3); margin-top: 2px; }
.gauge .gs .badge { margin-right: 4px; }
.summary-line { display: flex; flex-wrap: wrap; gap: 4px 18px; color: var(--ink-2); font-size: .92rem; }
.summary-line b { color: var(--ink); font-weight: 600; }
details.raw summary { cursor: pointer; font-weight: 600; color: var(--ink-2); min-height: 40px; display: flex; align-items: center; }
details.raw pre { max-height: 420px; overflow: auto; background: var(--surface-2); padding: 12px; border-radius: var(--r); font: .8rem/1.45 var(--mono); }
@media (max-width: 520px) { .gauge-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; } .gauge .g-num { font-size: 26px; } }

/* sign-in */
.who { display: flex; align-items: center; gap: 10px; margin: 0; }
.who .muted { max-width: 12ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 520px) { .who .muted { display: none; } }
.auth { min-height: 100vh; display: grid; place-items: center; padding: 20px 16px; background: var(--bg); }
.auth-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 26px 24px; }
.auth-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; }
.auth-brand b { display: block; font-size: 1.1rem; }
.auth-card form { display: grid; gap: 14px; }
.auth-card .btn { width: 100%; min-height: 44px; }
.auth-card .alert { margin-bottom: 14px; }
