/* ============================================================
   LIGN.ES — Swiss Design Departure Board
   Target: 1920×1080 / 1280×720 Android TV WebView
   ============================================================ */

:root {
  /* — Canvas — */
  --bg-deep: #060609;
  --bg-board: #0b0b10;
  --bg-stop: #10101a;
  --bg-stop-focus: #161625;

  /* — Text — */
  --text-primary: #e8e8f0;
  --text-secondary: #9a9ab4;
  --text-muted: #6a6a84;
  --text-accent: #f0c040;

  /* — Borders & Lines — */
  --rule-color: #1e1e30;

  /* — Badge fallback — */
  --badge-bg: #2a2a40;

  /* — Timing — */
  --transition-fast: 150ms ease;

  /* — Safe zone — */
  --safe: 48px;
}

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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg-deep);
  color: var(--text-primary);
  font-family: 'DM Sans', sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ============================================================
   BOARD — full viewport container
   ============================================================ */

.board {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  padding: var(--safe);
  background: var(--bg-board);
}

/* ============================================================
   STOPS CONTAINER — scrollable area
   ============================================================ */

.stops-container {
  position: relative;
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.stops-container::-webkit-scrollbar {
  display: none;
}

/* ============================================================
   ALERT BANNER
   ============================================================ */

.alert-banner {
  flex-shrink: 0;
  overflow: hidden;
  padding: 8px 16px;
  margin-bottom: 8px;
  border-radius: 4px;
  background: rgba(240, 192, 64, 0.12);
  border: 1px solid rgba(240, 192, 64, 0.3);
  color: var(--text-accent);
  font-family: 'DM Sans', sans-serif;
  font-size: 18px;
  font-weight: 500;
  white-space: nowrap;
}

.alert-banner[hidden] {
  display: none;
}

.alert-banner .alert-text {
  display: inline-block;
  animation: marquee 20s linear infinite;
}

.alert-banner .alert-text.no-scroll {
  animation: none;
}

@keyframes marquee {
  0%   { transform: translateX(0); }
  100% { transform: translateX(-50%); }
}

/* ============================================================
   LOADING STATE
   ============================================================ */

.loading-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  height: 100%;
  font-size: 22px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 2px;
}

.loading-rat {
  width: 80px;
  image-rendering: pixelated;
}

/* ============================================================
   STOP BLOCK
   ============================================================ */

.stop-block {
  padding: 20px 24px;
  border-left: 3px solid transparent;
  border-bottom: 1px solid var(--rule-color);
  transition:
    background var(--transition-fast),
    border-color var(--transition-fast);
}

.stop-block:last-child {
  border-bottom: none;
}

.stop-block.focused {
  background: var(--bg-stop-focus);
  border-left-color: var(--text-accent);
}

/* ============================================================
   STOP HEADER ROW
   ============================================================ */

.stop-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 12px;
}

.stop-name {
  font-family: 'DM Sans', sans-serif;
  font-weight: 700;
  font-size: 26px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-primary);
}

.stop-header::after {
  content: '';
  flex: 1;
  border-bottom: 1px dotted var(--rule-color);
  margin: 0 16px;
  position: relative;
  top: -5px;
}

.stop-distance {
  font-family: 'JetBrains Mono', monospace;
  font-weight: 500;
  font-size: 18px;
  color: var(--text-secondary);
  white-space: nowrap;
  flex-shrink: 0;
}

/* ============================================================
   DEPARTURES TABLE
   ============================================================ */

.departures-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.departure-row {
  display: grid;
  grid-template-columns: 64px 1fr auto;
  align-items: center;
  gap: 16px;
  padding: 6px 8px;
  border-radius: 4px;
}

.dep-badge {
  font-family: 'JetBrains Mono', monospace;
  font-weight: 700;
  font-size: 17px;
  text-align: center;
  padding: 4px 0;
  border-radius: 3px;
  color: #fff;
  background: var(--badge-bg);
  letter-spacing: 0.5px;
  text-transform: uppercase;
  line-height: 1.2;
}

.dep-headsign {
  font-family: 'DM Sans', sans-serif;
  font-weight: 400;
  font-size: 22px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.dep-time-group {
  display: flex;
  align-items: baseline;
  gap: 8px;
  justify-content: flex-end;
  min-width: 170px;
}

.dep-countdown {
  font-family: 'JetBrains Mono', monospace;
  font-weight: 500;
  font-size: 22px;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  text-align: right;
}

.dep-delay {
  font-family: 'JetBrains Mono', monospace;
  font-weight: 700;
  font-size: 16px;
  color: #e8854a;
  white-space: nowrap;
}

.dep-rt-dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #4ae862;
  flex-shrink: 0;
  position: relative;
  top: -1px;
}

.dep-countdown.imminent {
  color: var(--text-accent);
  font-weight: 700;
  animation: countdown-pulse 1.5s ease-in-out infinite;
}

.dep-countdown.now {
  color: var(--text-accent);
  font-weight: 700;
  animation: countdown-pulse 1s ease-in-out infinite;
}

@keyframes countdown-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.dep-countdown.delayed {
  color: #e8854a;
}

.dep-countdown.early {
  color: #4ae862;
}

/* ── Sweet spot: "Partez maintenant" ── */
.departure-row.sweet-spot {
  background: rgba(74, 232, 98, 0.06);
  border-left: 2px solid #4ae862;
  margin-left: -2px;
}

/* ── Departure fade-out ── */
.departure-row.departing {
  opacity: 0;
  max-height: 0;
  padding-top: 0;
  padding-bottom: 0;
  overflow: hidden;
  transition: opacity 300ms ease, max-height 300ms ease, padding 300ms ease;
}

/* ── Stale cache indicator ── */
.stops-container.stale .stop-block {
  opacity: 0.5;
}

.no-departures {
  font-size: 20px;
  color: var(--text-muted);
  font-style: italic;
  padding: 4px 8px;
}

/* ============================================================
   FOOTER BAR
   ============================================================ */

.footer-bar {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  padding-top: 12px;
  margin-top: 8px;
  border-top: 1px solid var(--rule-color);
  font-family: 'DM Sans', sans-serif;
  font-size: 15px;
  color: var(--text-muted);
  line-height: 1;
}

.footer-clock {
  font-family: 'JetBrains Mono', monospace;
  font-weight: 700;
  font-size: 22px;
  color: var(--text-primary);
  letter-spacing: 1px;
  font-variant-numeric: tabular-nums;
}

.footer-sep {
  display: inline-block;
  width: 1px;
  height: 14px;
  background: var(--rule-color);
  margin: 0 16px;
  flex-shrink: 0;
}

.footer-meta {
  color: var(--text-secondary);
  font-size: 15px;
  white-space: nowrap;
}

.footer-source {
  font-family: 'JetBrains Mono', monospace;
  font-size: 13px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1.5px;
}

.footer-spacer {
  flex: 1;
}

.footer-nav {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--text-muted);
  white-space: nowrap;
}

.footer-nav kbd {
  font-family: 'JetBrains Mono', monospace;
  font-size: 13px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--rule-color);
  border-radius: 3px;
  padding: 1px 6px;
  color: var(--text-secondary);
}

.footer-refresh {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 15px;
  color: var(--text-muted);
}

.refresh-icon {
  display: inline-block;
  font-size: 16px;
  transition: transform 0.6s ease;
}

.refresh-icon.spinning {
  animation: spin 0.8s ease;
}

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

/* ============================================================
   ERROR STATE
   ============================================================ */

.error-state {
  padding: 40px 0;
  font-size: 22px;
  color: var(--text-accent);
}

/* ============================================================
   EMPTY STATE
   ============================================================ */

.empty-state {
  padding: 60px 0;
  text-align: center;
  font-size: 24px;
  color: var(--text-muted);
}

/* ============================================================
   DATA REFRESH TRANSITION
   ============================================================ */

.stops-container.refreshing .stop-block {
  opacity: 0.5;
  transition: opacity 200ms ease;
}

/* ============================================================
   LOCATION SCREEN
   ============================================================ */

.location-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  height: 100%;
  text-align: center;
}

.location-screen[hidden] {
  display: none;
}

.location-title {
  font-family: 'DM Sans', sans-serif;
  font-weight: 700;
  font-size: 24px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--text-primary);
}

.location-subtitle {
  font-family: 'DM Sans', sans-serif;
  font-size: 18px;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.location-status {
  font-family: 'DM Sans', sans-serif;
  font-size: 18px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1.5px;
}

.address-input-wrap {
  width: 100%;
  max-width: 600px;
}

.address-input {
  width: 100%;
  padding: 14px 20px;
  font-family: 'DM Sans', sans-serif;
  font-size: 22px;
  color: var(--text-primary);
  background: var(--bg-stop);
  border: 2px solid var(--rule-color);
  border-radius: 6px;
  outline: none;
  caret-color: var(--text-accent);
  transition: border-color var(--transition-fast);
}

.address-input::placeholder {
  color: var(--text-muted);
}

.address-input:focus {
  border-color: var(--text-accent);
}

.suggestions-list {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 600px;
  margin-top: 4px;
}

.suggestion-row {
  padding: 12px 20px;
  font-family: 'DM Sans', sans-serif;
  font-size: 20px;
  color: var(--text-secondary);
  text-align: left;
  background: transparent;
  border: none;
  border-left: 3px solid transparent;
  border-bottom: 1px solid var(--rule-color);
  cursor: pointer;
  outline: none;
  transition:
    background var(--transition-fast),
    border-color var(--transition-fast),
    color var(--transition-fast);
}

.suggestion-row:last-child {
  border-bottom: none;
}

.suggestion-row:focus,
.suggestion-row:hover {
  background: var(--bg-stop-focus);
  border-left-color: var(--text-accent);
  color: var(--text-primary);
}

.suggestion-row .suggestion-context {
  display: block;
  font-size: 15px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ============================================================
   QR PAIRING SECTION
   ============================================================ */

.qr-section {
  width: 100%;
  max-width: 600px;
  margin-bottom: 16px;
}

.qr-section[hidden] {
  display: none;
}

.qr-pairing {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 32px;
}

.qr-code {
  width: 300px;
  height: 300px;
  border-radius: 8px;
  background: #fff;
  padding: 12px;
  image-rendering: pixelated;
}

.qr-instructions {
  text-align: left;
}

.qr-label {
  font-family: 'DM Sans', sans-serif;
  font-size: 22px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

.qr-code-text {
  font-family: 'JetBrains Mono', monospace;
  font-size: 28px;
  font-weight: 700;
  color: var(--text-accent);
  letter-spacing: 3px;
}

.location-divider {
  display: flex;
  align-items: center;
  gap: 16px;
  margin: 24px 0;
  color: var(--text-muted);
  font-size: 16px;
  text-transform: uppercase;
  letter-spacing: 2px;
}

.location-divider::before,
.location-divider::after {
  content: '';
  flex: 1;
  border-bottom: 1px solid var(--rule-color);
}

/* ── QR section focus (D-pad) ── */
.qr-section.focused {
  border-left: 3px solid var(--text-accent);
  background: rgba(240, 192, 64, 0.04);
  border-radius: 6px;
  padding-left: 16px;
}

/* ============================================================
   SIDEBAR
   ============================================================ */

.sidebar {
  position: fixed;
  top: 0;
  right: 0;
  width: 360px;
  height: 100%;
  background: var(--bg-stop);
  border-left: 1px solid var(--rule-color);
  z-index: 10;
  padding: var(--safe);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sidebar[hidden] {
  display: none;
}

.sidebar-header {
  font-family: 'DM Sans', sans-serif;
  font-size: 14px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 2px;
  color: var(--text-accent);
  margin-bottom: 16px;
}

.sidebar-item {
  display: block;
  width: 100%;
  padding: 14px 16px;
  font-family: 'DM Sans', sans-serif;
  font-size: 20px;
  color: var(--text-secondary);
  text-align: left;
  background: transparent;
  border: none;
  border-left: 3px solid transparent;
  border-bottom: 1px solid var(--rule-color);
  cursor: pointer;
  outline: none;
  transition:
    background var(--transition-fast),
    border-color var(--transition-fast),
    color var(--transition-fast);
}

.sidebar-item.focused,
.sidebar-item:focus {
  background: var(--bg-stop-focus);
  border-left-color: var(--text-accent);
  color: var(--text-primary);
}

/* ============================================================
   MEDIA QUERIES — 720p fallback
   ============================================================ */

@media (max-height: 800px) {
  :root {
    --safe: 32px;
  }

  .footer-clock {
    font-size: 18px;
  }

  .footer-bar {
    font-size: 13px;
    padding-top: 8px;
    margin-top: 4px;
  }

  .footer-sep {
    margin: 0 10px;
  }

  .stop-name {
    font-size: 22px;
  }

  .dep-headsign,
  .dep-countdown {
    font-size: 19px;
  }

  .dep-badge {
    font-size: 15px;
  }

  .departure-row {
    grid-template-columns: 56px 1fr auto;
    gap: 12px;
  }

  .dep-time-group {
    min-width: 150px;
  }

  .stop-block {
    padding: 14px 20px;
  }

  .stop-header {
    margin-bottom: 8px;
  }

  .location-title {
    font-size: 20px;
  }

  .location-subtitle {
    font-size: 16px;
  }

  .address-input {
    font-size: 19px;
    padding: 12px 16px;
  }

  .suggestion-row {
    font-size: 18px;
    padding: 10px 16px;
  }

  .qr-code {
    width: 240px;
    height: 240px;
  }

  .qr-label {
    font-size: 18px;
  }

  .qr-code-text {
    font-size: 22px;
  }

  .qr-pairing {
    gap: 24px;
  }

  .sidebar {
    width: 300px;
  }

  .sidebar-item {
    font-size: 18px;
    padding: 12px 14px;
  }
}
