@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800;900&family=Oswald:wght@500;700&family=Amiri:wght@400;700&display=swap');

/* --- DARK THEME (DEFAULT) VARIABLES --- */
:root {
    --primary: #1e293b;
    --accent: #6366f1;
    --accent-grad: linear-gradient(135deg, #6366f1 0%, #4f46e5 100%);
    --bg: #0f172a;
    --surface: #1e293b;
    --surface-hover: #334155;
    --border: #334155;
    --text-main: #f8fafc;
    --text-sub: #94a3b8;
    --header-grad: linear-gradient(135deg, #020617 0%, #0f172a 100%);
    --input-bg: #0f172a;
    --input-text: #fff;
}

/* --- LIGHT THEME OVERRIDES --- */
[data-theme="light"] {
    --primary: #ffffff;
    --accent: #4f46e5;
    --accent-grad: linear-gradient(135deg, #4f46e5 0%, #4338ca 100%);
    --bg: #f1f5f9; /* Slate 100 */
    --surface: #ffffff;
    --surface-hover: #e2e8f0; /* Slate 200 */
    --border: #cbd5e1; /* Slate 300 */
    --text-main: #0f172a; /* Slate 900 */
    --text-sub: #64748b; /* Slate 500 */
    --header-grad: linear-gradient(135deg, #2563eb 0%, #1e40af 100%); /* Blueish for Light Mode */
    --input-bg: #ffffff;
    --input-text: #0f172a;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { scroll-behavior: smooth; }

body {
    font-family: 'Inter', sans-serif;
    background: var(--bg);
    margin: 0;
    padding: 0;
    color: var(--text-main);
    overflow-x: hidden;
    /* Optimised transition for speed */
    transition: background 0.15s ease, color 0.15s ease;
}

/* Scrollbar Styling */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: #475569; border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: #64748b; }

/* GLOBAL THEME OVERRIDES */
.bg-white, .bg-slate-50, .bg-gray-50, .bg-gray-100, .bg-slate-100 { background-color: var(--surface) !important; color: var(--text-main) !important; }
.text-slate-900, .text-gray-900, .text-black, .text-gray-800, .text-gray-700 { color: var(--text-main) !important; }
.text-gray-500, .text-gray-600, .text-slate-500, .text-gray-400 { color: var(--text-sub) !important; }
.border-gray-200, .border-gray-100, .border-slate-100, .border-slate-200, .border-gray-300 { border-color: var(--border) !important; }
.shadow-sm, .shadow-md, .shadow-lg, .shadow-xl { box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.2) !important; }

/* Dynamic Input Styling */
input, select, textarea, .inp, .input-box, .gen-input-box, .gen-code-area {
    background-color: var(--input-bg) !important;
    color: var(--input-text) !important;
    border-color: var(--border) !important;
    transition: all 0.1s ease;
}
input::placeholder, textarea::placeholder { color: var(--text-sub) !important; }

/* Forced Dark Mode Elements (Like Splash) */
.always-dark { background: #0f172a !important; color: white !important; }

/* LAPTOP & MOBILE OPTIMIZATION */
@media (min-width: 0px) {
    body {
        font-size: 13px !important;
        background: var(--bg);
        overflow-x: hidden;
    }
    h1:not(.splash-logo):not(.header-logo-text), h2, h3, h4, h5 { font-size: 15px !important; }
    
    .splash-logo { font-size: 80px !important; }
    .header-logo-text { font-size: 42px !important; }

    .max-w-7xl {
        max-width: 100% !important;
        width: 100vw !important;
        margin: 0 !important;
        padding: 0 !important;
        box-shadow: none;
        min-height: 100vh;
    }

    /* Grids - ULTRA FAST RENDERING */
    #pList, #uList, #oList, #pos-grid, #saved-bills-list {
        display: grid !important;
        grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)) !important;
        gap: 15px !important;
        padding-bottom: 40px !important;
        content-visibility: auto; /* KEY PERFORMANCE BOOST */
        contain-intrinsic-size: 240px; /* Helps browser calculate layout faster */
    }
    
    .card-item { 
        padding: 18px !important; 
        min-height: 240px; 
        will-change: transform; /* GPU Acceleration */
    } 
    
    /* MODALS AS FULL PAGES */
    .modal-overlay {
        background: var(--bg) !important;
        padding: 0 !important;
        align-items: flex-start !important;
        z-index: 2000 !important;
    }

    .modal-box {
        width: 100% !important;
        max-width: 100% !important;
        height: 100dvh !important;
        max-height: 100dvh !important;
        min-height: 100vh;
        border-radius: 0 !important;
        box-shadow: none !important;
        padding: 40px 60px !important;
        animation: none !important;
        overflow-y: auto !important;
        background: var(--surface) !important;
    }
    
    @media (max-width: 768px) {
        .modal-box { padding: 20px !important; }
        #pList, #uList, #oList, #pos-grid, #saved-bills-list {
             grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)) !important;
        }
    }

    /* SUB PAGES AS FULL PAGES */
    .sub-page {
        width: 100% !important;
        height: 100dvh !important; /* Fixed for mobile */
        top: 0 !important;
        left: 0 !important;
        right: auto !important;
        bottom: auto !important;
        transform: none !important;
        border-radius: 0 !important;
        box-shadow: none !important;
        padding: 40px 60px !important;
        background: var(--surface) !important;
        border: none !important;
        z-index: 2000 !important;
        animation: fadeIn 0.2s ease !important;
    }
    
    @media (max-width: 768px) {
        .sub-page { padding: 20px !important; }
    }
    
    @keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

    .modal-box .close-btn-classic { display: none !important; }

    /* POS Layout Adjustments */
    #view-pos.pos-active {
        display: flex !important;
        flex-direction: column;
        height: 100vh;
        overflow: hidden;
        padding: 0 !important;
        background: var(--bg);
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        z-index: 5000;
    }
    
    #view-pos.pos-active .pos-wrapper {
        display: grid !important; 
        grid-template-columns: 1fr 370px;
        gap: 20px;
        flex: 1;
        height: calc(100vh - 70px);
        overflow: hidden;
        padding: 20px;
    }

    @media (max-width: 800px) {
        #view-pos.pos-active .pos-wrapper {
            display: flex !important;
            flex-direction: column;
            gap: 15px;
            overflow-y: auto;
            height: auto;
            padding-bottom: 80px;
        }
        .pos-left-pane {
            height: auto !important;
            overflow: visible !important;
            order: 2;
        }
        .pos-right-pane {
            height: auto !important;
            width: 100% !important;
            max-height: unset !important;
            overflow-y: visible !important;
            order: 1;
            position: relative;
            top: 0;
        }
    }

    .pos-left-pane { padding: 0; height: 100%; overflow-y: auto; padding-right: 5px; }
    .pos-right-pane { height: 100%; padding: 0px; background: transparent; border-radius: 0; border: none; overflow-y: visible; overflow-x: hidden; }
    
    /* FIX FOR SCROLLING VIEWS (Users, Orders, Messages) */
    .view-section-full {
        display: none;
        width: 100%;
        min-height: 100vh;
        height: 100vh; /* Force full height */
        padding: 20px 40px !important;
        position: fixed;
        top: 0;
        left: 0;
        background: var(--bg);
        z-index: 50;
        overflow-y: auto !important; /* ENABLE SCROLL */
        padding-bottom: 100px !important; /* Space for bottom content */
        -webkit-overflow-scrolling: touch; /* Smooth scroll mobile */
    }

    .view-section:not(#view-pos):not(.view-section-full) {
        display: block;
        width: 100%;
        padding: 20px 40px !important;
    }
    @media (max-width: 768px) {
        .view-section:not(#view-pos) { padding: 20px !important; }
        .view-section-full { padding: 20px !important; padding-bottom: 100px !important; }
    }

    .inp, .input-box {
        padding: 16px !important;
        font-size: 14px !important;
        background: var(--input-bg) !important;
    }
}

/* Animations */
.animation-fade { animation: fadeContent 0.1s cubic-bezier(0.4, 0, 0.2, 1); will-change: opacity, transform; }
@keyframes fadeContent { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: translateY(0); } }

/* Splash */
.splash-screen { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: #0f172a; display: flex; flex-direction: column; justify-content: center; align-items: center; z-index: 9999; text-align: center; }
.splash-logo { font-family: 'Oswald', sans-serif; font-size: 60px; line-height: 1; font-weight: 700; color: #fff; letter-spacing: 2px; margin-bottom: 15px; animation: fadeUp 0.6s cubic-bezier(0.2, 0.8, 0.2, 1); text-shadow: 0 10px 30px rgba(99, 102, 241, 0.4); }
.splash-sub { color: #94a3b8; font-size: 14px; font-weight: 500; letter-spacing: 4px; text-transform: uppercase; margin-bottom: 40px; border-top: 1px solid #334155; padding-top: 10px; width: 200px; margin-left: auto; margin-right: auto; }
.loader-track { width: 200px; height: 3px; background: #334155; border-radius: 4px; overflow: hidden; position: relative; margin: 0 auto; }
.loader-fill { height: 100%; background: #6366f1; width: 0%; animation: fillBar 1s cubic-bezier(0.22, 1, 0.36, 1) forwards; }
@keyframes fillBar { 0% { width: 0%; } 100% { width: 100%; } }
@keyframes fadeUp { 0% { opacity: 0; transform: translateY(20px); } 100% { opacity: 1; transform: translateY(0); } }

/* Login Form */
.black-curve { background: var(--header-grad); height: 35vh; min-height: 280px; border-radius: 0 0 40px 40px; display: flex; flex-direction: column; align-items: center; justify-content: center; position: relative; width: 100%; }
.form-area { background: var(--surface); border-radius: 24px; margin: -60px 20px 0 20px; padding: 40px 30px; box-shadow: 0 25px 50px -12px rgba(0,0,0,0.5); position: relative; z-index: 10; max-width: 420px; width: calc(100% - 40px); border: 1px solid var(--border); }
.desktop-center-form { display: flex; flex-direction: column; align-items: center; justify-content: flex-start; min-height: 100vh; background: var(--bg); width: 100%; }
@media (min-width: 768px) {
    .desktop-center-form { justify-content: center; background: #020617; }
    .black-curve { height: 140px; min-height: unset; border-radius: 24px 24px 0 0; width: 100%; margin: 0; box-shadow: none; }
    .form-area { margin: 0; border-radius: 0 0 24px 24px; width: 100%; max-width: 100%; box-shadow: 0 20px 60px rgba(0,0,0,0.3); }
}

.input-box { width: 100%; padding: 18px 20px; background: var(--input-bg); border-radius: 12px; margin-bottom: 16px; border: 1px solid var(--border); outline: none; font-size: 16px; font-weight: 500; transition: all 0.2s ease; color: var(--input-text); }
.input-box:focus { border-color: #6366f1; background: var(--surface-hover); box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.2); }
.btn-main { width: 100%; background: var(--accent-grad); color: #fff; padding: 18px; border-radius: 12px; font-weight: 700; font-size: 14px; text-transform: uppercase; letter-spacing: 1px; transition: all 0.2s ease; cursor: pointer; border: none; }
.btn-main:active { transform: scale(0.98); opacity: 0.9; }

/* Tabs */
.tab-badge { position: absolute; top: -5px; right: -5px; background: #ef4444; color: white; border-radius: 50%; width: 20px; height: 20px; font-size: 10px; display: flex; align-items: center; justify-content: center; border: 2px solid var(--surface); z-index: 10; font-weight: 800; }

.inp { width: 100%; padding: 14px; border-radius: 10px; border: 1px solid var(--border); font-size: 14px; margin-bottom: 10px; outline: none; transition: 0.2s; background: var(--input-bg); color: var(--input-text); }
.inp:focus { border-color: #6366f1; background: var(--surface-hover); box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1); }
select.inp { appearance: none; background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e"); background-repeat: no-repeat; background-position: right 1rem center; background-size: 1em; }
[data-theme="light"] select.inp { background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e"); }

/* Modals */
.modal-overlay { display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0, 0, 0, 0.8); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); z-index: 200; align-items: center; justify-content: center; padding: 20px; }
.modal-box { background: var(--surface); width: 100%; max-width: 360px; padding: 20px; border-radius: 24px; box-shadow: 0 25px 50px -12px rgba(0,0,0,0.5); animation: scaleUp 0.1s cubic-bezier(0.16, 1, 0.3, 1); max-height: 85vh; overflow-y: auto; color: var(--text-main); }
@keyframes scaleUp { from { transform: scale(0.95) translateY(10px); opacity: 0; } to { transform: scale(1) translateY(0); opacity: 1; } }

.chat-bubble-user { align-self: flex-start; background: var(--surface-hover); color: var(--text-main); border-radius: 18px 18px 18px 4px; padding: 12px 16px; font-size: 14px; max-width: 85%; margin-bottom: 10px; box-shadow: 0 2px 5px rgba(0,0,0,0.2); border: 1px solid var(--border); }
.chat-bubble-admin { align-self: flex-end; background: #4f46e5; color: #fff; border-radius: 18px 18px 4px 18px; padding: 12px 16px; font-size: 14px; max-width: 85%; margin-bottom: 10px; box-shadow: 0 4px 10px rgba(79, 70, 229, 0.3); }

/* Settings Grid Buttons */
.setting-card-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 20px;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 4px 6px rgba(0,0,0,0.2);
    position: relative;
    color: var(--text-main);
}
.setting-card-btn:hover {
    transform: translateY(-5px);
    box-shadow: 0 10px 20px rgba(0,0,0,0.4);
    border-color: #6366f1;
    background: var(--surface-hover);
}
.setting-card-btn svg { width: 32px; height: 32px; color: #6366f1; margin-bottom: 10px; }
.setting-card-btn span { font-weight: 700; font-size: 13px; color: var(--text-sub); }

/* Sub Pages */
.sub-page { display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: var(--bg); z-index: 170; overflow-y: auto; padding: 20px; padding-bottom: 100px; animation: slidePage 0.15s cubic-bezier(0.16, 1, 0.3, 1); will-change: transform; color: var(--text-main); }
@keyframes slidePage { from { transform: translateX(100%); } to { transform: translateX(0); } }
@media (min-width: 768px) and (max-width: 1023px) {
    .sub-page { width: 50%; left: auto; right: 0; border-left: 1px solid var(--border); box-shadow: -20px 0 40px rgba(0,0,0,0.5); }
}
.sub-header { display: flex; align-items: center; gap: 15px; margin-bottom: 25px; position: sticky; top: 0; background: var(--bg); backdrop-filter: blur(10px); padding: 10px 0; z-index: 10; border-bottom: 1px solid var(--border); }
.pos-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-top: 15px; }
@media (min-width: 640px) { .pos-grid { grid-template-columns: repeat(3, 1fr); } }

/* Print Bill Fixed - MUST STAY WHITE */
@media print {
    @page { margin: 0; size: 58mm auto; }
    body { margin: 0; padding: 0; background-color: #fff !important; color: #000 !important; }
    body * { visibility: hidden; color: #000 !important; background-color: #fff !important; }
    #print-area, #print-area * { visibility: visible; }
    #print-area { position: absolute; left: 0; top: 0; width: 100%; margin: 0; padding: 5px; display: block !important; font-family: 'Courier New', Courier, monospace; background: white !important; color: black !important; }
}
.pos-item { border-bottom: 1px dashed var(--border); padding: 10px 0; display: flex; flex-direction: column; gap: 6px; }
.pos-inp-row { display: flex; gap: 8px; align-items: center; }

/* Product Cards - Dark Mode */
.card-item {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 18px; /* Increased padding */
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    box-shadow: 0 4px 6px rgba(0,0,0,0.2);
    height: 100%;
    min-height: 240px; /* Increased height for thicker look */
    transition: all 0.2s cubic-bezier(0.25, 0.8, 0.25, 1);
    position: relative;
    overflow: hidden;
    will-change: transform;
}
.card-item:hover { transform: translateY(-4px); box-shadow: 0 15px 30px rgba(99, 102, 241, 0.15); border-color: #6366f1; background: var(--surface-hover); }
.card-item:active { transform: scale(0.98); }
.prod-icon {
    width: 100%;
    aspect-ratio: 4/3;
    background: var(--bg);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 12px;
}
.prod-icon svg { width: 45%; height: 45%; color: var(--text-sub); opacity: 0.8; }

/* NEW ICON PRO GENERATOR STYLES */
.gen-card {
    background: var(--surface);
    width: 100%;
    border-radius: 20px;
    padding: 25px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.2);
    text-align: center;
    border: 1px solid var(--border);
    margin-top: 20px;
}
.gen-header-text { font-size: 18px; font-weight: 600; margin-bottom: 15px; color: var(--text-main); text-align: left; }
.gen-input-box { width: 100%; padding: 16px; border: 1.5px solid var(--border); border-radius: 15px; font-size: 14px; margin-bottom: 10px; outline: none; transition: 0.3s; background: var(--input-bg); color: var(--input-text); }
.gen-input-box:focus { border-color: #6366f1; background: var(--surface-hover); }
#genIconPreview { background: var(--bg); width: 80px; height: 80px; margin: 10px auto 20px; border-radius: 20px; display: flex; align-items: center; justify-content: center; border: 1px dashed var(--border); }
#genIconPreview svg { width: 45px; height: 45px; fill: var(--text-main); }
.gen-code-area { width: 100%; height: 100px; background: var(--bg); border: 1.5px solid var(--border); border-radius: 15px; padding: 12px; font-family: 'Courier New', monospace; font-size: 11px; color: var(--text-sub); resize: none; margin-bottom: 15px; }
.gen-btn-add { width: 100%; padding: 16px; background: #4f46e5; color: #fff; border: none; border-radius: 15px; font-size: 14px; font-weight: 600; text-transform: uppercase; letter-spacing: 1px; cursor: pointer; transition: 0.2s; }
.gen-btn-add:active { transform: scale(0.96); background: #4338ca; }
.gen-hint { font-size: 12px; color: var(--text-sub); margin-top: -5px; margin-bottom: 15px; text-align: left; padding-left: 5px; }

/* SUPER FANCY CLOSE BUTTON */
.btn-close-styled {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--surface);
    border: 1px solid var(--border);
    padding: 8px 16px;
    border-radius: 12px;
    color: var(--text-main);
    font-weight: 700;
    font-size: 13px;
    transition: all 0.2s cubic-bezier(0.25, 0.8, 0.25, 1);
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
    cursor: pointer;
    will-change: transform, background, color;
}
.btn-close-styled:hover {
    background: var(--surface-hover);
    color: var(--text-main);
    border-color: var(--border);
    transform: translateY(-2px);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
}
.btn-close-styled:active {
    transform: scale(0.96);
}
.btn-close-styled svg {
    width: 18px;
    height: 18px;
    transition: transform 0.2s;
}
.btn-close-styled:hover svg {
    transform: rotate(90deg);
}

/* Floating Bill Button */
.fab-bill {
    position: fixed;
    bottom: 30px;
    right: 30px;
    width: 70px;
    height: 70px;
    background: linear-gradient(135deg, #6366f1 0%, #4f46e5 100%);
    border-radius: 50%;
    box-shadow: 0 10px 30px rgba(99, 102, 241, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 900;
    font-size: 12px;
    flex-direction: column;
    z-index: 100;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    border: 2px solid rgba(255,255,255,0.2);
}
.fab-bill:hover {
    transform: scale(1.1);
    box-shadow: 0 15px 40px rgba(99, 102, 241, 0.6);
}
.fab-bill svg { width: 24px; height: 24px; margin-bottom: 2px; }

/* NEW Add Product FAB */
.fab-add-prod {
    position: fixed;
    bottom: 115px; /* Above the Bill button */
    right: 35px;
    width: 60px;
    height: 60px;
    background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
    border-radius: 50%;
    box-shadow: 0 10px 30px rgba(59, 130, 246, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 900;
    font-size: 11px;
    flex-direction: column;
    z-index: 100;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    border: 2px solid rgba(255,255,255,0.2);
}
.fab-add-prod:hover { transform: scale(1.1); box-shadow: 0 15px 40px rgba(59, 130, 246, 0.6); }
.fab-add-prod svg { width: 22px; height: 22px; margin-bottom: 1px; }

@keyframes spin { 100% { transform: rotate(360deg); } }
