/**
 * Estilos globales - BEM
 * Block__Element--Modifier
 */

/* ===============================
   VARIABLES
   =============================== */
:root {
    /* Colores - Bookstore palette */
    --color-primary: #8b7355;
    --color-primary-dark: #6b5645;
    --color-white: #ffffff;
    --color-dark: #2c2c2c;
    --color-gray: #666666;
    --color-light: #faf9f7;
    --color-border: #e8e5e0;
    --color-paper: #faf9f7;
    
    /* Tipografía */
    --font-main: Georgia, 'Times New Roman', serif;
    --font-title: Georgia, serif;
    
    /* Espaciado */
    --spacing-xs: 0.25rem;
    --spacing-sm: 0.5rem;
    --spacing-md: 1rem;
    --spacing-lg: 1.75rem;
    --spacing-xl: 2.5rem;
    --spacing-2xl: 3.5rem;
    
    /* Tamaños */
    --sidebar-margin: 10%;
    --max-width: 1400px;
    --border-radius: 8px;
    --border-radius-lg: 12px;
    
    /* Efectos */
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.1);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.15);
    --transition: 0.25s ease;
}

/* ===============================
   RESET
   =============================== */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
    overflow-x: hidden;
}

body {
    font-family: var(--font-main);
    font-size: 16px; /* Base size for better readability */
    background-color: var(--color-white);
    color: var(--color-dark);
    line-height: 1.7;
    min-height: 100vh;
    overflow-x: hidden;
    width: 100%;
}

a {
    color: inherit;
    text-decoration: none;
}

img {
    max-width: 100%;
    height: auto;
    display: block;
}

/* ===============================
   HEADER (Block)
   =============================== */
.header {
    background: var(--color-white);
    position: sticky;
    top: 0;
    z-index: 100;
    border-bottom: 1px solid var(--color-border);
    width: 100%;
    overflow: hidden;
}

.header__bar {
    display: flex;
    align-items: center;
    padding: 1rem 2rem;
    gap: 2rem;
    max-width: 1600px;
    margin: 0 auto;
    width: 100%;
}

.header__logo {
    flex-shrink: 0;
}

.header__logo img {
    height: 40px;
}

/* Mobile Menu Toggle Button */
.header__menu-toggle {
    display: none;
    background: none;
    border: none;
    padding: 0.5rem;
    cursor: pointer;
    color: var(--color-dark);
    min-height: 44px;
    min-width: 44px;
    align-items: center;
    justify-content: center;
    border-radius: var(--border-radius);
    transition: background-color var(--transition);
}

.header__menu-toggle:hover {
    background-color: var(--color-light);
}

.header__menu-toggle svg {
    width: 24px;
    height: 24px;
}

.header__menu-toggle .icon-close {
    display: none;
}

.header__menu-toggle.active .icon-menu {
    display: none;
}

.header__menu-toggle.active .icon-close {
    display: block;
}

/* Hide search when home is active (use visibility to prevent layout shift) */
.header--home .search {
    visibility: hidden;
    opacity: 0;
    pointer-events: none;
}

.search {
    transition: opacity 0.2s ease, visibility 0.2s ease;
}

/* ===============================
   SEARCH (Block)
   =============================== */
.search {
    position: relative;
    flex: 1;
    max-width: 500px;
}

.search__input {
    width: 100%;
    padding: 0.85rem 1rem;
    padding-left: 2.75rem;
    font-size: 1rem;
    border: 2px solid transparent;
    border-radius: 50px;
    background: var(--color-light);
    outline: none;
    transition: all 0.3s ease;
    min-height: 44px; /* Touch target accesible */
}

.search__input::placeholder {
    color: var(--color-gray);
    opacity: 0.7;
}

.search__input:hover {
    background: #f0f1f3;
}

.search__input:focus {
    background: var(--color-white);
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(139, 115, 85, 0.1);
}

.search__button {
    position: absolute;
    left: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    padding: 0.5rem;
    cursor: pointer;
    color: var(--color-gray);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
}

.search__input:focus ~ .search__button,
.search__button:hover {
    color: var(--color-primary);
}

.search__results {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    right: 0;
    min-width: min(400px, 90vw);
    background: var(--color-white);
    border: none;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
    max-height: 450px;
    overflow-y: auto;
    display: none;
    z-index: 200;
    animation: slideDown 0.2s ease;
}

@keyframes slideDown {
    from { 
        opacity: 0;
        transform: translateY(-10px);
    }
    to { 
        opacity: 1;
        transform: translateY(0);
    }
}

/* ===============================
   NAV (Block)
   =============================== */
.nav {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex: 1;
}

.nav__link {
    padding: 0.6rem 1rem;
    font-family: var(--font-main);
    font-size: 1rem;
    font-weight: 400;
    color: var(--color-gray);
    letter-spacing: 0.02em;
    transition: color 0.3s ease;
    white-space: nowrap;
    min-height: 44px; /* Touch target accesible */
    display: inline-flex;
    align-items: center;
}

.nav__link:hover {
    color: var(--color-dark);
}

.nav__link--active {
    color: var(--color-primary);
}

/* ===============================
   MAIN (Block)
   =============================== */
.main {
    background-color: var(--color-white);
    min-height: calc(100vh - 200px); /* Header + Footer aprox */
    max-width: 1600px;
    margin: 0 auto;
    overflow-x: hidden;
}

/* ===============================
   SECTION (Block)
   =============================== */
.section {
    padding: var(--spacing-xl) var(--spacing-lg);
    animation: fadeIn 0.4s ease;
}

.section__title {
    font-family: var(--font-title);
    font-size: clamp(1.5rem, 4vw, 2rem);
    font-weight: 400;
    color: #2c2c2c;
    text-align: center;
    margin-bottom: 2rem;
    padding-top: 2rem;
}

/* ===============================
   GRID (Block)
   =============================== */
.grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: var(--spacing-xl);
    padding: var(--spacing-xl);
    max-width: var(--max-width);
    margin: 0 auto;
}

.grid__item {
    position: relative;
    border-radius: var(--border-radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), 
                box-shadow 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    background: var(--color-light);
}

.grid__item::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(to top, rgba(0,0,0,0.3) 0%, transparent 50%);
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
}

.grid__item img,
.grid__item > div {
    width: 100%;
    aspect-ratio: 2/3;
    object-fit: cover;
    transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

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

.grid__item:hover::after {
    opacity: 1;
}

.grid__item:hover img {
    transform: scale(1.05);
}

/* ===============================
   CARD (Block) - Search Results
   =============================== */
.card {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--color-border);
    gap: 1rem;
    transition: background 0.2s ease;
}

.card:last-child {
    border-bottom: none;
}

.card:hover {
    background: var(--color-light);
}

.card__content {
    flex: 1;
    min-width: 0;
}

.card__title {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 0.25rem;
    color: var(--color-dark);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.card__subtitle {
    font-size: 0.9rem;
    font-weight: 400;
    color: var(--color-gray);
}

.card__action {
    padding: 0.6rem 1.25rem;
    background-color: var(--color-primary);
    color: var(--color-white);
    border: none;
    border-radius: var(--border-radius);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    transition: background-color var(--transition);
}

.card__action:hover {
    background-color: var(--color-primary-dark);
}

/* ===============================
   WHATSAPP (Block)
   =============================== */
.whatsapp {
    position: fixed;
    bottom: var(--spacing-md);
    right: var(--spacing-md);
    z-index: 1000;
    animation: fadeIn 0.5s ease 0.5s both;
}

.whatsapp__icon {
    width: clamp(48px, 8vw, 56px);
    height: clamp(48px, 8vw, 56px);
    border-radius: 50%;
    transition: transform var(--transition);
}

.whatsapp:hover .whatsapp__icon {
    transform: scale(1.1);
}

/* ===============================
   FOOTER (Block)
   =============================== */
.footer {
    margin-top: auto;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: var(--spacing-lg);
    padding: var(--spacing-xl) var(--spacing-lg);
    background-color: var(--color-dark);
    color: var(--color-white);
    text-align: center;
    width: 100%;
    overflow: hidden;
}

.footer__inner {
    max-width: 1600px;
    margin: 0 auto;
}

.footer__section {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
}

.footer__title {
    color: var(--color-primary);
    font-size: 1rem;
    margin-bottom: var(--spacing-xs);
}

.footer__text {
    font-size: 0.85rem;
    line-height: 1.5;
}

.footer__link {
    transition: color var(--transition);
}

.footer__link:hover {
    color: var(--color-primary);
}

.footer__social {
    display: flex;
    justify-content: center;
    gap: var(--spacing-md);
    margin-top: var(--spacing-xs);
}

.footer__social-link {
    padding: var(--spacing-sm);
    border-radius: 50%;
    transition: color var(--transition), transform var(--transition);
}

.footer__social-link:hover {
    color: var(--color-primary);
    transform: translateY(-2px);
}

/* Footer hidden modifier */
.footer--hidden {
    display: none;
}

/* ===============================
   UTILITIES
   =============================== */
.u-hidden {
    display: none !important;
}

.u-loading {
    text-align: center;
    padding: var(--spacing-xl);
    color: var(--color-gray);
}

/* ===============================
   ANIMATIONS
   =============================== */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* ===============================
   RESPONSIVE
   =============================== */

/* Tablet landscape and below */
@media screen and (max-width: 1024px) {
    .header__bar {
        padding: 0.875rem 1.5rem;
        gap: 1.5rem;
    }
    
    .nav__link {
        padding: 0.5rem 0.75rem;
        font-size: 0.9rem;
    }
    
    .search {
        max-width: 350px;
    }
}

/* Tablet portrait and below */
@media screen and (max-width: 800px) {
    .header {
        overflow: visible;
    }
    
    .header__bar {
        padding: var(--spacing-sm) var(--spacing-md);
        gap: var(--spacing-sm);
        position: relative;
    }
    
    .header__menu-toggle {
        display: flex;
        flex-shrink: 0;
        margin-left: auto;
    }
    
    .header__logo {
        flex-shrink: 0;
    }
    
    .search {
        flex: 1;
        max-width: none;
        min-width: 0;
    }
    
    .nav {
        position: absolute;
        top: 100%;
        left: 0;
        right: 0;
        background: var(--color-white);
        flex-direction: column;
        align-items: stretch;
        gap: 0;
        max-height: 0;
        overflow: hidden;
        transition: max-height 0.3s ease;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
        z-index: 99;
    }
    
    .nav.nav--open {
        max-height: 350px;
        border-top: 1px solid var(--color-border);
    }
    
    .nav__link {
        padding: 0.875rem var(--spacing-md);
        font-size: 1rem;
        border-bottom: 1px solid var(--color-light);
        justify-content: flex-start;
    }
    
    .nav__link:last-child {
        border-bottom: none;
    }
    
    .grid {
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
        gap: var(--spacing-md);
        padding: var(--spacing-lg);
    }
    
    .grid__item:hover {
        transform: none;
    }
    
    .section {
        padding: var(--spacing-lg) var(--spacing-md);
    }
    
    .footer {
        gap: var(--spacing-xl);
        padding: var(--spacing-xl) var(--spacing-md);
    }
    
    .whatsapp:hover .whatsapp__icon {
        transform: none;
    }
    
    .whatsapp:active .whatsapp__icon {
        transform: scale(0.95);
    }
}

/* Mobile phones */
@media screen and (max-width: 480px) {
    :root {
        --spacing-lg: 1.25rem;
        --spacing-xl: 2rem;
    }
    
    .header__bar {
        padding: 0.5rem var(--spacing-sm);
    }
    
    .header__logo img {
        height: 32px;
    }
    
    .search__input {
        padding: 0.7rem 0.875rem;
        padding-left: 2.5rem;
        font-size: 16px; /* Prevents zoom on iOS */
    }
    
    .search__results {
        min-width: 100%;
        max-height: 60vh;
        border-radius: 8px;
    }
    
    /* Exactly 2 columns on mobile with proper spacing */
    .grid {
        grid-template-columns: repeat(2, 1fr);
        gap: var(--spacing-md);
        padding: var(--spacing-md) var(--spacing-lg);
    }
    
    .section__title {
        margin-bottom: var(--spacing-lg);
    }
    
    .card {
        padding: 0.875rem 1rem;
        flex-direction: column;
        align-items: flex-start;
        gap: 0.75rem;
    }
    
    .card__action {
        width: 100%;
        text-align: center;
    }
    
    .footer {
        grid-template-columns: 1fr;
        gap: var(--spacing-lg);
        padding: var(--spacing-lg) var(--spacing-md);
    }
    
    .footer__section {
        padding-bottom: var(--spacing-md);
        border-bottom: 1px solid rgba(255,255,255,0.1);
    }
    
    .footer__section:last-child {
        border-bottom: none;
        padding-bottom: 0;
    }
    
    .whatsapp {
        bottom: var(--spacing-sm);
        right: var(--spacing-sm);
    }
    
    .whatsapp__icon {
        width: 48px;
        height: 48px;
    }
}

/* Extra small phones */
@media screen and (max-width: 360px) {
    .header__bar {
        gap: 0.35rem;
    }
    
    .header__logo img {
        height: 28px;
    }
    
    .grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.5rem;
    }
    
    .nav__link {
        padding: 0.75rem var(--spacing-sm);
        font-size: 0.95rem;
    }
}

/* ===============================
   ACCESSIBILITY
   =============================== */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}

:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
}

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