/* UsChat Admin. Served under a strict CSP: no inline styles anywhere, everything lives here. */

:root {
  color-scheme: light dark;

  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;

  --bg: #f5f7f7;
  --surface: #ffffff;
  --surface-2: #f0f3f3;
  --surface-hover: #f6f8f8;
  --border: #e1e6e6;
  --border-strong: #c9d1d1;
  --text: #15191b;
  --text-muted: #5b6569;
  --text-faint: #7d878b;

  --accent: #0f9d76;            /* brand: marks, focus, meters */
  --accent-strong: #0b7d5f;     /* button fill / link text (AA on white) */
  --accent-strong-hover: #096b51;
  --on-accent: #ffffff;
  --accent-soft: #e2f4ee;
  --accent-soft-text: #0a6a50;

  --danger: #c0322d;
  --danger-hover: #a52824;
  --on-danger: #ffffff;
  --danger-soft: #fdecea;
  --danger-soft-text: #a3241f;

  --warn-soft: #fdf2d9;
  --warn-soft-text: #85560a;
  --info-soft: #e7effc;
  --info-soft-text: #1f4c9e;
  --neutral-soft: #edf0f1;
  --neutral-soft-text: #485256;

  --focus: 0 0 0 3px color-mix(in srgb, var(--accent) 45%, transparent);
  --shadow-sm: 0 1px 2px rgb(16 24 28 / .06);
  --shadow: 0 1px 2px rgb(16 24 28 / .05), 0 4px 16px rgb(16 24 28 / .06);
  --shadow-lg: 0 12px 40px rgb(16 24 28 / .18), 0 2px 6px rgb(16 24 28 / .08);
  --backdrop: rgb(10 16 18 / .45);

  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1213;
    --surface: #161b1d;
    --surface-2: #1d2325;
    --surface-hover: #1b2123;
    --border: #283033;
    --border-strong: #384245;
    --text: #e6eaeb;
    --text-muted: #9ba6aa;
    --text-faint: #7a8589;

    --accent: #2fbf93;
    --accent-strong: #35c99c;
    --accent-strong-hover: #52d6ad;
    --on-accent: #04261c;
    --accent-soft: #113329;
    --accent-soft-text: #74e0bd;

    --danger: #c63a35;
    --danger-hover: #d64c46;
    --on-danger: #ffffff;
    --danger-soft: #3a1918;
    --danger-soft-text: #ff9f98;

    --warn-soft: #3a2d10;
    --warn-soft-text: #f2c565;
    --info-soft: #172540;
    --info-soft-text: #9dbcff;
    --neutral-soft: #242b2e;
    --neutral-soft-text: #b5bfc2;

    --shadow-sm: 0 1px 2px rgb(0 0 0 / .4);
    --shadow: 0 1px 2px rgb(0 0 0 / .35), 0 4px 16px rgb(0 0 0 / .25);
    --shadow-lg: 0 16px 48px rgb(0 0 0 / .55), 0 2px 6px rgb(0 0 0 / .3);
    --backdrop: rgb(0 0 0 / .6);
  }
}

/* ------------------------------------------------------------------ base */

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3 { margin: 0; line-height: 1.25; font-weight: 650; letter-spacing: -.01em; }
p { margin: 0; }
code, kbd, .mono { font-family: var(--mono); }
b, strong { font-weight: 600; }
a { color: var(--accent-strong); }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
::selection { background: color-mix(in srgb, var(--accent) 30%, transparent); }

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0);
  white-space: nowrap; border: 0;
}

.skip-link {
  position: absolute; left: 12px; top: -48px; z-index: 100;
  padding: 8px 14px; border-radius: var(--radius-sm);
  background: var(--accent-strong); color: var(--on-accent); text-decoration: none; font-weight: 600;
}
.skip-link:focus { top: 12px; }

.muted { color: var(--text-muted); }
.hint { color: var(--text-muted); font-size: 13px; }
.icon { width: 18px; height: 18px; flex: none; }

.container { width: 100%; max-width: 1180px; margin: 0 auto; padding: 0 24px; }

/* ------------------------------------------------------------------ brand */

.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--accent); }
.brand-mark { width: 30px; height: 30px; flex: none; }
.brand-name { color: var(--text); font-weight: 700; font-size: 17px; letter-spacing: -.01em; white-space: nowrap; }
.brand-sub { color: var(--text-muted); font-weight: 500; }
.brand-lg .brand-mark { width: 40px; height: 40px; }
.brand-lg .brand-name { font-size: 20px; }

/* ------------------------------------------------------------------ buttons */

.btn {
  --btn-bg: var(--surface);
  --btn-fg: var(--text);
  --btn-border: var(--border-strong);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 38px; padding: 0 16px;
  border: 1px solid var(--btn-border); border-radius: var(--radius-sm);
  background: var(--btn-bg); color: var(--btn-fg);
  font: inherit; font-weight: 600; font-size: 14px; line-height: 1.2;
  white-space: nowrap; cursor: pointer; user-select: none;
  transition: background-color .12s, border-color .12s, color .12s, box-shadow .12s;
}
.btn:focus-visible { outline: none; box-shadow: var(--focus); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .55; cursor: not-allowed; }

.btn-primary { --btn-bg: var(--accent-strong); --btn-fg: var(--on-accent); --btn-border: var(--accent-strong); }
.btn-primary:not(:disabled):hover { --btn-bg: var(--accent-strong-hover); --btn-border: var(--accent-strong-hover); }
.btn-secondary:not(:disabled):hover { --btn-bg: var(--surface-2); }
.btn-ghost { --btn-bg: transparent; --btn-border: transparent; --btn-fg: var(--text-muted); }
.btn-ghost:not(:disabled):hover { --btn-bg: var(--surface-2); --btn-fg: var(--text); }
.btn-danger { --btn-bg: var(--danger); --btn-fg: var(--on-danger); --btn-border: var(--danger); }
.btn-danger:not(:disabled):hover { --btn-bg: var(--danger-hover); --btn-border: var(--danger-hover); }

.btn-sm { min-height: 32px; padding: 0 12px; font-size: 13px; }
.btn-lg { min-height: 46px; font-size: 15px; }
.btn-block { width: 100%; }

.btn.is-busy { position: relative; color: transparent !important; pointer-events: none; opacity: 1; cursor: progress; }
.btn.is-busy > * { visibility: hidden; }
.btn.is-busy::after {
  content: ""; position: absolute; inset: 0; margin: auto;
  width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid var(--btn-fg); border-right-color: transparent;
  animation: spin .7s linear infinite;
}

.link-btn {
  padding: 2px 4px; margin: -2px -4px;
  border: 0; border-radius: 4px; background: none;
  color: var(--accent-strong); font: inherit; font-weight: 600; cursor: pointer;
  text-decoration: underline; text-decoration-color: color-mix(in srgb, currentColor 35%, transparent); text-underline-offset: 3px;
}
.link-btn:hover { text-decoration-color: currentColor; }

/* ------------------------------------------------------------------ forms */

.field { display: grid; gap: 6px; margin: 0; padding: 0; border: 0; min-width: 0; }
.label { font-size: 13px; font-weight: 600; color: var(--text); padding: 0; }
legend.label { margin-bottom: 6px; }

.input {
  width: 100%; min-height: 40px; padding: 8px 12px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text);
  font: inherit; font-size: 15px;
  transition: border-color .12s, box-shadow .12s;
}
.input::placeholder { color: var(--text-faint); }
.input:focus { outline: none; border-color: var(--accent); box-shadow: var(--focus); }
.input[aria-invalid="true"] { border-color: var(--danger); }
.input[readonly] { background: var(--surface-2); }
.input-mono { font-family: var(--mono); font-size: 14px; }
.input-code { font-family: var(--mono); font-size: 22px; letter-spacing: .3em; text-align: center; min-height: 50px; }
.input-invite { letter-spacing: .12em; text-transform: uppercase; font-size: 19px; }
.input-code::placeholder { letter-spacing: .3em; }

.input-prefix { display: flex; align-items: stretch; }
.input-prefix > span {
  display: grid; place-items: center; padding: 0 10px;
  border: 1px solid var(--border-strong); border-right: 0;
  border-radius: var(--radius-sm) 0 0 var(--radius-sm);
  background: var(--surface-2); color: var(--text-muted);
}
.input-prefix > .input { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }

.stack { display: grid; gap: 14px; }
.inline-form { display: flex; gap: 8px; }
.inline-form .input { min-width: 0; }

.radio-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.radio-card { position: relative; display: flex; gap: 10px; align-items: flex-start; padding: 12px; border: 1px solid var(--border-strong); border-radius: var(--radius); cursor: pointer; background: var(--surface); }
.radio-card > span { display: grid; gap: 2px; }
.radio-card input { margin: 3px 0 0; accent-color: var(--accent-strong); }
.radio-card:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.radio-card:has(input:focus-visible) { box-shadow: var(--focus); }
.radio-card:has(input:disabled) { opacity: .6; cursor: not-allowed; }

/* ------------------------------------------------------------------ banners, badges */

.banner { padding: 10px 12px; border-radius: var(--radius-sm); font-size: 14px; }
.banner-error { background: var(--danger-soft); color: var(--danger-soft-text); }
.banner-info { background: var(--info-soft); color: var(--info-soft-text); }

.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px 9px; border-radius: 999px;
  font-size: 12.5px; font-weight: 600; line-height: 1.6; white-space: nowrap;
  background: var(--neutral-soft); color: var(--neutral-soft-text);
}
.badge-dot::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-active { background: var(--accent-soft); color: var(--accent-soft-text); }
.badge-pending { background: var(--warn-soft); color: var(--warn-soft-text); }
.badge-locked { background: var(--danger-soft); color: var(--danger-soft-text); }
.badge-admin { background: var(--info-soft); color: var(--info-soft-text); }
.badge-you { background: transparent; border: 1px solid var(--border-strong); color: var(--text-muted); padding: 0 7px; font-size: 11.5px; line-height: 1.5; }

.kbd {
  display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 5px;
  border: 1px solid var(--border-strong); border-bottom-width: 2px; border-radius: 4px;
  font-size: 12px; color: var(--text-faint); background: var(--surface);
}

/* ------------------------------------------------------------------ loading */

.view-loading { display: grid; place-items: center; min-height: 100vh; }
.spinner {
  width: 28px; height: 28px; border-radius: 50%;
  border: 3px solid var(--border); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ------------------------------------------------------------------ sign-in */

.signin { display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 100vh; padding: 40px 16px; gap: 20px; }
.signin-card {
  width: 100%; max-width: 420px;
  display: grid; gap: 20px;
  padding: 32px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}
.signin-foot { color: var(--text-faint); font-size: 13px; }
.step { display: grid; gap: 14px; }
.step-title { font-size: 22px; }
.step-title:focus { outline: none; }
.step-text { color: var(--text-muted); }
.step-kicker { color: var(--accent-strong); font-weight: 650; font-size: 13px; text-transform: uppercase; letter-spacing: .06em; }
.back-btn { justify-self: start; margin-left: -10px; }

.divider { display: flex; align-items: center; gap: 12px; color: var(--text-faint); font-size: 13px; margin: 4px 0; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }

.dev-form fieldset { margin: 8px 0 0; padding: 14px; border: 1px dashed var(--border-strong); border-radius: var(--radius); display: grid; gap: 10px; }
.dev-form legend { padding: 0 6px; font-size: 12px; font-weight: 650; text-transform: uppercase; letter-spacing: .06em; color: var(--warn-soft-text); }

.totp-setup { display: grid; grid-template-columns: auto 1fr; gap: 16px; align-items: center; padding: 14px; background: var(--surface-2); border-radius: var(--radius); }
.totp-secret { display: grid; gap: 8px; justify-items: start; min-width: 0; }
.secret { font-size: 15px; letter-spacing: .04em; word-spacing: .2em; line-height: 1.6; overflow-wrap: anywhere; color: var(--text); }

/* ------------------------------------------------------------------ QR */

.qr-frame { display: grid; place-items: center; padding: 8px; background: #fff; border-radius: var(--radius); border: 1px solid var(--border); }
.qr-frame img { display: block; width: 200px; height: 200px; image-rendering: pixelated; }
.qr-sm img { width: 168px; height: 168px; }
.qr-fallback { width: 200px; padding: 16px; color: #5b6569; font-size: 13px; text-align: center; }
.qr-figure { margin: 0; display: grid; gap: 8px; justify-items: center; text-align: center; }

/* ------------------------------------------------------------------ top bar */

.topbar { position: sticky; top: 0; z-index: 20; background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: saturate(1.4) blur(8px); border-bottom: 1px solid var(--border); }
.topbar-inner { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 60px; }
.topbar-user { display: flex; align-items: center; gap: 12px; min-width: 0; }
.topbar-me { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }

.main { padding-top: 28px; padding-bottom: 64px; outline: none; }

/* ------------------------------------------------------------------ stats */

.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.stat {
  display: grid; gap: 2px; align-content: start;
  padding: 16px 18px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.stat-label { font-size: 13px; font-weight: 600; color: var(--text-muted); }
.stat-value { font-size: 28px; font-weight: 680; letter-spacing: -.02em; font-variant-numeric: tabular-nums; line-height: 1.25; }
.stat-sub { font-size: 13px; color: var(--text-muted); overflow-wrap: anywhere; }
.bar { height: 6px; margin-top: 10px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.bar-fill { height: 100%; width: 0; border-radius: inherit; background: var(--accent); transition: width .4s ease; }
.stat.is-warn .bar-fill { background: #d9901a; }
.stat.is-danger .bar-fill { background: var(--danger); }
.stat.is-danger .stat-value { color: var(--danger-soft-text); }

.retention { display: flex; gap: 8px; align-items: center; margin: 14px 2px 0; color: var(--text-muted); font-size: 13.5px; }

/* ------------------------------------------------------------------ tabs */

.tabs { display: flex; gap: 4px; margin: 32px 0 0; border-bottom: 1px solid var(--border); }
.tab {
  position: relative; padding: 10px 14px; margin-bottom: -1px;
  border: 0; border-bottom: 2px solid transparent; background: none;
  color: var(--text-muted); font: inherit; font-weight: 600; cursor: pointer;
}
.tab:hover { color: var(--text); }
.tab[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); }
.tab:focus-visible { outline: none; box-shadow: inset var(--focus); border-radius: var(--radius-sm) var(--radius-sm) 0 0; }

.panel { padding-top: 18px; outline: none; }

/* ------------------------------------------------------------------ toolbar */

.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-bottom: 14px; }
.toolbar-end { justify-content: space-between; }
.toolbar-text { font-size: 14px; }
.toolbar > .btn-primary { margin-left: auto; }

.search { position: relative; flex: 1 1 260px; max-width: 360px; }
.search .icon { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--text-faint); pointer-events: none; }
.search .input { padding-left: 36px; padding-right: 36px; }
.search .kbd { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); pointer-events: none; }
.search .input:focus ~ .kbd, .search .input:not(:placeholder-shown) ~ .kbd { display: none; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 0; padding: 0; border: 0; }
.chip { position: relative; }
.chip input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.chip > span {
  display: inline-flex; align-items: center; gap: 6px; min-height: 32px; padding: 0 12px;
  border: 1px solid var(--border-strong); border-radius: 999px;
  font-size: 13px; font-weight: 600; color: var(--text-muted); background: var(--surface);
}
.chip input:hover + span { color: var(--text); }
.chip input:checked + span { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-soft-text); }
.chip input:focus-visible + span { box-shadow: var(--focus); }
.chip-count { font-variant-numeric: tabular-nums; font-weight: 500; opacity: .8; }

/* ------------------------------------------------------------------ users table */

.table-wrap {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-sm); overflow: hidden;
}
.users { width: 100%; border-collapse: collapse; font-size: 14px; }
.users th {
  padding: 10px 14px; text-align: left; white-space: nowrap;
  font-size: 12px; font-weight: 650; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted);
  background: var(--surface-2); border-bottom: 1px solid var(--border);
}
.users td { padding: 12px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.users tbody tr:last-child td { border-bottom: 0; }
.users tbody tr:hover td { background: var(--surface-hover); }
.users .num { text-align: right; font-variant-numeric: tabular-nums; }
.users .cell-actions { width: 1%; text-align: right; white-space: nowrap; }
.users tr.is-locked .person-name { color: var(--text-muted); }

.person { display: flex; align-items: center; gap: 12px; min-width: 0; }
.person > div { min-width: 0; }
.person-name { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; font-weight: 600; }
.person-handle { color: var(--text-muted); font-size: 13px; overflow-wrap: anywhere; }
.avatar {
  display: grid; place-items: center; flex: none;
  width: 36px; height: 36px; border-radius: 50%;
  font-size: 13px; font-weight: 700; letter-spacing: .02em;
  background: var(--neutral-soft); color: var(--neutral-soft-text);
}
.avatar.c0 { background: #dff3ec; color: #0a6a50; }
.avatar.c1 { background: #e3ecfb; color: #234f9c; }
.avatar.c2 { background: #fbe9dc; color: #8c4413; }
.avatar.c3 { background: #efe5fa; color: #5f2f96; }
.avatar.c4 { background: #fbe4ea; color: #96273f; }
.avatar.c5 { background: #e2f1f6; color: #145c73; }
.avatar.c6 { background: #f4eed6; color: #6d5810; }
.avatar.c7 { background: #e7ece9; color: #3d4a44; }
@media (prefers-color-scheme: dark) {
  .avatar.c0 { background: #113329; color: #74e0bd; }
  .avatar.c1 { background: #172540; color: #9dbcff; }
  .avatar.c2 { background: #3a2316; color: #f6b48a; }
  .avatar.c3 { background: #2a1d3d; color: #cba6f7; }
  .avatar.c4 { background: #3a1822; color: #f5a3b5; }
  .avatar.c5 { background: #13303a; color: #8fd3ea; }
  .avatar.c6 { background: #352d12; color: #e8cf7a; }
  .avatar.c7 { background: #242b28; color: #b9c6bf; }
}

.status-cell { display: grid; gap: 4px; justify-items: start; }
.sub { font-size: 12.5px; color: var(--text-muted); }
.sub-warn { color: var(--warn-soft-text); }

.menu-btn::after {
  content: ""; width: 7px; height: 7px; margin: -3px 0 0 2px;
  border-right: 2px solid currentColor; border-bottom: 2px solid currentColor;
  transform: rotate(45deg); opacity: .7;
}

.empty { padding: 48px 16px; text-align: center; color: var(--text-muted); }
.empty strong { display: block; color: var(--text); font-size: 15px; margin-bottom: 4px; }

/* ------------------------------------------------------------------ row menu */

.menu {
  position: fixed; z-index: 50; min-width: 220px; max-width: calc(100vw - 16px);
  padding: 6px; display: grid;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
}
.menu-item {
  display: grid; gap: 1px; width: 100%; padding: 8px 10px; text-align: left;
  border: 0; border-radius: var(--radius-sm); background: none; color: var(--text);
  font: inherit; font-size: 14px; font-weight: 500; cursor: pointer;
}
.menu-item:hover, .menu-item:focus { outline: none; background: var(--surface-2); }
.menu-item:focus-visible { box-shadow: inset 0 0 0 2px var(--accent); }
.menu-item .hint { font-size: 12px; font-weight: 400; }
.menu-item.is-danger { color: var(--danger-soft-text); }
.menu-item[aria-disabled="true"] { color: var(--text-faint); cursor: not-allowed; }
.menu-sep { height: 1px; margin: 6px 4px; background: var(--border); }

/* ------------------------------------------------------------------ activity */

.audit { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm); }
.audit:empty { display: none; }
.audit-item { display: grid; grid-template-columns: 34px 1fr auto; gap: 12px; align-items: start; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.audit-item:last-child { border-bottom: 0; }
.audit-icon { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; background: var(--neutral-soft); color: var(--neutral-soft-text); }
.audit-icon .icon { width: 16px; height: 16px; }
.audit-icon.tone-good { background: var(--accent-soft); color: var(--accent-soft-text); }
.audit-icon.tone-warn { background: var(--warn-soft); color: var(--warn-soft-text); }
.audit-icon.tone-bad { background: var(--danger-soft); color: var(--danger-soft-text); }
.audit-icon.tone-info { background: var(--info-soft); color: var(--info-soft-text); }
.audit-text { min-width: 0; font-size: 14px; overflow-wrap: anywhere; }
.audit-detail { font-size: 13px; color: var(--text-muted); margin-top: 2px; }
.audit-time { font-size: 13px; color: var(--text-muted); white-space: nowrap; font-variant-numeric: tabular-nums; }

/* ------------------------------------------------------------------ dialogs */

.dialog {
  width: min(520px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px);
  padding: 0; border: 1px solid var(--border); border-radius: var(--radius-lg);
  background: var(--surface); color: var(--text);
  box-shadow: var(--shadow-lg);
}
.dialog-wide { width: min(720px, calc(100vw - 24px)); }
.dialog::backdrop { background: var(--backdrop); }
.dialog[open] { animation: dialog-in .16s ease-out; }
@keyframes dialog-in { from { opacity: 0; transform: translateY(6px) scale(.985); } }

.dialog-body { display: grid; gap: 18px; padding: 24px; }
.dialog-head { display: grid; gap: 4px; }
.dialog-head h2 { font-size: 19px; }
.dialog-foot { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 8px; margin-top: 4px; }

.confirm-desc { display: grid; gap: 10px; color: var(--text); }
.consequences { margin: 0; padding: 0; list-style: none; display: grid; gap: 8px; }
.consequences li { position: relative; padding-left: 22px; color: var(--text-muted); }
.consequences li::before {
  content: ""; position: absolute; left: 4px; top: .6em;
  width: 7px; height: 7px; border-radius: 50%; background: var(--border-strong);
}
.consequences li.is-strong { color: var(--text); font-weight: 600; }
.consequences li.is-strong::before { background: var(--danger); }

.invite { display: grid; grid-template-columns: auto 1fr; gap: 24px; align-items: start; }
.invite-info { display: grid; gap: 16px; min-width: 0; }
.code-row { display: flex; align-items: center; gap: 8px; min-width: 0; }
.code-row .input { min-width: 0; }
.invite-code { font-size: 24px; font-weight: 650; letter-spacing: .08em; padding: 4px 10px; background: var(--surface-2); border-radius: var(--radius-sm); white-space: nowrap; }
.howto { margin: 0; padding-left: 20px; display: grid; gap: 4px; color: var(--text-muted); font-size: 14px; }
.howto b { color: var(--text); }

.devices { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.device { display: flex; align-items: center; gap: 12px; padding: 12px; border: 1px solid var(--border); border-radius: var(--radius); }
.device-icon { display: grid; place-items: center; width: 36px; height: 36px; flex: none; border-radius: var(--radius-sm); background: var(--surface-2); color: var(--text-muted); }
.device-main { flex: 1; min-width: 0; display: grid; gap: 2px; }
.device-name { font-weight: 600; overflow-wrap: anywhere; }
.device-meta { font-size: 13px; color: var(--text-muted); }
.devices .empty { padding: 24px 8px; }

/* ------------------------------------------------------------------ toasts */

.toasts {
  position: fixed; z-index: 200; right: 20px; bottom: 20px;
  display: grid; gap: 8px; width: min(380px, calc(100vw - 32px));
  pointer-events: none;
}
.toast {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 12px 12px 12px 14px;
  background: var(--text); color: var(--bg);
  border-radius: var(--radius); box-shadow: var(--shadow-lg);
  font-size: 14px; pointer-events: auto;
  animation: toast-in .18s ease-out;
}
.toast-error { background: var(--danger); color: var(--on-danger); }
.toast-msg { flex: 1; padding-top: 2px; overflow-wrap: anywhere; }
.toast-close {
  flex: none; width: 26px; height: 26px; border: 0; border-radius: 6px;
  background: transparent; color: inherit; opacity: .75; cursor: pointer; font-size: 18px; line-height: 1;
}
.toast-close:hover { opacity: 1; background: rgb(255 255 255 / .15); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ------------------------------------------------------------------ responsive */

@media (max-width: 960px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 760px) {
  .container { padding: 0 16px; }
  .main { padding-top: 20px; }
  .hide-sm { display: none !important; }
  .stats { gap: 10px; }
  .stat { padding: 14px; }
  .stat-value { font-size: 22px; }

  .toolbar { gap: 10px; }
  .search { flex-basis: 100%; max-width: none; }
  .toolbar > .btn-primary { margin-left: 0; flex: 1 1 100%; }
  .chips { flex: 1 1 100%; }

  /* Table becomes a stack of cards. */
  .table-wrap { background: none; border: 0; box-shadow: none; overflow: visible; }
  .users, .users tbody, .users tr, .users td { display: block; width: 100%; }
  .users thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .users tbody { display: grid; gap: 10px; }
  .users tr {
    display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px;
    padding: 14px; background: var(--surface);
    border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm);
  }
  .users tbody tr:hover td { background: none; }
  .users td { padding: 0; border: 0; display: grid; gap: 3px; align-content: start; justify-items: start; text-align: left; }
  .users td.num { text-align: left; }
  .users td[data-label]::before {
    content: attr(data-label);
    font-size: 11.5px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em;
  }
  .users td.cell-name { grid-column: 1 / -1; grid-row: 1; padding: 0 104px 12px 0; border-bottom: 1px solid var(--border); }
  .users td.cell-actions { grid-column: 3; grid-row: 1; justify-self: end; align-self: start; width: auto; }
  .users td:nth-child(3) { grid-column: span 2; } /* status + invite note */

  .audit-item { grid-template-columns: 30px 1fr; padding: 12px; }
  .audit-time { grid-column: 2; }

  .signin-card { padding: 24px 20px; }
  .totp-setup { grid-template-columns: 1fr; justify-items: center; text-align: center; }
  .totp-secret { justify-items: center; }
  .invite { grid-template-columns: 1fr; }
  .invite-code { font-size: 19px; letter-spacing: .04em; padding: 4px 8px; }
  .radio-cards { grid-template-columns: 1fr; }
  .dialog-body { padding: 20px 16px; }
  .dialog-foot .btn { flex: 1 1 auto; }

  .toasts { left: 16px; right: 16px; bottom: 16px; width: auto; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
}

@media print {
  .topbar, .tabs, .toolbar, .toasts, .cell-actions { display: none !important; }
}
