/*!
 * Vägvisaren — app.css
 * Stort, lugnt gränssnitt med hög kontrast. Ljust/mörkt via systemet
 * eller manuellt val. Inga ramverk.
 * © 2026 Per Lindhé — IT Lösningar
 */

:root {
  --bg: #f4f2ee;
  --surface: #ffffff;
  --surface-2: #eae7e1;
  --line: #d6d2ca;
  --text: #14171c;
  --text-dim: #5c6470;
  --accent: #0f7a37;
  --accent-ink: #ffffff;
  --danger: #b3261e;
  --focus: #1d4ed8;
  --shadow: 0 6px 24px rgba(20, 23, 28, .12);
  --r: 16px;
  --tap: 60px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1319;
    --surface: #171c24;
    --surface-2: #202730;
    --line: #2c333e;
    --text: #eef2f7;
    --text-dim: #9aa4b2;
    --accent: #34d977;
    --accent-ink: #05230f;
    --danger: #ff6b60;
    --focus: #7dabff;
    --shadow: 0 6px 28px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0f1319;
  --surface: #171c24;
  --surface-2: #202730;
  --line: #2c333e;
  --text: #eef2f7;
  --text-dim: #9aa4b2;
  --accent: #34d977;
  --accent-ink: #05230f;
  --danger: #ff6b60;
  --focus: #7dabff;
  --shadow: 0 6px 28px rgba(0, 0, 0, .5);
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

/* Måste stå före .busy/.dest-card/.btn — annars vinner deras display-värde
   över [hidden] och osynliga element fortsätter fånga tryck. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  overscroll-behavior: none;
}

body {
  background: var(--bg);
  color: var(--text);
  font: 400 17px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

/* ---------- Skärmhantering ---------- */

.screen {
  position: fixed;
  inset: 0;
  display: none;
  flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.screen.is-active { display: flex; }

.fullcanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

/* ---------- Topprad ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px 4px;
  flex: 0 0 auto;
}

.brand {
  margin: 0;
  font-size: clamp(20px, 5vw, 26px);
  font-weight: 700;
  letter-spacing: -.02em;
}

.icon-btn {
  width: 48px; height: 48px;
  display: grid; place-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}
.icon-btn.small { width: 42px; height: 42px; flex: 0 0 auto; }
.icon-btn svg { width: 22px; height: 22px; fill: currentColor; }

/* ---------- Startskärm ---------- */

.start-body {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 8px 20px 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  max-width: 680px;
  width: 100%;
  margin: 0 auto;
}

.lede {
  margin: 8px 0 2px;
  font-size: clamp(26px, 7vw, 38px);
  font-weight: 700;
  letter-spacing: -.03em;
  line-height: 1.15;
}

.search-wrap { position: relative; }

.search {
  width: 100%;
  height: var(--tap);
  padding: 0 18px;
  font-size: 19px;
  color: var(--text);
  background: var(--surface);
  border: 2px solid var(--line);
  border-radius: var(--r);
  appearance: none;
}
.search::placeholder { color: var(--text-dim); }
.search:focus { border-color: var(--focus); outline: none; }

.suggest {
  position: absolute;
  z-index: 20;
  top: calc(var(--tap) + 6px);
  left: 0; right: 0;
  margin: 0; padding: 6px;
  list-style: none;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r);
  box-shadow: var(--shadow);
  max-height: 46vh;
  overflow-y: auto;
}
.suggest li {
  padding: 14px 14px;
  border-radius: 10px;
  cursor: pointer;
  min-height: 56px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.suggest li:hover, .suggest li[aria-selected="true"] { background: var(--surface-2); }
/* Platskoden är inte ett sökträff bland andra — den är ett exakt svar. */
.suggest li.suggest-code { border-left: 4px solid var(--accent); }
.suggest li.suggest-code strong { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: .06em; }
.suggest strong { font-size: 17px; font-weight: 600; }
.suggest span { font-size: 14px; color: var(--text-dim); }

/* ---------- Knappar ---------- */

.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: var(--tap);
  padding: 0 22px;
  font: inherit;
  font-size: 18px;
  font-weight: 650;
  border-radius: var(--r);
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform .06s ease;
}
.btn:active { transform: scale(.985); }
.btn svg { width: 22px; height: 22px; fill: currentColor; }

.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:disabled { background: var(--surface-2); color: var(--text-dim); cursor: not-allowed; }

.btn-ghost { background: var(--surface); color: var(--text); border-color: var(--line); }
.btn-danger { background: var(--danger); color: #fff; padding: 0 26px; }

.btn-link {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 15px;
  font-weight: 500;
  min-height: 46px;
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* ---------- Målkort ---------- */

.dest-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 14px 14px 18px;
  background: var(--surface);
  border: 2px solid var(--accent);
  border-radius: var(--r);
}
.dest-info { display: flex; flex-direction: column; min-width: 0; flex: 1 1 auto; }
.dest-label { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--text-dim); }
#dest-name { font-size: 19px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dest-meta { font-size: 14px; color: var(--text-dim); }

.status { color: var(--text-dim); font-size: 15px; margin: 2px 0 0; min-height: 1.4em; }
.status.error { color: var(--danger); }

.foot {
  flex: 0 0 auto;
  padding: 10px 20px calc(14px + env(safe-area-inset-bottom));
  font-size: 12px;
  color: var(--text-dim);
  text-align: center;
}
.foot p { margin: 2px 0; }
.copy { opacity: .85; }

/* ---------- Kartval ---------- */

.map-hint {
  position: absolute;
  top: calc(14px + env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  padding: 12px 20px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  box-shadow: var(--shadow);
  font-size: 15px;
  font-weight: 600;
  text-align: center;
  /* Rent upplysande — den ska aldrig äta ett tryck på kartan under sig. */
  pointer-events: none;
  max-width: calc(100% - 32px);
}

.map-bottom {
  position: absolute;
  left: 16px; right: 16px;
  bottom: calc(16px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 10px;
}

.map-actions {
  display: grid;
  grid-template-columns: 1fr 1.4fr;
  gap: 12px;
}

/* ---------- Navigerings-HUD ---------- */

.hud-top {
  position: absolute;
  top: calc(12px + env(safe-area-inset-top));
  left: 12px; right: 12px;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px 20px;
  background: var(--surface);
  border-radius: 20px;
  box-shadow: var(--shadow);
}

.man-icon { width: 56px; height: 56px; flex: 0 0 auto; color: var(--accent); }
.man-icon svg { width: 100%; height: 100%; }

.man-text { min-width: 0; display: flex; flex-direction: column; }
.man-dist { font-size: clamp(28px, 8vw, 38px); font-weight: 750; line-height: 1.05; letter-spacing: -.02em; }
.man-desc { font-size: clamp(15px, 4vw, 18px); color: var(--text-dim); overflow: hidden; text-overflow: ellipsis; }

.hud-bottom {
  position: absolute;
  left: 12px; right: 12px;
  bottom: calc(12px + env(safe-area-inset-bottom));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 12px 12px 22px;
  background: var(--surface);
  border-radius: 20px;
  box-shadow: var(--shadow);
}
.trip { display: flex; flex-direction: column; }
.trip strong { font-size: 24px; font-weight: 700; line-height: 1.1; }
.trip span { font-size: 15px; color: var(--text-dim); }

.toast {
  position: absolute;
  top: calc(108px + env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  padding: 12px 20px;
  background: var(--danger);
  color: #fff;
  border-radius: 999px;
  font-size: 15px;
  font-weight: 600;
  box-shadow: var(--shadow);
  white-space: nowrap;
}

/* ---------- Laddning ---------- */

.busy {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 18px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(3px);
}
.busy p { margin: 0; font-size: 17px; font-weight: 600; }

.spinner {
  width: 46px; height: 46px;
  border: 4px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 900ms linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  .spinner { animation-duration: 2.4s; }
  .btn { transition: none; }
}

/* ---------- Landskapsläge på telefon ---------- */

@media (orientation: landscape) and (max-height: 520px) {
  .hud-top { right: auto; max-width: 58%; padding: 12px 16px; }
  .man-icon { width: 44px; height: 44px; }
  .hud-bottom { left: auto; right: 12px; width: min(340px, 42%); }
  .lede { font-size: 24px; }
}

.foot a { color: var(--text-dim); }

.head-src { font-size: 11px; color: var(--text-dim); opacity: .7; letter-spacing: .04em; }
.trip-sub { display: flex; gap: 10px; align-items: baseline; }
/* Förfluten tid: ska finnas där när man tittar efter den, inte pocka på. */
.trip-clock { font-size: 11px; color: var(--text-dim); opacity: .55; font-variant-numeric: tabular-nums; letter-spacing: .04em; }
.trip-clock:empty { display: none; }

/* ---------- Framme ---------- */

.fx { pointer-events: none; z-index: 5; }

.arrive {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  z-index: 6;
  pointer-events: none;
}
.arrive-card {
  pointer-events: auto;
  width: min(360px, 100%);
  padding: 26px 22px 22px;
  text-align: center;
  background: var(--surface);
  border-radius: 24px;
  box-shadow: 0 18px 50px rgba(0,0,0,.35);
  animation: arrive-in .5s cubic-bezier(.2,.9,.3,1.2) both;
}
@keyframes arrive-in { from { transform: translateY(30px) scale(.9); opacity: 0; } to { transform: none; opacity: 1; } }
.arrive-mark {
  width: 64px; height: 64px; margin: 0 auto 10px;
  display: grid; place-items: center;
  color: var(--accent-ink);
  background: var(--accent);
  border-radius: 50%;
  animation: arrive-pop .6s .15s cubic-bezier(.2,.9,.3,1.4) both;
}
.arrive-mark svg { width: 36px; height: 36px; }
@keyframes arrive-pop { from { transform: scale(0); } to { transform: scale(1); } }
.arrive-card h2 { margin: 0; font-size: 30px; letter-spacing: -.01em; }
.arrive-name { margin: 4px 0 18px; color: var(--text-dim); font-size: 15px; }
.arrive-stats { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; margin-bottom: 20px; }
.arrive-stats div { padding: 10px 4px; background: var(--surface-2); border-radius: 14px; }
.arrive-stats strong { display: block; font-size: 17px; font-variant-numeric: tabular-nums; }
.arrive-stats span { font-size: 11px; color: var(--text-dim); text-transform: uppercase; letter-spacing: .06em; }
.arrive-card .btn { width: 100%; }


/* ---------- Panel för att vrida vyn ---------- */

.viewpanel {
  position: absolute;
  left: 12px; right: 12px;
  bottom: calc(96px + env(safe-area-inset-bottom));
  padding: 14px 16px 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: var(--shadow);
  max-height: 62vh;
  overflow-y: auto;
}

.vp-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin: 12px 0 8px;
  font-size: 12px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text-dim);
}
.vp-head:first-child { margin-top: 0; }
.vp-head strong { font-size: 20px; color: var(--text); letter-spacing: 0; text-transform: none; }

.vp-btns { display: flex; flex-wrap: wrap; gap: 8px; }

.vp-btns button {
  flex: 1 1 auto;
  min-width: 74px;
  min-height: 48px;
  padding: 0 12px;
  font: inherit;
  font-size: 15px;
  font-weight: 650;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  cursor: pointer;
}
.vp-btns button:active { transform: scale(.96); }
.vp-btns button.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

.vp-readout {
  margin: 0;
  padding: 10px 12px;
  background: var(--surface-2);
  border-radius: 12px;
  font: 12.5px/1.6 ui-monospace, SFMono-Regular, Menlo, monospace;
  color: var(--text);
  white-space: pre-wrap;
}

.busy #btn-cancel { min-width: 200px; margin-top: 4px; }

.map-attr {
  align-self: flex-end;
  padding: 4px 9px;
  background: color-mix(in srgb, var(--surface) 82%, transparent);
  border-radius: 8px;
  font-size: 11px;
  color: var(--text-dim);
  pointer-events: none;
  max-width: 70%;
}

/* ---------- Simuleringens fartväljare (i navigeringsvyn) ---------- */

.sim-speed {
  position: absolute;
  left: 12px;
  top: calc(112px + env(safe-area-inset-top));
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px 6px 14px;
  background: var(--surface);
  border-radius: 999px;
  box-shadow: var(--shadow);
}

.sim-speed-label {
  font-size: 12px;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-right: 4px;
}

.sim-speed button {
  min-width: 46px;
  min-height: 40px;
  padding: 0 10px;
  font: inherit;
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
}
.sim-speed button:active { transform: scale(.94); }
.sim-speed button.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

/* Fyra farter får inte tvinga fram radbrytning på smala skärmar. */
.sim-speed { max-width: calc(100% - 24px); }
.sim-speed button { min-width: 40px; padding: 0 8px; }
@media (max-width: 380px) {
  .sim-speed-label { display: none; }
}

.dest-prep { font-size: 13px; color: var(--accent); font-weight: 600; margin-top: 2px; }

/* ---------- Platskod ---------- */

.code-tag {
  font-size: 10px;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--text-dim);
}
.dest-code { display: flex; align-items: center; gap: 8px; margin-top: 6px; flex-wrap: wrap; }
.dest-code strong {
  font: 700 15px/1.3 ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: .06em;
  white-space: nowrap;
}
.code-copy {
  padding: 4px 10px;
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  background: none;
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
}
.code-copy:active { transform: scale(.94); }

.map-code {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px 14px;
  background: var(--surface);
  border-radius: 18px;
  box-shadow: var(--shadow);
}
.map-code-main { display: flex; align-items: center; gap: 10px; min-width: 0; }
.map-code-main strong {
  flex: 1 1 auto;
  font: 700 19px/1.1 ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: .08em;
  white-space: nowrap;
  overflow-x: auto;
}

/* Kopieringsknappen sitter på samma rad som koden och tar bara sin ikon. */
.code-icon {
  flex: none;
  width: 44px; height: 44px;
  margin: -8px -6px -8px 0;
  display: grid; place-items: center;
  color: var(--accent);
  background: none;
  border: none;
  border-radius: 12px;
  cursor: pointer;
}
.code-icon svg { width: 22px; height: 22px; }
.code-icon:active { background: var(--surface-2); transform: scale(.92); }
.code-icon.klar { color: var(--accent); }
.code-icon.klar svg { animation: kopierad .5s ease-out; }
@keyframes kopierad { 0% { transform: scale(1); } 45% { transform: scale(1.35); } 100% { transform: scale(1); } }

.floor-hint { font-size: 12px; color: var(--text-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.floor-hint:empty { display: none; }

/* Våningsfrågan dyker upp först när man tryckt inuti ett hus. */
.floor-ask {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 8px 8px 12px;
  background: color-mix(in srgb, var(--accent) 10%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--accent) 35%, var(--surface));
  border-radius: 14px;
  animation: floor-in .25s ease-out both;
}
@keyframes floor-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.floor-ask-text { display: flex; flex-direction: column; min-width: 0; }
.floor-ask-text strong { font-size: 14px; }
.floor-ask-sub { font-size: 12px; color: var(--text-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.floor-pick {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 3px;
  background: var(--surface-2);
  border-radius: 999px;
}
.floor-pick button {
  width: 34px; height: 36px;
  font: 700 19px/1 inherit;
  color: var(--text);
  background: none;
  border: none;
  border-radius: 999px;
  cursor: pointer;
}
.floor-pick button:active { background: var(--line); }
.floor-value {
  min-width: 62px;
  text-align: center;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
}
.floor-chip {
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 700;
  color: var(--accent-ink);
  background: var(--accent);
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.arrive-floor {
  margin: -12px 0 16px;
  font-size: 17px;
  font-weight: 700;
  color: var(--accent);
}
@media (max-width: 340px) { .map-code-main strong { font-size: 17px; } }


/* Grafikvalet: en vanlig kryssruta, men stor nog för en tumme. */
.opt {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 14px;
  background: var(--surface);
  border: 2px solid var(--line);
  border-radius: var(--r);
  cursor: pointer;
}
.opt input { position: absolute; opacity: 0; width: 0; height: 0; }
.opt-box {
  flex: none;
  width: 26px; height: 26px;
  display: grid; place-items: center;
  color: transparent;
  background: var(--surface-2);
  border: 2px solid var(--line);
  border-radius: 8px;
}
.opt-box svg { width: 18px; height: 18px; }
.opt input:checked + .opt-box { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.opt input:focus-visible + .opt-box { outline: 3px solid var(--accent); outline-offset: 2px; }
.opt:has(input:checked) { border-color: var(--accent); }
.opt-text strong { display: block; font-size: 15px; line-height: 1.2; }
.opt-text small { display: block; font-size: 12px; color: var(--text-dim); margin-top: 3px; }

/* Färdsätt: två stora knappar, en är alltid vald. */
.mode {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.mode-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 62px;
  padding: 10px 12px;
  font: inherit;
  text-align: left;
  color: var(--text);
  background: var(--surface);
  border: 2px solid var(--line);
  border-radius: var(--r);
  cursor: pointer;
}
.mode-btn svg { width: 26px; height: 26px; flex: none; fill: currentColor; color: var(--text-dim); }
.mode-btn strong { display: block; font-size: 15px; line-height: 1.2; }
.mode-btn small { display: block; font-size: 12px; color: var(--text-dim); margin-top: 2px; }
.mode-btn:active { transform: scale(.97); }
.mode-btn.on { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, var(--surface)); }
.mode-btn.on svg { color: var(--accent); }
@media (max-width: 360px) { .mode-btn small { display: none; } }

