/* app.css — one screen, read at arm's length while walking to a stop.
   Priorities: the number is legible, staleness is obvious, nothing moves. */

:root {
  --bg: #101820;
  --surface: #18232f;
  --surface-2: #1f2d3b;
  --line: #2b3b4c;
  --text: #eef3f7;
  --muted: #93a5b5;
  --accent: #f2b134;        /* one accent, used only for the live signal */
  --good: #4bb98a;
  --warn: #e0873a;
  --bad: #d9594c;
  --radius: 6px;
  --tabbar-h: 56px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100vh;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px));
}

/* ---------- top bar ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
  padding: env(safe-area-inset-top, 0px) 16px 0;
}

.topbar-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
}

.brand {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.status {
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* The gear icon that opens Информации - a settings-shaped screen belongs in
   the corner, not competing with Постојка/Најди for bottom-tab space. */
.settings-btn {
  width: 30px;
  height: 30px;
  border-color: transparent;
  background: transparent;
  color: var(--muted);
}
.settings-btn:active { background: var(--surface-2); }
.settings-btn[aria-pressed="true"] { color: var(--accent); }

.status.live::before {
  content: "";
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--good);
  margin-right: 6px;
  vertical-align: middle;
}

.status.stale::before { background: var(--warn); }
.status.down::before { background: var(--bad); }

.banner {
  cursor: pointer;
  margin: 0 0 12px;
  padding: 10px 12px;
  border-radius: var(--radius);
  background: rgba(217, 89, 76, 0.14);
  border: 1px solid rgba(217, 89, 76, 0.4);
  color: #f4c8c3;
  font-size: 13px;
  line-height: 1.45;
}

/* ---------- favourite stops strip ---------- */

/* Quick-switch row above the stop header, visible whenever at least one stop
   is favourited - this is the only place favourited stops are selectable
   from without going through search first. */
.fav-strip {
  display: flex;
  gap: 8px;
  padding: 12px 16px 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.fav-strip[hidden] { display: none; }

.fav-chip {
  flex: 0 0 auto;
  appearance: none;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  padding: 8px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  max-width: 160px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.fav-chip:active { background: var(--line); }
.fav-chip.is-active { color: var(--accent); border-color: var(--accent); }

/* ---------- stop header ---------- */

.stop-head {
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.stop-name {
  margin: 0;
  font-size: 22px;
  font-weight: 650;
  line-height: 1.25;
}

.stop-meta {
  margin: 6px 0 0;
  font-size: 13px;
  color: var(--muted);
}

.stop-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  flex-wrap: wrap;
}

/* The favourite heart and the notify bell sit right after the stop
   name/meta, side by side. */
.stop-head .heart-btn,
.stop-head .bell-btn { margin-top: 12px; }
.stop-head .heart-btn { margin-right: 8px; }

/* ---------- buttons: rectangular, never pill-shaped ---------- */

.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  padding: 9px 14px;
  border-radius: var(--radius);
  cursor: pointer;
  min-height: 40px;
}

.btn:active { background: var(--line); }
.btn[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); }
.btn-danger { border-color: rgba(217, 89, 76, 0.6); color: #f0a49b; }

/* A small square button carrying only an icon - the refresh icons, the
   favourite heart, the settings gear, the detail view's back arrow. */
.icon-btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--muted);
  cursor: pointer;
}
.icon-btn:active { background: var(--line); }
.icon-btn:disabled { cursor: default; opacity: 0.7; }
.icon-btn .icon { display: flex; }

.heart-btn.is-favourite,
.heart-btn[aria-pressed="true"] { color: var(--accent); border-color: var(--accent); }
/* Outline by default, solid once favourited - one path, opacity does the rest. */
.heart-btn .icon svg { fill-opacity: 0; }
.heart-btn.is-favourite .icon svg,
.heart-btn[aria-pressed="true"] .icon svg { fill-opacity: 1; }

/* The bell stays outlined either way (its own two-part icon already draws a
   solid clapper against an outlined body) - only the button colour changes,
   the same accent-on-active convention as the heart. */
.bell-btn[aria-pressed="true"] { color: var(--accent); border-color: var(--accent); }

/* ---------- arrivals ---------- */

.arrivals {
  list-style: none;
  margin: 0;
  padding: 0;
}

.arrival {
  display: grid;
  grid-template-columns: 54px 1fr auto auto;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
}

.arrival:active { background: var(--surface); }
.arrival:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

.row-refresh.is-spinning,
.icon-btn.is-spinning { color: var(--accent); border-color: var(--accent); }
.row-refresh.is-spinning .refresh-icon svg,
.icon-btn.is-spinning .refresh-icon svg { animation: sb-spin 0.9s linear infinite; }

@keyframes sb-spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.route-badge {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 4px 6px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-weight: 700;
  font-size: 17px;
  font-variant-numeric: tabular-nums;
}

.arrival-main { min-width: 0; }

.headsign {
  display: block;
  font-size: 15px;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.arrival-sub {
  display: block;
  margin-top: 3px;
  font-size: 12px;
  color: var(--muted);
}

.arrival-time {
  text-align: right;
  white-space: nowrap;
}

.time-text {
  display: block;
  font-size: 20px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}

.time-sub {
  display: block;
  font-size: 11px;
  color: var(--muted);
  margin-top: 2px;
  font-variant-numeric: tabular-nums;
}

.arrival.is-due .time-text,
.arrival.is-arriving .time-text,
.arrival.is-at_stop .time-text { color: var(--good); }

.arrival.is-stale { opacity: 0.62; }
.arrival.is-stale .time-text { color: var(--warn); font-size: 15px; }

/* A scheduled row is a prediction, not a sighting. It is deliberately quieter
   than a live row and its badge is dashed, so the two can never be confused at
   a glance. The accent colour stays reserved for a real live signal. */
/* Tracked by GPS, but far enough up the line that the estimate is a range.
   Quieter than a near row, but not dashed: this bus is genuinely being seen. */
.arrival.is-far { opacity: 0.86; }
.arrival.is-far .time-text { font-size: 18px; }

.arrival.is-predicted { opacity: 0.78; }
.arrival.is-predicted .time-text { color: var(--muted); font-size: 16px; }
.arrival.is-predicted .time-sub { color: var(--warn); }
.arrival.is-predicted .route-badge { border-style: dashed; }

/* ---------- bus detail (full screen, one bus) ---------- */

/* `!important` is load-bearing: app.js toggles `panel.hidden` for the tabbed
   panels, but this overlay is shown/hidden directly by js/ui-detail.js the
   same way - the UA stylesheet's [hidden]{display:none} loses to an author
   `display:flex` otherwise, and the overlay would render behind everything. */
#panel-detail {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: var(--bg);
  display: flex;
  flex-direction: column;
}
#panel-detail[hidden] { display: none !important; }

.detail-head {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 0 0 auto;
  padding: calc(env(safe-area-inset-top, 0px) + 12px) 16px 12px;
  border-bottom: 1px solid var(--line);
}

.detail-headsign {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 16px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.detail-body {
  flex: 0 0 auto;
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.detail-time {
  display: block;
  font-size: 38px;
  font-weight: 700;
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
}

.detail-sub {
  display: block;
  margin-top: 2px;
  font-size: 14px;
  color: var(--muted);
}

.detail-age {
  margin: 10px 0 0;
  font-size: 13px;
  color: var(--muted);
  line-height: 1.4;
}

.detail-actions { display: flex; gap: 8px; margin-top: 14px; }
.detail-actions .row-refresh { width: auto; padding: 0 14px; gap: 8px; }

#detail-map {
  flex: 1 1 auto;
  min-height: 0;
  background: var(--surface);
}

.leaflet-container {
  background: var(--surface);
  font: inherit;
}

.bus-pin {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: var(--radius);
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 11px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  position: relative;
}

.bus-pin.is-stale { opacity: 0.62; border-color: var(--warn); }

.bus-num { pointer-events: none; }

/* Rotation lives here, never on the marker root: Leaflet overwrites the root's
   transform on every setLatLng, pan and zoom, which would erase the heading. */
.bus-arrow {
  position: absolute;
  top: -7px;
  left: 50%;
  width: 0;
  height: 0;
  margin-left: -5px;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-bottom: 8px solid var(--accent);
  transform-origin: 50% 21px;
}

.bus-pin.is-stale .bus-arrow { border-bottom-color: var(--warn); }

.bus-dot {
  position: absolute;
  top: -5px;
  left: 50%;
  margin-left: -3px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--muted);
}

/* ---------- states ---------- */

.empty {
  margin: 0;
  padding: 32px 16px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
  text-align: center;
}

.stale-note {
  padding: 10px 16px;
  font-size: 12px;
  color: var(--warn);
  border-bottom: 1px solid var(--line);
}

/* ---------- stop picker ---------- */

.search {
  width: 100%;
  padding: 12px;
  font: inherit;
  font-size: 16px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  min-height: 44px;
}

.search::placeholder { color: var(--muted); }
.pick-wrap { padding: 16px; }

.result {
  display: block;
  width: 100%;
  text-align: left;
  padding: 13px 16px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  color: var(--text);
  font: inherit;
  cursor: pointer;
}

.result:active { background: var(--surface); }
.result-name { display: block; font-size: 15px; }
.result-meta { display: block; font-size: 12px; color: var(--muted); margin-top: 3px; }

/* ---------- info / debug ---------- */

.info { padding: 16px; line-height: 1.55; font-size: 14px; }
.info h2 { font-size: 15px; margin: 22px 0 8px; }
.info h2:first-child { margin-top: 0; }
.info p { margin: 0 0 10px; color: var(--muted); }
.info dl { margin: 0; display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; }
.info dt { color: var(--muted); }
.info dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }

.row-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}

/* ---------- tab bar ---------- */

.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

.tab {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  height: var(--tabbar-h);
  cursor: pointer;
}

.tab[aria-pressed="true"] {
  color: var(--text);
  box-shadow: inset 0 2px 0 var(--accent);
}

/* ---------- modal ---------- */

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(8, 12, 16, 0.68);
}

.modal {
  width: 100%;
  max-width: 340px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
}

.modal-msg { margin: 0 0 16px; font-size: 15px; line-height: 1.45; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; }

/* ---------- toast ---------- */

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabbar-h) + 16px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%) translateY(8px);
  max-width: calc(100vw - 32px);
  padding: 10px 14px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
  z-index: 60;
}

#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.err { border-color: rgba(217, 89, 76, 0.6); color: #f4c8c3; }

@media (prefers-reduced-motion: reduce) {
  #toast { transition: none; }
  .row-refresh.is-spinning .refresh-icon svg,
  .icon-btn.is-spinning .refresh-icon svg { animation: none; }
}
