/* ========================================
   ALL-IN MOBILE-FIRST LAYOUT CSS
   ======================================== */

:root {
    --primary-dark: #1e3a5f;
    --primary-blue: #3b82f6;
    --light-blue: #60a5fa;
    --glass-blue: #e0f2fe;
    --dark: #0f172a;
    --gray: #64748b;
    --white: #ffffff;
    --bottom-nav-height: 65px;
}

* { 
    margin: 0; 
    padding: 0; 
    box-sizing: border-box; 
    font-family: 'Cairo', sans-serif; 
}

body {
    background: linear-gradient(135deg, #f0f9ff 0%, #f5f3ff 50%, #dbeafe 100%);
    min-height: 100vh;
    direction: rtl;
}

/* ========== TOP HEADER ========== */
.top-header {
    background: linear-gradient(135deg, var(--dark) 0%, var(--primary-dark) 100%);
    height: 56px;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1001;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 12px;
    gap: 8px;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.menu-toggle {
    background: rgba(255,255,255,0.1);
    border: none;
    color: white;
    font-size: 1.4rem;
    cursor: pointer;
    padding: 10px 12px;
    border-radius: 10px;
    transition: all 0.3s;
}

.menu-toggle:hover, 
.menu-toggle:active {
    background: rgba(255,255,255,0.2);
}

.header-logo-text {
    color: white;
    font-weight: 800;
    font-size: 1.3rem;
}

/* Mobile header - centered logo */
@media (max-width: 991px) {
    .top-header {
        justify-content: space-between;
    }
    
    .header-logo-text {
        position: absolute;
        left: 50%;
        transform: translateX(-50%);
        font-size: 1.4rem;
    }
}

/* Header Stats - DESKTOP */
.header-stats {
    display: flex;
    gap: 6px;
    flex-wrap: nowrap;
}

.stat-item {
    display: flex;
    align-items: center;
    gap: 4px;
    color: white;
    font-size: 0.8rem;
    text-decoration: none;
    padding: 6px 10px;
    background: rgba(255,255,255,0.1);
    border-radius: 20px;
    transition: all 0.2s;
    white-space: nowrap;
}

.stat-item:hover, 
.stat-item:active {
    background: rgba(255,255,255,0.2);
    color: white;
}

.stat-item i {
    font-size: 1rem;
}

.stat-item .count {
    background: rgba(255,255,255,0.3);
    padding: 2px 8px;
    border-radius: 12px;
    font-weight: 700;
    font-size: 0.75rem;
    min-width: 24px;
    text-align: center;
}

.stat-item .count.green { background: #22c55e; }
.stat-item .count.red { background: #ef4444; }
.stat-item .count.orange { background: #f59e0b; }

/* ========== MOBILE STATS BAR (Cubes) ========== */
.mobile-stats-bar {
    display: none;
    position: fixed;
    top: 52px;
    left: 0;
    right: 0;
    z-index: 1000;
    background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
    padding: 8px 10px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.08);
    border-bottom: 1px solid #e2e8f0;
}

.mobile-stats-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 8px;
}

.mobile-stat-cube {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 10px 5px;
    border-radius: 12px;
    text-decoration: none;
    transition: all 0.2s;
    min-height: 60px;
}

.mobile-stat-cube.blue {
    background: linear-gradient(135deg, #3b82f6, #2563eb);
    color: white;
}

.mobile-stat-cube.green {
    background: linear-gradient(135deg, #22c55e, #16a34a);
    color: white;
}

.mobile-stat-cube.orange {
    background: linear-gradient(135deg, #f59e0b, #d97706);
    color: white;
}

.mobile-stat-cube.red {
    background: linear-gradient(135deg, #ef4444, #dc2626);
    color: white;
}

.mobile-stat-cube.purple {
    background: linear-gradient(135deg, #8b5cf6, #7c3aed);
    color: white;
}

.mobile-stat-cube:active {
    transform: scale(0.95);
}

.mobile-stat-cube i {
    font-size: 1.3rem;
    margin-bottom: 4px;
}

.mobile-stat-cube .cube-value {
    font-size: 1rem;
    font-weight: 800;
}

.mobile-stat-cube .cube-label {
    font-size: 0.6rem;
    opacity: 0.9;
    margin-top: 2px;
}

/* ========== FULL SCREEN MOBILE MENU ========== */
.mobile-menu-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 2000;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s;
}

.mobile-menu-overlay.active {
    opacity: 1;
    visibility: visible;
}

.mobile-menu {
    position: fixed;
    top: 0;
    right: -100%;
    width: 85%;
    max-width: 320px;
    height: 100vh;
    background: linear-gradient(180deg, #f8fafc 0%, #ffffff 100%);
    z-index: 2001;
    transition: right 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.mobile-menu.active {
    right: 0;
}

.mobile-menu-header {
    background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary-blue) 100%);
    padding: 20px;
    text-align: center;
    color: white;
    position: relative;
}

.mobile-menu-close {
    position: absolute;
    top: 15px;
    left: 15px;
    background: rgba(255,255,255,0.2);
    border: none;
    color: white;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    font-size: 1.2rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.mobile-menu-logo {
    width: 100px;
    height: 100px;
    margin: 0 auto 15px;
    border-radius: 20px;
    overflow: hidden;
    border: 4px solid rgba(255,255,255,0.3);
    box-shadow: 0 8px 25px rgba(0,0,0,0.2);
}

.mobile-menu-logo img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.mobile-menu-user-name {
    font-size: 1.2rem;
    font-weight: 700;
    margin-bottom: 5px;
}

.mobile-menu-user-role {
    font-size: 0.85rem;
    opacity: 0.9;
}

.mobile-menu-balance {
    background: rgba(255,255,255,0.2);
    padding: 8px 20px;
    border-radius: 20px;
    display: inline-block;
    margin-top: 10px;
    font-weight: 700;
}

.mobile-menu-nav {
    flex: 1;
    overflow-y: auto;
    padding: 15px;
}

.mobile-nav-section {
    margin-bottom: 15px;
}

.mobile-nav-title {
    font-size: 0.75rem;
    font-weight: 700;
    color: #94a3b8;
    text-transform: uppercase;
    padding: 10px 15px 5px;
    letter-spacing: 0.5px;
}

.mobile-nav-item {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 14px 15px;
    color: #475569;
    text-decoration: none;
    border-radius: 12px;
    margin-bottom: 4px;
    transition: all 0.2s;
    font-size: 0.95rem;
}

.mobile-nav-item:hover, 
.mobile-nav-item:active {
    background: linear-gradient(135deg, #e0f2fe, #dbeafe);
    color: var(--primary-blue);
}

.mobile-nav-item.active {
    background: linear-gradient(135deg, var(--primary-blue), #2563eb);
    color: white;
}

.mobile-nav-item i {
    width: 24px;
    font-size: 1.1rem;
    text-align: center;
}

.mobile-nav-item.logout {
    color: #ef4444;
}

.mobile-nav-item.logout:hover {
    background: #fee2e2;
}

/* ========== DESKTOP SIDEBAR ========== */
.sidebar {
    position: fixed;
    top: 56px;
    right: 0;
    width: 260px;
    height: calc(100vh - 56px);
    background: linear-gradient(180deg, #f8fafc 0%, #f1f5f9 100%);
    box-shadow: -4px 0 15px rgba(0,0,0,0.08);
    z-index: 1000;
    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    border-right: 1px solid #e2e8f0;
}

.sidebar-logo {
    padding: 15px 20px;
    text-align: center;
    border-bottom: 1px solid #e2e8f0;
    background: linear-gradient(135deg, #f0f9ff 0%, #f5f3ff 50%, #dbeafe 100%);
    flex-shrink: 0;
}

.logo-wrapper {
    width: 140px;
    height: 140px;
    margin: 0 auto;
    border-radius: 16px;
    padding: 5px;
    background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary-blue) 100%);
    box-shadow: 0 8px 25px rgba(59, 130, 246, 0.3);
    transition: all 0.3s;
}

.logo-wrapper.logo-admin {
    width: 160px;
    height: 160px;
}

.logo-wrapper img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 12px;
    border: 3px solid white;
}

.logo-text {
    font-size: 1.4rem;
    font-weight: 800;
    color: var(--primary-dark);
    margin-top: 12px;
}

.logo-subtitle {
    font-size: 0.75rem;
    color: var(--gray);
    margin-top: 2px;
}

.sidebar-user {
    background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary-blue) 100%);
    padding: 20px;
    text-align: center;
    color: white;
    display: block;
    text-decoration: none;
    flex-shrink: 0;
}

.user-avatar {
    width: 70px;
    height: 70px;
    background: rgba(255,255,255,0.25);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 10px;
    font-size: 1.6rem;
    font-weight: 700;
    color: white;
    overflow: hidden;
}

.user-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.user-name {
    font-weight: 700;
    font-size: 1rem;
    margin-bottom: 2px;
    color: white;
}

.user-role {
    font-size: 0.75rem;
    color: white;
    opacity: 0.9;
}

.user-balance-box {
    background: rgba(255,255,255,0.2);
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 0.9rem;
    font-weight: 700;
    margin-top: 10px;
    display: inline-block;
    color: white;
}

.sidebar-nav {
    padding: 15px 10px;
    flex: 1;
    overflow-y: auto;
}

.nav-section {
    margin-bottom: 5px;
}

.nav-title {
    font-size: 0.7rem;
    font-weight: 700;
    color: #94a3b8;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 15px 15px 8px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 15px;
    color: #475569;
    text-decoration: none;
    border-radius: 10px;
    transition: all 0.2s;
    margin-bottom: 4px;
}

.nav-item:hover {
    background: linear-gradient(135deg, #f0f9ff, #f5f3ff);
    color: var(--primary-blue);
}

.nav-item.active {
    background: linear-gradient(135deg, #e0f2fe, #dbeafe);
    color: var(--primary-blue);
    font-weight: 600;
    border-right: 4px solid var(--primary-blue);
}

.nav-item i {
    width: 18px;
    text-align: center;
    font-size: 0.95rem;
}

.nav-item.logout {
    color: #ef4444;
}

.nav-divider {
    height: 1px;
    background: #e2e8f0;
    margin: 10px 15px;
}

.nav-badge {
    background: #ef4444;
    color: white;
    font-size: 0.65rem;
    padding: 2px 8px;
    border-radius: 10px;
    margin-right: auto;
}

.nav-badge.hidden {
    display: none;
}

/* ========== BOTTOM NAVIGATION ========== */
.bottom-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--bottom-nav-height);
    background: white;
    box-shadow: 0 -4px 20px rgba(0,0,0,0.1);
    z-index: 1002;
    border-top: 1px solid #e2e8f0;
}

.bottom-nav-inner {
    display: flex;
    height: 100%;
    align-items: center;
    justify-content: space-around;
    padding: 0 10px;
}

.bottom-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    color: #64748b;
    padding: 8px 12px;
    border-radius: 12px;
    transition: all 0.2s;
    min-width: 60px;
    background: none;
    border: none;
    cursor: pointer;
}

.bottom-nav-item i {
    font-size: 1.4rem;
    margin-bottom: 4px;
}

.bottom-nav-item span {
    font-size: 0.7rem;
    font-weight: 600;
}

.bottom-nav-item.active {
    color: var(--primary-blue);
    background: #e0f2fe;
}

.bottom-nav-item:hover {
    color: var(--primary-blue);
}

.bottom-nav-item.center-btn {
    background: linear-gradient(135deg, var(--primary-blue), #2563eb);
    color: white;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    margin-top: -20px;
    box-shadow: 0 4px 15px rgba(59, 130, 246, 0.4);
}

.bottom-nav-item.center-btn i {
    font-size: 1.5rem;
    margin-bottom: 0;
}

.bottom-nav-item.center-btn span {
    display: none;
}

.bottom-nav-item.center-btn:hover {
    transform: scale(1.05);
    color: white;
}

/* ========== MAIN CONTENT ========== */
.main-wrapper {
    margin-right: 260px;
    margin-top: 56px;
    min-height: calc(100vh - 56px);
    transition: margin 0.3s;
}

.main-content {
    padding: 20px;
}

/* ========== GLASS CARD ========== */
.glass-card {
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(10px);
    border-radius: 16px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.08);
    border: 1px solid rgba(255,255,255,0.5);
    padding: 20px;
    margin-bottom: 20px;
}

/* ========== GLOBAL BUTTONS ========== */
.btn-primary-custom {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 24px;
    background: linear-gradient(135deg, #3b82f6, #2563eb);
    color: white;
    border: none;
    border-radius: 12px;
    font-weight: 700;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.3s;
    box-shadow: 0 4px 15px rgba(59, 130, 246, 0.3);
    text-decoration: none;
}

.btn-primary-custom:hover {
    background: linear-gradient(135deg, #2563eb, #1d4ed8);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(59, 130, 246, 0.4);
    color: white;
}

.btn-primary-custom:active {
    transform: scale(0.98);
}

/* Floating Add Button (Mobile) */
.btn-add-floating {
    transition: all 0.3s;
}

@media (max-width: 768px) {
    .btn-add-floating {
        position: fixed !important;
        bottom: 85px !important;
        left: 20px !important;
        z-index: 999 !important;
        width: 56px !important;
        height: 56px !important;
        border-radius: 50% !important;
        padding: 0 !important;
        box-shadow: 0 4px 20px rgba(59, 130, 246, 0.5) !important;
    }
    
    .btn-add-floating span {
        display: none !important;
    }
    
    .btn-add-floating i {
        font-size: 1.4rem !important;
        margin: 0 !important;
    }
}

/* ========== PAGE HEADER ========== */
.page-header {
    margin-bottom: 25px;
}

.page-title {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--primary-dark);
    margin-bottom: 5px;
}

.page-subtitle {
    color: var(--gray);
    font-size: 0.9rem;
}

/* ========== MOBILE CARDS (for tables) ========== */
.mobile-cards {
    display: none;
}

.mobile-card {
    background: white;
    border-radius: 12px;
    padding: 15px;
    margin-bottom: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
    border: 1px solid #e2e8f0;
}

.mobile-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    padding-bottom: 10px;
    border-bottom: 1px solid #f1f5f9;
}

.mobile-card-title {
    font-weight: 700;
    font-size: 1rem;
    color: var(--primary-dark);
}

.mobile-card-row {
    display: flex;
    justify-content: space-between;
    padding: 6px 0;
    font-size: 0.9rem;
}

.mobile-card-label {
    color: #64748b;
}

.mobile-card-value {
    font-weight: 600;
    color: #1e293b;
}

.mobile-card-actions {
    display: flex;
    gap: 10px;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid #f1f5f9;
}

.mobile-card-actions .btn {
    flex: 1;
    padding: 10px;
    font-size: 0.85rem;
}

/* ========== RESPONSIVE ========== */
@media (max-width: 991px) {
    .sidebar {
        display: none !important;
    }
    
    .main-wrapper {
        margin-right: 0;
        margin-bottom: var(--bottom-nav-height);
    }
    
    .bottom-nav {
        display: block;
    }
    
    .main-content {
        padding: 15px;
        padding-bottom: calc(var(--bottom-nav-height) + 15px);
    }
    
    /* Hide header stats on mobile */
    .header-stats {
        display: none !important;
    }
    
    /* Show mobile stats cubes */
    .mobile-stats-bar {
        display: block;
    }
    
    /* Adjust main content for stats bar */
    .main-wrapper {
        margin-top: calc(52px + 76px); /* header + stats bar */
    }
}

@media (max-width: 768px) {
    .table-responsive-cards .table {
        display: none;
    }
    
    .mobile-cards {
        display: block;
    }
}

@media (max-width: 576px) {
    .top-header {
        height: 52px;
        padding: 0 10px;
        justify-content: space-between;
    }
    
    .header-logo-text {
        font-size: 1.2rem;
        flex: 1;
        text-align: center;
    }
    
    .menu-toggle {
        padding: 8px 10px;
        font-size: 1.3rem;
    }
    
    .main-wrapper {
        margin-top: calc(52px + 76px);
    }
    
    .main-content {
        padding: 10px;
    }
    
    /* Mobile stats cubes - smaller on very small screens */
    .mobile-stats-bar {
        padding: 6px 8px;
    }
    
    .mobile-stats-grid {
        gap: 6px;
    }
    
    .mobile-stat-cube {
        padding: 8px 4px;
        border-radius: 10px;
        min-height: 55px;
    }
    
    .mobile-stat-cube i {
        font-size: 1.1rem;
    }
    
    .mobile-stat-cube .cube-value {
        font-size: 0.9rem;
    }
    
    .mobile-stat-cube .cube-label {
        font-size: 0.55rem;
    }
}

/* ========== MOBILE MENU FIXES ========== */
/* Ensure mobile menu toggle is always visible on mobile */
@media (max-width: 991px) {
    .menu-toggle {
        display: flex !important;
        align-items: center;
        justify-content: center;
    }
    
    /* Make sure mobile menu is properly positioned */
    .mobile-menu {
        position: fixed !important;
        top: 0 !important;
        right: -100% !important;
        width: 85% !important;
        max-width: 320px !important;
        height: 100vh !important;
        height: 100dvh !important; /* For mobile browsers */
        z-index: 2001 !important;
        visibility: visible !important;
        opacity: 1 !important;
    }
    
    .mobile-menu.active {
        right: 0 !important;
    }
    
    /* Mobile menu overlay */
    .mobile-menu-overlay {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        z-index: 2000 !important;
    }
    
    .mobile-menu-overlay.active {
        opacity: 1 !important;
        visibility: visible !important;
    }
}

/* Fix for iOS safe areas */
@supports (padding-top: env(safe-area-inset-top)) {
    .mobile-menu-header {
        padding-top: calc(20px + env(safe-area-inset-top));
    }
    
    .bottom-nav {
        padding-bottom: env(safe-area-inset-bottom);
        height: calc(var(--bottom-nav-height) + env(safe-area-inset-bottom));
    }
}

/* Improve touch targets for mobile */
@media (max-width: 768px) {
    .menu-toggle,
    .bottom-nav-item,
    .mobile-nav-item {
        min-height: 44px;
        min-width: 44px;
    }
}
