/* ============================================================
   BUSNOW — style.css
   Dark, utilitarian, Citymapper-inspired
   ============================================================ */

/* ── Variables ─────────────────────────────────────────────── */
:root {
  --bg:          #0a0a0f;
  --bg-panel:    #111118;
  --bg-card:     #1a1a24;
  --bg-card-hover: #20202e;
  --border:      rgba(255,255,255,0.07);
  --border-med:  rgba(255,255,255,0.12);

  --accent:      #00e5a0;       /* TfL-ish green */
  --accent-dim:  rgba(0,229,160,0.12);
  --accent-bus:  #e8c23a;       /* bus yellow */
  --red:         #ff4444;

  --text-primary:   #f0f0f5;
  --text-secondary: #8888a8;
  --text-muted:     #55556a;

  --font-display: 'Syne', sans-serif;
  --font-mono:    'DM Mono', monospace;

  --radius-sm:   6px;
  --radius-md:   12px;
  --radius-lg:   20px;

  --panel-height: 52vh;
  --header-h:     56px;
  --safe-bottom:  env(safe-area-inset-bottom, 0px);
}

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

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text-primary);
  font-family: var(--font-display);
  -webkit-font-smoothing: antialiased;
}

/* ── Header ─────────────────────────────────────────────────── */
.app-header {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--header-h);
  z-index: 900;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
  padding-top: env(safe-area-inset-top, 0px);
  background: rgba(10,10,15,0.85);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.logo-icon {
  font-size: 22px;
  color: var(--accent);
  line-height: 1;
}

.logo-text {
  font-size: 18px;
  font-weight: 800;
  letter-spacing: -0.5px;
  color: var(--text-primary);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.live-badge {
  display: flex;
  align-items: center;
  gap: 5px;
  background: var(--accent-dim);
  border: 1px solid rgba(0,229,160,0.25);
  border-radius: 999px;
  padding: 3px 10px;
}

.live-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse-dot 1.6s ease-in-out infinite;
}

.live-label {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 1px;
  color: var(--accent);
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: 0.4; transform: scale(0.8); }
}

.btn-locate, .btn-refresh {
  width: 36px; height: 36px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-med);
  background: var(--bg-card);
  color: var(--text-secondary);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: all 0.18s ease;
}
.btn-locate svg, .btn-refresh svg { width: 16px; height: 16px; }

.btn-locate:hover, .btn-refresh:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-dim);
}

.btn-refresh.spinning svg {
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Map Panel ──────────────────────────────────────────────── */
.map-panel {
  position: fixed;
  top: var(--header-h);
  left: 0; right: 0;
  height: calc(100vh - var(--header-h) - var(--panel-height));
  z-index: 1;
}

#map {
  width: 100%; height: 100%;
}

.map-gradient-bottom {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 60px;
  background: linear-gradient(to bottom, transparent, var(--bg));
  pointer-events: none;
  z-index: 500;
}

.radius-chip {
  position: absolute;
  top: 12px; left: 50%;
  transform: translateX(-50%);
  z-index: 600;
  background: rgba(10,10,15,0.75);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border-med);
  border-radius: 999px;
  padding: 4px 12px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-secondary);
  pointer-events: none;
}

/* ── Leaflet overrides ──────────────────────────────────────── */
.leaflet-container {
  background: #13131e !important;
  font-family: var(--font-display) !important;
}

.leaflet-control-zoom {
  border: 1px solid var(--border-med) !important;
  border-radius: var(--radius-sm) !important;
  overflow: hidden;
}

.leaflet-control-zoom a {
  background: var(--bg-card) !important;
  color: var(--text-secondary) !important;
  border: none !important;
  border-bottom: 1px solid var(--border) !important;
}

.leaflet-control-zoom a:hover {
  background: var(--bg-card-hover) !important;
  color: var(--accent) !important;
}

.leaflet-control-attribution {
  background: rgba(10,10,15,0.7) !important;
  color: var(--text-muted) !important;
  font-size: 9px !important;
}

.leaflet-control-attribution a { color: var(--text-muted) !important; }

/* Custom user marker */
.user-marker {
  width: 18px; height: 18px;
  background: var(--accent);
  border: 3px solid #fff;
  border-radius: 50%;
  box-shadow: 0 0 0 4px rgba(0,229,160,0.25), 0 2px 8px rgba(0,0,0,0.5);
}

.user-marker-pulse {
  width: 50px; height: 50px;
  background: rgba(0,229,160,0.12);
  border-radius: 50%;
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  animation: ring-pulse 2s ease-out infinite;
}

@keyframes ring-pulse {
  0%   { transform: translate(-50%,-50%) scale(0.4); opacity: 1; }
  100% { transform: translate(-50%,-50%) scale(1.4); opacity: 0; }
}

/* Bus stop marker */
.stop-marker {
  width: 28px; height: 28px;
  background: var(--bg-card);
  border: 2px solid var(--accent-bus);
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  font-size: 13px;
  font-weight: 700;
  color: var(--accent-bus);
  font-family: var(--font-display);
  box-shadow: 0 2px 8px rgba(0,0,0,0.5);
  cursor: pointer;
  transition: transform 0.15s;
}

.stop-marker.active {
  background: var(--accent-bus);
  color: var(--bg);
  transform: scale(1.15);
}

.stop-marker:hover { transform: scale(1.1); }

/* Leaflet popup */
.leaflet-popup-content-wrapper {
  background: var(--bg-card) !important;
  border: 1px solid var(--border-med) !important;
  border-radius: var(--radius-md) !important;
  color: var(--text-primary) !important;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5) !important;
  padding: 0 !important;
}

.leaflet-popup-content {
  margin: 0 !important;
}

.leaflet-popup-tip {
  background: var(--bg-card) !important;
}

.popup-inner {
  padding: 10px 14px;
  min-width: 140px;
}

.popup-name {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 2px;
}

.popup-dist {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-secondary);
}

/* ── Arrivals Panel ─────────────────────────────────────────── */
.arrivals-panel {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: var(--panel-height);
  z-index: 800;
  background: var(--bg-panel);
  border-top: 1px solid var(--border-med);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.panel-handle-bar {
  display: flex;
  justify-content: center;
  padding: 10px 0 4px;
  flex-shrink: 0;
}

.handle {
  width: 36px; height: 4px;
  border-radius: 999px;
  background: var(--border-med);
}

/* Panel Header */
.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 18px 10px;
  flex-shrink: 0;
}

.panel-title-area {}

.panel-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.3px;
  line-height: 1.3;
}

.panel-subtitle {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-secondary);
  margin-top: 2px;
}

/* Stop Tabs */
.stop-tabs-wrapper {
  padding: 0 18px 8px;
  flex-shrink: 0;
  overflow-x: auto;
  scrollbar-width: none;
}
.stop-tabs-wrapper::-webkit-scrollbar { display: none; }

.stop-tabs {
  display: flex;
  gap: 6px;
  width: max-content;
}

.stop-tab {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--border-med);
  background: var(--bg-card);
  color: var(--text-secondary);
  font-family: var(--font-display);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.stop-tab .tab-dist {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-muted);
}

.stop-tab:hover {
  border-color: var(--accent-bus);
  color: var(--text-primary);
}

.stop-tab.active {
  background: var(--accent-bus);
  border-color: var(--accent-bus);
  color: #111;
}

.stop-tab.active .tab-dist { color: rgba(0,0,0,0.5); }

/* Arrivals List */
.arrivals-list-wrapper {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0 14px;
  padding-bottom: calc(12px + var(--safe-bottom));
  scrollbar-width: thin;
  scrollbar-color: var(--border-med) transparent;
}

.arrivals-list-wrapper::-webkit-scrollbar { width: 3px; }
.arrivals-list-wrapper::-webkit-scrollbar-track { background: transparent; }
.arrivals-list-wrapper::-webkit-scrollbar-thumb { background: var(--border-med); border-radius: 999px; }

.arrivals-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* Arrival Card */
.arrival-card {
  display: grid;
  grid-template-columns: 52px 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  transition: all 0.15s ease;
  animation: card-in 0.25s ease both;
}

@keyframes card-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.arrival-card:hover {
  border-color: var(--border-med);
  background: var(--bg-card-hover);
}

.arrival-card.due-now {
  border-color: rgba(232,194,58,0.3);
  background: rgba(232,194,58,0.06);
}

/* Bus route badge */
.route-badge {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 36px;
  border-radius: var(--radius-sm);
  background: var(--accent-bus);
  color: #111;
  font-size: 14px;
  font-weight: 800;
  letter-spacing: -0.5px;
}

.route-badge.route-night {
  background: #1a1a60;
  color: #fff;
  border: 1px solid #3333aa;
}

/* Arrival info */
.arrival-info {}

.arrival-dest {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 180px;
}

.arrival-stop-name {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* Arrival time */
.arrival-time {
  text-align: right;
  flex-shrink: 0;
}

.time-value {
  font-family: var(--font-mono);
  font-size: 20px;
  font-weight: 500;
  color: var(--accent);
  line-height: 1;
}

.time-value.imminent { color: var(--accent-bus); }
.time-value.due      { color: var(--red); }

.time-unit {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* Section header (groups by time band) */
.arrivals-section-header {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 1.5px;
  color: var(--text-muted);
  text-transform: uppercase;
  padding: 8px 4px 4px;
}

/* States */
.state-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px 20px;
  gap: 12px;
  color: var(--text-muted);
}

.state-icon {
  font-size: 32px;
  color: var(--border-med);
  animation: spin-slow 8s linear infinite;
}

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

.state-empty p {
  font-family: var(--font-mono);
  font-size: 12px;
  text-align: center;
  line-height: 1.6;
  color: var(--text-muted);
}

.state-error {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px 20px;
  gap: 10px;
}

.state-error .err-icon { font-size: 24px; }
.state-error .err-msg {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--red);
  text-align: center;
}

/* Skeleton loader */
.skeleton-card {
  height: 60px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  position: relative;
}

.skeleton-card::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent 0%, rgba(255,255,255,0.04) 50%, transparent 100%);
  animation: shimmer 1.4s infinite;
}

@keyframes shimmer {
  from { transform: translateX(-100%); }
  to   { transform: translateX(100%); }
}

/* ── Toast ──────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: calc(var(--panel-height) + 14px);
  left: 50%; transform: translateX(-50%) translateY(6px);
  z-index: 1000;
  background: var(--bg-card);
  border: 1px solid var(--border-med);
  border-radius: 999px;
  padding: 8px 18px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  max-width: calc(100vw - 48px);
  text-align: center;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ── Responsive ─────────────────────────────────────────────── */
@media (min-width: 600px) {
  :root { --panel-height: 45vh; }

  .arrivals-panel {
    max-width: 480px;
    left: 50%;
    transform: translateX(-50%);
    border-left: 1px solid var(--border-med);
    border-right: 1px solid var(--border-med);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  }
}

@media (min-width: 900px) {
  :root { --panel-height: 40vh; }
}
