/* ============================================================
   Precinct Leader Finder — Stylesheet
   ============================================================ */

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

:root {
  --blue:    #003087;
  --blue-dk: #002070;
  --green:   #28a745;
  --amber:   #ffc107;
  --red:     #dc3545;
  --gray-bg: #f5f7fa;
  --border:  #dde3ea;
  --text:    #1a1a2e;
  --muted:   #64748b;
}

html, body {
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--gray-bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ---- Header ---- */
header {
  background: var(--blue);
  color: #fff;
  padding: 0.85rem 1.25rem;
  flex-shrink: 0;
  z-index: 1000;
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  max-width: 1400px;
  margin: 0 auto;
  width: 100%;
}

header h1 {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.header-stats {
  font-size: 0.78rem;
  color: rgba(255,255,255,0.75);
  white-space: nowrap;
}

/* ---- Main layout ---- */
main {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ---- Left panel ---- */
.panel {
  width: 380px;
  min-width: 300px;
  background: #fff;
  border-right: 1px solid var(--border);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  padding: 1.25rem;
  gap: 1.1rem;
  flex-shrink: 0;
}

/* ---- Search section ---- */
.search-section label {
  display: block;
  font-size: 0.875rem;
  font-weight: 600;
  margin-bottom: 0.45rem;
  color: var(--text);
}

.input-row {
  display: flex;
  gap: 0.45rem;
}

.input-row input[type="text"] {
  flex: 1;
  padding: 0.55rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.9rem;
  color: var(--text);
  background: #fff;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.input-row input[type="text"]:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(0,48,135,0.12);
}

.input-row button {
  padding: 0.55rem 1rem;
  background: var(--blue);
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s;
}

.input-row button:hover:not(:disabled) {
  background: var(--blue-dk);
}

.input-row button:disabled {
  background: #9baabf;
  cursor: not-allowed;
}

.hint {
  margin-top: 0.4rem;
  font-size: 0.775rem;
  color: var(--muted);
  line-height: 1.4;
}

/* ---- Loading ---- */
.loading {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  font-size: 0.875rem;
  color: var(--muted);
  padding: 0.25rem 0;
}

.spinner {
  width: 18px;
  height: 18px;
  border: 2.5px solid #d4dbe6;
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
  flex-shrink: 0;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Error ---- */
.error-box {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  background: #fff5f5;
  border: 1px solid #fecaca;
  border-radius: 8px;
  padding: 0.75rem 1rem;
  color: #b91c1c;
  font-size: 0.875rem;
  line-height: 1.45;
}

.error-box .icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  margin-top: 1px;
}

/* ---- Result box ---- */
.result-box {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.matched-address {
  font-size: 0.8rem;
  color: var(--muted);
  line-height: 1.4;
}

.matched-address .muted {
  font-weight: 600;
  margin-right: 0.2rem;
}

/* ---- Precinct card ---- */
.precinct-card {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #f0f4ff;
  border: 1px solid #c7d4f0;
  border-radius: 10px;
  padding: 0.9rem 1rem;
}

.precinct-label {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--blue);
  margin-bottom: 0.15rem;
}

.precinct-code {
  font-size: 2rem;
  font-weight: 800;
  color: var(--blue);
  line-height: 1;
}

.ld-label {
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 0.25rem;
}

/* Status badge */
.precinct-card-right {
  text-align: center;
  padding: 0.6rem 0.9rem;
  border-radius: 8px;
  min-width: 90px;
}

.badge-count {
  font-size: 2rem;
  font-weight: 800;
  line-height: 1;
}

.badge-of {
  font-size: 0.7rem;
  opacity: 0.75;
  margin: 0.15rem 0 0.2rem;
}

.badge-label {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* Status variants */
.status-full  { background: #d1fae5; color: #065f46; }
.status-needs { background: #fef3c7; color: #78350f; }
.status-empty { background: #fee2e2; color: #991b1b; }

/* ---- CTA box ---- */
.cta-box {
  background: #fffbeb;
  border: 1px solid #fde68a;
  border-left: 4px solid var(--amber);
  border-radius: 8px;
  padding: 1rem 1.1rem;
}

.cta-box h3 {
  font-size: 0.95rem;
  font-weight: 700;
  color: #92400e;
  margin-bottom: 0.5rem;
}

.cta-box p {
  font-size: 0.85rem;
  color: #555;
  line-height: 1.55;
  margin-bottom: 0.5rem;
}

.cta-btn {
  display: inline-block;
  margin-top: 0.35rem;
  padding: 0.6rem 1.1rem;
  background: var(--blue);
  color: #fff;
  text-decoration: none;
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 600;
  transition: background 0.15s;
}

.cta-btn:hover {
  background: var(--blue-dk);
}

.cta-btn-secondary {
  background: transparent;
  color: var(--blue);
  border: 1.5px solid var(--blue);
  margin-top: 0.5rem;
}

.cta-btn-secondary:hover {
  background: var(--blue);
  color: #fff;
}

/* ---- Full-staffed box ---- */
.full-box {
  background: #ecfdf5;
  border: 1px solid #a7f3d0;
  border-left: 4px solid var(--green);
  border-radius: 8px;
  padding: 1rem 1.1rem;
}

.full-box h3 {
  font-size: 0.95rem;
  font-weight: 700;
  color: #065f46;
  margin-bottom: 0.4rem;
}

.full-box p {
  font-size: 0.85rem;
  color: #555;
  line-height: 1.55;
}

/* ---- Mobile legend ---- */
.legend-mobile {
  margin-top: auto;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
  display: none;
}

.legend-mobile h4 {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--muted);
  margin-bottom: 0.4rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.legend-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.82rem;
  color: var(--text);
  margin-bottom: 0.25rem;
}

.swatch {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  flex-shrink: 0;
}

/* ---- Map ---- */
#map {
  flex: 1;
  z-index: 1;
}

/* ---- Leaflet legend (desktop) ---- */
.map-legend {
  background: rgba(255,255,255,0.95);
  padding: 0.55rem 0.75rem;
  border-radius: 7px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
  font-size: 0.78rem;
  line-height: 1.6;
}

.map-legend h4 {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.3rem;
}

.map-legend .row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.map-legend .dot {
  width: 13px;
  height: 13px;
  border-radius: 3px;
  flex-shrink: 0;
}

/* ---- Modal ---- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal-box {
  background: #fff;
  border-radius: 12px;
  padding: 1.5rem;
  max-width: 480px;
  width: 100%;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
  max-height: 90vh;
  overflow-y: auto;
  position: relative;
}

.modal-scroll-hint {
  text-align: center;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--blue);
  background: #eef2ff;
  border-radius: 6px;
  padding: 0.5rem 0.75rem;
  margin-bottom: 1rem;
  transition: opacity 0.3s;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 0.4rem;
}

.modal-header h2 {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.3;
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  color: var(--muted);
  flex-shrink: 0;
  padding: 0;
}

.modal-close:hover { color: var(--text); }

.modal-desc {
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 1rem;
  line-height: 1.4;
}

.modal-intro {
  margin-bottom: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.modal-intro p {
  font-size: 0.85rem;
  color: var(--text);
  line-height: 1.55;
}

.modal-privacy {
  font-style: italic;
  color: var(--muted) !important;
}

.field-hint {
  font-size: 0.775rem;
  color: var(--muted);
  margin-bottom: 0.3rem;
  line-height: 1.3;
}

.radio-group {
  display: flex;
  gap: 1.5rem;
  margin-top: 0.3rem;
}

.radio-label {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.875rem;
  font-weight: 400;
  cursor: pointer;
}

.modal-success {
  background: #ecfdf5;
  border: 1px solid #a7f3d0;
  border-radius: 8px;
  padding: 0.75rem 1rem;
  font-size: 0.875rem;
  color: #065f46;
  margin-bottom: 0.5rem;
}

.modal-form-error {
  background: #fff5f5;
  border: 1px solid #fecaca;
  border-radius: 8px;
  padding: 0.75rem 1rem;
  font-size: 0.875rem;
  color: #b91c1c;
  margin-bottom: 0.75rem;
}

/* ---- Form inside modal ---- */
.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.form-group {
  margin-bottom: 0.85rem;
}

.form-group label {
  display: block;
  font-size: 0.825rem;
  font-weight: 600;
  margin-bottom: 0.3rem;
  color: var(--text);
}

.required { color: var(--red); }
.optional  { color: var(--muted); font-weight: 400; }

.form-group input[type="text"],
.form-group input[type="email"],
.form-group input[type="tel"],
.form-group textarea {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.875rem;
  color: var(--text);
  background: #fff;
  font-family: inherit;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.form-group input:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(0,48,135,0.12);
}

.form-group textarea {
  resize: vertical;
  min-height: 70px;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.6rem;
  margin-top: 0.25rem;
}

.btn-primary {
  padding: 0.55rem 1.2rem;
  background: var(--blue);
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-primary:hover:not(:disabled) { background: var(--blue-dk); }
.btn-primary:disabled { background: #9baabf; cursor: not-allowed; }

.btn-secondary {
  padding: 0.55rem 1.2rem;
  background: #fff;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.btn-secondary:hover {
  background: var(--gray-bg);
  border-color: #bbc8d8;
}

/* ---- Utility ---- */
.hidden { display: none !important; }

/* ---- Responsive ---- */
@media (max-width: 680px) {
  main {
    flex-direction: column;
    overflow: visible;
  }

  .panel {
    width: 100%;
    min-width: unset;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  #map {
    height: 55vw;
    min-height: 240px;
    max-height: 380px;
  }

  .legend-mobile {
    display: block;
  }
}
