:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --line: #e1e4ea;
  --text: #1b2230;
  --muted: #5d6677;
  --brand: #1f4fd1;
  --brand-ink: #ffffff;
  --brand-soft: #e8eefc;
  --ok: #157f4b;
  --ok-soft: #e4f4ea;
  --warn: #9a5b00;
  --warn-soft: #fdf1dc;
  --bad: #b42318;
  --bad-soft: #fde8e6;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, "Noto Sans", "Malgun Gothic", sans-serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151b; --surface: #1a1e26; --surface-2: #20252f; --line: #2d3340; --text: #e6e9ef; --muted: #9aa3b2;
    --brand: #6d93ff; --brand-ink: #0c1020; --brand-soft: #1e2a4a; --ok: #4fc483; --ok-soft: #173326;
    --warn: #e7a93b; --warn-soft: #3a2c12; --bad: #ff7a6e; --bad-soft: #3d1a17;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.5; }
a { color: var(--brand); }
h1 { font-size: 1.4rem; margin: 0 0 .25rem; }
h2 { font-size: 1.1rem; margin: 1.5rem 0 .5rem; }
p { margin: .4rem 0; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
[hidden] { display: none !important; }

/* ---- Auth pages ---- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.auth-card { width: 100%; max-width: 420px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 28px; box-shadow: var(--shadow); }
.brand { display: flex; align-items: center; gap: 10px; margin-bottom: 18px; font-weight: 600; }
.brand-mark { width: 30px; height: 30px; border-radius: 7px; background: var(--brand); color: var(--brand-ink); display: grid; place-items: center; font-weight: 700; font-size: 14px; }
.step { margin-top: 12px; }
.qr { background: #fff; padding: 8px; border-radius: 8px; width: 200px; margin: 10px auto; border: 1px solid var(--line); }
.qr svg { display: block; width: 100%; height: auto; }
.secret { font-family: ui-monospace, Consolas, monospace; background: var(--surface-2); border: 1px solid var(--line); padding: 6px 8px; border-radius: 6px; word-break: break-all; font-size: .9rem; }
.codes { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 16px; font-family: ui-monospace, Consolas, monospace; background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; padding: 12px 16px; margin: 10px 0; }

/* ---- Forms ---- */
label { display: block; font-weight: 600; font-size: .9rem; margin: 14px 0 4px; }
input[type=text], input[type=email], input[type=password], input:not([type]), select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); color: var(--text); font: inherit;
}
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }
input.code { font-size: 1.4rem; letter-spacing: .3em; text-align: center; font-family: ui-monospace, Consolas, monospace; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 400; margin-top: 12px; }
.hint { font-size: .82rem; color: var(--muted); margin-top: 4px; }
button, .btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 9px 16px; border-radius: 6px; border: 1px solid transparent;
  font: inherit; font-weight: 600; cursor: pointer; background: var(--brand); color: var(--brand-ink); text-decoration: none;
}
button.block { width: 100%; margin-top: 18px; }
button.secondary, .btn.secondary { background: var(--surface); color: var(--text); border-color: var(--line); }
button.danger { background: var(--surface); color: var(--bad); border-color: var(--line); }
button.link { background: none; border: 0; color: var(--brand); padding: 0; font-weight: 500; }
button.small { padding: 5px 10px; font-size: .85rem; }
button:disabled { opacity: .55; cursor: default; }
.msg { margin-top: 12px; padding: 9px 12px; border-radius: 6px; font-size: .9rem; }
.msg.error { background: var(--bad-soft); color: var(--bad); }
.msg.ok { background: var(--ok-soft); color: var(--ok); }
.msg.info { background: var(--brand-soft); color: var(--text); }

/* ---- App shell ---- */
.shell { display: grid; grid-template-columns: 230px 1fr; min-height: 100vh; }
.side { background: var(--surface); border-right: 1px solid var(--line); padding: 18px 12px; display: flex; flex-direction: column; gap: 2px; }
.side .brand { padding: 0 8px; }
.side .group { font-size: .75rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 16px 8px 4px; }
.side a.nav { display: block; padding: 7px 10px; border-radius: 6px; color: var(--text); text-decoration: none; }
.side a.nav:hover { background: var(--surface-2); }
.side a.nav.active { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.side .spacer { flex: 1; }
.side .who { padding: 10px 8px; border-top: 1px solid var(--line); font-size: .88rem; }
.main { padding: 24px 28px; min-width: 0; }
.topbar { display: none; }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 12px 0; }
.toolbar .grow { flex: 1; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; margin-top: 12px; }
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { background: var(--surface-2); font-weight: 600; font-size: .82rem; color: var(--muted); white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
td.actions { white-space: nowrap; text-align: right; }
.pill { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: .78rem; font-weight: 600; }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.info { background: var(--brand-soft); color: var(--brand); }
.grid-select { min-width: 110px; padding: 5px 6px; font-size: .85rem; }

dialog { border: 1px solid var(--line); border-radius: 12px; padding: 0; width: min(520px, calc(100vw - 32px)); background: var(--surface); color: var(--text); }
dialog::backdrop { background: rgba(10, 14, 22, .45); }
dialog form, dialog .body { padding: 22px; }
dialog .foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.access-rows { display: grid; grid-template-columns: 1fr 140px; gap: 6px 12px; align-items: center; margin-top: 6px; }
.access-rows label { margin: 0; font-weight: 400; }

@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .side { display: none; position: fixed; inset: 0 30% 0 0; z-index: 10; }
  .side.open { display: flex; }
  .topbar { display: flex; align-items: center; gap: 10px; padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--line); }
  .main { padding: 16px; }
}

/* Utilities (no inline styles: the CSP forbids them) */
.card-link { text-decoration: none; color: inherit; }
.card-link:hover { border-color: var(--brand); }
.narrow { max-width: 560px; }
h2.first { margin-top: 0; }
.gap-top { margin-top: 16px; }
.w-180 { max-width: 180px; }
.w-240 { max-width: 240px; }
.w-280 { max-width: 280px; }
.nowrap { white-space: nowrap; }
td.detail { max-width: 320px; word-break: break-word; }
