/* Mapiia Lab design system — Corporate Futurism, dark-first.
   Ref: stitch_lab10_design_audit / DESIGN.md */
:root {
  color-scheme: dark;
  --bg: #121214;
  --surface: #1c1c1e;
  --surface-high: #26262a;
  --surface-highest: #32343f;
  --border: #2d2d30;
  --border-strong: #434656;
  --text-primary: #e1e1ef;
  --text-secondary: #9a9cad;
  --electric-blue: #0052ff;
  --electric-blue-light: #b7c4ff;
  --lime: #c3f400;
  --lime-dim: #8fb300;
  --cyan: #00f0ff;
  --amber: #f6f072;
  --error: #ff6b6b;
  --error-bg: rgba(255, 107, 107, 0.12);

  --font-display: "Lexend", system-ui, sans-serif;
  --font-body: "Inter", system-ui, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, monospace;

  --r-sm: 0.25rem;
  --r-md: 0.375rem;
  --r-lg: 0.625rem;
  --r-full: 9999px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text-primary);
}

body {
  display: flex;
  flex-direction: column;
}

.topbar {
  padding: 14px 16px 8px;
  background: linear-gradient(180deg, var(--surface) 0%, var(--bg) 100%);
  border-bottom: 1px solid var(--border);
}

.topbar-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 6px;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.15rem;
  letter-spacing: -0.02em;
}

.topbar-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.icon-btn {
  flex-shrink: 0;
  width: 34px;
  height: 34px;
  border-radius: var(--r-full);
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
}

.brand-mark {
  color: var(--text-primary);
}

.brand-country {
  font-family: var(--font-mono);
  font-weight: 500;
  font-size: 0.62rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--bg);
  background: var(--lime);
  padding: 3px 7px;
  border-radius: var(--r-full);
}

.subtitle {
  margin: 4px 0 0;
  font-size: 0.74rem;
  color: var(--text-secondary);
  font-family: var(--font-mono);
  letter-spacing: 0.01em;
}

.disclaimer {
  margin: 8px 14px 6px;
  padding: 8px 10px;
  border-radius: var(--r-md);
  background: rgba(246, 240, 114, 0.08);
  border: 1px solid rgba(246, 240, 114, 0.25);
  font-size: 0.72rem;
  color: var(--text-secondary);
  line-height: 1.4;
}

.disclaimer strong {
  color: var(--amber);
}

.controls {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 14px;
  flex-wrap: wrap;
}

.controls label {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.controls-row2 {
  justify-content: space-between;
}

#citySelect,
#barrioSelect {
  flex: 1;
  min-width: 140px;
  padding: 9px 10px;
  border-radius: var(--r-md);
  border: 1px solid var(--border);
  font-size: 0.88rem;
  font-family: var(--font-body);
  background: var(--surface);
  color: var(--text-primary);
}

#citySelect:focus,
#barrioSelect:focus {
  outline: none;
  border-color: var(--electric-blue-light);
  box-shadow: 0 0 0 2px rgba(183, 196, 255, 0.25);
}

.toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.82rem;
}

.toggle.hidden {
  display: none;
}

.toggle input {
  width: 16px;
  height: 16px;
  accent-color: var(--electric-blue-light);
}

.basemap-btn {
  padding: 8px 12px;
  border-radius: var(--r-md);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-primary);
  font-size: 0.82rem;
  white-space: nowrap;
}

.mmi-badge {
  font-size: 0.68rem;
  font-family: var(--font-mono);
  color: var(--text-secondary);
  white-space: nowrap;
}

.stats {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 6px;
  padding: 6px 14px 10px;
  overflow-x: auto;
}

.stat-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 4px;
  border-radius: var(--r-md);
  background: var(--surface);
  border: 1px solid var(--border);
  min-width: 64px;
}

.stat-value {
  font-weight: 600;
  font-size: 0.95rem;
  font-family: var(--font-mono);
  color: var(--electric-blue-light);
}

.stat-label {
  font-size: 0.6rem;
  color: var(--text-secondary);
  text-align: center;
  line-height: 1.2;
  margin-top: 2px;
}

#map {
  flex: 1;
  min-height: 0;
  position: relative;
}

.legend {
  position: absolute;
  left: 10px;
  bottom: 58px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: rgba(28, 28, 30, 0.9);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 10px 12px;
  font-size: 0.72rem;
  z-index: 5;
  pointer-events: none;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  max-width: 220px;
}

.legend.hidden {
  display: none;
}

.legend-title {
  display: block;
  font-family: var(--font-mono);
  font-weight: 500;
  font-size: 0.62rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.legend-section + .legend-section {
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

.legend-section.hidden {
  display: none;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  line-height: 1.5;
  color: var(--text-primary);
}

.legend-reports {
  display: flex;
  flex-direction: column;
  gap: 3px;
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px solid var(--border);
}

.swatch {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  display: inline-block;
  border: 1px solid rgba(255, 255, 255, 0.15);
}

.mmi-vertical {
  display: flex;
  gap: 8px;
  height: 230px;
  margin: 6px 0;
}

.mmi-gradient-v {
  width: 12px;
  height: 100%;
  border-radius: var(--r-full);
  border: 1px solid var(--border-strong);
  flex-shrink: 0;
}

.mmi-ticks-v {
  position: relative;
  flex: 1;
  height: 100%;
}

.mmi-tick-v {
  position: absolute;
  left: 0;
  right: 0;
  transform: translateY(-50%);
  line-height: 1.15;
}

.mmi-tick-value {
  display: block;
  font-weight: 500;
  font-family: var(--font-mono);
  font-size: 0.62rem;
  color: var(--text-primary);
}

.mmi-tick-label {
  display: block;
  font-size: 0.58rem;
  color: var(--text-secondary);
}

.legend-source {
  margin: 4px 0 0;
  font-family: var(--font-mono);
  font-size: 0.58rem;
  color: var(--text-secondary);
  line-height: 1.4;
}

.view-toggle-btn {
  position: absolute;
  left: 10px;
  top: 10px;
  z-index: 5;
  background: var(--surface);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 8px 10px;
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 0.78rem;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
}

.view-toggle-btn:active {
  transform: scale(0.97);
}

.legend-toggle-btn {
  position: absolute;
  left: 10px;
  bottom: 12px;
  z-index: 6;
  width: 38px;
  height: 38px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-full);
  font-size: 1.05rem;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
}

.legend-toggle-btn:active {
  transform: scale(0.97);
}

.epicenter-marker {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: radial-gradient(circle, var(--cyan) 0%, var(--cyan) 40%, rgba(0, 240, 255, 0.3) 70%);
  border: 2px solid #fff;
  box-shadow: 0 0 12px 2px rgba(0, 240, 255, 0.6);
  cursor: pointer;
}

/* ---------- Popup (info edificio) ---------- */

.popup {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 16px 18px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.5);
  z-index: 10;
  max-width: 420px;
  margin: 0 auto;
}

.popup.hidden {
  display: none;
}

.popup-close {
  position: absolute;
  top: 8px;
  right: 12px;
  border: none;
  background: none;
  font-size: 1.3rem;
  color: var(--text-secondary);
  line-height: 1;
  cursor: pointer;
}

.popup strong {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1rem;
}

.popup dl {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 3px 10px;
  margin: 10px 0 0;
  font-size: 0.88rem;
}

.popup dt {
  color: var(--text-secondary);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  align-self: center;
}

.popup dd {
  margin: 0;
  font-weight: 600;
}

.popup-note {
  margin: 10px 0 0;
  font-size: 0.7rem;
  color: var(--text-secondary);
  line-height: 1.4;
}

.popup-actions {
  display: flex;
  gap: 6px;
  margin-top: 10px;
}

.popup-action-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 8px 6px;
  border-radius: var(--r-md);
  border: 1px solid var(--border);
  background: none;
  color: var(--electric-blue-light);
  font-size: 0.7rem;
  font-weight: 600;
  font-family: var(--font-body);
  text-decoration: none;
  text-align: center;
  cursor: pointer;
  white-space: nowrap;
}

.popup-action-btn:hover {
  border-color: var(--electric-blue-light);
}

.popup-reference {
  margin-top: 10px;
}

.popup-reference.hidden {
  display: none;
}

.ref-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: var(--r-md);
  background: rgba(195, 244, 0, 0.08);
  border: 1px solid rgba(195, 244, 0, 0.3);
  font-size: 0.82rem;
}

.ref-badge-tag {
  font-family: var(--font-mono);
  font-size: 0.6rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--lime);
  flex-shrink: 0;
}

/* ---------- Botones ---------- */

.btn-primary {
  background: var(--electric-blue);
  color: #fff;
  border: none;
  border-radius: var(--r-md);
  padding: 11px 16px;
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 0.88rem;
  cursor: pointer;
  transition: box-shadow 0.15s ease, transform 0.15s ease;
}

.btn-primary:hover {
  box-shadow: 0 0 0 3px rgba(0, 82, 255, 0.25);
}

.btn-primary:active {
  transform: scale(0.98);
}

.btn-block {
  display: block;
  width: 100%;
  margin-top: 12px;
}

.popup-btn-row {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.popup-btn-row .btn-primary {
  flex: 1;
  font-size: 0.82rem;
  padding: 11px 8px;
}

.person-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 10px;
  padding: 8px 10px;
  border-radius: var(--r-md);
  background: rgba(255, 107, 107, 0.1);
  border: 1px solid rgba(255, 107, 107, 0.3);
  color: #ff8f8f;
  font-size: 0.8rem;
  font-weight: 600;
}

.person-badge.hidden {
  display: none;
}

/* ---------- Sheet: formulario de referencia ---------- */

.sheet {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(4px);
}

.sheet.hidden {
  display: none;
}

.sheet-card {
  position: relative;
  width: 100%;
  max-width: 440px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-top-left-radius: var(--r-lg);
  border-top-right-radius: var(--r-lg);
  padding: 20px 20px 24px;
  box-shadow: 0 -12px 40px rgba(0, 0, 0, 0.5);
  max-height: 88vh;
  overflow-y: auto;
}

.sheet-eyebrow {
  margin: 0 0 4px;
  font-family: var(--font-mono);
  font-size: 0.62rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--lime);
}

.sheet-title {
  margin: 0 0 8px;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.2rem;
  letter-spacing: -0.01em;
  padding-right: 24px;
}

.sheet-help {
  margin: 0 0 16px;
  font-size: 0.82rem;
  color: var(--text-secondary);
  line-height: 1.5;
}

.donate-block {
  margin: 4px 0 18px;
  padding: 14px;
  border-radius: var(--r-lg);
  background: rgba(195, 244, 0, 0.06);
  border: 1px solid rgba(195, 244, 0, 0.25);
}

.donate-title {
  margin: 0 0 6px;
  font-weight: 600;
}

.donate-text {
  margin: 0 0 12px;
  font-size: 0.8rem;
  color: var(--text-secondary);
  line-height: 1.5;
}

.donate-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 16px;
  border-radius: var(--r-md);
  background: var(--lime);
  color: #1a1a00;
  font-weight: 700;
  font-size: 0.88rem;
  text-decoration: none;
}

.social-intro {
  margin: 12px 0 6px;
  font-size: 0.72rem;
  color: var(--text-secondary);
}

.social-links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.social-links a {
  font-size: 0.78rem;
  color: var(--electric-blue-light);
  text-decoration: none;
  padding: 5px 10px;
  border-radius: var(--r-full);
  border: 1px solid var(--border);
}

.tab-bar {
  display: flex;
  gap: 6px;
  margin: 4px 0 16px;
  background: #0a0a0a;
  border-radius: var(--r-md);
  padding: 4px;
}

.tab-btn {
  flex: 1;
  padding: 9px 8px;
  border: none;
  border-radius: var(--r-sm);
  background: none;
  color: var(--text-secondary);
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 0.82rem;
  cursor: pointer;
}

.tab-btn.active {
  background: var(--surface-high);
  color: var(--text-primary);
  box-shadow: 0 0 0 1px var(--border-strong);
}

.tab-panel.hidden {
  display: none;
}

.btn-danger {
  background: var(--error);
}

.btn-danger:hover {
  box-shadow: 0 0 0 3px rgba(255, 107, 107, 0.25);
}

.privacy-note {
  background: rgba(255, 107, 107, 0.08);
  border: 1px solid rgba(255, 107, 107, 0.25);
  border-radius: var(--r-md);
  padding: 8px 10px;
}

.field-label {
  display: block;
  font-family: var(--font-mono);
  font-size: 0.65rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-secondary);
  margin: 12px 0 6px;
}

.field-input {
  width: 100%;
  background: #0a0a0a;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 10px 12px;
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 0.9rem;
}

.field-input:focus {
  outline: none;
  border-color: var(--electric-blue-light);
  box-shadow: 0 0 0 2px rgba(183, 196, 255, 0.25);
}

.field-textarea {
  resize: vertical;
  min-height: 64px;
}

.radio-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 6px;
}

.radio-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  border-radius: var(--r-full);
  border: 1px solid var(--border);
  background: #0a0a0a;
  font-size: 0.82rem;
  cursor: pointer;
}

.radio-pill input {
  accent-color: var(--electric-blue-light);
}

.radio-pill:has(input:checked) {
  border-color: var(--electric-blue-light);
  background: rgba(183, 196, 255, 0.1);
}

.photo-preview {
  display: block;
  margin-top: 10px;
  max-width: 100%;
  max-height: 180px;
  border-radius: var(--r-md);
  border: 1px solid var(--border);
  object-fit: cover;
}

.photo-preview.hidden {
  display: none;
}

.photo-thumb {
  width: 100%;
  max-height: 160px;
  object-fit: cover;
  border-radius: var(--r-md);
  margin-top: 8px;
  display: block;
}

.damage-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: var(--r-full);
  margin-left: 6px;
}

.damage-badge.afectado {
  background: rgba(255, 107, 107, 0.15);
  color: #ff8f8f;
}

.damage-badge.no_afectado {
  background: rgba(195, 244, 0, 0.12);
  color: var(--lime);
}

.damage-badge.no_se {
  background: rgba(154, 156, 173, 0.15);
  color: var(--text-secondary);
}

.sheet-status {
  min-height: 1.2em;
  margin: 10px 0 0;
  font-size: 0.8rem;
  text-align: center;
}

.sheet-status.ok {
  color: var(--lime);
}

.sheet-status.error {
  color: var(--error);
}

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: var(--surface-high);
  border: 1px solid var(--border-strong);
  color: var(--text-primary);
  padding: 10px 18px;
  border-radius: var(--r-full);
  font-size: 0.82rem;
  z-index: 30;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
}

.toast.hidden {
  display: none;
}

/* ---------- Movil: priorizar el mapa sobre texto largo ---------- */

@media (max-width: 640px) {
  .disclaimer {
    display: none;
  }
}

/* ---------- Recorrido guiado (driver.js) — tema Mapiia Lab ---------- */

.driver-popover {
  background: var(--surface) !important;
  color: var(--text-primary) !important;
  border: 1px solid var(--border-strong) !important;
  border-radius: var(--r-lg) !important;
  font-family: var(--font-body) !important;
  max-width: 320px !important;
}

.driver-popover-title {
  font-family: var(--font-display) !important;
  color: var(--text-primary) !important;
  font-size: 1rem !important;
}

.driver-popover-description {
  color: var(--text-secondary) !important;
  font-size: 0.86rem !important;
  line-height: 1.5 !important;
}

.driver-popover-progress-text {
  color: var(--text-secondary) !important;
  font-family: var(--font-mono) !important;
  font-size: 0.68rem !important;
}

.driver-popover-footer button {
  background: var(--electric-blue) !important;
  color: #fff !important;
  text-shadow: none !important;
  border: none !important;
  border-radius: var(--r-md) !important;
  font-family: var(--font-body) !important;
  font-weight: 600 !important;
  padding: 7px 12px !important;
}

.driver-popover-footer .driver-popover-prev-btn {
  background: var(--surface-high) !important;
  color: var(--text-primary) !important;
}

.driver-popover-close-btn {
  color: var(--text-secondary) !important;
}

.driver-popover-arrow-side-top.driver-popover-arrow {
  border-top-color: var(--surface) !important;
}
.driver-popover-arrow-side-bottom.driver-popover-arrow {
  border-bottom-color: var(--surface) !important;
}
.driver-popover-arrow-side-left.driver-popover-arrow {
  border-left-color: var(--surface) !important;
}
.driver-popover-arrow-side-right.driver-popover-arrow {
  border-right-color: var(--surface) !important;
}

/* Durante el tour, el sheet/popup demo debe verse por encima del overlay
   oscuro de driver.js pero por debajo de su globo de texto. */
.tour-dialog {
  z-index: 10001 !important;
}
