:root {
  --early: #2563eb;
  --ontime: #16a34a;
  --late: #ea8a0c;
  --verylate: #dc2626;
  --unknown: #8a919c;
  --doors: #facc15;

  --bg: #ffffff;
  --fg: #1b1d22;
  --muted: #5f6672;
  --line: #e2e5ea;
  --accent: #0b6bcb;
  --chip: #eef2f7;
  --shadow: 0 6px 24px rgba(15, 23, 42, .18);
  --radius: 12px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1c1f24;
    --fg: #e8eaee;
    --muted: #a3aab5;
    --line: #333841;
    --accent: #5aa7ff;
    --chip: #2a2f37;
    --shadow: 0 6px 24px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--fg);
  background: var(--bg);
  overflow: hidden;
}
#map { position: fixed; inset: 0; }

/* ---------------------------------------------------------------- paneeli */
.panel, .card {
  position: fixed;
  z-index: 2;
  background: var(--bg);
  color: var(--fg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.panel {
  top: 12px; left: 12px;
  width: 320px;
  max-height: calc(100% - 24px);
  display: flex; flex-direction: column;
}
.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 12px 6px 14px;
}
.panel-head h1 {
  font-size: 17px; margin: 0;
  display: flex; align-items: center; gap: 8px;
}
.panel-body { padding: 0 14px 10px; overflow-y: auto; }
.panel.collapsed .panel-body { display: none; }
.panel.collapsed #panel-toggle { transform: rotate(180deg); }

.icon-btn {
  border: 0; background: transparent; color: var(--muted);
  font-size: 18px; width: 32px; height: 32px; border-radius: 8px; cursor: pointer;
}
.icon-btn:hover { background: var(--chip); color: var(--fg); }

.tabs {
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--chip); border-radius: 10px; padding: 3px; gap: 2px;
  margin-bottom: 10px;
}
.tabs button {
  border: 0; background: transparent; color: var(--muted);
  padding: 7px 0; border-radius: 8px; font: inherit; font-size: 13.5px; cursor: pointer;
}
.tabs button[aria-selected="true"] {
  background: var(--bg); color: var(--fg); font-weight: 600;
  box-shadow: 0 1px 3px rgba(0,0,0,.12);
}

.mode { margin-bottom: 8px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 6px 0; }
.row input { flex: 1; min-width: 0; }
input, select {
  font: inherit; color: var(--fg); background: var(--bg);
  border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px;
}
input:focus, select:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.btn {
  font: inherit; font-weight: 600; color: #fff; background: var(--accent);
  border: 0; border-radius: 8px; padding: 7px 12px; cursor: pointer;
}
.btn.secondary { background: var(--chip); color: var(--fg); }
.field { display: flex; justify-content: space-between; align-items: center; margin: 6px 0; gap: 8px; }
.check { display: flex; gap: 6px; align-items: center; margin: 6px 0; font-size: 14px; }
.hint { color: var(--muted); font-size: 13px; margin: 4px 0; }

.chips { list-style: none; padding: 0; margin: 6px 0; display: flex; flex-wrap: wrap; gap: 6px; }
.chips li {
  display: flex; align-items: center; gap: 4px;
  background: var(--chip); border-radius: 999px; padding: 3px 4px 3px 10px; font-weight: 600;
}
.chips li .n { color: var(--muted); font-weight: 400; font-size: 12px; }
.chips button {
  border: 0; background: transparent; color: var(--muted); cursor: pointer;
  width: 22px; height: 22px; border-radius: 50%;
}
.chips button:hover { background: var(--line); color: var(--fg); }

.results { list-style: none; padding: 0; margin: 6px 0; }
.results li button {
  width: 100%; text-align: left; font: inherit; color: var(--fg);
  background: var(--chip); border: 0; border-radius: 8px; padding: 8px 10px; margin: 3px 0; cursor: pointer;
}
.results li button:hover { background: var(--line); }

.legend { margin-top: 6px; border-top: 1px solid var(--line); padding-top: 8px; }
.legend summary { cursor: pointer; font-size: 14px; color: var(--muted); }
.legend ul { list-style: none; padding: 0; margin: 8px 0; display: grid; gap: 5px; font-size: 13.5px; }
.legend li { display: flex; align-items: center; gap: 8px; }
.sw { width: 16px; height: 16px; border-radius: 50%; background: var(--c); border: 2px solid #fff;
      box-shadow: 0 0 0 1px rgba(0,0,0,.2); margin: 0 2px; }

.status {
  display: flex; align-items: center; gap: 8px;
  border-top: 1px solid var(--line); padding: 8px 14px; font-size: 13px; color: var(--muted);
}
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--unknown); flex: none; }
.dot.ok { background: var(--ontime); }
.dot.warn { background: var(--late); }
.dot.err { background: var(--verylate); }

/* ---------------------------------------------------------------- tietokortti */
.card {
  top: 12px; right: 12px; width: 340px; max-height: calc(100% - 24px);
  overflow-y: auto; padding: 12px 14px;
}
.card-head { display: flex; justify-content: space-between; gap: 8px; }
.card-title { font-size: 20px; font-weight: 700; }
.card-sub { color: var(--muted); font-size: 13.5px; }
.delay-banner {
  margin: 10px 0 6px; padding: 8px 10px; border-radius: 8px; font-weight: 600;
  color: #fff; background: var(--unknown);
}
.delay-banner[data-c="early"] { background: var(--early); }
.delay-banner[data-c="on_time"] { background: var(--ontime); }
.delay-banner[data-c="late"] { background: var(--late); }
.delay-banner[data-c="very_late"] { background: var(--verylate); }
.facts { display: grid; grid-template-columns: auto 1fr; gap: 5px 12px; margin: 8px 0; font-size: 14px; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; display: flex; justify-content: space-between; gap: 6px; }
.src {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted);
  border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; align-self: center; white-space: nowrap;
}
.src.derived { border-style: dashed; }
.warn-text { color: var(--verylate); font-weight: 600; }
.card-actions { border-top: 1px solid var(--line); padding-top: 6px; }

.maplibregl-popup-content { background: var(--bg); color: var(--fg); border-radius: 8px; }
.maplibregl-popup-tip { border-top-color: var(--bg) !important; border-bottom-color: var(--bg) !important; }

/* ---------------------------------------------------------------- tiedotteet-painike */
.alerts-btn {
  margin-left: auto; margin-right: 4px;
  border: 0; border-radius: 999px; padding: 4px 10px; cursor: pointer;
  font: inherit; font-size: 13px; font-weight: 600;
  background: var(--chip); color: var(--fg);
}
.alerts-btn.has { background: #fef3c7; color: #7c4a03; }
.map-opt { border-top: 1px solid var(--line); padding-top: 8px; }

/* ---------------------------------------------------------------- lähtölista */
.deps { list-style: none; padding: 0; margin: 8px 0; }
.deps li {
  display: grid; grid-template-columns: 48px 1fr auto; gap: 4px 10px; align-items: center;
  padding: 8px 0; border-bottom: 1px solid var(--line);
}
.deps .ln {
  font-weight: 700; text-align: center; border-radius: 6px; padding: 3px 0;
  background: var(--accent); color: #fff; font-size: 14px;
}
.deps .hs { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.deps .hs small { display: block; color: var(--muted); font-size: 12px; }
.deps .tm { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.deps .tm small { display: block; font-weight: 400; font-size: 11.5px; color: var(--muted); }
.deps .tm.sched { font-weight: 400; font-style: italic; color: var(--muted); }
.live { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--ontime);
        margin-right: 5px; vertical-align: middle; animation: pulse 2s infinite; }
@keyframes pulse { 50% { opacity: .35; } }
@media (prefers-reduced-motion: reduce) { .live { animation: none; } }
.d-late { color: var(--verylate); }
.d-early { color: var(--early); }

.pop { font-size: 13px; min-width: 180px; }
.pop b { font-size: 14px; }
.pop ul { list-style: none; padding: 0; margin: 6px 0 0; }
.pop li { display: flex; gap: 8px; justify-content: space-between; }
.pop .hint { margin: 4px 0 0; }

/* ---------------------------------------------------------------- tiedotteet */
.alerts { list-style: none; padding: 0; margin: 6px 0; }
.alert { border: 1px solid var(--line); border-left: 4px solid var(--late); border-radius: 8px;
         padding: 8px 10px; margin: 8px 0; }
.alert.info { border-left-color: var(--accent); }
.alert.upcoming { opacity: .8; border-left-style: dashed; }
.alert h3 { font-size: 14px; margin: 0 0 4px; }
.alert .meta { color: var(--muted); font-size: 12.5px; }
.alert .lines { display: flex; flex-wrap: wrap; gap: 4px; margin: 6px 0 2px; }
.alert .lines span { background: var(--chip); border-radius: 5px; padding: 1px 6px; font-size: 12px; font-weight: 600; }
.alert details { margin-top: 4px; font-size: 13.5px; }
.alert details p { white-space: pre-line; margin: 6px 0; }
.alert a { color: var(--accent); }
.seg { display: inline-flex; background: var(--chip); border-radius: 8px; padding: 2px; }
.seg button { border: 0; background: transparent; color: var(--muted); font: inherit; font-size: 13px;
              padding: 4px 10px; border-radius: 6px; cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--bg); color: var(--fg); font-weight: 600; }

/* ---------------------------------------------------------------- mobiili */
@media (max-width: 700px) {
  .panel {
    top: auto; bottom: 0; left: 0; right: 0; width: auto;
    border-radius: var(--radius) var(--radius) 0 0;
    max-height: 55%;
    padding-bottom: env(safe-area-inset-bottom);
  }
  .card {
    top: auto; bottom: 0; left: 0; right: 0; width: auto; max-height: 60%;
    border-radius: var(--radius) var(--radius) 0 0; z-index: 3;
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
  }
  .maplibregl-ctrl-bottom-right, .maplibregl-ctrl-bottom-left { bottom: 56px; }
}

.sec { font-size: 14px; margin: 14px 0 4px; }
