/* Shared neutral grayish-black surface for every dark theme (Basic, Fiber
   NOC, Midnight Ocean, Sunset Amber, Terminal Green) — only Light overrides
   these. Each dark theme still gets its own accent/link/status colors below;
   only the base canvas/panels/borders are unified, not the "flavor". */
:root {
    --bg: #121214;
    --panel: #1c1c20;
    --panel-2: #18181b;
    --line: #2a2a2e;
    --panel-hover: #232327;
    --overlay: 255,255,255;

    --text: #e2e8f0;
    --muted: #94a3b8;
    --faint: #64748b;
    --link: #60a5fa;
    --up: #22c55e;
    --down: #ef4444;
    --degraded: #f59e0b;
    --unknown: #64748b;
    --accent: #2563eb;
    --accent-hover: #1d4ed8;
    --accent-rgb: 59,130,246;
    --link-rgb: 96,165,250;
    --up-rgb: 34,197,94;
    --down-rgb: 239,68,68;
    --degraded-rgb: 245,158,11;
    --muted-rgb: 148,163,184;
}

html.theme-fiber-noc {
    --text: #f7f4fa;
    --muted: #c8bbd0;
    --faint: #93899a;
    --link: #e13aa4;
    --up: #4fd8a8;
    --down: #ff6478;
    --degraded: #f5bd4f;
    --unknown: #8f8992;
    --accent: #df329e;
    --accent-hover: #bd247f;
    --accent-rgb: 223,50,158;
    --link-rgb: 225,58,164;
    --up-rgb: 79,216,168;
    --down-rgb: 255,100,120;
    --degraded-rgb: 245,189,79;
    --muted-rgb: 200,187,208;
}

html.theme-midnight-ocean {
    --text: #e0f2f5;
    --muted: #8fb8c2;
    --faint: #5f8790;
    --link: #22d3ee;
    --up: #2dd4bf;
    --down: #f87171;
    --degraded: #fbbf24;
    --unknown: #64818a;
    --accent: #0891b2;
    --accent-hover: #0e7490;
    --accent-rgb: 8,145,178;
    --link-rgb: 34,211,238;
    --up-rgb: 45,212,191;
    --down-rgb: 248,113,113;
    --degraded-rgb: 251,191,36;
    --muted-rgb: 143,184,194;
}

html.theme-sunset-amber {
    --text: #fdf1e3;
    --muted: #d9b48f;
    --faint: #a8825f;
    --link: #fb923c;
    --up: #4ade80;
    --down: #f87171;
    --degraded: #fbbf24;
    --unknown: #9c7f5f;
    --accent: #ea580c;
    --accent-hover: #c2410c;
    --accent-rgb: 234,88,12;
    --link-rgb: 251,146,60;
    --up-rgb: 74,222,128;
    --down-rgb: 248,113,113;
    --degraded-rgb: 251,191,36;
    --muted-rgb: 217,180,143;
}

html.theme-light {
    --bg: #f4f6f9;
    --panel: #ffffff;
    --panel-2: #eef1f6;
    --line: #dbe1ea;
    --panel-hover: #f1f4f9;
    --overlay: 0,0,0;

    --text: #101828;
    --muted: #5b6474;
    --faint: #8b93a3;
    --link: #2563eb;
    --up: #16a34a;
    --down: #dc2626;
    --degraded: #d97706;
    --unknown: #6b7280;
    --accent: #2563eb;
    --accent-hover: #1d4ed8;
    --accent-rgb: 37,99,235;
    --link-rgb: 37,99,235;
    --up-rgb: 22,163,74;
    --down-rgb: 220,38,38;
    --degraded-rgb: 217,119,6;
    --muted-rgb: 91,100,116;
}

html.theme-terminal-green {
    --text: #d3ffe0;
    --muted: #7fd9a0;
    --faint: #4f9a6c;
    --link: #39ff88;
    --up: #39ff88;
    --down: #ff5c5c;
    --degraded: #ffd93d;
    --unknown: #5b8a6e;
    --accent: #22c55e;
    --accent-hover: #16a34a;
    --accent-rgb: 34,197,94;
    --link-rgb: 57,255,136;
    --up-rgb: 57,255,136;
    --down-rgb: 255,92,92;
    --degraded-rgb: 255,217,61;
    --muted-rgb: 127,217,160;
}
html.theme-terminal-green, html.theme-terminal-green .brand-app-name, html.theme-terminal-green h1, html.theme-terminal-green h2 {
    font-family: "Cascadia Code", "Consolas", "SF Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }

html {
    min-height: 100%;
    overflow-x: hidden;
    overflow-y: auto;
}
body {
    min-height: 100%;
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 15px/1.5 system-ui, "Segoe UI", Roboto, Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    overflow-y: auto;
    touch-action: pan-x pan-y;
}
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---- top bar ---- */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 12px 24px;
    background: var(--panel-2);
    border-bottom: 1px solid var(--line);
    position: sticky;
    top: 0;
    z-index: 10;
}
.brand {
    display: inline-flex;
    align-items: center;
    gap: 9px;
    color: var(--text);
    font-weight: 700;
    font-size: 16px;
}
.brand:hover { text-decoration: none; }
.brand .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--up); box-shadow: 0 0 8px var(--up); }
.brand-logo { gap: 12px; min-width: 0; }
.brand-logo img { display: block; height: 34px; width: auto; max-width: 210px; }
.brand-app-name {
    color: var(--muted);
    font-size: 13px;
    font-weight: 600;
    padding-left: 12px;
    border-left: 1px solid var(--line);
    white-space: nowrap;
}
.mainnav a {
    color: var(--muted);
    padding: 6px 12px;
    border-radius: 7px;
    font-weight: 500;
}
.mainnav { display: flex; align-items: center; justify-content: flex-end; gap: 2px; flex-wrap: wrap; }
.mainnav a:hover { color: var(--text); background: rgba(var(--overlay),.05); text-decoration: none; }
.mainnav a.active { color: var(--text); background: rgba(var(--link-rgb),.14); }
.install-app-btn {
    width: auto;
    margin: 0 4px;
    padding: 6px 10px;
    border: 1px solid rgba(var(--link-rgb),.45);
    border-radius: 7px;
    color: var(--text);
    background: rgba(var(--link-rgb),.12);
    font-size: 12px;
    font-weight: 700;
}
.install-app-btn:hover { background: rgba(var(--link-rgb),.22); }
.install-app-btn[hidden] { display: none; }

.theme-menu { position: relative; display: inline-flex; margin: 0 2px; }
.theme-panel {
    position: absolute; top: calc(100% + 8px); right: 0; z-index: 50;
    width: 210px; background: var(--panel); border: 1px solid var(--line);
    border-radius: 10px; padding: 8px; box-shadow: 0 8px 24px rgba(0,0,0,.35);
}
/* [hidden] must win over the flex layout below, or the browser's built-in
   hidden-attribute behavior (display:none) gets overridden by this rule and
   the panel renders permanently visible regardless of JS toggling it. */
.theme-panel:not([hidden]) { display: flex; flex-direction: column; gap: 2px; }
.theme-option-form { margin: 0; }
.theme-option-btn {
    display: flex; align-items: center; gap: 10px; width: 100%;
    padding: 7px 9px; border-radius: 7px; border: none; background: transparent;
    color: var(--text); font-size: 13px; font-family: inherit; font-weight: 500;
    cursor: pointer; text-align: left;
}
.theme-option-btn:hover { background: rgba(var(--overlay),.07); }
.theme-option-btn.active { background: rgba(var(--link-rgb),.16); font-weight: 700; }
.theme-option-icon { font-size: 16px; width: 20px; text-align: center; flex-shrink: 0; }

@media (max-width: 760px) {
    .brand-logo img { height: 28px; max-width: 170px; }
    .brand-app-name { display: none; }
}

/* ---- layout ---- */
.wrap { max-width: 1600px; margin: 0 auto; padding: 24px; }
.foot { text-align: center; color: var(--faint); font-size: 12px; padding: 28px 24px 20px; }
.foot-brand { display: flex; align-items: center; justify-content: center; gap: 8px; margin-bottom: 4px; }
.foot-inf {
    font-size: 22px; font-weight: 700; line-height: 1;
    background: linear-gradient(135deg, #a855f7, #ec4899);
    -webkit-background-clip: text; background-clip: text; color: transparent;
}
.foot-brand-text { font-size: 17px; font-weight: 700; color: var(--text); letter-spacing: .01em; }
.foot-brand-text .grad {
    background: linear-gradient(135deg, #a855f7, #ec4899);
    -webkit-background-clip: text; background-clip: text; color: transparent;
}
.foot-tagline { font-size: 11.5px; color: var(--muted); letter-spacing: .03em; margin-bottom: 10px; }
.foot-tagline .dots { color: #ec4899; letter-spacing: 2px; }
.foot-owner { font-size: 11.5px; color: var(--faint); margin-bottom: 14px; }
.foot-app { font-size: 20px; font-weight: 800; color: var(--text); margin-bottom: 8px; }
.foot-meta { font-size: 11px; color: var(--faint); }

h1 { font-size: 1.4rem; margin: 0 0 4px; }
h2 { font-size: 1rem; color: var(--muted); font-weight: 600; margin: 28px 0 12px; text-transform: uppercase; letter-spacing: .04em; }
.sub { color: var(--muted); margin: 0 0 20px; }

/* ---- summary tiles ---- */
.summary { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin: 20px 0 8px; }
.summary .tile {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 14px 16px;
}
.summary .tile .n { font-size: 1.9rem; font-weight: 700; line-height: 1; }
.summary .tile .l { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; margin-top: 6px; }
.summary .tile.up .n { color: var(--up); }
.summary .tile.down .n { color: var(--down); }
.summary .tile.degraded .n { color: var(--degraded); }
.summary .tile.total .n { color: var(--text); }
a.tile { text-decoration: none; transition: border-color .12s, background .12s; }
a.tile:hover { border-color: var(--faint); background: var(--panel-hover); text-decoration: none; }
a.tile.active { border-color: var(--link); box-shadow: 0 0 0 1px var(--link) inset; }

.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.page-head h1 { margin: 0 0 4px; }
.who-chip { color: var(--faint); font-size: 12px; }
.role-badge { display: inline-block; padding: 1px 7px; border-radius: 999px; font-size: 11px; font-weight: 600; background: rgba(var(--link-rgb),.16); color: var(--link); }

.bell-btn {
    background: transparent; border: 1px solid var(--line); color: var(--muted);
    border-radius: 7px; padding: 5px 9px; font-size: 15px; line-height: 1; cursor: pointer;
}
.bell-btn:hover { background: rgba(var(--overlay),.05); color: var(--text); }
.bell-btn[aria-pressed=true] { border-color: rgba(var(--link-rgb),.4); background: rgba(var(--link-rgb),.12); }

.alert-menu { position: relative; display: inline-flex; gap: 4px; }
.alert-panel {
    position: absolute; top: calc(100% + 8px); right: 0; z-index: 50;
    width: 220px; background: var(--panel); border: 1px solid var(--line);
    border-radius: 10px; padding: 10px 12px; box-shadow: 0 8px 24px rgba(0,0,0,.35);
}
.alert-panel-h { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--faint); font-weight: 600; margin: 8px 0 4px; }
.alert-panel-h:first-child { margin-top: 0; }
.alert-panel label { display: flex; align-items: center; gap: 8px; padding: 4px 2px; font-size: 13px; color: var(--text); cursor: pointer; }
.alert-panel input[type=checkbox] { width: auto; accent-color: var(--accent); }
.alert-test-btn { justify-content: center; width: 100%; margin-top: 12px; }

.toast-stack {
    position: fixed; right: 16px; bottom: 16px; z-index: 999;
    display: flex; flex-direction: column; gap: 8px; max-width: 320px;
}
.toast {
    background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
    padding: 10px 14px; font-size: 13px; box-shadow: 0 8px 24px rgba(0,0,0,.35);
    opacity: 1; transform: translateY(0); transition: opacity .3s, transform .3s;
}
.toast strong { display: block; margin-bottom: 2px; font-size: 13.5px; }
.toast div { color: var(--muted); }
.toast.out { opacity: 0; transform: translateY(6px); }

/* ---- status pill / dot ---- */
.pill {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600;
    border: 1px solid transparent;
}
.pill .d { width: 8px; height: 8px; border-radius: 50%; }
.st-up      { color: var(--up);       background: rgba(var(--up-rgb),.12);       border-color: rgba(var(--up-rgb),.3); }
.st-down    { color: var(--down);     background: rgba(var(--down-rgb),.12);     border-color: rgba(var(--down-rgb),.3); }
.st-degraded{ color: var(--degraded); background: rgba(var(--degraded-rgb),.12); border-color: rgba(var(--degraded-rgb),.3); }
.st-unknown { color: var(--unknown);  background: rgba(var(--muted-rgb),.14);    border-color: rgba(var(--muted-rgb),.3); }
.st-up .d { background: var(--up); } .st-down .d { background: var(--down); }
.st-degraded .d { background: var(--degraded); } .st-unknown .d { background: var(--unknown); }

/* ---- tables ---- */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; overflow-x: auto; overflow-y: hidden; }
table { width: 100%; min-width: max-content; border-collapse: collapse; }
th, td { text-align: left; padding: 11px 16px; }
th { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .05em; font-weight: 600; background: var(--panel-2); border-bottom: 1px solid var(--line); }
tbody tr { border-top: 1px solid var(--line); }
tbody tr:first-child { border-top: none; }
tbody tr:hover { background: rgba(var(--overlay),.025); }
td.num { text-align: right; font-variant-numeric: tabular-nums; }

/* Sortable headers. The arrow only appears on the active column so the header
   row stays quiet until someone actually sorts. */
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--text); }
th.sortable::after { content: ''; }
th.sorted-asc::after  { content: ' ↑'; opacity: .8; }
th.sorted-desc::after { content: ' ↓'; opacity: .8; }

.loss-val.warn { color: var(--degraded); font-weight: 600; }
.loss-val.bad  { color: var(--down); font-weight: 700; }
td .name { font-weight: 600; color: var(--text); }
td .meta { color: var(--faint); font-size: 12px; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }

.uptime-bar { display: inline-block; width: 54px; height: 6px; border-radius: 3px; background: rgba(var(--overlay),.08); overflow: hidden; vertical-align: middle; margin-right: 8px; }
.uptime-bar > i { display: block; height: 100%; background: var(--up); }
.uptime-bar.warn > i { background: var(--degraded); }
.uptime-bar.bad > i { background: var(--down); }

/* ---- site detail ---- */
.dev-head { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-bottom: 6px; }
.dev-head h1 { margin: 0; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin: 20px 0; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; }
.stat .v { font-size: 1.5rem; font-weight: 700; line-height: 1; }
.stat .k { color: var(--muted); font-size: 12px; margin-top: 6px; }
.stat.warn .v { color: var(--degraded); }
.stat.bad .v { color: var(--down); }

.ranges { display: inline-flex; gap: 4px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 3px; }
.ranges a, .ranges button { color: var(--muted); padding: 4px 12px; border-radius: 6px; font-size: 13px; font-weight: 600; background: transparent; border: none; cursor: pointer; font-family: inherit; }
.ranges a:hover, .ranges button:hover { color: var(--text); text-decoration: none; }
.ranges a.active, .ranges button.active { color: var(--text); background: rgba(var(--link-rgb),.16); }

.chart-empty {
    position: absolute; inset: 0;
    color: var(--faint); font-size: 13px; text-align: center; padding: 0 20px; pointer-events: none;
}
.chart-empty:not([hidden]) { display: flex; align-items: center; justify-content: center; }

.chart-card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 16px; margin-bottom: 16px; }
.chart-card h3 { margin: 0 0 12px; font-size: 14px; color: var(--muted); font-weight: 600; }

/* ---- collapsible section headings ---- */
h2.collapsible { margin-bottom: 10px; }
.collapse-btn {
    display: inline-flex; align-items: center; gap: 8px;
    background: none; border: none; padding: 0; cursor: pointer;
    color: inherit; font: inherit; letter-spacing: inherit; text-transform: inherit;
}
.collapse-btn:hover { opacity: .85; }
.collapse-caret { display: inline-block; transition: transform .15s ease; font-size: .85em; }
h2.collapsed .collapse-caret { transform: rotate(-90deg); }
.collapse-count {
    font-size: 11px; font-weight: 600; color: var(--muted);
    background: rgba(var(--overlay),.08); border-radius: 10px; padding: 1px 8px;
}

/* ---- back to top ---- */
.to-top {
    position: fixed; right: 20px; bottom: 20px; z-index: 900;
    width: 42px; height: 42px; border-radius: 50%;
    background: var(--panel); color: var(--text);
    border: 1px solid var(--line); box-shadow: 0 6px 20px rgba(0,0,0,.45);
    font-size: 18px; line-height: 1; cursor: pointer;
    /* Hidden until it is useful, and never intercepting clicks while hidden. */
    opacity: 0; visibility: hidden; transform: translateY(6px);
    transition: opacity .15s ease, transform .15s ease, visibility .15s;
}
.to-top.show { opacity: .92; visibility: visible; transform: none; }
.to-top:hover { opacity: 1; border-color: var(--link); color: var(--link); }
@media (max-width: 640px) {
    .to-top { right: 14px; bottom: 14px; width: 46px; height: 46px; }
}

/* Chart title plus its source picker on one line, wrapping on narrow screens
   rather than squeezing the select. */
.chart-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; }
.chart-head h3 { margin: 0 0 12px; }
.chart-source { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.chart-source select { width: auto; min-width: 170px; padding: 5px 9px; font-size: 13px; }

.gauge-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin: 20px 0; }
.gauge { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; }
.gauge .lbl { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 12.5px; font-weight: 600; margin-bottom: 8px; }
.gauge .v { font-size: 1.6rem; font-weight: 700; line-height: 1; color: var(--up); margin-bottom: 10px; }
.gauge .v.warn { color: var(--degraded); }
.gauge .v.bad { color: var(--down); }
.gauge-track { height: 6px; border-radius: 3px; background: rgba(var(--overlay),.08); overflow: hidden; }
.gauge-track > i { display: block; height: 100%; background: var(--up); border-radius: 3px; }
.gauge-track.warn > i { background: var(--degraded); }
.gauge-track.bad > i { background: var(--down); }

/* ---- Ubiquiti connected stations ---- */
.section-head {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 16px;
    margin-top: 26px;
    margin-bottom: 10px;
}
.section-head h2 { margin: 0 0 4px; }
.station-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 24px;
    height: 24px;
    margin-left: 5px;
    padding: 0 7px;
    border-radius: 999px;
    background: rgba(var(--accent-rgb), .16);
    color: var(--link);
    font-size: 12px;
    vertical-align: middle;
}
.station-search { width: min(320px, 100%); }
.station-signal { font-weight: 700; }
.station-signal.good { color: var(--up); }
.station-signal.warn { color: var(--degraded); }
.station-signal.bad { color: var(--down); }
.station-row[hidden] { display: none !important; }

.flap-count {
    display: inline-flex; align-items: center; justify-content: center;
    min-width: 22px; padding: 1px 7px; border-radius: 999px; font-size: 12px; font-weight: 700;
    background: rgba(var(--muted-rgb),.15); color: var(--muted);
}
.flap-count.warn { background: rgba(var(--degraded-rgb),.16); color: var(--degraded); }
.flap-count.bad { background: rgba(var(--down-rgb),.16); color: var(--down); }

.info-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 16px; }
.info-grid .k { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--faint); font-weight: 600; margin-bottom: 4px; }
.info-grid .v { font-size: 14px; font-weight: 600; }
.chart { position: relative; height: 240px; }

.back { color: var(--muted); font-size: 13px; }

.empty { text-align: center; color: var(--muted); padding: 48px 24px; }
.empty .big { font-size: 1.1rem; color: var(--text); margin-bottom: 6px; }

.banner { background: rgba(239,68,68,.1); border: 1px solid rgba(239,68,68,.35); color: #fecaca; padding: 12px 16px; border-radius: 10px; margin-bottom: 20px; font-size: 14px; }

.mainnav a.muted-link { color: var(--faint); }
.mainnav a.muted-link:hover { color: var(--text); }

/* ---- buttons ---- */
.btn {
    display: inline-flex; align-items: center; gap: 6px;
    background: var(--panel); color: var(--text);
    border: 1px solid var(--line); border-radius: 8px;
    padding: 8px 14px; font-size: 14px; font-weight: 600; cursor: pointer;
    font-family: inherit; text-decoration: none;
}
.btn:hover { background: var(--panel-hover); text-decoration: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-danger { color: #fecaca; border-color: rgba(239,68,68,.4); background: rgba(239,68,68,.1); }
.btn-danger:hover { background: rgba(239,68,68,.2); }
.btn-sm { padding: 5px 10px; font-size: 12.5px; border-radius: 6px; }
.btn-row { display: flex; gap: 10px; align-items: center; margin-top: 8px; }

.bulk-bar { display: flex; gap: 10px; align-items: center; margin: 10px 0; padding: 10px 14px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; }
.bulk-bar select { margin-left: auto; }
th.chk, td.chk { width: 34px; padding-right: 0; }

/* ---- forms ---- */
.form-card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 20px; margin-bottom: 24px; }
.form-card h2 { margin: 0 0 16px; color: var(--text); text-transform: none; letter-spacing: 0; font-size: 1.1rem; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 18px; }
/* Any explicit display (the flex rules below, grid, etc.) beats the browser's
   built-in [hidden] { display: none }, so hiding a .field via the hidden
   attribute silently did nothing. Global so this cannot bite again. */
[hidden] { display: none !important; }

.transfer-secret-option { margin: 18px 0 6px; }
.transfer-template-form { margin-top: 12px; }
.card ul { line-height: 1.55; }

.field { display: flex; flex-direction: column; gap: 5px; }
.field.wide { grid-column: 1 / -1; }
.field label { font-size: 12.5px; color: var(--muted); font-weight: 600; }
.field .hint { font-size: 11.5px; color: var(--faint); }
.field .err { font-size: 12px; color: #fca5a5; }
input[type=text], input[type=password], input[type=number], input[type=email], input[type=search], select {
    background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
    border-radius: 8px; padding: 9px 11px; font-size: 14px; font-family: inherit; width: 100%;
}
.overview-filters {
    display: flex;
    align-items: flex-end;
    gap: 12px;
    margin: 14px 0;
    flex-wrap: wrap;
}
.device-scope-tabs {
    display: flex;
    align-self: flex-end;
    gap: 6px;
    padding: 4px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 10px;
}
.scope-tab {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 38px;
    padding: 7px 12px;
    border-radius: 7px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 600;
    text-decoration: none;
    white-space: nowrap;
}
.scope-tab:hover {
    color: var(--text);
    background: var(--panel-hover);
    text-decoration: none;
}
.scope-tab.active {
    color: var(--text);
    background: rgba(var(--link-rgb), .16);
    box-shadow: 0 0 0 1px rgba(var(--link-rgb), .45) inset;
}
.scope-tab span {
    min-width: 22px;
    padding: 1px 6px;
    border-radius: 999px;
    background: var(--panel-2);
    color: var(--faint);
    font-size: 11px;
    text-align: center;
}
.scope-tab.active span { color: var(--link); }
.overview-filters label {
    display: block;
    margin-bottom: 5px;
    color: var(--muted);
    font-size: 12.5px;
    font-weight: 600;
}
.search-bar { flex: 1 1 280px; max-width: 420px; margin: 0; }
.type-filter { flex: 0 1 260px; min-width: 210px; }
.filter-clear {
    align-self: center;
    margin-top: 20px;
    font-size: 13px;
    white-space: nowrap;
}
input:focus, select:focus { outline: none; border-color: var(--link); box-shadow: 0 0 0 3px rgba(var(--accent-rgb),.2); }
.field.invalid input, .field.invalid select { border-color: rgba(239,68,68,.6); }
.check { flex-direction: row; align-items: center; gap: 9px; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); }
.check label { color: var(--text); font-weight: 500; }
.org-choice-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.org-choice {
    display: flex; flex-direction: row; align-items: center; gap: 9px;
    padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px;
    background: var(--panel-2); color: var(--text); cursor: pointer;
}
.org-choice input { width: 16px; height: 16px; flex: 0 0 auto; accent-color: var(--accent); }
.stack { display: flex; flex-direction: column; gap: 8px; }
.picklist-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; margin-top: 20px; }
.pick-list { display: flex; flex-direction: column; gap: 10px; }
.pick-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 0;
    border-top: 1px solid rgba(var(--muted-rgb), .12);
}
.pick-item:first-child { border-top: none; }
.pick-item-main { min-width: 0; }
.pick-item-main strong { display: block; font-size: 14px; }
.pick-edit-row {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 0;
    border-top: 1px solid rgba(var(--muted-rgb), .12);
}
.pick-edit-row:first-of-type { border-top: none; }
.pick-edit-fields {
    display: grid;
    grid-template-columns: minmax(0, 1.2fr) minmax(0, .9fr);
    gap: 10px;
    flex: 1;
}
.pick-edit-fields-single { grid-template-columns: 1fr; }
.pick-actions { display: inline-flex; gap: 8px; align-items: center; }
.pick-icon-btn {
    width: 34px;
    min-width: 34px;
    justify-content: center;
    padding: 0;
    font-size: 14px;
}
.pick-dialog {
    border: none;
    padding: 0;
    background: transparent;
}
.pick-dialog::backdrop {
    background: rgba(3, 8, 18, .68);
    backdrop-filter: blur(4px);
}
.pick-dialog-card {
    width: min(460px, calc(100vw - 24px));
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 18px;
    box-shadow: 0 24px 60px rgba(0,0,0,.34);
}
.pick-dialog-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
}
.pick-dialog-head h3 {
    margin: 0;
    font-size: 1rem;
}

/* ---- flash ---- */
.flash { padding: 11px 16px; border-radius: 9px; margin-bottom: 20px; font-size: 14px; font-weight: 500; }
.flash.ok { background: rgba(34,197,94,.12); border: 1px solid rgba(34,197,94,.35); color: #bbf7d0; }
.flash.err { background: rgba(239,68,68,.1); border: 1px solid rgba(239,68,68,.35); color: #fecaca; }

/* ---- table action buttons ---- */
td.actions { text-align: right; white-space: nowrap; }
td.actions form { display: inline; }
td.actions .btn { margin-left: 6px; }
.badge-off { color: var(--faint); font-size: 12px; font-weight: 600; }
.mute-badge { font-size: 12px; margin-left: 4px; opacity: .8; }

/* ---- run-script popup shown straight after adding a device ---- */
.script-modal {
    position: fixed; inset: 0; z-index: 1200;
    background: rgba(0,0,0,.66);
    display: flex; align-items: flex-start; justify-content: center;
    padding: 40px 20px; overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}
.script-modal-box {
    width: 100%; max-width: 980px;
    background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
    box-shadow: 0 24px 70px rgba(0,0,0,.6);
    display: flex; flex-direction: column; max-height: calc(100vh - 80px);
}
.script-modal-head {
    display: flex; align-items: flex-start; justify-content: space-between; gap: 16px;
    padding: 18px 20px 12px; border-bottom: 1px solid var(--line);
}
.script-modal-head h2 { margin: 0 0 2px; font-size: 17px; }
.script-modal-head .sub { margin: 0; font-size: 12.5px; }
/* The script itself is the point of the dialog, so it takes the space and
   scrolls on its own rather than pushing the buttons off screen. */
.script-modal .code {
    margin: 0; flex: 1 1 auto; overflow: auto; border: none; border-radius: 0;
    max-height: none; min-height: 200px;
}
.script-modal-foot {
    display: flex; flex-wrap: wrap; gap: 8px;
    padding: 14px 20px; border-top: 1px solid var(--line);
}
@media (max-width: 640px) {
    .script-modal { padding: 12px; }
    .script-modal-box { max-height: calc(100dvh - 24px); }
    .script-modal-foot .btn { flex: 1 1 auto; justify-content: center; }
}

/* ---- login ---- */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.auth-card { width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 28px; }
.auth-logo { display: block; margin: 0 auto 14px; height: 44px; width: auto; max-width: 100%; }
.auth-card .tag { text-align: center; color: var(--muted); font-size: 13px; margin: 0 0 22px; }
.auth-card .field { margin-bottom: 14px; }
.auth-card .btn-primary { width: 100%; justify-content: center; margin-top: 4px; }
.auth-hint { text-align: center; color: var(--faint); font-size: 12px; margin-top: 18px; }
.auth-hint code { background: var(--panel-2); padding: 2px 6px; border-radius: 4px; }

/* ---- generated-script view ---- */
.script-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin: 26px 0 10px; }
.script-head h2 { margin: 0; text-transform: none; letter-spacing: 0; font-size: 1.05rem; color: var(--text); }
.script-head h2 .hint { font-weight: 400; color: var(--faint); font-size: 13px; }
.script-actions { display: flex; gap: 8px; }
.script-block {
    background: #0b1220; border: 1px solid var(--line); border-radius: 10px;
    padding: 14px 16px; margin: 0; overflow-x: auto; max-height: 460px;
    font: 12.5px/1.6 ui-monospace, "Cascadia Code", Menlo, Consolas, monospace;
    color: #cbd5e1; white-space: pre; -moz-tab-size: 4; tab-size: 4;
}
.btn.copied { color: var(--up); border-color: rgba(34,197,94,.4); }
code { background: var(--panel-2); padding: 1px 5px; border-radius: 4px; font-size: .9em; }

/* ---- Fiber NOC / Infinity Desk theme ------------------------------------- */
html.theme-fiber-noc .topbar {
    background: rgba(24,24,27,.97);
    border-top: 4px solid var(--line);
    border-bottom-color: var(--line);
    box-shadow: 0 8px 24px rgba(0,0,0,.18);
    backdrop-filter: blur(14px);
}
html.theme-fiber-noc .brand-app-name {
    color: #eadff0;
    border-left-color: #514b54;
}
html.theme-fiber-noc h2 {
    color: var(--link);
    letter-spacing: .08em;
}
html.theme-fiber-noc a:not(.btn):hover {
    color: #f06ab9;
}
html.theme-fiber-noc .mainnav a {
    color: #c8bbd0;
    border-radius: 0;
    border-bottom: 3px solid transparent;
}
html.theme-fiber-noc .mainnav a:hover {
    color: #fff;
    background: transparent;
    border-bottom-color: rgba(var(--accent-rgb),.45);
}
html.theme-fiber-noc .mainnav a.active {
    color: #fff;
    background: transparent;
    border-bottom-color: var(--accent);
}
html.theme-fiber-noc .card,
html.theme-fiber-noc .stat,
html.theme-fiber-noc .gauge,
html.theme-fiber-noc .chart-card,
html.theme-fiber-noc .form-card,
html.theme-fiber-noc .auth-card {
    border-color: var(--line);
    box-shadow: 0 12px 30px rgba(0,0,0,.18);
}
html.theme-fiber-noc .summary .tile {
    position: relative;
    overflow: hidden;
    border-color: var(--line);
    box-shadow: 0 8px 22px rgba(0,0,0,.14);
}
html.theme-fiber-noc .summary .tile::before {
    content: "";
    position: absolute;
    inset: 0 0 auto 0;
    width: auto;
    height: 3px;
    background: var(--accent);
}
html.theme-fiber-noc .summary .tile.up::before { background: var(--up); }
html.theme-fiber-noc .summary .tile.degraded::before { background: var(--degraded); }
html.theme-fiber-noc .summary .tile.down::before { background: var(--down); }
html.theme-fiber-noc th {
    background: var(--panel-2);
    color: #d9cddd;
}
html.theme-fiber-noc tbody tr:hover {
    background: rgba(var(--accent-rgb),.055);
}
html.theme-fiber-noc input,
html.theme-fiber-noc select,
html.theme-fiber-noc textarea {
    background: var(--panel-2);
    border-color: var(--line);
}
html.theme-fiber-noc input:focus,
html.theme-fiber-noc select:focus,
html.theme-fiber-noc textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(var(--accent-rgb),.18);
}
html.theme-fiber-noc .btn-primary {
    background: var(--accent);
    border-color: var(--accent);
}
html.theme-fiber-noc .btn-primary:hover {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
}
html.theme-fiber-noc .badge,
html.theme-fiber-noc .role-badge {
    border-color: #4b4650;
}
html.theme-fiber-noc .script-block {
    background: #111014;
    color: #e4dce8;
}

@media (max-width: 900px) {
    .topbar { align-items: flex-start; flex-direction: column; }
    .mainnav { justify-content: flex-start; }
}

@media (max-width: 640px) {
    .summary { grid-template-columns: repeat(2, 1fr); }
    .overview-filters { align-items: stretch; }
    .device-scope-tabs { width: 100%; }
    .scope-tab { flex: 1 1 0; justify-content: center; }
    .search-bar, .type-filter { flex-basis: 100%; max-width: none; width: 100%; }
    .filter-clear { align-self: flex-start; margin-top: 0; }
    .wrap { padding: 16px; }
    .hide-sm { display: none; }
    .form-grid { grid-template-columns: 1fr; }
    .org-choice-grid { grid-template-columns: 1fr; }
    .picklist-grid { grid-template-columns: 1fr; }
    .pick-edit-row { flex-direction: column; }
    .pick-edit-fields { grid-template-columns: 1fr; width: 100%; }
    .topbar { position: static; padding: 12px 16px; }
    .mainnav { width: 100%; }
    .theme-switch { order: 20; margin-left: 0; }
    .alert-panel {
        position: fixed;
        top: 50vh;
        top: 50dvh;
        left: 50%;
        right: auto;
        width: min(320px, calc(100vw - 32px));
        max-height: calc(100vh - 32px);
        max-height: calc(100dvh - 32px);
        padding: 18px 20px;
        overflow-y: auto;
        transform: translate(-50%, -50%);
        z-index: 1001;
        overscroll-behavior: contain;
        -webkit-overflow-scrolling: touch;
        box-shadow: 0 20px 60px rgba(0,0,0,.65);
    }
    .alert-panel-h { font-size: 12px; margin-top: 14px; }
    .alert-panel label { gap: 10px; padding: 7px 2px; font-size: 14px; }
    .alert-panel input[type=checkbox] {
        flex: 0 0 auto;
        width: 18px;
        height: 18px;
    }
    .card {
        max-width: 100%;
        overflow-x: auto;
        overflow-y: visible;
        overscroll-behavior-x: contain;
        -webkit-overflow-scrolling: touch;
        touch-action: pan-x pan-y;
    }
    .card > table { min-width: 660px; }
    .section-head { align-items: stretch; flex-direction: column; }
    .station-search { width: 100%; }
    .station-card { overflow: visible; background: transparent; border: 0; }
    .station-card > .station-table { display: block; min-width: 0; }
    .station-table thead { display: none; }
    .station-table tbody { display: grid; gap: 10px; }
    .station-table tr {
        display: grid;
        grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
        gap: 10px 16px;
        padding: 14px;
        background: var(--panel);
        border: 1px solid var(--line);
        border-radius: 12px;
    }
    .station-table td {
        display: block;
        min-width: 0;
        padding: 0;
        border: 0;
        text-align: left;
        white-space: normal;
        overflow-wrap: anywhere;
    }
    .station-table td:first-child { grid-column: 1 / -1; }
    .station-table td::before {
        content: attr(data-label);
        display: block;
        margin-bottom: 3px;
        color: var(--faint);
        font-size: 10px;
        font-weight: 700;
        letter-spacing: .06em;
        text-transform: uppercase;
    }
}
