:root {
  --orange: #ff7a1a;
  --orange-dark: #e86100;
  --orange-soft: #fff0e6;
  --bg: #f7f7f7;
  --card: #ffffff;
  --text: #222222;
  --muted: #666666;
  --line: #e8e8e8;
  --dark: #111111;
  --whatsapp: #25d366;
  --danger: #c0392b;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  color: var(--text);
  background: radial-gradient(circle at top right, #ffe0cc 0, transparent 28%), var(--bg);
}

.app-shell {
  width: min(100%, 560px);
  margin: 0 auto;
  padding: 18px 14px 28px;
}

.hero-card {
  background: linear-gradient(135deg, var(--orange), #ff9b4a);
  color: #fff;
  border-radius: 28px;
  padding: 24px;
  box-shadow: 0 18px 40px rgba(255, 122, 26, 0.25);
}

.brand-row { display: flex; gap: 14px; align-items: center; }
.brand-icon {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: 16px;
  background: rgba(255,255,255,.22);
  font-size: 25px;
  font-weight: 900;
}
.eyebrow { margin: 0; font-size: 13px; opacity: .9; }
h1 { margin: 2px 0 0; font-size: 31px; letter-spacing: -.6px; }
.hero-text { margin: 18px 0 0; line-height: 1.45; font-size: 16px; }

.card {
  background: var(--card);
  margin-top: 16px;
  border-radius: 24px;
  padding: 18px;
  box-shadow: 0 12px 35px rgba(0,0,0,.06);
  border: 1px solid rgba(0,0,0,.04);
}

label {
  display: block;
  font-size: 13px;
  font-weight: 800;
  margin: 12px 0 7px;
}

input {
  width: 100%;
  border: 1px solid var(--line);
  background: #fafafa;
  border-radius: 16px;
  min-height: 50px;
  padding: 0 14px;
  font-size: 16px;
  outline: none;
}
input:focus { border-color: var(--orange); box-shadow: 0 0 0 4px rgba(255,122,26,.12); }

.field-card {
  background: #fafafa;
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 12px;
}
.field-card input {
  background: #fff;
  border-radius: 14px;
}

.input-action-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.search-btn {
  border: 0;
  min-height: 52px;
  border-radius: 16px;
  background: var(--orange);
  color: #fff;
  font-weight: 900;
  cursor: pointer;
  width: 100%;
  display: block;
  font-size: 15px;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.search-btn:disabled { opacity: .65; cursor: wait; }

.field-actions,
.field-actions.one-action {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  margin-top: 10px;
}

.small-btn, .chip, .toggle, .secondary-btn, .primary-btn, .whatsapp-btn {
  border: 0;
  border-radius: 16px;
  cursor: pointer;
  font-weight: 800;
  text-decoration: none;
  text-align: center;
  min-height: 52px;
  font-size: 15px;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.small-btn {
  width: 100%;
  padding: 0 14px;
  background: var(--dark);
  color: #fff;
}
.small-btn.outline {
  background: var(--dark);
  color: #fff;
}
.small-btn.active-map-btn {
  background: var(--orange);
  color: #fff;
}

.status-text { margin: 7px 2px 0; font-size: 12px; color: var(--muted); min-height: 16px; }
.quick-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.chip { background: var(--orange-soft); color: var(--orange-dark); padding: 10px 12px; }
.section-title { margin: 0 0 10px; font-weight: 900; color: var(--muted); font-size: 13px; text-transform: uppercase; letter-spacing: .4px; }

.map-header { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.map-header .section-title { margin: 0; }
.map-mode {
  border: 0;
  border-radius: 16px;
  padding: 11px 12px;
  cursor: pointer;
  font-weight: 900;
  background: #efefef;
  color: var(--text);
  min-height: 52px;
  font-size: 15px;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.map-mode.ghost { background: var(--orange-soft); color: var(--orange-dark); }

.map-box {
  width: 100%;
  height: 310px;
  border-radius: 22px;
  overflow: hidden;
  border: 1px solid var(--line);
  background: #ececec;
  position: relative;
}

.map-card { padding-bottom: 12px; }
.map-preview { margin-top: 0; }
.preview-map { height: 230px; }

.leaflet-container { font-family: inherit; }
.leaflet-popup-content { font-weight: 800; }

.conditions { margin-top: 18px; }
.toggle-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 9px; }
.toggle { padding: 13px 10px; background: #f1f1f1; color: var(--text); }
.toggle.active { background: var(--orange); color: #fff; box-shadow: 0 8px 20px rgba(255,122,26,.24); }

.primary-btn {
  width: 100%;
  min-height: 52px;
  margin-top: 18px;
  background: var(--dark);
  color: #fff;
  font-size: 15px;
}
.primary-btn:disabled { opacity: .65; cursor: wait; }

.error-box { display: none; margin: 12px 0 0; color: var(--danger); background: #fff1ee; padding: 12px; border-radius: 14px; font-weight: 700; }
.hidden { display: none; }

.route-summary { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.route-summary div { background: #fafafa; border-radius: 18px; padding: 14px; border: 1px solid var(--line); }
.route-summary span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 5px; }
.route-summary strong { font-size: 18px; }

.price-box { margin-top: 14px; background: var(--orange-soft); border-radius: 22px; padding: 18px; text-align: center; }
.price-box p { margin: 0; color: var(--muted); font-weight: 800; }
.price-box h2 { margin: 8px 0 8px; font-size: 36px; color: var(--orange-dark); }
.price-box span { display: block; color: var(--muted); font-size: 13px; }
.price-box strong { display: block; font-size: 24px; margin-top: 3px; }

.breakdown { margin-top: 14px; display: grid; gap: 7px; }
.breakdown-row { display: flex; justify-content: space-between; padding: 10px 12px; background: #fafafa; border-radius: 14px; color: var(--muted); font-size: 14px; }
.breakdown-row strong { color: var(--text); }

.action-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 16px; }
.secondary-btn, .whatsapp-btn { padding: 15px 10px; }
.secondary-btn { background: #eeeeee; color: var(--text); }
.whatsapp-btn { background: var(--whatsapp); color: #fff; }

summary { font-weight: 900; cursor: pointer; }
.settings-grid { display: grid; grid-template-columns: repeat(2,1fr); gap: 10px; margin-top: 10px; }
.settings-grid label { margin: 0; font-size: 12px; color: var(--muted); }
.settings-grid input { margin-top: 6px; min-height: 44px; }

.legal-note { color: var(--muted); font-size: 12px; line-height: 1.4; text-align: center; padding: 0 12px; }

.map-modal {
  position: fixed;
  inset: 0;
  z-index: 99999;
  background: rgba(0,0,0,.55);
  padding: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.map-modal.hidden { display: none; }

.map-modal-card {
  width: min(100%, 680px);
  max-height: 96vh;
  overflow: auto;
  background: #fff;
  border-radius: 26px;
  padding: 14px;
  box-shadow: 0 25px 80px rgba(0,0,0,.28);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 8px;
}
.modal-header h2 { margin: 0; font-size: 24px; }
.modal-eyebrow { color: var(--orange-dark); font-weight: 900; }

.close-btn {
  min-width: 48px;
  min-height: 48px;
  border: 0;
  border-radius: 14px;
  background: #f0f0f0;
  color: var(--text);
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
}

.modal-help { margin: 0 0 12px; color: var(--muted); font-size: 14px; line-height: 1.35; }

.modal-map-box {
  height: 58vh;
  min-height: 380px;
  margin: 12px 0;
  border-radius: 20px;
}

.modal-primary { margin-top: 0; }

.modal-search { margin-bottom: 8px; }
.modal-search input { margin-bottom: 0; border-radius: 14px; }
.modal-search-results {
  max-height: 150px;
  overflow-y: auto;
  display: none;
  background: #fff;
  border: 1px solid var(--line);
  border-top: 0;
  border-radius: 0 0 14px 14px;
}
.modal-search-results.active { display: block; }
.modal-search-result {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  font-size: 14px;
  line-height: 1.3;
}
.modal-search-result:last-child { border-bottom: 0; }
.modal-search-result:hover,
.modal-search-result:active { background: var(--orange-soft); }
.modal-search-result.empty { color: var(--muted); cursor: default; }

.origin-display {
  margin-top: 8px;
  background: transparent !important;
  border: 0 !important;
  min-height: auto !important;
  padding: 2px 4px !important;
  font-size: 14px !important;
  cursor: default;
  color: var(--muted);
}
.origin-display:not(:placeholder-shown) { color: var(--text); }

.leaflet-pane,
.leaflet-tile,
.leaflet-marker-icon,
.leaflet-marker-shadow,
.leaflet-tile-container,
.leaflet-pane > svg,
.leaflet-pane > canvas,
.leaflet-zoom-box,
.leaflet-image-layer,
.leaflet-layer {
  position: absolute;
  left: 0;
  top: 0;
}
.leaflet-container {
  overflow: hidden;
  width: 100% !important;
  height: 100% !important;
  background: #ddd;
  outline-offset: 1px;
}
.leaflet-tile,
.leaflet-marker-icon,
.leaflet-marker-shadow {
  -webkit-user-select: none;
  -moz-user-select: none;
  user-select: none;
  -webkit-user-drag: none;
}
.leaflet-safari .leaflet-tile { image-rendering: -webkit-optimize-contrast; }
.leaflet-control { position: relative; z-index: 800; pointer-events: auto; }
.leaflet-top, .leaflet-bottom { position: absolute; z-index: 1000; pointer-events: none; }
.leaflet-top { top: 0; }
.leaflet-right { right: 0; }
.leaflet-bottom { bottom: 0; }
.leaflet-left { left: 0; }
.leaflet-control { float: left; clear: both; }
.leaflet-right .leaflet-control { float: right; }
.leaflet-top .leaflet-control { margin-top: 10px; }
.leaflet-bottom .leaflet-control { margin-bottom: 10px; }
.leaflet-left .leaflet-control { margin-left: 10px; }
.leaflet-right .leaflet-control { margin-right: 10px; }
.leaflet-control-attribution {
  background: rgba(255,255,255,.8);
  padding: 0 5px;
  font-size: 11px;
}
.leaflet-control-zoom a {
  background: #fff;
  border-bottom: 1px solid #ccc;
  width: 30px;
  height: 30px;
  line-height: 30px;
  display: block;
  text-align: center;
  text-decoration: none;
  color: #000;
  font-weight: 800;
}
.leaflet-control-zoom a:first-child { border-top-left-radius: 4px; border-top-right-radius: 4px; }
.leaflet-control-zoom a:last-child { border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-bottom: 0; }
.leaflet-popup { position: absolute; text-align: center; margin-bottom: 20px; }
.leaflet-popup-content-wrapper { padding: 1px; text-align: left; border-radius: 12px; background: #fff; box-shadow: 0 3px 14px rgba(0,0,0,.25); }
.leaflet-popup-content { margin: 12px 14px; line-height: 1.3; }
.leaflet-popup-tip-container { width: 40px; height: 20px; position: absolute; left: 50%; margin-left: -20px; overflow: hidden; pointer-events: none; }
.leaflet-popup-tip { width: 17px; height: 17px; padding: 1px; margin: -10px auto 0; transform: rotate(45deg); background: white; box-shadow: 0 3px 14px rgba(0,0,0,.25); }
.preview-map, .modal-map-box { min-height: 260px; }

.credit { text-align: center; font-size: 13px; color: #bbb; margin-top: 0; }

@media (max-width: 430px) {
  .app-shell { padding-left: 12px; padding-right: 12px; }
  .card { padding: 16px; }
  input { min-height: 56px; font-size: 16px; }
  .preview-map { height: 220px; }
  .modal-map-box { height: 56vh; min-height: 360px; }
  .onboarding-card { margin: 12px; padding: 20px; }
}

.onboarding-overlay.hidden { display: none; }
.onboarding-overlay {
  position: fixed; inset: 0; z-index: 9999;
  background: rgba(0,0,0,.5);
  display: flex; align-items: center; justify-content: center;
  backdrop-filter: blur(2px);
}
.onboarding-card {
  background: #fff; border-radius: 24px; padding: 28px;
  max-width: 380px; width: 100%; box-shadow: 0 12px 40px rgba(0,0,0,.25);
  position: relative; animation: fadeUp .35s ease;
}
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}
.onboarding-skip {
  position: absolute; top: 12px; right: 14px;
  background: none; border: none; color: #999; font-size: 14px;
  cursor: pointer; padding: 6px 10px;
}
.onboarding-content { min-height: 170px; position: relative; }
.onboarding-step { display: none; text-align: center; }
.onboarding-step.active { display: block; }
.onboarding-icon {
  width: 48px; height: 48px; line-height: 48px;
  background: var(--orange); color: #fff; border-radius: 50%;
  font-size: 22px; font-weight: 800; margin: 0 auto 10px;
  text-align: center;
}
.onboarding-step h3 { margin: 0 0 8px; font-size: 18px; color: var(--text); }
.onboarding-step p { margin: 0; font-size: 15px; line-height: 1.5; color: #666; }
.onboarding-step p strong { color: var(--orange-dark); }
.onboarding-dots { display: flex; gap: 8px; justify-content: center; margin: 18px 0; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: #ddd; transition: background .2s; }
.dot.active { background: var(--orange); width: 24px; border-radius: 5px; }
.onboarding-nav { display: flex; gap: 10px; justify-content: center; }
.onboarding-btn { padding: 10px 20px; font-size: 15px; min-width: 100px; }
.onboarding-btn:disabled { opacity: .4; pointer-events: none; }

.waiting-panel { margin-top: 18px; padding: 16px; border: 1px solid #ffd5b8; background: #fff8f2; border-radius: 18px; }
.waiting-panel.hidden { display: none; }
.waiting-panel label { margin-top: 8px; }

.toll-panel { margin-top: 18px; padding: 16px; border: 1px solid #d9e5f7; background: #f7faff; border-radius: 18px; }
.toll-panel .section-title { color: #315a8a; }
.toll-panel .settings-grid { margin-bottom: 8px; }
.toll-select { width: 100%; min-height: 50px; padding: 0 12px; background: #fff; color: var(--text); border: 1px solid var(--line); border-radius: 14px; font-size: 15px; }
.toll-panel .hidden { display: none; }

/* Detección asistida de casetas CAS */
.toll-detected-list {margin-top:8px; display:grid; gap:6px;}
.toll-choice,.toll-confirm {display:flex;align-items:center;gap:10px;margin:6px 0;padding:10px 12px;border-radius:12px;background:#fff8f2;font-size:13px;line-height:1.35;font-weight:650;}
.toll-choice input,.toll-confirm input {width:20px;height:20px;min-height:20px;flex:none;accent-color:#ff7a1a;}
.toll-source {display:inline-block;margin-top:10px;color:#bf4c00;font-size:13px;font-weight:700;}

/* v13: casetas a la vista y fáciles de configurar en móvil */
.toll-panel { border:2px solid #ff9d56; background:#fff5ec; box-shadow:0 8px 22px rgba(255,122,26,.09); margin-top:22px; padding:18px; }
.toll-panel .section-title {color:#b94e00; font-size:16px; margin-bottom:8px;}
.toll-intro {font-size:14px; line-height:1.45; color:#583c2c; margin:0 0 14px;}
.toll-panel > label, .toll-panel #tollFields > label {font-size:15px; font-weight:800; margin:14px 0 8px;}
.toll-select { appearance:auto; -webkit-appearance:menulist; display:block; width:100%; min-height:56px; font-size:16px; padding:10px 12px; border:2px solid #ffc294; border-radius:14px; background:#fff; color:#222; }
.toll-panel input[type=number] {background:#fff; border:2px solid #ffc294; font-weight:750; font-size:17px; }
.toll-panel #tollFields { margin-top:14px; padding-top:12px; border-top:1px solid #ffceb0; }
.toll-confirm-info {margin:10px 0; font-size:13px; line-height:1.45; color:#714831; background:#fff; padding:11px; border-radius:12px;}
.toll-total-line {display:flex;justify-content:space-between;align-items:center;gap:12px; padding:15px; margin-top:15px; background:#fff; border:2px solid #ffba85; border-radius:14px; font-size:15px; font-weight:750;}
.toll-total-line strong {color:#c65300;font-size:23px;}
.toll-panel .settings-grid {grid-template-columns:repeat(auto-fit,minmax(185px,1fr));}
.breakdown-row {gap:12px; align-items:center;}
.breakdown-row strong {text-align:right; overflow-wrap:anywhere;}
