/* === UPP Canvassing App - Mobile First === */
:root {
  --primary: #2563EB;
  --primary-dark: #1D4ED8;
  --primary-light: #DBEAFE;
  --heat-1: #DC2626; /* ALP Die-hard */
  --heat-2: #F97316; /* ALP Leaning */
  --heat-3: #EAB308; /* Undecided */
  --heat-4: #60A5FA; /* UPP Leaning */
  --heat-5: #2563EB; /* UPP Die-hard */
  --bg: #F1F5F9;
  --surface: #FFFFFF;
  --text: #1E293B;
  --text-secondary: #64748B;
  --border: #E2E8F0;
  --danger: #DC2626;
  --success: #16A34A;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.1);
  --shadow-lg: 0 4px 12px rgba(0,0,0,0.15);
  --nav-height: 64px;
  --topbar-height: 56px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

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

.top-bar {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--topbar-height);
  padding: 0 16px;
  background: var(--primary);
  color: #fff;
  box-shadow: var(--shadow);
}
.top-bar-left { display: flex; align-items: center; gap: 10px; }
.top-bar-logo {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  object-fit: cover;
  background: rgba(255,255,255,0.2);
}
.page-title { font-size: 1.05rem; font-weight: 600; }
.top-bar-right { display: flex; align-items: center; gap: 8px; }
.user-name { font-size: 0.85rem; opacity: 0.9; display: none; }
.btn-icon {
  display: flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; border-radius: 50%;
  color: #fff; text-decoration: none; transition: background 0.2s;
}
.btn-icon:hover { background: rgba(255,255,255,0.2); }

.content {
  flex: 1;
  padding: 16px;
  padding-bottom: calc(var(--nav-height) + 16px);
  max-width: 960px;
  margin: 0 auto;
  width: 100%;
}

.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 100;
  display: flex;
  justify-content: space-around;
  height: var(--nav-height);
  background: var(--surface);
  border-top: 1px solid var(--border);
  box-shadow: 0 -2px 8px rgba(0,0,0,0.08);
  padding-bottom: env(safe-area-inset-bottom, 0);
}
.nav-item {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 2px;
  text-decoration: none; color: var(--text-secondary);
  font-size: 0.7rem; padding: 4px 8px;
  transition: color 0.2s;
  min-width: 56px;
}
.nav-item .material-icons { font-size: 24px; }
.nav-item.active { color: var(--primary); font-weight: 600; }
.nav-item:hover { color: var(--primary); }

/* === Login === */
.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, #1E3A5F 0%, #2563EB 100%);
}
.login-container {
  width: 100%;
  max-width: 380px;
  padding: 24px;
}
.login-logo {
  text-align: center;
  color: #fff;
  margin-bottom: 32px;
}
.login-logo-img {
  width: 100px;
  height: 100px;
  border-radius: 20px;
  object-fit: cover;
  margin-bottom: 12px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.3);
}
.login-logo h1 { font-size: 1.5rem; margin-bottom: 4px; }
.login-logo p { opacity: 0.7; font-size: 0.95rem; }
.login-form {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow-lg);
}

/* === Forms === */
.form-group { margin-bottom: 16px; }
.form-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
}
.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 10px 12px;
  font-size: 1rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  transition: border-color 0.2s;
  -webkit-appearance: none;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}
.form-group textarea { resize: vertical; min-height: 80px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* === Buttons === */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 20px;
  font-size: 0.95rem;
  font-weight: 600;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
  white-space: nowrap;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: var(--bg); color: var(--text); border: 1.5px solid var(--border); }
.btn-secondary:hover { background: var(--border); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #B91C1C; }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #15803D; }
.btn-small { padding: 6px 12px; font-size: 0.8rem; }
.btn-full { width: 100%; }
.btn .material-icons { font-size: 18px; }

/* === Cards === */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 12px;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.card-header h2 { font-size: 1rem; font-weight: 700; }
.card-header h3 { font-size: 0.95rem; font-weight: 600; }

/* === Alerts === */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
  font-size: 0.9rem;
}
.alert-error { background: #FEE2E2; color: #991B1B; }
.alert-success { background: #DCFCE7; color: #166534; }

/* === Heat Level Badge === */
.heat-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 700;
  color: #fff;
  white-space: nowrap;
}
.heat-1 { background: var(--heat-1); }
.heat-2 { background: var(--heat-2); }
.heat-3 { background: var(--heat-3); color: #1E293B; }
.heat-4 { background: var(--heat-4); }
.heat-5 { background: var(--heat-5); }

/* === Heat Selector === */
.heat-selector {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.heat-option {
  flex: 1;
  min-width: 56px;
  text-align: center;
}
.heat-option input { display: none; }
.heat-option label {
  display: block;
  padding: 8px 4px;
  border-radius: var(--radius-sm);
  font-size: 0.7rem;
  font-weight: 600;
  cursor: pointer;
  border: 2px solid transparent;
  transition: all 0.2s;
  color: #fff;
}
.heat-option:nth-child(1) label { background: var(--heat-1); }
.heat-option:nth-child(2) label { background: var(--heat-2); }
.heat-option:nth-child(3) label { background: var(--heat-3); color: #1E293B; }
.heat-option:nth-child(4) label { background: var(--heat-4); }
.heat-option:nth-child(5) label { background: var(--heat-5); }
.heat-option input:checked + label {
  border-color: var(--text);
  box-shadow: 0 0 0 2px var(--text);
  transform: scale(1.05);
}

/* === Voter List === */
.search-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  position: sticky;
  top: var(--topbar-height);
  z-index: 50;
  background: var(--bg);
  padding: 8px 0;
}
.search-bar input {
  flex: 1;
  padding: 10px 12px;
  font-size: 1rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
}
.search-bar input:focus { outline: none; border-color: var(--primary); }

.filter-bar {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.filter-chip {
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 600;
  border: 1.5px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
  color: var(--text);
}
.filter-chip.active { border-color: var(--primary); background: var(--primary-light); color: var(--primary); }
.filter-chip:hover { border-color: var(--primary); }

.voter-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 8px;
  text-decoration: none;
  color: var(--text);
  transition: box-shadow 0.2s;
  cursor: pointer;
}
.voter-card:hover { box-shadow: var(--shadow-lg); }
.voter-card .heat-dot {
  width: 12px; height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
}
.voter-card .voter-info { flex: 1; min-width: 0; }
.voter-card .voter-name { font-weight: 600; font-size: 0.95rem; }
.voter-card .voter-address {
  font-size: 0.8rem;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.voter-card .voter-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-top: 2px;
}
.voter-card .material-icons { font-size: 16px; color: var(--text-secondary); }

/* === Voter Detail === */
.voter-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}
.voter-header .back-btn {
  display: flex;
  align-items: center;
  color: var(--primary);
  text-decoration: none;
  font-size: 0.9rem;
}
.section-title {
  font-size: 0.85rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
  margin: 20px 0 8px;
}
.detail-grid {
  display: grid;
  gap: 8px;
}
.detail-item {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}
.detail-item .label { color: var(--text-secondary); }
.detail-item .value { font-weight: 500; text-align: right; }

/* === Map === */
.map-container {
  width: 100%;
  height: calc(100vh - var(--topbar-height) - var(--nav-height) - 32px);
  height: calc(100dvh - var(--topbar-height) - var(--nav-height) - 32px);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}
.map-container-small {
  width: 100%;
  height: 200px;
  border-radius: var(--radius-sm);
  margin-top: 8px;
}
.map-filter-overlay {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 1000;
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 8px;
  box-shadow: var(--shadow-lg);
}

/* === Dashboard === */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.stat-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  text-align: center;
}
.stat-number { font-size: 2rem; font-weight: 800; }
.stat-label { font-size: 0.8rem; color: var(--text-secondary); margin-top: 4px; }

.heat-bar {
  display: flex;
  height: 32px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  margin-bottom: 16px;
}
.heat-bar-segment {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
  color: #fff;
  min-width: 20px;
  transition: width 0.3s;
}

/* === Issues Chips === */
.issue-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.issue-chip {
  padding: 4px 10px;
  border-radius: 16px;
  font-size: 0.78rem;
  background: var(--primary-light);
  color: var(--primary-dark);
  font-weight: 500;
}
.issue-chip.removable { cursor: pointer; }
.issue-chip.removable::after { content: ' ✕'; }

/* === Checkbox grid for issues === */
.checkbox-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}
.checkbox-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  padding: 6px;
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.checkbox-item:hover { background: var(--bg); }
.checkbox-item input[type="checkbox"] {
  width: 18px; height: 18px; accent-color: var(--primary);
}

/* === Notes Timeline === */
.note-item {
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.note-item .note-meta {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-bottom: 4px;
}
.note-item .note-text { font-size: 0.9rem; line-height: 1.4; }

/* === Followup List === */
.followup-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.followup-item input[type="checkbox"] {
  margin-top: 3px;
  width: 18px; height: 18px;
  accent-color: var(--success);
}
.followup-item.completed .followup-text { text-decoration: line-through; opacity: 0.6; }
.followup-text { flex: 1; font-size: 0.9rem; }
.followup-due {
  font-size: 0.75rem;
  color: var(--text-secondary);
}
.followup-due.overdue { color: var(--danger); font-weight: 600; }

/* === Table (admin, import) === */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}
.data-table th {
  text-align: left;
  padding: 10px 8px;
  border-bottom: 2px solid var(--border);
  font-weight: 700;
  color: var(--text-secondary);
  font-size: 0.78rem;
  text-transform: uppercase;
}
.data-table td {
  padding: 10px 8px;
  border-bottom: 1px solid var(--border);
}
.data-table tr:hover td { background: var(--bg); }

/* === Floating Action Button === */
.fab {
  position: fixed;
  bottom: calc(var(--nav-height) + 16px);
  right: 16px;
  z-index: 90;
  width: 56px; height: 56px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  border: none;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.2s, background 0.2s;
  text-decoration: none;
}
.fab:hover { background: var(--primary-dark); transform: scale(1.05); }
.fab .material-icons { font-size: 28px; }

/* === Pagination === */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 16px 0;
}
.pagination a, .pagination span {
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  text-decoration: none;
  color: var(--text);
}
.pagination a { background: var(--surface); border: 1px solid var(--border); }
.pagination a:hover { border-color: var(--primary); }
.pagination .current { background: var(--primary); color: #fff; font-weight: 600; }

/* === Utilities === */
.text-center { text-align: center; }
.text-secondary { color: var(--text-secondary); }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
.flex { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.gap-1 { gap: 8px; }
.gap-2 { gap: 16px; }
.hidden { display: none !important; }

/* === Empty State === */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-secondary);
}
.empty-state .material-icons { font-size: 64px; opacity: 0.3; }
.empty-state h3 { margin: 12px 0 4px; font-size: 1.1rem; color: var(--text); }
.empty-state p { font-size: 0.9rem; }

/* === Loading spinner === */
.spinner {
  display: inline-block;
  width: 24px; height: 24px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* === Modal/Overlay === */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.5);
  z-index: 200;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.modal {
  background: var(--surface);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 24px;
  width: 100%;
  max-width: 500px;
  max-height: 80vh;
  overflow-y: auto;
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}
.modal-header h2 { font-size: 1.1rem; }
.modal-close {
  background: none; border: none; cursor: pointer;
  color: var(--text-secondary); font-size: 1.5rem;
}

/* === Dashboard Enhancements === */
.dash-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  margin-bottom: 12px;
}

.heat-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  margin-top: 8px;
}
.heat-legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  color: var(--text-secondary);
  white-space: nowrap;
}
.heat-legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.chart-details {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}
.detail-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.82rem;
  padding: 3px 0;
  color: var(--text-secondary);
}
.detail-row strong { color: var(--text); }
.detail-row-link {
  text-decoration: none;
  border-radius: 4px;
  padding: 4px 6px;
  margin: -1px -6px;
  transition: background 0.15s;
}
.detail-row-link:hover { background: var(--bg); }
.detail-row .dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.stat-card-accent {
  position: relative;
}
.stat-card-accent .stat-number {
  color: var(--primary);
}

.stat-card-link {
  text-decoration: none;
  color: var(--text);
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
}
.stat-card-link:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.active-filter-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.active-filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border: 1.5px solid;
  border-radius: 20px;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  background: var(--surface);
  transition: background 0.15s;
}
.active-filter-chip:hover {
  background: var(--bg);
}

.empty-mini {
  text-align: center;
  padding: 24px 12px;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

/* === Desktop Enhancements === */
@media (min-width: 768px) {
  .user-name { display: inline; }
  .content { padding: 24px; padding-bottom: 24px; }
  .bottom-nav {
    position: static;
    border-top: none;
    box-shadow: none;
    justify-content: flex-start;
    gap: 4px;
    padding: 0 16px;
    height: 48px;
    background: var(--primary-dark);
  }
  .nav-item {
    flex-direction: row;
    color: rgba(255,255,255,0.7);
    font-size: 0.85rem;
    padding: 8px 16px;
    border-radius: var(--radius-sm);
  }
  .nav-item .material-icons { font-size: 20px; }
  .nav-item.active { color: #fff; background: rgba(255,255,255,0.15); }
  .nav-item:hover { color: #fff; }
  .app-shell { flex-direction: column; }
  .app-shell .bottom-nav { order: -1; }
  .content { padding-bottom: 24px; }
  .modal { border-radius: var(--radius); align-self: center; }
  .stats-grid { grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); }
  .dash-row { grid-template-columns: 1fr 1fr; }
  .checkbox-grid { grid-template-columns: 1fr 1fr 1fr; }
  .form-row { grid-template-columns: 1fr 1fr 1fr; }
}
