/**
 * Terraviva Menu - Frontend Styles
 * Mobile-first responsive design
 */

/* CSS Variables */
:root {
    --tv-primary: #E67066;
    --tv-bg: #FBEAE8;
    --tv-text: #1a1a1a;
    --tv-price: #1a1a1a;
    --tv-section-bg: #fff;
    --tv-border: #f0d0ce;
    --tv-muted: #888;
}

/* Main Container */
.tv-menu {
    background: var(--tv-bg);
    padding: 20px;
    border-radius: 8px;
    max-width: 100%;
    margin: 0 auto;
    font-family: inherit;
    line-height: 1.5;
}

/* Header */
.tv-menu-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 2px solid var(--tv-border);
    gap: 15px;
}

/* Title */
.tv-menu-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--tv-primary);
    margin: 0;
    flex: 1;
}

/* Language Switcher */
.tv-lang-switcher {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
}

.tv-lang-btn {
    padding: 6px 12px;
    background: var(--tv-section-bg);
    border: 1px solid var(--tv-border);
    border-radius: 4px;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--tv-muted);
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: inherit;
}

.tv-lang-btn:hover {
    border-color: var(--tv-primary);
    color: var(--tv-primary);
}

.tv-lang-btn.active {
    background: var(--tv-primary);
    border-color: var(--tv-primary);
    color: #fff;
}

/* Filters */
.tv-menu-filters {
    margin-bottom: 20px;
}

.tv-filter-group {
    display: flex;
    flex-wrap: nowrap;
    gap: 8px;
    overflow-x: auto;
    padding: 5px 0;
    margin-bottom: 10px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    scrollbar-color: var(--tv-border) transparent;
}

.tv-filter-group::-webkit-scrollbar {
    height: 4px;
}

.tv-filter-group::-webkit-scrollbar-track {
    background: transparent;
}

.tv-filter-group::-webkit-scrollbar-thumb {
    background: var(--tv-border);
    border-radius: 2px;
}

.tv-filter-label {
    flex-shrink: 0;
    font-size: 0.85rem;
    color: var(--tv-muted);
    align-self: center;
    margin-right: 5px;
}

.tv-filter-chip {
    flex-shrink: 0;
    padding: 8px 16px;
    background: var(--tv-section-bg);
    border: 1px solid var(--tv-border);
    border-radius: 20px;
    font-size: 0.85rem;
    color: var(--tv-text);
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
    font-family: inherit;
}

.tv-filter-chip:hover {
    border-color: var(--tv-primary);
    color: var(--tv-primary);
}

.tv-filter-chip.active {
    background: var(--tv-primary);
    border-color: var(--tv-primary);
    color: #fff;
}

.tv-allergen-chip {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
}

.tv-allergen-chip .tv-allergen-icon {
    width: 18px;
    height: 18px;
}

/* Sections */
.tv-menu-sections {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.tv-section {
    background: var(--tv-section-bg);
    border-radius: 8px;
    padding: 20px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
    transition: opacity 0.3s ease, max-height 0.3s ease;
}

.tv-section.tv-hidden {
    display: none;
}

.tv-section-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 15px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--tv-border);
}

.tv-section-title {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--tv-primary);
    margin: 0;
}

.tv-section-price {
    font-size: 1rem;
    font-weight: 700;
    color: var(--tv-price);
}

.tv-section-notes {
    font-size: 0.85rem;
    color: var(--tv-muted);
    font-style: italic;
    margin: 0 0 15px;
}

/* Dishes */
.tv-dishes {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.tv-dish {
    transition: opacity 0.3s ease, max-height 0.3s ease, padding 0.3s ease, margin 0.3s ease;
    overflow: hidden;
}

.tv-dish.tv-hidden {
    opacity: 0;
    max-height: 0;
    padding: 0;
    margin: 0;
}

.tv-dish-main {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 15px;
}

.tv-dish-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.tv-dish-name {
    font-size: 1rem;
    color: var(--tv-text);
    font-weight: 500;
}

.tv-dish-description {
    font-size: 0.85rem;
    color: var(--tv-muted);
}

.tv-dish-price {
    font-size: 1rem;
    font-weight: 700;
    color: var(--tv-price);
    white-space: nowrap;
}

/* Allergens */
.tv-dish-allergens {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
}

.tv-allergen-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    background: var(--tv-bg);
    border-radius: 50%;
    font-size: 10px;
    font-weight: 600;
    color: var(--tv-primary);
    border: 1px solid var(--tv-border);
}

/* Allergen icons - using first letters */
.tv-allergen-gluten::before { content: 'G'; }
.tv-allergen-lacteos::before { content: 'L'; }
.tv-allergen-huevos::before { content: 'H'; }
.tv-allergen-pescado::before { content: 'P'; }
.tv-allergen-marisco::before { content: 'Ma'; font-size: 8px; }
.tv-allergen-frutos_secos::before { content: 'FS'; font-size: 8px; }
.tv-allergen-soja::before { content: 'So'; font-size: 9px; }
.tv-allergen-apio::before { content: 'Ap'; font-size: 9px; }
.tv-allergen-mostaza::before { content: 'Mo'; font-size: 8px; }
.tv-allergen-sesamo::before { content: 'Se'; font-size: 9px; }
.tv-allergen-sulfitos::before { content: 'Su'; font-size: 9px; }
.tv-allergen-altramuces::before { content: 'Al'; font-size: 9px; }
.tv-allergen-moluscos::before { content: 'Ml'; font-size: 9px; }

/* Footer */
.tv-menu-footer {
    margin-top: 20px;
    padding-top: 15px;
    border-top: 1px solid var(--tv-border);
}

.tv-menu-notes {
    font-size: 0.85rem;
    color: var(--tv-muted);
    font-style: italic;
    text-align: center;
    margin: 0;
}

/* No Results Message */
.tv-no-results {
    text-align: center;
    padding: 30px 20px;
    color: var(--tv-muted);
    font-style: italic;
}

/* Error Message */
.tv-menu-error {
    text-align: center;
    padding: 20px;
    color: #d63638;
    background: #fcf0f1;
    border-radius: 4px;
}

/* Selector Styles */
.tv-selector {
    margin-bottom: 20px;
}

.tv-selector-nav {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.tv-selector-tabs .tv-selector-nav {
    border-bottom: 2px solid var(--tv-border);
    gap: 0;
}

.tv-selector-item {
    padding: 10px 20px;
    text-decoration: none;
    color: var(--tv-text);
    font-size: 0.95rem;
    transition: all 0.2s ease;
}

.tv-selector-tabs .tv-selector-item {
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
}

.tv-selector-tabs .tv-selector-item:hover,
.tv-selector-tabs .tv-selector-item.active {
    border-bottom-color: var(--tv-primary);
    color: var(--tv-primary);
}

.tv-selector-botones .tv-selector-item {
    background: var(--tv-section-bg);
    border: 1px solid var(--tv-border);
    border-radius: 4px;
}

.tv-selector-botones .tv-selector-item:hover {
    border-color: var(--tv-primary);
    color: var(--tv-primary);
}

.tv-selector-botones .tv-selector-item.active {
    background: var(--tv-primary);
    border-color: var(--tv-primary);
    color: #fff;
}

.tv-selector-dropdown {
    width: 100%;
    max-width: 300px;
    padding: 10px 15px;
    font-size: 1rem;
    border: 1px solid var(--tv-border);
    border-radius: 4px;
    background: var(--tv-section-bg);
    color: var(--tv-text);
    cursor: pointer;
}

.tv-selector-dropdown:focus {
    outline: none;
    border-color: var(--tv-primary);
}

/* Responsive - Tablet and up */
@media (min-width: 768px) {
    .tv-menu {
        padding: 30px;
    }

    .tv-menu-title {
        font-size: 1.75rem;
    }

    .tv-section {
        padding: 25px;
    }

    /* Two column layout for dishes when there are many */
    .tv-dishes.tv-two-columns {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 15px 30px;
    }

    .tv-filter-group {
        flex-wrap: wrap;
        overflow-x: visible;
    }
}

/* Responsive - Desktop */
@media (min-width: 1024px) {
    .tv-menu {
        padding: 40px;
        max-width: 900px;
    }
}

/* Print styles */
@media print {
    .tv-menu {
        background: #fff;
        box-shadow: none;
    }

    .tv-menu-filters {
        display: none;
    }

    .tv-section {
        box-shadow: none;
        border: 1px solid #ddd;
        page-break-inside: avoid;
    }

    .tv-dish {
        page-break-inside: avoid;
    }
}

/* Accessibility */
.tv-filter-chip:focus {
    outline: 2px solid var(--tv-primary);
    outline-offset: 2px;
}

.tv-filter-chip:focus:not(:focus-visible) {
    outline: none;
}

/* Scroll hint - hidden by default (only shown on mobile) */
.tv-scroll-hint {
    display: none;
}

/* Animation for filtering */
@keyframes tv-fade-in {
    from {
        opacity: 0;
        transform: translateY(-5px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.tv-dish:not(.tv-hidden) {
    animation: tv-fade-in 0.3s ease;
}

/* Mobile specific fixes */
@media (max-width: 767px) {
    /* Contenedor padre - asegurar que no bloquea el scroll */
    .tv-menu-filters {
        overflow: visible;
        overflow-x: visible;
    }

    /* 1. CATEGORÍAS - scroll horizontal */
    .tv-section-filters {
        display: flex !important;
        flex-wrap: nowrap !important;
        overflow-x: scroll !important;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        -ms-overflow-style: none;
        padding-bottom: 8px;
        margin: 0 -20px;
        padding-left: 20px;
        padding-right: 20px;
        position: relative;
    }

    .tv-section-filters::-webkit-scrollbar {
        display: none;
        height: 0;
        width: 0;
    }

    .tv-section-filters .tv-filter-chip {
        flex: 0 0 auto !important;
        white-space: nowrap !important;
    }

    /* Indicador de scroll horizontal */
    .tv-scroll-hint {
        display: flex !important;
        flex: 0 0 auto;
        align-items: center;
        gap: 4px;
        font-size: 0.75rem;
        color: var(--tv-muted);
        padding: 4px 8px;
        animation: tv-hint-pulse 1.5s ease-in-out infinite;
    }

    .tv-scroll-hint::after {
        content: '→';
        font-size: 1rem;
    }

    .tv-scroll-hint.tv-hidden {
        display: none !important;
    }

    @keyframes tv-hint-pulse {
        0%, 100% { opacity: 0.6; transform: translateX(0); }
        50% { opacity: 1; transform: translateX(3px); }
    }

    /* 2. ALÉRGENOS - wrap en lugar de desbordarse */
    .tv-allergen-filters {
        flex-wrap: wrap;
    }

    .tv-allergen-filters .tv-allergen-chip {
        flex-shrink: 0;
        white-space: nowrap;
    }

    /* 3. FILA NOMBRE + PRECIO */
    .tv-dish-main {
        display: flex;
        justify-content: space-between;
        align-items: flex-start;
    }

    .tv-dish-info {
        flex: 1;
        min-width: 0;
    }

    .tv-dish-name {
        word-wrap: break-word;
    }

    .tv-dish-price {
        flex-shrink: 0;
        white-space: nowrap;
        margin-left: 10px;
    }
}
