/**
 * Receiteria Smart Search - CSS
 * 
 * DESIGN SYSTEM:
 * - THUMB-FIRST: Otimizado para uso com polegar
 * - Mobile-first (90% do tráfego)
 * - Touch targets: mínimo 48px
 * - Bottom sheet pattern em mobile
 * - Safe areas para notch/home indicator
 * 
 * CORES RECEITERIA:
 * --rc-primary: #EB4F37 (laranja/vermelho)
 * --rc-secondary: #F7EFE4 (bege claro)
 * --rc-dark: #53240C (marrom)
 * --rc-bg: #FBF7F1 (fundo)
 */

:root {
    --rss-primary: #EB4F37;
    --rss-primary-hover: #d94430;
    --rss-primary-tap: #c73d2b;
    --rss-secondary: #F7EFE4;
    --rss-dark: #53240C;
    --rss-bg: #FBF7F1;
    --rss-white: #FFFFFF;
    --rss-gray-50: #fafafa;
    --rss-gray-100: #f8f9fa;
    --rss-gray-200: #e9ecef;
    --rss-gray-300: #dee2e6;
    --rss-gray-400: #ced4da;
    --rss-gray-600: #6c757d;
    --rss-shadow: 0 4px 20px rgba(83, 36, 12, 0.15);
    --rss-shadow-lg: 0 -4px 32px rgba(83, 36, 12, 0.2);
    --rss-radius: 16px;
    --rss-radius-sm: 8px;
    --rss-radius-xl: 24px;
    --rss-transition: 0.2s ease;
    --rss-transition-fast: 0.1s ease;
    
    /* Touch targets - Google recommends 48px minimum */
    --rss-touch-target: 48px;
    --rss-touch-target-lg: 56px;
    
    /* Safe areas */
    --rss-safe-bottom: env(safe-area-inset-bottom, 0px);
    --rss-safe-top: env(safe-area-inset-top, 0px);
}

/* ============================================
   CONTAINER PRINCIPAL
   ============================================ */

.rss-search-container {
    position: relative;
    width: 100%;
    max-width: 600px;
}

.rss-search-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

/* ============================================
   INPUT DE BUSCA
   ============================================ */

.rss-search-input {
    width: 100%;
    height: var(--rss-touch-target);
    padding: 0 52px 0 20px;
    font-size: 16px; /* Previne zoom em iOS */
    font-family: inherit;
    border: 2px solid var(--rss-gray-200);
    border-radius: var(--rss-radius);
    background: var(--rss-white);
    color: var(--rss-dark);
    outline: none;
    transition: border-color var(--rss-transition), box-shadow var(--rss-transition);
    -webkit-appearance: none;
    appearance: none;
    /* Remove highlight de tap no iOS */
    -webkit-tap-highlight-color: transparent;
}

.rss-search-input::placeholder {
    color: var(--rss-gray-600);
}

.rss-search-input:focus {
    border-color: var(--rss-primary);
    box-shadow: 0 0 0 3px rgba(235, 79, 55, 0.15);
}

/* Botão de busca */
.rss-search-btn {
    position: absolute;
    right: 4px;
    top: 50%;
    transform: translateY(-50%);
    width: 40px;
    height: 40px;
    border: none;
    background: var(--rss-primary);
    color: var(--rss-white);
    border-radius: var(--rss-radius-sm);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--rss-transition-fast), transform var(--rss-transition-fast);
    -webkit-tap-highlight-color: transparent;
}

.rss-search-btn:active {
    background: var(--rss-primary-tap);
    transform: translateY(-50%) scale(0.95);
}

.rss-search-btn i {
    font-size: 16px;
}

/* Loading state */
.rss-search-container.rss-loading .rss-search-btn i {
    animation: rss-spin 0.8s linear infinite;
}

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

/* ============================================
   DROPDOWN - DESKTOP
   ============================================ */

.rss-dropdown {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    right: 0;
    background: var(--rss-white);
    border-radius: var(--rss-radius);
    box-shadow: var(--rss-shadow);
    z-index: 9999;
    max-height: 70vh;
    overflow-y: auto;
    overflow-x: hidden;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: opacity var(--rss-transition), transform var(--rss-transition), visibility var(--rss-transition);
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

.rss-dropdown.rss-visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

/* ============================================
   SEÇÕES DO DROPDOWN
   ============================================ */

.rss-section {
    padding: 12px 16px;
}

.rss-section:not(:last-child) {
    border-bottom: 1px solid var(--rss-gray-200);
}

.rss-section-title {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--rss-gray-600);
    margin-bottom: 10px;
    padding-left: 4px;
}

/* ============================================
   ITEM DE RESULTADO (RECEITA)
   ============================================ */

.rss-result-item {
    margin: 0 -16px;
}

.rss-result-item a {
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: var(--rss-touch-target);
    padding: 8px 16px;
    text-decoration: none;
    color: inherit;
    transition: background var(--rss-transition-fast);
    -webkit-tap-highlight-color: transparent;
}

/* Active state para feedback imediato */
.rss-result-item a:active {
    background: var(--rss-secondary);
    transition: none;
}

.rss-result-item.rss-selected a {
    background: var(--rss-secondary);
}

/* Thumbnail */
.rss-thumb {
    flex-shrink: 0;
    width: 56px;
    height: 56px;
    border-radius: var(--rss-radius-sm);
    overflow: hidden;
    background: var(--rss-gray-200);
}

.rss-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.rss-thumb-placeholder {
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, var(--rss-gray-200), var(--rss-gray-100));
}

/* Info */
.rss-info {
    flex: 1;
    min-width: 0;
}

.rss-title {
    font-size: 14px;
    font-weight: 500;
    color: var(--rss-dark);
    line-height: 1.3;
    margin-bottom: 4px;
    /* Truncate */
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.rss-title mark {
    background: rgba(235, 79, 55, 0.15);
    color: var(--rss-primary);
    padding: 0 2px;
    border-radius: 2px;
}

.rss-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
}

.rss-time {
    color: var(--rss-gray-600);
    display: flex;
    align-items: center;
    gap: 4px;
}

.rss-time i {
    font-size: 10px;
}

/* Badge passo-a-passo */
.rss-badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    background: var(--rss-primary);
    color: var(--rss-white);
    border-radius: 10px;
}

/* ============================================
   CHIPS (SUGESTÕES/CATEGORIAS)
   ============================================ */

.rss-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.rss-chip {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 36px;
    padding: 8px 14px;
    font-size: 13px;
    font-weight: 500;
    color: var(--rss-primary);
    background: var(--rss-secondary);
    border-radius: 20px;
    text-decoration: none;
    transition: background var(--rss-transition-fast), color var(--rss-transition-fast), transform var(--rss-transition-fast);
    white-space: nowrap;
    -webkit-tap-highlight-color: transparent;
}

.rss-chip:active {
    background: var(--rss-primary);
    color: var(--rss-white);
    transform: scale(0.96);
}

.rss-chip-category {
    background: var(--rss-gray-100);
    color: var(--rss-dark);
}

.rss-chip-category:active {
    background: var(--rss-dark);
    color: var(--rss-white);
}

/* ============================================
   GRID DE CATEGORIAS (EMPTY STATE)
   ============================================ */

.rss-category-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}

.rss-category-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: var(--rss-touch-target-lg);
    padding: 12px 8px;
    background: var(--rss-secondary);
    border-radius: var(--rss-radius-sm);
    text-decoration: none;
    transition: background var(--rss-transition-fast), transform var(--rss-transition-fast);
    -webkit-tap-highlight-color: transparent;
}

.rss-category-item:active {
    background: var(--rss-primary);
    transform: scale(0.96);
}

.rss-category-item:active .rss-category-name {
    color: var(--rss-white);
}

.rss-category-icon {
    font-size: 24px;
    margin-bottom: 4px;
}

.rss-category-name {
    font-size: 12px;
    font-weight: 500;
    color: var(--rss-dark);
    text-align: center;
    transition: color var(--rss-transition-fast);
}

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

.rss-no-results {
    padding: 30px 20px;
    text-align: center;
    color: var(--rss-gray-600);
    font-size: 14px;
}

/* ============================================
   MOBILE - THUMB-FIRST BOTTOM SHEET
   ============================================ */

@media (max-width: 768px) {
    /* Overlay de fundo */
    .rss-search-container.rss-open::before {
        content: '';
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 9998;
        opacity: 0;
        animation: rss-fadeOverlay 0.2s ease forwards;
    }
    
    @keyframes rss-fadeOverlay {
        to { opacity: 1; }
    }
    
    /* Bottom Sheet */
    .rss-dropdown {
        position: fixed;
        top: auto;
        bottom: 0;
        left: 0;
        right: 0;
        max-height: 85vh;
        max-height: 85dvh; /* Dynamic viewport height */
        border-radius: var(--rss-radius-xl) var(--rss-radius-xl) 0 0;
        box-shadow: var(--rss-shadow-lg);
        transform: translateY(100%);
        padding-bottom: calc(var(--rss-safe-bottom) + 8px);
        /* Scroll snap para seções */
        scroll-snap-type: y proximity;
    }
    
    .rss-dropdown.rss-visible {
        transform: translateY(0);
        animation: rss-slideUp 0.3s cubic-bezier(0.32, 0.72, 0, 1);
    }
    
    @keyframes rss-slideUp {
        from { transform: translateY(100%); }
        to { transform: translateY(0); }
    }
    
    /* Handle de arraste (visual) */
    .rss-dropdown::before {
        content: '';
        position: sticky;
        top: 0;
        display: block;
        width: 36px;
        height: 4px;
        margin: 12px auto 8px;
        background: var(--rss-gray-300);
        border-radius: 2px;
        z-index: 1;
    }
    
    /* Seções com scroll snap */
    .rss-section {
        padding: 16px 20px;
        scroll-snap-align: start;
    }
    
    .rss-section-title {
        font-size: 12px;
        margin-bottom: 14px;
    }
    
    /* Input maior para toque */
    .rss-search-input {
        height: var(--rss-touch-target-lg);
        padding: 0 60px 0 20px;
        font-size: 17px;
        border-radius: var(--rss-radius);
    }
    
    .rss-search-btn {
        width: var(--rss-touch-target);
        height: var(--rss-touch-target);
        right: 4px;
        border-radius: 12px;
    }
    
    .rss-search-btn i {
        font-size: 18px;
    }
    
    /* Itens de resultado - thumb-friendly */
    .rss-result-item {
        margin: 0 -20px;
    }
    
    .rss-result-item a {
        min-height: var(--rss-touch-target-lg);
        padding: 12px 20px;
        gap: 14px;
    }
    
    /* Thumbnail maior em mobile */
    .rss-thumb {
        width: 72px;
        height: 72px;
        border-radius: 12px;
    }
    
    .rss-title {
        font-size: 16px;
        line-height: 1.35;
        margin-bottom: 6px;
    }
    
    .rss-meta {
        gap: 10px;
        font-size: 13px;
    }
    
    .rss-badge {
        padding: 3px 10px;
        font-size: 11px;
    }
    
    /* Chips maiores para toque */
    .rss-chips {
        gap: 10px;
        /* Scroll horizontal em mobile */
        flex-wrap: nowrap;
        overflow-x: auto;
        overflow-y: hidden;
        scroll-snap-type: x mandatory;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        margin: 0 -20px;
        padding: 0 20px 8px;
    }
    
    .rss-chips::-webkit-scrollbar {
        display: none;
    }
    
    .rss-chip {
        min-height: var(--rss-touch-target);
        padding: 12px 18px;
        font-size: 15px;
        border-radius: var(--rss-radius-xl);
        scroll-snap-align: start;
        flex-shrink: 0;
    }
    
    /* Grid de categorias - 2 colunas em mobile para targets maiores */
    .rss-category-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
    }
    
    .rss-category-item {
        min-height: 80px;
        padding: 16px 12px;
        border-radius: var(--rss-radius);
    }
    
    .rss-category-icon {
        font-size: 32px;
        margin-bottom: 6px;
    }
    
    .rss-category-name {
        font-size: 14px;
    }
    
    /* Receitas rápidas - cards horizontais scrolláveis */
    .rss-section.rss-quick {
        padding-bottom: calc(var(--rss-safe-bottom) + 20px);
    }
    
    .rss-quick .rss-result-item {
        margin: 0;
    }
    
    .rss-quick .rss-result-item + .rss-result-item {
        margin-top: 8px;
    }
    
    /* No results com padding maior */
    .rss-no-results {
        padding: 40px 24px calc(var(--rss-safe-bottom) + 40px);
        font-size: 15px;
    }
}

/* ============================================
   MOBILE LANDSCAPE - Ajustes para tela deitada
   ============================================ */

@media (max-width: 768px) and (orientation: landscape) {
    .rss-dropdown {
        max-height: 70vh;
    }
    
    .rss-category-grid {
        grid-template-columns: repeat(3, 1fr);
    }
    
    .rss-thumb {
        width: 56px;
        height: 56px;
    }
}

/* ============================================
   TELAS PEQUENAS (iPhone SE, etc)
   ============================================ */

@media (max-width: 375px) {
    .rss-section {
        padding: 14px 16px;
    }
    
    .rss-result-item a {
        padding: 10px 16px;
    }
    
    .rss-thumb {
        width: 64px;
        height: 64px;
    }
    
    .rss-title {
        font-size: 15px;
    }
    
    .rss-chip {
        padding: 10px 14px;
        font-size: 14px;
    }
    
    .rss-category-grid {
        gap: 8px;
    }
    
    .rss-category-item {
        min-height: 70px;
        padding: 12px 8px;
    }
    
    .rss-category-icon {
        font-size: 28px;
    }
    
    .rss-category-name {
        font-size: 13px;
    }
}

/* ============================================
   HEADER INTEGRATION
   Estilos para o search no header do tema
   ============================================ */

/* Desktop header search */
.navbar .rss-search-container {
    max-width: 300px;
}

.navbar .rss-search-input {
    height: 40px;
    padding: 0 44px 0 16px;
    font-size: 14px;
    border-radius: 24px;
}

.navbar .rss-search-btn {
    width: 32px;
    height: 32px;
    right: 4px;
    border-radius: 50%;
}

.navbar .rss-dropdown {
    min-width: 380px;
    right: auto;
}

/* Mobile offcanvas search */
#offcanvasSearch .rss-search-container {
    width: 100%;
    max-width: 100%;
}

#offcanvasSearch .rss-search-input {
    border-radius: var(--rss-radius-sm);
}

#offcanvasSearch .rss-dropdown {
    position: relative;
    top: 12px;
    box-shadow: none;
    border: 1px solid var(--rss-gray-200);
    max-height: calc(100vh - 120px);
}

/* ============================================
   ANIMAÇÕES
   ============================================ */

@media (prefers-reduced-motion: no-preference) {
    .rss-result-item {
        animation: rss-fadeIn 0.2s ease;
        animation-fill-mode: both;
    }
    
    .rss-result-item:nth-child(1) { animation-delay: 0ms; }
    .rss-result-item:nth-child(2) { animation-delay: 40ms; }
    .rss-result-item:nth-child(3) { animation-delay: 80ms; }
    .rss-result-item:nth-child(4) { animation-delay: 120ms; }
    .rss-result-item:nth-child(5) { animation-delay: 160ms; }
}

@keyframes rss-fadeIn {
    from {
        opacity: 0;
        transform: translateX(-8px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* ============================================
   HAPTIC FEEDBACK STATES (para JS integração)
   Classes usadas pelo JavaScript para feedback
   ============================================ */

.rss-haptic-light,
.rss-haptic-medium,
.rss-haptic-heavy {
    /* Placeholder para JS - pode ser usado para animações visuais */
    will-change: transform;
}

/* ============================================
   DARK MODE SUPPORT
   ============================================ */

@media (prefers-color-scheme: dark) {
    .rss-search-container[data-theme="auto"] {
        --rss-white: #1a1a1a;
        --rss-gray-50: #222;
        --rss-gray-100: #2a2a2a;
        --rss-gray-200: #3a3a3a;
        --rss-gray-300: #4a4a4a;
        --rss-gray-400: #5a5a5a;
        --rss-gray-600: #9a9a9a;
        --rss-dark: #f5f5f5;
        --rss-secondary: #2a2a2a;
        --rss-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
        --rss-shadow-lg: 0 -4px 32px rgba(0, 0, 0, 0.5);
    }
}

/* ============================================
   PRINT (esconde dropdown)
   ============================================ */

@media print {
    .rss-dropdown {
        display: none !important;
    }
}

/* ============================================
   ACCESSIBILITY
   ============================================ */

/* Focus visível para navegação por teclado */
.rss-search-input:focus-visible {
    outline: 2px solid var(--rss-primary);
    outline-offset: 2px;
}

.rss-result-item a:focus-visible,
.rss-chip:focus-visible,
.rss-category-item:focus-visible {
    outline: 2px solid var(--rss-primary);
    outline-offset: -2px;
}

/* Reduz movimento para usuários sensíveis */
@media (prefers-reduced-motion: reduce) {
    .rss-dropdown,
    .rss-result-item,
    .rss-chip,
    .rss-category-item,
    .rss-search-btn {
        transition: none !important;
        animation: none !important;
    }
}
