/* ============================================================================
   Атлас — премиум-светлая тема
   ========================================================================== */
:root {
  --red: #c8102e;
  --red-deep: #9e0c24;
  --red-soft: #fbe9ec;

  --ink: #14161b;
  --ink-2: #3a3f48;
  --muted: #585e68;   /* ~5.4:1 на белом — читаемый */
  --faint: #7c828c;   /* ~4.6:1 — для второстепенного текста */

  --bg: #f5f5f3;
  --surface: #ffffff;
  --surface-2: #fafafa;

  --line: rgba(20, 22, 28, 0.09);
  --line-2: rgba(20, 22, 28, 0.16);

  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;

  --font: "Inter", -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;

  --ease: cubic-bezier(0.22, 0.61, 0.36, 1);
}

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

html, body { height: 100%; }

body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* --- Шапка --- */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  padding: 0 28px;
  height: 60px;
  display: flex;
  align-items: center;
  flex: 0 0 auto;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand .mark {
  width: 34px; height: 34px;
  display: grid; place-items: center;
  color: #fff; background: var(--red);
  border-radius: 9px;
}
.brand .word {
  font-size: 19px; font-weight: 800; letter-spacing: -0.02em;
}
.brand .tag {
  font-size: 12.5px; color: var(--faint); font-weight: 500;
  padding-left: 10px; margin-left: 4px;
  border-left: 1px solid var(--line);
}

/* --- Раскладка --- */
.layout { flex: 1; display: flex; min-height: 0; }

.panel {
  width: 460px;
  flex: 0 0 460px;
  background: var(--surface);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

/* --- Поля ввода --- */
.controls { padding: 26px 26px 22px; }

.fields { position: relative; display: flex; flex-direction: column; gap: 26px; }
.field { position: relative; }
.field label {
  display: block;
  font-size: 11.5px; font-weight: 600; letter-spacing: 0.06em;
  text-transform: uppercase; color: var(--muted);
  margin-bottom: 10px; padding-left: 2px;
}
.field input {
  width: 100%;
  height: 48px;
  padding: 0 16px;
  font-family: var(--font);
  font-size: 16px; font-weight: 500; color: var(--ink);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  outline: none;
  transition: border-color 0.16s var(--ease), box-shadow 0.16s var(--ease),
    background 0.16s var(--ease);
}
.field input::placeholder { color: var(--faint); font-weight: 400; }
.field input:hover { border-color: var(--line-2); }
.field input:focus {
  background: var(--surface);
  border-color: var(--red);
  box-shadow: 0 0 0 4px var(--red-soft);
}

/* кнопка «поменять местами» */
.swap {
  position: absolute;
  right: 34px;
  top: 50%;
  transform: translateY(-50%);
  width: 44px; height: 44px;
  display: grid; place-items: center;
  background: var(--surface);
  color: var(--ink-2);
  border: 1px solid var(--line);
  border-radius: 50%;
  cursor: pointer;
  z-index: 5;
  transition: transform 0.3s var(--ease), border-color 0.16s, color 0.16s;
}
.swap:hover { color: var(--red); border-color: var(--line-2); }
.swap:active { transform: translateY(-50%) rotate(180deg); }

/* кнопка расчёта */
.calc {
  margin-top: 16px;
  width: 100%;
  height: 50px;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  font-family: var(--font); font-size: 15.5px; font-weight: 600; color: #fff;
  background: var(--red);
  border: none;
  border-radius: var(--r-md);
  cursor: pointer;
  transition: background 0.16s var(--ease), transform 0.08s var(--ease);
}
.calc:hover { background: var(--red-deep); }
.calc:active { transform: scale(0.99); }
.calc.busy { pointer-events: none; opacity: 0.85; }

/* --- Автоподсказки --- */
.autocomplete {
  position: absolute;
  top: calc(100% + 6px); left: 0; right: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  box-shadow: 0 12px 34px rgba(20, 22, 28, 0.13);
  z-index: 1000;
  display: none;
  max-height: 340px; overflow-y: auto;
  padding: 5px;
}
.ac-item {
  padding: 9px 11px; cursor: pointer; border-radius: var(--r-sm);
  transition: background 0.12s;
}
.ac-item:hover, .ac-item.active { background: var(--red-soft); }
.ac-item b { font-size: 14px; font-weight: 600; color: var(--ink); }
.ac-sub { font-size: 12px; color: var(--faint); margin-top: 2px; font-variant-numeric: tabular-nums; }

/* --- Результат --- */
#result { padding: 4px 26px 28px; }

.placeholder {
  color: var(--faint);
  font-size: 14px; line-height: 1.6;
  padding: 36px 6px;
  display: flex; flex-direction: column; gap: 14px;
}
.placeholder svg { color: var(--line-2); }

.summary { animation: rise 0.3s var(--ease) both; }
.hero { display: flex; align-items: flex-end; gap: 10px; }
.big {
  font-family: var(--mono);
  font-size: clamp(50px, 6.5vw, 72px);
  font-weight: 700; letter-spacing: -0.04em; line-height: 0.92;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.big .unit {
  font-family: var(--font);
  font-size: 19px; font-weight: 600; letter-spacing: 0;
  color: var(--muted); margin-left: 2px;
}
.route-name {
  font-size: 16px; font-weight: 700; color: var(--ink);
  margin-top: 16px; line-height: 1.35; letter-spacing: -0.01em;
}
.route-name .arr { color: var(--red); margin: 0 6px; }
.sub {
  display: flex; align-items: center; flex-wrap: wrap; gap: 8px;
  font-size: 12.5px; color: var(--muted); margin-top: 10px;
}

.src {
  font-size: 11px; font-weight: 600; padding: 2px 9px; border-radius: 20px;
  display: inline-flex; align-items: center; gap: 5px;
}
.src::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.src.local { background: #e8f5ec; color: #167a3c; }
.src.rzd { background: var(--red-soft); color: var(--red-deep); }
.src.approx { background: #fff3df; color: #97650a; }

.refresh {
  display: inline-flex; align-items: center; gap: 4px;
  color: var(--faint); text-decoration: none; font-size: 12px; font-weight: 500;
  cursor: pointer; transition: color 0.14s;
}
.refresh:hover { color: var(--red); }
.refresh svg { width: 13px; height: 13px; }

/* разделитель */
.divider { height: 1px; background: var(--line); margin: 22px 0 18px; }

.stops-head {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 11.5px; font-weight: 600; letter-spacing: 0.05em;
  text-transform: uppercase; color: var(--faint); margin-bottom: 14px;
}
.stops-head a { color: var(--red); text-decoration: none; font-weight: 600; text-transform: none; letter-spacing: 0; }
.stops-head a:hover { text-decoration: underline; }

/* --- Нитка маршрута --- */
.timeline { display: flex; flex-direction: column; }
.stop {
  display: grid;
  grid-template-columns: 20px 1fr auto;
  gap: 12px;
  align-items: center;
  min-height: 40px;
  animation: rise 0.3s var(--ease) both;
}
.stop { cursor: pointer; border-radius: 8px; transition: background 0.12s; }
.stop:hover { background: var(--surface-2); }
.stop .rail { position: relative; width: 20px; align-self: stretch; }
.stop .rail::before {
  content: ""; position: absolute; left: 9px; top: 0; bottom: 0;
  width: 2px; background: var(--line-2);
}
.stop:first-child .rail::before { top: 50%; }
.stop:last-child .rail::before { bottom: 50%; }
.stop .dot {
  position: absolute; left: 5px; top: 50%; transform: translateY(-50%);
  width: 10px; height: 10px; border-radius: 50%;
  background: #fff; border: 2px solid var(--line-2); z-index: 1;
}
.stop.end .dot { width: 13px; height: 13px; left: 3.5px; border-color: var(--red); background: var(--red); box-shadow: 0 0 0 4px var(--red-soft); }

.stop .info { min-width: 0; padding: 7px 0; }
.stop .nm { font-size: 13.5px; font-weight: 500; color: var(--ink-2); line-height: 1.25; }
.stop.end .nm { font-weight: 700; color: var(--ink); }
.road {
  display: inline-flex; align-items: center; gap: 5px; margin-top: 4px;
  font-size: 11px; font-weight: 600; letter-spacing: 0.02em; color: var(--muted);
}
.rw-dot { width: 7px; height: 7px; border-radius: 50%; flex: none; }
.stop .km {
  font-family: var(--mono); font-size: 13px; font-weight: 600;
  color: var(--ink); font-variant-numeric: tabular-nums; white-space: nowrap;
  text-align: right;
}
.stop.end .km { color: var(--red-deep); }
.stop .km .u { color: var(--faint); font-weight: 500; font-size: 11px; margin-left: 2px; }

.error {
  color: var(--red-deep); font-size: 14px; line-height: 1.5;
  background: var(--red-soft); border-radius: var(--r-md);
  padding: 14px 16px; margin-top: 8px;
}

/* спиннер при расчёте */
.loading { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 14px; padding: 24px 4px; }
.spin {
  width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid var(--line-2); border-top-color: var(--red);
  animation: spin 0.7s linear infinite;
}

/* индикатор наполнения сети */
.netstat {
  margin-top: auto;
  display: flex; align-items: center; gap: 8px;
  padding: 12px 26px;
  border-top: 1px solid var(--line);
  font-size: 12px; color: var(--muted);
}
.netstat .dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: #1f9d6b; flex: none;
  box-shadow: 0 0 0 0 rgba(31, 157, 107, 0.5);
  animation: pulse 2s var(--ease) infinite;
}
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(31, 157, 107, 0.45); }
  70% { box-shadow: 0 0 0 6px rgba(31, 157, 107, 0); }
  100% { box-shadow: 0 0 0 0 rgba(31, 157, 107, 0); }
}

/* --- Карта --- */
#map { flex: 1; background: #eceff2; }
.leaflet-container { font-family: var(--font); }
.leaflet-control-attribution { font-size: 10px; }

/* кнопка «весь маршрут» */
.map-reset {
  display: flex; align-items: center; gap: 6px;
  margin: 10px 10px 0 0;
  font-family: var(--font); font-size: 12px; font-weight: 600; color: var(--ink-2);
  background: #fff; border: 1px solid var(--line); border-radius: 9px;
  padding: 8px 11px; cursor: pointer;
  box-shadow: 0 2px 8px rgba(20, 22, 28, 0.14);
  transition: color 0.14s, border-color 0.14s;
}
.map-reset:hover { color: var(--red); border-color: var(--line-2); }

/* подписи станций на карте */
.leaflet-tooltip.stop-tip {
  background: var(--ink); color: #fff; border: none; border-radius: 7px;
  font-family: var(--font); font-size: 11.5px; font-weight: 600;
  padding: 4px 9px; box-shadow: 0 3px 10px rgba(0, 0, 0, 0.28); white-space: nowrap;
}
.leaflet-tooltip.stop-tip.leaflet-tooltip-top::before { border-top-color: var(--ink); }
.leaflet-popup-content { font-family: var(--font); font-size: 12.5px; line-height: 1.5; }
.leaflet-popup-content b { font-weight: 700; }

/* фокус для клавиатуры (поля используют своё кольцо) */
.calc:focus-visible, .swap:focus-visible, .refresh:focus-visible,
.stops-head a:focus-visible {
  outline: 2px solid var(--red);
  outline-offset: 2px;
}

@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}

/* --- Адаптив --- */
@media (max-width: 820px) {
  .layout { flex-direction: column; }
  .panel { width: 100%; flex: 0 0 auto; max-height: 56%; border-right: none; border-bottom: 1px solid var(--line); }
  #map { min-height: 240px; }
}
