:root {
  --ink: #0b2230;
  --sea: #0e3b52;
  --sea-line: #1d5873;
  --fibre: #45c4d6;
  --teal: #0b7a8f;
  --teal-strong: #095f70;
  --paper: #f3f6f8;
  --surface: #ffffff;
  --line: #d3dde3;
  --text: #13232d;
  --muted: #566a76;
  --ok: #13804a;
  --warn: #8f5f00;
  --bad: #b3261e;
  --bad-bg: #fbeceb;
  --focus: #0b7a8f;
  --in: #0b7a8f;
  --out: #b45f00;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #0d1a22;
    --surface: #132430;
    --line: #26404f;
    --text: #e4edf1;
    --muted: #93a8b4;
    --teal: #45c4d6;
    --teal-strong: #7ad8e6;
    --ok: #4cc58a;
    --warn: #e0a93a;
    --bad: #ff8b82;
    --bad-bg: #3a1a1a;
    --focus: #7ad8e6;
    --in: #45c4d6;
    --out: #f0b45a;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 15px/1.5 var(--font); color: var(--text); background: var(--paper); }
h1, h2, h3 { margin: 0; line-height: 1.25; font-weight: 650; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }
p { margin: 0; }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.mono { font-family: var(--mono); font-size: 0.92em; }
.muted { color: var(--muted); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- buttons & fields ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  min-height: 2.35rem; padding: 0.4rem 0.95rem; border-radius: 4px; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); font-weight: 560;
}
.btn:hover { border-color: var(--teal); }
.btn.primary { background: var(--teal); border-color: var(--teal); color: #fff; }
.btn.primary:hover { background: var(--teal-strong); border-color: var(--teal-strong); }
.btn.danger { color: var(--bad); }
.btn.small { min-height: 1.95rem; padding: 0.15rem 0.65rem; font-size: 0.9rem; }
.btn[disabled] { opacity: 0.55; cursor: not-allowed; }
@media (prefers-color-scheme: dark) { .btn.primary { color: #06222b; } }

.field { display: grid; gap: 0.3rem; margin-bottom: 1rem; align-content: start; }
.field label { font-weight: 560; font-size: 0.92rem; }
.field input, .field select {
  min-height: 2.5rem; padding: 0.4rem 0.7rem; border-radius: 4px;
  border: 1px solid var(--line); background: var(--surface); width: 100%;
}
.field .hint { font-size: 0.85rem; color: var(--muted); }
.row { display: flex; gap: 0.6rem; flex-wrap: wrap; align-items: center; }
.row.end { justify-content: flex-end; }
.error { color: var(--bad); background: var(--bad-bg); border-left: 3px solid var(--bad); padding: 0.55rem 0.75rem; margin-bottom: 1rem; border-radius: 0 4px 4px 0; }
.error:empty { display: none; }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); }
.login-art { background: var(--sea); color: #e4f3f7; padding: 3rem 3rem 2rem; display: flex; flex-direction: column; justify-content: space-between; position: relative; overflow: hidden; }
.login-art h1 { font-size: clamp(2rem, 3.4vw, 3rem); letter-spacing: -0.01em; max-width: 14ch; }
.login-art p { color: #a9cdd8; margin-top: 0.6rem; max-width: 34ch; }
.login-art svg { position: absolute; inset: auto 0 0 0; width: 100%; height: 62%; }
.login-art .path { fill: none; stroke: var(--fibre); stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }
.login-art .path.faint { stroke: var(--sea-line); stroke-width: 2; }
.login-art .node { fill: var(--sea); stroke: var(--fibre); stroke-width: 2.5; }
.login-art .label { fill: #8fc4d2; font: 12px var(--mono); }
.login-art .tick { fill: #3ecf8e; }
.login-art .unk { fill: #f0b429; }
.login-form-wrap { display: grid; place-items: center; padding: 2rem; }
.login-form { width: min(380px, 100%); }
.login-form h2 { font-size: 1.4rem; margin-bottom: 0.3rem; }
.login-form .sub { color: var(--muted); margin-bottom: 1.6rem; }
@media (max-width: 800px) {
  .login { grid-template-columns: 1fr; }
  .login-art { padding: 1.6rem; min-height: 200px; }
  .login-art svg { display: none; }
}

/* ---------- shell ---------- */
.shell { min-height: 100vh; display: grid; grid-template-columns: 232px minmax(0, 1fr); }
.side { background: var(--sea); color: #d7ebf1; display: flex; flex-direction: column; padding: 1.1rem 0.8rem; gap: 1.2rem; }
.brand { padding: 0 0.5rem; }
.brand b { display: block; font-size: 1.2rem; letter-spacing: 0.01em; color: #fff; }
.brand span { font-size: 0.85rem; color: #9bc3d0; overflow-wrap: anywhere; }
.nav { display: grid; gap: 0.2rem; }
.nav a { color: inherit; text-decoration: none; padding: 0.5rem 0.7rem; border-radius: 4px; border-left: 3px solid transparent; }
.nav a:hover { background: var(--sea-line); }
.nav a[aria-current="page"] { background: var(--sea-line); border-left-color: var(--fibre); color: #fff; font-weight: 600; }
.side .who { margin-top: auto; padding: 0.7rem 0.5rem 0; border-top: 1px solid var(--sea-line); font-size: 0.88rem; }
.side .who .btn { margin-top: 0.6rem; background: transparent; color: #d7ebf1; border-color: var(--sea-line); width: 100%; }
.side .who .btn:hover { border-color: var(--fibre); }
.side .who .muted { color: #9bc3d0; }
.main { padding: 1.6rem clamp(1rem, 3vw, 2.4rem) 3rem; max-width: 1180px; width: 100%; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.3rem; }
.page-head p { color: var(--muted); margin-top: 0.2rem; }
@media (max-width: 800px) {
  .shell { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto 1fr; }
  .side { display: grid; grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "brand who" "nav nav"; align-items: center; gap: 0.5rem 0.8rem; padding: 0.7rem 0.9rem; }
  .brand { grid-area: brand; padding: 0; display: flex; gap: 0.6rem; align-items: baseline; }
  .side .who { grid-area: who; margin: 0; padding: 0; border: 0; display: flex; align-items: center; gap: 0.6rem; }
  .side .who > div .muted { display: none; }
  .side .who .btn { width: auto; margin: 0; }
  .nav { grid-area: nav; display: flex; gap: 0.2rem; overflow-x: auto; }
  .nav a { white-space: nowrap; }
  .main { padding-top: 1.1rem; }
}

/* ---------- tables ---------- */
td select { min-height: 2rem; padding: 0.15rem 0.5rem; border-radius: 4px; border: 1px solid var(--line); background: var(--surface); }
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 4px; }
table { border-collapse: collapse; width: 100%; min-width: 640px; }
th, td { text-align: left; padding: 0.65rem 0.85rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 0.85rem; color: var(--muted); font-weight: 600; background: color-mix(in srgb, var(--surface) 92%, var(--line)); white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
td.actions { white-space: nowrap; text-align: right; }
td.actions .btn + .btn { margin-left: 0.35rem; }
.empty { padding: 2rem; text-align: center; color: var(--muted); }

/* status: a shape plus a word, never colour alone */
.status { display: inline-flex; align-items: center; gap: 0.4rem; font-weight: 560; }
.status::before { content: ""; width: 0.65rem; height: 0.65rem; border-radius: 50%; background: var(--ok); }
.status.off { color: var(--warn); }
.status.off::before { background: var(--warn); border-radius: 2px; }

/* ---------- dialog ---------- */
dialog { border: 1px solid var(--line); border-radius: 6px; padding: 0; width: min(520px, calc(100vw - 2rem)); background: var(--surface); color: var(--text); }
dialog::backdrop { background: rgba(6, 22, 31, 0.55); }
.dlg-head { padding: 1rem 1.2rem 0.4rem; }
.dlg-body { padding: 0.6rem 1.2rem 1.2rem; }
.dlg-body .row.end { margin-top: 0.4rem; }
.dlg-body p + p, .dlg-body .secret + p { margin-top: 0.5rem; }
.secret { display: flex; gap: 0.6rem; align-items: center; justify-content: space-between; background: var(--paper); border: 1px dashed var(--teal); border-radius: 4px; padding: 0.7rem 0.9rem; margin: 0.8rem 0; }
.secret .mono { font-size: 1.2rem; letter-spacing: 0.04em; user-select: all; }
fieldset { border: 1px solid var(--line); border-radius: 4px; margin: 0 0 1rem; padding: 0.7rem 0.9rem 0.2rem; }
legend { padding: 0 0.3rem; font-weight: 560; font-size: 0.92rem; }
.choice { display: flex; gap: 0.5rem; align-items: center; margin-bottom: 0.7rem; }

/* ---------- overview ---------- */
.roles { display: grid; gap: 0; border: 1px solid var(--line); border-radius: 4px; background: var(--surface); max-width: 760px; }
.roles > div { display: grid; grid-template-columns: 9rem 1fr; gap: 1rem; padding: 0.8rem 1rem; border-bottom: 1px solid var(--line); }
.roles > div:last-child { border-bottom: 0; }
.roles > div.you { border-left: 3px solid var(--teal); background: color-mix(in srgb, var(--surface) 94%, var(--teal)); }
.note { margin-top: 1.4rem; color: var(--muted); max-width: 62ch; }

@media (prefers-reduced-motion: no-preference) {
  .btn { transition: border-color 0.12s, background-color 0.12s; }
}

/* ---------- device & link state: a shape plus a word, never colour alone ---------- */
.state { display: inline-flex; align-items: center; gap: 0.45rem; font-weight: 560; white-space: nowrap; }
.state::before { content: ""; width: 0.65rem; height: 0.65rem; background: var(--muted); }
.state.up { color: var(--ok); }
.state.up::before { background: var(--ok); border-radius: 50%; }
.state.down { color: var(--bad); }
.state.down::before { background: var(--bad); transform: rotate(45deg) scale(0.9); }
.state.unknown { color: var(--muted); }
.state.unknown::before { border-radius: 2px; }

a.strong { font-weight: 650; color: var(--teal-strong); text-decoration: none; }
a.strong:hover { text-decoration: underline; }
a.btn { text-decoration: none; margin-top: 0.8rem; }
.small { font-size: 0.85rem; }
.notice { border-left: 3px solid var(--warn); background: color-mix(in srgb, var(--surface) 90%, var(--warn)); padding: 0.65rem 0.9rem; margin-bottom: 1rem; border-radius: 0 4px 4px 0; max-width: 70ch; }
h2.section { margin: 2rem 0 0.8rem; }

/* ---------- device page ---------- */
.meta { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 0; margin: 0 0 0.4rem; background: var(--surface); border: 1px solid var(--line); border-radius: 4px; }
.meta > div { padding: 0.7rem 0.95rem; border-right: 1px solid var(--line); min-width: 0; }
.meta > div:last-child { border-right: 0; }
.meta dt { font-size: 0.82rem; color: var(--muted); margin-bottom: 0.15rem; }
.meta dd { margin: 0; overflow-wrap: anywhere; }
.picker-tools { margin-bottom: 0.7rem; }
.picker-tools input[type="search"] { min-height: 2.2rem; padding: 0.3rem 0.65rem; border: 1px solid var(--line); border-radius: 4px; background: var(--surface); min-width: 15rem; }
.picker-tools .choice { margin: 0; }
.table-wrap.picker { max-height: 26rem; overflow: auto; }
.table-wrap.picker th { position: sticky; top: 0; z-index: 1; }
.table-wrap.picker table { min-width: 560px; }
.adv { margin: 0 0 1rem; }
.adv summary { cursor: pointer; font-weight: 560; margin-bottom: 0.7rem; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 0 0.8rem; align-items: start; }
.test-result { padding: 0.65rem 0.85rem; border-radius: 4px; margin-bottom: 1rem; border-left: 3px solid var(--muted); background: var(--paper); }
.test-result[hidden] { display: none; }
.test-result.ok { border-left-color: var(--ok); }
.test-result.bad { border-left-color: var(--bad); background: var(--bad-bg); }

/* ---------- graphs ---------- */
.graph-list { display: grid; gap: 1.1rem; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 1320px) { .graph-list.wide { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.graph-card { background: var(--surface); border: 1px solid var(--line); border-radius: 4px; padding: 0.9rem 1rem 1rem; min-width: 0; }
.graph-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 0.8rem; flex-wrap: wrap; margin-bottom: 0.6rem; }
.graph-body { min-height: 12rem; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 4px; overflow: hidden; }
.seg-btn { background: transparent; border: 0; border-right: 1px solid var(--line); padding: 0.28rem 0.8rem; cursor: pointer; min-height: 1.9rem; }
.seg-btn:last-child { border-right: 0; }
.seg-btn[aria-pressed="true"] { background: var(--teal); color: #fff; font-weight: 600; }
@media (prefers-color-scheme: dark) { .seg-btn[aria-pressed="true"] { color: #06222b; } }
.legend { display: flex; gap: 1.1rem; margin-bottom: 0.2rem; font-size: 0.88rem; }
.key::before { content: ""; display: inline-block; width: 1.4rem; height: 0.22rem; margin-right: 0.4rem; vertical-align: middle; border-radius: 2px; }
.key.in::before { background: var(--in); }
.key.out::before { background: var(--out); }
.chart { position: relative; }
.chart-svg { width: 100%; height: auto; display: block; touch-action: pan-y; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .axis { fill: var(--muted); font: 11px var(--font); }
.chart .line { fill: none; stroke-width: 1.7; stroke-linejoin: round; stroke-linecap: round; }
.chart .line.in, .chart .dot.in { stroke: var(--in); }
.chart .line.out, .chart .dot.out { stroke: var(--out); }
.chart .area { stroke: none; opacity: 0.13; }
.chart .area.in { fill: var(--in); }
.chart .area.out { fill: var(--out); }
.chart .dot { fill: var(--surface); stroke-width: 2; }
.chart .cross { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 3; }
.chart .hit { fill: transparent; cursor: crosshair; }
.chart-tip { position: absolute; top: 0.2rem; transform: translateX(-50%); background: var(--ink); color: #eaf5f8; padding: 0.4rem 0.6rem; border-radius: 4px; font-size: 0.85rem; pointer-events: none; white-space: nowrap; z-index: 2; }
.chart-tip[hidden] { display: none; }
.tip-time { color: #9bc3d0; margin-bottom: 0.15rem; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 0.8rem; margin-top: 0.7rem; }
.stat { padding: 0.55rem 0.8rem; border-left: 4px solid var(--line); background: var(--paper); border-radius: 0 4px 4px 0; }
.stat.in { border-left-color: var(--in); }
.stat.out { border-left-color: var(--out); }
.stat-label { font-size: 0.82rem; color: var(--muted); }
.stat-main { font-size: 1.25rem; font-weight: 650; }
