:root {
  color-scheme: light dark;
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #e3e6eb;
  --text: #14181f;
  --muted: #667085;
  --accent: #2456e8;
  --accent-ink: #ffffff;
  --accent-soft: #e8eefe;
  --danger: #c62828;
  --danger-soft: #fdeaea;
  --ok: #157347;
  --ok-soft: #e3f4ea;
  --warn: #9a5b00;
  --warn-soft: #fff2d9;
  --info: #1a5fb4;
  --info-soft: #e3eefb;
  --neutral-soft: #eceef2;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);
  --radius: 12px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1117;
    --surface: #161b22;
    --surface-2: #1c232c;
    --border: #2a323d;
    --text: #e6eaf0;
    --muted: #8b95a5;
    --accent: #5b8cff;
    --accent-ink: #0b1220;
    --accent-soft: #1b2a4d;
    --danger: #ff7b72;
    --danger-soft: #3a1c1c;
    --ok: #4cc38a;
    --ok-soft: #14301f;
    --warn: #f0b752;
    --warn-soft: #3a2b10;
    --info: #79b0ff;
    --info-soft: #14283f;
    --neutral-soft: #222a34;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0 0 4px; letter-spacing: -0.01em; }
h2 { font-size: 1.05rem; margin: 0 0 12px; }
h3 { font-size: 0.95rem; margin: 0 0 8px; }
p { margin: 0 0 12px; }
code, .mono { font-family: var(--mono); font-size: 0.86em; }
code { background: var(--surface-2); padding: 1px 6px; border-radius: 5px; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.right { text-align: right; }
.hidden { display: none !important; }

/* Layout */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 1120px; margin: 0 auto; padding: 0 16px;
  display: flex; align-items: center; gap: 20px; min-height: 56px; flex-wrap: wrap;
}
.brand { font-weight: 700; letter-spacing: 0.02em; color: var(--text); display: flex; align-items: center; gap: 8px; }
.brand-mark { width: 22px; height: 22px; border-radius: 6px; background: var(--accent); display: inline-block; }
.brand small { font-weight: 500; color: var(--muted); letter-spacing: 0; }
.nav { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; }
.nav a {
  color: var(--muted); padding: 8px 12px; border-radius: 8px; font-weight: 500;
}
.nav a:hover { background: var(--surface-2); text-decoration: none; color: var(--text); }
.nav a.active { background: var(--accent-soft); color: var(--accent); }
.topbar-user { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 0.85rem; }
main { max-width: 1120px; margin: 0 auto; padding: 24px 16px 64px; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head .sub { color: var(--muted); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* Cards & grids */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow);
}
.card + .card { margin-top: 16px; }
.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.grid + .grid, .grid + .card, .card + .grid { margin-top: 16px; }
.stat .label { color: var(--muted); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.05em; font-weight: 600; }
.stat .value { font-size: 1.9rem; font-weight: 700; letter-spacing: -0.02em; line-height: 1.2; margin-top: 4px; }
.stat .foot { color: var(--muted); font-size: 0.82rem; margin-top: 2px; }

/* Buttons & forms */
.btn {
  appearance: none; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 8px 14px; border-radius: 9px; font: inherit; font-weight: 600; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px; line-height: 1.2;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: 0.55; 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 { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.sm { padding: 5px 10px; font-size: 0.85rem; }
.btn.danger-outline { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn.danger-outline:hover { background: var(--danger-soft); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

label.field { display: block; margin-bottom: 14px; }
label.field > span { display: block; font-weight: 600; font-size: 0.88rem; margin-bottom: 5px; }
label.field .hint { color: var(--muted); font-size: 0.82rem; margin-top: 4px; font-weight: 400; display: block; }
input[type=text], input[type=email], input[type=password], input[type=url], input[type=search], select, textarea {
  width: 100%; padding: 9px 12px; border-radius: 9px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: var(--accent); }
textarea { min-height: 84px; resize: vertical; }
.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row > * { flex: 1 1 200px; }
.toolbar { display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; align-items: center; }
.toolbar input, .toolbar select { width: auto; min-width: 180px; }
.toolbar .grow { flex: 1; }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
th {
  text-align: left; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--muted); font-weight: 600; padding: 8px 12px; border-bottom: 1px solid var(--border); white-space: nowrap;
}
td { padding: 11px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tbody tr.click { cursor: pointer; }
tbody tr.click:hover { background: var(--surface-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.empty { color: var(--muted); text-align: center; padding: 28px 12px; }

/* Badges */
.badge {
  display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 0.78rem; font-weight: 600; white-space: nowrap;
  background: var(--neutral-soft); color: var(--muted);
}
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.bad { background: var(--danger-soft); color: var(--danger); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.info { background: var(--info-soft); color: var(--info); }

/* Charts */
.chart { width: 100%; height: auto; display: block; }
.chart .bar { fill: var(--accent); opacity: 0.85; }
.chart .bar:hover { opacity: 1; }
.chart .axis, .chart .grid-line { stroke: var(--border); stroke-width: 1; }
.chart text { fill: var(--muted); font-size: 11px; font-family: inherit; }
.status-list { display: grid; gap: 10px; }
.status-row { display: grid; grid-template-columns: 150px 1fr 48px; gap: 10px; align-items: center; font-size: 0.88rem; }
.status-track { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.status-fill { height: 100%; border-radius: 99px; background: var(--accent); }
.status-fill.ok { background: var(--ok); }
.status-fill.bad { background: var(--danger); }
.status-fill.warn { background: var(--warn); }
.status-fill.neutral { background: var(--muted); }

/* Misc */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; padding: 0 0 14px 22px; }
.timeline li::before { content: ""; position: absolute; left: 4px; top: 6px; width: 9px; height: 9px; border-radius: 50%; background: var(--accent); }
.timeline li::after { content: ""; position: absolute; left: 8px; top: 16px; bottom: 0; width: 1px; background: var(--border); }
.timeline li:last-child::after { display: none; }
.timeline .t { color: var(--muted); font-size: 0.8rem; }
.kv { display: grid; grid-template-columns: 140px 1fr; gap: 8px 12px; font-size: 0.92rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-word; }
.copybox {
  display: flex; gap: 8px; align-items: center; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 9px; padding: 8px 10px;
}
.copybox code { background: none; padding: 0; flex: 1; overflow-wrap: anywhere; font-size: 0.85rem; }
.notice { padding: 12px 14px; border-radius: 9px; margin-bottom: 14px; font-size: 0.92rem; }
.notice.warn { background: var(--warn-soft); color: var(--warn); }
.notice.bad { background: var(--danger-soft); color: var(--danger); }
.notice.info { background: var(--info-soft); color: var(--info); }
.id-images { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 14px; }
.id-images figure { margin: 0; }
.id-images img { width: 100%; border-radius: 10px; border: 1px solid var(--border); background: var(--surface-2); display: block; min-height: 120px; object-fit: contain; }
.id-images figcaption { font-weight: 600; font-size: 0.85rem; margin-bottom: 6px; }
.qr-box { text-align: center; }
.qr-box img { width: 240px; height: 240px; image-rendering: pixelated; border: 1px solid var(--border); border-radius: 10px; background: #fff; padding: 8px; }

/* Auth screens */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.auth-card { width: 100%; max-width: 420px; }
.auth-card .brand { justify-content: center; font-size: 1.25rem; margin-bottom: 4px; }
.auth-card .tagline { text-align: center; color: var(--muted); margin-bottom: 20px; }
.tabs { display: flex; gap: 4px; background: var(--surface-2); padding: 4px; border-radius: 10px; margin-bottom: 18px; }
.tabs button { flex: 1; border: 0; background: transparent; color: var(--muted); padding: 8px; border-radius: 7px; font: inherit; font-weight: 600; cursor: pointer; }
.tabs button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

/* Modal & toast */
.overlay { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.5); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 100; }
.modal { background: var(--surface); border-radius: var(--radius); max-width: 520px; width: 100%; padding: 22px; max-height: 90vh; overflow: auto; border: 1px solid var(--border); }
.modal h2 { margin-bottom: 10px; }
.modal .modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.toasts { position: fixed; bottom: 16px; right: 16px; display: grid; gap: 8px; z-index: 200; }
.toast { background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 9px; font-size: 0.9rem; box-shadow: 0 6px 20px rgba(0,0,0,.25); max-width: 340px; }
.toast.bad { background: var(--danger); color: #fff; }

@media (max-width: 640px) {
  .status-row { grid-template-columns: 110px 1fr 40px; }
  .kv { grid-template-columns: 1fr; gap: 2px 0; }
  .kv dd { margin-bottom: 8px; }
  main { padding-top: 16px; }
}
