:root {
  --ground: #e6eaee;
  --surface: #f6f8fa;
  --raised: #ffffff;
  --ink: #15202b;
  --ink-2: #485562;
  --ink-3: #56616c;
  --line: #cbd3db;
  --line-soft: #dde3e8;
  --signal: #07684f;
  --signal-soft: #d2eee5;
  --cobalt: #2743c7;
  --cobalt-hover: #1f37a8;
  --on-cobalt: #ffffff;
  --amber: #7a5100;
  --amber-soft: #fbefd2;
  --danger: #b42318;
  --danger-soft: #fde4e1;
  --focus: #2743c7;

  --font-ui: "Schibsted Grotesk", "Segoe UI", system-ui, sans-serif;
  --font-code: "Martian Mono", ui-monospace, "SFMono-Regular", Consolas, monospace;

  --r-control: 6px;
  --r-panel: 10px;
  --shadow-dialog: 0 24px 60px rgba(21, 32, 43, 0.22);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --ground: #0e1318;
    --surface: #141a21;
    --raised: #1a222b;
    --ink: #e2e8ee;
    --ink-2: #a3aeb9;
    --ink-3: #939fa9;
    --line: #2b3540;
    --line-soft: #222b34;
    --signal: #3ccaa2;
    --signal-soft: #12352c;
    --cobalt: #8ea2ff;
    --cobalt-hover: #aab9ff;
    --on-cobalt: #0e1318;
    --amber: #e6b54a;
    --amber-soft: #392d12;
    --danger: #f2766b;
    --danger-soft: #3c1b18;
    --focus: #8ea2ff;
    --shadow-dialog: 0 24px 60px rgba(0, 0, 0, 0.55);
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }

html, body { margin: 0; }

body {
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--ground);
  -webkit-font-smoothing: antialiased;
}

[hidden] { display: none !important; }

a { color: var(--cobalt); text-underline-offset: 3px; }

code, .code { font-family: var(--font-code); font-size: 0.8em; letter-spacing: -0.01em; }

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

h1, h2, h3 { margin: 0; line-height: 1.2; font-weight: 650; letter-spacing: -0.015em; }
h1 { font-size: 1.75rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0; }

.muted { color: var(--ink-2); }
.faint { color: var(--ink-3); font-size: 0.87rem; }

/* ---------- Controls ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.45rem;
  min-height: 38px; padding: 0 0.95rem;
  font: inherit; font-size: 0.9rem; font-weight: 600;
  color: var(--ink); background: var(--raised);
  border: 1px solid var(--line); border-radius: var(--r-control);
  cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { border-color: var(--ink-3); }
.btn:disabled { opacity: 0.55; cursor: progress; }
.btn svg { width: 16px; height: 16px; flex: none; }

.btn-primary { background: var(--cobalt); border-color: var(--cobalt); color: var(--on-cobalt); }
.btn-primary:hover { background: var(--cobalt-hover); border-color: var(--cobalt-hover); }

.btn-danger { color: var(--danger); }
.btn-danger:hover { border-color: var(--danger); background: var(--danger-soft); }

.btn-quiet { border-color: transparent; background: transparent; }
.btn-quiet:hover { background: var(--line-soft); border-color: transparent; }

.btn-icon { width: 38px; padding: 0; }
.btn-sm { min-height: 32px; padding: 0 0.7rem; font-size: 0.84rem; }

.field { display: grid; gap: 0.35rem; }
.field > span { font-size: 0.87rem; font-weight: 600; color: var(--ink-2); }
.field small { color: var(--ink-3); font-size: 0.82rem; }

.input, select.input {
  width: 100%; min-height: 40px; padding: 0 0.75rem;
  font: inherit; color: var(--ink); background: var(--raised);
  border: 1px solid var(--line); border-radius: var(--r-control);
}
.input:hover { border-color: var(--ink-3); }
.input:focus { outline: none; border-color: var(--focus); box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 22%, transparent); }
.input.code { font-family: var(--font-code); font-size: 0.84rem; }

.segmented { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 0.4rem; }
.segmented label {
  display: grid; gap: 0.1rem; padding: 0.6rem 0.7rem; cursor: pointer;
  border: 1px solid var(--line); border-radius: var(--r-control); background: var(--raised);
}
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented strong { font-size: 0.9rem; }
.segmented small { font-size: 0.78rem; color: var(--ink-3); line-height: 1.3; }
.segmented label:has(input:checked) { border-color: var(--cobalt); box-shadow: inset 0 0 0 1px var(--cobalt); }
.segmented label:has(input:focus-visible) { outline: 2px solid var(--focus); outline-offset: 2px; }

.alert { padding: 0.7rem 0.85rem; border-radius: var(--r-control); font-size: 0.9rem; }
.alert-error { background: var(--danger-soft); color: var(--danger); }
.alert-warn { background: var(--amber-soft); color: var(--amber); }

/* ---------- Shell ---------- */

.shell { display: grid; grid-template-columns: 236px minmax(0, 1fr); min-height: 100vh; }

.rail {
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: 1.5rem;
  padding: 1.25rem 0.9rem; background: var(--surface); border-right: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 0.6rem; padding: 0 0.4rem; font-weight: 700; letter-spacing: -0.02em; }
.brand svg { width: 28px; height: 28px; color: var(--cobalt); }

.nav { display: grid; gap: 2px; }
.nav a {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.5rem 0.6rem; border-radius: var(--r-control);
  color: var(--ink-2); text-decoration: none; font-weight: 550;
}
.nav a:hover { background: var(--line-soft); color: var(--ink); }
.nav a[aria-current="page"] { background: var(--raised); color: var(--ink); box-shadow: inset 3px 0 0 var(--cobalt); }
.nav .count { font-family: var(--font-code); font-size: 0.72rem; color: var(--ink-3); }

.rail-foot { margin-top: auto; display: grid; gap: 0.5rem; padding: 0.75rem 0.4rem 0; border-top: 1px solid var(--line); }
.rail-foot .who { font-size: 0.85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.main { padding: 2rem clamp(1rem, 3vw, 2.75rem) 4rem; max-width: 1180px; width: 100%; min-width: 0; }

.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 1rem; margin-bottom: 1.5rem; }
.page-head p { margin-top: 0.3rem; }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-panel); }
.panel-pad { padding: 1.25rem; }
.panel + .panel { margin-top: 1rem; }
.panel-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.75rem; padding: 1rem 1.25rem; border-bottom: 1px solid var(--line); }

.empty { padding: 2.75rem 1.5rem; text-align: center; display: grid; gap: 0.8rem; justify-items: center; }
.empty p { max-width: 46ch; }

/* ---------- Route rows: the signature element ---------- */

.routes { list-style: none; margin: 0; padding: 0; }

.route {
  display: grid;
  grid-template-columns: minmax(150px, 12.5rem) minmax(0, 1fr) auto;
  align-items: center; gap: 1.25rem;
  padding: 1rem 1.25rem; border-top: 1px solid var(--line-soft);
}
.route:first-child { border-top: 0; }

.route-name { display: grid; gap: 0.2rem; min-width: 0; }
.route-name strong { font-size: 1rem; overflow-wrap: anywhere; }
.route-meta { display: flex; flex-wrap: wrap; gap: 0.35rem 0.6rem; align-items: center; font-size: 0.8rem; color: var(--ink-3); }

.proto { font-family: var(--font-code); font-size: 0.68rem; padding: 0.1rem 0.35rem; border-radius: 4px; border: 1px solid var(--line); color: var(--ink-2); }

.lamp { display: inline-flex; align-items: center; gap: 0.35rem; font-size: 0.8rem; font-weight: 600; color: var(--ink-3); }
.lamp::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--ink-3); }
.lamp.on { color: var(--signal); }
.lamp.on::before { background: var(--signal); box-shadow: 0 0 0 3px var(--signal-soft); }

.circuit { display: grid; grid-template-columns: minmax(0, max-content) minmax(64px, 1fr) minmax(0, max-content); align-items: center; gap: 0.75rem; min-width: 0; }

.endpoint {
  font-family: var(--font-code); font-size: 0.78rem; padding: 0.4rem 0.6rem;
  border: 1px solid var(--line); border-radius: var(--r-control); background: var(--raised);
  white-space: nowrap; min-width: 0; overflow: hidden; text-overflow: ellipsis;
}
.endpoint.public { color: var(--ink); text-decoration: none; }
a.endpoint.public:hover { border-color: var(--cobalt); color: var(--cobalt); }

.wire { position: relative; height: 12px; }
.wire::before {
  content: ""; position: absolute; left: 0; right: 7px; top: 50%; height: 0;
  border-top: 2px dashed var(--line);
}
.wire::after {
  content: ""; position: absolute; right: 0; top: 50%; transform: translateY(-50%);
  border-left: 7px solid var(--line); border-top: 5px solid transparent; border-bottom: 5px solid transparent;
}
.wire.live::before {
  border-top: 2px solid var(--signal);
  background: linear-gradient(90deg, transparent 0 40%, var(--signal-soft) 50%, transparent 60% 100%);
  background-size: 250% 6px; background-repeat: no-repeat; height: 6px; top: calc(50% - 4px);
  animation: carrier 2.8s linear infinite;
}
.wire.live::after { border-left-color: var(--signal); }

@keyframes carrier { from { background-position: 120% 0; } to { background-position: -120% 0; } }

.route-actions { display: flex; gap: 0.4rem; justify-content: flex-end; }

/* ---------- Tables ---------- */

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
th { text-align: left; font-weight: 600; color: var(--ink-2); padding: 0.6rem 1rem; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 0.65rem 1rem; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }

.tag { display: inline-flex; align-items: center; gap: 0.3rem; padding: 0.12rem 0.5rem; border-radius: 999px; font-size: 0.76rem; font-weight: 600; background: var(--line-soft); color: var(--ink-2); }
.tag.ok { background: var(--signal-soft); color: var(--signal); }
.tag.wait { background: var(--amber-soft); color: var(--amber); }
.tag.bad { background: var(--danger-soft); color: var(--danger); }

/* ---------- Domains ---------- */

.domain { padding: 1rem 1.25rem; border-top: 1px solid var(--line-soft); display: grid; gap: 0.75rem; }
.domain:first-child { border-top: 0; }
.domain-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.75rem; }
.domain-row strong { font-family: var(--font-code); font-size: 0.86rem; overflow-wrap: anywhere; }

.dns-steps { margin: 0; padding-left: 1.2rem; display: grid; gap: 0.6rem; font-size: 0.9rem; }
.record { display: grid; grid-template-columns: 70px minmax(0, 1.2fr) minmax(0, 1.4fr) auto; gap: 0.5rem; align-items: center; margin-top: 0.35rem; }
.record code { padding: 0.35rem 0.5rem; background: var(--raised); border: 1px solid var(--line); border-radius: var(--r-control); overflow-wrap: anywhere; }

.inline-form { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.3fr) auto; gap: 0.75rem; align-items: end; }

/* ---------- Account ---------- */

.stack { display: grid; gap: 1rem; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
.token-row { display: flex; gap: 0.4rem; align-items: stretch; flex-wrap: wrap; }
.token-row .input { flex: 1 1 280px; }

.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); margin: 0; }
.facts div { padding: 1rem 1.25rem; border-right: 1px solid var(--line-soft); }
.facts div:last-child { border-right: 0; }
.facts dt { font-size: 0.82rem; color: var(--ink-3); }
.facts dd { margin: 0.15rem 0 0; font-size: 1.4rem; font-weight: 650; font-variant-numeric: tabular-nums; }

/* ---------- Dialogs ---------- */

dialog {
  width: min(620px, calc(100vw - 32px)); max-height: calc(100vh - 48px);
  padding: 0; border: 1px solid var(--line); border-radius: var(--r-panel);
  background: var(--surface); color: var(--ink); box-shadow: var(--shadow-dialog);
}
dialog::backdrop { background: rgba(14, 19, 24, 0.5); }
dialog[open] { animation: rise 160ms ease-out; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }

.dialog-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; padding: 1.1rem 1.25rem; border-bottom: 1px solid var(--line); }
.dialog-body { padding: 1.25rem; display: grid; gap: 1rem; }
.dialog-foot { display: flex; justify-content: flex-end; gap: 0.5rem; padding: 0.9rem 1.25rem; border-top: 1px solid var(--line); }

.preview { padding: 0.9rem; border: 1px dashed var(--line); border-radius: var(--r-control); }


.tabs { display: flex; gap: 0.25rem; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tabs button {
  font: inherit; font-size: 0.88rem; font-weight: 600; color: var(--ink-2);
  padding: 0.55rem 0.75rem; background: none; border: 0; border-bottom: 2px solid transparent; cursor: pointer; white-space: nowrap;
}
.tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--cobalt); }

.steps { margin: 0; padding-left: 1.2rem; display: grid; gap: 0.75rem; }
.snippet { position: relative; }
.snippet pre {
  margin: 0; padding: 0.8rem 0.9rem; padding-right: 5.5rem;
  font-family: var(--font-code); font-size: 0.75rem; line-height: 1.6;
  background: var(--raised); border: 1px solid var(--line); border-radius: var(--r-control);
  white-space: pre-wrap; word-break: break-all; max-height: 260px; overflow: auto;
}
.snippet .btn { position: absolute; top: 0.4rem; right: 0.4rem; }

details.advanced summary { cursor: pointer; font-size: 0.88rem; color: var(--ink-2); font-weight: 600; }
details.advanced[open] summary { margin-bottom: 0.75rem; }

/* ---------- Toasts ---------- */

.toasts { position: fixed; inset: auto 16px 16px auto; margin: 0; padding: 0; border: 0; background: none; overflow: visible; display: grid; gap: 0.5rem; z-index: 50; max-width: min(420px, calc(100vw - 32px)); }
.toasts:not(:popover-open) { display: none; }
.toast { display: flex; align-items: flex-start; gap: 0.75rem; padding: 0.7rem 0.6rem 0.7rem 0.9rem; border-radius: var(--r-control); background: var(--ink); color: var(--surface); font-size: 0.9rem; box-shadow: var(--shadow-dialog); }
.toast.error { background: var(--danger); color: #fff; }

/* ---------- Auth pages ---------- */

.auth { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1fr) minmax(360px, 480px); }
.auth-art { padding: clamp(1.5rem, 5vw, 4rem); display: flex; flex-direction: column; justify-content: space-between; gap: 2rem; border-right: 1px solid var(--line); background: var(--surface); }
.auth-art h1 { font-size: clamp(2rem, 4vw, 3.1rem); max-width: 16ch; letter-spacing: -0.03em; }
.auth-art p { max-width: 48ch; margin-top: 1rem; font-size: 1.05rem; }
.auth-circuit { display: grid; gap: 0.9rem; max-width: 680px; }
.auth-form { padding: clamp(1.5rem, 5vw, 3.5rem); display: flex; flex-direction: column; justify-content: center; gap: 1.25rem; }
.auth-form form { display: grid; gap: 1rem; }

/* ---------- Responsive ---------- */

@media (max-width: 960px) {
  .inline-form { grid-template-columns: 1fr; }
  .grid-2 { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .rail { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; gap: 0.5rem 1rem; padding: 0.75rem 1rem; border-right: 0; border-bottom: 1px solid var(--line); }
  .nav { grid-auto-flow: column; overflow-x: auto; order: 3; width: 100%; }
  .nav .count { display: none; }
  .nav a[aria-current="page"] { box-shadow: inset 0 -2px 0 var(--cobalt); }
  .rail-foot { margin: 0 0 0 auto; border: 0; padding: 0; grid-auto-flow: column; align-items: center; }
  .rail-foot .who { display: none; }
  .main { padding: 1.25rem 1rem 3rem; }
  .auth { grid-template-columns: 1fr; }
  .auth-art { border-right: 0; border-bottom: 1px solid var(--line); }
  .auth-circuit { display: none; }
  .segmented { grid-template-columns: 1fr; }
  .route-actions { grid-column: 1 / -1; justify-content: flex-start; flex-wrap: wrap; }
  .record { grid-template-columns: 1fr; }
  .facts div { border-right: 0; border-bottom: 1px solid var(--line-soft); }
}

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

fieldset.bare { border: 0; padding: 0; margin: 0; min-width: 0; }
[data-gap] { margin-top: 0.5rem; }
[data-gap-below] { margin-bottom: 0.5rem; }
.grid-2 > .panel { margin-top: 0; }
.stack { align-content: start; }


/* ---------- Iteration 2: alignment, menus, admin tools ---------- */

.skip { position: absolute; left: 1rem; top: -3rem; z-index: 60; padding: 0.5rem 0.8rem; background: var(--cobalt); color: var(--on-cobalt); border-radius: var(--r-control); font-weight: 600; }
.skip:focus { top: 1rem; }

.routes .endpoint { text-align: left; }

.endpoint-public { display: flex; align-items: stretch; min-width: 0; border: 1px solid var(--line); border-radius: var(--r-control); background: var(--raised); }
.endpoint-public .endpoint { border: 0; background: none; flex: 1 1 auto; }
.endpoint-public .icon-btn { border-left: 1px solid var(--line-soft); }
.endpoint-public:has(a:hover) { border-color: var(--cobalt); }

.icon-btn {
  display: inline-grid; place-items: center; width: 34px; flex: none;
  color: var(--ink-3); background: none; border: 0; border-radius: 0 var(--r-control) var(--r-control) 0; cursor: pointer;
}
.icon-btn:hover { color: var(--ink); background: var(--line-soft); }
.icon-btn svg { width: 15px; height: 15px; }

.btn-more { width: 34px; padding: 0; }
.btn-more svg { width: 16px; height: 16px; }

.menu {
  margin: 0; padding: 0.3rem; min-width: 220px; inset: auto;
  border: 1px solid var(--line); border-radius: var(--r-panel); background: var(--raised); color: var(--ink);
  box-shadow: var(--shadow-dialog);
}
.menu button {
  display: block; width: 100%; text-align: left; font: inherit; font-size: 0.9rem;
  padding: 0.55rem 0.7rem; border: 0; border-radius: var(--r-control); background: none; color: var(--ink); cursor: pointer;
}
.menu button:hover { background: var(--line-soft); }
.menu button:focus-visible { background: var(--line-soft); outline: 2px solid var(--cobalt); outline-offset: -2px; }
.menu button.danger { color: var(--danger); }

.quota { display: inline-flex; align-items: center; gap: 0.5rem; }
.meter { width: 72px; height: 6px; border-radius: 999px; background: var(--line-soft); overflow: hidden; }
.meter span { display: block; height: 100%; background: var(--cobalt); }
.meter.full span { background: var(--amber); }

.onboard { list-style: none; counter-reset: step; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1rem; text-align: left; max-width: 860px; }
.onboard li { counter-increment: step; padding: 1rem; border: 1px solid var(--line-soft); border-radius: var(--r-panel); background: var(--raised); }
.onboard li::before { content: counter(step); display: inline-grid; place-items: center; width: 24px; height: 24px; margin-bottom: 0.5rem; border-radius: 50%; background: var(--line-soft); font-size: 0.8rem; font-weight: 700; }
.onboard strong { display: block; margin-bottom: 0.2rem; }

.connect-status { display: grid; gap: 0.2rem; padding: 0.75rem 0.9rem; border-radius: var(--r-control); background: var(--raised); border: 1px solid var(--line); }
.connect-status.on { border-color: var(--signal); background: var(--signal-soft); }
.connect-status .lamp:not(.on)::before { animation: blink 1.4s ease-in-out infinite; }
@keyframes blink { 50% { opacity: 0.25; } }
.usage h3 { margin-bottom: 0.25rem; }
.usage code { padding: 0.1rem 0.3rem; background: var(--raised); border: 1px solid var(--line); border-radius: 4px; }

.plain-list { list-style: none; margin: 0; padding: 0; }
.plain-list li { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.5rem 1rem; padding: 0.7rem 1.25rem; border-top: 1px solid var(--line-soft); }
.plain-list li:first-child { border-top: 0; }
.plain-list .code { font-size: 0.8rem; overflow-wrap: anywhere; }
.plain-list .empty-row { color: var(--ink-3); font-size: 0.9rem; }

.dns-table { margin-top: 0.4rem; border: 1px solid var(--line); border-radius: var(--r-control); background: var(--raised); overflow: hidden; }
.dns-row { display: grid; grid-template-columns: 4rem minmax(0, 1fr); border-top: 1px solid var(--line-soft); }
.dns-row:first-child { border-top: 0; }
.dns-row > span { padding: 0.5rem 0.7rem; font-size: 0.8rem; color: var(--ink-3); border-right: 1px solid var(--line-soft); }
.dns-cell { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; min-width: 0; padding: 0.25rem 0.25rem 0.25rem 0.7rem; }
.dns-cell code { overflow-wrap: anywhere; font-size: 0.78rem; }
.dns-cell .icon-btn { height: 30px; border-radius: var(--r-control); }
.check-note { font-size: 0.87rem; color: var(--amber); }

.tabs-panel { padding: 0 1rem; }
.tabs .count { font-family: var(--font-code); font-size: 0.72rem; color: var(--ink-3); margin-left: 0.2rem; }
.toolbar { display: flex; flex-wrap: wrap; gap: 0.5rem; padding: 0.9rem 1rem; border-bottom: 1px solid var(--line-soft); }
.toolbar input[type="search"] { flex: 1 1 260px; }
.toolbar select { flex: 0 1 220px; }
.row-muted td { color: var(--ink-3); }
tr.security td:first-child { box-shadow: inset 3px 0 0 var(--amber); }
.facts dd small { font-size: 0.8rem; font-weight: 500; color: var(--ink-3); margin-left: 0.3rem; }
.facts dd.alert-num { color: var(--amber); }
.cell-actions { text-align: right; white-space: nowrap; }
.table-note { padding: 0.6rem 1rem; font-size: 0.82rem; color: var(--ink-3); border-top: 1px solid var(--line-soft); }

@media (max-width: 960px) {
  .onboard { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
  .endpoint-public { max-width: 100%; }
  .route-actions { grid-column: 1 / -1; }
  .facts { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .facts div:nth-child(odd) { border-right: 1px solid var(--line-soft); }
  .toolbar select { flex: 1 1 100%; }
  .tabs-panel { padding: 0 0.5rem; }
}


/* ---------- Iteration 3: polish from Playwright review ---------- */

.head-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 0.75rem 1rem; }
.quota-full { font-size: 0.87rem; font-weight: 600; color: var(--amber); }
.btn:disabled:not([aria-busy]) { cursor: not-allowed; }


td.nowrap, .nowrap { white-space: nowrap; }
.num-btn { font: inherit; font-variant-numeric: tabular-nums; padding: 0; border: 0; background: none; color: var(--cobalt); text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }
.toolbar select { flex: 0 1 260px; }
.facts .fact-alert dd { color: var(--amber); }

@media (max-width: 760px) {
  .route { grid-template-columns: minmax(0, 1fr); }
  .head-actions { width: 100%; justify-content: space-between; }

  table.cards-on-mobile thead { display: none; }
  table.cards-on-mobile, table.cards-on-mobile tbody, table.cards-on-mobile tr { display: block; width: 100%; }
  table.cards-on-mobile tr { padding: 0.6rem 0; border-top: 1px solid var(--line-soft); }
  table.cards-on-mobile tr:first-child { border-top: 0; }
  table.cards-on-mobile td { display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: 0.3rem 1rem; border: 0; white-space: normal; text-align: right; overflow-wrap: anywhere; }
  table.cards-on-mobile td[data-label]::before { content: attr(data-label); flex: none; color: var(--ink-3); font-family: var(--font-ui); font-size: 0.8rem; text-align: left; }
  table.cards-on-mobile td.cell-actions { justify-content: flex-end; }
  table.cards-on-mobile td.cell-actions::before { content: none; }
  tr.security td:first-child { box-shadow: none; }
  tr.security { box-shadow: inset 3px 0 0 var(--amber); }
}

td.break { overflow-wrap: anywhere; min-width: 12rem; }
@media (min-width: 1321px) {
  table.cards-on-mobile td.cell-actions { width: 1%; }
}
@media (max-width: 760px) {
  .toolbar select { flex: 1 1 100%; }
}
@media (max-width: 1320px) {
  table.cards-on-mobile thead { display: none; }
  table.cards-on-mobile, table.cards-on-mobile tbody { display: block; width: 100%; }
  table.cards-on-mobile tr { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); padding: 0.6rem 0; border-top: 1px solid var(--line-soft); }
  table.cards-on-mobile tr:first-child { border-top: 0; }
  table.cards-on-mobile td { display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: 0.3rem 1rem; border: 0; width: auto; min-width: 0; white-space: normal; text-align: right; overflow-wrap: anywhere; }
  table.cards-on-mobile td[data-label]::before { content: attr(data-label); flex: none; color: var(--ink-3); font-family: var(--font-ui); font-size: 0.8rem; }
  table.cards-on-mobile td.cell-actions { justify-content: flex-end; }
  table.cards-on-mobile td.cell-actions::before { content: none; }
}
@media (max-width: 760px) {
  table.cards-on-mobile tr { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 1320px) {
  table.cards-on-mobile td.cell-actions { grid-column: 1 / -1; padding-top: 0.5rem; }
  table.cards-on-mobile td.nowrap { white-space: normal; }
}
@media (max-width: 1280px) and (min-width: 761px) {
  .facts { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .facts div:nth-child(-n+3) { border-bottom: 1px solid var(--line-soft); }
  .facts div:nth-child(3n) { border-right: 0; }
}
@media (max-width: 1280px) {
  .facts dd small { display: block; margin-left: 0; }
}
@media (max-width: 1320px) {
}
@media (max-width: 760px) {
}
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }


/* ---------- Iteration 4: fixes from independent review ---------- */

/* H2: long names wrap and the action column stays reachable. */
#adminTunnels td:first-child { white-space: normal; overflow-wrap: anywhere; min-width: 10rem; }
#adminTunnels td:first-child strong { overflow-wrap: anywhere; }
@media (min-width: 1321px) {
  table.cards-on-mobile td.cell-actions, table.cards-on-mobile th:last-child { position: sticky; right: 0; background: var(--surface); box-shadow: -8px 0 8px -8px rgba(0, 0, 0, 0.18); }
}

/* H4: busy/unavailable buttons keep focus instead of being disabled. */
.btn[aria-disabled="true"] { opacity: 0.55; cursor: not-allowed; }
.btn[aria-busy="true"] { cursor: progress; }

/* H10: disabled fields look disabled; inline field errors. */
.input:disabled { background: var(--line-soft); color: var(--ink-3); cursor: not-allowed; }
.input[aria-invalid="true"] { border-color: var(--danger); }
.field-error { color: var(--danger); font-size: 0.84rem; }
.form-error { grid-column: 1 / -1; }

.toast .toast-close { flex: none; margin-left: auto; width: 24px; height: 24px; display: grid; place-items: center; border: 0; border-radius: 4px; background: none; color: inherit; font-size: 1.1rem; line-height: 1; cursor: pointer; opacity: 0.8; }
.toast .toast-close:hover { opacity: 1; background: rgba(255, 255, 255, 0.15); }

.preview-invalid { color: var(--danger); font-size: 0.84rem; }

@media (max-width: 760px) {
  /* H9: connect tabs wrap instead of hiding the last one. */
  .tabs:not(.tabs-panel) { flex-wrap: wrap; overflow-x: visible; }
  /* H10: show which account is signed in on mobile. */
  .rail-foot .who { display: block; max-width: 45vw; font-size: 0.78rem; color: var(--ink-3); }
  .rail-foot { gap: 0.6rem; }
  .toasts { inset: auto 16px 16px 16px; max-width: none; }
}
.alert-info { background: var(--line-soft); color: var(--ink); }
.tunnel-cell { display: grid; gap: 0.15rem; justify-items: start; }
.tunnel-cell .code { font-size: 0.76rem; }
@media (min-width: 1321px) {
  #adminTunnels td:first-child { min-width: 11rem; }
  #adminTunnels td:nth-child(2) { white-space: nowrap; }
  #adminTunnels td.break { min-width: 16rem; }
  #adminTunnels td:nth-child(4) { white-space: nowrap; }
}
@media (max-width: 1320px) {
  .tunnel-cell { justify-items: end; }
}


/* ---------- Iteration 5: second review fixes ---------- */


/* N3: white on the light danger red fails AA in dark mode. */
@media (prefers-color-scheme: dark) {
  .toast.error { background: #9b2c24; color: #ffffff; }
}

/* N4: audit details and user e-mails may be long in any layout. */
#adminAudit td, #adminUsers td { overflow-wrap: anywhere; }


/* ---------- Iteration 6: tunnel row layout (single source of truth) ---------- */

/* Addresses wrap instead of being cut, and the public address always gets the widest track:
   the circuit sits under the name until 1400px, where three columns still leave it ~400px. */
/* setAddress() adds <wbr> between address parts; anywhere is only the fallback for a single very long part. */
:is(.routes, .preview) .endpoint { white-space: normal; overflow-wrap: anywhere; text-overflow: clip; }
.routes .circuit { grid-template-columns: minmax(0, 11rem) 3.5rem minmax(0, 1fr); }
.route { grid-template-columns: minmax(0, 1fr) auto; }
.route .circuit { grid-column: 1 / -1; grid-row: 2; }
@media (min-width: 1400px) {
  .route { grid-template-columns: minmax(150px, 12.5rem) minmax(0, 1fr) 9.5rem; }
  .route .circuit { grid-column: auto; grid-row: auto; }
}
@media (max-width: 960px) {
  .routes .circuit { grid-template-columns: minmax(0, 1fr); gap: 0; justify-items: start; }
  .routes .circuit .endpoint { max-width: 100%; }
  .routes .circuit .wire { width: 12px; height: 22px; margin-left: 1.1rem; }
  .routes .circuit .wire::before { left: 50%; right: auto; top: 0; bottom: 6px; height: auto; border-top: 0; border-left: 2px dashed var(--line); background: none; }
  .routes .circuit .wire.live::before { border-left: 2px solid var(--signal); height: auto; top: 0; animation: none; }
  .routes .circuit .wire::after { right: auto; left: 50%; top: auto; bottom: 0; transform: translateX(-50%); border-left: 5px solid transparent; border-right: 5px solid transparent; border-top: 7px solid var(--line); border-bottom: 0; }
  .routes .circuit .wire.live::after { border-top-color: var(--signal); border-left-color: transparent; }
}
/* The dialog is narrow at every width, so the preview always stacks. */
.preview .circuit { grid-template-columns: minmax(0, 1fr); gap: 0; justify-items: start; }
.preview .circuit .endpoint { max-width: 100%; }
.preview .circuit .wire { width: 12px; height: 22px; margin-left: 1.1rem; }
.preview .circuit .wire::before { left: 50%; right: auto; top: 0; bottom: 6px; height: auto; border-top: 0; border-left: 2px dashed var(--line); background: none; }
.preview .circuit .wire.live::before { border-left: 2px solid var(--signal); height: auto; top: 0; animation: none; }
.preview .circuit .wire::after { right: auto; left: 50%; top: auto; bottom: 0; transform: translateX(-50%); border-left: 5px solid transparent; border-right: 5px solid transparent; border-top: 7px solid var(--line); border-bottom: 0; }
.preview .circuit .wire.live::after { border-top-color: var(--signal); border-left-color: transparent; }
@media (max-width: 760px) {
  .route { grid-template-columns: minmax(0, 1fr); }
}

.input::placeholder { color: var(--ink-3); opacity: 1; }
