:root {
  --bg: #F5F7FA;
  --surface: #FFFFFF;
  --surface2: #EEF2F7;
  --accent: #1D6FEB;
  --accent-light: #EBF2FF;
  --accent-hover: #1558CC;
  --text: #0F1724;
  --text-muted: #6B7A99;
  --text-faint: #9BA8C0;
  --green: #16A34A;
  --green-bg: #F0FDF4;
  --green-border: #BBF7D0;
  --orange: #D97706;
  --orange-bg: #FFFBEB;
  --orange-border: #FDE68A;
  --red: #DC2626;
  --red-bg: #FEF2F2;
  --red-border: #FECACA;
  --border: #E2E8F0;
  --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08), 0 2px 4px rgba(0,0,0,0.04);
  --radius: 12px;
  --radius-sm: 8px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}

/* ── Header ── */
header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 13px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: var(--shadow);
  position: relative;
  z-index: 10;
}

.logo {
  font-size: 1.2rem;
  font-weight: 800;
  color: var(--text);
  letter-spacing: -0.5px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.logo-icon {
  width: 30px;
  height: 30px;
  background: var(--accent);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.95rem;
  line-height: 1;
  flex-shrink: 0;
}

.logo span { color: var(--accent); }

.header-tag {
  margin-left: auto;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-light);
  padding: 3px 9px;
  border-radius: 20px;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

/* ── Controls ── */
.controls {
  background: var(--surface);
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  border-bottom: 1px solid var(--border);
}

.search-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.search-wrap {
  position: relative;
  flex: 1;
}

input[type="text"] {
  width: 100%;
  background: var(--bg);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 10px 14px;
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  font-family: inherit;
}

input[type="text"]:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(29,111,235,0.1);
  background: var(--surface);
}

input[type="text"]::placeholder { color: var(--text-faint); }

.autocomplete {
  position: absolute;
  top: calc(100% + 4px);
  left: 0; right: 0;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  z-index: 1000;
  overflow: hidden;
  box-shadow: var(--shadow-md);
}

.autocomplete-item {
  padding: 10px 14px;
  cursor: pointer;
  font-size: 0.88rem;
  border-bottom: 1px solid var(--border);
  transition: background 0.1s;
  color: var(--text);
}

.autocomplete-item:last-child { border-bottom: none; }
.autocomplete-item:hover { background: var(--accent-light); }

.btn-geo {
  background: var(--accent);
  border: none;
  border-radius: var(--radius-sm);
  color: #fff;
  padding: 10px 14px;
  cursor: pointer;
  font-size: 1rem;
  flex-shrink: 0;
  transition: background 0.15s, transform 0.1s;
  line-height: 1;
}

.btn-geo:hover { background: var(--accent-hover); }
.btn-geo:active { transform: scale(0.95); }

.selectors {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 8px;
}

select {
  background: var(--bg);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 9px 12px;
  font-size: 0.88rem;
  outline: none;
  cursor: pointer;
  flex: 1;
  min-width: 120px;
  font-family: inherit;
  transition: border-color 0.15s, box-shadow 0.15s;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%236B7A99' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 30px;
}

select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(29,111,235,0.1);
}

/* ── Map ── */
#map {
  height: 260px;
  width: 100%;
  flex-shrink: 0;
}

/* ── Results header ── */
.results-header {
  padding: 12px 16px 6px;
  font-size: 0.82rem;
  color: var(--text-muted);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.results-count {
  font-weight: 700;
  color: var(--text);
  font-size: 0.88rem;
}

/* ── Results list ── */
#results {
  flex: 1;
  overflow-y: auto;
  padding: 0 12px 20px;
}

/* ── Station card ── */
.station-card {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.1s;
  box-shadow: var(--shadow);
}

.station-card:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.station-card.selected {
  border-color: var(--accent);
  background: var(--accent-light);
}

.card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 8px;
  gap: 8px;
}

.station-name {
  font-weight: 700;
  font-size: 0.93rem;
  flex: 1;
  color: var(--text);
  line-height: 1.3;
}

.station-address {
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.3;
  margin-top: 1px;
}

.price-badge {
  font-size: 1.2rem;
  font-weight: 800;
  white-space: nowrap;
  letter-spacing: -0.5px;
}

.price-green { color: var(--green); }
.price-orange { color: var(--orange); }
.price-red { color: var(--red); }

.station-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  align-items: center;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.badge {
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 0.72rem;
  font-weight: 700;
  white-space: nowrap;
  letter-spacing: 0.01em;
}

.badge-24h {
  background: var(--accent-light);
  color: var(--accent);
  border: 1px solid rgba(29,111,235,0.2);
}

.badge-calme {
  background: var(--green-bg);
  color: var(--green);
  border: 1px solid var(--green-border);
}

.badge-modere {
  background: var(--orange-bg);
  color: var(--orange);
  border: 1px solid var(--orange-border);
}

.badge-frequente {
  background: var(--red-bg);
  color: var(--red);
  border: 1px solid var(--red-border);
}

.savings {
  font-size: 0.78rem;
  color: var(--green);
  font-weight: 600;
}

.update-time {
  font-size: 0.72rem;
  color: var(--text-faint);
}

.nav-links {
  display: flex;
  gap: 6px;
  margin-top: 10px;
  flex-wrap: wrap;
}

.nav-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 5px 11px;
  border-radius: 6px;
  font-size: 0.76rem;
  font-weight: 600;
  text-decoration: none;
  border: 1.5px solid var(--border);
  color: var(--text-muted);
  background: var(--surface);
  transition: all 0.15s;
  font-family: inherit;
}

.nav-btn:hover {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-light);
}

/* ── Rank badge ── */
.rank {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px; height: 22px;
  border-radius: 50%;
  font-size: 0.72rem;
  font-weight: 800;
  background: var(--surface2);
  color: var(--text-muted);
  flex-shrink: 0;
}

.rank-1 {
  background: var(--green);
  color: #fff;
}

.rank-2 {
  background: rgba(22,163,74,0.3);
  color: var(--green);
}

/* ── Loader ── */
.loader {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 48px;
  flex-direction: column;
  gap: 12px;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.spinner {
  width: 28px; height: 28px;
  border: 2.5px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}

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

/* ── Empty state ── */
.empty {
  text-align: center;
  padding: 48px 20px;
  color: var(--text-muted);
}

.empty-icon { margin-bottom: 12px; display: flex; justify-content: center; }
.empty p { font-size: 0.9rem; line-height: 1.6; }

/* ── Toast ── */
.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: #fff;
  padding: 10px 20px;
  border-radius: 20px;
  font-size: 0.85rem;
  font-weight: 500;
  z-index: 9999;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.25s;
  white-space: nowrap;
  box-shadow: var(--shadow-md);
}

.toast.show { opacity: 1; }

/* ── Leaflet overrides ── */
.leaflet-container { background: #dde8f0; }

.leaflet-popup-content-wrapper {
  background: var(--surface);
  color: var(--text);
  border-radius: 10px;
  border: 1.5px solid var(--border);
  box-shadow: var(--shadow-md);
}

.leaflet-popup-tip { background: var(--surface); }

.leaflet-popup-content {
  margin: 12px 14px;
  font-size: 0.85rem;
  line-height: 1.5;
  font-family: -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', sans-serif;
}

.leaflet-control-zoom a {
  border-radius: 8px !important;
  border: 1.5px solid var(--border) !important;
  color: var(--text) !important;
  font-weight: 700 !important;
}

.leaflet-bar { border-radius: 8px !important; overflow: hidden; box-shadow: var(--shadow) !important; }

/* ── Mode Tabs ── */
.mode-tabs {
  display: flex;
  gap: 6px;
  padding-bottom: 2px;
}

.mode-tab {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  background: var(--bg);
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.15s;
  flex: 1;
  justify-content: center;
}

.mode-tab:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-light);
}

.mode-tab.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* ── Route Inputs ── */
.route-inputs {
  display: flex;
  flex-direction: column;
  gap: 0;
  margin-bottom: 10px;
}

.route-input-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.route-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
  border: 2px solid #fff;
  box-shadow: 0 0 0 2px currentColor;
}

.route-dot-start {
  color: var(--accent);
  background: var(--accent);
}

.route-dot-end {
  color: #e94560;
  background: #e94560;
}

.route-connector {
  width: 2px;
  height: 10px;
  background: var(--border);
  margin-left: 5px;
  margin-top: -2px;
  margin-bottom: -2px;
}

.btn-geo-sm {
  background: var(--accent);
  border: none;
  border-radius: var(--radius-sm);
  color: #fff;
  padding: 8px 10px;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s, transform 0.1s;
  line-height: 1;
  display: flex;
  align-items: center;
}

.btn-geo-sm:hover { background: var(--accent-hover); }
.btn-geo-sm:active { transform: scale(0.95); }

.btn-search-route {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  width: 100%;
  padding: 11px 16px;
  margin-top: 8px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s, transform 0.1s;
}

.btn-search-route:hover { background: var(--accent-hover); }
.btn-search-route:active { transform: scale(0.98); }

/* ── Route badge on result cards ── */
.badge-depart {
  background: var(--accent-light);
  color: var(--accent);
  border: 1px solid rgba(29,111,235,0.3);
}

.badge-arrivee {
  background: #FFF0F0;
  color: #e94560;
  border: 1px solid rgba(233,69,96,0.3);
}

.badge-trajet {
  background: var(--surface2);
  color: var(--text-muted);
  border: 1px solid var(--border);
}

/* ── Responsive ── */
@media (min-width: 600px) {
  #map { height: 320px; }
  .selectors { flex-wrap: nowrap; }
  #results { padding: 0 16px 24px; }
}

@media (min-width: 900px) {
  .app-layout {
    display: grid;
    grid-template-columns: 400px 1fr;
    grid-template-rows: auto 1fr;
    height: 100vh;
    overflow: hidden;
  }

  header { grid-column: 1 / -1; }

  .controls {
    grid-column: 1;
    border-right: 1px solid var(--border);
    border-bottom: none;
    overflow-y: auto;
  }

  .map-results {
    grid-column: 2;
    display: flex;
    flex-direction: column;
  }

  #map { flex: 1; height: auto; min-height: 300px; }

  #results { grid-column: 1; overflow-y: auto; }
  .results-header { grid-column: 1; }
}
