:root {
  --surface: #ffffff;
  --surface-soft: #f5f8fc;
  --text: #142033;
  --muted: #68758a;
  --border: #dfe5ee;
  --primary: #0068d9;
  --primary-dark: #004eaa;
  --success: #138a5b;
  --danger: #a02c2c;
  --shadow: 0 14px 40px rgba(20, 32, 51, 0.15);
  --radius: 16px;
}

* { box-sizing: border-box; }

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background: #dce8f4;
}

button,
input { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.55; }

.map-app,
.map-section,
.map {
  width: 100%;
  height: 100%;
  min-height: 100dvh;
}

.map-section { position: relative; }
.map { background: #dce8f4; }

.map-toolbar {
  position: absolute;
  z-index: 700;
  top: 18px;
  left: 18px;
  right: 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 12px 14px;
  border: 1px solid rgba(223, 229, 238, 0.88);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}

.toolbar-copy {
  min-width: 0;
  display: grid;
  gap: 2px;
}

.eyebrow {
  font-size: 0.68rem;
  font-weight: 900;
  letter-spacing: 0.14em;
  color: var(--primary);
}

.toolbar-copy strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 1rem;
}

.toolbar-copy > span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
  font-size: 0.8rem;
}

.toolbar-actions {
  flex: 0 0 auto;
  display: flex;
  gap: 8px;
}

.btn {
  min-height: 40px;
  border: 0;
  border-radius: 10px;
  padding: 9px 13px;
  font-weight: 800;
  transition: transform 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
}
.btn:hover:not(:disabled) { transform: translateY(-1px); }
.btn-primary { color: #fff; background: var(--primary); }
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); }
.btn-light {
  color: var(--text);
  border: 1px solid var(--border);
  background: #fff;
}

.search-summary {
  position: absolute;
  z-index: 680;
  left: 18px;
  bottom: 54px;
  max-width: calc(100% - 36px);
  padding: 9px 12px;
  border-radius: 999px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 6px 20px rgba(20, 32, 51, 0.13);
  font-size: 0.79rem;
  font-weight: 800;
  backdrop-filter: blur(10px);
}

.map-note {
  position: absolute;
  z-index: 670;
  left: 18px;
  bottom: 14px;
  max-width: calc(100% - 36px);
  padding: 7px 10px;
  border-radius: 9px;
  color: #445068;
  background: rgba(255, 255, 255, 0.88);
  box-shadow: 0 5px 16px rgba(20, 32, 51, 0.1);
  font-size: 0.72rem;
}

/* Pins */
.custom-pin-wrap { background: transparent; border: 0; }
.custom-pin {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 3px solid #fff;
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  background: var(--primary);
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.28);
}
.custom-pin > span {
  display: grid;
  place-items: center;
  width: 19px;
  height: 19px;
  border-radius: 50%;
  color: var(--primary-dark);
  background: #fff;
  font-size: 0.7rem;
  font-weight: 900;
  transform: rotate(45deg);
}
.custom-pin.is-user { background: #172033; }
.custom-pin.is-user > span { width: 8px; height: 8px; font-size: 0; }
.custom-pin.is-top { background: #11a06b; }

/* Popup nativo de Leaflet para cada distribuidor */
.leaflet-popup-content-wrapper { border-radius: 14px; }
.leaflet-popup-content { margin: 15px 16px; min-width: 210px; }
.popup-title { margin: 0 0 6px; font-size: 1rem; }
.popup-address { margin: 0 0 8px; color: var(--muted); line-height: 1.4; }
.popup-lines { margin: 0 0 10px; font-size: 0.82rem; line-height: 1.4; }
.popup-rank-label { margin: 8px 0 10px; font-weight: 800; color: var(--primary-dark); }
.popup-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.popup-link {
  display: inline-block;
  padding: 8px 11px;
  border-radius: 8px;
  color: #fff !important;
  background: var(--primary);
  font-weight: 800;
  text-decoration: none;
}

/* SweetAlert2: Wizard */
.swal2-popup.distributor-wizard,
.swal2-popup.results-dialog {
  width: min(620px, calc(100vw - 28px));
  border-radius: 22px;
  padding: 26px;
}

.swal2-popup.distributor-wizard .swal2-title,
.swal2-popup.results-dialog .swal2-title {
  padding: 0;
  color: var(--text);
  font-size: clamp(1.45rem, 4vw, 2rem);
  line-height: 1.15;
}

.swal2-popup.distributor-wizard .swal2-html-container,
.swal2-popup.results-dialog .swal2-html-container {
  margin: 14px 0 0;
  overflow: visible;
  color: var(--text);
}

.wizard-intro {
  margin: 0 0 18px;
  color: var(--muted);
  line-height: 1.5;
  font-size: 0.92rem;
}

.product-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.wizard-option {
  position: relative;
  width: 100%;
  min-height: 92px;
  display: flex;
  align-items: center;
  gap: 13px;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 15px;
  text-align: left;
  color: var(--text);
  background: var(--surface-soft);
  transition: border-color 0.15s ease, background 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease;
}

.wizard-option:hover,
.wizard-option:focus-visible {
  border-color: var(--primary);
  background: #eef6ff;
  outline: none;
  transform: translateY(-1px);
  box-shadow: 0 7px 18px rgba(0, 104, 217, 0.1);
}

.wizard-option-icon {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 12px;
  color: var(--primary);
  background: #e7f2ff;
  font-size: 1rem;
  font-weight: 900;
}

.wizard-option-copy { min-width: 0; }
.wizard-option-copy strong {
  display: block;
  margin-bottom: 3px;
  font-size: 0.98rem;
}
.wizard-option-copy span {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.35;
}

.location-current {
  min-height: 78px;
}

.wizard-divider {
  display: flex;
  align-items: center;
  gap: 11px;
  margin: 17px 0;
  color: #8d99aa;
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.wizard-divider::before,
.wizard-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

.postal-block {
  text-align: left;
}
.postal-label {
  display: block;
  margin-bottom: 7px;
  font-size: 0.85rem;
  font-weight: 900;
}
.postal-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}
.postal-input {
  width: 100%;
  min-width: 0;
  height: 46px;
  border: 1px solid var(--border);
  border-radius: 11px;
  padding: 0 13px;
  color: var(--text);
  background: #fff;
  outline: none;
}
.postal-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(0, 104, 217, 0.11);
}
.postal-search-btn {
  min-height: 46px;
  border: 0;
  border-radius: 11px;
  padding: 0 15px;
  color: #fff;
  background: var(--primary);
  font-weight: 900;
}
.postal-search-btn:hover { background: var(--primary-dark); }
.postal-search-btn:disabled,
.wizard-option:disabled { opacity: 0.55; cursor: wait; transform: none; }
.postal-help {
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 0.76rem;
}

.wizard-status {
  min-height: 20px;
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 0.82rem;
  text-align: center;
}
.wizard-status.is-loading { color: var(--primary-dark); font-weight: 800; }

.wizard-back {
  margin-top: 14px;
  border: 0;
  padding: 6px 10px;
  color: var(--primary-dark);
  background: transparent;
  font-weight: 800;
}

.swal2-validation-message {
  border-radius: 10px;
  font-size: 0.83rem;
}

/* Popup para volver a consultar las tres recomendaciones */
.results-list {
  display: grid;
  gap: 9px;
  margin-top: 8px;
}
.result-card {
  width: 100%;
  display: grid;
  grid-template-columns: 40px 1fr auto;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--border);
  border-radius: 13px;
  padding: 12px;
  text-align: left;
  color: var(--text);
  background: var(--surface-soft);
}
.result-card:hover {
  border-color: var(--primary);
  background: #eef6ff;
}
.result-number {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  color: #fff;
  background: var(--primary);
  font-weight: 900;
}
.result-card:first-child .result-number { background: var(--success); }
.result-copy strong { display: block; font-size: 0.9rem; }
.result-copy span { display: block; margin-top: 2px; color: var(--muted); font-size: 0.76rem; }
.result-distance { color: var(--primary-dark); font-size: 0.78rem; font-weight: 900; white-space: nowrap; }

@media (max-width: 700px) {
  .map-toolbar {
    top: 10px;
    left: 10px;
    right: 10px;
    align-items: flex-start;
    gap: 10px;
    padding: 10px;
  }
  .toolbar-copy > span:last-child { display: none; }
  .toolbar-actions { gap: 6px; }
  .btn { min-height: 36px; padding: 8px 10px; font-size: 0.78rem; }
  .search-summary { left: 10px; bottom: 50px; max-width: calc(100% - 20px); }
  .map-note { left: 10px; bottom: 10px; max-width: calc(100% - 20px); font-size: 0.66rem; }
  .swal2-popup.distributor-wizard,
  .swal2-popup.results-dialog { padding: 20px 16px; }
}

@media (max-width: 520px) {
  .product-grid { grid-template-columns: 1fr; }
  .wizard-option { min-height: 70px; }
  .postal-row { grid-template-columns: 1fr; }
  .postal-search-btn { width: 100%; }
  .result-card { grid-template-columns: 36px 1fr; }
  .result-distance { grid-column: 2; }
  #resultsBtn { display: none; }
}
