:root {
  color-scheme: light dark;
  --bg: #f2f4f8;
  --surface: #ffffff;
  --surface-2: #eaeef4;
  --ink: #16202e;
  --muted: #566274;
  --line: #d6dce6;
  --accent: #1f5fa8;
  --accent-ink: #ffffff;
  --accent-soft: #dfeaf7;
  --up: #17783f;
  --up-soft: #dcf1e5;
  --down: #b3261e;
  --down-soft: #f9dedc;
  --warn: #8f5200;
  --warn-soft: #fbebd0;
  --focus: #1f5fa8;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", "DejaVu Sans Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --radius: 5px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0c121b;
    --surface: #131b27;
    --surface-2: #1b2535;
    --ink: #e3e9f2;
    --muted: #8e9bb0;
    --line: #25314a;
    --accent: #6fa9e8;
    --accent-ink: #0a1320;
    --accent-soft: #1a2c46;
    --up: #4cc38a;
    --up-soft: #12301f;
    --down: #f27872;
    --down-soft: #3a1815;
    --warn: #e3a64c;
    --warn-soft: #36270f;
    --focus: #8bbcf0;
  }
}
* { box-sizing: border-box; }
html { font-size: 14px; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--sans); line-height: 1.45; }
h1, h2, h3 { margin: 0; line-height: 1.25; font-weight: 600; }
h1 { font-size: 1.35rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: 0.95rem; }
p { margin: 0 0 0.6rem; }
a { color: var(--accent); text-underline-offset: 2px; }
code, .mono, pre, textarea.mono, input.mono { font-family: var(--mono); font-size: 0.93em; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -999px; top: 0; background: var(--accent); color: var(--accent-ink); padding: 0.5rem 0.8rem; z-index: 100; }
.skip:focus { left: 0; }
.muted { color: var(--muted); }
.up { color: var(--up); } .down { color: var(--down); } .warn { color: var(--warn); }
.right { text-align: right; }
.nowrap { white-space: nowrap; }

/* shell */
.shell { display: grid; grid-template-columns: 188px minmax(0, 1fr); grid-template-rows: 46px 1fr; min-height: 100vh; }
.topbar { grid-column: 1 / -1; display: flex; align-items: center; gap: 1rem; padding: 0 1rem; background: var(--surface); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 0.5rem; font-weight: 700; letter-spacing: 0.02em; font-size: 1.05rem; }
.brand svg { width: 18px; height: 18px; fill: var(--accent); }
.topbar .spacer { flex: 1; }
.sidenav { background: var(--surface); border-right: 1px solid var(--line); padding: 0.6rem 0.5rem; display: flex; flex-direction: column; gap: 1px; }
.sidenav a { padding: 0.38rem 0.6rem; border-radius: var(--radius); color: var(--ink); text-decoration: none; }
.sidenav a:hover { background: var(--surface-2); }
.sidenav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.sidenav .group { margin: 0.8rem 0.6rem 0.2rem; color: var(--muted); font-size: 0.85rem; }
main { padding: 1rem 1.25rem 3rem; min-width: 0; outline: none; }
.page-head { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; margin-bottom: 0.9rem; }
.page-head .grow { flex: 1; }
.crumbs { color: var(--muted); font-size: 0.9rem; margin-bottom: 0.2rem; }
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; grid-template-rows: 46px auto 1fr; }
  .sidenav { flex-direction: row; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  .sidenav a { white-space: nowrap; }
  .sidenav .group { display: none; }
  main { padding: 0.75rem; }
}

/* controls */
button, input, select, textarea { font: inherit; color: inherit; }
.btn { display: inline-flex; align-items: center; gap: 0.35rem; padding: 0.32rem 0.8rem; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); cursor: pointer; text-decoration: none; color: var(--ink); line-height: 1.3; }
.btn:hover { background: var(--surface-2); }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--down); border-color: var(--down); background: transparent; }
.btn.danger:hover { background: var(--down-soft); }
.btn.danger.solid { background: var(--down); color: #fff; }
.btn.small { padding: 0.12rem 0.5rem; font-size: 0.9rem; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
input[type=text], input[type=password], input[type=email], input[type=number], input[type=search], input:not([type]), select, textarea {
  width: 100%; padding: 0.3rem 0.5rem; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); min-width: 0;
}
textarea { resize: vertical; min-height: 4.5rem; }
input[type=checkbox] { width: 1rem; height: 1rem; accent-color: var(--accent); vertical-align: -2px; }
.field { display: flex; flex-direction: column; gap: 0.2rem; margin-bottom: 0.7rem; }
.field > label, .field > .label { font-weight: 600; font-size: 0.92rem; }
.field .hint { color: var(--muted); font-size: 0.88rem; }
.check { display: flex; align-items: center; gap: 0.45rem; margin-bottom: 0.5rem; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 0 0.9rem; }
.toolbar { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; margin-bottom: 0.7rem; }
.toolbar .grow { flex: 1; }
.toolbar input[type=search] { max-width: 20rem; }
.actions { display: flex; gap: 0.3rem; justify-content: flex-end; flex-wrap: nowrap; }

/* surfaces */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 0.9rem 1rem; margin-bottom: 1rem; }
.panel > h2, .panel > h3 { margin-bottom: 0.6rem; }
.notice { padding: 0.55rem 0.8rem; border-radius: var(--radius); background: var(--warn-soft); color: var(--warn); margin-bottom: 0.8rem; }
.notice.error { background: var(--down-soft); color: var(--down); }
.empty { padding: 1.6rem 1rem; text-align: center; color: var(--muted); }
.badge { display: inline-block; padding: 0 0.45rem; border-radius: 99px; font-size: 0.82rem; border: 1px solid var(--line); background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge.up { background: var(--up-soft); color: var(--up); border-color: transparent; }
.badge.down { background: var(--down-soft); color: var(--down); border-color: transparent; }
.badge.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge.accent { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.dot { display: inline-block; width: 0.6rem; height: 0.6rem; border-radius: 50%; background: var(--muted); margin-right: 0.3rem; vertical-align: -1px; }
.dot.up { background: var(--up); } .dot.down { background: var(--down); }

/* tables */
.tablewrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
table.data { width: 100%; border-collapse: collapse; }
table.data th, table.data td { text-align: left; padding: 0.34rem 0.7rem; border-bottom: 1px solid var(--line); vertical-align: top; }
table.data th { font-weight: 600; color: var(--muted); font-size: 0.88rem; background: var(--surface-2); position: sticky; top: 0; }
table.data tr:last-child td { border-bottom: 0; }
table.data tbody tr:hover { background: color-mix(in srgb, var(--accent-soft) 40%, transparent); }
table.data td.mono, table.data td .mono { word-break: break-all; }
table.data tr.editing { background: var(--accent-soft); }
table.data tr.editing td { vertical-align: middle; }
.recs { margin: 0; padding: 0; list-style: none; font-family: var(--mono); font-size: 0.93em; }
.recs li { word-break: break-all; }
.recs li.disabled { text-decoration: line-through; opacity: 0.6; }

/* tabs */
.tabs { display: flex; gap: 0.1rem; border-bottom: 1px solid var(--line); margin-bottom: 1rem; overflow-x: auto; }
.tabs a { padding: 0.45rem 0.9rem; text-decoration: none; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs a:hover { color: var(--ink); }
.tabs a[aria-current="page"] { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

/* code */
.codeblock { position: relative; margin: 0 0 0.8rem; }
.codeblock pre { margin: 0; padding: 0.7rem 0.9rem; padding-right: 4.5rem; background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius); overflow-x: auto; white-space: pre; }
.codeblock .btn { position: absolute; top: 0.4rem; right: 0.4rem; }
.copyline { display: flex; gap: 0.4rem; align-items: center; }
.copyline code { flex: 1; padding: 0.2rem 0.5rem; background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius); word-break: break-all; }

/* dialogs and toasts */
dialog { border: 1px solid var(--line); border-radius: 8px; padding: 0; background: var(--surface); color: var(--ink); width: min(34rem, calc(100vw - 2rem)); max-height: calc(100vh - 3rem); box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35); }
dialog.wide { width: min(52rem, calc(100vw - 2rem)); }
dialog::backdrop { background: rgba(8, 12, 20, 0.55); }
dialog form, dialog .dlg { display: flex; flex-direction: column; max-height: calc(100vh - 3rem); }
.dlg-head { padding: 0.8rem 1rem 0.2rem; }
.dlg-body { padding: 0.6rem 1rem; overflow-y: auto; }
.dlg-foot { padding: 0.7rem 1rem; display: flex; justify-content: flex-end; gap: 0.5rem; border-top: 1px solid var(--line); }
#toasts { position: fixed; right: 1rem; bottom: 1rem; display: flex; flex-direction: column; gap: 0.5rem; z-index: 200; max-width: min(26rem, calc(100vw - 2rem)); }
.toast { padding: 0.6rem 0.8rem; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--accent); box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25); display: flex; gap: 0.6rem; align-items: flex-start; }
.toast.error { border-left-color: var(--down); }
.toast.success { border-left-color: var(--up); }
.toast span { flex: 1; word-break: break-word; }
.toast button { border: 0; background: transparent; cursor: pointer; color: var(--muted); font-size: 1.1rem; line-height: 1; }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.login .panel { width: min(24rem, 100%); }
.login .brand { font-size: 1.4rem; margin-bottom: 0.2rem; }
.login .brand svg { width: 26px; height: 26px; }

/* rollover steps */
.steps { display: flex; flex-wrap: wrap; gap: 0.4rem; margin: 0.4rem 0 0.8rem; padding: 0; list-style: none; }
.steps li { padding: 0.25rem 0.7rem; border: 1px solid var(--line); border-radius: 99px; color: var(--muted); }
.steps li.done { color: var(--up); border-color: var(--up); }
.steps li.current { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }

/* steering */
.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 0.8rem; }
.pool { border: 1px solid var(--line); border-radius: var(--radius); padding: 0.6rem 0.7rem; background: var(--bg); margin-bottom: 0.7rem; }
.pool-head { display: flex; gap: 0.5rem; align-items: center; margin-bottom: 0.5rem; }
.ep { display: grid; grid-template-columns: minmax(8rem, 2fr) minmax(7rem, 1.2fr) auto auto; gap: 0.4rem; align-items: center; margin-bottom: 0.3rem; }
.rule { display: grid; grid-template-columns: 4.5rem 7rem minmax(6rem, 1fr) minmax(6rem, 1fr) minmax(6rem, 1fr) auto; gap: 0.4rem; align-items: center; margin-bottom: 0.3rem; }
.rule-labels { display: grid; grid-template-columns: 4.5rem 7rem minmax(6rem, 1fr) minmax(6rem, 1fr) minmax(6rem, 1fr) auto; gap: 0.4rem; color: var(--muted); font-size: 0.85rem; }
.rule-labels span:last-child { width: 3.2rem; }
@media (max-width: 760px) { .ep, .rule { grid-template-columns: 1fr 1fr; } .rule-labels { display: none; } }
.viewmap { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 0.5rem; margin-bottom: 1rem; }
.tile { border: 1px solid var(--line); border-radius: var(--radius); padding: 0.5rem 0.65rem; background: var(--surface); min-height: 5rem; }
.tile.default { grid-column: 1 / -1; border-color: var(--accent); background: var(--accent-soft); }
.tile h3 { display: flex; justify-content: space-between; gap: 0.4rem; margin-bottom: 0.25rem; }
.tile .pool-name { color: var(--muted); font-weight: 400; font-size: 0.85rem; }
.tile ul { margin: 0; padding: 0; list-style: none; font-family: var(--mono); font-size: 0.9em; }
.tile li { word-break: break-all; }
.tile.derived { border-style: dashed; }

/* monitor grid */
td.cell-ok { background: var(--up-soft); }
td.cell-lag { background: var(--warn-soft); }
td.cell-bad { background: var(--down-soft); }
td.cell-none { color: var(--muted); }
td small { display: block; color: var(--muted); }
.scopes { display: flex; gap: 0.25rem; flex-wrap: wrap; }
.picklist { max-height: 9rem; overflow-y: auto; border: 1px solid var(--line); border-radius: var(--radius); padding: 0.3rem 0.5rem; background: var(--surface); }
.qr { display: inline-block; padding: 8px; background: #fff; border-radius: var(--radius); line-height: 0; }
.qr svg { width: 220px; height: 220px; }
@media (prefers-reduced-motion: no-preference) {
  .toast { animation: toast-in 0.15s ease-out; }
  @keyframes toast-in { from { opacity: 0; transform: translateY(6px); } }
}
