:root {
  --bg: #f4f5f7;
  --card-bg: #ffffff;
  --text: #1a1d23;
  --muted: #6b7280;
  --border: #e5e7eb;
  --brand: #0f172a;
  --brand-2: #1e293b;
  --ontime: #15803d;
  --ontime-bg: #dcfce7;
  --delayed: #b45309;
  --delayed-bg: #fef3c7;
  --cancelled: #b91c1c;
  --cancelled-bg: #fee2e2;
  --unknown: #4b5563;
  --unknown-bg: #e5e7eb;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: 90px;
}

.app-header {
  background: var(--brand);
  color: white;
  padding: 14px 16px 10px;
}

.header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.app-header h1 {
  font-size: 1.25rem;
  margin: 0;
  font-weight: 600;
}

.last-updated {
  margin: 6px 0 0;
  font-size: 0.78rem;
  color: #cbd5e1;
}

.tabs, .subtabs {
  display: flex;
  background: var(--brand-2);
  position: sticky;
  top: 0;
  z-index: 5;
}

.subtabs {
  background: #334155;
  margin: 0 0 12px;
  border-radius: 8px;
  overflow: hidden;
  position: static;
}

.tab-btn, .subtab-btn {
  flex: 1;
  background: none;
  border: none;
  color: #cbd5e1;
  padding: 12px 6px;
  font-size: 0.85rem;
  cursor: pointer;
  border-bottom: 3px solid transparent;
}

.tab-btn.active {
  color: white;
  border-bottom-color: #38bdf8;
  font-weight: 600;
}

.subtab-btn.active {
  color: white;
  background: #0f172a;
  font-weight: 600;
}

#app {
  padding: 14px 12px 0;
  max-width: 640px;
  margin: 0 auto;
}

.panel { display: none; }
.panel.active { display: block; }

.subpanel { display: none; }
.subpanel.active { display: block; }

.panel-title {
  font-size: 1rem;
  color: var(--muted);
  margin: 4px 0 12px;
  font-weight: 500;
}

.nrcc-banner {
  background: #fff7ed;
  border: 1px solid #fdba74;
  color: #9a3412;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 0.85rem;
  margin-bottom: 12px;
}

.hint {
  color: var(--muted);
  font-size: 0.9rem;
}

.error-box {
  background: var(--cancelled-bg);
  color: var(--cancelled);
  border-radius: 8px;
  padding: 12px;
  font-size: 0.9rem;
}

.service-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 12px;
  overflow: hidden;
}

.service-summary {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  cursor: pointer;
}

.service-time {
  font-size: 1.15rem;
  font-weight: 700;
  min-width: 54px;
}

.service-mid {
  flex: 1;
  min-width: 0;
}

.service-dest {
  font-size: 0.85rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.service-meta {
  font-size: 0.75rem;
  color: var(--muted);
}

.status-pill {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 4px 9px;
  border-radius: 999px;
  white-space: nowrap;
}

.status-ontime { color: var(--ontime); background: var(--ontime-bg); }
.status-delayed { color: var(--delayed); background: var(--delayed-bg); }
.status-cancelled { color: var(--cancelled); background: var(--cancelled-bg); }
.status-unknown { color: var(--unknown); background: var(--unknown-bg); }

.expand-arrow {
  color: var(--muted);
  font-size: 0.8rem;
  transition: transform 0.15s ease;
}

.service-card.open .expand-arrow { transform: rotate(180deg); }

.reason-line {
  font-size: 0.8rem;
  color: var(--cancelled);
  padding: 0 14px 10px;
  margin: 0;
}

.calling-points {
  display: none;
  border-top: 1px solid var(--border);
  padding: 10px 14px 12px;
}

.service-card.open .calling-points { display: block; }

.calling-points ol {
  list-style: none;
  margin: 0;
  padding: 0;
  position: relative;
}

.calling-points li {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 6px 0 6px 16px;
  font-size: 0.85rem;
  border-left: 2px solid var(--border);
  position: relative;
}

.calling-points li::before {
  content: "";
  position: absolute;
  left: -5px;
  top: 12px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
}

.calling-points li.highlight {
  font-weight: 700;
}

.calling-points li.highlight::before {
  background: var(--brand);
}

.calling-points li.cp-cancelled {
  color: var(--cancelled);
  text-decoration: line-through;
}

.cp-name { flex: 1; }
.cp-time { color: var(--muted); white-space: nowrap; }
.calling-points li.highlight .cp-time { color: var(--text); }

.app-footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--card-bg);
  border-top: 1px solid var(--border);
  padding: 10px 16px 14px;
  text-align: center;
}

.refresh-btn {
  background: var(--brand);
  color: white;
  border: none;
  padding: 10px 22px;
  border-radius: 999px;
  font-size: 0.9rem;
  cursor: pointer;
}

.auto-refresh-note {
  margin: 6px 0 0;
  font-size: 0.72rem;
  color: var(--muted);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0f19;
    --card-bg: #161b26;
    --text: #e5e7eb;
    --muted: #9ca3af;
    --border: #262b38;
  }
}
