/* ============================================================
   Tour-mode — Maps-inspired guided collage UI
   Top "next stop" banner + collapsible bottom sheet.
   Light by default; dark under html[data-bop-theme="dark"].
   ============================================================ */

:root {
    --tour-surface: #ffffff;
    --tour-surface-2: #f1f5f9;
    --tour-text: #11181f;
    --tour-text-dim: #64748b;
    --tour-line: rgba(17, 24, 31, 0.08);
    --tour-shadow: 0 8px 30px rgba(0, 0, 0, 0.18);
    --tour-green: #16a34a;
    --tour-green-hover: #15803d;
    --tour-amber: #d97706;
    --tour-amber-hover: #b45309;
    --tour-red: #b91c1c;
    --tour-red-hover: #991b1b;
    --tour-accent: #ff6b35;
}
html[data-bop-theme="dark"] {
    --tour-surface: #11181f;
    --tour-surface-2: #1f2937;
    --tour-text: #ffffff;
    --tour-text-dim: #93a3b5;
    --tour-line: rgba(255, 255, 255, 0.08);
    --tour-shadow: 0 8px 30px rgba(0, 0, 0, 0.45);
}

/* ---- Dim non-tour panneau pins while a tour is active -------- */
body.is-tour-active .mapboxgl-marker {
    opacity: 0.18;
    pointer-events: none;
    transition: opacity 220ms ease;
}
body.is-tour-active .mapboxgl-marker:has(.cc-tour-marker) {
    opacity: 1;
    pointer-events: auto;
}

/* During a tour the app's mobile bottom bar collides with the card. */
body.is-tour-active #bop-mobile-bar {
    display: none !important;
}

/* Maps hides the search + zoom chrome during navigation; the top banner
   needs that space anyway. Pinch / scroll zoom still works. */
body.is-tour-active #bop-geocoder,
body.is-tour-active .mapboxgl-ctrl-top-right,
body.is-tour-active .mapboxgl-ctrl-top-left,
body.is-tour-active .carte-collage-tour-restart {
    display: none !important;
}

/* ============================================================
   Top banner — the "manoeuvre" strip
   ============================================================ */
.cc-tour-banner {
    position: fixed;
    top: 12px;
    /* Centre with margin (no translateX — that horizontal transform broke
       positioning). Slide uses translateY only. */
    left: 0;
    right: 0;
    margin: 0 auto;
    box-sizing: border-box;
    width: calc(100% - 24px);
    max-width: 560px;
    z-index: 4250;
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 13px 16px;
    background: var(--tour-surface);
    color: var(--tour-text);
    border-radius: 16px;
    box-shadow: var(--tour-shadow);
    transform: translateY(0);
    transition: transform 240ms ease, opacity 180ms ease;
}
.cc-tour-banner.is-hidden {
    transform: translateY(-140%);
    opacity: 0;
    pointer-events: none;
}
.cc-tour-banner__arrow {
    font-size: 26px;
    line-height: 1;
    color: var(--tour-green);
    flex: none;
}
.cc-tour-banner__who {
    flex: 1;
    min-width: 0;
}
.cc-tour-banner__dist {
    font-size: 22px;
    font-weight: 800;
    letter-spacing: -0.01em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.cc-tour-banner__min {
    font-size: 14px;
    font-weight: 600;
    color: var(--tour-text-dim);
}
.cc-tour-banner__sub {
    font-size: 13px;
    color: var(--tour-text-dim);
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.cc-tour-banner__close {
    flex: none;
    background: transparent;
    border: 0;
    color: var(--tour-text-dim);
    font-size: 20px;
    line-height: 1;
    padding: 6px 8px;
    border-radius: 8px;
    cursor: pointer;
}
.cc-tour-banner__close:hover {
    background: var(--tour-surface-2);
    color: var(--tour-text);
}
.cc-tour-banner.is-arrived {
    box-shadow: 0 8px 30px rgba(22, 163, 74, 0.4);
}
.cc-tour-banner.is-arrived .cc-tour-banner__arrow {
    content: "✅";
}
.cc-tour-banner.is-arrived .cc-tour-banner__sub::before {
    content: "✅ Vous êtes arrivé · ";
    color: var(--tour-green);
    font-weight: 700;
}

/* ============================================================
   Bottom sheet
   ============================================================ */
.cc-tour-card {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    margin: 0 auto;          /* centre via margin — no transform needed */
    width: 100%;
    max-width: 560px;
    z-index: 4200;
    /* Capture all touch gestures on the sheet ourselves — otherwise the
       browser treats a vertical swipe as a pan and it leaks to the Mapbox
       canvas behind, so the user "grabs the map" instead of the sheet.
       The scrollable list re-enables vertical panning below. */
    touch-action: none;
    background: var(--tour-surface);
    color: var(--tour-text);
    border-radius: 18px 18px 0 0;
    box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.22);
    transform: translateY(0);  /* only Y is animated for the slide */
    transition: transform 240ms cubic-bezier(.4, 0, .2, 1), opacity 180ms ease;
    padding-bottom: env(safe-area-inset-bottom, 0px);
}
html[data-bop-theme="dark"] .cc-tour-card {
    box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.5);
}
.cc-tour-card.is-hidden {
    transform: translateY(100%);
    opacity: 0;
    pointer-events: none;
}

/* Grab handle (also the desktop drag handle). */
.cc-tour-card__grab {
    width: 40px;
    height: 5px;
    border-radius: 999px;
    background: var(--tour-text-dim);
    opacity: 0.4;
    margin: 10px auto 4px;
    touch-action: none;
}
@media (min-width: 641px) {
    .cc-tour-card__grab { cursor: move; }
}

/* Progress dots */
.cc-tour-dots {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    justify-content: center;
    padding: 2px 16px 8px;
}
.cc-tour-dots i {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--tour-line);
}
.cc-tour-dots i.done { background: var(--tour-text-dim); }
.cc-tour-dots i.cur {
    background: var(--tour-green);
    width: 16px;
    border-radius: 3px;
}

/* Head: progress + remaining ETA + chevron (tap to collapse/expand, or
   swipe vertically on mobile). touch-action:none lets the swipe work
   without the page intercepting it as a scroll. */
.cc-tour-card__head {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 4px 18px 6px;
    background: transparent;
    border: 0;
    cursor: pointer;
    font: inherit;
    color: inherit;
    touch-action: none;
}
.cc-tour-card__progress {
    font-size: 13px;
    font-weight: 700;
}
.cc-tour-card__eta {
    flex: 1;
    text-align: left;
    font-size: 13px;
    color: var(--tour-text-dim);
}
.cc-tour-card__chev {
    color: var(--tour-text-dim);
    font-size: 13px;
    transition: transform 240ms ease;
}
.cc-tour-card.is-open .cc-tour-card__chev {
    transform: rotate(180deg);
}

/* Primary action (always visible) */
.cc-tour-card__primary {
    padding: 6px 16px 14px;
}
.cc-tour-card__primary .cc-tour-action {
    width: 100%;
}

/* Collapsible "more": secondary actions / walkable list */
.cc-tour-card__more {
    max-height: 0;
    overflow: hidden;
    transition: max-height 260ms cubic-bezier(.4, 0, .2, 1);
    padding: 0 16px;
}
.cc-tour-card.is-open .cc-tour-card__more {
    max-height: 60vh;
    overflow-y: auto;
    touch-action: pan-y; /* re-allow vertical scroll inside the panel list */
}

.cc-tour-card__panelinfo {
    text-align: center;
    font-size: 13px;
    color: var(--tour-text-dim);
    padding: 2px 0 12px;
}

/* Action buttons */
.cc-tour-card__actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    padding-bottom: 14px;
}
.cc-tour-action {
    appearance: none;
    border: 0;
    border-radius: 12px;
    padding: 15px 12px;
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
    color: #fff;
    background: var(--tour-surface-2);
    transition: transform 90ms ease, background 120ms ease;
}
html[data-bop-theme="dark"] .cc-tour-action { color: #fff; }
.cc-tour-action:active { transform: scale(0.97); }

.cc-tour-action--primary {
    background: var(--tour-green);
    padding: 18px 12px;
    font-size: 18px;
}
.cc-tour-action--primary:hover { background: var(--tour-green-hover); }
.cc-tour-action--warn { background: var(--tour-amber); }
.cc-tour-action--warn:hover { background: var(--tour-amber-hover); }
.cc-tour-action--danger { background: var(--tour-red); }
.cc-tour-action--danger:hover { background: var(--tour-red-hover); }
.cc-tour-action--ghost {
    background: var(--tour-surface-2);
    color: var(--tour-text);
    grid-column: 1 / -1;
}

/* Multi-panel walkable list */
.cc-tour-stop-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin: 0 0 14px;
}
.cc-tour-stop-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 8px 10px;
    background: var(--tour-surface-2);
    border-radius: 10px;
    transition: opacity 140ms ease, background 140ms ease;
}
.cc-tour-stop-row.is-marked {
    opacity: 0.5;
    background: rgba(22, 163, 74, 0.14);
}
.cc-tour-stop-row__id { font-size: 16px; font-weight: 700; }
.cc-tour-stop-row__btns { display: flex; gap: 6px; }
.cc-tour-mini {
    appearance: none;
    border: 0;
    border-radius: 8px;
    width: 44px;
    height: 40px;
    font-size: 17px;
    cursor: pointer;
    background: var(--tour-surface);
    border: 1px solid var(--tour-line);
    transition: transform 90ms ease;
}
.cc-tour-mini:active { transform: scale(0.92); }
.cc-tour-mini--ok { background: rgba(22, 163, 74, 0.9); border-color: transparent; }
.cc-tour-mini--warn { background: rgba(217, 119, 6, 0.9); border-color: transparent; }
.cc-tour-mini--danger { background: rgba(185, 28, 28, 0.9); border-color: transparent; }

/* Loading state dims the primary action */
.cc-tour-card.is-loading .cc-tour-card__primary {
    opacity: 0.4;
    pointer-events: none;
}

/* ============================================================
   Numbered markers on the map
   ============================================================ */
.cc-tour-marker {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--tour-accent);
    color: #fff;
    font-weight: 700;
    font-size: 13px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid #fff;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
    cursor: default;
    transition: transform 160ms ease, background 160ms ease;
}
/* Do NOT set position on .cc-tour-marker — Mapbox positions it absolutely
   from its own stylesheet; an override here knocks markers out of the map's
   coordinate space. The badge anchors fine without it. */
.cc-tour-marker__badge {
    position: absolute;
    top: -6px;
    right: -6px;
    min-width: 16px;
    height: 16px;
    padding: 0 3px;
    border-radius: 999px;
    background: #11181f;
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    line-height: 16px;
    text-align: center;
    border: 1px solid #fff;
}
.cc-tour-marker.is-done {
    background: #94a3b8;
    width: 22px;
    height: 22px;
    font-size: 0;
    opacity: 0.85;
}
.cc-tour-marker.is-done::after {
    content: "✓";
    font-size: 13px;
    font-weight: 700;
    color: #fff;
    line-height: 1;
}
.cc-tour-marker.is-current {
    background: var(--tour-green);
    transform: scale(1.18);
    box-shadow: 0 0 0 6px rgba(22, 163, 74, 0.25), 0 2px 8px rgba(0, 0, 0, 0.4);
    animation: cc-tour-pulse 1600ms ease-in-out infinite;
}
@keyframes cc-tour-pulse {
    0%, 100% { box-shadow: 0 0 0 6px rgba(22, 163, 74, 0.25), 0 2px 8px rgba(0, 0, 0, 0.4); }
    50%      { box-shadow: 0 0 0 12px rgba(22, 163, 74, 0.08), 0 2px 8px rgba(0, 0, 0, 0.4); }
}
.cc-tour-marker.is-pending { background: var(--tour-accent); }

/* ============================================================
   End-of-tour recap modal
   ============================================================ */
.cc-tour-recap {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    z-index: 4300;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}
.cc-tour-recap.is-hidden { display: none; }
.cc-tour-recap__inner {
    background: var(--tour-surface);
    color: var(--tour-text);
    border-radius: 14px;
    padding: 28px 24px 22px;
    width: min(420px, 100%);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.35);
}
.cc-tour-recap__inner h2 { margin: 0 0 16px; font-size: 20px; }
.cc-tour-recap__stats ul { list-style: none; padding: 0; margin: 0 0 16px; }
.cc-tour-recap__stats li { padding: 6px 0; font-size: 15px; }
.cc-tour-recap__warn {
    background: rgba(217, 119, 6, 0.12);
    border: 1px solid rgba(217, 119, 6, 0.4);
    color: var(--tour-amber-hover);
    border-radius: 8px;
    padding: 10px 12px;
    font-size: 13px;
    margin: 0 0 14px;
}
html[data-bop-theme="dark"] .cc-tour-recap__warn { color: #fbbf24; }
.cc-tour-recap__time { color: var(--tour-text-dim); font-size: 13px; margin-bottom: 16px; }

/* ---- Mobile tweaks ------------------------------------------- */
@media (max-width: 640px) {
    /* Base already handles position (left/right/margin/translateY); here we
       only add the scroll cap. No transform overrides — that was what
       skewed/offset the card. */
    .cc-tour-card {
        max-height: 82vh;
        display: flex;
        flex-direction: column;
    }
    /* Slightly tighter inset on phones. */
    .cc-tour-banner {
        width: calc(100% - 16px);
    }
    /* Only the OPEN state gets height — collapsed stays 0 (the base rule)
       so the sheet actually folds on mobile. */
    .cc-tour-card.is-open .cc-tour-card__more { max-height: 50vh; }
    .cc-tour-action { padding: 14px 10px; font-size: 14px; }
    .cc-tour-action--primary { padding: 17px 12px; font-size: 17px; }
    .cc-tour-mini { width: 42px; height: 40px; }
}
