@import url('https://fonts.googleapis.com/css2?family=Tajawal:wght@200;300;400;500;700;800;900&display=swap');

/* =========================================
   1. VARIABLES & RESET
   ========================================= */
:root {
    /* AliExpress Brand Colors */
    --primary-color: #FF4747;
    /* The Reddish-Orange */
    --primary-hover: #FF2E2E;
    --primary-light: #FFF0E5;
    /* Very light orange used for backgrounds */

    --secondary-color: #FF9E00;
    /* The Bright Orange */
    --secondary-hover: #E68A00;

    /* AliExpress Gradient */
    --brand-gradient: linear-gradient(90deg, #FF9E00 0%, #FF4747 100%);

    /* Neutral / UI Colors */
    --background-color: #F5F5F5;
    /* Standard E-commerce Gray */
    --sidebar-bg: #FFFFFF;
    /* WHITE SIDEBAR */
    --sidebar-border: #E8E8E8;
    --sidebar-active: #FFF0E5;
    /* Light Orange Background for active items */
    --sidebar-text: #333333;

    --card-bg: #ffffff;

    /* Text Colors */
    --text-color: #222222;
    /* Almost Black */
    --text-muted: #757575;
    --text-light: #999999;
    --white: #ffffff;

    /* Borders & Shadows */
    --border-color: #E8E8E8;
    --border-radius: 8px;
    --border-radius-lg: 12px;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);

    /* Status Colors */
    --success-color: #00A65A;
    --success-bg: #E6F7EF;
    --danger-color: #FF4747;
    --danger-bg: #FFF0F0;
    --warning-color: #FF9E00;
    --warning-bg: #FFF5E6;
    --info-color: #0077FF;
    --info-bg: #F0F7FF;

    /* Modern Glassmorphism & Soft Depth */
    --glass-bg: rgba(255, 255, 255, 0.7);
    --glass-border: rgba(255, 255, 255, 0.3);
    --glass-blur: blur(12px);
    --shadow-soft: 0 10px 30px -5px rgba(0, 0, 0, 0.05), 0 5px 15px -5px rgba(0, 0, 0, 0.03);
    --shadow-inner: inset 0 2px 4px 0 rgba(0, 0, 0, 0.06);

    /* Animation Tokens */
    --transition-fast: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-base: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.fade-in {
    animation: fadeIn 0.5s ease-out forwards;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.delay-1 {
    animation-delay: 0.1s;
}

.delay-2 {
    animation-delay: 0.2s;
}

.delay-3 {
    animation-delay: 0.3s;
}

* {
    box-sizing: border-box;
}

body {
    font-family: 'Tajawal', sans-serif;
    margin: 0;
    padding: 0;
    background-color: var(--background-color);
    color: var(--text-color);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

a {
    text-decoration: none;
    color: var(--primary-color);
    transition: color 0.2s;
}

a:hover {
    color: var(--primary-hover);
}

/* =========================================
   2. TYPOGRAPHY
   ========================================= */
h1,
h2,
h3,
h4,
h5,
h6 {
    margin: 0;
    font-weight: 700;
    color: var(--text-color);
}

h1 {
    font-size: 28px;
}

h2 {
    font-size: 24px;
}

h3 {
    font-size: 20px;
}

h4 {
    font-size: 18px;
}

h5 {
    font-size: 16px;
}

p {
    margin: 0 0 10px;
}

/* =========================================
   3. BUTTONS
   ========================================= */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 20px;
    border-radius: 20px;
    /* Pill shape like app */
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
    border: none;
    transition: all 0.2s ease;
    text-align: center;
    gap: 8px;
}

.btn:active {
    transform: scale(0.98);
}

.btn-primary {
    background: linear-gradient(90deg, var(--secondary-color), var(--primary-color));
    color: var(--white);
    box-shadow: 0 4px 10px rgba(255, 71, 71, 0.3);
}

.btn-primary:hover {
    box-shadow: 0 6px 15px rgba(255, 71, 71, 0.4);
    opacity: 0.95;
    color: white;
}

.btn-secondary {
    background: var(--white);
    color: var(--text-color);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background: #f9f9f9;
    border-color: #d1d1d1;
    color: var(--text-color);
}

.btn-success {
    background: var(--success-color);
    color: var(--white);
}

.btn-danger {
    background: linear-gradient(90deg, #ff6b6b, #ff4747);
    color: var(--white);
    box-shadow: 0 4px 10px rgba(255, 71, 71, 0.2);
}

.btn-danger:hover {
    opacity: 0.9;
    color: white;
}

.btn-sm {
    padding: 6px 14px;
    font-size: 12px;
}

.btn-block {
    width: 100%;
    display: flex;
}

/* =========================================
   4. FORMS
   ========================================= */
.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: var(--text-color);
    font-size: 13px;
}

.form-control {
    width: 100%;
    padding: 12px 15px;
    font-size: 14px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background-color: var(--white);
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
}

.form-control:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(255, 71, 71, 0.1);
}

textarea.form-control {
    resize: vertical;
    min-height: 100px;
}

select.form-control {
    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='%23333' 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 15px center;
    background-size: 16px;
    padding-right: 40px;
}

[dir="rtl"] select.form-control {
    background-position: left 15px center;
    padding-right: 15px;
    padding-left: 40px;
}

/* =========================================
   5. LAYOUT: LOGIN
   ========================================= */
.login-page {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
}

.login-container {
    background: var(--white);
    padding: 40px;
    border-radius: 16px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.2);
    width: 100%;
    max-width: 400px;
    text-align: center;
}

.login-container h2 {
    color: var(--primary-color);
    margin-bottom: 30px;
    font-size: 28px;
}

/* =========================================
   6. LAYOUT: DASHBOARD (Sidebar & Main)
   ========================================= */
.wrapper {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 280px;
    background: var(--glass-bg);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    color: var(--sidebar-text);
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow: hidden;
    border-right: 1px solid var(--glass-border);
    transition: all var(--transition-base);
}

.sidebar-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--sidebar-border);
}

.sidebar-header .brand {
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--primary-color);
}

.sidebar-header .brand i {
    font-size: 28px;
    background: var(--brand-gradient);
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.sidebar-header .brand span {
    font-size: 20px;
    font-weight: 800;
    letter-spacing: -0.5px;
}

.sidebar-content {
    flex: 1;
    overflow-y: auto;
    padding: 15px 12px;
}

.sidebar-scroll {
    display: flex;
    flex-direction: column;
    gap: 2px;
    /* Smaller gap for a continuous list */
}

/* Group labels removed */

.sidebar a {
    display: flex;
    align-items: center;
    padding: 8px 12px;
    color: var(--sidebar-text);
    border-radius: 8px;
    font-weight: 500;
    font-size: 13.5px;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    gap: 10px;
    position: relative;
}

.sidebar a i {
    font-size: 20px;
    transition: transform 0.2s ease;
}

.sidebar a:hover {
    background: var(--sidebar-active);
    color: var(--primary-color);
}

.sidebar a:hover i {
    transform: translateX(3px);
}

.sidebar a.active {
    background: var(--brand-gradient);
    color: var(--white);
    box-shadow: 0 4px 12px rgba(255, 71, 71, 0.2);
}

.sidebar a.active i {
    color: var(--white);
}

/* Sidebar Footer */
.sidebar-footer {
    padding: 16px;
    background: #FAFAFA;
    border-top: 1px solid var(--sidebar-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
    min-width: 0;
}

.user-avatar {
    width: 36px;
    height: 36px;
    background: var(--brand-gradient);
    color: white;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 14px;
    flex-shrink: 0;
}

.user-details {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.user-details .username {
    font-weight: 600;
    font-size: 13px;
    color: var(--text-color);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-details .user-role {
    font-size: 11px;
    color: var(--text-muted);
}

.logout-link {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-light);
    border-radius: 8px;
    transition: all 0.2s;
    font-size: 20px;
}

.logout-link:hover {
    background: var(--danger-bg);
    color: var(--danger-color);
}

.main-content {
    flex: 1;
    padding: 30px;
    background-color: var(--background-color);
    overflow-x: hidden;
    animation: fadeIn 0.6s ease-out;
}

/* Header inside Main Content */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--white);
    padding: 20px 30px;
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-sm);
    margin-bottom: 30px;
}

.header h2 {
    font-size: 22px;
    color: var(--text-color);
}

.header-time {
    color: var(--text-light);
    font-size: 14px;
    font-weight: 500;
}

/* =========================================
   7. CARDS & CONTAINERS
   ========================================= */
.card {
    background: var(--white);
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-soft);
    border: 1px solid var(--border-color);
    margin-bottom: 25px;
    overflow: hidden;
    transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}

.card:hover {
    box-shadow: 0 15px 35px -5px rgba(0, 0, 0, 0.08);
}

.card-header {
    padding: 20px 25px;
    border-bottom: 1px solid var(--border-color);
    background: var(--white);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.card-body {
    padding: 25px;
}

.card-title {
    margin: 0;
    font-size: 18px;
    font-weight: 700;
}

/* Product Grid Cards */
.grid-products {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 20px;
}

.product-card {
    background: var(--white);
    border-radius: var(--border-radius);
    padding: 15px;
    text-align: center;
    box-shadow: var(--shadow-sm);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    border: 1px solid transparent;
}

.product-card:hover {
    transform: translateY(-5px);
    box-shadow: var(--shadow-lg);
    border-color: var(--primary-color);
}

/* =========================================
   8. TABLES
   ========================================= */
.table-responsive {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    white-space: nowrap;
}

th {
    background-color: #f8f9fa;
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
    font-size: 12px;
    padding: 16px;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

td {
    padding: 16px;
    vertical-align: middle;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-color);
    font-size: 14px;
}

tr:last-child td {
    border-bottom: none;
}

tr:hover td {
    background-color: #fafbfc;
}

/* =========================================
   9. BADGES & ALERTS
   ========================================= */
.badge {
    padding: 6px 10px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
}

.badge-success {
    background: var(--success-bg);
    color: var(--success-color);
}

.badge-danger {
    background: var(--danger-bg);
    color: var(--danger-color);
}

.badge-warning {
    background: var(--warning-bg);
    color: var(--warning-color);
}

.badge-info {
    background: var(--info-bg);
    color: var(--info-color);
}

.alert {
    padding: 15px 20px;
    border-radius: 8px;
    margin-bottom: 20px;
    font-weight: 500;
    display: flex;
    align-items: center;
}

.alert-success {
    background: var(--success-bg);
    color: var(--success-color);
    border: 1px solid rgba(0, 191, 99, 0.1);
}

.alert-danger {
    background: var(--danger-bg);
    color: var(--primary-color);
    border: 1px solid rgba(255, 71, 71, 0.1);
}

/* =========================================
   10. UTILITIES
   ========================================= */
.d-flex {
    display: flex;
}

.flex-column {
    flex-direction: column;
}

.align-center {
    align-items: center;
}

.justify-between {
    justify-content: space-between;
}

.justify-center {
    justify-content: center;
}

.gap-10 {
    gap: 10px;
}

.gap-20 {
    gap: 20px;
}

.flex-1 {
    flex: 1;
}

.w-100 {
    width: 100%;
}

.text-center {
    text-align: center;
}

.text-right {
    text-align: right;
}

.text-bold {
    font-weight: 700;
}

.text-muted {
    color: var(--text-muted);
}

.text-primary {
    color: var(--primary-color);
}

.mt-10 {
    margin-top: 10px;
}

.mt-20 {
    margin-top: 20px;
}

.mb-10 {
    margin-bottom: 10px;
}

.mb-20 {
    margin-bottom: 20px;
}

/* Scrollbar Styling */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: #bbb;
}

/* =========================================
   11. MEDIA QUERIES (Mobile Responsiveness)
   ========================================= */
@media (max-width: 768px) {

    /* Hamburger Menu Button */
    .btn-menu {
        display: flex !important;
        background: transparent;
        border: none;
        color: var(--text-color);
        cursor: pointer;
        padding: 5px;
        margin-left: 15px;
    }

    [dir="rtl"] .btn-menu {
        margin-left: 0;
        margin-right: 15px;
    }

    /* Utilities Addition */
    .flex-2 {
        flex: 2;
    }

    .p-20 {
        padding: 20px;
    }

    .mb-0 {
        margin-bottom: 0;
    }

    /* GENERIC MOBILE FIXES */
    /* Stack flex containers in forms/cards by default on mobile to prevent squeezing */
    form .d-flex,
    .card .d-flex:not(.btn-group) {
        flex-direction: column;
        gap: 15px !important;
    }

    /* Ensure tables scroll even if they lack the .table-responsive wrapper */
    table {
        display: block;
        overflow-x: auto;
        white-space: nowrap;
        width: 100%;
    }

    /* Layout Adjustments */
    .wrapper {
        flex-direction: column;
        position: relative;
    }

    .sidebar {
        width: 280px;
        height: 100vh;
        position: fixed;
        top: 0;
        left: 0;
        z-index: 1000;
        flex-direction: column;
        align-items: stretch;
        background: var(--sidebar-bg);
        border-right: none;
        transform: translateX(-100%);
        transition: transform 0.3s cubic-bezier(0.4, 0.0, 0.2, 1);
        padding: 0;
        box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
    }

    [dir="rtl"] .sidebar {
        left: auto;
        right: 0;
        transform: translateX(100%);
        box-shadow: -2px 0 10px rgba(0, 0, 0, 0.1);
    }

    .sidebar-open .sidebar {
        transform: translateX(0);
    }

    .sidebar-overlay {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0, 0, 0, 0.5);
        z-index: 999;
        display: none;
        opacity: 0;
        transition: opacity 0.3s;
    }

    .sidebar-overlay.active {
        display: block;
        opacity: 1;
    }

    .sidebar-header {
        border-bottom: 1px solid var(--sidebar-border);
        margin-bottom: 0;
        /* Reset margin */
    }

    .sidebar-content {
        padding: 10px;
        width: 100%;
        overflow-y: auto;
    }

    .sidebar-scroll {
        flex-direction: column;
        gap: 15px;
        /* Slightly tighter on mobile */
        padding-bottom: 20px;
    }

    .sidebar a {
        padding: 12px 15px;
        font-size: 14px;
        background: transparent;
    }

    .sidebar a.active {
        background: var(--brand-gradient);
        color: var(--white);
    }

    .main-content {
        padding: 15px;
        width: 100%;
    }

    /* Header */
    .header {
        flex-direction: row;
        /* Keep row for hamburger + title */
        gap: 10px;
        align-items: center;
        padding: 15px;
        margin-bottom: 20px;
    }

    .header h2 {
        font-size: 20px;
    }

    .header-time {
        display: none; /* Hide time on mobile to save space */
    }

    /* Cards */
    .card-header {
        padding: 15px;
        flex-direction: column;
        gap: 10px;
        align-items: flex-start;
    }

    .card-body {
        padding: 15px;
    }

    /* Forms */
    .form-group {
        margin-bottom: 15px;
    }

    /* Login Page */
    .login-container {
        width: 95%;
        padding: 25px;
    }

    /* Typography */
    h1 { font-size: 22px; }
    h2 { font-size: 18px; }
    h3 { font-size: 16px; }

    /* Tables */
    .table-responsive {
        border: 1px solid var(--border-color);
        border-radius: 8px;
    }

    th,
    td {
        padding: 10px;
        font-size: 12px;
    }

    /* Buttons */
    .btn {
        width: 100%;
        /* Full width buttons for better touch targets */
        margin-bottom: 8px;
        justify-content: center;
        padding: 12px;
    }

    .btn-sm {
        width: auto;
        display: inline-flex;
    }

    /* Product Grid */
    .grid-products {
        grid-template-columns: repeat(2, 1fr);
        /* 2 columns on mobile like AliExpress */
        gap: 10px;
    }

    .product-card {
        padding: 10px;
    }

    /* POS Mobile Fixes */
    .pos-container {
        flex-direction: column !important;
        height: auto !important;
        gap: 15px !important;
        overflow: visible !important;
    }

    .pos-left {
        flex: none !important;
        order: 2;
        padding-right: 0 !important;
        overflow-y: visible !important;
    }

    .pos-right {
        flex: none !important;
        order: 1;
        position: sticky;
        top: 10px;
        z-index: 100;
        max-height: none !important;
        box-shadow: var(--shadow-md);
        background: white;
    }

    .cart-body {
        max-height: 200px;
        border-bottom: 1px solid var(--border-color);
    }

    .pos-grid {
        grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)) !important;
        gap: 12px !important;
    }

    .pos-card img {
        height: 100px !important;
    }

    .pos-card .p-name {
        font-size: 12px !important;
        height: 34px !important;
    }

    .pos-card .p-price {
        font-size: 14px !important;
    }

    .category-tabs {
        padding: 10px 0;
        margin-bottom: 5px;
    }

    .cat-btn {
        padding: 8px 16px !important;
        font-size: 13px !important;
    }

    /* Search bar on mobile */
    #productSearch {
        padding: 12px !important;
        font-size: 15px !important;
    }
}

@media (max-width: 480px) {
    .grid-products {
        grid-template-columns: 1fr;
        /* 1 column on very small screens */
    }

    .pos-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }
}
