/* SafeCom admin console — dark-first, with a light variant. No external resources. */

/* ------------------------------------------------------------------------ */
/* Tokens                                                                   */

:root,
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0A0E1A;
  --bg-glow: rgba(79, 139, 255, 0.10);
  --surface: #121829;
  --elevated: #1A2236;
  --hover: #1F2840;
  --border: #26304A;
  --border-strong: #34405F;
  --text: #E8ECF5;
  --muted: #8A93A8;
  --faint: #5D6680;
  --accent-a: #22D3A6;
  --accent-b: #4F8BFF;
  --accent: #4F8BFF;
  --accent-text: #7DA9FF;
  --accent-soft: rgba(79, 139, 255, 0.14);
  --gradient: linear-gradient(135deg, var(--accent-a), var(--accent-b));
  --gradient-soft: linear-gradient(135deg, rgba(34, 211, 166, 0.16), rgba(79, 139, 255, 0.16));
  --success: #22D3A6;
  --success-soft: rgba(34, 211, 166, 0.14);
  --warn: #F5B544;
  --warn-soft: rgba(245, 181, 68, 0.14);
  --danger: #FF5C7A;
  --danger-soft: rgba(255, 92, 122, 0.13);
  --on-accent: #06121F;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.35);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.28);
  --shadow-lg: 0 24px 64px rgba(0, 0, 0, 0.55);
  --focus: 0 0 0 3px rgba(79, 139, 255, 0.45);
  --input-bg: #0E1322;
  --backdrop: rgba(4, 7, 15, 0.72);
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #F4F6FB;
  --bg-glow: rgba(79, 139, 255, 0.08);
  --surface: #FFFFFF;
  --elevated: #F7F9FD;
  --hover: #EEF2FA;
  --border: #E1E6F0;
  --border-strong: #CBD3E3;
  --text: #121829;
  --muted: #5E6880;
  --faint: #8D96AB;
  --accent: #2F6FEB;
  --accent-text: #2459C9;
  --accent-soft: rgba(47, 111, 235, 0.10);
  --gradient-soft: linear-gradient(135deg, rgba(34, 211, 166, 0.13), rgba(79, 139, 255, 0.13));
  --success: #0E9F7A;
  --success-soft: rgba(14, 159, 122, 0.12);
  --warn: #B7791F;
  --warn-soft: rgba(221, 160, 50, 0.16);
  --danger: #E0365A;
  --danger-soft: rgba(224, 54, 90, 0.10);
  --on-accent: #FFFFFF;
  --shadow-sm: 0 1px 2px rgba(18, 24, 41, 0.06);
  --shadow: 0 1px 2px rgba(18, 24, 41, 0.05), 0 8px 24px rgba(18, 24, 41, 0.07);
  --shadow-lg: 0 24px 64px rgba(18, 24, 41, 0.22);
  --focus: 0 0 0 3px rgba(47, 111, 235, 0.30);
  --input-bg: #FFFFFF;
  --backdrop: rgba(18, 24, 41, 0.42);
}

:root {
  --radius: 14px;
  --radius-sm: 10px;
  --radius-xs: 7px;
  --sidebar-w: 260px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

/* ------------------------------------------------------------------------ */
/* Base                                                                     */

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3 { margin: 0; line-height: 1.25; font-weight: 650; letter-spacing: -0.01em; }
h1 { font-size: 26px; }
h2 { font-size: 16px; }
h3 { font-size: 15px; }
p { margin: 0 0 12px; }
a { color: var(--accent-text); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font-family: var(--mono); font-size: 12.5px; background: var(--elevated); border: 1px solid var(--border); padding: 1px 6px; border-radius: 6px; }
[hidden] { display: none !important; }
:focus-visible { outline: none; box-shadow: var(--focus); }

.icon { width: 18px; height: 18px; flex: none; }
.mono { font-family: var(--mono); }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.block { display: block; }
.center { text-align: center; justify-content: center; }
.nowrap { white-space: nowrap; }
.break { word-break: break-all; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.stack { display: flex; flex-direction: column; gap: 1px; }
.stack > .pill { align-self: flex-start; margin-bottom: 2px; }
.table-host + p { margin-top: 12px; }
.stack-lg { display: flex; flex-direction: column; gap: 20px; min-width: 0; }
.sr-only, .offscreen {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.noscript { padding: 40px; text-align: center; }

/* ------------------------------------------------------------------------ */
/* Buttons                                                                  */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 38px; padding: 0 16px; border-radius: var(--radius-sm);
  border: 1px solid transparent; background: none; color: var(--text);
  font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap;
  transition: background .15s, border-color .15s, color .15s, box-shadow .15s, transform .05s, filter .15s;
  text-decoration: none; user-select: none; position: relative;
}
.btn:hover { text-decoration: none; }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn .icon { width: 16px; height: 16px; }
.btn-primary { background: var(--gradient); color: #06121F; box-shadow: 0 6px 18px -8px rgba(79, 139, 255, .7); }
.btn-primary:hover:not(:disabled) { filter: brightness(1.08); }
.btn-ghost { background: var(--elevated); border-color: var(--border); }
.btn-ghost:hover:not(:disabled) { background: var(--hover); border-color: var(--border-strong); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { filter: brightness(1.08); }
.btn-danger-ghost { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.btn-danger-ghost:hover:not(:disabled) { border-color: var(--danger); }
.btn-sm { height: 32px; padding: 0 12px; font-size: 13px; border-radius: 9px; }
.btn-block { width: 100%; }
.btn-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-top: 16px; }
.btn-row.center { justify-content: center; }
.btn.busy, label.btn.busy { color: transparent !important; pointer-events: none; }
.btn.busy::after {
  content: ""; position: absolute; width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid currentColor; border-color: var(--text) transparent var(--text) transparent;
  animation: spin .8s linear infinite;
}
.btn-primary.busy::after { border-color: #06121F transparent #06121F transparent; }

.icon-btn {
  display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 9px;
  border: 1px solid transparent; background: none; color: var(--muted); cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
}
.icon-btn:hover { background: var(--hover); color: var(--text); }
.icon-btn-danger:hover { background: var(--danger-soft); color: var(--danger); }

/* ------------------------------------------------------------------------ */
/* Forms                                                                    */

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; min-width: 0; }
.field-label { font-weight: 600; font-size: 13px; }
.req { color: var(--danger); }
.field-hint { color: var(--muted); font-size: 12.5px; }
.field-error { color: var(--danger); font-size: 12.5px; font-weight: 500; }
.input {
  width: 100%; height: 40px; padding: 0 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--input-bg); color: var(--text);
  font: inherit; transition: border-color .15s, box-shadow .15s;
}
.input::placeholder { color: var(--faint); }
.input:hover { border-color: var(--border-strong); }
.input:focus { outline: none; border-color: var(--accent); box-shadow: var(--focus); }
.input[readonly] { color: var(--muted); }
.has-error .input { border-color: var(--danger); }
.has-error .input:focus { box-shadow: 0 0 0 3px var(--danger-soft); }
.textarea { height: auto; padding: 10px 12px; resize: vertical; font-size: 12.5px; line-height: 1.55; }
.input-code { font-family: var(--mono); font-size: 18px; letter-spacing: .25em; height: 46px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: 16px; }
.form-alert {
  padding: 10px 12px; border-radius: var(--radius-sm); margin-bottom: 14px;
  background: var(--danger-soft); color: var(--danger); font-weight: 500; font-size: 13px;
}
.form-alert-info { background: var(--accent-soft); color: var(--accent-text); }

.switch-group { display: flex; flex-direction: column; gap: 4px; margin: 4px 0 18px; }
.switch-row {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 12px 14px; border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--elevated); cursor: pointer;
}
.switch-text { display: flex; flex-direction: column; }
.switch-label { font-weight: 600; }
.switch-desc { color: var(--muted); font-size: 12.5px; }
.switch { position: relative; flex: none; }
.switch-input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.switch-track {
  display: block; width: 42px; height: 24px; border-radius: 99px; background: var(--border-strong);
  transition: background .2s; position: relative;
}
.switch-thumb {
  position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%;
  background: #fff; box-shadow: var(--shadow-sm); transition: transform .2s;
}
.switch-input:checked + .switch-track { background: var(--gradient); }
.switch-input:checked + .switch-track .switch-thumb { transform: translateX(18px); }
.switch-input:focus-visible + .switch-track { box-shadow: var(--focus); }

.check-row { display: flex; gap: 12px; align-items: flex-start; cursor: pointer; padding: 4px 0; }
.check-row input { width: 18px; height: 18px; margin: 2px 0 0; accent-color: var(--accent); flex: none; }

/* ------------------------------------------------------------------------ */
/* Login                                                                    */

.boot { min-height: 100vh; display: grid; place-content: center; justify-items: center; gap: 18px; padding: 24px; }
.login-screen { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; position: relative; overflow: hidden; }
.login-glow {
  position: absolute; inset: -30% -10% auto; height: 80%;
  background: radial-gradient(closest-side, rgba(34, 211, 166, .16), transparent 70%),
              radial-gradient(closest-side at 70% 40%, rgba(79, 139, 255, .18), transparent 70%);
  pointer-events: none;
}
.login-card {
  position: relative; width: 100%; max-width: 400px; padding: 32px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 20px; box-shadow: var(--shadow-lg);
}
.login-brand { display: flex; align-items: center; gap: 14px; margin-bottom: 26px; }
.login-product { font-size: 20px; font-weight: 700; letter-spacing: -0.01em; }
.login-sub { color: var(--muted); font-size: 13px; }
.login-form .btn-block { height: 44px; margin-top: 4px; }
.login-e2e { margin-top: 22px; }
.login-theme { position: absolute; top: 16px; right: 16px; }

.brand-mark { width: 34px; height: 34px; flex: none; display: block; filter: drop-shadow(0 6px 14px rgba(79, 139, 255, .35)); }
.brand-mark-lg { width: 46px; height: 46px; }

.e2e-note {
  display: flex; gap: 10px; align-items: flex-start; padding: 12px; border-radius: var(--radius-sm);
  background: var(--gradient-soft); border: 1px solid var(--border); font-size: 12.5px; line-height: 1.45; color: var(--text);
}
.e2e-icon { color: var(--accent-a); display: flex; }
.e2e-icon .icon { width: 16px; height: 16px; }

/* ------------------------------------------------------------------------ */
/* Shell                                                                    */

.shell {
  display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); min-height: 100vh;
  /* Paint the sidebar column to the bottom of long pages; the sticky sidebar itself is one viewport tall. */
  background: linear-gradient(to right, var(--surface) calc(var(--sidebar-w) - 1px), var(--border) calc(var(--sidebar-w) - 1px) var(--sidebar-w), transparent var(--sidebar-w));
}
.topbar { display: none; }
.scrim { display: none; }

.sidebar {
  position: sticky; top: 0; align-self: start; height: 100vh; display: flex; flex-direction: column;
  background: var(--surface); border-right: 1px solid var(--border); padding: 20px 14px 16px; overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 12px; padding: 4px 8px 22px; }
.brand-text { min-width: 0; flex: 1; }
.brand-company { font-weight: 700; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-sub { color: var(--muted); font-size: 12px; }
.brand-logo { width: 34px; height: 34px; object-fit: contain; border-radius: 8px; background: #fff; border: 1px solid var(--border); flex: none; }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-link, .nav-btn {
  position: relative; display: flex; align-items: center; gap: 12px; height: 40px; padding: 0 12px;
  border-radius: var(--radius-sm); color: var(--muted); font-weight: 550; text-decoration: none;
  transition: background .15s, color .15s; border: 0; background: none; font: inherit; cursor: pointer; width: 100%;
}
.nav-link:hover, .nav-btn:hover { background: var(--hover); color: var(--text); text-decoration: none; }
.nav-link.active { background: var(--accent-soft); color: var(--text); }
.nav-link.active .icon { color: var(--accent-text); }
.nav-link.active::before {
  content: ""; position: absolute; left: -14px; top: 8px; bottom: 8px; width: 4px;
  border-radius: 0 4px 4px 0; background: var(--gradient);
}
.nav-btn-compact { width: auto; background: var(--surface); border: 1px solid var(--border); }

.sidebar-footer { margin-top: auto; padding-top: 20px; display: flex; flex-direction: column; gap: 8px; }
.user-row { display: flex; align-items: center; gap: 6px; padding-top: 8px; border-top: 1px solid var(--border); }
.user-link {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; padding: 6px 8px;
  border-radius: var(--radius-sm); color: var(--text); font-weight: 600;
}
.user-link:hover { background: var(--hover); text-decoration: none; }
.user-link.active { background: var(--accent-soft); }
.user-avatar { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; background: var(--elevated); border: 1px solid var(--border); color: var(--muted); flex: none; }
.user-avatar .icon { width: 16px; height: 16px; }
.user-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.main { min-width: 0; padding: 36px 40px 64px; outline: none; }
.main:focus-visible { box-shadow: none; }
.view { max-width: 1240px; margin: 0 auto; }

.page-header { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 26px; }
.page-subtitle { color: var(--muted); margin: 6px 0 0; max-width: 680px; }
.page-actions { display: flex; gap: 10px; flex-wrap: wrap; }

/* ------------------------------------------------------------------------ */
/* Cards, stats                                                             */

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 22px; box-shadow: var(--shadow); margin-bottom: 20px; min-width: 0;
}
.stack-lg > .card, .grid-2 > .card { margin-bottom: 0; }
.card-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.card-header-icon { color: var(--muted); display: flex; }
.section-title { margin: 20px 0 10px; }

.stats { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 16px; margin-bottom: 20px; }
.stat {
  position: relative; overflow: hidden; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow);
}
.stat::after {
  content: ""; position: absolute; left: 18px; right: 18px; top: 0; height: 2px; border-radius: 0 0 2px 2px;
  background: var(--gradient); opacity: .0; transition: opacity .2s;
}
.stat-accent::after, .stat:hover::after { opacity: 1; }
.stat-top { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 12.5px; font-weight: 600; }
.stat-icon { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 9px; background: var(--gradient-soft); color: var(--accent-text); }
.stat-icon .icon { width: 16px; height: 16px; }
.stat-value { font-size: 28px; font-weight: 700; letter-spacing: -0.02em; margin-top: 12px; font-variant-numeric: tabular-nums; }
.stat-sub { color: var(--muted); font-size: 12.5px; margin-top: 2px; }

.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; align-items: start; margin-bottom: 20px; }
.grid-settings { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: 20px; align-items: start; }

.copy-field { padding: 12px 0; border-top: 1px solid var(--border); }
.copy-field-label { color: var(--muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; }
.copy-field-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 4px; }
.copy-field-value { font-size: 15px; font-weight: 600; word-break: break-all; }

.e2e-banner {
  display: flex; gap: 14px; margin-top: 14px; padding: 16px; border-radius: var(--radius-sm);
  background: var(--gradient-soft); border: 1px solid var(--border);
}
.e2e-banner p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.e2e-banner-icon { display: grid; place-items: center; width: 36px; height: 36px; flex: none; border-radius: 10px; background: var(--gradient); color: #06121F; }

.poster-qr { display: grid; place-items: center; padding: 16px; min-height: 220px; }
.qr-img { display: block; width: 100%; max-width: 220px; aspect-ratio: 1; background: #fff; border-radius: 12px; padding: 10px; border: 1px solid var(--border); }
.poster-actions { display: flex; flex-direction: column; align-items: center; }
.poster-actions .btn-row { margin-top: 10px; }
.join-link { font-size: 12px; color: var(--muted); word-break: break-all; text-align: center; max-width: 100%; }

/* ------------------------------------------------------------------------ */
/* Pills, tags, callouts                                                    */

.pill {
  display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 10px; border-radius: 99px;
  font-size: 12px; font-weight: 600; white-space: nowrap; background: var(--elevated); color: var(--muted); border: 1px solid var(--border);
}
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill-success { background: var(--success-soft); color: var(--success); border-color: transparent; }
.pill-warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.pill-danger { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.pill-accent { background: var(--accent-soft); color: var(--accent-text); border-color: transparent; }
.pill-accent::before { display: none; }

.tag { display: inline-block; padding: 2px 8px; border-radius: 6px; background: var(--elevated); border: 1px solid var(--border); font-size: 12px; font-weight: 600; white-space: nowrap; }

.callout {
  display: flex; gap: 12px; align-items: flex-start; padding: 14px 16px; border-radius: var(--radius-sm);
  margin: 14px 0; font-size: 13px; line-height: 1.5;
}
.callout > .icon { margin-top: 1px; }
.callout .btn-row { margin-top: 12px; }
.callout-tight { margin-top: 0; margin-bottom: 18px; }
.callout-warn { background: var(--warn-soft); color: var(--text); }
.callout-warn > .icon { color: var(--warn); }
.callout-info { background: var(--accent-soft); color: var(--text); }
.callout-info > .icon { color: var(--accent-text); }

/* ------------------------------------------------------------------------ */
/* Toolbar + tables                                                         */

.toolbar { display: flex; align-items: center; gap: 16px; margin-bottom: 16px; flex-wrap: wrap; }
.search-wrap { position: relative; flex: 1; max-width: 440px; min-width: 220px; }
.search-icon { position: absolute; left: 12px; top: 11px; color: var(--muted); pointer-events: none; }
.input-search { padding-left: 40px; }
.toolbar-count { font-size: 13px; }

.table-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.table-scroll { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius-sm); }
.table { width: 100%; border-collapse: separate; border-spacing: 0; }
.table th {
  text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .05em;
  padding: 12px 16px; border-bottom: 1px solid var(--border); background: var(--elevated); white-space: nowrap;
}
.table th.num { text-align: right; }
.table-card { --inner-radius: calc(var(--radius) - 1px); }
.table-card .table thead tr:first-child th:first-child { border-top-left-radius: var(--inner-radius); }
.table-card .table thead tr:first-child th:last-child { border-top-right-radius: var(--inner-radius); }
.table-card .table tbody tr:last-child td:first-child { border-bottom-left-radius: var(--inner-radius); }
.table-card .table tbody tr:last-child td:last-child { border-bottom-right-radius: var(--inner-radius); }
.table td { overflow-wrap: break-word; }
.table td.nowrap, .table td .nowrap { overflow-wrap: normal; }
.table td { padding: 12px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr { transition: background .12s; }
.table tbody tr:hover { background: var(--elevated); }
.table-compact th, .table-compact td { padding: 8px 12px; font-size: 13px; }
.row-disabled .member-name, .row-disabled .member-sub, .row-disabled .avatar { opacity: .55; }
.row-warn { background: var(--warn-soft); }
.row-muted .member-name, .row-muted td:nth-child(n+4) { opacity: .7; }
.cell-actions { width: 1%; text-align: right; white-space: nowrap; }
.table-footer { display: flex; justify-content: center; padding: 14px; border-top: 1px solid var(--border); }
.details-cell { max-width: 360px; font-size: 13px; }
.code-cell { letter-spacing: .08em; font-weight: 600; }

.member-cell { display: flex; align-items: center; gap: 12px; min-width: 0; }
.member-names { min-width: 0; }
.member-name { font-weight: 600; }
.member-sub { color: var(--muted); font-size: 12.5px; }
.avatar { width: 36px; height: 36px; border-radius: 50%; object-fit: cover; flex: none; display: block; }
.avatar-initials {
  display: grid; place-items: center; background: var(--gradient); color: #06121F;
  font-weight: 700; font-size: 13px; letter-spacing: .02em;
}
.avatar-sm { width: 30px; height: 30px; font-size: 11px; }

/* Segmented control */
.seg { display: inline-flex; padding: 3px; border-radius: 11px; background: var(--elevated); border: 1px solid var(--border); }
.seg-btn {
  height: 32px; padding: 0 16px; border: 0; border-radius: 8px; background: none; color: var(--muted);
  font: inherit; font-weight: 600; cursor: pointer; transition: background .15s, color .15s;
}
.seg-btn:hover { color: var(--text); }
.seg-btn.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }

/* Row action menu */
.menu-wrap { position: relative; display: inline-block; }
.menu-wrap.open .icon-btn { background: var(--hover); color: var(--text); }
.menu {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 30; min-width: 220px; padding: 6px;
  background: var(--elevated); border: 1px solid var(--border-strong); border-radius: 12px; box-shadow: var(--shadow-lg);
  text-align: left; animation: pop .12s ease-out;
}
.menu-item {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 10px; border: 0; border-radius: 8px;
  background: none; color: var(--text); font: inherit; font-weight: 500; cursor: pointer; text-align: left;
}
.menu-item .icon { width: 16px; height: 16px; color: var(--muted); }
.menu-item:hover:not(:disabled), .menu-item:focus-visible { background: var(--hover); box-shadow: none; }
.menu-item:disabled { opacity: .45; cursor: not-allowed; }
.menu-item.danger, .menu-item.danger .icon { color: var(--danger); }
.menu-item.danger:hover:not(:disabled) { background: var(--danger-soft); }
.menu-sep { height: 1px; background: var(--border); margin: 6px 4px; }

/* ------------------------------------------------------------------------ */
/* Loading / empty                                                          */

.loading { display: flex; align-items: center; justify-content: center; gap: 12px; padding: 48px 16px; color: var(--muted); }
.spinner {
  width: 20px; height: 20px; border-radius: 50%; border: 2px solid var(--border-strong);
  border-top-color: var(--accent-b); animation: spin .8s linear infinite; flex: none;
}
.empty {
  display: flex; flex-direction: column; align-items: center; text-align: center; padding: 56px 24px;
  background: var(--surface); border: 1px dashed var(--border-strong); border-radius: var(--radius);
}
.empty h3 { margin: 14px 0 6px; }
.empty p { color: var(--muted); max-width: 420px; }
.empty .btn-row { margin-top: 6px; }
.empty-icon { display: grid; place-items: center; width: 52px; height: 52px; border-radius: 16px; background: var(--gradient-soft); color: var(--accent-text); }
.empty-icon .icon { width: 24px; height: 24px; }
.empty-error .empty-icon { background: var(--danger-soft); color: var(--danger); }
.modal .empty { border: 0; padding: 28px 8px; background: none; }

/* ------------------------------------------------------------------------ */
/* Toasts                                                                   */

.toasts {
  position: fixed; inset: auto 20px 20px auto; z-index: 1000; display: flex; flex-direction: column; gap: 10px;
  width: min(380px, calc(100vw - 32px)); pointer-events: none;
  margin: 0; padding: 0; border: 0; background: transparent; color: inherit; overflow: visible;
}
.toasts[popover]:not(:popover-open) { display: none; }
.toast {
  display: flex; align-items: flex-start; gap: 10px; padding: 12px 12px 12px 14px; border-radius: 12px;
  background: var(--elevated); border: 1px solid var(--border-strong); box-shadow: var(--shadow-lg);
  pointer-events: auto; opacity: 0; transform: translateY(8px); transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: none; }
.toast-icon { margin-top: 1px; }
.toast-success .toast-icon { color: var(--success); }
.toast-error { border-color: var(--danger); }
.toast-error .toast-icon { color: var(--danger); }
.toast-info .toast-icon { color: var(--accent-text); }
.toast-text { flex: 1; font-weight: 500; }
.toast-close { border: 0; background: none; color: var(--muted); cursor: pointer; padding: 2px; border-radius: 6px; display: flex; }
.toast-close .icon { width: 16px; height: 16px; }
.toast-close:hover { color: var(--text); }

/* ------------------------------------------------------------------------ */
/* Modals                                                                   */

.modal {
  width: min(520px, calc(100vw - 32px)); max-height: calc(100vh - 48px); padding: 0; margin: auto;
  border: 1px solid var(--border-strong); border-radius: 18px; background: var(--surface); color: var(--text);
  box-shadow: var(--shadow-lg); display: flex; flex-direction: column; overflow: hidden;
  animation: pop .16s ease-out;
}
.modal:not([open]) { display: none; }
.modal.closing { animation: fade-out .16s ease-in forwards; }
.modal::backdrop { background: var(--backdrop); backdrop-filter: blur(3px); }
.modal-sm { width: min(440px, calc(100vw - 32px)); }
.modal-lg { width: min(760px, calc(100vw - 32px)); }
.modal-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; padding: 22px 24px 0; }
.modal-title { font-size: 18px; }
.modal-subtitle { color: var(--muted); margin: 6px 0 0; font-size: 13px; }
.modal-close { margin: -6px -8px 0 0; }
.modal-body { padding: 20px 24px; overflow-y: auto; }
.modal-footer { display: flex; justify-content: flex-end; gap: 10px; flex-wrap: wrap; padding: 16px 24px; border-top: 1px solid var(--border); background: var(--elevated); }
.modal-body > form > .field:last-child { margin-bottom: 0; }

.confirm-body { display: flex; gap: 14px; }
.confirm-body p { margin: 0; }
.confirm-icon { display: grid; place-items: center; width: 40px; height: 40px; flex: none; border-radius: 12px; background: var(--danger-soft); color: var(--danger); }
.confirm-details { margin: 10px 0 0; padding-left: 18px; color: var(--muted); font-size: 13px; }
.confirm-details li + li { margin-top: 4px; }

/* Activation code modal */
.code-layout { display: grid; grid-template-columns: minmax(0, 1fr) 240px; gap: 24px; }
.code-box {
  text-align: center; padding: 20px 16px; border-radius: var(--radius); background: var(--gradient-soft);
  border: 1px solid var(--border-strong);
}
.code-box .btn-row { margin-top: 12px; }
.code-label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .08em; font-weight: 600; }
.code-big { font-size: 34px; font-weight: 700; letter-spacing: .16em; margin-top: 6px; word-break: break-all; user-select: all; }
.code-main > p { margin: 14px 0 0; }
.code-qr { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.code-qr p { margin: 0; }
.kv { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 8px 16px; margin: 16px 0 0; font-size: 13.5px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 550; }

/* Devices */
.device-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.device { display: flex; align-items: center; gap: 14px; padding: 12px 14px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--elevated); }
.device-revoked { opacity: .6; }
.device-icon { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 10px; background: var(--gradient-soft); color: var(--accent-text); flex: none; }
.device-info { flex: 1; min-width: 0; }
.device-name { font-weight: 600; }
.device-meta { font-size: 12.5px; }

/* TOTP */
.totp-layout { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 24px; align-items: start; }
.steps { margin: 0 0 10px; padding-left: 18px; }
.steps li + li { margin-top: 4px; }
.secret {
  padding: 10px 12px; border-radius: var(--radius-sm); background: var(--elevated); border: 1px solid var(--border);
  font-size: 14px; letter-spacing: .06em; word-break: break-all; user-select: all;
}
.totp-layout .btn-row { margin: 10px 0 18px; }

/* ------------------------------------------------------------------------ */
/* Import                                                                   */

.import-inputs { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.3fr); gap: 20px; margin-top: 8px; }
.import-inputs .field { margin-bottom: 0; }
.dropzone {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; text-align: center;
  padding: 24px; border: 2px dashed var(--border-strong); border-radius: var(--radius); background: var(--elevated);
  cursor: pointer; transition: border-color .15s, background .15s; min-height: 180px;
}
.dropzone:hover, .dropzone.dragging { border-color: var(--accent); background: var(--accent-soft); }
.dropzone:focus-within { box-shadow: var(--focus); }
.dropzone-icon { display: grid; place-items: center; width: 46px; height: 46px; border-radius: 14px; background: var(--gradient); color: #06121F; margin-bottom: 6px; }
.dropzone-title { font-weight: 600; }
.drop-file { font-size: 12.5px; color: var(--success); }

.result-stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.result-stat { padding: 14px 16px; border-radius: var(--radius-sm); background: var(--elevated); border: 1px solid var(--border); display: flex; flex-direction: column; }
.result-stat strong { font-size: 24px; font-variant-numeric: tabular-nums; }
.result-stat span { color: var(--muted); font-size: 12.5px; }
.result-stat.ok strong { color: var(--success); }
.result-stat.warn strong { color: var(--warn); }
.details { margin: 12px 0; }
.details summary { cursor: pointer; font-weight: 600; padding: 6px 0; color: var(--accent-text); }
.details .table-scroll { margin-top: 8px; }

/* ------------------------------------------------------------------------ */
/* Settings                                                                 */

.logo-row { display: flex; gap: 20px; align-items: center; }
.logo-row p { margin: 0; }
.logo-row .btn-row { margin-top: 12px; }
.logo-preview {
  width: 104px; height: 104px; flex: none; border-radius: var(--radius); border: 1px solid var(--border);
  background: #fff; display: grid; place-items: center; overflow: hidden;
}
.logo-preview-img { max-width: 100%; max-height: 100%; object-fit: contain; }
.logo-placeholder { display: flex; flex-direction: column; align-items: center; gap: 4px; color: #8A93A8; font-size: 12px; }
label.btn { cursor: pointer; }
input.sr-only:focus-visible + label.btn { box-shadow: var(--focus); }

/* ------------------------------------------------------------------------ */
/* Animations                                                               */

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pop { from { opacity: 0; transform: translateY(6px) scale(.98); } to { opacity: 1; transform: none; } }
@keyframes fade-out { to { opacity: 0; transform: translateY(4px) scale(.98); } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}

/* ------------------------------------------------------------------------ */
/* Responsive                                                               */

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

@media (max-width: 960px) {
  .grid-2, .grid-settings { grid-template-columns: minmax(0, 1fr); }
  .main { padding: 28px 24px 56px; }
}

/* Tables become stacked cards so nothing needs horizontal scrolling:
   wide tables (members, invites) already below 1100px, the rest on phones. */
@media (max-width: 1100px) {
  .table-wide thead { display: none; }
  .table-wide, .table-wide tbody, .table-wide tr, .table-wide td { display: block; width: 100%; }
  .table-wide tr { position: relative; padding: 14px 16px; border-bottom: 1px solid var(--border); }
  .table-wide tbody tr:last-child { border-bottom: 0; }
  .table-wide td { border: 0; padding: 3px 0; text-align: left; }
  .table-wide td[data-label]:not(:first-child)::before {
    content: attr(data-label); display: inline-block; min-width: 96px; color: var(--muted); font-size: 12px; font-weight: 600;
  }
  .table-wide td:first-child { padding-right: 44px; margin-bottom: 6px; }
  .table-wide .cell-actions { position: absolute; top: 12px; right: 10px; width: auto; padding: 0; }
  .table-wide td .stack { display: inline-flex; vertical-align: top; }
  .table-wide td.num { text-align: left; }
  .table-wide .cell-actions-btn { position: static; margin-top: 8px; }
  .table-wide .cell-actions-btn:empty { display: none; }
  .table-card .table-wide tbody tr:last-child { border-radius: 0 0 var(--inner-radius) var(--inner-radius); }
  .table-card .table-wide tbody tr:last-child td { border-radius: 0; }
}

@media (max-width: 860px) {
  .table-responsive thead { display: none; }
  .table-responsive, .table-responsive tbody, .table-responsive tr, .table-responsive td { display: block; width: 100%; }
  .table-responsive tr { position: relative; padding: 14px 16px; border-bottom: 1px solid var(--border); }
  .table-responsive tbody tr:last-child { border-bottom: 0; }
  .table-responsive td { border: 0; padding: 3px 0; text-align: left; }
  .table-responsive td[data-label]:not(:first-child)::before {
    content: attr(data-label); display: inline-block; min-width: 96px; color: var(--muted); font-size: 12px; font-weight: 600;
  }
  .table-responsive td:first-child { padding-right: 44px; margin-bottom: 6px; }
  .table-responsive .cell-actions { position: absolute; top: 12px; right: 10px; width: auto; padding: 0; }
  .table-responsive td .stack { display: inline-flex; vertical-align: top; }
  .table-responsive td.num { text-align: left; }
  .table-responsive .cell-actions-btn { position: static; margin-top: 8px; }
  .table-card .table-responsive tbody tr:last-child { border-radius: 0 0 var(--inner-radius) var(--inner-radius); }
  .table-card .table-responsive tbody tr:last-child td { border-radius: 0; }

  .shell { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto 1fr; background: none; }
  .topbar {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    position: sticky; top: 0; z-index: 40; height: 60px; padding: 0 16px;
    background: var(--surface); border-bottom: 1px solid var(--border);
  }
  .topbar-brand { display: flex; align-items: center; gap: 10px; min-width: 0; font-weight: 700; }
  .topbar-brand .brand-mark { width: 30px; height: 30px; }
  .topbar-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .sidebar {
    position: fixed; z-index: 60; top: 0; left: 0; bottom: 0; width: min(300px, 86vw); height: auto;
    transform: translateX(-102%); transition: transform .22s ease; box-shadow: var(--shadow-lg);
  }
  .nav-open .sidebar { transform: none; }
  .nav-open .scrim { display: block; position: fixed; inset: 0; z-index: 50; background: var(--backdrop); }
  .main { padding: 22px 16px 48px; }
  h1 { font-size: 22px; }

}

@media (max-width: 640px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat-value { font-size: 22px; }
  .form-grid, .import-inputs, .code-layout, .totp-layout { grid-template-columns: minmax(0, 1fr); }
  .code-big { font-size: 28px; letter-spacing: .1em; }
  .result-stats { grid-template-columns: minmax(0, 1fr); }
  .page-actions { width: 100%; }
  .page-actions .btn { flex: 1; }
  .card { padding: 18px; }
  .modal-header, .modal-body { padding-left: 18px; padding-right: 18px; }
  .modal-footer { padding: 14px 18px; }
  .modal-footer .btn { flex: 1; }
  .logo-row { flex-direction: column; align-items: flex-start; }
  .login-card { padding: 26px 20px; }
}

/* ------------------------------------------------------------------------ */
/* Print: only #print-root (welcome letter / poster) is printed.            */

#print-root { display: none; }

@media print {
  @page { size: A4; margin: 18mm; }
  body.printing > *:not(#print-root) { display: none !important; }
  body.printing { background: #fff !important; color: #121829 !important; }
  body.printing #print-root { display: block; }
  #print-root, #print-root * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }

  .print-page { font-family: var(--font); color: #121829; font-size: 11.5pt; line-height: 1.5; }
  .print-brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 13pt; margin-bottom: 14mm; }
  .print-mark { width: 26px; height: 26px; }
  .print-page h1 { font-size: 24pt; margin-bottom: 4mm; color: #0A0E1A; }
  .print-lead { font-size: 12.5pt; color: #3D465C; margin-bottom: 9mm; }
  .print-qr { width: 58mm; height: 58mm; display: block; }
  .print-steps { padding-left: 6mm; margin: 0; }
  .print-steps li { margin-bottom: 3mm; }
  .print-columns { display: flex; gap: 10mm; align-items: flex-start; margin-bottom: 9mm; }
  .print-columns .print-steps { flex: 1; }
  .print-codes { border: 1.5pt solid #121829; border-radius: 4mm; padding: 6mm 8mm; }
  .print-kv { display: flex; justify-content: space-between; align-items: baseline; gap: 8mm; padding: 2.5mm 0; border-bottom: 0.5pt solid #CBD3E3; }
  .print-codes .print-kv:last-child { border-bottom: 0; }
  .print-kv span { color: #5E6880; }
  .print-kv strong { font-size: 13pt; }
  .print-kv-code strong { font-size: 22pt; letter-spacing: .14em; }
  .print-note { margin-top: 8mm; font-weight: 600; }
  .print-foot { margin-top: 8mm; color: #5E6880; font-size: 10pt; }

  .print-poster { text-align: center; }
  .print-poster .print-brand { justify-content: center; }
  .print-poster h1 { font-size: 32pt; }
  .print-poster .print-qr { width: 110mm; height: 110mm; margin: 0 auto 10mm; }
  .print-poster .print-steps { text-align: left; display: inline-block; margin-bottom: 8mm; font-size: 13pt; }
  .print-poster .print-kv { max-width: 110mm; margin: 0 auto; border: 0; }
  .print-poster .print-kv strong { font-size: 20pt; letter-spacing: .1em; }
}
