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

:root {
    --bg-dark: #090a0f;
    --card-bg: rgba(17, 18, 27, 0.7);
    --card-border: rgba(255, 255, 255, 0.06);
    --text-primary: #f3f4f6;
    --text-secondary: #9ca3af;
    --accent-primary: #8b5cf6;
    --accent-secondary: #3b82f6;
    --gradient-purple: linear-gradient(135deg, #8b5cf6 0%, #d946ef 100%);
    --gradient-blue: linear-gradient(135deg, #3b82f6 0%, #06b6d4 100%);
    --gradient-glow: linear-gradient(135deg, rgba(139, 92, 246, 0.1) 0%, rgba(59, 130, 246, 0.1) 100%);
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Cairo', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

body {
    background-color: var(--bg-dark);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    overflow-x: hidden;
    direction: rtl;
}

/* Sidebar Styling */
.sidebar {
    width: 260px;
    background: rgba(10, 11, 16, 0.95);
    border-left: 1px solid var(--card-border);
    display: flex;
    flex-direction: column;
    padding: 2rem 1.5rem;
    position: fixed;
    right: 0;
    left: auto;
    height: 100vh;
    z-index: 100;
}

.logo-container {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 3rem;
    padding-left: 0.5rem;
}

.logo-icon {
    width: 38px;
    height: 38px;
    background: var(--gradient-purple);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    font-weight: 700;
    color: white;
    box-shadow: 0 0 15px rgba(139, 92, 246, 0.4);
}

.logo-text {
    font-size: 1.5rem;
    font-weight: 700;
    background: var(--gradient-purple);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.nav-links {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.nav-item a {
    display: flex;
    align-items: center;
    gap: 1rem;
    color: var(--text-secondary);
    text-decoration: none;
    padding: 0.75rem 1rem;
    border-radius: 12px;
    font-weight: 500;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.nav-item a:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.03);
    transform: translateX(-4px);
}

.nav-item.active a {
    color: white;
    background: var(--gradient-purple);
    box-shadow: 0 4px 15px rgba(139, 92, 246, 0.3);
}

/* Main Content Area */
.main-wrapper {
    margin-right: 260px;
    margin-left: 0;
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.navbar {
    height: 80px;
    background: rgba(10, 11, 16, 0.6);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--card-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 2.5rem;
    position: sticky;
    top: 0;
    z-index: 90;
}

.page-title {
    font-size: 1.5rem;
    font-weight: 700;
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.user-avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: var(--gradient-blue);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    color: white;
    box-shadow: 0 0 10px rgba(59, 130, 246, 0.3);
}

.user-details {
    display: flex;
    flex-direction: column;
}

.user-name {
    font-size: 0.9rem;
    font-weight: 600;
}

.user-role {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.content-body {
    padding: 2.5rem;
    flex: 1;
}

/* Grid & Layout Utilities */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2.5rem;
}

.glass-card {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 20px;
    padding: 1.75rem;
    backdrop-filter: blur(12px);
    transition: all 0.3s ease;
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.2);
}

.glass-card:hover {
    transform: translateY(-5px);
    border-color: rgba(255, 255, 255, 0.12);
    box-shadow: 0 12px 40px 0 rgba(139, 92, 246, 0.15);
}

/* Stats Card Specific */
.stat-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.stat-info h3 {
    font-size: 0.85rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.5rem;
}

.stat-info p {
    font-size: 2rem;
    font-weight: 700;
}

.stat-icon {
    width: 50px;
    height: 50px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
}

.stat-icon.purple {
    background: rgba(139, 92, 246, 0.15);
    color: #a78bfa;
}

.stat-icon.blue {
    background: rgba(59, 130, 246, 0.15);
    color: #60a5fa;
}

.stat-icon.green {
    background: rgba(16, 185, 129, 0.15);
    color: #34d399;
}

.stat-icon.orange {
    background: rgba(245, 158, 11, 0.15);
    color: #fbbf24;
}

/* Table Design */
.table-section {
    margin-top: 1.5rem;
}

.table-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
}

.table-responsive {
    width: 100%;
    overflow-x: auto;
}

.custom-table {
    width: 100%;
    border-collapse: collapse;
    text-align: right;
}

.custom-table th {
    padding: 1rem 1.5rem;
    color: var(--text-secondary);
    font-weight: 600;
    border-bottom: 1px solid var(--card-border);
    font-size: 0.9rem;
}

.custom-table td {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.03);
    font-size: 0.95rem;
}

.custom-table tr:last-child td {
    border-bottom: none;
}

/* Status Badges */
.badge {
    padding: 0.25rem 0.75rem;
    border-radius: 50px;
    font-size: 0.75rem;
    font-weight: 600;
    display: inline-block;
}

.badge.active {
    background: rgba(16, 185, 129, 0.15);
    color: #34d399;
}

.badge.expired {
    background: rgba(239, 68, 68, 0.15);
    color: #f87171;
}

.badge.suspended {
    background: rgba(245, 158, 11, 0.15);
    color: #fbbf24;
}

.badge.success {
    background: rgba(16, 185, 129, 0.15);
    color: #34d399;
}

.badge.pending {
    background: rgba(245, 158, 11, 0.15);
    color: #fbbf24;
}

.badge.failed {
    background: rgba(239, 68, 68, 0.15);
    color: #f87171;
}

/* Button UI */
.btn {
    padding: 0.6rem 1.25rem;
    border-radius: 12px;
    font-weight: 600;
    font-size: 0.875rem;
    cursor: pointer;
    border: none;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    text-decoration: none;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.btn-primary {
    background: var(--gradient-purple);
    color: white;
    box-shadow: 0 4px 15px rgba(139, 92, 246, 0.3);
}

.btn-primary:hover {
    box-shadow: 0 6px 20px rgba(139, 92, 246, 0.5);
    transform: translateY(-2px);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--card-border);
    color: var(--text-primary);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.1);
    transform: translateY(-2px);
}

.btn-danger {
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.2);
    color: #f87171;
}

.btn-danger:hover {
    background: var(--danger);
    color: white;
    transform: translateY(-2px);
}

.action-buttons {
    display: flex;
    gap: 0.5rem;
}

/* Forms */
.form-group {
    margin-bottom: 1.5rem;
}

.form-group label {
    display: block;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}

.form-control {
    width: 100%;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--card-border);
    border-radius: 12px;
    padding: 0.75rem 1rem;
    color: white;
    font-size: 0.95rem;
    outline: none;
    transition: all 0.3s ease;
}

.form-control:focus {
    border-color: var(--accent-primary);
    box-shadow: 0 0 10px rgba(139, 92, 246, 0.2);
}

select.form-control {
    background-color: #11131e;
    color: white;
}

select.form-control option {
    background-color: #11131e;
    color: white;
}

.features-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.feature-item {
    display: flex;
    gap: 1rem;
    align-items: center;
}

.alert {
    padding: 1rem 1.5rem;
    border-radius: 12px;
    margin-bottom: 1.5rem;
    font-size: 0.95rem;
}

.alert-success {
    background: rgba(16, 185, 129, 0.1);
    border: 1px solid rgba(16, 185, 129, 0.2);
    color: #34d399;
}

.alert-danger {
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.2);
    color: #f87171;
}

/* ==========================================
   Responsive & Mobile Overhaul (RTL Support)
   ========================================== */

/* Hamburger menu button */
.sidebar-toggle {
    display: none;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--card-border);
    color: var(--text-primary);
    cursor: pointer;
    font-size: 1.25rem;
    transition: all 0.2s ease;
}

.sidebar-toggle:hover {
    background: rgba(255, 255, 255, 0.08);
}

.sidebar-toggle:active {
    transform: scale(0.95);
}

/* Sidebar Backdrop */
.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 95;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.sidebar-backdrop.show {
    display: block;
    opacity: 1;
    pointer-events: auto;
}

/* Tablet & Mobile Breakpoints */
@media (max-width: 1024px) {
    /* Hide sidebar and transform to Drawer */
    .sidebar {
        position: fixed;
        top: 0;
        right: -280px; /* Hide to the right for RTL layout */
        left: auto;
        width: 280px;
        height: 100vh;
        z-index: 100;
        box-shadow: -10px 0 30px rgba(0, 0, 0, 0.5);
        transition: right 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        background: rgba(10, 11, 16, 0.98);
        backdrop-filter: blur(20px);
    }

    .sidebar.open {
        right: 0;
    }

    /* Adjust Main Wrapper */
    .main-wrapper {
        margin-right: 0 !important;
        width: 100%;
        max-width: 100%;
    }

    /* Show hamburger menu toggle */
    .sidebar-toggle {
        display: inline-flex;
    }

    .navbar {
        padding: 0 1.5rem;
        height: 75px;
    }

    .content-body {
        padding: 1.5rem;
    }

    /* Stack forced grids vertically */
    .dashboard-main-grid {
        grid-template-columns: 1fr !important;
    }

    .reports-sections-grid {
        grid-template-columns: 1fr !important;
    }
}

/* Mobile Breakpoints */
@media (max-width: 768px) {
    .navbar {
        padding: 0 1rem;
        height: 70px;
    }

    .content-body {
        padding: 1rem;
    }

    /* Stats Grid */
    .stats-grid {
        grid-template-columns: 1fr !important;
        gap: 1rem;
        margin-bottom: 1.5rem;
    }

    /* Stack flex-aligned cards (like register status widget) vertically */
    .glass-card[style*="display: flex"],
    .glass-card[style*="display:flex"] {
        display: flex !important;
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 1.25rem !important;
    }
    
    .glass-card[style*="display: flex"] > div,
    .glass-card[style*="display:flex"] > div {
        width: 100% !important;
    }

    .glass-card[style*="display: flex"] > div:last-child,
    .glass-card[style*="display:flex"] > div:last-child {
        margin-top: 0.5rem !important;
    }

    .glass-card[style*="display: flex"] > div:last-child .btn,
    .glass-card[style*="display:flex"] > div:last-child .btn {
        width: 100% !important;
        justify-content: center !important;
    }

    /* Handle flex divs inside register status action headers */
    .glass-card[style*="display: flex"] div[style*="display: flex"],
    .glass-card[style*="display:flex"] div[style*="display: flex"] {
        display: flex !important;
        flex-direction: column !important;
        gap: 0.75rem !important;
        width: 100% !important;
    }

    .glass-card[style*="display: flex"] div[style*="display: flex"] .btn,
    .glass-card[style*="display:flex"] div[style*="display: flex"] .btn {
        width: 100% !important;
    }

    .glass-card {
        padding: 1.25rem;
        border-radius: 16px;
    }

    /* Convert Tables to Premium Cards */
    .table-responsive {
        width: 100%;
        overflow-x: visible;
    }

    .custom-table {
        display: block !important;
        width: 100% !important;
    }

    .custom-table thead {
        display: none !important;
    }

    .custom-table tbody, 
    .custom-table tr, 
    .custom-table td {
        display: block !important;
        width: 100% !important;
    }

    .custom-table tr {
        background: rgba(17, 18, 27, 0.45) !important;
        border: 1px solid var(--card-border) !important;
        border-radius: 18px !important;
        padding: 1.25rem !important;
        margin-bottom: 1.25rem !important;
        box-shadow: 0 8px 25px rgba(0, 0, 0, 0.25) !important;
        position: relative;
    }

    .custom-table td {
        display: flex !important;
        justify-content: space-between !important;
        align-items: center !important;
        padding: 0.8rem 0 !important;
        border-bottom: 1px solid rgba(255, 255, 255, 0.05) !important;
        text-align: left !important;
        font-size: 0.9rem !important;
        color: var(--text-primary) !important;
    }

    /* Read and inject headers as labels */
    .custom-table td::before {
        content: attr(data-label) !important;
        font-weight: 700 !important;
        color: var(--text-secondary) !important;
        margin-left: 1rem !important;
        text-align: right !important;
        flex-shrink: 0;
        font-size: 0.8rem !important;
    }

    .custom-table td:last-child {
        border-bottom: none !important;
        justify-content: flex-end !important;
        width: 100% !important;
        padding-top: 1rem !important;
        margin-top: 0.25rem !important;
    }

    .custom-table td strong {
        font-size: 0.95rem !important;
        color: white !important;
    }

    .custom-table td .badge {
        font-size: 0.8rem !important;
        padding: 0.35rem 0.8rem !important;
    }

    /* Adjust spacing & sizing for inputs and touch actions */
    .form-control {
        padding: 0.85rem 1rem;
        font-size: 1rem;
    }

    .btn, button, a.btn {
        min-height: 44px; /* Touch friendly minimum height target */
        padding: 0.75rem 1.25rem;
        font-size: 0.95rem;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    .action-buttons {
        width: 100% !important;
        margin-top: 0 !important;
        gap: 0.75rem !important;
        display: flex !important;
        flex-direction: row !important;
    }
    
    .action-buttons .btn,
    .action-buttons form {
        flex: 1 !important;
        width: 100% !important;
        margin: 0 !important;
    }

    .action-buttons form .btn {
        width: 100% !important;
    }

    .action-buttons .btn {
        justify-content: center !important;
        min-height: 40px !important;
        font-size: 0.875rem !important;
    }

    .table-header {
        flex-direction: column;
        align-items: stretch !important;
        gap: 1rem;
    }

    .table-header .btn {
        width: 100%;
        justify-content: center;
    }
}

/* Very Small Mobile Screens (320px - 480px) */
@media (max-width: 480px) {
    .user-profile .user-details {
        display: none !important; /* Hide user text details, keep only avatar to fit space */
    }

    .page-title {
        font-size: 1.15rem;
    }

    .stat-info p {
        font-size: 1.75rem;
    }

    .stat-card {
        padding: 1rem;
    }

    /* Modal adjustments */
    .modal-content {
        width: 95% !important;
        margin: 1rem auto !important;
        padding: 1.25rem !important;
    }
}

/* Products Page Responsive Layouts */
.mobile-products-list {
    display: none;
}
.desktop-only-table {
    display: block;
}

@media (max-width: 768px) {
    .desktop-only-table {
        display: none !important;
    }
    
    .mobile-products-list {
        display: flex !important;
        flex-direction: column;
        gap: 0.75rem;
        width: 100%;
        margin-top: 1rem;
    }
    
    .compact-product-card {
        background: rgba(255, 255, 255, 0.02);
        border: 1px solid var(--card-border);
        border-radius: 14px;
        padding: 0.75rem 1rem;
        display: flex;
        flex-direction: column;
        gap: 0.5rem;
        box-shadow: 0 4px 15px rgba(0, 0, 0, 0.15);
        transition: transform 0.2s, border-color 0.2s;
    }
    
    .compact-product-card:hover {
        transform: translateY(-2px);
        border-color: rgba(255, 255, 255, 0.1);
    }
    
    .card-main-row {
        display: flex;
        align-items: center;
        gap: 0.75rem;
        width: 100%;
    }
    
    .product-emoji-container {
        width: 44px;
        height: 44px;
        background: var(--gradient-glow);
        border: 1px solid rgba(255, 255, 255, 0.05);
        border-radius: 10px;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 1.25rem;
        flex-shrink: 0;
        box-shadow: 0 0 10px rgba(139, 92, 246, 0.1);
    }
    
    .product-core-info {
        flex: 1;
        display: flex;
        flex-direction: column;
        gap: 0.25rem;
        min-width: 0; /* allows text truncation */
    }
    
    .product-title {
        font-size: 0.95rem;
        font-weight: 700;
        color: white;
        margin: 0;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    
    .product-meta {
        display: flex;
        align-items: center;
        gap: 0.35rem;
        font-size: 0.75rem;
        color: var(--text-secondary);
    }
    
    .barcode-divider {
        color: rgba(255, 255, 255, 0.15);
    }
    
    .barcode-val {
        font-family: monospace;
        color: rgba(156, 163, 175, 0.8);
    }
    
    .product-financials {
        display: flex;
        align-items: center;
        flex-shrink: 0;
    }
    
    .price-box {
        display: flex;
        flex-direction: column;
        align-items: flex-end;
        gap: 0.15rem;
    }
    
    .sell-price {
        font-size: 0.95rem;
        font-weight: 700;
        color: #a78bfa; /* soft purple/accent */
    }
    
    .cost-price {
        font-size: 0.7rem;
        color: var(--text-secondary);
    }
    
    .card-details-row {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 1rem;
        background: rgba(255, 255, 255, 0.01);
        padding: 0.4rem 0.6rem;
        border-radius: 8px;
        border: 1px solid rgba(255, 255, 255, 0.02);
    }
    
    .stock-badge-box .badge {
        font-size: 0.75rem !important;
        padding: 0.2rem 0.5rem !important;
    }
    
    .sizes-box {
        display: flex;
        gap: 0.25rem;
        flex-wrap: wrap;
        justify-content: flex-end;
    }
    
    .size-badge {
        background: rgba(255, 255, 255, 0.03);
        border: 1px solid rgba(255, 255, 255, 0.05);
        padding: 0.15rem 0.35rem;
        border-radius: 4px;
        font-size: 0.7rem;
        color: var(--text-secondary);
    }
    
    .no-sizes {
        font-size: 0.7rem;
        color: var(--text-secondary);
    }
    
    .card-actions-row {
        display: flex;
        gap: 0.5rem;
        width: 100%;
        margin-top: 0.25rem;
        border-top: 1px solid rgba(255, 255, 255, 0.04);
        padding-top: 0.5rem;
    }
    
    .card-actions-row .btn,
    .card-actions-row form {
        flex: 1 !important;
        margin: 0 !important;
        width: 100%;
    }
    
    .card-actions-row .btn {
        min-height: 36px !important;
        font-size: 0.8rem !important;
        padding: 0.35rem !important;
        justify-content: center !important;
    }
}

@media (max-width: 480px) {
    .search-actions {
        width: 100% !important;
        display: flex !important;
        gap: 0.5rem !important;
    }
    .search-actions .btn {
        flex: 1 !important;
        width: 100% !important;
    }
}
