/* Traily: grå-blå skiffertoning (samma familj som konsultsidan), himmelsblå accent, fet smal versal rubrikstil. En medvetet mörk look. */
@font-face {
  font-family: "Saira Condensed";
  src: url("fonts/saira-condensed-600.woff2") format("woff2");
  font-weight: 600;
  font-display: swap;
}
@font-face {
  font-family: "Saira Condensed";
  src: url("fonts/saira-condensed-800.woff2") format("woff2");
  font-weight: 800;
  font-display: swap;
}

:root {
  --slate-950: #141d2a;
  --slate-800: #26354b;
  --slate-700: #2b3b54;
  --slate-600: #3c516f;
  --slate-500: #7488a4;
  --accent: #8cc8ff;
  --accent-press: #6db3f2;
  --on-accent: #142033;
  --fun: linear-gradient(110deg, #7cf0c5 0%, #6cc6ff 45%, #a6a2ff 75%, #7cf0c5 100%);
  --fun-glow: 0 10px 28px rgb(108 198 255 / 0.35);
  --bad: #ff8c96;
  --white: #ffffff;
  --soft: rgb(255 255 255 / 0.74);
  --dim: rgb(255 255 255 / 0.55);
  --glass: rgb(255 255 255 / 0.07);
  --glass-strong: rgb(255 255 255 / 0.12);
  --line: rgb(255 255 255 / 0.16);
  --good: #5fd3a0;
  --warn: #ffc94a;
  --display: "Saira Condensed", "Arial Narrow", "Helvetica Neue", sans-serif;
  --body: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { background: var(--slate-950); -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  color: var(--white);
  font: 16px/1.5 var(--body);
  background: linear-gradient(165deg, var(--slate-600) 0%, var(--slate-700) 38%, #1f2c3f 70%, var(--slate-950) 100%);
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
/* Diagonala ljusytor, som de genomskinliga trianglarna i förlagan */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(115deg, transparent 0 55%, rgb(255 255 255 / 0.06) 55% 75%, transparent 75%),
    linear-gradient(200deg, rgb(116 136 164 / 0.45) 0 30%, transparent 30%);
  z-index: 0;
}
button, input, label { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }

.screen {
  position: relative;
  z-index: 1;
  max-width: 560px;
  margin: 0 auto;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-block: 12px 40px;
  display: grid;
  gap: 18px;
}

h1, h2, h3, .eyebrow, .label, .stat-label, .unit {
  font-family: var(--display);
  text-transform: uppercase;
}
h1, h2, h3 { margin: 0; line-height: 1; text-wrap: balance; }
h1 { font-size: clamp(2.8rem, 15vw, 4.2rem); font-weight: 800; letter-spacing: 0.005em; }
h2 { font-size: 1.35rem; font-weight: 800; letter-spacing: 0.02em; }
h3 { font-size: 1.1rem; font-weight: 800; letter-spacing: 0.03em; }
p { margin: 0; }
.accent-text { color: var(--accent); }
.muted { color: var(--soft); font-size: 0.92rem; }
.small-text { font-size: 0.82rem; color: var(--dim); }
.hint { color: var(--soft); font-size: 0.9rem; }
.hint:empty { display: none; }
.eyebrow { color: var(--soft); font-weight: 600; letter-spacing: 0.18em; font-size: 0.95rem; }

/* Sidhuvud */
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.logo { display: flex; align-items: center; gap: 10px; }
.logo-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--fun);
  background-size: 200% 100%;
  box-shadow: 0 6px 18px rgb(108 198 255 / 0.3), inset 0 1px 0 rgb(255 255 255 / 0.45);
  flex: none;
}
.logo-mark svg { width: 70%; height: 70%; overflow: visible; }
.logo-mark path { fill: none; stroke: var(--on-accent); stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.logo-mark circle { fill: var(--on-accent); }
.logo-mark.small { width: 32px; height: 32px; }
.logo-word {
  font: 800 1.6rem/1 var(--body);
  letter-spacing: -0.045em;
  text-transform: lowercase;
}
.sync-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  padding: 0 12px;
  background: var(--glass);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 0.82rem;
  color: var(--soft);
  max-width: 60%;
}
.sync-chip span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sync-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--dim); flex: none; }
.sync-chip[data-state="ok"] .sync-dot { background: var(--good); }
.sync-chip[data-state="busy"] .sync-dot { background: var(--warn); }
.sync-chip[data-state="offline"] .sync-dot,
.sync-chip[data-state="err"] .sync-dot { background: var(--bad); }

/* Hjälteyta */
.hero { display: grid; gap: 14px; padding-top: 18px; }
.start-btn {
  width: 100%;
  min-height: 76px;
  border: 0;
  border-radius: 18px;
  background: var(--fun);
  background-size: 200% 100%;
  color: var(--on-accent);
  font: 800 1.7rem/1 var(--display);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  box-shadow: var(--fun-glow), inset 0 1px 0 rgb(255 255 255 / 0.5);
  transition: background-position 0.6s ease, transform 0.12s ease;
}

/* Nyckeltal */
.stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.stat {
  background: var(--glass);
  border: 1px solid var(--line);
  border-top: 3px solid var(--accent);
  padding: 12px 14px;
  display: grid;
  gap: 2px;
  min-width: 0;
}
.stat-label { color: var(--soft); font-weight: 600; font-size: 0.85rem; letter-spacing: 0.1em; }
.stat-value { font: 800 1.9rem/1.05 var(--display); font-variant-numeric: tabular-nums; }
.stat-sub { color: var(--dim); font-size: 0.8rem; }

.panel {
  background: var(--glass);
  border: 1px solid var(--line);
  padding: 16px;
  display: grid;
  gap: 12px;
}

/* Knappar */
.btn-outline, .btn-solid {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 46px;
  padding: 0 18px;
  font: 800 1.05rem/1 var(--display);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}
.btn-outline { background: transparent; border: 2px solid var(--accent); border-radius: 12px; }
.btn-outline:active { background: rgb(140 200 255 / 0.14); }
.btn-outline.small { min-height: 38px; padding: 0 12px; font-size: 0.92rem; border-radius: 10px; }
.btn-outline.danger { border-color: var(--bad); color: var(--bad); }
.btn-solid {
  border: 0;
  border-radius: 14px;
  background: var(--fun);
  background-size: 200% 100%;
  color: var(--on-accent);
  box-shadow: var(--fun-glow), inset 0 1px 0 rgb(255 255 255 / 0.5);
  transition: background-position 0.6s ease, transform 0.12s ease;
}
.btn-solid:disabled { opacity: 0.6; cursor: wait; }

/* Toningen glider vid hovring och tryck, knappen trycks ner lite */
@media (hover: hover) {
  .start-btn:hover, .btn-solid:hover { background-position: 100% 0; }
}
.start-btn:active, .btn-solid:active { background-position: 100% 0; transform: scale(0.98); }
@media (prefers-reduced-motion: reduce) {
  .start-btn, .btn-solid { transition: none; }
  .start-btn:active, .btn-solid:active { transform: none; }
}

/* Inloggning */
.auth { min-height: 100dvh; align-content: start; padding-top: 28px; gap: 24px; }
.auth-head { display: grid; gap: 8px; padding-top: 12px; }
.auth-form, .auth-invite { display: grid; gap: 8px; }
.auth-form .btn-solid { margin-top: 12px; min-height: 56px; font-size: 1.3rem; }
.link-btn {
  justify-self: start;
  background: none;
  border: 0;
  padding: 8px 0;
  color: var(--white);
  text-decoration: underline;
  text-decoration-color: var(--accent);
  text-decoration-thickness: 2px;
  text-underline-offset: 4px;
}

.account {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
  color: var(--soft);
  font-size: 0.9rem;
  min-width: 0;
}
.account span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account strong { color: var(--white); }

/* Passlista */
.section-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 10px; }
.run-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.run-item {
  width: 100%;
  text-align: left;
  background: var(--glass);
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  padding: 12px 14px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2px 12px;
}
.run-item:active { background: var(--glass-strong); }
.run-date { color: var(--soft); font-size: 0.85rem; }
.run-km { grid-row: span 2; align-self: center; font: 800 1.7rem/1 var(--display); font-variant-numeric: tabular-nums; }
.run-meta { font-variant-numeric: tabular-nums; }
.run-note { grid-column: 1 / -1; color: var(--dim); font-size: 0.85rem; overflow-wrap: anywhere; }
.run-pending { color: var(--warn); font-size: 0.8rem; }
.empty { color: var(--soft); padding: 4px 0; }

/* Inspelning */
.rec { min-height: 100dvh; align-content: start; padding-top: 14px; }
.rec-top { display: flex; align-items: center; gap: 12px; }
.rec-status { display: flex; align-items: center; gap: 8px; font-size: 0.9rem; color: var(--soft); }
.dot { width: 12px; height: 12px; border-radius: 50%; background: var(--dim); flex: none; }
.dot.good { background: var(--good); }
.dot.ok { background: var(--warn); }
.dot.bad { background: var(--bad); }
.rec-metrics { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.metric { background: var(--glass); border: 1px solid var(--line); padding: 12px 14px; display: grid; min-width: 0; }
.metric .num { font: 800 2.4rem/1 var(--display); font-variant-numeric: tabular-nums; }
.hero-metric { border-top: 3px solid var(--accent); }
.hero-metric .num { font-size: clamp(3.2rem, 17vw, 4.6rem); }
.metric .unit { color: var(--soft); font-weight: 600; font-size: 0.85rem; letter-spacing: 0.1em; margin-top: 4px; }
.rec.paused .hero-metric .num { color: var(--dim); }
.rec-controls { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.btn-lg { min-height: 68px; border: 0; font: 800 1.45rem/1 var(--display); text-transform: uppercase; letter-spacing: 0.08em; }
.btn-lg.ghost { background: transparent; border: 2px solid var(--white); }
.btn-lg.accent { background: var(--accent); color: var(--on-accent); }
.btn-lg.accent:active { background: var(--accent-press); }

.route { width: 100%; max-width: 100%; aspect-ratio: 1; background: rgb(0 0 0 / 0.18); border: 1px solid var(--line); }
.route-line { fill: none; stroke: var(--accent); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.route-start { fill: var(--white); }
.route-end { fill: var(--on-accent); stroke: var(--accent); stroke-width: 1.2; }
.route-empty { fill: var(--dim); font-size: 5px; }

/* Detalj */
.back-btn { background: none; border: 0; color: var(--white); font: 800 1.15rem/1 var(--display); text-transform: uppercase; letter-spacing: 0.08em; padding: 10px 0; }
.detail-title { font-size: 2rem; }
.splits { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.split { display: grid; grid-template-columns: 2em 1fr 3.4em; align-items: center; gap: 10px; font-variant-numeric: tabular-nums; }
.split-km { color: var(--dim); font: 600 1rem var(--display); }
.split-bar { height: 10px; background: rgb(255 255 255 / 0.1); overflow: hidden; }
.split-fill { display: block; height: 100%; background: rgb(255 255 255 / 0.45); }
.split.best .split-fill { background: var(--accent); }
.split-pace { text-align: right; font: 800 1.15rem var(--display); }
.note { color: var(--soft); overflow-wrap: anywhere; }
.note:empty { display: none; }

/* Formulär och dialoger */
.label { color: var(--soft); font-weight: 600; font-size: 0.9rem; letter-spacing: 0.1em; }
input {
  width: 100%;
  min-height: 46px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgb(0 0 0 / 0.25);
  color: var(--white);
}
input::placeholder { color: var(--dim); }
dialog {
  width: min(92vw, 440px);
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--slate-800);
  color: var(--white);
  padding: 20px;
}
dialog[open], dialog form { display: grid; gap: 8px; }
dialog::backdrop { background: rgb(10 16 26 / 0.72); }
dialog h2 { margin-bottom: 6px; font-size: 1.7rem; }
.summary { font: 800 1.8rem/1.1 var(--display); font-variant-numeric: tabular-nums; }
.dlg-actions { display: grid; gap: 8px; margin-top: 12px; }
.error { color: var(--bad); font-size: 0.9rem; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  max-width: calc(100vw - 32px);
  background: var(--white);
  color: var(--slate-950);
  border-left: 4px solid var(--accent);
  padding: 10px 16px;
  font-size: 0.95rem;
  font-weight: 600;
  z-index: 20;
}

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* Passanalys: etapper, färgad rutt och höjdprofil */
:root {
  --seg-stark: #7cf0c5;
  --seg-jamn: #6cc6ff;
  --seg-lugn: #a6a2ff;
}
.panel-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.panel-head .small-text { text-align: right; }

.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 0.82rem; color: var(--soft); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.swatch { width: 14px; height: 4px; border-radius: 2px; display: inline-block; }
.swatch.stark { background: var(--seg-stark); }
.swatch.jamn { background: var(--seg-jamn); }
.swatch.lugn { background: var(--seg-lugn); }
.swatch.km { width: 10px; height: 10px; border-radius: 50%; background: var(--slate-950); border: 1.5px solid var(--white); }

.elev { width: 100%; height: auto; display: block; }
.elev-area { fill: rgb(108 198 255 / 0.18); }
.elev-line { fill: none; stroke: var(--seg-jamn); stroke-width: 1.6; stroke-linejoin: round; }
.elev-axis { stroke: var(--line); stroke-width: 1; }
.elev-sel { fill: rgb(255 255 255 / 0.12); }
.elev-label { fill: var(--dim); font: 600 10px var(--body); }

.segs { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.seg {
  width: 100%;
  text-align: left;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2px 12px;
  align-items: center;
  padding: 10px 12px 10px 14px;
  background: rgb(0 0 0 / 0.16);
  border: 1px solid var(--line);
  border-left: 4px solid var(--seg-jamn);
  border-radius: 12px;
  font-variant-numeric: tabular-nums;
}
.seg.stark { border-left-color: var(--seg-stark); }
.seg.lugn { border-left-color: var(--seg-lugn); }
.seg.selected { background: rgb(255 255 255 / 0.1); border-color: var(--white); border-left-width: 4px; }
.seg-range { color: var(--soft); font-size: 0.85rem; }
.seg-pace { grid-column: 1; font: 800 1.45rem/1.1 var(--display); }
.seg-badge {
  grid-column: 2;
  grid-row: 1 / span 2;
  justify-self: end;
  padding: 4px 10px;
  border-radius: 999px;
  font: 800 0.85rem/1 var(--display);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--on-accent);
  background: var(--seg-jamn);
}
.seg-badge.stark { background: var(--seg-stark); }
.seg-badge.lugn { background: var(--seg-lugn); }
.seg-gap, .seg-climb { grid-column: 1 / -1; color: var(--dim); font-size: 0.82rem; }

/* Veckorad: en prick per dag */
.week {
  background: var(--glass);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px 14px 10px;
  display: grid;
  gap: 10px;
}
.week-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.week-head h2 { font-size: 1.1rem; }
.week-total { color: var(--soft); font-size: 0.9rem; font-variant-numeric: tabular-nums; }
.week-days { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; text-align: center; }
.day { display: grid; justify-items: center; gap: 4px; }
.day-letter { font: 600 0.8rem/1 var(--display); color: var(--dim); }
.day-dot { width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--line); }
.day.ran .day-dot { border: 0; background: var(--fun); box-shadow: 0 4px 12px rgb(108 198 255 / 0.3); }
.day.today .day-dot { border-color: var(--accent); }
.day.today .day-letter { color: var(--white); }
.day.future .day-dot { border-style: dashed; opacity: 0.5; }
.day-km { min-height: 1em; font: 800 0.8rem/1 var(--display); font-variant-numeric: tabular-nums; }

/* Vanliga rutter: kort som scrollas i sidled */
.route-list {
  list-style: none;
  margin: 0;
  padding: 2px 0 6px;
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(150px, 46%);
  gap: 10px;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  scrollbar-width: none;
}
.route-list::-webkit-scrollbar { display: none; }
.route-list li { scroll-snap-align: start; min-width: 0; }
.route-card {
  width: 100%;
  height: 100%;
  text-align: left;
  display: grid;
  align-content: start;
  gap: 2px;
  padding: 10px;
  background: var(--glass);
  border: 1px solid var(--line);
  border-radius: 16px;
}
.route-card.selected { border-color: var(--accent); background: rgb(140 200 255 / 0.12); }
.route-thumb { width: 100%; aspect-ratio: 1.4; max-width: 100%; background: rgb(0 0 0 / 0.18); border-radius: 10px; margin-bottom: 6px; }
.route-thumb .route-line { stroke-width: 3; }
.route-thumb .route-start, .route-thumb .route-end { r: 4; }
.route-name { font: 800 1.15rem/1.1 var(--display); text-transform: uppercase; letter-spacing: 0.02em; }
.route-count { color: var(--soft); font-size: 0.82rem; }
.route-best { font-weight: 700; font-size: 0.9rem; font-variant-numeric: tabular-nums; margin-top: 4px; }
.route-last { color: var(--dim); font-size: 0.8rem; font-variant-numeric: tabular-nums; }

.filter-chip {
  min-height: 34px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid var(--accent);
  background: rgb(140 200 255 / 0.14);
  font-size: 0.85rem;
  font-weight: 600;
  max-width: 60%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Karta i efterhand: OpenStreetMap, mörkt tonad så den smälter in i appen */
.map {
  height: 340px;
  max-height: 55vh;
  border-radius: 14px;
  overflow: hidden;
  background: #1b2635;
  border: 1px solid var(--line);
}
.map.leaflet-container { font: 600 12px/1.4 var(--body); background: #1b2635; }
.map .leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) brightness(0.92) contrast(0.88) saturate(0.55); }
.map .leaflet-control-attribution { background: rgb(20 29 42 / 0.75); color: var(--soft); font-size: 10px; }
.map .leaflet-control-attribution a { color: var(--accent); }
.map .leaflet-bar { border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.map .leaflet-bar a { background: var(--slate-800); color: var(--white); border-bottom-color: var(--line); }
.map .leaflet-bar a:hover { background: var(--slate-700); }
.km-marker {
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--slate-950);
  border: 2px solid var(--white);
  color: var(--white);
  font: 800 10px/1 var(--body);
  box-shadow: 0 2px 6px rgb(0 0 0 / 0.4);
}

/* Typ av pass: asfalt, trail, gång */
:root { --kind-road: #6cc6ff; --kind-trail: #7cf0c5; --kind-walk: #ffc94a; }
.kind-pill {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  margin-right: 8px;
  border-radius: 999px;
  font: 800 0.72rem/1 var(--display);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--on-accent);
  background: var(--soft);
  vertical-align: 1px;
}
.kind-pill:empty { display: none; }
.kind-pill.road { background: var(--kind-road); }
.kind-pill.trail { background: var(--kind-trail); }
.kind-pill.walk { background: var(--kind-walk); }
.rec-top .kind-pill { margin: 0 0 0 auto; }
.detail-head { display: grid; gap: 8px; justify-items: start; }

.kind-filter { display: flex; gap: 6px; flex-wrap: wrap; }
.kind-filter button {
  min-height: 36px;
  padding: 0 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--glass);
  color: var(--soft);
  font: 800 0.9rem/1 var(--display);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.kind-filter button[aria-pressed="true"] { background: var(--white); border-color: var(--white); color: var(--on-accent); }

/* Startdialog: stora val */
.choice-step { display: grid; gap: 14px; }
.choices { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.choice {
  display: grid;
  justify-items: center;
  gap: 8px;
  padding: 22px 10px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: rgb(0 0 0 / 0.18);
}
.choice:active, .choice:hover { border-color: var(--accent); background: rgb(140 200 255 / 0.12); }
.choice-icon { font-size: 2.4rem; line-height: 1; }
.choice-name { font: 800 1.35rem/1 var(--display); text-transform: uppercase; letter-spacing: 0.06em; }
#startDlg .link-btn { justify-self: center; margin-top: 6px; }

/* Hjälptext under fält när man skapar konto */
.field-hint { margin: -2px 0 4px; font-size: 0.82rem; color: var(--dim); }
.field-hint.ok { color: var(--good); }
