/**
 * 📚 КАТАЛОГ - Исправленные стили (БЕЗ КОНФЛИКТОВ И АВТОЗАПУСКАЮЩИХСЯ АНИМАЦИЙ!)
 * ✅ Использует существующие CSS переменные из variables.css
 * ✅ Совместим с base.css и navigation.css
 * ✅ Правильная работа скролла и нижней навигации
 * ✅ ИСПРАВЛЕНО: Убраны автозапускающиеся анимации, оставлены только контролируемые
 */

/* ============================================================================
   🎯 ПЕРСОНАЛИЗАЦИЯ (используем существующие переменные!)
   ============================================================================ */

.personalization-card {
    background: linear-gradient(135deg, var(--primary-color), var(--primary-dark));
    color: var(--text-inverse);
    border-radius: var(--radius-lg);
    padding: var(--spacing-md);
    text-align: center;
    margin-bottom: var(--spacing-lg);
    box-shadow: var(--shadow-primary);
    transition: all var(--duration-normal) var(--ease-out);
    position: relative;
    overflow: hidden;
}

.personalization-card::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(circle, rgba(255, 255, 255, 0.1) 0%, transparent 70%);
    animation: personalizationFloat 8s ease-in-out infinite;
}

@keyframes personalizationFloat {
    0%, 100% { transform: translate(0, 0) rotate(0deg); }
    50% { transform: translate(-20px, -20px) rotate(2deg); }
}

.personalization-title {
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-semibold);
    margin-bottom: var(--spacing-xs);
    position: relative;
    z-index: 1;
}

.personalization-subtitle {
    font-size: var(--font-size-xs);
    opacity: 0.9;
    margin-bottom: var(--spacing-sm);
    position: relative;
    z-index: 1;
}

.user-tags {
    display: flex;
    gap: var(--spacing-xs);
    justify-content: center;
    flex-wrap: wrap;
    position: relative;
    z-index: 1;
}

.user-tag {
    background: rgba(255,255,255,0.2);
    padding: var(--spacing-xs) var(--spacing-sm);
    border-radius: var(--radius-lg);
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-medium);
}

/* ============================================================================
   🏷️ ФИЛЬТРЫ (используем существующие переменные!)
   ============================================================================ */

.filter-tabs {
    display: flex;
    gap: var(--spacing-xs);
    margin-bottom: var(--spacing-md);
    overflow-x: auto;
    padding-bottom: var(--spacing-xs);
    -webkit-overflow-scrolling: touch;
}

.filter-tab {
    background: var(--bg-card);
    color: var(--text-secondary);
    border: 2px solid var(--text-muted);
    padding: var(--spacing-xs) var(--spacing-md);
    border-radius: var(--radius-xl);
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-semibold);
    white-space: nowrap;
    cursor: pointer;
    transition: all var(--duration-normal) var(--ease-out);
}

.filter-tab.active {
    background: var(--primary-color);
    color: var(--text-inverse);
    border-color: var(--primary-color);
}

.filter-tab:not(.active):hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
}

/* ============================================================================
   🔍 ПОИСК (используем существующие переменные!)
   ============================================================================ */

.search-section {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: var(--spacing-sm);
    margin-bottom: var(--spacing-md);
    border: 2px solid var(--text-muted);
    transition: all var(--duration-normal) var(--ease-out);
}

.search-section.active {
    border-color: var(--primary-color);
}

.search-input {
    width: 100%;
    border: none;
    background: transparent;
    font-size: var(--font-size-sm);
    color: var(--text-primary);
    outline: none;
    font-family: var(--font-family-primary);
}

.search-input::placeholder {
    color: var(--text-muted);
}

/* ============================================================================
   📖 КАРТОЧКИ КНИГ (используем существующие переменные!)
   ============================================================================ */

.book-card {
    /* ✅ RESET: Сброс конфликтующих стилей из components/cards.css */
    all: unset;
    /* ✅ LAYOUT: Применяем правильную структуру */
    display: flex;
    flex-direction: column;
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: var(--spacing-md);
    margin-bottom: var(--spacing-md);
    border: 1px solid var(--text-muted);
    box-shadow: var(--shadow-md);
    transition: all var(--duration-normal) var(--ease-out);
    cursor: pointer;
}

.book-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.book-main {
    display: flex;
    gap: var(--spacing-sm);
    margin-bottom: var(--spacing-sm);
}

.book-cover {
    width: 60px;
    height: 80px;
    border-radius: var(--radius-sm);
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-inverse);
    font-size: var(--font-size-xs);
    text-align: center;
    padding: var(--spacing-xs);
    font-weight: var(--font-weight-semibold);
    line-height: var(--line-height-tight);
    position: relative;
    overflow: hidden;
}

/* Разные градиенты для обложек */
.book-cover.cover-1 { background: linear-gradient(135deg, #8B5A3C, #A0522D); }
.book-cover.cover-2 { background: linear-gradient(135deg, #4A5D23, #6B8E23); }
.book-cover.cover-3 { background: linear-gradient(135deg, #8B008B, #9370DB); }
.book-cover.cover-4 { background: linear-gradient(135deg, #2F4F4F, #708090); }
.book-cover.cover-5 { background: linear-gradient(135deg, #B22222, #DC143C); }
.book-cover.cover-6 { background: linear-gradient(135deg, #191970, #4169E1); }

/* Book cover image styles */
.book-cover-img {
    width: 100%;
    height: 100%;
    border-radius: var(--radius-sm);
    object-fit: cover;
    position: absolute;
    top: 0;
    left: 0;
    z-index: 2;
}

/* Fallback text for when image is not available */
.cover-fallback-text {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1;
    padding: var(--spacing-xs);
}

/* Show fallback when book cover has fallback class or image is hidden */
.book-cover.fallback .book-cover-img,
.book-cover .book-cover-img[style*="display: none"] {
    display: none !important;
}

.book-info {
    flex: 1;
}

.book-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: var(--spacing-xs);
}
    margin-bottom: var(--spacing-xs);
}

.book-title {
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-semibold);
    color: var(--text-primary);
    margin-bottom: 2px;
    transition: color var(--duration-normal) var(--ease-out);
}

.book-author {
    font-size: var(--font-size-xs);
    color: var(--text-secondary);
    transition: color var(--duration-normal) var(--ease-out);
}

.book-badge {
    padding: 2px 6px;
    border-radius: var(--radius-sm);
    font-size: 9px;
    font-weight: var(--font-weight-semibold);
    flex-shrink: 0;
}

.book-badges {
    display: flex;
    gap: var(--spacing-xs);
    align-items: flex-start;
}

.book-badge.top {
    background: var(--primary-color);
    color: var(--text-inverse);
}

.book-badge.top-week {
    background: var(--primary-color);
    color: var(--text-inverse);
}

.book-badge.new {
    background: var(--warning-color);
    color: var(--text-inverse);
}

.book-badge.popular {
    background: var(--success-color);
    color: var(--text-inverse);
}

.book-description {
    font-size: var(--font-size-xs);
    color: var(--text-primary);
    line-height: var(--line-height-normal);
    margin-bottom: var(--spacing-sm);
    transition: color var(--duration-normal) var(--ease-out);
    /* Line clamp for 3 lines */
    overflow: hidden;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 3;
}

/* .book-meta - commented out per redesign
.book-meta {
    display: flex;
    align-items: center;
    gap: var(--spacing-xs);
    margin-bottom: var(--spacing-xs);
}

.book-meta-item {
    font-size: var(--font-size-xs);
    color: var(--text-secondary);
    transition: color var(--duration-normal) var(--ease-out);
}
*/
    flex-wrap: wrap;
}

.book-meta-item {
    font-size: 10px;
    color: var(--text-secondary);
    transition: color var(--duration-normal) var(--ease-out);
}

.book-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: auto; /* Push footer to bottom */
    gap: var(--spacing-xs);
}

.book-pricing {
    flex: 1;
}

.book-old-price {
    font-size: var(--font-size-xs);
    color: var(--text-muted);
    text-decoration: line-through;
    transition: color var(--duration-normal) var(--ease-out);
}

.book-price {
    font-size: var(--font-size-base);
    font-weight: var(--font-weight-semibold);
    color: var(--primary-color);
    transition: color var(--duration-normal) var(--ease-out);
}

.buy-button {
    background: var(--primary-color);
    color: var(--text-inverse);
    border: none;
    padding: var(--spacing-sm) var(--spacing-md);
    border-radius: var(--radius-md);
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-semibold);
    cursor: pointer;
    transition: all var(--duration-normal) var(--ease-out);
    white-space: nowrap;
    min-height: var(--touch-target-min);
}

.buy-button:hover {
    background: var(--primary-light);
    transform: translateY(-1px);
}

/* ============================================================================
   🎁 ПРОМО СЕКЦИИ (используем существующие переменные!)
   ============================================================================ */

.promo-section {
    background: linear-gradient(45deg, var(--primary-color), var(--primary-dark));
    color: var(--text-inverse);
    border-radius: var(--radius-lg);
    padding: var(--spacing-md);
    text-align: center;
    margin: var(--spacing-lg) 0;
}

.promo-title {
    font-weight: var(--font-weight-semibold);
    margin-bottom: var(--spacing-xs);
    font-size: var(--font-size-xs);
}

.promo-text {
    font-size: 10px;
    opacity: 0.9;
    margin-bottom: var(--spacing-sm);
    line-height: var(--line-height-normal);
}

.promo-button {
    background: var(--text-inverse);
    color: var(--primary-color);
    border: none;
    padding: var(--spacing-xs) var(--spacing-sm);
    border-radius: var(--radius-lg);
    font-weight: var(--font-weight-semibold);
    cursor: pointer;
    font-size: 10px;
    transition: transform var(--duration-fast) var(--ease-out);
}

.promo-button:hover {
    transform: translateY(-1px);
}

/* ============================================================================
   🔥 СКИДКИ И АКЦИИ (используем существующие переменные!)
   ============================================================================ */

.top-promo-banner {
    background: linear-gradient(45deg, var(--warning-color), #ff8c00);
    color: var(--text-inverse);
    border-radius: var(--radius-lg);
    padding: var(--spacing-md);
    text-align: center;
    margin-bottom: var(--spacing-lg);
}

.top-promo-title {
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-semibold);
    margin-bottom: var(--spacing-xs);
}

.top-promo-subtitle {
    font-size: var(--font-size-xs);
    opacity: 0.9;
    margin-bottom: var(--spacing-sm);
}

.top-promo-timer {
    font-size: 10px;
    opacity: 0.8;
}

.book-card.discount-card {
    border: 2px solid var(--warning-color);
    position: relative;
}

/* ✅ ИСПРАВЛЕНО: Убрана автозапускающаяся анимация discountPulse */
/* Теперь анимация запускается только через Router */
.animate-content .book-card.discount-card {
    animation: discountPulse 2s ease-in-out infinite;
}

.no-animations .book-card.discount-card {
    animation: none !important;
}

@keyframes discountPulse {
    0%, 100% { 
        box-shadow: var(--shadow-md), 0 0 0 0 rgba(255, 152, 0, 0.3); 
    }
    50% { 
        box-shadow: var(--shadow-lg), 0 0 0 4px rgba(255, 152, 0, 0.1); 
    }
}

.discount-badge {
    position: absolute;
    top: -10px;
    right: var(--spacing-sm);
    background: var(--warning-color);
    color: var(--text-inverse);
    padding: var(--spacing-xs) var(--spacing-sm);
    border-radius: var(--radius-lg);
    font-size: 10px;
    font-weight: var(--font-weight-semibold);
}

.buy-button.discount-button {
    background: var(--warning-color);
}

.buy-button.discount-button:hover {
    background: #e0a800;
}

/* ============================================================================
   📊 РЕЗУЛЬТАТЫ ПОИСКА (используем существующие переменные!)
   ============================================================================ */

.search-results-info {
    font-size: var(--font-size-xs);
    color: var(--text-secondary);
    margin-bottom: var(--spacing-md);
    transition: color var(--duration-normal) var(--ease-out);
}

.search-results-count {
    font-weight: var(--font-weight-semibold);
    color: var(--primary-color);
}

/* ============================================================================
   📱 МОБИЛЬНАЯ АДАПТАЦИЯ (используем существующие переменные!)
   ============================================================================ */

@media (max-width: 480px) {
    .personalization-card {
        padding: var(--spacing-sm);
        margin-bottom: var(--spacing-md);
    }
    
    .user-tags {
        gap: var(--spacing-xs);
    }
    
    .filter-tabs {
        gap: var(--spacing-xs);
        margin-bottom: var(--spacing-sm);
    }
    
    .filter-tab {
        padding: var(--spacing-xs) var(--spacing-sm);
        font-size: 10px;
    }
    
    .book-card {
        padding: var(--spacing-sm);
        margin-bottom: var(--spacing-sm);
    }
    
    .book-cover {
        width: 50px;
        height: 70px;
        font-size: 9px;
        /* Ensure minimum touch target area */
        min-width: var(--touch-target-min);
        min-height: var(--touch-target-min);
    }
    
    .book-cover-img {
        /* Maintain aspect ratio on smaller screens */
        border-radius: var(--radius-xs);
    }
    
    .book-main {
        gap: var(--spacing-sm);
        margin-bottom: var(--spacing-sm);
    }
    
    .book-title {
        font-size: var(--font-size-xs);
    }
    
    .book-author {
        font-size: 10px;
    }
    
    .book-description {
        font-size: 11px;
        /* Allow 4 lines on very narrow screens */
        -webkit-line-clamp: 4;
    }
    
    .book-meta {
        gap: var(--spacing-xs);
    }
    
    .book-meta-item {
        font-size: 9px;
    }
    
    .book-price {
        font-size: var(--font-size-sm);
    }
    
    .buy-button {
        padding: var(--spacing-xs) var(--spacing-sm);
        font-size: 11px;
    }
    
    .promo-section {
        padding: var(--spacing-sm);
        margin: var(--spacing-md) 0;
    }
    
    .top-promo-banner {
        padding: var(--spacing-sm);
        margin-bottom: var(--spacing-md);
    }
}

/* ============================================================================
   ✨ КОНТРОЛИРУЕМЫЕ АНИМАЦИИ (✅ ИСПРАВЛЕНО!)
   ============================================================================ */

/* ✅ ИСПРАВЛЕНО: Убраны автозапускающиеся анимации */
/* Анимации теперь запускаются только через Router при переходах */

/* Контролируемые анимации для Router */
.animate-content .book-card {
    animation: bookCardSlideUp 0.6s var(--ease-out);
    animation-fill-mode: both;
}

.animate-content .book-card:nth-child(1) { animation-delay: 0.1s; }
.animate-content .book-card:nth-child(2) { animation-delay: 0.2s; }
.animate-content .book-card:nth-child(3) { animation-delay: 0.3s; }
.animate-content .book-card:nth-child(4) { animation-delay: 0.4s; }
.animate-content .book-card:nth-child(5) { animation-delay: 0.5s; }
.animate-content .book-card:nth-child(6) { animation-delay: 0.6s; }

/* Отключение анимаций при флаге no-animations */
.no-animations .book-card {
    animation: none !important;
}

@keyframes bookCardSlideUp {
    from {
        opacity: 0;
        transform: translateY(30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Эффект ряби для кнопок */
.buy-button {
    position: relative;
    overflow: hidden;
}

.buy-button::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: var(--radius-round);
    background: rgba(255, 255, 255, 0.3);
    transition: width 0.6s, height 0.6s;
    transform: translate(-50%, -50%);
}

.buy-button:active::before {
    width: 300px;
    height: 300px;
}

/* ===== Mobile readable bump (+1px for micro sizes, variables for common sizes) ===== */
@media (hover: none) and (pointer: coarse) {
  /* Tiny texts */
  .book-badge { font-size: 10px; }              /* 9 -> 10 */
  .book-meta-item { font-size: 11px; }          /* 10 -> 11 */
  .promo-text { font-size: 11px; }              /* 10 -> 11 */
  .promo-button { font-size: 11px; }            /* 10 -> 11 */
  .top-promo-timer { font-size: 11px; }         /* 10 -> 11 */
  .discount-badge { font-size: 11px; }          /* 10 -> 11 */

  /* Remap to variables so scale applies */
  .book-title { font-size: var(--font-size-xs); }     /* 12 -> 13 */
  .book-author { font-size: 11px; }                   /* 10 -> 11 */
  .book-description { font-size: 12px; }              /* 11 -> 12 */
  .book-price { font-size: var(--font-size-sm); }     /* sm scales */
  .buy-button { font-size: 12px; }                    /* 11 -> 12 */
  .filter-tab { font-size: 11px; }                    /* 10 -> 11 */
  .book-cover { font-size: 10px; }                    /* 9 -> 10 */
}

/* Fallback by width */
@media (max-width: 480px) {
  .book-badge { font-size: 10px; }
  .book-meta-item { font-size: 11px; }
  .promo-text { font-size: 11px; }
  .promo-button { font-size: 11px; }
  .top-promo-timer { font-size: 11px; }
  .discount-badge { font-size: 11px; }
  .book-title { font-size: var(--font-size-xs); }
  .book-author { font-size: 11px; }
  .book-description { font-size: 12px; }
  .book-price { font-size: var(--font-size-sm); }
  .buy-button { font-size: 12px; }
  .filter-tab { font-size: 11px; }
  .book-cover { font-size: 10px; }
}

/* Retina support for book cover images */
@media screen and (-webkit-min-device-pixel-ratio: 2), 
       screen and (min-resolution: 2dppx) {
    .book-cover-img {
        image-rendering: -webkit-optimize-contrast;
        image-rendering: crisp-edges;
    }
}

.book-card.highlighted {
    border: 2px solid #ff9800 !important;
    box-shadow: 0 0 16px #ff9800;
    background: #fff8e1;
    transition: box-shadow 0.3s, background 0.3s;
}

/* ✅ НОВОЕ: Highlight class для совместимости */
.catalog-item--highlight {
    border: 2px solid #ff9800 !important;
    box-shadow: 0 0 16px #ff9800;
    background: #fff8e1;
    transition: box-shadow 0.3s, background 0.3s;
    animation: highlightPulse 0.5s ease-in-out;
}

@keyframes highlightPulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.02); }
    100% { transform: scale(1); }
}
