/* Command Deck: dark, dense, keyboard-first. The CSP allows no web fonts or
   inline styles, so fonts fall back to whatever is installed and every style
   lives here. */
:root {
  --bg: #0d0f12;
  --rail: #111419;
  --surface: #111419;
  --surface-2: #181c22;
  --surface-3: #1d222a;
  --sunk: #0f1216;
  --line: #232831;
  --line-soft: #1c2027;
  --line-strong: #2f3540;
  --text: #e6e9ee;
  --text-2: #aeb7c4;
  --muted: #8f99a8;
  --accent: #b8f34a;
  --accent-hover: #cdfb72;
  --accent-text: #c9f77a;
  --accent-soft: #24330f;
  --ok: #5be49b;
  --ok-text: #7ef0b0;
  --ok-soft: #143322;
  --warn: #f5b544;
  --warn-text: #ffd27a;
  --warn-soft: #3a2d10;
  --danger: #ff7a6b;
  --danger-text: #ffaa9e;
  --danger-soft: #3a1814;
  --sans: Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "SF Mono", "Cascadia Code", Menlo, Consolas, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
/* Component display rules (button, label…) would otherwise beat the hidden attribute. */
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.5 var(--sans); -webkit-font-smoothing: antialiased; }
h1, h2, h3 { margin: 0; line-height: 1.25; letter-spacing: -0.01em; }
h1 { font-size: 22px; font-weight: 650; }
h2 { font-size: 14px; font-weight: 600; }
p { margin: 0; }
a { color: var(--accent); }
a:hover { color: var(--accent-hover); }
code, .mono { font-family: var(--mono); font-size: 12.5px; }
code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }
kbd { font-family: var(--mono); font-size: 11px; border: 1px solid var(--line-strong); border-radius: 4px; padding: 1px 6px; color: var(--text-2); }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.tiny { font-size: 11.5px; }
.boot { padding: 48px; text-align: center; color: var(--muted); }
.icon { flex: none; color: var(--muted); }
.ellipsis { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.break { word-break: break-all; }
.grow { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.row.tight { gap: 4px 6px; }
.row.end { justify-content: flex-end; }
.row.nowrap { flex-wrap: nowrap; }
.stack { display: grid; gap: 20px; }
.stack > * { min-width: 0; }
.stack-sm { display: grid; gap: 10px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ── Dots and pills ── */
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: none; background: #3a414c; }
.dot.ok { background: var(--ok); }
.dot.warn { background: var(--warn); }
.dot.down { background: var(--danger); }
.dot-space { width: 8px; flex: none; }
.pill { display: inline-flex; align-items: center; gap: 5px; font-family: var(--mono); font-size: 11.5px; padding: 1px 8px; border-radius: 999px; white-space: nowrap; background: var(--surface-3); color: var(--text-2); }
.pill.ok { background: var(--ok-soft); color: var(--ok-text); }
.pill.bad { background: var(--danger-soft); color: var(--danger-text); }
.pill.warn { background: var(--warn-soft); color: var(--warn-text); }
.pill.acc { background: var(--accent-soft); color: var(--accent-text); }
.pill.retry { margin-left: 4px; }

/* ── Shell ── */
.shell { display: flex; flex-wrap: wrap; min-height: 100vh; }
.rail { flex: 0 0 232px; background: var(--rail); border-right: 1px solid var(--line); padding: 18px 12px; display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.content { flex: 1 1 560px; min-width: 0; max-width: 1240px; padding: 28px 32px 96px; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 14px; font-weight: 600; white-space: nowrap; }
.logo { width: 22px; height: 22px; flex: none; }
.jump { justify-content: space-between; width: 100%; min-height: 40px; color: var(--muted); background: var(--surface-2); margin-bottom: 10px; font-weight: 400; }
.jump:hover { color: var(--text); }
.nav-item { display: flex; align-items: center; gap: 10px; min-height: 40px; padding: 8px 12px; border-radius: 8px; color: var(--text-2); text-decoration: none; font-weight: 500; }
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item[aria-current="page"] { background: var(--surface-3); color: #fff; }
.count { font-family: var(--mono); font-size: 11px; color: var(--muted); }
.rail-foot { margin-top: auto; padding: 12px 8px 0; border-top: 1px solid var(--line); display: grid; gap: 6px; font-size: 12px; }
.rail-signout { justify-self: start; padding-left: 0; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.page-head p { margin-top: 4px; }

/* ── Panels ── */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.panel.open { overflow: visible; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.panel-body { padding: 16px; }
.empty-panel { padding: 40px 20px; text-align: center; display: grid; gap: 10px; justify-items: center; }
.empty { padding: 32px 16px; text-align: center; color: var(--muted); }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.stat { background: var(--surface); padding: 14px 16px; }
.stat .label { font: 11px var(--mono); letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.stat .value { font-size: 26px; font-weight: 600; font-variant-numeric: tabular-nums; margin-top: 2px; }
.stat .value.bad { color: var(--danger-text); }
.health { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px; }
.health-card { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; display: grid; gap: 4px; color: var(--text); text-decoration: none; }
.health-card:hover { border-color: var(--line-strong); color: var(--text); }

/* ── Notices ── */
.notice { padding: 10px 14px; border-radius: 8px; font-size: 13.5px; border: 1px solid transparent; }
.notice.warn { background: #2a220e; border-color: #4a3a12; color: #ffe2a3; }
.notice.danger { background: #2c1411; border-color: #57241d; color: #ffc2b9; }
.notice.ok { background: #11281b; border-color: #1e4a31; color: #a8f5c8; }
.notice a { color: inherit; font-weight: 600; }

/* ── Grid tables ── */
.scroll { overflow-x: auto; }
.grid-table { min-width: 860px; }
.gr { display: grid; align-items: center; gap: 12px; padding: 10px 16px; border-bottom: 1px solid var(--line-soft); }
.grid-table > :last-child, .grid-table > :last-child .gr { border-bottom: 0; }
.gr.head { font: 11px var(--mono); letter-spacing: 0.05em; text-transform: uppercase; color: var(--muted); background: var(--sunk); border-bottom: 1px solid var(--line); }
.num { text-align: right; font-family: var(--mono); font-size: 12.5px; font-variant-numeric: tabular-nums; white-space: nowrap; }

.req { grid-template-columns: 78px 100px minmax(0, 1.6fr) 130px 80px 64px 64px 70px; }
.req-wrap { border-bottom: 1px solid var(--line-soft); }
.req-button { width: 100%; border: 0; border-radius: 0; background: transparent; color: inherit; font: inherit; font-weight: 400; text-align: left; border-bottom: 0; min-height: 0; }
.req-button:hover { background: #151920; }
.req-button.err { color: var(--danger-text); }
.req-detail { margin: 0; padding: 12px 16px 16px 106px; background: var(--sunk); display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px 24px; }
.req-detail dt { font: 11px var(--mono); color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.req-detail dd { margin: 2px 0 0; font: 12.5px var(--mono); word-break: break-word; }
.req-detail .wide { grid-column: 1 / -1; }
.bad-text { color: var(--danger-text); }

.conn { grid-template-columns: minmax(0, 1.1fr) minmax(0, 1.5fr) 120px minmax(0, 1fr) minmax(0, 1.4fr) 280px; }
.conn-wrap { border-bottom: 1px solid var(--line-soft); }
.conn-wrap .gr { border-bottom: 0; }
.conn-test { padding: 0 16px 12px; }
.keys { grid-template-columns: minmax(140px, 1.5fr) 100px 100px 80px 120px 80px 150px; }
.keys.revoked { color: var(--muted); }
/* The key name is a button (it opens Rename) but reads as the row's title. */
.key-name { max-width: 100%; overflow: hidden; text-overflow: ellipsis; justify-content: flex-start; min-height: 0; padding: 0; border: 0; background: transparent; color: inherit; font-weight: 600; text-decoration: underline dotted var(--muted); text-underline-offset: 3px; }
.key-name:hover { background: transparent; color: var(--accent-text); }

/* ── Routing rules ── */
.rule { grid-template-columns: 36px 92px minmax(0, 1.3fr) minmax(160px, 0.9fr) minmax(220px, 1.4fr) 164px; align-items: start; }
.rule > * { min-height: 36px; display: flex; align-items: center; }
.rule > .match, .rule > .dd { display: block; }
.rule.head > * { min-height: 0; }
.rule-group:empty { display: none; }
.rule-wrap { border-bottom: 1px solid var(--line-soft); }
.rule-group:last-child > .rule-wrap:last-child { border-bottom: 0; }
.rule-wrap > .gr { border-bottom: 0; }
.rule.fb { background: var(--sunk); padding-top: 6px; padding-bottom: 6px; }
.rule.fb .match { line-height: 36px; }
.match { display: grid; gap: 4px; min-width: 0; }
.match > .mono, .match > .muted { line-height: 36px; }
.match-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.match button { justify-self: start; }
.lift { position: relative; z-index: 12; }
.warnline { font-size: 12px; color: var(--warn-text); }
.warnline[hidden] { display: none; }

.dd { position: relative; min-width: 0; }
.dd-button, .combo { display: flex; align-items: center; gap: 8px; width: 100%; min-height: 36px; padding: 6px 10px; border-radius: 8px; border: 1px solid var(--line-strong); background: var(--bg); color: var(--text); font-weight: 400; text-align: left; }
.dd-button:hover, .combo:hover { background: var(--bg); border-color: #3a424e; }
.dd-button[aria-expanded="true"], .combo:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px rgb(184 243 74 / 0.18); }
.dd-button .placeholder { color: var(--muted); }
.combo { padding-top: 0; padding-bottom: 0; cursor: text; }
.combo.disabled { cursor: not-allowed; }
.combo-input { flex: 1; min-width: 0; border: 0; background: transparent; padding: 8px 0; font: 13px var(--mono); color: var(--text); box-shadow: none; }
.combo-input:focus { outline: none; box-shadow: none; }
.combo-input::placeholder { color: var(--text-2); }
.combo-input:disabled { background: transparent; cursor: not-allowed; }
.combo-input:disabled::placeholder { color: #6b7584; }
.menu { position: absolute; left: 0; top: calc(100% + 6px); width: 100%; min-width: 260px; max-height: 300px; overflow: auto; background: var(--surface-2); border: 1px solid #3a424e; border-radius: 10px; box-shadow: 0 16px 40px rgb(0 0 0 / 0.55); padding: 6px; z-index: 15; }
.menu[hidden] { display: none; }
.menu-meta { padding: 6px 10px 8px; font: 11.5px var(--mono); color: var(--muted); }
.menu-item { display: flex; align-items: center; gap: 8px; width: 100%; min-height: 36px; padding: 6px 10px; border: 0; border-radius: 6px; background: transparent; color: var(--text); font: inherit; font-size: 13px; font-weight: 400; text-align: left; cursor: pointer; }
.menu-item.mono { font-family: var(--mono); font-size: 12.5px; }
.menu-item:hover, .menu-item.active, .menu-item:focus-visible { background: #232932; outline: none; }
.menu-item.selected { color: var(--accent-text); }
.menu-item.selected .icon { color: var(--accent-text); }

.dirty-bar { position: sticky; bottom: 16px; z-index: 20; display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 10px 12px 10px 16px; background: var(--surface-3); border: 1px solid #3a424e; border-radius: 10px; box-shadow: 0 12px 32px rgb(0 0 0 / 0.5); }
.dirty-bar[hidden] { display: none; }

/* ── Buttons ── */
button {
  font: inherit; font-weight: 500; cursor: pointer; border-radius: 8px; min-height: 36px; padding: 7px 14px;
  border: 1px solid var(--line-strong); background: var(--surface-2); color: var(--text);
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; white-space: nowrap;
  transition: background-color 120ms, border-color 120ms;
}
button:hover { background: #20252d; }
button:disabled { opacity: 0.45; cursor: not-allowed; }
button.busy { cursor: progress; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--bg); font-weight: 600; }
button.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
button.primary:disabled { background: #3a414c; border-color: #3a414c; color: var(--muted); opacity: 1; }
button.danger { color: #ff9a8d; }
button.danger:hover { background: var(--danger-soft); }
button.ghost { border-color: transparent; background: transparent; color: var(--text-2); }
button.ghost:hover { color: var(--text); background: var(--surface-2); }
button.small { min-height: 30px; padding: 4px 10px; font-size: 12.5px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { min-height: 32px; padding: 4px 12px; border-radius: 999px; color: var(--text-2); font-size: 13px; font-weight: 400; }
.chip.on { border-color: var(--accent); color: var(--text); background: #20291a; }

/* ── Forms ── */
label { display: grid; gap: 6px; font-weight: 500; font-size: 13px; align-content: start; }
label .hint { font-weight: 400; color: var(--muted); font-size: 12.5px; }
label[hidden] { display: none; }
input, select {
  font: inherit; font-weight: 400; color: var(--text); background: var(--bg);
  border: 1px solid var(--line-strong); border-radius: 8px; padding: 8px 11px; width: 100%; min-width: 0; min-height: 38px;
}
input:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgb(184 243 74 / 0.18); }
input.mono { font: 13px var(--mono); }
input:disabled { color: var(--muted); }
.cell-input { min-height: 36px; padding: 6px 10px; }
.form { display: grid; gap: 14px; }
.form.narrow { max-width: 640px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; align-items: start; }
label.checkbox { display: flex; align-items: center; gap: 8px; font-weight: 400; }
label.checkbox input { width: auto; min-height: 0; accent-color: var(--accent); }
details.advanced summary { cursor: pointer; color: var(--muted); font-size: 13px; padding: 2px 0; }
details.advanced[open] summary { margin-bottom: 12px; }
.field-error { color: var(--danger-text); font-size: 13px; }
.field-error[hidden] { display: none; }
.test-result { font-size: 13px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.codeblock { margin: 0; background: #0b0d10; border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; font: 12.5px var(--mono); white-space: pre-wrap; word-break: break-all; color: #d6dbe2; }

.facts { margin: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1px; background: var(--line); }
.facts > div { background: var(--surface); padding: 12px 16px; }
.facts dt { font-size: 12px; color: var(--muted); }
.facts dd { margin: 2px 0 0; font: 13px var(--mono); word-break: break-all; }
.facts .env { font: 11px var(--mono); color: var(--accent-text); }

/* ── Auth screens ── */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.auth-card { width: min(400px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 28px; display: grid; gap: 18px; }
.auth-card .brand { padding: 0; }
.auth-card p { margin-top: 4px; }

/* ── Dialogs ── */
dialog {
  border: 1px solid var(--line-strong); border-radius: 12px; padding: 0; background: #14171c; color: var(--text);
  width: min(560px, calc(100vw - 32px)); box-shadow: 0 24px 64px rgb(0 0 0 / 0.6);
}
dialog::backdrop { background: rgb(5 6 8 / 0.72); }
dialog[open] { animation: pop 140ms ease-out; }
@keyframes pop { from { opacity: 0; transform: translateY(6px) scale(0.98); } }
.dialog-head { padding: 16px 20px; border-bottom: 1px solid var(--line); }
.dialog-head h2 { font-size: 16px; }
.dialog-body { padding: 18px 20px; display: grid; gap: 14px; max-height: 70vh; overflow-y: auto; }
.dialog-foot { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }

dialog.wide { width: min(760px, calc(100vw - 32px)); }
h3.sec { font: 11px var(--mono); letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.kv { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 6px 16px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.tbl { display: grid; grid-template-columns: minmax(0, 2fr) repeat(5, minmax(0, 1fr)); gap: 6px 12px; font-size: 12.5px; }
.tbl .th { font: 11px var(--mono); text-transform: uppercase; color: var(--muted); }
dialog.palette { width: min(620px, calc(100vw - 32px)); margin-top: 12vh; }
dialog.palette .dialog-body { padding: 0; gap: 0; }
.palette-input { border: 0; border-bottom: 1px solid var(--line); border-radius: 0; min-height: 52px; padding: 14px 18px; font-size: 15px; background: transparent; }
.palette-input:focus { box-shadow: none; }
.palette-list { padding: 6px 0; max-height: 360px; overflow: auto; }
.palette-item { display: flex; justify-content: space-between; width: 100%; min-height: 44px; padding: 8px 18px; border: 0; border-radius: 0; background: transparent; font-weight: 400; text-align: left; }
.palette-item:hover, .palette-item.active { background: var(--surface-3); }
.palette-empty { padding: 14px 18px; }

/* ── Toasts ── */
#toasts { position: fixed; bottom: 20px; right: 20px; display: grid; gap: 8px; z-index: 100; }
.toast { background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 8px; font-size: 13.5px; font-weight: 500; box-shadow: 0 8px 24px rgb(0 0 0 / 0.4); max-width: 380px; animation: pop 140ms ease-out; }
.toast.error { background: var(--danger); color: #1a0806; }

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

@media (max-width: 900px) {
  .rule.head { display: none; }
  .rule { grid-template-columns: 36px minmax(0, 1fr); }
  .rule > :nth-child(n + 3) { grid-column: 2; }
  .rule > :last-child { justify-content: flex-start; }
}

@media (max-width: 720px) {
  .rail { flex-basis: 100%; height: auto; position: static; border-right: 0; border-bottom: 1px solid var(--line); }
  .content { padding: 20px 16px 96px; }
  .form-grid, .match-pair { grid-template-columns: 1fr; }
  .req-detail { padding-left: 16px; }
  #toasts { left: 16px; right: 16px; }
}
