:root {
    /* Premium Dark Palette */
    --primary-color: #3498db;
    /* Bright Blue for Dark Mode Contrast */
    --secondary-color: #f1c40f;
    /* Vibrant Gold */
    --accent-color: #e74c3c;
    /* Red */

    /* Backgrounds: Deep Space/Teal Gradient */
    --bg-gradient: linear-gradient(135deg, #0f2027 0%, #203a43 50%, #2c5364 100%);

    /* Glass: Dark Navy Transparent */
    --glass-bg: rgba(22, 33, 62, 0.85);
    --glass-border: rgba(255, 255, 255, 0.15);
    /* Subtle white border for definition */

    /* Text: Inverted for Dark Mode */
    --text-color: #ecf0f1;
    /* White-ish */
    --text-light: #bdc3c7;
    /* Light Gray */

    /* Effects */
    --shadow: 0 15px 35px 0 rgba(0, 0, 0, 0.4);
    /* Stronger dark shadow */
    --radius: 20px;
    --font-main: 'Tajawal', sans-serif;

    /* Status Colors */
    --status-red: #ff7675;
    --status-orange: #fdcb6e;
    --status-green: #55efc4;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-main);
    background: var(--bg-gradient);
    color: var(--text-color);
    min-height: 100vh;
    padding: 20px;
    direction: rtl;
    line-height: 1.6;
    /* App Feel: Disable text selection */
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    /* Prevent pull-to-refresh on mobile if supported */
    overscroll-behavior-y: none;
}

/* Allow selection on inputs */
input,
textarea,
[contenteditable] {
    -webkit-user-select: text;
    user-select: text;
}

.app-container {
    max-width: 1200px;
    margin: 0 auto;
    position: relative;
    padding-bottom: 80px;
    width: 100%;
    overflow-x: hidden;
    /* Stop horizontal scroll - Force hard stop */
    width: 100%;
}

/* Fix for potential ghost sidebar by ensuring no element exceeds width */
html,
body {
    overflow-x: hidden;
    max-width: 100vw;
}

/* Premium Dark Glass Card */
.glass-card {
    background: var(--glass-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-radius: var(--radius);
    border: 1px solid var(--glass-border);
    box-shadow: var(--shadow);
    padding: 25px;
    margin-bottom: 25px;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    color: var(--text-color);
}

.glass-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 20px 45px rgba(0, 0, 0, 0.5);
    border-color: rgba(255, 255, 255, 0.3);
}

/* Polished Buttons */
.btn {
    padding: 12px 28px;
    border: none;
    border-radius: 12px;
    font-family: var(--font-main);
    font-weight: 700;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-size: 0.95rem;
    letter-spacing: 0.5px;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary-color) 0%, #2980b9 100%);
    color: white;
    box-shadow: 0 4px 15px rgba(52, 152, 219, 0.4);
}

.btn-primary:hover {
    box-shadow: 0 6px 20px rgba(52, 152, 219, 0.6);
    transform: translateY(-2px);
    filter: brightness(1.1);
}

.btn-danger {
    background: var(--status-red);
    color: white;
}

.btn-success {
    background: var(--status-green);
    color: #2d3436;
    /* Dark text for contrast on light green */
}

/* Dark Mode Inputs */
input,
select,
textarea {
    width: 100%;
    padding: 14px;
    background: rgba(0, 0, 0, 0.3);
    /* Dark transparent background */
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 12px;
    font-family: var(--font-main);
    margin-bottom: 15px;
    outline: none;
    transition: all 0.3s;
    color: white;
    /* Bright text */
    font-size: 1rem;
}

input::placeholder,
textarea::placeholder {
    color: rgba(255, 255, 255, 0.5);
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(52, 152, 219, 0.3);
    background: rgba(0, 0, 0, 0.5);
}

/* Typography */
h1,
h2,
h3,
h4 {
    margin-bottom: 15px;
    color: var(--primary-color);
    font-weight: 800;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

h2 {
    font-size: 1.8rem;
}

h3 {
    font-size: 1.4rem;
}

.text-center {
    text-align: center;
}

/* Grid System */
.grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 25px;
}

/* Helpers */
.hidden {
    display: none !important;
}

.fade-in {
    animation: fadeIn 0.6s cubic-bezier(0.22, 0.61, 0.36, 1);
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Phase 2: Entrance Cards (Dark) */
.entrance-card {
    height: 260px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    background: rgba(255, 255, 255, 0.05);
    /* Very subtle light overlay */
    border-radius: 24px;
    cursor: pointer;
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
    color: white;
}

.entrance-card:hover {
    transform: translateY(-10px) scale(1.02);
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.4);
    background: rgba(255, 255, 255, 0.1);
}

.entrance-card.admin:hover {
    border-color: var(--primary-color);
}

.entrance-card.client:hover {
    border-color: var(--secondary-color);
}

/* Barcode */
.barcode-visual {
    font-family: 'Courier New', Courier, monospace;
    letter-spacing: 4px;
    font-weight: 900;
    transform: scaleY(1.5);
    display: inline-block;
    color: var(--secondary-color);
    /* Gold barcode */
}

/* --- Premium Component Styles --- */

/* Scrollable Category Bar */
.category-scroll {
    display: flex;
    gap: 15px;
    overflow-x: auto;
    padding: 5px 5px 15px 5px;
    scrollbar-width: thin;
    margin-bottom: 25px;
}

.category-chip {
    padding: 12px 25px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 50px;
    font-weight: 700;
    color: var(--text-light);
    cursor: pointer;
    white-space: nowrap;
    border: 1px solid rgba(255, 255, 255, 0.1);
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 10px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.category-chip:hover {
    background: rgba(255, 255, 255, 0.15);
    transform: translateY(-3px);
    color: white;
    border-color: white;
}

.category-chip.active {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
    box-shadow: 0 8px 15px rgba(52, 152, 219, 0.4);
}

/* Premium Product Card (Dark) */
/* Product Card Premium Redesign */
.product-card {
    background: rgba(30, 30, 30, 0.6);
    /* Darker, sleek background */
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 20px;
    overflow: hidden;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    display: flex;
    flex-direction: column;
    height: 100%;
    backdrop-filter: blur(10px);
}

.product-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.3);
    border-color: var(--primary-color);
}

.product-img-container {
    width: 100%;
    height: 180px;
    background: #fff;
    /* White bg for product images to pop */
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    /* Removed padding */
    position: relative;
}

.product-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    /* Fill the area */
    transition: transform 0.3s;
}

.product-card:hover .product-img {
    transform: scale(1.05);
    /* Subtle zoom */
}

.product-content {
    padding: 15px;
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    text-align: right;
}

.product-title {
    color: white;
    /* White title */
}

.product-price {
    color: var(--secondary-color);
    /* Gold for price */
    font-weight: 900;
    font-size: 1.4rem;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 5px;
}

.product-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.product-barcode {
    font-family: 'Libre Barcode 128', 'Libre Barcode 39 Text', cursive;
    color: #888;
    font-size: 2.5rem;
    /* Large enough for the barcode font to be readable as lines */
    background: transparent;
    padding: 0;
    line-height: 1;
    transform: translateY(5px);
    /* Adjust alignment */
}

.product-price {
    color: var(--primary-color);
    font-weight: 800;
    font-size: 1.2rem;
}

.product-actions {
    display: flex;
    gap: 12px;
}

.action-btn {
    flex: 1;
    padding: 12px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    background: rgba(255, 255, 255, 0.05);
    border-radius: 14px;
    cursor: pointer;
    font-weight: 700;
    font-size: 0.9rem;
    transition: all 0.2s;
    color: white;
}

.btn-piece:hover,
.btn-dozen:hover {
    border-color: var(--primary-color);
    background: var(--primary-color);
    color: white;
}

/* Responsive */
/* Tablet & Desktop Tweaks */
@media (min-width: 769px) {
    .grid {
        grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
        /* Better density on desktop */
        gap: 30px;
    }

    .entrance-card {
        height: 300px;
        font-size: 1.1rem;
    }
}

/* Responsive Mobile Optimization */
@media (max-width: 768px) {
    body {
        padding: 15px;
        /* More breathing room than 10px */
    }

    .grid {
        display: grid;
        grid-template-columns: 1fr 1fr;
        /* Force 2 columns */
        gap: 15px;
        /* Increased gap for comfort */
    }

    /* Client View Product Card */
    .client-product-card {
        background: rgba(30, 30, 30, 0.4) !important;
        border: 1px solid rgba(255, 255, 255, 0.05);
        border-radius: 16px;
        padding: 0 !important;
        overflow: hidden;
        display: flex;
        flex-direction: column;
        height: 100%;
        box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2) !important;
    }

    .client-product-img-wrapper {
        width: 100%;
        padding-top: 100%;
        /* Square Aspect Ratio */
        position: relative;
        background: #fff;
        /* White bg for product clarity */
    }

    .client-product-img {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        object-fit: contain;
        /* Show full product */
        padding: 10px;
        transition: transform 0.3s;
    }

    .client-product-info {
        padding: 10px;
        flex: 1;
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        text-align: right;
    }

    .client-product-title {
        font-size: 0.9rem;
        font-weight: bold;
        color: #fff;
        margin-bottom: 5px;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        /* Limit to 2 lines */
        -webkit-box-orient: vertical;
        overflow: hidden;
    }

    /* --- Add Mobile Fixes Here --- */

    /* Fix Admin Product Card Layout on Mobile */
    .product-card-admin {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 15px !important;
        padding: 15px !important;
    }

    .product-card-admin>div:first-child {
        width: 100%;
    }

    .product-card-admin h4 {
        white-space: normal !important;
        /* Allow text wrap */
        max-width: 100% !important;
    }

    /* Fix Order Card Action Buttons Clutter */
    .order-actions-container {
        display: grid !important;
        grid-template-columns: repeat(3, 1fr) !important;
        /* 3 buttons per row */
        gap: 8px !important;
        width: 100% !important;
        justify-content: stretch !important;
    }

    .order-actions-container .btn {
        padding: 8px 5px !important;
        font-size: 0.8rem !important;
        width: 100% !important;
        display: flex;
        justify-content: center;
        align-items: center;
    }

    /* Fix "Unavailable" list style on mobile */
    .unavailable-card-mobile {
        flex-direction: column !important;
        align-items: stretch !important;
    }
}

/* --- Splash Screen Animation --- */
#splash-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #ffffff;
    /* Solid White */
    z-index: 99999;
    /* Always on top */
    display: flex;
    justify-content: center;
    align-items: center;
    transition: opacity 0.5s ease-in-out, visibility 0.5s;
}

#splash-screen.fade-out {
    opacity: 0;
    visibility: hidden;
}

.splash-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
}

/* Professional Clean Logo Effect on White */
.splash-logo {
    width: 180px;
    height: 180px;
    object-fit: contain;
    opacity: 0;
    /* Fast 1s Animation */
    animation: logoEnter 1.0s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

@keyframes logoEnter {
    0% {
        opacity: 0;
        transform: scale(0.6) translateY(20px);
        filter: blur(5px);
    }

    100% {
        opacity: 1;
        transform: scale(1.0) translateY(0);
        filter: blur(0);
    }
}

/* Optional: Loading Progress Bar fitting for apps */
.splash-loader {
    width: 0%;
    height: 3px;
    background: linear-gradient(90deg, var(--secondary-color), var(--primary-color));
    margin-top: 30px;
    border-radius: 2px;
    animation: loadProgress 2.5s ease-out forwards;
    box-shadow: 0 0 10px var(--primary-color);
}

@keyframes loadProgress {
    0% {
        width: 0%;
        opacity: 0;
    }

    20% {
        width: 20%;
        opacity: 1;
    }

    80% {
        width: 90%;
    }

    100% {
        width: 100%;
        opacity: 0;
    }
}

/* Scanner UI */
#camera-scanner-modal #reader {
    width: 100%;
    background: black;
    border-radius: 12px;
    overflow: hidden;
}

#camera-scanner-modal #reader video {
    width: 100% !important;
    height: auto !important;
    border-radius: 12px;
    object-fit: cover;
}