:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface-2: #232735;
  --border: #2e3344;
  --text: #e2e4ea;
  --muted: #7a7f94;
  --primary: #5b8def;
  --primary-2: #4974d4;
  --rwb-navy: #0A2240;
  --rwb-red: #C8102E;
  --rwb-cream: #F5F1E8;
  --rwb-gold: #E4A84B;
  --danger: #f87171;
  --success: #4ade80;
  --warning: #E4A84B;
  --info: #60a5fa;
  --sidebar-w: 240px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.4);
  --shadow-md: 0 4px 12px rgba(0,0,0,.5);
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--info); }

button {
  font-family: inherit;
  font-size: 14px;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  padding: 0.5rem 1rem;
  border-radius: 6px;
  transition: background 0.15s, border-color 0.15s;
}
button:hover { background: var(--border); }
button:disabled { opacity: 0.5; cursor: not-allowed; }
button.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
button.btn-primary:hover { background: var(--primary-2); }
button.btn-danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}
button.btn-red {
  background: var(--rwb-red);
  border-color: var(--rwb-red);
  color: #fff;
}
button.btn-red:hover { background: #a30d24; }

input, select, textarea {
  font-family: inherit;
  font-size: 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
  width: 100%;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
}

label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 0.25rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 600;
}

/* Layout */
.app {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: var(--sidebar-w);
  background: var(--rwb-navy);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
}

.sidebar .brand {
  padding: 1.25rem 1rem;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.sidebar .brand .wordmark {
  font-weight: 900;
  font-size: 18px;
  letter-spacing: 0.04em;
}
.sidebar .brand .wordmark .red { color: var(--rwb-red); }
.sidebar .brand .wordmark .white { color: #fff; }
.sidebar .brand .wordmark .ball { color: var(--rwb-gold); }
.sidebar .brand .sub {
  font-size: 11px;
  color: rgba(255,255,255,0.6);
  margin-top: 0.25rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.sidebar nav {
  flex: 1;
  padding: 0.75rem 0.5rem;
  overflow-y: auto;
}
.sidebar nav a {
  display: flex;
  align-items: center;
  padding: 0.6rem 0.75rem;
  color: rgba(255,255,255,0.75);
  font-size: 14px;
  border-radius: 6px;
  margin-bottom: 2px;
  font-weight: 500;
}
.sidebar nav a:hover {
  background: rgba(255,255,255,0.08);
  color: #fff;
}
.sidebar nav a.active {
  background: var(--rwb-red);
  color: #fff;
}
.sidebar nav .nav-icon {
  width: 18px;
  display: inline-block;
  margin-right: 0.5rem;
  text-align: center;
}

.sidebar .user-panel {
  padding: 1rem;
  border-top: 1px solid rgba(255,255,255,0.08);
  font-size: 13px;
}
.sidebar .user-panel .name { color: #fff; font-weight: 600; }
.sidebar .user-panel .email { color: rgba(255,255,255,0.6); font-size: 12px; margin-top: 0.15rem; }
.sidebar .user-panel button {
  margin-top: 0.75rem;
  width: 100%;
  background: rgba(255,255,255,0.05);
  border-color: rgba(255,255,255,0.15);
  color: #fff;
  font-size: 13px;
}
.sidebar .user-panel button:hover {
  background: rgba(255,255,255,0.12);
}

.main {
  flex: 1;
  margin-left: var(--sidebar-w);
  display: flex;
  flex-direction: column;
}

.topbar {
  padding: 1rem 2rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.topbar h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 600;
}
.topbar .breadcrumb {
  font-size: 12px;
  color: var(--muted);
  margin-top: 0.15rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.content {
  padding: 2rem;
  max-width: 1400px;
  width: 100%;
}

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.25rem;
  margin-bottom: 1.25rem;
  box-shadow: var(--shadow-sm);
}
.card h2 {
  margin: 0 0 1rem 0;
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.card h3 {
  margin: 0 0 0.75rem 0;
  font-size: 14px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

/* KPI grid */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.25rem;
}
.kpi .label {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 0.5rem;
  font-weight: 600;
}
.kpi .value {
  font-size: 32px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.1;
}
.kpi .sub {
  font-size: 12px;
  color: var(--muted);
  margin-top: 0.5rem;
}

/* Tables */
.table-wrap {
  overflow-x: auto;
  border-radius: 6px;
  border: 1px solid var(--border);
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
thead th {
  text-align: left;
  padding: 0.6rem 0.85rem;
  background: var(--surface-2);
  color: var(--muted);
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: 0.06em;
  font-weight: 600;
  border-bottom: 1px solid var(--border);
}
tbody td {
  padding: 0.7rem 0.85rem;
  border-bottom: 1px solid var(--border);
}
tbody tr:last-child td { border-bottom: none; }
tbody tr.clickable { cursor: pointer; transition: background 0.1s; }
tbody tr.clickable:hover { background: rgba(255,255,255,0.03); }

/* Badges */
.badge {
  display: inline-block;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 600;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
}
.badge-success { background: rgba(74,222,128,0.15); color: var(--success); border: 1px solid rgba(74,222,128,0.3); }
.badge-warning { background: rgba(228,168,75,0.15); color: var(--warning); border: 1px solid rgba(228,168,75,0.3); }
.badge-danger  { background: rgba(248,113,113,0.15); color: var(--danger); border: 1px solid rgba(248,113,113,0.3); }
.badge-info    { background: rgba(96,165,250,0.15); color: var(--info); border: 1px solid rgba(96,165,250,0.3); }
.badge-muted   { background: rgba(122,127,148,0.15); color: var(--muted); border: 1px solid var(--border); }
.badge-primary { background: rgba(91,141,239,0.15); color: var(--primary); border: 1px solid rgba(91,141,239,0.3); }
.badge-venmo   { background: rgba(0,140,255,0.15); color: #005fba; border: 1px solid rgba(0,140,255,0.4); }

/* Progress bars */
.progress {
  position: relative;
  height: 8px;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid var(--border);
}
.progress .fill {
  position: absolute;
  left: 0; top: 0; bottom: 0;
  background: var(--primary);
  border-radius: 999px;
  transition: width 0.3s;
}
.progress.full .fill { background: var(--danger); }
.progress.nearfull .fill { background: var(--warning); }

/* Filters */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  margin-bottom: 1rem;
}
.filter-bar input[type="text"] { max-width: 280px; }
.chips {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
}
.chip {
  padding: 0.35rem 0.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 999px;
  font-size: 12px;
  cursor: pointer;
  font-weight: 500;
}
.chip:hover { color: var(--text); }
.chip.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

/* Pagination */
.pagination {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 1rem;
  font-size: 13px;
  color: var(--muted);
}
.pagination .controls { display: flex; gap: 0.5rem; }
.pagination button { padding: 0.4rem 0.85rem; font-size: 13px; }

/* Login page */
.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #0f1117 0%, #1a1d27 100%);
  padding: 1.5rem;
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 2.5rem 2rem;
  max-width: 380px;
  width: 100%;
  box-shadow: var(--shadow-md);
}
.login-card .brand {
  text-align: center;
  margin-bottom: 1.75rem;
}
.login-card .wordmark {
  font-weight: 900;
  font-size: 24px;
  letter-spacing: 0.04em;
  margin-bottom: 0.25rem;
}
.login-card .wordmark .red { color: var(--rwb-red); }
.login-card .wordmark .white { color: #fff; }
.login-card .wordmark .ball { color: var(--rwb-gold); }
.login-card .sub {
  font-size: 13px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}
.login-card .form-row { margin-bottom: 1rem; }
.login-card button[type="submit"] {
  width: 100%;
  padding: 0.75rem;
  font-size: 15px;
  margin-top: 0.5rem;
}
.error-msg {
  background: rgba(248,113,113,0.1);
  border: 1px solid rgba(248,113,113,0.35);
  color: var(--danger);
  padding: 0.6rem 0.85rem;
  border-radius: 6px;
  font-size: 13px;
  margin-bottom: 1rem;
}
.success-msg {
  background: rgba(74,222,128,0.1);
  border: 1px solid rgba(74,222,128,0.35);
  color: var(--success);
  padding: 0.6rem 0.85rem;
  border-radius: 6px;
  font-size: 13px;
  margin-bottom: 1rem;
}

/* Utility */
.row { display: flex; gap: 1rem; align-items: center; }
.flex-col { display: flex; flex-direction: column; gap: 0.5rem; }
.spacer { flex: 1; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 12px; }
.center { text-align: center; }
.right { text-align: right; }
.empty {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--muted);
  font-style: italic;
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 1rem;
}
.grid-3 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1rem;
}

.action-bar {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
}

.detail-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 1.25rem;
  gap: 1rem;
}
.detail-header h1 {
  margin: 0 0 0.35rem 0;
  font-size: 24px;
  font-weight: 700;
}
.detail-header .meta {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  align-items: center;
  margin-top: 0.5rem;
}

dl.kv {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0.5rem 1rem;
  margin: 0;
}
dl.kv dt {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 600;
}
dl.kv dd { margin: 0; }

.copy-row {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}
.copy-row input {
  flex: 1;
  font-family: ui-monospace, monospace;
  font-size: 12px;
}
.copy-row button { white-space: nowrap; }

@media (max-width: 768px) {
  :root { --sidebar-w: 200px; }
  .content { padding: 1.25rem; }
  .topbar { padding: 0.85rem 1.25rem; }
}

/* ============================================================
   Enhanced dashboard — charts, fill bars, activity feed, etc.
   ============================================================ */

/* Quick actions bar */
.quick-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  margin-bottom: 1.25rem;
  padding: 0.65rem 0.85rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.quick-actions .qa-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.45rem 0.85rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s, border-color 0.15s;
}
.quick-actions .qa-btn:hover:not(:disabled) {
  background: var(--border);
  color: var(--text);
}
.quick-actions .qa-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Refresh indicator */
.refresh-indicator {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.refresh-indicator .dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--muted);
  display: inline-block;
  transition: background 0.2s;
}
.refresh-indicator.pulse .dot {
  background: var(--success);
  animation: refresh-pulse 1.2s ease-out;
}
.refresh-indicator.pulse .text { color: var(--text); }
@keyframes refresh-pulse {
  0%   { transform: scale(1);   box-shadow: 0 0 0 0 rgba(74,222,128,0.55); }
  60%  { transform: scale(1.5); box-shadow: 0 0 0 8px rgba(74,222,128,0); }
  100% { transform: scale(1);   box-shadow: 0 0 0 0 rgba(74,222,128,0); }
}

/* Chart card */
.chart-card .chart-host {
  width: 100%;
  min-height: 220px;
  position: relative;
}
.chart-svg {
  width: 100%;
  height: auto;
  display: block;
}
.chart-legend {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  margin-top: 0.5rem;
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.chart-legend .swatch {
  display: inline-block;
  width: 12px;
  height: 3px;
  border-radius: 2px;
  vertical-align: middle;
  margin-right: 0.35rem;
}
.swatch-navy { background: var(--rwb-navy); }
.swatch-gold { background: var(--rwb-gold); }
.swatch-red  { background: var(--rwb-red); }

/* Division fill bars */
.fillbars {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.fillbar-row {
  display: grid;
  grid-template-columns: minmax(140px, 1fr) minmax(160px, 2fr);
  align-items: center;
  gap: 1rem;
  padding: 0.5rem 0.65rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  text-decoration: none;
  transition: background 0.12s, border-color 0.12s;
}
.fillbar-row:hover {
  background: var(--border);
  border-color: var(--primary);
}
.fillbar-label { font-size: 13px; }
.fillbar-track {
  position: relative;
  height: 22px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  overflow: hidden;
}
.fillbar-fill {
  position: absolute;
  left: 0; top: 0; bottom: 0;
  border-radius: 999px;
  transition: width 0.3s;
}
.fillbar-full { background: linear-gradient(90deg, #3a7bd5, var(--info)); }
.fillbar-high { background: linear-gradient(90deg, #2c9c5c, var(--success)); }
.fillbar-mid  { background: linear-gradient(90deg, #b08038, var(--warning)); }
.fillbar-low  { background: linear-gradient(90deg, #a52a2a, var(--danger)); }
.fillbar-count {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 11px;
  font-weight: 700;
  color: var(--text);
  text-shadow: 0 1px 2px rgba(0,0,0,0.6);
  letter-spacing: 0.02em;
}

/* KPI ring (waiver completion) */
.kpi-with-ring .kpi-ring-row {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  margin-top: 0.25rem;
}
.kpi-with-ring .value { font-size: 22px; }
.ring-wrap { flex: 0 0 auto; }
.ring { display: block; }

/* Revenue summary */
.revenue-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.85rem;
  margin: 0 0 0.5rem 0;
}
.revenue-summary > div {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.6rem 0.75rem;
}
.revenue-summary dt {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
  margin-bottom: 0.25rem;
}
.revenue-summary dd {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
}
.success-text { color: var(--success); }
.warning-text { color: var(--warning); }
.danger-text  { color: var(--danger); }

/* Activity feed */
.activity-feed {
  display: flex;
  flex-direction: column;
  max-height: 420px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 6px;
}
.activity-item {
  display: grid;
  grid-template-columns: 36px 1fr;
  gap: 0.5rem;
  padding: 0.6rem 0.85rem;
  border-bottom: 1px solid var(--border);
  text-decoration: none;
  color: var(--text);
  transition: background 0.1s;
  align-items: center;
}
.activity-item:last-child { border-bottom: none; }
.activity-item:hover { background: rgba(255,255,255,0.03); }
.activity-icon {
  display: flex;
  align-items: center;
  justify-content: center;
}
.activity-icon .ico {
  width: 28px;
  height: 28px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 13px;
  line-height: 1;
  border: 1px solid var(--border);
  background: var(--surface-2);
}
.ico-reg    { color: var(--success); border-color: rgba(74,222,128,0.4); }
.ico-pay    { color: var(--rwb-gold); border-color: rgba(228,168,75,0.45); }
.ico-player { color: var(--info); border-color: rgba(96,165,250,0.4); }
.ico-email  { color: var(--primary); border-color: rgba(91,141,239,0.4); }
.activity-body {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.activity-label {
  font-size: 13px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.activity-meta {
  font-size: 11px;
  color: var(--muted);
  margin-top: 0.15rem;
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 1rem;
}
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow-md);
  max-width: 500px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem 1.5rem 0;
}
.modal-header h3 { margin: 0; font-size: 16px; font-weight: 600; }
.modal-close {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 22px;
  cursor: pointer;
  padding: 0.15rem 0.45rem;
  line-height: 1;
  border-radius: 4px;
}
.modal-close:hover { color: var(--text); background: var(--surface-2); }
.modal-body { padding: 1.25rem 1.5rem; }
.modal-footer {
  padding: 0 1.5rem 1.5rem;
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}
.form-row { margin-bottom: 1rem; }

@media (max-width: 540px) {
  .quick-actions { padding: 0.5rem; }
  .refresh-indicator { margin-left: 0; width: 100%; justify-content: flex-end; }
  .fillbar-row { grid-template-columns: 1fr; gap: 0.35rem; }
}
