:root {
    --bg:       #f4f6f8;
    --panel:    #ffffff;
    --ink:      #1c2733;
    --ink-dim:  #5b6b7a;
    --line:     #dde3e8;
    --accent:   #2c5f7c;
    --accent-h: #1f4659;
    --ok:       #2c8a4d;
    --warn:     #b8741b;
    --bad:      #b03030;
    --pending:  #b8741b;
    --shadow:   0 1px 2px rgba(0,0,0,.04), 0 4px 12px rgba(28,39,51,.06);
    --radius:   8px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
    font: 14px/1.45 -apple-system, "Segoe UI", system-ui, sans-serif;
    color: var(--ink);
    background: var(--bg);
}
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-h); text-decoration: underline; }
code, pre { font-family: "JetBrains Mono", "Cascadia Code", Consolas, monospace; font-size: 12.5px; }

.topbar {
    background: #1c2733;
    color: #cfd6dd;
    padding: 10px 24px;
    display: flex;
    align-items: center;
    gap: 32px;
}
/* Pin sign-out (or any topbar-right child) to the far right of the topbar.
 * Need an explicit non-inline display so margin-left:auto actually pushes —
 * .inline-form's display:inline would otherwise neutralise it. */
.topbar-right { margin-left: auto !important; display: flex !important; align-items: center; }
/* Wide screens: the app name, the menu items and Sign out sit on one text baseline
   (the name is set larger, so centring the boxes left it 1.6px low). */
@media (min-width: 641px) { .topbar { align-items: baseline; } }
.topbar .brand { color: #fff; font-weight: 600; font-size: 16px; letter-spacing: .3px; }
.topbar nav { display: flex; gap: 22px; align-items: center; }
.topbar nav a { color: #cfd6dd; font-weight: 500; }
.topbar nav a:hover { color: #fff; text-decoration: none; }
.topbar nav a[aria-current="page"] { color: #fff; }
/* Phones: the menu folds behind this button (see the max-width: 640px block). */
.topbar .nav-toggle {
    display: none; margin-left: auto;
    width: 40px; height: 36px; padding: 0;
    align-items: center; justify-content: center;
    background: transparent; border: 1px solid rgba(255, 255, 255, .18); border-radius: 8px;
    color: #fff; cursor: pointer;
}
.topbar .nav-toggle svg { width: 20px; height: 20px; stroke: currentColor; stroke-width: 2; stroke-linecap: round; fill: none; }
.topbar .so-icon { display: none; width: 20px; height: 20px; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; fill: none; }
/* Boats list, wide screens: a plain "Quick view" link at the end of each row. */
/* Wide screens: one line per boat, no wrapped cells (the group name may wrap). */
@media (min-width: 641px) {
    table.devices th, table.devices tr[data-id] td { white-space: nowrap; }
    table.devices th, table.devices td { padding-left: 10px; padding-right: 10px; }
}
/* Narrow windows (tablets): drop the least-needed columns so the list still fits. */
@media (min-width: 641px) and (max-width: 1000px) {
    table.devices th:nth-child(7), table.devices th:nth-child(8),
    table.devices td[data-label="Dist"], table.devices td[data-label="Pos"] { display: none; }
}
@media (min-width: 641px) and (max-width: 800px) {
    table.devices th:nth-child(9), table.devices th:nth-child(10),
    table.devices td[data-label="FW"], table.devices td[data-label="Settings"] { display: none; }
}
table.devices td.row-qv { text-align: right; white-space: nowrap; }
table.devices td.row-qv a { font-size: 12.5px; font-weight: 500; color: var(--accent); }
.pair-new { margin: 16px 0 0; }
.pair-actions { display: flex; gap: 10px; align-items: center; }
.pair-actions button, .pair-actions a { padding: 8px 18px; font-size: 13px; font-weight: 500; line-height: 1.2; border: 1px solid var(--accent); }
/* Line icons inside buttons: one drawing style everywhere (same as the menu and sign-out icons). */
svg.ic { width: 15px; height: 15px; margin-right: 6px; vertical-align: -2.5px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.inline-form { display: inline; margin: 0; padding: 0; }
button.link {
    background: none; border: none; color: #cfd6dd; cursor: pointer; padding: 0;
    font: inherit;
}
button.link:hover { color: #fff; text-decoration: underline; }

.page { max-width: 1100px; margin: 24px auto; padding: 0 20px; }
.page h1 { margin: 0 0 4px; font-size: 22px; }
.heading-id {
    font-size: 13px; font-weight: 400; margin-left: 10px;
    font-family: "JetBrains Mono", Consolas, monospace;
    color: #a6b2bd;   /* just an opaque device id — keep it faint / low-key */
}
.page h2 { margin: 28px 0 12px; font-size: 16px; color: var(--ink-dim); text-transform: uppercase; letter-spacing: .5px; }
.page h3 { margin: 16px 0 8px; font-size: 14px; color: var(--ink-dim); }
.dim   { color: var(--ink-dim); }
.empty { color: var(--ink-dim); padding: 40px; text-align: center; background: var(--panel); border-radius: var(--radius); }
.info  { background: #fff8e6; border: 1px solid #f0d68a; padding: 10px 14px; border-radius: 6px; }
.error { color: var(--bad); }

.auth { max-width: 360px; margin: 80px auto; padding: 32px; background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); }
.auth h1 { text-align: center; margin: 0 0 24px; font-size: 24px; }
.auth label { display: block; margin-bottom: 14px; font-size: 13px; color: var(--ink-dim); }
.auth input { display: block; width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 6px; font: inherit; margin-top: 4px; }
.auth button { width: 100%; padding: 10px; background: var(--accent); color: white; border: none; border-radius: 6px; font: inherit; font-weight: 500; cursor: pointer; }
.auth button:hover { background: var(--accent-h); }

table { width: 100%; border-collapse: collapse; background: var(--panel); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
th { text-align: left; padding: 10px 12px; font-size: 12px; text-transform: uppercase; letter-spacing: .4px; color: var(--ink-dim); background: #f9fafc; border-bottom: 1px solid var(--line); }
td { padding: 10px 12px; border-bottom: 1px solid var(--line); }
tr:last-child td { border-bottom: none; }
tr.stale td { opacity: .55; }
tr:hover td { background: #f9fafc; }

.badge { display: inline-block; padding: 2px 7px; border-radius: 999px; font-size: 11px; font-weight: 500; }
.badge.pending { background: #fff1de; color: var(--pending); }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin: 16px 0; }
.card { background: var(--panel); padding: 14px 16px; border-radius: var(--radius); box-shadow: var(--shadow); }
.card-label { font-size: 11px; color: var(--ink-dim); text-transform: uppercase; letter-spacing: .5px; }
.card-unit-lbl { text-transform: none; letter-spacing: 0; }
/* ON/OFF badge shown on Live cards for channels with event detection. Reuses the
   .sensor-edge-state pill colours from the Sensors tab; just resets the label's
   uppercase/letter-spacing so the pill reads cleanly. */
.card-onoff { margin-left: 6px; vertical-align: middle; text-transform: none; letter-spacing: 0; }
.card-value {
    font-size: 22px; font-weight: 600; margin-top: 6px; color: var(--ink);
    font-variant-numeric: tabular-nums;
    min-height: 1.3em;
}

form label  { display: block; margin: 10px 0; }
form input  { width: 100%; max-width: 340px; padding: 7px 9px; border: 1px solid var(--line); border-radius: 6px; font: inherit; }
form button { padding: 8px 16px; background: var(--accent); color: white; border: none; border-radius: 6px; font: inherit; cursor: pointer; }
form button:hover { background: var(--accent-h); }

table.cal td input { width: 110px; }
table.cal td:first-child { width: 60px; font-family: monospace; }

/* Link-type row label (e.g., "Wi-Fi", "Cellular") that prefixes a .home-row of
   interval inputs. Aligns to the input baseline so the row reads as a single line. */
.link-tag {
    font-size: 12px; color: var(--ink-dim); font-weight: 500;
    align-self: flex-end; padding-bottom: 5px; min-width: 56px;
}

/* Button colours, everywhere:
     filled blue  (push-btn, and a plain button in a form) = the main action of the screen:
                  it creates, saves or sends something, or starts doing so;
     white + blue outline (secondary-btn) = everything else: cancel, edit, copy, test;
     white + red outline (danger, in tables)  = deletes something.
   Links that act as buttons use the same classes. */
button.push-btn, button.secondary-btn, a.push-btn, a.secondary-btn {
    display: inline-block; text-decoration: none;
    padding: 8px 18px;
    font: inherit; font-size: 13px;
    font-weight: 500;
    border-radius: 6px;
    cursor: pointer;
    line-height: 1.2;
}
button.push-btn, a.push-btn {
    background: var(--accent); color: white; border: 1px solid var(--accent);
}
button.push-btn:hover, a.push-btn:hover { background: var(--accent-h); border-color: var(--accent-h); text-decoration: none; }
button.push-btn:disabled {
    background: var(--line); color: var(--ink-dim); cursor: not-allowed;
    border-color: var(--line);
}
button.secondary-btn, a.secondary-btn {
    background: white; color: var(--accent); border: 1px solid var(--accent);
}
button.secondary-btn:hover, a.secondary-btn:hover { background: #eef4f8; text-decoration: none; }
table button.danger, table form button.danger { background: #fff; color: var(--bad); border: 1px solid #e2b4b4; border-radius: 6px; padding: 6px 14px; font: inherit; font-size: 13px; cursor: pointer; }
table button.danger:hover, table form button.danger:hover { background: #fdf0f0; }
.settings-actions {
    display: flex; align-items: center; gap: 10px; margin-bottom: 14px;
    padding: 12px 16px; background: #fcfdfe; border-radius: var(--radius);
    border: 1px solid var(--line);
}
.settings-actions .inline-form { display: inline; }
.snapshot {
    display: flex; justify-content: space-between; align-items: center;
    padding: 6px 0; border-bottom: 1px dashed var(--line); font-size: 12px;
}
.snapshot:last-child { border-bottom: none; }
.snapshot .label { color: var(--ink-dim); }
.snapshot button {
    background: var(--accent); color: white; border: none;
    padding: 3px 10px; font-size: 11px; border-radius: 4px; cursor: pointer;
}
.snapshot button:hover { background: var(--accent-h); }
.snapshot button.ghost-mini {
    background: transparent; color: var(--ink-dim); border: 1px solid var(--line);
    padding: 2px 6px; font-size: 11px;
}
.snapshot button.ghost-mini:hover { background: #fde0e0; color: var(--bad); border-color: var(--bad); }
.snapshot .src-device { color: #2c8a4d; font-weight: 500; }
.snapshot .src-admin  { color: var(--ink-dim); }

/* Bulk action bar on devices list */
.bulk-bar {
    display: flex; flex-direction: column; gap: 8px;
    padding: 10px 14px; background: var(--accent); color: white;
    border-radius: var(--radius); margin-bottom: 12px;
    box-shadow: var(--shadow);
}
.bulk-header { display: flex; align-items: center; gap: 10px; }
.bulk-actions {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 6px;
}
.bulk-actions button { line-height: 1.1; }
.bulk-bar button {
    background: rgba(255,255,255,0.18); color: white; border: 1px solid rgba(255,255,255,0.3);
    padding: 6px 11px; border-radius: 5px; cursor: pointer; font: inherit; font-size: 12.5px;
    text-align: center;
}
/* Wide screens: dissolve .bulk-header and .bulk-actions into the parent flex
 * via display:contents so all items live on a single inline row. When the
 * buttons can't all fit on one row, narrow-screen layout (below) takes over
 * and lifts the count + clear onto a dedicated header row above the button grid. */
@media (min-width: 900px) {
    .bulk-bar { flex-direction: row; align-items: center; flex-wrap: wrap; }
    .bulk-header, .bulk-actions { display: contents; }
}
/* Clear is a link, not a button — sits right after the count in the header.
 * Hidden when nothing is selected (.bulk-bar.idle is JS-toggled). */
.bulk-clear {
    background: transparent !important;
    border: 0 !important;
    color: rgba(255,255,255,0.85) !important;
    padding: 0 !important;
    text-decoration: underline;
    font-size: 12px !important;
    cursor: pointer;
}
.bulk-clear:hover { color: #fff !important; text-decoration: underline; }
.bulk-bar.idle .bulk-clear { display: none !important; }
.bulk-bar button:hover:not(:disabled) { background: rgba(255,255,255,0.30); }
.bulk-bar button:disabled {
    background: rgba(255,255,255,0.06); color: rgba(255,255,255,0.45);
    border-color: rgba(255,255,255,0.15); cursor: not-allowed;
}
.bulk-bar button.warn { background: rgba(255,150,0,0.40); border-color: rgba(255,180,80,0.6); }
.bulk-bar button.warn:hover:not(:disabled) { background: rgba(255,150,0,0.55); }
.bulk-bar button.ghost { background: transparent; border-color: rgba(255,255,255,0.4); }
.bulk-bar.idle { background: var(--ink-dim); }
.bulk-bar .bulk-count { font-weight: 600; margin-right: 10px; }

/* Devices page header: title + search on row 1 (title compact), tick on row 2.
 * The tick has order:99 + flex-basis:100% so it always wraps to its own row
 * regardless of where the other items end up. */
.devices-header {
    display: flex; align-items: center; gap: 4px 14px;
    margin: 8px 0 10px;
    flex-wrap: wrap;
}
.devices-header h1 { margin: 0; flex: 0 0 auto; font-size: 18px; line-height: 1.2; }
.devices-header .search-input {
    flex: 1 1 220px; margin-left: auto; max-width: 420px;
}
.devices-header .tick {
    flex: 1 1 100%;
    order: 99;
    margin: 0;
    font-size: 11.5px;
    color: var(--ink-dim);
    line-height: 1.1;
}
@media (max-width: 640px) {
    .devices-header .search-input { flex: 1 1 100%; margin-left: 0; max-width: none; }
}

/* ---- Sensors tab ---- */
.sensor-list { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; max-width: 1000px; }
@media (max-width: 720px) { .sensor-list { grid-template-columns: 1fr; } }
.sensor-card {
    background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
    padding: 10px 12px; box-shadow: 0 1px 2px rgba(0,0,0,0.04);
}
.sensor-card.disabled { opacity: 0.55; }
/* Basic-mode read-only bits */
.sensor-color-swatch { width: 16px; height: 16px; border-radius: 4px; flex: 0 0 16px; }
.sensor-name-ro { font-weight: 600; font-size: 15px; flex: 1 1 auto; }
.sensor-events-status { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: #eef2f4; color: #90a4ae; }
.sensor-events-status.on  { background: #e3f4e8; color: #1a7a3a; }
.sensor-events-status.off { background: #eef2f4; color: #90a4ae; }
.sensor-card-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.sensor-label { flex: 1 1 auto; font: inherit; padding: 6px 8px; border: 1px solid var(--line); border-radius: 4px; font-weight: 600; min-width: 0; }
.sensor-enabled { display: flex; align-items: center; gap: 5px; font-size: 12.5px; color: var(--ink); white-space: nowrap; }
.sensor-color { width: 26px; height: 26px; border: 1px solid var(--line); border-radius: 4px; padding: 0; cursor: pointer; flex: 0 0 auto; }
.sensor-src { font-family: var(--mono, monospace); font-size: 11px; }
/* Live value + sparkline row */
.sensor-live { display: flex; align-items: center; gap: 12px; min-width: 0; margin-bottom: 12px; }
.sensor-live-value { font-size: 24px; font-weight: 600; line-height: 1; white-space: nowrap; }
.sensor-live-unit { font-size: 12px; color: var(--ink-dim); font-weight: 400; }
.sensor-spark-wrap { flex: 1 1 auto; min-width: 0; }
.sensor-spark { width: 100%; height: 32px; display: block; }
/* Labelled sections inside a sensor card */
.sensor-section { border-top: 1px solid var(--line); padding-top: 8px; margin-top: 8px; }
.sensor-section-title { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .4px; color: var(--ink-dim); margin-bottom: 6px; display: flex; align-items: center; gap: 8px; }
.sensor-fields { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: flex-end; }
.sensor-fields label { display: flex; flex-direction: column; gap: 3px; font-size: 11.5px; color: var(--ink-dim); }
.sensor-fields input[type="number"], .sensor-fields input[type="text"] {
    width: 84px; font: inherit; padding: 5px 7px; border: 1px solid var(--line); border-radius: 4px; font-size: 12.5px; color: var(--ink);
}
.sensor-fields select { font: inherit; padding: 5px 7px; border: 1px solid var(--line); border-radius: 4px; font-size: 12.5px; color: var(--ink); background: #fff; }
.sensor-fields .sensor-unit { width: 56px; }
.sensor-fields .sensor-thresh, .sensor-fields .sensor-hyst { width: 70px; }
.sensor-fields .num-sm { width: 52px; }
.sensor-fields input:disabled { background: #f2f4f6; color: #b0b8be; cursor: not-allowed; }
.sensor-fields .cal-wiz-btn { padding: 6px 12px; font-size: 12px; align-self: flex-end; width: auto; flex: 0 0 auto; white-space: nowrap; }
.sensor-hint { font-size: 11px; margin-top: 6px; line-height: 1.35; }
.sensor-toggle { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--ink); cursor: pointer; }
.sensor-toggle input { margin: 0; }
/* A toggle placed inside a fields row: keep it on one line (not the column layout
   the other labels use), full width so it doesn't get squeezed and wrap. */
.sensor-fields .sensor-toggle { flex-direction: row; flex: 1 1 100%; white-space: nowrap; }
/* input with a unit suffix sitting inline to its right (no wrapping) */
.input-unit { display: inline-flex; align-items: center; gap: 5px; }
.input-unit .unit-suffix { font-size: 11.5px; color: var(--ink-dim); }

.sensor-groups { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; max-width: 1000px; }
@media (max-width: 720px) { .sensor-groups { grid-template-columns: 1fr; } }
.sensor-group-card { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; }
.sensor-group-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.sensor-group-label { flex: 1 1 auto; padding: 5px 7px; border: 1px solid var(--line); border-radius: 4px; font: inherit; font-weight: 600; }
.sensor-group-delete { padding: 4px 8px; font-size: 12px; }
.sensor-group-members { display: flex; flex-wrap: wrap; gap: 8px 14px; font-size: 13px; }
.sensor-group-member { display: flex; align-items: center; gap: 4px; }

.sensor-edge-state { font-weight: 600; padding: 1px 6px; border-radius: 999px; font-size: 11px; }
.sensor-edge-state.on  { color: #1a7a3a; background: #e3f4e8; }
.sensor-edge-state.off { color: #90a4ae; background: #eef2f4; }

/* Sensors tab: Basic|Expert segmented toggle (lives in the top actions bar) */
.mode-toggle { display: inline-flex; border: 1px solid var(--line); border-radius: 7px; overflow: hidden; }
.mode-toggle button { background: var(--panel); border: 0; padding: 5px 14px; font: inherit; font-size: 12.5px; cursor: pointer; color: var(--ink-dim); }
.mode-toggle button + button { border-left: 1px solid var(--line); }
.mode-toggle button.active { background: var(--accent); color: #fff; }
/* In basic mode, hide expert-only chrome */
.tab-panel.mode-basic .expert-only { display: none !important; }

/* Devices list: "offline" in the Link column for a device that has gone stale. Muted
   red rather than a loud alert — a boat out of Wi-Fi range on purpose is normal. */
.link-offline { color: var(--bad); font-weight: 600; cursor: help; }

/* Diagnostics tab cards + shared "send to device" button colour */
.diag-card { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 14px 16px; margin: 12px 0; max-width: 560px; box-shadow: 0 1px 2px rgba(0,0,0,0.04); }
.device-send-btn { background: var(--accent); color: #fff; border: 0; border-radius: 6px; padding: 6px 14px; font: inherit; font-size: 12.5px; cursor: pointer; }
.device-send-btn:hover:not(:disabled) { filter: brightness(1.08); }
.device-send-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Buzzer test: combo + small Send button on its right */
.buzzer-test { display: flex; flex-direction: row; align-items: center; gap: 8px; flex-wrap: wrap; }
.buzzer-select { font: inherit; padding: 6px 9px; border: 1px solid var(--line); border-radius: 6px; min-width: 150px; }
.buzzer-test #buzzer-test-status { flex: 1 1 100%; margin-top: 2px; }
.buzzer-test .secondary-btn.warn { border-color: #c98a2b; color: #a8690f; }

/* Legacy toolbar wrapper — still used on other pages */
.toolbar { margin: 12px 0 8px; }
.search-input {
    width: 100%; max-width: 420px; padding: 8px 12px 8px 36px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%236b7a89' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='6.5'/%3E%3Cpath d='M16 16l4.5 4.5'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: 11px 50%; background-size: 17px 17px;
    border: 1px solid var(--line); border-radius: 6px; font: inherit; font-size: 13.5px;
    background-color: white;
}
.search-input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }

/* Search-result highlighting — pure background, no padding so letters don't shift. */
table.devices mark {
    background: #fff3a0;
    color: inherit;
    padding: 0;
    border-radius: 1px;
}

/* ---- Devices list: phone card view ----
 * Below 640px the wide table is unreadable and the bulk-actions bar wraps the
 * action buttons at different widths. We collapse each row to a stacked card so
 * everything fits without horizontal scrolling. The td::before pseudo prints
 * the column label (from data-label="…") in front of each value so the user
 * still knows what they're looking at without the <thead>. */
@media (max-width: 640px) {
    .page { padding: 0 12px; margin-top: 12px; }
    .toolbar { margin: 8px 0; }
    .bulk-bar {
        flex-wrap: wrap; gap: 6px;
        position: sticky; top: 0; z-index: 5;
        padding: 8px 10px;
    }
    .bulk-bar button {
        font-size: 12px;
        padding: 5px 8px;        /* slimmer vertical so the 6-button stack isn't tall */
        line-height: 1.05;
    }
    .bulk-actions {
        grid-template-columns: repeat(2, minmax(0, 1fr));   /* force exactly 2 cols on phone — half the rows = half the height */
        gap: 5px;
    }

    /* Phones show a plain list: no search, no multi-select, no bulk actions. */
    .devices-header .search-input, #bulk-bar, table.devices .check-col { display: none !important; }

    table.devices, table.devices thead, table.devices tbody,
    table.devices tr, table.devices th, table.devices td {
        display: block;
    }
    table.devices { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
    table.devices thead { display: none; }
    /* One boat = one row: Quick view button, name, link + last seen under it, and the
     * four channel values right-aligned. Tap the name for the details page. */
    table.devices tbody tr[data-id] {
        display: grid;
        grid-template-columns: auto minmax(0, 1fr) auto;
        grid-template-areas: "name name go" "link seen vals";
        cursor: pointer;
        align-items: center;
        gap: 2px 8px;
        padding: 10px 12px;
        border-bottom: 1px solid var(--line);
    }
    table.devices tbody tr:last-child { border-bottom: 0; }
    table.devices tr.stale { opacity: 0.7; }
    table.devices td { border: 0; padding: 0; text-align: left; white-space: nowrap; font-size: 12.5px; }
    table.devices td.alias-cell {
        grid-area: name; min-width: 0;
        font-size: 16px; font-weight: 600;
        overflow: hidden; text-overflow: ellipsis;
    }
    table.devices td.alias-cell a { color: var(--ink); text-decoration: none; }
    table.devices th.row-qv, table.devices td.row-qv { display: none; }   /* the whole row opens Quick view */
    table.devices td[data-label="Link"] { grid-area: link; color: var(--ink-dim); }
    table.devices td[data-label="Last seen"] { grid-area: seen; color: var(--ink-dim); }
    table.devices td[data-label="Last seen"]::before { content: "· "; }
    table.devices tr.stale td[data-label="Last seen"], table.devices tr.stale .link-txt { display: none; }
    table.devices tr.stale .off-txt { display: inline; }
    table.devices tr.stale { opacity: 1; }
    table.devices tr.stale td.alias-cell, table.devices tr.stale td.ov-vals { opacity: .55; }
    table.devices td.ov-vals { display: block; grid-area: vals; text-align: right; font-variant-numeric: tabular-nums; }
    table.devices td.row-go { display: block; grid-area: go; text-align: right; }
    table.devices td.row-go a { display: inline-block; padding: 6px 0 6px 14px; font-size: 12.5px; color: var(--accent); }
    table.devices td[data-label="CH1/CH2"], table.devices td[data-label="CH3/CH4"],
    table.devices td[data-label="Dist"], table.devices td[data-label="Pos"],
    table.devices td[data-label="FW"], table.devices td[data-label="Settings"] { display: none; }
    table.devices tr.in-group td.alias-cell { padding-left: 0; }
    table.devices tr.in-group td.alias-cell::before { content: none; }
    table.devices tr.group-header { padding: 8px 12px; border-bottom: 1px solid var(--line); }
    table.devices tr.group-header td.group-header-cell { padding: 0; font-size: 13px; }

    /* Firmware builds, rollout, admins: one wrapped row each instead of a stack of cells. */
    table.devices.plain-list tbody tr {
        display: flex; flex-wrap: wrap; align-items: baseline; gap: 3px 12px;
        padding: 10px 12px; border-bottom: 1px solid var(--line);
    }
    table.devices.plain-list td { color: var(--ink-dim); white-space: normal; min-width: 0; }
    table.devices.plain-list td:first-child { font-size: 15px; font-weight: 600; color: var(--ink); }
    table.devices.plain-list td:empty { display: none; }
    table.devices.plain-list td:last-child:not(:first-child) { margin-left: auto; }
    /* Settings: the label sits above a full-width field, so placeholders are not cut off. */
    .settings-card label:not(.inline):not(.compact) { grid-template-columns: 1fr; gap: 4px; margin: 10px 0; }
    .settings-card { padding: 14px 14px; }
    .settings-card .home-row { gap: 10px; }
    .settings-card .home-row .link-tag { flex: 1 1 100%; }
    .settings-card .home-row label.compact { flex: 1 1 0; min-width: 0; }
    .settings-card .home-row label.compact input { width: 100%; padding: 7px 8px; font-size: 14px; }
    /* Users: stays a real table on phones (three short columns fit). */
    table.devices.users-table { display: table; width: 100%; border-collapse: collapse; }
    table.devices.users-table thead { display: table-header-group; }
    table.devices.users-table tbody { display: table-row-group; }
    table.devices.users-table tr { display: table-row; }
    table.devices.users-table th, table.devices.users-table td {
        display: table-cell; padding: 11px 12px; font-size: 14px; vertical-align: middle;
        border-bottom: 1px solid var(--line); white-space: nowrap;
    }
    table.devices.users-table th { font-size: 11px; text-transform: uppercase; letter-spacing: .4px; color: var(--ink-dim); text-align: left; }
    table.devices.users-table tbody tr:last-child td { border-bottom: 0; }
    table.devices.users-table td:first-child { font-weight: 600; white-space: normal; overflow-wrap: anywhere; }
    table.devices.users-table th:last-child:not(:nth-child(2)), table.devices.users-table td:last-child:not(:nth-child(2)) { text-align: right; }
    table.devices.users-table button.danger { padding: 6px 12px; }
    table.devices.ota-builds td:nth-child(3) { display: none; }                 /* checksum */
    table.devices.ota-builds td:nth-child(5) { flex: 1 1 100%; order: 9; color: var(--ink); overflow-wrap: anywhere; }

    /* Device page: four tabs and "More" in the row, Quick view top right; short header. */
    #device-tabs { position: relative; margin: 10px 0 12px; gap: 0; }
    #device-tabs a.tab-link, #device-tabs button.tab-extra { display: none; }
    #device-tabs > button { flex: 1 1 auto; padding: 12px 4px; font-size: 14px; white-space: nowrap; }
    #device-tabs .tab-more-caret { font-size: 11px; }
    .tab-more-menu {
        /* Above the map on the Track and Live tabs (the map's own layers go up to 1000). */
        position: absolute; right: 0; top: calc(100% + 4px); z-index: 1200; min-width: 190px;
        background: #fff; border: 1px solid var(--line); border-radius: 10px; overflow: hidden;
        box-shadow: 0 10px 28px rgba(15, 30, 45, .18);
    }
    .tab-more-menu[hidden] { display: none; }
    #device-tabs .tab-more-menu button {
        display: block; width: 100%; padding: 13px 16px; text-align: left; background: none; border: 0;
        border-radius: 0; margin: 0; font: inherit; font-size: 15px; color: var(--ink); cursor: pointer;
    }
    #device-tabs .tab-more-menu button + button { border-top: 1px solid var(--line); }
    #device-tabs .tab-more-menu button.active { color: var(--accent); font-weight: 600; }
    .page h1 { display: flex; align-items: baseline; gap: 10px; }
    .ov-top { margin-left: auto; font-size: 14px; font-weight: 600; color: var(--accent); text-decoration: none; padding: 6px 0 6px 12px; }
    .heading-id, #device-status .st-more { display: none; }
    #device-status .st-state { display: inline-block; }
    .st-full { display: block; }
    table.readings:not(.notif-table) { display: block; overflow-x: auto; white-space: nowrap; -webkit-overflow-scrolling: touch; }
}

/* Wide screens: the phone-only pieces stay out of the way. */
@media (min-width: 641px) {
    table.devices td.ov-vals, table.devices td.row-go, .off-txt, .ov-top, .tab-more, .tab-more-menu, .st-full, #device-status .st-state { display: none; }
}
.st-state { margin-right: 8px; font-weight: 600; }
.st-state::before { content: "\25CF"; margin-right: 4px; }
.st-state.on { color: #2c8a4d; } .st-state.off { color: var(--bad); }
.off-txt { color: var(--bad); font-weight: 600; }
.off-txt::before { content: "\25CF"; margin-right: 4px; }
.row-alarm { display: block; color: var(--bad); font-weight: 600; font-size: 12.5px; }
.row-alarm::before { content: "\25CF"; margin-right: 4px; }

/* Group chip in the devices list */
.group-chip {
    display: inline-block; padding: 2px 9px; background: #eef4f8;
    color: var(--accent); border-radius: 999px; font-size: 11.5px; font-weight: 500;
}

/* Tree-style group rows */
table.devices tr.group-header {
    cursor: pointer;
    background: #f4f7f9;
}
table.devices tr.group-header:hover { background: #eaeef2; }
table.devices tr.group-header td.group-header-cell {
    font-size: 13px; padding: 8px 12px; color: var(--ink);
}
table.devices tr.group-header .chevron {
    display: inline-block; width: 14px; color: var(--ink-dim);
    transition: transform .15s;
}
table.devices tr.in-group td.alias-cell { padding-left: 32px; position: relative; }
table.devices tr.in-group td.alias-cell::before {
    content: '└'; position: absolute; left: 14px; top: 9px;
    color: var(--ink-dim); font-family: monospace;
}
table.devices th.check-col, table.devices td.check-col { width: 30px; text-align: center; padding: 6px 4px; }

/* Modal */
.modal {
    position: fixed; inset: 0;
    background: rgba(28, 39, 51, 0.45);
    display: flex; align-items: center; justify-content: center; z-index: 9999;
}
.modal[hidden] { display: none; }
.modal-card {
    background: var(--panel); border-radius: var(--radius);
    box-shadow: 0 12px 32px rgba(0,0,0,.25);
    padding: 22px 26px; max-width: 480px; width: calc(100% - 32px);
}
.modal-card h3 { margin: 0 0 12px; font-size: 16px; }
.modal-card p  { margin: 8px 0; font-size: 13.5px; line-height: 1.45; }
.modal-card select, .modal-card input[type="text"] {
    padding: 7px 9px; border: 1px solid var(--line); border-radius: 6px; font: inherit;
    max-width: 100%; box-sizing: border-box;   /* a long option never pushes the field out of the dialog */
}
.modal-card p { overflow-wrap: anywhere; }
/* Export-dialog column picker: tight two-column grid of checkboxes. */
.export-cols {
    display: grid; grid-template-columns: 1fr 1fr; gap: 6px 14px;
    max-height: 360px; overflow-y: auto;
    border: 1px solid var(--line); border-radius: 6px;
    padding: 10px 12px; background: #fafbfc;
}
.export-col { display: flex; align-items: center; gap: 7px; font-size: 13px; cursor: pointer; }
.export-col input[type="checkbox"] { margin: 0; }
.modal-actions {
    display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px;
}
.modal-actions button {
    padding: 7px 15px; border-radius: 6px; font: inherit; font-size: 13px;
    border: none; cursor: pointer; background: var(--accent); color: white;
}
/* Same rule as on the pages: Cancel is the outline button, the action is filled (red when it deletes). */
.modal-actions button.ghost { background: #fff; color: var(--accent); border: 1px solid var(--accent); }
.modal-actions button.danger { background: var(--bad); }
.modal-actions button[hidden] { display: none; }
/* okvDialog (public/js/dialog.js): question, optional explanation, buttons. */
.okv-dialog .modal-card { max-width: 380px; padding: 20px 22px 18px; }
.okv-dialog .okv-dialog-title { margin: 0; font-size: 16px; font-weight: 600; color: var(--ink); line-height: 1.35; overflow-wrap: anywhere; }
.okv-dialog .okv-dialog-detail { margin: 8px 0 0; font-size: 13.5px; line-height: 1.45; overflow-wrap: anywhere; }
.okv-dialog .okv-dialog-copy { display: block; width: 100%; margin-top: 12px; font-family: monospace; font-size: 13px; }
.okv-dialog [hidden] { display: none; }
.modal-actions button:hover { opacity: .9; }
.modal-actions button:disabled,
.modal-actions button:disabled:hover {
    background: var(--line); color: var(--ink-dim); cursor: not-allowed; opacity: 1;
}
.modal-actions button.ghost:disabled,
.modal-actions button.ghost:disabled:hover {
    background: transparent; color: var(--ink-dim); border: 1px solid var(--line); opacity: .55;
}

/* Reusable callout — yellow/red/blue banner used both inline (e.g. "push is a no-op")
   and inside modal-card bodies (e.g. delete confirmations). Same visual primitive in
   both places so the warning style is consistent across the admin UI. */
.callout {
    display: flex; align-items: flex-start; gap: 10px;
    padding: 10px 12px; border: 1px solid; border-radius: 6px;
    font-size: 13px; line-height: 1.4;
}
.callout-icon  { font-size: 16px; line-height: 1; flex-shrink: 0; padding-top: 1px; }
.callout-body  { flex: 1; }
.callout-title { font-weight: 600; margin-bottom: 2px; }
.callout-warn   { background: #fff8e1; border-color: #f0c060; color: #6a4400; }
.callout-info   { background: #eff6ff; border-color: #93c5fd; color: #1e3a8a; }
.callout-danger { background: #fef2f2; border-color: #fca5a5; color: #7f1d1d; }
.callout-inline { margin-left: 10px; padding: 6px 10px; font-size: 12.5px; }

.badge.pending {
    background: #fff1de; color: var(--pending); cursor: help;
    padding: 2px 9px;
}

table.readings td, table.readings th { font-size: 12.5px; padding: 6px 10px; }
table.readings { font-variant-numeric: tabular-nums; }
/* Tiny inline-gap indicator between two consecutive readings — shows "+12s" between
   rows so the reader can see the cadence at a glance without doing mental math on
   the When column. Aligned under the When column with a very subtle disabled-grey
   colour so it stays out of the way of the actual data. */
table.readings tr.reading-delta td {
    /* Shift the +xxs token roughly 50 % to the left of cell-centre (text-align:left
       plus a left padding that lands well left of the timestamp's midpoint) and
       squash vertical space so the row hugs the data rows above and below. */
    padding: 0 0 0 30px; text-align: left;
    font-size: 10px; color: #c0c8ce; line-height: 0.9;
    border: none; background: transparent;
}
table.readings tr.new {
    animation: rowFadeIn 0.9s ease-out;
}
@keyframes rowFadeIn {
    0%   { opacity: 0; transform: translateY(-6px); background: #e7f4ec; }
    60%  { background: #f0f8f3; }
    100% { opacity: 1; transform: none; background: transparent; }
}
/* Newly-arrived Events-tab rows flash a warm highlight for a few seconds. */
#events-body tr.new-evt { animation: evtFlash 3s ease-out; }
@keyframes evtFlash {
    0%   { background: #fff1cc; }
    20%  { background: #fff1cc; }
    100% { background: transparent; }
}

.pair label { display: flex; flex-direction: column; gap: 4px; max-width: 280px; }
.pair input[name="token"] { font-family: monospace; font-size: 16px; letter-spacing: 2px; text-transform: uppercase; }

/* Events tab header: title + chart-style range buttons aligned right. */
.events-head {
    display: flex; justify-content: space-between; align-items: center;
    margin: 6px 0 12px;
}
.events-range button { /* inherits .range button look (white pill, accent when active) */ }

/* GPS-diagnostics toggle in the Events header. Off by default (muted pill) so the feed
   shows operational events; turns accent-filled when the user opts to show gps_recover. */
/* Diagnostics toggle. Rendered as a real switch rather than a plain pill: it is a
   persistent on/off state that changes what the table contains, and the old flat chip
   gave no clue which way it was set. The count badge shows how many events are being
   suppressed right now, so an empty feed is never a mystery. */
/* Geometry deliberately matches `.range button` (its neighbour in .charts-head):
   same 12px font, same 5px vertical padding, same 6px radius, same white/border
   treatment. It read as a foreign object when it was a 999px pill sitting next to
   square-ish buttons. The left margin keeps it clear of the "N events" count. */
.diag-toggle {
    display: inline-flex; align-items: center; gap: 7px;
    background: white; border: 1px solid var(--line);
    padding: 5px 10px 5px 8px;
    font: inherit; font-size: 12px; line-height: 1.25;
    border-radius: 6px;
    margin-left: 14px;
    color: var(--ink-dim); cursor: pointer; white-space: nowrap;
    transition: border-color 120ms ease, color 120ms ease, background 120ms ease;
}
.diag-toggle:hover { color: var(--ink); border-color: var(--accent); }
.diag-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* Switch track + knob, sized to sit inside a 12px-font control without inflating it. */
.diag-switch {
    width: 22px; height: 12px; flex: none; position: relative;
    background: #c9d2da; border-radius: 999px;
    transition: background 140ms ease;
}
.diag-switch::after {
    content: ''; position: absolute; top: 2px; left: 2px;
    width: 8px; height: 8px; border-radius: 50%;
    background: #fff; box-shadow: 0 1px 1px rgba(0,0,0,0.3);
    transition: transform 140ms ease;
}
.diag-toggle.active { border-color: var(--accent); color: var(--accent); background: #eef4f9; }
.diag-toggle.active .diag-switch { background: var(--accent); }
.diag-toggle.active .diag-switch::after { transform: translateX(10px); }

/* "22 hidden" badge — only rendered when the filter is actually suppressing something.
   Square-ish to match the button it sits in. */
.diag-count {
    font-size: 11px; font-variant-numeric: tabular-nums;
    padding: 1px 5px; border-radius: 4px;
    background: #eceff2; color: var(--ink-dim);
}
.diag-toggle.active .diag-count { background: var(--accent); color: #fff; }

/* The "N events" count. Fixed minimum width and never emptied, so the toggle beside it
   doesn't slide left and right as the number changes or the feed empties out. */
.filter-count { min-width: 92px; display: inline-block; white-space: nowrap; }

@media (prefers-reduced-motion: reduce) {
    .diag-toggle, .diag-switch, .diag-switch::after { transition: none; }
}

/* Self-explaining empty state for the events table. */
tr.events-empty td { text-align: center; padding: 26px 14px; color: var(--ink-dim); font-size: 13px; }
tr.events-empty .events-empty-hint { display: block; margin-top: 6px; font-size: 12.5px; }
.linklike {
    background: none; border: 0; padding: 0; font: inherit; font-size: inherit;
    color: var(--accent); text-decoration: underline; cursor: pointer;
}
.linklike:hover { filter: brightness(1.2); }

/* Column-header filter popovers: clicking a filterable <th> opens a small dropdown
   with chip toggles for that column's dimension (severity for Code, source for Source).
   The header chevron turns accent-coloured when at least one option is unchecked. */
table.events th.filterable {
    position: relative; cursor: pointer; user-select: none;
}
table.events th.filterable:hover { color: var(--ink); }
table.events th.filterable .filter-arrow {
    display: inline-block; margin-left: 4px; font-size: 10px; color: var(--ink-dim);
    transition: color 80ms ease;
}
table.events th.filterable.has-filter .filter-arrow { color: var(--accent); }
/* Reset-filter icon next to the chevron — only shown when a filter is active for
   the column. Clicking it re-enables all chips in that group. */
table.events th.filterable .filter-reset {
    display: none;
    margin-left: 4px; padding: 0 4px;
    font-size: 11px; line-height: 1; color: var(--ink-dim);
    border: 1px solid var(--line); border-radius: 10px;
    cursor: pointer; vertical-align: middle;
}
table.events th.filterable.has-filter .filter-reset { display: inline-block; }
table.events th.filterable .filter-reset:hover {
    color: var(--bad); border-color: var(--bad); background: #fde9e9;
}
/* Popover uses position: fixed and is positioned via JS so it escapes any ancestor
   overflow context. CSS only provides the visual chrome; JS sets top/left at open. */
.col-filter-popover {
    position: fixed; z-index: 1000;
    padding: 10px 12px;
    background: var(--panel); border: 1px solid var(--line); border-radius: 6px;
    box-shadow: 0 6px 18px rgba(0,0,0,.12);
    display: flex; flex-wrap: wrap; gap: 6px; min-width: 200px;
    font-weight: normal; text-transform: none; letter-spacing: 0;
}
.col-filter-popover[hidden] { display: none; }
.col-filter-popover .popover-title {
    width: 100%; font-size: 11.5px; color: var(--ink-dim); margin-bottom: 2px;
}
.col-filter-popover .filter-chip {
    padding: 3px 9px; font-size: 11.5px;
    background: white; border: 1px solid var(--line); color: var(--ink-dim);
    border-radius: 12px; cursor: pointer;
}
.col-filter-popover .filter-chip:hover { border-color: var(--accent); color: var(--ink); }
.col-filter-popover .filter-chip.active {
    background: var(--accent); color: white; border-color: var(--accent);
}
table.events tr.events-hidden { display: none; }
table.events td, table.events th { font-size: 12.5px; padding: 6px 10px; }
table.events td code[title] { border-bottom: 1px dotted var(--ink-dim); cursor: help; }
/* Severity tint applied directly to the <code> chip. Independent of row tint so the
   "who" axis (admin/server/device/nvs) stays orthogonal to the "what" axis. */
table.events td code.sev-error { background: #fde9e9; color: var(--bad);    padding: 1px 5px; border-radius: 3px; }
table.events td code.sev-warn  { background: #fdeacc; color: var(--warn);   padding: 1px 5px; border-radius: 3px; }
table.events td code.sev-ok    { background: #d8edd8; color: #2c8a4d;       padding: 1px 5px; border-radius: 3px; }
table.events td code.sev-info  { background: transparent; color: inherit; }
table.events tr.nvs        td { background: #fffaf0; }
table.events tr.admin-evt  td { background: #eef4f8; }
table.events tr.server-evt td { background: #f3f5f7; }
.badge.nvs { background: #fdeacc; color: var(--warn); }
.badge.owner { background: #e1edf6; color: var(--accent); }
.badge.admin { background: #e9ecef; color: var(--ink-dim); }
.badge.admin-src  { background: #d8e7f3; color: #134472; }
.badge.server-src { background: #e1e4e8; color: #4a5560; }
.badge.device-src { background: #d8edd8; color: #2c8a4d; }

.invite-link {
    background: var(--panel); padding: 14px; border-radius: var(--radius);
    box-shadow: var(--shadow); margin: 16px 0;
}
.invite-link input {
    width: 100%; padding: 7px 9px; border: 1px solid var(--line);
    border-radius: 6px; font-family: monospace; font-size: 12.5px;
}

form button.danger {
    background: var(--bad); padding: 4px 10px; font-size: 12.5px;
}
form button.danger:hover { background: #8d2525; }

.upload-box {
    background: var(--panel); padding: 16px; border-radius: var(--radius);
    box-shadow: var(--shadow); margin: 16px 0;
}
.upload-box input[type="file"] { width: 100%; max-width: 480px; }

form label.inline {
    display: flex; align-items: center; gap: 8px; max-width: 340px;
}
form label.inline input { width: auto; }

/* Settings grid layout */
.settings-grid {
    display: grid; grid-template-columns: 1fr 280px; gap: 16px;
    align-items: start; margin-top: 14px;
}
@media (max-width: 820px) {
    .settings-grid { grid-template-columns: 1fr; }
    /* Data usage moves in under Reporting intervals (see Devices.php): a normal block there. */
    .settings-main .settings-side { margin: 0 0 12px; }
    .settings-main .settings-side .info-box { position: static; }
}

/* Section heading inside the Settings form — separates "Behavior" (admin-only) from
   "Connectivity" (also editable via captive portal) so the admin knows which fields
   might drift on the device. */
.settings-section-heading {
    display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap;
    margin: 14px 0 4px;
}
.settings-section-heading h3 {
    margin: 0; font-size: 13px; text-transform: uppercase; letter-spacing: .5px;
    color: var(--ink-dim);
}
.settings-section-heading .dim { font-size: 12.5px; }
/* Connectivity section: tinted with the accent colour so it reads as part of the
   same "device channel" as the Push/Pull buttons (which use --accent). */
.settings-section.device-local {
    background: #eef4f8;
    border-left: 3px solid var(--accent);
    border-radius: 6px;
    padding: 4px 14px 10px;
    margin: 8px 0 0;
}
.settings-section.device-local .settings-section-heading h3 { color: var(--accent); }
.settings-section.device-local .settings-card { box-shadow: var(--shadow); }
.settings-card {
    background: var(--panel); padding: 16px 20px; border-radius: var(--radius);
    box-shadow: var(--shadow); margin-bottom: 12px;
}
.settings-card h3 {
    margin: 0 0 14px; font-size: 12px; color: var(--ink-dim);
    text-transform: uppercase; letter-spacing: .5px;
}
/* Grid alignment: every field label becomes a 2-col row (label | input). */
.settings-card label {
    display: grid;
    grid-template-columns: 170px 1fr;
    align-items: center;
    gap: 10px 14px;
    margin: 7px 0;
    max-width: 560px;
    font-size: 13px;
}
.settings-card label input,
.settings-card label select {
    width: 100%; max-width: none;
}
.settings-card label.inline {
    display: flex; align-items: center; gap: 10px; margin: 6px 0 14px;
}
.settings-card label.inline input { width: auto; }
/* Inline horizontal field row (e.g., HOME lat/lon/radius). Each label is a stacked
   label-above-input pair, all three sitting side by side like the intervals table. */
.home-row { display: flex; flex-wrap: wrap; gap: 14px; align-items: flex-end; margin: 4px 0; }
.settings-card .home-row label.compact {
    display: flex; flex-direction: column; gap: 3px;
    grid-template-columns: none;
    margin: 0; font-size: 12px; color: var(--ink-dim);
    text-transform: none; letter-spacing: 0;
    max-width: none;
}
.settings-card .home-row label.compact input { width: 110px; padding: 3px 6px; font-size: 12.5px; }
/* Small labels sit left over their field, like every other label on the page. */
.settings-card .home-row label.compact { align-items: flex-start; text-align: left; }
.settings-card > p.dim { margin: 4px 0 12px; font-size: 12.5px; max-width: 560px; }
.settings-card table.cal { margin: 0; max-width: 560px; }
.settings-card table.cal th { font-size: 11px; padding-bottom: 6px; }
.settings-card table.cal td:first-child { font-weight: 500; }
.settings-card table.cal td:last-child { width: 36px; text-align: right; }
button.cal-wiz-btn {
    background: transparent; border: 1px solid var(--line);
    width: 28px; height: 26px; line-height: 1; padding: 0; cursor: pointer;
    border-radius: 5px; font-size: 13px;
}
button.cal-wiz-btn:hover { border-color: var(--accent); background: #eef4f8; }

/* Calibration wizard modal: live reading + 2 capture steps + result */
.cal-wiz-live {
    background: #eef4f8; border-radius: 6px;
    padding: 10px 14px; margin: 8px 0 6px;
    font-size: 14px;
    transition: background 200ms ease;
}
.cal-wiz-live.fresh { background: #d8edd8; }   /* brief green flash when a new reading lands */
.cal-wiz-live-top { display: flex; align-items: baseline; gap: 6px; }
.cal-wiz-live-bot { font-size: 11.5px; margin-top: 2px; }
.cal-wiz-live #cal-wiz-live-value {
    font-size: 22px; font-weight: 600; color: var(--ink); margin: 0 4px 0 4px;
    font-variant-numeric: tabular-nums;
}
.cal-wiz-step-body button.cal-wiz-capture:disabled {
    background: var(--line); color: var(--ink-dim); cursor: not-allowed; opacity: .8;
}
.cal-wiz-step { margin: 0 0 12px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 6px; }
.cal-wiz-step-head { display: flex; align-items: center; gap: 8px; font-size: 13px; margin-bottom: 8px; }
.cal-wiz-step-num {
    display: inline-flex; align-items: center; justify-content: center;
    width: 22px; height: 22px;
    flex: 0 0 22px;          /* lock to 22px — don't let the flex parent shrink/stretch */
    box-sizing: border-box;
    border-radius: 50%;
    background: var(--accent); color: white;
    font-size: 12px; font-weight: 600; line-height: 1;
}
.cal-wiz-step-desc { font-size: 12px; }
.cal-wiz-step-body { display: flex; flex-wrap: wrap; align-items: end; gap: 10px; }
.cal-wiz-step-body label.compact input { width: 110px; }
.cal-wiz-step-body button.cal-wiz-capture {
    padding: 5px 14px; background: var(--accent); color: white; border: none;
    border-radius: 5px; font-size: 13px; cursor: pointer;
}
.cal-wiz-step-body button.cal-wiz-capture:hover { opacity: .9; }
.cal-wiz-captured-tag { font-size: 12px; color: #2c8a4d; font-weight: 500; }
.cal-wiz-result {
    background: #f7f9fb; border-radius: 6px; padding: 10px 14px; margin: 0 0 4px;
}
table.cal-wiz-result-table { border-collapse: collapse; font-size: 13px; }
table.cal-wiz-result-table td { padding: 3px 10px 3px 0; font-variant-numeric: tabular-nums; }
table.cal-wiz-result-table td:first-child { color: var(--ink-dim); width: 56px; }
.settings-card .push-btn { margin-top: 4px; }
.settings-main { display: flex; flex-direction: column; }
.settings-main .push-btn { align-self: flex-start; margin-top: 8px; }

.info-box {
    background: #f7f9fb; padding: 14px; border-radius: var(--radius);
    border: 1px solid var(--line); position: sticky; top: 14px;
    font-size: 13px;
}
.info-box h4 {
    margin: 0 0 10px; font-size: 11px; color: var(--ink-dim);
    text-transform: uppercase; letter-spacing: .5px;
}
.info-box hr {
    border: none; border-top: 1px solid var(--line); margin: 10px 0;
}
.info-box .kv b { font-size: 14px; color: var(--ink); }

/* Data usage panel: 2×2 grid of compact mode cells (Wi-Fi/cellular × Away/HOME). */
.usage-src { margin-bottom: 10px; font-size: 12.5px; }
.usage-grid {
    display: grid; grid-template-columns: 1fr 1fr; gap: 6px;
    margin-bottom: 8px;
}
.usage-cell {
    background: white; border: 1px solid var(--line); border-radius: 5px;
    padding: 7px 9px; font-size: 11.5px; line-height: 1.35;
}
.usage-cell-label { font-weight: 500; color: var(--ink); margin-bottom: 2px; font-size: 11.5px; }
.usage-cell-iv    { color: var(--ink-dim); font-size: 11px; margin-bottom: 3px; }
.usage-cell-val   { font-variant-numeric: tabular-nums; }
.usage-cell-val b { color: var(--ink); }
.usage-foot { font-size: 11.5px; line-height: 1.4; }

.tick { font-size: 12px; color: var(--ink-dim); margin-top: -4px; margin-bottom: 12px; }
.card-value { transition: color .2s; }
/* Live cards that lead somewhere (their chart, the track, the geofence settings). */
.card.card-link { cursor: pointer; transition: box-shadow .15s, transform .15s; }
.card.card-link:hover { box-shadow: 0 0 0 1px var(--accent), var(--shadow); }
.card.card-link:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
/* Where a shortcut lands: a brief ring so the eye finds it. */
@keyframes jump-target { 0% { box-shadow: 0 0 0 3px var(--accent); } 100% { box-shadow: 0 0 0 3px rgba(44, 95, 124, 0); } }
.jump-target { animation: jump-target 1.6s ease-out 1; }

.map-wrap { margin-top: 18px; }
.map-wrap iframe {
    width: 100%; height: 320px; border: 0; border-radius: var(--radius);
    box-shadow: var(--shadow); background: #eef1f4;
}
.map-empty {
    width: 100%; height: 320px; border-radius: var(--radius);
    background: repeating-linear-gradient(45deg, #f0f3f6 0 12px, #e8ecf0 12px 24px);
    display: flex; align-items: center; justify-content: center;
    color: var(--ink-dim); font-size: 13px; text-align: center; padding: 24px;
    box-shadow: var(--shadow);
}
.map-empty[hidden] { display: none; }     /* without this, .map-empty's display:flex
                                             wins over the [hidden] attribute. */

/* Inline monochrome icon. Inherits the surrounding text colour via stroke=currentColor
   in the SVG markup, so it visually matches whatever it sits next to. */
.icon-inline {
    display: inline-block; vertical-align: -2px;
    width: 14px; height: 14px; margin-right: 2px;
}

/* Connectivity card — sits at the top of the Live tab. Two rows (Wi-Fi, Cellular)
   so the user can see both link health snapshots side-by-side regardless of which
   one is the active channel. Colours encode state: green=ok, amber=marginal, red=fail,
   grey=unknown. */
.conn-card {
    background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow);
    padding: 10px 16px; margin-bottom: 14px;
}
.conn-row {
    display: flex; align-items: center; gap: 10px; flex-wrap: nowrap;
    padding: 5px 0; font-size: 13px; line-height: 1.35;
    white-space: nowrap; min-width: 0;
}
.conn-row > * { flex-shrink: 0; }
.conn-row .conn-status { flex-shrink: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.conn-row + .conn-row { border-top: 1px solid var(--line); }
.conn-icon  {
    display: inline-flex; align-items: center; justify-content: center;
    flex-shrink: 0; width: 22px; height: 22px;
    color: var(--ink-dim);
}
.conn-label { font-weight: 500; width: 80px; flex-shrink: 0; color: var(--ink); }
.conn-status { flex: 1; color: var(--ink-dim); font-size: 12.5px; }
.conn-status b { color: var(--ink); font-weight: 500; }
.conn-badge {
    /* Fixed width so ACTIVE / STANDBY / FAIL / WARN / — all occupy the same slot.
       72 px fits the longest expected label (STANDBY = 7 chars × ~9 px + slack). */
    /* ...but a longer label (LAST SEEN 63D AGO) widens the badge instead of spilling out of it. */
    min-width: 72px; width: auto; box-sizing: border-box; white-space: nowrap;
    padding: 2px 0; text-align: center;
    border-radius: 10px; font-size: 11px; font-weight: 500; letter-spacing: .2px;
    background: #e6ebee; color: var(--ink-dim);
}
.conn-badge.active  { background: var(--accent);  color: white; }
.conn-badge.standby { background: #d8edd8;        color: #2c8a4d; }
.conn-badge.warn    { background: #fdeacc;        color: var(--warn); }
.conn-badge.bad     { background: #fde9e9;        color: var(--bad); }
.leaflet-map {
    width: 100%; height: 360px; border-radius: var(--radius);
    box-shadow: var(--shadow); background: #eef1f4;
}
.leaflet-map[hidden] { display: none; }
table.readings tr.hover-highlight td { background: #f3f7fa !important; }

.charts-head {
    display: flex; justify-content: space-between; align-items: center;
    margin: 28px 0 12px;
}
/* Tab titles were removed (the nav already shows the active tab), so the range
   controls are often the only child left — keep them pinned to the right. */
.charts-head .range { margin-left: auto; }
.range button {
    background: white; border: 1px solid var(--line); padding: 5px 12px;
    font: inherit; font-size: 12px; cursor: pointer; color: var(--ink-dim);
    border-radius: 6px; margin-left: 4px;
}
.range button:hover  { color: var(--ink); }
.range button.active { background: var(--accent); color: white; border-color: var(--accent); }

.chart-panel {
    background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow);
    padding: 12px 14px; margin-bottom: 12px;
}
.chart-title {
    font-size: 12px; color: var(--ink-dim); text-transform: uppercase;
    letter-spacing: .5px; margin-bottom: 6px;
}
/* Small hardware-channel tag after the user's label, e.g. "Main batt (CH1)" */
.chart-title-tag { color: #a6b2bd; font-weight: 400; }
.chart {
    width: 100%; height: 200px; display: block; font-family: inherit;
    cursor: grab;   /* drag to pan, scroll to zoom */
}
#charts.chart-dragging .chart { cursor: grabbing; }
.chart .okv-hover { pointer-events: none; }

/* Custom date range flyout (attached to the Custom… button) */
.chart-flyout {
    position: absolute; top: calc(100% + 6px); right: 0;
    background: var(--panel); padding: 14px 16px;
    border-radius: var(--radius); box-shadow: 0 8px 24px rgba(28,39,51,.18);
    border: 1px solid var(--line);
    /* Must clear Leaflet, which stacks its panes up to 700 (popup-pane) and its
       controls at 800/1000. At the old z-index:50 the Track tab's "Custom…" flyout
       rendered UNDER the map. Still below .modal (9999) so dialogs win over it. */
    z-index: 1200; min-width: 280px;
    display: flex; flex-direction: column; gap: 10px;
}
.chart-flyout[hidden] { display: none; }
.chart-flyout label {
    display: flex; align-items: center; justify-content: space-between;
    gap: 10px; margin: 0; font-size: 12.5px;
}
.chart-flyout input[type="datetime-local"] {
    padding: 5px 8px; border: 1px solid var(--line); border-radius: 5px;
    font: inherit; font-size: 12.5px;
}
.chart-flyout-actions {
    display: flex; gap: 8px; justify-content: flex-end; margin-top: 4px;
}

/* Tabs */
.tabs {
    display: flex; gap: 2px; margin: 18px 0 16px;
    border-bottom: 1px solid var(--line);
}
.tabs button {
    background: none; border: none; padding: 10px 16px; cursor: pointer;
    color: var(--ink-dim); font: inherit; font-size: 13px; font-weight: 500;
    border-bottom: 2px solid transparent; margin-bottom: -1px; border-radius: 0;
    transition: color .15s;
}
.tabs button:hover           { color: var(--ink); }
.tabs button.active          { color: var(--accent); border-bottom-color: var(--accent); }
/* "Quick view": the link to admin/quick.php at the right end of the device tab bar. */
.tabs a.tab-link {
    /* Sits at the right end of the tab row: it is a way out to another page, not a tab. */
    order: 99; margin-left: auto;
    padding: 10px 4px 10px 16px; font-size: 13px; font-weight: 600; color: var(--accent);
    text-decoration: none; border-bottom: 2px solid transparent; margin-bottom: -1px;
    white-space: nowrap;
}
.tabs a.tab-link:hover { color: var(--accent-h); }
/* "Unsynced" dot on a tab name: this tab has edits not yet pushed to the device.
   .saved = saved server-side (e.g. Save calibration) but still not pushed to the
   device — a distinct colour so it reads differently from unsaved edits. */
.tab-badge { color: var(--warn, #c67605); font-size: 9px; vertical-align: super; margin-left: 3px; line-height: 0; }
.tab-badge.saved { color: var(--accent); }
/* "What changed" list under the Settings / Sensors action bars (device.js
   renderSettingsChanges / renderSensorChanges). Same panel as .settings-actions, with
   the warn accent of the tab dot. Secrets only ever render as "changed". */
.pending-changes {
    margin: -6px 0 14px; padding: 10px 16px;
    background: #fffdf7; border: 1px solid var(--line); border-left: 3px solid var(--warn);
    border-radius: var(--radius); font-size: 13px;
}
.pending-changes[hidden], .discard-btn[hidden] { display: none; }
.pc-group + .pc-group { margin-top: 10px; padding-top: 8px; border-top: 1px dashed var(--line); }
.pc-head { font-weight: 600; font-size: 12.5px; color: var(--ink); margin-bottom: 4px; }
.pc-head .dim { font-weight: 400; }
.pc-list { list-style: none; margin: 0; padding: 0; line-height: 1.6; }
.pc-row { overflow-wrap: anywhere; }
.pc-label { color: var(--ink-dim); }
.pc-from { color: var(--ink-dim); text-decoration: line-through; text-decoration-color: rgba(91,107,122,.45); }
.pc-arrow { color: var(--ink-dim); margin: 0 2px; }
.pc-to { color: var(--ink); font-weight: 600; }
.pc-added .pc-from, .pc-removed .pc-to { font-style: italic; font-weight: 400; text-decoration: none; }
.pc-secret .pc-to { color: var(--warn); font-style: italic; }
.callout .pc-list { margin: 4px 0 6px; }
.pc-confirm-p { margin: 6px 0 0; }
button.secondary-btn.discard-btn { color: var(--ink-dim); border-color: var(--line); }
button.secondary-btn.discard-btn:hover { color: var(--bad); border-color: var(--bad); background: #fef2f2; }
@media (max-width: 640px) { .settings-actions { flex-wrap: wrap; } }
.tab-panel                   { display: none; }
.tab-panel.active            { display: block; animation: fadeIn .18s ease-out; }

/* ===== Snapshots tab: list + raw viewer/editor ===== */
.snap-sync-actions { display: flex; align-items: center; gap: 10px; margin-bottom: 14px;
    padding: 12px 16px; background: #fcfdfe; border: 1px solid var(--line); border-radius: var(--radius); }
.snap-layout { display: grid; grid-template-columns: minmax(220px, 300px) 1fr; gap: 18px; align-items: start; }
.snap-list-col { min-width: 0; }
.snap-list-actions { display: flex; gap: 8px; margin-bottom: 10px; }
.snap-list-actions button { flex: 1; font-size: 12.5px; padding: 6px 8px; }
.snap-detail-col { min-width: 0; }
.snap-detail-empty { padding: 30px; text-align: center; background: var(--panel); border-radius: var(--radius); border: 1px dashed var(--line); }
/* When nothing is selected the placeholder is empty — hide it so there's no bare box. */
.snap-detail-empty:empty { display: none; }
/* Snapshots-tab list rows: a clickable column (icon+label on top, time below),
   overriding the compact horizontal .snapshot layout used elsewhere. */
#snapshots-list .snapshot { display: block; cursor: pointer; padding: 8px 10px; border-radius: 6px; border-bottom: 1px dashed var(--line); }
#snapshots-list .snapshot:hover { background: #f4f8fb; }
#snapshots-list .snapshot.selected { background: #eef4f8; }
#snapshots-list .snapshot .snap-label-input { width: 78%; min-width: 0; vertical-align: baseline; }
#snapshots-list .snapshot .snap-sub { display: block; margin-top: 3px; }
.snap-detail { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.snap-detail-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-bottom: 6px; }
.snap-detail-head h4 { margin: 0; font-size: 14px; }
.snap-detail-when { font-size: 12px; color: var(--ink-dim); }
.snap-detail-sub { font-size: 12px; color: var(--ink-dim); margin: 0 0 10px; }
.snap-json {
    width: 100%; box-sizing: border-box; min-height: 260px; resize: vertical;
    font-family: "JetBrains Mono", Consolas, monospace; font-size: 12px; line-height: 1.5;
    border: 1px solid var(--line); border-radius: 6px; padding: 10px; background: #fbfcfd; color: #1c2733;
    white-space: pre; overflow: auto;
}
.snap-json.invalid { border-color: var(--bad); background: #fff6f6; }
.snap-json-status { font-size: 12px; margin: 6px 0 0; min-height: 16px; }
.snap-json-status.ok  { color: #2c8a4d; }
.snap-json-status.err { color: var(--bad); }
.snap-diff { margin-top: 12px; border-top: 1px solid var(--line); padding-top: 10px; }
.snap-diff h5 { margin: 0 0 6px; font-size: 12px; color: var(--ink-dim); text-transform: uppercase; letter-spacing: .4px; }
.snap-diff-list { font-family: "JetBrains Mono", Consolas, monospace; font-size: 12px; line-height: 1.6; }
.snap-diff-row { white-space: pre-wrap; word-break: break-word; }
.snap-diff-add { color: #2c8a4d; }
.snap-diff-del { color: var(--bad); }
.snap-diff-chg { color: #b8741b; }
.snap-diff-none { color: var(--ink-dim); }
.snap-detail-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.snap-detail-actions button { font-size: 12.5px; padding: 6px 12px; }
/* Delete keeps the same shape as the other action buttons, just a red tint. */
.snap-detail-actions .snap-del { color: var(--bad); border-color: #e6b8b8; }
.snap-detail-actions .snap-del:hover { background: #fdeaea; border-color: var(--bad); }
@media (max-width: 760px) { .snap-layout { grid-template-columns: 1fr; } }
@keyframes fadeIn { from { opacity: 0; transform: translateY(2px); } to { opacity: 1; transform: none; } }

/* Modal overlay for "pushing/pulling" feedback */
.overlay {
    position: fixed; inset: 0;
    background: rgba(28, 39, 51, 0.45);
    display: flex; align-items: center; justify-content: center;
    z-index: 9999; backdrop-filter: blur(2px);
}
.overlay[hidden] { display: none; }
.overlay-card {
    background: var(--panel); padding: 28px 40px; border-radius: var(--radius);
    box-shadow: 0 12px 32px rgba(0,0,0,.25); text-align: center;
    position: relative; min-width: 260px;
}
.overlay-msg { margin-top: 14px; font-weight: 500; color: var(--ink); }
.overlay-min-btn {
    position: absolute; top: 6px; right: 8px;
    background: none; border: none; cursor: pointer;
    width: 28px; height: 28px; font-size: 22px; line-height: 22px;
    color: var(--ink-dim); border-radius: 4px;
}
.overlay-min-btn:hover { background: #eef1f4; color: var(--ink); }

/* Minimized pill in the bottom-right corner */
.overlay-pill {
    position: fixed; right: 18px; bottom: 18px;
    background: var(--accent); color: white;
    padding: 8px 14px 8px 12px; border-radius: 999px;
    display: flex; align-items: center; gap: 10px;
    box-shadow: 0 6px 18px rgba(0,0,0,.22);
    z-index: 9998; cursor: pointer;
    font-size: 13px;
    animation: pillIn .25s ease-out;
}
.overlay-pill[hidden] { display: none; }
.overlay-pill:hover { background: var(--accent-h); }
.overlay-pill.ready {
    background: var(--ok); cursor: default;
    padding: 6px 6px 6px 14px;
}
.overlay-pill.ready:hover { background: var(--ok); }
.overlay-pill button {
    background: rgba(255,255,255,0.20); color: white; border: 1px solid rgba(255,255,255,0.35);
    padding: 4px 10px; border-radius: 999px; font: inherit; font-size: 12px;
    cursor: pointer; font-weight: 500;
}
.overlay-pill button:hover { background: rgba(255,255,255,0.32); }
.overlay-pill button.pill-dismiss { padding: 4px 8px; font-weight: 600; }
@keyframes pillIn {
    from { transform: translateY(8px); opacity: 0; }
    to   { transform: none; opacity: 1; }
}

.spinner {
    width: 36px; height: 36px; margin: 0 auto;
    border: 3px solid var(--line);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.9s linear infinite;
}
.spinner-mini {
    width: 14px; height: 14px;
    border: 2px solid rgba(255,255,255,0.35);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Chart loading state. The indicator sits inline with the range chips rather than
   overlaying the charts, so the previous data stays readable while the new range
   loads instead of the panel going blank. #charts dims to signal "this is stale". */
/* Shared loading indicator for Charts, Track and Events.
   Toggled with `visibility`, NOT `display`, and given a reserved min-width: the element
   keeps its box whether or not it's showing, so appearing can never nudge the range
   buttons. (It also sidesteps the trap that bit the first version — `display:inline-flex`
   is an author rule and outranks the UA's `[hidden]{display:none}`, so the `hidden`
   attribute silently did nothing and the spinner stuck on screen after loading finished.)
   Right-aligned inside its reserved box so it hugs the filters it belongs to. */
.chart-loading {
    display: inline-flex; align-items: center; justify-content: flex-end; gap: 6px;
    min-width: 132px;          /* fits the longest label, "Loading 30 days…" */
    visibility: hidden;
    font-size: 12.5px; color: var(--ink-dim); white-space: nowrap;
}
.chart-loading.is-visible { visibility: visible; }
/* Push the indicator + its range bar to the right as one unit. The adjacent-sibling rule
   cancels .range's own margin-left:auto, otherwise two auto margins would split the free
   space and strand the spinner in the middle of the row. */
.charts-head .chart-loading { margin-left: auto; margin-right: 10px; }
.charts-head .chart-loading + .range { margin-left: 0; }
.spinner-inline {
    width: 12px; height: 12px; flex: none;
    border: 2px solid var(--line);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}
#charts.is-loading { opacity: 0.45; transition: opacity 120ms ease; pointer-events: none; }
#charts { transition: opacity 120ms ease; }
/* Respect a reduced-motion preference: keep the indicator, drop the spin. */
@media (prefers-reduced-motion: reduce) {
    .spinner-inline { animation: none; border-top-color: var(--accent); }
}

/* Snapshot panel: highlight the currently-loaded snapshot with a full-row tint
   in the accent colour family. No left-border or ::before marker — the row colour
   does the work without eating horizontal space from the rename input. */
.snapshot.current {
    background: #dde9f1; border-radius: 4px;
    padding: 6px 8px;
    margin-left: -8px; margin-right: -8px;
    border-bottom-color: transparent;
}
/* Unsaved snapshot row: same shape as other rows; only the label area becomes editable.
   The Save button inherits the default .snapshot button (same as Load). */
/* Unsaved row gets a warm tint so it's visually distinct from the current (blue) row. */
.snapshot.unsaved {
    background: #fdf3da; border-radius: 4px;
    padding: 6px 8px;
    margin-left: -8px; margin-right: -8px;
    border-bottom-color: transparent;
}
.snapshot.unsaved .src-admin { color: var(--ink); }
.snapshot .snap-label-input {
    border: 1px solid transparent;
    background: transparent;
    font: inherit; font-size: 12px; font-weight: 500;
    color: var(--ink);
    padding: 1px 6px;
    border-radius: 3px;
    width: 150px;
    vertical-align: baseline;
}
.snapshot.unsaved .snap-label-input { border-style: dashed; border-color: var(--line); }
.snapshot .snap-label-input:hover { border-color: var(--line); }
.snapshot .snap-label-input:focus {
    outline: none; border-color: var(--accent); border-style: solid; background: white;
}
.snapshot .snap-label-input::placeholder { color: var(--ink-dim); }
.current-banner {
    font-size: 12px; color: var(--ink-dim); margin: 8px 0 0;
}
.current-banner b { color: var(--accent); }

/* ===================== Sharing (admin panel) ===================== */
.share-admin { margin: 10px 0 2px; }
.btn-share {
    background: var(--panel); color: var(--accent); border: 1px solid var(--line);
    border-radius: var(--radius); padding: 6px 12px; font-size: 13px; cursor: pointer;
}
.btn-share:hover { border-color: var(--accent); }
/* Share now lives in a dialog, so the panel itself carries no chrome — the .modal-card
   provides the surface, border and shadow. Keeping its own box here would double them. */
.share-panel { margin: 0; }
/* Wider than the default 480px modal: share rows hold a full URL in a readonly input. */
.share-modal-card {
    max-width: 720px;
    max-height: 82vh;      /* long temp-link lists scroll inside the card, not the page */
    overflow-y: auto;
}
.share-panel-lead { margin: 0 0 12px; color: var(--ink-dim); font-size: 12.5px; }
.share-err { color: var(--bad); margin: 0; }
.share-link-row {
    display: flex; gap: 12px; align-items: flex-start; padding: 10px 0; border-top: 1px solid var(--line);
}
.share-link-row:first-of-type { border-top: none; }
.share-link-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.share-link-title { font-weight: 600; }
.share-link-desc { color: var(--ink-dim); font-size: 12px; }
.share-link-url {
    width: 100%; font-family: "JetBrains Mono", Consolas, monospace; font-size: 12px;
    padding: 5px 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); color: var(--ink);
}
.share-link-actions { display: flex; flex-direction: column; gap: 6px; flex-shrink: 0; }
.btn-copy, .btn-regen, .btn-revoke {
    border: 1px solid var(--line); background: var(--panel); border-radius: 6px;
    padding: 5px 10px; font-size: 12.5px; cursor: pointer; white-space: nowrap;
}
.btn-copy:hover { border-color: var(--accent); color: var(--accent); }
.btn-regen:hover, .btn-revoke:hover { border-color: var(--warn); color: var(--warn); }
.share-temp { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); }
.share-temp-h { font-weight: 600; font-size: 12.5px; margin-bottom: 8px; }
.share-temp-form { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-size: 13px; }
.share-temp-form select, .share-temp-form input {
    border: 1px solid var(--line); border-radius: 6px; padding: 5px 8px; font-size: 13px; background: var(--panel); color: var(--ink);
}
.share-temp-form input[type="number"] { width: 64px; }
.share-temp-form input[type="text"] { flex: 1; min-width: 130px; }
.share-temp-list { list-style: none; margin: 12px 0 0; padding: 0; }
.share-temp-list li { display: flex; align-items: center; gap: 8px; padding: 6px 0; font-size: 12.5px; }
.share-temp-meta { flex: 1; color: var(--ink-dim); }
.share-expired { color: var(--bad); }

/* ===================== Public share page ===================== */
body.share-page { background: var(--bg); }
#share-view { display: flex; flex-direction: column; min-height: 100vh; }
.share-head {
    position: sticky; top: 0; z-index: 500; display: flex; align-items: center; justify-content: space-between;
    gap: 12px; padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.share-title { display: flex; flex-direction: column; min-width: 0; }
.share-alias { font-weight: 600; font-size: 16px; color: var(--ink); }
.share-status { font-size: 12px; color: var(--ink-dim); }
.share-status.bad { color: var(--bad); }
.share-ranges { display: flex; gap: 4px; }
.share-ranges button {
    border: 1px solid var(--line); background: var(--panel); color: var(--ink-dim);
    border-radius: 6px; padding: 5px 10px; font-size: 12.5px; cursor: pointer;
}
.share-ranges button.on { background: var(--accent); color: #fff; border-color: var(--accent); }
#share-view[data-scope="track"] .share-map { height: calc(100vh - 108px); }
#share-view[data-scope="full"]  .share-map { height: 52vh; }
.share-map { width: 100%; min-height: 300px; background: #e8edf1; }
.share-metrics { display: flex; flex-wrap: wrap; gap: 8px; padding: 12px 12px 0; }
.share-chip { background: var(--panel); border: 1px solid var(--line); border-radius: 20px; padding: 4px 12px; font-size: 12.5px; }
.share-chip-v { font-weight: 600; color: var(--ink); }
.share-chip-l { color: var(--ink-dim); margin-left: 6px; }
.share-charts { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; padding: 12px; }
.share-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; }
.share-card-h { display: flex; align-items: baseline; gap: 6px; margin-bottom: 6px; }
.share-card-t { font-weight: 600; font-size: 13px; }
.share-card-v { margin-left: auto; font-weight: 600; font-size: 15px; color: var(--accent); }
.share-card-u { color: var(--ink-dim); font-size: 12px; }
.share-svg { width: 100%; height: 150px; display: block; }
.share-foot {
    display: flex; align-items: center; justify-content: space-between;
    padding: 8px 16px; color: var(--ink-dim); font-size: 11.5px; border-top: 1px solid var(--line); margin-top: auto;
}
.share-brand { font-weight: 600; letter-spacing: .3px; }
.share-gone { max-width: 460px; margin: 18vh auto; text-align: center; padding: 0 20px; }
.share-gone h1 { font-size: 20px; margin-bottom: 8px; }
.share-gone p { color: var(--ink-dim); }

/* ---- Mobile: wrap the Track/Charts option bar (range + Export + Share) cleanly ---- */
@media (max-width: 640px) {
    .charts-head { flex-wrap: wrap; gap: 6px; margin-top: 16px; }
    .charts-head .range { margin-left: 0; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
    /* gap now owns the spacing — drop the per-button and inline margins so wrapped
       rows line up flush instead of stair-stepping. */
    .range button { margin-left: 0 !important; }
    .share-head { flex-wrap: wrap; }
    .share-charts { grid-template-columns: 1fr; }
}

/* ---- Home mode selector (Settings tab) ---- */
.home-mode { display: flex; flex-wrap: wrap; gap: 18px; margin: 4px 0 12px; }
.home-mode label { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; font-size: 13px; }
.home-mode-body[hidden] { display: none; }
.ah-status { margin-top: 8px; font-style: italic; }

/* ---- Browser list ("Where alarms are sent" on the Alarms page; public/js/notifications.js) ----
   Fixed column widths (table-layout: fixed) so nothing shifts while a button's text
   changes or a row switches between off/on. */
.notif-page .notif-card { max-width: 920px; margin-bottom: 18px; }
.notif-page .notif-card p { margin: 6px 0; }
.notif-page .notif-card ol { margin: 6px 0 6px 20px; }
.notif-page .notif-on { color: var(--ok, #1e7b34); }
.notif-page .notif-this { font-size: 11px; background: #e6f0f6; color: var(--accent); border-radius: 10px; padding: 1px 8px; margin-left: 6px; white-space: nowrap; display: inline-block; }
.notif-page .notif-actions { white-space: nowrap; }
.notif-page .notif-actions button { padding: 5px 10px; min-width: 84px; }
.notif-page a.push-btn { display: inline-block; padding: 8px 18px; border-radius: 6px; background: var(--accent); color: #fff; text-decoration: none; font-size: 13px; font-weight: 500; }
.notif-page .notif-table { table-layout: fixed; width: 100%; }
.notif-page .notif-table col.c-added { width: 165px; }
.notif-page .notif-table col.c-last { width: 175px; }
.notif-page .notif-table col.c-act { width: 200px; }
.notif-page .notif-table td { overflow-wrap: anywhere; vertical-align: middle; }
@media (max-width: 600px) {
    /* Phones: drop the "Added" column but keep the cells so the layout stays fixed. */
    .notif-page .notif-table col.c-added { width: 0; }
    .notif-page .notif-table th:nth-child(2), .notif-page .notif-table td:nth-child(2) { display: table-cell; visibility: hidden; padding: 0; font-size: 0; }
    .notif-page .notif-table col.c-last { width: 110px; }
    .notif-page .notif-table col.c-act { width: 104px; }
    .notif-page .notif-actions button { display: block; width: 100%; margin: 2px 0; }
    /* ...except the "why it can't be turned on" cell (it IS the 2nd cell, colspan 3):
       on an iPhone outside the Home Screen app that text is the whole point. */
    .notif-page .notif-table td.notif-why { visibility: visible; font-size: 13px; padding: 10px 12px; }
}

/* Phones: the top menu doesn't fit on one line at 390 px — wrap instead of pushing
   "Sign out" off the right edge (which also made every admin page scroll sideways). */
@media (max-width: 640px) {
    .topbar { flex-wrap: wrap; gap: 0; padding: 8px 14px; }
    .topbar .nav-toggle { display: flex; order: -1; margin: 0 12px 0 -4px; }   /* menu button first, on the left */
    /* App name centred: the menu button is 48px wide with its margins, so balance it on the right. */
    /* App name centred between the menu button (left) and the sign-out icon (right). */
    .topbar .brand { flex: 1 1 0; text-align: center; }
    .topbar nav { display: none !important; order: 2; }
    .topbar .topbar-right { order: 1; margin: 0 -4px 0 12px !important; }
    .topbar .topbar-right button.link {
        display: flex; align-items: center; justify-content: center; width: 40px; height: 36px; padding: 0;
        border: 1px solid rgba(255, 255, 255, .18); border-radius: 8px; color: #fff;
    }
    .topbar .so-text { display: none; }
    .topbar .so-icon { display: block; }
    .topbar.open nav {
        display: flex !important; flex: 1 1 100%;
        flex-direction: column; align-items: stretch; gap: 0;
        margin-top: 8px; border-top: 1px solid rgba(255, 255, 255, .12);
    }
    .topbar.open nav a { padding: 12px 2px; font-size: 15px; border-bottom: 1px solid rgba(255, 255, 255, .08); }
    .topbar.open nav a:last-child { border-bottom: 0; padding-bottom: 6px; }   /* no line under the last item */
}

/* ---- Alarms page (public/js/alarms.js) ---- */
.alarms-page .alarms-intro { margin: 4px 0 14px; max-width: 760px; }
.alarms-page h2 { scroll-margin-top: 12px; }
.alarms-toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 8px 0 12px; }
.alarms-note { max-width: 920px; margin: 0 0 12px; }
.alarm-warn {
    max-width: 920px; margin: 0 0 12px; padding: 10px 14px; font-size: 13.5px;
    background: #fff6dc; border: 1px solid #ecd28a; border-left: 4px solid #e0a800; border-radius: 6px; color: #5c4700;
}
.alarm-warn a { color: inherit; text-decoration: underline; }
.alarm-list { display: flex; flex-direction: column; gap: 10px; max-width: 920px; }
.alarm-empty { max-width: 920px; padding: 22px 18px; text-align: left; }
/* "Sent to" is one card: the table inside it has no box of its own. */
.alarms-page .notif-card table.readings { box-shadow: none; border: 0; border-radius: 0; margin: 0; }
.alarms-page .notif-card:has(table.readings) { padding: 0; overflow: hidden; }
.alarm-rule {
    background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow);
    padding: 12px 16px; border-left: 4px solid #c7dccb;
}
.alarm-rule.is-active  { border-left-color: var(--bad); }
.alarm-rule.is-pending { border-left-color: var(--warn); }
.alarm-rule.is-off     { border-left-color: var(--line); }
.alarm-rule.is-off .alarm-rule-name, .alarm-rule.is-off .alarm-rule-text { opacity: .6; }
.alarm-rule-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.alarm-rule-name { font-weight: 600; font-size: 15px; flex: 1 1 160px; min-width: 0; overflow-wrap: anywhere; }
.alarm-status { font-size: 11.5px; font-weight: 600; padding: 2px 9px; border-radius: 999px; background: #e3f4e8; color: #1a7a3a; }
.alarm-status.active  { background: #fde9e9; color: var(--bad); }
.alarm-status.pending { background: #fdeacc; color: var(--warn); }
.alarm-status.off     { background: #eef2f4; color: #6b7a86; }
.alarm-rule-text { margin: 6px 0 10px; font-size: 13px; color: var(--ink-dim); line-height: 1.55; overflow-wrap: anywhere; }
.alarm-rule-text b { color: var(--ink); font-weight: 600; }
.alarm-kw { font-weight: 700; color: var(--accent); font-size: 11.5px; letter-spacing: .5px; }
.alarm-rule-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.alarm-rule-actions button.secondary-btn { padding: 5px 12px; }
button.secondary-btn.alarm-del { color: var(--bad); border-color: #e2b4b4; }
button.secondary-btn.alarm-del:hover { background: #fdf0f0; }

/* On/off switch (a real checkbox underneath, so it's keyboard + screen-reader friendly). */
.alarm-switch { position: relative; display: inline-block; width: 38px; height: 22px; flex: 0 0 38px; }
.alarm-switch input { position: absolute; inset: 0; opacity: 0; margin: 0; width: 100%; height: 100%; cursor: pointer; z-index: 1; }
.alarm-switch span { position: absolute; inset: 0; background: #c3ccd3; border-radius: 999px; transition: background .15s; }
.alarm-switch span::after {
    content: ''; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px;
    background: #fff; border-radius: 50%; box-shadow: 0 1px 2px rgba(0,0,0,.25); transition: transform .15s;
}
.alarm-switch input:checked + span { background: var(--accent); }
.alarm-switch input:checked + span::after { transform: translateX(16px); }
.alarm-switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.alarm-switch input:disabled { cursor: wait; }

/* Editor: a plain form, one labelled row per choice (label column + control). */
.alarm-editor {
    background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow);
    border: 1px solid #c9dbe7; padding: 14px 18px 16px; margin-bottom: 14px; max-width: 560px;
}
.alarm-editor h3 { margin: 0 0 4px; font-size: 12px; color: var(--ink-dim); text-transform: uppercase; letter-spacing: .5px; }
.alarm-editor-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.alarm-editor-top h3 { margin: 0; }
.alarm-sec { margin: 14px 0 6px; font-size: 14px; color: var(--ink-dim); }
.alarm-sec .alarm-kw { font-size: 13px; margin-right: 4px; }
.alarm-field { display: grid; grid-template-columns: 64px minmax(0, 1fr); align-items: center; gap: 10px; margin: 8px 0; font-size: 14px; }
.alarm-label { color: var(--ink-dim); font-size: 13px; }
.alarm-ctl { display: flex; align-items: center; gap: 8px; min-width: 0; }
.alarm-ctl select, .alarm-ctl input[type="number"], .alarm-ctl input[type="text"],
.alarm-line select, .alarm-line input[type="number"] {
    font: inherit; font-size: 15px; height: 40px; padding: 0 10px; border: 1px solid var(--line); border-radius: 8px;
    background: #fff; color: var(--ink); min-width: 0; flex: 1 1 0; width: 100%; box-sizing: border-box;
}
.alarm-ctl select:focus, .alarm-ctl input:focus, .alarm-line select:focus, .alarm-line input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
.alarm-when input[type="number"] { flex: 0 1 110px; }
.alarm-ctl .alarm-unit { color: var(--ink-dim); flex: none; }
.alarm-check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 14px; }
.alarm-check input { margin: 0; width: 18px; height: 18px; flex: none; }
.alarm-name { margin-top: 14px; }
.alarm-hint { font-size: 12.5px; margin: 8px 0 0; max-width: 760px; }
.alarm-hint + .alarm-hint { margin-top: 3px; }
.alarm-editor .error { margin: 8px 0 0; font-size: 13px; }
.alarm-editor-actions { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }

/* History */
.alarm-history { max-width: 920px; background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); }
.alarm-history > p { margin: 0; padding: 18px; }
.alarm-hist-row {
    display: grid; grid-template-columns: 112px 104px minmax(0, 1fr) auto;
    grid-template-areas: "time kind msg sent"; gap: 4px 12px; align-items: baseline;
    padding: 8px 14px; border-bottom: 1px solid var(--line); font-size: 13px;
}
.alarm-hist-row:last-child { border-bottom: 0; }
.ah-time { grid-area: time; color: var(--ink-dim); font-variant-numeric: tabular-nums; white-space: nowrap; }
.ah-kind { grid-area: kind; justify-self: start; font-size: 11px; font-weight: 600; padding: 1px 8px; border-radius: 999px; white-space: nowrap; }
.ah-kind.fire   { background: #fde9e9; color: var(--bad); }
.ah-kind.repeat { background: #fdeacc; color: var(--warn); }
.ah-kind.clear  { background: #d8edd8; color: #2c8a4d; }
.ah-kind.test   { background: #e6f0f6; color: var(--accent); }
.ah-msg { grid-area: msg; min-width: 0; overflow-wrap: anywhere; }
.ah-msg b { font-weight: 600; }
.ah-msg .dim { display: block; font-size: 12.5px; }
.ah-sent { grid-area: sent; color: var(--ink-dim); font-size: 12px; white-space: nowrap; }
.ah-sent.none { color: var(--bad); }
@media (max-width: 640px) {
    .alarm-rule { padding: 12px 12px; }
    .alarm-editor { padding: 12px 12px 14px; }
    .alarm-editor-actions button { flex: 1 1 0; }
    .alarm-hist-row { grid-template-columns: auto auto minmax(0, 1fr); grid-template-areas: "time kind sent" "msg msg msg"; }
    .ah-sent { justify-self: end; }
}


/* ==========================================================================
   One size for every field, button and title, on every page.
   Measured 2026-11-24: fields ran from 26 to 40 px tall with five font sizes,
   buttons from 30 to 34 px, card titles in three sizes. These rules come last
   and win on purpose, so a page cannot drift again:
     field   35 px tall, 13 px text      (phones: 42 px, 16 px - no zoom-in on iOS)
     button  35 px tall, 13 px text      (phones: 42 px, 14 px) - the same height as a
             field, so a field and a button side by side line up exactly
     corners 6 px
     page title 22 px; section title 16 px caps; card title 12 px caps
   Not covered, by design: tabs, the small range chips (1h / 24h / 7d), the
   Basic/Expert switches and the inline rename boxes in tables.
   ========================================================================== */
main.page input:is([type="text"], [type="number"], [type="password"], [type="search"], [type="email"], [type="date"], [type="datetime-local"], :not([type])):not(.snap-label-input),
main.page select {
    height: 35px !important; box-sizing: border-box !important;
    padding-top: 0 !important; padding-bottom: 0 !important;
    font-size: 13px !important; border-radius: 6px !important; line-height: normal !important;
}
main.page input:is([type="text"], [type="number"], [type="password"], [type="email"], :not([type])):not(.snap-label-input):not(.search-input) { padding-left: 10px !important; padding-right: 10px !important; }

main.page :is(button.push-btn, button.secondary-btn, a.push-btn, a.secondary-btn, button.device-send-btn,
              form.pair button, .bulk-actions button, .modal-actions button, table button.danger) {
    height: 35px !important; box-sizing: border-box !important;
    display: inline-flex; align-items: center; justify-content: center;
    padding: 0 16px !important; font-size: 13px !important; font-weight: 500; line-height: 1 !important;
    border-radius: 6px !important; white-space: nowrap;
}
main.page :is(button.push-btn, button.secondary-btn, a.push-btn, a.secondary-btn, button.device-send-btn)[hidden] { display: none; }
button.device-send-btn { border: 1px solid var(--accent); }

/* Rows that mix range chips and buttons: everything on one centre line, one height. */
.range { display: flex; flex-wrap: wrap; align-items: center; row-gap: 6px; }
.range > button:not(.push-btn):not(.secondary-btn), .diag-toggle {
    height: 35px; box-sizing: border-box; display: inline-flex; align-items: center; justify-content: center;
    padding-top: 0; padding-bottom: 0; font-size: 13px; line-height: 1;
}
@media (max-width: 640px) {
    .range > button:not(.push-btn):not(.secondary-btn), .diag-toggle { height: 42px; font-size: 14px; }
}

.devices-header h1 { font-size: 22px; }
.diag-card h3, .info-box h4, .settings-card h3 {
    font-size: 12px !important; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; color: var(--ink-dim);
}

@media (max-width: 640px) {
    main.page input:is([type="text"], [type="number"], [type="password"], [type="search"], [type="email"], [type="date"], [type="datetime-local"], :not([type])):not(.snap-label-input),
    main.page select { height: 42px !important; font-size: 16px !important; }
    main.page :is(button.push-btn, button.secondary-btn, a.push-btn, a.secondary-btn, button.device-send-btn,
                  form.pair button, .bulk-actions button, .modal-actions button, table button.danger) {
        height: 42px !important; font-size: 14px !important; padding: 0 14px !important;
    }
    /* Rows of buttons wrap onto a new line instead of squeezing each other tall. */
    .settings-actions, .alarm-rule-actions, .alarm-editor-actions, .notif-actions { flex-wrap: wrap; row-gap: 8px; }
    /* Snapshots: the four buttons as an even two-by-two block. */
    .snap-sync-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
    .snap-sync-actions > button { margin-left: 0 !important; width: 100%; padding: 0 6px !important; }
    /* The status note gets a full row of its own under the buttons (nothing when it is empty). */
    .snap-sync-actions > #snap-sync-hint { grid-column: 1 / -1; order: 9; }
    .snap-sync-actions > #snap-sync-hint:empty { display: none; }
}

/* Notification editor, Simple: one line - what, condition, limit. */
.alarm-line { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 10px 0 4px; }
.alarm-line select[data-f="metric"] { flex: 1 1 150px; min-width: 0; }
.alarm-line select[data-f="cond"], .alarm-line > span { flex: 0 1 auto; min-width: 0; }
.alarm-line input[type="number"] { flex: 0 0 84px; width: 84px; min-width: 0; }
.alarm-line select { width: auto; }
.alarm-line select[data-f="cond"] { max-width: 100%; }
@media (max-width: 640px) {
    .alarm-line { gap: 6px; }
    .alarm-line select[data-f="metric"] { flex: 1 1 96px; }
    .alarm-line input[type="number"] { flex: 0 0 64px; width: 64px; padding-left: 8px !important; padding-right: 4px !important; }
    .alarm-line select { padding-left: 6px; padding-right: 2px; }
}
.alarm-line select:not([data-f="metric"]):not([data-f="cond"]) { flex: 0 1 auto; }
.alarm-line .alarm-unit { color: var(--ink-dim); flex: none; }


/* "Loading…" placeholders stay invisible for the first half second, so a page or panel
   that fills in quickly never flashes them. */
@keyframes loading-late { from { opacity: 0; } to { opacity: 1; } }
.loading-late { animation: loading-late .01s linear .5s both; }

/* The loading note next to the range chips takes no room while there is nothing to say. */
.chart-loading:not(.is-visible) { display: none; }

/* Phones: range chips always sit at the right; on Events the Diagnostics switch sits at
   the left on the same line, and the event count goes on a line of its own below. */
@media (max-width: 640px) {
    .charts-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 8px 6px; }
    .charts-head .range { margin-left: auto; justify-content: flex-end; gap: 6px; }
    .charts-head .range > button { margin-left: 0 !important; }
    .charts-head .range > button:not(.push-btn):not(.secondary-btn) { padding-left: 7px; padding-right: 7px; min-width: 34px; }
    .charts-head .range { gap: 5px; }
    .charts-head .diag-toggle { order: -1; margin-left: 0; margin-right: auto; padding-left: 8px; padding-right: 8px; gap: 6px; }
    .diag-count-word { display: none; }
    .charts-head .filter-count { order: 8; flex: 1 1 100%; }
    .charts-head .chart-loading { order: 9; flex: 1 1 100%; margin: 0; justify-content: flex-end; min-width: 0; }
}

/* Phones, details page: name, state and age on one line, the Quick view link at the right
   ("Marita  ● online 12s ago            Quick view"). Wraps under the name if it is long. */
@media (max-width: 640px) {
    #device-live > h1 { display: inline; }
    #device-live > h1 .ov-top { float: right; margin: 0 0 0 10px; padding: 5px 0; line-height: 1.3; }
    #device-live > #device-status { display: inline; margin: 0 0 0 8px; font-size: 13.5px; white-space: nowrap; }
    #device-status .st-ls { display: none; }
    #device-status .st-state { margin-right: 5px; }
    #device-live > #device-tabs { clear: both; margin-top: 12px; }
}
.charts-head .diag-toggle { }
@media (max-width: 640px) { .charts-head .diag-toggle { font-size: 13px; } }

/* Phones: the Simple notification line is two tidy rows instead of a ragged wrap -
   what to watch across the full width, then condition (fills the row), limit and unit. */
@media (max-width: 640px) {
    .alarm-line { gap: 8px; }
    .alarm-line select[data-f="metric"] { flex: 1 1 100%; width: 100%; }
    .alarm-line select[data-f="cond"] { flex: 1 1 0; width: auto; min-width: 0; }
    .alarm-line select[data-f="value"] { flex: 1 1 0; min-width: 0; }
    .alarm-line input[type="number"] { flex: 0 0 84px; width: 84px; padding-left: 10px !important; padding-right: 6px !important; }
    .alarm-line select { padding-left: 10px; padding-right: 6px; }
}
