:root {
    --primary: #4A90D9;
    --primary-dark: #357ABD;
    --secondary: #6C757D;
    --success: #28A745;
    --bg-light: #F8F9FA;
    --bg-white: #FFFFFF;
    --text-dark: #212529;
    --text-muted: #6C757D;
    --border: #DEE2E6;
    --shadow: 0 2px 8px rgba(0,0,0,0.1);
    --shadow-hover: 0 4px 16px rgba(0,0,0,0.15);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg-light);
    color: var(--text-dark);
    line-height: 1.6;
}

.container { max-width: 1200px; margin: 0 auto; padding: 0 20px; }

/* Header */
header {
    background: var(--bg-white);
    box-shadow: var(--shadow);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 0;
    gap: 20px;
    flex-wrap: wrap;
}

.logo {
    display: flex;
    align-items: center;
    gap: 15px;
    text-decoration: none;
}

.logo img {
    height: 50px;
    width: auto;
}

.logo-text {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary);
}

#search {
    flex: 1;
    max-width: 500px;
    padding: 12px 20px;
    border: 2px solid var(--border);
    border-radius: 25px;
    font-size: 15px;
}

#search:focus {
    outline: none;
    border-color: var(--primary);
}

.header-actions {
    display: flex;
    gap: 15px;
    align-items: center;
}

.btn {
    padding: 10px 20px;
    border-radius: 25px;
    text-decoration: none;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: all 0.3s;
}

.btn-primary {
    background: var(--primary);
    color: white;
}

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

.btn-outline {
    background: white;
    color: var(--primary);
    border: 2px solid var(--primary);
}

.favorites-count {
    background: var(--primary);
    color: white;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 13px;
    margin-left: 5px;
}

/* Categories */
.categories-section { padding: 40px 0; }

.section-title {
    font-size: 2rem;
    margin-bottom: 30px;
    text-align: center;
    color: var(--text-dark);
}

.categories-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
    gap: 12px;
}

.category-card {
    background: var(--bg-white);
    border-radius: 8px;
    padding: 10px 12px;
    text-align: center;
    box-shadow: var(--shadow);
    cursor: pointer;
    transition: all 0.3s;
    min-height: 55px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    border: 2px solid transparent;
    text-decoration: none;
}

.category-card:hover, .category-card.active {
    transform: translateY(-2px);
    box-shadow: var(--shadow-hover);
    border-color: var(--primary);
}

.category-name { font-size: 12px; font-weight: 600; line-height: 1.2; margin-bottom: 3px; }
.category-count { color: var(--text-muted); font-size: 10px; }

/* Products */
.products-section { padding: 40px 0; }

.products-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 25px;
}

.card {
    background: var(--bg-white);
    border-radius: 12px;
    overflow: hidden;
    box-shadow: var(--shadow);
    transition: transform 0.3s;
    position: relative;
}

.card-image-container {
    position: relative;
    width: 100%;
}

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

.card > a[href^="products/"] {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
}

.card .btn-buy {
    position: relative;
    z-index: 10;
    pointer-events: auto;
}

.card .btn-add-to-list {
    position: relative;
    z-index: 10;
    pointer-events: auto;
}

.card .favorite-heart {
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 20;
    pointer-events: auto;
}

.card img {
    width: 100%;
    max-height: 250px;
    height: auto;
    object-fit: contain;
    background: #f8f9fa;
    display: block;
    margin: 0 auto;
}

.card-body {
    padding: 25px;
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: visible !important;
}

.card-title {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 15px;
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    min-height: 44px;
}

.card-price {
    font-size: 20px;
    font-weight: 700;
    color: var(--primary);
    margin: 15px 0;
}

.btn-buy {
    display: block;
    padding: 12px;
    background: var(--primary);
    color: white;
    text-align: center;
    text-decoration: none;
    border-radius: 8px;
    font-weight: 600;
    transition: background 0.3s;
    margin-top: 10px;
    border: none;
    cursor: pointer;
    width: 100%;
}

.btn-buy:hover { background: var(--primary-dark); }

.btn-add-to-list {
    display: block;
    padding: 10px;
    background: #dc3545;
    color: white;
    text-align: center;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    margin-top: 10px;
    width: 100%;
    transition: background 0.3s;
}

.btn-add-to-list:hover {
    background: #c82333;
}

.btn-in-list {
    background: #28A745;
}

.btn-in-list:hover {
    background: #218838;
}

/* Кнопка "В корзину" на странице товара */
.btn-add-cart {
    flex: 1;
    padding: 15px 25px;
    background: #dc3545;
    color: white;
    border: none;
    border-radius: 10px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.3s;
}

.btn-add-cart:hover {
    background: #c82333;
}

.btn-add-cart.added {
    background: #28A745;
}

/* Кнопка "В избранное" на странице товара */
.btn-favorite {
    width: 54px;
    padding: 15px;
    background: white;
    color: #dc3545;
    border: 2px solid #dc3545;
    border-radius: 10px;
    font-size: 1.5rem;
    cursor: pointer;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-favorite:hover {
    background: #dc3545;
    color: white;
}

.btn-favorite.active {
    background: #dc3545;
    color: white;
}

.favorite-heart {
    position: absolute;
    top: 10px;
    right: 10px;
    font-size: 28px;
    cursor: pointer;
    background: rgba(255, 255, 255, 0.9);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s;
    z-index: 10;
}

.favorite-heart:hover {
    transform: scale(1.1);
    background: white;
}

.favorite-heart.empty {
    color: #dc3545;
}

.favorite-heart.filled {
    color: #dc3545;
    animation: pulse 0.3s;
}

@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.2); }
    100% { transform: scale(1); }
}

/* Личный кабинет */
.cabinet-btn {
    background: white;
    color: var(--primary);
    border: 2px solid var(--primary);
}

.cabinet-btn:hover {
    background: var(--primary);
    color: white;
}

/* Модальные окна */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    z-index: 1000;
    justify-content: center;
    align-items: center;
}

.modal-content {
    background: white;
    padding: 30px;
    border-radius: 12px;
    max-width: 500px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
}

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

.modal-close {
    background: none;
    border: none;
    font-size: 28px;
    cursor: pointer;
    color: var(--text-muted);
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: var(--text-dark);
}

.form-group input {
    width: 100%;
    padding: 12px 15px;
    border: 2px solid var(--border);
    border-radius: 8px;
    font-size: 15px;
}

.form-group input:focus {
    outline: none;
    border-color: var(--primary);
}

.form-btn {
    width: 100%;
    padding: 12px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.3s;
}

.form-btn:hover {
    background: var(--primary-dark);
}

.user-info {
    text-align: center;
    padding: 20px;
}

.user-name {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 10px;
}

.user-stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
    margin: 20px 0;
}

.stat-item {
    background: var(--bg-light);
    padding: 15px;
    border-radius: 8px;
    text-align: center;
}

.stat-value {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--primary);
}

.stat-label {
    font-size: 13px;
    color: var(--text-muted);
    margin-top: 5px;
}

.logout-btn {
    width: 100%;
    padding: 12px;
    background: #dc3545;
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    margin-top: 15px;
}

.logout-btn:hover {
    background: #c82333;
}

/* Pagination */
.pagination {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-top: 40px;
    flex-wrap: wrap;
}

.pagination-wrapper {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    justify-content: center;
    background: var(--bg-white);
    padding: 15px 25px;
    border-radius: 12px;
    box-shadow: var(--shadow);
}

.pagination button,
.pagination .nav-btn,
.pagination .go-btn {
    padding: 12px 20px;
    background: var(--bg-white);
    color: var(--primary);
    border: 2px solid var(--primary);
    border-radius: 10px;
    cursor: pointer;
    font-weight: 600;
    font-size: 14px;
    transition: all 0.3s;
    white-space: nowrap;
}

.pagination button:hover,
.pagination .nav-btn:hover,
.pagination .go-btn:hover {
    background: var(--primary);
    color: white;
    transform: translateY(-2px);
    box-shadow: var(--shadow-hover);
}

.pagination button.active {
    background: var(--primary);
    color: white;
}

.pagination button:disabled,
.pagination .nav-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none;
}

.pagination button:disabled:hover,
.pagination .nav-btn:disabled:hover {
    background: var(--bg-white);
    color: var(--primary);
}

.page-input-wrapper {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--bg-light);
    padding: 8px 15px;
    border-radius: 8px;
}

.page-input-wrapper span {
    font-size: 14px;
    color: var(--text-muted);
    font-weight: 500;
}

.page-input-wrapper input {
    width: 70px;
    padding: 8px;
    text-align: center;
    border: 2px solid var(--border);
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    -moz-appearance: textfield;
}

.page-input-wrapper input:focus {
    outline: none;
    border-color: var(--primary);
}

.page-input-wrapper input::-webkit-outer-spin-button,
.page-input-wrapper input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.page-input-wrapper .go-btn {
    padding: 8px 16px;
    font-size: 13px;
}

/* Product Detail */
.product-detail { padding: 60px 0; }

.back-link {
    display: inline-block;
    margin-bottom: 30px;
    color: var(--primary);
    text-decoration: none;
    font-size: 1.1rem;
}

.product-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 50px;
    background: var(--bg-white);
    padding: 40px;
    border-radius: 16px;
    box-shadow: var(--shadow);
}

.product-image {
    position: relative;
    width: 100%;
    height: 300px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f8f9fa;
    border-radius: 16px;
    overflow: hidden;
}

.product-image img {
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    object-fit: contain !important;
    display: block;
}

.product-info h1 {
    font-size: 1.9rem;
    margin-bottom: 20px;
    color: var(--text-dark);
    line-height: 1.2;
}

.product-info .price {
    font-size: 2.2rem;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 25px;
}

.product-info .product-meta {
    background: var(--bg-light);
    padding: 20px;
    border-radius: 12px;
    margin-bottom: 25px;
}

.product-info .product-meta p {
    margin: 10px 0;
    color: var(--text-muted);
}

.product-description {
    margin-top: 50px;
    padding-top: 40px;
    border-top: 2px solid var(--border);
}

.product-description h2 {
    font-size: 1.6rem;
    margin-bottom: 25px;
    color: var(--text-dark);
}

.product-description .content {
    font-size: 1.05rem;
    line-height: 1.8;
    color: var(--text);
}

.product-description .content p {
    margin-bottom: 20px;
}

.product-description .content ul,
.product-description .content ol {
    margin: 20px 0;
    padding-left: 30px;
}

.product-description .content li {
    margin-bottom: 10px;
}

.description {
    background: var(--bg-light);
    padding: 25px;
    border-radius: 12px;
    margin-top: 20px;
}

.description h3 {
    margin-bottom: 15px;
    color: var(--primary);
}

.description-content {
    white-space: pre-wrap;
    line-height: 1.8;
    font-size: 15px;
    color: var(--text-dark);
}

.related { margin-top: 60px; }

/* Footer */
footer {
    background: var(--text-dark) !important;
    color: white;
    padding: 40px 0;
    margin-top: 60px;
    text-align: center;
}

footer .footer-links {
    justify-content: center !important;
}

footer a { color: var(--primary); }

/* Responsive */
@media (max-width: 768px) {
    .header-content { flex-direction: column; gap: 15px; }
    #search { max-width: 100%; }
    .product-grid { grid-template-columns: 1fr; gap: 30px; padding: 25px; }
    .product-image { height: 250px; }
    .product-info h1 { font-size: 1.5rem; }
    .product-info .price { font-size: 1.5rem; }
    .categories-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
    .products-grid { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
}

@media (max-width: 480px) {
    .product-grid { padding: 20px; gap: 20px; }
    .product-image { height: 200px; }
    .product-info h1 { font-size: 1.3rem; }
    .product-info .price { font-size: 1.3rem; }
    .categories-grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
    .products-grid { grid-template-columns: 1fr; }
}

/* Кнопки в модальном окне избранного */
.favorites-add-to-cart-btn {
    background: #dc3545;
    color: white;
    border: none;
    border-radius: 6px;
    padding: 6px 12px;
    font-weight: 600;
    font-size: 12px;
    cursor: pointer;
    transition: background 0.3s;
    white-space: nowrap;
}

.favorites-add-to-cart-btn:hover {
    background: #c82333;
}

.favorites-add-to-cart-btn.added {
    background: #28A745;
}

.favorites-add-to-cart-btn.added:hover {
    background: #218838;
}
