/* Look and feel carried over from the old trainstats-ui (Tailwind):
   gray-100 page, white rounded-lg card with shadow-lg, blue-600 stat
   numbers, green-50/red-50 operator panels, blue-50 explanation box. */

:root {
  --gray-100: #f3f4f6;
  --gray-500: #6b7280;
  --gray-600: #4b5563;
  --gray-800: #1f2937;
  --blue-50: #eff6ff;
  --blue-600: #2563eb;
  --blue-800: #1e40af;
  --green-50: #f0fdf4;
  --green-600: #16a34a;
  --green-700: #15803d;
  --green-800: #166534;
  --amber-600: #d97706;
  --red-50: #fef2f2;
  --red-600: #dc2626;
  --red-700: #b91c1c;
  --red-800: #991b1b;
}

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

body {
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  background: var(--gray-100);
  color: var(--gray-800);
  line-height: 1.5;
}

.page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.header { text-align: center; margin-bottom: 1rem; }
.header h1 { font-size: 1.875rem; font-weight: 700; margin-bottom: 0.5rem; }
.header .date { font-size: 1.125rem; color: var(--gray-600); }

.nav { margin-top: 0.5rem; font-size: 0.875rem; color: var(--gray-500); }
.nav a { color: var(--blue-600); text-decoration: none; }
.nav a:hover { text-decoration: underline; }
.nav span { font-weight: 600; color: var(--gray-800); }

.updated { font-size: 0.875rem; color: var(--gray-500); text-align: center; margin-bottom: 1rem; }

.connection { font-size: 1.125rem; margin-bottom: 1rem; }
.status-good { color: var(--green-600); }
.status-bad { color: var(--red-600); }

.waiting { font-size: 1.25rem; text-align: center; }

.card {
  background: #fff;
  box-shadow: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
  border-radius: 0.5rem;
  padding: 1.5rem;
  width: 100%;
  max-width: 56rem;
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

/* National stats row */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 1rem;
}
.stat { text-align: center; }
.stat-label { font-size: 1.125rem; font-weight: 600; margin-bottom: 0.5rem; }
.stat-value { font-size: 1.875rem; font-weight: 700; color: var(--blue-600); }
.stat-percentage { font-size: 1.125rem; color: var(--gray-600); }

/* RAG colouring, applied on top of stat/chip styles */
.rag-green { color: var(--green-600); }
.rag-amber { color: var(--amber-600); }
.rag-red { color: var(--red-600); }
.rag-white { color: var(--gray-500); }
.rag-blue { color: var(--blue-600); }

/* Best / worst operator panels */
.operator-cards {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 2rem;
}
.operator-card { padding: 1.5rem; border-radius: 0.5rem; }
.operator-card h3 { font-size: 1.25rem; font-weight: 600; margin-bottom: 1rem; }
.operator-card .operator-name { font-size: 1.125rem; font-weight: 700; margin-bottom: 0.5rem; }
.operator-card.best { background: var(--green-50); }
.operator-card.best h3 { color: var(--green-700); }
.operator-card.best .operator-name { color: var(--green-800); }
.operator-card.best .mini-label { color: var(--green-600); }
.operator-card.worst { background: var(--red-50); }
.operator-card.worst h3 { color: var(--red-700); }
.operator-card.worst .operator-name { color: var(--red-800); }
.operator-card.worst .mini-label { color: var(--red-600); }
.operator-stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1rem;
}
.mini-label { font-size: 0.875rem; }
.mini-value { font-weight: 600; }
.operator-ppm { font-size: 0.875rem; font-weight: 500; margin-top: 0.5rem; }

/* Operator tables (passenger and freight) */
.operator-table-wrap h3 { font-size: 1.25rem; font-weight: 600; margin-bottom: 1rem; }
.table-note { font-size: 0.875rem; color: var(--gray-500); margin: -0.5rem 0 1rem; }
.operator-table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
.operator-table th {
  color: var(--gray-500);
  font-weight: 600;
  text-transform: uppercase;
  font-size: 0.75rem;
  letter-spacing: 0.05em;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--gray-100);
  text-align: right;
}
.operator-table td {
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--gray-100);
  text-align: right;
}
.operator-table .left { text-align: left; }
.operator-table tbody tr:hover { background: var(--gray-100); }
.ppm-chip { font-weight: 700; }

/* Live network map */
.map-stats { grid-template-columns: repeat(4, 1fr); }
.map-wrap { text-align: center; position: relative; }
#trainmap {
  width: 100%;
  max-width: 30rem;
  height: auto;
  background: #fbfcfd;
  border: 1px solid var(--gray-100);
  border-radius: 0.5rem;
  cursor: grab;
}
.map-legend { font-size: 0.875rem; color: var(--gray-600); margin-top: 0.5rem; }
.map-legend span { margin: 0 0.25rem 0 0.75rem; }
.map-legend .map-hint { display: block; margin: 0.25rem 0 0; font-size: 0.75rem; color: var(--gray-500); }
.map-tooltip {
  position: absolute;
  pointer-events: none;
  z-index: 10;
  background: #fff;
  border: 1px solid var(--gray-100);
  border-radius: 0.375rem;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
  padding: 0.375rem 0.625rem;
  font-size: 0.75rem;
  text-align: left;
  max-width: 16rem;
}
.map-tooltip .where { color: var(--gray-600); }
.map-pill {
  position: absolute;
  z-index: 10;
  background: #fff;
  border: 1px solid var(--gray-100);
  border-radius: 9999px;
  padding: 0.25rem 0.75rem;
  font-size: 0.75rem;
  color: var(--gray-600);
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}
.map-pill:hover { color: var(--blue-600); }
.map-reset { top: 0.5rem; right: 0.5rem; }
.map-full-btn { top: 0.5rem; left: 0.5rem; }

/* Full-screen overlay: the wrap fills the viewport and the canvas is
   re-rendered at device resolution by map.js. Also applied while the
   native Fullscreen API has the wrap. */
.map-full {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: #fbfcfd;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0.5rem;
}
.map-full #trainmap {
  max-width: none;
  width: auto;
  height: min(calc(100vh - 4rem), calc((100vw - 2rem) * 1000 / 668));
}
body.map-noscroll { overflow: hidden; }
.map-unavailable { color: var(--gray-600); text-align: center; padding: 2rem 1rem; }
.top-operators h3 { font-size: 1.25rem; font-weight: 600; margin-bottom: 0.5rem; }
.top-operators p { font-size: 0.875rem; color: var(--gray-600); }

/* Explanation box */
.explanation-box {
  background: var(--blue-50);
  border: 1px solid rgba(59, 130, 246, 0.2);
  border-radius: 0.5rem;
  padding: 1rem;
  font-size: 0.875rem;
  color: var(--blue-800);
  line-height: 1.6;
}
.explanation-box h4 { font-weight: 600; margin-bottom: 0.5rem; }
.explanation-footnote { margin-top: 0.5rem; font-size: 0.75rem; }

/* Footer notes + attribution */
.info-note {
  margin-top: 2rem;
  font-size: 0.875rem;
  color: var(--gray-600);
  max-width: 42rem;
  text-align: center;
}
.attribution { margin-top: 2rem; text-align: center; }
.attribution p { font-size: 0.875rem; color: var(--gray-600); margin-bottom: 0.5rem; }
.attribution img { height: 3rem; }

/* Journey reliability check */
.journey-intro { font-size: 0.9375rem; color: var(--gray-600); margin-bottom: 1rem; }
.journey-disabled { font-size: 0.9375rem; color: var(--gray-600); line-height: 1.6; }
.journey-disabled code { background: var(--gray-100); padding: 0.1rem 0.3rem; border-radius: 0.25rem; }
.journey-error {
  background: var(--red-50);
  color: var(--red-700);
  border-radius: 0.5rem;
  padding: 0.75rem 1rem;
  font-size: 0.875rem;
  margin-bottom: 1rem;
}
.journey-form {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: flex-end;
  margin-bottom: 1rem;
}
.journey-field { display: flex; flex-direction: column; gap: 0.25rem; }
.journey-field label { font-size: 0.75rem; font-weight: 600; color: var(--gray-600); }
.journey-field input, .journey-field select {
  font: inherit;
  font-size: 0.875rem;
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--gray-300, #d1d5db);
  border-radius: 0.375rem;
  background: #fff;
}
.journey-field input[list] { min-width: 14rem; }
.journey-submit {
  font: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  color: #fff;
  background: var(--blue-600);
  border: none;
  border-radius: 0.375rem;
  padding: 0.55rem 1rem;
  cursor: pointer;
}
.journey-submit:hover { filter: brightness(1.08); }
.journey-submit:disabled { opacity: 0.6; cursor: wait; }
.journey-wait { font-size: 0.875rem; color: var(--gray-500); margin-bottom: 1rem; }
.journey-report h3 { font-size: 1.25rem; font-weight: 600; margin-bottom: 0.5rem; }
.journey-table { margin-bottom: 1rem; }
.journey-dep { font-weight: 700; }
.journey-service { color: var(--gray-600); }
.journey-bar-wrap {
  display: inline-block;
  width: 4rem;
  height: 0.5rem;
  background: var(--gray-100);
  border-radius: 0.25rem;
  overflow: hidden;
  margin-right: 0.4rem;
  vertical-align: middle;
}
.journey-bar { display: block; height: 100%; background: var(--green-600); }
.journey-low td { color: var(--gray-500); }
.journey-low-badge {
  font-size: 0.6875rem;
  color: var(--amber-600);
  border: 1px solid var(--amber-600);
  border-radius: 0.25rem;
  padding: 0 0.25rem;
  white-space: nowrap;
}
.journey-empty { font-size: 0.9375rem; color: var(--gray-600); margin: 1rem 0; }

/* Small screens: stack the grids */
@media (max-width: 48rem) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .operator-cards { grid-template-columns: 1fr; }
  .operator-table-wrap { overflow-x: auto; }
  .journey-report { overflow-x: auto; }
}
