/* hkbus-eta — dark, mobile-first UI shell.
   One file, no preprocessor, no nesting. Comments in English. */

:root {
  --bg: #111;
  --fg: #e8e8e8;
  --card: #1c1c1e;
  --border: #2c2c2e;
  --accent: #4da3ff;
  --positive: #3ddc84;
  --warn: #ffb340;
  --muted: #8e8e93;
}

* {
  box-sizing: border-box;
}

/* The hidden attribute must always win over any display rule. */
[hidden] {
  display: none !important;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  max-width: 520px;
  margin: 0 auto;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--type-font, "Roboto", -apple-system, BlinkMacSystemFont, "Segoe UI",
    "Helvetica Neue", Arial, "PingFang TC", "Microsoft JhengHei", "Noto Sans TC", sans-serif);
  font-size: 16px;
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

/* ---------- Sticky header ---------- */

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(17, 17, 17, 0.96);
  border-bottom: 1px solid var(--border);
  padding: calc(10px + env(safe-area-inset-top)) 12px 10px;
}

.app-title {
  margin: 0 0 2px;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.status {
  min-height: 18px;
  font-size: 13px;
  color: var(--muted);
}

/* ---------- Main / panels ---------- */

.app-main {
  flex: 1 1 auto;
  padding: 12px 12px 20px;
}

.tab-panel {
  animation: none;
}

.panel-title {
  margin: 2px 0 10px;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.results {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.route-panel {
  margin-top: 12px;
}

/* ---------- Search bar / controls ---------- */

.search-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

#q {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 44px;
  padding: 10px 12px;
  background: var(--card);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 12px;
  font-size: 16px;
}

#q::placeholder {
  color: var(--muted);
}

#q:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.btn {
  min-height: 44px;
  padding: 10px 14px;
  background: var(--card);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 12px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}

.btn:active {
  background: #2a2a2c;
}

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #071c33;
}

#search-btn,
#gps-btn {
  min-height: 44px;
  white-space: nowrap;
}

.near-controls {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

#district-select {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 44px;
  padding: 10px 12px;
  background: var(--card);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 12px;
  font-size: 16px;
}

.status-line {
  margin: 0 0 10px;
  font-size: 14px;
  color: var(--muted);
}

/* ---------- Generic tappable row ---------- */

.row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 44px;
  margin: 0;
  padding: 10px 12px;
  background: var(--card);
  color: inherit;
  border: 1px solid var(--border);
  border-radius: 12px;
  text-align: left;
  font: inherit;
  cursor: pointer;
}

.row:active {
  background: #2a2a2c;
}

.row-main {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 16px;
  font-weight: 600;
}

.row-sub {
  font-size: 13px;
  font-weight: 400;
  color: var(--muted);
}

/* ---------- Company badges ---------- */

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 2px 8px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: #333;
  color: var(--fg);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.6;
  white-space: nowrap;
}

.co-KMB {
  background: #e2231a;
  color: #fff;
}

.co-CTB {
  background: #ffcc00;
  color: #111;
}

.co-GMB {
  background: #00a04a;
  color: #fff;
}

/* NLB's own livery is green — too close to the GMB badge to read at a glance,
   so the badge is blue, which no other operator uses. */
.co-NLB {
  background: #1565c0;
  color: #fff;
}

/* ---------- ETA lines ---------- */

.eta-line {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
}

.eta-line:last-child {
  border-bottom: none;
}

.eta-min {
  min-width: 3.6em;
  font-size: 24px;
  font-weight: 700;
  color: var(--positive);
  font-variant-numeric: tabular-nums;
}

.eta-time {
  font-size: 13px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.eta-rmk {
  font-size: 12px;
  color: var(--warn);
}

/* ---------- State blocks ---------- */

.loading,
.empty,
.error {
  padding: 14px 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--card);
  font-size: 14px;
  text-align: center;
}

.loading {
  color: var(--accent);
}

.empty {
  color: var(--muted);
}

.error {
  color: #ff8a80;
  border-color: #5a1f1f;
}

/* ---------- Chips ----------
   The route-filter chips are the shared M3 chip. Their CSS ships in the generated static
   stylesheet (/vendor/fonts/portal-fonts.css), next to the token layer it reads. */

/* ---------- Favourite star (44px tap target) ---------- */

.star {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  /* min-width keeps the icon-only variant a 44px round target; the auto width
     lets the labelled variant ("☆ 收藏") render as a single-line pill instead
     of wrapping onto two lines. */
  width: auto;
  min-width: 44px;
  height: 44px;
  min-height: 44px;
  padding: 0 12px;
  background: transparent;
  color: var(--warn);
  border: none;
  border-radius: 999px;
  font-size: 22px;
  line-height: 1;
  white-space: nowrap;
  cursor: pointer;
}

.star.on {
  color: #ffd60a;
}

/* ---------- Favourite cards ---------- */

.fav-card {
  padding: 10px 12px;
  margin-bottom: 10px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.fav-card-head {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
}

.updated {
  margin: 6px 0 2px;
  font-size: 12px;
  color: var(--muted);
}

/* ---------- Sticky bottom tab bar ---------- */

.tabbar {
  position: sticky;
  bottom: 0;
  z-index: 20;
  display: flex;
  background: rgba(17, 17, 17, 0.97);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}

.tab {
  flex: 1 1 0;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 52px;
  padding: 0 4px;
  background: transparent;
  color: var(--muted);
  border: none;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}

.tab.active,
.tab[aria-selected="true"] {
  color: var(--accent);
}

/* ---------- ETA bottom sheet ---------- */

.sheet {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 100;
  max-width: 520px;
  margin: 0 auto;
  max-height: 80vh;
  overflow-y: auto;
  background: var(--card);
  border-top: 1px solid var(--border);
  border-radius: 16px 16px 0 0;
  box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.6);
  padding: 14px 14px calc(18px + env(safe-area-inset-bottom));
  -webkit-overflow-scrolling: touch;
}

.sheet-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.sheet-title {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
}

.sheet-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  min-width: 44px;
  height: 44px;
  min-height: 44px;
  background: var(--bg);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 50%;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}

.sheet-body {
  font-size: 15px;
}

/* ---------- Focus visibility ---------- */

button:focus-visible,
select:focus-visible,
input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* ---------- Integration additions (containers app.js renders into) ---------- */

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}

.panel-head {
  margin: 0 0 8px;
  font-size: 16px;
  font-weight: 700;
}

.stop-list,
.fav-list,
.sheet-eta {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.fav-body {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-top: 4px;
}

.sheet-eta .eta-line {
  padding: 8px 0;
}

/* "即將到站" is a warning, not a countdown in green */
.eta-min.soon {
  color: var(--warn);
}

.results .row,
.stop-list .row {
  flex-wrap: wrap;
}

.stop-list .row-main {
  flex: 1 1 60%;
}

/* ---------- Nearby rows with inline arrival times ---------- */

.near-row {
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 0;
}

.near-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  width: 100%;
}

.near-head .row-main {
  flex: 1 1 auto;
  min-width: 0;
}

.near-head .row-sub {
  white-space: nowrap;
}

.near-eta {
  width: 100%;
  margin-top: 6px;
}

.near-eta-line {
  padding: 4px 0;
  border-bottom: none;
  gap: 6px;
}

/* Keep a row to two compact lines, so more stops fit on screen */
.near-eta .eta-min {
  font-size: 18px;
  min-width: 3.2em;
}

.near-eta .badge {
  font-size: 11px;
}

/* Per-line favourite button inside the ETA sheet: still a fat tap target,
   just short enough to sit on a row with the arrival time. */
.star.inline {
  min-width: 40px;
  min-height: 40px;
  height: 40px;
  padding: 0 6px;
  margin-left: auto;
  font-size: 18px;
}

.sheet-eta .eta-line {
  flex-wrap: nowrap;
}

/* ---------- Footer: version stamp + APK download ---------- */

.app-footer {
  max-width: 520px;
  margin: 4px auto 76px;          /* clears the fixed tab bar */
  padding: 0 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 12px;
  color: #8a8a8a;
}

.app-ver {
  font-variant-numeric: tabular-nums;
}

.apk-link {
  display: inline-flex;
  align-items: center;
  min-height: 44px;               /* fat enough to tap on a phone */
  padding: 0 4px;
  color: #8ab4f8;
  text-decoration: none;
}

/* ---------- Favourite expansion: next 5 stops x coming 2 buses ---------- */

.fav-sub {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.fav-toggle {
  flex: 0 0 auto;
  min-height: 32px;
  padding: 0 10px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: #8ab4f8;
  font-size: 12px;
  white-space: nowrap;
  cursor: pointer;
}

.fav-expand {
  margin-top: 8px;
  padding-top: 6px;
  border-top: 1px dashed var(--border);
}

.fav-expand-cap {
  margin-bottom: 3px;
  font-size: 11px;
  color: #8a8a8a;
}

/* Deliberately smaller than the body ETA lines: 5 stops x 2 buses has to fit
   one card without wrapping. */
.fav-expand-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  padding: 2px 0;
  font-size: 12px;
  line-height: 1.35;
}

.fav-expand-name {
  min-width: 0;
  color: #cfcfcf;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.fav-expand-times {
  flex: 0 0 auto;
  color: #e8e8e8;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.fav-expand-note {
  font-size: 12px;
  color: #8a8a8a;
}
