/**
 * Routes index/directory page ("/{base}"): hero + sidebar list + map, with
 * a searchbar floating over the map. Builds on trufi-shared.css (hero,
 * list-title, line badge, geo button, Leaflet theme).
 *
 * Desktop: the hero flows normally (its own height), and only the
 * sidebar+map row below it is given a generous bounded height (`80vh`,
 * mirroring the route detail page's `.trufi-route-body`/`.trufi-route-map-wrap`
 * - see trufi-route.css) so the page still scrolls normally like any other
 * WordPress page and reaches the theme's footer without a jump. This used
 * to be `height: calc(100dvh - 82px)` on the whole section - a viewport-
 * locked "app shell" - but the theme's `#primary` padding (40px top+bottom)
 * plus the footer mean the page is *always* taller than one viewport
 * regardless, so that never actually achieved "no scroll"; it only made the
 * dynamic-viewport-height (`dvh`) unit recalculate against a page that
 * scrolls anyway, which is what made the footer look like it was jumping
 * around / "sticky" during scroll on mobile browsers (their chrome
 * show/hide changes `dvh`). A bounded `vh` height avoids that entirely.
 * Mobile (<=780px): a normal scrolling page - hero, then a search/filter
 * card, then a shorter map, then the routes list below it - per the
 * mobile design (see AGENTS.md).
 *
 * Searchbar: one line when the map column is wide enough, wrapping to a
 * second row (selects + buttons) when it isn't. It used to be `nowrap`,
 * which on mid-width screens squeezed the search input down to ~0px wide -
 * typing still filtered, but the text and caret were invisible. The input
 * keeps a real min-width and a full theme-style reset for that reason.
 *
 * The list is grouped by operator ("sindicato"): .trufi-group (name, route
 * count, share) > .trufi-line (badge + line title) > .trufi-pattern (a link
 * to the route's detail page + its share button).
 */

.trufi-index {
    margin: -1px 0 0;
    font-family: inherit;
    background: var(--trufi-gray-100);
}

.trufi-index-body {
    display: flex;
    flex-wrap: nowrap;
    height: 80vh;
    min-height: 480px;
    max-height: 860px;
}

.trufi-index-sidebar {
    flex: 0 1 320px;
    min-width: 260px;
    border-right: 1px solid var(--trufi-gray-500-a);
    display: flex;
    flex-direction: column;
    min-height: 0;
    background: var(--trufi-white);
}

.trufi-index-list {
    flex: 1 1 0;
    min-height: 0;
    overflow-y: auto;
    padding: 8px;
}

.trufi-line {
    border-radius: 8px;
    margin-bottom: 6px;
    overflow: hidden;
    border: 1px solid var(--trufi-gray-500-a);
}

.trufi-line-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    background: var(--trufi-gray-100);
}

.trufi-line-title {
    font-size: 14px;
    color: var(--trufi-gray-900);
    font-weight: 600;
}

.trufi-pattern {
    display: flex;
    align-items: center;
    gap: 8px;
    padding-right: 10px;
    font-size: 13px;
    border-top: 1px solid var(--trufi-gray-100);
}

.trufi-pattern-link {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 9px 0 9px 16px;
    color: var(--trufi-gray-600);
    text-decoration: none;
}

.trufi-pattern-link .trufi-icon {
    color: var(--trufi-gray-500);
    flex-shrink: 0;
}

.trufi-pattern-label {
    flex: 1 1 auto;
    min-width: 0;
}

.trufi-pattern:hover,
.trufi-pattern:focus-within {
    background: var(--trufi-gray-100);
}

.trufi-pattern-link:hover,
.trufi-pattern-link:focus-visible,
.trufi-pattern-link:hover .trufi-icon,
.trufi-pattern-link:focus-visible .trufi-icon {
    color: var(--trufi-pink);
}

/* Sindicato group: header (name, "N rutas trazadas", share) + its lines */

.trufi-group {
    margin-bottom: 14px;
}

.trufi-group-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 6px 4px 8px;
}

.trufi-group-info {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.trufi-group-name {
    font-size: 14px;
    font-weight: 700;
    color: var(--trufi-gray-900);
    line-height: 1.25;
}

.trufi-group-count {
    font-size: 12px;
    color: var(--trufi-gray-600);
}

.trufi-index-map-wrap {
    flex: 1 1 0;
    min-width: 0;
    min-height: 0;
    position: relative;
}

#trufi-index-map {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
    isolation: isolate;
}

/* Searchbar: floats over the map on desktop ------------------------------- */

.trufi-searchbar {
    position: absolute;
    top: 8px;
    left: 8px;
    right: 8px;
    z-index: 500;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px;
    background: rgba(255, 255, 255, 0.95);
    border: 1px solid rgba(33, 37, 41, 0.18);
    border-radius: 10px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.18);
    padding: 6px 8px;
}

.trufi-search-field {
    flex: 1 1 220px;
    min-width: 180px;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 7px 10px;
    border: 1px solid var(--trufi-gray-500);
    border-radius: 6px;
    background: var(--trufi-white);
}

.trufi-search-field .trufi-icon {
    color: var(--trufi-gray-500);
    flex-shrink: 0;
}

.trufi-search-field:focus-within {
    border-color: var(--trufi-pink);
}

/* Theme-proof reset: themes style bare text inputs (padding, fixed height,
 * borders, colors) in ways that can leave no room for the text itself -
 * selector specificity is deliberately above a theme's `input[type="text"]`. */
.trufi-searchbar .trufi-search-field input[type="text"] {
    flex: 1 1 auto;
    width: 100%;
    min-width: 0;
    margin: 0;
    padding: 0;
    height: auto;
    min-height: 0;
    border: none;
    border-radius: 0;
    outline: none;
    box-shadow: none;
    background: transparent;
    color: var(--trufi-gray-900);
    caret-color: var(--trufi-pink);
    font-size: 14px;
    line-height: 1.4;
    font-family: inherit;
}

.trufi-searchbar .trufi-search-field input[type="text"]::placeholder {
    color: var(--trufi-gray-600);
    opacity: 1;
}

.trufi-searchbar select {
    flex: 1 1 150px;
    max-width: 220px;
    min-width: 0;
    height: auto;
    margin: 0;
    padding: 7px 8px;
    border: 1px solid var(--trufi-gray-500);
    border-radius: 6px;
    font-size: 14px;
    line-height: 1.4;
    color: var(--trufi-gray-900);
    background-color: var(--trufi-white);
    font-family: inherit;
}

.trufi-searchbar-actions {
    display: flex;
    gap: 6px;
    align-items: center;
    flex: 0 0 auto;
    margin-left: auto;
}

.trufi-searchbar-actions .trufi-geo-btn {
    position: static;
    box-shadow: none;
}

/* Mobile: stacked scrolling page ------------------------------------------ */

@media (max-width: 780px) {
    .trufi-hero {
        padding: 16px 20px;
    }

    .trufi-hero h1 {
        font-size: 20px;
    }

    .trufi-index-body {
        display: flex;
        flex-direction: column;
        height: auto;
        min-height: 0;
        max-height: none;
    }

    /* Mobile order: hero (above) -> search/map card -> routes list, per the
     * mobile design. Flex `order` keeps the DOM (and its no-JS/reader
     * order: list, then map) unchanged while flipping the visual order. */
    /* The searchbar card sits *above* the map here, in normal flow - so the
     * map gets its own height instead of absolutely filling the wrapper.
     * Keep the card positioned (relative + z-index): a static card would be
     * painted underneath the positioned map and vanish (which is exactly
     * how search/filter used to disappear on mobile). */
    .trufi-index-map-wrap {
        order: 1;
        position: relative;
        display: flex;
        flex-direction: column;
        flex: 0 0 auto;
        height: auto;
        border-bottom: 1px solid var(--trufi-gray-500-a);
    }

    #trufi-index-map {
        position: relative;
        inset: auto;
        height: 320px;
        min-height: 260px;
    }

    .trufi-index-sidebar {
        order: 2;
    }

    .trufi-searchbar {
        position: relative;
        top: auto;
        left: auto;
        right: auto;
        z-index: 1;
        margin: 12px;
        box-shadow: 0 2px 4px rgba(171, 190, 209, 0.6);
    }

    .trufi-search-field {
        flex-basis: 100%;
        min-width: 0;
    }

    .trufi-searchbar select {
        flex: 1 1 140px;
        max-width: none;
    }

    .trufi-searchbar-actions {
        margin-left: 0;
        width: 100%;
        justify-content: space-between;
    }

    /* Size the list by its content. With the desktop `flex: 1 1 0;
     * min-height: 0` in this auto-height column it collapsed to 0px and its
     * rows overflowed underneath the theme's footer. */
    .trufi-index-sidebar {
        border-right: none;
        border-top: 1px solid var(--trufi-gray-500-a);
        min-width: 0;
        flex: 0 0 auto;
    }

    .trufi-index-list {
        flex: 0 0 auto;
        min-height: auto;
        overflow: visible;
    }
}
