:root,
[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0a0e14;
  --bg-elevated: #111820;
  --surface: #161d27;
  --surface-hover: #1c2532;
  --surface-active: #222d3d;
  --surface-inset: rgba(0, 0, 0, 0.2);
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.14);
  --text: #f0f4f8;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --accent: #38bdf8;
  --accent-dim: rgba(56, 189, 248, 0.12);
  --accent-hover: #7dd3fc;
  --accent-glow: rgba(56, 189, 248, 0.25);
  --accent-secondary: #818cf8;
  --success: #34d399;
  --success-dim: rgba(52, 211, 153, 0.12);
  --warning: #fbbf24;
  --warning-dim: rgba(251, 191, 36, 0.12);
  --danger: #f87171;
  --danger-dim: rgba(248, 113, 113, 0.12);
  --danger-border: rgba(248, 113, 113, 0.3);
  --danger-hover-bg: rgba(248, 113, 113, 0.2);
  --overlay: rgba(0, 0, 0, 0.65);
  --row-hover: rgba(255, 255, 255, 0.02);
  --badge-muted-bg: rgba(255, 255, 255, 0.05);
  --card-footer-bg: rgba(0, 0, 0, 0.15);
  --btn-primary-text: #0a0e14;
  --mfa-bg: linear-gradient(135deg, rgba(56, 189, 248, 0.08), rgba(129, 140, 248, 0.06));
  --mfa-border: rgba(56, 189, 248, 0.2);
  --auth-brand-bg:
    radial-gradient(ellipse 80% 60% at 20% 40%, rgba(56, 189, 248, 0.08), transparent),
    radial-gradient(ellipse 60% 50% at 80% 80%, rgba(52, 211, 153, 0.05), transparent),
    var(--bg-elevated);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 12px 48px rgba(0, 0, 0, 0.5);
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --radius-xl: 20px;
  --font: 'DM Sans', system-ui, -apple-system, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, monospace;
  --sidebar-width: 260px;
  --header-height: 72px;
  --transition: 150ms ease;
}

[data-theme="light"] {
  color-scheme: light;
  --bg: #f1f5f9;
  --bg-elevated: #ffffff;
  --surface: #ffffff;
  --surface-hover: #f8fafc;
  --surface-active: #f1f5f9;
  --surface-inset: #f1f5f9;
  --border: rgba(15, 23, 42, 0.1);
  --border-strong: rgba(15, 23, 42, 0.16);
  --text: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --accent: #0284c7;
  --accent-dim: rgba(2, 132, 199, 0.1);
  --accent-hover: #0369a1;
  --accent-glow: rgba(2, 132, 199, 0.2);
  --accent-secondary: #6366f1;
  --success: #059669;
  --success-dim: rgba(5, 150, 105, 0.1);
  --warning: #d97706;
  --warning-dim: rgba(217, 119, 6, 0.1);
  --danger: #dc2626;
  --danger-dim: rgba(220, 38, 38, 0.1);
  --danger-border: rgba(220, 38, 38, 0.25);
  --danger-hover-bg: rgba(220, 38, 38, 0.12);
  --overlay: rgba(15, 23, 42, 0.45);
  --row-hover: rgba(15, 23, 42, 0.03);
  --badge-muted-bg: rgba(15, 23, 42, 0.06);
  --card-footer-bg: #f8fafc;
  --btn-primary-text: #ffffff;
  --mfa-bg: linear-gradient(135deg, rgba(2, 132, 199, 0.06), rgba(99, 102, 241, 0.05));
  --mfa-border: rgba(2, 132, 199, 0.22);
  --auth-brand-bg:
    radial-gradient(ellipse 80% 60% at 20% 40%, rgba(2, 132, 199, 0.07), transparent),
    radial-gradient(ellipse 60% 50% at 80% 80%, rgba(5, 150, 105, 0.05), transparent),
    var(--bg-elevated);
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow: 0 4px 24px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 12px 48px rgba(15, 23, 42, 0.12);
}

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

html { -webkit-font-smoothing: antialiased; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
  transition: background var(--transition), color var(--transition);
}

.hidden { display: none !important; }

/* ─── Auth screens ─── */
.auth-screen {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1fr 1fr;
}

.auth-panel {
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 3rem;
}

.auth-panel-brand {
  background: var(--auth-brand-bg);
  border-right: 1px solid var(--border);
}

.auth-panel-brand h1 {
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 1.5rem 0 0.75rem;
}

.auth-panel-brand p {
  color: var(--text-secondary);
  font-size: 1.05rem;
  max-width: 360px;
  line-height: 1.6;
}

.auth-logo {
  width: min(240px, 80%);
  height: auto;
}

.auth-panel-form {
  background: var(--bg);
  align-items: center;
  position: relative;
}

.auth-theme-toggle {
  position: absolute;
  top: 1.25rem;
  right: 1.25rem;
}

.auth-card {
  width: 100%;
  max-width: 400px;
}

.auth-card h2 {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 0.35rem;
}

.text-muted { color: var(--text-muted); margin-bottom: 1.75rem; }

/* ─── App shell ─── */
.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-elevated);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 100;
}

.sidebar-brand {
  padding: 1.25rem 1.25rem 1rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.sidebar-logo {
  height: 28px;
  width: auto;
  display: block;
}

.sidebar-close {
  display: none;
  flex-shrink: 0;
  font-size: 1.5rem;
}

/* Mobile top bar — shown only ≤900px */
.mobile-topbar {
  display: none;
}

.sidebar-backdrop {
  display: none;
}

.sidebar-nav {
  flex: 1;
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
  padding: 0.65rem 0.85rem;
  border: none;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-secondary);
  font-family: var(--font);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  transition: background var(--transition), color var(--transition);
}

.nav-item:hover {
  background: var(--surface);
  color: var(--text);
}

.nav-item.active {
  background: var(--accent-dim);
  color: var(--accent);
}

.nav-item svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  opacity: 0.85;
}

.nav-item.active svg { opacity: 1; }

.sidebar-footer {
  padding: 1rem;
  border-top: 1px solid var(--border);
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem;
  margin-bottom: 0.5rem;
}

.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: var(--radius);
  background: linear-gradient(135deg, var(--accent), var(--accent-secondary));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}

.user-meta {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.user-name {
  font-size: 0.875rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-role {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: capitalize;
}

.app-main {
  flex: 1;
  margin-left: var(--sidebar-width);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.content-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.5rem 2rem 0;
  flex-wrap: wrap;
}

.page-title {
  font-size: 1.65rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.page-subtitle {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-top: 0.25rem;
}

.content-header-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.sync-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.45rem 0.85rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 0.8rem;
  color: var(--text-secondary);
  white-space: nowrap;
}

.sync-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 8px var(--success);
  animation: pulse 2s infinite;
}

.sync-pill.publishing .sync-dot {
  background: var(--warning);
  box-shadow: 0 0 8px var(--warning);
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text-secondary);
  cursor: pointer;
  flex-shrink: 0;
  transition: background var(--transition), border-color var(--transition), color var(--transition);
}

.theme-toggle:hover {
  background: var(--surface-hover);
  color: var(--text);
  border-color: var(--border-strong);
}

.notif-bell {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text-secondary);
  cursor: pointer;
  flex-shrink: 0;
  transition: background var(--transition), border-color var(--transition), color var(--transition);
}

.notif-bell:hover {
  background: var(--surface-hover);
  color: var(--text);
  border-color: var(--border-strong);
}

.notif-bell.has-pending {
  color: var(--warning);
  border-color: color-mix(in srgb, var(--warning) 35%, var(--border));
  background: var(--warning-dim);
}

.notif-bell-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--danger);
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
  line-height: 18px;
  text-align: center;
  pointer-events: none;
}

.notif-wrap {
  position: relative;
  flex-shrink: 0;
}

.notif-dropdown {
  position: absolute;
  top: calc(100% + 0.45rem);
  right: 0;
  z-index: 80;
  width: min(340px, calc(100vw - 2rem));
  max-height: min(420px, 70vh);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  transform-origin: top right;
  animation: notifDrop 0.18s ease;
}

.notif-dropdown.hidden {
  display: none;
}

@keyframes notifDrop {
  from { opacity: 0; transform: translateY(-8px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.notif-dropdown-header {
  padding: 0.75rem 1rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--border);
  background: var(--surface-inset);
}

.notif-dropdown-list {
  overflow-y: auto;
  flex: 1;
}

.notif-item {
  display: block;
  width: 100%;
  padding: 0.85rem 1rem;
  border: none;
  border-bottom: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  text-align: left;
  font-family: var(--font);
  cursor: pointer;
  transition: background var(--transition);
}

.notif-item:last-child {
  border-bottom: none;
}

.notif-item:hover {
  background: var(--surface-hover);
}

.notif-item-title {
  display: block;
  font-size: 0.875rem;
  font-weight: 600;
  margin-bottom: 0.2rem;
}

.notif-item-body {
  display: block;
  font-size: 0.8rem;
  color: var(--text-secondary);
  line-height: 1.4;
}

.notif-item-meta {
  display: block;
  margin-top: 0.35rem;
  font-size: 0.72rem;
  color: var(--text-muted);
}

.notif-empty {
  padding: 1.5rem 1rem;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.875rem;
}

.notif-item.approved .notif-item-title { color: var(--success); }
.notif-item.rejected .notif-item-title { color: var(--danger); }
.notif-item.pending .notif-item-title { color: var(--warning); }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.view-root {
  flex: 1;
  padding: 1.5rem 2rem 2rem;
  max-width: 1280px;
}

/* ─── Typography & layout helpers ─── */
h2.section-title {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 0.75rem;
  color: var(--text);
}

.stack { display: flex; flex-direction: column; gap: 1rem; }
.stack-sm { display: flex; flex-direction: column; gap: 0.5rem; }
.row { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }

/* ─── Cards & panels ─── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.card-padded { padding: 1.25rem 1.5rem; }

.card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
}

.card-header h3 {
  font-size: 0.95rem;
  font-weight: 600;
}

.card-header p {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 0.15rem;
}

.card-body { padding: 1.25rem 1.5rem; }

.card-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border);
  background: var(--card-footer-bg);
}

/* ─── Stats ─── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem 1.5rem;
  transition: border-color var(--transition);
}

.stat-card:hover { border-color: var(--border-strong); }

.stat-card .stat-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 0.85rem;
  background: var(--accent-dim);
  color: var(--accent);
}

.stat-card .stat-icon.success { background: var(--success-dim); color: var(--success); }
.stat-card .stat-icon.warning { background: var(--warning-dim); color: var(--warning); }

.stat-card .value {
  font-size: 1.85rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.1;
}

.stat-card .label {
  color: var(--text-muted);
  font-size: 0.8rem;
  margin-top: 0.25rem;
}

/* ─── MFA code display ─── */
.mfa-card {
  background: var(--mfa-bg);
  border: 1px solid var(--mfa-border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
}

.mfa-code {
  font-family: var(--mono);
  font-size: 2.5rem;
  font-weight: 500;
  letter-spacing: 0.35em;
  color: var(--accent);
  margin: 0.75rem 0;
  text-align: center;
}

.mfa-timer {
  text-align: center;
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 0.5rem;
}

.mfa-progress-track {
  height: 3px;
  background: var(--border);
  border-radius: 999px;
  margin-top: 0.75rem;
  overflow: hidden;
}

.mfa-progress-bar {
  height: 100%;
  width: 0;
  background: var(--accent);
  border-radius: 999px;
  transition: width 1s linear;
}

.mfa-timer strong { color: var(--warning); }

/* ─── App download ─── */
.app-download-card { margin-bottom: 1.5rem; }

.app-download-meta {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.app-download-icon {
  width: 52px;
  height: 52px;
  border-radius: var(--radius);
  background: var(--accent-dim);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.app-download-unavailable code {
  font-family: var(--mono);
  font-size: 0.8rem;
  background: var(--surface-inset);
  padding: 0.1rem 0.35rem;
  border-radius: var(--radius-sm);
}

.app-download-login {
  margin-top: 1.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}

/* ─── Forms ─── */
.field { display: block; }

.field-label {
  display: block;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 0.4rem;
}

input, select, textarea {
  display: block;
  width: 100%;
  padding: 0.65rem 0.85rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font);
  font-size: 0.9rem;
  transition: border-color var(--transition), box-shadow var(--transition);
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

input::placeholder,
textarea::placeholder { color: var(--text-muted); }

textarea {
  min-height: 120px;
  font-family: var(--font);
  font-size: 0.9rem;
  resize: vertical;
  line-height: 1.45;
}

.modal-reason-input {
  min-height: 140px;
  width: 100%;
}

.field-invalid {
  border-color: var(--danger) !important;
  box-shadow: 0 0 0 3px var(--danger-dim) !important;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
}

/* ─── Buttons ─── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.55rem 1rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface-hover);
  color: var(--text);
  font-family: var(--font);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--transition), border-color var(--transition), transform 80ms ease;
}

.btn:hover { border-color: var(--border-strong); background: var(--surface-active); }
.btn:active { transform: scale(0.98); }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--btn-primary-text);
  font-weight: 600;
}

.btn-primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.btn-danger {
  background: var(--danger-dim);
  border-color: var(--danger-border);
  color: var(--danger);
}

.btn-danger:hover {
  background: var(--danger-hover-bg);
  border-color: var(--danger);
}

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-secondary);
}

.btn-ghost:hover {
  background: var(--surface);
  color: var(--text);
}

.btn-sm { padding: 0.35rem 0.65rem; font-size: 0.8rem; }
.btn-block { width: 100%; }

.btn-icon {
  width: 32px;
  height: 32px;
  padding: 0;
  font-size: 1.25rem;
  line-height: 1;
  border: none;
  background: transparent;
  color: var(--text-muted);
  border-radius: var(--radius-sm);
}

.btn-icon:hover { background: var(--surface-hover); color: var(--text); }

.tree-icon-btn {
  width: 30px;
  height: 30px;
  flex-shrink: 0;
}

.tree-icon-btn svg {
  width: 16px;
  height: 16px;
  display: block;
  pointer-events: none;
}

.tree-icon-btn.btn-danger,
.tree-icon-btn.tree-icon-danger:hover {
  color: var(--danger);
}

.tree-icon-btn.tree-icon-danger:hover {
  background: var(--danger-dim);
}

.tree-toolbar-btn {
  width: 36px;
  height: 36px;
}

.tree-toolbar-btn svg {
  width: 18px;
  height: 18px;
  display: block;
}

.tree-actions {
  display: flex;
  gap: 0.2rem;
  flex-shrink: 0;
  align-items: center;
}

.modal-picker-item-disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.modal-picker-item-disabled:has(input:checked) {
  background: transparent;
}

.mb-2 { margin-bottom: 0.75rem; }

.modal-filter-toggle {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 0.5rem;
}

.modal-filter-toggle input {
  width: auto;
  display: inline-block;
  padding: 0;
  border: none;
  background: transparent;
  box-shadow: none;
  flex-shrink: 0;
  accent-color: var(--accent);
}

.btn-group { display: flex; gap: 0.5rem; flex-wrap: wrap; }

label.btn {
  cursor: pointer;
}

label.btn input[type="file"] { display: none; }

.file-picker {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.file-picker-btn {
  flex-shrink: 0;
}

.file-picker-name {
  font-size: 0.875rem;
  color: var(--text-muted);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-picker-name.has-file {
  color: var(--text-secondary);
}

.form-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-inset);
  cursor: pointer;
}

.form-toggle-copy {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  min-width: 0;
}

.form-toggle-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
}

.form-toggle-hint {
  font-size: 0.8rem;
  color: var(--text-muted);
  line-height: 1.4;
}

.form-toggle-input {
  width: 2.75rem;
  height: 1.5rem;
  flex-shrink: 0;
  margin: 0;
  appearance: none;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  position: relative;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.form-toggle-input::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: calc(1.5rem - 6px);
  height: calc(1.5rem - 6px);
  border-radius: 50%;
  background: var(--text-muted);
  transition: transform 0.15s ease, background 0.15s ease;
}

.form-toggle-input:checked {
  background: var(--accent);
  border-color: var(--accent);
}

.form-toggle-input:checked::after {
  transform: translateX(1.25rem);
  background: #fff;
}

.form-toggle-input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ─── Tables ─── */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.table-wrap { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
}

th, td {
  text-align: left;
  padding: 0.85rem 1.25rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.875rem;
}

th {
  background: var(--surface-inset);
  color: var(--text-muted);
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--row-hover); }

td.actions {
  white-space: nowrap;
}

td.actions .btn-group { justify-content: flex-end; }

.btn-group-icons {
  gap: 0.35rem;
  flex-wrap: nowrap;
}

.users-table th:last-child,
.users-table td.actions {
  width: 1%;
  text-align: right;
}

.users-table .user-primary {
  font-weight: 600;
}

.users-table .user-email {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-top: 0.15rem;
}

.users-table .count-pill {
  display: inline-flex;
  min-width: 1.75rem;
  justify-content: center;
}

/* ─── Badges ─── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  background: var(--surface-active);
  color: var(--text-secondary);
}

.badge-success { background: var(--success-dim); color: var(--success); }
.badge-warning { background: var(--warning-dim); color: var(--warning); }
.badge-danger { background: var(--danger-dim); color: var(--danger); }
.badge-muted { background: var(--badge-muted-bg); color: var(--text-muted); font-weight: 500; text-transform: none; letter-spacing: 0; }

/* ─── Empty & loading states ─── */
.empty-state {
  text-align: center;
  padding: 3.5rem 2rem;
  color: var(--text-muted);
}

.empty-state-icon {
  width: 48px;
  height: 48px;
  margin: 0 auto 1rem;
  opacity: 0.4;
}

.empty-state h3 {
  font-size: 1rem;
  color: var(--text-secondary);
  margin-bottom: 0.35rem;
}

.empty-state p { font-size: 0.875rem; max-width: 320px; margin: 0 auto; }

.loading-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 4rem 2rem;
  color: var(--text-muted);
  gap: 1rem;
}

.spinner {
  width: 28px;
  height: 28px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ─── Drag & drop ─── */
.dnd-container {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.dnd-column h3 {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.5rem;
}

.dnd-list {
  min-height: 240px;
  background: var(--bg);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  padding: 0.5rem;
}

.dnd-list.drag-over {
  border-color: var(--accent);
  background: var(--accent-dim);
}

.dnd-item {
  padding: 0.6rem 0.85rem;
  margin-bottom: 0.35rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: grab;
  font-size: 0.875rem;
  transition: border-color var(--transition);
}

.dnd-item:hover { border-color: var(--border-strong); }
.dnd-item.dragging { opacity: 0.45; }
.dnd-item:last-child { margin-bottom: 0; }

/* ─── Device group tree ─── */
.tree-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.tree-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.55rem 0.85rem;
  padding-left: calc(0.85rem + var(--depth, 0) * 1.35rem);
  border-bottom: 1px solid var(--border);
  min-height: 2.5rem;
}

.tree-row:last-child { border-bottom: none; }

.tree-row-group {
  background: color-mix(in srgb, var(--bg) 55%, var(--surface));
  font-weight: 500;
}

.tree-row-device {
  background: var(--surface);
}

.tree-row-meta {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.tree-type-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  color: var(--text-muted);
}

.tree-type-icon svg {
  width: 16px;
  height: 16px;
  display: block;
}

.tree-row-group .tree-type-icon {
  color: var(--accent);
}

.tree-id {
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--text-muted);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.1rem 0.4rem;
  cursor: help;
}

.tree-section-title {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin: 1.25rem 0 0.5rem;
}

.tree-empty-hint {
  padding: 1rem 0.85rem;
  color: var(--text-muted);
  font-size: 0.875rem;
}

/* ─── Code preview ─── */
.apdu-preview {
  font-family: var(--mono);
  font-size: 0.78rem;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-all;
  background: var(--bg);
  border: 1px solid var(--border);
  padding: 1rem 1.25rem;
  border-radius: var(--radius);
  max-height: 360px;
  overflow: auto;
  color: var(--text-secondary);
}

/* ─── Invite token box ─── */
.token-box {
  margin-top: 1.25rem;
  padding: 1.25rem;
  background: var(--bg);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  box-shadow: 0 0 24px var(--accent-glow);
}

.token-value {
  font-family: var(--mono);
  font-size: 1.1rem;
  font-weight: 500;
  color: var(--accent);
  word-break: break-all;
  margin: 0.5rem 0;
  user-select: all;
}

/* ─── Back link ─── */
.back-link {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  color: var(--text-muted);
  font-size: 0.875rem;
  font-weight: 500;
  background: none;
  border: none;
  cursor: pointer;
  font-family: var(--font);
  padding: 0;
  margin-bottom: 1rem;
  transition: color var(--transition);
}

.back-link:hover { color: var(--accent); }

/* ─── Transaction list ─── */
.tx-list {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.tx-list-head,
.tx-row {
  display: grid;
  grid-template-columns: minmax(9rem, 11rem) minmax(0, 1fr) minmax(6.5rem, 8rem) 2rem;
  gap: 0.75rem 1rem;
  align-items: center;
  padding: 0.7rem 1rem;
}

.tx-list-head {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.tx-item + .tx-item {
  border-top: 1px solid var(--border);
}

.tx-row {
  width: 100%;
  border: none;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: background var(--transition);
}

.tx-row:hover {
  background: color-mix(in srgb, var(--accent) 6%, transparent);
}

.tx-item.is-open .tx-row {
  background: color-mix(in srgb, var(--accent) 8%, transparent);
}

.tx-col-when {
  font-size: 0.85rem;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.tx-col-card {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  min-width: 0;
}

.tx-col-card strong {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tx-col-brand {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: capitalize;
}

.tx-col-result {
  justify-self: start;
}

.tx-col-chevron {
  display: flex;
  justify-content: center;
  color: var(--text-muted);
}

.tx-row:hover .tx-col-chevron {
  color: var(--accent);
}

.tx-detail-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1.25rem;
  margin: 0.75rem 0 0.5rem;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.tx-detail-form {
  display: grid;
  grid-template-columns: minmax(140px, 200px) 1fr;
  gap: 0.75rem;
  align-items: start;
  margin-top: 0.75rem;
}

@media (max-width: 700px) {
  .tx-list-head {
    display: none;
  }

  .tx-row {
    grid-template-columns: 1fr auto 1.5rem;
    grid-template-areas:
      "when when chevron"
      "card result chevron";
    gap: 0.35rem 0.75rem;
    padding: 0.85rem 1rem;
  }

  .tx-col-when { grid-area: when; }
  .tx-col-card { grid-area: card; }
  .tx-col-result { grid-area: result; justify-self: end; align-self: center; }
  .tx-col-chevron { grid-area: chevron; align-self: start; }

  .tx-detail-form {
    grid-template-columns: 1fr;
  }
}

/* legacy tx-card kept for any leftover markup */
.tx-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  margin-bottom: 1rem;
}

.tx-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.75rem;
  flex-wrap: wrap;
}

.tx-card-title { font-weight: 600; }
.tx-card-meta { font-size: 0.8rem; color: var(--text-muted); }

.chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  max-width: 16rem;
}

.chip-list .badge {
  font-weight: 500;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ─── Modal ─── */
.modal-root {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: var(--overlay);
  backdrop-filter: blur(4px);
}

.modal {
  position: relative;
  width: 100%;
  max-width: 640px;
  max-height: 85vh;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  animation: modalIn 0.2s ease;
}

@keyframes modalIn {
  from { opacity: 0; transform: scale(0.96) translateY(8px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
}

.modal-header h3 { font-size: 1rem; font-weight: 600; }

.modal-body {
  padding: 1.25rem 1.5rem;
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

.modal-message {
  color: var(--text-secondary);
  font-size: 0.95rem;
  line-height: 1.55;
}

.modal-form .field { margin-bottom: 0; }

.modal-group-picker .field { margin-bottom: 0.5rem; }

.modal-picker-list {
  display: flex;
  flex-direction: column;
  gap: 0;
  max-height: min(360px, 50vh);
  overflow-y: auto;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
}

.modal-picker-item {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  margin: 0;
  padding: 0.5rem 0.65rem;
  min-height: 2.5rem;
  border: none;
  border-bottom: 1px solid var(--border);
  border-radius: 0;
  background: transparent;
  cursor: pointer;
  transition: background var(--transition);
}

.modal-picker-item:last-child {
  border-bottom: none;
}

.modal-picker-item:hover {
  background: var(--surface-hover);
}

.modal-picker-item:has(input:checked) {
  background: var(--accent-dim);
}

.modal-picker-item input {
  margin: 0;
  flex-shrink: 0;
  width: auto;
  display: inline-block;
  padding: 0;
  border: none;
  background: transparent;
  box-shadow: none;
  accent-color: var(--accent);
}

.modal-picker-label {
  display: flex;
  flex: 1;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem 0.75rem;
  flex-wrap: nowrap;
  min-width: 0;
}

.modal-picker-label strong {
  font-size: 0.875rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
  flex: 0 1 auto;
}

.modal-picker-meta {
  font-size: 0.78rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
  flex: 1 1 auto;
  text-align: right;
}

.modal-picker-item .badge {
  flex-shrink: 0;
  padding: 0.1rem 0.45rem;
  font-size: 0.65rem;
}

/* ─── Toasts ─── */
#toast-container {
  position: fixed;
  bottom: 1.25rem;
  right: 1.25rem;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  pointer-events: none;
}

.toast {
  padding: 0.75rem 1.1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  font-size: 0.875rem;
  animation: toastIn 0.25s ease;
  pointer-events: auto;
  max-width: 360px;
}

.toast.success { border-left: 3px solid var(--success); }
.toast.error { border-left: 3px solid var(--danger); }
.toast.info { border-left: 3px solid var(--accent); }

@keyframes toastIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* ─── Tabs ─── */
.tabs {
  display: flex;
  gap: 0.25rem;
  padding: 0.25rem;
  background: var(--bg);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  width: fit-content;
  margin-bottom: 1.25rem;
}

.tabs button {
  padding: 0.45rem 1rem;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-family: var(--font);
  font-size: 0.85rem;
  font-weight: 500;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
}

.tabs button.active, .tabs button:hover {
  background: var(--surface);
  color: var(--text);
}

/* ─── Responsive ─── */
@media (max-width: 900px) {
  body {
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
  }

  body.nav-open {
    overflow: hidden;
    touch-action: none;
  }

  /* Auth: single column with compact brand header */
  .auth-screen {
    grid-template-columns: 1fr;
  }

  .auth-panel-brand {
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: calc(1.25rem + env(safe-area-inset-top)) 1.5rem 1rem;
    justify-content: flex-start;
  }

  .auth-panel-brand h1 {
    font-size: 1.35rem;
    margin: 0.75rem 0 0;
  }

  .auth-panel-brand p {
    display: none;
  }

  .auth-logo {
    width: min(160px, 55%);
  }

  .auth-panel-form {
    padding: 1.5rem 1.25rem calc(1.5rem + env(safe-area-inset-bottom));
    justify-content: flex-start;
  }

  .auth-theme-toggle {
    top: calc(0.75rem + env(safe-area-inset-top));
    right: calc(0.75rem + env(safe-area-inset-right));
  }

  /* Mobile top bar */
  .mobile-topbar {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    position: sticky;
    top: 0;
    z-index: 90;
    height: calc(56px + env(safe-area-inset-top));
    padding: env(safe-area-inset-top) 0.85rem 0;
    background: var(--bg-elevated);
    border-bottom: 1px solid var(--border);
  }

  .mobile-menu-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
    flex-shrink: 0;
  }

  .mobile-menu-btn:hover {
    background: var(--surface-hover);
  }

  .mobile-topbar-logo {
    height: 24px;
    width: auto;
    flex: 1;
    object-fit: contain;
    object-position: left center;
  }

  .mobile-topbar .theme-toggle {
    width: 44px;
    height: 44px;
  }

  .desktop-theme-toggle {
    display: none;
  }

  /* Backdrop for drawer */
  .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 110;
    background: var(--overlay);
    backdrop-filter: blur(2px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
  }

  body.nav-open .sidebar-backdrop {
    opacity: 1;
    pointer-events: auto;
  }

  /* Sidebar as left drawer */
  .sidebar {
    width: min(300px, 86vw);
    transform: translateX(-105%);
    transition: transform 0.25s ease;
    z-index: 120;
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
    box-shadow: none;
  }

  body.nav-open .sidebar {
    transform: translateX(0);
    box-shadow: var(--shadow-lg);
  }

  .sidebar-close {
    display: inline-flex;
    width: 44px;
    height: 44px;
  }

  .sidebar-nav {
    flex-direction: column;
    overflow-x: hidden;
    overflow-y: auto;
    padding: 0.75rem;
  }

  .nav-item {
    padding: 0.85rem 1rem;
    min-height: 48px;
    font-size: 0.95rem;
  }

  .sidebar-footer {
    display: block;
    padding-bottom: calc(1rem + env(safe-area-inset-bottom));
  }

  .app-shell {
    flex-direction: column;
  }

  .app-main {
    margin-left: 0;
    min-height: 0;
    flex: 1;
  }

  .content-header,
  .view-root {
    padding-left: 1rem;
    padding-right: 1rem;
  }

  .content-header {
    padding-top: 1.15rem;
  }

  .page-title {
    font-size: 1.35rem;
  }

  .btn {
    min-height: 44px;
    padding: 0.65rem 1.1rem;
  }

  .btn-sm {
    min-height: 40px;
    padding: 0.45rem 0.75rem;
  }

  .btn-icon {
    width: 44px;
    height: 44px;
  }

  .theme-toggle {
    width: 44px;
    height: 44px;
  }

  .notif-bell {
    width: 44px;
    height: 44px;
  }

  .tree-icon-btn {
    width: 44px;
    height: 44px;
  }

  .tree-icon-btn svg {
    width: 18px;
    height: 18px;
  }

  .tree-toolbar-btn {
    width: 44px;
    height: 44px;
  }

  .tree-row {
    flex-wrap: wrap;
    align-items: flex-start;
    padding-top: 0.75rem;
    padding-bottom: 0.75rem;
    gap: 0.65rem;
  }

  .tree-row-meta {
    flex: 1 1 100%;
  }

  .tree-actions {
    flex: 1 1 100%;
    justify-content: flex-start;
    gap: 0.35rem;
    padding-left: 0;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .stats-grid {
    grid-template-columns: 1fr;
  }

  .dnd-container {
    grid-template-columns: 1fr;
  }

  /* Modals as bottom sheets */
  .modal-root {
    align-items: flex-end;
    justify-content: stretch;
    padding: 0;
  }

  .modal {
    max-width: none;
    width: 100%;
    max-height: min(92vh, 100%);
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    border-left: none;
    border-right: none;
    border-bottom: none;
    padding-bottom: env(safe-area-inset-bottom);
    animation: sheetIn 0.25s ease;
  }

  @keyframes sheetIn {
    from { opacity: 0; transform: translateY(100%); }
    to { opacity: 1; transform: translateY(0); }
  }

  .modal-header,
  .modal-body,
  .modal-footer {
    padding-left: 1.15rem;
    padding-right: 1.15rem;
  }

  .modal-footer {
    flex-wrap: wrap;
  }

  .modal-footer .btn {
    flex: 1 1 auto;
  }

  #toast-container {
    left: 1rem;
    right: 1rem;
    bottom: calc(1rem + env(safe-area-inset-bottom));
  }

  .toast {
    max-width: none;
  }

  .tabs {
    width: 100%;
    overflow-x: auto;
  }

  .tabs button {
    min-height: 44px;
    flex: 1;
  }
}

@media (max-width: 600px) {
  .mfa-code {
    font-size: 1.75rem;
    letter-spacing: 0.2em;
  }

  .sync-pill {
    font-size: 0.75rem;
    padding: 0.4rem 0.7rem;
  }

  .card-header,
  .card-body,
  .card-footer,
  .card-padded {
    padding-left: 1rem;
    padding-right: 1rem;
  }
}
