/* Visibility */
#product-modal.hidden {
    display: none !important
}

#img-lightbox.hidden {
    display: none !important
}

/* Modal Root */
#product-modal {
    position: fixed;
    inset: 0;
    z-index: 999997;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 12px;
    background: rgba(0, 0, 0, .6);
    backdrop-filter: blur(2px);
    overflow: auto;
    /* erlaubt Scrollen falls Modal größer als Screen */
}

/* Modal Box */
#product-modal .modal-content {
    display: grid;
    gap: 12px;
    grid-template-rows: auto auto auto auto 1fr auto;
    /* close | title | stage | thumbs | info | cta */
    background: var(--pm-bg, #1f1f1f);
    color: var(--text-color, #fff);
    border-radius: 14px;
    box-shadow: 0 20px 80px rgba(0, 0, 0, .6);

    /* Größe begrenzen */
    max-width: 95vw;
    max-height: 95vh;
    width: auto;

    padding: 12px;
    overflow-y: auto;
    /* erlaubt vertikales Scrollen im Modal */
}

/* Close */
#product-modal .close-btn {
    position: sticky;
    top: 0;
    margin-left: auto;
    z-index: 999997;
    width: 36px;
    height: 36px;
    border: 0;
    border-radius: 8px;
    background: rgba(255, 255, 255, .08);
    color: #fff;
    font-size: 22px;
    cursor: pointer
}

#product-modal .close-btn:hover {
    filter: brightness(1.08)
}

/* Title */
#product-modal .pm-title {
    margin: 0;
    text-align: center;
    font-size: clamp(1.05rem, 2.2vw, 1.45rem);
    font-weight: 800;
    color: var(--accent-color, #e9a624)
}

/* Stage: 4:3 */
#product-modal .stage {
    position: relative;
    width: 100%;
    aspect-ratio: 4/3;
    max-height: 60vh;
    /* Bild passt sich Screen an */
    border-radius: 12px;
    overflow: hidden;
    background: #0d0d0d;
}

#product-modal #pm-img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
}

#product-modal .stage.cover #pm-img {
    object-fit: cover
}

/* Arrows */
#product-modal .nav-prev,
#product-modal .nav-next {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 42px;
    height: 42px;
    border: 0;
    border-radius: 50%;
    background: rgba(0, 0, 0, .45);
    color: #fff;
    font-size: 22px;
    cursor: pointer
}

#product-modal .nav-prev {
    left: 8px
}

.nav-next {
    right: 8px
}

#product-modal .nav-prev:hover,
#product-modal .nav-next:hover {
    background: rgba(0, 0, 0, .65)
}

/* Thumbs */
#product-modal .pm-thumbs {
    display: flex;
    gap: 8px;
    padding: 6px 2px 0;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    max-width: 100%;
}

#product-modal .pm-thumbs::-webkit-scrollbar {
    height: 8px
}

#product-modal .pm-thumbs::-webkit-scrollbar-thumb {
    background: rgba(128, 128, 128, .4);
    border-radius: 10px
}

#product-modal .pm-thumbs .thumb {
    border: 0;
    background: transparent;
    padding: 0;
    flex: 0 0 auto;
    border-radius: 8px;
    cursor: pointer;
    outline: none
}

#product-modal .pm-thumbs .thumb img {
    display: block;
    width: 120px;
    aspect-ratio: 4 / 3;
    height: auto;
    object-fit: cover;
    border-radius: 8px
}

@media (max-width:560px) {
    #product-modal .pm-thumbs .thumb img {
        width: 96px
    }
}

#product-modal .pm-thumbs .thumb:hover img {
    transform: translateY(-1px) scale(1.02);
    opacity: 1;
    box-shadow: 0 0 0 2px var(--accent-color, #e9a624)
}

#product-modal .pm-thumbs .thumb.active img {
    box-shadow: 0 0 0 2px var(--accent-color, #e9a624);
    opacity: 1
}

/* Info & Details */
#product-modal .pm-info {
    overflow-y: auto;
    max-height: 25vh;
    /* begrenzen, damit der CTA immer sichtbar bleibt */
}

#product-modal .pm-desc {
    margin: 6px 0 12px;
    line-height: 1.5;
    color: var(--text-muted-color, #ccc)
}

#product-modal .details-grid {
    display: grid;
    gap: 8px 12px;
    align-items: start;
    grid-template-columns: 1fr 2fr
}

@media (min-width:900px) {
    #product-modal .details-grid {
        grid-template-columns: 1fr 2fr 1fr 2fr
    }
}

#product-modal .details-grid .detail {
    display: contents
}

#product-modal .details-grid .label {
    font-weight: 600;
    opacity: .8;
    padding: 6px 8px;
    border-bottom: 1px solid rgba(255, 255, 255, .1)
}

#product-modal .details-grid .value {
    padding: 6px 8px;
    border-bottom: 1px solid rgba(255, 255, 255, .1)
}

/* CTA */
#product-modal .pm-cta {
    display: flex;
    justify-content: center;
    padding-top: 6px
}

#product-modal .btn-cta,
#product-modal #pm-cta {
    appearance: none;
    border: 0;
    cursor: pointer;
    padding: 10px 16px;
    border-radius: 10px;
    background: var(--accent-color, #e9a624);
    color: #111;
    font-weight: 700
}

#product-modal .btn-cta:hover,
#product-modal #pm-cta:hover {
    filter: brightness(1.06)
}

/* Lightbox */
#img-lightbox {
    position: fixed;
    inset: 0;
    z-index: 999999;
    display: grid;
    place-items: center;
    background: rgba(0, 0, 0, .8)
}

#img-lightbox .lb-content {
    position: relative;
    max-width: 95vw;
    max-height: 95vh
}

#img-lightbox #lb-img {
    max-width: 95vw;
    max-height: 95vh;
    display: block
}

#img-lightbox .lb-prev,
#img-lightbox .lb-next,
#img-lightbox .lb-close {
    position: absolute;
    border: 0;
    background: rgba(0, 0, 0, .4);
    color: #fff;
    cursor: pointer
}

#img-lightbox .lb-prev,
#img-lightbox .lb-next {
    top: 50%;
    transform: translateY(-50%);
    padding: .4rem .6rem;
    font-size: 2rem
}

#img-lightbox .lb-prev {
    left: -.5rem
}

#img-lightbox .lb-next {
    right: -.5rem
}

#img-lightbox .lb-close {
    top: .25rem;
    right: .25rem;
    padding: .2rem .5rem;
    font-size: 1.5rem
}

/* ===========================
   LIGHT MODE STYLES
   =========================== */
body.light-mode #product-modal .modal-content {
    background: #f4f4f4;
    color: #222;
    box-shadow: 0 10px 40px rgba(0, 0, 0, .2);
}

body.light-mode #product-modal .close-btn {
    background: rgba(0, 0, 0, .08);
    color: #111;
}

body.light-mode #product-modal .pm-title {
    color: var(--accent-color, #e9a624);
}

body.light-mode #product-modal .stage {
    background: #ddd;
}

body.light-mode #product-modal .pm-desc {
    color: #555;
}

body.light-mode #product-modal .details-grid .label {
    border-bottom: 1px solid rgba(0, 0, 0, .1);
    color: #333;
}

body.light-mode #product-modal .details-grid .value {
    border-bottom: 1px solid rgba(0, 0, 0, .1);
    color: #222;
}

body.light-mode #product-modal .btn-cta,
body.light-mode #product-modal #pm-cta {
    background: var(--accent-color, #e9a624);
    color: #fff;
}

body.light-mode #product-modal .btn-cta:hover,
body.light-mode #product-modal #pm-cta:hover {
    filter: brightness(1.08);
}

body.light-mode #product-modal .pm-thumbs .thumb img {
    border: 1px solid rgba(0, 0, 0, .1);
}

body.light-mode #product-modal .pm-thumbs .thumb:hover img {
    box-shadow: 0 0 0 2px var(--accent-color, #e9a624);
}

body.light-mode #product-modal .pm-thumbs .thumb.active img {
    box-shadow: 0 0 0 2px var(--accent-color, #e9a624);
}

/* Overlay füllt Viewport und erlaubt Außen-Scrollen bei sehr kleinen Screens */
#product-modal {
    position: fixed;
    inset: 0;
    z-index: 999998;
    display: grid;
    place-items: center;
    padding: 20px;
    background: rgba(0, 0, 0, .55);
    backdrop-filter: blur(2px);
    overflow: auto;
    /* Fallback-Scroll, falls Content höher als 100vh */
}

/* Karte: begrenzte Höhe + Innen-Scroll */
#product-modal .modal-content {
    width: min(1000px, 96vw);
    max-height: calc(100vh - 40px);
    /* wichtig: alles passt in den Viewport-Rahmen */
    overflow: auto;
    /* -> Inhalt scrollbar */
    border-radius: 16px;
    background: var(--panel-bg, #222);
    box-shadow: 0 14px 50px rgba(0, 0, 0, .4);
    display: grid;
    grid-template-rows: auto auto auto auto auto;
    /* Titel, Slideshow, Info, CTA ... */
    gap: 12px;
}

/* Bildbühne: niemals höher als ~60vh; Bild skaliert 'contain' */
#pm-stage {
    position: relative;
    width: 100%;
    max-height: 60vh;
    aspect-ratio: 4 / 3;
    /* schöne Grundform, bricht bei sehr schmalen Screens */
    overflow: hidden;
    border-radius: 12px;
    background: #111;
}

#pm-stage img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    /* nichts abschneiden */
    display: block;
}

/* Thumbs: horizontal scrollbar bei Platzmangel */
#pm-thumbs {
    display: flex;
    gap: 10px;
    margin-top: 10px;
    overflow-x: auto;
    padding-bottom: 6px;
    /* Platz für Scrollbar */
}

/* Info-Block unter den Bildern: eigener Scrollbereich falls nötig */
.pm-info {
    max-height: 28vh;
    /* zusammen mit 60vh oben bleibt genug Platz */
    overflow: auto;
}

/* Body-Scroll bei offenem Modal sperren (mit Klasse, s.u.) */
body.modal-open {
    overflow: hidden;
}