/* _lib.css -- shared styling for all /config/* pages.
 *
 * Palette mirrors the dashui dark/phosphor theme so the admin UI and
 * the dashboard pages feel like one product. Per-page HTML only needs
 *   <link rel="stylesheet" href="/config/lib.css">
 * and the page chrome (nav + sections + modal + banner) follows. */

:root {
    --bg:         #0a0e12;
    --bg-soft:    #0c1217;
    --panel:      #11171d;
    --panel-edge: #1d2730;
    --panel-head: #0e151b;
    --ink:        #c7d2da;
    --ink-dim:    #9fb0bc;
    --ink-mute:   #6b7a86;
    --hair:       #222d36;
    --phos:       #3ad6a0;
    --amber:      #e0a23c;
    --cyan:       #4fc3f7;
    --red:        #e0584f;
    --nav-w:      380px;   /* width of the left page-nav sidebar (three columns: core/apps/outputs | inputs | protocols) */
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
    background: var(--bg);
    color: var(--ink);
    -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale;
    font-family: system-ui, -apple-system, sans-serif;
    min-height: 100vh;
    font-size: 14px;
}
/* dead scanline overlay removed (was transparent / no visual effect, z-index:9999) */

/* ---- brand (top of rail) + nav + bottom bar -------------------------- */

/* Brand pinned at the top of the left rail; account bar (.rail-foot) pinned at
 * the bottom; the page links scroll between them (.nav-links). No header band. */
nav.tabs .brand {
    flex: 0 0 auto;
    padding: 9px 16px 10px; margin-bottom: 4px;
    border-bottom: 1px solid var(--hair);
}
nav.tabs .brand h1 {
    font-size: 16px; letter-spacing: 2px; font-weight: 500; color: var(--ink);
}
nav.tabs .brand .tag {
    font-size: 9px; color: var(--phos); letter-spacing: 1.5px;
    text-transform: none; margin-top: 3px;
}

/* Account / utility bar pinned at the bottom of the left rail. */
nav.tabs .rail-foot {
    flex: 0 0 auto;
    display: flex; flex-direction: column; gap: 7px;
    padding: 8px 14px 9px; border-top: 1px solid var(--hair);
    background: #0d141a;
    text-transform: none; letter-spacing: .5px;
}
nav.tabs .rail-foot #cfg-whoami { color: var(--ink-mute); font-size: 10px; }
nav.tabs .rail-foot .rf-links { display: flex; align-items: center; gap: 14px; }
nav.tabs .rail-foot .rf-links a {
    color: var(--ink-dim); text-decoration: none; padding: 0; border-left: 0;
}
nav.tabs .rail-foot .rf-links a:hover { color: var(--cyan); }
nav.tabs .rail-foot .lang-select {
    background: transparent; color: var(--ink-dim);
    border: 1px solid var(--hair); border-radius:0;
    font: inherit; font-size: 11px; letter-spacing: .5px;
    padding: 3px 6px; cursor: pointer; width: 100%;
}
nav.tabs .rail-foot .lang-select:hover { border-color: var(--cyan); color: var(--ink); }
nav.tabs .rail-foot .lang-select option { color: #1f2a33; background: #fff; letter-spacing: 0; }

/* Vertical left sidebar (was a horizontal top strip). Fixed so it stays put
 * while the content column scrolls; header / banner / main are shifted right
 * by --nav-w to clear it. Scrolls internally if the link list is tall. */
nav.tabs {
    position: fixed; top: 0; left: 0; bottom: 0; width: var(--nav-w); z-index: 40;
    display: flex; flex-direction: column; flex-wrap: nowrap; align-items: stretch;
    gap: 0; padding: 0; overflow: hidden;
    background: var(--bg-soft); border-right: 1px solid var(--hair);
    font-family: ui-monospace, Consolas, monospace; font-size: 11px;
    letter-spacing: 1px; text-transform: uppercase;
}
/* Scrollable middle of the rail (page links); brand + rail-foot stay pinned. */
nav.tabs .nav-links {
    flex: 1 1 auto; min-height: 0; overflow-y: auto;
    display: flex; flex-direction: row; align-items: flex-start; gap: 0; padding: 5px 0;
}
nav.tabs .nav-col { display: flex; flex-direction: column; flex: 1 1 0; min-width: 0; }
nav.tabs .nav-col-inputs,
nav.tabs .nav-col-protocols { border-left: 1px solid var(--hair); }
nav.tabs .group {
    display: flex; flex-direction: column; align-items: stretch; gap: 0;
    padding: 0 0 3px 0; margin: 0 0 3px 0;
    border-right: 0; border-bottom: 1px solid var(--hair);
}
nav.tabs .group:last-child { border-bottom: 0; margin-bottom: 0; }
nav.tabs .group .lbl {
    color: var(--ink-mute); padding: 6px 16px 4px;
    font-size: 9px; letter-spacing: 1.5px;
}
nav.tabs a {
    color: var(--ink-dim); text-decoration: none;
    padding: 4px 14px; border-left: 2px solid transparent;
}
nav.tabs a:hover { color: var(--cyan); }
nav.tabs a.active {
    color: var(--phos); border-left-color: var(--phos);
    background: rgba(58, 214, 160, .06);
}
/* Sub-entries under a category link (sensor / instance editor pages): the
   configured rows + "add new". Indented + smaller than the page links; names
   render in natural case (not uppercased). Expanded by default; .collapsed
   hides the group (toggled by the per-category caret). */
nav.tabs a.has-caret { display: flex; align-items: center; justify-content: space-between; }
nav.tabs a .caret {
    margin-left: 8px; color: var(--ink-mute); font-size: 9px;
    cursor: pointer; padding: 2px 4px; flex: 0 0 auto;
}
nav.tabs a .caret:hover { color: var(--cyan); }
nav.tabs .subnav { display: flex; flex-direction: column; margin: 0 0 4px 0; }
nav.tabs .subnav.collapsed { display: none; }
nav.tabs .subnav a {
    padding: 3px 12px 3px 26px; font-size: 10px; letter-spacing: .5px;
    text-transform: none; color: var(--ink-dim);
    border-left: 2px solid transparent;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
nav.tabs .subnav a:hover { color: var(--cyan); }
nav.tabs .subnav a.active {
    color: var(--phos); border-left-color: var(--phos);
    background: rgba(58, 214, 160, .06);
}
nav.tabs .subnav a.subnav-add { color: var(--ink-mute); font-style: italic; }
nav.tabs .subnav a.subnav-add:hover { color: var(--phos); }

/* Sub-item with live-state dot. */
nav.tabs .subnav a.sub-item { display: flex; align-items: center; gap: 6px; }
.subnav-dot {
    display: inline-block; width: 6px; height: 6px; border-radius: 50%;
    background: var(--ink-mute); flex-shrink: 0;
    transition: background .3s;
}
.subnav-dot.sd-st-ok   { background: var(--phos); }
.subnav-dot.sd-st-idle { background: var(--amber); }

/* ---- main content ---------------------------------------------------- */

main.page {
    margin-left: var(--nav-w); padding: 8px 14px 28px;
    display: flex; flex-direction: column; gap: 8px;
}
main.page > h1 {
    font-size: 16px; font-weight: 600; letter-spacing: 2px;
    color: var(--phos); text-transform: uppercase;
}
main.page .intro {
    color: var(--ink-dim); font-size: 12px; line-height: 1.6;
    max-width: 900px;
}

section.table {
    background: var(--panel);
    border: 1px solid var(--panel-edge); border-radius:0;
    overflow: hidden;
}
section.table > h2 {
    display: flex; align-items: center;
    padding: 6px 12px; background: var(--panel-head);
    border-bottom: 1px solid var(--hair);
    font-family: ui-monospace, Consolas, monospace; font-size: 12px;
    font-weight: 500; letter-spacing: 1.5px;
    color: var(--ink); text-transform: uppercase;
}
section.table > h2 .count {
    color: var(--ink-mute); font-weight: normal;
    margin-left: 10px; font-size: 11px;
}
section.table > h2 .doc {
    color: var(--ink-mute); font-weight: normal;
    margin-left: 14px; font-size: 11px; font-style: italic;
    text-transform: none; letter-spacing: 0;
}
section.table > h2 .row-filter {
    margin-left: auto; width: 180px;
    font-size: 11px; padding: 3px 8px;
}
section.table > h2 .row-filter::placeholder {
    color: var(--ink-mute); text-transform: none; letter-spacing: 0;
}
section.table > h2 .row-filter + button {
    margin-left: 10px;
}
section.table > h2 button.add-row,
section.table > h2 button.toggle-noise {
    margin-left: 10px;
}
section.table > h2 button.add-row:first-of-type {
    margin-left: auto;
}
section.table > h2 button.toggle-noise {
    font-size: 10px; padding: 3px 8px;
    color: var(--ink-mute); border-color: var(--hair);
}
section.table > h2 button.toggle-noise:hover {
    color: var(--cyan); border-color: var(--cyan);
}
section.table > h2 button.toggle-noise.active {
    color: var(--cyan); border-color: var(--cyan);
    background: rgba(79, 195, 247, .06);
}

/* Hide noise columns by default; toggle-noise button removes the class. */
section.table.hide-noise table.rows th.noise,
section.table.hide-noise table.rows td.noise {
    display: none;
}
section.table .empty {
    padding: 14px; color: var(--ink-mute); font-style: italic;
    font-family: ui-monospace, Consolas, monospace; font-size: 12px;
}
section.table .scroll {
    overflow-x: auto;
}

table.rows {
    width: 100%; border-collapse: collapse;
    font-family: ui-monospace, Consolas, monospace; font-size: 12px;
}
table.rows th, table.rows td {
    padding: 3px 8px; text-align: left; vertical-align: top;
    border-bottom: 1px solid #141c23;
}
table.rows th {
    background: #0e151b; color: var(--ink-dim); font-weight: 500;
    font-size: 10px; letter-spacing: 1px; text-transform: uppercase;
    position: sticky; top: 0;
}
table.rows td { color: var(--ink); max-width: 28rem; word-break: break-word; }
table.rows td.null { color: var(--ink-mute); font-style: italic; }
table.rows td.actions { white-space: nowrap; text-align: right; }
table.rows tr:hover td:not(.actions) { background: rgba(79, 195, 247, .03); }
a.tag-link {
    color: var(--cyan); cursor: pointer; text-decoration: none;
    border-bottom: 1px dashed rgba(79, 195, 247, .4);
}
a.tag-link:hover {
    color: var(--phos); border-bottom-color: var(--phos);
}

/* ---- buttons + form controls ---------------------------------------- */

button {
    background: var(--panel); color: var(--ink);
    border: 1px solid var(--panel-edge); border-radius:0;
    padding: 5px 11px; cursor: pointer;
    font-family: ui-monospace, Consolas, monospace; font-size: 11px;
    letter-spacing: .5px;
}
button:hover { border-color: var(--phos); color: var(--phos); }
button.primary { border-color: var(--phos); color: var(--phos); }
button.primary:hover { background: rgba(58, 214, 160, .12); }
button.danger:hover { border-color: var(--red); color: var(--red); }
button.tags { border-color: var(--hair); color: var(--ink-dim); }
button.tags:hover { border-color: var(--cyan); color: var(--cyan); }
button:disabled { color: var(--ink-mute); border-color: var(--hair); cursor: not-allowed; }
button:disabled:hover { color: var(--ink-mute); border-color: var(--hair); }
button:focus-visible { outline: 2px solid var(--phos); outline-offset: 2px; border-radius: 0; }
button.danger:focus-visible { outline-color: var(--red); }

input, select, textarea {
    background: #0a0e12; color: var(--ink);
    border: 1px solid var(--panel-edge); border-radius:0;
    padding: 4px 8px;
    font-family: ui-monospace, Consolas, monospace; font-size: 12px;
}
input:focus, select:focus, textarea:focus {
    outline: none; border-color: var(--cyan);
}
input[readonly], select[disabled], textarea[readonly] {
    background: #0c1217; color: var(--ink-mute);
}
input[type="checkbox"] {
    width: 16px; height: 16px;
}

/* ---- toggle button (replaces raw checkboxes for bool fields) --------- */
.cfg-toggle {
    display: inline-flex; align-items: center;
    cursor: pointer; user-select: none;
    background: transparent; border: none; padding: 0;
}
.cfg-toggle input[type="checkbox"] {
    position: absolute; opacity: 0; width: 0; height: 0;
    pointer-events: none; margin: 0; padding: 0;
}
.cfg-toggle-track {
    width: 36px; height: 20px; border-radius:0;
    background: #1a2530; border: 1px solid var(--hair);
    transition: background .15s, border-color .15s;
    position: relative; display: block; flex-shrink: 0;
}
.cfg-toggle input:checked + .cfg-toggle-track {
    background: var(--cyan); border-color: var(--cyan);
}
.cfg-toggle-thumb {
    position: absolute; top: 2px; left: 2px;
    width: 14px; height: 14px; border-radius: 50%;
    background: var(--ink-mute);
    transition: left .15s, background .15s;
}
.cfg-toggle input:checked + .cfg-toggle-track .cfg-toggle-thumb {
    left: 18px; background: #fff;
}
.cfg-toggle input:disabled + .cfg-toggle-track {
    opacity: 0.45; cursor: not-allowed;
}

/* ---- modal ----------------------------------------------------------- */

#modal {
    display: none; position: fixed; inset: 0; z-index: 100;
    background: rgba(0, 0, 0, .65);
    align-items: flex-start; justify-content: center; padding: 8vh 0;
}
#modal.show { display: flex; }
#modal .content {
    background: var(--panel);
    border: 1px solid var(--panel-edge); border-radius:0;
    box-shadow: 0 8px 40px rgba(0, 0, 0, .8);
    width: min(640px, 92vw); max-height: 80vh;
    display: flex; flex-direction: column; overflow: hidden;
}
#modal .content > h3 {
    padding: 12px 16px; background: #0e151b;
    border-bottom: 1px solid var(--hair);
    font-family: ui-monospace, Consolas, monospace; font-size: 12px;
    color: var(--ink); letter-spacing: 1.5px; text-transform: uppercase;
    font-weight: 500;
}
#modal #modal-fields {
    padding: 6px 16px 12px; overflow-y: auto; flex: 1;
}

/* Collapsible field sections inside the modal. */
.field-section {
    border-top: 1px solid var(--hair);
}
.field-section:first-child {
    border-top: none;
}
.field-section-toggle {
    width: 100%; background: transparent; border: none;
    color: var(--ink-dim); padding: 8px 4px;
    text-align: left; cursor: pointer;
    font-family: ui-monospace, Consolas, monospace; font-size: 11px;
    letter-spacing: 1.5px; text-transform: uppercase; font-weight: 500;
    display: flex; align-items: center; gap: 8px;
}
.field-section-toggle:hover { color: var(--phos); }
.field-section-toggle .caret {
    display: inline-block; width: 10px; transition: transform .12s;
    color: var(--ink-mute);
}
.field-section.collapsed .field-section-toggle .caret {
    transform: rotate(-90deg);
}
.field-section-toggle .count {
    color: var(--ink-mute); font-weight: normal; letter-spacing: .5px;
}
.field-section-body { padding: 0 0 6px 8px; }
.field-section.collapsed .field-section-body { display: none; }
#modal .field {
    display: grid; grid-template-columns: 12rem 1fr;
    align-items: center; gap: 10px; padding: 5px 0;
}
#modal .field label {
    font-family: ui-monospace, Consolas, monospace; font-size: 11px;
    color: var(--ink-dim); letter-spacing: .5px;
}
#modal .field label .req { color: var(--amber); margin-left: 3px; }
#modal .field input, #modal .field select, #modal .field textarea {
    width: 100%;
}
#modal .field input[type="checkbox"] { width: 16px; justify-self: start; }
#modal .field .cfg-toggle { justify-self: start; }
#modal .field textarea { min-height: 5em; resize: vertical; }

/* Searchable tag combobox (renderTagField) -- used in the modal AND the inline
   settings panel. The match menu is position:fixed (JS sets its coords under
   the input) so the modal's overflow-y clip can't cut it off. */
.tag-combo { width: 100%; }
.tag-combo-input { width: 100%; }
.tag-combo-menu {
    position: fixed; z-index: 200; max-height: 240px; overflow-y: auto;
    background: #0a0e12; border: 1px solid var(--cyan); border-radius:0;
    box-shadow: 0 8px 20px rgba(0, 0, 0, .55);
}
.tag-combo-menu[hidden] { display: none; }
.tag-combo-opt {
    padding: 4px 9px; cursor: pointer; white-space: nowrap;
    overflow: hidden; text-overflow: ellipsis;
    font-family: ui-monospace, Consolas, monospace; font-size: 12px; color: var(--ink);
}
.tag-combo-opt:hover, .tag-combo-opt.active {
    background: rgba(58, 214, 160, .14); color: var(--phos);
}
.tag-combo-empty {
    padding: 4px 9px; font-size: 11px; color: var(--ink-mute); font-style: italic;
}
#modal .field .hint {
    font-family: ui-monospace, Consolas, monospace; font-size: 10px;
    color: var(--ink-mute); letter-spacing: .5px; grid-column: 2;
}
#modal .field.disabled label { color: var(--ink-mute); }
#modal .field.disabled .hint { color: var(--ink-mute); font-style: italic; }
/* Irrelevant fields: hidden when not applicable to the current discriminator
 * (kind, parser_key, transport, etc.). JS toggles .irrelevant on change. */
#modal .field.irrelevant { display: none; }
#modal .field .hint.relevance { color: var(--ink-mute); opacity: .55; }
#modal #modal-error {
    color: var(--red); font-family: ui-monospace, Consolas, monospace;
    font-size: 11px; padding: 0 16px; min-height: 1em;
}
#modal .actions {
    padding: 10px 16px; background: #0e151b;
    border-top: 1px solid var(--hair);
    display: flex; justify-content: flex-end; gap: 8px;
}

/* ---- port sub-modal: inline endpoint editor, layered above #modal --- */
/* Opened from the "+ New / Edit" buttons beside an endpoint_id dropdown so
 * an operator can define/adjust a port without leaving the input they are
 * editing. Flat field list (the endpoint form is short) rather than the
 * collapsible sections of the main modal. */
#port-modal {
    display: none; position: fixed; inset: 0; z-index: 120;
    background: rgba(0, 0, 0, .55);
    align-items: flex-start; justify-content: center; padding: 10vh 0;
}
#port-modal.show { display: flex; }
#port-modal .content {
    background: var(--panel);
    border: 1px solid var(--panel-edge); border-radius:0;
    box-shadow: 0 8px 40px rgba(0, 0, 0, .8);
    width: min(560px, 92vw); max-height: 78vh;
    display: flex; flex-direction: column; overflow: hidden;
}
#port-modal .content > h3 {
    padding: 12px 16px; background: #0e151b;
    border-bottom: 1px solid var(--hair);
    font-family: ui-monospace, Consolas, monospace; font-size: 12px;
    color: var(--cyan); letter-spacing: 1.5px; text-transform: uppercase;
    font-weight: 500;
}
#port-modal #port-modal-fields { padding: 8px 16px 12px; overflow-y: auto; flex: 1; }
#port-modal .field {
    display: grid; grid-template-columns: 12rem 1fr;
    align-items: center; gap: 10px; padding: 5px 0;
}
#port-modal .field label {
    font-family: ui-monospace, Consolas, monospace; font-size: 11px;
    color: var(--ink-dim); letter-spacing: .5px;
}
#port-modal .field input, #port-modal .field select { width: 100%; }
#port-modal .field input[type="checkbox"] { width: 16px; justify-self: start; }
#port-modal .field .cfg-toggle { justify-self: start; }
#port-modal .field .hint {
    font-family: ui-monospace, Consolas, monospace; font-size: 10px;
    color: var(--amber); letter-spacing: .5px; grid-column: 2;
}
#port-modal .field.irrelevant { display: none; }
#port-modal #port-modal-error {
    color: var(--red); font-family: ui-monospace, Consolas, monospace;
    font-size: 11px; padding: 0 16px; min-height: 1em;
}
#port-modal .actions {
    padding: 10px 16px; background: #0e151b;
    border-top: 1px solid var(--hair);
    display: flex; justify-content: flex-end; gap: 8px;
}

/* Inline "+ New / Edit" controls wrapping an endpoint_id dropdown. */
.ep-field-wrap { display: flex; gap: 6px; align-items: center; }
.ep-field-wrap select { flex: 1 1 auto; min-width: 0; }
.ep-actions { display: flex; gap: 4px; flex: 0 0 auto; }
.ep-actions .ep-btn { padding: 4px 8px; font-size: 10px; }

/* ---- confirm dialog (uses #modal CSS, narrower) --------------------- */

#confirm {
    display: none; position: fixed; inset: 0; z-index: 150;
    background: rgba(0, 0, 0, .65);
    align-items: center; justify-content: center;
}
#confirm.show { display: flex; }
#confirm .content {
    background: var(--panel);
    border: 1px solid var(--red); border-radius:0;
    box-shadow: 0 8px 40px rgba(0, 0, 0, .8);
    width: min(420px, 92vw);
    display: flex; flex-direction: column; overflow: hidden;
}
#confirm h3 {
    padding: 12px 16px; background: #0e151b;
    border-bottom: 1px solid var(--hair);
    font-family: ui-monospace, Consolas, monospace; font-size: 12px;
    color: var(--red); letter-spacing: 1.5px; text-transform: uppercase;
    font-weight: 500;
}
#confirm .body {
    padding: 14px 16px; color: var(--ink); font-size: 13px;
    line-height: 1.5;
}
#confirm .body code {
    background: #06090c; padding: 1px 6px; border-radius:0;
    color: var(--cyan); font-family: ui-monospace, Consolas, monospace;
    font-size: .92em;
}
#confirm .body .warn {
    color: var(--ink-mute); font-size: 11px; margin-top: 8px;
    font-family: ui-monospace, Consolas, monospace; letter-spacing: .5px;
}
#confirm .actions {
    padding: 10px 16px; background: #0e151b;
    border-top: 1px solid var(--hair);
    display: flex; justify-content: flex-end; gap: 8px;
}
#confirm button.danger {
    border-color: var(--red); color: var(--red);
}
#confirm button.danger:hover {
    background: rgba(224, 88, 79, .12); color: var(--red);
}

/* ---- reload banner --------------------------------------------------- */

#reload-banner {
    display: none; position: sticky; top: 0; z-index: 50;
    margin-left: var(--nav-w);   /* clear the fixed left nav sidebar */
    background: rgba(224, 162, 60, .12); border-bottom: 1px solid var(--amber);
    color: var(--amber);
    padding: 9px 22px;
    font-family: ui-monospace, Consolas, monospace; font-size: 12px;
    letter-spacing: .5px;
    align-items: center; gap: 12px;
}
#reload-banner.show { display: flex; }
#reload-banner.success {
    background: rgba(58, 214, 160, .10); border-bottom-color: var(--phos);
    color: var(--phos);
}
#reload-banner.error {
    background: rgba(224, 88, 79, .12); border-bottom-color: var(--red);
    color: var(--red);
}
#reload-banner .spacer { flex: 1; }
#reload-banner small { color: inherit; opacity: .75; }

/* ---- plot popup (non-modal, draggable, resizable) ------------------- */
/* A floating window, not a blocking modal: the #plot layer is
 * pointer-events:none so the page behind stays interactive, and .content is
 * a position:fixed box (JS sets left/top on open + on drag) with
 * resize:both. renderSvgChart() redraws at the live body size on resize. */

#plot {
    display: none; position: fixed; inset: 0; z-index: 110;
    pointer-events: none;
}
#plot.show { display: block; }
#plot .content {
    pointer-events: auto;
    position: fixed; top: 60px; left: 60px;
    width: min(820px, 92vw); height: min(460px, 80vh);
    min-width: 420px; min-height: 220px;
    max-width: 96vw; max-height: 92vh;
    resize: both; overflow: hidden;
    background: var(--panel);
    border: 1px solid var(--panel-edge); border-radius:0;
    box-shadow: 0 8px 40px rgba(0, 0, 0, .8);
    display: flex; flex-direction: column;
}
#plot .head {
    display: flex; align-items: center; gap: 8px;
    padding: 10px 14px; background: #0e151b;
    border-bottom: 1px solid var(--hair);
    cursor: move; user-select: none;
}
#plot .head h3 {
    flex: 1;
    font-family: ui-monospace, Consolas, monospace; font-size: 12px;
    color: var(--phos); letter-spacing: 1px; text-transform: lowercase;
    font-weight: 500;
}
#plot .head button {
    background: transparent; border: 1px solid var(--hair);
    color: var(--ink-dim); width: 28px; height: 26px;
    padding: 0; font-size: 14px; line-height: 1;
}
#plot .head button:hover { color: var(--phos); border-color: var(--phos); }
#plot .head .plot-ranges {
    display: flex; gap: 1px; margin-right: 6px;
}
#plot .head button.plot-range {
    width: auto; padding: 0 10px; height: 26px;
    font-family: ui-monospace, monospace; font-size: 10px;
    color: var(--ink-mute); letter-spacing: .5px;
    border-radius:0; border-right: none;
}
#plot .head button.plot-range:first-of-type {
    border-top-left-radius:0; border-bottom-left-radius:0;
}
#plot .head button.plot-range:last-of-type {
    border-right: 1px solid var(--hair);
    border-top-right-radius:0; border-bottom-right-radius:0;
}
#plot .head button.plot-range:hover {
    color: var(--cyan); border-color: var(--cyan);
}
#plot .head button.plot-range.active {
    color: var(--phos); border-color: var(--phos);
    background: rgba(58, 214, 160, .08);
}
#plot .body {
    flex: 1 1 auto; min-height: 0;
    padding: 14px 14px 6px;
    background: #06090c;
    overflow: hidden;
}
#plot .body svg {
    display: block;
}
#plot .body svg .grid line {
    stroke: var(--hair); stroke-width: 1;
}
#plot .body svg .grid text {
    fill: var(--ink-mute); font-family: ui-monospace, monospace; font-size: 10px;
}
#plot .body svg .line {
    fill: none; stroke: var(--phos); stroke-width: 1.5;
    stroke-linejoin: round; stroke-linecap: round;
}
#plot .body svg .bad-dot {
    fill: var(--amber); stroke: none;
}
#plot .body svg .crosshair line {
    stroke: var(--cyan); stroke-width: 1;
    stroke-dasharray: 3 3; opacity: .75; pointer-events: none;
}
#plot .body svg .crosshair .cx-dot {
    fill: var(--phos); stroke: #06090c; stroke-width: 1.5;
}
#plot .body .plot-empty {
    color: var(--ink-mute); font-family: ui-monospace, monospace; font-size: 12px;
    padding: 120px 0; text-align: center;
}
#plot .body .plot-empty code {
    color: var(--cyan); background: #0c1217; padding: 1px 5px; border-radius:0;
}
#plot .foot {
    padding: 8px 14px; background: #0e151b;
    border-top: 1px solid var(--hair);
    font-family: ui-monospace, monospace; font-size: 11px;
    color: var(--ink-mute);
}

/* Hover value tooltip -- floats next to the cursor, follows the crosshair.
 * Sibling of .content inside #plot so it isn't wiped by body re-renders and
 * hides with the window. */
#plot-tooltip {
    position: fixed; z-index: 111; display: none;
    pointer-events: none;
    background: rgba(10, 14, 18, .96);
    border: 1px solid var(--cyan); border-radius:0;
    padding: 4px 9px;
    font-family: ui-monospace, Consolas, monospace; letter-spacing: .5px;
    box-shadow: 0 4px 18px rgba(0, 0, 0, .65);
    white-space: nowrap;
}
#plot-tooltip .tip-val { color: var(--phos); font-size: 13px; }
#plot-tooltip .tip-val.bad { color: var(--amber); }
#plot-tooltip .tip-val .tip-q { color: var(--ink-mute); font-size: 10px; }
#plot-tooltip .tip-time { color: var(--ink-mute); font-size: 10px; margin-top: 1px; }

/* ---- tag drawer ----------------------------------------------------- */

#tag-drawer {
    position: fixed; top: 0; right: 0; bottom: 0;
    width: 380px; z-index: 90;
    background: var(--panel);
    border-left: 1px solid var(--panel-edge);
    box-shadow: -4px 0 16px rgba(0, 0, 0, .35);
    display: none; flex-direction: column;
}
#tag-drawer.show { display: flex; }
body.tag-rail-open main.page { margin-right: 380px; }
#tag-drawer .drawer-head {
    display: flex; align-items: center; gap: 10px;
    padding: 12px 16px; background: #0e151b;
    border-bottom: 1px solid var(--hair);
}
#tag-drawer .drawer-head h3 {
    flex: 1;
    font-family: ui-monospace, Consolas, monospace; font-size: 12px;
    color: var(--phos); letter-spacing: 1.5px; text-transform: uppercase;
    font-weight: 500;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
#tag-drawer .drawer-head code {
    background: #06090c; padding: 1px 5px; border-radius:0;
    color: var(--cyan); font-size: .9em;
}
#tag-drawer .drawer-body {
    padding: 14px 16px; overflow-y: auto; flex: 1;
}
#tag-drawer .drawer-body .empty {
    color: var(--ink-mute); font-family: ui-monospace, Consolas, monospace;
    font-size: 12px; font-style: italic;
}
#tag-drawer .drawer-body .empty code {
    color: var(--cyan); background: #06090c; padding: 1px 5px;
    border-radius:0; font-style: normal;
}
ul.tag-list { list-style: none; padding: 0; margin: 0; }
ul.tag-list li {
    display: flex; align-items: center; gap: 8px;
    padding: 6px 0; border-bottom: 1px solid #141c23;
}
ul.tag-list li:last-child { border-bottom: none; }
ul.tag-list .name {
    flex: 1; font-family: ui-monospace, Consolas, monospace; font-size: 12px;
    color: var(--ink); word-break: break-all;
}
ul.tag-list .missing {
    font-family: ui-monospace, Consolas, monospace; font-size: 10px;
    color: var(--amber); letter-spacing: .5px;
}
ul.tag-list .tag-val {
    font-family: ui-monospace, Consolas, monospace; font-size: 11px;
    color: var(--ink); min-width: 52px; text-align: right; white-space: nowrap;
}
ul.tag-list .tag-qual {
    font-family: ui-monospace, Consolas, monospace; font-size: 9px;
    letter-spacing: .5px; text-transform: uppercase;
    min-width: 36px; text-align: center;
}
ul.tag-list .tq-good   { color: var(--phos); }
ul.tag-list .tq-uncert { color: var(--amber); }
ul.tag-list .tq-bad,
ul.tag-list .tq-oor    { color: var(--red); }
ul.tag-list button.plot {
    font-size: 10px; padding: 3px 8px;
}

/* Selected row in a has-tags table. */
section.table.has-tags tbody tr { cursor: pointer; }
tr.tdr-selected td { background: #0a1520 !important; }
#tag-drawer .drawer-foot {
    margin-top: 14px; padding-top: 10px;
    border-top: 1px solid var(--hair);
    color: var(--ink-mute);
}
#tag-drawer .drawer-foot small {
    font-family: ui-monospace, Consolas, monospace; font-size: 10px;
}
#tag-drawer .drawer-foot code {
    background: #06090c; padding: 1px 5px; border-radius:0;
    color: var(--cyan); font-size: .9em;
}

/* ---- toasts --------------------------------------------------------- */

#toasts {
    position: fixed; bottom: 20px; right: 20px; z-index: 200;
    display: flex; flex-direction: column; gap: 8px;
    max-width: 420px; pointer-events: none;
}
.toast {
    pointer-events: auto;
    background: var(--panel);
    border: 1px solid var(--panel-edge); border-radius:0;
    padding: 9px 14px;
    font-family: ui-monospace, Consolas, monospace; font-size: 12px;
    color: var(--ink); letter-spacing: .5px;
    display: flex; align-items: center; gap: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, .6);
    transition: opacity .35s, transform .25s;
    animation: toast-in .18s ease-out;
}
@keyframes toast-in {
    from { opacity: 0; transform: translateX(20px); }
    to   { opacity: 1; transform: translateX(0); }
}
@media (prefers-reduced-motion: reduce) {
    .toast { animation: none; }
    *, *::before, *::after { transition-duration: .01ms !important; }
}
.toast.fade { opacity: 0; transform: translateX(20px); }
.toast .msg { flex: 1; }
.toast.success { border-color: var(--phos); color: var(--phos); }
.toast.success::before {
    content: ""; width: 8px; height: 8px; border-radius: 50%;
    background: var(--phos); 
    flex-shrink: 0;
}
.toast.error { border-color: var(--red); color: var(--red); }
.toast.error::before {
    content: ""; width: 8px; height: 8px; border-radius: 50%;
    background: var(--red); 
    flex-shrink: 0;
}
.toast.info { border-color: var(--cyan); color: var(--cyan); }
.toast.info::before {
    content: ""; width: 8px; height: 8px; border-radius: 50%;
    background: var(--cyan); 
    flex-shrink: 0;
}
.toast .dismiss {
    background: transparent; border: none; color: inherit; opacity: .6;
    cursor: pointer; padding: 0 4px; font-size: 16px; line-height: 1;
}
.toast .dismiss:hover { opacity: 1; }

/* ---- status line ----------------------------------------------------- */

#status {
    font-family: ui-monospace, Consolas, monospace; font-size: 11px;
    color: var(--ink-mute); letter-spacing: .5px;
}
#status.err { color: var(--red); }

/* ====== master-detail sensor editor ================================== */
.sensor-editor {
    background: var(--panel);
    border: 1px solid var(--panel-edge); border-radius:0;
    margin-bottom: 22px;
}

/* ---- sensor count chip in page heading -------------------------------- */
.sensor-count-chip {
    display: inline-block; vertical-align: middle;
    font-family: ui-monospace, Consolas, monospace;
    font-size: 9px; letter-spacing: 1px; text-transform: uppercase;
    color: var(--ink-mute); border: 1px solid var(--hair);
    padding: 1px 8px; margin-left: 12px; font-weight: normal;
}
.sensor-count-chip.chip-none { color: var(--amber); border-color: var(--amber); }

/* ---- empty state ------------------------------------------------------- */
.sensor-detail-empty { padding: 0; }
.sensor-detail-empty .muted, .endpoint-box .muted {
    color: var(--ink-mute); font-style: italic; font-size: 13px;
}
.sensor-empty-state {
    display: flex; flex-direction: column; align-items: center;
    padding: 52px 24px; gap: 10px; text-align: center;
}
.ses-glyph {
    font-family: ui-monospace, Consolas, monospace;
    font-size: 30px; color: var(--hair); letter-spacing: 6px; line-height: 1;
    margin-bottom: 4px;
}
.ses-heading {
    font-size: 12px; font-weight: 600; color: var(--ink-dim);
    letter-spacing: 1px; text-transform: uppercase;
}
.ses-body {
    font-size: 11px; color: var(--ink-mute); max-width: 34ch;
    line-height: 1.55; font-family: ui-monospace, Consolas, monospace;
    letter-spacing: .3px;
}
.ses-add { margin-top: 6px; }
.sensor-detail {
    display: grid; grid-template-columns: minmax(14rem, 20rem) 1fr;
    gap: 16px; padding: 14px 16px;
}
/* Single column when there's no left pane (no endpoint FK + no live feed,
   e.g. OPC UA instances): the settings form spans the full width. */
.sensor-detail.single { grid-template-columns: 1fr; }
@media (max-width: 880px) { .sensor-detail { grid-template-columns: 1fr; } }

/* ---- Settings / Maps tab bar (protocol instance detail pane) ---------- */
.detail-with-maps { display: flex; flex-direction: column; min-width: 0; }
.detail-tabs {
    display: flex; gap: 0; flex-shrink: 0;
    border-bottom: 1px solid var(--hair);
}
.dtab {
    background: transparent; border: none;
    border-bottom: 2px solid transparent;
    color: var(--ink-mute);
    font-family: ui-monospace, Consolas, monospace; font-size: 11px;
    letter-spacing: 1px; text-transform: uppercase;
    padding: 7px 14px; cursor: pointer; margin-bottom: -1px;
    transition: color .12s, border-color .12s;
}
.dtab:hover { color: var(--ink); }
.dtab.dtab-active { color: var(--phos); border-bottom-color: var(--phos); }
.dtab:focus-visible { outline: 2px solid var(--phos); outline-offset: -2px; border-radius: 0; }
.dtab-count {
    display: inline-block; min-width: 18px; text-align: center;
    background: rgba(58,214,160,.18); color: var(--phos);
    border-radius: 0; font-size: 10px; padding: 0 4px;
    letter-spacing: 0; vertical-align: middle;
    margin-left: 4px;
}
.dtab-pane { display: none; }
.dtab-pane.dtab-pane-active { display: block; }

/* ---- Inline instance-maps table --------------------------------------- */
/* Lives in the Maps tab; reuses .rows table styles for the data table. */
.imaps { padding: 10px 14px 4px; }
.imaps-hdr {
    display: flex; align-items: center; gap: 10px;
    padding-bottom: 8px; margin-bottom: 6px;
    border-bottom: 1px solid var(--hair);
}
.imaps-count {
    flex: 1 1 auto;
    font-family: ui-monospace, Consolas, monospace; font-size: 11px;
    color: var(--ink-mute); letter-spacing: .3px;
}
.imaps-add { font-size: 10px; padding: 3px 9px; }
.imaps-empty {
    padding: 14px 0; font-size: 12px; color: var(--ink-mute);
    font-family: ui-monospace, Consolas, monospace;
    letter-spacing: .3px; line-height: 1.55;
}
.imaps-empty strong { color: var(--ink-dim); }
.imaps-scroll { overflow-x: auto; }
/* imaps-table reuses .rows for header/row styling; only scope it to be compact. */
.imaps-table { font-size: 11px; }
.imaps-table td, .imaps-table th { padding: 2px 6px; }
.imaps-del { font-size: 10px; padding: 2px 7px; border-color: var(--red); color: var(--red); }
.imaps-del:hover { background: rgba(224,88,79,.12); border-color: var(--red); color: var(--red); }
.imaps-edit { font-size: 10px; padding: 2px 7px; margin-right: 4px; }

/* Singleton inline settings form (e.g. helideck_config): a standalone
   .settings-box inside a .table section, width-capped for readability. */
.singleton-form .settings-box { max-width: 60rem; }
.singleton-form .settings-actions { display: flex; align-items: center;
    gap: 12px; margin-top: 12px; }

/* Regime-grouped roster (helicopter_limits): filter + list + inline detail. */
section.table.roster > h2 .roster-regime { margin-left: auto;
    font-weight: normal; text-transform: none; letter-spacing: 0;
    font-size: 11px; color: var(--ink-mute); display: inline-flex;
    align-items: center; gap: 6px; }
section.table.roster > h2 .roster-regime select { font: inherit; }
section.table.roster > h2 button.add-row { margin-left: 10px; }
.roster-body { display: grid; grid-template-columns: minmax(15rem, 20rem) 1fr;
    gap: 16px; padding: 14px 16px; }
@media (max-width: 880px) { .roster-body { grid-template-columns: 1fr; } }
.roster-list { display: flex; flex-direction: column; gap: 4px;
    max-height: 30rem; overflow-y: auto; }
.roster-item { display: flex; align-items: baseline; gap: 8px; width: 100%;
    text-align: left; padding: 6px 10px; border: 1px solid var(--hair);
    border-radius:0; background: var(--bg-soft); color: var(--ink);
    font: inherit; cursor: pointer; }
.roster-item:hover { border-color: var(--cyan); }
.roster-item.selected { border-color: var(--cyan);
    background: rgba(80, 160, 200, .12); }
.roster-item .ri-code { font-family: ui-monospace, Consolas, monospace;
    font-weight: 600; }
.roster-item .ri-name { color: var(--ink-dim); flex: 1 1 auto; overflow: hidden;
    text-overflow: ellipsis; white-space: nowrap; }
.roster-item .ri-cat { font-size: 10px; color: var(--ink-mute); }
.roster-item .ri-def { font-size: 9px; text-transform: uppercase;
    letter-spacing: 1px; color: var(--cyan); border: 1px solid var(--cyan);
    border-radius:0; padding: 0 4px; }

/* ---- endpoint box header: status badge + port identity -------------- */
.ep-header {
    display: flex; align-items: center; gap: 10px; margin-bottom: 8px;
}
.ep-ident { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; min-width: 0; }
.ep-state-badge {
    font-family: ui-monospace, Consolas, monospace; font-size: 11px;
    text-transform: uppercase; letter-spacing: 1.5px;
    border: 1px solid var(--hair); color: var(--ink-mute);
    padding: 3px 10px; flex-shrink: 0;
    transition: color .25s, border-color .25s, background .25s;
}
.ep-state-badge.st-ok   { color: var(--phos);  border-color: var(--phos);  background: rgba(58,214,160,.08); }
.ep-state-badge.st-idle { color: var(--amber); border-color: var(--amber); background: rgba(224,162,60,.08); }
.ep-state-badge.st-none { background: transparent; }
.ep-where-line {
    color: var(--ink-mute); font-family: ui-monospace, Consolas, monospace;
    font-size: 11px; margin-bottom: 10px; padding-bottom: 8px;
    border-bottom: 1px solid var(--hair);
}
.rx-values-head {
    font-family: ui-monospace, Consolas, monospace; font-size: 10px;
    text-transform: uppercase; letter-spacing: 1px; color: var(--ink-dim);
    margin: 12px 0 6px;
}

/* --- left: endpoint box --- */
.endpoint-box, .settings-box {
    border: 1px solid var(--hair); border-radius:0;
    background: var(--bg-soft); padding: 12px 14px;
}
.endpoint-box h3, .settings-box h3 {
    font-family: ui-monospace, Consolas, monospace; font-size: 11px;
    text-transform: uppercase; letter-spacing: 1.5px; color: var(--ink);
    border-bottom: 1px solid var(--hair); padding-bottom: 8px; margin-bottom: 10px;
}
.endpoint-box h4 {
    font-family: ui-monospace, Consolas, monospace; font-size: 10px;
    text-transform: uppercase; letter-spacing: 1px; color: var(--ink-dim);
    margin: 12px 0 6px; display: flex; align-items: center; gap: 8px;
}
.ep-summary {
    display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
    margin-bottom: 10px;
}
.kind-badge {
    font-family: ui-monospace, Consolas, monospace; font-size: 10px;
    text-transform: uppercase; letter-spacing: 1px; color: var(--cyan);
    border: 1px solid var(--cyan); border-radius:0; padding: 1px 6px;
}
.ep-summary .ep-name { color: var(--ink); font-size: 13px; }
.ep-summary .ep-where {
    color: var(--ink-mute); font-family: ui-monospace, Consolas, monospace;
    font-size: 11px; width: 100%;
}
.ep-repoint { margin-bottom: 4px; }
.ep-repoint > label {
    display: block; font-family: ui-monospace, Consolas, monospace;
    font-size: 10px; text-transform: uppercase; letter-spacing: 1px;
    color: var(--ink-dim); margin-bottom: 4px;
}

/* feed status */
.ep-status .status-grid { width: 100%; border-collapse: collapse; }
.ep-status .status-grid th {
    text-align: left; font-weight: normal; color: var(--ink-mute);
    font-family: ui-monospace, Consolas, monospace; font-size: 11px; padding: 2px 0;
}
.ep-status .status-grid td {
    text-align: right; color: var(--phos);
    font-family: ui-monospace, Consolas, monospace; font-size: 12px;
}
.live-state {
    font-family: ui-monospace, Consolas, monospace; font-size: 10px;
    text-transform: uppercase; letter-spacing: 1px; border-radius:0;
    padding: 1px 7px; border: 1px solid var(--hair); color: var(--ink-mute);
}
.live-state.st-ok   { color: var(--phos);  border-color: var(--phos); }
.live-state.st-idle { color: var(--amber); border-color: var(--amber); }
.live-state.st-none { color: var(--ink-mute); }

/* received values (raw decoded channels) -- sensor editor left pane */
.rx-grid { width: 100%; border-collapse: collapse; }
.rx-grid th {
    text-align: left; font-weight: normal; color: var(--ink-mute);
    font-family: ui-monospace, Consolas, monospace; font-size: 11px; padding: 2px 0;
}
.rx-grid td {
    text-align: right; color: var(--ink);
    font-family: ui-monospace, Consolas, monospace; font-size: 12px;
    font-variant-numeric: tabular-nums;
}

/* inspect-stream console + send box (ported from the monitor page) */
.inspect-block, .send-box {
    margin-top: 12px; padding-top: 8px; border-top: 1px solid var(--hair);
}
.inspect-toggle {
    display: flex; align-items: center; gap: 6px; cursor: pointer;
    font-family: ui-monospace, Consolas, monospace; font-size: 11px;
    color: var(--ink-dim); letter-spacing: .5px;
}
.inspect-toggle input { margin: 0; }
.inspect-console {
    display: none; margin-top: 6px;
    background: #06090c; border: 1px solid var(--hair); border-radius:0;
    padding: 4px 6px; max-height: 16rem; overflow-y: auto;
    font-family: ui-monospace, Consolas, monospace; font-size: 10px;
    color: var(--ink-dim); line-height: 1.45;
}
.inspect-console.on { display: block; }
.inspect-console .ts    { color: var(--ink-mute); }
.inspect-console .muted { color: var(--ink-mute); font-style: italic; }
.inspect-console .hex   { color: var(--phos); }
.inspect-console .asc   { color: var(--cyan); }
.inspect-console .cmd   { color: var(--amber); }
.inspect-console .cmd-tag { color: var(--amber); font-weight: 600; padding: 0 4px; }
.inspect-console .gap   { color: var(--red); font-weight: 600; }
.send-box { display: flex; align-items: center; gap: 8px; }
.send-box input[type="text"] {
    flex: 1; min-width: 0; background: #06090c; color: var(--ink);
    border: 1px solid var(--panel-edge); border-radius:0; padding: 4px 7px;
    font-family: ui-monospace, Consolas, monospace; font-size: 11px;
}
.send-box input[type="text"]:focus { border-color: var(--cyan); outline: none; }
.send-box .send-status {
    font-size: 10px; min-width: 4em; color: var(--ink-mute);
    font-family: ui-monospace, Consolas, monospace;
}
.send-box .send-status.ok  { color: var(--phos); }
.send-box .send-status.err { color: var(--red); }

/* --- right: settings form (mirrors the modal .field rules, scoped here
 * so the modal is untouched) --- */
.settings-box .field {
    display: grid; grid-template-columns: 11rem 1fr;
    align-items: center; gap: 10px; padding: 5px 0;
}
.settings-box .field label {
    font-family: ui-monospace, Consolas, monospace; font-size: 11px;
    color: var(--ink-dim); letter-spacing: .5px;
}
.settings-box .field input, .settings-box .field select,
.settings-box .field textarea { width: 100%; }
.settings-box .field input[type="checkbox"] { width: 16px; justify-self: start; }
.settings-box .field .cfg-toggle { justify-self: start; }
.settings-box .field textarea { min-height: 5em; resize: vertical; }
.settings-box .field .hint {
    font-family: ui-monospace, Consolas, monospace; font-size: 10px;
    color: var(--ink-mute); letter-spacing: .5px; grid-column: 2;
}
.settings-box .field.disabled label { color: var(--ink-mute); }
.settings-box .field.disabled .hint { color: var(--ink-mute); font-style: italic; }
.settings-box .field.irrelevant { display: none; }
.settings-box .field .hint.relevance { color: var(--ink-mute); opacity: .55; }
.settings-actions {
    margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--hair);
    display: flex; align-items: center; gap: 8px;
}
.settings-actions .settings-msg {
    font-family: ui-monospace, Consolas, monospace; font-size: 11px;
    color: var(--ink-mute);
}
.settings-actions .settings-msg.err { color: var(--red); }
.settings-action-gap { flex: 1; }

/* Field-section accent: open sections get a left-border pulse. */
.field-section:not(.collapsed) > .field-section-toggle {
    color: var(--ink);
    box-shadow: inset 2px 0 0 var(--phos);
}
