/* SMTOOL — dark & light NOC-style UI, red accent throughout.
   Theme tokens live on :root (dark, the default) and are swapped wholesale
   under [data-theme="light"]. The <html data-theme> attribute is set as
   early as possible by an inline script in <head> — before this stylesheet
   is even requested — computed from localStorage, falling back to the OS
   preference, so there is no flash of the wrong theme on load and no CSS
   media-query duplication is needed here. */
:root {
    --bg:        #0a0d12;
    --bg-2:      #10141c;
    --bg-3:      #171d28;
    --line:      #242c3a;
    --line-soft: #1a212c;
    --text:      #e6ebf3;
    --muted:     #8792a8;
    --heading:   #f2f6fd;
    --accent:    #ff6b81;
    --accent-2:  #3fb950;
    --accent-dk: #e2354f;
    --ok:        #3fb950;
    --warn:      #d29922;
    --crit:      #f85149;
    --down:      #6e7887;
    /* "ink" colours: text sitting on a translucent tinted fill (badges,
       alerts, faceplate ports) needs to be a pale tint of the state colour
       in dark mode but a deep, saturated one in light mode, or it reads as
       nearly invisible against its own fill. */
    --ok-ink:    #7fe6b6;
    --warn-ink:  #f7c877;
    --crit-ink:  #ffb0b6;
    --info-ink:  #ffb3c1;
    --row-hover: rgba(255,255,255,.025);
    --radius:    10px;
    --radius-sm: 7px;
    --shadow:    0 1px 2px rgba(0,0,0,.5), 0 12px 28px -14px rgba(0,0,0,.75);
    --shadow-sm: 0 1px 2px rgba(0,0,0,.5);
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --mono: ui-monospace, "Cascadia Mono", Consolas, "Courier New", monospace;
    color-scheme: dark;
}

:root[data-theme="light"] {
    --bg:        #f5f6f9;
    --bg-2:      #ffffff;
    --bg-3:      #eef0f4;
    --line:      #dde1e9;
    --line-soft: #e7e9ef;
    --text:      #1b2130;
    --muted:     #64748b;
    --heading:   #0f1420;
    --accent:    #be123c;
    --accent-2:  #16a34a;
    --accent-dk: #c81e45;
    --ok:        #16a34a;
    --warn:      #b45309;
    --crit:      #dc2626;
    --down:      #94a3b8;
    --ok-ink:    #15803d;
    --warn-ink:  #a15c07;
    --crit-ink:  #b91c1c;
    --info-ink:  #9f1239;
    --row-hover: rgba(15,23,42,.035);
    --shadow:    0 1px 2px rgba(20,20,30,.05), 0 12px 24px -14px rgba(20,20,30,.12);
    --shadow-sm: 0 1px 2px rgba(20,20,30,.06);
    color-scheme: light;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 14px/1.55 var(--font);
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
    transition: background-color .25s ease, color .25s ease;
}

/* ---------------------------------------------------------- motion
   Every entrance/attention animation below is scoped inside this query, so
   a visitor with "reduce motion" set at the OS level gets an instant,
   perfectly static UI instead — the same content, none of the movement. */
@media (prefers-reduced-motion: no-preference) {
    @keyframes riseIn {
        from { opacity: 0; transform: translateY(10px); }
        to   { opacity: 1; transform: translateY(0); }
    }
    @keyframes popIn {
        from { opacity: 0; transform: scale(.94) translateY(6px); }
        to   { opacity: 1; transform: scale(1) translateY(0); }
    }
    @keyframes dropIn {
        from { opacity: 0; transform: translateY(-8px); }
        to   { opacity: 1; transform: translateY(0); }
    }

    .panel, .tile, .device-card, .auth-card { animation: riseIn .45s cubic-bezier(.16,1,.3,1) both; }
    .modal { animation: popIn .22s cubic-bezier(.16,1,.3,1) both; }
    .alert { animation: dropIn .3s cubic-bezier(.16,1,.3,1) both; }
    .fp-port { animation: riseIn .35s cubic-bezier(.16,1,.3,1) both; }

    /* A light stagger reads as the board "powering up" rather than a slow
       reveal — capped at a handful of items so it stays snappy even on a
       page with dozens of tiles, cards or panels. */
    .tiles .tile:nth-child(1), .device-cards .device-card:nth-child(1), .wrap > .panel:nth-of-type(1) { animation-delay: .02s; }
    .tiles .tile:nth-child(2), .device-cards .device-card:nth-child(2), .wrap > .panel:nth-of-type(2) { animation-delay: .06s; }
    .tiles .tile:nth-child(3), .device-cards .device-card:nth-child(3), .wrap > .panel:nth-of-type(3) { animation-delay: .10s; }
    .tiles .tile:nth-child(4), .device-cards .device-card:nth-child(4), .wrap > .panel:nth-of-type(4) { animation-delay: .14s; }
    .tiles .tile:nth-child(5), .device-cards .device-card:nth-child(5) { animation-delay: .18s; }
    .tiles .tile:nth-child(6), .device-cards .device-card:nth-child(6) { animation-delay: .22s; }
    .fp-col:nth-child(1) .fp-port { animation-delay: .01s; }
    .fp-col:nth-child(2) .fp-port { animation-delay: .025s; }
    .fp-col:nth-child(3) .fp-port { animation-delay: .04s; }
    .fp-col:nth-child(4) .fp-port { animation-delay: .055s; }
    .fp-col:nth-child(5) .fp-port { animation-delay: .07s; }
    .fp-col:nth-child(6) .fp-port { animation-delay: .085s; }
    .fp-row.wrap .fp-port:nth-child(1) { animation-delay: .01s; }
    .fp-row.wrap .fp-port:nth-child(2) { animation-delay: .025s; }
    .fp-row.wrap .fp-port:nth-child(3) { animation-delay: .04s; }
    .fp-row.wrap .fp-port:nth-child(4) { animation-delay: .055s; }
    .fp-row.wrap .fp-port:nth-child(5) { animation-delay: .07s; }
    .fp-row.wrap .fp-port:nth-child(6) { animation-delay: .085s; }
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, pre, .mono { font-family: var(--mono); }
.muted { color: var(--muted); }
.text-crit { color: var(--crit); font-weight: 650; }
.small { font-size: 12px; }
h1, h2, h3 { margin: 0 0 .6em; font-weight: 650; letter-spacing: -.1px; color: var(--heading); }
h1 { font-size: 21px; }
h2 { font-size: 15.5px; }

/* Slim, on-theme scrollbars (WebKit/Blink + Firefox). */
* { scrollbar-width: thin; scrollbar-color: var(--line) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb { background: var(--line); border-radius: 20px; border: 2px solid transparent; background-clip: content-box; }
*::-webkit-scrollbar-thumb:hover { background: var(--muted); background-clip: content-box; }

/* ---------------------------------------------------------------- layout */
.sidebar-toggle-state { display: none; }
.shell { display: flex; align-items: stretch; min-height: 100vh; }

.sidebar {
    display: flex; flex-direction: column;
    width: 220px; flex: none;
    position: sticky; top: 0; align-self: flex-start; height: 100vh;
    background: var(--bg-2);
    border-right: 1px solid var(--line);
    padding: 16px 14px;
    z-index: 40;
    transition: background-color .25s ease, border-color .25s ease;
}
.brand {
    display: inline-flex; align-items: center; gap: 9px;
    font-weight: 700; font-size: 16px; letter-spacing: -.2px; color: var(--heading); white-space: nowrap;
    padding: 0 6px;
}
.brand:hover { text-decoration: none; opacity: .92; }
.brand-word { background: linear-gradient(90deg, var(--heading), var(--accent)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.logo-mark { display: block; filter: drop-shadow(0 2px 6px rgba(226,53,79,.35)); flex-shrink: 0; }

.nav { display: flex; flex-direction: column; gap: 2px; margin-top: 22px; }
.nav a {
    color: var(--muted); padding: 9px 12px; border-radius: var(--radius-sm); font-size: 13.5px; font-weight: 500;
    transition: background-color .15s ease, color .15s ease, transform .12s ease;
}
.nav a:hover { background: var(--bg-3); color: var(--text); text-decoration: none; transform: translateX(2px); }
.nav a.active { background: var(--accent-dk); color: #fff; box-shadow: var(--shadow-sm); }
.nav a.active:hover { transform: none; }

.sidebar .who {
    margin-top: auto; padding-top: 14px; border-top: 1px solid var(--line-soft);
    display: flex; flex-direction: column; gap: 9px;
}
.who-line { display: flex; align-items: center; gap: 8px; padding: 0 6px; }
.who-name { color: var(--text); font-weight: 500; font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who-logout, .theme-toggle {
    display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12.5px;
    padding: 7px 9px; border-radius: var(--radius-sm); transition: background-color .15s ease, color .15s ease;
    background: none; border: none; font: inherit; cursor: pointer; width: 100%; text-align: left;
}
.who-logout:hover, .theme-toggle:hover { background: var(--bg-3); color: var(--text); text-decoration: none; }
.who-logout svg { flex-shrink: 0; }
/* Fixed-size stage so both icons can sit stacked (position: absolute) and
   cross-fade with a quarter-turn instead of the flat, instant swap a plain
   display:none/block toggle would give. */
.theme-toggle-icon { position: relative; width: 15px; height: 15px; flex-shrink: 0; }
.theme-toggle-icon svg {
    position: absolute; inset: 0;
    transition: opacity .3s ease, transform .3s ease;
}
.theme-toggle .icon-sun  { opacity: 0; transform: rotate(-90deg) scale(.4); }
.theme-toggle .icon-moon { opacity: 1; transform: rotate(0) scale(1); }
:root[data-theme="light"] .theme-toggle .icon-sun  { opacity: 1; transform: rotate(0) scale(1); }
:root[data-theme="light"] .theme-toggle .icon-moon { opacity: 0; transform: rotate(90deg) scale(.4); }

/* Compact variant: a small floating icon-only circle, used on the auth pages
   (login/install) which have no sidebar to dock the full-width version in. */
.theme-toggle.compact {
    width: auto; padding: 9px; border-radius: 50%;
    background: var(--bg-2); border: 1px solid var(--line); box-shadow: var(--shadow-sm);
}
.theme-toggle.compact .theme-toggle-label { display: none; }
.auth-theme-toggle { position: fixed; top: 18px; right: 18px; }

.sidebar-backdrop { display: none; }

.main { flex: 1; min-width: 0; }

/* Slim topbar: hidden on desktop, holds the menu button + brand on mobile. */
.topbar {
    display: none; align-items: center; gap: 12px;
    background: var(--bg-2);
    backdrop-filter: blur(10px) saturate(1.2);
    -webkit-backdrop-filter: blur(10px) saturate(1.2);
    border-bottom: 1px solid var(--line);
    padding: 0 16px; height: 52px;
    position: sticky; top: 0; z-index: 30;
    transition: background-color .25s ease, border-color .25s ease;
}
.menu-btn { display: inline-flex; color: var(--text); padding: 6px; border-radius: var(--radius-sm); cursor: pointer; }
.menu-btn:hover { background: var(--bg-3); }
.brand-mobile { font-size: 15px; }

.wrap { max-width: 1500px; margin: 0 auto; padding: 22px 20px 64px; }

@media (max-width: 880px) {
    .topbar { display: flex; }
    .sidebar {
        position: fixed; top: 0; left: 0; height: 100vh; z-index: 60;
        transform: translateX(-100%);
        transition: transform .18s ease;
        box-shadow: 0 0 40px rgba(0,0,0,.5);
    }
    .sidebar-backdrop {
        display: none;
        position: fixed; inset: 0; background: rgba(4,8,14,.6); z-index: 50;
    }
    .sidebar-toggle-state:checked ~ .shell .sidebar { transform: translateX(0); }
    .sidebar-toggle-state:checked ~ .shell .sidebar-backdrop { display: block; }
}
.page-head { display: flex; align-items: flex-start; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head .grow { flex: 1; min-width: 240px; }

/* ---------------------------------------------------------------- panels */
.panel {
    background: linear-gradient(180deg, var(--bg-2), var(--bg-2) 60%, var(--bg));
    border: 1px solid var(--line);
    border-radius: var(--radius);
    margin-bottom: 18px;
    box-shadow: var(--shadow);
    overflow: hidden;
    transition: border-color .25s ease;
}
.panel > header {
    display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
    padding: 13px 17px;
    border-bottom: 1px solid var(--line-soft);
    background: linear-gradient(180deg, rgba(255,255,255,.02), transparent);
    transition: border-color .25s ease;
}
.panel > header h2 { margin: 0; font-size: 14px; letter-spacing: .1px; }
.panel > header .grow { flex: 1; }
.panel .body { padding: 17px; }

/* ---------------------------------------------------------------- tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(165px, 1fr)); gap: 12px; margin-bottom: 20px; }
.tile {
    position: relative;
    background: var(--bg-2); border: 1px solid var(--line);
    border-radius: var(--radius); padding: 15px 16px 15px 19px;
    box-shadow: var(--shadow-sm);
    transition: transform .12s ease, box-shadow .12s ease, background-color .25s ease, border-color .25s ease;
}
.tile::before {
    content: ""; position: absolute; left: 0; top: 10px; bottom: 10px; width: 3px; border-radius: 3px;
    background: var(--line);
    transition: background-color .25s ease;
}
.tile:hover { transform: translateY(-1px); box-shadow: var(--shadow); }
.tile-filter { cursor: pointer; }
.tile-filter:hover { border-color: var(--accent); }
.tile-filter:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.tile-filter.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent), var(--shadow); }
.tile-filter.active::after {
    content: "filtering"; position: absolute; right: 12px; top: 12px;
    font-size: 9.5px; font-weight: 700; letter-spacing: .4px; text-transform: uppercase;
    color: var(--accent);
}
.tile .k { color: var(--muted); font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .7px; }
.tile .v { font-size: 27px; font-weight: 650; margin-top: 5px; letter-spacing: -.3px; font-variant-numeric: tabular-nums; }
.tile.ok   .v { color: var(--ok); }   .tile.ok::before   { background: var(--ok); }
.tile.warn .v { color: var(--warn); } .tile.warn::before { background: var(--warn); }
.tile.crit .v { color: var(--crit); } .tile.crit::before { background: var(--crit); }

/* ---------------------------------------------------------------- tables */
table.grid { width: 100%; border-collapse: collapse; font-size: 13px; }
table.grid th, table.grid td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--line-soft); white-space: nowrap; transition: border-color .25s ease; }
table.grid th {
    color: var(--muted); font-weight: 600; font-size: 11.5px;
    text-transform: uppercase; letter-spacing: .5px;
    background: var(--bg-3);
    transition: background-color .25s ease, border-color .25s ease;
}
table.grid th:first-child, table.grid td:first-child { padding-left: 17px; }
table.grid th:last-child, table.grid td:last-child { padding-right: 17px; }
table.grid tbody tr { transition: background-color .1s ease; }
table.grid tbody tr:hover { background: var(--row-hover); }
table.grid td.num { text-align: right; font-family: var(--mono); font-variant-numeric: tabular-nums; }
table.grid td.wrap { white-space: normal; min-width: 160px; }
/* No position:sticky on table.grid th: overflow-x:auto here silently forces
   overflow-y to "auto" as well (a CSS quirk — the pair can't be mixed
   visible/non-visible), which turns this box into its own scroll container.
   A sticky header inside then locks to *this* container instead of the page,
   landing on top of the first row instead of staying above it. Not worth the
   fragility for a header that only needs to be readable, not pinned. */
.table-scroll { overflow-x: auto; }

/* Pins the Actions column to the right edge of the scroll area, so buttons
   like Delete are always reachable without scrolling all the way across a
   wide table on a phone — the row used to just clip off mid-button there,
   with nothing telling you there was more to scroll to. The left-edge
   shadow is the same "frozen column" cue spreadsheets use for this. */
.sticky-actions {
    position: sticky; right: 0;
    background: var(--bg-2);
    box-shadow: -6px 0 8px -6px rgba(0,0,0,.4);
}
table.grid th.sticky-actions { background: var(--bg-3); }

/* ---------------------------------------------------------------- badges */
.badge {
    display: inline-flex; align-items: center; padding: 2.5px 9px; border-radius: 20px;
    font-size: 11px; font-weight: 650; letter-spacing: .3px;
    border: 1px solid transparent;
    transition: background-color .25s ease, color .25s ease, border-color .25s ease;
}
.badge.up      { background: rgba(63,185,80,.14); color: var(--ok);   border-color: rgba(63,185,80,.35); }
.badge.down    { background: rgba(248,81,73,.13); color: var(--crit); border-color: rgba(248,81,73,.35); }
.badge.admdown { background: rgba(107,124,153,.18); color: var(--muted); border-color: rgba(107,124,153,.4); }
.badge.unknown { background: rgba(107,124,153,.12); color: var(--muted); border-color: var(--line); }
.badge.warn    { background: rgba(210,153,34,.14);  color: var(--warn); border-color: rgba(210,153,34,.35); }
.badge.info    { background: rgba(226,53,79,.13);   color: var(--accent); border-color: rgba(226,53,79,.35); }

.dbm { font-family: var(--mono); font-weight: 600; }
.dbm.ok   { color: var(--ok); }
.dbm.warn { color: var(--warn); }
.dbm.crit { color: var(--crit); }
.dbm.dark { color: var(--crit); font-size: 12px; letter-spacing: .3px; }
.dbm.none { color: var(--muted); font-weight: 400; }

/* Signal strength bar next to the Rx value. */
.bar { display: inline-block; width: 54px; height: 6px; background: var(--bg-3); border-radius: 3px; overflow: hidden; vertical-align: middle; margin-left: 8px; }
.bar > i { display: block; height: 100%; border-radius: 3px; }
.bar > i.ok { background: var(--ok); }
.bar > i.warn { background: var(--warn); }
.bar > i.crit { background: var(--crit); }

/* ---------------------------------------------------------------- buttons */
.btn {
    display: inline-flex; align-items: center; gap: 6px;
    background: var(--bg-3); color: var(--text);
    border: 1px solid var(--line); border-radius: var(--radius-sm);
    padding: 7px 13px; font-size: 13px; font-weight: 500; font-family: inherit;
    cursor: pointer; text-decoration: none; white-space: nowrap;
    transition: background-color .12s ease, border-color .12s ease, transform .06s ease, box-shadow .12s ease, color .2s ease;
}
.btn:hover { border-color: var(--accent); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn.busy { opacity: .55; cursor: not-allowed; transform: none; }
.btn.primary { background: var(--accent-dk); border-color: var(--accent-dk); color: #fff; box-shadow: 0 1px 0 rgba(255,255,255,.08) inset, 0 4px 12px -4px rgba(226,53,79,.6); }
.btn.primary:hover { background: var(--accent); border-color: var(--accent); }
.btn.danger { background: rgba(248,81,73,.12); border-color: rgba(248,81,73,.45); color: var(--crit-ink); }
.btn.danger:hover { background: rgba(248,81,73,.22); }
.btn.good { background: rgba(63,185,80,.12); border-color: rgba(63,185,80,.45); color: var(--ok-ink); }
.btn.good:hover { background: rgba(63,185,80,.22); }
.btn.tiny { padding: 3.5px 10px; font-size: 11.5px; border-radius: 6px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
/* Inside a table row, wrapping just makes that one row tall and uneven —
   the table already scrolls horizontally (.table-scroll) for exactly this
   case, so the actions stay on one line and the table handles the overflow
   instead of the buttons. */
table.grid .btn-row { flex-wrap: nowrap; }

/* ---------------------------------------------------------------- forms */
label { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 12px; }
input[type=text], input[type=password], input[type=number], input[type=search], select, textarea {
    width: 100%; margin-top: 5px;
    background: var(--bg); color: var(--text);
    border: 1px solid var(--line); border-radius: var(--radius-sm);
    padding: 8px 10px; font: inherit;
    transition: border-color .12s ease, box-shadow .12s ease, background-color .25s ease, color .25s ease;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(226,53,79,.15); }
textarea { font-family: var(--mono); font-size: 12.5px; resize: vertical; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 0 16px; }
.span2 { grid-column: span 2; }
label.check { display: flex; align-items: center; gap: 8px; color: var(--text); }
label.check input { width: auto; margin: 0; }
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.toolbar input[type=search], .toolbar select { width: auto; min-width: 150px; margin-top: 0; }

/* Users table's per-row edit form: stacked label+field pairs instead of
   everything crammed onto one line, but narrow enough to still sit
   comfortably inside a table cell. */
.user-edit-form { min-width: 210px; max-width: 230px; white-space: normal; }
.user-edit-form label { margin-bottom: 8px; }
.user-edit-form .btn-row { align-items: center; margin-top: 2px; }

/* ---------------------------------------------------------------- alerts */
.alert { padding: 11px 14px; border-radius: var(--radius-sm); margin-bottom: 14px; border: 1px solid; border-left-width: 3px; font-size: 13px; }
.alert.ok    { background: rgba(63,185,80,.1);  border-color: rgba(63,185,80,.4);  color: var(--ok-ink); }
.alert.error { background: rgba(248,81,73,.1);  border-color: rgba(248,81,73,.4);  color: var(--crit-ink); }
.alert.warn  { background: rgba(210,153,34,.1);  border-color: rgba(210,153,34,.4);  color: var(--warn-ink); }
.alert.info  { background: rgba(226,53,79,.1);   border-color: rgba(226,53,79,.4);  color: var(--info-ink); }
.alert p:last-child { margin-bottom: 0; }

/* ---------------------------------------------------------------- console */
pre.console {
    background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius);
    padding: 14px; margin: 0;
    font-family: var(--mono); font-size: 12.5px; line-height: 1.5;
    color: var(--text); white-space: pre-wrap; word-break: break-word;
    max-height: 60vh; overflow: auto;
}

/* ---------------------------------------------------------------- auth */
.auth-body {
    display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 20px;
    background: var(--bg);
}
.auth-logo { display: flex; justify-content: center; margin-bottom: 16px; }
.auth-card {
    background: linear-gradient(180deg, var(--bg-2), var(--bg));
    border: 1px solid var(--line);
    border-radius: 14px; padding: 32px; width: 100%; max-width: 380px;
    box-shadow: var(--shadow);
    text-align: center;
    transition: border-color .25s ease;
}
.auth-card.wide { max-width: 620px; }
.auth-card h1 { margin-bottom: 4px; font-size: 22px; }
.auth-card > p.muted { margin-bottom: 22px; }
.auth-card form,
.auth-card label { text-align: left; }
.auth-card.wide { text-align: left; }
.auth-card.wide .auth-logo { justify-content: flex-start; }

/* ---------------------------------------------------------------- modal */
.modal-backdrop {
    position: fixed; inset: 0; background: rgba(4,8,14,.78);
    backdrop-filter: blur(2px);
    display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 100;
    animation: fadeIn .12s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.modal {
    background: linear-gradient(180deg, var(--bg-2), var(--bg));
    border: 1px solid var(--line); border-radius: 14px;
    width: 100%; max-width: 780px; max-height: 88vh; display: flex; flex-direction: column;
    box-shadow: 0 20px 60px -12px rgba(0,0,0,.6);
}
.modal header { padding: 15px 19px; border-bottom: 1px solid var(--line-soft); display: flex; align-items: center; transition: border-color .25s ease; }
.modal header h2 { margin: 0; flex: 1; }
.modal .body { padding: 19px; overflow: auto; }
.modal footer { padding: 12px 18px; border-top: 1px solid var(--line-soft); display: flex; gap: 10px; justify-content: flex-end; transition: border-color .25s ease; }

/* ------------------------------------------------------------ faceplate */
.fp-module { margin-bottom: 20px; }
.fp-module:last-of-type { margin-bottom: 0; }
.fp-title {
    color: var(--muted); font-size: 11.5px; font-weight: 600;
    text-transform: uppercase; letter-spacing: .6px; margin-bottom: 8px;
}

.faceplate {
    background: linear-gradient(180deg, var(--bg-3), var(--bg));
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 12px;
    overflow-x: auto;
}
.fp-row { display: flex; gap: 5px; }
.fp-row.wrap { flex-wrap: wrap; width: auto; }

/* Ports are laid out column by column (each column = one physical pair, top
   odd / bottom even) rather than as two independently-packed rows. A port
   the switch never reported would otherwise shift every later port in just
   one row out of step with its neighbour above/below it — a blank .fp-slot
   keeps both rows aligned instead. */
.fp-cols { display: flex; gap: 5px; width: max-content; }
.fp-col  { display: flex; flex-direction: column; gap: 5px; flex: none; }
.fp-slot { display: block; width: 40px; height: 34px; flex: none; }

.fp-port {
    position: relative;
    width: 40px; height: 34px; flex: none;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    border: 1px solid var(--line);
    border-radius: 4px;
    background: var(--bg-3);
    color: var(--muted);
    font: 600 11px/1 var(--mono);
    cursor: pointer; padding: 0;
    transition: transform .08s ease, box-shadow .08s ease, background-color .25s ease, border-color .25s ease, color .25s ease;
}
.fp-port:hover { transform: translateY(-2px); box-shadow: 0 3px 10px rgba(0,0,0,.5); z-index: 2; }
.fp-port:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.fp-port.up    { background: rgba(63,185,80,.20); border-color: rgba(63,185,80,.55); color: var(--ok-ink); }
.fp-port.down  { background: rgba(248,81,73,.18); border-color: rgba(248,81,73,.50); color: var(--crit-ink); }
/* Admin-shut gets its own strong colour (amber) so it reads at a glance and
   is never confused with the muted grey "no SFP" cell next to it. */
.fp-port.shut  { background: rgba(210,153,34,.24); border-color: rgba(210,153,34,.75); color: var(--warn-ink); }
.fp-port.blank { background: var(--bg); border-color: var(--line-soft); color: var(--muted); }
.fp-port.alarm { box-shadow: 0 0 0 1px rgba(248,81,73,.5), 0 0 10px rgba(248,81,73,.35); }

.fp-num { pointer-events: none; }
.fp-bar {
    position: absolute; left: 4px; right: 4px; bottom: 3px;
    height: 3px; border-radius: 2px; background: var(--down);
}
.fp-bar.ok   { background: var(--ok); }
.fp-bar.warn { background: var(--warn); }
.fp-bar.crit { background: var(--crit); }
.fp-bar.none { background: var(--line); }
/* Fitted optic receiving nothing — flashes so a cut fibre is obvious. */
.fp-bar.dark { background: var(--crit); animation: darkPulse 1.4s ease-in-out infinite; }
@keyframes darkPulse { 0%,100% { opacity: 1; } 50% { opacity: .25; } }

.fp-legend { display: flex; gap: 14px; flex-wrap: wrap; align-items: center; font-size: 11.5px; color: var(--muted); }
.fp-legend span { display: inline-flex; align-items: center; gap: 5px; }
.fp-legend .fp-sep { width: 1px; height: 14px; background: var(--line); padding: 0; }
.fp-key { width: 12px; height: 12px; border-radius: 3px; border: 1px solid var(--line); display: inline-block; }
.fp-key.up    { background: rgba(63,185,80,.20); border-color: rgba(63,185,80,.55); }
.fp-key.down  { background: rgba(248,81,73,.18); border-color: rgba(248,81,73,.5); }
.fp-key.shut  { background: rgba(210,153,34,.24); border-color: rgba(210,153,34,.75); }
.fp-key.blank { background: var(--bg); border-color: var(--line-soft); }
.fp-key.bar-ok   { background: var(--ok);   border: none; height: 4px; border-radius: 2px; }
.fp-key.bar-warn { background: var(--warn); border: none; height: 4px; border-radius: 2px; }
.fp-key.bar-crit { background: var(--crit); border: none; height: 4px; border-radius: 2px; }
.fp-key.bar-dark { background: var(--crit); border: none; height: 4px; border-radius: 2px; animation: darkPulse 1.4s ease-in-out infinite; }

/* Port detail modal */
.pd-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; margin-bottom: 4px; }
.pd-cell { background: var(--bg-3); border: 1px solid var(--line); border-radius: 7px; padding: 9px 11px; }
.pd-cell .k { color: var(--muted); font-size: 10.5px; text-transform: uppercase; letter-spacing: .5px; }
.pd-cell .v { font-family: var(--mono); font-size: 17px; font-weight: 600; margin-top: 3px; }
.pd-cell .v.ok { color: var(--ok); } .pd-cell .v.warn { color: var(--warn); } .pd-cell .v.crit { color: var(--crit); }
.pd-cell .v.none { color: var(--muted); font-weight: 400; }

/* ---------------------------------------------------------------- misc */
.device-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 14px; }
.device-card {
    background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 15px 17px;
    box-shadow: var(--shadow-sm); transition: transform .12s ease, box-shadow .12s ease, border-color .12s ease, background-color .25s ease;
}
.device-card:hover { transform: translateY(-1px); box-shadow: var(--shadow); border-color: var(--accent); }
.device-card h3 { margin: 0 0 2px; font-size: 15px; }
.device-card .rows { margin-top: 10px; font-size: 12.5px; }
.device-card .rows div { display: flex; justify-content: space-between; padding: 3.5px 0; color: var(--muted); }
.device-card .rows div b { color: var(--text); font-weight: 500; }
.empty { padding: 40px 20px; text-align: center; color: var(--muted); }
.spinner {
    width: 13px; height: 13px; border: 2px solid rgba(255,255,255,.25);
    border-top-color: #fff; border-radius: 50%; animation: spin .7s linear infinite; display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

.spark { display: block; width: 100%; height: 150px; }

@media (max-width: 720px) {
    .grid-2 { grid-template-columns: 1fr; }
    .span2 { grid-column: span 1; }
}

/* ------------------------------------------------------------ mobile */
@media (max-width: 600px) {
    .wrap { padding: 16px 12px 48px; }
    h1 { font-size: 18px; }
    .tiles { grid-template-columns: repeat(2, 1fr); gap: 8px; }
    .tile { padding: 12px 12px 12px 15px; }
    .tile .v { font-size: 22px; }
    .panel .body { padding: 13px; }
    .panel > header { padding: 11px 13px; }
    table.grid th:first-child, table.grid td:first-child { padding-left: 13px; }
    table.grid th:last-child, table.grid td:last-child { padding-right: 13px; }
    /* Buttons and inputs get a taller tap target on touch screens. */
    .btn { padding: 9px 14px; min-height: 38px; }
    .btn.tiny { padding: 6px 11px; min-height: 30px; }
    input[type=text], input[type=password], input[type=number], input[type=search], select, textarea {
        padding: 10px 11px;
    }
    .toolbar input[type=search], .toolbar select { width: 100%; min-width: 0; }
    .toolbar { flex-direction: column; align-items: stretch; }
    .page-head { flex-direction: column; }
    .page-head .btn-row { width: 100%; }
    .page-head .btn-row .btn { flex: 1; justify-content: center; }
    .device-cards { grid-template-columns: 1fr; }
    .pd-grid { grid-template-columns: repeat(2, 1fr); }
    .modal { max-height: 94vh; }
    .modal .body { padding: 14px; }
    .modal footer { flex-wrap: wrap; }
    .modal footer .btn { flex: 1; justify-content: center; }
}
