/* Gotthard Stau — design system (2026-07 redesign).
 *
 * Mobile-first. Same validated palette as the main app (dataviz reference:
 * direction = categorical slots 1+2, heat = fixed status scale) plus ONE new
 * semantic hue: --forecast (#199e70, validated against BOTH direction colors
 * in BOTH modes, no contrast relief needed). Semantics everywhere:
 *   gemessen  = direction color, solid line
 *   Prognose  = teal, dashed line + teal wash band
 * Direction colors never encode measured-vs-forecast again.
 */

:root {
  color-scheme: light;
  --page: #f6f6f3;
  --surface: #fcfcfb;
  --surface-2: #f1f0ec;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11, 11, 11, 0.1);

  --south: #eb6834;
  --north: #2a78d6;
  --south-wash: rgba(235, 104, 52, 0.12);
  --north-wash: rgba(42, 120, 214, 0.12);

  --forecast: #199e70;
  --forecast-wash: rgba(25, 158, 112, 0.14);

  --heat-0: #0ca30c;
  --heat-1: #fab219;
  --heat-2: #ec835a;
  --heat-3: #d03b3b;

  --good-text: #006300;
  --bad-text: #b3362f;
  --warn-bg: rgba(250, 178, 25, 0.16);

  /* "Portal" identity surface — tunnel-dark in both themes (signage panel). */
  --portal: #14181c;
  --portal-ink: #f5f6f4;
  --portal-muted: #9aa3a9;

  --radius: 16px;
  --shadow: 0 1px 2px rgba(11, 11, 11, 0.04), 0 4px 16px rgba(11, 11, 11, 0.05);
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #232322;
    --ink: #ffffff;
    --ink-2: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --baseline: #383835;
    --border: rgba(255, 255, 255, 0.1);

    --south: #d95926;
    --north: #3987e5;
    --south-wash: rgba(217, 89, 38, 0.18);
    --north-wash: rgba(57, 135, 229, 0.18);

    --forecast: #199e70;
    --forecast-wash: rgba(25, 158, 112, 0.18);

    --good-text: #0ca30c;
    --bad-text: #e66767;
    --warn-bg: rgba(250, 178, 25, 0.12);

    --portal: #101418;
    --portal-ink: #f5f6f4;
    --portal-muted: #8b949b;

    --shadow: none;
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

body {
  background: var(--page);
  color: var(--ink);
  font-family:
    system-ui,
    -apple-system,
    "Segoe UI",
    sans-serif;
  font-size: 15px;
  line-height: 1.45;
  /* Kill any accidental horizontal stretch — the #1 mobile complaint. */
  overflow-x: hidden;
}

/* ── Page frame ─────────────────────────────────────────────────────── */

.wrap {
  max-width: 640px;
  margin: 0 auto;
  padding: 0 12px calc(24px + env(safe-area-inset-bottom));
}

@media (min-width: 900px) {
  .wrap.wide {
    max-width: 960px;
  }
}

/* ── Cards & tiles ──────────────────────────────────────────────────── */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
  margin-top: 12px;
}

/* ── Chips, dots, pills ─────────────────────────────────────────────── */

.dir-dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex: none;
}

.dir-dot.south {
  background: var(--south);
}

.dir-dot.north {
  background: var(--north);
}

.status-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex: none;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--surface-2);
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink-2);
}

.chip.ok .status-dot {
  background: var(--heat-0);
}

.chip.bad .status-dot {
  background: var(--heat-3);
}

.chip.unknown .status-dot {
  background: var(--baseline);
}

.heat-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  font-weight: 700;
}

.heat-swatch {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 3px;
}

.heat-bg-0 {
  background: var(--heat-0);
}
.heat-bg-1 {
  background: var(--heat-1);
}
.heat-bg-2 {
  background: var(--heat-2);
}
.heat-bg-3 {
  background: var(--heat-3);
}

/* ── Chart legend with CORRECT semantics (gemessen vs Prognose) ─────── */

.viz-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  font-size: 12px;
  color: var(--ink-2);
  margin: 6px 2px 0;
}

.viz-legend .key {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.key-line {
  display: inline-block;
  width: 18px;
  height: 0;
  border-top: 2.5px solid var(--ink-2);
  border-radius: 2px;
}

.key-line.south {
  border-top-color: var(--south);
}
.key-line.north {
  border-top-color: var(--north);
}

.key-line.forecast {
  border-top-style: dashed;
  border-top-color: var(--forecast);
}

.key-band {
  display: inline-block;
  width: 18px;
  height: 10px;
  border-radius: 3px;
  background: var(--forecast-wash);
}

.chart-box {
  position: relative;
  height: 200px;
  margin-top: 8px;
}

.chart-box.tall {
  height: 260px;
}

/* ── Info-on-demand (i) buttons + popover ───────────────────────────── */

.ibtn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 1.5px solid var(--baseline);
  background: none;
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 700;
  font-style: italic;
  font-family: Georgia, serif;
  cursor: pointer;
  flex: none;
  padding: 0;
}

.ibtn:hover {
  color: var(--ink);
  border-color: var(--ink-2);
}

/* ── Bottom sheet (mobile) / modal (desktop) ────────────────────────── */

.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 90;
  animation: fade-in 0.15s ease;
}

.sheet {
  position: fixed;
  z-index: 91;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: 88dvh;
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  box-shadow: 0 -8px 40px rgba(0, 0, 0, 0.25);
  display: flex;
  flex-direction: column;
  animation: sheet-up 0.2s ease;
}

@media (min-width: 700px) {
  .sheet {
    left: 50%;
    right: auto;
    bottom: auto;
    top: 50%;
    transform: translate(-50%, -50%);
    width: min(640px, 94vw);
    max-height: 86vh;
    border-radius: 20px;
    animation: fade-in 0.15s ease;
  }
}

.sheet-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--border);
}

.sheet-head h2 {
  margin: 0;
  font-size: 17px;
  flex: 1;
}

.sheet-head .sub {
  display: block;
  font-size: 12.5px;
  font-weight: 400;
  color: var(--muted);
}

.sheet-close {
  border: none;
  background: var(--surface-2);
  color: var(--ink-2);
  width: 30px;
  height: 30px;
  border-radius: 50%;
  font-size: 15px;
  cursor: pointer;
  flex: none;
}

.sheet-body {
  overflow-y: auto;
  padding: 4px 16px calc(16px + env(safe-area-inset-bottom));
  overscroll-behavior: contain;
}

.sheet-grab {
  width: 36px;
  height: 4px;
  border-radius: 2px;
  background: var(--baseline);
  margin: 8px auto 0;
}

@media (min-width: 700px) {
  .sheet-grab {
    display: none;
  }
}

@keyframes sheet-up {
  from {
    transform: translateY(40px);
    opacity: 0.5;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

/* ── Segmented control ──────────────────────────────────────────────── */

.seg {
  display: inline-flex;
  background: var(--surface-2);
  border-radius: 10px;
  padding: 3px;
  gap: 2px;
}

.seg button {
  border: none;
  background: none;
  color: var(--ink-2);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 8px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.seg button[aria-pressed="true"] {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}

/* ── Tables (compact, scroll INSIDE, never stretch the page) ────────── */

.tscroll {
  overflow-x: auto;
  margin-top: 8px;
}

table {
  border-collapse: collapse;
  width: 100%;
  font-size: 12.5px;
}

th,
td {
  text-align: left;
  padding: 5px 8px;
  border-bottom: 1px solid var(--grid);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

th {
  color: var(--muted);
  font-weight: 600;
  font-size: 11.5px;
}

/* ── Misc ───────────────────────────────────────────────────────────── */

.muted {
  color: var(--muted);
  font-size: 12.5px;
}

.src-note {
  color: var(--muted);
  font-size: 11.5px;
  margin-top: 10px;
}

.src-note a {
  color: inherit;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

h1,
h2,
h3 {
  margin: 0;
  letter-spacing: -0.01em;
}

.section-title {
  font-size: 14px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-top: 20px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.flag {
  display: inline-flex;
  width: 15px;
  height: 11px;
  border-radius: 2px;
  overflow: hidden;
  vertical-align: -1px;
}

.flag svg {
  width: 100%;
  height: 100%;
}

/* ── Dashboard page ─────────────────────────────────────────────────── */

/* ── V2 — widget dashboard. Page order: Tunnel (⊃ Portale) → Pass →
       Tagesverlauf → Meldungen. Portal widgets mirror the DRIVING order:
       Nordportal reads top→down like driving south (Einfahrten → Zahlen →
       Portal-Messstelle), Südportal reversed — stacked they read like the
       corridor itself, tunnel in the middle. ── */

/* Mobile: cards flatten into full-bleed bands — no border ring, no
       radius, and the .wrap gutter is cancelled with negative margins, so
       the only horizontal inset is the band's own 12px padding (~38px more
       usable width on a phone). The card chrome returns at ≥700px where
       horizontal space is plentiful. */
.card {
  border-inline: 0;
  border-radius: 0;
  box-shadow: none;
  margin: 14px -12px 0;
  padding: 18px 12px;
}

@media (min-width: 700px) {
  .card {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin: 18px 0 0;
    padding: 20px 18px;
  }
}

.topbar-v2 {
  position: sticky;
  top: 0;
  z-index: 30;
  background: var(--portal);
  color: var(--portal-ink);
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.topbar-v2 .stand {
  margin-left: auto;
  font-size: 12px;
  color: var(--portal-muted);
  font-variant-numeric: tabular-nums;
}

.topbar-v2 a.proto-link {
  color: var(--portal-muted);
  font-size: 12px;
  text-decoration: none;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 999px;
  padding: 3px 9px;
}

.widget-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 17px;
  font-weight: 750;
  letter-spacing: -0.01em;
}

.widget-title .spacer {
  flex: 1;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 12px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 800;
  letter-spacing: 0.04em;
}

.badge.ok {
  background: color-mix(in srgb, var(--heat-0) 18%, transparent);
  color: var(--good-text);
}

.badge.bad {
  background: color-mix(in srgb, var(--heat-3) 18%, transparent);
  color: var(--bad-text);
}

.badge.unknown {
  background: var(--surface-2);
  color: var(--muted);
}

.tunnel-note {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
  color: var(--ink-2);
  margin-top: 8px;
}

.tunnel-note.ok {
  color: var(--good-text);
}

/* ── Portals inside the tunnel widget ── */

/* Portals are plain sections inside the tunnel widget — no card-in-card.
       Mobile: stacked with the tunnel divider between them; desktop: two
       columns split by a hairline. */
.tunnel-portals {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0;
  margin-top: 6px;
}

@media (min-width: 860px) {
  .tunnel-portals {
    grid-template-columns: 1fr 1fr;
    gap: 0 28px;
  }

  .portal-sec.dir-north {
    border-left: 1px solid var(--border);
    padding-left: 28px;
  }
}

.portal-sec {
  padding: 24px 0 10px;
}

/* The tunnel divider (mobile only): hairline with a small label. */
.tunnel-connector {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 18px;
  color: var(--muted);
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-top: 10px;
}

.tunnel-connector::before,
.tunnel-connector::after {
  content: "";
  flex: 1;
  border-top: 1px solid var(--border);
}

@media (min-width: 860px) {
  .tunnel-connector {
    display: none;
  }
}

.p-head {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 16px;
}

.p-name {
  font-size: 13.5px;
  font-weight: 800;
  letter-spacing: 0.05em;
}

.p-place {
  font-size: 13px;
  color: var(--muted);
  font-weight: 600;
}

.p-dir {
  font-size: 12.5px;
  color: var(--ink-2);
  font-weight: 650;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-top: 2px;
}

.p-head .right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 7px;
}

/* Rail (vertical approach schematic) — desktop only; on mobile the
       info-lines carry the same facts and the width belongs to the numbers. */
.portal-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 4px 12px;
}

.rail {
  display: none;
}

@media (min-width: 860px) {
  .portal-grid {
    grid-template-columns: 84px 1fr;
  }

  .rail {
    display: block;
  }
}

.rail svg {
  width: 84px;
  height: auto;
  display: block;
}

.p-content {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.p-hero {
  display: flex;
  align-items: baseline;
  gap: 24px;
  margin: 2px 0;
}

.p-hero .big {
  white-space: nowrap;
  font-size: 34px;
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.p-hero .big small {
  font-size: 15px;
  font-weight: 650;
  color: var(--ink-2);
  letter-spacing: 0;
}

.p-hero .mid {
  font-size: 21px;
  font-weight: 750;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.p-hero .mid small {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink-2);
}

.hero-label {
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin-top: 4px;
  white-space: nowrap;
}

.trend {
  font-size: 19px;
  font-weight: 800;
  line-height: 1;
  margin-left: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.trend small {
  font-size: 9.5px;
  font-weight: 650;
  color: var(--muted);
}

.trend.up {
  color: var(--bad-text);
}

.trend.down {
  color: var(--good-text);
}

.trend.flat {
  color: var(--muted);
}

/* Mini day chart — tap opens the big graph */
.mini-wrap {
  position: relative;
  height: 72px;
  border-radius: 9px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.mini-wrap:hover {
  background: color-mix(in srgb, var(--surface-2) 70%, transparent);
}

.prog-chart .zoom,
.mini-wrap .zoom {
  position: absolute;
  top: 0;
  right: 4px;
  font-size: 12px;
  color: var(--muted);
  pointer-events: none;
}

/* Additional info (Einfahrten / CUPRA / Zählstelle): one shared
       typography — plain lines with a status dot, no boxes, no labels. */
.info-line {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 10px;
  font-size: 13px;
  color: var(--ink-2);
  font-variant-numeric: tabular-nums;
}

.info-line .item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.info-line .status-dot.ok {
  background: var(--heat-0);
}

.info-line .status-dot.mid {
  background: var(--heat-2);
}

.info-line .status-dot.bad {
  background: var(--heat-3);
}

.info-line .status-dot.off {
  background: var(--baseline);
}

.flow-lbl {
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin-right: 2px;
}

.prog-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 10px;
  margin-top: 8px;
}

.chip.sm {
  padding: 2.5px 8px;
  font-size: 11.5px;
}

/* ── Pass widget ── */
.pass-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px 18px;
  margin-top: 14px;
}

@media (min-width: 860px) {
  .pass-stats {
    grid-template-columns: repeat(4, auto);
    justify-content: start;
    gap: 10px 34px;
  }
}

.stat .s-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 5px;
}

.stat .s-value {
  font-size: 17px;
  font-weight: 700;
  margin-top: 2px;
}

.stat .s-sub {
  font-size: 11.5px;
  color: var(--muted);
}

/* Long feed text (e.g. Pass-Einschränkungen) stays compact — full text
       lives one tap away in the sheet. */
.stat .s-value.clamp {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  max-width: 340px;
}

/* ── Tagesverlauf widget ── */
.prog-nav {
  display: flex;
  align-items: center;
  gap: 7px;
  flex-wrap: nowrap;
}

.widget-title {
  flex-wrap: wrap;
  row-gap: 10px;
}

.prog-nav button.nav {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  width: 32px;
  height: 32px;
  border-radius: 9px;
  font-size: 15px;
  cursor: pointer;
}

.prog-nav button.nav:disabled {
  opacity: 0.35;
  cursor: default;
}

.prog-nav .date-input {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  border-radius: 9px;
  padding: 5px 8px;
  font: inherit;
  font-size: 13.5px;
  font-weight: 650;
}

.prog-dirs {
  display: grid;
  grid-template-columns: 1fr;
  gap: 26px;
  margin-top: 20px;
}

@media (min-width: 860px) {
  .prog-dirs {
    grid-template-columns: 1fr 1fr;
  }
}

/* Grid items default to min-width:auto, which locks each track to the
   chart canvas's current intrinsic width — Chart.js can then never shrink
   a chart when the viewport narrows (it only ever grows). Allow every
   chart-bearing grid cell to shrink below its content. */
.tunnel-portals > *,
.portal-grid > *,
.prog-dirs > * {
  min-width: 0;
}

.prog-block .head {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 13.5px;
  font-weight: 700;
}

.prog-chart {
  position: relative;
  height: 150px;
  margin-top: 6px;
  cursor: pointer;
}

.win-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 7px;
}

.chip.best {
  background: color-mix(in srgb, var(--heat-0) 14%, transparent);
  color: var(--good-text);
}

.chip.worst {
  background: color-mix(in srgb, var(--heat-3) 12%, transparent);
  color: var(--bad-text);
}

/* ── Meldungen ── */
.inc-item {
  padding: 9px 0;
  border-bottom: 1px solid var(--grid);
  font-size: 13px;
}

.inc-item:last-child {
  border-bottom: none;
}

.inc-item strong {
  display: block;
  font-size: 13px;
}

.inc-item .when {
  color: var(--muted);
  font-size: 11.5px;
}

.inc-item p {
  margin: 3px 0 0;
  color: var(--ink-2);
  font-size: 12.5px;
}

details.inc-group summary {
  cursor: pointer;
  font-weight: 650;
  font-size: 13px;
  padding: 8px 0;
  color: var(--ink-2);
}

.stale-strip {
  background: var(--warn-bg);
  border-radius: 12px;
  padding: 9px 12px;
  font-size: 13px;
  margin-top: 12px;
  display: flex;
  gap: 8px;
  align-items: center;
}

.footer-v2 {
  margin: 22px 2px 0;
  font-size: 11.5px;
  color: var(--muted);
  line-height: 1.7;
}

.footer-v2 a {
  color: inherit;
}

.skel {
  height: 160px;
  background: var(--surface-2);
  animation: pulse 1.2s ease-in-out infinite;
  /* Mirror the mobile full-bleed card bands — no rounded-card flash on
     first paint. */
  border-radius: 0;
  margin: 14px -12px 0;
}

@media (min-width: 700px) {
  .skel {
    border-radius: var(--radius);
    margin: 18px 0 0;
  }
}

@keyframes pulse {
  50% {
    opacity: 0.55;
  }
}
/* ── Topbar brand/link + Methodik page ──────────────────────────────── */

.proto-brand {
  display: flex;
  align-items: baseline;
  gap: 7px;
  color: inherit;
  text-decoration: none;
  font-weight: 700;
  font-size: 16px;
  white-space: nowrap;
}

.proto-brand small {
  font-weight: 500;
  color: var(--portal-muted);
  font-size: 11px;
}

.proto-link {
  color: var(--portal-muted);
  font-size: 12px;
  text-decoration: none;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 999px;
  padding: 3px 9px;
}

.back-link {
  color: var(--muted);
  text-decoration: none;
  font-size: 13px;
  display: inline-block;
  margin-top: 16px;
}

.page-title {
  font-size: 26px;
  margin: 6px 0 0;
}

.page-sub {
  color: var(--ink-2);
  margin: 4px 0 0;
}

.prose h2 {
  font-size: 17px;
  margin: 0 0 8px;
}

.prose ul {
  padding-left: 18px;
}

.prose li {
  margin: 4px 0;
}

.prose p {
  margin: 8px 0;
}
