/* ================================================================
   Civic Tracker — styles.css  (v5 — masonry + pill filters)
   Fonts: Playfair Display · DM Sans · DM Mono
   ================================================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --ink:       #0d1117;
  --ink-soft:  #3d4757;
  --ink-mute:  #7c8899;
  --paper:     #f7f5f0;
  --paper-2:   #edeae3;
  --paper-3:   #ddd9d0;
  --surface:   #ffffff;
  --border:    rgba(13,17,23,0.09);
  --shadow-sm: 0 1px 4px rgba(13,17,23,0.07);
  --shadow-md: 0 4px 20px rgba(13,17,23,0.10);
  --shadow-lg: 0 12px 40px rgba(13,17,23,0.14);
  --radius:    14px;
  --radius-sm: 8px;
  --primary:   #1a3a6b;
  --accent:    #c8392b;
  --gold:      #d4a843;
  --green:     #2d7a4f;
  --bg:        var(--paper);
  --text:      var(--ink);
  --muted:     var(--ink-mute);
  --line:      var(--border);
  --tint-a:    #f4f5f3;
  --tint-b:    #f2f5f4;
}

html { font-size: 15px; }
body {
  font-family: 'DM Sans', system-ui, -apple-system, sans-serif;
  background: var(--paper); color: var(--ink); line-height: 1.6;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
.container { max-width: 1400px; margin: 0 auto; padding: 0 28px; }
.muted  { color: var(--ink-mute); font-size: 12px; }
.error  { color: #b91c1c; background: #fee2e2; border: 1px solid #fecaca; padding: 8px; border-radius: 8px; }

/* ================================================================
   SITE HEADER — dark sticky nav
   ================================================================ */
.site-header {
  background: var(--brand-color, var(--ink)) !important;
  border-bottom: none !important;
  position: sticky; top: 0; z-index: 200;
  box-shadow: 0 2px 16px rgba(0,0,0,0.2);
}
.site-header-inner,
.site-header .wrap {
  display: flex; align-items: center;
  justify-content: space-between;
  max-width: 1400px; margin: 0 auto;
  padding: 11px 28px; gap: 16px;
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; flex-shrink: 0; }
#navLogo  { height: 38px; width: auto; }
#navTitle { color: #fff !important; font-weight: 700; font-size: 14px; letter-spacing: -0.2px; }

.nav { display: flex; align-items: center; gap: 2px; }
.nav a {
  color: rgba(255,255,255,0.55) !important;
  font-size: 13px; font-weight: 500;
  text-decoration: none !important;
  padding: 7px 14px; border-radius: var(--radius-sm);
  transition: all 0.15s; background: transparent !important;
}
.nav a:hover  { color: #fff !important; background: rgba(255,255,255,0.08) !important; }
.nav a.active { color: #fff !important; background: rgba(255,255,255,0.14) !important; font-weight: 600; }

.hamburger {
  display: none; flex-direction: column; gap: 5px;
  background: none; border: none; cursor: pointer; padding: 6px;
}
.hamburger span { display: block; width: 22px; height: 2px; background: rgba(255,255,255,0.7); border-radius: 2px; }

/* ================================================================
   HERO STAT BANNER
   ================================================================ */
.hero-banner {
  background: var(--primary);
  padding: 0 28px; min-height: 66px;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  position: relative; overflow: hidden;
}
.hero-banner::before {
  content: ''; position: absolute; inset: 0;
  background: url("data:image/svg+xml,%3Csvg width='40' height='40' viewBox='0 0 40 40' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='%23ffffff' fill-opacity='0.03'%3E%3Cpath d='M20 20h4v4h-4zm-8 0h4v4h-4zM4 12h4v4H4zm16 0h4v4h-4zM4 4h4v4H4z'/%3E%3C/g%3E%3C/svg%3E");
  pointer-events: none;
}
.hero-stat-wrap { display: flex; align-items: center; gap: 16px; min-width: 0; }
.hero-label     { font-size: 10px; font-weight: 700; letter-spacing: 0.14em; text-transform: uppercase; color: rgba(255,255,255,0.45); flex-shrink: 0; }
.hero-content   { display: flex; align-items: center; gap: 14px; min-width: 0; }
.hero-number    { font-family: 'Playfair Display', Georgia, serif; font-size: 36px; font-weight: 900; color: var(--gold); line-height: 1; flex-shrink: 0; transition: opacity 0.2s; }
.hero-text      { font-size: 13.5px; color: rgba(255,255,255,0.82); line-height: 1.4; transition: opacity 0.2s; overflow: hidden; }
.hero-text strong { color: #fff; font-weight: 600; }
.hero-right     { display: flex; align-items: center; gap: 14px; flex-shrink: 0; }
.hero-dots      { display: flex; gap: 5px; align-items: center; }
.hero-dot       { width: 6px; height: 6px; border-radius: 50%; background: rgba(255,255,255,0.25); cursor: pointer; transition: all 0.2s; }
.hero-dot.active{ background: var(--gold); width: 16px; border-radius: 3px; }
.hero-meta      { font-size: 10.5px; color: rgba(255,255,255,0.3); font-family: 'DM Mono', monospace; white-space: nowrap; }

/* ================================================================
   DESCRIPTOR HEADER
   ================================================================ */
.header { background: var(--paper-2); border-bottom: 1px solid var(--border); padding: 18px 0; }
.header-inner {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  max-width: 1400px; margin: 0 auto; padding: 0 28px;
}
#siteTitle, .header-left h1 {
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 24px; font-weight: 700; margin: 0 0 4px;
  color: var(--primary); line-height: 1.2;
}
#siteSubtitle { color: var(--ink-mute); font-size: 12px; margin: 0; }
.desc         { color: var(--ink-soft); font-size: 13.5px; margin-top: 6px; line-height: 1.5; }

.header-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: flex-end; }
.btn {
  height: 36px; padding: 0 14px;
  border: 1px solid var(--border); background: var(--surface);
  cursor: pointer; border-radius: var(--radius-sm);
  font-weight: 600; font-size: 13px;
  font-family: 'DM Sans', sans-serif; color: var(--ink);
  transition: all 0.15s;
  display: inline-flex; align-items: center; gap: 5px;
  text-decoration: none !important; white-space: nowrap;
}
.btn:hover   { background: var(--paper-2); box-shadow: var(--shadow-sm); }
.btn.primary { background: var(--primary); color: #fff !important; border-color: var(--primary); }
.btn.primary:hover { opacity: 0.9; }
.btn.ghost   { background: var(--surface); color: var(--ink-soft); }
.auto { font-size: 12px; color: var(--ink-mute); display: flex; align-items: center; gap: 5px; cursor: pointer; white-space: nowrap; }

/* ================================================================
   LAYOUT
   ================================================================ */
.main-pad { padding-top: 28px; padding-bottom: 56px; }
.dash-grid-left {
  display: grid;
  grid-template-columns: 290px 1fr;
  gap: 28px; align-items: start;
  max-width: 1400px; margin: 0 auto; padding: 0 28px;
}

/* ================================================================
   LEFT RAIL — SIDEBAR
   ================================================================ */
.left-rail {
  position: sticky;
  top: calc(56px + 66px + 12px);
  max-height: calc(100vh - 168px);
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0; /* sections handle internal padding */
  box-shadow: var(--shadow-sm);
}

/* KPI strip at top of sidebar */
.sidebar-kpis {
  display: grid; grid-template-columns: repeat(3, 1fr);
  gap: 0; border-bottom: 1px solid var(--border);
}
.sidebar-kpi {
  text-align: center; padding: 14px 8px 12px;
  border-right: 1px solid var(--border);
}
.sidebar-kpi:last-child { border-right: none; }
.sidebar-kpi-val {
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 20px; font-weight: 700; color: var(--primary); line-height: 1;
}
.sidebar-kpi-lbl {
  font-size: 9px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.07em; color: var(--ink-mute); margin-top: 3px;
}

.sidebar-divider { height: 1px; background: var(--border); margin: 0; }

/* Questions block */
.questions-block { padding: 14px 16px; }
.label { font-size: 10px; color: var(--ink-mute); display: block; margin-bottom: 8px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; }
.label.big { font-size: 10px; }
.questions-block .search {
  height: 36px; padding: 0 12px;
  border: 1px solid var(--border); width: 100%;
  border-radius: var(--radius-sm); background: var(--surface);
  font-size: 13px; font-family: 'DM Sans', sans-serif;
  outline: none; transition: border-color 0.15s; margin-bottom: 10px;
}
.questions-block .search:focus { border-color: var(--primary); }
.questions-block select {
  width: 100%; min-height: 100px; max-height: 130px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); font-size: 13px; margin-bottom: 10px;
}
.question-select-row { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-group { display: flex; gap: 8px; width: 100%; }
.btn-group .btn { flex: 1; justify-content: center; }

/* Filters section */
.filters-section { padding: 14px 16px; }

.filter-group { margin-bottom: 14px; }
.filter-group:last-child { margin-bottom: 0; }
.filter-lbl {
  font-size: 10px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.07em; color: var(--ink-mute); margin-bottom: 6px;
}

/* Pill chips (Age, Gender) */
.pill-group { display: flex; flex-wrap: wrap; gap: 5px; }
.filter-pill {
  appearance: none;
  border: 1.5px solid var(--border); background: var(--surface);
  padding: 4px 11px; border-radius: 20px;
  font-size: 12px; font-weight: 500; color: var(--ink-soft) !important;
  cursor: pointer; transition: all 0.15s;
  font-family: 'DM Sans', sans-serif; line-height: 1.4;
}
.filter-pill:hover { border-color: var(--primary); color: var(--primary) !important; }
.filter-pill.active {
  background: var(--primary) !important;
  color: #fff !important;
  border-color: var(--primary) !important;
  font-weight: 600;
}

/* Select filters (State, Area, Relationship) */
.filter-select {
  width: 100%; min-height: 72px; max-height: 100px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); font-size: 12.5px; padding: 4px;
  font-family: 'DM Sans', sans-serif;
}

/* Date section */
.date-section { padding: 14px 16px; }
.date-row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.date-row input[type="date"] {
  height: 34px; border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 0 8px;
  font-size: 12px; flex: 1; min-width: 100px;
  font-family: 'DM Sans', sans-serif;
}
.sep { font-size: 12px; color: var(--ink-mute); }
.date-hint { font-size: 11px; color: var(--ink-mute); margin-top: 4px; }

/* Sidebar action buttons */
.sidebar-actions { padding: 12px 16px; display: flex; gap: 6px; border-top: 1px solid var(--border); }
.sidebar-actions .btn { flex: 1; justify-content: center; font-size: 12px; height: 34px; }

/* ================================================================
   ACTIVE FILTER TAGS BAR
   ================================================================ */
.active-filters {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 10px 14px; margin-bottom: 16px;
  background: var(--paper-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.active-filters-label { font-size: 11px; font-weight: 700; color: var(--ink-mute); text-transform: uppercase; letter-spacing: 0.06em; flex-shrink: 0; }
.active-filter-tags { display: flex; flex-wrap: wrap; gap: 6px; flex: 1; }
.active-tag {
  display: flex; align-items: center; gap: 5px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 20px; padding: 3px 10px;
  font-size: 12px; color: var(--ink-soft);
}
.active-tag-label { font-weight: 700; color: var(--ink-mute); font-size: 10px; text-transform: uppercase; }
.active-tag-x {
  background: none; border: none; cursor: pointer;
  color: var(--ink-mute); font-size: 14px; line-height: 1;
  padding: 0 0 0 2px; transition: color 0.1s;
}
.active-tag-x:hover { color: var(--accent); }
.active-filters-reset {
  background: none; border: none; cursor: pointer;
  font-size: 11px; font-weight: 600; color: var(--accent);
  white-space: nowrap; padding: 0; font-family: 'DM Sans', sans-serif;
  flex-shrink: 0;
}

/* ================================================================
   AI INSIGHTS CARD
   ================================================================ */
.insights-card {
  background: var(--ink); border-radius: var(--radius);
  margin-bottom: 24px; overflow: hidden; box-shadow: var(--shadow-lg);
}
.insights-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 22px; gap: 12px; flex-wrap: wrap;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}
.insights-brand { display: flex; align-items: center; gap: 12px; }
.insights-icon {
  width: 34px; height: 34px; border-radius: var(--radius-sm);
  background: linear-gradient(135deg, var(--accent), #e8553e);
  display: grid; place-items: center; font-size: 15px; flex-shrink: 0;
}
.insights-title    { color: #fff; font-size: 14px; font-weight: 700; }
.insights-subtitle { color: rgba(255,255,255,0.4); font-size: 11.5px; margin-top: 2px; }
.insights-actions  { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.quota-badge { font-size: 11px; font-weight: 600; padding: 4px 10px; border-radius: 20px; white-space: nowrap; }
.quota-ok    { background: rgba(110,231,183,0.1); color: #6ee7b7; border: 1px solid rgba(110,231,183,0.2); }
.quota-empty { background: rgba(239,68,68,0.12); color: #fca5a5; border: 1px solid rgba(239,68,68,0.2); }

.btn-copy {
  font-size: 12px; font-weight: 500; padding: 7px 13px; border-radius: var(--radius-sm);
  border: 1px solid rgba(255,255,255,0.12); background: transparent;
  color: rgba(255,255,255,0.6); cursor: pointer; transition: all 0.15s; white-space: nowrap;
}
.btn-copy:hover { background: rgba(255,255,255,0.08); color: #fff; }

.btn-generate, #generateInsights {
  font-size: 13px; font-weight: 600; padding: 8px 18px;
  border-radius: var(--radius-sm); border: none;
  background: linear-gradient(135deg, #3b6fd4, #1a3a6b);
  color: #fff; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px;
  transition: all 0.2s; white-space: nowrap;
  box-shadow: 0 2px 10px rgba(59,111,212,0.3);
}
.btn-generate:hover, #generateInsights:hover { transform: translateY(-1px); box-shadow: 0 4px 16px rgba(59,111,212,0.4); }
#generateInsights:disabled { opacity: 0.55; cursor: not-allowed; transform: none; box-shadow: none; }
#copyInsight { display: none; align-items: center; gap: 5px; }

.insight-tabs { display: flex; overflow-x: auto; border-bottom: 1px solid rgba(255,255,255,0.07); scrollbar-width: none; }
.insight-tabs::-webkit-scrollbar { display: none; }
.insight-tab {
  font-size: 11px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase;
  color: rgba(255,255,255,0.35); padding: 12px 20px; border: none; background: none;
  border-bottom: 2px solid transparent; cursor: pointer; white-space: nowrap; transition: all 0.15s;
}
.insight-tab:hover  { color: rgba(255,255,255,0.7); }
.insight-tab.active { color: #fff; border-bottom-color: #3b6fd4; }

.insights-body { padding: 22px; min-height: 80px; color: rgba(255,255,255,0.88); }
#insightSpinner { display: none; align-items: center; justify-content: center; gap: 10px; padding: 28px 0; color: rgba(255,255,255,0.4); font-size: 13px; }
.insight-content, .insight-content p, .insight-content li { color: rgba(255,255,255,0.88); font-size: 14px; line-height: 1.7; }
.insight-content strong { color: #fff; }
.insight-content h3, .insight-content h4 { color: #fff; margin: 14px 0 6px; }
.spinner-ring { width: 20px; height: 20px; border: 2px solid rgba(255,255,255,0.1); border-top-color: #3b6fd4; border-radius: 50%; animation: spin 0.7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
#insightError { display: none; padding: 10px 14px; background: rgba(239,68,68,0.1); border: 1px solid rgba(239,68,68,0.2); border-radius: var(--radius-sm); color: #fca5a5; font-size: 13px; margin: 4px 0; }
#insightBody { font-size: 13.5px; line-height: 1.78; color: rgba(255,255,255,0.8); }
#insightBody h3     { font-size: 14px; font-weight: 700; color: #fff; margin: 14px 0 4px; }
#insightBody h4     { font-size: 13px; font-weight: 700; color: rgba(255,255,255,0.9); margin: 12px 0 3px; }
#insightBody p      { margin: 0 0 10px; }
#insightBody ul     { margin: 6px 0 10px 18px; }
#insightBody li     { margin-bottom: 6px; }
#insightBody strong { color: #fff; font-weight: 600; }
.insights-idle { display: flex; align-items: center; gap: 10px; padding: 28px 0; color: rgba(255,255,255,0.3); font-size: 13px; text-align: center; justify-content: center; }
.insights-idle-icon { font-size: 20px; opacity: 0.3; }
.insights-idle strong { color: rgba(255,255,255,0.5); }
.insights-footer { padding: 13px 22px; border-top: 1px solid rgba(255,255,255,0.06); display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.powered-by-claude { display: flex; align-items: center; gap: 6px; font-size: 11px; color: rgba(255,255,255,0.3); }
.powered-by-claude strong { color: rgba(255,255,255,0.5); }
.insight-meta, #insightMeta { font-size: 11px; color: rgba(255,255,255,0.25); font-family: 'DM Mono', monospace; padding: 0; border: none; }

/* Upgrade wall */
.upgrade-wall    { text-align: center; padding: 28px 20px; }
.upgrade-icon    { font-size: 26px; opacity: 0.3; margin-bottom: 10px; }
.upgrade-heading { font-size: 15px; font-weight: 700; color: #fff; margin-bottom: 8px; }
.upgrade-body    { font-size: 13px; color: rgba(255,255,255,0.5); margin-bottom: 16px; line-height: 1.6; }
.upgrade-cta     { display: inline-block; padding: 10px 22px; background: linear-gradient(135deg,#3b82f6,#6366f1); color: #fff; border-radius: 8px; font-size: 13px; font-weight: 600; }
.upgrade-reset   { font-size: 11px; color: rgba(255,255,255,0.25); margin-top: 12px; }

/* ================================================================
   CHARTS — MASONRY GRID
   Width controlled per-card by applyMasonry() in script.js
   ================================================================ */
.charts {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 20px;
  align-items: start;
}

/* JS toggles this class based on count + label count */
.chart-card--wide { grid-column: span 2; }

.chart-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 22px 24px 16px;
  box-shadow: var(--shadow-sm); min-width: 0;
  transition: box-shadow 0.2s, transform 0.2s;
}
.chart-card:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); }

.chart-story-title {
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 18px; font-weight: 700; color: var(--ink);
  line-height: 1.25; margin-bottom: 6px;
}
.chart-question-sub {
  font-size: 15px; font-weight: 500; color: var(--ink);
  margin-bottom: 16px; line-height: 1.5;
  padding-bottom: 13px; border-bottom: 1px solid var(--paper-2);
  display: flex; align-items: flex-start; gap: 5px;
}
.chart-question-sub::before {
  content: 'Q'; font-family: 'DM Mono', monospace;
  font-size: 15px; font-weight: 600; color: #6d6d6d;
  background: var(--paper-2); border-radius: 3px; padding: 1px 4px;
  flex-shrink: 0; margin-top: 1px;
  
}
.chart-title { display: none !important; }

.canvas-wrap  { position: relative; min-height: 220px; }
.chart-actions { position: absolute; top: 6px; right: 6px; display: flex; gap: 6px; z-index: 2; }
.icon-btn {
  border: 1px solid var(--border); background: var(--surface);
  border-radius: 6px; height: 28px; padding: 0 8px;
  cursor: pointer; font-size: 11px; color: var(--ink-mute);
}
.icon-btn:hover { background: var(--paper-2); }

/* Tab bar inside chart cards */
.tab-bar { display: flex; gap: 6px; padding: 0 0 12px; }
.tab-btn {
  appearance: none;
  border: 1.5px solid var(--border); background: var(--surface);
  padding: 5px 14px; border-radius: 20px;
  font-weight: 600; cursor: pointer; font-size: 12px;
  color: var(--ink-soft) !important;
  transition: all 0.15s; font-family: 'DM Sans', sans-serif;
  display: inline-flex; align-items: center;
}
.tab-btn:hover  { border-color: var(--primary); color: var(--primary) !important; background: var(--paper); }
.tab-btn.active { background: var(--primary) !important; color: #fff !important; border-color: var(--primary) !important; }

.chart-footer { margin-top: 14px; padding-top: 11px; border-top: 1px solid var(--paper-2); display: flex; align-items: center; justify-content: space-between; }
.chart-n      { font-size: 11px; color: var(--ink-mute); font-family: 'DM Mono', monospace; }

/* ================================================================
   PAGE FOOTER + PICKER OVERLAY
   ================================================================ */
.footer { display: flex; justify-content: space-between; align-items: center; margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--border); }
.overlay { position: fixed; inset: 0; display: none; align-items: flex-end; justify-content: center; background: rgba(0,0,0,0.4); z-index: 9999; }
.overlay.active { display: flex; }
.sheet { width: 100%; max-width: 760px; background: var(--surface); border-top-left-radius: var(--radius); border-top-right-radius: var(--radius); box-shadow: 0 -8px 32px rgba(0,0,0,0.15); display: flex; flex-direction: column; max-height: 82vh; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 16px; border-bottom: 1px solid var(--border); }
.drag { width: 32px; height: 3px; background: var(--paper-3); border-radius: 2px; }
.sheet-title { font-weight: 700; font-size: 14px; }
.x { border: 1px solid var(--border); background: var(--surface); border-radius: 6px; height: 28px; padding: 0 8px; cursor: pointer; font-size: 13px; }
.sheet-body { padding: 12px 16px; overflow-y: auto; flex: 1; }
.picker-list { display: flex; flex-direction: column; gap: 8px; }
.picker-item { display: flex; gap: 10px; align-items: flex-start; padding: 4px 2px; }
.picker-text { line-height: 1.35; font-size: 13px; }
.sheet-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 10px 16px; border-top: 1px solid var(--border); background: var(--surface); position: sticky; bottom: 0; }

/* Picker search */
#pickerSearch {
  height: 38px; padding: 0 12px; border: 1px solid var(--border);
  width: 100%; border-radius: var(--radius-sm); background: var(--surface);
  font-size: 13px; font-family: 'DM Sans', sans-serif; outline: none;
  transition: border-color 0.15s; margin-bottom: 10px; display: block;
}
#pickerSearch:focus { border-color: var(--primary); }

/* ================================================================
   RESPONSIVE
   ================================================================ */




/* ================================================================
   MOBILE CHIPS STRIP
   ================================================================ */
.mobile-chips-strip {
  display: flex; gap: 7px; overflow-x: auto;
  padding: 6px 14px 8px; scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.mobile-chips-strip::-webkit-scrollbar { display: none; }
.mobile-active-chip {
  display: inline-flex; align-items: center; gap: 5px;
  background: var(--primary); color: #fff;
  border: none; border-radius: 20px;
  font-size: 12px; font-weight: 600;
  padding: 4px 10px 4px 12px;
  white-space: nowrap; cursor: pointer;
  flex-shrink: 0; transition: opacity 0.15s;
}
.mobile-active-chip:hover { opacity: 0.85; }
.chip-x { font-size: 14px; line-height: 1; opacity: 0.75; }

/* Mobile filter count badge */
.mobile-filter-count {
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--accent); color: #fff;
  font-size: 10px; font-weight: 700;
  width: 18px; height: 18px; border-radius: 50%;
  flex-shrink: 0;
}
/* Mobile reset button */
.mobile-reset-btn {
  font-size: 12px; font-weight: 600; color: var(--ink-mute);
  background: transparent; border: none; cursor: pointer;
  padding: 0 4px; white-space: nowrap; flex-shrink: 0;
  text-decoration: underline; text-underline-offset: 2px;
}


/* ================================================================
   FLOATING SHARE BUTTON (FAB) — fixed bottom-right, all screens
   ================================================================ */
.fab-share-wrap {
  position: fixed;
  bottom: 24px; right: 24px;
  z-index: 400;
  display: flex; flex-direction: column; align-items: flex-end; gap: 8px;
}
.fab-share-btn {
  width: 44px; height: 44px;
  border-radius: 50%;
  background: var(--primary);
  border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  color: #fff;
  box-shadow: 0 4px 16px rgba(0,0,0,0.22);
  transition: transform 0.2s, box-shadow 0.2s, background 0.15s;
}
.fab-share-btn:hover    { transform: scale(1.08); box-shadow: 0 6px 20px rgba(0,0,0,0.28); }
.fab-share-btn.active   { background: var(--ink); transform: rotate(45deg); }
.fab-share-panel {
  display: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 32px rgba(0,0,0,0.18);
  min-width: 230px;
  overflow: hidden;
  animation: fabDropIn 0.18s ease;
}
@keyframes fabDropIn {
  from { opacity: 0; transform: translateY(10px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
.fab-share-panel.open { display: block; }
.fab-panel-title {
  font-size: 11px; font-weight: 700; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--ink-mute);
  padding: 12px 16px 8px;
}
.fab-panel-item {
  display: flex; align-items: center; gap: 10px;
  width: 100%; padding: 10px 16px;
  border: none; background: transparent;
  text-align: left; cursor: pointer; color: inherit;
  text-decoration: none; transition: background 0.12s;
}
.fab-panel-item:hover { background: var(--paper-2); }
.fab-item-icon {
  width: 32px; height: 32px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px;
}
.fab-item-body {
  display: flex; flex-direction: column; gap: 1px;
  font-size: 13.5px; font-weight: 500; color: var(--ink);
}
.fab-item-body span {
  font-size: 11px; font-weight: 400; color: var(--ink-mute);
}
.fab-panel-divider { height: 1px; background: var(--border); margin: 4px 0; }
.fab-panel-check   { cursor: default; }
.fab-panel-check input { cursor: pointer; }
.fab-overlay {
  display: none;
  position: fixed; inset: 0;
  z-index: 399;
}
.fab-overlay.open { display: block; }

/* On mobile: slightly smaller FAB, higher to clear browser chrome */
@media (max-width: 640px) {
  .fab-share-wrap { bottom: 80px; right: 16px; }
  .fab-share-btn  { width: 40px; height: 40px; }
}


/* ================================================================
   NAV VIEW TABS (Charts / Map) — always visible in site header
   ================================================================ */
.nav-view-tabs {
  display: flex; gap: 4px; align-items: center; margin-left: auto;
}
.nav-view-btn {
  height: 32px; padding: 0 14px;
  border: 1px solid rgba(255,255,255,0.18);
  background: transparent;
  color: rgba(255,255,255,0.65);
  border-radius: var(--radius-sm);
  font-size: 13px; font-weight: 600;
  cursor: pointer; transition: all 0.15s;
  font-family: 'DM Sans', sans-serif;
}
.nav-view-btn:hover  { background: rgba(255,255,255,0.1); color: #fff; }
.nav-view-btn.active { background: rgba(255,255,255,0.15); color: #fff; border-color: rgba(255,255,255,0.35); }

/* On mobile: slightly more compact */
@media (max-width: 640px) {
  .nav-view-tabs { margin-left: auto; gap: 4px; }
  .nav-view-btn  { height: 28px; padding: 0 11px; font-size: 12px; }
}

@media (max-width: 1200px) {
  .dash-grid-left { grid-template-columns: 270px 1fr; gap: 22px; padding: 0 20px; }
  .header-inner   { padding: 0 20px; }
  .site-header-inner, .site-header .wrap { padding: 11px 20px; }
}

@media (max-width: 960px) {
  .dash-grid-left { grid-template-columns: 1fr; padding: 0 16px; }
  .left-rail { position: static; max-height: none; margin-bottom: 18px; }
  .charts { grid-template-columns: repeat(2, 1fr); }
  /* On tablet, keep masonry 2-col but wide cards work normally */
}

@media (max-width: 640px) {

  /* ═══════════════════════════════════════════════
     SITE HEADER
  ═══════════════════════════════════════════════ */
  .site-header-inner, .site-header .wrap { padding: 10px 14px; }
  /* Hide desktop nav links; show hamburger */
  .nav {
    display: none; flex-direction: column;
    position: fixed; top: 56px; left: 0; right: 0;
    background: var(--ink); padding: 8px 14px 16px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    gap: 2px; z-index: 199;
  }
  .nav.open  { display: flex; }
  .hamburger { display: flex; }
  /* header-right is empty on mobile, no hide needed */

  /* ═══════════════════════════════════════════════
     HERO BANNER
  ═══════════════════════════════════════════════ */
  .hero-banner { padding: 0 14px; min-height: 52px; }
  .hero-number { font-size: 24px; }
  .hero-text   { font-size: 12px; }
  .hero-right  { display: none; }

  /* ═══════════════════════════════════════════════
     DESCRIPTOR HEADER (title + subtitle, no buttons)
  ═══════════════════════════════════════════════ */
  .header-inner { padding: 0 14px; flex-direction: column; gap: 10px; }
  #siteTitle    { font-size: 18px; }
  #siteSubtitle { font-size: 11px; }

  /* ═══════════════════════════════════════════════
     STICKY FILTER BAR
  ═══════════════════════════════════════════════ */
  .mobile-filter-bar {
    display: flex !important;
    flex-direction: column;
    position: sticky; top: var(--site-header-h, 58px); z-index: 190;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
  }
  .mobile-filter-row {
    display: flex; align-items: center; gap: 8px;
    padding: 8px 14px;
  }
  .mobile-filter-btn {
    display: inline-flex !important;
    align-items: center; gap: 6px; flex-shrink: 0;
    font-size: 12px; font-weight: 600; color: var(--ink);
    background: var(--paper-2); border: 1px solid var(--border);
    border-radius: var(--radius-sm); padding: 6px 11px;
    cursor: pointer; white-space: nowrap;
  }
  .mobile-filter-btn svg { width: 13px; height: 13px; }
  /* Active chip strip */
  .mobile-chips-strip {
    display: none; /* shown by JS when chips exist */
    gap: 7px; overflow-x: auto; padding: 0 14px 8px;
    scrollbar-width: none; -webkit-overflow-scrolling: touch;
  }
  .mobile-chips-strip::-webkit-scrollbar { display: none; }

  /* ═══════════════════════════════════════════════
     MAIN LAYOUT — single column
  ═══════════════════════════════════════════════ */
  .main-pad         { padding-top: 0; padding-bottom: 40px; }
  .dash-grid-left   { grid-template-columns: 1fr; padding: 0; gap: 0; }

  /* ═══════════════════════════════════════════════
     LEFT RAIL — main filter drawer (not map rail)
  ═══════════════════════════════════════════════ */
  #leftRail {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: 88vw; max-width: 340px;
    z-index: 250;
    border-radius: 0 16px 16px 0;
    border: none;
    box-shadow: 4px 0 32px rgba(0,0,0,0.22);
    overflow-y: auto; -webkit-overflow-scrolling: touch;
    transform: translateX(-110%);
    transition: transform 0.28s cubic-bezier(0.4,0,0.2,1);
    display: block !important;
  }
  #leftRail.mobile-open { transform: translateX(0); }

  /* Map rail — stays static, stacks above map on mobile */
  .map-rail {
    position: static !important;
    transform: none !important;
    width: 100% !important;
    max-width: none !important;
    max-height: none !important;
    border-radius: 0 !important;
    border: none !important;
    border-bottom: 1px solid var(--border) !important;
    box-shadow: none !important;
    overflow-y: visible !important;
  }

  /* ═══════════════════════════════════════════════
     CHARTS GRID
  ═══════════════════════════════════════════════ */
  .charts          { grid-template-columns: 1fr; gap: 12px; padding: 14px; }
  .chart-card--wide { grid-column: span 1; }
  .chart-card      { padding: 14px 14px 12px; }
  .chart-story-title { font-size: 15px; }
  .chart-plain-summary { font-size: 12px; }
  /* Chart action buttons: move below chart */
  .chart-actions {
    position: static; display: flex; gap: 5px;
    margin-top: 10px; padding-top: 10px;
    border-top: 1px solid var(--border);
    flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none;
  }
  .chart-actions::-webkit-scrollbar { display: none; }
  .icon-btn { font-size: 11px; padding: 5px 10px; height: 28px; }
  /* Tab bar */
  .tab-bar { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
  .tab-bar::-webkit-scrollbar { display: none; }
  .tab-btn { flex-shrink: 0; font-size: 11.5px; padding: 5px 11px; }

  /* ═══════════════════════════════════════════════
     AI INSIGHTS CARD — collapsed until tapped
  ═══════════════════════════════════════════════ */
  .insights-card    { border-radius: 0; margin: 0 0 12px; }
  .insights-header  { padding: 12px 14px; gap: 8px; cursor: pointer; }
  .insights-actions { gap: 6px; }
  .btn-generate, #generateInsights { font-size: 12px; padding: 7px 14px; }
  .quota-badge      { font-size: 10px; }
  .btn-copy         { font-size: 11px; padding: 6px 10px; }
  /* Collapsed state */
  .insight-tabs  { display: none; }
  .insights-body { display: none; }
  .insights-card.mobile-expanded .insight-tabs { display: flex; }
  .insights-card.mobile-expanded .insights-body { display: block; }
  .insights-header::after {
    content: '▾ expand'; font-size: 10px;
    color: rgba(255,255,255,0.35);
    margin-left: auto; white-space: nowrap; align-self: center;
  }
  .insights-card.mobile-expanded .insights-header::after { content: '▴ collapse'; }
  .insight-tab    { font-size: 10px; padding: 10px 14px; }
  .insights-body  { padding: 14px; }

  /* ═══════════════════════════════════════════════
     FILTERS INSIDE RAIL
  ═══════════════════════════════════════════════ */
  .pill-group  { gap: 4px; flex-wrap: wrap; }
  .filter-pill { font-size: 11px; padding: 3px 9px; }
  .sidebar-kpi { padding: 10px 6px 8px; }
  .kpi-val     { font-size: 20px; }
  .kpi-label   { font-size: 9px; }

  /* ═══════════════════════════════════════════════
     MISC
  ═══════════════════════════════════════════════ */
  select { font-size: 16px; } /* prevent iOS zoom */
  .wrap  { padding: 0 14px; }
}

/* Mobile filter bar hidden on desktop */
.mobile-filter-bar { display: none; }
.mobile-filter-btn { display: none; }

/* Filter drawer overlay (created by JS) */
#mobileFilterOverlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 249;
}

@media print {
  .site-header, .hero-banner, .header, .left-rail, .insights-card { display: none !important; }
  .dash-grid-left { display: block; padding: 0; }
  .charts { grid-template-columns: 1fr; }
  .chart-card--wide { grid-column: span 1; }
}

/* ── Charts/Map view switcher ───────────────────────────────── */
.view-sw {
  background: var(--paper-2) !important;
  color: var(--ink-soft) !important;
  border-color: var(--border) !important;
}
.view-sw.active {
  background: var(--primary) !important;
  color: #fff !important;
  border-color: var(--primary) !important;
}

/* ── Map tab layout ─────────────────────────────────────────── */
#mapTab .dash-grid-left { display:flex; gap:24px; padding:24px var(--gap); max-width:1400px; margin:0 auto; }
#mapTab .left-rail { width:280px; flex-shrink:0; }
#mapTab .right-rail { flex:1; min-width:0; }

@media (max-width: 640px) {
  #mapTab .dash-grid-left { flex-direction:column; gap:0; padding:0; }
  #mapTab .left-rail  { width:100%; border-radius:0; border:none; border-bottom:1px solid var(--border); }
  #mapTab .right-rail { width:100%; padding:14px; box-sizing:border-box; min-height:320px; }
  #mapSvgWrap         { width:100% !important; max-width:100% !important; }
  #mapSvgWrap svg     { width:100% !important; height:auto !important; }
}
#mapTab .filter-select { width:100%; height:36px; min-height:unset; max-height:unset; }
#mapSvgWrap svg path { transition: fill 0.12s; }

/* ── Selected question tags (replaces raw <select>) ─────────── */
.selected-q-tags {
  display: flex;
  flex-direction: column;
  gap: 5px;
  max-height: 200px;
  overflow-y: auto;
  padding: 2px 0;
  min-height: 32px;
}
.no-qs-hint {
  font-size: 12px;
  color: var(--ink-mute);
  font-style: italic;
  padding: 6px 2px;
}
.q-tag {
  display: flex;
  align-items: flex-start;
  gap: 7px;
  padding: 7px 10px;
  background: var(--paper-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 12px;
  line-height: 1.4;
  cursor: default;
}
.q-tag-num {
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  background: var(--primary);
  color: #fff;
  border-radius: 50%;
  font-size: 10px;
  font-family: 'DM Mono', monospace;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 1px;
}
.q-tag-text {
  color: var(--ink-soft);
  flex: 1;
}

/* ── Theme filter bar ───────────────────────────────────────── */
#themeBar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 14px 0 18px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
}

.theme-pill {
  padding: 6px 16px;
  border-radius: 20px;
  border: 1.5px solid var(--border);
  background: var(--paper);
  color: var(--ink-soft);
  font-family: 'DM Sans', sans-serif;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  white-space: nowrap;
}
.theme-pill:hover {
  border-color: var(--primary);
  color: var(--primary);
}
.theme-pill.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

/* ── Picker group headers ───────────────────────────────────── */
.picker-group-hdr {
  padding: 10px 4px 5px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-mute);
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
  margin-top: 6px;
}
.picker-group-hdr:first-child {
  margin-top: 0;
}

/* ── Plain language summary ─────────────────────────────────── */
.chart-plain-summary {
  font-size: 13.5px;
  line-height: 1.6;
  color: var(--ink-soft);
  margin: 4px 0 14px;
  font-family: 'DM Sans', sans-serif;
}

/* ── Significance flags ─────────────────────────────────────── */
.sig-wrap {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}
.sig-hdr {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-mute);
  margin-bottom: 8px;
}
.sig-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.sig-none {
  font-size: 12px;
  color: var(--ink-mute);
  font-style: italic;
}
.sig-flag {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  padding: 6px 10px;
  border-radius: 8px;
  border-left: 3px solid transparent;
  background: var(--paper-2);
}
.sig-flag--above { border-left-color: #16a34a; }
.sig-flag--below { border-left-color: #dc2626; }
.sig-group {
  font-weight: 700;
  color: var(--ink);
}
.sig-answer {
  color: var(--ink-soft);
}
.sig-delta {
  font-weight: 700;
  font-family: 'DM Mono', monospace;
}
.sig-flag--above .sig-delta { color: #16a34a; }
.sig-flag--below .sig-delta { color: #dc2626; }
.sig-context {
  color: var(--ink-mute);
  font-size: 11px;
}

/* ── Crosstab ────────────────────────────────────────────────── */
.crosstab-wrap {
  padding-top: 4px;
}
/* ── Crosstab table (CSS bars, no canvas) ─────────────────── */
.xtab-container {
  margin-top: 8px;
}

.xtab-legend {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 14px;
  font-size: 11.5px;
  color: var(--ink-soft);
  font-family: 'DM Sans', sans-serif;
}
.xtab-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.xtab-dot--a { background: rgba(26,58,107,0.85); }
.xtab-dot--b { background: rgba(212,168,67,0.85); }
.xtab-legend-label { margin-right: 12px; }

.xtab-table {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.xtab-row {
  display: grid;
  grid-template-columns: minmax(100px, 30%) 1fr;
  gap: 10px;
  align-items: center;
  padding: 7px 0;
  border-bottom: 1px solid rgba(13,17,23,0.05);
}
.xtab-row:last-child { border-bottom: none; }

.xtab-label {
  font-size: 12px;
  color: var(--ink-mid, #3d4757);
  font-family: 'DM Sans', sans-serif;
  line-height: 1.35;
  word-break: break-word;
}

.xtab-bars {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.xtab-bar-row {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 14px;
}

/* Track: fluid up to a sensible cap, never overflows */
.xtab-bar {
  flex: 1;
  min-width: 0;
  max-width: min(260px, 70%);
  height: 100%;
  position: relative;
  background: rgba(13,17,23,0.06);
  border-radius: 2px;
}

@media (max-width: 480px) {
  .xtab-row {
    grid-template-columns: minmax(80px, 35%) 1fr;
    gap: 6px;
  }
  .xtab-label { font-size: 11px; }
  .xtab-bar-row { height: 12px; }
  .xtab-pct { font-size: 10px; width: 26px; }
}

/* The fill is the actual coloured bar — always 100% of track */
.xtab-bar-fill {
  position: absolute;
  inset: 0;
  border-radius: 2px;
  transition: width 0.3s ease;
}
.xtab-bar--a .xtab-bar-fill { background: rgba(26,58,107,0.82); }
.xtab-bar--b .xtab-bar-fill { background: rgba(212,168,67,0.82); }

.xtab-pct {
  font-size: 11px;
  font-family: 'DM Mono', monospace;
  color: var(--ink-soft, #7c8899);
  width: 32px;
  text-align: right;
  flex-shrink: 0;
}

/* Hover highlight on rows */
.xtab-row:hover { background: rgba(13,17,23,0.025); border-radius: 4px; }
.xtab-row:hover .xtab-label { color: var(--ink-dark, #0d1117); }
.crosstab-controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 16px;
}
.crosstab-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.crosstab-lbl {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--ink-mute);
  border-left: 3px solid;
  padding-left: 7px;
}
.crosstab-sel {
  font-size: 12px;
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--paper-2);
  color: var(--ink);
  font-family: 'DM Sans', sans-serif;
  cursor: pointer;
}
.crosstab-meta {
  margin-top: 10px;
  font-size: 12px;
  color: var(--ink-mute);
}
