/* Fira Sans и Roboto Condensed подключены вместе с лицензиями SIL OFL. */
@font-face {
  font-family: "Fira Sans";
  src: url("../vendor/typefaces/fira-sans-regular.ttf") format("truetype");
  font-style: normal;
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: "Fira Sans";
  src: url("../vendor/typefaces/fira-sans-medium.ttf") format("truetype");
  font-style: normal;
  font-weight: 500;
  font-display: swap;
}
@font-face {
  font-family: "Fira Sans";
  src: url("../vendor/typefaces/fira-sans-semibold.ttf") format("truetype");
  font-style: normal;
  font-weight: 600;
  font-display: swap;
}
@font-face {
  font-family: "Fira Sans";
  src: url("../vendor/typefaces/fira-sans-bold.ttf") format("truetype");
  font-style: normal;
  font-weight: 700;
  font-display: swap;
}
@font-face {
  font-family: "Roboto Condensed";
  src: url("../vendor/typefaces/roboto-condensed-variable.ttf") format("truetype");
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
}

/* Палитра и размеры общие для страницы, слоёв карты и всплывающих карточек. */
:root {
  color-scheme: light;
  --font: "Fira Sans", "Segoe UI", sans-serif;
  --font-display: "Roboto Condensed", "Arial Narrow", sans-serif;
  --bg: #f0f3f3;
  --panel: #ffffff;
  --panel-soft: #f5f7f6;
  --text: #293e38;
  --muted: #61736c;
  --line: #e0e7e3;
  --accent: #275e44;
  --accent-soft: #edf3ef;
  --brand-color: #4e7f6d;
  --button-bg: #4e7f6d;
  --button-text: #ffffff;
  --header-bg: #f9fbfa;
  --map-bg: #e5ebe8;
  --shadow: 0 8px 32px #263c3010, 0 1px 4px #263c3006;
  --warning-bg: #fff7e5;
  --warning-text: #7c5b1d;
  --warning-line: #e7d8ad;
  --topbar-height: 92px;
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #202b29;
  --panel: #2a3834;
  --panel-soft: #30413a;
  --text: #e8efeb;
  --muted: #b1c1b8;
  --line: #43574c;
  --accent: #a6c8b8;
  --accent-soft: #3a5045;
  --brand-color: #93b4a4;
  --button-bg: #89ad9a;
  --button-text: #193b2c;
  --header-bg: #293a32;
  --map-bg: #24352c;
  --shadow: 0 8px 32px #00000030;
  --warning-bg: #3b331e;
  --warning-text: #ebd79c;
  --warning-line: #5b5031;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.5 var(--font); }
button, input { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: wait; opacity: .65; }
button, a, input, summary { -webkit-tap-highlight-color: transparent; }
button:focus-visible, a:focus-visible, input:focus-visible, summary:focus-visible {
  outline: 3px solid var(--accent); outline-offset: 4px;
}
[hidden] { display: none !important; }
::selection { background: #dce9e1; color: #275e44; }
.skip-link { position: fixed; top: -80px; left: 20px; z-index: 3000; padding: 12px 20px; border-radius: 12px; color: var(--text); background: var(--accent-soft); }
.skip-link:focus { top: 12px; }

/* Знак маршрута и двухстрочное название образуют единый логотип. */
.topbar {
  height: var(--topbar-height); padding: 0 28px; display: flex; align-items: center;
  justify-content: space-between; gap: 24px; border-bottom: 1px solid var(--line);
  background: var(--header-bg); color: var(--text);
}
.brand { display: inline-flex; align-items: center; gap: 15px; color: inherit; text-decoration: none; flex-shrink: 0; }
.brand-symbol { width: 54px; height: 54px; flex-shrink: 0; }
.brand-wordmark { display: flex; flex-direction: column; gap: 2px; }
.brand-name { font-family: var(--font-display); font-size: 32px; font-weight: 650; letter-spacing: -.2px; line-height: 1.05; }
.brand-subtitle { color: var(--muted); font-size: 13px; font-weight: 500; letter-spacing: 3.2px; }
.header-caption { display: flex; flex-direction: column; gap: 5px; padding-left: 28px; border-left: 1px solid var(--line); margin-right: auto; }
.header-caption .eyebrow { color: var(--accent); font-size: 9px; letter-spacing: 1.8px; }
.header-caption > span:last-child { color: var(--muted); font-size: 12px; }
.header-meta { display: flex; align-items: center; gap: 24px; font-size: 12px; }
.header-city { display: inline-flex; align-items: center; gap: 7px; color: var(--muted); white-space: nowrap; }
.header-city svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.7; }
.source-badge { padding: 8px 13px; border: 1px solid var(--line); border-radius: 30px; background: var(--panel); color: var(--muted); font-size: 11px; font-weight: 650; white-space: nowrap; }
.source-badge.calculated { background: var(--accent-soft); color: var(--accent); border-color: var(--line); }

/* Панель и карта располагаются на общей подложке с промежутком между ними. */
.workspace {
  display: flex; gap: 16px; padding: 16px; height: calc(100dvh - var(--topbar-height));
  min-height: 590px;
}
.sidebar {
  display: flex; flex-direction: column; flex-shrink: 0; width: 338px; overflow: hidden;
  background: var(--panel); border: 1px solid var(--line); border-radius: 22px;
}
.sidebar-heading { padding: 25px 24px 20px; }
.section-kicker { display: inline-flex; align-items: center; gap: 8px; font-size: 9px; font-weight: 750; letter-spacing: 1.6px; color: var(--muted); }
.caption-dot { width: 6px; height: 6px; flex-shrink: 0; border-radius: 50%; background: var(--accent); }
.eyebrow { color: var(--muted); font-size: 9px; font-weight: 700; letter-spacing: 1px; }
h1 { display: flex; align-items: center; gap: 12px; margin: 11px 0 7px; font-family: var(--font-display); font-size: 34px; font-weight: 700; line-height: 1.3; letter-spacing: -.3px; }
.count-badge { padding: 4px 9px; border-radius: 9px; background: var(--accent-soft); color: var(--accent); font-size: 12px; letter-spacing: 0; font-weight: 750; }
.sidebar-heading p { margin: 0; color: var(--muted); font-size: 12px; }
.search-box { display: flex; align-items: center; gap: 10px; margin: 0 20px; padding: 13px 14px; border: 1px solid var(--line); border-radius: 13px; background: var(--panel-soft); }
.search-box svg { width: 18px; height: 18px; flex-shrink: 0; fill: none; stroke: var(--muted); stroke-width: 1.7; }
.search-box input { min-width: 0; width: 100%; border: 0; background: transparent; color: var(--text); outline: 0; font-size: 12px; }
.search-box:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.search-box input::placeholder { color: var(--muted); }
.selection-actions { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin: 13px 20px 18px; }
.selection-actions button { padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); color: var(--accent); font-size: 10px; font-weight: 700; }
.selection-actions button:first-child { background: var(--accent-soft); border-color: transparent; }
.selection-actions button:first-child span { margin-left: 8px; }
.selection-actions button:last-child { color: var(--muted); }
.selection-actions button:hover { border-color: var(--accent); }
.list-heading { display: flex; justify-content: space-between; padding: 11px 24px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); color: var(--muted); background: var(--panel-soft); font-size: 8px; font-weight: 700; letter-spacing: .9px; }
.route-list { flex: 1; min-height: 0; overflow-y: auto; padding: 8px 10px; scrollbar-width: thin; scrollbar-color: var(--line) transparent; }
.route-row { display: flex; align-items: center; gap: 12px; min-height: 91px; margin-bottom: 3px; padding: 12px 10px; border: 1px solid transparent; border-radius: 13px; cursor: pointer; }
.route-row:hover { background: var(--panel-soft); border-color: var(--line); }
.route-number { display: grid; place-items: center; width: 51px; min-height: 40px; padding: 3px; flex-shrink: 0; border-radius: 11px; background: var(--panel-soft); color: var(--muted); font-family: var(--font-display); font-size: 17px; font-weight: 700; letter-spacing: 0; }
.route-row:has(input:checked) .route-number { background: var(--accent-soft); color: var(--accent); }
.route-description { flex: 1; min-width: 0; }
.route-description strong { display: block; font-size: 13px; font-weight: 750; }
.route-description small { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; margin-top: 4px; color: var(--muted); font-size: 11px; line-height: 1.5; }
.route-row input { appearance: none; display: grid; place-content: center; width: 19px; height: 19px; margin: 0; border: 1.5px solid var(--line); border-radius: 6px; flex-shrink: 0; cursor: pointer; background: var(--panel); }
.route-row input:checked { background: var(--button-bg); border-color: var(--button-bg); }
.route-row input:checked::after { content: ""; width: 5px; height: 9px; margin-top: -3px; border: solid var(--button-text); border-width: 0 2px 2px 0; transform: rotate(45deg); }
.prediction-badge { display: inline-block; margin-top: 5px; color: var(--accent); font-size: 9px; font-weight: 600; }
.empty-state { padding: 28px 12px; text-align: center; color: var(--muted); font-size: 12px; }
.sidebar-footer { display: flex; align-items: center; gap: 11px; padding: 17px 22px; border-top: 1px solid var(--line); background: var(--panel-soft); }
.foot-icon { display: grid; place-items: center; width: 34px; height: 34px; flex-shrink: 0; border-radius: 11px; background: var(--accent-soft); color: var(--accent); }
.foot-icon svg { width: 21px; height: 21px; fill: none; stroke: currentColor; stroke-width: 1.5; }
.sidebar-footer p { margin: 0; font-size: 11px; font-weight: 650; }
.sidebar-footer small { display: block; margin-top: 3px; color: var(--muted); font-size: 9px; font-weight: 500; }

/* Карта сохраняет полезную площадь, панели не перехватывают жесты вне кнопок. */
.map-area { position: relative; flex: 1; min-width: 0; overflow: hidden; border: 1px solid var(--line); border-radius: 22px; background: var(--map-bg); }
#map { width: 100%; height: 100%; background-color: var(--map-bg); background-image: linear-gradient(#80988a16 1px, transparent 1px), linear-gradient(90deg, #80988a16 1px, transparent 1px); background-size: 40px 40px; }
.map-caption { position: absolute; top: 20px; left: 20px; z-index: 500; display: flex; align-items: center; gap: 11px; padding: 10px 14px 10px 10px; border: 1px solid var(--line); border-radius: 15px; background: var(--panel); box-shadow: var(--shadow); pointer-events: none; }
.map-caption-icon { display: grid; place-items: center; width: 35px; height: 35px; border-radius: 10px; background: var(--accent-soft); color: var(--accent); }
.map-caption-icon svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linejoin: round; }
.caption-name { font-size: 13px; font-weight: 750; line-height: 1.5; }
.caption-name small { display: block; color: var(--muted); font-size: 9px; font-weight: 500; }
.map-caption > .caption-dot { margin-left: 5px; }
.map-controls { position: absolute; top: 20px; right: 20px; z-index: 500; display: flex; flex-direction: column; align-items: flex-end; gap: 10px; }
.control-button { display: flex; align-items: center; justify-content: center; gap: 9px; height: 43px; min-width: 43px; padding: 0 14px; border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); background: var(--panel); color: var(--text); font-size: 11px; font-weight: 700; }
.control-button:hover { background: var(--accent-soft); }
.theme-button span:first-child { font-size: 20px; line-height: 1; }
.zoom-group { display: flex; overflow: hidden; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); box-shadow: var(--shadow); }
.zoom-group .control-button { border: 0; border-radius: 0; box-shadow: none; padding: 0; font-size: 23px; font-weight: 500; }
.zoom-group .control-button:first-child { border-right: 1px solid var(--line); }
.refresh-button { background: var(--button-bg); color: var(--button-text); border-color: transparent; }
.refresh-button:hover { background: var(--button-bg); filter: brightness(1.12); }
.refresh-icon { display: inline-flex; }
.refresh-icon svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.refresh-button.busy .refresh-icon { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.map-messages { position: absolute; left: 20px; bottom: 260px; z-index: 500; display: grid; gap: 8px; max-width: min(540px, calc(100% - 40px)); pointer-events: none; }
.notice, .map-empty { margin: 0; padding: 11px 14px; border: 1px solid var(--warning-line); border-radius: 12px; background: var(--warning-bg); color: var(--warning-text); font-size: 11px; box-shadow: var(--shadow); }
.map-empty { background: var(--panel); color: var(--text); border-color: var(--line); }

/* Сводка компактна; подробное описание источника открывается по запросу. */
.map-bottom { position: absolute; bottom: 28px; left: 20px; right: 20px; z-index: 500; display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; pointer-events: none; }
.data-card { width: 438px; max-width: 100%; overflow: hidden; border: 1px solid var(--line); border-radius: 20px; box-shadow: var(--shadow); background: var(--panel); pointer-events: auto; }
.data-card-main { display: flex; align-items: center; gap: 21px; padding: 18px 21px 14px; }
.vehicle-stat { display: flex; flex-direction: column; flex-shrink: 0; }
.vehicle-stat strong { color: var(--accent); font-family: var(--font-display); font-size: 50px; font-weight: 700; line-height: 1.05; letter-spacing: -1px; font-variant-numeric: tabular-nums; }
.vehicle-stat span { margin-top: 6px; color: var(--muted); font-size: 10px; }
.update-stat { min-width: 0; padding-left: 20px; border-left: 1px solid var(--line); }
.update-stat .eyebrow { font-size: 8px; letter-spacing: .8px; }
.update-stat time { display: block; margin-top: 4px; font-size: 15px; font-weight: 750; font-variant-numeric: tabular-nums; }
.source-text { display: block; margin-top: 5px; color: var(--muted); font-size: 9px; line-height: 1.5; overflow-wrap: anywhere; }
.prediction-summary { padding: 0 21px 13px; color: var(--muted); font-size: 9px; line-height: 1.6; }
.data-message { padding: 11px 21px; border-top: 1px solid var(--line); color: var(--muted); font-size: 10px; line-height: 1.65; }
#vehicle-limit-note { background: var(--panel-soft); }
.data-details summary { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 11px 21px; border-top: 1px solid var(--line); color: var(--muted); font-size: 10px; font-weight: 650; list-style: none; cursor: pointer; }
.data-details summary::-webkit-details-marker { display: none; }
.data-details summary:hover { color: var(--accent); background: var(--panel-soft); }
.data-details summary svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.5; flex-shrink: 0; }
.data-details[open] summary svg { transform: rotate(180deg); }
.data-card.warning #data-message { color: var(--warning-text); background: var(--warning-bg); }
.map-legend { position: absolute; right: 20px; bottom: 28px; z-index: 500; display: flex; align-items: center; gap: 16px; padding: 11px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); color: var(--muted); box-shadow: var(--shadow); font-size: 10px; white-space: nowrap; pointer-events: none; }
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.legend-marker { display: grid; place-items: center; width: 18px; height: 19px; border-radius: 5px; background: #275e44; color: #ffffff; font-size: 13px; }
.legend-stop { width: 9px; height: 9px; border: 2px solid #ffffff; border-radius: 50%; background: #e58a24; box-shadow: 0 0 0 1px #c4b085; }
.legend-route { width: 18px; height: 4px; border-radius: 4px; background: #1687ff; }

/* Маркеры и карточки Leaflet наследуют шрифт и цвет текущей темы. */
.route-highlight { filter: drop-shadow(0 1px 2px #062d6080); }
.bus-icon { background: transparent; border: none; }
.bus-marker { display: flex; align-items: center; justify-content: center; gap: 4px; height: 34px; min-width: 44px; padding: 0 7px; border: 2px solid #ffffff; border-radius: 11px; background: var(--bus-color, #275e44); color: #ffffff; box-shadow: 0 3px 9px #10292150; font: 700 13px/1 var(--font-display); }
.bus-heading { display: inline-block; font-size: 17px; line-height: 1; }
:root[data-theme="dark"] .leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) brightness(.75) contrast(.9) saturate(.5); }
.leaflet-container { font-family: var(--font); }
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--panel); color: var(--text); }
.leaflet-popup-content-wrapper { border-radius: 17px; box-shadow: var(--shadow); }
.leaflet-popup-content { margin: 20px; min-width: 220px; }
.bus-popup h2 { margin: 0 0 14px; color: var(--accent); font-size: 19px; font-weight: 800; letter-spacing: -.5px; }
.bus-popup dl { display: grid; grid-template-columns: auto 1fr; gap: 8px 15px; margin: 0; font-size: 10px; }
.bus-popup dt { color: var(--muted); }
.bus-popup dd { margin: 0; text-align: right; overflow-wrap: anywhere; }
.prediction-block { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line); }
.prediction-block h3 { margin: 0 0 10px; font-size: 11px; font-weight: 750; }
.prediction-block p { margin: 6px 0; font-size: 11px; }
.prediction-block .stop-eta { color: var(--accent); font-weight: 750; }
.prediction-block small { font-size: 9px; color: var(--muted); }
.stop-dot { filter: drop-shadow(0 1px 2px #10292180); }
.stop-popup h2 { margin: 0 0 8px; color: var(--accent); font-size: 16px; font-weight: 750; }
.stop-popup h3 { margin: 15px 0 8px; font-size: 11px; }
.stop-popup .stop-address { margin: 0 0 5px; color: var(--muted); font-size: 10px; }
.stop-popup > small { color: var(--muted); font-size: 9px; }
.stop-popup .stop-bus-list { list-style: none; margin: 0; padding: 0; }
.stop-bus-list li { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 8px; padding: 8px 0; border-top: 1px solid var(--line); font-size: 9px; }
.stop-bus-list li strong { color: var(--accent); font-size: 11px; }
.stop-bus-list li span { overflow: hidden; text-overflow: ellipsis; color: var(--muted); }
.stop-bus-list li b { white-space: nowrap; }
.stop-popup .stop-routes { display: block; margin-top: 11px; }
.leaflet-container a.leaflet-popup-close-button { color: var(--muted); }
.leaflet-container .leaflet-control-attribution { background: var(--panel); color: var(--muted); padding: 3px 7px; font-size: 9px; }
.leaflet-control-attribution a { color: var(--accent); }
.leaflet-container .leaflet-control-scale-line { background: var(--panel); color: var(--text); border-color: var(--muted); }
.noscript { position: fixed; z-index: 2000; top: 100px; left: 20px; right: 20px; padding: 20px; border-radius: 14px; background: var(--warning-bg); color: var(--warning-text); }

/* На узкой карте оставляем место под карточкой для легенды в нижнем правом углу. */
@media (max-width: 1200px) {
  .map-bottom { bottom: 80px; }
}
@media (max-width: 1100px) {
  .header-caption { display: none; }
  .sidebar { width: 300px; }
  .sidebar-heading { padding: 23px 20px 18px; }
  .theme-button span:last-child, .refresh-button > span:last-child { display: none; }
  .control-button { padding: 0 11px; }
  .data-card { width: 405px; }
}

/* На телефоне карта занимает верхнюю часть, список маршрутов прокручивается под ней. */
@media (max-width: 760px) {
  :root { --topbar-height: 80px; }
  .topbar { padding: 0 16px; gap: 12px; }
  .brand { gap: 11px; }
  .brand-symbol { width: 44px; height: 44px; }
  .brand-name { font-size: 27px; letter-spacing: -.2px; }
  .brand-subtitle { font-size: 11px; letter-spacing: 2.6px; }
  .header-city { display: none; }
  .source-badge { max-width: 112px; padding: 6px 9px; overflow: hidden; text-overflow: ellipsis; font-size: 9px; }
  .workspace { flex-direction: column-reverse; gap: 10px; padding: 10px; min-height: 740px; }
  .map-area { flex: 1; min-height: 480px; border-radius: 18px; }
  .sidebar { width: 100%; height: 220px; border-radius: 18px; }
  .sidebar-heading, .sidebar-footer, .list-heading { display: none; }
  .search-box { margin: 12px 14px 0; padding: 10px 12px; border-radius: 10px; }
  .selection-actions { margin: 7px 14px; }
  .selection-actions button { padding: 4px 8px; font-size: 9px; }
  .route-list { padding: 0 7px 6px; }
  .route-row { min-height: 76px; margin: 0; padding: 10px; gap: 12px; }
  .route-number { width: 45px; min-height: 35px; font-size: 16px; }
  .route-description small { -webkit-line-clamp: 1; }
  .bus-marker { transform: scale(.84); transform-origin: center; }
  .prediction-badge { font-size: 8px; margin-top: 3px; }
  .map-caption { top: 12px; left: 12px; padding: 7px 11px 7px 7px; gap: 8px; border-radius: 12px; }
  .map-caption-icon { width: 31px; height: 31px; border-radius: 8px; }
  .caption-name { font-size: 11px; }
  .caption-name small { font-size: 8px; }
  .map-controls { top: 12px; right: 12px; gap: 8px; }
  .control-button { min-width: 39px; height: 39px; border-radius: 10px; }
  .zoom-group { border-radius: 10px; }
  .zoom-group .control-button { min-width: 35px; }
  .map-bottom { position: static; }
  .data-card { position: absolute; z-index: 500; bottom: 74px; left: 12px; right: 12px; width: auto; max-width: none; border-radius: 16px; }
  .data-card-main { gap: 17px; padding: 14px 16px 11px; }
  .vehicle-stat strong { font-size: 42px; }
  .vehicle-stat span { font-size: 9px; }
  .update-stat { padding-left: 16px; }
  .update-stat .eyebrow { font-size: 7px; letter-spacing: .3px; }
  .update-stat time { font-size: 13px; }
  .source-text { font-size: 8px; }
  .prediction-summary { padding: 0 16px 10px; font-size: 8px; }
  .data-message { padding: 9px 16px; font-size: 9px; }
  .data-details summary { padding: 9px 16px; font-size: 9px; }
  .map-legend { right: 12px; bottom: 28px; padding: 7px 10px; gap: 12px; font-size: 9px; border-radius: 9px; }
  .legend-marker { width: 14px; height: 15px; font-size: 10px; }
  .legend-route { width: 14px; }
  .legend-stop { width: 8px; height: 8px; }
  .map-messages { left: 12px; max-width: calc(100% - 24px); }
  .notice, .map-empty { padding: 9px 12px; font-size: 10px; }
}
@media (max-width: 360px) {
  .topbar { padding: 0 12px; gap: 8px; }
  .brand-name { font-size: 23px; }
  .brand-symbol { width: 40px; height: 40px; }
  .brand { gap: 9px; }
  .source-badge { max-width: 94px; font-size: 8px; }
  .data-card-main { gap: 12px; padding-left: 13px; padding-right: 13px; }
  .update-stat { padding-left: 12px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; scroll-behavior: auto !important; }
}
