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

/* ── Theme tokens ─────────────────────────────────────────────────────────── */
:root {
  --tags-h:       0px;
  --bg:           #f5f5f5;
  --surface:      #ffffff;
  --surface2:     #efefef;
  --text:         #111111;
  --text-muted:   #666666;
  --accent:       #222222;
  --accent-dim:   #e5e5e5;
  --border:       #dcdcdc;
  --shadow-sm:    0 1px 4px rgba(0,0,0,0.10);
  --shadow:       0 4px 24px rgba(0,0,0,0.13);
  --header-h:     56px;
  --sheet-peek:   72px;
  --radius:       16px;
  --bus-ida:      #2563eb;
  --bus-volta:    #ea580c;
  --stop-normal:  #9ca3af;
  --stop-active:  #f59e0b;
  --user-color:   #10b981;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:           #0a0a0a;
    --surface:      #171717;
    --surface2:     #222222;
    --text:         #f0f0f0;
    --text-muted:   #888888;
    --accent:       #e5e5e5;
    --accent-dim:   #2a2a2a;
    --border:       #333333;
    --shadow-sm:    0 1px 4px rgba(0,0,0,0.4);
    --shadow:       0 4px 24px rgba(0,0,0,0.6);
    --bus-ida:      #60a5fa;
    --bus-volta:    #fb923c;
    --stop-normal:  #555555;
    --stop-active:  #fbbf24;
  }
}

/* ── Layout ──────────────────────────────────────────────────────────────── */
html, body {
  height: 100%; width: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 15px;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

/* ── Header ──────────────────────────────────────────────────────────────── */
.top-bar {
  position: fixed;
  inset: 0 0 auto 0;
  height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 10px 0 14px;
  z-index: 1000;
  box-shadow: var(--shadow-sm);
}

.app-brand {
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.app-brand img {
  width: 28px;
  height: 28px;
  border-radius: 6px;
}

/* Line search */
.search-wrap {
  flex: 1;
  position: relative;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 6px;
}

.search-mode-btn {
  flex-shrink: 0;
  background: none;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  padding: 5px 6px;
  cursor: pointer;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  line-height: 1;
}
.search-mode-btn:hover      { background: var(--surface2); color: var(--text); }
.search-mode-btn.active     { background: var(--accent-dim); color: var(--accent); border-color: var(--accent); }

.search-wrap input {
  flex: 1;
  min-width: 0;
  padding: 8px 12px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  background: var(--surface2);
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color 0.18s;
}

.search-wrap input::placeholder { color: var(--text-muted); }
.search-wrap input:focus { border-color: var(--accent); }

.line-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0; right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  max-height: 260px;
  overflow-y: auto;
  box-shadow: var(--shadow);
  z-index: 2000;
}

.line-dropdown:empty,
.line-dropdown[hidden] { display: none; }

.line-opt {
  padding: 11px 14px;
  cursor: pointer;
  font-size: 14px;
  border-bottom: 1px solid var(--border);
  transition: background 0.12s;
}

.line-opt:last-child { border-bottom: none; }
.line-opt:hover, .line-opt:active { background: var(--surface2); }
.line-opt .cod { font-weight: 600; color: var(--accent); margin-right: 6px; }

/* Icon buttons */
.icon-btn {
  flex-shrink: 0;
  background: none;
  border: none;
  padding: 8px;
  border-radius: 10px;
  cursor: pointer;
  color: var(--text);
  line-height: 1;
  font-size: 20px;
  transition: background 0.15s;
  display: flex;
  align-items: center;
}

.icon-btn:hover { background: var(--surface2); }
.icon-btn.spinning svg { animation: spin 0.9s linear infinite; }

/* ── Map ─────────────────────────────────────────────────────────────────── */
#map {
  position: fixed;
  inset: calc(var(--header-h) + var(--tags-h)) 0 var(--sheet-peek) 0;
  transition: bottom 0.3s ease;
}

/* ── Bottom sheet ────────────────────────────────────────────────────────── */
.sheet {
  position: fixed;
  inset: auto 0 0 0;
  height: calc(100dvh - var(--header-h) - 32px);
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  box-shadow: var(--shadow);
  transform: translateY(calc(100% - var(--sheet-peek)));
  transition: transform 0.32s cubic-bezier(0.4,0,0.2,1);
  z-index: 500;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sheet.open { transform: translateY(0); }

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

.sheet-peek-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 16px 8px;
  flex-shrink: 0;
  cursor: pointer;
}

.sheet-peek-title {
  flex: 1;
  font-weight: 600;
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sheet-peek-sub {
  font-size: 12px;
  color: var(--text-muted);
}

.sheet-divider {
  height: 1px;
  background: var(--border);
  margin: 0;
  flex-shrink: 0;
}

.sheet-body {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px 24px;
  overscroll-behavior: contain;
}

/* ── Sentido tabs ────────────────────────────────────────────────────────── */
.sentido-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
}

.stab {
  flex: 1;
  padding: 7px 0;
  border: 1.5px solid var(--border);
  border-radius: 20px;
  background: none;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  text-align: center;
}

.stab.active-ida  { border-color: var(--bus-ida);   background: var(--bus-ida);   color: white; }
.stab.active-volta{ border-color: var(--bus-volta); background: var(--bus-volta); color: white; }

/* ── Stop list ───────────────────────────────────────────────────────────── */
.stop-list { list-style: none; }

.stop-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 6px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  border-radius: 10px;
  transition: background 0.12s;
}

.stop-item:last-child { border-bottom: none; }
.stop-item:hover, .stop-item:active { background: var(--surface2); }

.stop-icon-wrap {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--accent-dim);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: var(--text-muted);
}

.stop-info { flex: 1; min-width: 0; }
.stop-name { font-weight: 500; font-size: 14px; }
.stop-sub  { font-size: 12px; color: var(--text-muted); margin-top: 1px; }

.stop-eta {
  font-weight: 700;
  font-size: 14px;
  color: var(--accent);
  flex-shrink: 0;
}

/* ── Vehicle list ────────────────────────────────────────────────────────── */
.vehicle-list { list-style: none; }

.vehicle-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 6px;
  border-bottom: 1px solid var(--border);
}

.vehicle-item:last-child { border-bottom: none; }

.vdot {
  width: 12px; height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
}

.vdot.ida   { background: var(--bus-ida); }
.vdot.volta { background: var(--bus-volta); }

.vehicle-info { flex: 1; min-width: 0; }
.v-line   { font-weight: 600; font-size: 14px; }
.v-detail { font-size: 12px; color: var(--text-muted); margin-top: 1px; }

.vehicle-eta {
  font-weight: 700;
  font-size: 14px;
  color: var(--accent);
  flex-shrink: 0;
}

/* ── Section header ──────────────────────────────────────────────────────── */
.sec-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-muted);
  padding: 10px 0 6px;
}

/* ── Loading / empty ─────────────────────────────────────────────────────── */
.center-msg {
  text-align: center;
  padding: 28px 12px;
  color: var(--text-muted);
  font-size: 14px;
}

.spinner {
  display: inline-block;
  width: 24px; height: 24px;
  border: 2.5px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
  vertical-align: middle;
}

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

/* ── Custom map markers ──────────────────────────────────────────────────── */
.bus-pin {
  width: 34px; height: 34px;
  border-radius: 50%;
  border: 2.5px solid white;
  box-shadow: 0 2px 8px rgba(0,0,0,0.35);
  display: flex;
  align-items: center;
  justify-content: center;
}

/* color is set inline per line */

.bus-pin svg { width: 18px; height: 18px; fill: white; }

.stop-pin {
  border-radius: 50%;
  border: 2px solid white;
  box-shadow: 0 1px 4px rgba(0,0,0,0.3);
  transition: transform 0.15s;
}

.user-pin {
  width: 16px; height: 16px;
  background: var(--user-color);
  border: 3px solid white;
  border-radius: 50%;
  box-shadow: 0 0 0 4px rgba(16,185,129,0.25);
  animation: user-pulse 2s ease-in-out infinite;
}

@keyframes user-pulse {
  0%, 100% { box-shadow: 0 0 0 4px rgba(16,185,129,0.25); }
  50%       { box-shadow: 0 0 0 9px rgba(16,185,129,0.08); }
}

/* ── Leaflet overrides ───────────────────────────────────────────────────── */
.leaflet-container { background: var(--bg) !important; }
.leaflet-control-zoom a {
  background: var(--surface) !important;
  color: var(--text) !important;
  border-color: var(--border) !important;
}
.leaflet-popup-content-wrapper {
  background: var(--surface);
  color: var(--text);
  border-radius: 12px;
  box-shadow: var(--shadow);
}
.leaflet-popup-tip { background: var(--surface); }

.leaflet-control-attribution {
  background: var(--surface) !important;
  color: var(--text-muted) !important;
  border-radius: 6px 0 0 0 !important;
  font-size: 10px !important;
  padding: 2px 6px !important;
  box-shadow: none !important;
}

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

/* ── Desktop: sidebar instead of bottom sheet ───────────────────────────── */
@media (min-width: 640px) {
  .line-tags-bar { right: 340px; }

  #map {
    right: 340px;
    bottom: 0;
    transition: none;
  }

  .sheet {
    inset: calc(var(--header-h) + var(--tags-h)) 0 0 auto;
    width: 340px;
    height: auto;
    border-radius: 0;
    border-left: 1px solid var(--border);
    box-shadow: none;
    transform: none !important;
  }

  .sheet-drag,
  .sheet-peek-row { display: none; }

  .sheet-body { padding-top: 16px; }
}

/* ── Selected stop highlight ─────────────────────────────────────────────── */
.stop-selected {
  background: var(--accent-dim) !important;
  border-radius: 10px;
}

.stop-selected .stop-name { color: var(--accent); }

/* ── Timeline stop list ──────────────────────────────────────────────────── */
.timeline { list-style: none; padding: 0 0 0 4px; }

.tl-item {
  display: flex;
  align-items: flex-start;
  gap: 0;
  position: relative;
  cursor: pointer;
  transition: background 0.12s;
  border-radius: 8px;
  padding: 1px 6px 1px 0;
}
.tl-item:hover, .tl-item:active { background: var(--surface2); }

/* Incoming row highlight */
.tl-item.tl-incoming {
  background: color-mix(in srgb, var(--bus-ida) 6%, transparent);
  border-radius: 8px;
}
.tl-item.tl-incoming:hover { background: color-mix(in srgb, var(--bus-ida) 10%, transparent); }

/* Vertical line + dot column */
.tl-rail {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex-shrink: 0;
  width: 30px;
}

/* Dot base */
.tl-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
  z-index: 1;
  transition: transform 0.15s, box-shadow 0.15s;
  box-sizing: border-box;
}
.tl-item:hover .tl-dot { transform: scale(1.2); }

/* Direction colors */
.tl-dot.ida   { background: var(--bus-ida); }
.tl-dot.volta { background: var(--bus-volta); }
.tl-dot.both  { background: var(--stop-normal); }

/* Terminal: rounded square */
.tl-dot.terminal { width: 13px; height: 13px; border-radius: 3px; }

/* Selected */
.tl-dot.selected { width: 14px; height: 14px; background: #f59e0b !important; box-shadow: 0 0 0 3px rgba(245,158,11,0.3) !important; border: none !important; }

/* Passed: small grey dot */
.tl-dot.passed {
  width: 7px; height: 7px;
  background: var(--text-muted) !important;
  border: none !important;
  box-shadow: none !important;
}

/* Upcoming: hollow */
.tl-dot.upcoming {
  background: var(--surface) !important;
  box-shadow: none !important;
}
.tl-dot.upcoming.ida   { border: 2px solid var(--bus-ida); }
.tl-dot.upcoming.volta { border: 2px solid var(--bus-volta); }
.tl-dot.upcoming.both  { border: 2px solid var(--stop-normal); }
.tl-dot.upcoming.terminal { border-width: 2.5px; }

/* Incoming: larger, glowing, pulsing */
.tl-dot.incoming { width: 13px; height: 13px; }
.tl-dot.incoming.ida   { box-shadow: 0 0 0 4px color-mix(in srgb, var(--bus-ida)   28%, transparent); animation: tl-pulse-ida   1.5s ease-in-out infinite; }
.tl-dot.incoming.volta { box-shadow: 0 0 0 4px color-mix(in srgb, var(--bus-volta) 28%, transparent); animation: tl-pulse-volta 1.5s ease-in-out infinite; }
.tl-dot.incoming.both  { box-shadow: 0 0 0 4px color-mix(in srgb, var(--stop-normal) 28%, transparent); }

@keyframes tl-pulse-ida {
  0%, 100% { box-shadow: 0 0 0 3px color-mix(in srgb, var(--bus-ida) 28%, transparent); }
  50%       { box-shadow: 0 0 0 9px color-mix(in srgb, var(--bus-ida)  8%, transparent); }
}
@keyframes tl-pulse-volta {
  0%, 100% { box-shadow: 0 0 0 3px color-mix(in srgb, var(--bus-volta) 28%, transparent); }
  50%       { box-shadow: 0 0 0 9px color-mix(in srgb, var(--bus-volta)  8%, transparent); }
}

/* Line connecting dots */
.tl-line {
  width: 2px;
  flex: 1;
  min-height: 16px;
  background: var(--border);
}
.tl-line.passed.ida   { background: var(--bus-ida);     opacity: 0.7; width: 3px; }
.tl-line.passed.volta { background: var(--bus-volta);   opacity: 0.7; width: 3px; }
.tl-line.passed.both  { background: var(--stop-normal); opacity: 0.7; width: 3px; }
.tl-line.upcoming     { background: var(--border); opacity: 0.35; }
.tl-line.ida          { background: color-mix(in srgb, var(--bus-ida)   25%, var(--border)); }
.tl-line.volta        { background: color-mix(in srgb, var(--bus-volta) 25%, var(--border)); }
.tl-line.both         { background: var(--border); }

/* Content */
.tl-content {
  flex: 1;
  padding: 5px 0 5px 6px;
  min-width: 0;
}
.tl-content.passed   { opacity: 0.35; }
.tl-content.upcoming { opacity: 0.6; }
.tl-content.incoming { opacity: 1; }

.tl-row {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.tl-name {
  flex: 1;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tl-content.incoming .tl-name { font-weight: 700; font-size: 14px; }

.tl-sub {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 1px;
}

/* Bus ETA chips */
.tl-buses {
  display: flex;
  gap: 3px;
  flex-shrink: 0;
  align-items: center;
}
.tl-bus {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 9px;
  white-space: nowrap;
  letter-spacing: 0.01em;
}
.tl-bus.ida   { background: var(--bus-ida);   color: white; }
.tl-bus.volta { background: var(--bus-volta); color: white; }

/* ── Favorites ───────────────────────────────────────────────────────────── */
.fav-list { list-style: none; }

.fav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 4px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  border-radius: 8px;
  transition: background 0.12s;
}
.fav-item:last-child { border-bottom: none; }
.fav-item:active { background: var(--surface2); }

.fav-icon { font-size: 20px; flex-shrink: 0; line-height: 1; }

.fav-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.fav-name {
  font-weight: 600;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.fav-sub { font-size: 12px; color: var(--text-muted); }

.fav-empty { font-size: 13px; color: var(--text-muted); padding: 4px 0 12px; }

.fav-btn-rm,
.fav-btn-rename {
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px;
  font-size: 14px;
  opacity: 0.55;
  flex-shrink: 0;
  line-height: 1;
}
.fav-btn-rm:hover, .fav-btn-rename:hover { opacity: 1; }

.btn-back {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  padding: 4px 0;
  transition: color 0.15s;
}
.btn-back:hover { color: var(--text); }

.btn-fav-save {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: none;
  border: 1.5px solid var(--border);
  border-radius: 20px;
  padding: 4px 12px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  margin-bottom: 12px;
  transition: border-color 0.15s, color 0.15s;
}
.btn-fav-save:hover { border-color: var(--accent); color: var(--text); }

/* ── Line tags bar ──────────────────────────────────────────────────────── */
.line-tags-bar {
  position: fixed;
  top: var(--header-h);
  left: 0; right: 0;
  height: var(--tags-h);
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 12px;
  overflow-x: auto;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  z-index: 999;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.line-tags-bar::-webkit-scrollbar { display: none; }

.line-tag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 8px 3px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
  color: white;
  flex-shrink: 0;
  cursor: pointer;
  opacity: 0.7;
  transition: opacity 0.15s;
  text-shadow: 0 1px 2px rgba(0,0,0,0.25);
}
.line-tag.focused { opacity: 1; box-shadow: 0 0 0 2px white, 0 0 0 4px rgba(0,0,0,0.3); }

.tag-x {
  font-size: 13px;
  font-weight: 400;
  opacity: 0.85;
  line-height: 1;
  padding: 1px 2px;
  cursor: pointer;
}

/* ── ETA list (stop detail) ─────────────────────────────────────────────── */
.eta-list { list-style: none; display: flex; flex-direction: column; gap: 6px; }

.eta-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  border-radius: 8px;
  padding: 3px 4px;
  transition: background 0.12s;
}
.eta-item[data-lid] { cursor: pointer; }
.eta-item[data-lid]:hover { background: var(--surface2); }

.eta-dir {
  min-width: 38px;
  font-weight: 600;
  color: var(--text-muted);
}

.eta-badge {
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 600;
}

.eta-badge.passed   { background: color-mix(in srgb, #22c55e 15%, transparent); color: #22c55e; }
.eta-badge.upcoming { background: color-mix(in srgb, var(--accent) 10%, transparent); color: var(--text-muted); }

/* ── Welcome screen buttons ─────────────────────────────────────────────── */
.welcome-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border-radius: 12px;
  border: none;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
  text-align: left;
  transition: opacity 0.15s, transform 0.1s;
}
.welcome-btn:active { transform: scale(0.98); opacity: 0.85; }
.welcome-btn.primary   { background: var(--accent); color: var(--surface); }
.welcome-btn.secondary { background: var(--surface2); color: var(--text); border: 1.5px solid var(--border); }

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