/* ═══════════════════════════════════════════════════
   AZ Dev — App Detail Modal
   ═══════════════════════════════════════════════════ */

/* ── Overlay backdrop ───────────────────────────────── */
#app-modal-backdrop {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    z-index: 9998;
    background: rgba(0, 0, 0, 0);
    backdrop-filter: blur(0px);
    -webkit-backdrop-filter: blur(0px);
    pointer-events: none;
    transition:
        background 0.35s ease,
        backdrop-filter 0.35s ease;
}
#app-modal-backdrop.open {
    background: rgba(0, 0, 0, 0.82);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    pointer-events: all;
}

/* ── Modal container ─────────────────────────────────── */
#app-modal {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.25rem;
    pointer-events: none;
    opacity: 0;
    transform: translateY(24px) scale(0.97);
    transition:
        opacity 0.32s cubic-bezier(0.22, 1, 0.36, 1),
        transform 0.32s cubic-bezier(0.22, 1, 0.36, 1);
}
#app-modal.open {
    pointer-events: all;
    opacity: 1;
    transform: translateY(0) scale(1);
}

/* ── Modal inner panel ───────────────────────────────── */
#app-modal-panel {
    background: #0D1526;
    border: 1px solid #1E2D4A;
    border-radius: 1.25rem;
    width: 100%;
    max-width: 1020px;
    /* vh fallback, then svh for browsers that support it */
    height: calc(100vh - 2.5rem);
    max-height: calc(100vh - 2.5rem);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow:
        0 0 0 1px rgba(0, 216, 255, 0.08),
        0 32px 80px rgba(0, 0, 0, 0.7),
        0 0 80px rgba(0, 216, 255, 0.06);
    position: relative;
}
@supports (height: 100svh) {
    #app-modal-panel {
        height: calc(100svh - 2.5rem);
        max-height: calc(100svh - 2.5rem);
    }
}

/* ── Modal header ─────────────────────────────────────── */
#app-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.875rem 1.25rem;
    border-bottom: 1px solid #1E2D4A;
    background: rgba(5, 11, 24, 0.6);
    flex-shrink: 0;
    gap: 0.75rem;
}
#app-modal-header-left {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    min-width: 0;
    flex: 1;
}
#app-modal-category-badge {
    font-size: 0.6rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: #050B18;
    padding: 0.2rem 0.6rem;
    border-radius: 9999px;
    background: #00D8FF;
    white-space: nowrap;
    flex-shrink: 0;
}
#app-modal-title {
    font-family: 'Outfit', sans-serif;
    font-weight: 800;
    font-size: 1.1rem;
    color: white;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
#app-modal-tagline {
    font-size: 0.7rem;
    color: #64748b;
    font-weight: 500;
    margin-top: 1px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
#app-modal-close {
    width: 2rem;
    height: 2rem;
    min-width: 2rem;
    border-radius: 50%;
    border: 1px solid #1E2D4A;
    background: rgba(255,255,255,0.04);
    color: #94a3b8;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 0.9rem;
    transition: background 0.2s, color 0.2s, border-color 0.2s, transform 0.2s;
    flex-shrink: 0;
    -webkit-tap-highlight-color: transparent;
}
#app-modal-close:hover {
    background: rgba(0, 216, 255, 0.1);
    color: #00D8FF;
    border-color: rgba(0, 216, 255, 0.4);
    transform: rotate(90deg);
}

/* ── Modal body: two-column layout ───────────────────── */
#app-modal-body {
    display: grid;
    grid-template-columns: 1fr 1fr;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

/* ── Left: Gallery ───────────────────────────────────── */
#app-modal-gallery {
    position: relative;
    background: #050B18;
    border-right: 1px solid #1E2D4A;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 0;
}
#app-modal-gallery-main {
    flex: 1;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    min-height: 0;
}
.modal-gallery-slide {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transform: translateX(30px);
    transition: opacity 0.28s ease, transform 0.28s ease;
    pointer-events: none;
}
.modal-gallery-slide.active {
    opacity: 1;
    transform: translateX(0);
    pointer-events: all;
}
.modal-gallery-slide.exit-left {
    opacity: 0;
    transform: translateX(-30px);
}
.modal-gallery-slide img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}
.modal-gallery-slide video {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

/* Gallery navigation arrows */
.modal-gallery-arrow {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    z-index: 20;
    width: 2rem;
    height: 2rem;
    border-radius: 50%;
    background: rgba(0,0,0,0.6);
    border: 1px solid rgba(255,255,255,0.12);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 0.7rem;
    transition: background 0.2s, border-color 0.2s;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    -webkit-tap-highlight-color: transparent;
}
.modal-gallery-arrow:hover,
.modal-gallery-arrow:active {
    background: rgba(0, 216, 255, 0.2);
    border-color: rgba(0, 216, 255, 0.4);
    color: #00D8FF;
}
#modal-gallery-prev { left: 0.625rem; }
#modal-gallery-next { right: 0.625rem; }

/* Gallery counter */
#modal-gallery-counter {
    position: absolute;
    top: 0.625rem;
    left: 0.625rem;
    z-index: 20;
    background: rgba(0,0,0,0.65);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    color: white;
    font-size: 0.65rem;
    font-weight: 700;
    padding: 0.18rem 0.55rem;
    border-radius: 9999px;
    border: 1px solid rgba(255,255,255,0.1);
    pointer-events: none;
}

/* Gallery thumbnails strip */
#app-modal-gallery-thumbs {
    display: flex;
    gap: 0.4rem;
    padding: 0.5rem 0.625rem;
    overflow-x: auto;
    background: rgba(0,0,0,0.35);
    border-top: 1px solid #1E2D4A;
    flex-shrink: 0;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    scrollbar-color: #1E2D4A transparent;
}
#app-modal-gallery-thumbs::-webkit-scrollbar { height: 2px; }
#app-modal-gallery-thumbs::-webkit-scrollbar-thumb { background: #1E2D4A; border-radius: 2px; }

.modal-thumb {
    flex-shrink: 0;
    width: 46px;
    height: 36px;
    border-radius: 5px;
    border: 2px solid transparent;
    overflow: hidden;
    cursor: pointer;
    background: #0D1526;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: border-color 0.2s;
    -webkit-tap-highlight-color: transparent;
}
.modal-thumb.active { border-color: #00D8FF; }
.modal-thumb img { width: 100%; height: 100%; object-fit: cover; }
.modal-thumb-icon { font-size: 1rem; color: rgba(0,216,255,0.5); }

/* ── Right: Details ──────────────────────────────────── */
#app-modal-details {
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 1.25rem;
    gap: 1rem;
    scrollbar-width: thin;
    scrollbar-color: #1E2D4A transparent;
    min-height: 0;
}
#app-modal-details::-webkit-scrollbar { width: 3px; }
#app-modal-details::-webkit-scrollbar-thumb { background: #1E2D4A; border-radius: 2px; }

#app-modal-desc {
    color: #94a3b8;
    font-size: 0.85rem;
    line-height: 1.7;
    margin: 0;
}

#app-modal-pricing {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.7rem;
    font-weight: 700;
    padding: 0.3rem 0.75rem;
    border-radius: 9999px;
}

.modal-divider {
    border: none;
    border-top: 1px solid #1E2D4A;
    margin: 0;
}

.modal-section-label {
    font-size: 0.62rem;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: #475569;
    margin-bottom: 0.5rem;
}

#app-modal-features {
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
    list-style: none;
    margin: 0;
    padding: 0;
}
.modal-feature-item {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    font-size: 0.82rem;
    color: #cbd5e1;
}
.modal-feature-dot {
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: #00D8FF;
    flex-shrink: 0;
    box-shadow: 0 0 5px #00D8FF;
}

#app-modal-tech {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
}
.modal-tech-tag {
    font-size: 0.67rem;
    font-weight: 600;
    font-family: 'JetBrains Mono', monospace;
    padding: 0.22rem 0.55rem;
    background: rgba(255,255,255,0.04);
    border: 1px solid #1E2D4A;
    border-radius: 4px;
    color: #64748b;
}

#app-modal-ctas {
    display: flex;
    flex-direction: column;
    gap: 0.55rem;
    margin-top: auto;
    padding-top: 0.25rem;
}
.modal-cta-primary {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.8rem;
    background: #00D8FF;
    color: #050B18;
    font-weight: 800;
    font-size: 0.85rem;
    border-radius: 0.625rem;
    text-decoration: none;
    transition: background 0.2s, transform 0.2s, box-shadow 0.2s;
    box-shadow: 0 4px 20px rgba(0, 216, 255, 0.25);
    -webkit-tap-highlight-color: transparent;
}
.modal-cta-primary:hover,
.modal-cta-primary:active {
    background: #67e8f9;
    transform: translateY(-2px);
    box-shadow: 0 8px 30px rgba(0, 216, 255, 0.4);
}
.modal-cta-youtube {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.7rem;
    background: rgba(220, 38, 38, 0.12);
    border: 1px solid rgba(220, 38, 38, 0.3);
    color: #fca5a5;
    font-weight: 700;
    font-size: 0.85rem;
    border-radius: 0.625rem;
    text-decoration: none;
    transition: background 0.2s, border-color 0.2s, transform 0.2s;
    -webkit-tap-highlight-color: transparent;
}
.modal-cta-youtube:hover,
.modal-cta-youtube:active {
    background: rgba(220, 38, 38, 0.22);
    border-color: rgba(220, 38, 38, 0.6);
    transform: translateY(-2px);
}
.modal-cta-disabled {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.8rem;
    background: rgba(255,255,255,0.03);
    border: 1px solid #1E2D4A;
    color: #334155;
    font-weight: 700;
    font-size: 0.85rem;
    border-radius: 0.625rem;
    cursor: default;
}

.modal-youtube-slide {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.875rem;
    cursor: pointer;
    background: linear-gradient(135deg, rgba(127,29,29,0.4), #050B18);
    -webkit-tap-highlight-color: transparent;
}
.modal-youtube-slide:hover .modal-yt-icon,
.modal-youtube-slide:active .modal-yt-icon { transform: scale(1.1); }
.modal-yt-icon {
    width: 56px;
    height: 56px;
    background: #dc2626;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    color: white;
    box-shadow: 0 0 36px rgba(220,38,38,0.5);
    transition: transform 0.2s;
}
.modal-youtube-label {
    color: white;
    font-size: 0.85rem;
    font-weight: 600;
}

.modal-unavailable-slide {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.625rem;
    background: #0D1526;
    padding: 1rem;
    text-align: center;
}

/* ═══════════════════════════════════════════════════
   MOBILE — bottom sheet, full width, slides up
   ═══════════════════════════════════════════════════ */
@media (max-width: 768px) {

    /* Container: no padding, align to bottom */
    #app-modal {
        padding: 0;
        align-items: flex-end;
        /* Slide up from below instead of scale */
        transform: translateY(100%);
    }
    #app-modal.open {
        transform: translateY(0);
        opacity: 1;
    }

    /* Panel: fills width, rounded top only, safe height */
    #app-modal-panel {
        border-radius: 1rem 1rem 0 0;
        border-left: none;
        border-right: none;
        border-bottom: none;
        width: 100%;
        max-width: 100%;
        /* 92vh fallback; 92svh excludes address bar on iOS/Android */
        height: 92vh;
        max-height: 92vh;
    }
    @supports (height: 100svh) {
        #app-modal-panel {
            height: 92svh;
            max-height: 92svh;
        }
    }

    /* Drag handle indicator */
    #app-modal-panel::before {
        content: '';
        display: block;
        width: 36px;
        height: 4px;
        border-radius: 2px;
        background: rgba(255,255,255,0.15);
        margin: 0.55rem auto 0;
        flex-shrink: 0;
    }

    /* Stack: gallery top, details below — both scroll together */
    #app-modal-body {
        grid-template-columns: 1fr;
        grid-template-rows: auto 1fr;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        /* reset the overflow:hidden from desktop so inner scroll works */
        overflow-x: hidden;
    }

    /* Gallery fixed height on mobile */
    #app-modal-gallery {
        border-right: none;
        border-bottom: 1px solid #1E2D4A;
        height: 260px;
        min-height: 260px;
        max-height: 260px;
        flex-shrink: 0;
    }

    /* Details: natural height, no inner scroll */
    #app-modal-details {
        overflow-y: unset;
        padding: 1rem;
        /* safe area bottom so buttons aren't hidden by home bar */
        padding-bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
    }

    /* CTAs don't need margin-top: auto when stacked */
    #app-modal-ctas {
        margin-top: 0.5rem;
    }

    /* Tighter header */
    #app-modal-header { padding: 0.7rem 1rem; }
    #app-modal-title  { font-size: 1rem; }

    /* Arrows always visible on touch (no hover) */
    #modal-gallery-prev,
    #modal-gallery-next {
        display: flex !important;
        opacity: 0.9;
    }
}

/* ═══════════════════════════════════════════════════
   LIGHT MODE
   ═══════════════════════════════════════════════════ */
html:not(.dark) #app-modal-panel          { background: #ffffff; border-color: #e2e8f0; }
html:not(.dark) #app-modal-header         { background: rgba(248,250,252,0.9); border-color: #e2e8f0; }
html:not(.dark) #app-modal-title          { color: #0f172a; }
html:not(.dark) #app-modal-tagline        { color: #94a3b8; }
html:not(.dark) #app-modal-close          { border-color: #e2e8f0; background: #f1f5f9; color: #64748b; }
html:not(.dark) #app-modal-gallery        { background: #f1f5f9; border-color: #e2e8f0; }
html:not(.dark) #app-modal-gallery-thumbs { background: rgba(0,0,0,0.04); border-color: #e2e8f0; }
html:not(.dark) .modal-thumb              { background: #ffffff; }
html:not(.dark) #app-modal-details        { background: #ffffff; }
html:not(.dark) #app-modal-desc           { color: #64748b; }
html:not(.dark) .modal-section-label      { color: #94a3b8; }
html:not(.dark) .modal-feature-item       { color: #334155; }
html:not(.dark) .modal-tech-tag           { background: #f8fafc; border-color: #e2e8f0; color: #94a3b8; }
html:not(.dark) .modal-divider            { border-color: #e2e8f0; }
html:not(.dark) .modal-cta-disabled       { background: #f8fafc; border-color: #e2e8f0; color: #cbd5e1; }
html:not(.dark) #app-modal-panel::before  { background: rgba(0,0,0,0.12); }
