:root {
  --color-missing:    #ef4444;
  --color-stale:      #f59e0b;
  --color-mismatched: #f97316;
  --color-unreadable: #a855f7;
  --color-ok:         #22c55e;

  --bg:          #0f172a;
  --bg-card:     #1e293b;
  --bg-hover:    #263148;
  --border:      #334155;
  --text:        #f1f5f9;
  --text-muted:  #94a3b8;
  --text-dim:    #64748b;
  --accent:      #3b82f6;
}

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

html { font-size: 15px; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── Header ──────────────────────────────────────────────────────────────── */
header {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  padding: 1rem 1.5rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

h1 {
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.subtitle {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 0.1rem;
}

.header-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1rem;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.stale-banner {
  background: #78350f;
  color: #fde68a;
  padding: 0.25rem 0.6rem;
  border-radius: 4px;
  font-weight: 600;
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.7; }
}

/* ── Main ────────────────────────────────────────────────────────────────── */
main {
  flex: 1;
  padding: 1.25rem 1.5rem;
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
}

/* ── Summary bar ─────────────────────────────────────────────────────────── */
.summary-bar {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

.summary-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-left-width: 4px;
  border-radius: 6px;
  padding: 0.75rem 1rem;
  cursor: pointer;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  transition: background 0.15s;
  color: inherit;
}
.summary-card:hover { background: var(--bg-hover); }
.summary-card:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.summary-card.missing    { border-left-color: var(--color-missing); }
.summary-card.stale      { border-left-color: var(--color-stale); }
.summary-card.mismatched { border-left-color: var(--color-mismatched); }
.summary-card.unreadable { border-left-color: var(--color-unreadable); }
.summary-card.ok         { border-left-color: var(--color-ok); }

.summary-card .count {
  font-size: 1.8rem;
  font-weight: 700;
  line-height: 1;
}
.summary-card.missing    .count { color: var(--color-missing); }
.summary-card.stale      .count { color: var(--color-stale); }
.summary-card.mismatched .count { color: var(--color-mismatched); }
.summary-card.unreadable .count { color: var(--color-unreadable); }
.summary-card.ok         .count { color: var(--color-ok); }

.summary-card .label {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* ── Filter tabs ─────────────────────────────────────────────────────────── */
.filter-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 1rem;
}

.tab {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 0.4rem 0.9rem;
  border-radius: 9999px;
  font-size: 0.8rem;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.tab:hover { background: var(--bg-hover); color: var(--text); }
.tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}
.tab:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ── Status messages ─────────────────────────────────────────────────────── */
.status-message {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
}
.status-message.error { color: var(--color-missing); }

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.retry-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 0.4rem 1.2rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
  margin-top: 0.25rem;
}
.retry-btn:hover { opacity: 0.85; }

/* ── Table ───────────────────────────────────────────────────────────────── */
.table-wrapper {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

thead {
  position: sticky;
  top: 0;
  background: #162032;
  z-index: 1;
}

th {
  padding: 0.65rem 1rem;
  text-align: left;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  font-weight: 600;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

td {
  padding: 0.6rem 1rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--bg-hover); }
tr:nth-child(even) td { background: rgba(255,255,255,0.02); }
tr:nth-child(even):hover td { background: var(--bg-hover); }

.train-num {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.stale-icon {
  font-size: 0.7rem;
  color: var(--color-stale);
  margin-left: 0.3rem;
  cursor: help;
}

.route-cell {
  max-width: 200px;
}

.route-name {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.disruption-badge {
  display: inline-block;
  background: var(--color-missing);
  color: #fff;
  font-size: 0.6rem;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 3px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  vertical-align: middle;
  margin-left: 0.3rem;
}

.od-cell { white-space: nowrap; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.od-cell .arrow { color: var(--text-dim); margin: 0 0.2rem; }

.delay-cell { font-variant-numeric: tabular-nums; white-space: nowrap; }
.next-stop-cell { white-space: nowrap; color: var(--text-muted); font-size: 0.8rem; font-variant-numeric: tabular-nums; }
.delay-ok     { color: var(--color-ok); }
.delay-minor  { color: var(--color-stale); }
.delay-severe { color: var(--color-missing); }
.delay-early  { color: #38bdf8; }

.alert-text-cell {
  min-width: 220px;
  max-width: 420px;
  color: var(--text-muted);
  font-size: 0.8rem;
  word-break: break-word;
  white-space: normal;
}
.alert-text-cell.has-alert { color: var(--text); }
.alert-text-cell .em-dash { color: var(--text-dim); }
.alert-full { display: block; line-height: 1.4; }

.alert-delay-cell { font-variant-numeric: tabular-nums; white-space: nowrap; }
.alert-delay-cell .unparseable { color: var(--color-unreadable); font-style: italic; }

.train-link {
  color: inherit;
  text-decoration: none;
}
.train-link:hover { text-decoration: underline; color: var(--accent); }

.dep-day {
  font-size: 0.75rem;
  font-weight: 400;
  color: var(--text-muted);
  margin-left: 0.15rem;
}

/* ── Issue badges ────────────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 9999px;
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
  color: #fff;
}
.badge-missing_alert { background: var(--color-missing); }
.badge-stale_alert   { background: var(--color-stale); color: #000; }
.badge-mismatched    { background: var(--color-mismatched); }
.badge-unreadable    { background: var(--color-unreadable); }
.badge-ok            { background: #1e4030; color: var(--color-ok); border: 1px solid var(--color-ok); }

/* ── Footer ──────────────────────────────────────────────────────────────── */
footer {
  text-align: center;
  padding: 1rem;
  font-size: 0.75rem;
  color: var(--text-dim);
  border-top: 1px solid var(--border);
}
footer a { color: var(--text-muted); }
footer a:hover { color: var(--text); }

/* ── Export button ───────────────────────────────────────────────────────── */
.export-btn {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 0.3rem 0.8rem;
  border-radius: 6px;
  font-size: 0.8rem;
  text-decoration: none;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}
.export-btn:hover { background: var(--bg-hover); color: var(--text); }

/* ── Utility ─────────────────────────────────────────────────────────────── */
.hidden { display: none !important; }

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 900px) {
  .summary-bar { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 600px) {
  header { flex-direction: column; align-items: flex-start; }
  .summary-bar { grid-template-columns: repeat(2, 1fr); }
  main { padding: 1rem; }
  th, td { padding: 0.5rem 0.6rem; }
  .route-cell { max-width: 120px; }
  .alert-text-cell { min-width: 0; max-width: 240px; }
}


#last-updated,
#refresh-countdown {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-variant-numeric: tabular-nums;
}
