/* ============================================================
   PoliTrak — Global Design System
   politrak.jeremys.io
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Libre+Baskerville:ital,wght@0,400;0,700;1,400&family=DM+Sans:wght@300;400;500;600&display=swap');

/* ── Variables ─────────────────────────────────────────────── */
:root {
  /* Color palette */
  --bg:           #F7F3EC;      /* warm cream */
  --surface:      #FFFFFF;
  --surface-alt:  #F0EBE1;      /* slightly darker cream for inset areas */
  --border:       #DDD5C8;
  --border-light: #EDE8DF;

  /* Typography */
  --navy:         #1B2B3A;      /* primary text, near-black navy */
  --slate:        #4A5A6B;      /* secondary text */
  --muted:        #8A9BA8;      /* tertiary / placeholder */

  /* Brand accents */
  --green:        #2A6049;      /* primary action — forest green */
  --green-dark:   #1E4535;
  --green-light:  #EAF2EE;
  --gold:         #C8891A;      /* secondary accent — amber gold */
  --gold-light:   #FDF3E0;
  --red:          #B83232;      /* danger / not endorsed */
  --red-light:    #FAEAEA;
  --blue:         #1D4E89;      /* info / federal */
  --blue-light:   #EAF0F8;

  /* Status colors */
  --status-considering:  var(--gold);
  --status-screened:     var(--blue);
  --status-voted:        var(--slate);
  --status-endorsed:     var(--green);
  --status-not-endorsed: var(--red);

  /* Typography scale */
  --font-display: 'Libre Baskerville', Georgia, serif;
  --font-body:    'DM Sans', system-ui, sans-serif;

  --text-xs:   0.75rem;
  --text-sm:   0.875rem;
  --text-base: 1rem;
  --text-lg:   1.125rem;
  --text-xl:   1.25rem;
  --text-2xl:  1.5rem;
  --text-3xl:  1.875rem;
  --text-4xl:  2.25rem;

  /* Spacing */
  --space-1:  0.25rem;
  --space-2:  0.5rem;
  --space-3:  0.75rem;
  --space-4:  1rem;
  --space-5:  1.25rem;
  --space-6:  1.5rem;
  --space-8:  2rem;
  --space-10: 2.5rem;
  --space-12: 3rem;
  --space-16: 4rem;

  /* Radius */
  --radius-sm: 4px;
  --radius:    8px;
  --radius-lg: 12px;
  --radius-xl: 16px;

  /* Shadows */
  --shadow-sm:  0 1px 3px rgba(27,43,58,0.08);
  --shadow:     0 2px 8px rgba(27,43,58,0.10);
  --shadow-md:  0 4px 16px rgba(27,43,58,0.12);
  --shadow-lg:  0 8px 32px rgba(27,43,58,0.14);

  /* Layout */
  --sidebar-w: 240px;
  --topbar-h:  60px;
  --content-max: 1200px;

  /* Transitions */
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --t-fast: 120ms var(--ease);
  --t-base: 200ms var(--ease);
  --t-slow: 300ms var(--ease);
}

/* ── Reset ──────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font-body);
  font-size: var(--text-base);
  color: var(--navy);
  background: var(--bg);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
img, svg { display: block; max-width: 100%; }
a { color: var(--green); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font-family: inherit; font-size: inherit; }

/* ── Typography ─────────────────────────────────────────────── */
h1, h2, h3, h4 {
  font-family: var(--font-display);
  color: var(--navy);
  line-height: 1.25;
  font-weight: 700;
}
h1 { font-size: var(--text-3xl); }
h2 { font-size: var(--text-2xl); }
h3 { font-size: var(--text-xl); }
h4 { font-size: var(--text-lg); }
h5, h6 {
  font-family: var(--font-body);
  font-weight: 600;
  font-size: var(--text-base);
  color: var(--navy);
  line-height: 1.4;
}
p { color: var(--slate); line-height: 1.7; }
small { font-size: var(--text-sm); color: var(--muted); }

.label {
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

/* ── Layout Shell ───────────────────────────────────────────── */
.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: var(--topbar-h) 1fr;
  min-height: 100vh;
}

/* Mount divs are the actual grid children — must place them correctly */
#topbar-mount  { grid-column: 1 / -1; grid-row: 1; }
#sidebar-mount { grid-column: 1;      grid-row: 2; min-height: 0; }
.main-content  { grid-column: 2;      grid-row: 2; }

/* Top bar */
.topbar {
  grid-column: 1 / -1;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 var(--space-6);
  gap: var(--space-4);
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-sm);
}
.topbar-brand {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-family: var(--font-display);
  font-size: var(--text-xl);
  font-weight: 700;
  color: var(--navy);
  text-decoration: none;
  flex-shrink: 0;
}
.topbar-brand .brand-dot {
  width: 8px; height: 8px;
  background: var(--green);
  border-radius: 50%;
  display: inline-block;
}
.topbar-search {
  flex: 1;
  max-width: 480px;
  margin-left: auto;
}
.topbar-right {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-left: var(--space-4);
}

/* Sidebar */
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: var(--space-6) 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  overflow-y: auto;
  position: sticky;
  top: var(--topbar-h);
  height: calc(100vh - var(--topbar-h));
}
.sidebar-section {
  padding: var(--space-4) var(--space-4) var(--space-2);
}
.sidebar-section + .sidebar-section {
  border-top: 1px solid var(--border-light);
  margin-top: var(--space-2);
  padding-top: var(--space-4);
}
.nav-link {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-4);
  color: var(--slate);
  font-size: var(--text-sm);
  font-weight: 500;
  border-radius: 0;
  transition: background var(--t-fast), color var(--t-fast);
  cursor: pointer;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  text-decoration: none;
}
.nav-link:hover { background: var(--surface-alt); color: var(--navy); text-decoration: none; }
.nav-link.active {
  background: var(--green-light);
  color: var(--green);
  font-weight: 600;
  border-right: 3px solid var(--green);
}
.nav-link svg { width: 18px; height: 18px; flex-shrink: 0; opacity: 0.7; }
.nav-link.active svg { opacity: 1; }
.nav-badge {
  margin-left: auto;
  background: var(--gold-light);
  color: var(--gold);
  font-size: var(--text-xs);
  font-weight: 700;
  padding: 1px 7px;
  border-radius: 20px;
}

/* Main content */
.main-content {
  padding: var(--space-8);
  overflow-y: auto;
}
.page-header {
  margin-bottom: var(--space-8);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-4);
  flex-wrap: wrap;
}
.page-title { font-size: var(--text-3xl); }
.page-subtitle { color: var(--slate); margin-top: var(--space-1); font-size: var(--text-base); }

/* ── Cards ──────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  box-shadow: var(--shadow-sm);
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-5);
  gap: var(--space-4);
}
.card-title {
  font-family: var(--font-display);
  font-size: var(--text-lg);
  font-weight: 700;
  color: var(--navy);
}

/* Stat card */
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  box-shadow: var(--shadow-sm);
  position: relative;
  overflow: hidden;
}
.stat-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: var(--green);
}
.stat-card.gold::before { background: var(--gold); }
.stat-card.blue::before { background: var(--blue); }
.stat-card.red::before  { background: var(--red); }
.stat-value {
  font-family: var(--font-display);
  font-size: var(--text-4xl);
  font-weight: 700;
  color: var(--navy);
  line-height: 1;
  margin: var(--space-2) 0;
}
.stat-label { font-size: var(--text-sm); color: var(--muted); font-weight: 500; }
.stat-delta {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--green);
  margin-top: var(--space-2);
}
.stat-delta.neg { color: var(--red); }

/* ── Buttons ────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: 0.625rem var(--space-5);
  border-radius: var(--radius);
  font-size: var(--text-sm);
  font-weight: 600;
  cursor: pointer;
  border: 1.5px solid transparent;
  transition: all var(--t-fast);
  text-decoration: none;
  white-space: nowrap;
  line-height: 1;
}
.btn:hover { text-decoration: none; }
.btn-primary {
  background: var(--green);
  color: #fff;
  border-color: var(--green);
}
.btn-primary:hover { background: var(--green-dark); border-color: var(--green-dark); }
.btn-secondary {
  background: var(--surface);
  color: var(--navy);
  border-color: var(--border);
}
.btn-secondary:hover { background: var(--surface-alt); border-color: var(--slate); }
.btn-ghost {
  background: transparent;
  color: var(--slate);
  border-color: transparent;
}
.btn-ghost:hover { background: var(--surface-alt); color: var(--navy); }
.btn-danger {
  background: var(--red);
  color: #fff;
  border-color: var(--red);
}
.btn-sm {
  padding: 0.375rem var(--space-3);
  font-size: var(--text-xs);
}
.btn-lg {
  padding: 0.875rem var(--space-8);
  font-size: var(--text-base);
}
.btn svg { width: 16px; height: 16px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ── Forms ──────────────────────────────────────────────────── */
.form-group { display: flex; flex-direction: column; gap: var(--space-2); }
.form-label {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--navy);
}
.form-label .required { color: var(--red); margin-left: 2px; }
.form-input, .form-select, .form-textarea {
  width: 100%;
  padding: 0.625rem var(--space-4);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--navy);
  font-size: var(--text-sm);
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
  appearance: none;
}
.form-input::placeholder, .form-textarea::placeholder { color: var(--muted); }
.form-input:focus, .form-select:focus, .form-textarea:focus {
  outline: none;
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(42,96,73,0.12);
}
.form-input.error { border-color: var(--red); }
.form-error { font-size: var(--text-xs); color: var(--red); font-weight: 500; }
.form-hint { font-size: var(--text-xs); color: var(--muted); }
.form-select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%234A5A6B' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}
.form-textarea { resize: vertical; min-height: 100px; }

/* Search input */
.search-input-wrap {
  position: relative;
}
.search-input-wrap svg {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 16px; height: 16px;
  color: var(--muted);
  pointer-events: none;
}
.search-input-wrap input {
  padding-left: 38px;
}

/* ── Badges / Tags ──────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 10px;
  border-radius: 20px;
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.02em;
}
.badge-green  { background: var(--green-light); color: var(--green); }
.badge-gold   { background: var(--gold-light);  color: var(--gold); }
.badge-red    { background: var(--red-light);   color: var(--red); }
.badge-blue   { background: var(--blue-light);  color: var(--blue); }
.badge-gray   { background: var(--surface-alt); color: var(--slate); }

/* Party badges */
.party-D { background: #dbeafe; color: #1e40af; }
.party-R { background: #fee2e2; color: #991b1b; }
.party-W { background: #fde68a; color: #92400e; } /* Working Families */
.party-I { background: var(--surface-alt); color: var(--slate); }

/* Endorsement status */
.status-considering  { background: var(--gold-light);  color: var(--gold);  }
.status-screened     { background: var(--blue-light);  color: var(--blue);  }
.status-voted        { background: var(--surface-alt); color: var(--slate); }
.status-endorsed     { background: var(--green-light); color: var(--green); }
.status-not-endorsed { background: var(--red-light);   color: var(--red);   }

/* ── Tables ─────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
}
thead th {
  text-align: left;
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--muted);
  border-bottom: 2px solid var(--border);
  background: var(--bg);
  white-space: nowrap;
}
tbody tr {
  border-bottom: 1px solid var(--border-light);
  transition: background var(--t-fast);
}
tbody tr:hover { background: var(--surface-alt); }
tbody tr:last-child { border-bottom: none; }
tbody td {
  padding: var(--space-3) var(--space-4);
  color: var(--navy);
  vertical-align: middle;
}

/* ── Tabs ───────────────────────────────────────────────────── */
.tabs {
  display: flex;
  gap: 0;
  border-bottom: 2px solid var(--border);
  margin-bottom: var(--space-6);
}
.tab {
  padding: var(--space-3) var(--space-5);
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--slate);
  cursor: pointer;
  border: none;
  background: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: color var(--t-fast), border-color var(--t-fast);
}
.tab:hover { color: var(--navy); }
.tab.active { color: var(--green); border-bottom-color: var(--green); font-weight: 600; }

/* ── Alerts / Messages ──────────────────────────────────────── */
.alert {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-4);
  border-radius: var(--radius);
  font-size: var(--text-sm);
}
.alert-success { background: var(--green-light); color: var(--green-dark); border: 1px solid rgba(42,96,73,0.2); }
.alert-warning { background: var(--gold-light);  color: #7A4F0A; border: 1px solid rgba(200,137,26,0.2); }
.alert-error   { background: var(--red-light);   color: var(--red); border: 1px solid rgba(184,50,50,0.2); }
.alert-info    { background: var(--blue-light);  color: var(--blue); border: 1px solid rgba(29,78,137,0.2); }

/* ── Avatar ─────────────────────────────────────────────────── */
.avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--green-light);
  color: var(--green);
  font-weight: 700;
  font-size: var(--text-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-family: var(--font-display);
}
.avatar-sm { width: 28px; height: 28px; font-size: var(--text-xs); }
.avatar-lg { width: 48px; height: 48px; font-size: var(--text-lg); }

/* ── Divider ────────────────────────────────────────────────── */
.divider {
  height: 1px;
  background: var(--border);
  margin: var(--space-6) 0;
}

/* ── Grid helpers ───────────────────────────────────────────── */
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--space-6); }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--space-6); }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--space-6); }

/* ── Utility ────────────────────────────────────────────────── */
.flex     { display: flex; }
.flex-col { display: flex; flex-direction: column; }
.items-center  { align-items: center; }
.items-start   { align-items: flex-start; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.gap-4 { gap: var(--space-4); }
.gap-6 { gap: var(--space-6); }
.mt-2  { margin-top: var(--space-2); }
.mt-4  { margin-top: var(--space-4); }
.mt-6  { margin-top: var(--space-6); }
.mt-8  { margin-top: var(--space-8); }
.mb-4  { margin-bottom: var(--space-4); }
.mb-6  { margin-bottom: var(--space-6); }
.text-right { text-align: right; }
.text-center { text-align: center; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.w-full { width: 100%; }
.font-display { font-family: var(--font-display); }
.text-navy  { color: var(--navy); }
.text-slate { color: var(--slate); }
.text-muted { color: var(--muted); }
.text-green { color: var(--green); }
.text-gold  { color: var(--gold); }
.text-red   { color: var(--red); }
.text-sm    { font-size: var(--text-sm); }
.text-xs    { font-size: var(--text-xs); }
.font-600   { font-weight: 600; }
.font-700   { font-weight: 700; }

/* ── Empty state ────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: var(--space-16) var(--space-8);
  color: var(--muted);
}
.empty-state svg { width: 48px; height: 48px; margin: 0 auto var(--space-4); opacity: 0.35; }
.empty-state h3 { color: var(--slate); margin-bottom: var(--space-2); font-family: var(--font-display); }

/* ── Mobile sidebar overlay ─────────────────────────────────── */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(27,43,58,0.45);
  z-index: 200;
}
.mobile-menu-btn {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  padding: var(--space-2);
  color: var(--navy);
}

/* ── Responsive ─────────────────────────────────────────────── */
@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: var(--topbar-h) 1fr;
  }
  #topbar-mount  { grid-column: 1; grid-row: 1; }
  #sidebar-mount { grid-column: 1; grid-row: 2; position: fixed; top: var(--topbar-h); left: -var(--sidebar-w); z-index: 200; }
  .main-content  { grid-column: 1; grid-row: 2; }
  .sidebar {
    position: fixed;
    left: -100%;
    top: var(--topbar-h);
    height: calc(100vh - var(--topbar-h));
    width: var(--sidebar-w);
    z-index: 300;
    transition: left var(--t-slow);
    box-shadow: var(--shadow-lg);
  }
  .sidebar.open { left: 0; }
  .sidebar-overlay.open { display: block; }
  .mobile-menu-btn { display: flex; }
  .main-content { padding: var(--space-5) var(--space-4); }
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .grid-3 { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 600px) {
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .page-header { flex-direction: column; align-items: flex-start; }
  .topbar-search { display: none; }
  h1 { font-size: var(--text-2xl); }
}