/**
 * Pre-built Products Widget styles.
 * Self-contained — uses BEM naming under .ms-products to avoid clashing
 * with whatever CSS the AI-generated page already has.
 *
 * Theme: respects the host page's accent color via --ms-accent if defined
 * on :root, otherwise falls back to a neutral gold.
 */

:root {
    --ms-accent: var(--accent-color, #c89b3c);
    --ms-text:   #1f2937;
    --ms-muted:  #6b7280;
    --ms-bg:     #ffffff;
    --ms-border: #e5e7eb;
    --ms-shadow: 0 2px 6px rgba(0,0,0,0.06);
    --ms-shadow-hover: 0 8px 24px rgba(0,0,0,0.10);
    --ms-radius: 12px;
}

/* Wrapper */
.ms-products {
    width: 100%;
    max-width: 1280px;
    margin: 0 auto;
    padding: 32px 16px;
    box-sizing: border-box;
    font-family: inherit;
    color: var(--ms-text);
}

/* ── Search ───────────────────────────────────────────────────────────── */
.ms-products__search {
    margin: 0 0 24px;
    display: flex;
    justify-content: center;
}
.ms-products__search-input {
    width: 100%;
    max-width: 480px;
    padding: 12px 16px;
    border: 1px solid var(--ms-border);
    border-radius: 999px;
    font-size: 14px;
    font-family: inherit;
    background: var(--ms-bg);
    transition: border-color 0.15s, box-shadow 0.15s;
    box-sizing: border-box;
}
.ms-products__search-input:focus {
    outline: none;
    border-color: var(--ms-accent);
    box-shadow: 0 0 0 3px rgba(200,155,60,0.15);
}

/* ── Filter bar (category / price / custom fields) ────────────────────── */
.ms-products__filters:empty {
    display: none;
}
.ms-products__filters-row {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 12px 16px;
    margin: 0 0 24px;
    padding: 16px 18px;
    background: var(--ms-bg);
    border: 1px solid var(--ms-border);
    border-radius: 14px;
}
.ms-products__filter {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 160px;
    flex: 1 1 160px;
}
.ms-products__filter--range,
.ms-products__filter--number { flex-basis: 220px; }
.ms-products__filter--checkbox { flex: 0 0 auto; justify-content: flex-end; padding-bottom: 9px; }
.ms-products__filter--actions { flex: 0 0 auto; flex-direction: row; gap: 8px; margin-left: auto; }
.ms-products__filter-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--ms-muted);
    text-transform: uppercase;
    letter-spacing: .03em;
}
.ms-products__filter-input,
.ms-products__filter select {
    width: 100%;
    height: 40px;
    padding: 0 12px;
    border: 1px solid var(--ms-border);
    border-radius: 10px;
    font: inherit;
    font-size: 14px;
    background: var(--ms-bg);
    color: var(--ms-text);
    box-sizing: border-box;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.ms-products__filter-input:focus {
    outline: none;
    border-color: var(--ms-accent);
    box-shadow: 0 0 0 3px rgba(200,155,60,0.15);
}
.ms-products__filter-range {
    display: flex;
    align-items: center;
    gap: 6px;
}
.ms-products__filter-range input { min-width: 0; }
.ms-products__filter-dash { color: var(--ms-muted); }
.ms-products__filter-check {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    cursor: pointer;
    white-space: nowrap;
}
.ms-products__filter-check input {
    width: 18px;
    height: 18px;
    accent-color: var(--ms-accent);
    margin: 0;
}
.ms-products__filter-btn {
    height: 40px;
    padding: 0 18px;
    border-radius: 10px;
    font: inherit;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    border: 1px solid var(--ms-accent);
    background: var(--ms-accent);
    color: #fff;
    transition: opacity 0.15s, background 0.15s, color 0.15s;
}
.ms-products__filter-reset {
    background: var(--ms-bg);
    color: var(--ms-accent);
}
.ms-products__filter-btn:hover:not([disabled]) { opacity: .88; }
.ms-products__filter-btn[disabled] { opacity: .45; cursor: not-allowed; }
@media (max-width: 640px) {
    .ms-products__filter { flex-basis: 100%; }
    .ms-products__filter--actions { margin-left: 0; width: 100%; }
    .ms-products__filter--actions .ms-products__filter-btn { flex: 1; }
}

/* ── List container — varies by layout ────────────────────────────────── */

/* GRID (default) */
.ms-products--grid .ms-products__list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 20px;
}

/* LIST */
.ms-products--list .ms-products__list {
    display: flex;
    flex-direction: column;
    gap: 16px;
}
.ms-products--list .ms-products__card {
    flex-direction: row;
    max-width: 800px;
    width: 100%;
    margin: 0 auto;
}
.ms-products--list .ms-products__img-wrap {
    width: 220px;
    flex-shrink: 0;
    aspect-ratio: 4 / 3;
}
.ms-products--list .ms-products__body {
    flex: 1;
}
.ms-products--list .ms-products__footer {
    border-top: none;
    padding-top: 0;
}
@media (max-width: 640px) {
    .ms-products--list .ms-products__card {
        flex-direction: column;
    }
    .ms-products--list .ms-products__img-wrap {
        width: 100%;
        aspect-ratio: 16 / 10;
    }
}

/* CAROUSEL */
.ms-products--carousel .ms-products__list {
    display: flex;
    gap: 16px;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    padding: 4px 4px 16px 4px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    scrollbar-color: var(--ms-accent) transparent;
}
.ms-products--carousel .ms-products__card {
    flex: 0 0 280px;
    scroll-snap-align: start;
}
.ms-products--carousel .ms-products__list::-webkit-scrollbar {
    height: 8px;
}
.ms-products--carousel .ms-products__list::-webkit-scrollbar-thumb {
    background: var(--ms-accent);
    border-radius: 4px;
}

/* FEATURED-STRIP — compact horizontal */
.ms-products--featured-strip .ms-products__list {
    display: flex;
    gap: 12px;
    overflow-x: auto;
    padding: 4px 4px 12px;
    scroll-snap-type: x mandatory;
}
.ms-products--featured-strip .ms-products__card {
    flex: 0 0 200px;
    scroll-snap-align: start;
}
.ms-products--featured-strip .ms-products__name {
    font-size: 0.95rem;
}
.ms-products--featured-strip .ms-products__desc {
    display: none;
}
.ms-products--featured-strip .ms-products__img-wrap {
    aspect-ratio: 1 / 1;
}

/* ── Card ─────────────────────────────────────────────────────────────── */
.ms-products__card {
    display: flex;
    flex-direction: column;
    background: var(--ms-bg);
    border: 1px solid var(--ms-border);
    border-radius: var(--ms-radius);
    overflow: hidden;
    transition: transform 0.18s, box-shadow 0.18s, border-color 0.18s;
    box-shadow: var(--ms-shadow);
}
.ms-products__card:hover {
    transform: translateY(-2px);
    box-shadow: var(--ms-shadow-hover);
    border-color: var(--ms-accent);
}
.ms-products__card.is-disabled {
    opacity: 0.55;
}
.ms-products__card.is-disabled:hover {
    transform: none;
    border-color: var(--ms-border);
    box-shadow: var(--ms-shadow);
}

.ms-products__img-wrap {
    position: relative;
    aspect-ratio: 4 / 3;
    background: linear-gradient(135deg, #f3f4f6, #e5e7eb);
    overflow: hidden;
}
.ms-products__img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: transform 0.4s;
}
.ms-products__card:hover .ms-products__img {
    transform: scale(1.05);
}

.ms-products__ribbon {
    position: absolute;
    top: 8px;
    left: 8px;
    background: var(--ms-accent);
    color: #fff;
    padding: 4px 10px;
    font-size: 11px;
    font-weight: 600;
    border-radius: 999px;
    box-shadow: 0 2px 6px rgba(0,0,0,0.15);
    z-index: 2;
}

.ms-products__badge {
    position: absolute;
    top: 8px;
    right: 8px;
    padding: 4px 10px;
    font-size: 11px;
    font-weight: 600;
    border-radius: 999px;
    color: #fff;
    z-index: 2;
}
.ms-products__badge--out          { background: #dc2626; }
.ms-products__badge--preorder     { background: #2563eb; }
.ms-products__badge--discontinued { background: #6b7280; }

.ms-products__body {
    padding: 14px 16px;
    flex: 1;
}
.ms-products__name {
    margin: 0 0 6px;
    font-size: 1.05rem;
    font-weight: 600;
    line-height: 1.3;
    color: var(--ms-text);
}
.ms-products__desc {
    margin: 0 0 10px;
    font-size: 0.875rem;
    color: var(--ms-muted);
    line-height: 1.45;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Price */
.ms-products__price {
    display: flex;
    align-items: baseline;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 8px;
}
.ms-products__price-current {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--ms-text);
}
.ms-products__price-original {
    font-size: 0.875rem;
    color: var(--ms-muted);
    text-decoration: line-through;
}
.ms-products__price-badge {
    background: #dc2626;
    color: #fff;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
}
.ms-products__price--contact {
    color: var(--ms-accent);
    font-weight: 600;
    font-size: 0.95rem;
}

/* Footer + button */
.ms-products__footer {
    padding: 12px 16px 16px;
    border-top: 1px solid var(--ms-border);
}
.ms-products__btn {
    width: 100%;
    padding: 10px 16px;
    background: var(--ms-accent);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    transition: background 0.15s, transform 0.1s, opacity 0.15s;
}
.ms-products__btn:hover:not(:disabled) {
    filter: brightness(0.92);
    transform: translateY(-1px);
}
.ms-products__btn:active:not(:disabled) {
    transform: translateY(0);
}
.ms-products__btn:disabled {
    cursor: not-allowed;
    opacity: 0.5;
}

/* ── States: loading / empty / error ──────────────────────────────────── */
.ms-products__state {
    text-align: center;
    padding: 60px 20px;
    color: var(--ms-muted);
    font-size: 1rem;
}
.ms-products__state p {
    margin: 12px 0 0;
}
.ms-products__spinner {
    width: 36px;
    height: 36px;
    margin: 0 auto;
    border: 3px solid var(--ms-border);
    border-top-color: var(--ms-accent);
    border-radius: 50%;
    animation: ms-products-spin 0.9s linear infinite;
}
@keyframes ms-products-spin {
    to { transform: rotate(360deg); }
}
.ms-products__empty-icon,
.ms-products__error-icon {
    font-size: 3rem;
    line-height: 1;
}
.ms-products__error small {
    display: block;
    margin-top: 8px;
    font-size: 0.8rem;
    color: #ef4444;
    opacity: 0.85;
    word-break: break-word;
    max-width: 480px;
    margin-left: auto;
    margin-right: auto;
}

/* ── Responsive tweaks ────────────────────────────────────────────────── */
@media (max-width: 640px) {
    .ms-products {
        padding: 20px 12px;
    }
    .ms-products--grid .ms-products__list {
        grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
        gap: 12px;
    }
    .ms-products__name {
        font-size: 0.95rem;
    }
    .ms-products__desc {
        -webkit-line-clamp: 2;
        font-size: 0.8rem;
    }
    .ms-products__price-current {
        font-size: 1rem;
    }
}

/* ─────────────────────────────────────────────────────────────────────── */
/* Modal: product details (.ms-pmodal__*)                                  */
/* Opened by products.js when the user clicks "Մանրամասներ" on a card.    */
/* ─────────────────────────────────────────────────────────────────────── */

.ms-pmodal__backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    padding: 16px;
    animation: ms-pmodal-fade 0.18s ease;
}
@keyframes ms-pmodal-fade {
    from { opacity: 0; }
    to   { opacity: 1; }
}
@keyframes ms-pmodal-slide {
    from { transform: translateY(20px); opacity: 0; }
    to   { transform: translateY(0);    opacity: 1; }
}
.ms-pmodal {
    background: #fff;
    border-radius: 12px;
    max-width: 960px;
    width: 100%;
    max-height: 92vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.3);
    animation: ms-pmodal-slide 0.22s ease;
    font-family: inherit;
    color: #1f2937;
}

/* Header */
.ms-pmodal__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 20px;
    border-bottom: 1px solid #e5e7eb;
    flex-shrink: 0;
}
.ms-pmodal__title {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 600;
}
.ms-pmodal__close {
    background: transparent;
    border: none;
    font-size: 1.5rem;
    line-height: 1;
    color: #6b7280;
    cursor: pointer;
    padding: 4px 12px;
    border-radius: 6px;
    transition: background 0.15s;
    font-family: inherit;
}
.ms-pmodal__close:hover {
    background: #f3f4f6;
    color: #1f2937;
}

/* Body + 2-column layout */
.ms-pmodal__body {
    overflow-y: auto;
    padding: 20px;
    flex: 1;
}
.ms-pmodal__layout {
    display: grid;
    grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr);
    gap: 24px;
    /* Stretch both columns so they share a height — enables CTA pinning. */
    align-items: stretch;
}
@media (max-width: 720px) {
    .ms-pmodal__layout {
        grid-template-columns: 1fr;
        gap: 16px;
    }
}

/* Gallery (left side) */
.ms-pmodal__gallery {
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-width: 0;
    /* Don't stretch the gallery if the info column is taller (long description).
       Without this the gallery would have empty space below the image. */
    align-self: start;
}
.ms-pmodal__main {
    width: 100%;
    aspect-ratio: 4 / 3;
    object-fit: contain;
    background: #f3f4f6;
    border-radius: 10px;
    display: block;
    min-height: 0;
}
.ms-pmodal__thumbs {
    display: flex;
    flex-wrap: wrap;       /* wrap to next row instead of horizontal scroll */
    gap: 8px;
    padding: 2px;
}
.ms-pmodal__thumb {
    width: 72px;
    height: 56px;
    object-fit: cover;
    border-radius: 6px;
    border: 2px solid transparent;
    cursor: pointer;
    transition: border-color 0.15s, opacity 0.15s;
    flex-shrink: 0;
}
.ms-pmodal__thumb:hover {
    opacity: 0.85;
}
.ms-pmodal__thumb.is-active {
    border-color: var(--ms-accent, #c89b3c);
}

/* Info (right side) */
.ms-pmodal__info {
    min-width: 0;
    /* Flex column so the CTA can use margin-top:auto to stick to the bottom,
       keeping the button in a fixed position regardless of description length. */
    display: flex;
    flex-direction: column;
}
.ms-pmodal__name {
    margin: 0 0 8px;
    font-size: 1.4rem;
    font-weight: 700;
    line-height: 1.25;
}
.ms-pmodal__category {
    display: inline-block;
    align-self: flex-start;
    background: #f3f4f6;
    color: #4b5563;
    padding: 4px 12px;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 500;
    margin-bottom: 14px;
}

/* Price block */
.ms-pmodal__price {
    display: flex;
    align-items: baseline;
    gap: 12px;
    flex-wrap: wrap;
    margin: 6px 0 16px;
}
.ms-pmodal__price-current {
    font-size: 1.5rem;
    font-weight: 700;
}
.ms-pmodal__price-original {
    font-size: 1rem;
    color: #6b7280;
    text-decoration: line-through;
}
.ms-pmodal__price-badge {
    background: #dc2626;
    color: #fff;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 600;
}
.ms-pmodal__price--contact {
    color: var(--ms-accent, #c89b3c);
    font-weight: 600;
    font-size: 1rem;
}

/* Stock badge */
.ms-pmodal__stock {
    display: inline-block;
    align-self: flex-start;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 600;
    color: #fff;
    margin-bottom: 14px;
}
.ms-pmodal__stock--in           { background: #16a34a; }
.ms-pmodal__stock--out          { background: #dc2626; }
.ms-pmodal__stock--preorder     { background: #2563eb; }
.ms-pmodal__stock--discontinued { background: #6b7280; }

/* Description */
.ms-pmodal__section-title {
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: #9ca3af;
    margin: 18px 0 8px;
}
.ms-pmodal__desc {
    color: #374151;
    line-height: 1.65;
    font-size: 0.95rem;
    white-space: pre-wrap;
    word-wrap: break-word;
}

/* CTA (always pinned to bottom of the info column) */
.ms-pmodal__cta {
    margin-top: auto;       /* ← pushes button to the bottom */
    padding: 12px 22px;
    background: var(--ms-accent, #c89b3c);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: filter 0.15s;
    font-family: inherit;
    align-self: flex-start; /* don't stretch full-width inside the flex column */
}
.ms-pmodal__cta:hover:not(:disabled) {
    filter: brightness(0.92);
}
.ms-pmodal__cta:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Loading + error states */
.ms-pmodal__loading,
.ms-pmodal__error {
    text-align: center;
    padding: 50px 20px;
    color: #6b7280;
}
.ms-pmodal__error small {
    display: block;
    margin-top: 8px;
    color: #ef4444;
    font-size: 0.8rem;
}

/* ── Pagination (Prev · 1 … 4 5 6 … 280 · Next + "49–60 / 3357") ────────── */
.ms-products__pager {
    margin-top: 28px;
}
.ms-products__pager:empty {
    display: none;
}
.ms-products__pager-nav {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: 6px;
}
.ms-products__page-btn {
    min-width: 38px;
    height: 38px;
    padding: 0 12px;
    background: var(--ms-bg);
    color: var(--ms-text);
    border: 1px solid var(--ms-border);
    border-radius: 8px;
    font: inherit;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
.ms-products__page-btn:hover:not([disabled]):not(.is-current) {
    border-color: var(--ms-accent);
    color: var(--ms-accent);
}
.ms-products__page-btn.is-current {
    background: var(--ms-accent);
    border-color: var(--ms-accent);
    color: #fff;
    cursor: default;
}
.ms-products__page-btn[disabled] {
    opacity: 0.45;
    cursor: not-allowed;
}
.ms-products__page-gap {
    min-width: 24px;
    text-align: center;
    color: var(--ms-muted);
    user-select: none;
}
.ms-products__pager-info {
    margin-top: 10px;
    text-align: center;
    font-size: 0.85rem;
    color: var(--ms-muted);
}
@media (max-width: 560px) {
    .ms-products__page-btn--prev span,
    .ms-products__page-btn--next span {
        display: none; /* arrows only on narrow phones */
    }
}

/* ── "Load more" (home page teaser) ──────────────────────────────────────── */
.ms-products__more {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}
.ms-products__more-btn {
    min-width: 200px;
    height: 46px;
    padding: 0 28px;
    background: var(--ms-bg);
    color: var(--ms-accent);
    border: 2px solid var(--ms-accent);
    border-radius: 10px;
    font: inherit;
    font-size: 0.95rem;
    font-weight: 700;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease, transform 0.15s ease;
}
.ms-products__more-btn:hover:not([disabled]) {
    background: var(--ms-accent);
    color: #fff;
    transform: translateY(-1px);
}
.ms-products__more-btn[disabled] {
    opacity: 0.6;
    cursor: wait;
}
.ms-products__more .ms-products__pager-info {
    margin-top: 0;
}

/* While the next page is being fetched the old cards stay in place,
   dimmed, so the layout does not jump. */
.ms-products__list.is-loading {
    opacity: 0.45;
    pointer-events: none;
    transition: opacity 0.15s ease;
}

/* ── Product attributes (custom fields chosen in Dynamic Website settings) ── */
.ms-products__attrs {
    list-style: none; margin: 8px 0 0; padding: 0;
    display: flex; flex-wrap: wrap; gap: 6px;
}
.ms-products__attrs li {
    display: inline-flex; align-items: baseline; gap: 4px; max-width: 100%;
    padding: 3px 9px; border-radius: 999px;
    background: rgba(0, 0, 0, .05); font-size: 12px; line-height: 1.3;
}
.ms-products__attr-k { color: #64748b; white-space: nowrap; }
.ms-products__attr-k::after { content: ':'; }
.ms-products__attr-v { color: #1e293b; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ms-products--list .ms-products__attrs { margin-top: 6px; }

.ms-pmodal__attrs {
    margin: 0 0 16px; padding: 0;
    display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 8px 18px;
}
.ms-pmodal__attr {
    display: flex; justify-content: space-between; gap: 12px;
    padding: 7px 0; border-bottom: 1px dashed #e2e8f0; font-size: 14px;
}
.ms-pmodal__attr dt { margin: 0; color: #64748b; }
.ms-pmodal__attr dd { margin: 0; color: #1e293b; font-weight: 600; text-align: right; word-break: break-word; }

/* sql101: «X / piece» hint for products sold by the piece */
.ms-products__price-piece { font-size: 0.8rem; opacity: 0.8; margin-top: 2px; }
.ms-pmodal__price-piece { font-size: 0.9rem; opacity: 0.85; margin-top: 4px; }
