/* Tidskartan (tidskarta.html). Sidhuvudet ligger i subpage.css, färger och mått i tokens.css.
   Kartan fyller hela ytan under sidhuvudet. Sökfältet, lägesväljaren, zoomknapparna och kortet flyter över den:
   på mobilen ligger kortet nertill och fälls ut över kartan, på bred skärm är det en spalt till vänster.
   Kartans egna färger (--tm-…) läses av timemap-view.js och har ett ljust och ett mörkt läge. */
:root {
  --tm-sea: #d5e3ee; --tm-land: #e3e7e2; --tm-se: #fbfbf7; --tm-urban: #eadfc8; --tm-road: #e4d8ba; --tm-rail: #7c8894;
  --tm-halo: #ffffff; --tm-edge: rgba(18, 26, 35, .45);
}
:root[data-night="on"] {
  --tm-sea: #070d13; --tm-land: #0f161d; --tm-se: #18222c; --tm-urban: #26323f; --tm-road: #2a3644; --tm-rail: #63758a;
  --tm-halo: #0d141b; --tm-edge: rgba(0, 0, 0, .6);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); background: var(--tm-sea); color: var(--fg); font: var(--fs-md)/1.4 var(--font); overflow: hidden; }
a { color: var(--accent); }
.tm-sr { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

.tm { position: relative; min-height: 0; overflow: hidden; }
#tm-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; cursor: grab; outline: none; }
#tm-canvas.dragging { cursor: grabbing; }
#tm-canvas:focus-visible { box-shadow: inset 0 0 0 3px var(--accent); }

/* ---------- Sök och läge ---------- */
.tm-top { position: absolute; z-index: 3; top: 10px; left: 10px; right: 10px; display: flex; gap: 8px; align-items: flex-start; pointer-events: none; }
.tm-top > * { pointer-events: auto; }
.tm-search { position: relative; flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; height: 46px; padding: 0 14px 0 16px; border-radius: var(--r-pill); background: var(--panel); box-shadow: var(--shadow-2); }
.tm-search:focus-within { box-shadow: var(--shadow-2), 0 0 0 2px var(--accent); }
.tm-search label { flex: none; font-size: var(--fs-xs); font-weight: var(--fw-bold); letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.tm-search input { flex: 1; min-width: 0; height: 100%; border: 0; background: none; color: var(--fg); font: var(--fw-heavy) 16px var(--font); letter-spacing: var(--tracking-tight); outline: none; text-overflow: ellipsis; }
.tm-search input::placeholder { color: var(--muted); font-weight: var(--fw-medium); }
.tm-search > svg { flex: none; color: var(--muted); }
.tm-sugg { position: absolute; top: calc(100% + 6px); left: 0; right: 0; margin: 0; padding: 6px; list-style: none; border-radius: var(--r-lg); background: var(--panel); box-shadow: var(--shadow-3); max-height: min(56vh, 420px); overflow-y: auto; }
.tm-sugg li { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 44px; padding: 0 12px; border-radius: var(--r-md); font-size: var(--fs-lg); font-weight: var(--fw-medium); cursor: pointer; }
.tm-sugg li small { font: var(--fw-medium) var(--fs-xs) var(--mono); color: var(--muted); }
.tm-sugg li[aria-selected="true"], .tm-sugg li[data-i]:hover { background: var(--accent-soft); }
.tm-sugg li.none { color: var(--muted); cursor: default; font-weight: var(--fw-regular); }

.tm-mode { flex: none; display: flex; height: 46px; padding: 4px; border-radius: var(--r-pill); background: var(--panel); box-shadow: var(--shadow-2); }
.tm-mode button { min-width: 64px; padding: 0 12px; border: 0; border-radius: var(--r-pill); background: none; color: var(--muted); font: var(--fw-bold) var(--fs-sm) var(--font); cursor: pointer; transition: background var(--dur-2) var(--ease), color var(--dur-2) var(--ease); }
.tm-mode button[aria-pressed="true"] { background: var(--fg); color: var(--panel); }
.tm-mode button:focus-visible, .tm-zoom button:focus-visible, .tm-card button:focus-visible, .tm-card a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Tid på dygnet: en rad under sökfältet */
.tm-when { position: absolute; z-index: 2; top: 64px; left: 10px; display: flex; max-width: calc(100% - 72px); height: 40px; padding: 4px; border-radius: var(--r-pill); background: var(--panel); box-shadow: var(--shadow-1); overflow-x: auto; scrollbar-width: none; }
.tm-when::-webkit-scrollbar { display: none; }
.tm-when button { flex: none; padding: 0 11px; border: 0; border-radius: var(--r-pill); background: none; color: var(--muted); font: var(--fw-bold) var(--fs-sm) var(--font); white-space: nowrap; cursor: pointer; transition: background var(--dur-2) var(--ease), color var(--dur-2) var(--ease); }
.tm-when button[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); }
.tm-when button:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

.tm-zoom { position: absolute; z-index: 2; right: 10px; top: 64px; display: grid; border-radius: var(--r-lg); background: var(--panel); box-shadow: var(--shadow-1); overflow: hidden; }
.tm-zoom button { width: 42px; height: 42px; display: grid; place-items: center; border: 0; background: none; color: var(--fg); cursor: pointer; }
.tm-zoom button + button { border-top: 1px solid var(--line); }
.tm-zoom button:hover { background: var(--surface-2); }

/* ---------- Kortet ---------- */
.tm-card { position: absolute; z-index: 4; left: 8px; right: 8px; bottom: calc(8px + env(safe-area-inset-bottom, 0px)); display: flex; flex-direction: column; max-height: calc(100% - 114px); border-radius: var(--r-xl); background: var(--panel); box-shadow: var(--shadow-3); overflow: hidden; }
.tm-main { padding: 14px 16px 10px; }
.tm-title { margin: 0; font-size: var(--fs-3xl); line-height: 1.15; font-weight: var(--fw-heavy); letter-spacing: var(--tracking-tight); text-wrap: balance; }
.tm-title > span { display: block; margin-bottom: 3px; font-size: var(--fs-xs); font-weight: var(--fw-bold); letter-spacing: .08em; text-transform: uppercase; color: var(--accent); }
.tm-kicker { margin: 0 0 2px; font-size: var(--fs-xs); font-weight: var(--fw-bold); letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.tm-lead { margin: 6px 0 0; font-size: var(--fs-sm); color: var(--text-2); }
.tm-legend { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 4px; margin: 12px 0 0; padding: 0; list-style: none; }
.tm-legend li { display: grid; gap: 1px; padding-top: 7px; border-top: 5px solid var(--c); border-radius: 2px; font-size: var(--fs-xs); line-height: 1.25; }
.tm-legend b { font-weight: var(--fw-heavy); white-space: nowrap; }
.tm-legend li > span { color: var(--muted); font-family: var(--mono); }
.tm-chip i, .tm-time i, .tm-list h3 i { flex: none; width: 10px; height: 10px; border-radius: 50%; box-shadow: inset 0 0 0 1px var(--tm-edge); }

.tm-sel { position: relative; padding-right: 40px; }
.tm-x { position: absolute; top: -4px; right: -6px; width: 40px; height: 40px; display: grid; place-items: center; border: 0; border-radius: 50%; background: var(--surface-2); color: var(--fg); cursor: pointer; }
.tm-time { display: flex; align-items: center; gap: 8px; margin: 6px 0 0; }
.tm-time i { width: 14px; height: 14px; }
.tm-time b { font: var(--fw-heavy) 30px/1 var(--font); letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.tm-time span { align-self: flex-end; padding-bottom: 2px; font-size: var(--fs-xs); color: var(--muted); }
.tm-span { margin: 10px 0 0; padding: 10px 12px 6px; border-radius: var(--r-md); background: var(--surface-2); }
.tm-span p { margin: 0 0 8px; font-size: var(--fs-sm); line-height: 1.4; color: var(--text-2); }
.tm-span b { color: var(--fg); font-weight: var(--fw-heavy); }
.tm-strip svg { display: block; width: 100%; height: 34px; border-bottom: 1px solid var(--line); }
.tm-ticks { position: relative; height: 16px; font: var(--fw-medium) 10px var(--mono); color: var(--muted); }
.tm-ticks span { position: absolute; top: 3px; transform: translateX(-50%); }
.tm-sub { margin: 6px 0 0; font-size: var(--fs-md); color: var(--text-2); }
.tm-cmp { margin: 4px 0 0; font-size: var(--fs-sm); color: var(--muted); }
.tm-acts { display: flex; gap: 8px; margin: 12px -40px 0 0; }
.tm-btn { display: inline-flex; align-items: center; justify-content: center; min-height: 44px; padding: 0 16px; border: 1.5px solid var(--line); border-radius: var(--r-pill); background: var(--panel); color: var(--fg); font: var(--fw-bold) var(--fs-md) var(--font); text-decoration: none; cursor: pointer; white-space: nowrap; }
.tm-btn.primary { flex: 1; border-color: var(--accent); background: var(--accent); color: var(--on-accent); }
.tm-btn.icon { width: 44px; padding: 0; }
.tm-btn.icon svg { width: 18px; height: 18px; }
.tm-btn:hover { border-color: var(--accent); }

.tm-grip { display: flex; align-items: center; justify-content: center; gap: 6px; width: 100%; min-height: 44px; border: 0; border-top: 1px solid var(--line); background: none; color: var(--accent); font: var(--fw-bold) var(--fs-sm) var(--font); cursor: pointer; }
.tm-grip svg { transition: transform var(--dur-2) var(--ease); }
.tm-grip[aria-expanded="true"] svg { transform: rotate(180deg); }
.tm-more { display: none; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 4px 16px 16px; border-top: 1px solid var(--line); }
.tm-card[data-open="true"] .tm-more { display: block; }
.tm-card[data-open="true"] .tm-lead { display: none; }

.tm-ins h2, .tm-all h2 { margin: 14px 0 8px; font-size: var(--fs-xs); font-weight: var(--fw-bold); letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.tm-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.tm-chip { display: inline-flex; align-items: center; gap: 7px; min-height: 38px; padding: 0 12px 0 10px; border: 1.5px solid var(--line); border-radius: var(--r-pill); background: var(--panel); color: var(--fg); font: var(--fw-bold) var(--fs-sm) var(--font); cursor: pointer; }
.tm-chip span { font: var(--fw-medium) var(--fs-xs) var(--mono); color: var(--muted); }
.tm-chip:hover { border-color: var(--accent); }
.tm-list h3 { display: flex; align-items: center; gap: 8px; margin: 12px 0 2px; font-size: var(--fs-sm); font-weight: var(--fw-heavy); }
.tm-list ol { margin: 0; padding: 0; list-style: none; }
.tm-list li + li { border-top: 1px solid var(--line); }
.tm-list button { display: flex; align-items: center; justify-content: space-between; gap: 12px; width: 100%; min-height: 40px; padding: 0 2px; border: 0; background: none; color: var(--fg); font: var(--fw-medium) var(--fs-md) var(--font); text-align: left; cursor: pointer; }
.tm-list button b { font: var(--fw-medium) var(--fs-sm) var(--mono); color: var(--text-2); }
.tm-list button:hover span { color: var(--accent); }
.tm-links { display: flex; flex-wrap: wrap; gap: 6px 16px; margin: 16px 0 0; font-size: var(--fs-sm); font-weight: var(--fw-bold); }
.tm-link { padding: 0; border: 0; background: none; color: var(--accent); font: inherit; text-decoration: underline; cursor: pointer; }
.tm-note { margin: 10px 0 0; font-size: var(--fs-xs); line-height: 1.5; color: var(--muted); }
.tm-skel { display: grid; gap: 8px; margin-top: 10px; }
.tm-skel i { height: 14px; border-radius: var(--r-sm); background: var(--surface-2); }
.tm-skel i + i { width: 60%; }
.tm-main .st-err, .tm-main .st-msg { margin-top: 10px; }

/* ---------- Bred skärm: kortet som spalt till vänster ---------- */
@media (min-width: 900px) {
  .tm-top { top: 16px; left: 16px; right: auto; width: 380px; }
  .tm-when { top: 72px; left: 16px; max-width: 380px; }
  .tm-card { left: 16px; right: auto; top: 124px; bottom: 16px; width: 380px; max-height: none; }
  .tm-main { padding: 18px 20px 14px; }
  .tm-title { font-size: var(--fs-4xl); }
  .tm-grip { display: none; }
  .tm-more { display: block; padding: 2px 20px 20px; }
  .tm-zoom { top: 16px; right: 16px; }
  .tm-card[data-open="true"] .tm-lead { display: block; }
}
@media (max-width: 380px) {
  .tm-search label { display: none; }
  .tm-mode button { min-width: 0; padding: 0 10px; }
}
/* Liggande telefon: kortet får inte ta hela höjden */
@media (max-width: 899px) and (max-height: 480px) {
  .tm-card { right: auto; width: min(340px, 50%); }
  .tm-lead { display: none; }
}
