/**
 * SweetAlert2 Light & Dark Mode Universal Stylesheet
 * Ensures consistent theme transitions between light and dark mode across all pages
 *
 * ── SINGLE SOURCE OF TRUTH ของสไตล์แจ้งเตือนทั้งระบบ (SweetAlert2 Modal + Toast) ──
 * ทุก Layout ต้องโหลดไฟล์นี้ (app / platform / auth / workspace) เพื่อให้ padding,
 * ขนาดตัวอักษร และ responsive เหมือนกันหมด — ห้ามประกาศ CSS ชุดนี้ซ้ำใน Layout
 *
 * Responsive standard (ดู rules.md §12):
 *   • Desktop / Tablet (≥641px) : modal padding 1.25rem · title 1.25rem · ปุ่ม 0.5rem 1.25rem
 *   • Mobile (≤640px)            : modal padding 1rem    · title 1.125rem · ปุ่ม 0.5rem 1rem
 *   • Toast ทุกขนาด              : padding 0.5rem 0.75rem · ข้อความ wrap ได้ ไม่ล้นจอ
 */

/* ── Toast container ──
   1) กัน toast ทับ header: ค่า default = padding เดิมของ SweetAlert2 container (0.625rem)
      → หน้าที่ไม่มี header จะอยู่ตำแหน่งเดิม ส่วน Layout ที่มี header จะ set ค่านี้จาก JS (วัดขอบล่าง header จริง)
   2) กำหนดความกว้าง container เป็น 360px (มาตรฐาน SweetAlert2) — ถ้าไม่กำหนด container จะ
      shrink-to-fit ตามเนื้อหา ทำให้ข้อความยาว wrap ในคอลัมน์แคบ ~107px จนสูงเป็นหอด */
.swal2-container.swal2-top {
    padding-top: var(--swal2-toast-top, 0.625rem) !important;
    width: min(360px, calc(100vw - 1.5rem)) !important;
}

/* ── Toast Animations (Fade Down / Fade Up) ── */
@keyframes swalToastFadeDown {
    0% { opacity: 0; transform: translate3d(0, -32px, 0) scale(0.96); }
    100% { opacity: 1; transform: translate3d(0, 0, 0) scale(1); }
}
@keyframes swalToastFadeUp {
    0% { opacity: 1; transform: translate3d(0, 0, 0) scale(1); }
    100% { opacity: 0; transform: translate3d(0, -32px, 0) scale(0.96); }
}
.swal2-popup.swal2-toast.swal2-show,
.swal2-container.swal2-top .swal2-popup.swal2-toast.swal2-show,
.swal2-toast-fade-down {
    animation: swalToastFadeDown 0.35s cubic-bezier(0.16, 1, 0.3, 1) !important;
}
.swal2-popup.swal2-toast.swal2-hide,
.swal2-container.swal2-top .swal2-popup.swal2-toast.swal2-hide,
.swal2-toast-fade-up {
    animation: swalToastFadeUp 0.25s cubic-bezier(0.16, 1, 0.3, 1) forwards !important;
}

/* ── Typography & Base Modal Styling ── */
.swal2-popup:not(.swal2-toast),
.swal2-popup:not(.swal2-toast) *:not([class*="ph"]):not([class*="ph-"]) {
    font-family: 'Prompt', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif !important;
}

.swal2-popup:not(.swal2-toast) {
    border-radius: 1rem !important;
    padding: 1.25rem !important;
    /* กล่องแจ้งเตือนแคบลง (เดิม 32em กว้างเกิน — เนื้อหาสั้น ๆ ลอยกลางจอกว้างเปล่าเกินไป) */
    max-width: min(24em, calc(100vw - 2rem)) !important;
    max-height: calc(100vh - 2rem) !important;
    max-height: calc(100dvh - 2rem) !important;
    overflow-y: auto !important;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04) !important;
    /* ── ย่อไอคอนของ Modal (SweetAlert2 ตั้งค่า --swal2-icon-zoom ไว้ให้ใช้โดยตรง)
          เดิมกล่องไอคอน 5em (80px) + margin บน 2.5em (40px) = กินพื้นที่ด้านบนเยอะเกินจำเป็น */
    --swal2-icon-zoom: 0.72;
}

/* payment sheet ของหน้า POS มีเลย์เอาต์เฉพาะของตัวเอง — คงความกว้างเดิม */
.swal2-popup.pos-payment-swal-popup {
    max-width: min(32em, calc(100vw - 2rem)) !important;
}

/* ระยะห่างจากขอบบนของ modal ถึงไอคอน (เดิม 2.5em บน + 1em ล่าง → ลดเหลือเล็กน้อย) */
.swal2-popup:not(.swal2-toast) .swal2-icon {
    margin: 0.9em auto 0.35em !important;
}

/* หน้า POS: success dialog ย่อไอคอนเองด้วย transform(0.72) อยู่แล้ว
   ⇒ คืนค่า zoom/margin เดิม ไม่ให้ถูกย่อซ้ำสองชั้น */
.swal2-container.pos-success-swal .swal2-popup {
    --swal2-icon-zoom: 1 !important;
}
.swal2-container.pos-success-swal .swal2-icon.swal2-success {
    margin: 0.3em auto 0 !important;
}

.swal2-popup:not(.swal2-toast) .swal2-title {
    font-weight: 700 !important;
    font-size: 1.25rem !important;
    padding: 0 0 0.5rem !important;
}

.swal2-popup:not(.swal2-toast) .swal2-html-container {
    padding: 0 !important;
}

.swal2-popup:not(.swal2-toast) .swal2-actions {
    margin-top: 1rem !important;
}

.swal2-popup:not(.swal2-toast) .swal2-confirm {
    border-radius: 0.75rem !important;
    font-weight: 600 !important;
    padding: 0.5rem 1.25rem !important;
    font-size: 0.875rem !important;
    box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05) !important;
}

.swal2-popup:not(.swal2-toast) .swal2-cancel {
    border-radius: 0.75rem !important;
    font-weight: 600 !important;
    padding: 0.5rem 1.25rem !important;
    font-size: 0.875rem !important;
}

/* ── Toast Styling ── */
.swal2-popup.swal2-toast {
    border-radius: 0.75rem !important;
    padding: 0.5rem 0.75rem !important;
    /* กระชับตามเนื้อหา (ข้อความสั้น = pill เล็ก) แต่ไม่เกินความกว้าง container */
    width: fit-content !important;
    max-width: 100% !important;
    justify-self: center !important;
    /* ใช้ flex เพื่อให้ไอคอนกับข้อความอยู่กึ่งกลางแนวตั้งเดียวกัน
       (เดิมเป็น grid → ข้อความชิดบน เหลือช่องว่างใต้ข้อความไว้ใต้ไอคอน) */
    display: flex !important;
    flex-wrap: wrap !important;
    align-items: center !important;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05) !important;
}

/* เนื้อหา/ปุ่ม/ฟุตเตอร์ของ toast ต้องลงบรรทัดใหม่เต็มความกว้าง */
.swal2-popup.swal2-toast .swal2-html-container,
.swal2-popup.swal2-toast .swal2-actions,
.swal2-popup.swal2-toast .swal2-footer {
    flex: 1 1 100% !important;
}

.swal2-popup.swal2-toast .swal2-title {
    font-family: 'Prompt', sans-serif !important;
    font-weight: 600 !important;
    font-size: 0.8125rem !important;
    /* ข้อความยาวต้อง wrap ได้ — ห้าม clip ทอดจอมือถือ */
    white-space: normal !important;
    overflow-wrap: anywhere;
    line-height: 1.35;
    margin: 0 !important;
    padding: 0 !important;
    /* ยอมให้ข้อความหด+ขยายเต็มพื้นที่ที่เหลือข้างไอคอน เพื่อ wrap อยู่บรรทัดเดียวกับไอคอน
       (basis 0 กัน flex-wrap ดันข้อความไปตกบรรทัดใหม่) */
    flex: 1 1 0 !important;
    min-width: 0;
}

/* ── Responsive: Mobile / Tablet ── */
@media (max-width: 640px) {
    .swal2-popup:not(.swal2-toast) {
        border-radius: 0.875rem !important;
        padding: 1rem !important;
        max-width: calc(100vw - 1.5rem) !important;
        max-height: calc(100vh - 1.5rem) !important;
        max-height: calc(100dvh - 1.5rem) !important;
    }

    .swal2-popup:not(.swal2-toast) .swal2-title {
        font-size: 1.125rem !important;
        padding: 0 0 0.375rem !important;
    }

    .swal2-popup:not(.swal2-toast) .swal2-actions {
        margin-top: 0.75rem !important;
    }

    .swal2-popup:not(.swal2-toast) .swal2-confirm,
    .swal2-popup:not(.swal2-toast) .swal2-cancel {
        padding: 0.5rem 1rem !important;
    }

    .swal2-popup.swal2-toast {
        padding: 0.5rem 0.625rem !important;
    }
}

/* ── Dark Mode Overrides (html.dark .swal2-* / .dark .swal2-*) ── */
html.dark .swal2-popup,
.dark .swal2-popup {
    background-color: #1e293b !important;
    color: #f8fafc !important;
    border: 1px solid #334155 !important;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5) !important;
}

html.dark .swal2-title,
.dark .swal2-title,
html.dark .swal2-html-container,
.dark .swal2-html-container,
html.dark .swal2-content,
.dark .swal2-content {
    color: #f8fafc !important;
}

/* Dark mode inputs, selects, textareas */
html.dark .swal2-input,
.dark .swal2-input,
html.dark .swal2-file,
.dark .swal2-file,
html.dark .swal2-textarea,
.dark .swal2-textarea,
html.dark .swal2-select,
.dark .swal2-select,
html.dark .swal2-radio,
.dark .swal2-radio,
html.dark .swal2-checkbox,
.dark .swal2-checkbox {
    background-color: #0f172a !important;
    color: #f8fafc !important;
    border: 1px solid #334155 !important;
}

html.dark .swal2-input:focus,
.dark .swal2-input:focus,
html.dark .swal2-textarea:focus,
.dark .swal2-textarea:focus,
html.dark .swal2-select:focus,
.dark .swal2-select:focus {
    border-color: #3b82f6 !important;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.25) !important;
    outline: none !important;
}

html.dark .swal2-input::placeholder,
.dark .swal2-input::placeholder,
html.dark .swal2-textarea::placeholder,
.dark .swal2-textarea::placeholder {
    color: #64748b !important;
}

/* Dark mode validation message */
html.dark .swal2-validation-message,
.dark .swal2-validation-message {
    background-color: #334155 !important;
    color: #fca5a5 !important;
    border: 1px solid #475569 !important;
}

/* Dark mode close button & footer */
html.dark .swal2-close,
.dark .swal2-close {
    color: #94a3b8 !important;
}

html.dark .swal2-close:hover,
.dark .swal2-close:hover {
    color: #f8fafc !important;
}

html.dark .swal2-footer,
.dark .swal2-footer {
    border-top-color: #334155 !important;
    color: #94a3b8 !important;
}

/* Dark mode icons */
html.dark .swal2-icon.swal2-warning,
.dark .swal2-icon.swal2-warning {
    border-color: #eab308 !important;
    color: #eab308 !important;
}

html.dark .swal2-icon.swal2-error,
.dark .swal2-icon.swal2-error {
    border-color: #ef4444 !important;
    color: #ef4444 !important;
}

html.dark .swal2-icon.swal2-success,
.dark .swal2-icon.swal2-success {
    border-color: #22c55e !important;
    color: #22c55e !important;
}

html.dark .swal2-icon.swal2-info,
.dark .swal2-icon.swal2-info {
    border-color: #3b82f6 !important;
    color: #3b82f6 !important;
}

html.dark .swal2-icon.swal2-question,
.dark .swal2-icon.swal2-question {
    border-color: #a855f7 !important;
    color: #a855f7 !important;
}

/* Prevent white mask bug on success checkmark animation in dark mode */
html.dark .swal2-icon.swal2-success [class^='swal2-success-circular-line'],
.dark .swal2-icon.swal2-success [class^='swal2-success-circular-line'],
html.dark .swal2-icon.swal2-success .swal2-success-fix,
.dark .swal2-icon.swal2-success .swal2-success-fix,
html.dark .swal2-icon.swal2-success .swal2-success-circular-line-left,
.dark .swal2-icon.swal2-success .swal2-success-circular-line-left,
html.dark .swal2-icon.swal2-success .swal2-success-circular-line-right,
.dark .swal2-icon.swal2-success .swal2-success-circular-line-right {
    background-color: transparent !important;
}

/* Dark mode timer progress bar */
html.dark .swal2-timer-progress-bar,
.dark .swal2-timer-progress-bar {
    background: rgba(255, 255, 255, 0.25) !important;
}

/* ── Progress Bar & Icon Animations ── */
@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}
.animate-spin {
    animation: spin 1s linear infinite !important;
}

.swal-preload-bar {
    transition: width 0.3s ease;
}

/* Dark mode toast specific overrides */
html.dark .swal2-popup.swal2-toast,
.dark .swal2-popup.swal2-toast {
    background-color: #1e293b !important;
    color: #f8fafc !important;
    border: 1px solid #334155 !important;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.4) !important;
}

html.dark .swal2-popup.swal2-toast .swal2-title,
.dark .swal2-popup.swal2-toast .swal2-title {
    color: #f8fafc !important;
}

/* ── Fix SweetAlert2 viewport auto-height bug ── */
html.swal2-shown,
body.swal2-shown,
html.swal2-height-auto,
body.swal2-height-auto {
    height: 100% !important;
    min-height: 100% !important;
}
