/* JDM Stuff — Gallery
   -----------------------------------------------------------------
   All styles namespaced under .jdmg- to avoid collisions with the
   wholesale individual-listing markup (which uses .jdmw-*).
*/

.jdmg-gallery {
    display: block;
    width: 100%;
    max-width: 100%;
    margin: 0 0 1.5em;
    box-sizing: border-box;
}

.jdmg-gallery * {
    box-sizing: border-box;
}

/* ── View toggle ─────────────────────────────────────────────── */

.jdmg-view-toggle {
    display: flex;
    gap: 0;
    margin-bottom: 0.75em;
    border-radius: 6px;
    overflow: hidden;
    width: fit-content;
    border: 1px solid #ccc;
}

.jdmg-toggle-btn {
    padding: 0.4em 1em;
    font-size: 0.9em;
    background: #f5f5f5;
    color: #333;
    border: none;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
    line-height: 1.4;
}

.jdmg-toggle-btn + .jdmg-toggle-btn {
    border-left: 1px solid #ccc;
}

.jdmg-toggle-btn:hover {
    background: #e5e5e5;
}

.jdmg-toggle-btn.is-active {
    background: #222;
    color: #fff;
}

/* ── Carousel ────────────────────────────────────────────────── */

.jdmg-carousel-wrapper {
    display: block;
    width: 100%;
}

.jdmg-carousel {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #111;
    border-radius: 6px;
    overflow: hidden;
    width: 100%;
    aspect-ratio: 4 / 3;
}

.jdmg-main-image {
    max-width: 100% !important;
    max-height: 100%;
    width: auto;
    height: 100% !important;
    object-fit: cover;
    cursor: zoom-in;
    user-select: none;
    -webkit-user-drag: none;
    touch-action: pan-y;  /* allow vertical scroll; JS preventDefault's horizontal */
}

.jdmg-arrow {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(0, 0, 0, 0.45);
    color: #fff;
    border: none;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    font-size: 1.6em;
    line-height: 1;
    cursor: pointer;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s ease;
}

.jdmg-arrow:hover,
.jdmg-arrow:focus-visible {
    background: rgba(0, 0, 0, 0.75);
    outline: none;
}

.jdmg-prev { left: 8px; }
.jdmg-next { right: 8px; }

/* ── Thumbnails ──────────────────────────────────────────────── */

.jdmg-thumbnails {
    display: flex;
    gap: 6px;
    margin-top: 8px;
    overflow-x: auto;
    overflow-y: hidden;
    scroll-behavior: smooth;
    padding-bottom: 4px;
    /* Slim scrollbar */
    scrollbar-width: thin;
}

.jdmg-thumbnails::-webkit-scrollbar {
    height: 6px;
}
.jdmg-thumbnails::-webkit-scrollbar-thumb {
    background: #bbb;
    border-radius: 3px;
}

.jdmg-thumbnail {
    flex: 0 0 auto;
    width: 90px;
    height: 60px;
    object-fit: cover;
    cursor: pointer;
    border: 2px solid transparent;
    border-radius: 4px;
    opacity: 0.65;
    transition: opacity 0.15s ease, border-color 0.15s ease;
}

.jdmg-thumbnail:hover {
    opacity: 0.9;
}

.jdmg-thumbnail.is-active {
    opacity: 1;
    border-color: #d33;
}

/* ── Grid view ───────────────────────────────────────────────── */

.jdmg-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    width: 100%;
}

.jdmg-grid[hidden],
.jdmg-carousel-wrapper[hidden] {
    display: none !important;
}

.jdmg-grid-item {
    display: block;
    padding: 0;
    border: none;
    background: #111;
    cursor: zoom-in;
    border-radius: 4px;
    overflow: hidden;
    aspect-ratio: 4 / 3;
}

.jdmg-grid-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: transform 0.25s ease;
}

.jdmg-grid-item:hover img,
.jdmg-grid-item:focus-visible img {
    transform: scale(1.04);
}

.jdmg-grid-item:focus-visible {
    outline: 2px solid #d33;
    outline-offset: 2px;
}

/* ── Lightbox overlay ────────────────────────────────────────── */

.jdmg-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100000;
    padding: 20px;
}

.jdmg-overlay[hidden] {
    display: none !important;
}

.jdmg-overlay-img {
    max-width: 95vw;
    max-height: 90vh;
    object-fit: contain;
    user-select: none;
    -webkit-user-drag: none;
    touch-action: pan-y;
}

.jdmg-overlay-btn {
    position: absolute;
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
    border: none;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    font-size: 1.4em;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s ease;
}

.jdmg-overlay-btn:hover,
.jdmg-overlay-btn:focus-visible {
    background: rgba(255, 255, 255, 0.3);
    outline: none;
}

.jdmg-overlay-close {
    top: 16px;
    right: 16px;
    font-size: 1.6em;
}

.jdmg-overlay-prev {
    left: 16px;
    top: 50%;
    transform: translateY(-50%);
}

.jdmg-overlay-next {
    right: 16px;
    top: 50%;
    transform: translateY(-50%);
}

.jdmg-overlay-counter {
    position: absolute;
    bottom: 16px;
    left: 50%;
    transform: translateX(-50%);
    color: #fff;
    background: rgba(0, 0, 0, 0.5);
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 0.85em;
}

/* ── Mobile tweaks ───────────────────────────────────────────── */

@media (max-width: 600px) {
    .jdmg-thumbnail {
        width: 70px;
        height: 50px;
    }

    .jdmg-arrow {
        width: 34px;
        height: 34px;
        font-size: 1em;
    }

    .jdmg-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 4px;
    }

    .jdmg-overlay-btn {
        width: 40px;
        height: 40px;
    }
}
