/* GavaMedia — Unified Monochrome Black & White Theme
   Reused across every page (Public Intelligence + Admin Console). */

:root, [data-theme="light"] {
  --bg: #ffffff;
  --bg-subtle: #f6f6f7;
  --bg-hover: #ededef;
  --bg-inverse: #0a0a0a;
  --text: #0a0a0a;
  --text-secondary: #3f3f46;
  --text-muted: #71717a;
  --text-inverse: #ffffff;
  --border: #e4e4e7;
  --border-strong: #18181b;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.08);
  --font-sans: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
}

[data-theme="dark"] {
  --bg: #09090b;
  --bg-subtle: #121215;
  --bg-hover: #1c1c21;
  --bg-inverse: #fafafa;
  --text: #fafafa;
  --text-secondary: #d4d4d8;
  --text-muted: #a1a1aa;
  --text-inverse: #09090b;
  --border: #27272a;
  --border-strong: #e4e4e7;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 12px 32px rgba(0, 0, 0, 0.6);
}

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

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

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

code, pre, .mono {
  font-family: var(--font-mono);
}

/* App Shell */
.app-shell {
  display: flex;
  min-height: 100vh;
}

/* Minimalist Sidebar */
.sidebar {
  width: 244px;
  flex-shrink: 0;
  background: var(--bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  z-index: 40;
}

.sidebar-brand {
  padding: 18px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 11px;
  cursor: pointer;
  text-decoration: none;
}
.sidebar-brand:hover { text-decoration: none; }

.brand-mark {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-sm);
  background: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
  border: 1px solid var(--border);
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.brand-logo-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  padding: 2px;
}
[data-theme="dark"] .brand-mark {
  background: #0f172a;
  border-color: rgba(255,255,255,0.15);
}
[data-theme="dark"] .brand-logo-img {
  filter: invert(1) brightness(1.2);
}

.brand-meta h1 {
  margin: 0;
  font-size: 14.5px;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.brand-meta small {
  display: block;
  font-size: 11px;
  color: var(--text-muted);
}

.sidebar-group {
  padding: 14px 12px 6px;
}

.sidebar-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  padding: 0 8px 6px;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  border: 1px solid transparent;
  transition: background 0.12s ease, color 0.12s ease;
}
.nav-link:hover {
  background: var(--bg-subtle);
  color: var(--text);
  text-decoration: none;
}
.nav-link.active {
  background: var(--bg-inverse);
  color: var(--text-inverse);
  font-weight: 600;
}
.nav-count {
  font-family: var(--font-mono);
  font-size: 11px;
  opacity: 0.72;
}

/* Workspace & Topbar */
.workspace {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  padding: 10px 24px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.mobile-menu-btn {
  display: none;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  font-size: 15px;
  cursor: pointer;
}

.search-wrap {
  position: relative;
  flex: 1;
  min-width: 220px;
  max-width: 520px;
  display: flex;
  gap: 6px;
}

.search-input, .input, .select, .textarea {
  width: 100%;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 11px;
  font-size: 13px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.12s ease;
}
.search-input:focus, .input:focus, .select:focus, .textarea:focus {
  border-color: var(--border-strong);
}

.topbar-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}

.select-compact {
  width: auto;
  min-width: 190px;
  padding: 7px 10px;
  font-weight: 600;
}

.autocomplete-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  z-index: 80;
  max-height: 320px;
  overflow-y: auto;
}
.autocomplete-item {
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}
.autocomplete-item:last-child { border-bottom: none; }
.autocomplete-item:hover { background: var(--bg-subtle); }

/* Main Container */
.main-content {
  width: 100%;
  max-width: 1160px;
  margin: 0 auto;
  padding: 26px 24px 60px;
}

/* Page Header */
.page-header {
  padding-bottom: 20px;
  margin-bottom: 22px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 18px;
  flex-wrap: wrap;
}

.eyebrow {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.page-title {
  margin: 0;
  font-size: 26px;
  font-weight: 750;
  letter-spacing: -0.025em;
  line-height: 1.2;
}

.page-subtitle {
  margin: 6px 0 0;
  color: var(--text-muted);
  font-size: 13.5px;
  max-width: 720px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--bg-inverse);
  background: var(--bg-inverse);
  color: var(--text-inverse);
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
  transition: opacity 0.12s ease, background 0.12s ease;
}
.btn:hover { opacity: 0.86; text-decoration: none; }

.btn-outline {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-outline:hover {
  background: var(--bg-subtle);
  border-color: var(--border-strong);
  opacity: 1;
}
.btn-outline.active {
  background: var(--bg-inverse);
  color: var(--text-inverse);
  border-color: var(--bg-inverse);
}

.btn-sm {
  padding: 5px 10px;
  font-size: 12px;
}

/* Grids */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}

.grid {
  display: grid;
  gap: 14px;
}
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

/* Cards */
.card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px 18px;
}
.card-subtle {
  background: var(--bg-subtle);
}
.card-priority {
  border: 1px solid var(--border);
}
.card-clickable {
  cursor: pointer;
  transition: border-color 0.12s ease, background 0.12s ease;
}
.card-clickable:hover {
  border-color: var(--border-strong);
  background: var(--bg-subtle);
}

.kpi-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
}
.kpi-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}
.kpi-value {
  font-size: 22px;
  font-weight: 750;
  letter-spacing: -0.02em;
  margin: 4px 0 2px;
  font-variant-numeric: tabular-nums;
}
.kpi-sub {
  font-size: 11.5px;
  color: var(--text-muted);
}

/* Section Headers & Show-More Bars */
.section-block {
  margin-bottom: 28px;
}

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.section-title {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.section-meta {
  font-size: 12px;
  color: var(--text-muted);
}

.reveal-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 14px;
  padding: 10px;
  border: 1px dashed var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-subtle);
}

.filter-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 10px 12px;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  margin-bottom: 16px;
}

/* Badges (Strict Black & White) */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  line-height: 1.5;
  border: 1px solid transparent;
}
.badge-solid {
  background: var(--bg-inverse);
  color: var(--text-inverse);
  border-color: var(--bg-inverse);
}
.badge-outline {
  background: transparent;
  color: var(--text);
  border-color: var(--border-strong);
}
.badge-muted {
  background: var(--bg-subtle);
  color: var(--text-secondary);
  border-color: var(--border);
}

/* Grade Box */
.grade-box {
  min-width: 44px;
  height: 44px;
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius-sm);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2px 6px;
  flex-shrink: 0;
}
.grade-box.grade-high {
  background: var(--bg-inverse);
  color: var(--text-inverse);
}
.grade-letter {
  font-size: 16px;
  font-weight: 800;
  line-height: 1;
}
.grade-score {
  font-family: var(--font-mono);
  font-size: 10px;
  opacity: 0.8;
}

/* Math Proof Box */
.math-box {
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  margin: 10px 0;
  font-size: 12.5px;
}
.math-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 2px 0;
}
.math-row.total {
  margin-top: 5px;
  padding-top: 6px;
  border-top: 1px solid var(--border);
  font-weight: 700;
}

/* Tables */
.table-wrap {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg);
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
th {
  text-align: left;
  padding: 10px 12px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  background: var(--bg-subtle);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--bg-subtle); }

/* Monochrome Progress Bar */
.progress-track {
  width: 100%;
  height: 6px;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: 999px;
  overflow: hidden;
  margin-top: 4px;
}
.progress-fill {
  height: 100%;
  background: var(--bg-inverse);
}

/* Modals */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 100;
}
.modal-box {
  position: relative;
  width: 100%;
  max-width: 820px;
  max-height: 88vh;
  overflow-y: auto;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-md);
}
.modal-close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 30px;
  height: 30px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}
.modal-close:hover {
  background: var(--bg-inverse);
  color: var(--text-inverse);
}

/* Utilities */
.muted { color: var(--text-muted); }
.small { font-size: 12px; }
.hidden { display: none !important; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.row-gap { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.empty-state {
  padding: 34px 18px;
  text-align: center;
  color: var(--text-muted);
  border: 1px dashed var(--border);
  border-radius: var(--radius-md);
}

/* ==========================================================================
   Comprehensive Mobile & Small-Device Responsive Architecture
   ========================================================================== */

/* Universal Mobile Safeguards */
* {
  box-sizing: border-box;
}
img, svg, video, canvas {
  max-width: 100%;
  height: auto;
}
body {
  overflow-x: hidden;
}

/* Sidebar Backdrop */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(2px);
  z-index: 85;
}
.sidebar-backdrop.active {
  display: block;
}
.mobile-close-btn {
  display: none;
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 19px;
  cursor: pointer;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
}
.mobile-close-btn:hover {
  background: var(--bg-subtle);
}

/* Table Horizontal Scrolling on Mobile */
.table-wrap {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-bottom: 14px;
}
.table-wrap table {
  min-width: 540px;
}

/* Tablet & Intermediate Breakpoint */
@media (max-width: 980px) {
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
  .grid-3, .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .topbar { padding: 10px 16px; }
  .main-content { padding: 20px 16px 48px; }
}

/* Auto-Scrolling Politician Performance Ticker (Monochrome, Uniform Border) */
.perf-callout-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 12px;
}
.perf-ticker-viewport {
  width: 100%;
  overflow-x: auto;
  scroll-behavior: auto;
  padding-bottom: 6px;
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) var(--bg-subtle);
}
.perf-ticker-track {
  display: flex;
  gap: 12px;
  width: max-content;
}
.perf-ticker-card {
  width: 295px;
  flex: 0 0 295px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 13px 15px;
  cursor: pointer;
  transition: border-color 0.12s ease, background 0.12s ease;
}
.perf-ticker-card:hover {
  border-color: var(--border-strong);
  background: var(--bg-subtle);
}
.proof-text-long {
  margin: 10px 0 0;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  white-space: pre-line;
  line-height: 1.58;
  color: var(--text-secondary);
}

/* Mobile & Small Screen Breakpoint (max-width: 768px) */
@media (max-width: 768px) {
  /* Sidebar Drawer */
  .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: -285px;
    width: 275px;
    height: 100vh;
    z-index: 90;
    box-shadow: 0 0 28px rgba(0,0,0,0.35);
    transition: left 0.22s cubic-bezier(0.16, 1, 0.3, 1);
  }
  .sidebar.open {
    left: 0;
  }
  .mobile-menu-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    white-space: nowrap;
    font-weight: 600;
  }
  .mobile-close-btn {
    display: inline-flex;
  }

  /* Topbar Stacking */
  .topbar {
    padding: 8px 12px;
    gap: 8px;
    flex-direction: column;
    align-items: stretch;
  }
  .topbar-row-1 {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
  }
  .search-wrap {
    min-width: 0;
    flex: 1;
    max-width: 100%;
  }
  .topbar-right {
    margin-left: 0;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
    flex-wrap: wrap;
  }
  .header-donate-card {
    flex: 1 1 100% !important;
    text-align: center;
    justify-content: center;
    font-size: 12px !important;
    padding: 6px 10px !important;
  }
  .select-compact {
    flex: 1 1 auto;
    min-width: 120px;
    font-size: 12px;
    padding: 6px 8px;
  }
  #themeToggleBtn {
    flex: 0 0 auto;
    padding: 6px 8px;
    font-size: 11.5px;
  }

  /* Main Workspace Content */
  .main-content {
    padding: 14px 10px 48px;
  }

  /* Header & Action Stacking */
  .page-header {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
    padding-bottom: 14px;
    margin-bottom: 16px;
  }
  .page-title {
    font-size: 21px !important;
    line-height: 1.25;
  }
  .page-subtitle {
    font-size: 13px !important;
  }
  .header-actions {
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
  }
  .header-actions .btn, .header-actions a.btn {
    flex: 1 1 auto;
    text-align: center;
    justify-content: center;
  }
  .header-actions .card {
    width: 100%;
    justify-content: space-between;
  }

  /* Section Headers */
  .section-head {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }
  .section-title {
    font-size: 16px;
  }

  /* Filter Bars on Mobile */
  .filter-bar {
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
    padding: 8px;
  }
  .filter-bar input, .filter-bar .input, .filter-bar select, .filter-bar .select {
    width: 100% !important;
    max-width: 100% !important;
    margin-left: 0 !important;
  }
  .filter-bar .btn {
    flex: 1 1 auto;
    text-align: center;
    justify-content: center;
  }

  /* KPI Grids: 1 column on mobile */
  .kpi-grid {
    grid-template-columns: 1fr !important;
    gap: 8px;
  }
  .grid-2, .grid-3, .grid-4 {
    grid-template-columns: 1fr !important;
    gap: 8px;
  }
  .kpi-card {
    padding: 12px 14px;
  }
  .kpi-value {
    font-size: 22px;
  }

  /* Cards & Lists */
  .card {
    padding: 14px 12px;
  }
  .perf-callout-grid {
    grid-template-columns: 1fr;
  }

  /* Project and Item card row-between */
  .project-card-row {
    flex-direction: column;
    align-items: stretch !important;
    gap: 12px;
  }
  .project-card-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    padding-top: 10px;
    border-top: 1px solid var(--border);
    flex-wrap: wrap;
  }
  .project-card-figures {
    text-align: left !important;
    margin-right: 0 !important;
    flex: 1;
  }

  /* Modal Optimization */
  .modal-overlay {
    padding: 8px;
  }
  .modal-box {
    padding: 16px 12px;
    max-height: 94vh;
  }
}

/* Very Small Mobile Devices (max-width: 480px) */
@media (max-width: 480px) {
  .page-title {
    font-size: 18.5px !important;
  }
  .badge {
    font-size: 10px;
    padding: 2px 5px;
  }
  .math-row {
    font-size: 11.5px;
  }
  .btn-sm {
    padding: 5px 8px;
    font-size: 11.5px;
  }
  .table-wrap table {
    min-width: 480px;
  }
}

@media print {
  .sidebar, .topbar, .no-print { display: none !important; }
  .main-content { max-width: 100%; padding: 0; }
  body { background: #ffffff; color: #000000; }
  .card, .table-wrap { border-color: #000000; }
}
