/* ═══════════════════════════════════════════════════════════════
   dronecan.css — DroneCAN Interface page styles + shared component
   library for every feature panel (nodes, bus monitor, plotter,
   subscriber, log, ESC/actuator panels, adapter panel).

   Everything visual sits on tokens.css / base.css / modern.css; this
   file adds the tab strip, the local-node strip, the dc-* component
   kit (tables, toolbars, chips, pills, modals, kv grids, vertical
   sliders, log views, progress bars) in the same square, mono
   Hargrave language as canterminal. All colours come from tokens
   (var(--accent) etc.); every hardcoded dark surface (#1e1e1e
   pattern) carries a [data-theme="light"] override next to it.
   ═══════════════════════════════════════════════════════════════ */

.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }

/* ─────────────────────────────────────────────
   Topbar — compact single-row connection bar
   (canterminal pattern) + stat chips
   ───────────────────────────────────────────── */
.topbar { padding: 5px 12px; gap: 8px; }
.topbar .status { padding: 3px 8px; font-size: 12.5px; white-space: nowrap; }
.topbar-status { gap: 8px; flex-wrap: wrap; }
.topbar-conn { gap: 5px; }
.topbar-conn select {
    width: auto;
    min-width: 0;
    height: 24px;
    padding: 2px 4px;
    font-size: 11px;
}
.topbar-conn button {
    height: 24px;
    padding: 3px 8px;
    font-size: 11px;
    letter-spacing: 0.6px;
    white-space: nowrap;
}

/* stat chips (FRAMES / RATE / LOAD / TX / ERR) — shared clone as .dc-chip */
.term-chip,
.dc-chip {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 12px;
    color: var(--muted2);
    letter-spacing: 0.4px;
    white-space: nowrap;
}
.term-chip b,
.dc-chip b {
    color: var(--muted);
    font-weight: 600;
}

/* #statLoad severity: warn colour past 70 %, err past 90 % */
#statLoad.hot { color: var(--warn); }
#statLoad.crit { color: var(--err); }

/* ─────────────────────────────────────────────
   Local-node / adapter / bus strip
   ───────────────────────────────────────────── */
.term-strip {
    display: flex;
    align-items: center;
    gap: 6px 12px;
    flex-wrap: wrap;
    padding: 5px 12px;
    margin-bottom: 10px;
}
.strip-title {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1.6px;
    color: var(--accent);
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    white-space: nowrap;
}
[data-theme="light"] .strip-title { color: #b35000; }
.strip-item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
}
.strip-sep {
    width: 1px;
    height: 18px;
    background: var(--border2);
    flex-shrink: 0;
}
.term-strip button { height: 24px; padding: 3px 10px; font-size: 12px; }
.term-strip .toggle-switch { gap: 5px; }
.term-strip .toggle-label { font-size: 11px; }

/* local node ID input — small mono spin */
#localNodeId {
    width: 60px;
    height: 24px;
    padding: 2px 6px;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 12px;
}

/* conflict warning chip */
#nodeIdWarn { font-weight: 700; letter-spacing: 0.8px; }

/* flash / event line — monospace, right-aligned, grows */
#flashMsg {
    margin-left: auto;
    flex: 1 1 140px;
    min-width: 0;
    text-align: right;
    font-size: 11px;
    color: var(--muted2);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
#flashMsg.ok { color: var(--ok); }
#flashMsg.err { color: var(--err); }

/* ─────────────────────────────────────────────
   Bus-signal pills (WARN / PASSIVE / BUS-OFF / OVERRUN)
   ───────────────────────────────────────────── */
.sig-pill {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 10.5px;
    font-weight: 700;
    letter-spacing: 1.2px;
    padding: 2px 7px;
    border: 1px solid var(--border2);
    color: var(--muted2);
    background: rgba(0,0,0,0.15);
    white-space: nowrap;
    transition: color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}
.sig-pill.on {
    color: var(--ok);
    border-color: rgba(92,184,92,0.5);
    box-shadow: 0 0 10px rgba(92,184,92,0.15);
}
.sig-pill.warnp.on {
    color: var(--warn);
    border-color: rgba(255,196,0,0.5);
    box-shadow: 0 0 10px rgba(255,196,0,0.16);
}
.sig-pill.bad.on {
    color: var(--err);
    border-color: rgba(217,83,79,0.55);
    box-shadow: 0 0 10px rgba(217,83,79,0.18);
}
[data-theme="light"] .sig-pill { background: #efefef; }

/* ─────────────────────────────────────────────
   Tab strip + panel sections
   ───────────────────────────────────────────── */
.dc-tabs {
    display: flex;
    flex-wrap: wrap;
    margin-bottom: 10px;
}
.dc-tabs .mode-btn {
    padding: 7px 16px;
    font-size: 11px;
    letter-spacing: 1px;
}
.dc-tabs .mode-btn + .mode-btn { border-left: none; }

.dc-panel[hidden],
.dc-subpanel[hidden] { display: none !important; }

/* PANELS inner segmented switch */
#panelsSwitch { margin-bottom: 10px; flex-wrap: wrap; }

/* segmented switch — card headers (Trace/Overview-style) + #panelsSwitch */
.view-switch { display: inline-flex; flex-shrink: 0; }
.view-switch .mode-btn {
    padding: 5px 12px;
    font-size: 11px;
    letter-spacing: 0.8px;
}
.view-switch .mode-btn + .mode-btn { border-left: none; }

/* card header: section title left, controls right */
.section-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 6px;
}
.section-head .section-title { margin-bottom: 0; }

/* ─────────────────────────────────────────────
   NODES layout — wide main column + right rail
   ───────────────────────────────────────────── */
.dc-grid-nodes {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 340px;
    gap: 10px;
    align-items: start;
}
.dc-rail {
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-width: 0;
}

/* ─────────────────────────────────────────────
   Toolbar (term-actions clone) + inputs
   ───────────────────────────────────────────── */
.dc-toolbar {
    display: flex;
    align-items: center;
    gap: 6px 14px;
    flex-wrap: wrap;
    margin-bottom: 6px;
}
.dc-toolbar-right {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}
.dc-toolbar button { height: 24px; padding: 3px 9px; font-size: 11px; }
.dc-toolbar select {
    width: auto;
    min-width: 0;
    height: 26px;
    padding: 2px 6px;
    font-size: 11.5px;
}

/* checkbox toggles inside toolbars (term-toggle clone) */
.term-toggle,
.dc-check {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    user-select: none;
    cursor: pointer;
    font-size: 12px;
    color: var(--muted);
    white-space: nowrap;
}
.term-toggle input[type="checkbox"],
.dc-check input[type="checkbox"] { accent-color: var(--accent); cursor: pointer; }

/* mono text/number inputs in toolbars, form rows and command rows */
.dc-toolbar input[type="text"],
.dc-form-row input[type="text"],
.dc-cmd-row input[type="text"] {
    height: 26px;
    width: auto;
    padding: 4px 7px;
    background: #1e1e1e;
    color: var(--text);
    border: 1px solid var(--border);
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 12px;
    outline: none;
}
.dc-toolbar input[type="number"],
.dc-form-row input[type="number"] {
    height: 26px;
    width: 74px;
    padding: 4px 7px;
    background: #1e1e1e;
    color: var(--text);
    border: 1px solid var(--border);
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 12px;
    outline: none;
}
.dc-toolbar input[type="text"]:focus,
.dc-toolbar input[type="number"]:focus,
.dc-form-row input[type="text"]:focus,
.dc-form-row input[type="number"]:focus,
.dc-cmd-row input[type="text"]:focus { border-color: var(--accent); }
[data-theme="light"] .dc-toolbar input[type="text"],
[data-theme="light"] .dc-toolbar input[type="number"],
[data-theme="light"] .dc-form-row input[type="text"],
[data-theme="light"] .dc-form-row input[type="number"],
[data-theme="light"] .dc-cmd-row input[type="text"] { background: #e4e4e4; }

/* invalid-input flag (bad expression / bad hex) */
.dc-toolbar input.bad,
.dc-form-row input.bad,
.dc-cmd-row input.bad,
input.dc-bad {
    border-color: var(--err);
    box-shadow: 0 0 0 2px rgba(217,83,79,0.18);
}

/* label + control rows */
.dc-form-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 6px 0;
    flex-wrap: wrap;
}
.dc-form-row > label { font-size: 12px; color: var(--muted); min-width: 120px; }

/* command line row (adapter panel & friends) */
.dc-cmd-row {
    display: flex;
    align-items: stretch;
    gap: 6px;
    margin-top: 6px;
    flex-wrap: wrap;
}
.dc-cmd-row input[type="text"] { flex: 1; min-width: 140px; }
.dc-cmd-row button { height: 26px; padding: 3px 10px; font-size: 12px; }

/* shared hint line */
.term-hint,
.dc-hint {
    margin-top: 4px;
    font-size: 11px;
    color: var(--muted2);
    line-height: 1.5;
}
.term-hint b,
.dc-hint b { color: var(--muted); font-weight: 600; }

/* ─────────────────────────────────────────────
   Tables — mono, sticky thead, canterminal look
   ───────────────────────────────────────────── */
.dc-table-wrap {
    background: #1e1e1e;
    border: 1px solid var(--border);
    min-height: 80px;
    max-height: 420px;
    overflow-y: auto;
    overflow-x: auto;
    resize: vertical;
    overflow-anchor: none;
}
[data-theme="light"] .dc-table-wrap { background: #e4e4e4; }
.dc-table {
    width: 100%;
    border-collapse: collapse;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 11.5px;
}
.dc-table thead th {
    position: sticky;
    top: 0;
    z-index: 2;
    text-align: left;
    padding: 5px 8px;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--muted);
    /* opaque so scrolling rows never show through the sticky header */
    background: linear-gradient(rgba(255,134,41,0.05), rgba(255,134,41,0.05)), #1e1e1e;
    border-bottom: 1px solid var(--border2);
    white-space: nowrap;
}
[data-theme="light"] .dc-table thead th {
    background: linear-gradient(rgba(198,86,0,0.05), rgba(198,86,0,0.05)), #e4e4e4;
}
.dc-table td {
    padding: 2px 8px;
    border-bottom: 1px solid #2a2a2a;
    color: var(--text);
    white-space: nowrap;
    vertical-align: top;
}
[data-theme="light"] .dc-table td { border-bottom-color: #d6d6d6; }
.dc-table tbody tr:hover td { background: rgba(255,255,255,0.03); }
[data-theme="light"] .dc-table tbody tr:hover td { background: rgba(0,0,0,0.04); }
/* selected row */
.dc-table tbody tr.sel td { background: rgba(255,134,41,0.14); }
[data-theme="light"] .dc-table tbody tr.sel td { background: rgba(198,86,0,0.12); }
/* stale / offline rows */
.dc-table tr.dc-stale td { color: var(--muted2); opacity: 0.66; }
/* change flash (DNA table & friends): add .chg, remove after ~1.5 s */
.dc-table tbody tr.chg td { background: rgba(255,134,41,0.16); }
[data-theme="light"] .dc-table tbody tr.chg td { background: rgba(198,86,0,0.12); }

/* ─────────────────────────────────────────────
   Log / YAML views — mono scroll boxes
   ───────────────────────────────────────────── */
.dc-log-view {
    background: #1e1e1e;
    border: 1px solid var(--border);
    padding: 6px 8px;
    height: 220px;
    overflow-y: auto;
    overflow-x: auto;
    resize: vertical;
    overflow-anchor: none;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 11.5px;
    line-height: 1.5;
    color: var(--muted);
    white-space: pre-wrap;
    word-break: break-word;
}
[data-theme="light"] .dc-log-view { background: #e4e4e4; }
.dc-log-view .tx { color: var(--accent); }
.dc-log-view .rx { color: var(--text); }
.dc-log-view .muted { color: var(--muted2); }
.dc-log-view .err { color: var(--err); }

/* ─────────────────────────────────────────────
   Key/value info grids (node info, adapter identity)
   ───────────────────────────────────────────── */
.dc-kv {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 3px 14px;
    align-items: start;
}
.dc-kv > :nth-child(odd) {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--muted2);
    padding-top: 2px;
    white-space: nowrap;
}
.dc-kv > :nth-child(even) {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 11.5px;
    color: var(--text);
    word-break: break-all;
    min-width: 0;
}

/* ─────────────────────────────────────────────
   Health / mode pills (node monitor & friends)
   .h0 OK · .h1 WARNING · .h2 ERROR · .h3 CRITICAL
   .m1 INIT · .m2 MAINT · .m3 SW-UPDATE · .m7 OFFLINE
   ───────────────────────────────────────────── */
.dc-pill {
    display: inline-block;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 10.5px;
    font-weight: 700;
    letter-spacing: 0.6px;
    padding: 1px 7px;
    border: 1px solid var(--border2);
    color: var(--muted);
    background: rgba(0,0,0,0.15);
    white-space: nowrap;
}
[data-theme="light"] .dc-pill { background: #efefef; }
.dc-pill.h0 { color: var(--ok);   border-color: rgba(92,184,92,0.45); }
.dc-pill.h1 { color: var(--warn); border-color: rgba(255,196,0,0.45); }
.dc-pill.h2 { color: #ff7043;     border-color: rgba(255,112,67,0.5); }
.dc-pill.h3 { color: var(--err);  border-color: rgba(217,83,79,0.55); }
.dc-pill.m1 { color: #41c7d6;     border-color: rgba(65,199,214,0.45); }
.dc-pill.m2,
.dc-pill.m3 { color: #d06bd0;     border-color: rgba(208,107,208,0.45); }
.dc-pill.m7 { color: var(--err);  border-color: rgba(217,83,79,0.55); }
[data-theme="light"] .dc-pill.h2 { color: #c2410c; border-color: rgba(194,65,12,0.4); }
[data-theme="light"] .dc-pill.m1 { color: #0e7c8a; border-color: rgba(14,124,138,0.4); }
[data-theme="light"] .dc-pill.m2,
[data-theme="light"] .dc-pill.m3 { color: #a12fa1; border-color: rgba(161,47,161,0.35); }

/* ─────────────────────────────────────────────
   LEDs, progress bars, danger buttons
   ───────────────────────────────────────────── */
.dc-led {
    display: inline-block;
    width: 9px;
    height: 9px;
    background: #3a3a3a;
    border: 1px solid var(--border2);
    flex-shrink: 0;
}
[data-theme="light"] .dc-led { background: #d0d0d0; }
.dc-led.on   { background: var(--ok);   box-shadow: 0 0 6px rgba(92,184,92,0.5); }
.dc-led.warn { background: var(--warn); box-shadow: 0 0 6px rgba(255,196,0,0.45); }
.dc-led.err  { background: var(--err);  box-shadow: 0 0 6px rgba(217,83,79,0.5); }

/* thin accent progress (firmware update etc.):
   <div class="dc-progress"><div class="dc-progress-fill"></div></div> */
.dc-progress {
    height: 4px;
    background: #333;
    overflow: hidden;
}
[data-theme="light"] .dc-progress { background: #dedede; }
.dc-progress-fill {
    display: block;
    height: 100%;
    width: 0%;
    background: var(--accent);
    transition: width 0.2s ease;
}

/* err-tinted button with two-click arm confirm: JS adds .armed for 3 s */
.dc-btn-danger {
    color: var(--err);
    border-color: rgba(217,83,79,0.30);
}
.dc-btn-danger:hover { background: rgba(217,83,79,0.10); }
.dc-btn-danger.armed {
    background: rgba(217,83,79,0.16);
    border-color: var(--err);
    color: var(--err);
}
[data-theme="light"] .dc-btn-danger { border-color: rgba(217,48,37,0.25); }
[data-theme="light"] .dc-btn-danger:hover { background: rgba(217,48,37,0.06); }
[data-theme="light"] .dc-btn-danger.armed { background: rgba(217,48,37,0.10); border-color: var(--err); }

/* ─────────────────────────────────────────────
   Modal (node properties etc.)
   ───────────────────────────────────────────── */
.dc-modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 200;
    background: rgba(0,0,0,0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 18px;
}
[data-theme="light"] .dc-modal-backdrop { background: rgba(0,0,0,0.30); }
.dc-modal-backdrop[hidden] { display: none !important; }
.dc-modal {
    background: var(--card);
    border: 1px solid var(--border2);
    box-shadow: var(--shadow);
    border-radius: 0;
    width: 100%;
    max-width: 860px;
    max-height: 92vh;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 12px 14px 14px;
}
.dc-modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 8px;
}
.dc-modal-title {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 1px;
    text-transform: uppercase;
    color: var(--accent);
}
[data-theme="light"] .dc-modal-title { color: #b35000; }
.dc-modal-close { height: 24px; width: 26px; padding: 0; font-size: 16px; line-height: 1; flex-shrink: 0; }

/* ─────────────────────────────────────────────
   Vertical slider columns (ESC / actuator panels)
   ───────────────────────────────────────────── */
.dc-slider-row {
    display: flex;
    gap: 10px;
    align-items: stretch;
    overflow-x: auto;
    padding: 4px 2px 8px;
}
.dc-slider-col {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    flex: 0 0 44px;
    width: 44px;
    min-width: 44px;
}
.dc-slider-col input[type="range"] {
    writing-mode: vertical-lr;
    direction: rtl;
    width: 24px;
    height: 170px;
    margin: 0;
    padding: 0;
    background: transparent;
    accent-color: var(--accent);
    cursor: pointer;
}
.dc-slider-col input[type="number"] {
    width: 44px;
    height: 22px;
    padding: 2px 3px;
    text-align: center;
    background: #1e1e1e;
    color: var(--text);
    border: 1px solid var(--border);
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 10.5px;
    outline: none;
}
.dc-slider-col input[type="number"]:focus { border-color: var(--accent); }
[data-theme="light"] .dc-slider-col input[type="number"] { background: #e4e4e4; }
.dc-slider-col button {
    height: 20px;
    width: 44px;
    padding: 1px 4px;
    font-size: 10px;
    letter-spacing: 0.4px;
}
.dc-slider-label {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 10px;
    font-weight: 700;
    color: var(--muted);
    white-space: nowrap;
}
.dc-telem {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 9.5px;
    line-height: 1.45;
    color: var(--muted2);
    text-align: center;
    white-space: nowrap;
}

/* ─────────────────────────────────────────────
   Series visibility chips (plotter — commsbox clone)
   ───────────────────────────────────────────── */
.series-checks {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-wrap: wrap;
    margin-right: auto;
}
.series-check {
    display: flex;
    align-items: center;
    gap: 4px;
    cursor: pointer;
    padding: 2px 6px;
    border: 1px solid #333;
    background: #252525;
    transition: background 0.12s ease, border-color 0.12s ease, opacity 0.15s ease;
    user-select: none;
}
.series-check:hover { background: #303030; border-color: #4a4a4a; }
.series-check.unchecked { opacity: 0.40; }
.series-dot { width: 8px; height: 8px; flex-shrink: 0; }
.series-check input[type="checkbox"] { display: none; }
.series-label {
    font-size: 10px;
    letter-spacing: 0.3px;
    color: var(--text);
    white-space: nowrap;
}
[data-theme="light"] .series-check { background: #e4e4e4; border-color: #d0d0d0; }
[data-theme="light"] .series-check:hover { background: #dedede; border-color: #bebebe; }

/* ─────────────────────────────────────────────
   DNA card specifics
   ───────────────────────────────────────────── */
/* scrollbar-gutter: once allocations overflow the max-height, a classic
   scrollbar would otherwise eat track width and clip the ID column */
#dnaCard .dc-table-wrap { max-height: 220px; min-height: 64px; scrollbar-gutter: stable; }
.dna-off { opacity: 0.55; }

/* ─────────────────────────────────────────────
   Responsive collapse
   ───────────────────────────────────────────── */
@media (max-width: 900px) {
    .dc-grid-nodes { grid-template-columns: 1fr; }
    .dc-tabs .mode-btn {
        flex: 1 1 auto;
        border-left: 1px solid var(--border2);
        margin: 0 -1px -1px 0;
    }
}
@media (max-width: 700px) {
    #flashMsg { flex-basis: 100%; text-align: left; }
}
