/* Redirector admin interface. Every page's styling lives here: templates
   carry no <style> block and no style= attribute. Layout: a fixed left rail
   with the pages, a content column with a page header, a toolbar card, a
   table card, and a pending-changes bar pinned to the bottom while anything
   is staged. Under 760px the rail becomes a top bar. Colours follow the
   Locus app; IBM Plex is used when installed locally (nothing is fetched)
   and the system stack stands in for it otherwise. */
:root {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --rail: #0f172a;
  --rail-fg: #cbd5e1;
  --rail-active: #1e293b;
  --fg: #1e293b;
  --muted: #64748b;
  --line: #e2e8f0;
  --accent: #2563eb;
  --accent-soft: #e8efff;
  --accent-fg: #ffffff;
  --ok: #15803d;      --ok-soft: #e7f6ec;
  --warn: #b45309;    --warn-soft: #fdf3e2;
  --bad: #b91c1c;     --bad-soft: #fdeaea;
  --staged: #7c3aed;  --staged-soft: #f1eafe;
  --font: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  --radius: 8px;
  --rail-width: 220px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1120; --surface: #111a2e; --surface-2: #0f172a;
    --rail: #070c18; --rail-fg: #94a3b8; --rail-active: #17213a;
    --fg: #e2e8f0; --muted: #94a3b8; --line: #1f2b45;
    --accent: #5b8cff; --accent-soft: #16244a; --accent-fg: #0b1120;
    --ok: #4ade80; --ok-soft: #10301f; --warn: #fbbf24; --warn-soft: #33270c;
    --bad: #f87171; --bad-soft: #3a1414; --staged: #b794ff; --staged-soft: #261a45;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0b1120; --surface: #111a2e; --surface-2: #0f172a;
  --rail: #070c18; --rail-fg: #94a3b8; --rail-active: #17213a;
  --fg: #e2e8f0; --muted: #94a3b8; --line: #1f2b45;
  --accent: #5b8cff; --accent-soft: #16244a; --accent-fg: #0b1120;
  --ok: #4ade80; --ok-soft: #10301f; --warn: #fbbf24; --warn-soft: #33270c;
  --bad: #f87171; --bad-soft: #3a1414; --staged: #b794ff; --staged-soft: #261a45;
  color-scheme: dark;
}

/* The hidden attribute must win over every display rule below: the pending
   bar, the review dialog and the empty chips are shown and hidden by it. */
[hidden] { display: none !important; }
* { box-sizing: border-box; }
html, body { min-height: 100%; }
body { margin: 0; background: var(--bg); color: var(--fg); font: 14px/1.5 var(--font); }
a { color: var(--accent); }
code, .mono { font-family: var(--mono); font-size: 13px; }
.sub { color: var(--muted); font-size: 12px; }
.skip { position: absolute; left: -9999px; top: 8px; z-index: 20; background: var(--surface); color: var(--fg); padding: 8px 12px; border-radius: 6px; }
.skip:focus { left: 8px; }

.app { display: grid; grid-template-columns: var(--rail-width) minmax(0, 1fr); min-height: 100vh; }

/* rail */
.rail { background: var(--rail); color: var(--rail-fg); padding-block: 20px; padding-inline: 12px; display: flex; flex-direction: column; gap: 24px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { padding-inline: 10px; min-width: 0; }
.brand b { display: block; color: #fff; font-weight: 600; letter-spacing: .01em; }
.brand span { display: block; font: 12px var(--mono); color: var(--rail-fg); overflow-wrap: anywhere; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 6px; color: var(--rail-fg); text-decoration: none; }
.nav a:hover { background: var(--rail-active); color: #fff; }
.nav a[aria-current="page"] { background: var(--rail-active); color: #fff; box-shadow: inset 2px 0 0 var(--accent); }
.nav a:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.nav .count { font: 12px var(--mono); background: #1e2a44; color: #e2e8f0; padding: 0 7px; border-radius: 99px; font-variant-numeric: tabular-nums; }
.nav .sep { height: 1px; background: #1e293b; margin: 8px 10px; border: 0; }
.who { margin: auto 0 0; padding-inline: 10px; font-size: 13px; display: flex; justify-content: space-between; align-items: center; gap: 8px; min-width: 0; }
.who span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who button { all: unset; cursor: pointer; color: var(--rail-fg); text-decoration: underline; text-underline-offset: 3px; white-space: nowrap; }
.who button:hover { color: #fff; }
.who button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 2px; }

/* main column */
main { min-width: 0; padding-inline: 28px; padding-block: 24px 120px; display: flex; flex-direction: column; gap: 18px; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; }
.page-head h1 { margin: 0; font-size: 22px; font-weight: 600; text-wrap: balance; }
.page-head p { margin: 2px 0 0; color: var(--muted); max-width: 72ch; }
.cert { background: var(--warn-soft); color: var(--warn); border-radius: var(--radius); padding: 8px 14px; font-size: 13px; margin: 0; }
.error { background: var(--bad-soft); color: var(--bad); border-radius: var(--radius); padding: 8px 14px; margin: 0; }
.flash { border-radius: var(--radius); padding: 8px 14px; margin: 0; }
.flash.ok { background: var(--ok-soft); color: var(--ok); }
.flash.warn { background: var(--warn-soft); color: var(--warn); }
.empty { background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius); padding: 24px; color: var(--muted); margin: 0; }
.note { font-size: 13px; color: var(--muted); margin: 0; }

/* buttons */
.btn { all: unset; box-sizing: border-box; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 7px 14px; border-radius: 6px; font-weight: 500; font-size: 14px; line-height: 1.4; border: 1px solid var(--line); background: var(--surface); color: var(--fg); white-space: nowrap; text-decoration: none; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn[disabled] { opacity: .45; cursor: not-allowed; }
.btn[disabled]:hover { border-color: var(--line); filter: none; }
.btn.primary[disabled]:hover { border-color: var(--accent); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* form controls */
select, input[type=text], input[type=search], input[type=password], textarea {
  font: 14px var(--font); color: var(--fg); background: var(--surface-2); border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; min-width: 0; max-width: 100%;
}
textarea { font-family: var(--mono); font-size: 13px; width: 100%; resize: vertical; }
select:disabled { opacity: .55; cursor: not-allowed; }
select:focus-visible, input:focus-visible, textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
input[type=checkbox] { accent-color: var(--accent); width: 15px; height: 15px; margin: 0; vertical-align: middle; }
input[type=checkbox]:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); min-width: 0; }
.field > span { text-transform: uppercase; letter-spacing: .06em; font-weight: 500; }
.field.grow { flex: 1 1 200px; }
.check { display: inline-flex; align-items: center; gap: 8px; }

/* toolbar card */
.toolbar { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; display: flex; flex-direction: column; gap: 12px; }
.toolbar form, .toolbar .row { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; margin: 0; }
.toolbar .bulk { border-top: 1px solid var(--line); padding-top: 12px; }
.toolbar .bulk .spacer { flex: 1 1 0; }

/* table card */
.table-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: auto; max-height: calc(100vh - 140px); }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
thead th { position: sticky; top: 0; z-index: 1; background: var(--surface-2); text-align: left; font-weight: 500; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
tbody td { padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--surface-2); }
tbody tr.is-staged, tbody tr.is-staged:hover { background: var(--staged-soft); }
td select { padding: 4px 6px; font-size: 13px; max-width: 200px; }
td.wrap { white-space: normal; min-width: 260px; }
td ul { margin: 0; padding-left: 18px; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* chips */
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 1px 9px; border-radius: 99px; font-size: 12px; font-weight: 500; white-space: nowrap; }
.chip::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex: none; }
.chip:empty { display: none; }
.chip.ok { background: var(--ok-soft); color: var(--ok); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.bad { background: var(--bad-soft); color: var(--bad); }
.chip.idle { background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); }
.chip.staged { background: var(--staged-soft); color: var(--staged); }
tr.is-staged .sync { display: none; }
.route { display: inline-flex; flex-direction: column; align-items: flex-start; gap: 2px; }
.route .why { font-size: 10.5px; padding-left: 4px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }

/* pending bar */
.pending { position: fixed; left: var(--rail-width); right: 0; bottom: 0; z-index: 5; padding-inline: 28px; padding-block: 12px calc(12px + env(safe-area-inset-bottom, 0px)); background: var(--surface); border-top: 2px solid var(--staged); display: flex; gap: 12px; align-items: center; flex-wrap: wrap; box-shadow: 0 -6px 20px rgb(15 23 42 / .08); }
.pending strong { color: var(--staged); }
.pending .spacer { flex: 1; }

/* review dialog */
.scrim { position: fixed; inset: 0; z-index: 10; background: rgb(15 23 42 / .45); display: grid; place-items: center; padding: 16px; }
.dialog { background: var(--surface); color: var(--fg); border-radius: 10px; width: min(640px, 100%); max-height: 90vh; overflow: auto; padding: 22px; display: flex; flex-direction: column; gap: 14px; box-shadow: 0 20px 60px rgb(0 0 0 / .3); }
.dialog:focus { outline: none; }
.dialog h2 { margin: 0; font-size: 18px; }
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.stat { background: var(--surface-2); border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px; }
.stat b { display: block; font: 600 20px var(--mono); font-variant-numeric: tabular-nums; }
.stat span { font-size: 12px; color: var(--muted); }
.stat.bad b { color: var(--bad); }
.moves, .refusals { list-style: none; margin: 0; padding: 0; border: 1px solid var(--line); border-radius: 6px; }
.moves:empty, .refusals:empty { display: none; }
.moves li, .refusals li { padding: 8px 12px; border-bottom: 1px solid var(--line); display: flex; gap: 10px; flex-wrap: wrap; align-items: baseline; overflow-wrap: anywhere; }
.moves li:last-child, .refusals li:last-child { border-bottom: 0; }
.refusals { border-color: var(--bad); background: var(--bad-soft); color: var(--bad); }
.refusals li { border-color: var(--bad-soft); }
.arrow { color: var(--muted); }
.dialog .actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.result:empty { display: none; }
.result { margin: 0; color: var(--bad); }

/* cards: CSPs & groups, forms */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; }
.card h2 { margin: 0 0 12px; font-size: 17px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; align-items: end; }
.form-grid .actions { grid-column: 1 / -1; display: flex; gap: 8px; }
.form-grid .span-all, .form-grid .register-lines { grid-column: 1 / -1; }
.form-grid h2.span-all { margin: 0; }
.csp-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.csp-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.csp-head h2 { margin: 0; font-size: 17px; }
.csp-head .sub { font-family: var(--mono); }
.csp-body { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); }
.csp-body > section { padding: 16px 18px; min-width: 0; }
.csp-body > section + section { border-left: 1px solid var(--line); }
.csp-body h3 { margin: 0 0 10px; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 500; }
.groups, .csp-servers { list-style: none; margin: 0; padding: 0; }
.group { display: grid; grid-template-columns: minmax(14em, 1fr) auto; gap: 8px 16px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); }
.group:last-child { border-bottom: 0; }
.group-rename { display: flex; gap: 6px; align-items: center; margin: 0; min-width: 0; }
.group-rename input[type=text] { flex: 1 1 auto; font-weight: 500; background: transparent; border-color: transparent; padding-inline: 6px; margin-left: -6px; min-width: 6em; }
.group-rename input[type=text]:hover { border-color: var(--line); }
.group-rename input[type=text]:focus { background: var(--surface-2); border-color: var(--line); }
.group .meta { display: flex; gap: 10px; flex-wrap: wrap; align-items: baseline; }
.group .count { font: 13px var(--mono); color: var(--muted); font-variant-numeric: tabular-nums; }
.group .default { display: flex; gap: 6px; align-items: end; grid-row: span 2; min-width: 0; }
.group .default select { width: 230px; max-width: 100%; }
.srv { display: flex; justify-content: space-between; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); align-items: center; }
.srv:last-child { border-bottom: 0; }
.srv > div { min-width: 0; overflow-wrap: anywhere; }
.add { margin: 12px 0 0; padding-top: 12px; border-top: 1px dashed var(--line); display: flex; gap: 8px; flex-wrap: wrap; align-items: end; }
.add .field:first-of-type { flex: 1 1 160px; }
.hint { padding: 10px 18px; background: var(--surface-2); border-top: 1px solid var(--line); font-size: 12.5px; color: var(--muted); border-radius: 0 0 var(--radius) var(--radius); margin: 0; }

/* login */
.login-main { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(380px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 26px; display: flex; flex-direction: column; gap: 14px; box-shadow: 0 10px 30px rgb(15 23 42 / .08); }
.login-card .brand { padding: 0; }
.login-card .brand b { color: var(--fg); font-size: 18px; }
.login-card .brand span { color: var(--muted); }
.login-card input { width: 100%; }
.login-card .btn { width: 100%; }

@media (max-width: 760px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .rail { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; gap: 8px 12px; padding-block: 12px; }
  .brand span { display: none; }
  .nav { flex-direction: row; flex-wrap: wrap; order: 3; width: 100%; }
  .nav a { padding: 6px 8px; }
  .nav .sep { display: none; }
  .who { margin: 0 0 0 auto; }
  main { padding-inline: 16px; }
  .pending { left: 0; padding-inline: 16px; }
  .csp-body { grid-template-columns: minmax(0, 1fr); }
  .csp-body > section + section { border-left: 0; border-top: 1px solid var(--line); }
  .group { grid-template-columns: minmax(0, 1fr); }
  .group .default { grid-row: auto; }
  .group .default .field { flex: 1 1 auto; }
  .group .default select { width: 100%; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .table-wrap { max-height: none; }
}
@media (prefers-reduced-motion: no-preference) {
  tbody tr, .nav a, .btn { transition: background-color .12s, border-color .12s; }
}
