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

:root {
  --bg: #0f0f13;
  --surface: #1a1a22;
  --border: #2a2a36;
  --accent: #6c63ff;
  --accent-hover: #8078ff;
  --danger: #ef4444;
  --success: #10b981;
  --warning: #f59e0b;
  --text: #e8e8f0;
  --text-muted: #8888aa;
  --radius: 10px;
  --sidebar-w: 220px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ── Login ── */
#login-screen {
  width: 100%;
  max-width: 400px;
  padding: 20px;
}

.logo {
  text-align: center;
  margin-bottom: 36px;
}
.logo h1 { font-size: 26px; font-weight: 700; letter-spacing: -0.5px; }
.logo span { color: var(--accent); }
.logo p { color: var(--text-muted); font-size: 13px; margin-top: 6px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
}

.form-group { margin-bottom: 18px; }
label { display: block; font-size: 12px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 8px; }
input[type="email"], input[type="password"], input[type="text"] {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
  padding: 10px 14px;
  outline: none;
  transition: border-color .2s;
}
input:focus { border-color: var(--accent); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: background .2s, opacity .2s;
}
.btn-primary { background: var(--accent); color: #fff; width: 100%; padding: 12px; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-sm { padding: 6px 14px; font-size: 12px; }
.btn-warning { background: rgba(245,158,11,.15); color: var(--warning); border: 1px solid rgba(245,158,11,.3); }
.btn-warning:hover { background: rgba(245,158,11,.25); }
.btn-danger { background: rgba(239,68,68,.15); color: var(--danger); border: 1px solid rgba(239,68,68,.3); }
.btn-danger:hover { background: rgba(239,68,68,.25); }
.btn-ghost { background: var(--border); color: var(--text-muted); }
.btn-ghost:hover { color: var(--text); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.error-msg {
  background: rgba(239,68,68,.1);
  border: 1px solid rgba(239,68,68,.3);
  color: var(--danger);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 13px;
  margin-top: 14px;
  display: none;
}
.error-msg.show { display: block; }

/* ── Dashboard ── */
#dashboard-screen {
  display: none;
  width: 100%;
  min-height: 100vh;
  flex-direction: column;
}

header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  z-index: 10;
}
header .brand { font-weight: 700; font-size: 16px; display: flex; align-items: center; gap: 10px; }
header .brand svg { width: 32px; height: 32px; flex-shrink: 0; }
header .brand span { color: var(--accent); }
header .header-actions { display: flex; align-items: center; gap: 12px; }

/* ── User avatar menu ── */
.user-menu { position: relative; }

.user-avatar-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 2px;
  border-radius: 50%;
  transition: box-shadow .2s;
}
.user-avatar-btn:hover { box-shadow: 0 0 0 2px rgba(108,99,255,.4); }

.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #a855f7);
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
}

.user-avatar-lg {
  width: 44px;
  height: 44px;
  font-size: 17px;
  flex-shrink: 0;
}

.user-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 6px;
  min-width: 240px;
  box-shadow: 0 12px 32px rgba(0,0,0,.5);
  opacity: 0;
  visibility: hidden;
  transform: translateY(-8px) scale(.96);
  transition: opacity .2s ease, transform .2s ease, visibility .2s;
  z-index: 200;
}
.user-dropdown.open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}

.user-dropdown-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 12px 10px;
}
.user-dropdown-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.user-dropdown-info strong {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.user-dropdown-info span {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-dropdown-divider {
  height: 1px;
  background: var(--border);
  margin: 4px 8px;
}

.user-dropdown-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  border: none;
  background: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
  transition: background .15s, color .15s;
}
.user-dropdown-item:hover { background: rgba(255,255,255,.06); }
.user-dropdown-item svg { flex-shrink: 0; opacity: .6; }
.user-dropdown-item:hover svg { opacity: .9; }

.user-dropdown-signout { color: var(--danger); }
.user-dropdown-signout svg { opacity: .8; }
.user-dropdown-signout:hover { background: rgba(239,68,68,.1); }

/* ── App body (sidebar + content) ── */
.app-body {
  display: flex;
  flex: 1;
  min-height: calc(100vh - 56px);
}

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 20px 12px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.sidebar-section {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  padding: 8px 12px 4px;
  margin-top: 8px;
}
.sidebar-section:first-child { margin-top: 0; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  transition: background .15s, color .15s;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}
.nav-item:hover { background: rgba(255,255,255,.05); color: var(--text); }
.nav-item.active { background: rgba(108,99,255,.15); color: var(--accent); }
.nav-item svg { flex-shrink: 0; opacity: .7; }
.nav-item.active svg { opacity: 1; }

/* ── Main content ── */
main {
  flex: 1;
  padding: 32px;
  min-width: 0;
}

.section-title {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 24px;
}

/* ── Sections ── */
.section { display: none; }
.section.active { display: block; }

/* ── Create user form ── */
.create-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 24px;
}
.create-card h2 { font-size: 13px; font-weight: 600; margin-bottom: 20px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .5px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr 1fr 1fr 1fr 1fr auto; gap: 12px; align-items: end; }
@media (max-width: 1100px) { .form-row { grid-template-columns: 1fr 1fr 1fr; } }
@media (max-width: 600px) { .form-row { grid-template-columns: 1fr; } }

select {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
  padding: 10px 14px;
  outline: none;
  transition: border-color .2s;
  cursor: pointer;
}
select:focus { border-color: var(--accent); }
select option { background: var(--bg); }

.sub-essential { background: rgba(59,130,246,.15); color: #60a5fa; }
.sub-family    { background: rgba(168,85,247,.15);  color: #c084fc; }
.sub-premium   { background: rgba(245,158,11,.15);  color: #fbbf24; }
.sub-free      { background: var(--border); color: var(--text-muted); }

.success-msg {
  background: rgba(16,185,129,.1);
  border: 1px solid rgba(16,185,129,.3);
  color: var(--success);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 13px;
  margin-top: 14px;
  display: none;
}
.success-msg.show { display: block; }

/* ── Users table ── */
.users-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.users-header {
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.users-header h2 { font-size: 13px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .5px; }
.badge { background: var(--border); color: var(--text-muted); border-radius: 20px; padding: 2px 10px; font-size: 12px; font-weight: 600; }

table { width: 100%; border-collapse: collapse; }
th {
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .5px;
  padding: 12px 24px;
  border-bottom: 1px solid var(--border);
}
td { padding: 14px 24px; font-size: 14px; border-bottom: 1px solid var(--border); }
tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(255,255,255,.02); }

/* ── Pills (status + subscription) ── */
.pill, .sub-pill {
  display: inline-block;
  border-radius: 20px;
  padding: 3px 10px;
  font-size: 11px;
  font-weight: 600;
}
.pill-active { background: rgba(16,185,129,.15); color: var(--success); }
.pill-queued { background: rgba(245,158,11,.15); color: var(--warning); }
.pill-inactive { background: rgba(239,68,68,.1); color: var(--danger); }

.td-actions { display: flex; gap: 8px; }

.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-muted);
  font-size: 14px;
}

.loading { color: var(--text-muted); font-size: 14px; padding: 24px; text-align: center; }

/* ── Dashboard stats ── */
.dash-stats {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px;
}
@media (max-width: 900px) { .dash-stats { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 500px) { .dash-stats { grid-template-columns: 1fr; } }

/* ── Plan mix ── */
.plan-mix-card {
  display: flex; gap: 16px;
}
.plan-mix-stat {
  display: flex; flex-direction: column; justify-content: center;
  min-width: 160px;
}
.plan-mix-chart-card { flex: 1; }
@media (max-width: 700px) { .plan-mix-card { flex-direction: column; } }

.plan-mix-row {
  display: flex; align-items: center; gap: 24px;
}
@media (max-width: 500px) { .plan-mix-row { flex-direction: column; align-items: flex-start; } }

.plan-mix-legend {
  display: flex; flex-direction: column; gap: 8px; flex: 1;
}
.plan-mix-item {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; font-weight: 500; color: var(--text);
}
.plan-mix-dot {
  width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0;
}
.stat-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px 20px;
}
.stat-value {
  font-size: 22px; font-weight: 700; color: var(--text); margin-bottom: 4px;
  display: flex; gap: 6px; flex-wrap: wrap; align-items: center;
}
.stat-label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .5px; color: var(--text-muted); }
.stat-card-link:hover { border-color: var(--accent); }

/* ── Cap bar ── */
.cap-bar-wrap { min-width: 100px; }
.cap-bar-text { font-size: 12px; font-weight: 600; color: var(--text); margin-bottom: 4px; }
.cap-bar-track { width: 100%; height: 6px; background: var(--border); border-radius: 99px; overflow: hidden; }
.cap-bar-fill { height: 100%; border-radius: 99px; transition: width .3s; }

/* ── Modal ── */
.modal-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(0,0,0,0.6); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.modal-box {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); width: 100%; max-width: 600px;
  max-height: 80vh; overflow-y: auto;
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 24px; border-bottom: 1px solid var(--border);
}
.modal-header h2 {
  font-size: 14px; font-weight: 600; color: var(--text);
}
#queue-modal-body { padding: 0; }
#queue-modal-body .empty-state { padding: 32px 24px; }

/* ── Password reveal ── */
.pw-field-wrap {
  position: relative;
}
.pw-field-wrap input {
  width: 100%;
  padding-right: 40px;
}
.pw-reveal-btn {
  position: absolute; right: 10px; top: 50%; transform: translateY(-50%);
  background: none; border: none; cursor: pointer; padding: 4px;
  color: var(--text-muted); display: flex; align-items: center;
}
.pw-reveal-btn:hover { color: var(--text); }
.pw-reveal-btn .pw-icon-hide { display: none; }
.pw-reveal-btn.showing .pw-icon-show { display: none; }
.pw-reveal-btn.showing .pw-icon-hide { display: block; }

/* ── User Profile Modal ── */
.modal-box-wide { max-width: 700px; }

.user-modal-content { padding: 0; }

.profile-section {
  border-bottom: 1px solid var(--border);
  padding: 20px 24px;
}
.profile-section:last-child { border-bottom: none; }

.profile-section-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--text-muted);
  margin-bottom: 16px;
}

.profile-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px 24px;
}
@media (max-width: 500px) { .profile-grid { grid-template-columns: 1fr; } }

.profile-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.profile-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .3px;
}

.profile-value {
  font-size: 14px;
  color: var(--text);
}

.profile-edit-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.profile-edit-row {
  display: flex;
  gap: 14px;
}
@media (max-width: 500px) { .profile-edit-row { flex-direction: column; } }

.profile-edit-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 4px;
}
.profile-edit-actions .error-msg,
.profile-edit-actions .success-msg {
  margin-top: 0;
  padding: 6px 12px;
  font-size: 12px;
}

/* ── Clickable table rows ── */
.clickable-cell { cursor: pointer; }
.clickable-cell:hover { color: var(--accent) !important; }

.clickable-row { cursor: pointer; }
.clickable-row:hover td { background: rgba(108,99,255,.05) !important; }

/* ── Column filters ── */
.th-filterable {
  cursor: pointer;
  user-select: none;
  position: relative;
}
.th-filterable:hover { color: var(--accent); }

.th-filter-dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  margin-left: 4px;
  vertical-align: middle;
}

.filter-dropdown {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 0;
  min-width: 160px;
  z-index: 200;
  box-shadow: 0 8px 24px rgba(0,0,0,.4);
}

.filter-dropdown-title {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--text-muted);
  padding: 8px 14px 4px;
}

.filter-dropdown-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 7px 14px;
  font-size: 13px;
  color: var(--text);
  background: none;
  border: none;
  cursor: pointer;
  text-align: left;
}
.filter-dropdown-item:hover { background: rgba(255,255,255,.05); }
.filter-dropdown-item.filter-active { color: var(--accent); background: rgba(108,99,255,.1); }
.filter-dropdown-item.filter-clear {
  color: var(--text-muted);
  font-size: 12px;
  border-top: 1px solid var(--border);
  margin-top: 4px;
  padding-top: 8px;
}
.filter-dropdown-item.filter-clear:hover { color: var(--danger); }

.filter-count {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 600;
}

.filter-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 24px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.filter-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: rgba(108,99,255,.15);
  color: var(--accent);
  border-radius: 20px;
  padding: 3px 10px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
}
.filter-pill:hover { background: rgba(108,99,255,.25); }

.filter-clear-all {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 11px;
  cursor: pointer;
  padding: 3px 6px;
}
.filter-clear-all:hover { color: var(--danger); }
