/* HX Conn WWW — dark theme matching the mobile app (hx_theme.dart).
   No inline styles (CSP style-src 'self'). */
:root {
  --bg: #031523; --surface: #0D263C; --surface-2: #092338; --border: #274D6A; --muted: #9BBBD7;
  --green: #00ED92; --cyan: #00CFFF; --red: #FF544D; --warning: #FFD342; --orange: #FF6820;
  --ink: #F1F7FF; --input: #031523; --error-bg: #3A202B; --cyan-bg: #103747;
  --radius: 22px; --radius-sm: 12px;
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink); background: var(--bg); color-scheme: dark;
}
* { box-sizing: border-box; }
body {
  margin: 0; min-height: 100vh;
  background: radial-gradient(circle at 15% 15%, #0C3049 0%, #031523 55%, #020E1A 100%) fixed;
}
[hidden] { display: none !important; }
a { color: var(--cyan); }
h1 { font-size: 28px; line-height: 1.2; margin: 0 0 4px; font-weight: 600; letter-spacing: -.6px; }
h2 { font-size: 17px; margin: 0 0 14px; font-weight: 600; }
h3 { font-size: 15px; margin: 0; font-weight: 600; }
p { margin: 0 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.ok-text { color: var(--green); }
.placeholder { color: var(--muted); padding: 24px 0; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip-link { position: absolute; left: -9999px; }
.skip-link:focus { left: 12px; top: 12px; z-index: 20; background: var(--surface); padding: 8px 12px; border-radius: 8px; }

/* ---- controls ---- */
button, .button {
  font: inherit; font-size: 15px; font-weight: 600; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; justify-content: center;
  border: 1px solid var(--border); background: var(--surface); color: var(--ink);
  padding: 8px 16px; border-radius: 999px; text-decoration: none; min-height: 40px;
}
button:hover, .button:hover { border-color: var(--cyan); }
button.primary, .button.primary { background: var(--green); border-color: var(--green); color: var(--bg); }
button.primary:hover, .button.primary:hover { filter: brightness(1.08); }
button.danger { background: var(--red); border-color: var(--red); color: #fff; }
button.ghost, .button.ghost { background: transparent; color: var(--cyan); border-color: var(--border); }
button.small { min-height: 32px; padding: 4px 12px; font-size: 13px; }
button.link { border: 0; background: none; padding: 4px 6px; min-height: 0; color: var(--cyan); text-decoration: underline; font-weight: 500; }
button.link.danger-link { color: var(--red); }
button.wide { width: 100%; }
button:disabled { opacity: .45; cursor: not-allowed; }
:focus-visible { outline: 3px solid var(--warning); outline-offset: 2px; }
label { display: block; font-size: 14px; color: var(--muted); margin-bottom: 14px; }
input, textarea, select {
  font: inherit; display: block; width: 100%; margin-top: 4px; color: var(--ink);
  border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 12px; background: var(--input);
}
input:focus, textarea:focus, select:focus { border-color: var(--cyan); outline: none; }
textarea { resize: vertical; min-height: 80px; }
.form-status, .history-status, .notes-status { min-height: 1.5em; font-size: 14px; }
[data-kind="error"] { color: var(--red); }
[data-kind="ok"] { color: var(--green); }
.form-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 14px; }

/* ---- top bar ---- */
.topbar {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 20px;
  min-height: 62px; padding: 8px 24px; background: rgba(9, 35, 56, .92); border-bottom: 1px solid var(--border);
  backdrop-filter: blur(8px);
}
.brand { color: var(--ink); text-decoration: none; font-size: 22px; letter-spacing: -.5px; display: flex; align-items: center; gap: 8px; }
@font-face { font-family: InterBrand; src: url('/branding/Inter-Variable.ttf') format('truetype'); font-weight: 100 900; font-display: swap; }
.brand-symbol { display: block; flex-shrink: 0; object-fit: contain; }
.brand-wordmark { font-family: InterBrand, system-ui, sans-serif; font-weight: 750; letter-spacing: -.7px; color: #F8FAFC; white-space: nowrap; }
.brand-wordmark strong { font-weight: inherit; color: #00D4EF; }
.main-nav { display: flex; gap: 4px; }
.main-nav a { color: var(--muted); text-decoration: none; padding: 8px 14px; border-radius: 999px; font-weight: 600; }
.main-nav a:hover { color: var(--ink); }
.main-nav a.active { background: rgba(0, 237, 146, .12); color: var(--green); }
.connection { margin-left: auto; font-size: 13px; color: var(--muted); display: inline-flex; align-items: center; gap: 6px; }
.connection::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: var(--muted); }
.connection[data-state="online"]::before { background: var(--green); box-shadow: 0 0 8px var(--green); }
.connection[data-state="connecting"]::before { background: var(--warning); }
.connection[data-state="offline"]::before { background: var(--red); }
.user { font-size: 14px; color: var(--muted); max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#logout { color: var(--muted); }
main { max-width: 1440px; margin: 0 auto; padding: 24px; outline: none; }

/* ---- notice ---- */
.notice {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 40;
  max-width: min(640px, 92vw); padding: 14px 20px; border-radius: 16px; color: var(--ink);
  background: var(--error-bg); border: 1px solid var(--red); box-shadow: 0 8px 24px rgba(0,0,0,.4);
}
.notice-info, .notice-ok { background: var(--cyan-bg); border-color: var(--cyan); }

/* ---- cards ---- */
.card, .panel, .empty, .auth {
  background: rgba(13, 38, 60, .88); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px;
}
.card, .panel { margin-bottom: 16px; }
.empty { text-align: center; padding: 28px; border-style: dashed; }
.empty p { color: var(--muted); }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 10px; }
.panel-head h2 { margin: 0; }

/* ---- auth ---- */
.auth { max-width: 430px; margin: 6vh auto; padding: 32px; }
.auth-brand { display: flex; align-items: center; gap: 14px; font-size: 32px; margin-bottom: 24px; }
.auth-links { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 12px; margin-top: 18px; }

/* ---- status pills ---- */
.pill { display: inline-flex; align-items: center; gap: 4px; padding: 2px 10px; border-radius: 999px; font-size: 13px; font-weight: 600; border: 1px solid transparent; }
.pill.sev-alarm { background: var(--error-bg); color: var(--red); border-color: rgba(255,84,77,.5); }
.pill.sev-warning { background: rgba(255,211,66,.12); color: var(--warning); border-color: rgba(255,211,66,.4); }
.pill.sev-message { background: var(--cyan-bg); color: var(--cyan); border-color: rgba(0,207,255,.35); }
.pill.sev-none { background: rgba(0,237,146,.1); color: var(--green); border-color: rgba(0,237,146,.35); }
.pill.sev-unknown { background: transparent; color: var(--muted); border-color: var(--border); border-style: dashed; }
.pill.sev-sim { background: rgba(255,104,32,.14); color: var(--orange); border-color: rgba(255,104,32,.45); }
.conn { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.conn::before { content: ""; width: 9px; height: 9px; border-radius: 50%; }
.conn-online::before { background: var(--green); }
.conn-offline::before { background: var(--red); }
.conn-offline { color: var(--red); font-weight: 600; }
.conn-unknown::before { border: 2px solid var(--muted); }
.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 700; background: var(--surface-2); }
.notes-badge { background: rgba(255,211,66,.18); color: var(--warning); }
.tag-stale { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .4px; color: var(--warning); background: rgba(255,211,66,.12); padding: 1px 6px; border-radius: 4px; white-space: nowrap; }

/* ---- object list ---- */
.overview.with-tree { display: grid; grid-template-columns: 280px minmax(0, 1fr); gap: 24px; align-items: start; }
.tree-panel { position: sticky; top: 86px; background: rgba(13,38,60,.88); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; max-height: calc(100vh - 110px); overflow: auto; }
.section-title { font-size: 12px; text-transform: uppercase; letter-spacing: .8px; color: var(--muted); margin-bottom: 10px; }
.tree { list-style: none; margin: 0; padding: 0; }
.tree.nested { padding-left: 12px; border-left: 1px solid var(--border); margin-left: 10px; }
.tree-node { width: 100%; justify-content: space-between; border: 0; background: none; color: var(--ink); padding: 6px 10px; min-height: 34px; text-align: left; font-size: 14px; font-weight: 500; border-radius: 10px; }
.tree-node span:first-child { overflow: hidden; text-overflow: ellipsis; }
.tree-node.node-org, .tree-node.node-all, .tree-node.node-integrator { font-weight: 700; }
.tree-node[aria-pressed="true"] { background: rgba(0,237,146,.12); color: var(--green); }
.count { font-size: 12px; color: var(--muted); font-weight: 600; }
.tree-meta { display: inline-flex; align-items: center; gap: 6px; }
.sev-dot { width: 8px; height: 8px; border-radius: 50%; display: none; }
[data-severity="alarm"] .sev-dot { display: inline-block; background: var(--red); }
[data-severity="warning"] .sev-dot { display: inline-block; background: var(--warning); }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; }
.segmented { display: inline-flex; border: 1px solid var(--border); border-radius: 999px; overflow: hidden; background: var(--surface-2); padding: 3px; gap: 2px; }
.segmented > a, .segmented > button { border: 0; border-radius: 999px; padding: 6px 16px; text-decoration: none; color: var(--muted); font-weight: 600; min-height: 34px; display: inline-flex; align-items: center; background: none; }
.segmented > .active, .segmented > [aria-pressed="true"] { background: rgba(0,237,146,.14); color: var(--green); }
.toolbar { margin: 18px 0 10px; }
.toolbar input { max-width: 520px; margin: 0; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 18px; }
.chip { min-height: 34px; padding: 4px 14px; font-size: 14px; font-weight: 500; background: var(--surface-2); }
.chip[aria-pressed="true"] { border-color: var(--green); color: var(--green); }
.chip-alarm .count { color: var(--red); }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.station-card {
  display: flex; flex-direction: column; gap: 6px; padding: 18px 20px 16px; color: inherit; text-decoration: none;
  background: rgba(13,38,60,.88); border: 1px solid var(--border); border-radius: var(--radius); position: relative; overflow: hidden;
}
.station-card::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 5px; background: var(--border); }
.station-card:hover { border-color: var(--cyan); }
.station-card.sev-alarm::before { background: var(--red); }
.station-card.sev-warning::before { background: var(--warning); }
.station-card.sev-message::before { background: var(--cyan); }
.station-card.sev-none::before { background: var(--green); }
.card-head { display: flex; justify-content: space-between; gap: 8px; align-items: flex-start; }
.card-title { font-weight: 600; font-size: 17px; overflow-wrap: anywhere; }
.card-sub, .card-path, .card-fresh { font-size: 13px; color: var(--muted); }
.card-status { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: 4px; }

/* ---- map ---- */
.map { position: relative; height: min(70vh, 640px); min-height: 340px; overflow: hidden; border-radius: var(--radius); border: 1px solid var(--border); background: #0a2236; touch-action: none; cursor: grab; user-select: none; }
.map.dragging { cursor: grabbing; }
.map-tiles, .map-markers { position: absolute; inset: 0; }
.map-tile { position: absolute; left: 0; top: 0; width: 256px; height: 256px; max-width: none; filter: brightness(.78) saturate(.85); }
.map-tile-missing { visibility: hidden; }
.marker { position: absolute; left: -11px; top: -11px; width: 22px; height: 22px; min-height: 0; padding: 0; border-radius: 50%; border: 3px solid var(--bg); background: var(--muted); box-shadow: 0 0 0 2px rgba(255,255,255,.6); }
.marker.sev-alarm { background: var(--red); width: 26px; height: 26px; left: -13px; top: -13px; }
.marker.sev-warning { background: var(--warning); }
.marker.sev-message { background: var(--cyan); }
.marker.sev-none { background: var(--green); }
.marker.conn-offline { box-shadow: 0 0 0 2px var(--red); }
.map-popup { position: absolute; left: 0; top: 0; margin: 18px 0 0 -125px; width: 250px; z-index: 3; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 12px; box-shadow: 0 6px 20px rgba(0,0,0,.45); display: flex; flex-direction: column; gap: 6px; align-items: flex-start; cursor: default; }
.map-popup small { color: var(--muted); }
.map-controls { position: absolute; top: 10px; right: 10px; z-index: 4; display: flex; flex-direction: column; gap: 6px; }
.map-controls button { width: 40px; height: 40px; padding: 0; font-size: 20px; }
.map-attribution { position: absolute; right: 0; bottom: 0; z-index: 4; background: rgba(3,21,35,.85); color: var(--muted); font-size: 12px; padding: 2px 8px; border-top-left-radius: 8px; }
#map-note { margin-top: 10px; }

/* ---- station ---- */
.breadcrumb { font-size: 14px; color: var(--muted); margin-bottom: 8px; }
.station-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; margin-bottom: 14px; }
.status-row { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
.tabs { display: flex; gap: 4px; margin-bottom: 18px; overflow-x: auto; padding: 4px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; width: fit-content; max-width: 100%; }
.tabs a { padding: 8px 18px; text-decoration: none; color: var(--muted); font-weight: 600; border-radius: 999px; white-space: nowrap; }
.tabs a:hover { color: var(--ink); }
.tabs a.active { background: rgba(0,237,146,.12); color: var(--green); }
.live-banner { padding: 10px 16px; border-radius: 14px; margin-bottom: 16px; font-size: 14px; background: var(--surface-2); border: 1px solid var(--border); color: var(--muted); }
.live-banner[data-kind="ok"] { color: var(--green); border-color: rgba(0,237,146,.35); }
.live-banner[data-kind="warn"] { color: var(--warning); border-color: rgba(255,211,66,.4); }
.live-banner[data-kind="info"] { color: var(--cyan); border-color: rgba(0,207,255,.35); }
.disconnected .stat-value, .disconnected .pump-state, .disconnected .metric-value { color: var(--muted); }

.overview-grid { display: grid; grid-template-columns: minmax(0, 1.65fr) minmax(280px, 1fr); gap: 16px; align-items: start; }
.well-card { padding: 18px 18px 12px; }
.well-stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin-bottom: 8px; }
.stat { background: var(--bg); border: 1px solid var(--border); border-radius: 16px; padding: 10px 14px; display: flex; flex-direction: column; gap: 2px; }
.stat-label { font-size: 13px; color: var(--muted); }
.stat-value { font-size: 26px; font-weight: 600; font-variant-numeric: tabular-nums; color: var(--ink); line-height: 1.15; }
.stat:first-child .stat-value { color: var(--cyan); }
.stat-value small { font-size: 14px; font-weight: 500; color: var(--muted); }
.stat.stale .stat-value { color: var(--muted); }
.stat .pill, .stat .tag-stale { align-self: flex-start; margin-top: 4px; }
.well-figure { width: 100%; max-width: 760px; margin: 0 auto; }
.well-svg { display: block; width: 100%; height: auto; aspect-ratio: 480 / 340; font-family: inherit; }
.well-flow.moving { animation: well-flow 1.4s linear infinite; }
@keyframes well-flow { to { stroke-dashoffset: -26; } }
.well-pump.maintenance .rim { animation: well-blink 2s ease-in-out infinite; }
.well-svg.paused .well-pump.maintenance .rim { animation: none; }
@keyframes well-blink { 50% { stroke-opacity: .35; } }
@media (prefers-reduced-motion: reduce) { .well-flow.moving, .well-pump.maintenance .rim { animation: none; } }
.well-notes { list-style: none; margin: 6px 0 0; padding: 0; display: grid; gap: 4px; font-size: 13px; color: var(--warning); }
.side-col { display: grid; gap: 12px; }
.side-col .card { margin: 0; }

.pump { padding: 14px 16px; }
.pump-head { display: flex; align-items: center; gap: 10px; }
.pump-head h3 { flex: 1; font-size: 16px; }
.pump-dot { width: 30px; height: 30px; aspect-ratio: 1; flex: none; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-weight: 600; border: 2px solid var(--border); color: var(--muted); }
.pump-state { font-weight: 700; font-size: 13px; letter-spacing: .5px; text-transform: uppercase; color: var(--muted); }
.pump-run .pump-dot { border-color: var(--green); color: var(--green); }
.pump-run .pump-state { color: var(--green); }
.pump-fault .pump-dot { border-color: var(--red); color: var(--red); }
.pump-fault .pump-state { color: var(--red); }
.pump.stale .pump-dot { border-style: dashed; }
.chips { list-style: none; margin: 10px 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.pump-fields { margin: 10px 0 0; font-size: 13px; display: grid; gap: 4px; border-top: 1px solid var(--border); padding-top: 8px; }
.pump-fields div { display: flex; justify-content: space-between; gap: 10px; }
.pump-fields dt { color: var(--muted); }
.pump-fields dd { margin: 0; font-weight: 600; font-variant-numeric: tabular-nums; }
.pump-fields .stale dd { color: var(--muted); }
.signal-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.signal-list li { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }

.metrics { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 10px; }
.metric { background: var(--bg); border: 1px solid var(--border); border-radius: 14px; padding: 10px 12px; display: flex; flex-direction: column; gap: 2px; }
.metric-label { font-size: 13px; color: var(--muted); }
.metric-value { font-size: 19px; font-weight: 600; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.metric-value small { font-size: 13px; font-weight: 500; color: var(--muted); }
.metric.stale .metric-value { color: var(--muted); }

/* ---- settings ---- */
.write-state { padding: 10px 16px; border-radius: 14px; font-size: 14px; border: 1px solid var(--border); background: var(--surface-2); }
.write-state[data-kind="warn"] { color: var(--warning); border-color: rgba(255,211,66,.4); }
.write-state[data-kind="ok"] { color: var(--muted); }
.settings-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 420px), 1fr)); gap: 16px; align-items: start; margin-top: 14px; }
.setting-group { margin: 0; }
.setting-row { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; align-items: center; gap: 4px 12px; padding: 10px 0; border-top: 1px solid var(--border); }
.setting-group h2 + .setting-row { border-top: 0; }
.setting-label { font-size: 15px; }
.setting-value { font-weight: 600; font-variant-numeric: tabular-nums; text-align: right; }
.setting-row.is-readonly .setting-label { color: var(--muted); }
.readonly { font-size: 12px; color: var(--muted); }
.cat { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; padding: 1px 6px; border-radius: 4px; margin-left: 4px; vertical-align: 1px; }
.cat-service { color: var(--orange); background: rgba(255,104,32,.12); }
.cat-administration { color: var(--cyan); background: var(--cyan-bg); }
.setting-action { display: flex; align-items: center; gap: 8px; }
.setting-switch { flex: 0 0 auto; width: 48px; min-height: 28px; height: 28px; border-radius: 20px; padding: 3px; border: 1px solid var(--border); background: var(--surface-2); }
.setting-switch span { display: block; width: 20px; height: 20px; border-radius: 50%; background: var(--muted); transform: translateX(0); transition: transform .12s; }
.setting-switch[aria-checked="true"] { background: var(--green); border-color: var(--green); }
.setting-switch[aria-checked="true"] span { background: var(--bg); transform: translateX(20px); }
.setting-switch:disabled { opacity: 1; cursor: not-allowed; }
.setting-switch[aria-busy="true"] { border-style: dashed; }
.switch-unknown span { border: 2px dashed var(--muted); background: transparent; }
.switch-feedback { display: block; color: var(--muted); font-size: 11px; font-weight: 400; }
.write-result { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; padding: 12px 0; font-size: 13px; }
.write-result .command-main { flex: 1; }
.write-result[data-kind="error"] .command-state { color: var(--red); }
.write-result[data-kind="ok"] .command-state { color: var(--green); }
.event-categories { margin: 12px 0; display: flex; flex-wrap: wrap; }
.event-types { margin: 12px 0; }
.event-types summary { cursor: pointer; padding: 8px 0; font-size: 14px; }
.event-type-list { max-height: 240px; overflow: auto; }
.event-type { display: flex; flex-direction: row; align-items: center; gap: 10px; padding: 8px 0; font-size: 13px; }
.event-type input { width: 18px; height: 18px; margin: 0; }
.event-entry { margin: 10px 0; border-left-width: 4px; }
.event-entry h3 { margin: 0 0 6px; font-size: 15px; }
.event-entry p { margin: 0; color: var(--muted); font-size: 13px; }
.event-alarm { border-left-color: var(--red); }
.event-warning { border-left-color: var(--warning); }
.event-message { border-left-color: var(--green); }
.event-alarm h3, .sev-text-alarm { color: var(--red); }
.event-warning h3, .sev-text-warning { color: var(--warning); }
.event-message h3, .sev-text-message { color: var(--green); }
.commands-card { margin-top: 16px; }
.command-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.command { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 10px 14px; border-radius: 14px; background: var(--bg); border: 1px solid var(--border); border-left-width: 4px; }
.command[data-kind="ok"] { border-left-color: var(--green); }
.command[data-kind="info"] { border-left-color: var(--cyan); }
.command[data-kind="warn"] { border-left-color: var(--warning); }
.command[data-kind="error"] { border-left-color: var(--red); }
.command-main { display: grid; gap: 2px; min-width: 0; }
.command-state { font-size: 14px; color: var(--muted); }
.command[data-kind="ok"] .command-state { color: var(--green); }
.command[data-kind="error"] .command-state { color: var(--red); }
.command-observed { font-size: 14px; color: var(--cyan); }
.command-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.hx-dialog { background: var(--surface); color: var(--ink); border: 1px solid var(--border); border-radius: 24px; padding: 0; width: min(460px, 92vw); }
.hx-dialog::backdrop { background: rgba(2, 14, 26, .72); }
.dialog-body { padding: 22px 24px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
.confirm-change { font-size: 17px; font-weight: 600; color: var(--cyan); }
.input-unit { display: flex; align-items: center; gap: 8px; }
.input-unit input { flex: 1; }
.input-unit span { color: var(--muted); margin-top: 4px; }
.row-inputs { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.choice { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 8px 14px; margin: 0 0 14px; }
.choice legend { color: var(--muted); font-size: 14px; padding: 0 6px; }
.radio { display: flex; align-items: center; gap: 8px; color: var(--ink); margin: 6px 0; }
.radio input { width: auto; margin: 0; }

/* ---- history ---- */
.history-controls { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-end; gap: 14px; margin-bottom: 10px; }
.range-form { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px; }
.range-form label { margin: 0; }
.range-form input { width: auto; }
.chart-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-end; gap: 10px; margin: 8px 0; }
.chart-head label { margin: 0; min-width: 240px; }
.chart { width: 100%; overflow: hidden; border: 1px solid var(--border); border-radius: 16px; background: var(--bg); }
.chart svg { display: block; }
.chart .grid { stroke: #173a55; stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 12px; font-family: inherit; }
.chart .series { fill: none; stroke: var(--cyan); stroke-width: 2; stroke-linejoin: round; }
.chart .sample { fill: var(--cyan); }
.chart .cursor { stroke: var(--warning); stroke-width: 1.5; }
.chart-legend { margin-top: 6px; }
.chart:focus-visible { outline: 2px solid var(--cyan); outline-offset: 2px; }
.chart .placeholder { padding: 16px; }
.chart-card { margin: 12px 0; padding: 14px; }
.chart-card h2 { font-size: 17px; margin: 0; }
.chart-card .chart-head { align-items: center; }
.series-toggles { display: flex; flex-wrap: wrap; gap: 6px; }
.toggle { min-height: 32px; padding: 4px 10px; font-size: 13px; display: inline-flex; align-items: center; gap: 6px; }
.toggle[aria-pressed="false"] { opacity: .5; text-decoration: line-through; }
.swatch { display: inline-block; width: 16px; height: 0; border-top: 3px solid var(--c, var(--muted)); vertical-align: middle; }
.swatch.dashed { border-top-style: dashed; }
.swatch.block { height: 10px; border: 0; background: var(--c, var(--muted)); border-radius: 2px; }
.swatch.thin { height: 4px; border: 0; background: var(--border); }
.chart-key { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 4px 14px; color: var(--muted); }
.chart-key li { display: inline-flex; align-items: center; gap: 6px; }
.chart-readout { min-height: 2.6em; margin: 4px 0; color: var(--ink); font-variant-numeric: tabular-nums; }
.history-notice { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin: 8px 0; padding: 10px 14px; border-radius: 14px; border: 1px solid rgba(255,211,66,.4); color: var(--warning); background: var(--surface-2); font-size: 14px; }
.history-notice p { margin: 0; }
.history-cache-warning { color: var(--warning); margin: 4px 0; }
.button.small { min-height: 32px; padding: 4px 12px; font-size: 13px; }
@media (max-width: 520px) {
  .chart-card { padding: 10px; margin: 10px -4px; }
  .history-controls .segmented { width: 100%; justify-content: space-between; }
  .history-controls .segmented > button { padding: 6px 10px; }
}
.history-more { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin: 10px 0; }
.history-table summary { cursor: pointer; font-weight: 600; padding: 8px 0; }
.scroll { overflow: auto; max-height: 480px; border: 1px solid var(--border); border-radius: 14px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
thead th { position: sticky; top: 0; background: var(--surface-2); font-size: 13px; color: var(--muted); }
tbody th { font-weight: 500; color: var(--muted); }

/* ---- notes ---- */
.note-form { border-bottom: 1px solid var(--border); padding-bottom: 14px; margin-bottom: 8px; }
.note { display: flex; gap: 12px; padding: 14px 0; border-bottom: 1px solid var(--border); }
.note:last-child { border-bottom: 0; }
.note-body { flex: 1; min-width: 0; }
.note-text { white-space: pre-wrap; overflow-wrap: anywhere; margin-bottom: 4px; }
.note.done > .note-body > .note-text { text-decoration: line-through; color: var(--muted); }
.note-meta { font-size: 13px; color: var(--muted); margin-bottom: 2px; }
.note-actions { display: flex; gap: 6px; margin-left: -6px; }
.check { flex: none; width: 28px; height: 28px; min-height: 0; padding: 0; border: 2px solid var(--border); border-radius: 8px; background: var(--bg); margin-top: 2px; }
.check[aria-pressed="true"], .note.done .check.static { background: var(--green); border-color: var(--green); }
.check[aria-pressed="true"]::after, .note.done .check.static::after { content: "✓"; color: var(--bg); font-weight: 700; }
.check.static { display: inline-flex; align-items: center; justify-content: center; border-style: dashed; }
.confirm { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; background: var(--error-bg); border-radius: 12px; padding: 8px 10px; margin-top: 6px; font-size: 14px; }
.note-edit textarea { margin-bottom: 8px; }
.conflict { background: rgba(255,211,66,.1); border: 1px solid rgba(255,211,66,.4); border-radius: 12px; padding: 10px 12px; margin-bottom: 8px; font-size: 14px; display: grid; gap: 4px; }
.conflict .note-text { background: var(--bg); padding: 6px 8px; border-radius: 8px; margin: 0; }

/* ---- responsive ---- */
@media (max-width: 1100px) {
  .overview-grid { grid-template-columns: 1fr; }
  .side-col { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
}
@media (max-width: 960px) {
  .overview.with-tree { grid-template-columns: 1fr; }
  .tree-panel { position: static; max-height: 260px; }
}
@media (max-width: 640px) {
  .topbar { flex-wrap: wrap; gap: 8px 12px; padding: 8px 14px; }
  .main-nav { order: 3; width: 100%; }
  .user { display: none; }
  .connection { font-size: 12px; }
  main { padding: 16px 12px; }
  h1 { font-size: 23px; }
  .auth { padding: 22px; margin-top: 16px; }
  .card, .panel { padding: 14px; border-radius: 18px; }
  .well-stats { grid-template-columns: 1fr 1fr; }
  .well-stats .stat:first-child { grid-column: 1 / -1; }
  .stat-value { font-size: 22px; }
  .tabs { border-radius: 16px; }
  .setting-row { grid-template-columns: 1fr auto; }
  .setting-action { grid-column: 1 / -1; }
  .range-form input { width: 100%; }
  .range-form label { flex: 1 1 140px; }
}

/* Persistent navigation: full-width shell, small left margin. */
main.app-shell { max-width: none; margin: 0; padding: 12px; display: grid; grid-template-columns: 320px minmax(0, 1fr); gap: 18px; align-items: start; }
.workspace { min-width: 0; outline: none; padding: 6px 6px 20px 0; }
.navigation-sidebar { position: sticky; top: 76px; max-height: calc(100dvh - 90px); overflow: auto; scrollbar-gutter: stable; padding: 12px 10px; border: 1px solid var(--border); border-radius: 16px; background: rgba(13,38,60,.88); }
.navigation-sidebar input { font-size: 13px; padding: 8px 10px; margin: 0 0 10px; }
.navigation-roots, .nav-children { list-style: none; padding: 0; margin: 0; }
.nav-children { padding-left: 9px; margin-left: 9px; border-left: 1px solid var(--border); }
.nav-branch-head { display: flex; align-items: center; gap: 2px; min-width: 0; }
.nav-expand { flex: 0 0 26px; width: 26px; padding: 0; min-height: 34px; border: 0; border-radius: 7px; background: transparent; color: var(--muted); font-size: 22px; }
.nav-scope, .nav-all { display: flex; align-items: center; gap: 6px; min-width: 0; flex: 1; padding: 8px 5px; border-radius: 8px; color: var(--ink); text-decoration: none; font-size: 13px; font-weight: 600; }
.nav-scope:hover, .nav-all:hover { background: var(--cyan-bg); }
.nav-scope-name { overflow-wrap: anywhere; flex: 1; }
.nav-scope.selected, .nav-all.selected { background: rgba(0,237,146,.12); color: var(--green); }
.nav-map-icon, .nav-note-icon { flex: 0 0 auto; width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linejoin: round; }
.nav-map-icon { color: var(--cyan); }
.nav-all { margin-bottom: 6px; justify-content: space-between; }
.nav-empty { padding: 6px 10px; font-size: 12px; color: var(--muted); }
.nav-station { display: flex; flex-direction: column; gap: 6px; padding: 9px; margin: 6px 0; background: var(--bg); border: 1px solid var(--border); border-radius: 11px; color: var(--ink); text-decoration: none; }
.nav-station:hover { border-color: var(--cyan); }
.nav-station.active { border-color: var(--green); background: rgba(0,237,146,.07); }
.nav-station-title { display: flex; gap: 7px; align-items: baseline; font-size: 13px; font-weight: 600; overflow-wrap: anywhere; }
.station-status-dot { flex: 0 0 9px; width: 9px; height: 9px; border-radius: 50%; background: var(--muted); }
.sev-alarm .station-status-dot { background: var(--red); }
.sev-warning .station-status-dot { background: var(--warning); }
.sev-message .station-status-dot, .sev-none .station-status-dot { background: var(--green); }
.nav-station-meta { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 5px; }
.nav-station-meta .conn { font-size: 11px; }
.nav-station-meta .conn::before { width: 6px; height: 6px; }
.nav-notes { display: inline-flex; gap: 3px; align-items: center; color: var(--warning); font-size: 12px; }
.setting-row.has-switch { grid-template-columns: minmax(0, 1fr) auto; }
/* Absolute knob geometry avoids inherited button centering + translation. */
.setting-switch { position: relative; display: inline-block; padding: 0; overflow: hidden; width: 48px; height: 28px; min-height: 28px; }
.setting-switch span { position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; background: #F1F7FF; transform: translateX(0); }
.setting-switch[aria-checked="true"] span { background: #F1F7FF; transform: translateX(20px); }
.setting-switch.switch-unknown span { background: transparent; }
@media (max-width: 1100px) and (min-width: 801px) { main.app-shell { grid-template-columns: 280px minmax(0, 1fr); gap: 12px; } .settings-grid { grid-template-columns: 1fr; } }
@media (max-width: 800px) { main.app-shell { display: block; padding: 10px; } .navigation-sidebar { position: static; max-height: 280px; margin-bottom: 16px; } .workspace { padding: 0; } }
.setting-switch[data-stale="true"] { border-color: var(--warning); border-style: dashed; }
.setting-row.has-switch .setting-label { grid-column: 1; grid-row: 1; }
.setting-row.has-switch .setting-action { grid-column: 2; grid-row: 1; }

/* Approved sidebar: flat hierarchy, understated controls, status on cards. */
.navigation-sidebar { border: 0; border-right: 1px solid var(--border); border-radius: 0; background: rgba(8,28,42,.65); padding: 10px 12px 12px 4px; }
.nav-search-row { display: grid; grid-template-columns: minmax(0,1fr) 28px; gap: 8px; align-items: center; margin-bottom: 12px; }
.nav-search-row input { margin: 0; }
.nav-search-action { background: transparent; border: 0; padding: 0; min-height: 34px; color: var(--muted); }
.nav-search-action svg { width: 23px; height: 23px; fill: none; stroke: currentColor; stroke-width: 1.7; }
.nav-children { margin: 0; padding: 0; border: 0; }
.nav-integrator > .nav-branch-head { background: #123247; border-radius: 9px; margin: 6px 0; }
.nav-org { margin: 0; padding: 0; }
.nav-org + .nav-org { border-top: 1px solid #33586D; }
.nav-group { padding-left: 10px; }
.nav-branch-head { min-height: 40px; }
.nav-expand { flex-basis: 23px; width: 23px; min-height: 40px; }
.nav-triangle { display: block; width: 0; height: 0; border-left: 5px solid #91A9BA; border-top: 4px solid transparent; border-bottom: 4px solid transparent; opacity: .8; }
.nav-expand[aria-expanded="true"] .nav-triangle { transform: rotate(90deg); }
.nav-scope { min-height: 40px; padding: 7px 5px; }
.nav-scope .count { display: inline-flex; align-items: center; justify-content: center; min-width: 23px; height: 20px; padding: 0 6px; border-radius: 12px; background: #1B3C50; color: #B5CCDB; font-size: 11px; }
.nav-map-icon { color: #7393A8; }
.nav-station { position: relative; overflow: hidden; display: grid; grid-template-columns: minmax(0,1fr) auto; align-items: center; gap: 8px; min-height: 64px; padding: 10px 9px 10px 14px; margin: 5px 0; }
.nav-station::before { content: ''; position: absolute; inset: 0 auto 0 0; width: 4px; background: var(--muted); }
.nav-station.sev-alarm::before { background: var(--red); }
.nav-station.sev-warning::before { background: var(--warning); }
.nav-station.sev-none::before, .nav-station.sev-message::before { background: var(--green); }
.nav-station.active { border-color: #36586B; background: rgba(0,207,200,.08); }
.nav-station-text { display: flex; flex-direction: column; min-width: 0; gap: 3px; }
.nav-station-title { display: block; font-size: 13px; }
.nav-station-name { color: #91A9BA; font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-station-icons { display: flex; align-items: center; gap: 9px; }
.nav-station-icons .nav-notes { color: #91A9BA; gap: 4px; }
.nav-station-icons .nav-notes.has-notes { color: var(--warning); }
.nav-connection { display: inline-flex; color: var(--cyan); }
.nav-connection svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.nav-connection.connection-offline { color: #D87978; }
.nav-connection.connection-unknown { color: #91A9BA; }
.workspace.map-workspace { padding: 0; }
.map-workspace #map-host { width: 100%; }
.map-workspace .map { height: 100%; min-height: 0; max-height: none; }
.map-workspace #map-note { margin: 8px 0 0; }
