:root {
  --bg: #f4f5f2;
  --surface: #ffffff;
  --sunken: #eceee9;
  --line: #dcdfd7;
  --text: #1b211d;
  --muted: #647067;
  --accent: #0b7a53;
  --accent-ink: #ffffff;
  --accent-soft: #e0f2e9;
  --danger: #b3261e;
  --danger-soft: #fbe9e7;
  --warn: #8a5a00;
  --warn-soft: #fdf0d0;
  --info: #1f5fa8;
  --info-soft: #e3eefb;
  --radius: 10px;
  --mono: ui-monospace, "Cascadia Code", Consolas, Menlo, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121512;
    --surface: #1a1e1b;
    --sunken: #222723;
    --line: #2f3631;
    --text: #e7ebe6;
    --muted: #98a39b;
    --accent: #3ecf8e;
    --accent-ink: #062416;
    --accent-soft: #16332a;
    --danger: #ff8a80;
    --danger-soft: #3a1f1d;
    --warn: #f2c66d;
    --warn-soft: #3a2f14;
    --info: #8fbcf5;
    --info-soft: #1a2a3f;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
}
h1, h2, h3 { margin: 0; line-height: 1.25; font-weight: 650; }
h1 { font-size: 22px; letter-spacing: -0.01em; }
h2 { font-size: 16px; }
p { margin: 0; }
a { color: var(--accent); }
code, pre, .mono { font-family: var(--mono); font-size: 13px; }
pre {
  margin: 0; padding: 14px 16px; overflow-x: auto;
  background: var(--sunken); border-radius: 8px; line-height: 1.55;
}
[hidden] { display: none !important; }

/* ---------- layout ---------- */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.side {
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: 4px;
  padding: 20px 12px; background: var(--surface); border-right: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; padding: 0 10px 18px; font-weight: 700; font-size: 16px; }
.brand-mark {
  width: 28px; height: 28px; border-radius: 8px; background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center; font-size: 13px; font-weight: 800;
}
.nav a {
  display: block; padding: 8px 12px; border-radius: 8px;
  color: var(--muted); text-decoration: none; font-weight: 500;
}
.nav a:hover { background: var(--sunken); color: var(--text); }
.nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav-label { padding: 14px 12px 4px; font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.side-foot { margin-top: auto; padding: 12px 10px 0; border-top: 1px solid var(--line); font-size: 13px; color: var(--muted); }
.side-foot strong { display: block; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.main { padding: 28px 32px 56px; min-width: 0; max-width: 1180px; width: 100%; }
.head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.head p { color: var(--muted); margin-top: 4px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grid { display: grid; gap: 16px; }
.cols-4 { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.cols-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.stack { display: flex; flex-direction: column; gap: 16px; }

/* ---------- components ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; }
.card > h2 { margin-bottom: 12px; }
.stat-label { color: var(--muted); font-size: 13px; }
.stat-value { font-size: 28px; font-weight: 650; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.stat-sub { color: var(--muted); font-size: 13px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 550; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--sunken); }
.btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn:disabled { opacity: 0.55; cursor: default; }

label { display: block; font-weight: 550; font-size: 13.5px; margin-bottom: 5px; }
.hint { color: var(--muted); font-size: 12.5px; margin-top: 4px; font-weight: 400; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=url],
input[type=datetime-local], input[type=search], input[type=file], select, textarea {
  width: 100%; padding: 8px 11px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text); font: inherit;
}
textarea { min-height: 120px; resize: vertical; }
.field { margin-bottom: 14px; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; margin: 0; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 0 14px; }

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 14px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--line); }
th { font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); font-weight: 600; background: var(--sunken); white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
td.actions { white-space: nowrap; text-align: right; }
td.clip { max-width: 340px; overflow-wrap: anywhere; }
.muted { color: var(--muted); }
.empty { padding: 36px 20px; text-align: center; color: var(--muted); }

.badge { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: 12px; font-weight: 600; background: var(--sunken); color: var(--muted); white-space: nowrap; }
.badge.ok { background: var(--accent-soft); color: var(--accent); }
.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); }

.token { display: inline-flex; align-items: center; gap: 6px; }
.token code { background: var(--sunken); padding: 3px 8px; border-radius: 6px; overflow-wrap: anywhere; }
.pager { display: flex; justify-content: space-between; align-items: center; margin-top: 12px; color: var(--muted); font-size: 13px; }

/* ---------- modal / toast ---------- */
.modal { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 16px; background: rgb(0 0 0 / 0.45); }
.dialog { width: min(520px, 100%); max-height: calc(100vh - 32px); overflow-y: auto; background: var(--surface); border-radius: 14px; padding: 22px 24px; box-shadow: 0 20px 60px rgb(0 0 0 / 0.3); }
.dialog h2 { font-size: 18px; margin-bottom: 16px; }
.dialog-foot { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
.qr { display: grid; place-items: center; min-height: 300px; background: #fff; border-radius: 10px; border: 1px solid var(--line); }
.qr img { width: 280px; height: 280px; }
.pair-code { font: 700 30px/1 var(--mono); letter-spacing: 0.18em; text-align: center; padding: 26px 0; color: var(--text); }
.toast { position: fixed; bottom: 24px; left: 50%; translate: -50% 0; z-index: 30; padding: 10px 18px; border-radius: 10px; background: var(--text); color: var(--bg); font-weight: 550; box-shadow: 0 8px 30px rgb(0 0 0 / 0.25); max-width: calc(100vw - 32px); }
.toast.error { background: var(--danger); color: #fff; }

/* ---------- auth ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.auth-card { width: min(400px, 100%); }
.auth-card .brand { padding: 0 0 18px; font-size: 18px; }
.auth-card h1 { margin-bottom: 4px; }
.auth-card .sub { color: var(--muted); margin-bottom: 20px; }
.auth-card .btn { width: 100%; margin-top: 4px; }
.auth-switch { margin-top: 16px; text-align: center; color: var(--muted); font-size: 14px; }

@media (max-width: 820px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 10px 12px; border-right: 0; border-bottom: 1px solid var(--line); }
  .brand { padding: 0 8px 0 4px; }
  .nav { display: flex; gap: 2px; overflow-x: auto; flex: 1 1 100%; order: 3; }
  .nav a { white-space: nowrap; padding: 6px 10px; }
  .nav-label, .side-foot strong { display: none; }
  .side-foot { margin: 0 0 0 auto; padding: 0; border: 0; }
  .main { padding: 20px 16px 48px; }
}
