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

:root {
  --bg: #0f1923;
  --bg2: #1a2535;
  --bg3: #232f42;
  --surface: #1e2d3f;
  --border: rgba(255,255,255,0.08);
  --border2: rgba(255,255,255,0.15);
  --text: #f0f4f8;
  --text2: #8fa3b8;
  --text3: #556070;
  --accent: #1a9e6e;
  --accent2: #13c47a;
  --radius: 14px;
  --sheet-h: 320px;
  --topbar-h: 56px;
}

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  font-family: 'DM Sans', sans-serif;
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

/* Splash */
#splash {
  position: fixed; inset: 0; z-index: 9999;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  transition: opacity 0.4s ease;
}
#splash.fade-out { opacity: 0; pointer-events: none; }
.splash-inner { text-align: center; }
.splash-logo { margin-bottom: 16px; animation: pulse 1.5s ease infinite; }
@keyframes pulse { 0%,100%{transform:scale(1)} 50%{transform:scale(1.06)} }
.splash-title { font-family: 'Space Mono', monospace; font-size: 28px; font-weight: 700; letter-spacing: -0.5px; }
.splash-sub { font-size: 14px; color: var(--text2); margin-top: 6px; }
.splash-loader { margin: 24px auto 0; width: 36px; height: 4px; background: var(--bg3); border-radius: 2px; overflow: hidden; }
.splash-loader div { height: 100%; width: 40%; background: var(--accent); border-radius: 2px; animation: load 1.2s ease infinite; }
@keyframes load { 0%{transform:translateX(-100%)} 100%{transform:translateX(350%)} }

/* App layout */
#app { position: fixed; inset: 0; display: flex; flex-direction: column; }
.hidden { display: none !important; }

/* Topbar */
.topbar {
  height: var(--topbar-h);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center;
  padding: 0 16px;
  gap: 12px;
  z-index: 100;
  flex-shrink: 0;
}
.topbar-left { flex: 1; }
.topbar-right { display: flex; gap: 8px; }

.city-pill {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--bg3);
  border: 1px solid var(--border2);
  border-radius: 20px;
  padding: 6px 12px 6px 10px;
  font-size: 14px; font-weight: 500; color: var(--text);
  cursor: pointer; transition: background 0.15s;
}
.city-pill:active { background: var(--surface); }
#city-flag { font-size: 18px; line-height: 1; }

.icon-btn {
  width: 36px; height: 36px; border-radius: 10px;
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text2);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: background 0.15s;
}
.icon-btn:active { background: var(--surface); }
.icon-btn.active { color: var(--accent); border-color: var(--accent); }

/* Search bar */
#search-bar {
  position: absolute;
  top: var(--topbar-h); left: 0; right: 0;
  z-index: 200;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  padding: 10px 16px;
}
#search-input {
  width: 100%; padding: 10px 14px;
  background: var(--bg3);
  border: 1px solid var(--border2);
  border-radius: 10px;
  color: var(--text); font-size: 15px;
  outline: none;
}
#search-input::placeholder { color: var(--text3); }
#search-results { margin-top: 8px; }
.search-item {
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 14px; cursor: pointer;
  display: flex; align-items: center; gap: 10px;
  transition: background 0.1s;
}
.search-item:hover, .search-item:active { background: var(--bg3); }
.search-item-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.search-item-name { font-weight: 500; }
.search-item-line { font-size: 12px; color: var(--text2); }

/* Map */
#map {
  flex: 1;
  position: relative;
  z-index: 1;
}

/* Override leaflet for dark theme */
.leaflet-container { background: #0e1c2a !important; }
.leaflet-tile-pane { filter: brightness(0.85) saturate(0.7); }
.leaflet-popup-content-wrapper {
  background: var(--bg2);
  border: 1px solid var(--border2);
  border-radius: 12px;
  color: var(--text);
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
}
.leaflet-popup-tip { background: var(--bg2); }
.leaflet-popup-content { margin: 12px 14px; }
.popup-name { font-weight: 600; font-size: 14px; margin-bottom: 4px; }
.popup-line { font-size: 12px; color: var(--text2); margin-bottom: 8px; }
.popup-actions { display: flex; gap: 6px; }
.popup-btn {
  flex: 1; padding: 6px 8px;
  background: var(--bg3);
  border: 1px solid var(--border2);
  border-radius: 8px;
  color: var(--text2); font-size: 12px;
  cursor: pointer; text-align: center;
  transition: background 0.15s;
}
.popup-btn:hover { background: var(--accent); color: white; border-color: var(--accent); }

/* Bottom sheet */
#bottom-sheet {
  position: relative;
  z-index: 50;
  background: var(--bg);
  border-top: 1px solid var(--border);
  height: var(--sheet-h);
  flex-shrink: 0;
  overflow: hidden;
  display: flex; flex-direction: column;
}

.sheet-handle {
  width: 36px; height: 4px;
  background: var(--border2);
  border-radius: 2px;
  margin: 10px auto 0;
  flex-shrink: 0;
}

/* Tabs */
.tab-nav {
  display: flex;
  padding: 8px 12px 0;
  gap: 4px;
  flex-shrink: 0;
}
.tab {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 7px 4px;
  border-radius: 10px;
  font-size: 11px; font-weight: 500; color: var(--text3);
  cursor: pointer; transition: all 0.15s;
  background: transparent; border: none;
}
.tab.active { background: var(--bg3); color: var(--accent); }
.tab svg { opacity: 0.6; }
.tab.active svg { opacity: 1; }

.tab-content {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px;
  -webkit-overflow-scrolling: touch;
}

/* Planner */
.planner-form {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  position: relative;
  margin-bottom: 12px;
}
.planner-field {
  display: flex; align-items: center; gap: 10px;
}
.planner-field + .planner-field { margin-top: 10px; }
.planner-dot {
  width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0;
}
.planner-dot.from { background: var(--accent); }
.planner-dot.to { background: #e25b4a; }

.station-select {
  flex: 1;
  background: var(--bg3);
  border: 1px solid var(--border2);
  border-radius: 8px;
  padding: 9px 12px;
  color: var(--text); font-size: 14px;
  outline: none; cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
}

.swap-btn {
  position: absolute;
  right: 14px; top: 50%; transform: translateY(-50%);
  width: 30px; height: 30px;
  background: var(--bg3);
  border: 1px solid var(--border2);
  border-radius: 8px;
  color: var(--text2);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; z-index: 2;
}

.go-btn {
  width: 100%;
  padding: 13px;
  background: var(--accent);
  border: none;
  border-radius: 12px;
  color: white; font-size: 15px; font-weight: 600;
  cursor: pointer; transition: background 0.15s, transform 0.1s;
  letter-spacing: 0.3px;
}
.go-btn:active { background: var(--accent2); transform: scale(0.98); }

/* Route result */
#route-result, #fare-result {
  margin-top: 12px;
}

.route-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}
.route-meta {
  display: flex; gap: 12px; margin-bottom: 14px;
}
.route-stat {
  flex: 1;
  background: var(--bg3);
  border-radius: 10px;
  padding: 10px;
  text-align: center;
}
.route-stat-val { font-family: 'Space Mono', monospace; font-size: 18px; font-weight: 700; }
.route-stat-lbl { font-size: 11px; color: var(--text2); margin-top: 2px; }

.route-steps { display: flex; flex-direction: column; gap: 0; }
.route-step {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.route-step:last-child { border-bottom: none; }
.step-icon {
  width: 24px; height: 24px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700; flex-shrink: 0;
  margin-top: 1px;
}
.step-text { flex: 1; line-height: 1.5; }
.step-label { color: var(--text2); font-size: 11px; }

/* Fare */
.fare-form { margin-bottom: 12px; }
.ticket-type-row {
  display: flex; align-items: center; justify-content: space-between;
  margin-top: 12px;
  font-size: 13px; color: var(--text2);
}
.ticket-toggle { display: flex; gap: 4px; }
.toggle-btn {
  padding: 6px 12px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text2); font-size: 12px;
  cursor: pointer; transition: all 0.15s;
}
.toggle-btn.active {
  background: rgba(26,158,110,0.2);
  border-color: var(--accent);
  color: var(--accent);
}

.fare-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  text-align: center;
}
.fare-amount {
  font-family: 'Space Mono', monospace;
  font-size: 36px; font-weight: 700;
  color: var(--accent);
}
.fare-currency { font-size: 18px; margin-right: 4px; }
.fare-desc { font-size: 13px; color: var(--text2); margin-top: 6px; }
.fare-breakdown {
  margin-top: 14px;
  text-align: left;
  font-size: 13px;
}
.fare-row {
  display: flex; justify-content: space-between;
  padding: 6px 0;
  border-top: 1px solid var(--border);
}

/* Lines tab */
.line-item {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 0;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.1s;
}
.line-item:last-child { border-bottom: none; }
.line-dot { width: 14px; height: 14px; border-radius: 50%; flex-shrink: 0; }
.line-name { font-weight: 500; font-size: 14px; flex: 1; }
.line-count { font-size: 12px; color: var(--text2); }
.line-badge {
  font-size: 11px; font-weight: 600;
  padding: 3px 8px; border-radius: 20px;
  letter-spacing: 0.3px;
}

/* Info tab */
.info-card h3 { font-size: 16px; font-weight: 600; }
.info-stats {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 8px; margin-top: 14px;
}
.info-stat {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
}
.info-stat-val { font-family: 'Space Mono', monospace; font-size: 18px; font-weight: 700; color: var(--accent); }
.info-stat-lbl { font-size: 11px; color: var(--text2); margin-top: 2px; }
.info-tips { margin-top: 14px; }
.info-tips h4 { font-size: 13px; color: var(--text2); margin-bottom: 8px; text-transform: uppercase; letter-spacing: 0.5px; }
.tip-item {
  display: flex; gap: 10px;
  font-size: 13px;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
  line-height: 1.5;
}
.tip-item:last-child { border-bottom: none; }
.tip-icon { flex-shrink: 0; font-size: 15px; }

/* City modal */
.modal {
  position: fixed; inset: 0; z-index: 500;
  display: flex; align-items: flex-end;
}
.modal-backdrop {
  position: absolute; inset: 0;
  background: rgba(0,0,0,0.6);
}
.modal-sheet {
  position: relative; z-index: 1;
  width: 100%;
  background: var(--bg);
  border-radius: 20px 20px 0 0;
  border-top: 1px solid var(--border2);
  padding: 0 0 40px;
  animation: slideUp 0.25s ease;
}
@keyframes slideUp { from{transform:translateY(100%)} to{transform:translateY(0)} }
.modal-handle { width: 36px; height: 4px; background: var(--border2); border-radius: 2px; margin: 12px auto; }
.modal-title { font-size: 14px; font-weight: 600; color: var(--text2); text-transform: uppercase; letter-spacing: 0.8px; padding: 0 20px 10px; }

.city-option {
  display: flex; align-items: center; gap: 14px;
  padding: 14px 20px;
  cursor: pointer; transition: background 0.1s;
  border-bottom: 1px solid var(--border);
}
.city-option:last-child { border-bottom: none; }
.city-option:active { background: var(--bg2); }
.city-option.active { background: rgba(26,158,110,0.08); }
.city-flag-lg { font-size: 28px; line-height: 1; }
.city-opt-name { font-weight: 600; font-size: 15px; }
.city-opt-lines { font-size: 12px; color: var(--text2); margin-top: 2px; }
.city-check { margin-left: auto; color: var(--accent); opacity: 0; }
.city-option.active .city-check { opacity: 1; }

/* Layers panel */
.panel {
  position: absolute;
  top: calc(var(--topbar-h) + 8px);
  right: 12px;
  background: var(--bg2);
  border: 1px solid var(--border2);
  border-radius: var(--radius);
  padding: 12px 14px;
  z-index: 200;
  min-width: 180px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
  animation: fadeIn 0.15s ease;
}
@keyframes fadeIn { from{opacity:0;transform:scale(0.95)} to{opacity:1;transform:scale(1)} }
.panel-title { font-size: 11px; font-weight: 600; color: var(--text2); text-transform: uppercase; letter-spacing: 0.6px; margin-bottom: 10px; }
.layer-toggle {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 0;
  cursor: pointer;
}
.layer-toggle + .layer-toggle { border-top: 1px solid var(--border); }
.layer-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.layer-label { font-size: 13px; flex: 1; }
.layer-switch {
  width: 32px; height: 18px;
  background: var(--bg3);
  border-radius: 9px;
  position: relative;
  transition: background 0.2s;
}
.layer-switch.on { background: var(--accent); }
.layer-switch::after {
  content: ''; position: absolute;
  width: 14px; height: 14px;
  border-radius: 50%; background: white;
  top: 2px; left: 2px;
  transition: transform 0.2s;
}
.layer-switch.on::after { transform: translateX(14px); }

/* Station marker custom */
.station-marker {
  width: 10px; height: 10px;
  border-radius: 50%;
  border: 2px solid white;
  cursor: pointer;
  transition: transform 0.15s;
}
.station-marker:hover { transform: scale(1.4); }
.station-marker.interchange {
  width: 14px; height: 14px;
  border-width: 2.5px;
}

/* Scrollbar */
::-webkit-scrollbar { width: 3px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 2px; }

/* Error / empty states */
.empty-state {
  text-align: center; padding: 20px;
  color: var(--text2); font-size: 13px;
}
.error-msg {
  background: rgba(226,91,74,0.15);
  border: 1px solid rgba(226,91,74,0.3);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 13px; color: #e25b4a;
}

/* Station name labels */
.station-label {
  white-space: nowrap;
  font-size: 10px;
  font-weight: 500;
  color: #e8f0f8;
  background: rgba(15,25,35,0.82);
  border-left: 2px solid;
  padding: 2px 5px;
  border-radius: 3px;
  pointer-events: none;
  line-height: 1.3;
  letter-spacing: 0.1px;
  backdrop-filter: blur(2px);
}

/* Route station labels */
.route-station-label {
  white-space: nowrap;
  font-size: 11px;
  font-weight: 500;
  color: #c8fce4;
  background: rgba(0,30,20,0.85);
  border-left: 2px solid #00e87a;
  padding: 2px 6px;
  border-radius: 3px;
  pointer-events: none;
  line-height: 1.4;
}
.route-station-label.endpoint {
  font-weight: 700;
  font-size: 12px;
  color: #00e87a;
  border-left-width: 3px;
}

/* Route view toggle */
.route-view-toggle {
  display: flex;
  gap: 6px;
  margin-bottom: 12px;
}
.route-view-btn {
  flex: 1;
  padding: 7px 10px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text2);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}
.route-view-btn.active {
  background: rgba(0,232,122,0.12);
  border-color: #00e87a;
  color: #00e87a;
}

/* Airport line styles */
.airport-badge {
  font-size: 10px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 20px;
  background: rgba(124,58,237,0.18);
  color: #a78bfa;
  letter-spacing: 0.3px;
  flex-shrink: 0;
}
.line-airport-note {
  font-size: 11px;
  color: #a78bfa;
  margin-top: 4px;
  line-height: 1.4;
}

/* ── AI Chat FAB ──────────────────────────────────────────────── */
#chat-fab {
  position: fixed;
  bottom: 24px; right: 16px;
  width: 52px; height: 52px;
  border-radius: 50%;
  background: var(--bg2);
  border: 1.5px solid var(--border2);
  color: var(--text);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  box-shadow: 0 4px 24px rgba(0,0,0,0.5);
  z-index: 300;
  transition: background 0.2s, transform 0.15s;
}
#chat-fab:active { transform: scale(0.94); }
#chat-fab.active { background: var(--bg3); border-color: var(--accent); }

/* ── Chat Panel ───────────────────────────────────────────────── */
#chat-panel {
  position: fixed;
  bottom: 88px; right: 12px;
  width: calc(100vw - 24px);
  max-width: 380px;
  max-height: 70vh;
  background: var(--bg);
  border: 1px solid var(--border2);
  border-radius: 18px;
  box-shadow: 0 16px 48px rgba(0,0,0,0.7);
  z-index: 299;
  display: flex; flex-direction: column;
  overflow: hidden;
  transform: scale(0.92) translateY(20px);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.2s cubic-bezier(0.34,1.56,0.64,1), opacity 0.2s ease;
}
#chat-panel.open {
  transform: scale(1) translateY(0);
  opacity: 1;
  pointer-events: all;
}

.chat-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  flex-shrink: 0;
  background: var(--bg2);
}
.chat-header-left { display: flex; align-items: center; gap: 10px; }
.chat-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, #1a9e6e, #0ea5e9);
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 700; color: white;
}
.chat-title { font-size: 13px; font-weight: 600; }
.chat-subtitle { font-size: 11px; color: var(--text2); margin-top: 1px; }
.chat-close-btn {
  width: 28px; height: 28px;
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text2);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
}

#chat-messages {
  flex: 1; overflow-y: auto;
  padding: 12px 14px;
  display: flex; flex-direction: column; gap: 8px;
  -webkit-overflow-scrolling: touch;
}

.chat-msg {
  max-width: 88%;
  padding: 10px 13px;
  border-radius: 14px;
  font-size: 13px;
  line-height: 1.55;
}
.chat-msg.user {
  background: var(--accent);
  color: white;
  align-self: flex-end;
  border-bottom-right-radius: 4px;
}
.chat-msg.assistant {
  background: var(--bg3);
  color: var(--text);
  align-self: flex-start;
  border-bottom-left-radius: 4px;
}
.chat-msg.assistant code {
  background: rgba(255,255,255,0.08);
  padding: 1px 5px;
  border-radius: 4px;
  font-family: 'Space Mono', monospace;
  font-size: 11px;
}
.chat-note {
  align-self: center;
  font-size: 11px; color: var(--accent);
  background: rgba(26,158,110,0.1);
  border: 1px solid rgba(26,158,110,0.2);
  padding: 4px 10px; border-radius: 20px;
}

/* Typing indicator */
.chat-msg.typing {
  display: flex; gap: 5px; align-items: center;
  padding: 12px 16px;
}
.chat-msg.typing span {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--text3);
  animation: typingBounce 1.2s ease infinite;
}
.chat-msg.typing span:nth-child(2) { animation-delay: 0.2s; }
.chat-msg.typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typingBounce {
  0%,60%,100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-6px); opacity: 1; }
}

/* Suggestion chips */
.chat-chips {
  padding: 8px 12px;
  display: flex; gap: 6px; flex-wrap: wrap;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.chip {
  padding: 5px 10px;
  background: var(--bg3);
  border: 1px solid var(--border2);
  border-radius: 20px;
  font-size: 11px; color: var(--text2);
  cursor: pointer; white-space: nowrap;
  transition: background 0.15s;
}
.chip:active { background: var(--surface); }

/* Chat input */
.chat-input-row {
  display: flex; gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--bg2);
}
#chat-input {
  flex: 1;
  background: var(--bg3);
  border: 1px solid var(--border2);
  border-radius: 10px;
  padding: 9px 12px;
  color: var(--text); font-size: 13px;
  outline: none;
}
#chat-input::placeholder { color: var(--text3); }
#chat-input:disabled { opacity: 0.5; }
#chat-send-btn {
  width: 36px; height: 36px;
  background: var(--accent);
  border: none; border-radius: 10px;
  color: white;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; flex-shrink: 0;
  transition: background 0.15s;
}
#chat-send-btn:disabled { opacity: 0.5; cursor: not-allowed; }
#chat-send-btn:active { background: var(--accent2); }

/* ── Bus layer styles ─────────────────────────────────────────── */
.lines-section-header {
  font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.6px;
  color: var(--text2);
  padding: 12px 0 6px;
  border-top: 1px solid var(--border);
  margin-top: 4px;
}
