:root {
  --ink: #16181c;
  --muted: #5c6570;
  --line: #d7dde4;
  --panel: #f3f5f7;
  --accent: #b42318;
  --accent-soft: rgba(180, 35, 24, 0.12);
  --ok: #3d5a45;
  --rail-w: 320px;
  --font: "IBM Plex Sans", "Helvetica Neue", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: var(--font);
  color: var(--ink);
  background: #e4eaef;
}

a { color: var(--accent); }

.app {
  display: grid;
  grid-template-columns: var(--rail-w) 1fr;
  height: 100vh;
  height: 100dvh;
}

.rail {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--panel);
  border-right: 1px solid var(--line);
  z-index: 5;
}

.rail__brand {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.85rem 1rem 0.7rem;
  border-bottom: 1px solid var(--line);
}

.rail__brand > div {
  display: flex;
  flex-direction: column;
  gap: 0.08rem;
}

.rail__brand a {
  font-size: 0.72rem;
  font-weight: 600;
  text-decoration: none;
  color: var(--muted);
}

.rail__brand strong {
  font-size: 1.2rem;
  letter-spacing: -0.03em;
}

.rail-close {
  display: none;
  margin-left: auto;
  appearance: none;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 8px;
  padding: 0.12rem 0.45rem;
  font: inherit;
  cursor: pointer;
}

.rail__section {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--line);
}

.rail__section--list {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.rail__section h2,
.rail__label {
  margin: 0;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.rail__row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.45rem;
}

.stat {
  margin: 0 0 0.25rem;
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.25;
}

.rail__hint {
  margin: 0 0 0.65rem;
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.4;
}

.modes {
  display: flex;
  gap: 0.35rem;
  margin-bottom: 0.65rem;
}

.modes button {
  flex: 1;
  appearance: none;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 8px;
  padding: 0.38rem 0.4rem;
  font: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
}

.modes button.is-on {
  background: var(--ink);
  border-color: var(--ink);
  color: #fff;
}

.rail__search {
  width: 100%;
  margin-bottom: 0.55rem;
  padding: 0.45rem 0.55rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  font: inherit;
  font-size: 0.88rem;
}

.check {
  display: flex;
  align-items: flex-start;
  gap: 0.45rem;
  font-size: 0.8rem;
  color: var(--muted);
  cursor: pointer;
}

.check input {
  margin-top: 0.15rem;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.75rem;
  margin: 0.7rem 0 0;
  padding: 0;
  list-style: none;
  font-size: 0.72rem;
  color: var(--muted);
}

.legend li {
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

.legend__arrow {
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-bottom: 11px solid #b42318;
}

.legend__arrow--line { border-bottom-color: #4a5d6b; }

.text-btn {
  border: 0;
  background: none;
  color: var(--accent);
  font: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
}

.bunch-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow: auto;
  flex: 1;
}

.bunch-list li {
  margin: 0 0 0.4rem;
}

.bunch {
  display: grid;
  gap: 0.12rem;
  width: 100%;
  padding: 0.55rem 0.6rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  text-align: left;
  font: inherit;
  cursor: pointer;
}

.bunch:hover,
.bunch.is-on {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.bunch__top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
}

.bunch__route {
  font-weight: 700;
  font-size: 0.95rem;
}

.bunch__gap {
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--accent);
  white-space: nowrap;
}

.bunch__meta {
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.35;
}

.rail__foot {
  padding: 0.65rem 1rem 0.85rem;
  border-top: 1px solid var(--line);
}

.rail__foot details {
  font-size: 0.8rem;
  color: var(--muted);
  line-height: 1.45;
}

.rail__foot summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--ink);
}

.rail__foot p {
  margin: 0.45rem 0 0;
}

.rail__status {
  margin: 0.55rem 0 0;
  font-family: var(--mono);
  font-size: 0.68rem;
  color: var(--muted);
}

.map-pane {
  position: relative;
  min-width: 0;
  min-height: 0;
}

.map {
  width: 100%;
  height: 100%;
  background: #dce5ec;
}

.rail-toggle {
  display: none;
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 1000;
  width: 40px;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.12);
  cursor: pointer;
}

.vehicle-icon {
  background: transparent !important;
  border: 0 !important;
}

.vehicle-arrow {
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  transform-origin: 50% 50%;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.4));
}

.vehicle-arrow.is-muted {
  opacity: 0.42;
}

.vehicle-arrow svg { display: block; }

.vehicle-arrow path {
  fill: var(--vehicle-color, #b42318);
  stroke: #fff;
  stroke-width: 1.6;
  stroke-linejoin: round;
}

.vp__title {
  font-weight: 700;
  font-size: 0.92rem;
  margin-bottom: 0.15rem;
}

.vp__line { font-size: 0.86rem; }

.vp__meta {
  margin-top: 0.2rem;
  font-size: 0.75rem;
  color: var(--muted);
}

.leaflet-popup-content {
  margin: 0.65rem 0.8rem;
  font-family: var(--font);
  line-height: 1.35;
  min-width: 140px;
}

@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; }

  .rail {
    position: absolute;
    inset: 0 auto 0 0;
    width: min(340px, 90vw);
    transform: translateX(-105%);
    transition: transform 0.2s ease;
    box-shadow: 12px 0 40px rgba(0, 0, 0, 0.18);
  }

  .rail.is-open { transform: translateX(0); }

  .rail-toggle,
  .rail-close { display: block; }
}
