:root {
  --bg: #f4f6f9; --panel: #ffffff; --panel2: #f9fafb; --text: #17202b; --muted: #5d6b7a; --line: #dfe4ea;
  --brand: #1f5fbf; --brand-ink: #ffffff; --ok: #16794a; --ok-bg: #e3f5ec; --warn: #9a5b00; --warn-bg: #fff2dc;
  --bad: #b3261e; --bad-bg: #fde7e5; --info-bg: #e6eefb; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
  --radius: 10px; --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0f141a; --panel: #171e27; --panel2: #1c2530; --text: #e6ebf1; --muted: #9aa8b8; --line: #2a3441;
    --brand: #5b9bff; --brand-ink: #0b1220; --ok: #52d596; --ok-bg: #12301f; --warn: #f0b457; --warn-bg: #33270f;
    --bad: #ff8a80; --bad-bg: #3a1714; --info-bg: #14233b; --shadow: none; }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
h1 { font-size: 22px; margin: 0 0 4px; } h2 { font-size: 16px; margin: 0 0 12px; } h3 { font-size: 14px; margin: 0 0 8px; }
a { color: var(--brand); }
code, .mono { font-family: var(--mono); font-size: 12.5px; }
.muted { color: var(--muted); } .small { font-size: 12px; } .right { text-align: right; } .nowrap { white-space: nowrap; }
.noscript { padding: 24px; }

/* login / wizard */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.auth-card { width: 100%; max-width: 420px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 28px; box-shadow: var(--shadow); }
.auth-card h1 { font-size: 20px; } .brand { display: flex; gap: 10px; align-items: center; margin-bottom: 18px; font-weight: 650; }
.logo { width: 34px; height: 34px; border-radius: 9px; background: var(--brand); color: var(--brand-ink); display: grid; place-items: center; font-weight: 800; }
.qr { display: block; width: 200px; height: 200px; margin: 12px auto; background: #fff; padding: 6px; border-radius: 8px; border: 1px solid var(--line); }

/* shell */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.side { background: var(--panel); border-right: 1px solid var(--line); padding: 16px 12px; display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100vh; }
.side .brand { padding: 0 8px 14px; margin: 0; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px; color: var(--text); text-decoration: none; font-weight: 520; }
.nav a:hover { background: var(--panel2); } .nav a.active { background: var(--info-bg); color: var(--brand); }
.side .who { margin-top: auto; border-top: 1px solid var(--line); padding: 12px 8px 0; }
.main { padding: 24px 28px 48px; min-width: 0; max-width: 1280px; }
.page-head { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-start; justify-content: space-between; margin-bottom: 18px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; } .side { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; }
  .side .who { margin: 0 0 0 auto; border: 0; padding: 0; } .nav { display: flex; flex-wrap: wrap; } .main { padding: 16px; }
}

/* cards, tables, forms */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); margin-bottom: 16px; }
.grid { display: grid; gap: 14px; } .g2 { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); } .g4 { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.stat .v { font-size: 24px; font-weight: 700; } .stat .l { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--panel2); border: 1px solid var(--line); margin: 0 4px 2px 0; }
.badge.ok { background: var(--ok-bg); color: var(--ok); border-color: transparent; } .badge.bad { background: var(--bad-bg); color: var(--bad); border-color: transparent; }
.badge.warn { background: var(--warn-bg); color: var(--warn); border-color: transparent; } .badge.info { background: var(--info-bg); color: var(--brand); border-color: transparent; }
label { display: block; font-weight: 600; margin: 12px 0 4px; }
.hint { color: var(--muted); font-size: 12px; margin-top: 3px; font-weight: 400; }
input[type=text], input[type=password], input[type=url], input[type=number], select, textarea {
  width: 100%; padding: 9px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); color: var(--text); font: inherit; }
textarea { min-height: 70px; font-family: var(--mono); font-size: 12.5px; }
input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }
.row { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 0 14px; }
.check { display: flex; gap: 8px; align-items: center; font-weight: 500; margin: 6px 0; } .check input { width: auto; }
button, .btn { font: inherit; font-weight: 600; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel); color: var(--text); cursor: pointer; text-decoration: none; display: inline-block; }
button:hover, .btn:hover { background: var(--panel2); }
button.primary, .btn.primary { background: var(--brand); color: var(--brand-ink); border-color: transparent; } button.primary:hover { filter: brightness(1.08); }
button.danger { color: var(--bad); } button.danger.solid { background: var(--bad); color: #fff; border-color: transparent; }
button.sm { padding: 4px 9px; font-size: 12.5px; } button:disabled { opacity: .55; cursor: not-allowed; }
.alert { padding: 10px 12px; border-radius: 8px; margin: 10px 0; border: 1px solid transparent; }
.alert.err { background: var(--bad-bg); color: var(--bad); } .alert.ok { background: var(--ok-bg); color: var(--ok); }
.alert.warn { background: var(--warn-bg); color: var(--warn); } .alert.info { background: var(--info-bg); color: var(--brand); }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 18px; } .kv dt { color: var(--muted); } .kv dd { margin: 0; word-break: break-word; }
.secret { display: flex; gap: 8px; align-items: center; } .secret code { flex: 1; padding: 9px 10px; border: 1px dashed var(--warn); border-radius: 8px; background: var(--warn-bg); word-break: break-all; user-select: all; }
.steps { list-style: none; margin: 0; padding: 0; } .steps li { display: grid; grid-template-columns: 24px 190px 1fr auto; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line); align-items: start; }
.steps li:last-child { border-bottom: 0; } .dot { width: 14px; height: 14px; border-radius: 50%; margin-top: 4px; background: var(--muted); }
.dot.ok { background: var(--ok); } .dot.bad { background: var(--bad); }
.chart { width: 100%; height: auto; display: block; } .chart text { fill: var(--muted); font-size: 11px; } .bar-ok { fill: var(--brand); } .bar-err { fill: var(--bad); }
.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; margin-bottom: 14px; } .filters > div { min-width: 150px; } .filters label { margin-top: 0; }
.perm-matrix td, .perm-matrix th { text-align: center; } .perm-matrix td:first-child, .perm-matrix th:first-child { text-align: left; }

/* dialog + toast */
dialog { border: 1px solid var(--line); border-radius: 14px; background: var(--panel); color: var(--text); padding: 0; width: min(640px, calc(100vw - 24px)); box-shadow: 0 20px 60px rgba(0,0,0,.35); }
dialog::backdrop { background: rgba(10, 16, 24, .55); }
.dlg-head { padding: 16px 20px; border-bottom: 1px solid var(--line); font-weight: 700; font-size: 16px; }
.dlg-body { padding: 8px 20px 4px; max-height: 70vh; overflow: auto; } .dlg-foot { padding: 14px 20px; display: flex; justify-content: flex-end; gap: 8px; border-top: 1px solid var(--line); margin-top: 10px; }
#toasts { position: fixed; right: 16px; bottom: 16px; display: grid; gap: 8px; z-index: 50; }
.toast { padding: 10px 14px; border-radius: 8px; background: var(--text); color: var(--bg); box-shadow: 0 6px 20px rgba(0,0,0,.3); max-width: 360px; }
.toast.err { background: var(--bad); color: #fff; }
.empty { padding: 28px; text-align: center; color: var(--muted); }

/* form action rows: a clean gap above, buttons aligned on one line; on the sign-in card the primary action is full width */
.form-actions { margin-top: 20px; align-items: stretch; }
.auth-card .form-actions { flex-direction: column; }
.auth-card .form-actions button { width: 100%; padding: 11px 14px; }
.auth-card .form-actions button + button { margin-top: 0; }
.auth-card form { margin-top: 4px; }

.codeblock { background: #0f1b2d; color: #e6edf7; border-radius: 8px; padding: 10px 12px; overflow-x: auto; font: 12.5px/1.5 var(--mono); margin: 8px 0; white-space: pre; }
.codeblock code { background: none; border: 0; padding: 0; color: inherit; }
details summary { cursor: pointer; font-weight: 600; margin: 8px 0; }
