:root {
  --bg: #f5f5f7;
  --surface: #ffffff;
  --text: #1c1c1e;
  --text-dim: #8e8e93;
  --accent: #0071e3;
  --accent-hover: #0058b0;
  --border: #d1d1d6;
  --success: #30d158;
  --error: #ff3b30;
  --warning: #ff9f0a;
  --radius: 0.5rem;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

/* ── Layout ───────────────────────────────────────────────── */

.top-bar {
  background: var(--text);
  color: #fff;
  padding: 1rem 0;
}

.top-bar .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.top-bar h1 {
  font-size: 1.125rem;
  font-weight: 600;
}

.top-bar .tag {
  font-size: 0.7rem;
  background: rgba(255, 255, 255, 0.15);
  padding: 0.2rem 0.6rem;
  border-radius: 99rem;
  white-space: nowrap;
}

.container {
  max-width: 48rem;
  margin: 0 auto;
  padding: 1.5rem;
}

footer {
  text-align: center;
  padding: 2rem 0;
  color: var(--text-dim);
  font-size: 0.75rem;
}

/* ── Hero stat ────────────────────────────────────────────── */

.hero-stat {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 2rem;
  margin: 1.5rem 0;
  text-align: center;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.hero-stat .amount {
  font-size: 3rem;
  font-weight: 800;
  color: var(--accent);
  letter-spacing: -0.02em;
}

.hero-stat .label {
  font-size: 0.9rem;
  color: var(--text-dim);
  margin-top: 0.25rem;
}

.hero-stat .sub-stats {
  display: flex;
  justify-content: center;
  gap: 2rem;
  margin-top: 1.25rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border);
}

.hero-stat .sub-stat {
  text-align: center;
}

.hero-stat .sub-val {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text);
}

.hero-stat .sub-lbl {
  font-size: 0.7rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* ── Progress ─────────────────────────────────────────────── */

.progress-wrap {
  margin: 1.5rem 0;
}

.progress-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 0.5rem;
}

.progress-header h2 {
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-dim);
}

.progress-header .pct {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--accent);
}

.track {
  height: 0.5rem;
  background: var(--border);
  border-radius: 99rem;
  overflow: hidden;
}

.track-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 99rem;
  transition: width 0.6s ease;
  width: 0%;
}

/* ── Section / panel ──────────────────────────────────────── */

.section {
  background: var(--surface);
  border-radius: var(--radius);
  margin: 1.5rem 0;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
  overflow: hidden;
}

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

.section-header h2 {
  font-size: 0.9rem;
  font-weight: 600;
}

.section-header .count {
  font-size: 0.75rem;
  color: var(--text-dim);
  background: var(--bg);
  padding: 0.15rem 0.5rem;
  border-radius: 99rem;
}

.section-body {
  padding: 1.25rem;
}

/* ── Table ────────────────────────────────────────────────── */

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

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8125rem;
}

th {
  text-align: left;
  padding: 0.5rem 1.25rem;
  background: var(--bg);
  color: var(--text-dim);
  font-weight: 600;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

td {
  padding: 0.625rem 1.25rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

tr:last-child td {
  border-bottom: none;
}

.name-cell {
  font-weight: 600;
}

.amount-cell {
  font-weight: 700;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

/* ── Badges ───────────────────────────────────────────────── */

.badge {
  display: inline-block;
  padding: 0.1rem 0.4rem;
  border-radius: 0.25rem;
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  white-space: nowrap;
}

.badge-active {
  background: #d1fae5;
  color: #065f46;
}

.status-cell {
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
}

.status-count {
  font-size: 0.7rem;
  color: var(--text-muted, #6b7280);
}

.badge-cond {
  background: #fef3c7;
  color: #92400e;
}

.badge-inactive {
  background: #f3f4f6;
  color: #6b7280;
}

.badge-anon {
  background: #ede9fe;
  color: #5b21b6;
}

/* ── Buttons ──────────────────────────────────────────────── */

.btn {
  padding: 0.5rem 1rem;
  border: none;
  border-radius: var(--radius);
  font-size: 0.8125rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
  display: inline-block;
  text-decoration: none;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

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

.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-danger {
  background: var(--error);
  color: #fff;
}

.btn-danger:hover {
  background: #cc2f25;
}

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

.btn-ghost:hover {
  background: var(--border);
}

.btn-small {
  padding: 0.25rem 0.625rem;
  font-size: 0.75rem;
}

/* ── Forms ────────────────────────────────────────────────── */

.form-group {
  margin-bottom: 1rem;
}

.form-label {
  display: block;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-dim);
  margin-bottom: 0.375rem;
}

.form-input,
.form-textarea {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
}

.form-textarea {
  resize: vertical;
  min-height: 6rem;
}

.form-input:focus,
.form-textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0, 113, 227, 0.12);
}

.form-input.error,
.form-textarea.error {
  border-color: var(--error);
}

.form-error {
  font-size: 0.75rem;
  color: var(--error);
  margin-top: 0.25rem;
  display: none;
}

.form-error.visible {
  display: block;
}

.form-checkbox-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  font-size: 0.875rem;
}

.form-checkbox-row input[type="checkbox"] {
  width: 1rem;
  height: 1rem;
  accent-color: var(--accent);
  cursor: pointer;
}

/* ── Alerts ───────────────────────────────────────────────── */

.alert {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  font-size: 0.875rem;
  margin: 1rem 0;
}

.alert-success {
  background: #d1fae5;
  color: #065f46;
  border: 1px solid #6ee7b7;
}

.alert-error {
  background: #fee2e2;
  color: #991b1b;
  border: 1px solid #fca5a5;
}

.alert-info {
  background: #dbeafe;
  color: #1e40af;
  border: 1px solid #93c5fd;
}

/* ── Empty state ──────────────────────────────────────────── */

.empty-state {
  text-align: center;
  padding: 2.5rem 1.25rem;
  color: var(--text-dim);
}

.empty-state p {
  font-size: 0.875rem;
}

/* ── Rules display ────────────────────────────────────────── */

.rules-box {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  font-size: 0.875rem;
  max-height: 12rem;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text);
  margin-bottom: 1rem;
}

/* ── Loading skeleton ─────────────────────────────────────── */

.skeleton {
  background: linear-gradient(90deg, var(--border) 25%, var(--bg) 50%, var(--border) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  border-radius: var(--radius);
  height: 1rem;
  display: inline-block;
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ── Stats grid ───────────────────────────────────────────── */

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(9rem, 1fr));
  gap: 1rem;
  padding: 1.25rem;
}

.stat-card {
  background: var(--bg);
  border-radius: var(--radius);
  padding: 1rem;
  text-align: center;
}

.stat-card .stat-val {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--accent);
}

.stat-card .stat-lbl {
  font-size: 0.7rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-top: 0.25rem;
}

/* ── Admin nav ────────────────────────────────────────────── */

.admin-nav {
  display: flex;
  gap: 0.5rem;
  padding: 0.75rem 1.25rem;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.admin-nav-item {
  padding: 0.375rem 0.75rem;
  border-radius: var(--radius);
  font-size: 0.8125rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  background: transparent;
  color: var(--text-dim);
}

.admin-nav-item.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

/* ── Inline confirm ───────────────────────────────────────── */

.confirm-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8125rem;
}

/* ── Responsive ───────────────────────────────────────────── */

@media (max-width: 48rem) {
  .hero-stat .amount {
    font-size: 2.25rem;
  }

  .hero-stat .sub-stats {
    gap: 1rem;
  }

  .container {
    padding: 1rem;
  }

  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  th, td {
    padding-left: 0.75rem;
    padding-right: 0.75rem;
  }
}
