:root {
  --bg-0: #0b0d14;
  --bg-1: #11141d;
  --bg-2: #161a26;
  --bg-3: #1d2231;
  --border: rgba(255, 255, 255, 0.06);
  --border-strong: rgba(255, 255, 255, 0.12);
  --text: #e7eaf3;
  --text-muted: #8b91a6;
  --text-dim: #5d6378;
  --primary: #7c5cff;
  --primary-soft: rgba(124, 92, 255, 0.18);
  --primary-glow: rgba(124, 92, 255, 0.45);
  --success: #22d3a8;
  --success-soft: rgba(34, 211, 168, 0.15);
  --warning: #f5a524;
  --warning-soft: rgba(245, 165, 36, 0.15);
  --danger: #f04444;
  --info: #38bdf8;
  --info-soft: rgba(56, 189, 248, 0.15);
  --shadow-lg: 0 20px 60px rgba(0, 0, 0, 0.45);
  --shadow-card: 0 1px 0 rgba(255,255,255,0.04) inset, 0 8px 24px rgba(0,0,0,0.25);
  --radius: 14px;
  --radius-sm: 10px;
  --bg-glow-1: rgba(124, 92, 255, 0.18);
  --bg-glow-2: rgba(34, 211, 168, 0.10);
  --bg-glow-bottom: rgba(124, 92, 255, 0.08);
  --grid-line: rgba(255, 255, 255, 0.04);
  --topbar-bg: rgba(11, 13, 20, 0.7);
  --color-scheme: dark;
}

[data-theme="light"] {
  --bg-0: #f5f7fb;
  --bg-1: #ffffff;
  --bg-2: #f7f8fc;
  --bg-3: #eef1f7;
  --border: rgba(15, 23, 42, 0.07);
  --border-strong: rgba(15, 23, 42, 0.14);
  --text: #1a1d29;
  --text-muted: #5d6378;
  --text-dim: #8b91a6;
  --primary: #6b46ff;
  --primary-soft: rgba(107, 70, 255, 0.10);
  --primary-glow: rgba(107, 70, 255, 0.30);
  --success: #0bbd8a;
  --success-soft: rgba(11, 189, 138, 0.10);
  --warning: #d97706;
  --warning-soft: rgba(217, 119, 6, 0.10);
  --danger: #dc2626;
  --info: #0284c7;
  --info-soft: rgba(2, 132, 199, 0.10);
  --shadow-lg: 0 20px 50px rgba(15, 23, 42, 0.12);
  --shadow-card: 0 1px 0 rgba(255,255,255,0.5) inset, 0 4px 14px rgba(15, 23, 42, 0.06);
  --bg-glow-1: rgba(107, 70, 255, 0.08);
  --bg-glow-2: rgba(11, 189, 138, 0.05);
  --bg-glow-bottom: rgba(107, 70, 255, 0.04);
  --grid-line: rgba(15, 23, 42, 0.06);
  --topbar-bg: rgba(255, 255, 255, 0.75);
  --color-scheme: light;
}

html { color-scheme: var(--color-scheme); }

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

html, body {
  background: var(--bg-0);
  color: var(--text);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

body {
  background:
    radial-gradient(1200px 600px at 10% -10%, var(--bg-glow-1), transparent 60%),
    radial-gradient(900px 500px at 110% 20%, var(--bg-glow-2), transparent 60%),
    var(--bg-0);
  position: relative;
  overflow-x: hidden;
  transition: background-color 0.2s ease;
}

.bg-glow {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(800px 400px at 50% 100%, var(--bg-glow-bottom), transparent 70%);
  z-index: 0;
}

button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input { font-family: inherit; }

/* ---------- Topbar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 32px;
  background: var(--topbar-bg);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-logo {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--primary), #5b3df0);
  box-shadow: 0 8px 22px var(--primary-glow);
  color: white;
}

.brand-logo svg { width: 22px; height: 22px; }

.brand h1 {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.brand p {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  background: var(--bg-2);
  border: 1px solid var(--border);
}

.pill .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-dim);
}

.pill-success { color: var(--success); background: var(--success-soft); border-color: rgba(34, 211, 168, 0.3); }
.pill-success .dot { background: var(--success); box-shadow: 0 0 10px var(--success); }
.pill-danger { color: var(--danger); background: rgba(240, 68, 68, 0.12); border-color: rgba(240, 68, 68, 0.3); }
.pill-danger .dot { background: var(--danger); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.btn svg { width: 16px; height: 16px; }
.btn-sm { padding: 7px 12px; font-size: 12px; }

.btn-primary {
  background: linear-gradient(135deg, var(--primary), #5b3df0);
  color: white;
  box-shadow: 0 8px 22px var(--primary-glow);
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 12px 28px var(--primary-glow); }
.btn-primary:active { transform: translateY(0); }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; transform: none; }

.btn-ghost {
  background: var(--bg-2);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-ghost:hover { background: var(--bg-3); border-color: var(--border-strong); }

.btn-icon { padding: 9px; }
.btn-icon svg { width: 18px; height: 18px; }
.btn-icon .icon-sun { display: none; }
.btn-icon .icon-moon { display: block; }
[data-theme="light"] .btn-icon .icon-sun { display: block; }
[data-theme="light"] .btn-icon .icon-moon { display: none; }

/* ---------- Layout ---------- */
.container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 28px 32px 60px;
  position: relative;
  z-index: 1;
}

.card {
  background: linear-gradient(180deg, var(--bg-1), var(--bg-2));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  padding: 22px;
  margin-bottom: 22px;
  transition: background 0.2s ease, border-color 0.2s ease;
}

.card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}

.card-header h2 {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.card-sub {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ---------- Filters ---------- */
.filters {
  display: grid;
  grid-template-columns: 1.35fr 1fr;
  gap: 24px;
  align-items: stretch;
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
}

.filter-group + .filter-group {
  padding-left: 24px;
  border-left: 1px solid var(--border);
}

.filter-label {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 2px;
}
.filter-icon {
  width: 18px;
  height: 18px;
  color: var(--primary);
  flex-shrink: 0;
}
.filter-label-text { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.filter-label-text > span { font-size: 13px; font-weight: 600; }
.filter-label-text small { font-size: 12px; color: var(--text-muted); font-weight: 400; }

.input {
  background: var(--bg-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  width: 100%;
  outline: none;
  transition: all 0.15s ease;
}
.input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.input::placeholder { color: var(--text-dim); }

.search-wrap {
  position: relative;
  display: flex;
  align-items: center;
}
.search-wrap .input { padding-left: 40px; padding-right: 130px; }
.search-icon {
  position: absolute;
  top: 50%;
  left: 14px;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  color: var(--text-dim);
  pointer-events: none;
}

.date-controls {
  display: flex;
  flex-direction: column;
  gap: 14px;
  flex: 1;
}

.quick-ranges {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}
.chip {
  padding: 8px 6px;
  border-radius: 8px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  transition: all 0.15s;
  text-align: center;
}
.chip:hover { color: var(--text); border-color: var(--border-strong); background: var(--bg-3); }
.chip.active {
  background: var(--primary-soft);
  border-color: var(--primary);
  color: var(--primary);
  font-weight: 600;
}
[data-theme="light"] .chip.active { color: var(--primary); }

.date-input-wrap {
  position: relative;
}
.date-input-wrap .input { padding-left: 40px; cursor: pointer; }
.date-input-icon {
  position: absolute;
  top: 50%;
  left: 14px;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  color: var(--text-dim);
  pointer-events: none;
}

.accounts-control {
  display: flex;
  flex-direction: column;
  gap: 12px;
  flex: 1;
  min-height: 0;
}

.accounts-actions {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
}

.link-btn {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  padding: 4px 0;
  cursor: pointer;
  transition: color 0.15s;
}
.link-btn:hover { color: var(--primary); }

.dot-sep {
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: var(--border-strong);
}

.btn-block {
  width: 100%;
  justify-content: center;
  padding: 12px 16px;
  font-size: 14px;
}

.accounts-list {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px;
  max-height: 220px;
  min-height: 160px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
}
.accounts-list::-webkit-scrollbar { width: 8px; }
.accounts-list::-webkit-scrollbar-track { background: transparent; }
.accounts-list::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 4px; }

.account-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.12s;
}
.account-row:hover { background: var(--bg-3); }
.account-row input[type="checkbox"] {
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 5px;
  border: 1.5px solid var(--border-strong);
  background: var(--bg-3);
  cursor: pointer;
  position: relative;
  flex-shrink: 0;
  transition: all 0.15s;
}
.account-row input[type="checkbox"]:checked {
  background: var(--primary);
  border-color: var(--primary);
}
.account-row input[type="checkbox"]:checked::after {
  content: '';
  position: absolute;
  left: 5px;
  top: 1px;
  width: 5px;
  height: 10px;
  border: solid white;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

.account-info {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
}
.account-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.account-meta {
  font-size: 11px;
  color: var(--text-muted);
  display: flex;
  gap: 6px;
}
.account-meta .badge {
  background: var(--success-soft);
  color: var(--success);
  padding: 1px 6px;
  border-radius: 4px;
  font-weight: 600;
  font-size: 10px;
}

.empty-state {
  padding: 32px 20px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.spinner {
  width: 24px;
  height: 24px;
  border: 2.5px solid var(--border-strong);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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


/* ---------- Metrics ---------- */
.metrics {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 14px;
  margin-bottom: 22px;
}

.metric-card {
  background: linear-gradient(180deg, var(--bg-1), var(--bg-2));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  display: flex;
  align-items: flex-start;
  gap: 14px;
  box-shadow: var(--shadow-card);
  position: relative;
  overflow: hidden;
  transition: transform 0.15s, border-color 0.15s;
}
.metric-card:hover { transform: translateY(-2px); border-color: var(--border-strong); }

.metric-card::before {
  content: '';
  position: absolute;
  top: -40px;
  right: -40px;
  width: 120px;
  height: 120px;
  background: radial-gradient(circle, var(--primary-soft), transparent 70%);
  opacity: 0;
  transition: opacity 0.2s;
}
.metric-card:hover::before { opacity: 1; }

.metric-icon {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}
.metric-icon svg { width: 18px; height: 18px; }

.icon-spend   { background: var(--primary-soft); color: var(--primary); }
.icon-conv    { background: var(--success-soft); color: var(--success); }
.icon-cpl     { background: var(--warning-soft); color: var(--warning); }
.icon-imp     { background: var(--info-soft); color: var(--info); }
.icon-reach   { background: rgba(244, 114, 182, 0.15); color: #f472b6; }

.metric-body { flex: 1; min-width: 0; }
.metric-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  font-weight: 600;
}
.metric-value {
  font-size: 24px;
  font-weight: 800;
  letter-spacing: -0.02em;
  margin: 4px 0 2px;
  color: var(--text);
  line-height: 1.1;
}
.metric-sub { font-size: 11px; color: var(--text-dim); }

.metric-card.loading .metric-value {
  color: transparent;
  background: linear-gradient(90deg, var(--bg-3), var(--bg-2), var(--bg-3));
  background-size: 200% 100%;
  animation: shimmer 1.4s linear infinite;
  border-radius: 6px;
  height: 26px;
  width: 80%;
}

[data-theme="light"] .icon-reach { background: rgba(236, 72, 153, 0.1); color: #ec4899; }
[data-theme="light"] .pill-success {
  color: var(--success);
  background: var(--success-soft);
  border-color: rgba(11, 189, 138, 0.25);
}
@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ---------- Chart ---------- */
.chart-card { padding: 22px; }
.chart-wrap {
  position: relative;
  height: 320px;
}
.chart-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--text-muted);
  font-size: 13px;
  background: var(--bg-1);
  opacity: 0.6;
  border-radius: 10px;
}
.chart-empty.hidden { display: none; }

.chart-legend {
  display: flex;
  gap: 16px;
  font-size: 12px;
  color: var(--text-muted);
}
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.legend-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
}

/* ---------- Tables ---------- */
.grid-2 {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 22px;
}

.table-wrap { overflow-x: auto; max-height: 360px; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th, .data-table td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.data-table th {
  font-weight: 600;
  color: var(--text-muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  position: sticky;
  top: 0;
  background: var(--bg-2);
}
.data-table td.num, .data-table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.data-table tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: var(--bg-3); }
.data-table .empty {
  text-align: center;
  color: var(--text-dim);
  padding: 32px 12px;
  font-style: italic;
}
.data-table .name-cell { max-width: 280px; }
.data-table .name-cell-text {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 500;
}
.data-table .name-cell small {
  font-size: 11px;
  color: var(--text-muted);
}

/* ---------- Footer ---------- */
.footer {
  margin-top: 32px;
  text-align: center;
  font-size: 12px;
  color: var(--text-dim);
}
.footer code {
  background: var(--bg-3);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: 'SF Mono', Menlo, monospace;
  color: var(--primary);
  font-size: 11px;
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--bg-2);
  border: 1px solid var(--border-strong);
  padding: 14px 18px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  z-index: 100;
  max-width: 360px;
  display: flex;
  align-items: center;
  gap: 10px;
  animation: toast-in 0.25s ease;
}
.toast.hidden { display: none; }
.toast.error { border-color: rgba(240, 68, 68, 0.4); background: rgba(240, 68, 68, 0.1); }
.toast.success { border-color: rgba(34, 211, 168, 0.4); background: rgba(34, 211, 168, 0.1); }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------- Flatpickr theme tweaks ---------- */
.flatpickr-calendar {
  background: var(--bg-2) !important;
  border: 1px solid var(--border-strong) !important;
  box-shadow: var(--shadow-lg) !important;
  border-radius: 12px !important;
  color: var(--text) !important;
}
.flatpickr-calendar.arrowTop:before, .flatpickr-calendar.arrowTop:after {
  border-bottom-color: var(--bg-2) !important;
}
.flatpickr-months .flatpickr-month,
.flatpickr-current-month,
.flatpickr-monthDropdown-months,
.flatpickr-current-month input.cur-year {
  color: var(--text) !important;
  fill: var(--text) !important;
  background: transparent !important;
}
.flatpickr-weekdays, .flatpickr-weekday {
  color: var(--text-muted) !important;
  background: transparent !important;
}
.flatpickr-day {
  color: var(--text) !important;
  background: transparent !important;
  border-color: transparent !important;
}
.flatpickr-day.prevMonthDay, .flatpickr-day.nextMonthDay {
  color: var(--text-dim) !important;
}
.flatpickr-day:hover {
  background: var(--bg-3) !important;
}
.flatpickr-day.today {
  border-color: var(--primary) !important;
}
.flatpickr-day.selected, .flatpickr-day.startRange, .flatpickr-day.endRange {
  background: var(--primary) !important;
  border-color: var(--primary) !important;
  color: white !important;
}
.flatpickr-day.inRange {
  background: var(--primary-soft) !important;
  border-color: transparent !important;
  box-shadow: -5px 0 0 var(--primary-soft), 5px 0 0 var(--primary-soft) !important;
}
.flatpickr-months .flatpickr-prev-month,
.flatpickr-months .flatpickr-next-month {
  fill: var(--text) !important;
  color: var(--text) !important;
}
.flatpickr-months .flatpickr-prev-month:hover svg,
.flatpickr-months .flatpickr-next-month:hover svg {
  fill: var(--primary) !important;
}

/* ---------- Auth (Login) ---------- */
.auth-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-shell {
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  position: relative;
  z-index: 1;
}

.auth-card {
  width: 100%;
  background: linear-gradient(180deg, var(--bg-1), var(--bg-2));
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 32px 28px;
  box-shadow: var(--shadow-lg);
}

.auth-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 24px;
}
.auth-brand h1 { font-size: 18px; font-weight: 700; }
.auth-brand p { font-size: 12px; color: var(--text-muted); }

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

.auth-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.auth-field label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
}
.auth-field input {
  background: var(--bg-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  outline: none;
  transition: all 0.15s;
  font-family: inherit;
  width: 100%;
}
.auth-field input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}

.password-wrap { position: relative; }
.password-wrap input { padding-right: 44px; }
.password-toggle {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  color: var(--text-dim);
  border-radius: 6px;
  transition: all 0.15s;
}
.password-toggle:hover { color: var(--text); background: var(--bg-3); }
.password-toggle svg { width: 18px; height: 18px; }

.auth-error {
  background: rgba(240, 68, 68, 0.12);
  border: 1px solid rgba(240, 68, 68, 0.3);
  color: var(--danger);
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
}
.auth-error.hidden { display: none; }

.auth-footer {
  text-align: center;
  font-size: 12px;
  color: var(--text-dim);
}

/* ---------- Admin page ---------- */
.admin-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 22px;
}

.users-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.users-table th, .users-table td {
  padding: 12px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.users-table th {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  font-weight: 600;
}
.users-table tbody tr:hover { background: var(--bg-2); }
.users-table .actions {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
}

.role-badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
}
.role-badge.role-superadmin { background: var(--primary-soft); color: var(--primary); }
.role-badge.role-user { background: var(--info-soft); color: var(--info); }

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
}
.status-badge.status-active { background: var(--success-soft); color: var(--success); }
.status-badge.status-inactive { background: rgba(240, 68, 68, 0.12); color: var(--danger); }
.status-badge::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: grid;
  place-items: center;
  z-index: 200;
  padding: 20px;
  animation: fade-in 0.18s ease;
}
.modal-overlay.hidden { display: none; }

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal {
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow-lg);
  animation: modal-in 0.22s cubic-bezier(0.2, 0.9, 0.3, 1.2);
}
@keyframes modal-in {
  from { opacity: 0; transform: translateY(8px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
}
.modal-header h2 { font-size: 16px; font-weight: 700; }
.modal-close {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  color: var(--text-muted);
  transition: all 0.15s;
}
.modal-close:hover { color: var(--text); background: var(--bg-3); }
.modal-close svg { width: 18px; height: 18px; }

.modal-body { padding: 22px; }
.modal-footer {
  padding: 16px 22px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.form-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}
.form-row label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
}
.form-row input, .form-row select {
  background: var(--bg-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-family: inherit;
  outline: none;
  width: 100%;
  transition: all 0.15s;
}
.form-row input:focus, .form-row select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}
.form-row.row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.account-checks {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px;
  max-height: 240px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.password-row {
  display: flex;
  align-items: stretch;
  gap: 8px;
}
.password-row .password-wrap {
  flex: 1;
  min-width: 0;
}
.password-row .password-wrap input {
  font-family: 'SF Mono', Menlo, Consolas, monospace;
  font-size: 13px;
  letter-spacing: 0.5px;
}
.password-row .btn { white-space: nowrap; }

.accounts-row-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}
.accounts-row-header label {
  margin: 0;
}
.accounts-actions-inline {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-danger {
  background: rgba(240, 68, 68, 0.12);
  color: var(--danger);
  border: 1px solid rgba(240, 68, 68, 0.3);
}
.btn-danger:hover { background: rgba(240, 68, 68, 0.2); }

.btn-secondary {
  background: var(--bg-2);
  color: var(--text);
  border: 1px solid var(--border);
}

/* User dropdown menu in topbar */
.user-menu {
  position: relative;
}
.user-trigger {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px 6px 6px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
  transition: all 0.15s;
}
.user-trigger:hover { background: var(--bg-3); border-color: var(--border-strong); }
.user-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), #5b3df0);
  display: grid;
  place-items: center;
  color: white;
  font-size: 12px;
  font-weight: 700;
}
.user-name {
  font-size: 13px;
  font-weight: 500;
  max-width: 130px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dropdown-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 220px;
  background: var(--bg-1);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
  padding: 6px;
  z-index: 60;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.dropdown-menu.hidden { display: none; }
.dropdown-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 6px;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  font-family: inherit;
}
.dropdown-item:hover { background: var(--bg-3); }
.dropdown-item svg { width: 16px; height: 16px; color: var(--text-muted); }
.dropdown-item.danger { color: var(--danger); }
.dropdown-item.danger svg { color: var(--danger); }
.dropdown-item .user-info { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.dropdown-item .user-info strong { font-size: 13px; font-weight: 600; }
.dropdown-item .user-info small { font-size: 11px; color: var(--text-muted); }
.dropdown-divider { height: 1px; background: var(--border); margin: 4px 0; }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .metrics { grid-template-columns: repeat(3, 1fr); }
  .grid-2 { grid-template-columns: 1fr; }
}
@media (max-width: 900px) {
  .filters { grid-template-columns: 1fr; gap: 22px; }
  .filter-group + .filter-group {
    padding-left: 0;
    padding-top: 22px;
    border-left: none;
    border-top: 1px solid var(--border);
  }
}

@media (max-width: 720px) {
  .topbar { padding: 14px 18px; }
  .container { padding: 18px; }
  .metrics { grid-template-columns: repeat(2, 1fr); }
  .brand p { display: none; }
  .card { padding: 16px; }
  .metric-value { font-size: 20px; }
  .quick-ranges { grid-template-columns: repeat(3, 1fr); }
  .search-wrap .input { padding-right: 14px; }
  .accounts-actions {
    position: static;
    transform: none;
    margin-top: 4px;
    justify-content: flex-end;
  }
  .search-wrap { flex-direction: column; align-items: stretch; }
}
@media (max-width: 480px) {
  .metrics { grid-template-columns: 1fr; }
}
