:root {
  color-scheme: dark;
  --bg: #0b1018;
  --header: #0e1622;
  --surface: #121b28;
  --surface-raised: #172234;
  --surface-muted: #0f1723;
  --surface-strong: #0d1725;
  --input: #0d1520;
  --code: #070b11;
  --text: #e8eef7;
  --muted: #98a9be;
  --border: #2a3b52;
  --primary: #35b9d5;
  --primary-strong: #1b92b1;
  --accent: #73d596;
  --success: #4fd181;
  --warning: #f5bd4f;
  --danger: #ff7777;
  --radius: 8px;
  --shadow: 0 12px 28px rgb(0 0 0 / 14%);
}

.header-link { color: var(--muted); font-weight: 700; text-decoration: none; }
.header-link:hover { color: var(--accent); }
.filter-bar { display: grid; grid-template-columns: minmax(180px, 1fr) 180px 180px auto auto; gap: 10px; align-items: end; margin-bottom: 16px; }
.filter-bar label { margin: 0; }
.event-list, .rule-list { display: grid; gap: 8px; }
.event-item { display: grid; grid-template-columns: 4px minmax(0, 1fr) auto; gap: 14px; align-items: center; padding: 14px; border: 1px solid var(--border); background: var(--surface); border-radius: 6px; }
.event-item__marker { width: 4px; align-self: stretch; border-radius: 3px; background: var(--accent); }
.event-item--warning .event-item__marker { background: var(--warning); }
.event-item--critical .event-item__marker { background: var(--danger); }
.event-item__heading, .rule-row, .event-item__actions, .inline-fields { display: flex; align-items: center; gap: 10px; }
.event-item__heading { justify-content: space-between; }
.event-item p { margin: 4px 0; }
.event-item small, .rule-row small { color: var(--muted); display: block; }
.event-item__actions { justify-content: flex-end; }
.operations-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.operations-panel { min-height: 360px; }
.rule-row { justify-content: space-between; padding: 10px 0; border-bottom: 1px solid var(--border); }
.template-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.compact-card { padding: 16px; }
.compact-card h3 { margin-top: 0; }
.icon-button--danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 50%, var(--border)); }
@media (max-width: 860px) {
  .filter-bar, .operations-grid, .template-grid { grid-template-columns: 1fr; }
  .event-item { grid-template-columns: 4px minmax(0, 1fr); }
  .event-item__actions { grid-column: 2; justify-content: flex-start; }
  .inline-fields { align-items: stretch; flex-direction: column; }
}

html[data-theme="light"] {
  color-scheme: light;
  --bg: #f3f6fa;
  --header: #ffffff;
  --surface: #ffffff;
  --surface-raised: #eef4f8;
  --surface-muted: #f7f9fc;
  --surface-strong: #edf3f8;
  --input: #ffffff;
  --code: #eef3f7;
  --text: #162235;
  --muted: #5d6f84;
  --border: #cbd6e2;
  --primary: #087f9d;
  --primary-strong: #087f9d;
  --accent: #278f59;
  --success: #18864b;
  --warning: #a76600;
  --danger: #c33b45;
  --shadow: 0 8px 22px rgb(35 55 80 / 8%);
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; background: var(--bg); color: var(--text); font-family: Inter, "Segoe UI", system-ui, sans-serif; line-height: 1.5; }
a { color: var(--primary); text-underline-offset: 3px; }
h1, h2, h3, p { margin-top: 0; }
h1 { font-size: 30px; line-height: 1.18; margin-bottom: 8px; letter-spacing: 0; }
h2 { font-size: 18px; line-height: 1.3; margin-bottom: 16px; letter-spacing: 0; }

.app-header { height: 62px; background: var(--header); border-bottom: 1px solid var(--border); }
.app-header__content, .page { width: min(1220px, calc(100% - 32px)); margin: 0 auto; }
.app-header__content { height: 100%; display: flex; align-items: center; justify-content: space-between; }
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; font-size: 17px; font-weight: 700; }
.brand__mark { display: grid; place-items: center; width: 30px; height: 30px; border: 1px solid #32738b; border-radius: 7px; color: #9ae9f6; background: #123143; font-size: 14px; }
.app-header__actions { display: flex; align-items: center; gap: 12px; }
.app-header__meta { color: var(--muted); font-size: 13px; }
.theme-toggle { font-size: 17px; }
.page { padding: 30px 0 48px; }
.page--narrow { width: min(520px, calc(100% - 32px)); padding-top: 62px; }
.eyebrow, .muted { color: var(--muted); }
.eyebrow { margin-bottom: 5px; font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; }
.page-heading { display: flex; gap: 20px; align-items: flex-start; justify-content: space-between; margin-bottom: 24px; }
.page-heading__description { color: var(--muted); margin: 0; }
.back-link { display: inline-block; margin-bottom: 18px; font-weight: 600; text-decoration: none; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.card--wide { grid-column: 1 / -1; }
.card__heading { display: flex; align-items: start; justify-content: space-between; gap: 12px; }
.card--form { padding: 28px; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(265px, 1fr)); grid-auto-flow: dense; gap: 14px; align-items: start; }
.stack { display: grid; gap: 16px; }
.section { margin-top: 26px; }
.toolbar, .bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.toolbar__actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.metric { display: grid; gap: 3px; padding: 11px 0; border-bottom: 1px solid rgb(42 59 82 / 70%); }
.metric:last-child { border-bottom: 0; padding-bottom: 0; }
.metric__label { color: var(--muted); font-size: 13px; }
.metric__value { font-size: 18px; font-weight: 700; overflow-wrap: anywhere; }
.panel-list { margin: 0; padding: 0; list-style: none; display: grid; gap: 9px; }
.panel-list li { border-left: 3px solid #2e6077; padding: 7px 9px; background: var(--surface-muted); border-radius: 0 5px 5px 0; overflow-wrap: anywhere; }

.button, button { appearance: none; min-height: 32px; border: 1px solid transparent; border-radius: 5px; padding: 5px 10px; background: var(--primary-strong); color: #f4fbff; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 6px; width: auto; font: inherit; font-size: 13px; font-weight: 700; line-height: 1.2; text-decoration: none; transition: background-color .15s ease, border-color .15s ease, color .15s ease, transform .15s ease; }
[hidden] { display: none !important; }
.button:hover, button:hover { background: var(--primary); color: #041116; }
.button:active, button:active { transform: translateY(1px); }
.button:focus-visible, button:focus-visible { outline: 2px solid rgb(53 185 213 / 45%); outline-offset: 2px; }
.button--secondary { background: transparent; border-color: #3a5c76; color: #bceaf3; }

.topology-editor { display: grid; gap: 10px; }
.topology-row { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-raised); }
.topology-row > summary { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 13px 14px; cursor: pointer; list-style: none; }
.topology-row > summary::-webkit-details-marker { display: none; }
.topology-row > summary span:first-child { display: grid; gap: 3px; min-width: 0; }
.topology-row > summary small { color: var(--muted); overflow-wrap: anywhere; }
.topology-row__body { padding: 14px; border-top: 1px solid var(--border); }
.topology-delete { padding: 0 14px 14px; }
.topology-row--new { border-style: dashed; }
.button--secondary:hover { background: #173344; }
.button--danger { background: transparent; border-color: #7d353d; color: var(--danger); }
.button--danger:hover { background: #48252a; color: #ffb3b3; }
.button--small { min-height: 28px; padding: 4px 8px; font-size: 12px; }
.icon-button { width: 32px; min-width: 32px; height: 32px; min-height: 32px; padding: 0; border-radius: 5px; background: transparent; border-color: var(--border); color: var(--muted); font-size: 15px; }
.icon-button:hover { background: #253044; color: var(--text); }
.icon-button--danger:hover { border-color: #7d353d; background: #48252a; color: var(--danger); }
form { margin: 0; }
.form-stack { display: grid; gap: 15px; }
.form-stack > button { justify-self: start; }
.control-form { display: grid; gap: 12px; margin-top: 18px; }
.control-form--diagnostics { margin-top: 0; }
.control-subsection { margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--border); }
.control-subsection__title { margin: 0 0 10px; color: var(--muted); font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; }
.control-form label + .button-row { margin-top: 8px; }
.button-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 6px; padding-top: 2px; }
.risk-badge { display: inline-flex; align-items: center; border: 1px solid #56462a; border-radius: 999px; padding: 4px 9px; color: var(--warning); background: rgb(75 61 30 / 35%); font-size: 12px; font-weight: 700; }
.risk-badge--readonly { border-color: #2a5361; color: var(--primary); background: rgb(28 74 89 / 35%); }
.risk-badge--safe { border-color: #2c6143; color: var(--success); background: rgb(23 65 42 / 35%); }
.risk-badge--danger { border-color: #7d353d; color: var(--danger); background: rgb(92 33 42 / 35%); }
label { display: grid; gap: 6px; color: var(--muted); font-size: 14px; font-weight: 650; }
input, select, textarea { width: 100%; min-width: 0; max-width: 100%; min-height: 40px; border: 1px solid var(--border); border-radius: 6px; padding: 8px 10px; background: var(--input); color: var(--text); font: inherit; }
input:focus, select:focus, textarea:focus { outline: 3px solid rgb(53 185 213 / 20%); border-color: var(--primary); }
input[type="checkbox"], input[type="radio"] { flex: 0 0 auto; width: 16px; height: 16px; min-height: 16px; margin: 0; padding: 0; accent-color: var(--primary); }
.checkbox-row, .choice { display: inline-flex; align-items: center; gap: 7px; width: fit-content; color: var(--text); }
fieldset { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 0; padding: 10px 12px; border: 1px solid var(--border); border-radius: 6px; }
legend { padding: 0 5px; color: var(--muted); font-size: 12px; font-weight: 700; }

.status { display: inline-flex; align-items: center; gap: 6px; border-radius: 999px; padding: 4px 9px; font-size: 12px; font-weight: 750; background: #233042; color: #b4c4d7; text-transform: uppercase; letter-spacing: .03em; }
.status::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; box-shadow: 0 0 0 3px rgb(255 255 255 / 4%); }
.status--online, .status--success, .status--done { background: #163c2b; color: var(--success); }
.status--offline, .status--expired, .status--failed { background: #48252a; color: var(--danger); }
.status--queued, .status--sent, .status--running { background: #4b3d1e; color: var(--warning); }
.status--provisioned { background: #173b4a; color: var(--primary); }
.device-meta { color: var(--muted); margin: 0; overflow-wrap: anywhere; }
.device-meta__separator { padding: 0 5px; color: #4e657d; }

dl { margin: 0; display: grid; grid-template-columns: minmax(100px, .8fr) minmax(0, 1.2fr); gap: 9px 12px; }
dt { color: var(--muted); }
dd { margin: 0; font-weight: 650; overflow-wrap: anywhere; }
ul { margin: 0 0 16px; padding-left: 20px; }
.card form { margin-top: 14px; }
.card form + form { padding-top: 14px; border-top: 1px solid var(--border); }
.sub-list { display: grid; gap: 6px; margin-top: 10px; }
.sub-list__item { display: grid; gap: 2px; padding: 8px 10px; border-radius: 6px; background: rgb(16 24 36 / 85%); }
.empty-inline { color: var(--muted); padding: 8px 0; }
.control-form--columns { grid-template-columns: repeat(3, minmax(0, 1fr)); align-items: end; padding-top: 16px; border-top: 1px solid var(--border); }
.control-form__actions { grid-column: 1 / -1; }
.form-grid, .settings-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.form-grid__wide { grid-column: 1 / -1; }
[data-wan-fields][hidden] { display: none; }
.settings-grid { margin-top: 20px; padding-top: 20px; border-top: 1px solid var(--border); align-items: start; }
.service-grid { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 14px; }
.service-pill { padding: 5px 8px; border: 1px solid var(--border); border-radius: 5px; color: var(--muted); font-size: 12px; }
.service-pill--running { color: var(--success); border-color: #2c6143; }
.service-pill--stopped { color: var(--danger); border-color: #7d353d; }
.metric__value--small { font-size: 15px; font-weight: 600; }

.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
table { border-collapse: collapse; width: 100%; min-width: 720px; }
th, td { border-bottom: 1px solid var(--border); padding: 13px 14px; text-align: left; vertical-align: middle; }
th { color: #a8bed4; background: var(--surface-muted); font-size: 12px; font-weight: 750; text-transform: uppercase; letter-spacing: .04em; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #172638; }
td a { font-weight: 700; text-decoration: none; }
code, pre { font-family: "Cascadia Code", Consolas, monospace; font-size: 12px; }
pre { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.raw-telemetry { max-height: 420px; overflow: auto; background: var(--code); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.empty-state { padding: 28px; text-align: center; color: var(--muted); }
.notice { border-left: 4px solid var(--primary); background: #102735; padding: 12px 14px; border-radius: 0 6px 6px 0; }
.error { color: var(--danger); }

.page--device { width: min(1480px, calc(100% - 32px)); }
.device-layout { display: grid; grid-template-columns: 230px minmax(0, 1fr); gap: 30px; align-items: start; }
.device-sidebar { position: sticky; top: 20px; display: grid; gap: 18px; }
.device-sidebar__back { color: var(--muted); font-size: 13px; font-weight: 650; text-decoration: none; }
.device-sidebar__identity { display: flex; align-items: center; gap: 11px; min-width: 0; padding: 0 4px; }
.device-sidebar__identity div { display: grid; min-width: 0; }
.device-sidebar__identity strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.device-sidebar__identity span { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.device-sidebar__icon, .router-card__icon { display: grid; place-items: center; width: 38px; height: 38px; flex: 0 0 auto; border: 1px solid #32738b; border-radius: 7px; background: #123143; color: #9ae9f6; font-weight: 800; }
.device-nav { display: grid; gap: 4px; }
.device-nav__group { margin: 10px 12px 2px; color: #6f91ad; font-size: 10px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.device-nav__group:first-child { margin-top: 0; }
.device-nav__item { display: grid; gap: 1px; padding: 10px 12px; border-left: 3px solid transparent; border-radius: 0 6px 6px 0; color: var(--text); text-decoration: none; }
.device-nav__item span { font-size: 14px; font-weight: 720; }
.device-nav__item small { color: var(--muted); font-size: 11px; }
.device-nav__item:hover { background: #111d2b; }
.device-nav__item.is-active { border-left-color: var(--primary); background: #142534; color: #a4edf7; }
.device-content { min-width: 0; }
.device-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; margin-bottom: 24px; padding-bottom: 19px; border-bottom: 1px solid var(--border); }
.device-header__title-row { display: flex; align-items: center; gap: 12px; }
