/* ==========================================
   V2 Attachment Preview / Lightbox Component
   Reusable full-screen preview for attachments.
   Supports single item or multi-item with bottom thumbnail slider.

   Usage:
     window.v2AttachmentPreview.open({ url, type, fileName, onDelete })
     window.v2AttachmentPreview.open({ items, startIndex, onDelete })
     window.v2AttachmentPreview.close()

   Types: 'image', 'video', 'doc'
   ========================================== */

/* Overlay */
.v2-ap-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    z-index: 200001;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

/* Content area */
.v2-ap-content {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    max-width: 90%;
    max-height: calc(100% - 80px);
    padding: 40px 0;
    overflow: hidden;
    min-height: 0;
}
/* When bottom strip is visible, shrink content to prevent overflow */
.v2-ap-overlay.v2-ap-has-strip .v2-ap-content {
    max-height: calc(100% - 168px);
}

/* Image */
.v2-ap-img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: 4px;
}

/* Video */
.v2-ap-video {
    max-width: 100%;
    max-height: 100%;
    border-radius: 4px;
    outline: none;
}

/* PDF / Office iframe — wrapped so the spinner can sit underneath the
   iframe while it loads. The iframe fades in once `load` fires. */
.v2-ap-pdf-wrap {
    position: relative;
    width: 100%;
    height: 100%;
    border-radius: 4px;
    overflow: hidden;
    background: #1a1a1a;
}
.v2-ap-pdf {
    width: 100%;
    height: 100%;
    border: none;
    border-radius: 4px;
    background: #fff;
    transition: opacity 0.25s ease;
    position: relative;
    z-index: 1;
}
.v2-ap-pdf.v2-ap-pdf-loading {
    opacity: 0;
}

/* Loading state: dark surface with a small spinner so the user gets
   instant feedback. Sits behind the iframe (which is opacity:0 while
   loading) and disappears together with the .v2-ap-pdf-loading class. */
.v2-ap-loading {
    position: absolute;
    inset: 0;
    z-index: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
    color: rgba(255, 255, 255, 0.85);
    font-family: 'Lato', sans-serif;
    font-size: 14px;
    background: #1a1a1a;
    pointer-events: none;
}
.v2-ap-spinner {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 3px solid rgba(255, 255, 255, 0.15);
    border-top-color: #fff;
    animation: v2ApSpin 0.8s linear infinite;
}
@keyframes v2ApSpin {
    to { transform: rotate(360deg); }
}
.v2-ap-loading-text {
    letter-spacing: 0.4px;
}

/* Expand content area for document previews. Reserve a strip at the top so
   the close/download buttons don't sit on top of the iframe's white body
   (they have translucent backgrounds and would otherwise disappear). */
.v2-ap-content.v2-ap-doc-mode {
    max-width: 95%;
    width: 95%;
    min-width: 800px;
    padding-top: 72px;
}

/* Doc placeholder */
.v2-ap-doc {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
}
.v2-ap-doc svg {
    opacity: 0.9;
}
.v2-ap-doc-name {
    color: #fff;
    font-size: 14px;
    font-family: 'Lato', sans-serif;
    max-width: 300px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Top-right action buttons. High z-index so iframe stacking contexts can't
   sit on top of them in document preview mode. */
.v2-ap-actions {
    position: absolute;
    top: 20px;
    right: 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    z-index: 10;
}
.v2-ap-delete-btn,
.v2-ap-download-btn {
    height: 40px;
    padding: 0 16px;
    border-radius: 20px;
    background: rgba(255, 255, 255, 0.15);
    color: #FFFFFF;
    border: 1px solid rgba(255, 255, 255, 0.3);
    font-family: 'Lato', sans-serif;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    outline: none;
    transition: background 0.15s;
}
.v2-ap-delete-btn:hover,
.v2-ap-download-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}
.v2-ap-close-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.15);
    color: #FFFFFF;
    border: none;
    font-size: 28px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    outline: none;
    transition: background 0.15s;
}
.v2-ap-close-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* ---- Bottom Thumbnail Slider Strip ---- */
.v2-ap-strip {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 16px 24px;
    flex-shrink: 0;
    overflow: hidden;
    width: 100%;
}
/* Add button (optional, matches question attachment flow) */
.v2-ap-add-btn {
    width: 56px;
    height: 56px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.15);
    border: 1px dashed rgba(255, 255, 255, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: background 0.15s;
}
.v2-ap-add-btn:hover {
    background: rgba(255, 255, 255, 0.25);
}
/* PS-2206 max-disable */
.v2-ap-add-btn.v2-ap-add-disabled {
    opacity: .4;
    pointer-events: none;
    cursor: not-allowed;
}
.v2-ap-thumbs-wrap {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    overflow: hidden;
    min-width: 0;
    max-width: calc(100% - 80px);
}
.v2-ap-thumbs {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
    scroll-behavior: smooth;
}
.v2-ap-thumbs::-webkit-scrollbar {
    display: none;
}

/* Image thumbnail */
.v2-ap-thumb {
    width: 56px;
    height: 56px;
    border-radius: 8px;
    object-fit: cover;
    cursor: pointer;
    flex-shrink: 0;
    border: 2px solid transparent;
    opacity: 0.6;
    transition: opacity 0.15s, border-color 0.15s;
}
.v2-ap-thumb:hover {
    opacity: 0.85;
}
.v2-ap-thumb.v2-ap-thumb-active {
    border-color: #fff;
    opacity: 1;
}

/* File/video thumbnail */
.v2-ap-file-thumb {
    width: 56px;
    height: 56px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    border: 2px solid transparent;
    opacity: 0.6;
    transition: opacity 0.15s, border-color 0.15s;
    position: relative;
    overflow: hidden;
}
.v2-ap-file-thumb:hover {
    opacity: 0.85;
}
.v2-ap-file-thumb.v2-ap-thumb-active {
    border-color: #fff;
    opacity: 1;
}

/* Video thumbnail variant — first-frame poster + translucent play badge */
.v2-ap-file-thumb-video {
    background: #000;
}
.v2-ap-thumb-poster {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}
.v2-ap-thumb-play {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 28px;
    height: 28px;
    transform: translate(-50%, -50%);
    border-radius: 50%;
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}
.v2-ap-thumb-play svg {
    display: block;
}

/* Scroll (prev/next) buttons */
.v2-ap-scroll-btn {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.15);
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    color: #fff;
    transition: background 0.15s;
}
.v2-ap-scroll-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}
.v2-ap-count {
    color: #fff;
    font-size: 14px;
    font-weight: 600;
    margin-right: 12px;
    align-self: center;
    letter-spacing: 0.3px;
}
.v2-ap-doc-note { color: rgba(255,255,255,0.7); font-size: 13px; margin-top: 8px; }

/* ==========================================
   Question-details layout (only when items carry question details, e.g. submitted
   process view). Matches the Figma "image detail page" frame: a media stage
   (max 950 x 640) with the counter + Download above it and the thumbnail strip
   below, and a 399px full-height white details drawer on the right. Every file is
   shown at its uploaded size, shrunk only to fit the stage, and centred in it.
   ========================================== */
.v2-ap-overlay.v2-ap-has-qpanel {
    background: rgba(0, 0, 0, 0.8);
    flex-direction: row;
    align-items: stretch;
    justify-content: flex-start;
}
.v2-ap-qp-main {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    padding: 24px 51px 45px 40px;
    box-sizing: border-box;
}
.v2-ap-qp-top {
    flex: 0 0 auto;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    height: 42px;
    margin-bottom: 20px;
}
/* Figma "Button / sm / Tertiary gray": 42px glass pill, 6/14/6/8 padding, 8px icon gap */
.v2-ap-qp-top .v2-ap-download-btn {
    position: static;
    height: 42px;
    padding: 6px 14px 6px 8px;
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
    gap: 8px;
    font-size: 14px;
    font-weight: 600;
    line-height: 20px;
    box-sizing: border-box;
    margin: 0;
}
.v2-ap-qp-top .v2-ap-download-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}
.v2-ap-qp-stage {
    position: relative;
    /* Figma: this box is the maximum space for the file (950 x 640 on a 1440 x 900
       screen). It fills whatever is left between the top row and the strip, so the
       24px top / 45px bottom gaps stay the same on every screen size. */
    flex: 1 1 auto;
    min-height: 0;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}
.v2-ap-has-qpanel .v2-ap-qp-stage .v2-ap-content {
    flex: none;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    max-width: 100%;
    max-height: 100%;
    min-width: 0;
    padding: 0;
    overflow: hidden;
}
.v2-ap-has-qpanel .v2-ap-qp-stage .v2-ap-img,
.v2-ap-has-qpanel .v2-ap-qp-stage .v2-ap-video {
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    object-fit: contain;
    border-radius: 3px;
}
.v2-ap-has-qpanel .v2-ap-qp-stage .v2-ap-pdf-wrap {
    width: 100%;
    height: 100%;
}
.v2-ap-has-qpanel .v2-ap-strip {
    flex: 0 0 auto;
    width: 100%;
    margin-top: 24px;
    padding: 16px 24px;
}
.v2-ap-qp-side {
    flex: 0 0 399px;
    width: 399px;
    height: 100%;
    background: #fff;
    border-radius: 12px 0 0 12px;
    box-shadow: 0 18px 42px rgba(103, 110, 118, 0.08);
    box-sizing: border-box;
    padding: 24px;
    overflow-y: auto;
    position: relative;
    font-family: 'Lato', sans-serif;
}
.v2-ap-qp-close {
    position: absolute;
    top: 24px;
    right: 24px;
    width: 30px;
    height: 27px;
    padding: 0;
    border: none;
    background: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}
.v2-ap-qp-details {
    display: flex;
    flex-direction: column;
    gap: 18px;
}
.v2-ap-qp-num {
    font-size: 18px;
    font-weight: 700;
    line-height: 150%;
    color: #1F1F1F;
    padding-right: 40px;
}
.v2-ap-qp-rows {
    display: flex;
    flex-direction: column;
    gap: 16px;
}
.v2-ap-qp-row {
    display: flex;
    align-items: flex-start;
    gap: 4px;
}
.v2-ap-qp-k {
    flex: 0 0 90px;
    font-size: 14px;
    font-weight: 500;
    line-height: 16px;
    color: #7A7A7A;
}
.v2-ap-qp-v {
    flex: 1 1 auto;
    min-width: 0;
    font-size: 16px;
    font-weight: 500;
    line-height: 16px;
    color: #3D3D3D;
    white-space: pre-wrap;
    word-break: break-word;
}
.v2-ap-qp-comments {
    margin-top: 18px;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    font-weight: 700;
    line-height: 24px;
    color: #3D3D3D;
}
.v2-ap-qp-badge {
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    border-radius: 10px;
    background: #EEF0F3;
    font-size: 12px;
    font-weight: 600;
    line-height: 150%;
    color: #000;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
}
.v2-ap-qp-comment {
    font-size: 14px;
    font-weight: 500;
    line-height: 20px;
    color: #3D3D3D;
    white-space: pre-wrap;
    word-break: break-word;
}
.v2-ap-has-qpanel .v2-ap-count {
    color: #fff;
    font-size: 18px;
    font-weight: 500;
    line-height: 24px;
    letter-spacing: 0;
    margin: 0;
}
@media (max-width: 900px) {
    .v2-ap-overlay.v2-ap-has-qpanel {
        flex-direction: column;
        overflow-y: auto;
    }
    .v2-ap-qp-main {
        padding: 16px 12px;
    }
    .v2-ap-qp-stage {
        flex: none;
        height: 50vh;
    }
    .v2-ap-has-qpanel .v2-ap-strip {
        margin-top: 24px;
    }
    .v2-ap-qp-side {
        flex: 0 0 auto;
        width: 100%;
        height: auto;
        border-radius: 12px 12px 0 0;
    }
}
