/**
 * Modal Display Styles
 * Handles modal positioning and animations for feedback forms
 *
 * @package Customer_Feedback_Dashboard
 * @since 1.3.0
 */

/* Body scroll lock when modal is open - keeps scrollbar visible */
body.cfd-modal-open {
    position: fixed;
    width: 100%;
    overflow-y: scroll;
}

/*
 * Pre-init guard — prevents modal flash before JavaScript runs.
 * JS removes this class immediately on document.ready so CSS transitions
 * work normally afterwards.
 */
.cfd-modal-pre-init {
    display: none !important;
}

/* Modal Overlay */
.cfd-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999998;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.cfd-modal-overlay.cfd-modal-active {
    opacity: 1;
    visibility: visible;
}

/* Modal Container */
.cfd-modal-container {
    position: fixed;
    z-index: 999999;
    background: #ffffff;
    border-radius: 8px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    max-width: 500px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
    transform: scale(0.9);
    opacity: 0;
    visibility: hidden;
    transition: transform 0.3s ease, opacity 0.3s ease, visibility 0.3s ease;
}

.cfd-modal-container.cfd-modal-active {
    transform: scale(1);
    opacity: 1;
    visibility: visible;
}

/* Position: Top Left */
.cfd-modal-container.cfd-position-top-left {
    top: 20px;
    left: 20px;
    transform-origin: top left;
}

.cfd-modal-container.cfd-position-top-left.cfd-modal-active {
    transform: scale(1);
}

/* Position: Top Right */
.cfd-modal-container.cfd-position-top-right {
    top: 20px;
    right: 20px;
    transform-origin: top right;
}

.cfd-modal-container.cfd-position-top-right.cfd-modal-active {
    transform: scale(1);
}

/* Position: Bottom Left */
.cfd-modal-container.cfd-position-bottom-left {
    bottom: 20px;
    left: 20px;
    transform-origin: bottom left;
}

.cfd-modal-container.cfd-position-bottom-left.cfd-modal-active {
    transform: scale(1);
}

/* Position: Bottom Right (Default) */
.cfd-modal-container.cfd-position-bottom-right {
    bottom: 20px;
    right: 20px;
    transform-origin: bottom right;
}

.cfd-modal-container.cfd-position-bottom-right.cfd-modal-active {
    transform: scale(1);
}

/* Position: Center */
.cfd-modal-container.cfd-position-center {
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.9);
    transform-origin: center;
}

.cfd-modal-container.cfd-position-center.cfd-modal-active {
    transform: translate(-50%, -50%) scale(1);
}

/* Modal Header */
.cfd-modal-header {
    position: relative;
    padding: 20px;
    border-bottom: 1px solid #e5e7eb;
}

.cfd-modal-title {
    margin: 0 0 8px 0;
    font-size: 18px;
    font-weight: 600;
    color: #111827;
}

.cfd-modal-description {
    margin: 0;
    font-size: 14px;
    line-height: 1.5;
    color: #64748b;
    padding-right: 30px; /* Space for close button */
}

.cfd-modal-close {
    position: absolute;
    top: 15px;
    right: 15px;
    background: transparent;
    border: none;
    font-size: 24px;
    line-height: 1;
    color: #6b7280;
    cursor: pointer;
    padding: 5px;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: background-color 0.2s ease, color 0.2s ease;
}

.cfd-modal-close:hover {
    background-color: #f3f4f6;
    color: #111827;
}

/* Modal Body */
.cfd-modal-body {
    padding: 20px;
}

/* Mobile Styles */
@media screen and (max-width: 768px) {
    .cfd-modal-container {
        /* Override all positions on mobile - always bottom center */
        top: auto !important;
        left: 50% !important;
        right: auto !important;
        bottom: 0 !important;
        transform: translateX(-50%) translateY(100%) !important;
        width: 100%;
        max-width: 100%;
        border-radius: 12px 12px 0 0;
        max-height: 85vh;
    }

    .cfd-modal-container.cfd-modal-active {
        transform: translateX(-50%) translateY(0) !important;
    }

    .cfd-modal-header {
        padding: 16px;
    }

    .cfd-modal-title {
        font-size: 16px;
        padding-right: 30px;
    }

    .cfd-modal-description {
        font-size: 13px;
        padding-right: 25px;
    }

    .cfd-modal-body {
        padding: 16px;
    }

    .cfd-modal-close {
        top: 12px;
        right: 12px;
    }
}

/* Slide-in animations for corners */
@media screen and (min-width: 769px) {
    .cfd-modal-container.cfd-position-top-left,
    .cfd-modal-container.cfd-position-bottom-left {
        animation: slideInFromLeft 0.4s ease-out;
    }

    .cfd-modal-container.cfd-position-top-right,
    .cfd-modal-container.cfd-position-bottom-right {
        animation: slideInFromRight 0.4s ease-out;
    }

    @keyframes slideInFromLeft {
        from {
            transform: translateX(-100%);
            opacity: 0;
        }
        to {
            transform: translateX(0);
            opacity: 1;
        }
    }

    @keyframes slideInFromRight {
        from {
            transform: translateX(100%);
            opacity: 0;
        }
        to {
            transform: translateX(0);
            opacity: 1;
        }
    }
}

/* Mobile slide-up animation */
@media screen and (max-width: 768px) {
    .cfd-modal-container {
        animation: slideUpFromBottom 0.3s ease-out;
    }

    @keyframes slideUpFromBottom {
        from {
            transform: translateX(-50%) translateY(100%);
        }
        to {
            transform: translateX(-50%) translateY(0);
        }
    }
}

/* Scrollbar styling */
.cfd-modal-container::-webkit-scrollbar {
    width: 8px;
}

.cfd-modal-container::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

.cfd-modal-container::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 4px;
}

.cfd-modal-container::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* Backdrop blur effect (optional, can be enabled via settings) */
.cfd-modal-overlay.cfd-backdrop-blur {
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

/* ============================================================
   Persistent Icon — reopen button shown after modal is closed
   ============================================================ */
.cfd-persistent-icon {
    position: fixed;
    z-index: 999997;
    display: none; /* shown via JS */
}

/* Desktop positions */
@media screen and (min-width: 769px) {
    .cfd-persistent-icon.cfd-position-bottom-right {
        bottom: 24px;
        right: 24px;
    }
    .cfd-persistent-icon.cfd-position-bottom-left {
        bottom: 24px;
        left: 24px;
    }
    .cfd-persistent-icon.cfd-position-top-right {
        top: 24px;
        right: 24px;
    }
    .cfd-persistent-icon.cfd-position-top-left {
        top: 24px;
        left: 24px;
    }
    /* center modal → icon defaults to bottom-right */
    .cfd-persistent-icon.cfd-position-center {
        bottom: 24px;
        right: 24px;
    }
}

/* Mobile: respect configured side but pin to bottom */
@media screen and (max-width: 768px) {
    .cfd-persistent-icon.cfd-position-bottom-right,
    .cfd-persistent-icon.cfd-position-top-right,
    .cfd-persistent-icon.cfd-position-center {
        bottom: 20px;
        right: 16px;
    }
    .cfd-persistent-icon.cfd-position-bottom-left,
    .cfd-persistent-icon.cfd-position-top-left {
        bottom: 20px;
        left: 16px;
    }
}

/* Button */
.cfd-persistent-icon-btn {
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.18);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    overflow: hidden;
    outline: none;
}

.cfd-persistent-icon-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.25);
}

.cfd-persistent-icon-btn:focus-visible {
    outline: 3px solid #3b82f6;
    outline-offset: 2px;
}

.cfd-persistent-icon-btn img {
    display: block;
    object-fit: contain;
    pointer-events: none;
}
