/*
 * strava-browser.css — the Strava browsing and import surface (scripts/ui/strava-browser.js).
 *
 * The component is MOUNTABLE: it can land in the Saved Routes dock, in the profile
 * panel, or in a mobile sheet. So nothing here positions anything — no fixed, no
 * z-index, no dock geometry. The block fills whatever container it is given and
 * borrows that container's glass tokens from styles/main.css, which is what makes it
 * look native in each of its hosts instead of like a panel inside a panel.
 *
 * Rows are laid out as a 3-column grid (thumbnail / text / actions) that collapses to
 * two on a narrow phone: the actions drop under the text rather than squeezing the
 * name to three characters. The silhouette never shrinks below 44px, because a shape
 * you cannot recognise is worse than no shape at all.
 */

.strava-browser {
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: 100%;
    min-width: 0;
    color: #fff;
    font-family: var(--font-ui, system-ui, sans-serif);
}

.strava-browser[hidden],
.strava-browser [hidden] {
    display: none;
}

/* ---- Not connected ------------------------------------------------------ */

.strava-browser__signin {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
    padding: 16px;
    border: 1px solid var(--glass-border, rgba(255, 255, 255, 0.28));
    border-radius: var(--glass-radius, 16px);
    background: var(--glass-surface, rgba(255, 255, 255, 0.06));
    backdrop-filter: blur(var(--glass-blur, 16px));
}

.strava-browser__signin-text {
    margin: 0;
    font-size: 13px;
    line-height: 1.5;
    color: rgba(255, 255, 255, 0.86);
}

/* ---- Structure ---------------------------------------------------------- */

.strava-browser__main {
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-width: 0;
}

.strava-browser__tabs {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.strava-browser__toolbar {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.strava-browser__period {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: rgba(255, 255, 255, 0.78);
}

.strava-browser__select {
    appearance: none;
    padding: 6px 10px;
    border: 1px solid var(--glass-border, rgba(255, 255, 255, 0.28));
    border-radius: 10px;
    background: rgba(12, 24, 36, 0.75);
    color: #fff;
    font-family: inherit;
    font-size: 12px;
    cursor: pointer;
}

.strava-browser__select:disabled {
    opacity: 0.5;
    cursor: default;
}

/*
 * The budget line is the promise made before a half-hour job starts, so it stays
 * readable rather than shrinking into a hint.
 */
.strava-browser__budget {
    font-size: 12px;
    line-height: 1.4;
    color: rgba(255, 255, 255, 0.72);
}

.strava-browser__resume,
.strava-browser__progress {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    padding: 10px 12px;
    border: 1px solid var(--glass-border, rgba(255, 255, 255, 0.28));
    border-radius: 12px;
    background: var(--glass-surface, rgba(255, 255, 255, 0.06));
    font-size: 12px;
    line-height: 1.45;
}

/* An interrupted import is the one thing on this surface worth an accent. */
.strava-browser__resume {
    border-left: 3px solid var(--strava-orange, #fc4c02);
}

.strava-browser__resume-text,
.strava-browser__progress-label {
    flex: 1 1 12ch;
    min-width: 0;
}

.strava-browser__gate {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
    padding: 14px;
    border: 1px solid var(--glass-border, rgba(255, 255, 255, 0.28));
    border-radius: 12px;
    background: var(--glass-surface, rgba(255, 255, 255, 0.06));
}

.strava-browser__gate-text,
.strava-browser__gate-hint {
    margin: 0;
    font-size: 12px;
    line-height: 1.5;
    color: rgba(255, 255, 255, 0.82);
}

.strava-browser__gate-hint {
    color: rgba(255, 255, 255, 0.62);
}

.strava-browser__attribution {
    margin: 0;
    font-size: 11px;
}

/* ---- Buttons and tabs --------------------------------------------------- */

.strava-browser__btn,
.strava-browser__tab {
    appearance: none;
    padding: 7px 12px;
    border: 1px solid var(--glass-border, rgba(255, 255, 255, 0.28));
    border-radius: 10px;
    background: var(--glass-surface, rgba(255, 255, 255, 0.06));
    color: #fff;
    font-family: inherit;
    font-size: 12px;
    font-weight: 600;
    line-height: 1.2;
    cursor: pointer;
    transition: background 0.2s ease, border-color 0.2s ease, opacity 0.2s ease;
}

.strava-browser__btn:hover:not(:disabled),
.strava-browser__tab:hover {
    border-color: var(--glass-border-strong, rgba(255, 255, 255, 0.4));
    background: rgba(255, 255, 255, 0.14);
}

.strava-browser__btn:disabled {
    opacity: 0.45;
    cursor: default;
}

.strava-browser__btn--primary {
    border-color: transparent;
    background: var(--strava-orange, #fc4c02);
}

.strava-browser__btn--primary:hover:not(:disabled) {
    background: #ff5f1a;
}

.strava-browser__btn--ghost {
    background: transparent;
}

.strava-browser__tab[aria-selected='true'] {
    border-color: transparent;
    background: rgba(255, 255, 255, 0.2);
}

/* ---- List --------------------------------------------------------------- */

.strava-browser__list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.strava-browser__empty {
    padding: 16px 12px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.04);
    color: rgba(255, 255, 255, 0.62);
    font-size: 12px;
    text-align: center;
}

.strava-browser__pagination {
    display: flex;
    justify-content: center;
}

.strava-row {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 12px;
    padding: 10px;
    border: 1px solid var(--glass-border, rgba(255, 255, 255, 0.28));
    border-radius: 12px;
    background: var(--glass-surface, rgba(255, 255, 255, 0.06));
}

/* A row we cannot import is still readable; it just stops inviting a click. */
.strava-row--blocked {
    opacity: 0.62;
}

.strava-row--imported {
    border-color: rgba(120, 220, 160, 0.4);
}

/* ---- Thumbnail: silhouette first, photo over it ------------------------- */

.strava-row__thumb {
    position: relative;
    flex: 0 0 auto;
    width: 56px;
    height: 56px;
    min-width: 44px;
    border-radius: 10px;
    overflow: hidden;
    background: rgba(0, 0, 0, 0.28);
    /* The silhouette is drawn with stroke: currentColor, so this is its colour. */
    color: var(--strava-orange, #fc4c02);
}

.strava-row__thumb > svg {
    display: block;
    width: 100%;
    height: 100%;
}

.strava-row__thumb-empty {
    opacity: 0.35;
}

/*
 * The photo is layered ON TOP of the shape and fades in only once decoded, so a slow
 * or failed image never leaves an empty box where a recognisable trace used to be.
 */
.strava-row__photo {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    opacity: 0;
    transition: opacity 0.35s ease;
}

.strava-row__photo.is-visible {
    opacity: 1;
}

@media (prefers-reduced-motion: reduce) {
    .strava-row__photo {
        transition: none;
    }
}

/* ---- Row text ----------------------------------------------------------- */

.strava-row__main {
    display: flex;
    flex-direction: column;
    gap: 3px;
    min-width: 0;
}

.strava-row__title {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
    min-width: 0;
}

.strava-row__name {
    min-width: 0;
    overflow: hidden;
    color: #fff;
    font-size: 13px;
    font-weight: 650;
    line-height: 1.3;
    text-overflow: ellipsis;
    white-space: nowrap;
    text-decoration: none;
}

a.strava-row__name:hover {
    text-decoration: underline;
}

.strava-row__flag {
    flex: 0 0 auto;
    padding: 1px 6px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.16);
    font-size: 10px;
    font-weight: 600;
    white-space: nowrap;
}

.strava-row__meta {
    color: rgba(255, 255, 255, 0.68);
    font-size: 11px;
    line-height: 1.4;
}

.strava-row__reason {
    color: rgba(255, 190, 160, 0.9);
    font-size: 11px;
    line-height: 1.4;
}

.strava-row__actions {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.strava-row__badge {
    padding: 3px 8px;
    border-radius: 999px;
    background: rgba(120, 220, 160, 0.18);
    color: rgba(190, 245, 215, 0.95);
    font-size: 10px;
    font-weight: 700;
    white-space: nowrap;
}

/* ---- Phone -------------------------------------------------------------- */

@media (max-width: 600px) {
    .strava-row {
        /* Two columns: the actions move under the text instead of crushing the name. */
        grid-template-columns: auto minmax(0, 1fr);
        align-items: start;
    }

    .strava-row__actions {
        grid-column: 1 / -1;
        justify-content: flex-start;
    }

    .strava-row__thumb {
        width: 48px;
        height: 48px;
    }

    .strava-browser__toolbar {
        gap: 8px;
    }

    .strava-browser__btn,
    .strava-browser__tab {
        /* Comfortable thumb target without making the row taller than it must be. */
        min-height: 36px;
    }
}
