/* Modal Styling */
.modal {
    display: none;
    position: fixed;
    z-index: 9999;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    overflow: hidden; /* Prevents page scroll */
}

.modal-content {
    background-color: white;
    margin: 5% auto;
    padding: 20px;
    border-radius: 8px;
    width: 50%;
    max-width: 600px;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
    position: relative;
    display: flex;
    flex-direction: column;
    max-height: 80vh; /* Limits height */
    overflow-y: auto; /* Keeps scrollbar inside the modal */
}


/* Modal body should scroll, not the whole modal container */
#modal-body {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

/* Keep Save/Close visible (reduces the “big blank” feeling on mobile) */
.button-container {
    position: sticky;
    bottom: 0;
    background: #fff;
    padding-top: 12px;
    padding-bottom: 12px;
}

/*
 * Mobile/WebGL: allow finger rotation/pinch zoom on the Three.js canvas.
 * Without these, iOS/Android browsers can treat the canvas like an image and perform page zoom/scroll.
 */
#three-container,
#three-container canvas {
    touch-action: none;
    -ms-touch-action: none;
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
}

#three-container {
    overscroll-behavior: contain;
}

/* Close Button */
#dfc-details-modal-close {
    float: right;
    font-size: 24px;
    cursor: pointer;
}

#dfc-details-modal-close:hover {
    color: red;
}

/* Two-Column Grid for Item Details */
.item-details-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
    background: #f8f8f8;
    padding: 10px;
    border-radius: 5px;
    margin-bottom: 20px;
}

.item-details-grid div {
    font-size: 14px;
    font-weight: 500;
    padding: 5px;
}

/* Label Styling */
.modal-content label {
    font-weight: bold;
    margin-top: 10px;
    display: block;
}

/* Dropdowns & Inputs */
.modal-content select, 
.modal-content input {
    width: 100%;
    padding: 8px;
    margin-top: 5px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 14px;
    background: #fff;
}

/* Option Rows - Align Labels and Fields */
.option-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
}

/* Buttons - Styled for Better UX */
.button-container {
    display: flex;
    justify-content: space-between;
    margin-top: 20px;
}

#save-options-btn, #close-modal-btn {
    flex: 1;
    margin: 0 5px;
    padding: 10px;
    border: none;
    border-radius: 4px;
    font-size: 14px;
    cursor: pointer;
}

/* Save Button */
#save-options-btn {
    background-color: #0073e6;
    color: white;
}

#save-options-btn:hover {
    background-color: #005bb5;
}

/* Close Button */
#close-modal-btn {
    background-color: #ddd;
    color: black;
}

#close-modal-btn:hover {
    background-color: #bbb;
}

/* Responsive Adjustments */
@media (max-width: 768px) {
    .modal-content {
        width: 90%;
        margin: 10% auto;
        max-height: 90vh;
    }

    .item-details-grid {
        grid-template-columns: 1fr;
    }
}

/* ------------------------------
   Mobile "Viewer Mode" (3D first)
   ------------------------------ */

.dfc-mobile-viewer-bar {
    display: none;
    gap: 12px;
    padding: 12px 14px;
    border-top: 1px solid rgba(0,0,0,0.08);
    background: #fff;
}

.dfc-mobile-btn {
    flex: 1;
    padding: 12px 10px;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
}

.dfc-mobile-btn-primary {
    background-color: #0073e6;
    color: #fff;
}

.dfc-mobile-btn-secondary {
    background-color: #f0f0f0;
    color: #111;
}

#dfc-details-modal.dfc-viewer-mode .modal-content {
    width: 100%;
    height: 100%;
    max-width: none;
    max-height: none;
    margin: 0;
    padding: 0;
    border-radius: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

#dfc-details-modal.dfc-viewer-mode #modal-body {
    flex: 1;
    min-height: 0;
    overflow: hidden;
    padding: 0;
    display: flex;
    flex-direction: column;
}

/* Make the injected form/columns participate in the full-screen flex layout */
#dfc-details-modal.dfc-viewer-mode .modal-form {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

#dfc-details-modal.dfc-viewer-mode .modal-columns {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    margin: 0 !important;
    padding: 0 !important;
}

/* Hide the editor UI in viewer mode (3D fills the screen)
   IMPORTANT: do NOT hide .modal-columns because it contains #three-container. */
#dfc-details-modal.dfc-viewer-mode .item-details-grid,
#dfc-details-modal.dfc-viewer-mode h3,
#dfc-details-modal.dfc-viewer-mode .option-row,
#dfc-details-modal.dfc-viewer-mode .button-container,
#dfc-details-modal.dfc-viewer-mode #additional-cost-box {
    display: none !important;
}

/* In viewer mode we keep the column wrapper visible, but hide the options column only */
#dfc-details-modal.dfc-viewer-mode .options-column {
    display: none !important;
}

/* Ensure the 3D column can expand to full width/height */
#dfc-details-modal.dfc-viewer-mode .three-column {
    width: 100% !important;
    max-width: none !important;
    flex: 1;
    min-height: 0;
    display: flex;
}

/* In viewer mode, make the 3D area fill the available space */
#dfc-details-modal.dfc-viewer-mode #three-container {
    width: 100% !important;
    flex: 1;
    min-height: 0 !important;

    /* Some item scripts read container.clientHeight at init time.
       If the container height is still 0, they fall back to 300px (≈ “top half” on phones).
       Force a real viewport-based height in viewer mode so ALL items start full-screen. */
    height: calc(100vh - 84px - env(safe-area-inset-bottom)) !important;
    height: calc(100dvh - 84px - env(safe-area-inset-bottom)) !important;

    max-height: none !important;
    margin: 0 !important;
}


/* Make the WebGL canvas truly fill the viewer (prevents the “small box top-left” look) */
#dfc-details-modal.dfc-viewer-mode #three-container canvas {
    width: 100% !important;
    height: 100% !important;
    display: block;
}

/* Show the mobile viewer bar only in viewer mode */
#dfc-details-modal.dfc-viewer-mode #dfc-mobile-viewer-bar {
    display: flex !important;
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
}

#dfc-details-modal.dfc-viewer-mode #dfc-details-modal-close {
    position: absolute;
    top: 10px;
    right: 12px;
    z-index: 3;
    background: rgba(255,255,255,0.9);
    width: 36px;
    height: 36px;
    line-height: 36px;
    text-align: center;
    border-radius: 18px;
}

/* Confirm tick styling (Quote Review rows) */
.dfc-confirm-tick {
    display: inline-block;
    margin-left: 8px;
    font-weight: 800;
    color: #1a8f3a;
}
