:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #6d6c67;
  --axis: #898781;
  --grid: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --accent: #256abf;
  --accent-soft: #e4effc;
  --on-accent: #ffffff;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --good: #0ca30c;
  --warning: #fab219;
  --critical: #d03b3b;
  --critical-ink: #b52d2d;
  --info: #256abf;
  --warn-wash: #fff6e0;
  --crit-wash: #fdecec;
  --radius: 12px;
  --font: "Segoe UI", Tahoma, system-ui, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #2c2c2a;
    --ink: #f0efec;
    --ink-2: #c3c2b7;
    --muted: #a3a29a;
    --axis: #898781;
    --grid: #2c2c2a;
    --baseline: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --accent: #5598e7;
    --accent-soft: #1b2c42;
    --on-accent: #0b0b0b;
    --series-1: #3987e5;
    --series-2: #d95926;
    --info: #5598e7;
    --critical-ink: #ee8585;
    --warn-wash: #2f2610;
    --crit-wash: #331a1a;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font: 14px/1.5 var(--font);
}

h1, h2, p { margin: 0; }
h1 { font-size: 18px; font-weight: 700; line-height: 1.25; }
h2 { font-size: 15px; font-weight: 600; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; }
ul { margin: 0; padding: 0; list-style: none; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

.sprite { position: absolute; width: 0; height: 0; }
.icon { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.muted { color: var(--muted); }
.num { font-variant-numeric: tabular-nums; unicode-bidi: isolate; direction: ltr; }
.sub { display: block; color: var(--muted); font-size: 12px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

/* top bar */
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5; }
.topbar-inner { max-width: 1360px; margin: 0 auto; padding: 12px 24px 8px; display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-icon { width: 32px; height: 32px; padding: 6px; border-radius: 9px; background: var(--accent); color: var(--on-accent); stroke-width: 2; }
.brand p { font-size: 12px; }
.status-area { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; justify-content: flex-end; font-size: 12px; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; background: var(--surface-2); font-weight: 600; white-space: nowrap; }
.pill .icon { width: 15px; height: 15px; }

.tabs { max-width: 1360px; margin: 0 auto; padding: 0 16px; display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; }
.tab { padding: 10px 12px; background: none; border: 0; border-bottom: 2px solid transparent; color: var(--ink-2); white-space: nowrap; font-weight: 500; min-height: 44px; }
.tab:hover { color: var(--ink); }
.tab[aria-selected="true"] { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.count { display: inline-block; min-width: 20px; padding: 0 6px; margin-inline-start: 4px; border-radius: 999px; background: var(--crit-wash); color: var(--critical-ink); font-size: 12px; font-weight: 700; text-align: center; }

/* banner */
.banner { padding: 10px 24px; font-size: 13px; text-align: center; background: var(--accent-soft); }
.banner.error { background: var(--crit-wash); color: var(--critical-ink); font-weight: 600; }

main { max-width: 1360px; margin: 0 auto; padding: 20px 24px 48px; }
.view:focus { outline: none; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 16px 8px; flex-wrap: wrap; }

/* overview */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 12px; margin-bottom: 12px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; min-width: 0; }
.tile-label { color: var(--ink-2); font-size: 13px; }
.tile-value { font-size: 28px; font-weight: 700; line-height: 1.3; margin-top: 2px; }
.tile-value small { font-size: 14px; font-weight: 500; color: var(--ink-2); }
.tile-note { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 4px; min-height: 18px; }
.tile-note .icon { width: 14px; height: 14px; }

.overview-grid { display: grid; grid-template-columns: minmax(0, 2.1fr) minmax(300px, 1fr); gap: 12px; align-items: start; }
.side-stack { display: grid; gap: 12px; }
.chart-card { min-width: 0; }

.segmented { display: inline-flex; padding: 2px; border-radius: 9px; background: var(--surface-2); flex-wrap: wrap; }
.card-head .segmented { flex-wrap: nowrap; }
.segmented button { border: 0; background: none; padding: 4px 12px; border-radius: 7px; min-height: 32px; color: var(--ink-2); white-space: nowrap; }
.segmented button:hover { color: var(--ink); }
.segmented button[aria-pressed="true"] { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: 0 0 0 1px var(--border); }

.legend { display: flex; gap: 16px; padding: 0 16px; min-height: 20px; font-size: 12px; color: var(--ink-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 16px; height: 2px; border-radius: 1px; display: inline-block; }
.key-1 { background: var(--series-1); }
.key-2 { background: var(--series-2); }

.chart { position: relative; padding: 4px 8px 4px; min-height: 268px; transition: opacity .15s; }
.chart.loading { opacity: .55; }
.chart svg { display: block; width: 100%; height: 260px; direction: ltr; } /* time runs left to right, and text-anchor follows direction */
.chart svg:focus-visible { outline-offset: -2px; }
.chart text { font: 11px var(--font); fill: var(--axis); font-variant-numeric: tabular-nums; }
.chart text.end-label { fill: var(--ink-2); font-weight: 600; }
.grid-line { stroke: var(--grid); stroke-width: 1; }
.base-line { stroke: var(--baseline); stroke-width: 1; }
.series { fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.series-1 { stroke: var(--series-1); }
.series-2 { stroke: var(--series-2); }
.area-1 { fill: var(--series-1); opacity: .08; }
.cross { stroke: var(--axis); stroke-width: 1; }
.dot { stroke: var(--surface); stroke-width: 2; }
.dot-1 { fill: var(--series-1); }
.dot-2 { fill: var(--series-2); }
.empty-chart { display: flex; align-items: center; justify-content: center; height: 260px; color: var(--muted); text-align: center; padding: 0 24px; }

.tooltip { position: absolute; top: 12px; pointer-events: none; min-width: 148px; padding: 8px 10px; background: var(--surface); border: 1px solid var(--border); border-radius: 9px; box-shadow: 0 4px 16px rgba(0, 0, 0, .14); font-size: 12px; z-index: 2; }
.tooltip-time { color: var(--muted); margin-bottom: 4px; }
.tooltip-row { display: flex; align-items: center; gap: 8px; }
.tooltip-row i { width: 12px; height: 2px; border-radius: 1px; flex: none; }
.tooltip-row b { font-weight: 700; font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: isolate; }
.tooltip-row span { color: var(--ink-2); margin-inline-start: auto; }

.chart-table { padding: 2px 16px 12px; font-size: 13px; }
.chart-table summary { cursor: pointer; color: var(--ink-2); padding: 6px 0; width: fit-content; }
.table-scroll { max-height: 260px; overflow: auto; border: 1px solid var(--border); border-radius: 8px; }
.plain { width: 100%; border-collapse: collapse; font-size: 12px; }
.plain th, .plain td { padding: 5px 10px; text-align: start; border-bottom: 1px solid var(--grid); }
.plain th { position: sticky; top: 0; background: var(--surface-2); font-weight: 600; }

/* compact rows */
.rows { padding: 0 8px 8px; }
.rows > li { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 8px; min-width: 0; }
.rows > li + li { border-top: 1px solid var(--grid); border-radius: 0; }
.rows .row-main { min-width: 0; flex: 1; }
.rows .row-title { overflow-wrap: anywhere; }
.row-end { margin-inline-start: auto; white-space: nowrap; font-size: 13px; }
.sev { display: inline-flex; flex: none; }
.sev-good { color: var(--good); }
.sev-warning { color: var(--warning); }
.sev-critical { color: var(--critical); }
.sev-info { color: var(--info); }
.none { color: var(--muted); padding: 14px 8px !important; }

.bar { height: 4px; border-radius: 2px; background: var(--surface-2); margin-top: 4px; overflow: hidden; }
.bar i { display: block; height: 100%; border-radius: 2px; background: var(--series-1); }

/* toolbars and tables */
.toolbar { display: flex; align-items: center; flex-wrap: wrap; gap: 10px 12px; margin-bottom: 12px; }
.search { display: flex; align-items: center; gap: 8px; flex: 1 1 260px; max-width: 420px; padding: 0 10px; background: var(--surface); border: 1px solid var(--border); border-radius: 9px; color: var(--muted); }
.search:focus-within { outline: 2px solid var(--accent); outline-offset: 1px; }
.search input { flex: 1; min-width: 0; border: 0; outline: 0; background: none; padding: 7px 0; min-height: 36px; color: var(--ink); }
.select-label { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--ink-2); }
select { padding: 6px 8px; min-height: 36px; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; color: var(--ink); }

.table-card { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; }
.data th { padding: 10px 12px; text-align: start; font-size: 12px; font-weight: 600; color: var(--ink-2); border-bottom: 1px solid var(--baseline); white-space: nowrap; }
.data td { padding: 10px 12px; border-bottom: 1px solid var(--grid); vertical-align: middle; }
.data tbody tr:last-child td { border-bottom: 0; }
.data tbody tr:hover { background: var(--surface-2); }
.data tr.is-down { background: var(--crit-wash); }
.data tr.is-blocked { color: var(--muted); }
.cell-name { display: flex; align-items: center; gap: 10px; min-width: 160px; }
.cell-name .icon { color: var(--ink-2); }
.cell-name b { font-weight: 600; overflow-wrap: anywhere; }
.nowrap { white-space: nowrap; }
.status { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; font-weight: 500; }
.status .icon { width: 16px; height: 16px; }
.tag { display: inline-block; padding: 0 7px; border-radius: 999px; background: var(--surface-2); color: var(--ink-2); font-size: 11px; font-weight: 500; margin-inline-start: 6px; }
.tag-warn { background: var(--warn-wash); }
.sig-weak { color: var(--critical-ink); font-weight: 600; }

.actions { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 5px 10px; min-height: 34px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); white-space: nowrap; font-size: 13px; }
.btn .icon { width: 15px; height: 15px; }
.btn:hover:not(:disabled) { background: var(--surface-2); }
.btn:disabled { opacity: .45; }
.btn-on { background: var(--accent-soft); border-color: var(--accent); }
.btn-danger-text { color: var(--critical-ink); }
.btn-danger { background: var(--critical); border-color: var(--critical); color: #fff; font-weight: 600; }
.btn-danger:hover:not(:disabled) { background: #b52d2d; }

.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 600; }
.btn-primary:hover:not(:disabled) { background: var(--accent); opacity: .9; }

.alert-rows { padding: 4px 8px 8px; }
.alert-rows .row-end { color: var(--muted); font-size: 12px; }

/* router */
.router-grid { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); gap: 12px; margin-bottom: 12px; }
.router-sub { font-size: 12px; }
.router-warnings { margin-bottom: 12px; padding-top: 8px; }
.router-note { margin-bottom: 8px; font-size: 13px; }
.meters { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 12px 16px; padding: 4px 16px 16px; }
.meter-label { color: var(--ink-2); font-size: 12px; }
.meter-value { font-size: 20px; font-weight: 700; line-height: 1.35; display: flex; align-items: center; gap: 4px; }
.meter-value .icon { width: 15px; height: 15px; }
.meter-note { color: var(--muted); font-size: 12px; }
.bar i.is-high { background: var(--critical); }
.wan-rates { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; padding: 4px 16px 8px; }
.wan-details { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 2px 12px; padding: 0 16px 14px; font-size: 13px; }
.wan-details dt { color: var(--muted); }
.wan-details dd { margin: 0; overflow-wrap: anywhere; }
.wan-none { padding: 0 16px 14px; font-size: 13px; }
.log-rows > li { align-items: flex-start; }
.log-rows .row-end { color: var(--muted); font-size: 12px; }
.rule-match { direction: ltr; unicode-bidi: isolate; text-align: start; overflow-wrap: anywhere; display: block; color: var(--muted); font-size: 12px; }
.fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-top: 14px; }
.field { display: grid; gap: 4px; font-size: 13px; color: var(--ink-2); }
.field input, .field select, .field textarea { width: 100%; min-height: 40px; padding: 6px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--ink); font-variant-numeric: tabular-nums; }
.field input[dir="ltr"] { text-align: left; }
.field textarea { min-height: 72px; resize: vertical; }
.check { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--ink-2); }
.check input { width: 18px; height: 18px; }

/* the screens before the panel */
.gate { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.gate-card { width: min(420px, 100%); padding: 24px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; }
.gate-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; }
.stack { display: grid; gap: 12px; }
.stack .btn { min-height: 44px; }
.form-error { color: var(--critical-ink); font-weight: 600; font-size: 13px; }
.form-note { color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }

/* the service's own pages */
.icon-btn { padding: 5px; min-width: 34px; }
.status-area select { min-height: 30px; max-width: 200px; padding: 2px 8px; }
.toolbar-title { flex: 1 1 200px; min-width: 0; }
.toolbar .btn-primary { min-height: 38px; }
.empty-card { padding: 28px 20px; text-align: center; color: var(--ink-2); }
.tenants-table { margin-bottom: 12px; }
.account-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(290px, 1fr)); gap: 12px; margin-bottom: 12px; align-items: start; }
.card-body { padding: 0 16px 16px; }
.card-text { color: var(--ink-2); margin-bottom: 12px; }
.dialog-section { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--grid); }
.dialog-section .rows { padding: 0; }
.dialog-section .rows > li { padding: 8px 0; flex-wrap: wrap; }
.dialog-section .actions { width: auto; }
.fields-one { display: grid; gap: 12px; margin-top: 14px; }
.inline-form { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 8px; align-items: end; margin-top: 10px; }
.inline-form .btn { min-height: 40px; }
.inline-form .form-error { grid-column: 1 / -1; }
dialog.wide { width: min(720px, calc(100vw - 32px)); }
.steps { margin: 8px 0 12px; padding-inline-start: 22px; color: var(--ink-2); }
.steps li + li { margin-top: 2px; }
.script-box { direction: ltr; text-align: left; max-height: 220px; overflow: auto; margin: 0; padding: 10px 12px; background: var(--surface-2); border-radius: 8px; font: 12px/1.5 Consolas, "Courier New", monospace; white-space: pre; user-select: all; }
.link-box { white-space: pre-wrap; word-break: break-all; }
.dialog-note { margin-top: 10px; }
details.more { margin-top: 12px; font-size: 13px; color: var(--ink-2); }
details.more summary { cursor: pointer; padding: 4px 0; width: fit-content; }
details.more ul { list-style: disc; padding-inline-start: 22px; }
.script-status { display: flex; align-items: flex-start; gap: 6px; margin-top: 12px; font-weight: 600; font-size: 13px; }
.script-status .icon { width: 16px; height: 16px; }
.mfa-qr { display: block; width: 200px; height: 200px; margin: 12px auto; padding: 8px; background: #fff; border-radius: 8px; }
.mfa-secret { display: block; direction: ltr; text-align: center; font: 13px Consolas, "Courier New", monospace; overflow-wrap: anywhere; color: var(--ink-2); }

dialog { width: min(440px, calc(100vw - 32px)); padding: 20px; border: 1px solid var(--border); border-radius: 14px; background: var(--surface); color: var(--ink); }
dialog::backdrop { background: rgba(0, 0, 0, .45); }
dialog h2 { font-size: 17px; margin-bottom: 8px; overflow-wrap: anywhere; }
dialog p { color: var(--ink-2); }
.dialog-actions { display: flex; justify-content: flex-start; gap: 8px; margin-top: 18px; }
.dialog-actions .btn { min-height: 40px; padding: 6px 16px; }

.toast { position: fixed; bottom: 20px; inset-inline-start: 50%; transform: translateX(50%); max-width: calc(100vw - 32px); padding: 10px 16px; border-radius: 10px; background: var(--ink); color: var(--surface); font-weight: 500; box-shadow: 0 6px 24px rgba(0, 0, 0, .25); z-index: 20; }
.toast.error { background: var(--critical); color: #fff; }

@media (max-width: 1040px) {
  .overview-grid, .router-grid { grid-template-columns: minmax(0, 1fr); }
  .side-stack { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
}

@media (max-width: 760px) {
  .topbar { position: static; }
  .topbar-inner { padding: 10px 16px 6px; }
  .tabs { padding: 0 8px; gap: 0; }
  .tab { padding-inline: 8px; }
  main { padding: 14px 16px 40px; }
  .banner { padding: 8px 16px; }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .tile { padding: 12px; }
  .tile-value { font-size: 22px; }
  .search { max-width: none; flex-basis: 100%; }
  .segmented { width: 100%; }
  .segmented button { flex: 1; min-height: 40px; }
  .card-head .segmented { width: auto; }
  .btn { min-height: 44px; padding-inline: 12px; }
  select { min-height: 44px; }
  .status-area select { min-height: 40px; max-width: 150px; }
  .icon-btn { min-width: 40px; min-height: 40px; }
  .inline-form { grid-template-columns: minmax(0, 1fr); }

  /* tables become cards */
  .table-card { background: none; border: 0; overflow: visible; }
  table.data, .data tbody { display: block; }
  .data thead { display: none; }
  .data tbody tr { display: block; padding: 12px; margin-bottom: 8px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
  .data tbody tr:hover { background: var(--surface); }
  .data tbody tr.is-down, .data tbody tr.is-down:hover { background: var(--crit-wash); }
  .data td { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; padding: 4px 0; border: 0; }
  .data td[data-label]::before { content: attr(data-label); color: var(--muted); font-size: 12px; flex: none; }
  .data td.cell-title { padding-bottom: 8px; }
  .data td.cell-title::before { content: none; }
  .data td .cell-name { min-width: 0; }
  .data td.cell-actions { padding-top: 10px; }
  .actions { justify-content: stretch; width: 100%; }
  .actions .btn { flex: 1; }
  .data td .none-cell { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

@media (forced-colors: active) {
  .series-1 { stroke: CanvasText; }
  .series-2 { stroke: CanvasText; stroke-dasharray: 6 4; }
}
