/* Global Stability Fixes - لمنع الاهتزاز والحركة الأفقية */
html, body {
    overflow-x: hidden !important;
    width: 100%;
    max-width: 100%;
    position: relative;
}

/* تحسين سلاسة التمرير في الهواتف */
.overflow-y-auto,
main,
aside {
    -webkit-overflow-scrolling: touch;
    will-change: scroll-position;
}

/* تسريع الريندر عبر تعطيل البلر نهائياً */
* {
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
}

/* جعل الأزرار تستجيب للمس بدلاً من الماوس */
button:active {
    transform: scale(0.98);
    opacity: 0.8;
}

.font-cairo {
    font-family: 'Cairo', sans-serif;
}

.font-montserrat {
    font-family: 'Montserrat', sans-serif;
}

/* Animations - Optimized for Performance */
@keyframes shine {
    100% {
        transform: translateX(100%);
    }
}

@keyframes shake {

    0%,
    100% {
        transform: translateX(0);
    }

    25% {
        transform: translateX(-5px);
    }

    75% {
        transform: translateX(5px);
    }
}

.animate-shine {
    animation: shine 1.5s infinite;
}

.animate-shake {
    animation: shake 0.3s ease-in-out;
}

.animate-fade-in {
    animation: fadeIn 0.4s ease-out forwards;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Performance Optimization: Hide Background Blobs */
.blob {
    display: none !important;
}

/* Card Styles - Optimized (Solid Background, No Blur) */
.glass-card {
    background: #0f172a;
    /* Solid color is much faster to render */
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: #0f172a;
}

::-webkit-scrollbar-thumb {
    background: #475569;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #6366f1;
}

/* SweetAlert Customization - High Z-Index Fix */
.swal2-container {
    z-index: 2147483647 !important;
}

/* [NEW] إصلاح تعارض النافذة المنبثقة (dialog) مع التنبيهات */
dialog .swal2-container {
    position: fixed !important;
    inset: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    background: rgba(0,0,0,0.6) !important;
    z-index: 2147483647 !important;
}

/* --- Sidebar Mobile Overlay Logic [FIXED] --- */
/* Ensure the overlay is below the sidebar but above everything else */
#sidebar-overlay, #admin-sidebar-overlay {
    z-index: 9998 !important;
}

#sidebar-menu, #admin-sidebar {
    z-index: 9999 !important;
    /* High Z-Index ensuring X button is clickable */
}

/* Sidebar Transitions - Smooth */
#sidebar-menu.translate-x-full, #admin-sidebar.translate-x-full {
    pointer-events: none;
}

#sidebar-menu.translate-x-0, #admin-sidebar.translate-x-0 {
    pointer-events: auto;
}

/* Prevent body scroll when menu is open [FIXED for Stability] */
body.menu-open {
    overflow: hidden !important;
    height: 100vh !important;
    touch-action: none !important;
    width: 100%;
}

/* [FIX] FORCE DISPLAY USER INFO CONTAINER */
#user-info-container {
    display: flex !important;
}

/* [FIX] Responsive Buttons in Profile/Nav */
#user-info-container button span,
#user-info-container a span {
    font-size: 0.75rem;
    white-space: nowrap;
}

@media (max-width: 640px) {
    /* Hide text on very small screens, keep icons */
    #user-info-container span:not(.font-bold) {
        display: none;
    }
}

/* Light Mode Support */
body.light-mode {
    background-color: #f8fafc;
    color: #1e293b;
}

body.light-mode nav {
    background-color: #ffffff;
    border-bottom-color: #e2e8f0;
}

body.light-mode .bg-slate-900 {
    background-color: #f1f5f9;
    color: #1e293b;
}

body.light-mode .bg-slate-800 {
    background-color: #ffffff;
    border-color: #e2e8f0;
    color: #1e293b;
}

body.light-mode .bg-slate-950 {
    background-color: #e2e8f0;
    color: #475569;
}

body.light-mode .text-white {
    color: #1e293b;
}

body.light-mode .text-slate-400,
body.light-mode .text-slate-500 {
    color: #64748b;
}

body.light-mode .text-slate-300 {
    color: #94a3b8;
}

body.light-mode input,
body.light-mode select {
    background-color: #ffffff;
    border-color: #cbd5e1;
    color: #1e293b;
}

/* --- Fixed Aspect Ratio Utilities --- */
.aspect-ratio-2-1 {
    aspect-ratio: 16 / 9;
    width: 100%;
}
@media (min-width: 768px) {
    .aspect-ratio-2-1 {
        aspect-ratio: 2 / 1;
    }
}

.img-adaptive {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center;
}

/* --- Slider Styles (Optimized) --- */
.ad-slider-container {
    position: relative;
    width: 100%;
    overflow: hidden;
    border-radius: 0;
    margin-bottom: 1.5rem;
    background-color: #1e293b;
    aspect-ratio: 16 / 9;
}
@media (min-width: 768px) {
    .ad-slider-container {
        border-radius: 0.75rem;
        aspect-ratio: 2 / 1;
    }
}

.ad-slider-wrapper {
    display: flex;
    height: 100%;
    transition: transform 0.5s ease-in-out;
}

.ad-slide {
    min-width: 100%;
    height: 100%;
    position: relative;
}

.ad-slide img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center;
}

.ad-dots {
    position: absolute;
    bottom: 10px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 6px;
    z-index: 10;
}

.ad-dot {
    width: 8px;
    height: 8px;
    background: rgba(255, 255, 255, 0.5);
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.3s;
}

.ad-dot.active {
    background: #fff;
    width: 20px;
    border-radius: 4px;
}

/* --- Ticker / Marquee Styles --- */
.ticker-wrap {
    width: 100%;
    overflow: hidden;
    background-color: rgba(30, 41, 59, 0.8);
    backdrop-filter: blur(8px);
    color: #22d3ee;
    border: 1px solid #334155;
    padding: 8px 0;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    position: relative;
    z-index: 20;
    direction: ltr;
}

.ticker {
    display: inline-block;
    white-space: nowrap;
    padding-right: 100%;
    padding-left: 0;
    animation: marquee 20s linear infinite;
    font-weight: bold;
    font-size: 0.9rem;
    direction: rtl;
}

@keyframes marquee {
    0% {
        transform: translate3d(-100%, 0, 0);
    }

    100% {
        transform: translate3d(100vw, 0, 0);
    }
}

/* --- Sidebar Mobile Overlay --- */
.glass-backdrop {
    backdrop-filter: blur(2px);
    transition: opacity 0.3s ease;
}

/* --- Print & Screen Bulk Print Styles --- */
/* Hide print containers by default on screen */
@media screen {
    #receipt-container,
    #bulk-print-container {
        display: none;
    }
}

/* When printing-bulk is active, show the container and hide everything else (works for both screen and print) */
body.printing-bulk > *:not(#bulk-print-container):not(#manual-close-print) {
    display: none !important;
}

/* [CRITICAL FIX] Force white background on HTML and BODY to prevent dark theme leaking into PDF */
html.printing-bulk,
body.printing-bulk {
    background: #ffffff !important;
    background-color: #ffffff !important;
    color: #000000 !important;
    overflow: auto !important;
}

body.printing-bulk #bulk-print-container {
    display: grid !important;
    visibility: visible !important;
    position: relative;
    top: 0;
    left: 0;
    width: 210mm;
    min-height: 297mm;
    padding: 4mm;
    box-sizing: border-box;
    grid-template-columns: repeat(3, 65mm) !important;
    grid-auto-rows: 28mm !important;
    column-gap: 2mm;
    row-gap: 1mm;
    justify-content: center;
    align-content: start;
    background: #ffffff !important;
    background-color: #ffffff !important;
    font-family: 'Arial', sans-serif;
    z-index: 9999;
    opacity: 1 !important;
}

@media print {
    @page {
        size: A4 portrait;
        margin: 0;
    }

    html, body {
        background: #ffffff !important;
        background-color: #ffffff !important;
        color: #000000 !important;
        font-family: 'Arial', sans-serif;
        margin: 0;
        padding: 0;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }

    /* إخفاء زر الإغلاق اليدوي أثناء الطباعة الفعلية */
    #manual-close-print {
        display: none !important;
    }

    /* حالة طباعة فاتورة فردية */
    body:not(.printing-bulk) #receipt-container {
        display: block !important;
        visibility: visible !important;
        width: 100%;
        padding: 5mm;
        text-align: center;
        font-family: 'Courier New', monospace;
    }

    /* حالة طباعة الكروت المجمعة - إجبار 3 أعمدة على الورق */
    body.printing-bulk #bulk-print-container {
        grid-template-columns: repeat(3, 65mm) !important;
        grid-auto-rows: 28mm !important;
        background: #ffffff !important;
        background-color: #ffffff !important;
    }

    /* Ensure all elements print their background colors */
    * {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }
}

.bulk-card {
    width: 100%;
    height: 100%;
    border: 1px dashed #999;
    border-radius: 4px;
    position: relative;
    overflow: hidden;
    background: #ffffff !important;
    background-color: #ffffff !important;
    page-break-inside: avoid;
    display: flex;
    flex-direction: row;
    align-items: center;
    padding: 2px;
    box-sizing: border-box;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
}

.bulk-card.theme-blue {
    border-right: 4px solid #3b82f6;
    background-color: #eff6ff !important;
}

.bulk-card.theme-green {
    border-right: 4px solid #22c55e;
    background-color: #f0fdf4 !important;
}

.bulk-card.theme-red {
    border-right: 4px solid #ef4444;
    background-color: #fef2f2 !important;
}

.bulk-card.theme-black {
    border-right: 4px solid #000000;
    background-color: #f9fafb !important;
}

.bulk-card.theme-gray {
    border-right: 4px solid #6b7280;
    background-color: #f3f4f6 !important;
}

.bulk-card.theme-white {
    border-right: 4px solid #e5e7eb;
    background-color: #ffffff !important;
    border: 1px solid #ddd;
}

.bulk-card.theme-orange {
    border-right: 4px solid #f97316;
    background-color: #fff7ed !important;
}

.bulk-card.theme-purple {
    border-right: 4px solid #a855f7;
    background-color: #faf5ff !important;
}

.bulk-card.theme-pink {
    border-right: 4px solid #ec4899;
    background-color: #fdf2f8 !important;
}

.bulk-card.theme-cyan {
    border-right: 4px solid #06b6d4;
    background-color: #ecfeff !important;
}

.bulk-card.theme-fuchsia {
    border-right: 4px solid #d946ef;
    background-color: #fdf4ff !important;
}

.bulk-card.theme-yellow {
    border-right: 4px solid #eab308;
    background-color: #fefce8 !important;
}

.bulk-card.theme-teal {
    border-right: 4px solid #14b8a6;
    background-color: #f0fdfa !important;
}

.bulk-card.theme-emerald {
    border-right: 4px solid #10b981;
    background-color: #ecfdf5 !important;
}

.bulk-card.theme-lime {
    border-right: 4px solid #84cc16;
    background-color: #f7fee7 !important;
}

.bulk-card.theme-sky {
    border-right: 4px solid #0ea5e9;
    background-color: #f0f9ff !important;
}

.bulk-card.theme-amber {
    border-right: 4px solid #d97706;
    background-color: #fffbeb !important;
}

.bulk-card.theme-gold {
    border-right: 4px solid #ca8a04;
    background-color: #fefce8 !important;
}

.bulk-card.theme-indigo {
    border-right: 4px solid #6366f1;
    background-color: #eef2ff !important;
}

.bulk-card.theme-violet {
    border-right: 4px solid #7c3aed;
    background-color: #f5f3ff !important;
}

.bulk-card.theme-rose {
    border-right: 4px solid #f43f5e;
    background-color: #fff1f2 !important;
}

.bulk-card.theme-slate {
    border-right: 4px solid #475569;
    background-color: #f8fafc !important;
}

.bulk-card.theme-stone {
    border-right: 4px solid #57534e;
    background-color: #fafaf9 !important;
}

.bulk-card.theme-crimson {
    border-right: 4px solid #dc143c;
    background-color: #fff0f2 !important;
}

.bulk-card.theme-teal-dark {
    border-right: 4px solid #0f766e;
    background-color: #f0fdfa !important;
}

.bulk-card.theme-navy {
    border-right: 4px solid #1e3a8a;
    background-color: #e0e7ff !important;
}

.bulk-card.theme-maroon {
    border-right: 4px solid #7f1d1d;
    background-color: #fef2f2 !important;
}

.bulk-card::before {
    content: '';
    position: absolute;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    background-repeat: repeat;
    background-position: center;
    opacity: 0.05;
    background-size: 50px 50px;
}
.bulk-card-right {
    width: 68%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding-right: 4px;
    padding-left: 2px;
    z-index: 1;
}
.bulk-card-left {
    width: 32%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    border-right: 1px dashed rgba(0,0,0,0.2);
    padding: 2px;
    z-index: 1;
}
.bulk-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 8px;
    font-weight: bold;
    color: #000;
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
    padding-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
}
.bulk-card-code-area {
    width: 100%;
    text-align: center;
    flex-grow: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}
.bulk-card-code {
    font-family: 'Courier New', monospace;
    font-weight: 900;
    font-size: 11px;
    color: #000;
    letter-spacing: 0px;
    word-break: break-all;
}
.bulk-card-qr {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}
.bulk-card-qr img, .bulk-card-qr canvas {
    max-width: 100% !important;
    max-height: 100% !important;
    object-fit: contain;
    width: 100%;
}
.bulk-card-info-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 7px;
    color: #333;
    font-weight: bold;
    border-top: 1px solid rgba(0, 0, 0, 0.05);
    padding-top: 2px;
}
.bulk-card-info-bar span {
    display: flex;
    align-items: center;
    gap: 2px;
}
.bulk-card-footer {
    display: none !important;
}

/* --- تحسينات عرض المتجر (Shop) للحاسوب والهاتف --- */
.shop-max-width {
    max-width: 600px !important;
    margin-left: auto !important;
    margin-right: auto !important;
}

.cover-image-container {
    aspect-ratio: 21 / 9;
    width: 100%;
    position: relative;
    overflow: hidden;
}

.logo-image-container {
    width: 80px;
    height: 80px;
    border-radius: 0.75rem;
    z-index: 20;
    position: relative;
    flex-shrink: 0;
}

/* تعديل إخفاء زر رفع الملفات الافتراضي الخاص بمكتبة html5-qrcode */
/* بدلاً من إخفائه كلياً (display: none) مما يمنع التفاعل معه برمجياً في بعض محركات WebView،
   نقوم بإخفائه بصرياً فقط لكي يستقبل النقرات البرمجية */
#qr-reader input[type="file"] {
    opacity: 0 !important;
    position: absolute !important;
    z-index: -10 !important;
    width: 1px !important;
    height: 1px !important;
}

/* --- تحسينات الوضع النهاري (Light Mode) للبطاقات والنوافذ --- */
body.light-mode dialog .bg-slate-900,
body.light-mode dialog .bg-slate-800 {
    background-color: #ffffff !important;
    border-color: #e2e8f0 !important;
    color: #1e293b !important;
    box-shadow: 0 10px 25px rgba(0,0,0,0.1) !important;
}

body.light-mode dialog::backdrop {
    background-color: rgba(0, 0, 0, 0.5) !important;
}

body.light-mode .bg-slate-800\/50,
body.light-mode .bg-slate-900\/50,
body.light-mode .bg-slate-900\/40 {
    background-color: #ffffff !important;
    border-color: #e2e8f0 !important;
}

body.light-mode .border-slate-700,
body.light-mode .border-slate-600 {
    border-color: #e2e8f0 !important;
}

body.light-mode .text-slate-300 {
    color: #475569 !important;
}

/* --- قسم تعليمات الاستخدام (Instructions Section) --- */
#instructions .bg-white {
    transition: all 0.3s ease-in-out;
    border-right: 4px solid transparent;
}

#instructions .bg-white:hover {
    transform: translateY(-3px);
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1);
    border-right-color: #4f46e5;
}

#instructions h3 i {
    transition: transform 0.3s ease;
}

#instructions .bg-white:hover h3 i {
    transform: scale(1.2) rotate(10deg);
}

#instructions p {
    line-height: 1.8;
    color: #475569;
}

/* Light mode adjustments for instructions */
body.light-mode #instructions .bg-white {
    background-color: #ffffff !important;
    border-color: #e2e8f0;
}

/* --- App Lock Screen --- */
#app-lock-screen {
    position: fixed !important;
    inset: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    background-color: #020617 !important; /* Solid slate-950, no blur */
    z-index: 2147483647 !important; /* Max z-index to cover SweetAlerts */
    user-select: none !important;
    -webkit-user-select: none !important;
    backdrop-filter: none !important;
}

/* --- Global Voucher Print Styles --- */
.voucher-card {
    width: 100%;
    height: 100%;
    border: 2px dashed #cbd5e1;
    border-radius: 8px;
    position: relative;
    overflow: hidden;
    background: #ffffff !important;
    page-break-inside: avoid;
    display: flex;
    flex-direction: row;
    align-items: center;
    padding: 4px;
    box-sizing: border-box;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
}
.voucher-card.theme-new {
    border-color: #3b82f6;
    background-color: #eff6ff !important;
}
.voucher-card.theme-old {
    border-color: #22c55e;
    background-color: #f0fdf4 !important;
}
.voucher-right {
    width: 70%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding-right: 8px;
    padding-left: 4px;
}
.voucher-left {
    width: 30%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    border-right: 2px dashed rgba(0,0,0,0.1);
    padding: 4px;
}
.voucher-header {
    display: flex;
    justify-content: space-between;
    border-bottom: 1px solid rgba(0,0,0,0.1);
    padding-bottom: 4px;
    font-weight: 900;
    font-size: 12px;
}
.voucher-code {
    text-align: center;
    font-family: 'Courier New', monospace;
    font-weight: 900;
    font-size: 14px;
    letter-spacing: 2px;
    margin: 8px 0;
    color: #0f172a;
}
.voucher-instruction {
    font-size: 9px;
    font-weight: bold;
    color: #475569;
    text-align: center;
    background: #f1f5f9;
    border-radius: 4px;
    padding: 4px;
}
.voucher-footer {
    display: flex;
    justify-content: space-between;
    font-size: 8px;
    color: #64748b;
    margin-top: 4px;
}

/* --- Accordion Styles --- */
details > summary {
    list-style: none;
}
details > summary::-webkit-details-marker {
    display: none;
}
details[open] summary ~ * {
    animation: fadeIn 0.3s ease-in-out;
}
