/* ==========================================================================
   mina.css — My rides (replaces the former inline <style> in mina.html),
   loaded after theme.css. Every selector targets an existing ID/class/data-* hook, or a class
   that mina.js's templates add (marked NEW, see design.md §5).
   ========================================================================== */

* { margin: 0; padding: 0; box-sizing: border-box; }
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
body {
    background: var(--bg); color: var(--text);
    font-family: system-ui, -apple-system, sans-serif; font-size: var(--fs-md); line-height: 1.5;
    min-height: 100dvh;
}
a { color: var(--orange-text); text-underline-offset: 3px; }
a:hover { text-decoration-thickness: 2px; }
button { font: inherit; color: inherit; cursor: pointer; }
[hidden] { display: none !important; }

/* ── Layout column: centred, 16px gutter on phones, 24px from 600px (AC-27) ── */
.wrap, main, #signin {
    width: 100%; max-width: 960px; margin-inline: auto; padding-inline: var(--gutter);
}
@media (min-width: 600px) { :root { --gutter: 24px; } }

/* ── Topbar (NEW markup in mina.html: header.topbar) ─────────────────────── */
.topbar {
    position: sticky; top: 0; z-index: 20;
    background: var(--bar-bg); backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--bar-line);
}
.topbar .wrap { display: flex; align-items: center; gap: 12px; height: var(--bar-h); }
.topbar .beta-tag {
    font-size: 11px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase;
    color: var(--orange-text); border: 1px solid var(--orange); border-radius: 5px; padding: 2px 6px;
}
#signout { margin-left: auto; }

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn, .btn-primary {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    min-height: var(--tap); padding: 10px 18px;
    font-size: var(--fs-md); font-weight: 600; line-height: 1.25; text-align: center;
    text-decoration: none; white-space: normal;
    border-radius: var(--radius-ctl); border: 1px solid var(--line);
    background: var(--panel-2); color: var(--text);
    transition: background var(--dur), border-color var(--dur), color var(--dur);
}
.btn:hover { border-color: var(--orange); }
.btn-primary { background: var(--orange); border-color: var(--orange); color: var(--on-orange); }
.btn-primary:hover { background: var(--orange-hi); border-color: var(--orange-hi); }
.btn:disabled, .btn-primary:disabled { cursor: progress; opacity: 1; }
.btn-primary:disabled { background: var(--panel-2); border-color: var(--line); color: var(--muted); }
.btn:disabled { color: var(--muted); }
.btn-block { width: 100%; min-height: 52px; }
.btn-sm { padding: 8px 14px; font-size: 15px; }
/* Map buttons hold their width while the label changes (AC-47: ±4px). Q8 (beslut.md): the width is
   capped in every state, so a longer label (error/blocked) wraps onto two centred lines instead of
   widening the button. Below 600px the button is full-width (.row-actions rule), ride buttons fill
   their grid column at >= 600px, so only track/trail need the fixed inline-size. */
[data-show], [data-trail], [data-report] { min-width: 12.5em; max-width: 100%; white-space: normal; text-align: center; }
@media (min-width: 600px) { [data-show], [data-trail] { inline-size: 12.5em; } }
.btn.is-error { border-color: var(--red); color: var(--red); }
.btn.is-error::before { content: "!"; display: inline-grid; place-items: center; width: 18px; height: 18px;
    border-radius: 50%; background: var(--red); color: var(--panel); font-size: 12px; font-weight: 800; }

/* ── Type ───────────────────────────────────────────────────────────────── */
.eyebrow { font-size: var(--fs-xs); font-weight: 600; color: var(--eyebrow);
           text-transform: uppercase; letter-spacing: .1em; }
.page-title, #signin h1 {
    font-family: var(--display); font-style: italic; font-weight: 700;
    font-size: var(--fs-xl); line-height: 1.1; letter-spacing: -.3px; color: var(--text-strong);
}
.lede { color: var(--muted); font-size: 17px; margin-top: 8px; }

/* ── Sign-in ────────────────────────────────────────────────────────────── */
#signin { max-width: 468px; margin-block: 40px 64px; }
#signin .signin-card {
    background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-card);
    padding: 24px 20px; margin-top: 20px;
}
@media (min-width: 600px) { #signin .signin-card { padding: 28px; } }
.field { display: grid; gap: 6px; margin-bottom: 14px; }
.field label { font-size: var(--fs-sm); font-weight: 600; color: var(--text); }
#signin input {
    width: 100%; height: 52px; padding: 0 14px;
    background: var(--bg); color: var(--text); font: inherit; font-size: var(--fs-md);
    border: 1px solid var(--field-line); border-radius: var(--radius-ctl);
}
#signin input::placeholder { color: var(--muted); opacity: 1; }
#signin input:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-color: var(--focus); }
#code { font-family: var(--mono); font-size: 28px !important; letter-spacing: .3em; text-align: center; }
#signin:has(#signin-err:not([hidden])) input { border-color: var(--red); }
.note { font-size: var(--fs-sm); color: var(--muted); margin-top: 14px; }
#restart {
    display: inline-flex; align-items: center; min-height: var(--tap); padding-inline: 4px;
    font-weight: 600;
}
#signin-err {
    display: flex; gap: 10px; align-items: flex-start; margin-top: 14px;
    padding: 12px 14px; border-radius: var(--radius-ctl);
    background: var(--tint-red); border-left: 3px solid var(--red);
    color: var(--text); font-size: var(--fs-sm);
}
/* .state-error .state-icon is a real <span aria-hidden="true">!</span> in the template. */
#signin-err::before, .state-error .state-icon {
    content: "!"; flex: none; display: inline-grid; place-items: center;
    width: 20px; height: 20px; border-radius: 50%;
    background: var(--red); color: var(--panel); font-size: 13px; font-weight: 800; line-height: 1;
}
.signin-foot { margin-top: 18px; font-size: var(--fs-sm); color: var(--muted); }

/* ── Signed-in page head ────────────────────────────────────────────────── */
.page-head { padding-block: 24px 4px; }
.page-head .who-line {
    color: var(--muted); font-size: var(--fs-sm); margin-top: 6px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
#who { color: var(--text); }

/* ── Tabs (nav.tabs, data-view, aria-selected) ──────────────────────────── */
nav.tabs {
    position: sticky; top: var(--bar-h); z-index: 15;
    background: var(--bar-bg); backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--line);
}
nav.tabs .wrap { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; }
nav.tabs button {
    min-height: 48px; padding: 0 14px; background: none; border: 0;
    border-bottom: 2px solid transparent; margin-bottom: -1px;
    color: var(--muted); font-size: 15px; font-weight: 600; white-space: nowrap;
}
nav.tabs button:hover { color: var(--text); }
nav.tabs button[aria-selected="true"] { color: var(--text-strong); border-bottom-color: var(--accent-line); }
nav.tabs button:focus-visible { outline-offset: -4px; border-radius: 8px; }

main { padding-block: 20px 64px; }

/* ── Count line (NEW class .count; was .meta) ───────────────────────────── */
.count { color: var(--muted); font-size: var(--fs-sm); margin-bottom: 12px; }
.count b { color: var(--text); }

/* ── Cards ──────────────────────────────────────────────────────────────── */
.card {
    background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-card);
    padding: 16px; margin-bottom: 12px; scroll-margin-top: calc(var(--bar-h) + 60px);
}
@media (min-width: 600px) { .card { padding: 20px 22px; } }
.card h3 {
    font-family: var(--display); font-style: italic; font-weight: 500;
    font-size: var(--fs-lg); line-height: 1.25; color: var(--text-strong);
}
.pills { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.pill {
    display: inline-flex; align-items: center; gap: 6px; min-height: 24px;
    font-size: 13px; font-weight: 600; padding: 2px 10px; border-radius: var(--radius-pill);
    border: 1px solid var(--line); color: var(--muted); background: var(--panel-2);
}
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill.ok { color: var(--green-text); }
.pill.wait { color: var(--yellow-text); }
.pill.sensor::before { display: none; }
.meta {
    display: flex; flex-wrap: wrap; gap: 4px 16px; margin-top: 10px;
    font-size: var(--fs-sm); color: var(--muted); font-variant-numeric: tabular-nums;
}
.meta b { color: var(--text); font-weight: 600; }
.row-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
@media (max-width: 599px) { .row-actions > .btn { flex: 1 1 100%; } }

/* Coaching block: "AI coach" eyebrow + renderCoaching output (unchanged contract). */
.coach-wrap { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line); }
.coach-wrap .eyebrow { margin-bottom: 8px; }
.coach { font-size: 15px; line-height: 1.6; color: var(--text-soft); max-width: 68ch; }
.coach ul { padding-left: 0; list-style: none; }
.coach li { position: relative; padding-left: 18px; margin-bottom: 10px; }
.coach li::before { content: ""; position: absolute; left: 2px; top: .62em; width: 7px; height: 7px;
                    border-radius: 2px; background: var(--orange); transform: skewX(-20deg); }
.coach li:last-child, .coach p:last-child { margin-bottom: 0; }
.coach p { margin-bottom: 10px; }
.coach strong { color: var(--text-strong); font-weight: 650; }
.coach.absent { color: var(--muted); font-style: italic; }

/* Desktop: ride facts left, coaching right (the coaching is the payoff, S2). */
@media (min-width: 900px) {
    /* DOM order stays facts, coaching, button (mobile reading order); the grid moves the
       button under the facts on desktop. */
    .ride-card { display: grid; grid-template-columns: 280px 1fr; grid-template-rows: auto 1fr; gap: 0 28px; }
    .ride-card > .ride-facts { grid-column: 1; grid-row: 1; }
    .ride-card > .row-actions { grid-column: 1; grid-row: 2; align-self: end; }
    .ride-card > .coach-wrap { grid-column: 2; grid-row: 1 / span 2; margin-top: 0; padding-top: 0; border-top: 0;
                               padding-left: 28px; border-left: 1px solid var(--line); }
    .ride-card .row-actions > .btn { width: 100%; }
}

/* Jump-to-ride highlight (.flash, 1.6 s, set by mina.js). */
.card.flash { outline: 2px solid var(--orange); outline-offset: 2px;
              background: linear-gradient(var(--tint-orange), var(--tint-orange)), var(--panel);
              transition: outline-color 1.2s ease-out; }

/* ── States: loading / empty / error (NEW .state classes) ───────────────── */
.state {
    display: flex; gap: 12px; align-items: flex-start;
    background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-card);
    padding: 18px; color: var(--muted); font-size: 15px;
}
.state .state-title { color: var(--text); font-weight: 600; font-size: var(--fs-md); }
.state p + p, .state p + .btn, .state p + a.btn { margin-top: 6px; }
.state .btn { margin-top: 12px; }
.state-loading { min-height: 96px; align-items: center; }
.state-loading::before {
    content: ""; flex: none; width: 10px; height: 10px; border-radius: 50%; background: var(--orange);
    animation: pulse 1.2s ease-in-out infinite;
}
@keyframes pulse { 50% { opacity: .25; } }
.skeleton { display: grid; gap: 12px; }
.skeleton .bone { height: 120px; border-radius: var(--radius-card); background: var(--panel); border: 1px solid var(--line); }
.state-error { border-left: 3px solid var(--red); background: linear-gradient(var(--tint-red), var(--tint-red)), var(--panel); }
.state-error .state-title { color: var(--text); }
.state-error .state-detail { color: var(--muted); font-size: 13px; font-family: var(--mono); word-break: break-word; }
.state-empty .state-icon { flex: none; width: 36px; height: 36px; color: var(--orange-text); }

/* ── Track card extras ──────────────────────────────────────────────────── */
.card .sub { color: var(--muted); font-size: 13px; font-family: var(--mono); }
.lb { margin-top: 14px; }
.lb:empty { display: none; }
.lb .lb-head { font-size: var(--fs-xs); font-weight: 600; color: var(--muted); text-transform: uppercase;
               letter-spacing: .08em; margin-bottom: 6px; }
.lb .state { padding: 12px 14px; font-size: var(--fs-sm); }
.lb .state-loading { min-height: 48px; }
.ride-on-track {
    display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; align-items: center;
    padding: 10px 12px; min-height: 56px; border-top: 1px solid var(--line);
    font-size: var(--fs-sm); font-variant-numeric: tabular-nums;
}
.ride-on-track:first-of-type { border-top: 0; }
.ride-on-track > :nth-child(1) { color: var(--text); }
.ride-on-track > :nth-child(2) { color: var(--muted); grid-row: 2; }
.ride-on-track .best { color: var(--blue); grid-row: 2; grid-column: 2; justify-self: end; font-weight: 600; }
.ride-on-track > :last-child { grid-row: 1; grid-column: 2; justify-self: end; color: var(--muted); }
.ride-on-track:has(.mine) {
    background: var(--tint-orange); border-left: 3px solid var(--orange); border-radius: 8px;
}
.ride-on-track .mine { color: var(--text); font-weight: 600; }
.ride-on-track a[data-open] {
    display: inline-flex; align-items: center; min-height: var(--tap); padding-inline: 8px;
    margin-block: -8px; color: var(--orange-text); font-weight: 600;
}
@media (min-width: 720px) {
    .ride-on-track { grid-template-columns: 1.6fr 0.8fr 1fr 1.2fr; min-height: 48px; }
    .ride-on-track > * { grid-row: 1 !important; grid-column: auto !important; justify-self: start !important; }
    .ride-on-track > :last-child { justify-self: end !important; }
}

/* ── Maps inside mina ───────────────────────────────────────────────────── */
#map, #track-map {
    height: min(60vh, 520px); margin-top: 12px;
    border: 1px solid var(--line); border-radius: var(--radius-card); overflow: hidden;
    scroll-margin-top: calc(var(--bar-h) + 60px);
}
.leaflet-container { font: 13px/1.4 system-ui, sans-serif; background: var(--panel-2); }
.leaflet-tooltip { background: var(--panel); color: var(--text); border: 1px solid var(--line);
                   border-radius: 8px; box-shadow: var(--shadow); }
.leaflet-bar a { background: var(--panel); color: var(--text); border-color: var(--line); }

/* ── Footer link back to the app download ───────────────────────────────── */
.page-foot { margin-top: 32px; color: var(--muted); font-size: var(--fs-sm); }

@media (prefers-reduced-motion: reduce) {
    .card.flash { transition: none; }
    .state-loading::before { animation: none; }
}
