* {
    box-sizing: border-box;
}

:root {
    --dark: #1f1713;
    --accent: #c71f1f;
    --accent-dark: #781111;
    --paper: rgba(255, 255, 255, 0.9);
    --muted: #6b5f59;
    --line: rgba(69, 45, 35, 0.16);
    --shadow: 0 18px 45px rgba(60, 25, 14, 0.12);
}

body {
    position: relative;
    min-height: 100vh;
    margin: 0;
    font-family: Arial, sans-serif;
    color: var(--dark);
    background: #f5eee8;
}

body::before {
    content: "";
    position: fixed;
    inset: 0;
    z-index: -2;
    background-image: url("/static/brand-bg.jpg");
    background-repeat: no-repeat;
    background-position: center top;
    background-size: cover;
    opacity: 0.055;
    pointer-events: none;
}

body::after {
    content: "";
    position: fixed;
    inset: 0;
    z-index: -1;
    background: linear-gradient(180deg, rgba(255, 250, 244, 0.78), rgba(245, 238, 232, 0.94));
    pointer-events: none;
}

button,
input,
textarea,
select {
    font: inherit;
}

button {
    -webkit-tap-highlight-color: transparent;
}

.app {
    width: min(1480px, 100%);
    margin: 0 auto;
    padding: 14px;
}

.hero {
    overflow: hidden;
    margin-bottom: 10px;
    border-radius: 22px;
    background: rgba(255, 252, 247, 0.9);
    box-shadow: var(--shadow);
}

.hero-image {
    display: block;
    width: 100%;
    height: clamp(86px, 16vw, 170px);
    object-fit: contain;
    object-position: center;
    background: rgba(255, 252, 247, 0.94);
}

.header {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    align-items: flex-start;
    margin-bottom: 14px;
    padding: 16px;
    border: 1px solid var(--line);
    border-radius: 22px;
    background: var(--paper);
    backdrop-filter: blur(8px);
    box-shadow: var(--shadow);
}

.eyebrow {
    margin: 0 0 5px;
    font-size: 11px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

h1 {
    margin: 0;
    font-size: clamp(24px, 3vw, 40px);
    line-height: 1.05;
}

h2 {
    margin: 0 0 12px;
    font-size: 18px;
}

.clear-button {
    flex: 0 0 auto;
    border: none;
    border-radius: 999px;
    padding: 7px 10px;
    background: var(--dark);
    color: #fff;
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
}

.filters-section {
    padding: 15px;
    border: 1px solid var(--line);
    border-radius: 22px;
    background: var(--paper);
    backdrop-filter: blur(8px);
    box-shadow: var(--shadow);
    margin-bottom: 12px;
}

.filters {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.filter-group-title {
    width: fit-content;
    margin: 0 0 9px;
    border-radius: 999px;
    padding: 5px 10px;
    background: rgba(255, 255, 255, 0.62);
    color: #3d2a22;
    font-size: 15px;
    font-weight: 900;
    letter-spacing: 0.01em;
}

.filter-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
}

.filter-button {
    border: 1px solid rgba(83, 52, 38, 0.2);
    border-radius: 999px;
    padding: 8px 11px;
    background: rgba(255, 255, 255, 0.84);
    color: var(--dark);
    font-size: 13px;
    cursor: pointer;
}

.filter-button.active {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

.result-info {
    margin: 10px 2px 12px;
    color: var(--muted);
    font-size: 14px;
}

.products {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}

.product-card {
    overflow: hidden;
    border: 1px solid rgba(83, 52, 38, 0.12);
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.92);
    box-shadow: 0 12px 28px rgba(60, 25, 14, 0.1);
    cursor: pointer;
}

.product-image-wrap {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    aspect-ratio: 3 / 4;
    background: #fffaf5;
}

.product-image {
    display: block;
    width: 100%;
    height: 100%;
    padding: 0;
    object-fit: cover;
    object-position: center;
    background: #fffaf5;
}

.product-image-empty {
    min-height: 180px;
}

.product-content {
    padding: 10px;
}

.product-title {
    margin: 0 0 8px;
    font-size: 14px;
    line-height: 1.2;
    font-weight: 800;
}

.product-card-info {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-bottom: 10px;
    color: #3f342f;
    font-size: 13px;
    font-weight: 400;
}

.product-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 14px;
}

.product-tag {
    border-radius: 999px;
    padding: 5px 9px;
    background: #f3e8df;
    color: #4b3328;
    font-size: 12px;
}

.order-button {
    width: 100%;
    border: none;
    border-radius: 13px;
    padding: 10px 10px;
    background: var(--accent);
    color: white;
    font-size: 13px;
    font-weight: 800;
    cursor: pointer;
}

.order-button:hover {
    background: var(--accent-dark);
}

.empty-state {
    grid-column: 1 / -1;
    padding: 30px;
    border-radius: 22px;
    background: var(--paper);
    color: var(--muted);
    text-align: center;
}

.modal {
    position: fixed;
    inset: 0;
    display: none;
    z-index: 100;
}

.modal.active {
    display: block;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(31, 23, 19, 0.72);
}

.modal-card {
    position: relative;
    z-index: 101;
    max-width: 560px;
    max-height: calc(100vh - 24px);
    margin: 12px auto;
    overflow: auto;
    border-radius: 26px;
    background: #fffaf5;
    box-shadow: 0 24px 80px rgba(0, 0, 0, 0.32);
}

.modal-close {
    position: absolute;
    top: 12px;
    right: 12px;
    z-index: 5;
    width: 38px;
    height: 38px;
    border: none;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.92);
    color: var(--dark);
    font-size: 28px;
    line-height: 1;
    cursor: pointer;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.16);
}

.modal-gallery {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(180deg, #f5eee8, #e7ddd3);
}

.modal-image {
    display: block;
    width: 100%;
    height: min(64vh, 540px);
    object-fit: contain;
    object-position: center;
    background: transparent;
}

.gallery-arrow {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    display: none;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.9);
    color: var(--dark);
    font-size: 32px;
    line-height: 1;
    cursor: pointer;
    box-shadow: 0 10px 24px rgba(0, 0, 0, 0.18);
}

.gallery-arrow-left {
    left: 12px;
}

.gallery-arrow-right {
    right: 12px;
}

.modal-thumbnails {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding: 10px 14px 0;
}

.modal-thumbnail {
    flex: 0 0 auto;
    overflow: hidden;
    width: 58px;
    height: 58px;
    border: 2px solid transparent;
    border-radius: 12px;
    padding: 0;
    background: transparent;
    cursor: pointer;
}

.modal-thumbnail.active {
    border-color: var(--accent);
}

.modal-thumbnail img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    background: #f5eee8;
}

.modal-content {
    padding: 18px;
}

.modal-title {
    margin: 0 0 9px;
    font-size: 25px;
    line-height: 1.15;
}

.modal-description {
    margin: 0 0 14px;
    color: #4b3d36;
    line-height: 1.5;
}

.modal-summary {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 14px;
}

.modal-summary div {
    padding: 12px;
    border-radius: 16px;
    background: #f4e9df;
}

.modal-summary span {
    display: block;
    margin-bottom: 4px;
    color: var(--muted);
    font-size: 12px;
}

.modal-summary strong {
    font-size: 17px;
}

@media (min-width: 720px) {
    .products {
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 14px;
    }

    .product-title {
        font-size: 15px;
    }
}

@media (min-width: 1024px) {
    .app {
        padding: 22px;
    }

    .products {
        grid-template-columns: repeat(5, minmax(0, 1fr));
        gap: 16px;
    }

    .product-content {
        padding: 12px;
    }

    .product-card-info {
        font-size: 14px;
    }
}

@media (max-width: 640px) {
    .app {
        padding: 10px;
    }

    .hero {
        border-radius: 18px;
    }

    .hero-image {
        height: 90px;
    }

    .header {
        align-items: stretch;
        padding: 13px;
    }

    .clear-button {
        padding: 6px 9px;
        font-size: 11px;
    }

    .filters-section {
        padding: 13px;
    }

    .filter-button {
        padding: 7px 10px;
        font-size: 12px;
    }

    .modal-card {
        max-width: none;
        min-height: 100vh;
        max-height: none;
        margin: 0;
        border-radius: 0;
    }

    .modal-image {
        height: 58vh;
        min-height: 320px;
    }
}

/* description-button-layout-fix-v12-start */

/* Сохраняем абзацы и переносы строк в описании товара */
.modal-description,
.product-description,
.product-details-description,
.product-detail-description,
.description-text,
#modalDescription {
    white-space: pre-line;
}

/* Карточка товара растягивается по высоте аккуратно */
.products-grid > *,
.product-grid > *,
.catalog-grid > *,
.product-card,
.catalog-card,
.product-item {
    display: flex;
    flex-direction: column;
}

/* Внутренний текстовый блок карточки занимает свободное место */
.products-grid > * .product-info,
.products-grid > * .product-body,
.products-grid > * .card-body,
.product-grid > * .product-info,
.product-grid > * .product-body,
.product-grid > * .card-body,
.catalog-grid > * .product-info,
.catalog-grid > * .product-body,
.catalog-grid > * .card-body,
.product-card .product-info,
.product-card .product-body,
.product-card .card-body {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
}

/* Кнопка покупки фиксируется внизу карточки */
.products-grid > * .buy-button,
.products-grid > * .product-buy-button,
.products-grid > * .order-button,
.products-grid > * .telegram-button,
.products-grid > * a[href*="t.me"],
.product-grid > * .buy-button,
.product-grid > * .product-buy-button,
.product-grid > * .order-button,
.product-grid > * .telegram-button,
.product-grid > * a[href*="t.me"],
.catalog-grid > * .buy-button,
.catalog-grid > * .product-buy-button,
.catalog-grid > * .order-button,
.catalog-grid > * .telegram-button,
.catalog-grid > * a[href*="t.me"],
.product-card .buy-button,
.product-card .product-buy-button,
.product-card .order-button,
.product-card .telegram-button,
.product-card a[href*="t.me"] {
    margin-top: auto;
    margin-bottom: 8px;
}

/* description-button-layout-fix-v12-end */

/* mobile-modal-scroll-fix-v13-start */

/* На телефоне карточка товара должна прокручиваться целиком */
.modal,
.product-modal,
.modal-overlay,
#productModal {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    align-items: flex-start;
}

/* Само окно товара не должно быть выше экрана */
.modal-content,
.product-modal-content,
.product-detail-modal,
.modal-card {
    max-height: calc(100dvh - 24px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

/* На мобильных уменьшаем высоту фото внутри карточки товара */
@media (max-width: 640px) {
    .modal,
    .product-modal,
    .modal-overlay,
    #productModal {
        padding-top: 10px;
        padding-bottom: 10px;
    }

    .modal-content,
    .product-modal-content,
    .product-detail-modal,
    .modal-card {
        max-height: calc(100dvh - 20px);
        width: calc(100% - 16px);
        margin: 0 auto;
        overflow-y: auto;
        border-radius: 18px;
    }

    .modal-gallery {
        max-height: 46vh;
        min-height: auto;
    }

    .modal-image,
    #modalImage {
        max-height: 46vh;
        width: 100%;
        object-fit: contain;
    }

    .modal-body,
    .modal-info,
    .product-modal-body {
        padding-bottom: 18px;
    }
}

/* mobile-modal-scroll-fix-v13-end */
