/* Trafikpulsen – stilmall. Mörkt tema som standard, ljust via [data-theme="light"]. */

:root {
  --bg: #0b0d12;
  --card: rgba(17, 20, 27, 0.92);
  --card-solid: #12151c;
  --raise: rgba(255, 255, 255, 0.06);
  --raise-2: rgba(255, 255, 255, 0.11);
  --border: rgba(255, 255, 255, 0.08);
  --text: #e9ecf1;
  --muted: #8b93a3;
  --faint: #5c6370;
  --accent: #69db7c;
  --accent-ink: #0b0d12;
  --late: #ffa94d;
  --very-late: #ff6b6b;
  --early: #74c0fc;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  --radius: 14px;
  --col: 360px;
  --gap: 12px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}

[data-theme="light"] {
  --bg: #f4f5f7;
  --card: rgba(255, 255, 255, 0.95);
  --card-solid: #ffffff;
  --raise: rgba(15, 20, 30, 0.05);
  --raise-2: rgba(15, 20, 30, 0.1);
  --border: rgba(15, 20, 30, 0.1);
  --text: #161a22;
  --muted: #5f6878;
  --faint: #9aa1ad;
  --accent: #2f9e44;
  --accent-ink: #ffffff;
  --late: #e8590c;
  --very-late: #e03131;
  --early: #1c7ed6;
  --shadow: 0 8px 24px rgba(15, 20, 30, 0.14);
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

#map { position: absolute; inset: 0; }

button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  border: 0;
  background: transparent;
  border-radius: 10px;
  min-width: 36px;
  height: 36px;
  font-size: 20px;
  line-height: 1;
}
.icon-btn:hover { background: var(--raise); }
.icon-btn svg { width: 20px; height: 20px; fill: currentColor; }

.primary {
  border: 0;
  border-radius: 10px;
  padding: 9px 14px;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}
.ghost {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 7px 12px;
  background: var(--raise);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
}
.ghost:hover { background: var(--raise-2); }
.ghost.on { border-color: var(--accent); color: var(--accent); }
.ghost svg { width: 16px; height: 16px; fill: currentColor; }
.wide { width: 100%; }

/* ------------------------------------------------------------ kolumn */

.column {
  position: absolute;
  top: calc(var(--gap) + var(--safe-top));
  left: var(--gap);
  width: var(--col);
  max-height: calc(100% - 2 * var(--gap) - var(--safe-top) - 64px);
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 5;
  pointer-events: none;
}
.column > * { pointer-events: auto; }

.bar { padding: 6px 6px 6px 14px; position: relative; flex: none; border-radius: 12px; }
.notice { margin: 6px 4px 2px 0; font-size: 12px; color: var(--late); }
.bar-row { display: flex; align-items: center; gap: 10px; }

/* Statuspuls: grå = ingen realtid, grön (pulserar) = realtid, orange = varning. */
.pulse {
  flex: none;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--faint);
  cursor: help;
}
.pulse.live {
  background: var(--accent);
  box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 60%, transparent);
  animation: pulse 2.2s infinite;
}
.pulse.warn { background: var(--late); }
@keyframes pulse {
  70% { box-shadow: 0 0 0 10px transparent; }
  100% { box-shadow: 0 0 0 0 transparent; }
}

.search { position: relative; flex: 1; display: flex; align-items: center; }
.search-icon { position: absolute; left: 6px; width: 18px; height: 18px; fill: var(--muted); pointer-events: none; }
.search input {
  width: 100%;
  border: 0;
  background: transparent;
  border-radius: 8px;
  padding: 8px 32px 8px 30px;
  outline: none;
}
.search input:focus { background: var(--raise); }
.search input::-webkit-search-cancel-button { display: none; }
.search .clear { position: absolute; right: 2px; height: 30px; min-width: 30px; color: var(--muted); }

.clock-btn {
  flex: none;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  border: 0;
  background: transparent;
  padding: 2px 4px;
  border-radius: 8px;
}
.clock-btn:hover { background: var(--raise); }
.clock {
  font: 600 14px/1.1 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.speed { font-size: 11px; color: var(--late); font-weight: 600; }
.clock-btn.offset .clock { color: var(--late); }

.status {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
  padding-left: 1px;
  min-height: 16px;
}
.status .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--faint); flex: none; }
.status.live .dot { background: var(--accent); }
.status.warn .dot { background: var(--late); }

.results {
  list-style: none;
  margin: 8px -4px 0;
  padding: 4px 0 0;
  border-top: 1px solid var(--border);
  max-height: min(60vh, 420px);
  overflow: auto;
}
.results li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 9px;
  cursor: pointer;
}
.results li[aria-selected="true"], .results li:hover { background: var(--raise); }
.results .sub { color: var(--muted); font-size: 12px; }
.results .kind { margin-left: auto; color: var(--faint); font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; }
.results .section { cursor: default; color: var(--faint); font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; padding: 6px 10px 2px; }
.results .section:hover { background: none; }
.stop-glyph {
  width: 26px; height: 26px; border-radius: 7px; flex: none;
  display: grid; place-items: center; background: var(--raise-2); color: var(--muted);
}
.stop-glyph svg { width: 15px; height: 15px; fill: currentColor; }

/* ------------------------------------------------------------ panel */

.panel { display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
.panel-body { overflow: auto; overscroll-behavior: contain; padding: 14px 16px 16px; }
.panel-body:empty { display: none; }
.sheet-handle { display: none; }
.panel:has(.panel-body:empty) { display: none; }

.p-head { display: flex; align-items: flex-start; gap: 10px; }
.p-head h2 { margin: 0; font-size: 17px; line-height: 1.25; font-weight: 650; overflow-wrap: anywhere; }
.p-head .sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.p-head .grow { flex: 1; min-width: 0; }
.head-actions { display: flex; gap: 0; margin: -6px -8px 0 auto; flex: none; }
.head-actions .icon-btn { color: var(--muted); min-width: 32px; height: 32px; }
.head-actions .icon-btn:hover { color: var(--text); }
.head-actions .hbtn svg { width: 17px; height: 17px; }
.head-actions .hbtn.on { color: #fcc419; }
.p-actions { display: flex; flex-wrap: wrap; gap: 6px; margin: 12px 0 4px; }

.badge {
  display: inline-grid;
  place-items: center;
  min-width: 34px;
  height: 26px;
  padding: 0 8px;
  border-radius: 7px;
  font-weight: 700;
  font-size: 13px;
  color: #0b0d12;
  white-space: nowrap;
  flex: none;
}
.badge.sm { min-width: 30px; height: 22px; font-size: 12px; padding: 0 6px; border-radius: 6px; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: var(--raise-2);
  color: var(--muted);
}
.chip.ok { background: color-mix(in srgb, var(--accent) 18%, transparent); color: var(--accent); }
.chip.late { background: color-mix(in srgb, var(--late) 18%, transparent); color: var(--late); }
.chip.very-late, .chip.canceled { background: color-mix(in srgb, var(--very-late) 18%, transparent); color: var(--very-late); }
.chip.early { background: color-mix(in srgb, var(--early) 18%, transparent); color: var(--early); }

.facts { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 10px; font-size: 13px; color: var(--muted); }
.facts b { color: var(--text); font-weight: 600; }

.alerts { margin: 12px 0 0; display: flex; flex-direction: column; gap: 6px; }
.alert {
  border-radius: 10px;
  padding: 8px 10px;
  background: color-mix(in srgb, var(--late) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--late) 30%, transparent);
  font-size: 13px;
}
.alert summary { cursor: pointer; font-weight: 600; list-style: none; }
.alert summary::-webkit-details-marker { display: none; }
.alert p { margin: 6px 0 0; color: var(--muted); white-space: pre-line; }
.alert a { color: var(--text); }

h3.section { margin: 16px 0 6px; font-size: 12px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--faint); font-weight: 600; }

/* Hållplatslista för en tur */
.timeline { list-style: none; margin: 4px 0 0; padding: 0; position: relative; }
.timeline li {
  display: grid;
  grid-template-columns: 48px 18px 1fr;
  align-items: start;
  gap: 0 8px;
  padding: 5px 0;
  cursor: pointer;
  border-radius: 8px;
}
.timeline li:hover { background: var(--raise); }
.timeline .t { text-align: right; font-variant-numeric: tabular-nums; font-size: 13px; line-height: 1.3; }
.timeline .t s { display: block; color: var(--faint); font-size: 11px; }
.timeline .rail { position: relative; align-self: stretch; }
.timeline .rail::before {
  content: "";
  position: absolute;
  left: 7px;
  top: -5px;
  bottom: -5px;
  width: 4px;
  background: var(--line, var(--accent));
  opacity: 0.85;
}
.timeline li:first-child .rail::before { top: 9px; }
.timeline li:last-child .rail::before { bottom: calc(100% - 9px); }
.timeline .rail::after {
  content: "";
  position: absolute;
  left: 3px;
  top: 4px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--card-solid);
  border: 3px solid var(--line, var(--accent));
}
.timeline .name { font-size: 13px; line-height: 1.3; overflow-wrap: anywhere; }
.timeline .name small { color: var(--muted); margin-left: 4px; }
.timeline li.passed .t, .timeline li.passed .name { color: var(--faint); }
.timeline li.passed .rail::before, .timeline li.passed .rail::after { opacity: 0.35; }
.timeline li.skipped .name { text-decoration: line-through; color: var(--very-late); }
.timeline li.here .rail::after { background: var(--line, var(--accent)); box-shadow: 0 0 0 4px color-mix(in srgb, var(--line, var(--accent)) 35%, transparent); }
.timeline li.next .name { font-weight: 650; }
.timeline .vehicle-mark {
  position: absolute;
  left: 2px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--text);
  border: 3px solid var(--line, var(--accent));
  z-index: 1;
  transform: translateY(-50%);
}

/* Avgångar */
.deps { list-style: none; margin: 0; padding: 0; }
.deps li {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 8px 6px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  border-radius: 8px;
}
.deps li:hover { background: var(--raise); }
.deps .dest { min-width: 0; }
.deps .dest div { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.deps .dest small { color: var(--muted); font-size: 12px; }
.deps .when { text-align: right; font-variant-numeric: tabular-nums; }
.deps .when b { display: block; font-size: 14px; }
.deps .when small { color: var(--muted); font-size: 12px; }
.deps li.canceled .dest div, .deps li.canceled .when b { text-decoration: line-through; color: var(--very-late); }
.empty { color: var(--muted); padding: 12px 2px; }

.vlist { list-style: none; margin: 0; padding: 0; }
.vlist li { display: flex; align-items: center; gap: 10px; padding: 7px 6px; border-radius: 8px; cursor: pointer; }
.vlist li:hover { background: var(--raise); }
.vlist .grow { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.home .counts { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 8px; margin-top: 4px; }
.home .count { background: var(--raise); border-radius: 10px; padding: 8px 10px; }
.home .count b { display: block; font-size: 20px; font-variant-numeric: tabular-nums; }
.home .count span { color: var(--muted); font-size: 12px; }
.hint { color: var(--muted); font-size: 13px; margin: 10px 0 0; }
.favs { list-style: none; margin: 0; padding: 0; }
.favs li { display: flex; align-items: center; gap: 10px; padding: 7px 6px; border-radius: 8px; cursor: pointer; }
.favs li:hover { background: var(--raise); }

/* ------------------------------------------------------------ kontroller */

.controls {
  position: absolute;
  top: calc(var(--gap) + var(--safe-top));
  right: var(--gap);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 4;
}
.map-btn {
  width: 38px;
  height: 38px;
  background: var(--card);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}
.map-btn:hover { background: var(--card-solid); }
.map-btn.on { color: var(--accent); }
.zoom { display: flex; flex-direction: column; gap: 0; }
.zoom .map-btn:first-child { border-radius: 10px 10px 0 0; }
.zoom .map-btn:last-child { border-radius: 0 0 10px 10px; border-top: 0; }

.legend {
  position: absolute;
  left: var(--gap);
  bottom: calc(var(--gap) + var(--safe-bottom));
  display: flex;
  flex-wrap: wrap;
  gap: 0;
  padding: 3px;
  border-radius: 10px;
  z-index: 3;
  max-width: calc(100% - var(--col) - 4 * var(--gap) - 160px);
}
.legend button {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 8px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  font-size: 12px;
  color: var(--muted);
}
.legend button:hover { background: var(--raise); color: var(--text); }
body:has(.panel-body:not(:empty)) .legend { left: calc(var(--col) + 2 * var(--gap)); }
.legend .sw { width: 8px; height: 8px; border-radius: 50%; }
.stop-glyph.fav { color: #fcc419; }
.legend .n { font-weight: 650; font-variant-numeric: tabular-nums; min-width: 2ch; text-align: right; }
.legend button.off { opacity: 0.35; }

.attribution {
  position: absolute;
  right: var(--gap);
  bottom: calc(var(--gap) + var(--safe-bottom) + 22px);
  font-size: 11px;
  z-index: 3;
  background: var(--card);
  padding: 3px 8px;
  border-radius: 6px;
}
.attribution a { color: var(--muted); }

.maplibregl-ctrl-bottom-right { margin-bottom: var(--safe-bottom); }
.maplibregl-ctrl-attrib { background: var(--card) !important; }
.maplibregl-ctrl-attrib a { color: var(--muted) !important; }
[data-theme="dark"] .maplibregl-ctrl-attrib-button { filter: invert(1); }

/* ------------------------------------------------------------ popover/modal */

.popover {
  position: absolute;
  z-index: 20;
  width: 260px;
  padding: 14px;
}
.popover h3 { margin: 0 0 10px; font-size: 13px; color: var(--muted); font-weight: 600; }
.segmented { display: flex; background: var(--raise); border-radius: 10px; padding: 3px; gap: 2px; }
.segmented button {
  flex: 1;
  border: 0;
  background: transparent;
  border-radius: 8px;
  padding: 6px 4px;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}
.segmented button.on { background: var(--card-solid); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2); font-weight: 600; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 12px 0; font-size: 13px; }
.row input[type="time"], .row select {
  background: var(--raise);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 5px 8px;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: rgba(0, 0, 0, 0.35);
  display: grid;
  place-items: center;
  padding: 16px;
}
.modal-card { width: min(440px, 100%); max-height: min(86vh, 720px); display: flex; flex-direction: column; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 12px 4px 18px; }
.modal-head h2 { margin: 0; font-size: 17px; }
.modal-body { overflow: auto; padding: 4px 18px 18px; }
.modal-body h3 { margin: 18px 0 8px; font-size: 12px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--faint); }
.toggle { display: flex; align-items: center; justify-content: space-between; padding: 7px 0; font-size: 14px; cursor: pointer; }
.toggle input { width: 18px; height: 18px; accent-color: var(--accent); }
.feeds { width: 100%; border-collapse: collapse; font-size: 13px; }
.feeds td { padding: 4px 0; border-bottom: 1px solid var(--border); }
.feeds td:last-child { text-align: right; color: var(--muted); }
.small { font-size: 12px; color: var(--muted); }

.tooltip {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 15;
  padding: 7px 10px;
  max-width: 280px;
  background: var(--card-solid);
  border: 1px solid var(--border);
  border-radius: 9px;
  box-shadow: var(--shadow);
  pointer-events: none;
  will-change: transform;
  font-size: 13px;
}
.tooltip .tt-line { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.tooltip .tt-meta { color: var(--muted); font-size: 12px; margin-top: 2px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + var(--safe-bottom));
  transform: translateX(-50%);
  z-index: 40;
  background: var(--card-solid);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  border-radius: 10px;
  padding: 9px 14px;
  font-size: 13px;
}

/* ------------------------------------------------------------ mobil */

@media (max-width: 760px) {
  :root { --gap: 10px; }
  .column {
    left: var(--gap);
    right: var(--gap);
    width: auto;
    max-height: none;
    bottom: 0;
  }
  .bar { padding: 7px 8px 7px 12px; }
  .status { display: none; }
  .bar:focus-within .status { display: none; }

  /* Bottenark */
  .sheet {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    height: var(--sheet-h, 40vh);
    max-height: calc(100% - 70px - var(--safe-top));
    border-radius: 18px 18px 0 0;
    border-bottom: 0;
    transition: height 0.22s ease;
    padding-bottom: var(--safe-bottom);
  }
  .sheet.dragging { transition: none; }
  .sheet-handle {
    display: grid;
    place-items: center;
    height: 22px;
    flex: none;
    cursor: grab;
    touch-action: none;
  }
  .sheet-handle span { width: 40px; height: 5px; border-radius: 3px; background: var(--raise-2); }
  .panel-body { padding-top: 2px; }

  .controls { top: calc(68px + var(--safe-top)); }
  .zoom { display: none; }
  .legend { display: none; }
  .attribution { bottom: auto; top: calc(70px + var(--safe-top)); left: var(--gap); right: auto; }
  .maplibregl-ctrl-bottom-right { display: none; }
  .popover { left: var(--gap) !important; right: var(--gap); width: auto; }
  .modal { place-items: end center; padding: 0; }
  .modal-card { width: 100%; border-radius: 18px 18px 0 0; max-height: 88vh; padding-bottom: var(--safe-bottom); }
}

.attribution { color: var(--muted); }

.noscript {
  position: absolute;
  inset: 0;
  z-index: 10;
  padding: 24px;
  max-width: 640px;
  margin: 0 auto;
  color: var(--text);
}
