/* ===============================
   VARIABLES CSS
   =============================== */
:root {
    --index-font: system-ui;
    --index-color: #4CAF50;
    --hover-color: #45a049;
    --primary-color: #ffffff;
    --secondary-color: #333;
    --border-radius: 15px;
    --box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    --transition: 0.3s ease;
    --button-size: 3.5rem;
    --max-book-width: 350px;
    --max-grid-width: 1400px;
    --transition-fast: 150ms;
    --transition-main: 250ms;
}

/* ===============================
   RESET Y BASE
   =============================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--index-font);
    background-color: #f8f9fa;
    line-height: 1.6;
}

/* ===============================
   UTILITY CLASSES
   =============================== */
.hidden {
    display: none;
}

/* ===============================
   HEADER & MENU PRINCIPAL
   =============================== */
.menu {
    position: relative;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1000;
    background-color: var(--primary-color);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
    transition: var(--transition);
    margin-left: clamp(0%, 10%, 10%);
    margin-right: clamp(0%, 10%, 10%);
}

.menu-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: clamp(4px, 1vw, 8px);
    height: clamp(55px, 10vw, 80px);
}

/* ===============================
   LOGO
   =============================== */
.logo {
    display: flex;
    align-items: center;
    flex-shrink: 0;
}

.logo img {
    height: clamp(25px, 5vw, 40px);
}

/* ===============================
   COMPONENTE DE BÚSQUEDA
   =============================== */
.search-container {
    display: flex;
    align-items: center;
    position: relative;
    width: clamp(70%, 60%, 60%);
    max-width: 600px;
    margin: 0 auto;
}

.search-container input[type="text"] {
    padding: clamp(8px, 1.5vw, 10px) clamp(30px, 5vw, 40px);
    font-size: clamp(13px, 2vw, 16px);
    border-radius: 25px;
    border: 1px solid #ccc;
    outline: none;
    transition: all 0.3s ease;
    width: 100%;
}

.search-container input[type="text"]:focus {
    border-color: var(--index-color);
}

/* ===============================
   RESULTADOS DE BÚSQUEDA
   =============================== */
.search-results {
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    max-width: 600px;
    background: rgba(255, 255, 255, 0.95);
    max-height: 360px;
    overflow-y: auto;
    z-index: 1001;
    border: 1px solid #ccc;
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.2);
    border-radius: 10px;
    margin-top: 10px;
    display: none;
}

.search-results ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.search-results li {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: clamp(6px, 1.5vw, 8px) clamp(8px, 2vw, 12px);
    border-bottom: 1px solid #ddd;
    cursor: pointer;
}

.search-results li:hover {
    background-color: #f2f2f2;
}

/* ===============================
   BARRA DE NAVEGACIÓN
   =============================== */
.menu-navbar {
    display: flex;
    align-items: center;
    padding: clamp(4px, 1.5vw, 10px);
    border-top: 1px solid #f0f0f0;
}

.navbar {
    display: flex;
    gap: clamp(4px, 1.5vw, 10px);
    align-items: center;
    flex-direction: row;
    width: 100%;
    justify-content: center;
    flex-wrap: wrap;
}

.navbar a {
    color: var(--secondary-color);
    text-decoration: none;
    font-weight: 400;
    font-size: clamp(11px, 2vw, 16px);
    padding: clamp(4px, 1vw, 8px) clamp(6px, 1.5vw, 12px);
    letter-spacing: 0.3px;
    font-family: var(--index-font);
    transition: color var(--transition);
    min-height: 44px;
    display: flex;
    align-items: center;
    white-space: nowrap;
}

.navbar a:hover {
    color: var(--index-color);
}

.navbar a.active {
    color: var(--index-color);
    font-weight: 600;
}

/* ===============================
   CONTENIDO PRINCIPAL
   =============================== */
.contenido {
    font-family: var(--index-font);
    padding-top: 1rem;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    margin: 0;
    margin-left: clamp(0%, 10%, 10%);
    margin-right: clamp(0%, 10%, 10%);
    border-left: 1px solid #f0f0f0;
    border-right: 1px solid #f0f0f0;
    background-color: white;
}

.section {
    background-color: var(--primary-color);
    text-align: center;
    border-radius: var(--border-radius);
    opacity: 0;
    transform: translateY(8px);
    animation: sectionEnter 0.5s 0.1s forwards;
    padding: clamp(1rem, 3vw, 2rem);
}

.section-subtitle {
    color: #555;
    font-size: clamp(1.1rem, 2.5vw, 1.4rem);
    font-weight: 500;
    text-align: center;
    margin: 1rem 0 1.5rem 0;
    opacity: 0;
    animation: titleEnter 0.4s ease-out 0.15s forwards;
}

.titulo {
    color: #2c3e50;
    text-align: center;
    margin: 0 0 2.5rem 0;
    padding: 1rem 0;
    font-size: clamp(1.3rem, 3vw, 1.65rem);
    font-weight: 600;
    font-family: 'Georgia', serif;
    letter-spacing: 0.3px;
    opacity: 0;
    animation: titleEnter 0.4s ease-out 0.15s forwards;
}

.centered-container {
    max-width: var(--max-grid-width);
    display: contents;
}

.book-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(clamp(140px, 25vw, 250px), 1fr));
    gap: 12px;
    justify-content: center;
    padding: 2rem;
    margin-bottom: 2rem;
}

.book-item {
    width: 100%;
    max-width: var(--max-book-width);
    box-shadow: var(--box-shadow);
    border-radius: var(--border-radius);
    overflow: hidden;
    transition: all var(--transition-main) ease;
    opacity: 0;
    transform: translateY(12px);
    animation: bookAppear 0.5s forwards;
}

.book-item:nth-child(1) { animation-delay: 0.05s; }
.book-item:nth-child(2) { animation-delay: 0.1s; }
.book-item:nth-child(3) { animation-delay: 0.15s; }
.book-item:nth-child(4) { animation-delay: 0.2s; }
.book-item:nth-child(5) { animation-delay: 0.25s; }
.book-item:nth-child(n+6) { animation-delay: 0.3s; }

.book-item img {
    width: 100%;
    height: clamp(200px, 40vw, 335px);
    display: block;
    object-fit: cover;
    transition: transform var(--transition-main) ease;
}

.book-item:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.15);
}

.book-item:hover img {
    transform: scale(1.02);
}

/* ===============================
   SECCIONES DINÁMICAS
   =============================== */
.loading {
    text-align: center;
    padding: 2rem;
    font-size: clamp(1rem, 2vw, 1.2rem);
    color: var(--secondary-color);
}

.sucursales-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(clamp(250px, 40vw, 300px), 1fr));
    gap: clamp(1rem, 3vw, 2rem);
    padding: 0 clamp(1rem, 3vw, 2rem);
    margin-bottom: 2rem;
}

.sucursal-item {
    background-color: var(--primary-color);
    padding: clamp(1rem, 3vw, 2rem);
    border-radius: var(--border-radius);
    box-shadow: var(--box-shadow);
    text-align: left;
    transition: transform var(--transition);
}

.sucursal-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.15);
}

.sucursal-item h3 {
    color: var(--index-color);
    margin-bottom: 1rem;
    font-size: clamp(1.1rem, 2.5vw, 1.3rem);
}

.sucursal-item p {
    margin-bottom: 0.5rem;
    color: var(--secondary-color);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: clamp(0.9rem, 2vw, 1rem);
}

.book-card {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border: 1px solid #ddd;
    border-radius: 5px;
    margin: 10px;
    padding: 10px;
    transition: box-shadow 0.3s ease;
    background-color: #fff;
}

.book-card:hover {
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.2);
}

.book-details {
    flex-grow: 1;
}

.book-card h3,
.book-card h4,
.book-card h5 {
    margin: 0;
    padding: 0;
}

.consultar-button {
    background-color: var(--index-color);
    color: white;
    border: none;
    border-radius: 5px;
    padding: 10px 20px;
    cursor: pointer;
    transition: background-color 0.3s ease;
    font-size: 16px;
}

.consultar-button:hover {
    background-color: var(--hover-color);
}

.consultar-button:hover {
    background-color: var(--hover-color);
}

/* ===============================
   WHATSAPP FLOTANTE
   =============================== */
.whatsapp-float {
    position: fixed;
    bottom: clamp(0.5rem, 2vw, 1.25rem);
    right: clamp(0.5rem, 2vw, 1.25rem);
    z-index: 1000;
    border-radius: 50%;
    padding: clamp(0.2rem, 1vw, 0.5rem);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
    opacity: 0;
    animation: whatsappAppear 0.6s ease-out 0.8s forwards;
    text-decoration: none;
}

.whatsapp-icon {
    width: clamp(2.5rem, 6vw, var(--button-size));
    height: clamp(2.5rem, 6vw, var(--button-size));
    border-radius: 50%;
    display: block;
    transition: transform var(--transition-fast);
}

.whatsapp-float:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(37, 211, 102, 0.4);
}

.whatsapp-float:hover .whatsapp-icon {
    transform: scale(1.1);
}

.whatsapp-float:focus {
    outline: 2px solid #25D366;
    outline-offset: 2px;
}

.whatsapp-float:focus:not(:focus-visible) {
    outline: none;
}

/* ===============================
   FOOTER MEJORADO
   =============================== */
footer {
    margin-top: auto;
    opacity: 0;
    animation: footerFade 0.4s ease-out 0.6s forwards;
    margin-left: 10%;
    margin-right: 10%;
}

.footer-content {
    background-color: var(--secondary-color);
    color: var(--primary-color);
    padding: clamp(1rem, 3vw, 2rem) clamp(1rem, 2vw, 1.5rem);
    font-family: var(--index-font);
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: clamp(1rem, 3vw, 2rem);
    align-items: start;
    text-align: center;
}

.footer-contact h3,
.footer-social h3 {
    color: var(--index-color);
    margin-bottom: 1rem;
    font-size: clamp(1rem, 2.5vw, 1.2rem);
}

.footer-contact p {
    margin-bottom: 0.5rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    justify-content: center;
    font-size: clamp(0.8rem, 2vw, 0.9rem);
}

.footer-contact a {
    color: var(--primary-color);
    text-decoration: none;
    transition: color var(--transition-fast);
}

.footer-contact a:hover {
    color: var(--index-color);
}

.footer-info p {
    margin-bottom: 0.5rem;
    font-size: clamp(0.8rem, 2vw, 0.9rem);
}

.social-icons {
    display: flex;
    justify-content: center;
    gap: 1rem;
    flex-wrap: wrap;
}

.social-link {
    color: var(--primary-color);
    transition: all var(--transition-fast);
    padding: 0.5rem;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
}

.social-link:hover {
    color: var(--index-color);
    transform: translateY(-2px);
    background-color: rgba(76, 175, 80, 0.1);
}

/* ===============================
   ANIMACIONES
   =============================== */
@keyframes sectionEnter {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes titleEnter {
    to {
        opacity: 1;
    }
}

@keyframes bookAppear {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes footerFade {
    to { opacity: 1; }
}

@keyframes whatsappAppear {
    0% {
        opacity: 0;
        transform: translateY(20px) scale(0.8);
    }
    100% {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* ===============================
   PREFERENCIAS DE ACCESIBILIDAD
   =============================== */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
    
    .book-item,
    .section,
    .titulo,
    .whatsapp-float {
        animation: none;
        opacity: 1;
        transform: translateY(0);
    }
}

@media (prefers-contrast: high) {
    .whatsapp-float {
        border: 2px solid #ffffff;
    }
}

/* ===============================
   MEDIA QUERY ÚNICO < 800px
   =============================== */
@media screen and (max-width: 800px) {
    /* Layout más compacto para móviles */
    .book-grid {
        grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
        gap: clamp(10px, 3vw, 25px);
    }
    
    /* Navegación más compacta */
    .navbar {
        justify-content: space-around;
        gap: clamp(2px, 1vw, 6px);
    }
    
    .navbar a {
        font-size: clamp(10px, 2vw, 14px);
        padding: clamp(3px, 1vw, 6px) clamp(4px, 1vw, 8px);
        letter-spacing: 0.1px;
    }
    
    /* Search más ancho en móviles */
    .search-container {
        width: clamp(85%, 90%, 95%);
    }
    
    /* Ajustes específicos para táctil */
    .book-item:hover {
        transform: none;
        box-shadow: var(--box-shadow);
    }
    
    .book-item:hover img {
        transform: none;
    }
    
    .whatsapp-float:hover {
        transform: none;
        box-shadow: 0 4px 12px rgba(37, 211, 102, 0.3);
    }
    
    .whatsapp-float:hover .whatsapp-icon {
        transform: none;
    }
    
    .whatsapp-float:active {
        transform: scale(0.95);
        transition: transform 0.1s ease;
    }
}