/* ============================================================
   TÅGLÄGET – style.css v3.0
   Matchar internal.html:s designsystem exakt
   ============================================================ */

/* --- VARIABLER (samma som internal.html) --- */
:root {
  --primary: #dc2626; --primary-hover: #b91c1c;
  --bg-body: #f8fafc; --bg-card: #ffffff;
  --text-main: #0f172a; --text-muted: #64748b;
  --border: #e2e8f0; --radius: 0.75rem;
  --status-ok-bg: #dcfce7; --status-ok-text: #166534;
  --status-delay-bg: #fee2e2; --status-delay-text: #991b1b;
  --status-unknown-bg: #f1f5f9; --status-unknown-text: #475569;
}

[data-theme="dark"] {
  --bg-body: #0f172a; --bg-card: #1e293b;
  --text-main: #f8fafc; --text-muted: #94a3b8;
  --border: #334155;
  --status-ok-bg: #064e3b; --status-ok-text: #ecfdf5;
  --status-delay-bg: #7f1d1d; --status-delay-text: #fef2f2;
  --status-unknown-bg: #334155; --status-unknown-text: #e2e8f0;
}

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

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg-body);
  color: var(--text-main);
  line-height: 1.5;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }

/* ============================================================
   HEADER
   ============================================================ */
.tl-header {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0.75rem 1rem;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(10px);
}

.tl-back-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-main);
  font-size: 0.95rem;
  flex-shrink: 0;
  transition: background 0.15s;
}
.tl-back-btn:hover { background: var(--status-unknown-bg); }

.tl-header-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.tl-header-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tl-header-speed {
  font-size: 0.75rem;
  font-weight: 600;
  color: #4ade80;
  font-variant-numeric: tabular-nums;
}

.tl-refresh-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  font-size: 0.95rem;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s;
}
.tl-refresh-btn:hover { background: var(--status-unknown-bg); color: var(--text-main); }

/* ============================================================
   PLK-BAR
   ============================================================ */
.tl-plk-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 1rem;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.tl-plk-bar-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border-radius: 999px;
  border: 1px solid rgba(245,158,11,0.4);
  background: rgba(245,158,11,0.1);
  color: #f59e0b;
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s;
}
.tl-plk-bar-btn:hover { background: rgba(245,158,11,0.2); }

.tl-plk-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  flex: 1;
}

.tl-plk-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 8px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--status-unknown-bg);
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
}
.tl-plk-chip .chip-km {
  color: var(--text-muted);
  font-weight: 400;
}

/* ============================================================
   MAIN / LOADING / ERROR
   ============================================================ */
.tl-main {
  padding: 0 0 80px;
}

.tl-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 3rem 1rem;
  color: var(--text-muted);
  font-size: 0.95rem;
}

.tl-error {
  margin: 1rem;
  padding: 0.8rem 1rem;
  border-radius: var(--radius);
  border: 1px solid var(--status-delay-text);
  background: var(--status-delay-bg);
  color: var(--status-delay-text);
  font-size: 0.9rem;
}

.tl-last-update {
  text-align: center;
  font-size: 0.7rem;
  color: var(--text-muted);
  padding: 6px 0 4px;
  font-variant-numeric: tabular-nums;
}

/* ============================================================
   TABELL
   ============================================================ */
.tl-table-wrap {
  /* overflow-x: auto borttagen – bryter position:sticky på thead */
}

.tl-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

.tl-table thead th {
  position: sticky;
  top: var(--thead-top, 104px); /* justeras dynamiskt via JS */
  z-index: 50;
  padding: 8px 12px;
  text-align: left;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  background: var(--bg-body);
  border-bottom: 2px solid var(--border);
}

.tl-table thead th:first-child  { width: 22%; }
.tl-table thead th:nth-child(2) { width: 39%; }
.tl-table thead th:nth-child(3) { width: 39%; }

.tl-table tbody td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
  font-size: 0.85rem;
  line-height: 1.55;
}

/* ---- Stationsrad ---- */
.tl-station-link {
  font-weight: 600;
  color: var(--text-main);
  font-size: 0.85rem;
  text-decoration: none;
}
.tl-station-link:hover { text-decoration: underline; }

/* Ej annonserade driftplatser */
tr.tl-unadvertised .tl-station-link {
  color: var(--text-muted);
  font-weight: 400;
  font-size: 0.8rem;
}

/* ---- Tåglänkar ---- */
.tl-train-link {
  display: inline-block;
  color: var(--text-muted);
  font-size: 0.82rem;
  font-style: italic;
  text-decoration: none;
  line-height: 1.5;
}
.tl-train-link:hover { color: var(--text-main); text-decoration: underline; }

/* Statusfärger */
.tl-on-time  { color: #4ade80; font-weight: 700; font-size: 0.78em; }
.tl-delayed  { color: #f87171; font-weight: 700; font-size: 0.78em; }

/* ---- Aktuellt tåg – indikator ---- */
.tl-my-train {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 8px;
  border: 1px solid rgba(74,222,128,0.45);
  background: rgba(74,222,128,0.1);
  color: #4ade80;
  font-weight: 700;
  font-size: 0.82rem;
  margin-bottom: 3px;
}

/* ---- Rad: tåg i rörelse mellan stationer ---- */
tr.tl-between td {
  background: rgba(255,255,255,0.015);
  border-bottom: 1px dashed var(--border);
  padding: 6px 12px;
}
tr.tl-between td:first-child { /* tom kolumn */ }

/* ---- PLK-rad ---- */
tr.tl-plk-row td {
  padding: 6px 12px;
  font-size: 0.8rem;
  color: #f59e0b;
  background: rgba(245,158,11,0.06);
  border-bottom: 1px solid rgba(245,158,11,0.15);
}
tr.tl-plk-row .plk-id { color: var(--text-muted); font-size: 0.72rem; margin-left: 6px; }

/* ---- Nulägesrad (scroll-target) ---- */
tr.tl-current-row {
  background: rgba(74,222,128,0.04);
}

/* ============================================================
   PLK MODAL
   ============================================================ */
.tl-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  backdrop-filter: blur(4px);
  z-index: 9999;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
}

@media (min-width: 600px) {
  .tl-modal-backdrop {
    align-items: center;
    padding: 1rem;
  }
}

.tl-modal {
  background: var(--bg-card);
  width: 100%;
  max-width: 600px;
  border-radius: var(--radius) var(--radius) 0 0;
  border: 1px solid var(--border);
  box-shadow: 0 -10px 40px rgba(0,0,0,0.3);
  display: flex;
  flex-direction: column;
  max-height: 85vh;
  overflow: hidden;
}

@media (min-width: 600px) {
  .tl-modal {
    border-radius: var(--radius);
    box-shadow: 0 20px 50px rgba(0,0,0,0.4);
  }
}

.tl-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  font-weight: 700;
  font-size: 0.95rem;
  flex-shrink: 0;
}

.tl-modal-close {
  background: var(--status-unknown-bg);
  border: 1px solid var(--border);
  color: var(--text-muted);
  width: 32px;
  height: 32px;
  border-radius: 8px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}
.tl-modal-close:hover { background: var(--border); color: var(--text-main); }

.tl-modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 0;
}

/* PLK-rader i modalen */
.tl-plk-modal-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 1.25rem;
  border-bottom: 1px solid var(--border);
  transition: opacity 0.2s;
}
.tl-plk-modal-item.passed {
  opacity: 0.35;
  filter: grayscale(60%);
}
.tl-plk-modal-name {
  font-weight: 600;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  gap: 8px;
}
.tl-plk-modal-name .seq {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1px solid var(--border);
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--text-muted);
  flex-shrink: 0;
}
.tl-plk-modal-name .seq.done {
  border-color: rgba(74,222,128,0.4);
  color: #4ade80;
  background: rgba(74,222,128,0.08);
}
.tl-plk-modal-meta {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 2px;
}
.tl-plk-modal-km {
  font-weight: 700;
  font-size: 0.85rem;
  text-align: right;
  flex-shrink: 0;
}
.tl-plk-modal-bandel {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.tl-modal-empty {
  padding: 2rem;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* ============================================================
   DESKTOP
   ============================================================ */
@media (min-width: 768px) {
  .tl-main { max-width: 700px; margin: 0 auto; }
  .tl-header { max-width: 100%; }
  .tl-table tbody td { font-size: 0.9rem; }
}
