:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --text: #1b2330;
  --muted: #667180;
  --line: #e1e5ea;
  --accent: #c8102e;
  --accent-ink: #ffffff;
  --accent-soft: #fbe9ec;
  --ok: #1f7a4d;
  --ok-soft: #e5f4ec;
  --warn: #9a5b00;
  --warn-soft: #fff3df;
  --bad: #b42318;
  --bad-soft: #fdeceb;
  --info-soft: #eaf1fb;
  --focus: #2563eb;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 16px rgba(16, 24, 40, .06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11151b;
    --surface: #1a2028;
    --surface-2: #151a21;
    --text: #e6ebf1;
    --muted: #98a3b1;
    --line: #2a323d;
    --accent: #e0384f;
    --accent-soft: #3a1c22;
    --ok: #4cc38a;
    --ok-soft: #173326;
    --warn: #f0b45a;
    --warn-soft: #3a2c14;
    --bad: #f17066;
    --bad-soft: #3b1b19;
    --info-soft: #182638;
    --focus: #6ea0ff;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}
a { color: inherit; }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* --- brand & language switch --- */
.brand { font-weight: 700; font-size: 18px; letter-spacing: .2px; text-decoration: none; white-space: nowrap; }
.brand b { color: var(--accent); font-weight: 700; }
.langsw { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.langsw button { border: 0; background: transparent; padding: 4px 10px; font-size: 13px; font-weight: 600; color: var(--muted); cursor: pointer; }
.langsw button[aria-pressed="true"] { background: var(--text); color: var(--surface); }

/* --- auth layout --- */
.auth { min-height: 100vh; display: flex; flex-direction: column; align-items: center; padding: 16px; }
.auth-top { width: 100%; max-width: 440px; display: flex; justify-content: flex-end; }
.auth-card { width: 100%; max-width: 440px; margin: auto 0; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 28px 24px; }
.auth-card .brand { display: block; text-align: center; font-size: 22px; }
.auth-card .tagline { text-align: center; color: var(--muted); font-size: 13px; margin: 2px 0 22px; }
.auth-card h1 { font-size: 20px; margin: 0 0 6px; }
.auth-foot { color: var(--muted); font-size: 12px; padding: 16px 0 4px; text-align: center; }

/* --- app layout --- */
.top { position: sticky; top: 0; z-index: 10; background: var(--surface); border-bottom: 1px solid var(--line); }
.top-row { max-width: 1120px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.top-row .spacer { flex: 1; }
.who { color: var(--muted); font-size: 13px; max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; }
.nav a { text-decoration: none; padding: 7px 12px; border-radius: 8px; color: var(--muted); font-weight: 500; white-space: nowrap; }
.nav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); }
.nav a:hover { color: var(--text); }
main.page { max-width: 1120px; margin: 0 auto; padding: 20px 16px 48px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head h1 { font-size: 22px; margin: 0; }

@media (max-width: 719px) {
  .top-row { padding: 8px 16px; gap: 8px; }
  .nav { order: 10; width: 100%; margin: 0 -4px; flex-wrap: wrap; }
  .nav a { padding: 6px 10px; }
  .who { display: none; }
}

/* --- cards & text --- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }
.card + .card { margin-top: 16px; }
.card h2 { font-size: 17px; margin: 0 0 4px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
p { margin: 0 0 12px; }
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
.mod { padding: 16px; border: 1px dashed var(--line); border-radius: 10px; background: var(--surface-2); display: flex;
  justify-content: space-between; align-items: center; gap: 8px; color: var(--muted); }
.cols { display: grid; gap: 16px; grid-template-columns: 1fr; }
@media (min-width: 900px) { .cols { grid-template-columns: 1fr 1fr; } }

/* --- forms --- */
.field { margin-bottom: 14px; }
.field label, .label { display: block; font-weight: 600; font-size: 13px; margin-bottom: 5px; }
.hint { color: var(--muted); font-size: 12px; margin-top: 4px; }
.input, select.input { width: 100%; height: 42px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--surface); }
.input:focus { border-color: var(--focus); outline: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 20%, transparent); }
.input[aria-invalid="true"] { border-color: var(--bad); }
.input[readonly] { background: var(--surface-2); color: var(--muted); }
.input.code { font-size: 22px; letter-spacing: 6px; text-align: center; font-variant-numeric: tabular-nums; }
.pw { position: relative; }
.pw .input { padding-right: 76px; }
.pw button { position: absolute; right: 6px; top: 6px; height: 30px; border: 0; background: transparent; color: var(--muted);
  font-size: 12px; font-weight: 600; cursor: pointer; padding: 0 8px; }
.err { color: var(--bad); font-size: 13px; margin-top: 4px; }
.err:empty { display: none; }
.alert { border-radius: 8px; padding: 10px 12px; font-size: 14px; margin-bottom: 14px; }
.alert:empty { display: none; }
.alert.bad { background: var(--bad-soft); color: var(--bad); }
.alert.warn { background: var(--warn-soft); color: var(--warn); }
.alert.info { background: var(--info-soft); }
.rules { list-style: none; padding: 0; margin: 4px 0 14px; font-size: 13px; color: var(--muted); }
.rules li::before { content: "○"; display: inline-block; width: 20px; }
.rules li.ok { color: var(--ok); }
.rules li.ok::before { content: "✓"; }
.check { display: flex; gap: 8px; align-items: flex-start; margin: 12px 0; cursor: pointer; }
.check input { margin-top: 3px; width: 18px; height: 18px; }
.roles { display: grid; gap: 8px; }
.field .role-opt, .role-opt { display: flex; margin: 0; font-weight: 400; font-size: inherit; gap: 10px; align-items: flex-start; border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; cursor: pointer; }
.role-opt:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.role-opt input { margin-top: 4px; }
.role-opt b { display: block; font-size: 14px; }
.role-opt span { color: var(--muted); font-size: 12px; }

/* --- buttons --- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 40px; padding: 0 16px;
  border-radius: 8px; border: 1px solid var(--line); background: var(--surface); font-weight: 600; cursor: pointer;
  text-decoration: none; white-space: nowrap; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(.95); }
.btn.danger { color: var(--bad); }
.btn.block { width: 100%; height: 44px; }
.btn.sm { height: 32px; padding: 0 10px; font-size: 13px; font-weight: 500; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.btn.busy::before { content: ""; width: 14px; height: 14px; border: 2px solid currentColor; border-right-color: transparent;
  border-radius: 50%; animation: spin .7s linear infinite; }
.linkbtn { border: 0; background: none; padding: 0; color: var(--focus); cursor: pointer; font-size: 13px; text-decoration: underline; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.row.end { justify-content: flex-end; }
@keyframes spin { to { transform: rotate(360deg); } }

/* --- badges --- */
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--surface-2);
  color: var(--muted); border: 1px solid var(--line); white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.badge.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge.bad { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.badge.accent { background: var(--accent-soft); color: var(--accent); border-color: transparent; }

/* --- lists (users, audit) --- */
.list { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.lrow { display: grid; gap: 4px 16px; padding: 14px 16px; border-top: 1px solid var(--line); align-items: center; }
.lrow:first-child { border-top: 0; }
.lhead { background: var(--surface-2); color: var(--muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .3px; }
.lrow .c-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.users .lrow { grid-template-columns: minmax(180px, 2fr) 1.2fr 1.2fr 1.2fr auto; }
.audit .lrow { grid-template-columns: 140px 160px 1.4fr 2fr; }
.lrow .sub { color: var(--muted); font-size: 12px; }
.lrow.dim { opacity: .65; }
@media (max-width: 719px) {
  .lhead { display: none; }
  .users .lrow, .audit .lrow { grid-template-columns: 1fr; }
  .lrow [data-label]::before { content: attr(data-label) ": "; color: var(--muted); font-size: 12px; }
  .lrow .c-actions { justify-content: flex-start; margin-top: 6px; }
}
.empty { text-align: center; padding: 32px 16px; color: var(--muted); }
.skel { height: 56px; border-top: 1px solid var(--line); background: linear-gradient(90deg, var(--surface) 0, var(--surface-2) 50%, var(--surface) 100%);
  background-size: 200% 100%; animation: shimmer 1.2s infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* --- 2FA setup & recovery codes --- */
.steps { padding-left: 20px; margin: 0 0 12px; }
.steps li { margin-bottom: 10px; }
.qr { display: block; width: 200px; height: 200px; margin: 8px auto 12px; border-radius: 8px; background: #fff; padding: 4px; }
.secret { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 15px; letter-spacing: 1px; text-align: center;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; padding: 8px; overflow-wrap: anywhere; margin-bottom: 14px; }
.codes { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 12px 0; }
.codes code { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 16px; text-align: center; padding: 8px;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; letter-spacing: 1px; }
.linkbox { display: flex; gap: 8px; }
.linkbox .input { font-family: ui-monospace, Consolas, monospace; font-size: 12px; }

/* --- modal & toast --- */
.backdrop { position: fixed; inset: 0; background: rgba(10, 14, 20, .5); display: flex; align-items: center; justify-content: center;
  padding: 16px; z-index: 50; }
.modal { width: 100%; max-width: 480px; max-height: calc(100vh - 32px); overflow: auto; background: var(--surface); border-radius: var(--radius);
  border: 1px solid var(--line); padding: 22px 20px; }
.modal h2 { font-size: 18px; margin: 0 0 12px; }
.modal .row.end { margin-top: 16px; }
.toasts { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); display: grid; gap: 8px; z-index: 60;
  width: min(420px, calc(100vw - 32px)); }
.toast { background: var(--text); color: var(--surface); padding: 10px 14px; border-radius: 8px; font-size: 14px; box-shadow: var(--shadow); }
.toast.bad { background: var(--bad); color: #fff; }
.toast.warn { background: var(--warn-soft); color: var(--warn); border: 1px solid var(--warn); }
.boot { min-height: 100vh; display: flex; align-items: center; justify-content: center; color: var(--muted); }
.input.narrow { max-width: 280px; }
