:root {
  --bg: #f2f4f8;
  --card: #ffffff;
  --text: #16202e;
  --muted: #66707f;
  --accent: #1c64d9;
  --ok: #0d8a4f;
  --ok-bg: #e0f5ea;
  --sched: #66707f;
  --sched-bg: #eceff3;
  --warn: #9a6b00;
  --warn-bg: #fdf3d8;
  --bad: #c2312b;
  --bad-bg: #fbe5e4;
  --border: #dde3ec;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #10151d;
    --card: #1a2230;
    --text: #e8edf5;
    --muted: #93a0b4;
    --accent: #6ba3ff;
    --ok: #4cd48c;
    --ok-bg: #133525;
    --sched: #9aa7ba;
    --sched-bg: #232d3d;
    --warn: #eec55e;
    --warn-bg: #3a2f12;
    --bad: #ff7a72;
    --bad-bg: #43201e;
    --border: #2a3547;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
#app { max-width: 560px; margin: 0 auto; padding: 14px 14px 40px; }
.loading { color: var(--muted); text-align: center; padding: 40px 0; }

header { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
header h1 { font-size: 22px; margin: 0; flex: 1; }
header h1 span { color: var(--accent); }
select {
  background: var(--card); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px;
  padding: 8px 10px; font-size: 14px; max-width: 55%;
}

.search-box { position: relative; margin-bottom: 10px; }
input[type="search"] {
  width: 100%; padding: 12px 46px 12px 14px; font-size: 16px;
  border: 1px solid var(--border); border-radius: 12px;
  background: var(--card); color: var(--text); outline: none;
}
.scan-btn {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  border: none; background: none; font-size: 20px; cursor: pointer;
  padding: 4px 8px; line-height: 1;
}
.scan-modal {
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(0,0,0,.75);
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.scan-modal.hidden { display: none; }
.scan-box {
  background: var(--card); border: 1px solid var(--border); border-radius: 16px;
  width: 100%; max-width: 420px; overflow: hidden;
}
.scan-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 14px; font-weight: 600; border-bottom: 1px solid var(--border);
}
.scan-close { border: none; background: none; color: var(--text); font-size: 18px; cursor: pointer; }
.scan-video { width: 100%; max-height: 60vh; background: #000; display: block; }
.scan-msg { padding: 12px 14px; font-size: 13.5px; color: var(--muted); }
input[type="search"]:focus { border-color: var(--accent); }
.results {
  position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 5;
  background: var(--card); border: 1px solid var(--border); border-radius: 12px;
  overflow: hidden; box-shadow: 0 8px 24px rgba(0,0,0,.12);
}
.results:empty { display: none; }
.result {
  display: flex; justify-content: space-between; gap: 8px;
  padding: 10px 14px; cursor: pointer; border-bottom: 1px solid var(--border);
}
.result:last-child { border-bottom: none; }
.result:hover { background: var(--sched-bg); }
.result .code { color: var(--muted); font-variant-numeric: tabular-nums; }

.favs { margin-bottom: 12px; }
.fav-title { font-size: 12px; color: var(--muted); margin: 6px 0 4px; text-transform: uppercase; letter-spacing: .04em; }
.fav-row { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 6px; }
.fav-chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--card); border: 1px solid var(--border);
  border-radius: 999px; padding: 6px 12px; font-size: 14px; cursor: pointer;
  max-width: 100%;
}
.fav-chip .code { color: var(--muted); }
.fav-chip .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fav-chip.route .badge { min-width: 28px; font-size: 12px; padding: 2px 6px; }

.map-controls { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; flex-wrap: wrap; }
.map-toggle {
  display: flex; align-items: center; gap: 8px;
  font-size: 13.5px; color: var(--text); cursor: pointer;
}
.map-toggle input { width: 16px; height: 16px; accent-color: var(--accent); }
.locate-panel-btn {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--accent); color: #fff; border: none;
  border-radius: 10px; padding: 8px 14px; font-size: 14px; font-weight: 600; cursor: pointer;
}
.locate-panel-btn:active { opacity: .85; }

.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: 16px; padding: 14px; margin-bottom: 12px;
}
.stop-head { display: flex; align-items: flex-start; gap: 10px; margin-bottom: 6px; }
.stop-head h2 { font-size: 18px; margin: 0; flex: 1; }
.stop-head .code { color: var(--muted); font-size: 13px; }
.star {
  border: none; background: none; font-size: 22px; cursor: pointer;
  color: var(--muted); padding: 2px 6px;
}
.star.active { color: #f0b400; }

.warn-note {
  background: var(--warn-bg); color: var(--warn);
  border-radius: 10px; padding: 8px 12px; font-size: 13.5px; margin: 8px 0;
}

.arr { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.arr:last-child { border-bottom: none; }
.badge {
  min-width: 42px; text-align: center; font-weight: 700; font-size: 15px;
  border-radius: 9px; padding: 6px 8px; background: var(--accent); color: #fff;
}
.arr .mid { flex: 1; min-width: 0; }
.arr .dest { font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.arr .sub { font-size: 12.5px; color: var(--muted); margin-top: 1px; }
.arr .note { font-size: 12.5px; color: var(--warn); margin-top: 2px; }
.arr .right { text-align: right; }
.arr .eta { font-size: 19px; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.arr .when { font-size: 12.5px; color: var(--muted); font-variant-numeric: tabular-nums; }

.chip {
  display: inline-block; font-size: 11.5px; font-weight: 600;
  border-radius: 999px; padding: 3px 8px; margin-top: 4px; white-space: nowrap;
}
.chip.ok { background: var(--ok-bg); color: var(--ok); }
.chip.sched { background: var(--sched-bg); color: var(--sched); }
.chip.warn { background: var(--warn-bg); color: var(--warn); }
.chip.bad { background: var(--bad-bg); color: var(--bad); }

.section-title { font-size: 13px; color: var(--muted); margin: 12px 0 6px; text-transform: uppercase; letter-spacing: .04em; }
.lines { display: flex; flex-wrap: wrap; gap: 8px; }
.line-chip {
  display: inline-flex; align-items: center; gap: 7px;
  border: 1px solid var(--border); border-radius: 10px;
  padding: 5px 9px; font-size: 13px;
}
.line-chip .badge { min-width: 30px; font-size: 13px; padding: 3px 6px; }
.line-chip .hours { color: var(--muted); font-variant-numeric: tabular-nums; }
.line-chip.off { opacity: .75; }
.line-chip.off .hours { color: var(--bad); }

/* --- map --- */
.open-map-btn {
  width: 100%; margin-bottom: 10px; padding: 10px;
  background: var(--card); color: var(--text);
  border: 1px solid var(--border); border-radius: 12px;
  font-size: 14px; cursor: pointer;
}
.open-map-btn:hover { border-color: var(--accent); }
.open-map-btn.active { border-color: var(--accent); color: var(--accent); }
.map-panel { margin-bottom: 12px; }
.map-panel.hidden { display: none; }
#map {
  height: 300px; width: 100%;
  border-radius: 16px; border: 1px solid var(--border);
  background: var(--card); z-index: 1;
}
.map-legend { color: var(--muted); font-size: 12.5px; margin-top: 6px; text-align: center; }
.locate-btn { font-size: 18px; text-align: center; text-decoration: none; line-height: 30px; cursor: pointer; }
.bus-div { background: none; border: none; }
.bus-rot {
  width: 34px; height: 34px; position: relative;
  display: flex; align-items: center; justify-content: center;
}
.bus-pin {
  width: 30px; height: 30px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 12px;
  border: 2px solid #fff; box-shadow: 0 1px 5px rgba(0,0,0,.5);
}
/* стрелка направления движения: треугольник у верхнего края, поворачивается
   вместе с .bus-rot (по азимуту), номер внутри контр-повёрнут и остаётся прямым */
.bus-arrow {
  position: absolute; top: -3px; left: 50%; margin-left: -6px;
  width: 0; height: 0;
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-bottom: 9px solid #fff;
  filter: drop-shadow(0 -1px 1px rgba(0,0,0,.4));
}
.leaflet-popup-content { font: 13px/1.4 system-ui, sans-serif; }
.map-btn { font-size: 18px; }
.map-btn.active { color: var(--accent); }

/* --- route card / thermometer --- */
.badge.clickable, .line-chip.clickable { cursor: pointer; }
.badge.clickable:hover { outline: 2px solid var(--accent); outline-offset: 1px; }
.line-chip.clickable:hover { border-color: var(--accent); }
.back-btn { font-size: 22px; }
.thermo { margin-top: 8px; }
.thermo-stop {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 4px; cursor: pointer; position: relative;
}
.thermo-stop:hover { background: var(--sched-bg); border-radius: 8px; }
.thermo-dot {
  width: 13px; height: 13px; border-radius: 50%;
  border: 3px solid var(--accent); background: var(--card);
  flex: none; z-index: 1;
}
/* соединительная линия между точками */
.thermo-stop:not(:last-child)::before {
  content: ""; position: absolute; left: 10px; top: 50%; height: 100%;
  width: 3px; background: var(--border); z-index: 0;
}
.thermo-name { font-size: 14.5px; }
.thermo-stop.current { font-weight: 700; }
.thermo-stop.current .thermo-dot { background: var(--accent); width: 15px; height: 15px; }
.thermo-stop.current .thermo-name { color: var(--accent); }

.date-row { display: flex; align-items: center; gap: 8px; margin: 4px 0 10px; flex-wrap: wrap; }
.date-chip {
  border: 1px solid var(--border); background: var(--card); color: var(--text);
  border-radius: 999px; padding: 5px 12px; font-size: 13px; cursor: pointer;
}
.date-chip.active { border-color: var(--accent); color: var(--accent); }
.date-input {
  border: 1px solid var(--border); background: var(--card); color: var(--text);
  border-radius: 8px; padding: 4px 8px; font-size: 13px;
}
.feedback-link { display: block; margin-top: 8px; font-size: 12.5px; color: var(--muted); text-decoration: none; }
.feedback-link:hover { color: var(--accent); text-decoration: underline; }

.board-foot { display: flex; justify-content: space-between; gap: 8px; color: var(--muted); font-size: 12.5px; margin-top: 10px; }
.empty { color: var(--muted); text-align: center; padding: 18px 0; }
.error-banner { background: var(--bad-bg); color: var(--bad); border-radius: 12px; padding: 10px 14px; margin-bottom: 12px; }
footer#about { color: var(--muted); font-size: 12.5px; text-align: center; margin-top: 22px; }
