/**
 * AI PopUps Frontend Styles
 * 
 * สไตล์สำหรับ Popup บนหน้าเว็บ รองรับหลาย popup types
 * และ animation presets ต่างๆ
 * 
 * @package    AI_Popups
 * @subpackage Frontend/CSS
 * @since      1.0.0
 * @version    1.5.0
 */

/* ==========================================================================
   1. BASE STYLES - สไตล์พื้นฐานสำหรับ overlay
   ========================================================================== */

.ai-popup-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    -webkit-backdrop-filter: blur(5px);
    backdrop-filter: blur(5px);
    z-index: 99999999;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.ai-popup-overlay.is-visible {
    opacity: 1;
    visibility: visible;
}

/* ==========================================================================
   2. POPUP TYPES - ประเภท Popup ต่างๆ
   ========================================================================== */

/* 2.1 Modal (Center) - ค่าเริ่มต้น */
.ai-popup-overlay--modal {
    display: grid;
    place-items: center;
}

.ai-popup-overlay--modal .ai-popup-container {
    max-width: 600px;
    width: 90%;
}

/* 2.2 Slide-in Right - สไลด์เข้าจากขวาล่าง */
.ai-popup-overlay--slide-in-right {
    background: transparent;
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
    pointer-events: none;
}

.ai-popup-overlay--slide-in-right .ai-popup-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    max-width: 380px;
    width: calc(100% - 40px);
    pointer-events: auto;
    transform: translateX(120%);
}

.ai-popup-overlay--slide-in-right.is-visible .ai-popup-container {
    transform: translateX(0);
}

/* 2.3 Slide-in Left - สไลด์เข้าจากซ้ายล่าง */
.ai-popup-overlay--slide-in-left {
    background: transparent;
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
    pointer-events: none;
}

.ai-popup-overlay--slide-in-left .ai-popup-container {
    position: fixed;
    bottom: 20px;
    left: 20px;
    max-width: 380px;
    width: calc(100% - 40px);
    pointer-events: auto;
    transform: translateX(-120%);
}

.ai-popup-overlay--slide-in-left.is-visible .ai-popup-container {
    transform: translateX(0);
}

/* 2.4 Full Screen - เต็มจอ */
.ai-popup-overlay--fullscreen {
    display: grid;
    place-items: center;
}

.ai-popup-overlay--fullscreen .ai-popup-container {
    max-width: 100%;
    width: 100%;
    height: 100%;
    border-radius: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

/* 2.5 Top Bar - แถบด้านบน */
.ai-popup-overlay--top-bar {
    background: transparent;
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
    pointer-events: none;
}

.ai-popup-overlay--top-bar .ai-popup-container {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    max-width: 100%;
    width: 100%;
    border-radius: 0;
    padding: 1rem 2rem;
    pointer-events: auto;
    transform: translateY(-100%);
}

.ai-popup-overlay--top-bar.is-visible .ai-popup-container {
    transform: translateY(0);
}

.ai-popup-overlay--top-bar .ai-popup-close {
    position: static;
    margin-left: auto;
}

.ai-popup-overlay--top-bar .ai-popup-content {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    flex-wrap: wrap;
}

/* 2.6 Bottom Bar - แถบด้านล่าง */
.ai-popup-overlay--bottom-bar {
    background: transparent;
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
    pointer-events: none;
}

.ai-popup-overlay--bottom-bar .ai-popup-container {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    max-width: 100%;
    width: 100%;
    border-radius: 0;
    padding: 1rem 2rem;
    pointer-events: auto;
    transform: translateY(100%);
}

.ai-popup-overlay--bottom-bar.is-visible .ai-popup-container {
    transform: translateY(0);
}

.ai-popup-overlay--bottom-bar .ai-popup-close {
    position: static;
    margin-left: auto;
}

.ai-popup-overlay--bottom-bar .ai-popup-content {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    flex-wrap: wrap;
}

/* ==========================================================================
   3. CONTAINER STYLES - สไตล์กล่อง Popup
   ========================================================================== */

.ai-popup-container {
    background: #fff;
    padding: 2rem;
    border-radius: 1rem;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
    position: relative;
    transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* ==========================================================================
   4. ANIMATION PRESETS - เอฟเฟคอนิเมชัน
   ========================================================================== */

/* 4.1 Fade - จางเข้า/ออก */
.ai-popup-overlay--anim-fade .ai-popup-container {
    transform: none;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.ai-popup-overlay--anim-fade.is-visible .ai-popup-container {
    opacity: 1;
}

/* 4.2 Slide Up - สไลด์ขึ้น */
.ai-popup-overlay--anim-slide-up .ai-popup-container {
    transform: translateY(50px);
}

.ai-popup-overlay--anim-slide-up.is-visible .ai-popup-container {
    transform: translateY(0);
}

/* 4.3 Slide Down - สไลด์ลง */
.ai-popup-overlay--anim-slide-down .ai-popup-container {
    transform: translateY(-50px);
}

.ai-popup-overlay--anim-slide-down.is-visible .ai-popup-container {
    transform: translateY(0);
}

/* 4.4 Zoom - ซูมเข้า */
.ai-popup-overlay--anim-zoom .ai-popup-container {
    transform: scale(0.8);
    opacity: 0;
}

.ai-popup-overlay--anim-zoom.is-visible .ai-popup-container {
    transform: scale(1);
    opacity: 1;
}

/* 4.5 Bounce - เด้ง */
.ai-popup-overlay--anim-bounce .ai-popup-container {
    transform: scale(0.5);
    opacity: 0;
    transition: transform 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55), opacity 0.3s ease;
}

.ai-popup-overlay--anim-bounce.is-visible .ai-popup-container {
    transform: scale(1);
    opacity: 1;
}

/* 4.6 Flip - พลิก */
.ai-popup-overlay--anim-flip .ai-popup-container {
    transform: perspective(600px) rotateX(-30deg);
    opacity: 0;
}

.ai-popup-overlay--anim-flip.is-visible .ai-popup-container {
    transform: perspective(600px) rotateX(0);
    opacity: 1;
}

/* ==========================================================================
   5. CLOSE BUTTON - ปุ่มปิด
   ========================================================================== */

.ai-popup-close {
    position: absolute;
    top: 10px;
    right: 10px;
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    line-height: 1;
    color: #666;
    padding: 8px;
    border-radius: 50%;
    transition: color 0.2s, background 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
}

.ai-popup-close:hover {
    color: #000;
    background: rgba(0, 0, 0, 0.05);
}

.ai-popup-close:focus {
    outline: 2px solid #0073aa;
    outline-offset: 2px;
}

/* ==========================================================================
   6. RESPONSIVE - รองรับหน้าจอขนาดต่างๆ
   ========================================================================== */

@media (max-width: 600px) {

    /* Modal บนมือถือ */
    .ai-popup-overlay--modal .ai-popup-container {
        width: 95%;
        padding: 1.5rem;
        margin: 1rem;
        max-height: 90vh;
        overflow-y: auto;
    }

    /* Slide-in บนมือถือ - แสดงเป็น bottom sheet */
    .ai-popup-overlay--slide-in-right .ai-popup-container,
    .ai-popup-overlay--slide-in-left .ai-popup-container {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        max-width: 100%;
        width: 100%;
        border-radius: 1rem 1rem 0 0;
        transform: translateY(100%);
    }

    .ai-popup-overlay--slide-in-right.is-visible .ai-popup-container,
    .ai-popup-overlay--slide-in-left.is-visible .ai-popup-container {
        transform: translateY(0);
    }

    /* Top/Bottom bar บนมือถือ */
    .ai-popup-overlay--top-bar .ai-popup-container,
    .ai-popup-overlay--bottom-bar .ai-popup-container {
        padding: 0.75rem 1rem;
    }

    .ai-popup-overlay--top-bar .ai-popup-content,
    .ai-popup-overlay--bottom-bar .ai-popup-content {
        flex-direction: column;
        text-align: center;
    }
}

/* ==========================================================================
   7. REDUCED MOTION - สำหรับผู้ใช้ที่ต้องการลด animation
   ========================================================================== */

@media (prefers-reduced-motion: reduce) {

    .ai-popup-overlay,
    .ai-popup-container {
        transition: none !important;
        animation: none !important;
    }
}

/* ==========================================================================
   8. DARK MODE SUPPORT - รองรับ Dark Mode
   ========================================================================== */

@media (prefers-color-scheme: dark) {
    .ai-popup-container {
        background: #2d2d2d;
        color: #f0f0f0;
    }

    .ai-popup-close {
        color: #ccc;
    }

    .ai-popup-close:hover {
        color: #fff;
        background: rgba(255, 255, 255, 0.1);
    }
}

/* ==========================================================================
   9. SCREEN READER - สไตล์สำหรับ Screen Readers
   ========================================================================== */

.screen-reader-text {
    border: 0;
    clip: rect(1px, 1px, 1px, 1px);
    clip-path: inset(50%);
    height: 1px;
    margin: -1px;
    overflow: hidden;
    padding: 0;
    position: absolute;
    width: 1px;
    word-wrap: normal !important;
}

.screen-reader-text:focus {
    background-color: #f1f1f1;
    border-radius: 3px;
    box-shadow: 0 0 2px 2px rgba(0, 0, 0, 0.2);
    clip: auto !important;
    clip-path: none;
    color: #21759b;
    display: block;
    font-size: 14px;
    font-weight: bold;
    height: auto;
    left: 5px;
    line-height: normal;
    padding: 15px 23px 14px;
    text-decoration: none;
    top: 5px;
    width: auto;
    z-index: 100000;
}

/* ==========================================================================
   10. HIGH CONTRAST MODE - รองรับ Windows High Contrast
   ========================================================================== */

@media (forced-colors: active) {
    .ai-popup-overlay {
        background: Canvas;
    }

    .ai-popup-container {
        border: 2px solid ButtonText;
        background: Canvas;
        color: CanvasText;
    }

    .ai-popup-close {
        border: 1px solid ButtonText;
        background: ButtonFace;
        color: ButtonText;
    }

    .ai-popup-close:hover,
    .ai-popup-close:focus {
        background: Highlight;
        color: HighlightText;
    }
}

/* ==========================================================================
   11. FOCUS VISIBLE - Enhanced Focus Styles
   ========================================================================== */

.ai-popup-container :focus-visible {
    outline: 3px solid #0073aa;
    outline-offset: 2px;
}

.ai-popup-close:focus-visible {
    outline: 3px solid #0073aa;
    outline-offset: 2px;
}

/* ==========================================================================
   12. FORM STYLES - สไตล์สำหรับ Forms ใน Popup
   ========================================================================== */

.ai-popup-form-message {
    margin-top: 10px;
    padding: 8px 12px;
    border-radius: 4px;
    font-size: 14px;
}

.ai-popup-form-message.success {
    background: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}

.ai-popup-form-message.error {
    background: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

.ai-popup-content form input[type="email"],
.ai-popup-content form input[type="text"] {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 16px;
    margin-bottom: 10px;
}

.ai-popup-content form input[type="email"]:focus,
.ai-popup-content form input[type="text"]:focus {
    border-color: #0073aa;
    outline: none;
    box-shadow: 0 0 0 2px rgba(0, 115, 170, 0.2);
}

.ai-popup-content form button[type="submit"] {
    width: 100%;
    padding: 12px;
    background: #0073aa;
    color: #fff;
    border: none;
    border-radius: 4px;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    transition: background 0.2s;
}

.ai-popup-content form button[type="submit"]:hover {
    background: #005a87;
}

.ai-popup-content form button[type="submit"]:disabled {
    background: #999;
    cursor: not-allowed;
}