:root {
  --bg: #e9edf2;
  --card: #f8fafc;
  --ink: #0f172a;
  --muted: #475569;
  --line: #c7d2df;
  --accent: #0f766e;
  --accent-soft: #dff4f2;
  --warning: #b45309;
  --timeline-bg: #1f2937;
  --timeline-item: #334155;
  --timeline-item-active: #0f766e;
  --shadow: 0 12px 24px rgba(15, 23, 42, 0.14);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Outfit", sans-serif;
  color: var(--ink);
  background: var(--bg);
}

h1,
h2,
h3 {
  font-family: "Space Grotesk", sans-serif;
  margin: 0;
}

.app-shell {
  min-height: 100vh;
  padding: 0.85rem;
  padding-bottom: 230px;
}

.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.75rem;
}

.title-wrap h1 {
  line-height: 1.08;
}

.eyebrow {
  margin: 0 0 0.2rem;
  font-size: 0.72rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.topbar-right {
  display: flex;
  gap: 0.8rem;
  align-items: center;
}

.trip-meta {
  display: flex;
  gap: 0.45rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.meta-pill {
  font-size: 0.78rem;
  background: #dde7f2;
  border: 1px solid #c2cfdd;
  padding: 0.28rem 0.65rem;
  border-radius: 999px;
}

.burger {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 10px;
  width: 45px;
  height: 38px;
  padding: 0.4rem;
  display: grid;
  gap: 0.22rem;
  align-content: center;
  cursor: pointer;
}

.burger span {
  display: block;
  width: 100%;
  height: 2px;
  background: #0f172a;
}

.card {
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 14px;
  box-shadow: var(--shadow);
}

.map-stage {
  min-height: calc(100vh - 300px);
}

.map-panel {
  position: relative;
  overflow: hidden;
}

.map-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  padding: 0.6rem;
  border-bottom: 1px solid var(--line);
}

.mode-switch {
  display: inline-flex;
  border-radius: 9px;
  overflow: hidden;
  border: 1px solid var(--line);
}

.mode-switch button,
.playback-controls button,
button {
  border: 0;
  background: #e2e8f0;
  color: #111827;
  padding: 0.5rem 0.74rem;
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
}

.mode-switch button {
  border-right: 1px solid var(--line);
  font-size: 0.85rem;
}

.mode-switch button:last-child {
  border-right: 0;
}

.mode-switch button.active {
  background: #0f172a;
  color: #fff;
}

.toolbar-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.toggle-wrap {
  display: inline-flex;
  gap: 0.35rem;
  align-items: center;
  font-size: 0.82rem;
  color: #334155;
}

.playback-controls {
  display: flex;
  gap: 0.45rem;
  align-items: center;
}

.playback-controls button {
  border-radius: 8px;
  min-width: 42px;
}

.speed-wrap {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.78rem;
  color: #334155;
  border: 1px solid #cbd5e1;
  background: #f8fafc;
  border-radius: 8px;
  padding: 0.22rem 0.4rem;
}

.speed-wrap select {
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  padding: 0.18rem 0.28rem;
  font-size: 0.78rem;
  background: #fff;
}

.playback-controls button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

#map {
  min-height: calc(100vh - 360px);
  height: calc(100vh - 360px);
}

.active-note {
  position: absolute;
  left: 0.75rem;
  bottom: 0.75rem;
  max-width: 360px;
  background: rgba(15, 23, 42, 0.88);
  color: #f8fafc;
  border: 1px solid rgba(148, 163, 184, 0.35);
  border-radius: 10px;
  padding: 0.65rem;
  font-size: 0.86rem;
  display: none;
  z-index: 1000;
}

.active-note.visible {
  display: block;
}

.active-note-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.55rem;
  margin-bottom: 0.35rem;
  font-size: 0.86rem;
}

.active-note-km {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.12rem 0.42rem;
  border-radius: 999px;
  background: rgba(20, 184, 166, 0.22);
  border: 1px solid rgba(94, 234, 212, 0.5);
  color: #ccfbf1;
  font-size: 0.78rem;
  white-space: nowrap;
}

.active-note-text {
  margin: 0.2rem 0 0;
  font-size: 0.84rem;
  line-height: 1.35;
  color: #f1f5f9;
}

.active-note-image {
  display: block;
  width: 100%;
  max-height: 180px;
  object-fit: cover;
  border-radius: 8px;
  margin-top: 0.5rem;
  border: 1px solid rgba(148, 163, 184, 0.4);
}

.timeline-dock {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 850;
  width: 100%;
  background: var(--timeline-bg);
  border-top: 1px solid #0f172a;
  box-shadow: 0 -12px 30px rgba(15, 23, 42, 0.4);
  padding: 0.7rem 1rem 0.85rem;
}

.timeline-topline {
  display: grid;
  gap: 0.45rem;
  margin-bottom: 0.55rem;
}

.timeline-status {
  color: #dbe7f3;
  font-size: 0.9rem;
}

#timeline-scrub {
  width: 100%;
  accent-color: #14b8a6;
}

.timeline-viewport {
  position: relative;
  height: 130px;
  border: 1px solid #334155;
  border-radius: 10px;
  overflow: hidden;
  background: linear-gradient(90deg, #162235, #1f2f4a);
  cursor: grab;
}

.timeline-viewport.dragging {
  cursor: grabbing;
}

.timeline-axis {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.timeline-tick {
  position: absolute;
  top: 0.3rem;
  bottom: 0.35rem;
  width: 1px;
  background: rgba(148, 163, 184, 0.35);
}

.timeline-tick-label {
  position: absolute;
  top: 0.2rem;
  transform: translateX(-50%);
  font-size: 0.72rem;
  color: #cbd5e1;
  letter-spacing: 0.02em;
}

.timeline-trips {
  position: absolute;
  left: 0;
  right: 0;
  top: 1.8rem;
  bottom: 0.45rem;
}

.timeline-trip-bar {
  position: absolute;
  min-height: 30px;
  border-radius: 8px;
  border: 1px solid rgba(148, 163, 184, 0.6);
  background: rgba(71, 85, 105, 0.75);
  color: #e5e7eb;
  font-size: 0.76rem;
  padding: 0.28rem 0.45rem;
  white-space: nowrap;
  overflow: visible;
  text-overflow: clip;
  cursor: pointer;
}

.timeline-trip-bar:hover {
  border-color: #5eead4;
}

.timeline-trip-bar.active {
  background: rgba(15, 118, 110, 0.95);
  border-color: #99f6e4;
  color: #ecfeff;
}

.timeline-cursor {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  background: #2dd4bf;
  box-shadow: 0 0 0 1px rgba(15, 23, 42, 0.6);
  pointer-events: none;
}

.timeline-tooltip {
  position: fixed;
  z-index: 12;
  min-width: 250px;
  max-width: 340px;
  background: rgba(15, 23, 42, 0.95);
  border: 1px solid #334155;
  border-radius: 10px;
  padding: 0.6rem;
  color: #e2e8f0;
  box-shadow: 0 10px 24px rgba(2, 6, 23, 0.5);
  pointer-events: auto;
}

.timeline-tooltip h4 {
  margin: 0 0 0.18rem;
  font-size: 0.88rem;
}

.timeline-tooltip .range {
  font-size: 0.74rem;
  color: #cbd5e1;
  margin-bottom: 0.5rem;
}

.timeline-station-list {
  display: grid;
  gap: 0.3rem;
  max-height: calc(5 * 36px);
  overflow: auto;
}

.timeline-station-btn {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.45rem;
  width: 100%;
  border: 1px solid #475569;
  background: #1e293b;
  color: #f1f5f9;
  border-radius: 8px;
  padding: 0.35rem 0.45rem;
  font-size: 0.78rem;
  text-align: left;
  min-height: 34px;
}

.timeline-station-btn.active {
  border-color: #5eead4;
  background: #0f766e;
}

.drawer {
  position: fixed;
  right: -430px;
  top: 0;
  bottom: 0;
  width: min(430px, 92vw);
  background: #ffffff;
  border-left: 1px solid var(--line);
  box-shadow: -12px 0 28px rgba(15, 23, 42, 0.2);
  z-index: 1000;
  overflow-y: auto;
  padding: 0.85rem;
  transition: right 220ms ease;
}

.drawer.open {
  right: 0;
}

.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.35);
  z-index: 920;
}

.drawer-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.drawer-header button {
  border-radius: 9px;
}

.drawer-section {
  margin-top: 1rem;
  border-top: 1px solid #e2e8f0;
  padding-top: 0.9rem;
}

.stack-form {
  display: grid;
  gap: 0.7rem;
}

label {
  display: grid;
  gap: 0.3rem;
  color: #334155;
  font-size: 0.9rem;
}

input,
textarea,
select {
  border: 1px solid #cbd5e1;
  border-radius: 9px;
  padding: 0.55rem 0.65rem;
  font-family: inherit;
  font-size: 0.92rem;
}

textarea {
  resize: vertical;
}

button[type="submit"] {
  border-radius: 9px;
  background: #155e75;
  color: #fff;
}

.station-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  z-index: 1200;
  display: grid;
  place-items: center;
  padding: 1rem;
}

.station-modal-backdrop[hidden] {
  display: none !important;
}

.station-modal {
  width: min(560px, 100%);
  background: #fff;
  border: 1px solid #cbd5e1;
  border-radius: 12px;
  box-shadow: 0 16px 36px rgba(15, 23, 42, 0.3);
  padding: 0.85rem;
}

.station-modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.6rem;
}

.station-modal-head button {
  border-radius: 8px;
}

.station-modal-actions {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
}

#station-modal-delete {
  background: #fee2e2;
  color: #991b1b;
  border: 1px solid #fecaca;
  border-radius: 9px;
}

.hint {
  margin: 0;
  font-size: 0.8rem;
  color: var(--muted);
}

.split-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.65rem;
}

.leaflet-div-icon.station-chip {
  background: transparent;
  border: 0;
}

.station-chip-dot {
  width: 22px;
  height: 22px;
  border-radius: 999px;
  background: #111827;
  color: #fff;
  border: 2px solid #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.72rem;
  font-weight: 700;
}

@media (max-width: 980px) {
  .app-shell {
    padding-bottom: 265px;
  }

  .topbar {
    flex-direction: column;
    align-items: flex-start;
  }

  .topbar-right {
    width: 100%;
    justify-content: space-between;
  }

  #map {
    min-height: calc(100vh - 430px);
    height: calc(100vh - 430px);
  }

  .timeline-viewport {
    height: 104px;
  }
}

@media (max-width: 640px) {
  .app-shell {
    padding: 0.55rem;
    padding-bottom: 280px;
  }

  .toolbar-right {
    width: 100%;
    justify-content: space-between;
  }

  .toggle-wrap {
    font-size: 0.74rem;
  }

  #map {
    min-height: calc(100vh - 455px);
    height: calc(100vh - 455px);
  }

  .active-note {
    max-width: calc(100% - 1.5rem);
  }

  .split-fields {
    grid-template-columns: 1fr;
  }

  .timeline-viewport {
    height: 100px;
  }
}
