/* D1 Canvass — mobile-first canvassing app
   Nexus palette, teal accent, Satoshi type
*/
:root {
  --bg: #F7F6F2;
  --surface: #FBFBF9;
  --surface-alt: #FBFBF9;
  --border: #D4D1CA;
  --border-strong: #BAB9B4;
  --text: #28251D;
  --text-muted: #7A7974;
  --text-faint: #BAB9B4;
  --primary: #01696F;
  --primary-hover: #0C4E54;
  --primary-tint: #E6F0F1;
  --error: #A12C7B;
  --warning: #964219;
  --success: #437A22;
  --success-tint: #E8F1E0;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.04), 0 1px 3px rgba(0,0,0,0.08);
  --shadow: 0 4px 12px rgba(0,0,0,0.08), 0 2px 4px rgba(0,0,0,0.04);
  --shadow-lg: 0 20px 40px rgba(0,0,0,0.15), 0 8px 16px rgba(0,0,0,0.08);
  --radius: 10px;
  --radius-sm: 6px;
  --radius-lg: 16px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; overflow: hidden; overscroll-behavior: none; }
body {
  font-family: 'Satoshi', -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

.hidden { display: none !important; }

/* ---------- GATE ---------- */
.gate {
  position: fixed; inset: 0;
  background: linear-gradient(135deg, #01696F, #0C4E54);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  z-index: 1000;
}
.gate-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 32px 28px;
  width: 100%; max-width: 380px;
  text-align: center;
  color: var(--text);
  box-shadow: var(--shadow-lg);
}
.gate-card svg { color: var(--primary); margin-bottom: 12px; }
.gate-card h1 { font-size: 22px; margin: 0 0 4px; font-weight: 700; letter-spacing: -0.01em; }
.gate-sub { font-size: 13px; color: var(--text-muted); margin: 0 0 24px; }
.gate-card input {
  width: 100%; padding: 12px 14px; margin-bottom: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: inherit; font-size: 15px;
  background: white;
}
.gate-card input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(1,105,111,0.15);
}
.gate-card button {
  width: 100%; padding: 12px;
  background: var(--primary); color: white;
  border: none; border-radius: var(--radius);
  font-family: inherit; font-size: 15px; font-weight: 600;
  cursor: pointer; margin-top: 6px;
  transition: background 120ms;
}
.gate-card button:hover { background: var(--primary-hover); }
.gate-error { color: var(--error); font-size: 13px; margin-top: 10px; min-height: 18px; }

/* ---------- APP ---------- */
.app { position: fixed; inset: 0; display: flex; flex-direction: column; }
.topbar {
  padding: calc(var(--safe-top) + 8px) 8px 8px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 8px;
  z-index: 100;
}
.topbar-title { flex: 1; text-align: center; overflow: hidden; }
.topbar-turf { font-weight: 700; font-size: 15px; letter-spacing: -0.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-stats { font-size: 12px; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.icon-btn {
  background: none; border: none; padding: 10px;
  color: var(--text); cursor: pointer;
  border-radius: var(--radius-sm);
  position: relative;
  min-width: 44px; min-height: 44px;
  display: flex; align-items: center; justify-content: center;
}
.icon-btn:hover, .icon-btn:active { background: var(--border); }
.filter-badge {
  position: absolute; top: 6px; right: 6px;
  background: var(--primary); color: white;
  font-size: 10px; font-weight: 700;
  min-width: 16px; height: 16px; padding: 0 4px;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
}

/* Map */
/* Map container isolates its stacking context so Leaflet's internal z-indexes (up to 700) can't escape and cover UI overlays. */
#map {
  flex: 1;
  background: var(--bg);
  position: relative;
  z-index: 0;
  isolation: isolate;
  min-height: 0; /* required inside flex container so Leaflet gets correct height */
}
.leaflet-container {
  font-family: inherit;
  width: 100%;
  height: 100%;
  touch-action: none; /* Leaflet handles pan/pinch itself */
}

/* View toggle - positioned above home indicator with generous clearance */
.view-toggle {
  position: fixed; bottom: calc(var(--safe-bottom) + 24px);
  left: 50%; transform: translateX(-50%);
  background: var(--surface);
  border-radius: 100px;
  padding: 4px;
  display: flex;
  box-shadow: var(--shadow-lg);
  z-index: 50;
  border: 1px solid var(--border);
}
.view-btn {
  background: none; border: none; padding: 8px 20px;
  border-radius: 100px;
  font-family: inherit; font-size: 13px; font-weight: 600;
  color: var(--text-muted); cursor: pointer;
  min-height: 36px;
}
.view-btn.active { background: var(--primary); color: white; }

/* List view */
.list-view {
  flex: 1; overflow-y: auto;
  background: var(--bg);
  padding: 12px 12px calc(var(--safe-bottom) + 80px);
}
.list-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 68px;
}
.list-item:active { background: var(--border); }
.list-item .swatch { width: 4px; height: 40px; border-radius: 2px; flex-shrink: 0; }
.list-item .list-body { flex: 1; min-width: 0; }
.list-item .list-addr { font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-item .list-meta { font-size: 12px; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-item .list-tags { font-size: 11px; margin-top: 2px; display: flex; gap: 4px; flex-wrap: wrap; }
.list-status {
  font-size: 10px; font-weight: 700;
  text-transform: uppercase;
  padding: 3px 6px;
  border-radius: 4px;
  letter-spacing: 0.03em;
  flex-shrink: 0;
}

/* Side menu (slide from left) */
.side-menu {
  position: fixed; inset: 0;
  z-index: 1500;
  pointer-events: none;
}
.side-menu.open { pointer-events: auto; }
.side-scrim {
  position: absolute; inset: 0;
  background: rgba(0,0,0,0.4);
  opacity: 0;
  transition: opacity 200ms;
}
.side-menu.open .side-scrim { opacity: 1; }
.side-menu-inner {
  position: absolute; top: 0; bottom: 0; left: 0;
  width: 300px; max-width: 85vw;
  background: var(--surface);
  overflow-y: auto;
  transform: translateX(-100%);
  transition: transform 240ms cubic-bezier(0.32, 0.72, 0, 1);
  padding: calc(var(--safe-top) + 12px) 0 calc(var(--safe-bottom) + 20px);
  box-shadow: var(--shadow-lg);
  z-index: 2;
}
.side-menu.open .side-menu-inner { transform: translateX(0); }
.side-header {
  padding: 8px 20px 16px;
  display: flex; justify-content: space-between; align-items: center;
  border-bottom: 1px solid var(--border);
}
.side-name { font-weight: 700; font-size: 16px; }
.side-sub { font-size: 12px; color: var(--text-muted); }
.side-menu h3 { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-muted); margin: 20px 20px 8px; font-weight: 600; }
.turf-list { padding: 0 12px; }
.turf-item {
  display: flex; align-items: center;
  padding: 10px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
  min-height: 44px;
}
.turf-item:active { background: var(--border); }
.turf-item.active { background: var(--primary-tint); font-weight: 600; }
.turf-swatch { width: 10px; height: 10px; border-radius: 3px; margin-right: 10px; flex-shrink: 0; }
.turf-label { flex: 1; }
.turf-count { font-size: 11px; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.menu-action {
  display: flex; align-items: center; justify-content: space-between;
  width: calc(100% - 24px); margin: 4px 12px;
  padding: 12px 14px;
  background: white;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: inherit; font-size: 14px; font-weight: 500;
  color: var(--text);
  cursor: pointer;
  text-align: left;
  min-height: 44px;
}
.menu-action:active { background: var(--border); }
.menu-action.secondary { color: var(--text-muted); background: transparent; border-color: transparent; }
.pill {
  background: var(--primary); color: white;
  font-size: 11px; font-weight: 700;
  padding: 2px 8px; border-radius: 100px;
  font-variant-numeric: tabular-nums;
}
.side-footer {
  padding: 20px; font-size: 12px; color: var(--text-muted);
  border-top: 1px solid var(--border);
  margin-top: 20px;
}
.side-footer-sub { margin-top: 4px; font-size: 11px; }

/* Bottom sheet */
.sheet {
  position: fixed; inset: 0;
  z-index: 2000;
  pointer-events: none;
  background: rgba(0,0,0,0.5);
  opacity: 0;
  transition: opacity 200ms;
}
.sheet.open { pointer-events: auto; opacity: 1; }
.sheet-inner {
  position: absolute; bottom: 0; left: 0; right: 0;
  background: var(--surface);
  border-top-left-radius: var(--radius-lg);
  border-top-right-radius: var(--radius-lg);
  padding: 8px 20px calc(var(--safe-bottom) + 20px);
  max-height: 85vh;
  overflow-y: auto;
  transform: translateY(100%);
  transition: transform 240ms cubic-bezier(0.32, 0.72, 0, 1);
  z-index: 2001;
  -webkit-overflow-scrolling: touch;
}
.sheet.open .sheet-inner { transform: translateY(0); }
.sheet-handle {
  width: 40px; height: 4px;
  background: var(--border-strong);
  border-radius: 2px;
  margin: 8px auto 12px;
}
.sheet h2 { margin: 4px 0 12px; font-size: 18px; font-weight: 700; letter-spacing: -0.01em; }
.sheet-body { font-size: 14px; color: var(--text-muted); margin: 0 0 16px; }

/* Door detail */
.door-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.door-header h2 { margin-top: 0; }
.door-meta { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.section { margin-top: 20px; }
.section-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-muted); margin-bottom: 8px; font-weight: 600; }
.chip-row { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center;
  padding: 8px 12px;
  background: white;
  border: 1px solid var(--border);
  border-radius: 100px;
  font-size: 13px; font-weight: 500;
  cursor: pointer;
  min-height: 36px;
  transition: all 120ms;
  user-select: none;
}
.chip:active { transform: scale(0.97); }
.chip.selected {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}
.chip.selected-alt {
  background: var(--warning);
  color: white;
  border-color: var(--warning);
}
.chip-dot { width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }
textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: inherit; font-size: 14px;
  background: white;
  resize: vertical;
  min-height: 44px;
}
textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(1,105,111,0.15); }

/* Voter card */
.voter-card {
  background: white;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 8px;
}
.voter-card.new { background: #FFF9E5; border-color: #F0DFA0; }
.voter-header {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}
.voter-name { font-weight: 600; font-size: 14px; }
.voter-name .badge {
  display: inline-block; margin-left: 4px;
  padding: 1px 6px; font-size: 10px; font-weight: 700;
  border-radius: 4px; letter-spacing: 0.02em;
  vertical-align: 1px;
}
.badge.rep { background: #F3D8CE; color: #6D2A19; }
.badge.dem { background: #C5E3E6; color: #0E3538; }
.badge.npa { background: #E3E2DE; color: #56554F; }
.badge.new { background: #FBEACC; color: #7C5807; }
.voter-meta { font-size: 12px; color: var(--text-muted); }
.voter-actions {
  display: flex; gap: 6px; margin-top: 4px;
  flex-wrap: wrap;
}
.voter-actions .tag-btn {
  padding: 6px 10px; font-size: 12px;
  background: white; border: 1px solid var(--border);
  border-radius: 100px;
  cursor: pointer;
  font-weight: 500;
  min-height: 32px;
  transition: all 120ms;
}
.voter-actions .tag-btn.on {
  background: var(--primary); color: white; border-color: var(--primary);
}
.voter-notes {
  width: 100%; margin-top: 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font-size: 13px;
  font-family: inherit;
  resize: vertical;
  min-height: 36px;
}
.voter-notes:focus { outline: none; border-color: var(--primary); }
.call-link {
  color: var(--primary);
  text-decoration: none;
  font-weight: 500;
}
.call-link:hover { text-decoration: underline; }

/* Filter chips */
.filter-section { margin-bottom: 16px; }
.filter-label { font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 8px; font-weight: 600; }
.filter-actions {
  display: flex; gap: 8px; margin-top: 20px; padding-top: 16px;
  border-top: 1px solid var(--border);
}
.btn {
  flex: 1; padding: 12px;
  border: none; border-radius: var(--radius);
  font-family: inherit; font-size: 14px; font-weight: 600;
  cursor: pointer;
  min-height: 44px;
}
.btn.primary { background: var(--primary); color: white; }
.btn.primary:hover { background: var(--primary-hover); }
.btn.primary:disabled { background: var(--text-faint); cursor: not-allowed; }
.btn.secondary { background: white; color: var(--text); border: 1px solid var(--border); }

/* GHL push */
.ghl-preview {
  background: white;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  max-height: 40vh; overflow-y: auto;
  font-size: 13px;
  margin-bottom: 12px;
}
.ghl-preview-item {
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}
.ghl-preview-item:last-child { border-bottom: none; }
.ghl-preview-name { font-weight: 600; }
.ghl-preview-tags {
  font-size: 11px; color: var(--text-muted); margin-top: 2px;
}
.ghl-progress {
  margin-top: 16px;
  padding: 12px 14px;
  background: var(--primary-tint);
  border-radius: var(--radius);
  font-size: 13px;
  color: var(--primary-hover);
}

/* Toast */
.toast {
  position: fixed;
  bottom: calc(var(--safe-bottom) + 80px);
  left: 50%; transform: translateX(-50%) translateY(100px);
  background: var(--text);
  color: white;
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  z-index: 1000;
  transition: transform 240ms cubic-bezier(0.32, 0.72, 0, 1);
  pointer-events: none;
  max-width: 90vw;
  text-align: center;
  box-shadow: var(--shadow-lg);
}
.toast.show { transform: translateX(-50%) translateY(0); }
.toast.error { background: var(--error); }
.toast.success { background: var(--success); }

/* Custom Leaflet marker */
.voter-marker {
  border-radius: 50%;
  border: 2px solid white;
  box-shadow: 0 1px 3px rgba(0,0,0,0.3);
  cursor: pointer;
}
.voter-marker.has-status { box-shadow: 0 0 0 3px var(--success), 0 1px 3px rgba(0,0,0,0.3); }
.voter-marker.has-supporter { box-shadow: 0 0 0 3px #FFC553, 0 1px 3px rgba(0,0,0,0.3); }

/* Responsive: wider screens */
@media (min-width: 768px) {
  .side-menu-inner { width: 320px; }
  .sheet-inner {
    left: 50%; right: auto;
    transform: translateX(-50%) translateY(100%);
    width: 480px;
    max-width: calc(100vw - 32px);
    border-radius: var(--radius-lg);
    bottom: 20px;
  }
  .sheet.open .sheet-inner { transform: translateX(-50%) translateY(0); }
}
