:root {
  --bg: #f4f6fa;
  --panel: #ffffff;
  --text: #17202e;
  --muted: #5d6b80;
  --line: #e1e6ee;
  --brand: #1f5fd6;
  --brand-dark: #174aa8;
  --ok: #1d8a4a;
  --warn: #b26b00;
  --danger: #c42b2b;
  --danger-bg: #fdeeee;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 2px 8px rgba(16, 24, 40, .05);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f141c; --panel: #171e29; --text: #e6ebf2; --muted: #96a3b6; --line: #273142;
    --brand: #4d8af0; --brand-dark: #3a74d6; --ok: #4cc27f; --warn: #e6a23c; --danger: #f06a6a; --danger-bg: #3a1d1f;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.45; }
.hidden { display: none !important; }
a { color: var(--brand); }

.topbar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 20px;
  padding: 10px 24px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; white-space: nowrap; }
.logo { width: 28px; height: 28px; }
nav { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
nav a { padding: 7px 12px; border-radius: 8px; text-decoration: none; color: var(--muted); white-space: nowrap; }
nav a.active { background: var(--bg); color: var(--text); font-weight: 600; }
nav a.danger-link { color: var(--danger); }

main { max-width: 1180px; margin: 0 auto; padding: 24px; }
h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 16px; margin: 0 0 12px; }
.sub { color: var(--muted); margin: 0 0 20px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; margin-bottom: 18px; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.stat .label { color: var(--muted); font-size: 13px; }
.stat .value { font-size: 26px; font-weight: 650; margin-top: 2px; font-variant-numeric: tabular-nums; }
.stat .value.text { font-size: 17px !important; line-height: 1.3; margin-top: 6px; }
.stat .note { color: var(--muted); font-size: 12px; margin-top: 2px; }

.health { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 8px; }
.health div { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 8px; background: var(--bg); font-size: 14px; }
.dot { width: 9px; height: 9px; border-radius: 50%; flex: none; background: var(--danger); }
.dot.ok { background: var(--ok); }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover { background: var(--bg); }
.mono { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 13px; }
.table-wrap { overflow-x: auto; }

.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; background: var(--bg); color: var(--muted); border: 1px solid var(--line); white-space: nowrap; }
.badge.warn { color: var(--warn); }
.badge.ok { color: var(--ok); }

.toolbar { display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
input[type=text], input[type=password], input[type=search] {
  font: inherit; color: inherit; background: var(--panel); border: 1px solid var(--line); border-radius: 9px; padding: 9px 12px; min-width: 0;
}
input:focus-visible, button:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }
.toolbar input { flex: 1; min-width: 220px; }
label { display: block; font-weight: 600; font-size: 14px; margin: 14px 0 6px; }
label.check { display: flex; gap: 8px; align-items: center; font-weight: 500; }
.field { width: 100%; }
.code { letter-spacing: .3em; font-family: ui-monospace, Consolas, monospace; font-size: 18px; max-width: 180px; }

button { font: inherit; font-weight: 600; border: 0; border-radius: 9px; padding: 9px 16px; cursor: pointer; background: var(--brand); color: #fff; }
button:hover { background: var(--brand-dark); }
button:disabled { opacity: .55; cursor: progress; }
button.ghost { background: transparent; color: var(--text); border: 1px solid var(--line); }
button.ghost:hover { background: var(--bg); }
button.danger { background: var(--danger); }
button.danger:hover { filter: brightness(.92); background: var(--danger); }
button.small { padding: 5px 10px; font-size: 13px; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; }

.notice { border-left: 4px solid var(--warn); background: var(--bg); padding: 10px 14px; border-radius: 0 8px 8px 0; margin: 12px 0; font-size: 14px; }
.notice.danger { border-color: var(--danger); background: var(--danger-bg); }
.error { color: var(--danger); font-weight: 600; margin-top: 10px; min-height: 1.2em; }
dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 18px; margin: 0; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; word-break: break-all; }

.login { max-width: 400px; margin: 9vh auto; }
.login .logo { width: 48px; height: 48px; margin-bottom: 8px; }
.login button { width: 100%; margin-top: 18px; padding: 11px; }

dialog { border: 1px solid var(--line); border-radius: 14px; padding: 0; width: min(540px, 94vw); background: var(--panel); color: var(--text); box-shadow: 0 10px 40px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(10, 14, 22, .55); }
dialog .body { padding: 20px 22px; }
dialog .foot { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 22px; border-top: 1px solid var(--line); }

.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--panel); padding: 10px 18px; border-radius: 10px; font-weight: 600; z-index: 20; max-width: 90vw; }
.steps li { margin: 4px 0; }
.empty { color: var(--muted); padding: 18px 4px; }

@media (max-width: 720px) {
  .topbar { flex-wrap: wrap; padding: 10px 14px; gap: 8px; }
  nav { order: 3; flex: 1 1 100%; }
  #logout { margin-left: auto; }
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .stat .value { font-size: 22px; }
  main { padding: 14px; }
  .hide-sm { display: none; }
}
