:root {
  --bg: #f3f5f8;
  --surface: #ffffff;
  --surface-alt: #f8fafc;
  --ink: #0f172a;
  --ink-secondary: #475569;
  --ink-muted: #94a3b8;
  --line: #e2e8f0;
  --ctb-yellow: #facc15;
  --ctb-red: #e11d48;
  --brand: #1e293b;
  --accent: #0284c7;
  --urgent: #059669;
  --urgent-bg: #ecfdf5;
  --soon: #0284c7;
  --soon-bg: #f0f9ff;
  --pinned: #f59e0b;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.05), 0 1px 2px rgba(15, 23, 42, 0.03);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang HK", "PingFang SC", "Helvetica Neue", sans-serif;
  background-color: var(--bg);
  color: var(--ink);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

.shell {
  max-width: 1120px;
  margin: 0 auto;
  padding: 20px 16px 48px;
}

/* Topbar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
  color: #fff;
  padding: 18px 22px;
  border-radius: 14px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.12);
  margin-bottom: 16px;
}

.brand-wrap {
  display: flex;
  align-items: center;
  gap: 14px;
}

.ctb-badge {
  background: var(--ctb-yellow);
  color: #0f172a;
  font-weight: 800;
  font-size: 15px;
  letter-spacing: 0.5px;
  padding: 8px 11px;
  border-radius: 9px;
  border-bottom: 3px solid var(--ctb-red);
  flex-shrink: 0;
}

.title-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.title-row h1 {
  font-size: 21px;
  font-weight: 700;
  letter-spacing: -0.3px;
}

.stop-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  background: rgba(255, 255, 255, 0.14);
  color: #e2e8f0;
  padding: 2px 8px;
  border-radius: 6px;
}

.subtitle {
  font-size: 13px;
  color: #cbd5e1;
  margin-top: 2px;
}

.status-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.live-status {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12.5px;
  color: #cbd5e1;
  background: rgba(255, 255, 255, 0.08);
  padding: 6px 11px;
  border-radius: 20px;
}

.pulse-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #22c55e;
  box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.7);
  animation: pulse 2s infinite;
}

.pulse-dot.loading {
  background: var(--ctb-yellow);
}

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.6); }
  70% { box-shadow: 0 0 0 7px rgba(34, 197, 94, 0); }
  100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0); }
}

.btn-refresh {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--ctb-yellow);
  color: #0f172a;
  border: none;
  font-weight: 600;
  font-size: 13px;
  padding: 8px 13px;
  border-radius: 8px;
  cursor: pointer;
  transition: transform 0.15s ease, opacity 0.15s ease;
}

.btn-refresh:hover {
  opacity: 0.92;
}

.btn-refresh:active {
  transform: scale(0.97);
}

.btn-refresh.spinning svg {
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Toolbar & Direction Switch */
.toolbar {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
}

.dir-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 14px;
}

.dir-btn {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  text-align: left;
  padding: 11px 14px;
  border-radius: 9px;
  border: 1.5px solid var(--line);
  background: var(--surface-alt);
  color: var(--ink-secondary);
  cursor: pointer;
  transition: all 0.15s ease;
}

.dir-btn:hover {
  border-color: #cbd5e1;
}

.dir-btn.active {
  background: #f0f9ff;
  border-color: var(--accent);
  color: var(--ink);
}

.dir-main {
  font-size: 15px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 6px;
}

.dir-main small {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-weight: 500;
  font-size: 12px;
  color: var(--ink-muted);
}

.dir-sub {
  font-size: 12px;
  color: var(--ink-secondary);
  margin-top: 2px;
}

.filters-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.cat-chips {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.chip {
  border: 1px solid var(--line);
  background: var(--surface-alt);
  color: var(--ink-secondary);
  font-size: 12.5px;
  font-weight: 500;
  padding: 5px 11px;
  border-radius: 20px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.chip:hover {
  border-color: #cbd5e1;
  color: var(--ink);
}

.chip.active {
  background: var(--ink);
  color: #fff;
  border-color: var(--ink);
}

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

.search-box {
  position: relative;
  display: flex;
  align-items: center;
}

.search-box svg {
  position: absolute;
  left: 10px;
  color: var(--ink-muted);
  pointer-events: none;
}

.search-box input {
  padding: 6px 10px 6px 30px;
  font-size: 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-alt);
  color: var(--ink);
  width: 185px;
  outline: none;
}

.search-box input:focus {
  border-color: var(--accent);
  background: #fff;
}

.sort-toggle {
  display: inline-flex;
  background: var(--surface-alt);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 2px;
}

.sort-btn {
  border: none;
  background: transparent;
  color: var(--ink-secondary);
  font-size: 12px;
  font-weight: 500;
  padding: 4px 9px;
  border-radius: 6px;
  cursor: pointer;
}

.sort-btn.active {
  background: #fff;
  color: var(--ink);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}

/* Summary Bar */
.summary-bar {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}

.summary-item {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 11px 15px;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow);
}

.summary-label {
  font-size: 11.5px;
  color: var(--ink-secondary);
}

.summary-val {
  font-size: 16px;
  font-weight: 700;
  margin-top: 2px;
  color: var(--ink);
}

/* Routes Grid */
.routes-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(335px, 1fr));
  gap: 12px;
}

.route-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 15px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 12px;
  transition: border-color 0.15s ease, transform 0.15s ease;
}

.route-card:hover {
  border-color: #cbd5e1;
}

.route-card.pinned {
  border-left: 4px solid var(--pinned);
}

.route-card.inactive {
  opacity: 0.68;
}

.card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.route-ident {
  display: flex;
  align-items: center;
  gap: 11px;
}

.route-num {
  font-family: ui-monospace, SFMono-Regular, "SF Pro Display", Menlo, monospace;
  font-weight: 800;
  font-size: 18px;
  min-width: 58px;
  text-align: center;
  padding: 6px 9px;
  border-radius: 8px;
  background: #1e293b;
  color: #fff;
  letter-spacing: -0.3px;
}

.route-num.cat-kowloon {
  background: #be123c;
}

.route-num.cat-airport {
  background: #0369a1;
}

.route-dest-wrap {
  display: flex;
  flex-direction: column;
}

.route-dest {
  font-size: 15.5px;
  font-weight: 700;
  color: var(--ink);
  display: flex;
  align-items: center;
  gap: 5px;
}

.route-dest small {
  font-size: 12px;
  font-weight: 500;
  color: var(--ink-secondary);
}

.route-note {
  font-size: 12px;
  color: var(--ink-secondary);
  margin-top: 1px;
}

.pin-btn {
  border: none;
  background: transparent;
  color: #cbd5e1;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  padding: 2px 4px;
  transition: color 0.15s ease;
}

.pin-btn:hover,
.pin-btn.active {
  color: var(--pinned);
}

/* ETA List */
.eta-list {
  display: flex;
  flex-direction: column;
  gap: 7px;
  border-top: 1px solid #f1f5f9;
  padding-top: 10px;
}

.eta-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px;
  border-radius: 8px;
  background: var(--surface-alt);
}

.eta-row.first-eta {
  background: var(--soon-bg);
}

.eta-row.urgent-eta {
  background: var(--urgent-bg);
}

.eta-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.eta-seq {
  font-size: 11.5px;
  font-weight: 700;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: inline-grid;
  place-items: center;
  background: #e2e8f0;
  color: #475569;
}

.first-eta .eta-seq {
  background: var(--soon);
  color: #fff;
}

.urgent-eta .eta-seq {
  background: var(--urgent);
  color: #fff;
}

.eta-clock {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--ink);
}

.eta-rmk {
  font-size: 11.5px;
  color: var(--ink-secondary);
  background: rgba(15, 23, 42, 0.05);
  padding: 1px 6px;
  border-radius: 4px;
}

.eta-Wait {
  font-size: 15px;
  font-weight: 800;
  color: var(--ink);
}

.first-eta .eta-Wait {
  color: var(--soon);
  font-size: 16.5px;
}

.urgent-eta .eta-Wait {
  color: var(--urgent);
  font-size: 16.5px;
}

.eta-Wait small {
  font-size: 12px;
  font-weight: 600;
  margin-left: 2px;
}

.no-eta {
  font-size: 13px;
  color: var(--ink-muted);
  text-align: center;
  padding: 10px 0 4px;
}

.empty-state {
  grid-column: 1 / -1;
  background: var(--surface);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  padding: 36px 20px;
  text-align: center;
  color: var(--ink-secondary);
}

.footer {
  margin-top: 28px;
  text-align: center;
  font-size: 12px;
  color: var(--ink-muted);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

@media (max-width: 680px) {
  .topbar {
    flex-direction: column;
    align-items: flex-start;
    padding: 15px;
  }
  .status-controls {
    width: 100%;
    justify-content: space-between;
  }
  .dir-switch {
    grid-template-columns: 1fr;
  }
  .summary-bar {
    grid-template-columns: 1fr 1fr;
  }
  .summary-item:last-child {
    grid-column: 1 / -1;
  }
  .search-box input {
    width: 100%;
  }
  .right-tools {
    width: 100%;
    justify-content: space-between;
  }
  .routes-grid {
    grid-template-columns: 1fr;
  }
}
