/* Карта на цял екран с панел вляво (долу на телефон) */
/* ---------- Цветове: схема (палитра) × тема (светла/тъмна) ----------
   <html data-palette="sky|mint|lavender|sand|contrast" data-scheme="light|dark"> — задава ги theme.js
   (и малкият скрипт в index.html още преди зареждане, за да няма проблясване).
   Тъмната тема е графитено сива, не черна — картата и надписите остават четими. */
:root {
  --display: "Sofia Sans Condensed", "Arial Narrow", system-ui, sans-serif;
  --body: "Sofia Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --live: #23935a; --stale: #b7791f;
  /* любими: светложълт фон, наситена жълта звезда */
  --fav-bg: #fff6d6; --fav-border: #f0c94a; --fav-ink: #5c4300; --fav-star: #f2b300;
  --ctl: #ffffff; --ctl-ink: #333333; --shadow: #0000002e;
  --on-color: #ffffff; /* текст върху цветен фон (линия, бутон) */
  /* етикетите с часа по спирките на избран курс — бледожълти, за да се открояват от картата */
  --label-bg: #fff3c4; --label-ink: #3d3200; --label-border: #e8d27a;
  color-scheme: light;

  /* Небе (по подразбиране): ясно синьо и мандарина, хладно бял фон */
  --bg: #f2f5f9; --panel: #ffffff; --ink: #1b2531; --muted: #65707e; --line: #dde3ea;
  --bus: #2f6fd6; --trolley: #e8743a; --accent: #2f6fd6;
}
/* Мента: тюркоазено и корал */
:root[data-palette="mint"] {
  --bg: #eff6f4; --panel: #fbfefd; --ink: #15302a; --muted: #5d746e; --line: #d3e4df;
  --bus: #138a7a; --trolley: #e2655a; --accent: #138a7a;
}
/* Лавандула: индиго и розово */
:root[data-palette="lavender"] {
  --bg: #f4f3fa; --panel: #fdfcff; --ink: #221f38; --muted: #6b6884; --line: #e0ddef;
  --bus: #5a57d1; --trolley: #d4517b; --accent: #5a57d1;
}
/* Пясък: градински зелено и кехлибар, топъл фон */
:root[data-palette="sand"] {
  --bg: #f6f3ec; --panel: #fffdf8; --ink: #29261f; --muted: #756d5f; --line: #e6dfd1;
  --bus: #3b7d5c; --trolley: #c98317; --accent: #3b7d5c;
}
/* Висок контраст: бяло, черен текст, наситени цветове */
:root[data-palette="contrast"] {
  --bg: #ffffff; --panel: #ffffff; --ink: #000000; --muted: #3d3d3d; --line: #9a9a9a;
  --bus: #0040a8; --trolley: #b80000; --accent: #0040a8; --live: #1c6b35;
}

/* Тъмна тема — графитено сиво, общото за всички схеми */
:root[data-scheme="dark"] {
  color-scheme: dark;
  --live: #5ccf8a; --stale: #e0a94a;
  --fav-bg: #43391d; --fav-border: #93793a; --fav-ink: #f6e6b2; --fav-star: #f7cc4f;
  --ctl: #343a43; --ctl-ink: #e8ebef; --shadow: #00000066;
  --on-color: #10151b;
  --label-bg: #4d4524; --label-ink: #fbefc2; --label-border: #7d6f36;
  --bg: #22262c; --panel: #2b3038; --ink: #eceff3; --muted: #a3abb6; --line: #3e444e;
  --bus: #72a7ff; --trolley: #ff9d66; --accent: #72a7ff;
}
:root[data-scheme="dark"][data-palette="mint"] {
  --bg: #1f2826; --panel: #28322f; --line: #3b4945; --ctl: #303c39;
  --bus: #4fcab4; --trolley: #ff8e83; --accent: #4fcab4;
}
:root[data-scheme="dark"][data-palette="lavender"] {
  --bg: #24232f; --panel: #2d2c3a; --line: #413f54; --ctl: #363547;
  --bus: #a09dff; --trolley: #ff8db1; --accent: #a09dff;
}
:root[data-scheme="dark"][data-palette="sand"] {
  --bg: #27251f; --panel: #302d26; --line: #48433a; --ctl: #3a362e;
  --bus: #7fc6a1; --trolley: #f2b552; --accent: #7fc6a1;
}
:root[data-scheme="dark"][data-palette="contrast"] {
  --bg: #121212; --panel: #1a1a1a; --ink: #ffffff; --muted: #d0d0d0; --line: #6a6a6a; --ctl: #222222; --ctl-ink: #ffffff;
  --bus: #7ab0ff; --trolley: #ff7a6b; --accent: #7ab0ff; --live: #6ee08f;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--ink); font: 15px/1.4 var(--body);
  display: grid; grid-template-columns: 380px 1fr;
}
#map { height: 100%; background: var(--bg); }

aside {
  background: var(--panel); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; min-height: 0;
  padding-left: env(safe-area-inset-left, 0px);
}
header { padding: 18px 18px 12px; border-bottom: 1px solid var(--line); display: grid; gap: 6px; }
h1 { font: 800 26px/1 var(--display); margin: 0; text-wrap: balance; }
.status {
  margin: 0; display: flex; align-items: center; gap: 8px;
  color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums;
}
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--live); flex: none; }
.dot.stale { background: var(--stale); }

.filters { padding: 12px 18px; border-bottom: 1px solid var(--line); display: grid; gap: 10px; }
.modes { display: flex; gap: 6px; }
.lines { display: flex; flex-wrap: wrap; gap: 6px; max-height: 200px; overflow-y: auto; padding: 7px 8px 2px 0; } /* място за звездичките на любимите */

/* Бутон за свиване на страничния панел — езиче на ръба му. */
body { transition: grid-template-columns .25s ease; }
body.panel-collapsed { grid-template-columns: 0 1fr; }
body.panel-collapsed aside { visibility: hidden; border: 0; }
aside { overflow: hidden; }
.panel-toggle {
  position: fixed; z-index: 20; top: 50%; left: 380px; transform: translateY(-50%);
  width: 22px; height: 56px; padding: 0; display: grid; place-items: center;
  background: var(--panel); color: var(--ink); border: 1px solid var(--line); border-left: 0;
  border-radius: 0 10px 10px 0; box-shadow: 2px 0 8px #0002; cursor: pointer;
  transition: left .25s ease, bottom .25s ease;
}
.panel-toggle:hover { background: var(--bg); }
.panel-toggle:focus-visible { outline: 2px solid var(--bus); outline-offset: 2px; }
.panel-toggle svg { transition: transform .25s; }
body.panel-collapsed .panel-toggle { left: 0; }
body.panel-collapsed .panel-toggle svg { transform: rotate(180deg); }
@media (prefers-reduced-motion: reduce) { body, .panel-toggle, .panel-toggle svg { transition: none; } }
button { font: inherit; color: inherit; cursor: pointer; }
.mode {
  border: 1px solid var(--line); background: var(--bg); border-radius: 999px;
  padding: 4px 12px; font-size: 13px;
}
.mode.active { background: var(--ink); color: var(--panel); border-color: var(--ink); }
.chip {
  position: relative; min-width: 38px; border: 2px solid var(--c); background: transparent; color: var(--c);
  border-radius: 6px; padding: 3px 6px; font: 800 15px/1.1 var(--display); text-align: center;
}
.chip.on { background: var(--c); color: var(--on-color); }
.chip .count { font: 600 11px var(--body); opacity: .8; margin-left: 3px; }
.chip.idle { opacity: .4; }
.chip.idle:hover, .chip.idle:focus-visible { opacity: .8; }
button:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }

.list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.list li > button {
  all: unset; box-sizing: border-box; width: 100%; cursor: pointer;
  display: grid; grid-template-columns: 44px 1fr auto; gap: 10px; align-items: center;
  padding: 9px 18px; border-bottom: 1px solid var(--line);
}
.list li > button:hover, .list li > button:focus-visible { background: var(--bg); }
.list .badge {
  font: 800 17px/1 var(--display); color: var(--on-color); background: var(--c);
  border-radius: 6px; text-align: center; padding: 6px 0;
}
.where { min-width: 0; font-size: 13.5px; }
.where b { font-weight: 600; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.where small { color: var(--muted); }
.meta { font-size: 12px; color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; }
.old { opacity: .55; }
.empty { padding: 18px; color: var(--muted); }

/* Маркери на колите */
.veh { width: 30px; height: 30px; cursor: pointer; }
.veh .pin { position: relative; width: 30px; height: 30px; }
.veh .arrow { position: absolute; inset: -7px; transition: transform .6s; }
.veh .num {
  position: absolute; inset: 3px; border-radius: 50%; background: var(--c); color: var(--on-color);
  border: 2px solid var(--panel); font: 800 12px/20px var(--display); text-align: center;
  /* няколко слоя все по-широка и по-светла сянка: плавен преход вместо тъмно петно */
  /* тънък тъмен ръб + стегната сянка: когато иконите се застъпват, горната хвърля видима
     сянка върху долната; по-широките слоеве дават мекото „издигане“ над картата */
  box-shadow: 0 0 0 1px #00000033, 0 2px 3px #00000059, 0 4px 8px #00000033, 0 10px 20px #0000001f,
    inset 0 1px 0 #ffffff40;
  z-index: 1;
}
/* разлята сянка на земята под иконата — дава усещане за височина */
.veh .pin::after {
  content: ""; position: absolute; left: -6px; right: -6px; bottom: -14px; height: 20px;
  border-radius: 50%; background: radial-gradient(closest-side, #00000033, #00000014 60%, transparent);
  filter: blur(4px);
}
.veh.stale .num { opacity: .45; }
/* Балончета (MapLibre) */
.maplibregl-popup-content {
  font: 14px/1.45 var(--body); color: var(--ink);
  /* леко прозрачно, картата отдолу размита — текстът остава четим */
  background: color-mix(in srgb, var(--panel) 84%, transparent);
  -webkit-backdrop-filter: blur(7px) saturate(1.2); backdrop-filter: blur(7px) saturate(1.2);
  border: 1px solid color-mix(in srgb, var(--line) 70%, transparent);
  border-radius: 12px; padding: 12px 14px;
  /* мека сива сянка встрани върху картата */
  box-shadow: 0 2px 6px #0000001f, 0 10px 30px -4px #00000038;
  cursor: grab; touch-action: none;
}
.maplibregl-popup.dragging .maplibregl-popup-content { cursor: grabbing; box-shadow: 0 4px 10px #00000026, 0 18px 40px -6px #00000047; }
.maplibregl-popup-content button { cursor: pointer; }
/* Преместено встрани — стрелката вече не сочи колата */
.maplibregl-popup.moved .maplibregl-popup-tip { display: none; }
.maplibregl-popup-content b { font: 800 18px var(--display); }
.maplibregl-popup-close-button { font-size: 20px; padding: 0 8px; color: var(--muted); }
.maplibregl-popup-anchor-top .maplibregl-popup-tip, .maplibregl-popup-anchor-top-left .maplibregl-popup-tip,
.maplibregl-popup-anchor-top-right .maplibregl-popup-tip { border-bottom-color: color-mix(in srgb, var(--panel) 84%, transparent); }
.maplibregl-popup-anchor-bottom .maplibregl-popup-tip, .maplibregl-popup-anchor-bottom-left .maplibregl-popup-tip,
.maplibregl-popup-anchor-bottom-right .maplibregl-popup-tip { border-top-color: color-mix(in srgb, var(--panel) 84%, transparent); }
.maplibregl-popup-anchor-left .maplibregl-popup-tip { border-right-color: color-mix(in srgb, var(--panel) 84%, transparent); }
.maplibregl-popup-anchor-right .maplibregl-popup-tip { border-left-color: color-mix(in srgb, var(--panel) 84%, transparent); }
.tip .maplibregl-popup-content { padding: 4px 8px; font-size: 13px; border-radius: 6px; }
.tip { pointer-events: none; }
/* Бутоните на картата */
/* MapLibre прави бутоните в групата display:block — връщаме центрирането. */
.maplibregl-ctrl-group button.ctl-btn {
  width: 29px; height: 29px; padding: 0; display: grid; place-items: center;
  background: var(--ctl); color: var(--ctl-ink); border-radius: 4px; line-height: 1;
}
.maplibregl-ctrl-group button.ctl-btn svg { display: block; }
/* Превключвател 2D / 3D: оцветена е включената част */
.tilt-switch button.ctl-btn { font: 800 12px var(--display); color: #666; }
.tilt-switch button.ctl-btn[aria-pressed="true"] { background: var(--accent); color: var(--on-color); }
.tilt-switch button.ctl-btn[aria-pressed="true"]:hover { background: var(--accent); }

/* Вход */
.top { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.account { display: flex; align-items: center; gap: 8px; font-size: 13px; min-width: 0; flex: none; }
.account img { border-radius: 50%; }
.account .who { max-width: 110px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.muted { color: var(--muted); }
.link { all: unset; cursor: pointer; color: var(--bus); font-size: 13px; text-decoration: underline; text-underline-offset: 2px; }
.link:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.btn {
  border: 1px solid var(--line); background: var(--bg); border-radius: 8px; padding: 6px 12px; font-size: 14px;
}
.btn.sm { padding: 3px 9px; font-size: 13px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-color); font-weight: 600; }
.icon-btn {
  border: 1px solid var(--line); background: var(--bg); border-radius: 8px;
  width: 34px; height: 34px; flex: none; font-size: 17px; line-height: 1; padding: 0;
}
.star {
  border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  border-radius: 999px; padding: 4px 12px 4px 10px; font-size: 13px; font-weight: 600;
}
.star:hover { border-color: var(--fav-border); }
.star[aria-pressed="true"] { background: var(--fav-bg); border-color: var(--fav-border); color: var(--fav-ink); }
/* самата звезда (първият знак в бутона) — жълта, когато е любимо */
.star[aria-pressed="true"]::first-letter { color: var(--fav-star); }

/* Раздели */
.tabs { display: flex; border-bottom: 1px solid var(--line); padding: 0 12px; }
.tabs [role="tab"] {
  all: unset; cursor: pointer; padding: 10px 10px 8px; font: 600 14px var(--body); color: var(--muted);
  border-bottom: 3px solid transparent;
}
.tabs [role="tab"][aria-selected="true"] { color: var(--ink); border-bottom-color: var(--bus); }
.tabs [role="tab"]:focus-visible { outline: 2px solid var(--ink); outline-offset: -2px; }
.tab { display: flex; flex-direction: column; min-height: 0; flex: 1; }
.tab[hidden] { display: none; }
.tab.scroll { overflow-y: auto; }
.line-bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-size: 14px; }
/* Любима линия: малка жълта звезда в горния десен ъгъл на бутона */
.chip.is-fav::after {
  content: "★"; position: absolute; top: -8px; right: -7px;
  font: 11px/1 var(--body); color: var(--fav-star);
  text-shadow: 0 0 2px var(--panel), 0 0 2px var(--panel), 0 0 3px var(--panel);
}

/* Пътувания */
.planner { display: grid; gap: 8px; padding: 12px 18px; border-bottom: 1px solid var(--line); position: relative; }
.planner label { display: grid; gap: 3px; font-size: 12px; color: var(--muted); }
.field { display: flex; gap: 6px; }
.planner input, .planner select {
  font: inherit; color: var(--ink); background: var(--bg); border: 1px solid var(--line);
  border-radius: 8px; padding: 7px 10px; min-width: 0; flex: 1; width: 100%;
}
.planner input:focus-visible, .planner select:focus-visible { outline: 2px solid var(--bus); outline-offset: 0; }
.planner .row { display: flex; gap: 8px; }

.results { display: grid; }
.save-bar { padding: 10px 18px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.direction h3, .nearby h3, .fav-group h3 {
  font: 800 17px var(--display); margin: 0; padding: 12px 18px 6px; border-top: 1px solid var(--line);
}
.direction .more { margin: 0 18px 6px; }
.journeys { list-style: none; margin: 0; padding: 0; }
.journeys.hide-past > li.past { display: none; }
.jrny {
  all: unset; box-sizing: border-box; width: 100%; cursor: pointer;
  display: grid; grid-template-columns: 44px 52px 1fr auto; gap: 10px; align-items: center;
  padding: 8px 18px; border-bottom: 1px solid var(--line);
}
.jrny:hover, .jrny:focus-visible, .jrny[aria-expanded="true"] { background: var(--bg); }
.past .jrny { opacity: .5; }
.jt { display: grid; font-variant-numeric: tabular-nums; }
.jt b { font: 800 19px/1 var(--display); }
.jt small, .jw small, .js { color: var(--muted); font-size: 12px; }
.jw { min-width: 0; font-size: 13.5px; }
.jw b { font-weight: 600; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.js { text-align: right; font-variant-numeric: tabular-nums; max-width: 90px; }
.live { color: var(--live); font-weight: 600; }
.badge {
  font: 800 17px/1 var(--display); color: var(--on-color); background: var(--c);
  border-radius: 6px; text-align: center; padding: 6px 0; min-width: 34px; display: inline-block;
}
.detail { padding: 6px 18px 12px 72px; border-bottom: 1px solid var(--line); background: var(--bg); }
.live-note { margin: 4px 0 8px; font-size: 13px; }
.stops { list-style: none; margin: 0; padding: 0; font-size: 13.5px; }
.stops li {
  display: grid; grid-template-columns: 54px 1fr auto; gap: 8px; padding: 3px 0 3px 10px; cursor: pointer;
  border-left: 3px solid var(--line); font-variant-numeric: tabular-nums;
}
.stops li.board, .stops li.alight { border-left-color: var(--bus); font-weight: 600; }
.stops li.after { opacity: .5; }
.stops .t { display: grid; }
.stops .est { color: var(--stale); font-weight: 600; }
.stops .tag { color: var(--bus); font-size: 11px; text-transform: uppercase; letter-spacing: .03em; align-self: center; }
.stops .here { color: var(--live); font-size: 12px; font-weight: 600; }

.deps { list-style: none; margin: 4px 0 0; padding: 0; }
.dep {
  all: unset; box-sizing: border-box; width: 100%; cursor: pointer;
  display: grid; grid-template-columns: 38px 46px 1fr auto; gap: 8px; align-items: center; padding: 4px 0;
  font-size: 13px;
}
.dep .badge { font-size: 14px; padding: 4px 0; min-width: 0; }
.dep .t { font-variant-numeric: tabular-nums; }
.dep .hs { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dep small { color: var(--muted); text-align: right; }
.dep.past { opacity: .5; }
.dep:hover .hs, .dep:focus-visible .hs { text-decoration: underline; }
.deps .empty { padding: 4px 0; font-size: 13px; }

.nearby-list, .fav-list { list-style: none; margin: 0; padding: 0 18px 10px; }
.nearby-list > li { padding: 8px 0; border-bottom: 1px solid var(--line); }
.stop-name { font-weight: 600; color: var(--ink); text-decoration: none; margin-right: 6px; }

/* Любими */
.hint { padding: 18px; display: grid; gap: 10px; }
.hint p { margin: 0; }
.fav { display: flex; align-items: flex-start; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.fav-main { all: unset; cursor: pointer; flex: 1; display: grid; min-width: 0; }
.fav-main small { color: var(--muted); font-size: 12px; }
.fav-main:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.fav .icon-btn { width: 28px; height: 28px; font-size: 13px; }
.fav-deps { flex-basis: 100%; }
.fav-list.lines { display: flex; flex-wrap: wrap; gap: 8px; }
.fav.line { border: 0; padding: 0; align-items: center; gap: 2px; }

/* Балонче на спирка */
.stop-pop { display: grid; gap: 6px; }
.stop-pop .row { display: flex; gap: 6px; flex-wrap: wrap; }
.stop-pop .deps { max-height: 220px; overflow-y: auto; }

/* Моята позиция */
.me span {
  display: block; width: 18px; height: 18px; border-radius: 50%; background: #2b7de9;
  border: 3px solid #fff; box-shadow: 0 0 0 1px #0003, 0 1px 6px #0006;
}
.ctl-btn {
  all: unset; box-sizing: border-box; cursor: pointer; width: 34px; height: 34px;
  display: grid; place-items: center; background: var(--ctl); color: var(--ctl-ink); border-radius: 4px;
}
.ctl-btn:hover { background: #f4f4f4; }
.ctl-btn:focus-visible { outline: 2px solid #2b7de9; }
.ctl-btn.locate.on { color: #2b7de9; }

/* Стил на картата */
.style-ctl { position: relative; }
.style-menu {
  position: absolute; right: 0; top: 40px; width: min(330px, calc(100vw - 32px));
  background: var(--panel); color: var(--ink); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px; box-shadow: 0 6px 24px #0003; display: grid; gap: 10px; font: 14px var(--body);
}
.style-menu[hidden] { display: none; }
.style-menu small { color: var(--muted); }
.style-opts { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.style-opt {
  all: unset; cursor: pointer; display: grid; gap: 4px; justify-items: center; font-size: 12px; text-align: center;
}
.style-opt span {
  width: 64px; height: 52px; border-radius: 10px; border: 2px solid var(--line); background-size: cover;
}
.style-opt[aria-pressed="true"] span { border-color: var(--bus); box-shadow: 0 0 0 2px var(--bus); }
.style-opt[aria-pressed="true"] { font-weight: 600; }
.style-opt:focus-visible span { outline: 2px solid var(--ink); outline-offset: 2px; }
/* Мини прегледи: плочка 15/18717/12110 над центъра на града. */
.s-simple span { background-image: url(https://server.arcgisonline.com/ArcGIS/rest/services/Canvas/World_Light_Gray_Base/MapServer/tile/15/12110/18717); }
.s-rail span { background-image: url(https://tiles.openrailwaymap.org/standard/15/18717/12110.png), url(https://server.arcgisonline.com/ArcGIS/rest/services/Canvas/World_Light_Gray_Base/MapServer/tile/15/12110/18717); }
.s-osm span { background-image: url(https://tile.openstreetmap.org/15/18717/12110.png); }
.s-satellite span { background-image: url(https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/15/12110/18717); }

#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); z-index: 2000;
  background: var(--ink); color: var(--panel); padding: 9px 16px; border-radius: 10px; font-size: 14px;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; max-width: calc(100vw - 32px);
}
#toast.on { opacity: 1; transform: translate(-50%, 0); }

@media (prefers-reduced-motion: reduce) { .veh .arrow { transition: none; } }
.jw small { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.icon-btn svg { vertical-align: middle; }

/* Панел „Курс“ — излиза върху разделите */
aside { position: relative; }
.trip-view {
  position: absolute; inset: 0; z-index: 5; background: var(--panel); overflow-y: auto;
  padding-left: env(safe-area-inset-left, 0px);
}
.trip-view[hidden] { display: none; }
.tv-head { position: sticky; top: 0; background: var(--panel); padding: 14px 18px 8px; border-bottom: 1px solid var(--line); z-index: 1; }
.tv-head h2 { margin: 8px 0 4px; font: 800 20px var(--display); display: flex; align-items: center; gap: 10px; }
.tv-head h2 .badge { padding: 6px 8px; }
.stops.full { padding: 8px 18px 18px; }
.stops li.gone { opacity: .45; }
.stops li.now { border-left-color: var(--live); }
.maplibregl-popup-content .eta { font: 800 15px var(--body); }
.maplibregl-popup-content .btn { margin-top: 6px; }

/* Разписание на място */
.tt-title { font: 800 20px var(--display); margin: 0; padding: 12px 18px 4px; }
.tt-links { margin: 0; padding: 0 18px 10px; display: flex; gap: 8px; flex-wrap: wrap; align-items: baseline; }
.tt-group { padding: 6px 18px 10px; }
.tt-line { display: flex; align-items: center; gap: 8px; font-size: 13.5px; font-weight: 600; margin-bottom: 6px; }
.tt-times { display: flex; flex-wrap: wrap; gap: 6px; }
.tt-time {
  border: 1px solid var(--line); background: var(--bg); border-radius: 6px; padding: 3px 8px;
  font: 600 14px var(--body); font-variant-numeric: tabular-nums;
}
.tt-time.past { opacity: .4; }
.tt-time.on { border-color: var(--live); color: var(--live); }
.tt-time s { opacity: .6; font-weight: 400; }
.tt-legend { padding: 4px 18px 16px; font-size: 12px; margin: 0; }
.tt-legend .tt-time { font-size: 12px; padding: 1px 6px; }
.stops .est.early { color: var(--live); }
.dep .t s, .jt s { opacity: .55; font-weight: 400; }
.line-bar .route-mode { flex-basis: 100%; margin: 0; font-size: 12.5px; }
.veh.off .num { filter: grayscale(.75) brightness(1.1); }
.btn.google { display: inline-flex; align-items: center; gap: 8px; background: var(--panel); font-weight: 600; white-space: nowrap; }

/* Етикети с часа по спирките на избрания курс */
.stop-label {
  pointer-events: none; white-space: nowrap; max-width: 170px; overflow: hidden; text-overflow: ellipsis;
  background: var(--label-bg); color: var(--label-ink); border: 1px solid var(--label-border);
  border-radius: 7px; padding: 2px 7px;
  font: 12px/1.35 var(--body); box-shadow: 0 1px 2px #0003, 0 2px 8px #0002;
}
.stop-label b { font-weight: 700; font-variant-numeric: tabular-nums; }
.stop-label.k-board, .stop-label.k-alight { background: var(--bus); color: var(--on-color); font-weight: 600; }
.stop-label.gone { opacity: .55; }

/* Контролите на MapLibre по темата (иконите им са тъмни картинки — в тъмна тема ги обръщаме) */
.maplibregl-ctrl-group { background: var(--ctl); box-shadow: 0 0 0 2px var(--shadow); }
.maplibregl-ctrl-group button + button { border-top-color: var(--line); }
[data-scheme="dark"] .maplibregl-ctrl-icon { filter: invert(.9); }
.maplibregl-ctrl-attrib { background: color-mix(in srgb, var(--ctl) 85%, transparent) !important; color: var(--ctl-ink); }
.maplibregl-ctrl-attrib a { color: var(--ctl-ink); }
[data-scheme="dark"] .maplibregl-ctrl-attrib-button { filter: invert(.9); }

/* ---------- Прозорче „Изглед“ ---------- */
.top-actions { display: flex; align-items: center; gap: 8px; flex: none; }
.appearance-btn { width: 32px; height: 32px; display: grid; place-items: center; color: var(--ink); }
.appearance-btn[aria-expanded="true"] { background: var(--ink); color: var(--panel); border-color: var(--ink); }
header { position: relative; }
.appearance {
  position: absolute; z-index: 30; top: calc(100% - 4px); right: 12px; left: 12px; max-width: 356px; margin-left: auto;
  background: var(--panel); color: var(--ink); border: 1px solid var(--line); border-radius: 16px;
  padding: 14px 16px 16px; box-shadow: 0 12px 40px var(--shadow), 0 2px 6px var(--shadow);
  animation: ap-in .16s ease-out;
}
.appearance[hidden] { display: none; }
@keyframes ap-in { from { opacity: 0; transform: translateY(-6px); } }
@media (prefers-reduced-motion: reduce) { .appearance { animation: none; } }
.ap-head { display: flex; align-items: center; justify-content: space-between; }
.ap-head h2 { margin: 0; font: 800 20px var(--display); }
.ap-close { width: 28px; height: 28px; font-size: 13px; }
.appearance h3 { margin: 14px 0 8px; font: 600 12px var(--body); color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.ap-hint { margin: 6px 0 0; font-size: 12px; color: var(--muted); min-height: 1em; }

.ap-modes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; padding: 4px; background: var(--bg); border-radius: 12px; }
.ap-modes button {
  all: unset; cursor: pointer; display: grid; justify-items: center; gap: 4px; padding: 8px 4px; border-radius: 9px;
  font: 600 12.5px var(--body); color: var(--muted); text-align: center;
}
.ap-modes svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.ap-modes svg .fill { fill: currentColor; stroke: none; }
.ap-modes button[aria-checked="true"] { background: var(--panel); color: var(--ink); box-shadow: 0 1px 3px var(--shadow); }
.ap-modes button:focus-visible { outline: 2px solid var(--accent); }

.ap-palettes { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.ap-palettes button {
  all: unset; cursor: pointer; display: grid; gap: 1px; padding: 6px; border-radius: 12px;
  border: 1.5px solid var(--line); background: var(--panel);
}
.ap-palettes button:hover { border-color: var(--muted); }
.ap-palettes button[aria-checked="true"] { border-color: var(--accent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 30%, transparent); }
.ap-palettes button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.ap-swatch { display: grid; place-items: center; height: 54px; border-radius: 8px; margin-bottom: 5px; border: 1px solid #0000000f; }
.ap-card { display: flex; gap: 6px; padding: 7px 10px; border-radius: 8px; box-shadow: 0 1px 4px #00000022; }
.ap-card i { width: 16px; height: 16px; border-radius: 50%; display: block; box-shadow: 0 1px 2px #0003; }
.ap-name { font: 700 13.5px var(--body); padding: 0 2px; }
.ap-note { font-size: 11.5px; color: var(--muted); padding: 0 2px 2px; }

/* „По маршрут“ / „По линия“ */
.trip-modes {
  display: grid; grid-template-columns: 1fr 1fr; gap: 4px; margin: 12px 18px 0; padding: 4px;
  background: var(--bg); border-radius: 12px;
}
.trip-modes button {
  all: unset; cursor: pointer; text-align: center; padding: 7px 6px; border-radius: 9px;
  font: 600 13.5px var(--body); color: var(--muted);
}
.trip-modes button[aria-checked="true"] { background: var(--panel); color: var(--ink); box-shadow: 0 1px 3px var(--shadow); }
.trip-modes button:focus-visible { outline: 2px solid var(--accent); }
.planner select { appearance: auto; }
.tt-title .badge { vertical-align: 2px; margin-right: 4px; font-size: 15px; padding: 4px 6px; }
.tt-title small { display: block; font: 13px var(--body); margin-top: 2px; }
.planner[hidden] { display: none; }
.results > .more { margin: 0 18px 8px; justify-self: start; }

/* „По линия“: курсовете по посока — едро и ясно (удобно и за по-възрастни хора) */
.lt-dir { border-top: 1px solid var(--line); padding: 14px 18px 10px; }
.lt-dir h3 { margin: 0; font: 800 21px/1.2 var(--display); display: flex; gap: 8px; align-items: baseline; }
.lt-arrow { color: var(--accent); font-size: 18px; }
.lt-from { margin: 2px 0 10px; color: var(--muted); font-size: 14px; }
.lt-dir .more { display: inline-block; margin: 0 0 8px; font-size: 14px; }
.lt-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.lt-list.hide-past > li.past { display: none; }
.lt-btn {
  all: unset; box-sizing: border-box; width: 100%; cursor: pointer; min-height: 58px;
  display: grid; grid-template-columns: auto 1fr auto; gap: 14px; align-items: center;
  padding: 10px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel);
}
.lt-btn:hover, .lt-btn:focus-visible { border-color: var(--accent); background: var(--bg); }
.lt-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.lt-dep { font: 800 26px/1 var(--display); font-variant-numeric: tabular-nums; }
.lt-mid { display: grid; gap: 2px; min-width: 0; }
.lt-arr { font-size: 15px; }
.lt-note { font-size: 13px; color: var(--muted); }
.lt-status { font-size: 14px; text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; max-width: 120px; }
.lt-status .live { font-weight: 700; }
.past .lt-btn { opacity: .55; }
.fallback-note {
  margin: 6px 18px 10px; padding: 8px 12px; border-radius: 10px; font-size: 13px;
  background: var(--label-bg); color: var(--label-ink); border: 1px solid var(--label-border);
}

/* ---------- Телефон: картата на цял екран, панелът — изтеглящ се лист отдолу ----------
   Височината на листа е --sheet-h (задава я sheet.js): свит (само заглавие и раздели), наполовина,
   почти на цял екран. */
.sheet-handle { display: none; }
@media (max-width: 720px) {
  html, body { overflow: hidden; overscroll-behavior: none; }
  body { display: block; }
  #map { position: fixed; inset: 0; height: 100dvh; }
  .panel-toggle { display: none; }
  aside {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 15;
    height: var(--sheet-h, 50dvh); max-height: calc(100dvh - 48px);
    border: 0; border-radius: 18px 18px 0 0; box-shadow: 0 -4px 24px var(--shadow), 0 -1px 0 var(--line);
    padding: 0 env(safe-area-inset-right, 0px) env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);
    transition: height .28s cubic-bezier(.2, .8, .2, 1);
    overflow: hidden;
  }
  body.sheet-dragging aside { transition: none; }
  body.panel-collapsed aside { visibility: visible; }

  .sheet-handle {
    all: unset; display: block; width: 100%; height: 22px; cursor: grab; touch-action: none; flex: none;
  }
  .sheet-handle::before {
    content: ""; display: block; width: 44px; height: 5px; margin: 9px auto 0; border-radius: 3px; background: var(--line);
  }
  .sheet-handle:focus-visible::before { background: var(--accent); }

  header { padding: 0 14px 8px; gap: 2px; touch-action: none; }
  .top { align-items: center; gap: 8px; }
  h1 { font-size: 20px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
  .top-actions { gap: 6px; }
  .account .who { display: none; }
  .account img { width: 30px; height: 30px; }
  .appearance-btn { width: 36px; height: 36px; }
  .status { font-size: 12px; }
  .appearance { left: 8px; right: 8px; max-width: none; top: calc(100% + 2px); max-height: 70dvh; overflow-y: auto; }

  .tabs { padding: 0 8px; }
  .tabs [role="tab"] { flex: 1; text-align: center; padding: 10px 4px 9px; font-size: 15px; }

  .filters { padding: 10px 14px; gap: 8px; }
  .modes { overflow-x: auto; }
  .mode { padding: 6px 14px; font-size: 14px; flex: none; }
  .lines { max-height: 30dvh; gap: 6px; }
  .chip { min-width: 42px; padding: 6px 7px; font-size: 16px; }
  .list li > button { padding: 10px 14px; }

  .planner { padding: 12px 14px; }
  .planner input, .planner select { font-size: 16px; padding: 10px 12px; } /* 16px — iOS не увеличава при фокус */
  .btn { padding: 9px 14px; font-size: 15px; }
  .trip-modes { margin: 12px 14px 0; }
  .lt-dir { padding: 14px 14px 10px; }
  .direction h3, .nearby h3, .fav-group h3 { padding: 12px 14px 6px; }
  .jrny { padding: 10px 14px; }
  .detail { padding: 6px 14px 12px 14px; }
  .tv-head { padding: 6px 14px 8px; }
  .stops.full { padding: 8px 14px 18px; }

  /* Контролите на картата над листа, а не под него */
  .maplibregl-ctrl-top-left, .maplibregl-ctrl-top-right { top: env(safe-area-inset-top, 0px); }
  .maplibregl-popup { max-width: calc(100vw - 24px) !important; }
  #toast { bottom: calc(var(--sheet-h, 50dvh) + 12px); }
}

/* Компасът — само когато картата е завъртяна */
#map:not(.map-rotated) .maplibregl-ctrl-compass { display: none; }

/* Бутонът на Google е iframe: при тъмна тема браузърът му слага бял фон, ако страницата е
   „color-scheme: dark“ а той — светъл. Казваме му, че е светъл, и фонът става прозрачен. */
.login-slot { color-scheme: light; border-radius: 999px; }
.login-slot iframe { color-scheme: light; }
.line-bar [data-clear] { margin-left: auto; }
.tv-head .back { margin-bottom: 4px; }

/* Влаковете — свой цвят във всички схеми */
:root { --train: #7a4fc4; }
:root[data-scheme="dark"] { --train: #b89cff; }
:root[data-palette="contrast"] { --train: #5b1fa8; }

/* Превключвател „Градски транспорт / Влакове“ */
.system-switch { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; margin: 0 12px 8px; padding: 4px; background: var(--bg); border-radius: 12px; }
.system-switch button {
  all: unset; cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 7px;
  padding: 8px 6px; border-radius: 9px; font: 600 14px var(--body); color: var(--muted); text-align: center;
}
.system-switch button[aria-checked="true"] { background: var(--panel); color: var(--ink); box-shadow: 0 1px 3px var(--shadow); }
.system-switch button[data-system="rail"][aria-checked="true"] { color: var(--train); }
.system-switch button:focus-visible { outline: 2px solid var(--accent); }
/* В режим „Влакове“: без филтъра автобуси/тролейбуси и без „По линия“ (категориите са с по стотици влака) */
[data-system="rail"] .modes, [data-system="rail"] .trip-modes { display: none; }
/* Балончетата — над иконите на колите и етикетите по спирките (те са с голям z-index по дълбочина) */
.maplibregl-popup { z-index: 1000000; }
.list .empty .next-trips { display: block; margin-top: 6px; color: var(--ink); }
/* „На живо“: линия без кола на курс — следващите курсове за деня */
.list .next-head { padding: 12px 18px 6px; font: 800 17px var(--display); }
.list .next-trip { padding: 0 18px 6px; }
.list .next-trip .lt-btn { min-height: 54px; }
.list .next-trip .lt-dep { font-size: 22px; }
.list .next-trip .lt-note b { color: var(--accent); font-weight: 600; }

/* Изгледът на курса: спирките в разгъваем блок */
.stops-box { margin: 10px 18px 18px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); }
.stops-box > summary {
  list-style: none; cursor: pointer; display: grid; gap: 4px; padding: 12px 40px 12px 14px; position: relative;
}
.stops-box > summary::-webkit-details-marker { display: none; }
.stops-box > summary::after {
  content: ""; position: absolute; right: 16px; top: 50%; width: 9px; height: 9px; margin-top: -7px;
  border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: rotate(45deg); transition: transform .2s;
}
.stops-box[open] > summary::after { transform: rotate(-135deg); margin-top: -2px; }
.stops-box > summary:hover { background: var(--bg); border-radius: 12px; }
.stops-box > summary:focus-visible { outline: 2px solid var(--accent); border-radius: 12px; }
.sb-route { font-size: 14.5px; line-height: 1.4; }
.sb-route b { font-variant-numeric: tabular-nums; }
.sb-arrow { color: var(--accent); }
.sb-more { font-size: 13px; color: var(--accent); font-weight: 600; }
.stops-box .stops.full { padding: 4px 14px 14px; border-top: 1px solid var(--line); }
@media (prefers-reduced-motion: reduce) { .stops-box > summary::after { transition: none; } }

/* Първо зареждане: иконите падат отгоре и се приземяват с лек отскок; сянката им расте. */
.veh.drop .pin { animation: veh-drop 950ms cubic-bezier(.33, 0, .67, 1) var(--drop-delay, 0ms) both; }
.veh.drop .pin::after { animation: veh-drop-shadow 950ms ease-in var(--drop-delay, 0ms) both; }
@keyframes veh-drop {
  0%   { transform: translateY(-110vh); opacity: 0; }
  8%   { opacity: 1; }
  58%  { transform: translateY(0); animation-timing-function: cubic-bezier(.2, .8, .4, 1); }
  72%  { transform: translateY(-16px); animation-timing-function: cubic-bezier(.6, 0, .8, .4); }
  84%  { transform: translateY(0); }
  92%  { transform: translateY(-4px); }
  100% { transform: translateY(0); opacity: 1; }
}
@keyframes veh-drop-shadow {
  0%   { transform: scale(.2); opacity: 0; }
  58%  { transform: scale(1.15); opacity: 1; }
  72%  { transform: scale(.85); }
  100% { transform: scale(1); opacity: 1; }
}
@media (prefers-reduced-motion: reduce) { .veh.drop .pin, .veh.drop .pin::after { animation: none; } }
