/* ═════════════════════════════════════════
   Twilight Admin — Design System v2
   ═════════════════════════════════════════ */

/* ── Theme: Twilight (default green dark) ── */
:root, [data-theme="twilight"] {
  --primary: #3fb950;
  --primary-hover: #2ea043;
  --primary-bg: #3fb95018;
  --primary-gradient: linear-gradient(135deg, #3fb950, #2d8340);
  --accent: #bc8cff;
  --accent-bg: #bc8cff20;
  --warn: #d29922;
  --warn-bg: #d2992220;
  --error: #f85149;
  --error-bg: #f8514920;
  --bg: #0a0e13;
  --bg-secondary: #10151c;
  --surface: #151b24;
  --surface2: #1a212b;
  --surface3: #1f2733;
  --border: #252d38;
  --border-light: #303841;
  --on-bg: #e6edf3;
  --on-surface: #c4ccd4;
  --on-dim: #6e7681;
  --on-muted: #4a525e;
  --shadow-sm: 0 1px 3px rgba(0,0,0,.3);
  --shadow: 0 4px 24px rgba(0,0,0,.35);
  --shadow-lg: 0 8px 40px rgba(0,0,0,.45);
  --gradient-hero: radial-gradient(ellipse at 50% 0%, #3fb95012 0%, transparent 70%);
  --glass-bg: #151b24f0;
}

/* ── Theme: Ocean (blue dark) ── */
[data-theme="ocean"] {
  --primary: #58a6ff;
  --primary-hover: #388bfd;
  --primary-bg: #58a6ff18;
  --primary-gradient: linear-gradient(135deg, #58a6ff, #1f6feb);
  --accent: #79c0ff;
  --accent-bg: #79c0ff20;
  --warn: #d29922;
  --warn-bg: #d2992220;
  --error: #f85149;
  --error-bg: #f8514920;
  --bg: #0b111e;
  --bg-secondary: #101726;
  --surface: #131c2e;
  --surface2: #182237;
  --surface3: #1d2840;
  --border: #212d45;
  --border-light: #2a3852;
  --on-bg: #e3ecfa;
  --on-surface: #c2cdde;
  --on-dim: #69758a;
  --on-muted: #4a5568;
  --shadow-sm: 0 1px 3px rgba(0,0,0,.3);
  --shadow: 0 4px 24px rgba(0,0,0,.35);
  --shadow-lg: 0 8px 40px rgba(0,0,0,.45);
  --gradient-hero: radial-gradient(ellipse at 50% 0%, #58a6ff12 0%, transparent 70%);
  --glass-bg: #131c2ef0;
}

/* ── Theme: Amethyst (purple dark) ── */
[data-theme="amethyst"] {
  --primary: #a371f7;
  --primary-hover: #8b5cf6;
  --primary-bg: #a371f718;
  --primary-gradient: linear-gradient(135deg, #a371f7, #7c3aed);
  --accent: #c084fc;
  --accent-bg: #c084fc20;
  --warn: #d29922;
  --warn-bg: #d2992220;
  --error: #f85149;
  --error-bg: #f8514920;
  --bg: #0f0c1a;
  --bg-secondary: #151124;
  --surface: #1a142e;
  --surface2: #1f1838;
  --surface3: #251d42;
  --border: #2d2648;
  --border-light: #383054;
  --on-bg: #e8e0f5;
  --on-surface: #d0c8e2;
  --on-dim: #7b718e;
  --on-muted: #544c68;
  --shadow-sm: 0 1px 3px rgba(0,0,0,.3);
  --shadow: 0 4px 24px rgba(0,0,0,.35);
  --shadow-lg: 0 8px 40px rgba(0,0,0,.45);
  --gradient-hero: radial-gradient(ellipse at 50% 0%, #a371f714 0%, transparent 70%);
  --glass-bg: #1a142ef0;
}

/* ── Theme: Ember (warm orange dark) ── */
[data-theme="ember"] {
  --primary: #f0883e;
  --primary-hover: #e06c25;
  --primary-bg: #f0883e18;
  --primary-gradient: linear-gradient(135deg, #f0883e, #c94d1a);
  --accent: #f7b267;
  --accent-bg: #f7b26720;
  --warn: #e3b341;
  --warn-bg: #e3b34120;
  --error: #f85149;
  --error-bg: #f8514920;
  --bg: #100d0a;
  --bg-secondary: #17120e;
  --surface: #1c1610;
  --surface2: #221b14;
  --surface3: #2a2118;
  --border: #33271c;
  --border-light: #3f3226;
  --on-bg: #f0e6d8;
  --on-surface: #d9cebd;
  --on-dim: #7a7060;
  --on-muted: #544c40;
  --shadow-sm: 0 1px 3px rgba(0,0,0,.3);
  --shadow: 0 4px 24px rgba(0,0,0,.35);
  --shadow-lg: 0 8px 40px rgba(0,0,0,.45);
  --gradient-hero: radial-gradient(ellipse at 50% 0%, #f0883e12 0%, transparent 70%);
  --glass-bg: #1c1610f0;
}

/* ── Theme: Light ── */
[data-theme="light"] {
  --primary: #1a6b52;
  --primary-hover: #145a44;
  --primary-bg: #1a6b5212;
  --primary-gradient: linear-gradient(135deg, #1a6b52, #0f4d3a);
  --accent: #6d41a0;
  --accent-bg: #6d41a018;
  --warn: #9a6300;
  --warn-bg: #9a630018;
  --error: #cf222e;
  --error-bg: #cf222e18;
  --bg: #f6f8fa;
  --bg-secondary: #eff1f3;
  --surface: #ffffff;
  --surface2: #f3f4f6;
  --surface3: #e8eaed;
  --border: #d0d7de;
  --border-light: #d8dee4;
  --on-bg: #1f2328;
  --on-surface: #24292f;
  --on-dim: #656d76;
  --on-muted: #8b949e;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.06);
  --shadow: 0 3px 16px rgba(0,0,0,.08);
  --shadow-lg: 0 8px 32px rgba(0,0,0,.12);
  --gradient-hero: radial-gradient(ellipse at 50% 0%, #1a6b5210 0%, transparent 70%);
  --glass-bg: #fffffff5;
}

/* ═════════════════════════════════════════
   Base Reset
   ═════════════════════════════════════════ */
*, *::before, *::after { box-sizing: border-box; margin: 0; }

html {
  --radius: 14px;
  --radius-sm: 8px;
  --radius-xs: 6px;
  --radius-full: 9999px;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans SC', sans-serif;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --transition-fast: .15s ease;
  --transition-base: .2s ease;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--on-bg);
  min-height: 100vh;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  padding-bottom: var(--safe-bottom);
  transition: background var(--transition-base), color var(--transition-base);
}

/* ═════════════════════════════════════════
   Setup Screen
   ═════════════════════════════════════════ */
.setup-screen {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; min-height: 100dvh;
  padding: 24px;
  background: var(--gradient-hero);
  transition: background var(--transition-base);
}
.setup-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 20px; padding: clamp(32px, 5vw, 44px) clamp(24px, 5vw, 40px);
  max-width: 420px; width: 100%; text-align: center;
  box-shadow: var(--shadow-lg);
  animation: fadeUp .5s cubic-bezier(.16,1,.3,1);
  transition: background var(--transition-base), border-color var(--transition-base);
}
@keyframes fadeUp { from { opacity: 0; transform: translateY(20px); } }
.setup-logo {
  width: 60px; height: 60px;
  background: var(--primary-gradient);
  border-radius: 16px; margin: 0 auto 20px;
  display: flex; align-items: center; justify-content: center;
  font-size: 28px; color: #fff; font-weight: 800;
  box-shadow: 0 8px 24px var(--primary-bg);
}
.setup-card h2 { font-size: 22px; font-weight: 700; margin-bottom: 4px; letter-spacing: -.3px; }
.setup-card > p { color: var(--on-dim); font-size: 14px; margin-bottom: 28px; }
.setup-card .error-msg {
  background: var(--error-bg); border: 1px solid var(--error); border-radius: var(--radius-sm);
  color: var(--error); font-size: 13px; padding: 10px 14px; margin-bottom: 16px;
  display: none; white-space: pre-line; text-align: left; line-height: 1.6;
}
.form-group { text-align: left; margin-bottom: 18px; }
.form-group label {
  display: block; font-size: 11px; font-weight: 700; color: var(--on-dim);
  margin-bottom: 6px; text-transform: uppercase; letter-spacing: .6px;
}
.form-group input, .modal input, .modal select {
  width: 100%; background: var(--bg-secondary); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 10px 14px;
  font-size: clamp(14px, 2.5vw, 16px); color: var(--on-bg);
  outline: none; font-family: var(--font);
  transition: border-color var(--transition-base), box-shadow var(--transition-base), background var(--transition-base);
}
.form-group input:focus, .modal input:focus, .modal select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-bg);
}
.form-group input::placeholder { color: var(--on-muted); }

/* ═════════════════════════════════════════
   Header
   ═════════════════════════════════════════ */
header {
  background: var(--glass-bg);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
  padding: 0 clamp(14px, 3vw, 24px);
  height: 56px; display: flex; align-items: center; justify-content: space-between;
  position: sticky; top: 0; z-index: 100;
  transition: background var(--transition-base), border-color var(--transition-base);
}
.header-left { display: flex; align-items: center; gap: 10px; }
.header-logo {
  width: 34px; height: 34px;
  background: var(--primary-gradient);
  border-radius: 10px; display: flex; align-items: center; justify-content: center;
  font-size: 17px; color: #fff; font-weight: 800;
  transition: background var(--transition-base);
}
header h1 { font-size: clamp(14px, 2.5vw, 17px); font-weight: 700; letter-spacing: -.3px; }
header h1 em { font-style: normal; color: var(--primary); transition: color var(--transition-base); }
.header-actions { display: flex; gap: 4px; align-items: center; }
.header-status {
  display: flex; align-items: center; gap: 6px; font-size: 12px;
  color: var(--on-dim); margin-right: 6px; padding: 4px 10px;
  background: var(--primary-bg); border-radius: var(--radius-full);
  transition: background var(--transition-base);
}
.header-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--primary); animation: pulse 2s infinite;
}
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.35} }

/* ── Theme Picker ── */
.theme-picker-btn {
  position: relative;
}
.theme-picker-popup {
  display: none; position: absolute; top: calc(100% + 8px); right: 0;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px;
  box-shadow: var(--shadow-lg); z-index: 110; min-width: 200px;
  animation: fadeUp .15s ease;
}
.theme-picker-popup.show { display: block; }
.theme-swatches {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px;
}
.theme-swatch {
  padding: 10px 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); cursor: pointer;
  font-size: 12px; font-weight: 600; color: var(--on-surface);
  background: var(--surface2); text-align: center;
  transition: all var(--transition-fast);
  -webkit-tap-highlight-color: transparent;
  display: flex; align-items: center; gap: 8px; justify-content: center;
}
.theme-swatch:hover { border-color: var(--border-light); background: var(--surface3); }
.theme-swatch.active { border-color: var(--primary); background: var(--primary-bg); color: var(--primary); }
.theme-swatch-dot {
  width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0;
  border: 1px solid rgba(255,255,255,.15);
}
.theme-swatch-dot.twilight { background: linear-gradient(135deg, #3fb950, #2d8340); }
.theme-swatch-dot.ocean { background: linear-gradient(135deg, #58a6ff, #1f6feb); }
.theme-swatch-dot.amethyst { background: linear-gradient(135deg, #a371f7, #7c3aed); }
.theme-swatch-dot.ember { background: linear-gradient(135deg, #f0883e, #c94d1a); }
.theme-swatch-dot.light { background: linear-gradient(135deg, #1a6b52, #0f4d3a); }

/* ═════════════════════════════════════════
   Buttons
   ═════════════════════════════════════════ */
.btn {
  padding: 8px 16px; border-radius: var(--radius-sm); border: none;
  font-size: 13px; font-weight: 600; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px;
  font-family: var(--font);
  transition: all var(--transition-fast);
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent; user-select: none;
  min-height: 36px;
}
.btn:active { transform: scale(.96); }
.btn:disabled { opacity: .45; pointer-events: none; }

.btn-primary {
  background: var(--primary); color: #fff;
  border: 1px solid var(--primary-hover);
}
.btn-primary:hover { filter: brightness(1.1); }

.btn-outline {
  background: transparent; border: 1px solid var(--border); color: var(--on-surface);
}
.btn-outline:hover { background: var(--surface2); border-color: var(--border-light); }

.btn-ghost {
  background: transparent; border: none; color: var(--on-dim);
}
.btn-ghost:hover { color: var(--on-surface); background: var(--surface2); }

.btn-danger {
  background: var(--error-bg); border: 1px solid var(--error); color: var(--error);
}
.btn-danger:hover { background: var(--error); color: #fff; }

.btn-xs { padding: 5px 12px; font-size: 12px; border-radius: var(--radius-xs); min-height: 30px; }
.btn-icon { padding: 8px; border-radius: var(--radius-sm); min-width: 36px; min-height: 36px; justify-content: center; }

/* ═════════════════════════════════════════
   FAB (mobile)
   ═════════════════════════════════════════ */
.fab {
  display: none;
  position: fixed; bottom: calc(24px + var(--safe-bottom)); right: clamp(16px, 4vw, 24px);
  width: 54px; height: 54px; border-radius: 50%;
  background: var(--primary); color: #fff;
  border: 1px solid var(--primary-hover);
  box-shadow: 0 4px 20px var(--primary-bg);
  align-items: center; justify-content: center; cursor: pointer;
  z-index: 90; transition: transform var(--transition-fast), box-shadow var(--transition-fast);
  font-size: 24px; font-weight: 300;
  -webkit-tap-highlight-color: transparent;
}
.fab:active { transform: scale(.88); }
.fab:hover { box-shadow: 0 6px 28px var(--primary-bg); }

/* ═════════════════════════════════════════
   Container
   ═════════════════════════════════════════ */
.container {
  max-width: 1200px; margin: 0 auto;
  padding: clamp(14px, 3vw, 20px) clamp(14px, 3vw, 24px) 40px;
}

/* ═════════════════════════════════════════
   Stats Grid
   ═════════════════════════════════════════ */
.stats-grid {
  display: grid; grid-template-columns: repeat(4, 1fr);
  gap: clamp(8px, 1.5vw, 14px); margin-bottom: 20px;
}
.stat-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: clamp(14px, 2vw, 20px);
  display: flex; align-items: center; gap: clamp(10px, 2vw, 14px);
  cursor: pointer; position: relative; overflow: hidden;
  transition: border-color var(--transition-base), transform var(--transition-fast), box-shadow var(--transition-base);
  -webkit-tap-highlight-color: transparent;
}
.stat-card::before {
  content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 3px;
  background: transparent; border-radius: 0 2px 2px 0;
  transition: background var(--transition-base);
}
.stat-card:hover { border-color: var(--border-light); transform: translateY(-1px); box-shadow: var(--shadow-sm); }
.stat-card:active { transform: scale(.98); }
.stat-card.active { border-color: var(--primary); box-shadow: 0 0 0 1px var(--primary-bg); }
.stat-card.active::before { background: var(--primary); }

.stat-dot {
  width: clamp(38px, 5vw, 44px); height: clamp(38px, 5vw, 44px);
  border-radius: 12px; display: flex; align-items: center; justify-content: center;
  font-size: clamp(16px, 2.5vw, 20px); flex-shrink: 0;
  transition: background var(--transition-base);
}
.stat-dot.total { background: var(--primary-bg); color: var(--primary); }
.stat-dot.free { background: var(--surface3); color: var(--on-dim); }
.stat-dot.premium { background: var(--warn-bg); color: var(--warn); }
.stat-dot.pro { background: var(--accent-bg); color: var(--accent); }
.stat-value {
  font-size: clamp(24px, 3vw, 28px); font-weight: 800;
  line-height: 1; letter-spacing: -.5px; font-variant-numeric: tabular-nums;
}
.stat-label { font-size: clamp(11px, 1.5vw, 12px); color: var(--on-dim); margin-top: 3px; font-weight: 500; }

/* ═════════════════════════════════════════
   Table
   ═════════════════════════════════════════ */
.table-wrap {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden;
  transition: background var(--transition-base), border-color var(--transition-base);
  box-shadow: var(--shadow-sm);
}
.toolbar {
  padding: 12px clamp(14px, 2vw, 20px);
  display: flex; gap: 10px; align-items: center;
  border-bottom: 1px solid var(--border); flex-wrap: wrap;
  transition: border-color var(--transition-base);
}
.search-box { position: relative; flex: 1; max-width: 280px; min-width: 150px; }
.search-box svg {
  position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
  width: 15px; height: 15px; color: var(--on-dim); pointer-events: none;
}
.search-box input {
  width: 100%; background: var(--bg-secondary); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 8px 14px 8px 34px;
  font-size: 13px; color: var(--on-bg); outline: none; font-family: var(--font);
  transition: border-color var(--transition-base), background var(--transition-base);
}
.search-box input:focus { border-color: var(--primary); }
.filter-chip {
  padding: 6px 14px; border-radius: var(--radius-full); font-size: 12px; font-weight: 600;
  cursor: pointer; background: var(--bg-secondary); border: 1px solid var(--border);
  color: var(--on-dim); user-select: none;
  transition: all var(--transition-fast);
  -webkit-tap-highlight-color: transparent;
  min-height: 32px; display: inline-flex; align-items: center;
}
.filter-chip:hover { color: var(--on-surface); border-color: var(--border-light); }
.filter-chip.active {
  background: var(--primary-bg); border-color: var(--primary); color: var(--primary);
}
.result-count { font-size: 12px; color: var(--on-dim); margin-left: auto; }
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* Desktop table */
table { width: 100%; border-collapse: collapse; }
thead th {
  text-align: left; padding: 10px clamp(12px, 2vw, 18px);
  font-size: 11px; font-weight: 700; color: var(--on-dim);
  text-transform: uppercase; letter-spacing: .5px;
  background: var(--surface2); border-bottom: 1px solid var(--border);
  transition: background var(--transition-base), border-color var(--transition-base);
}
thead th:last-child { text-align: right; }
tbody td {
  padding: 12px clamp(12px, 2vw, 18px); border-bottom: 1px solid var(--border);
  font-size: 13px; vertical-align: middle;
  transition: background var(--transition-fast), border-color var(--transition-base);
}
tbody tr { transition: background var(--transition-fast); }
tbody tr:hover td { background: var(--surface2); }
tbody tr:last-child td { border-bottom: none; }

.user-cell { display: flex; align-items: center; gap: 10px; }
.user-avatar {
  width: 34px; height: 34px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700; color: #fff;
}
.avatar-free { background: var(--on-dim); }
.avatar-premium { background: linear-gradient(135deg, var(--warn), #e3b341); }
.avatar-pro { background: linear-gradient(135deg, var(--accent), #8b5cf6); }
.user-name { font-weight: 600; }
.user-email { font-size: 11px; color: var(--on-dim); margin-top: 1px; }

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 10px; border-radius: var(--radius-full);
  font-size: 11px; font-weight: 700;
}
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; }
.badge-free { background: var(--surface3); color: var(--on-dim); }
.badge-free::before { background: var(--on-dim); }
.badge-premium { background: var(--warn-bg); color: var(--warn); }
.badge-premium::before { background: var(--warn); }
.badge-pro { background: var(--accent-bg); color: var(--accent); }
.badge-pro::before { background: var(--accent); }

.expiry-warn { color: var(--warn) !important; font-weight: 600; }
.expiry-over { color: var(--error) !important; font-weight: 600; }

.actions-cell { display: flex; gap: 5px; justify-content: flex-end; align-items: center; }
.actions-cell select {
  background: var(--bg-secondary); border: 1px solid var(--border); color: var(--on-dim);
  padding: 4px 6px; border-radius: var(--radius-xs); font-size: 11px;
  font-family: var(--font); cursor: pointer; min-height: 30px;
  transition: border-color var(--transition-base);
}

/* ═════════════════════════════════════════
   User Cards (mobile)
   ═════════════════════════════════════════ */
.user-cards { display: none; }
.user-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px;
  animation: fadeUp .3s cubic-bezier(.16,1,.3,1);
  transition: background var(--transition-base), border-color var(--transition-base);
}
.user-card + .user-card { margin-top: 10px; }
.user-card-header { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.user-card-body { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; font-size: 12px; }
.user-card-body .meta-label {
  color: var(--on-dim); font-size: 10px; text-transform: uppercase; letter-spacing: .4px; margin-bottom: 2px;
}
.user-card-actions {
  display: flex; gap: 6px; margin-top: 14px; padding-top: 14px;
  border-top: 1px solid var(--border);
  transition: border-color var(--transition-base);
}

/* ═════════════════════════════════════════
   Empty State
   ═════════════════════════════════════════ */
.empty-state { text-align: center; padding: clamp(48px, 12vw, 72px) 20px; }
.empty-icon {
  width: 64px; height: 64px; border-radius: 50%; background: var(--surface2);
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 16px; font-size: 28px;
  transition: background var(--transition-base);
}
.empty-state h3 { font-size: 16px; font-weight: 700; margin-bottom: 6px; }
.empty-state p { font-size: 13px; color: var(--on-dim); }

/* ═════════════════════════════════════════
   Modal
   ═════════════════════════════════════════ */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.55);
  backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  z-index: 200; padding: 20px;
  animation: fadeIn .2s ease;
}
@keyframes fadeIn { from { opacity: 0; } }
.modal {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 18px; padding: clamp(20px, 4vw, 28px);
  max-width: 440px; width: 100%;
  max-height: 90vh; max-height: 90dvh; overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: modalIn .25s cubic-bezier(.16,1,.3,1);
  transition: background var(--transition-base), border-color var(--transition-base);
}
@keyframes modalIn { from { transform: translateY(16px) scale(.97); opacity: 0; } }
.modal h2 { font-size: 18px; font-weight: 700; margin-bottom: 18px; letter-spacing: -.3px; }
.modal .form-group { margin-bottom: 14px; }
.modal input, .modal select {
  width: 100%; background: var(--bg-secondary); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 10px 12px;
  font-size: clamp(14px, 2.5vw, 16px); color: var(--on-bg);
  outline: none; font-family: var(--font);
  transition: border-color var(--transition-base), box-shadow var(--transition-base), background var(--transition-base);
}
.modal input:focus, .modal select:focus {
  border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-bg);
}
.modal-btn-row { display: flex; gap: 10px; justify-content: flex-end; margin-top: 22px; }
.membership-toggle { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.membership-toggle button {
  padding: 10px 8px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--bg-secondary);
  color: var(--on-dim); font-size: 12px; font-weight: 600; cursor: pointer;
  font-family: var(--font); transition: all var(--transition-fast);
  -webkit-tap-highlight-color: transparent;
}
.membership-toggle button:hover { border-color: var(--border-light); color: var(--on-surface); }
.membership-toggle button.selected {
  background: var(--primary-bg); border-color: var(--primary); color: var(--primary);
}
.membership-toggle button.selected[data-value="premium"] {
  background: var(--warn-bg); border-color: var(--warn); color: var(--warn);
}
.membership-toggle button.selected[data-value="pro"] {
  background: var(--accent-bg); border-color: var(--accent); color: var(--accent);
}

/* ═════════════════════════════════════════
   Confirm Dialog
   ═════════════════════════════════════════ */
.confirm-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.55);
  backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  z-index: 250; padding: 20px;
  animation: fadeIn .2s ease;
}
.confirm-box {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; padding: 28px; max-width: 380px; width: 100%;
  text-align: center; box-shadow: var(--shadow-lg);
  animation: modalIn .25s cubic-bezier(.16,1,.3,1);
  transition: background var(--transition-base), border-color var(--transition-base);
}
.confirm-box .confirm-icon {
  width: 52px; height: 52px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 16px; font-size: 24px;
  transition: background var(--transition-base);
}
.confirm-box h3 { font-size: 16px; font-weight: 700; margin-bottom: 8px; }
.confirm-box p { font-size: 13px; color: var(--on-dim); margin-bottom: 22px; line-height: 1.6; }

/* ── Password Result Display ── */
.password-display {
  background: var(--bg-secondary); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 16px; text-align: center;
  transition: background var(--transition-base), border-color var(--transition-base);
}
.password-display code {
  display: block; font-family: 'SF Mono', 'Cascadia Code', 'Consolas', monospace;
  padding: 10px; border-radius: var(--radius-xs);
  background: var(--surface2); font-size: 18px;
  font-weight: 700; letter-spacing: 2px; color: var(--primary);
  user-select: all; cursor: text; word-break: break-all;
  transition: background var(--transition-base), color var(--transition-base);
}

/* ═════════════════════════════════════════
   Toast
   ═════════════════════════════════════════ */
.toasts {
  position: fixed; bottom: calc(20px + var(--safe-bottom));
  right: clamp(12px, 3vw, 24px);
  z-index: 300; display: flex; flex-direction: column; gap: 8px;
  pointer-events: none;
}
.toast {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 18px; border-radius: var(--radius-sm);
  font-size: 13px; font-weight: 500;
  box-shadow: var(--shadow); pointer-events: auto;
  min-width: 220px; max-width: min(380px, 90vw);
  animation: toastIn .35s cubic-bezier(.16,1,.3,1);
  overflow: hidden; position: relative;
}
.toast::after {
  content: ''; position: absolute; bottom: 0; left: 0; height: 2px;
  background: currentColor; opacity: .3; animation: toastTimer 2.8s linear forwards;
}
@keyframes toastTimer { from { width: 100%; } }
@keyframes toastIn { from { transform: translateY(20px); opacity: 0; } }
.toast-success { background: var(--primary-bg); border: 1px solid var(--primary); color: var(--primary); }
.toast-error { background: var(--error-bg); border: 1px solid var(--error); color: var(--error); }
.toast-icon { font-size: 15px; flex-shrink: 0; }

/* ═════════════════════════════════════════
   Skeleton
   ═════════════════════════════════════════ */
.skeleton-bar {
  height: 14px; border-radius: var(--radius-xs);
  background: var(--surface2);
  animation: skeletonPulse 1.8s ease-in-out infinite;
  transition: background var(--transition-base);
}
.skeleton-avatar { width: 34px; height: 34px; border-radius: 50%; }
@keyframes skeletonPulse {
  0%,100% { opacity: .4; }
  50% { opacity: .7; }
}

/* ═════════════════════════════════════════
   Sort Buttons
   ═════════════════════════════════════════ */
.sort-btn {
  padding: 5px 10px; border-radius: var(--radius-xs);
  border: 1px solid var(--border); background: var(--bg-secondary);
  color: var(--on-dim); font-size: 11px; font-weight: 600; cursor: pointer;
  font-family: var(--font); transition: all var(--transition-fast);
  display: inline-flex; align-items: center; gap: 4px;
}
.sort-btn:hover { border-color: var(--border-light); color: var(--on-surface); }
.sort-btn.active { background: var(--primary-bg); border-color: var(--primary); color: var(--primary); }
.sort-arrow { font-size: 10px; }

/* ═════════════════════════════════════════
   Tooltip
   ═════════════════════════════════════════ */
[data-tooltip] { position: relative; }
[data-tooltip]:hover::after {
  content: attr(data-tooltip); position: absolute; bottom: -28px; left: 50%;
  transform: translateX(-50%); background: var(--surface3); color: var(--on-surface);
  padding: 4px 12px; border-radius: var(--radius-xs); font-size: 11px;
  white-space: nowrap; z-index: 10; border: 1px solid var(--border);
  pointer-events: none;
}

/* ═════════════════════════════════════════
   Loading Bar
   ═════════════════════════════════════════ */
.loading-bar {
  height: 2px; background: linear-gradient(90deg, transparent, var(--primary), transparent);
  animation: loadingSlide 1.2s ease-in-out infinite;
  position: fixed; top: 0; left: 0; right: 0; z-index: 200;
  display: none;
}
@keyframes loadingSlide { 0% { transform: translateX(-100%); } 100% { transform: translateX(100%); } }

/* ═════════════════════════════════════════
   Bulk Action Bar
   ═════════════════════════════════════════ */
.bulk-bar {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 10px 16px; margin-top: 12px;
  display: none; align-items: center; gap: 8px;
  flex-wrap: wrap; animation: fadeUp .25s ease;
  position: sticky; bottom: 4px; z-index: 50;
  transition: background var(--transition-base), border-color var(--transition-base);
}
.bulk-bar span { font-size: 13px; color: var(--on-surface); }

/* ═════════════════════════════════════════
   Settings Panel
   ═════════════════════════════════════════ */
.settings-modal { max-width: 440px; }
.settings-section {
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 16px; margin-bottom: 14px;
  transition: background var(--transition-base), border-color var(--transition-base);
}
.settings-section h3 {
  font-size: 12px; font-weight: 700; color: var(--on-dim);
  margin-bottom: 12px; text-transform: uppercase; letter-spacing: .5px;
}
.settings-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 0; cursor: pointer; border-bottom: 1px solid var(--border);
  transition: opacity var(--transition-fast), border-color var(--transition-base);
  user-select: none; -webkit-tap-highlight-color: transparent;
}
.settings-row:last-child { border-bottom: none; }
.settings-row:hover { opacity: .8; }
.settings-row span { font-size: 13px; font-weight: 500; color: var(--on-surface); }

/* ── Theme row in settings ── */
.settings-theme-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-top: 8px;
}
.settings-theme-swatch {
  padding: 8px 6px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); cursor: pointer;
  font-size: 11px; font-weight: 600; color: var(--on-dim);
  background: var(--bg-secondary); text-align: center;
  transition: all var(--transition-fast);
  -webkit-tap-highlight-color: transparent;
  display: flex; align-items: center; gap: 6px; justify-content: center;
}
.settings-theme-swatch:hover { border-color: var(--border-light); color: var(--on-surface); }
.settings-theme-swatch.selected { border-color: var(--primary); background: var(--primary-bg); color: var(--primary); }
.settings-theme-dot {
  width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0;
  border: 1px solid rgba(255,255,255,.1);
}

/* ═════════════════════════════════════════
   Toggle Switch
   ═════════════════════════════════════════ */
.toggle { position: relative; display: inline-block; width: 40px; height: 22px; flex-shrink: 0; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute; cursor: pointer; inset: 0;
  background: var(--surface3); border-radius: 22px;
  transition: background var(--transition-base); border: 1px solid var(--border);
}
.toggle-slider::before {
  content: ''; position: absolute; height: 16px; width: 16px; left: 2px; bottom: 2px;
  background: var(--on-dim); border-radius: 50%; transition: transform var(--transition-base);
}
.toggle input:checked + .toggle-slider { background: var(--primary); border-color: var(--primary-hover); }
.toggle input:checked + .toggle-slider::before { transform: translateX(18px); background: #fff; }

/* ═════════════════════════════════════════
   Checkbox
   ═════════════════════════════════════════ */
.row-checkbox { width: 16px; height: 16px; cursor: pointer; }

/* ═════════════════════════════════════════
   Responsive (mobile)
   ═════════════════════════════════════════ */
@media (max-width: 640px) {
  .fab { display: flex; }
  table, thead { display: none; }
  .user-cards { display: block; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .stat-dot { width: 36px; height: 36px; font-size: 16px; }
  .stat-value { font-size: 22px; }
  .header-actions .btn span.label { display: none; }
  .header-status { font-size: 0; gap: 0; padding: 4px 6px; }
  .header-status span { display: none; }
  .toolbar { padding: 10px 14px; }
  .search-box { max-width: 100%; flex: 1 1 100%; order: -1; }
  .filter-chip { font-size: 11px; padding: 5px 12px; }
  .modal {
    border-radius: 18px 18px 0 0;
    max-height: 92dvh; margin-top: auto;
  }
  .modal-overlay { align-items: flex-end; padding-bottom: 0; }
  @keyframes modalIn { from { transform: translateY(100%); opacity: 0; } }
  .confirm-box { margin-bottom: var(--safe-bottom); }
  .bulk-bar {
    position: fixed; bottom: 0; left: 0; right: 0;
    border-radius: var(--radius) var(--radius) 0 0;
    margin: 0; padding-bottom: calc(12px + var(--safe-bottom));
    box-shadow: 0 -4px 20px rgba(0,0,0,.4);
  }
}

@media (max-width: 380px) {
  .stats-grid { grid-template-columns: 1fr 1fr; gap: 6px; }
  .stat-card { padding: 14px; gap: 8px; flex-direction: column; align-items: flex-start; }
  .stat-dot { width: 32px; height: 32px; font-size: 14px; }
  .stat-value { font-size: 20px; }
  .container { padding: 10px 10px 40px; }
}
