/* ── RoadGuard España — UI móvil sobre mapa ── */
@import url('https://fonts.googleapis.com/css2?family=Barlow+Condensed:wght@600;700&family=Inter:wght@400;500;600&display=swap');

:root {
  --bg:        #f0f4fa;
  --panel:     rgba(255,255,255,0.97);
  --card:      #ffffff;
  --border:    rgba(26, 79, 214, 0.13);
  --fg:        #0f172a;
  --muted:     #64748b;
  --dim:       #94a3b8;
  --accent:    #1a4fd6;
  --accent2:   #2563eb;
  --green:     #16a34a;
  --orange:    #d97706;
  --red:       #dc2626;
  --blue:      #2563eb;
  --sat:       env(safe-area-inset-top, 0px);
  --sab:       env(safe-area-inset-bottom, 0px);
  --sal:       env(safe-area-inset-left, 0px);
  --sar:       env(safe-area-inset-right, 0px);
  color-scheme: light;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

html, body {
  margin: 0; height: 100%;
  background: var(--bg);
  color: var(--fg);
  font: 14px/1.4 'Inter', system-ui, sans-serif;
  overflow: hidden;
  touch-action: manipulation;
}
button { font: inherit; color: inherit; cursor: pointer; }
input  { font: inherit; color: inherit; }

#map { position: fixed; inset: 0; background: #e8edf5; }

.card {
  background: var(--panel);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 4px 24px rgba(26,79,214,.10), 0 1px 4px rgba(0,0,0,.06);
}

/* ── Barra superior ── */
#topbar {
  position: fixed; z-index: 30; top: 0; left: 0; right: 0;
  padding: calc(var(--sat) + 10px) max(14px, var(--sar)) 10px max(14px, var(--sal));
  display: flex; align-items: center; gap: 10px;
  background: linear-gradient(135deg, #1a4fd6 0%, #2563eb 100%);
  box-shadow: 0 2px 16px rgba(26,79,214,.28);
}
#topbar > * { pointer-events: auto; }

.brand {
  display: flex; align-items: center; gap: 8px;
  font-family: 'Barlow Condensed', sans-serif;
  font-weight: 700; font-size: 21px; letter-spacing: .03em;
  color: #fff;
}
.brand-icon {
  background: rgba(255,255,255,0.18);
  border-radius: 8px;
  width: 30px; height: 30px;
  display: grid; place-items: center;
  font-size: 16px;
}

.gps-pill {
  margin-left: auto;
  display: flex; align-items: center; gap: 7px;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(255,255,255,0.15);
  border: 1px solid rgba(255,255,255,0.28);
  font-size: 12px; font-weight: 600;
  color: rgba(255,255,255,0.80);
}
.gps-dot { width: 8px; height: 8px; border-radius: 50%; background: rgba(255,255,255,0.4); }
.gps-pill[data-state="on"]   .gps-dot { background: #4ade80; box-shadow: 0 0 7px #4ade80; }
.gps-pill[data-state="on"]   { color: #fff; }
.gps-pill[data-state="wait"] .gps-dot { background: #fbbf24; animation: blink 1s infinite; }
.gps-pill[data-state="err"]  .gps-dot { background: #f87171; }
.gps-speed {
  font-family: 'Barlow Condensed', sans-serif;
  font-weight: 700; font-size: 16px;
  color: #fff;
  font-variant-numeric: tabular-nums;
}
.gps-speed:empty { display: none; }
@keyframes blink { 50% { opacity: .35; } }

.icon-btn {
  width: 36px; height: 36px; border-radius: 10px;
  border: 1px solid rgba(255,255,255,0.30);
  background: rgba(255,255,255,0.15);
  color: #fff;
  font-size: 17px;
  display: grid; place-items: center;
}
.icon-btn:active { background: rgba(255,255,255,0.28); }

/* ── Buscador ── */
#search-wrap {
  position: fixed; z-index: 25;
  left: max(12px, var(--sal)); right: max(12px, var(--sar));
  top: calc(var(--sat) + 62px);
  display: flex; flex-direction: column; gap: 8px;
  pointer-events: none;
}
#search {
  padding: 12px;
  display: flex; flex-direction: column; gap: 9px;
  pointer-events: auto;
}
#search.collapsed .field:first-child,
#search.collapsed #btn-route { display: none; }

.field { position: relative; display: flex; align-items: center; }
.field-dot { position: absolute; left: 12px; width: 10px; height: 10px; border-radius: 50%; }
.field-dot.origin { background: var(--green); box-shadow: 0 0 0 3px rgba(22,163,74,.18); }
.field-dot.dest   { background: var(--red); border-radius: 2px; transform: rotate(45deg); box-shadow: 0 0 0 3px rgba(220,38,38,.15); }

.field input {
  width: 100%;
  background: #f8faff;
  border: 1.5px solid var(--border);
  border-radius: 11px;
  padding: 11px 38px 11px 32px;
  font-size: 15px;
  outline: none;
  -webkit-appearance: none;
  color: var(--fg);
  transition: border-color .15s;
}
.field input:focus { border-color: var(--accent2); background: #fff; box-shadow: 0 0 0 3px rgba(37,99,235,.12); }
.field input::placeholder { color: var(--dim); }

.field-clear {
  position: absolute; right: 6px;
  width: 28px; height: 28px;
  border: none; border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
}

.suggest {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 11px;
  overflow: hidden;
  max-height: 220px;
  overflow-y: auto;
  box-shadow: 0 4px 16px rgba(26,79,214,.10);
}
.suggest-item {
  padding: 11px 14px;
  display: flex; gap: 10px; align-items: center;
  border-bottom: 1px solid rgba(26,79,214,.07);
  cursor: pointer;
  color: var(--fg);
  font-size: 14px;
}
.suggest-item:last-child { border-bottom: none; }
.suggest-item:active { background: #f0f4fa; }
.suggest-item small { color: var(--muted); margin-left: auto; font-size: 11px; }

.btn-primary {
  width: 100%; border: none; border-radius: 11px; padding: 13px;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent2) 100%);
  color: #fff;
  font-family: 'Barlow Condensed', sans-serif;
  font-weight: 700; font-size: 16px; letter-spacing: .06em;
  box-shadow: 0 2px 12px rgba(26,79,214,.30);
  transition: opacity .15s, transform .1s;
}
.btn-primary:active { opacity: .88; transform: scale(.98); }
.btn-primary:disabled { opacity: .45; }

.btn-ghost {
  width: 100%;
  border: 1.5px solid var(--border);
  border-radius: 11px; padding: 10px;
  background: transparent;
  color: var(--accent);
  font-weight: 600;
  transition: background .15s;
}
.btn-ghost:active { background: rgba(26,79,214,.07); }

/* ── Franja de datos ── */
.datastrip {
  display: flex; gap: 6px; flex-wrap: wrap;
  pointer-events: none; margin-top: 2px;
}
.ds-item {
  background: rgba(255,255,255,0.92);
  border: 1px solid rgba(26,79,214,.15);
  border-radius: 999px;
  padding: 4px 11px;
  font-size: 11.5px;
  color: var(--muted);
  backdrop-filter: blur(8px);
  white-space: nowrap;
  box-shadow: 0 1px 4px rgba(26,79,214,.07);
}
.ds-item b { font-family: 'Barlow Condensed', sans-serif; font-size: 14px; font-weight: 700; color: var(--fg); }
.ds-item.live b { color: var(--accent2); }
.ds-item.hist b { color: var(--red); }
.ds-item.radar b { color: var(--orange); }
.ds-item.muted { font-size: 10.5px; }

/* ── Banner control en vivo ── */
.live-banner {
  position: fixed; z-index: 40;
  left: max(12px, var(--sal)); right: max(12px, var(--sar));
  top: calc(var(--sat) + 62px);
  background: var(--red); color: #fff;
  border-radius: 14px; padding: 13px 16px;
  display: flex; gap: 13px; align-items: center;
  box-shadow: 0 8px 24px rgba(220,38,38,.38);
  animation: pulse 1.2s ease-in-out infinite;
}
.live-banner-icon { font-size: 28px; }
.live-banner-text { display: flex; flex-direction: column; }
.live-banner-text strong { font-family: 'Barlow Condensed', sans-serif; font-size: 21px; letter-spacing: .02em; }
.live-banner-text span { font-size: 13px; opacity: .93; }
@keyframes pulse { 50% { box-shadow: 0 8px 36px rgba(220,38,38,.72); } }

/* ── Toast ── */
.toast {
  position: fixed; z-index: 45;
  left: 50%; transform: translateX(-50%);
  bottom: calc(var(--sab) + 110px);
  max-width: min(92vw, 420px);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 13px;
  padding: 10px 15px;
  font-size: 13px;
  display: flex; gap: 10px; align-items: center;
  box-shadow: 0 4px 20px rgba(26,79,214,.14);
  color: var(--fg);
}
.toast.err { border-color: var(--red); }
.toast .spin {
  width: 14px; height: 14px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Controles del mapa ── */
#map-controls {
  position: fixed; z-index: 20;
  right: max(14px, var(--sar));
  bottom: calc(var(--sab) + 180px);
  display: flex; flex-direction: column; gap: 10px;
}
.round-btn {
  width: 48px; height: 48px;
  border-radius: 50%;
  border: 1.5px solid var(--border);
  background: var(--panel);
  font-size: 22px;
  display: grid; place-items: center;
  color: var(--accent);
  box-shadow: 0 4px 16px rgba(26,79,214,.18);
  transition: box-shadow .15s, transform .1s;
}
.round-btn:active { transform: scale(.93); }

/* ── Capas ── */
#layers {
  position: fixed; z-index: 35;
  right: max(12px, var(--sar));
  top: calc(var(--sat) + 62px);
  width: 280px; max-width: calc(100vw - 24px);
  padding: 14px;
  display: flex; flex-direction: column; gap: 11px;
}
.layers-title {
  font-family: 'Barlow Condensed', sans-serif;
  font-weight: 700; font-size: 13px; letter-spacing: .09em;
  text-transform: uppercase; color: var(--muted);
}
.switch { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--fg); }
.switch input { width: 18px; height: 18px; accent-color: var(--accent); }
.layers-meta { font-size: 11px; color: var(--muted); line-height: 1.5; border-top: 1px solid var(--border); padding-top: 9px; }
.layers-note { font-size: 11px; color: var(--green); line-height: 1.4; font-weight: 500; }

/* ── Hoja inferior ── */
#sheet {
  position: fixed; z-index: 30;
  left: max(10px, var(--sal)); right: max(10px, var(--sar));
  bottom: calc(var(--sab) + 10px);
  padding: 6px 16px 16px;
  max-height: 56vh; overflow-y: auto;
}
.sheet-handle { width: 40px; height: 4px; border-radius: 2px; background: var(--border); margin: 4px auto 12px; }
.route-head { display: flex; align-items: center; gap: 10px; margin-bottom: 9px; }
.route-tag {
  font-family: 'Barlow Condensed', sans-serif;
  font-weight: 700; font-size: 13px; letter-spacing: .07em;
  padding: 3px 10px; border-radius: 999px;
}
.route-tag.ok   { background: rgba(22,163,74,.12); color: var(--green); border: 1px solid var(--green); }
.route-tag.warn { background: rgba(217,119,6,.12); color: var(--orange); border: 1px solid var(--orange); }
.route-tag.bad  { background: rgba(220,38,38,.12); color: var(--red); border: 1px solid var(--red); }
.route-big { display: flex; align-items: baseline; gap: 12px; }
.route-big strong {
  font-family: 'Barlow Condensed', sans-serif;
  font-weight: 700; font-size: 36px; line-height: 1;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
}
.route-big span { color: var(--muted); font-size: 15px; }
.route-roads { color: var(--muted); font-size: 12.5px; margin: 6px 0 10px; line-height: 1.5; }
.route-roads b { color: var(--fg); font-weight: 600; }
.route-compare { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; margin-bottom: 13px; }
.cmp { background: #f8faff; border-radius: 11px; padding: 10px 12px; border-left: 3px solid var(--dim); }
.cmp.safe { border-left-color: var(--green); }
.cmp.fast { border-left-color: var(--red); }
.cmp .k { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.cmp .v { font-family: 'Barlow Condensed', sans-serif; font-weight: 700; font-size: 19px; margin-top: 2px; color: var(--fg); }
.cmp .v small { font-size: 12px; font-weight: 500; color: var(--muted); font-family: 'Inter', sans-serif; }
.route-actions { display: flex; gap: 9px; }
.route-actions .btn-primary { flex: 2; }
.route-actions .btn-ghost { flex: 1; }
.route-note { font-size: 11.5px; color: var(--muted); margin-top: 10px; line-height: 1.5; }
.route-note.bad { color: var(--red); }

/* ── Navegación activa ── */
#navbar {
  position: fixed; z-index: 30;
  left: max(10px, var(--sal)); right: max(10px, var(--sar));
  bottom: calc(var(--sab) + 10px);
  padding: 14px 16px;
  display: flex; align-items: center; gap: 14px;
}
.nav-main {
  flex: 1; min-width: 0;
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-rows: auto auto;
  gap: 2px 14px;
}
.nav-eta { grid-row: 1 / 3; display: flex; flex-direction: column; }
.nav-big {
  font-family: 'Barlow Condensed', sans-serif;
  font-weight: 700; font-size: 34px; line-height: 1;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
}
.nav-sub { color: var(--muted); font-size: 14px; }
.nav-road {
  font-family: 'Barlow Condensed', sans-serif;
  font-weight: 600; font-size: 18px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  align-self: end; color: var(--fg);
}
.nav-status { font-size: 12.5px; font-weight: 600; align-self: start; }
.nav-status.ok  { color: var(--green); }
.nav-status.bad { color: var(--red); }

.btn-stop {
  width: 50px; height: 50px;
  border-radius: 13px;
  border: 1.5px solid rgba(220,38,38,.35);
  background: rgba(220,38,38,.08);
  color: var(--red);
  font-size: 19px;
  flex-shrink: 0;
  transition: background .15s;
}
.btn-stop:active { background: rgba(220,38,38,.18); }

/* ── Leaflet overrides ── */
.leaflet-container { background: #e8edf5; font: inherit; }
.leaflet-control-attribution {
  background: rgba(255,255,255,0.85) !important;
  color: var(--muted) !important;
  font-size: 10px;
}
.leaflet-control-attribution a { color: var(--accent) !important; }
.leaflet-bottom.leaflet-right { bottom: calc(var(--sab) + 2px); }
.leaflet-control-zoom a {
  background: var(--panel) !important;
  color: var(--accent) !important;
  border-color: var(--border) !important;
}
.leaflet-control-zoom a:hover { background: #f0f4fa !important; }

/* ── Media: pantallas anchas ── */
@media (min-width: 720px) {
  #search-wrap { right: auto; width: 380px; }
  #sheet, #navbar { right: auto; width: 380px; }
  #map-controls { bottom: calc(var(--sab) + 24px); }
  .toast { bottom: calc(var(--sab) + 24px); left: auto; right: 24px; transform: none; }
}
