/**
 * Search Map Styles - Bestogoo 2025
 * Stili per la mappa e i tabs nella pagina di ricerca
 * Compatibile con WebView iOS/Android
 */

/* ==========================================================================
   WEBVIEW & MOBILE COMPATIBILITY
   ========================================================================== */

/* Safe area per iPhone X+ (notch) */
@supports (padding-top: env(safe-area-inset-top)) {
    .search-view-tabs {
        padding-top: calc(12px + env(safe-area-inset-top));
    }

    .map-info-card {
        bottom: calc(20px + env(safe-area-inset-bottom));
    }
}

/* Previeni zoom su double-tap (iOS) */
.search-view-tabs,
.search-view-tab,
.map-info-card {
    touch-action: manipulation;
}

/* Migliora scrolling su iOS */
.search-map-container {
    -webkit-overflow-scrolling: touch;
}

/* ==========================================================================
   SUBCATEGORY LABELS - Mantieni visibili in vista mappa
   ========================================================================== */

/* Quando la mappa è attiva, mantieni container-suggestion visibile */
body.search-map-active .container-suggestion {
    display: block !important;
    position: sticky;
    top: 0;
    z-index: 410;
    background: #fff;
    margin-bottom: 0;
    padding-bottom: 8px;
}

/* Aumenta altezza per mostrare etichette sotto le icone */
body.search-map-active .menu-suggestion {
    max-height: 120px; /* Era 90px, aumentato per le etichette */
    overflow-y: visible;
}

body.search-map-active .menu-wrapper-suggestion {
    overflow: visible; /* Permetti overflow per le etichette */
}

/* ==========================================================================
   TABS LISTA/MAPPA
   ========================================================================== */

.search-view-tabs {
    display: flex;
    justify-content: center;
    gap: 8px;
    padding: 12px 16px;
    background: #fff;
    position: sticky;
    top: 0;
    z-index: 400;
    border-bottom: 1px solid #e5e7eb;
    margin-bottom: 10px;
    /* Previeni selezione testo */
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

/* Quando mappa attiva, tabs sotto le subcategories */
body.search-map-active .search-view-tabs {
    top: auto; /* Non sticky, segue il flusso */
    position: relative;
    margin-top: 0;
}

.search-view-tab {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    border: 2px solid #e5e7eb;
    border-radius: 25px;
    background: #fff;
    color: #6b7280;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    /* Rimuovi stili default button */
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    outline: none;
    /* Migliora tap target per mobile */
    min-height: 44px;
    min-width: 100px;
    /* Previeni highlight su tap (Android) */
    -webkit-tap-highlight-color: transparent;
}

.search-view-tab:hover {
    border-color: #70c542;
    color: #70c542;
}

.search-view-tab:active {
    transform: scale(0.97);
}

.search-view-tab.active {
    background: #70c542;
    border-color: #70c542;
    color: #fff;
}

.search-view-tab svg {
    flex-shrink: 0;
    pointer-events: none;
}

/* ==========================================================================
   CONTAINER MAPPA
   ========================================================================== */

.search-map-container {
    position: relative;
    width: 100%;
    height: calc(100vh - 200px);
    height: calc(100dvh - 200px); /* Dynamic viewport height per mobile */
    min-height: 300px;
    max-height: 800px;
    /* Previeni problemi di rendering su WebView */
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
    /* Forza GPU acceleration */
    will-change: transform;
}

.search-map {
    width: 100%;
    height: 100%;
    border-radius: 0;
    /* Fix per Google Maps su WebView */
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
}

/* Fix per Google Maps controls su mobile */
.search-map .gm-style-cc,
.search-map .gm-style-cc + div {
    display: none !important;
}

/* ==========================================================================
   INFO CARD (al click sul marker)
   ========================================================================== */

.map-info-card {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    width: calc(100% - 32px);
    max-width: 400px;
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    z-index: 200;
    opacity: 0;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow: hidden;
    /* Migliora rendering su mobile */
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
}

.map-info-card.visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.map-info-card-close {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 36px;
    height: 36px;
    border: none;
    background: rgba(0, 0, 0, 0.5);
    color: #fff;
    border-radius: 50%;
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    z-index: 10;
    transition: background 0.2s;
    /* Tap target minimo per accessibilità */
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    -webkit-tap-highlight-color: transparent;
}

.map-info-card-close:hover,
.map-info-card-close:active {
    background: rgba(0, 0, 0, 0.7);
}

.map-info-card-link {
    display: flex;
    align-items: stretch;
    text-decoration: none;
    color: inherit;
    /* Feedback visivo su tap */
    -webkit-tap-highlight-color: rgba(112, 197, 66, 0.1);
}

.map-info-card-link:active {
    background: rgba(0, 0, 0, 0.02);
}

.map-info-card-image {
    width: 120px;
    height: 120px;
    object-fit: cover;
    flex-shrink: 0;
    /* Previeni distorsione immagine */
    background-color: #f3f4f6;
}

.map-info-card-image-placeholder {
    width: 120px;
    height: 120px;
    background: #f3f4f6;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.map-info-card-body {
    flex: 1;
    padding: 12px 16px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-width: 0; /* Permette text-overflow */
    overflow: hidden;
}

.map-info-card-position {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    background: #70c542;
    color: #fff;
    border-radius: 50%;
    font-size: 12px;
    font-weight: bold;
    margin-bottom: 6px;
    flex-shrink: 0;
}

.map-info-card-title {
    margin: 0 0 6px 0;
    font-size: 16px;
    font-weight: 700;
    color: #1f2937;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    /* Migliora rendering font */
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.map-info-card-rating {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-bottom: 4px;
    flex-wrap: nowrap;
}

.map-info-card-rating .star {
    color: #d1d5db;
    font-size: 14px;
    line-height: 1;
}

.map-info-card-rating .star.filled {
    color: #fbbf24;
}

.map-info-card-rating .rating-value {
    font-size: 13px;
    font-weight: 600;
    color: #6b7280;
    margin-left: 4px;
}

.map-info-card-address {
    margin: 0;
    font-size: 13px;
    color: #6b7280;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.map-info-card-arrow {
    display: flex;
    align-items: center;
    padding: 0 12px;
    color: #70c542;
    flex-shrink: 0;
}

/* ==========================================================================
   HOVER HIGHLIGHT (lista)
   ========================================================================== */

.box007.map-hover-highlight {
    box-shadow: 0 0 0 3px #70c542 !important;
    transform: scale(1.02);
    transition: all 0.2s ease;
}

/* ==========================================================================
   RESPONSIVE - TABLET (768px)
   ========================================================================== */

@media screen and (max-width: 768px) {
    .search-view-tabs {
        padding: 10px 12px;
        gap: 6px;
    }

    .search-view-tab {
        padding: 8px 16px;
        font-size: 13px;
        min-width: 90px;
    }

    .search-map-container {
        height: calc(100vh - 180px);
        height: calc(100dvh - 180px);
        min-height: 300px;
    }

    .map-info-card {
        bottom: 10px;
        width: calc(100% - 20px);
        max-width: none;
        border-radius: 12px;
    }

    .map-info-card-image,
    .map-info-card-image-placeholder {
        width: 100px;
        height: 100px;
    }

    .map-info-card-body {
        padding: 10px 12px;
    }

    .map-info-card-title {
        font-size: 15px;
    }

    .map-info-card-address {
        font-size: 12px;
    }
}

/* ==========================================================================
   RESPONSIVE - MOBILE SMALL (480px)
   ========================================================================== */

@media screen and (max-width: 480px) {
    .search-view-tabs {
        padding: 8px 10px;
        gap: 8px;
    }

    .search-view-tab {
        padding: 10px 14px;
        font-size: 13px;
        gap: 6px;
        min-width: 80px;
        flex: 1;
        max-width: 150px;
    }

    .search-view-tab svg {
        width: 16px;
        height: 16px;
    }

    .search-map-container {
        height: calc(100vh - 160px);
        height: calc(100dvh - 160px);
        min-height: 280px;
    }

    .map-info-card {
        bottom: 8px;
        width: calc(100% - 16px);
        border-radius: 12px;
    }

    .map-info-card-image,
    .map-info-card-image-placeholder {
        width: 85px;
        height: 85px;
    }

    .map-info-card-body {
        padding: 8px 10px;
    }

    .map-info-card-position {
        width: 20px;
        height: 20px;
        font-size: 10px;
    }

    .map-info-card-title {
        font-size: 14px;
        margin-bottom: 4px;
    }

    .map-info-card-rating .star {
        font-size: 12px;
    }

    .map-info-card-rating .rating-value {
        font-size: 12px;
    }

    .map-info-card-address {
        font-size: 11px;
    }

    .map-info-card-arrow {
        padding: 0 8px;
    }

    .map-info-card-arrow svg {
        width: 20px;
        height: 20px;
    }
}

/* ==========================================================================
   RESPONSIVE - MOBILE EXTRA SMALL (360px)
   ========================================================================== */

@media screen and (max-width: 360px) {
    .search-view-tab {
        padding: 8px 10px;
        font-size: 12px;
        min-height: 40px;
    }

    .search-view-tab svg {
        width: 14px;
        height: 14px;
    }

    .map-info-card-image,
    .map-info-card-image-placeholder {
        width: 70px;
        height: 70px;
    }

    .map-info-card-body {
        padding: 6px 8px;
    }

    .map-info-card-title {
        font-size: 13px;
    }
}

/* ==========================================================================
   LANDSCAPE MODE (mobile orizzontale)
   ========================================================================== */

@media screen and (max-height: 500px) and (orientation: landscape) {
    .search-map-container {
        height: calc(100vh - 120px);
        height: calc(100dvh - 120px);
        min-height: 200px;
    }

    .map-info-card {
        bottom: 5px;
        max-height: 100px;
    }

    .map-info-card-image,
    .map-info-card-image-placeholder {
        width: 80px;
        height: 80px;
    }

    .map-info-card-body {
        padding: 6px 10px;
    }

    .map-info-card-position {
        width: 18px;
        height: 18px;
        font-size: 9px;
        margin-bottom: 2px;
    }

    .map-info-card-title {
        font-size: 13px;
        margin-bottom: 2px;
    }

    .map-info-card-rating {
        margin-bottom: 0;
    }

    .map-info-card-address {
        display: none;
    }
}

/* ==========================================================================
   MARKER STYLES (custom markers numerati)
   ========================================================================== */

.custom-marker {
    background: #70c542;
    border: 3px solid #fff;
    border-radius: 50%;
    color: #fff;
    font-weight: bold;
    font-size: 12px;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    cursor: pointer;
    transition: all 0.2s ease;
}

.custom-marker:hover,
.custom-marker.selected {
    background: #ff6b35;
    transform: scale(1.2);
    z-index: 1000 !important;
}

/* ==========================================================================
   SEARCH HERE BUTTON (pulsante "Cerca qui")
   ========================================================================== */

.search-here-button {
    position: absolute;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 24px;
    background: #fff;
    color: #1f2937;
    font-size: 14px;
    font-weight: 600;
    border: none;
    border-radius: 30px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
    cursor: pointer;
    z-index: 300;
    transition: all 0.2s ease;
    -webkit-tap-highlight-color: transparent;
}

.search-here-button:hover {
    background: #70c542;
    color: #fff;
    transform: translateX(-50%) scale(1.05);
}

.search-here-button:active {
    transform: translateX(-50%) scale(0.98);
}

.search-here-button svg {
    flex-shrink: 0;
}

/* Safe area per iPhone X+ */
@supports (padding-top: env(safe-area-inset-top)) {
    .search-here-button {
        top: calc(20px + env(safe-area-inset-top));
    }
}

/* Responsive */
@media screen and (max-width: 480px) {
    .search-here-button {
        padding: 10px 18px;
        font-size: 13px;
        gap: 6px;
    }

    .search-here-button svg {
        width: 14px;
        height: 14px;
    }
}

/* ==========================================================================
   LOADING STATE
   ========================================================================== */

.search-map-loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    color: #6b7280;
    z-index: 100;
}

.search-map-loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid #e5e7eb;
    border-top-color: #70c542;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* ==========================================================================
   NO RESULTS STATE
   ========================================================================== */

.search-map-no-results {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    color: #6b7280;
    padding: 20px;
    z-index: 100;
}

.search-map-no-results svg {
    margin-bottom: 12px;
    opacity: 0.5;
}

.search-map-no-results p {
    margin: 0;
    font-size: 14px;
}

/* ==========================================================================
   DARK MODE SUPPORT (opzionale, segue preferenze sistema)
   ========================================================================== */

@media (prefers-color-scheme: dark) {
    /* Disabilita dark mode per ora - da implementare se necessario */
}

/* ==========================================================================
   REDUCED MOTION (accessibilità)
   ========================================================================== */

@media (prefers-reduced-motion: reduce) {
    .search-view-tab,
    .map-info-card,
    .custom-marker,
    .box007.map-hover-highlight {
        transition: none;
    }

    .search-map-loading-spinner {
        animation: none;
    }
}

/* ==========================================================================
   HIGH CONTRAST MODE (accessibilità)
   ========================================================================== */

@media (forced-colors: active) {
    .search-view-tab {
        border: 2px solid currentColor;
    }

    .search-view-tab.active {
        background: Highlight;
        color: HighlightText;
    }

    .map-info-card {
        border: 2px solid currentColor;
    }
}

/* ==========================================================================
   PRINT STYLES
   ========================================================================== */

@media print {
    .search-view-tabs,
    .search-map-container {
        display: none !important;
    }
}
