/* ══════════════════════════════════════════════════════════════════
   notify.css  —  Toast · Error Modal · Loading Overlay · Page Loader
   ใช้ร่วมกันทุกหน้า  |  ต้อง include notify.js คู่กันด้วย
══════════════════════════════════════════════════════════════════ */

/* ── Google Fonts: Kanit (ดึงตรงจาก CDN) ── */
@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Sans+Thai:wght@400;500;600;700&display=swap');

/* ── Material Symbols (ใช้กับไอคอนใน toast) — โหลดเองกันพลาดกรณีหน้าเว็บไม่ได้ include ──
   ใช้ display=block (ไม่ใช่ swap) ตามคำแนะนำของ Google เพื่อกันปัญหาไอคอน
   ค้างเป็นข้อความ เช่น "check_circle" แทนที่จะเป็นรูปไอคอน ระหว่างฟอนต์โหลด ── */
@import url('https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined&display=block');

/* ── Material Symbols Outlined — base ligature font rule ── */
.material-symbols-outlined {
    font-family: 'Material Symbols Outlined';
    font-weight: normal;
    font-style: normal;
    line-height: 1;
    letter-spacing: normal;
    text-transform: none;
    white-space: nowrap;
    word-wrap: normal;
    direction: ltr;
    font-feature-settings: 'liga';
    -webkit-font-feature-settings: 'liga';
    -webkit-font-smoothing: antialiased;
}

/* ── บังคับ font ทุก element ใน notify ── */
#toast,
#toast *,
#loadingOverlay,
#loadingOverlay *,
#errorModal,
#errorModal *,
#page-loader,
#page-loader *,
.modal-backdrop,
.modal-backdrop *,
.modal-box,
.modal-box *,
.pl-card,
.pl-card *,
#alertModal,
#alertModal * {
    font-family: 'IBM Plex Sans Thai', 'Sarabun', sans-serif !important;
}

/* ── กันไอคอน material-symbols-outlined โดนกฎบังคับฟอนต์ Kanit ด้านบนทับ ──
   ต้องใช้ selector ที่ specificity สูงกว่า "#toast *" (id + universal)
   ถึงจะชนะได้แม้ทั้งคู่มี !important ── */
#toast .material-symbols-outlined,
#loadingOverlay .material-symbols-outlined,
#errorModal .material-symbols-outlined,
#page-loader .material-symbols-outlined,
.modal-backdrop .material-symbols-outlined,
.modal-box .material-symbols-outlined,
.pl-card .material-symbols-outlined,
#alertModal .material-symbols-outlined {
    font-family: 'Material Symbols Outlined' !important;
}

/* ── Toast animations ── */
@keyframes toastSpin {
    to { transform: rotate(360deg); }
}
@keyframes toastSlideIn {
    from { opacity: 0; transform: translateX(24px); }
    to   { opacity: 1; transform: translateX(0); }
}
@keyframes toastSlideOut {
    from { opacity: 1; transform: translateX(0); }
    to   { opacity: 0; transform: translateX(24px); }
}

/* ── Toast element ── */
#toast {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 9999;
    display: flex;
    align-items: flex-start;
    gap: 12px;
    background: #fff;
    border-radius: 8px;
    padding: 14px 18px;
    box-shadow: 0 2px 8px rgba(0,0,0,.18), 0 0 0 1px rgba(0,0,0,.06);
    min-width: min(360px, calc(100vw - 40px));
    max-width: min(520px, calc(100vw - 40px));
    box-sizing: border-box;
    width: max-content;
}
#toast.toast-show {
    animation: toastSlideIn 0.22s cubic-bezier(.34,1.56,.64,1) forwards;
}
#toast.toast-hidden {
    animation: toastSlideOut 0.18s ease forwards;
    pointer-events: none;
}

/* ── Backdrop / Modal shared ── */
.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 50;
    background: rgba(0, 0, 0, .45);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.modal-box {
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, .18);
    width: 100%;
    max-width: 420px;
    overflow: hidden;
}

/* alert modal (Alert.fire) */
.modal-box.alert-box {
    max-width: 440px;
}

/* ── Loading overlay ── */
#loadingOverlay {
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: rgba(255, 255, 255, .7);
    display: flex;
    align-items: center;
    justify-content: center;
}
#loadingOverlay.hidden {
    display: none;
}

.spinner {
    width: 36px;
    height: 36px;
    border: 3px solid #e5e7eb;
    border-top-color: #3b82f6;
    border-radius: 50%;
    animation: spin .7s linear infinite;
}
@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ══════════════════════════════════════════
   Dark theme — Toast & Modals
══════════════════════════════════════════ */

/* toast */
[data-theme="black"] #toast {
    background: #3F3F3F !important;
    box-shadow: 0 2px 8px rgba(0,0,0,.5), 0 0 0 1px rgba(255,255,255,.08) !important;
}
[data-theme="black"] #toast #toastTitle { color: #f0ece4 !important; }
[data-theme="black"] #toast #toastMsg   { color: #94a3b8 !important; }
[data-theme="black"] #toast #toastClose { color: #94a3b8 !important; }

/* modal backdrop & box */
[data-theme="black"] .modal-backdrop {
    background: rgba(15, 23, 42, .75) !important;
}
[data-theme="black"] .modal-box {
    background: #3F3F3F !important;
    color: #f0ece4 !important;
}

/* error modal specifics */
[data-theme="black"] #errorModal > div {
    background-color: #3F3F3F !important;
}
[data-theme="black"] #errorModal [style*="background:#fef2f2"] {
    background-color: rgba(220, 38, 38, .12) !important;
}
[data-theme="black"] #errorModal [style*="color:#ef4444"] {
    color: #fca5a5 !important;
}
[data-theme="black"] #errorModal [style*="background:#ef4444"] {
    background-color: #ef4444 !important;
}
[data-theme="black"] .w-16.h-16.rounded-full {
    background-color: rgba(220, 38, 38, .12) !important;
}

/* print / pring modals */
[data-theme="black"] #printTicketModal,
[data-theme="black"] #purchaseModal {
    background: rgba(15, 23, 42, .75) !important;
}

/* ══════════════════════════════════════════════════════════════════
   Page Loader  —  Backdrop + Spinner (รวมใน notify.css)
══════════════════════════════════════════════════════════════════ */

/* ── ป้องกัน scroll ขณะโหลด ── */
body.pl-loading {
    overflow: hidden;
}

/* ── Backdrop (เหมือน modal) ── */
#page-loader {
    position: fixed;
    inset: 0;
    z-index: 99999;
    background: rgba(0, 0, 0, .45);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    opacity: 1;
    visibility: visible;
}

[data-theme="black"] #page-loader {
    background: rgba(15, 23, 42, .75);
}

/* ── Hide state ── */
#page-loader.pl-hide {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

/* ── Inner card (เหมือน modal-box) ── */
.pl-card {
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, .18);
    padding: 36px 40px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    min-width: 200px;
    text-align: center;
}

[data-theme="black"] .pl-card {
    background: #3F3F3F;
}

/* ── Spinner ── */
.pl-spinner-wrap {
    position: relative;
    width: 52px;
    height: 52px;
    flex-shrink: 0;
}

.pl-spinner-track {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    border: 3.5px solid #e2e8f0;
}

[data-theme="black"] .pl-spinner-track {
    border-color: #52525b;
}

.pl-spinner-fill {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    border: 3.5px solid transparent;
    border-top-color: #2563eb;
    border-right-color: #2563eb;
    animation: pl-spin 0.75s cubic-bezier(.4,0,.2,1) infinite;
}

@keyframes pl-spin {
    to { transform: rotate(360deg); }
}

/* ── Text ── */
.pl-title {
    font-size: 15px;
    font-weight: 700;
    color: #1e293b;
    margin: 0;
    line-height: 1.4;
}

[data-theme="black"] .pl-title {
    color: #f4f4f5;
}

.pl-msg {
    font-size: 13px;
    color: #64748b;
    margin: -8px 0 0;
    line-height: 1.5;
}

[data-theme="black"] .pl-msg {
    color: #a1a1aa;
}

/* ── Error state ── */
.pl-error-icon {
    display: none;
    width: 52px;
    height: 52px;
    background: #fef2f2;
    border-radius: 50%;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

[data-theme="black"] .pl-error-icon {
    background: rgba(220,38,38,.15);
}

.pl-error-icon svg {
    width: 26px;
    height: 26px;
    color: #dc2626;
}

#page-loader.pl-error .pl-spinner-wrap { display: none; }
#page-loader.pl-error .pl-error-icon   { display: flex; }
#page-loader.pl-error .pl-title        { color: #dc2626; }

.pl-reload-btn {
    display: none;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    font-weight: 600;
    color: #fff;
    background: #2563eb;
    border: none;
    border-radius: 8px;
    padding: 9px 20px;
    cursor: pointer;
    transition: background .15s;
    margin-top: 4px;
}

.pl-reload-btn:hover { background: #1d4ed8; }

#page-loader.pl-error .pl-reload-btn { display: flex; }

/* ── Dots animation ── */
.pl-dots::after {
    content: '';
    animation: pl-dots 1.4s steps(4, end) infinite;
}
@keyframes pl-dots {
    0%   { content: ''; }
    25%  { content: '.'; }
    50%  { content: '..'; }
    75%  { content: '...'; }
    100% { content: ''; }
}

/* ══════════════════════════════════════════════════════════════════
   Alert System (SweetAlert-style)  —  ใช้กับ Alert.fire() ใน notify.js
   ครอบคลุม: success · error · warning · info · question · loading ·
             confirm (มีปุ่มยกเลิก) · prompt (มี input) · toast (ใช้ #toast เดิม)
══════════════════════════════════════════════════════════════════ */
#alertModal {
    z-index: 10000;
}

.alert-box {
    padding: 34px 28px 26px;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    transform: scale(.9);
    opacity: 0;
    transition: transform .18s cubic-bezier(.34,1.56,.64,1), opacity .18s ease;
}
#alertModal.alert-show .alert-box {
    transform: scale(1);
    opacity: 1;
}

/* ── Icon circle ── */
.alert-icon-wrap {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 18px;
    flex-shrink: 0;
    animation: alertIconPop .3s cubic-bezier(.34,1.56,.64,1);
}
.alert-icon-wrap svg {
    width: 36px;
    height: 36px;
}
.alert-icon-wrap.alert-icon-loading {
    animation: none;
}
.alert-icon-wrap.alert-icon-loading .alert-spinner {
    width: 40px;
    height: 40px;
    border: 3.5px solid rgba(37,99,235,.2);
    border-top-color: #2563eb;
    border-radius: 50%;
    animation: pl-spin .75s cubic-bezier(.4,0,.2,1) infinite;
}

@keyframes alertIconPop {
    from { transform: scale(0); opacity: 0; }
    to   { transform: scale(1); opacity: 1; }
}

/* ── Text ── */
.alert-title {
    margin: 0 0 6px;
    font-size: 19px;
    font-weight: 700;
    color: #1e293b;
    line-height: 1.4;
}

.alert-text {
    margin: 0 0 4px;
    font-size: 14px;
    color: #64748b;
    line-height: 1.6;
    white-space: pre-line;
}

/* ── Input / Textarea ── */
.alert-input {
    width: 100%;
    margin-top: 16px;
    padding: 10px 14px;
    font-size: 14px;
    border: 1.5px solid #e2e8f0;
    border-radius: 8px;
    outline: none;
    color: #1e293b;
    background: #fff;
    transition: border-color .15s;
    box-sizing: border-box;
}
.alert-input:focus {
    border-color: #2563eb;
}
.alert-textarea {
    min-height: 84px;
    resize: vertical;
    font-family: inherit;
}

/* ── Buttons ── */
.alert-buttons {
    display: flex;
    gap: 10px;
    margin-top: 24px;
    width: 100%;
    justify-content: center;
}

.alert-btn {
    flex: 0 1 auto;
    min-width: 96px;
    max-width: 220px;
    padding: 10px 22px;
    font-size: 14px;
    font-weight: 600;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: background .15s, transform .1s, opacity .15s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-align: center;
}
.alert-btn:active { transform: scale(.97); }
.alert-btn:disabled { opacity: .6; cursor: not-allowed; }

.alert-btn-confirm {
    background: #2563eb;
    color: #fff;
}
.alert-btn-confirm:hover { background: #1d4ed8; }

.alert-btn-cancel {
    background: #f1f5f9;
    color: #475569;
}
.alert-btn-cancel:hover { background: #e2e8f0; }

.alert-btn-danger {
    background: #dc2626;
    color: #fff;
}
.alert-btn-danger:hover { background: #b91c1c; }

.alert-btn-success {
    background: var(--green, #00a870);
    color: #fff;
}
.alert-btn-success:hover { filter: brightness(.92); }

/* ── Layout ชิดซ้าย (ไม่มีไอคอน) — ใช้กับ Alert.fire({ align:'left' }) ── */
.alert-box.alert-left {
    padding: 26px 28px 24px;
    align-items: flex-start;
    text-align: left;
    border-radius: 10px;
    max-width: 480px;
}
.alert-left .alert-title {
    font-size: 17px;
    font-weight: 500;
    margin: 0 0 22px;
}
.alert-left .alert-text {
    font-size: 14px;
    color: #334155;
    margin: 0 0 6px;
}
.alert-left .alert-buttons {
    justify-content: flex-start;
    margin-top: 22px;
}
.alert-left .alert-btn {
    min-width: 0;
    padding: 9px 22px;
    border-radius: 4px;
}
.alert-left .alert-btn-cancel {
    background: #f1f1f1;
    color: #444;
}
.alert-left .alert-btn-cancel:hover { background: #e6e6e6; }

/* ── Dark theme ── */
[data-theme="black"] .alert-left .alert-text { color: #d4d4d8 !important; }
[data-theme="black"] .alert-title { color: #f4f4f5 !important; }
[data-theme="black"] .alert-text  { color: #a1a1aa !important; }
[data-theme="black"] .alert-input {
    background: #2a2a2a !important;
    border-color: #52525b !important;
    color: #f4f4f5 !important;
}
[data-theme="black"] .alert-btn-cancel {
    background: #4b4b4b !important;
    color: #e4e4e7 !important;
}
[data-theme="black"] .alert-btn-cancel:hover { background: #565656 !important; }

/* ══════════════════════════════════════════════════════════════════
   Responsive  —  มือถือ · แท็บเล็ต · จอเตี้ย (landscape) · safe-area
   วางท้ายไฟล์เพื่อ override ค่าด้านบน (ไม่เปลี่ยนหน้าตาบนเดสก์ท็อป)
══════════════════════════════════════════════════════════════════ */

/* ── พื้นฐาน: ข้อความยาว/ไม่มีช่องว่าง (เช่น ภาษาไทย, URL) ต้องไม่ล้นกรอบ ── */
#toast #toastTitle,
#toast #toastMsg,
.alert-title,
.alert-text,
.pl-title,
.pl-msg {
    overflow-wrap: anywhere;
}

/* ── Modal: จำกัดความสูงตามจอ + เลื่อนภายในกล่องเมื่อเนื้อหายาว ── */
.modal-backdrop {
    padding:
        max(16px, env(safe-area-inset-top))
        max(16px, env(safe-area-inset-right))
        max(16px, env(safe-area-inset-bottom))
        max(16px, env(safe-area-inset-left));
    box-sizing: border-box;
}
.modal-box {
    max-height: 100%;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    box-sizing: border-box;
}

/* กัน iOS Safari ซูมเองตอนโฟกัสช่อง input (ต้อง ≥ 16px) */
.alert-input {
    font-size: 16px;
}

/* ── Page Loader card ไม่ให้กว้างเกินจอ ── */
.pl-card {
    box-sizing: border-box;
    max-width: calc(100vw - 32px);
}

/* ── แท็บเล็ตและต่ำกว่า (≤ 768px) ── */
@media (max-width: 768px) {
    .alert-box {
        padding: 28px 22px 22px;
    }
    .alert-box.alert-left {
        padding: 22px 22px 20px;
    }
}

/* ── มือถือ (≤ 520px) ── */
@media (max-width: 520px) {

    /* Toast → แถบเต็มความกว้างด้านบน (เว้น safe-area / notch) */
    #toast {
        top: max(12px, env(safe-area-inset-top));
        right: max(12px, env(safe-area-inset-right));
        left: max(12px, env(safe-area-inset-left));
        min-width: 0;
        max-width: none;
        width: auto;
        padding: 12px 14px;
        gap: 10px;
    }
    #toast #toastClose {
        padding: 8px;          /* พื้นที่แตะใหญ่ขึ้น */
        margin: -6px -6px -6px 0;
    }
    @keyframes toastSlideIn {
        from { opacity: 0; transform: translateY(-16px); }
        to   { opacity: 1; transform: translateY(0); }
    }
    @keyframes toastSlideOut {
        from { opacity: 1; transform: translateY(0); }
        to   { opacity: 0; transform: translateY(-16px); }
    }

    /* Modal */
    .modal-box,
    .modal-box.alert-box,
    .alert-box.alert-left {
        max-width: 100%;
        border-radius: 14px;
    }
    .alert-box {
        padding: 24px 18px 18px;
    }
    .alert-box.alert-left {
        padding: 20px 18px 18px;
    }
    .alert-icon-wrap {
        width: 60px;
        height: 60px;
        margin-bottom: 14px;
    }
    .alert-icon-wrap svg {
        width: 30px;
        height: 30px;
    }
    .alert-title {
        font-size: 17px;
    }
    .alert-left .alert-title {
        font-size: 16px;
        margin-bottom: 16px;
    }

    /* ปุ่ม: ซ้อนแนวตั้ง เต็มความกว้าง ปุ่มหลักอยู่บน (แตะง่ายด้วยนิ้วโป้ง) */
    .alert-buttons,
    .alert-left .alert-buttons {
        flex-direction: column-reverse;
        align-items: stretch;
        gap: 8px;
        margin-top: 20px;
    }
    .alert-btn,
    .alert-left .alert-btn {
        width: 100%;
        max-width: none;
        min-height: 44px;
    }

    /* Page Loader */
    .pl-card {
        padding: 28px 24px;
        min-width: 0;
        width: min(280px, calc(100vw - 32px));
    }
    .pl-reload-btn {
        width: 100%;
        justify-content: center;
        min-height: 44px;
    }
}

/* ── จอเล็กมาก (≤ 360px) ── */
@media (max-width: 360px) {
    .alert-box {
        padding: 20px 14px 14px;
    }
    .alert-title { font-size: 16px; }
    .alert-text  { font-size: 13px; }
}

/* ── จอเตี้ย เช่น มือถือแนวนอน: ลดขนาดให้พอดีความสูง ── */
@media (max-height: 480px) {
    .alert-box {
        padding: 16px 20px 14px;
    }
    .alert-icon-wrap {
        width: 48px;
        height: 48px;
        margin-bottom: 8px;
    }
    .alert-icon-wrap svg {
        width: 24px;
        height: 24px;
    }
    .alert-buttons {
        margin-top: 14px;
    }
    .pl-card {
        padding: 18px 24px;
        gap: 10px;
    }
}

/* ── ผู้ใช้ที่ตั้งค่าลดการเคลื่อนไหว ── */
@media (prefers-reduced-motion: reduce) {
    #toast.toast-show,
    #toast.toast-hidden,
    .alert-box,
    .alert-icon-wrap {
        animation-duration: .01ms !important;
        transition-duration: .01ms !important;
    }
    .pl-spinner-fill,
    .alert-spinner,
    .spinner {
        animation-duration: 1.5s !important;  /* ยังหมุนช้าๆ เพื่อให้รู้ว่ากำลังโหลด */
    }
}