:root {
    --market-surface: #ffffff;
    --market-border: #e2e8f0;
    --market-muted: #64748b;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    min-height: 100%;
}

body.market-body {
    font-family: "Noto Sans Thai", "Segoe UI", sans-serif;
    color: var(--site-text-color, #0f172a);
    background-color: var(--bg-color, #f1f5f9);
}

/* Background image mode is toggled via a class on <body> since the two
   modes need different background-repeat/background-size combinations. */
body.market-bg-image {
    background-image: linear-gradient(rgba(0, 0, 0, var(--overlay-opacity, 0)), rgba(0, 0, 0, var(--overlay-opacity, 0))), var(--bg-image);
    background-attachment: fixed;
}
body.market-bg-image.market-bg-cover {
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
}
body.market-bg-image.market-bg-repeat {
    background-size: auto;
    background-repeat: repeat;
}

/* Uses Bootstrap's .container for responsive width/gutter handling,
   capped at 900px so it doesn't stretch too wide on large desktops. */
.market-shell.container {
    padding-bottom: 60px;
    max-width: 900px;
}

/* Cover shows the image at its true, uncropped aspect ratio (important on
   mobile, where a fixed 16:7 box used to crop tall covers). It also
   bleeds past the Bootstrap container's side gutter so it spans edge to
   edge instead of leaving a visible margin on phones. */
.market-cover {
    background: #cbd5e1;
    line-height: 0;
    margin-left: calc(-0.5 * var(--bs-gutter-x, 1.5rem));
    margin-right: calc(-0.5 * var(--bs-gutter-x, 1.5rem));
    width: calc(100% + var(--bs-gutter-x, 1.5rem));
}
.market-cover-img {
    display: block;
    width: 100%;
    height: auto;
}
.market-cover-text {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 40px 20px;
    min-height: 160px;
    font-size: 1.6rem;
    font-weight: 700;
    white-space: pre-line;
}

.market-header {
    padding: 18px 0 4px;
}
.market-slug {
    font-size: 1.3rem;
    font-weight: 700;
}
.market-bio {
    margin-top: 8px;
    font-size: 1rem;
    white-space: pre-line;
    opacity: 0.9;
}

.market-section-title {
    padding: 16px 0 8px;
    font-weight: 700;
    font-size: 1rem;
}

.market-credits-wrap {
    position: relative;
}
.market-credits {
    display: flex;
    gap: 10px;
    overflow-x: auto;
    padding: 0 0 10px;
    scrollbar-width: none;
    -ms-overflow-style: none;
}
.market-credits::-webkit-scrollbar {
    display: none;
}

/* On desktop (mouse pointer), swap the scrollbar for left/right nav
   buttons instead — touch devices keep the natural swipe gesture. */
.market-credits-nav {
    display: none;
}
@media (hover: hover) and (pointer: fine) {
    .market-credits-nav {
        display: flex;
        align-items: center;
        justify-content: center;
        position: absolute;
        top: 40%;
        transform: translateY(-50%);
        width: 32px;
        height: 32px;
        border: 0;
        border-radius: 50%;
        background: rgba(15, 23, 42, 0.55);
        color: #fff;
        font-size: 0.9rem;
        line-height: 1;
        cursor: pointer;
        z-index: 2;
    }
    .market-credits-nav:hover {
        background: rgba(15, 23, 42, 0.75);
    }
    .market-credits-nav.is-hidden {
        opacity: 0;
        pointer-events: none;
    }
}
.market-credits-prev {
    left: -6px;
}
.market-credits-next {
    right: -6px;
}
.market-credit-item {
    flex-shrink: 0;
    width: 140px;
    background: var(--market-surface);
    border: 1px solid var(--market-border);
    border-radius: 10px;
    overflow: hidden;
}
.market-credit-thumb-btn {
    display: block;
    width: 100%;
    padding: 0;
    border: 0;
    background: none;
    cursor: pointer;
}
.market-credit-thumb-btn img {
    width: 100%;
    height: 140px;
    object-fit: cover;
    display: block;
}
@media (min-width: 720px) {
    .market-credit-item { width: 190px; }
    .market-credit-thumb-btn img { height: 190px; }
}
.market-credit-caption {
    padding: 6px 8px;
    font-size: 0.75rem;
    color: var(--market-muted);
}

/* Full-screen image viewer — plain white, edge to edge, styled after the
   Facebook chat photo viewer: X to close top-left, image centered at its
   own aspect ratio (never stretched/cropped), details off to the side.
   A custom overlay (not a Bootstrap modal) so it can truly fill the
   viewport instead of being a centered dialog with a dimmed backdrop. */
body.market-viewer-open {
    overflow: hidden;
}
.market-viewer {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 2000;
    background: #fff;
}
.market-viewer.is-open {
    display: block;
}
.market-viewer-close {
    position: absolute;
    top: 14px;
    left: 14px;
    z-index: 2;
    width: 40px;
    height: 40px;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: #0f172a;
    font-size: 1.8rem;
    line-height: 1;
    cursor: pointer;
}
.market-viewer-close:hover {
    background: #f1f5f9;
}
.market-viewer-copy {
    position: absolute;
    top: 16px;
    right: 16px;
    z-index: 2;
    background: transparent;
    color: #0f172a;
    border: 1px solid #cbd5e1;
    border-radius: 999px;
    padding: 8px 16px;
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
}
.market-viewer-copy:hover {
    background: #f1f5f9;
}

.market-viewer-body {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;
}
@media (min-width: 768px) {
    .market-viewer-body {
        flex-direction: row;
    }
}

.market-viewer-media {
    position: relative;
    flex: 1;
    min-width: 0;
    min-height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 64px 0 20px;
}
@media (min-width: 768px) {
    .market-viewer-media {
        padding-left: 20px;
        padding-right: 20px;
    }
}
.market-viewer-image {
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    object-fit: contain;
    display: block;
}
.market-viewer-noimage {
    width: 100%;
    max-width: 320px;
    aspect-ratio: 1 / 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f1f5f9;
    color: var(--market-muted);
    border-radius: 8px;
    font-size: 0.9rem;
}
.market-viewer-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 42px;
    height: 42px;
    border: 0;
    border-radius: 50%;
    background: rgba(15, 23, 42, 0.55);
    color: #fff;
    font-size: 1.1rem;
    line-height: 1;
    cursor: pointer;
    z-index: 2;
    box-shadow: 0 2px 6px rgba(15, 23, 42, 0.2);
}
.market-viewer-nav:hover {
    background: rgba(15, 23, 42, 0.75);
}
.market-viewer-prev { left: 12px; }
.market-viewer-next { right: 12px; }
.market-viewer-counter {
    position: absolute;
    bottom: 16px;
    left: 50%;
    transform: translateX(-50%);
    color: var(--market-muted);
    font-size: 0.78rem;
}
.market-viewer-caption {
    position: absolute;
    bottom: 40px;
    left: 50%;
    transform: translateX(-50%);
    max-width: 80%;
    text-align: center;
    color: #334155;
    font-size: 0.85rem;
}

/* Side panel — product code + full description, only shown in product
   detail mode (credits leave it hidden and the image takes the full width).
   Themed with the same card background/text colors as the product cards
   themselves (--card-bg-color / --card-text-color) instead of a fixed
   white, so it matches whatever theme the seller picked. */
.market-viewer-side {
    flex-shrink: 0;
    width: 100%;
    padding: 20px 24px 32px;
    overflow-y: auto;
    background: var(--card-bg-color, #ffffff);
    color: var(--card-text-color, #0f172a);
    border-top: 1px solid rgba(128, 128, 128, 0.3);
}
@media (min-width: 768px) {
    .market-viewer-side {
        width: 340px;
        padding: 84px 28px 28px;
        border-top: 0;
        border-left: 1px solid rgba(128, 128, 128, 0.3);
    }
}
.market-viewer-side-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 12px;
}
.market-viewer-code {
    font-family: monospace;
    font-size: 0.8rem;
    color: inherit;
    opacity: 0.65;
}
.market-viewer-title {
    font-weight: 700;
    font-size: 1.02rem;
    line-height: 1.4;
    color: inherit;
    margin-bottom: 12px;
}
.market-viewer-short-desc {
    font-size: 0.86rem;
    color: inherit;
    opacity: 0.75;
    margin-bottom: 12px;
}
.market-viewer-price {
    margin-bottom: 14px;
    padding-bottom: 14px;
    border-bottom: 1px solid rgba(128, 128, 128, 0.3);
}
.market-viewer-price .price-main {
    font-weight: 700;
    font-size: 1.15rem;
    color: var(--price-color, #4338ca);
    line-height: 1.35;
}
.market-viewer-price .price-sub {
    font-size: 0.85rem;
    color: inherit;
    opacity: 0.7;
    margin-top: 2px;
}
.market-viewer-desc {
    font-size: 0.92rem;
    color: inherit;
    opacity: 0.85;
    white-space: pre-line;
    line-height: 1.5;
}
.market-viewer-hint {
    margin: 20px 0 0;
    font-size: 0.75rem;
    color: inherit;
    opacity: 0.55;
}

.market-expired-notice {
    margin: 10px 0;
    padding: 12px 16px;
    background: #fef3c7;
    color: #92400e;
    border-radius: 10px;
    font-size: 0.85rem;
}

/* Sort bar — a single, clean control instead of a cluttered filter form. */
.market-sort-bar {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    padding: 0 0 10px;
}
.market-sort-label {
    font-size: 0.82rem;
    color: var(--market-muted);
}
.market-sort-select {
    width: auto;
    font-size: 0.85rem;
}

.market-products-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 14px;
    padding: 8px 0 20px;
}
@media (min-width: 480px) {
    .market-products-grid { grid-template-columns: repeat(3, 1fr); }
}
@media (min-width: 720px) {
    .market-products-grid { grid-template-columns: repeat(4, 1fr); gap: 18px; }
}

/* Product card — ported from /pro/store/assets/css/store.css's .product-card
   system so buyer listings look identical to the seller's own preview.
   Duplicated (not linked) on purpose: /markets/ doesn't reference files
   outside its own folder. */
.product-card {
    display: flex;
    flex-direction: column;
    background: var(--card-bg-color, #ffffff);
    color: var(--card-text-color, #0f172a);
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.12);
    cursor: pointer;
}
.product-card-media {
    position: relative;
    width: 100%;
    aspect-ratio: 1 / 1;
    background: #f1f5f9;
}
/* Seller-chosen alternative box shapes (shops.product_image_aspect_ratio) —
   square is the default above; these two override it. */
.product-card-media.ratio-portrait {
    aspect-ratio: 3 / 4;
}
.product-card-media.ratio-landscape {
    aspect-ratio: 4 / 3;
}
.product-card-media img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}
/* Seller-chosen alternative (shops.product_image_display_mode = 'cover'):
   fills the box edge to edge with no letterboxing, cropping whatever
   doesn't fit instead. */
.product-card-media.display-cover img {
    object-fit: cover;
}
.product-card-image-count {
    position: absolute;
    right: 6px;
    bottom: 6px;
    background: rgba(0, 0, 0, 0.6);
    color: #fff;
    font-size: 0.68rem;
    font-weight: 600;
    padding: 1px 7px;
    border-radius: 999px;
    line-height: 1.4;
}
.product-card-media .no-image {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--market-muted);
    font-size: 0.7rem;
    text-align: center;
    padding: 6px;
}
.product-card-body {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 10px 10px 4px;
    flex: 1;
}
.product-card-top-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
}
.product-card-game {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--price-color, #4338ca);
    background: rgba(67, 56, 202, 0.1);
    padding: 2px 8px;
    border-radius: 999px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.product-card-title {
    font-weight: 700;
    font-size: 0.88rem;
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.product-card-desc {
    font-size: 0.76rem;
    opacity: 0.75;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.product-card-price {
    margin-top: auto;
    padding-top: 6px;
}
.product-card-price .price-main {
    font-weight: 700;
    font-size: 0.9rem;
    color: var(--price-color, #4338ca);
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.product-card-price .price-sub {
    font-size: 0.74rem;
    opacity: 0.7;
    margin-top: 2px;
}
.product-card-code {
    display: block;
    font-family: monospace;
    font-size: 0.68rem;
    opacity: 0.6;
    margin-top: 4px;
}
.badge {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 999px;
    font-size: 0.68rem;
    font-weight: 700;
    white-space: nowrap;
}
.badge-available { background: #dcfce7; color: #166534; }
.badge-reserved { background: #fef3c7; color: #92400e; }
.badge-sold { background: #e2e8f0; color: #475569; }

.market-empty, .market-fullpage-message {
    text-align: center;
    padding: 60px 20px;
    color: var(--market-muted);
}
.market-fullpage-message h1 {
    font-size: 1.3rem;
    margin-bottom: 8px;
    color: #0f172a;
}

/* Floating "contact shop" speed-dial: the main button toggles a vertical
   stack of round Facebook/Line/phone icon buttons above it, and itself
   swaps into a close ("X") button while open — no modal/popup dialog. */
.market-contact-widget {
    position: fixed;
    right: 18px;
    bottom: 18px;
    /* Above the image viewer (z-index 2000) and everything else on the
       page, so the contact button always stays reachable — nothing,
       including the product/credit photo popup, should ever cover it. */
    z-index: 2100;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 12px;
}
.market-contact-options {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    opacity: 0;
    visibility: hidden;
    transform: translateY(10px);
    transition: opacity 0.18s ease, transform 0.18s ease, visibility 0.18s;
}
.market-contact-widget.is-open .market-contact-options {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}
.market-contact-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 46px;
    height: 46px;
    border-radius: 50%;
    color: #fff;
    font-size: 1.15rem;
    text-decoration: none;
    box-shadow: 0 3px 10px rgba(15, 23, 42, 0.25);
}
.market-contact-icon-fb { background: #1877f2; }
.market-contact-icon-line { background: #06c755; }
.market-contact-icon-phone { background: #475569; }
.market-contact-icon-ig {
    background: radial-gradient(circle at 30% 107%, #fdf497 0%, #fdf497 5%, #fd5949 45%, #d6249f 60%, #285aeb 90%);
}
.market-contact-empty-pill {
    background: #fff;
    color: var(--market-muted);
    font-size: 0.75rem;
    padding: 8px 14px;
    border-radius: 999px;
    box-shadow: 0 3px 10px rgba(15, 23, 42, 0.2);
    white-space: nowrap;
}
.market-contact-fab {
    padding: 13px 20px;
    border: 0;
    border-radius: 999px;
    background: var(--price-color, #4338ca);
    color: #fff;
    font-size: 0.92rem;
    font-weight: 700;
    box-shadow: 0 4px 14px rgba(15, 23, 42, 0.28);
    cursor: pointer;
}
.market-contact-fab-close { display: none; }
.market-contact-widget.is-open .market-contact-fab-label { display: none; }
.market-contact-widget.is-open .market-contact-fab-close { display: inline; }
