/* ── Reset & base ──────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

:root {
  --color-bg:          #f5f7fa;
  --color-surface:     #ffffff;
  --color-border:      #e2e8f0;
  --color-text:        #1a202c;
  --color-text-muted:  #718096;
  --color-accent:      #2b6cb0;
  --color-accent-dark: #2c5282;
  --color-contrib:     #3182ce;
  --color-expend:      #e53e3e;
  --color-success:     #38a169;
  --radius:            8px;
  --shadow:            0 1px 4px rgba(0,0,0,.08);
}

body {
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  font-size: 15px;
  line-height: 1.6;
}

a { color: var(--color-accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Header ────────────────────────────────────────────────────────────── */
header {
  background: linear-gradient(135deg, #1a365d 0%, #2b6cb0 100%);
  color: #fff;
  padding: 24px 32px;
}
.header-inner { max-width: 1200px; margin: auto; }
header h1 { font-size: 1.75rem; font-weight: 700; margin-bottom: 4px; }
.subtitle { font-size: 0.9rem; opacity: 0.85; }
.subtitle a { color: #bee3f8; }

/* ── Tab nav ────────────────────────────────────────────────────────────── */
.tab-nav {
  background: var(--color-surface);
  border-bottom: 2px solid var(--color-border);
  display: flex;
  gap: 2px;
  padding: 0 32px;
  overflow-x: auto;
}
.tab-btn {
  background: none;
  border: none;
  border-bottom: 3px solid transparent;
  padding: 14px 20px;
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  color: var(--color-text-muted);
  transition: color 0.15s, border-color 0.15s;
  white-space: nowrap;
  margin-bottom: -2px;
}
.tab-btn:hover  { color: var(--color-accent); }
.tab-btn.active {
  color: var(--color-accent);
  border-bottom-color: var(--color-accent);
}

/* ── Main / panels ──────────────────────────────────────────────────────── */
main { max-width: 1200px; margin: 32px auto; padding: 0 24px; }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ── Stat cards ─────────────────────────────────────────────────────────── */
.stat-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 32px;
}
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 20px 24px;
  box-shadow: var(--shadow);
}
.card-label {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-muted);
  margin-bottom: 8px;
}
.card-value {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--color-accent);
  line-height: 1.2;
  white-space: nowrap;
}

/* ── Chart boxes ────────────────────────────────────────────────────────── */
.chart-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  margin-bottom: 24px;
}
@media (max-width: 720px) { .chart-row { grid-template-columns: 1fr; } }

.chart-box {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
  margin-bottom: 24px;
}
.chart-box h2 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 16px;
  color: var(--color-text);
}
.chart-box.full-width { width: 100%; }
.chart-box canvas { max-height: 380px; }

/* ── Controls bar ───────────────────────────────────────────────────────── */
.controls-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.controls-bar label { font-size: 0.9rem; font-weight: 500; }
.controls-bar select,
.controls-bar input[type="search"] {
  padding: 7px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 0.9rem;
  background: var(--color-surface);
}
.controls-bar input[type="search"] { width: 280px; }
.search-bar { margin-bottom: 12px; }
#search-clear {
  padding: 7px 16px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface);
  cursor: pointer;
  font-size: 0.9rem;
}
#search-clear:hover { background: var(--color-bg); }

.search-info {
  font-size: 0.85rem;
  color: var(--color-text-muted);
  margin-bottom: 12px;
}

/* ── Table search input ─────────────────────────────────────────────────── */
input.table-search {
  display: block;
  width: 100%;
  max-width: 320px;
  margin: 0 16px 12px;
  padding: 6px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 0.9rem;
  background: var(--color-bg);
}
input.table-search:focus { outline: 2px solid var(--color-accent); outline-offset: 1px; }

/* ── Tables ─────────────────────────────────────────────────────────────── */
.table-wrapper {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow-x: auto;
  margin-bottom: 32px;
}
.table-wrapper h2 {
  font-size: 1rem;
  font-weight: 600;
  padding: 16px 20px 12px;
  border-bottom: 1px solid var(--color-border);
}
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}
.data-table th {
  text-align: left;
  padding: 10px 16px;
  background: var(--color-bg);
  border-bottom: 1px solid var(--color-border);
  font-weight: 600;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
}
.data-table th.sortable { cursor: pointer; user-select: none; }
.data-table th.sortable:hover { color: var(--color-accent); }
.data-table th.sort-asc::after  { content: " ↑"; color: var(--color-accent); }
.data-table th.sort-desc::after { content: " ↓"; color: var(--color-accent); }
.data-table td {
  padding: 9px 16px;
  border-bottom: 1px solid var(--color-border);
  vertical-align: top;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: #f0f4f8; }
.data-table td.num,
.data-table th.num { text-align: right; font-variant-numeric: tabular-nums; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.03em;
}
.badge-C { background: #bee3f8; color: #1a365d; }
.badge-E { background: #fed7d7; color: #742a2a; }

/* ── Footer ─────────────────────────────────────────────────────────────── */
footer {
  text-align: center;
  padding: 24px;
  font-size: 0.8rem;
  color: var(--color-text-muted);
  border-top: 1px solid var(--color-border);
  margin-top: 48px;
}

/* ── Loading / error states ─────────────────────────────────────────────── */
.loading-msg {
  text-align: center;
  padding: 48px;
  color: var(--color-text-muted);
  font-size: 1rem;
}
.error-msg {
  background: #fff5f5;
  border: 1px solid #fc8181;
  border-radius: var(--radius);
  padding: 16px 20px;
  color: #742a2a;
  margin: 16px 0;
}

.last-updated {
  font-size: 0.8rem;
  color: var(--color-text-muted);
  margin-top: 8px;
}

/* ── Global filter bar ──────────────────────────────────────────────────── */
.global-filter-bar {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  padding: 12px 32px;
}
.filter-inner {
  max-width: 1200px;
  margin: auto;
  display: flex;
  align-items: flex-end;
  gap: 24px;
  flex-wrap: wrap;
}
.filter-label {
  display: block;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-muted);
  margin-bottom: 5px;
}

/* ── Filer combobox ─────────────────────────────────────────────────────── */
.filer-selector { flex: 1; min-width: 260px; }
.filer-combobox {
  position: relative;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface);
  transition: border-color 0.15s;
}
.filer-combobox:focus-within {
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px rgba(43,108,176,0.15);
}
.chip-input-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  min-height: 38px;
}
.filer-search-input {
  border: none;
  outline: none;
  background: transparent;
  flex: 1;
  min-width: 140px;
  padding: 4px 4px;
  font-size: 0.9rem;
  color: var(--color-text);
}

/* ── Chips ──────────────────────────────────────────────────────────────── */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: #ebf4ff;
  border: 1px solid #bee3f8;
  color: #1a365d;
  border-radius: 999px;
  padding: 2px 8px 2px 10px;
  font-size: 0.8rem;
  font-weight: 500;
  max-width: 220px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chip-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chip-remove {
  background: none;
  border: none;
  cursor: pointer;
  color: #2b6cb0;
  font-size: 1rem;
  line-height: 1;
  padding: 0 2px;
  flex-shrink: 0;
}
.chip-remove:hover { color: #e53e3e; }

/* ── Filer dropdown ─────────────────────────────────────────────────────── */
.filer-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: 0 4px 16px rgba(0,0,0,.12);
  z-index: 100;
  max-height: 260px;
  overflow-y: auto;
  list-style: none;
  padding: 4px 0;
  margin: 0;
}
.filer-dropdown li {
  padding: 8px 14px;
  font-size: 0.875rem;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.filer-dropdown li:hover,
.filer-dropdown li.selected { background: #ebf4ff; color: var(--color-accent); }
.filer-dropdown li.no-results {
  cursor: default;
  color: var(--color-text-muted);
  font-style: italic;
}

/* ── Date range selector ────────────────────────────────────────────────── */
.date-range-selector { flex-shrink: 0; }
.date-inputs {
  display: flex;
  align-items: center;
  gap: 8px;
}
.date-sep {
  font-size: 0.85rem;
  color: var(--color-text-muted);
}
input[type="date"] {
  padding: 6px 10px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 0.875rem;
  background: var(--color-surface);
  color: var(--color-text);
}
input[type="date"]:focus {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px rgba(43,108,176,0.15);
}

/* ── Apply button ───────────────────────────────────────────────────────── */
.filter-apply-btn {
  padding: 6px 14px;
  border: 1px solid var(--color-accent);
  border-radius: var(--radius);
  background: var(--color-accent);
  color: #fff;
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 600;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s;
}
.filter-apply-btn:hover {
  background: var(--color-accent-dark);
  border-color: var(--color-accent-dark);
}

/* ── Clear filters button ───────────────────────────────────────────────── */
.filter-clear-btn {
  padding: 7px 16px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface);
  cursor: pointer;
  font-size: 0.875rem;
  color: var(--color-text-muted);
  white-space: nowrap;
  align-self: flex-end;
  transition: border-color 0.15s, color 0.15s;
}
.filter-clear-btn:hover {
  border-color: #e53e3e;
  color: #e53e3e;
}

/* ── Filer comparison grid ──────────────────────────────────────────────── */
.filer-comparison-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.filer-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 16px 20px;
  box-shadow: var(--shadow);
}
.filer-card-name {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--color-accent);
  margin-bottom: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.filer-card-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 12px;
}
.filer-card-stat-label {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-text-muted);
}
.filer-card-stat-value {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--color-text);
  text-align: right;
}

/* ── View toggle (Summary / By Year) ────────────────────────────────────── */
.view-toggle {
  display: inline-flex;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  overflow: hidden;
}
.toggle-btn {
  background: var(--color-surface);
  border: none;
  padding: 6px 14px;
  font-size: 0.875rem;
  cursor: pointer;
  color: var(--color-text-muted);
  transition: background 0.15s, color 0.15s;
}
.toggle-btn + .toggle-btn { border-left: 1px solid var(--color-border); }
.toggle-btn:hover { background: var(--color-bg); color: var(--color-text); }
.toggle-btn.active {
  background: var(--color-accent);
  color: #fff;
}

/* ── Section desc ───────────────────────────────────────────────────────── */
.section-desc {
  font-size: 0.85rem;
  color: var(--color-text-muted);
  padding: 0 20px 10px;
}

/* ── Donut tooltip ──────────────────────────────────────────────────────── */
.donut-tooltip {
  position: fixed;
  z-index: 9999;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: 0 4px 16px rgba(0,0,0,.14);
  padding: 12px 14px;
  min-width: 200px;
  max-width: 260px;
  pointer-events: none;
  font-size: 0.85rem;
}
.dt-header { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.dt-swatch { flex-shrink: 0; width: 12px; height: 12px; border-radius: 3px; }
.dt-type { font-weight: 600; color: var(--color-text); word-break: break-word; }
.dt-amount { font-size: 1.05rem; font-weight: 700; color: var(--color-accent); margin-bottom: 2px; }
.dt-pct { color: var(--color-text-muted); margin-bottom: 8px; }
.dt-donors-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--color-text-muted);
  margin-bottom: 4px;
}
.dt-donor { display: flex; justify-content: space-between; gap: 8px; padding: 2px 0; }
.dt-donor-name { color: var(--color-text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.dt-donor-amt  { flex-shrink: 0; color: var(--color-text-muted); }

/* ── Multi-filer donuts ─────────────────────────────────────────────────── */
.multi-donut-row {
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
  padding: 8px 0;
}
.donut-unit {
  flex: 1 1 260px;
  min-width: 220px;
  max-width: 420px;
}
.donut-unit-title {
  text-align: center;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--color-text-muted);
  margin-bottom: 6px;
}

/* ── Multi-donut shared legend ──────────────────────────────────────────── */
.multi-donut-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
  padding: 8px 4px 4px;
}
.mdl-item { display: flex; align-items: center; gap: 6px; font-size: 0.82rem; }
.mdl-swatch { flex-shrink: 0; width: 11px; height: 11px; border-radius: 2px; }
.mdl-label { color: var(--color-text); }

/* ── Frozen columns: donors by-year pivot table ──────────────────────────── */
/* border-collapse:collapse silently disables position:sticky on table cells.
   Switch to separate+0 spacing for this table only — visually identical.    */
#table-donors-by-year {
  border-collapse: separate;
  border-spacing: 0;
}
/* Give the rank (#) column a fixed width so the left offset for the Donor
   column can be hardcoded to match exactly.                                  */
#table-donors-by-year th:nth-child(1),
#table-donors-by-year td:nth-child(1) {
  position: sticky;
  left: 0;
  z-index: 2;
  width: 48px;
  min-width: 48px;
  max-width: 48px;
}
/* Donor name column — sticky at left: 48px (width of the # column) */
#table-donors-by-year th:nth-child(2),
#table-donors-by-year td:nth-child(2) {
  position: sticky;
  left: 48px;
  z-index: 2;
  /* shadow replaces the collapsed border so a divider shows when scrolled */
  box-shadow: 3px 0 5px -2px rgba(0,0,0,0.10);
}
/* All Time (grand total) column — sticky on the right */
#table-donors-by-year th:last-child,
#table-donors-by-year td:last-child {
  position: sticky;
  right: 0;
  z-index: 2;
  box-shadow: -3px 0 5px -2px rgba(0,0,0,0.10);
}
/* Solid backgrounds so scrolling content doesn't bleed through */
#table-donors-by-year th:nth-child(1),
#table-donors-by-year th:nth-child(2),
#table-donors-by-year th:last-child {
  background: var(--color-bg);
}
#table-donors-by-year td:nth-child(1),
#table-donors-by-year td:nth-child(2),
#table-donors-by-year td:last-child {
  background: var(--color-surface);
}
/* Preserve the row hover colour on frozen cells */
#table-donors-by-year tr:hover td:nth-child(1),
#table-donors-by-year tr:hover td:nth-child(2),
#table-donors-by-year tr:hover td:last-child {
  background: #f0f4f8;
}

/* ── Frozen header row: donors by-year pivot ─────────────────────────────── */
/* The inner scroll container holds only the table, so the title and search
   bar (above it) stay visible while the table scrolls in both directions.   */
.by-year-scroll {
  overflow: auto;
  max-height: 70vh;
}
/* All header cells stick to the top of the scroll container */
#table-donors-by-year thead th {
  position: sticky;
  top: 0;
  z-index: 4; /* above column-sticky td (z-index:2) */
  background: var(--color-bg);
}
/* Corner cells are both column-sticky and row-sticky — need highest z-index */
#table-donors-by-year thead th:nth-child(1),
#table-donors-by-year thead th:nth-child(2),
#table-donors-by-year thead th:last-child {
  z-index: 6;
}
.mdl-label { color: var(--color-text); }
