/* =============================================
   TERminus — Railway Solari aesthetic
   Dark / amber / monospace
   ============================================= */

:root {
  --bg:           #0c0c0e;
  --bg-panel:     #111115;
  --bg-row:       #16161b;
  --bg-row-alt:   #1a1a20;
  --amber:        #f5a623;
  --amber-dim:    #9b6610;
  --amber-bright: #ffc347;
  --amber-glow:   rgba(245,166,35,.18);
  --red:          #e8473f;
  --red-dim:      rgba(232,71,63,.25);
  --green:        #39d98a;
  --green-dim:    rgba(57,217,138,.2);
  --muted:        #3a3a44;
  --text:         #e8dfc8;
  --text-dim:     #6b6570;
  --mono:         'Share Tech Mono', monospace;
  --cond:         'Saira Condensed', sans-serif;
  --radius:       3px;
}

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

/* hidden attribute must always hide — overrides any display rule */
[hidden] { display: none !important; }

html { font-size: 14px; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--mono);
  min-height: 100vh;
  padding-bottom: 3rem;
}

/* ── Header ── */
.site-header {
  background: var(--bg-panel);
  border-bottom: 1px solid var(--muted);
  padding: 0 1.5rem;
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-inner {
  max-width: 1600px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 64px;
}

.header-left {
  display: flex;
  align-items: center;
  gap: .9rem;
}

.logo-mark {
  width: 42px;
  height: 42px;
  flex-shrink: 0;
  filter: drop-shadow(0 0 6px var(--amber-glow));
}

.site-title {
  font-family: var(--cond);
  font-weight: 800;
  font-size: 1.7rem;
  letter-spacing: .12em;
  color: var(--amber-bright);
  line-height: 1;
  text-shadow: 0 0 14px var(--amber);
}

.site-sub {
  font-family: var(--cond);
  font-weight: 300;
  font-size: .75rem;
  letter-spacing: .22em;
  color: var(--amber-dim);
  text-transform: uppercase;
  margin-top: 2px;
}

.header-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: .25rem;
}

.live-clock {
  font-family: var(--mono);
  font-size: 1.55rem;
  color: var(--amber-bright);
  letter-spacing: .1em;
  text-shadow: 0 0 10px var(--amber);
}

.refresh-row {
  display: flex;
  align-items: center;
  gap: .5rem;
  font-size: .7rem;
  color: var(--text-dim);
}

.countdown {
  color: var(--amber-dim);
  font-size: .75rem;
  min-width: 2.5ch;
}

.btn-refresh {
  background: none;
  border: 1px solid var(--muted);
  color: var(--amber);
  border-radius: var(--radius);
  width: 22px;
  height: 22px;
  cursor: pointer;
  font-size: .9rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color .2s, background .2s;
}
.btn-refresh:hover { border-color: var(--amber); background: var(--amber-glow); }
.btn-refresh.spinning { animation: spin .6s linear infinite; }

.btn-pause {
  background: none;
  border: 1px solid var(--muted);
  color: var(--amber);
  border-radius: var(--radius);
  width: 22px;
  height: 22px;
  cursor: pointer;
  font-size: .75rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color .2s, background .2s, color .2s;
  flex-shrink: 0;
}
.btn-pause:hover { border-color: var(--amber); background: var(--amber-glow); }
.btn-pause.paused { border-color: var(--amber); color: var(--green); background: rgba(57,217,138,.08); }

.refresh-interval-select {
  background: var(--bg-panel);
  border: 1px solid var(--muted);
  color: var(--amber);
  font-family: var(--mono);
  font-size: .72rem;
  padding: .1rem .3rem;
  border-radius: var(--radius);
  cursor: pointer;
  outline: none;
}
.refresh-interval-select:focus { border-color: var(--amber); }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Window selector bar ── */
.window-bar {
  max-width: 1600px;
  margin: .9rem auto .3rem;
  padding: 0 1.5rem;
  display: flex;
  align-items: center;
  gap: .6rem;
  font-size: .78rem;
  color: var(--text-dim);
}

.window-bar select {
  background: var(--bg-panel);
  border: 1px solid var(--muted);
  color: var(--amber);
  font-family: var(--mono);
  font-size: .78rem;
  padding: .2rem .5rem;
  border-radius: var(--radius);
  cursor: pointer;
  outline: none;
}
.window-bar select:focus { border-color: var(--amber); }

#window-label {
  color: var(--amber-dim);
  font-size: .72rem;
}


/* ── Boards grid — two columns side by side ── */
main {
  max-width: 1600px;
  margin: 1rem auto 0;
  padding: 0 1.5rem;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  align-items: start;
}

.station-board { animation: fadeIn .35s ease; }

@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.board-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: .6rem;
  border-bottom: 1px solid var(--muted);
  padding-bottom: .5rem;
}

.station-name {
  font-family: var(--cond);
  font-weight: 800;
  font-size: 1.45rem;
  letter-spacing: .1em;
  color: var(--amber-bright);
  text-transform: uppercase;
}

.board-meta { font-size: .7rem; color: var(--text-dim); }

/* ── Table ── */
.departure-table {
  width: 100%;
  border-collapse: collapse;
}

.departure-table thead th {
  font-family: var(--cond);
  font-weight: 600;
  font-size: .68rem;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--text-dim);
  text-align: left;
  padding: .4rem .5rem;
  border-bottom: 1px solid var(--muted);
  white-space: nowrap;
}

.departure-table tbody tr {
  border-bottom: 1px solid #1e1e24;
  transition: background .15s;
}
.departure-table tbody tr:nth-child(odd)  { background: var(--bg-row); }
.departure-table tbody tr:nth-child(even) { background: var(--bg-row-alt); }
.departure-table tbody tr:hover { background: #1e1e2a; }

.departure-table td {
  padding: .5rem .5rem;
  font-size: .82rem;
  vertical-align: middle;
  white-space: nowrap;
}

/* ── Cell widths ── */
.cell-time      { width: 72px; font-size: .95rem; color: var(--amber-bright); letter-spacing: .05em; }
.cell-time .time-base     { color: var(--amber); }
.cell-time .time-expected { font-size: .72rem; color: var(--red); display: block; line-height: 1.2; }

.cell-train     { width: 72px; color: var(--text); font-size: .78rem; }
.cell-mode      { width: 52px; }
.cell-direction { max-width: 140px; overflow: hidden; text-overflow: ellipsis; color: var(--text); }
.cell-delay     { width: 70px; font-variant-numeric: tabular-nums; }
.cell-status    { width: 78px; }

/* ── Mode badges ── */
.mode-badge {
  display: inline-block;
  padding: .12rem .35rem;
  border-radius: 2px;
  font-family: var(--cond);
  font-weight: 600;
  font-size: .68rem;
  letter-spacing: .06em;
  text-transform: uppercase;
  background: rgba(245,166,35,.12);
  border: 1px solid var(--amber-dim);
  color: var(--amber);
}
.mode-badge.tgv { background: rgba(245,166,35,.25); border-color: var(--amber); color: var(--amber-bright); }
.mode-badge.ter { background: rgba(57,217,138,.1);  border-color: #1a6641; color: var(--green); }
.mode-badge.ic  { background: rgba(120,80,200,.15); border-color: #5a3080; color: #b08ce8; }



/* ── Generic dim text for N/A cells ── */
.cell-na { color: var(--text-dim); font-size: .75rem; }

/* ── Delay ── */
.delay-late { color: var(--red);      font-size: .82rem; font-weight: bold; }
.delay-none { color: var(--text-dim); font-size: .75rem; }

/* ── Status pills ── */
.status-pill {
  display: inline-block;
  padding: .12rem .4rem;
  border-radius: 20px;
  font-family: var(--cond);
  font-weight: 600;
  font-size: .67rem;
  letter-spacing: .05em;
  text-transform: uppercase;
}
.status-on_time   { background: var(--green-dim); color: var(--green); }
.status-delayed   { background: var(--red-dim);   color: var(--red); }
.status-cancelled { background: rgba(100,0,0,.4); color: #ff8888; text-decoration: line-through; }

/* ── Empty / error states ── */
.board-empty {
  padding: 2rem 1rem;
  text-align: center;
  color: var(--text-dim);
  font-size: .85rem;
  border: 1px dashed var(--muted);
  border-radius: var(--radius);
}
.board-empty .empty-icon { font-size: 2rem; margin-bottom: .5rem; display: block; }

.board-error {
  padding: 1rem;
  background: var(--red-dim);
  border: 1px solid var(--red);
  border-radius: var(--radius);
  color: #f2a09c;
  font-size: .82rem;
}

/* ── Loading overlay ── */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(12,12,14,.85);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.2rem;
  z-index: 200;
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--muted);
  border-top-color: var(--amber);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}

.overlay-text { font-size: .85rem; color: var(--amber-dim); letter-spacing: .12em; }

/* ── Row flicker on refresh ── */
@keyframes rowFlicker {
  0%   { opacity: 0; }
  30%  { opacity: .6; }
  60%  { opacity: .2; }
  100% { opacity: 1; }
}
.row-new { animation: rowFlicker .45s ease forwards; }

/* ── Responsive — single column below 1100px ── */
@media (max-width: 1100px) {
  main { grid-template-columns: 1fr; }
}

/* ── Desktop only: show desktop rows, hide mobile rows ── */
@media (min-width: 641px) {
  .row-mobile  { display: none; }
}

/* ── Mobile layout (≤ 640px) ── */
@media (max-width: 640px) {
  html { font-size: 13px; }

  .site-header  { padding: 0 .75rem; }
  .header-inner { height: 52px; }
  .site-title   { font-size: 1.15rem; }
  .site-sub     { display: none; }
  .live-clock   { font-size: 1.05rem; }
  .logo-mark    { width: 32px; height: 32px; }

  main        { padding: 0 .5rem; gap: .9rem; margin-top: .6rem; }
  .window-bar { padding: 0 .5rem; flex-wrap: wrap; gap: .4rem; }
  .station-name { font-size: 1.1rem; }

  /* Hide desktop rows and header; show mobile rows */
  .row-desktop  { display: none; }
  .desktop-thead { display: none; }

  /* Mobile row 1 */
  .row-mobile-1 td { padding: .5rem .4rem .1rem; }
  .mob-time      { width: 52px; font-size: .9rem; color: var(--amber-bright); white-space: nowrap; vertical-align: top; }
  .mob-time .time-expected { font-size: .67rem; color: var(--red); display: block; line-height: 1.3; }
  .mob-direction { font-size: .85rem; color: var(--text); vertical-align: top; }
  .mob-delay     { white-space: nowrap; vertical-align: top; text-align: right; }
  .mob-status    { white-space: nowrap; vertical-align: top; text-align: right; }

  /* Mobile row 2 */
  .row-mobile-2 td { padding: .1rem .4rem .45rem; }
  .mob-mode     { width: 52px; }
  .mob-train    { font-size: .75rem; color: var(--text-dim); white-space: nowrap; }
  .mob-platform { font-size: .75rem; text-align: right; }

  /* Pair rows share alternating background */
  .row-mobile-1:nth-of-type(4n+1),
  .row-mobile-1:nth-of-type(4n+1) + .row-mobile-2 { background: var(--bg-row); }
  .row-mobile-1:nth-of-type(4n+3),
  .row-mobile-1:nth-of-type(4n+3) + .row-mobile-2 { background: var(--bg-row-alt); }

  /* Disruption accent on mobile row 1 */
  .row-mobile-1.row-disrupted td:first-child { border-left: 2px solid var(--amber-dim); }
}


/* ── Platform column ── */
.cell-platform { width: 58px; text-align: center; }

.platform-loading {
  color: var(--text-dim);
  font-size: .7rem;
  animation: pulse 1.2s ease-in-out infinite;
}

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

.platform-certain {
  display: inline-block;
  font-family: var(--cond);
  font-weight: 800;
  font-size: .82rem;
  letter-spacing: .04em;
  color: var(--amber-bright);
  background: rgba(245,166,35,.15);
  border: 1px solid var(--amber);
  border-radius: 2px;
  padding: .12rem .45rem;
  text-shadow: 0 0 8px var(--amber-glow);
}


/* ── Status pill tooltip ── */
.status-has-reason {
  position: relative;
  cursor: help;
}

.status-info-icon {
  font-size: .6rem;
  opacity: .7;
  vertical-align: super;
  margin-left: 1px;
}

.status-tooltip {
  display: none;
  position: absolute;
  bottom: calc(100% + 6px);
  right: 0;
  min-width: 180px;
  max-width: 280px;
  white-space: normal;
  background: #1e1e28;
  border: 1px solid var(--muted);
  border-radius: 4px;
  padding: .5rem .7rem;
  font-family: var(--mono);
  font-size: .72rem;
  font-weight: 400;
  color: var(--text);
  line-height: 1.5;
  z-index: 50;
  box-shadow: 0 4px 16px rgba(0,0,0,.5);
  pointer-events: none;
  text-decoration: none;
  letter-spacing: 0;
}

/* Arrow pointing down */
.status-tooltip::after {
  content: '';
  position: absolute;
  top: 100%;
  right: 12px;
  border: 5px solid transparent;
  border-top-color: var(--muted);
}

/* Show on hover and keyboard focus */
.status-has-reason:hover .status-tooltip,
.status-has-reason:focus .status-tooltip,
.status-has-reason:focus-within .status-tooltip {
  display: block;
}

/* Colour the tooltip border to match the status */
.status-delayed .status-tooltip  { border-color: var(--red);   }
.status-cancelled .status-tooltip { border-color: var(--red);   }
.status-delayed .status-tooltip::after   { border-top-color: var(--red); }
.status-cancelled .status-tooltip::after { border-top-color: var(--red); }

/* ── Disruption-aware row and status states ── */

/* On-time train that has a partial/upstream disruption */
.status-warned {
  background: rgba(245,166,35,.12) !important;
  color: var(--amber) !important;
  border: 1px solid var(--amber-dim);
}
.status-warned .status-info-icon { color: var(--amber); }

/* Subtle left border on any row with a linked disruption */
.row-disrupted td:first-child {
  border-left: 2px solid var(--amber-dim);
}
tr.row-disrupted:has(.status-delayed) td:first-child,
tr.row-disrupted:has(.status-cancelled) td:first-child {
  border-left-color: var(--red);
}

