/* =========================================
   TERAPEUTAS – PUBLIC MAP PAGE
   ========================================= */

#th-wrap {
    /* Colores heredados del tema con fallback */
    --th-primary: var(--theme-color, #E91E63);
    --th-primary-rgb: 233, 30, 99;
    --th-secondary: var(--secondary-color, #ffad01);
    --th-secondary-rgb: 255, 173, 1;

    width: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    color: #222;
    box-sizing: border-box;
}

#th-wrap *,
#th-wrap *::before,
#th-wrap *::after {
    box-sizing: border-box;
}

/* ---- SEARCH BAR ---- */
#th-search-bar {
    padding: 14px 16px 10px;
    background: #fff;
    border-bottom: 1px solid #e8e8e8;
}

#th-search-inner {
    display: flex;
    align-items: center;
    background: #f5f5f5;
    border: 1.5px solid #e0e0e0;
    border-radius: 40px;
    padding: 0 16px;
    transition: border-color .2s;
}

#th-search-inner:focus-within {
    border-color: var(--th-primary);
    background: #fff;
    box-shadow: 0 0 0 3px rgba(var(--th-primary-rgb), .15);
}

#th-search-icon {
    width: 17px;
    height: 17px;
    color: #888;
    flex-shrink: 0;
}

#th-search-input {
    flex: 1;
    border: none;
    background: transparent;
    padding: 11px 10px;
    font-size: 14px;
    color: #222;
    outline: none;
}

#th-search-input::placeholder {
    color: #aaa;
}

#th-search-clear {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 15px;
    color: #aaa;
    padding: 0;
    display: none;
    line-height: 1;
}

#th-search-clear.visible {
    display: block;
}

#th-results-count {
    font-size: 12px;
    color: #888;
    margin-top: 6px;
    padding-left: 4px;
    min-height: 16px;
}

/* ---- LAYOUT ---- */
#th-layout {
    display: flex;
    height: 600px;
}

/* MAP COLUMN */
#th-map-col {
    flex: 0 0 50%;
    position: sticky;
    top: 0;
    height: 600px;
}

#th-map {
    width: 100%;
    height: 100%;
}

/* CARDS COLUMN (desktop) */
#th-cards-col {
    flex: 0 0 50%;
    overflow-y: auto;
    background: #fafafa;
    border-left: 1px solid #e8e8e8;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 0;
}

/* DESKTOP CARD */
.th-card {
    display: flex;
    align-items: stretch;
    background: #fff;
    border: 2px solid transparent;
    border-radius: 12px;
    margin-bottom: 10px;
    cursor: pointer;
    transition: border-color .2s, box-shadow .2s, transform .15s;
    overflow: hidden;
    box-shadow: 0 1px 4px rgba(0,0,0,.07);
}

.th-card:hover {
    box-shadow: 0 4px 16px rgba(0,0,0,.13);
    transform: translateY(-1px);
}

.th-card.active {
    border-color: var(--th-primary);
    box-shadow: 0 4px 20px rgba(var(--th-primary-rgb), .25);
}

.th-card-img {
    flex: 0 0 90px;
    height: 110px;
    overflow: hidden;
    background: #eee;
}

.th-card-img img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.th-card-placeholder {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #e8f0fa, #d0e2f5);
    font-size: 32px;
}

.th-card-body {
    flex: 1;
    padding: 10px 13px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 4px;
}

.th-card-tipo {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: .5px;
    text-transform: uppercase;
    color: #fff;
    background: var(--th-primary);
    border-radius: 20px;
    padding: 2px 9px;
    align-self: flex-start;
    white-space: nowrap;
}

.th-card-tipo.alimentacion {
    background: var(--th-secondary);
}

.th-card-nombre {
    font-size: 14px;
    font-weight: 700;
    margin: 0;
    color: #1a1a1a;
    line-height: 1.3;
}

.th-card-clinica,
.th-card-direccion {
    font-size: 12px;
    color: #666;
    margin: 0;
    display: flex;
    align-items: flex-start;
    gap: 4px;
    line-height: 1.4;
}

.th-card-clinica svg,
.th-card-direccion svg {
    width: 12px;
    height: 12px;
    flex-shrink: 0;
    margin-top: 2px;
    color: var(--th-primary);
}

/* NO RESULTS */
#th-no-results {
    display: none;
    text-align: center;
    color: #888;
    font-size: 14px;
    padding: 40px 20px;
}

#th-no-results.visible {
    display: block;
}

/* MOBILE SWIPE STRIP – hidden on desktop */
#th-cards-mobile-wrap {
    display: none;
}

/* ---- LEAFLET POPUP ---- */
.th-popup {
    text-align: center;
    min-width: 190px;
}

.th-popup-img {
    width: 70px;
    height: 70px;
    border-radius: 50%;
    object-fit: cover;
    display: block;
    margin: 0 auto 8px;
    border: 2px solid #e8e8e8;
}

.th-popup-placeholder {
    width: 70px;
    height: 70px;
    border-radius: 50%;
    background: linear-gradient(135deg, #e8f0fa, #d0e2f5);
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 8px;
    font-size: 26px;
}

.th-popup-nombre {
    font-size: 14px;
    font-weight: 700;
    margin: 0 0 4px;
    color: #1a1a1a;
}

.th-popup-tipo {
    font-size: 11px;
    color: #fff;
    background: var(--th-primary);
    display: inline-block;
    padding: 2px 9px;
    border-radius: 20px;
    margin: 0 0 8px;
}

.th-popup-tipo.alimentacion {
    background: var(--th-secondary);
}

.th-popup-datos {
    list-style: none;
    padding: 0;
    margin: 0;
    text-align: left;
    font-size: 12px;
    color: #555;
}

.th-popup-datos li {
    padding: 3px 0;
    border-bottom: 1px solid #f0f0f0;
}

.th-popup-datos li:last-child {
    border-bottom: none;
}

/* =========================================
   MOBILE – página del mapa: full screen,
   sin scroll de página, sin footer ni título
   ========================================= */
@media (max-width: 767px) {

    html:has(#th-wrap),
    body:has(#th-wrap) {
        overflow: hidden;
        height: 100%;
        height: 100dvh;
    }

    body:has(#th-wrap) footer,
    body:has(#th-wrap) .page-title-wrap,
    body:has(#th-wrap) section:has(.page-title-wrap) {
        display: none !important;
    }

    /* ---- HEADER: fixed, fondo blanco sólido, z-index máximo ---- */
    body:has(#th-wrap) header,
    body:has(#th-wrap) #header,
    body:has(#th-wrap) .site-header,
    body:has(#th-wrap) .header-wrap,
    body:has(#th-wrap) .sticky-menu,
    body:has(#th-wrap) .sticky-header {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        width: 100% !important;
        z-index: 10000 !important;
        background: #fff !important;
        background-color: #fff !important;
        box-shadow: 0 2px 8px rgba(0,0,0,.12) !important;
    }

    /* Todos los hijos del header en oscuro */
    body:has(#th-wrap) header *,
    body:has(#th-wrap) #header *,
    body:has(#th-wrap) .site-header *,
    body:has(#th-wrap) .header-wrap *,
    body:has(#th-wrap) .sticky-menu *,
    body:has(#th-wrap) .sticky-header * {
        color: #222 !important;
    }

    /* Compensar el espacio que el header fixed ya no ocupa en el flujo */
    #th-wrap {
        margin-top: var(--nav-h, 70px);
    }
}

/* =========================================
   MOBILE  (≤ 767px)
   ========================================= */
@media (max-width: 767px) {

    #th-layout {
        flex-direction: column;
        /* vh como fallback para navegadores sin soporte dvh */
        height: calc(100vh - var(--nav-h, 70px));
        /* dvh descuenta el chrome del navegador móvil (barra de dirección, etc.) */
        height: calc(100dvh - var(--nav-h, 70px));
        min-height: 300px;
        position: relative;
        overflow: hidden;
    }

    /* El mapa ocupa el espacio restante sin desbordarse */
    #th-map-col {
        flex: 0 0 80dvh;
        position: relative;
        height: 80dvh;
        min-height: unset;
        max-height: unset;
        z-index: 1;
    }

    #th-cards-col {
        display: none;
    }

    /* Search bar dentro del sheet */
    #th-search-bar {
        padding: 8px 14px 8px;
        border-bottom: 1px solid #f0f0f0;
        background: #fff;
        flex-shrink: 0;
    }

    #th-results-count {
        font-size: 11px;
        margin-top: 4px;
        padding-left: 2px;
    }

    /* ---- BOTTOM SHEET (fixed: escapa overflow del layout, cubre el mapa) ---- */
    #th-cards-mobile-wrap {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        top: var(--nav-h, 70px);
        display: flex;
        flex-direction: column;
        background: #fff;
        border-radius: 20px 20px 0 0;
        box-shadow: 0 -6px 30px rgba(0,0,0,.22);
        z-index: 1000;
        will-change: transform;
    }

    /* Drag handle pill */
    #th-sheet-handle {
        flex-shrink: 0;
        padding: 12px 0 6px;
        display: flex;
        justify-content: center;
        align-items: center;
        cursor: grab;
        -webkit-user-select: none;
        user-select: none;
    }

    #th-sheet-handle::after {
        content: '';
        display: block;
        width: 44px;
        height: 5px;
        background: #d0d0d0;
        border-radius: 3px;
    }

    /* Cards vertical list */
    #th-cards-mobile {
        flex: 1;
        min-height: 0;
        padding: 4px 12px;
        padding-bottom: max(env(safe-area-inset-bottom, 0px), 24px);
        display: flex;
        flex-direction: column;
        gap: 10px;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
        touch-action: pan-y;
    }

    /* MOBILE CARD – horizontal layout like desktop */
    .th-card-mobile {
        flex-shrink: 0;
        display: flex;
        align-items: stretch;
        background: #fff;
        border: 2px solid transparent;
        border-radius: 12px;
        box-shadow: 0 1px 6px rgba(0,0,0,.09);
        cursor: pointer;
        overflow: hidden;
        transition: border-color .2s, box-shadow .2s;
    }

    .th-card-mobile.active {
        border-color: var(--th-primary);
        box-shadow: 0 4px 20px rgba(var(--th-primary-rgb), .3);
    }

    .th-card-mobile-img {
        flex: 0 0 80px;
        height: 95px;
        overflow: hidden;
        background: linear-gradient(135deg, #e8f0fa, #d0e2f5);
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 32px;
    }

    .th-card-mobile-img img {
        width: 100%;
        height: 100%;
        object-fit: cover;
        display: block;
    }

    .th-card-mobile-body {
        flex: 1;
        padding: 10px 13px;
        display: flex;
        flex-direction: column;
        justify-content: center;
        gap: 3px;
    }

    .th-card-mobile-tipo {
        font-size: 10px;
        font-weight: 700;
        letter-spacing: .4px;
        text-transform: uppercase;
        color: #fff;
        background: var(--th-primary);
        border-radius: 20px;
        padding: 2px 9px;
        display: inline-block;
        margin-bottom: 4px;
        align-self: flex-start;
    }

    .th-card-mobile-tipo.alimentacion {
        background: var(--th-secondary);
    }

    .th-card-mobile-nombre {
        font-size: 14px;
        font-weight: 700;
        margin: 0 0 3px;
        color: #1a1a1a;
        line-height: 1.3;
    }

    .th-card-mobile-clinica,
    .th-card-mobile-direccion {
        font-size: 12px;
        color: #666;
        margin: 0 0 2px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        display: flex;
        align-items: center;
        gap: 4px;
    }

    .th-card-mobile-clinica svg,
    .th-card-mobile-direccion svg {
        width: 12px;
        height: 12px;
        flex-shrink: 0;
        color: var(--th-primary);
    }
}
