/* Responsive CSS for Smart Pharmacy */

@media (max-width: 992px) {
    .sidebar {
        position: fixed;
        right: -280px;
        top: 0;
        height: 100vh !important;
        overflow-y: auto !important;
        z-index: 10000;
        transition: right 0.4s cubic-bezier(0.4, 0, 0.2, 1);
        box-shadow: -5px 0 20px rgba(0,0,0,0.1);
        animation: slideOutRight 0.4s ease-out;
        padding-bottom: 100px !important; /* مساحة للقائمة السفلية ولتجنب القطع */
        background: var(--primary-color) !important;
    }

    /* تحسين التنقل داخل الجانب */
    .sidebar .menu {
        overflow-y: visible !important;
        height: auto !important;
    }

    .sidebar-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0,0,0,0.5);
        z-index: 9999;
        backdrop-filter: blur(2px);
    }

    .sidebar-overlay.active {
        display: block;
    }

    .sidebar-header {
        margin-bottom: 25px !important;
        justify-content: space-between;
    }

    .close-sidebar {
        display: flex !important;
        color: white;
        font-size: 1.2rem;
        cursor: pointer;
    }

    @keyframes slideOutRight {
        from {
            right: 0;
        }
        to {
            right: -280px;
        }
    }

    .sidebar.active {
        right: 0;
        animation: slideInRight 0.4s ease-out;
    }

    @keyframes slideInRight {
        from {
            right: -280px;
            opacity: 0;
        }
        to {
            right: 0;
            opacity: 1;
        }
    }

    .main-content {
        width: 100% !important;
        padding: 15px !important;
        padding-bottom: 80px !important;
    }
    .top-header {
        padding: 10px 15px;
    }
    .user-profile span {
        display: none;
    }
}

@media (max-width: 768px) {
    .stats-grid {
        grid-template-columns: 1fr 1fr !important;
        gap: 10px !important;
    }
    .stat-card {
        padding: 15px !important;
    }
    .stat-card p {
        font-size: 1.4rem !important;
    }

    /* تحويل الجداول إلى بطاقات */
    .inventory-table table, 
    .inventory-table thead, 
    .inventory-table tbody, 
    .inventory-table th, 
    .inventory-table td, 
    .inventory-table tr {
        display: block;
    }
    .inventory-table thead tr {
        position: absolute;
        top: -9999px;
        right: -9999px;
    }
    .inventory-table tr {
        margin-bottom: 15px;
        border: 1px solid #eee;
        border-radius: 12px;
        padding: 10px;
        background: var(--white);
        box-shadow: var(--shadow);
    }
    .inventory-table td {
        border: none;
        border-bottom: 1px solid #f8f9fa;
        position: relative;
        padding-right: 45% !important;
        text-align: left !important;
        min-height: 40px;
        display: flex;
        align-items: center;
        justify-content: flex-end;
    }
    .inventory-table td::before {
        content: attr(data-label);
        position: absolute;
        right: 10px;
        width: 40%;
        font-weight: bold;
        text-align: right;
        color: #636e72;
        font-size: 0.8rem;
    }
    .inventory-table td:last-child { border-bottom: 0; }

    /* تحسين الأزرار للجوال */
    .header-actions {
        flex-direction: column !important;
        width: 100% !important;
        gap: 10px !important;
    }

    .header-actions button {
        width: 100% !important;
        margin: 0 !important;
    }

    /* Modal Optimization */
    #medModal .stat-card, 
    .invoice-content, 
    .tracking-content, 
    #chatModal .stat-card {
        width: 95% !important;
        padding: 15px !important;
        max-height: 90vh !important;
        overflow-y: auto !important;
        margin: 10px !important;
    }

    .invoice-content {
        padding: 30px 15px !important;
    }

    .invoice-content h1 {
        font-size: 1.5rem !important;
    }

    .invoice-content table th, 
    .invoice-content table td {
        padding: 8px !important;
        font-size: 0.8rem !important;
    }

    .invoice-content .invoice-grid {
        grid-template-columns: 1fr !important;
        gap: 20px !important;
    }

    #chatModal .stat-card {
        height: 80vh !important;
    }

    #medModal form {
        grid-template-columns: 1fr !important;
        gap: 10px !important;
    }

    #medModal form div {
        grid-column: span 1 !important;
    }
    .btn-login, .btn-action {
        padding: 12px 15px;
    }

    /* --- تحسينات حساب الصيدلي الجديدة --- */
    
    /* 1. لوحة التحكم */
    .dashboard-grid {
        grid-template-columns: 1fr !important;
        gap: 20px !important;
    }
    
    .stats-grid {
        grid-template-columns: 1fr 1fr !important;
        gap: 12px !important;
    }
    .stats-grid > div:first-child {
        grid-column: span 2; 
    }
    
    .stat-card p {
        font-size: 1.5rem !important;
    }

    .quick-actions-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 12px !important;
    }
    
    .quick-actions-grid a {
        padding: 15px !important;
    }
    
    .quick-actions-grid i {
        font-size: 1.2rem !important;
    }
    
    .quick-actions-grid span {
        font-size: 0.85rem !important;
    }

    /* 2. شاشة الكاشير (POS) */
    .pos-container {
        grid-template-columns: 1fr !important; /* عمود واحد فقط */
        height: auto !important;
        padding-bottom: 100px;
    }
    
    .pos-bill {
        position: fixed;
        bottom: 70px;
        left: 0;
        width: 100%;
        height: 80vh;
        z-index: 1001;
        transform: translateY(110%);
        transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
        border-radius: 25px 25px 0 0 !important;
        box-shadow: 0 -10px 30px rgba(0,0,0,0.2) !important;
    }
    
    .pos-bill.active {
        transform: translateY(0);
    }
    
    .pos-fab, #mobileCartFab {
        display: flex !important;
        position: fixed;
        bottom: 85px;
        left: 20px;
        width: 65px;
        height: 65px;
        background: #e67e22; /* لون برتقالي للسلة في المتجر */
        color: white;
        border-radius: 50%;
        align-items: center;
        justify-content: center;
        font-size: 1.5rem;
        box-shadow: 0 5px 15px rgba(0,0,0,0.3);
        z-index: 1002;
        border: none;
        cursor: pointer;
    }
    
    .pos-fab .badge, #mobileCartFab .badge {
        position: absolute;
        top: 0;
        right: 0;
        background: #e74c3c;
        min-width: 22px;
        height: 22px;
        font-size: 0.8rem;
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
        border: 2px solid white;
    }

    /* 3. الملف الشخصي */
    .store-layout {
        flex-direction: column !important;
        gap: 20px !important;
    }
    
    .store-layout > div {
        width: 100% !important;
    }
    
    .profile-form-grid {
        grid-template-columns: 1fr !important;
        gap: 15px !important;
    }

    /* 4. الطلبات والتوريد */
    .inventory-table td[data-label="الإجراءات"] {
        justify-content: center !important;
        gap: 8px !important;
        padding-top: 15px !important;
        border-top: 1px dashed #eee;
    }
    
    .timeline-step {
        gap: 10px !important;
    }
    
    .tracking-content {
        width: 95% !important;
        padding: 15px !important;
    }

    .order-status-form {
        width: 100% !important;
        justify-content: space-between !important;
    }

    .reports-stats-grid, 
    .stats-grid[style*="grid-template-columns"] {
        grid-template-columns: 1fr 1fr !important;
        gap: 12px !important;
    }

    .stats-grid[style*="repeat(4, 1fr)"],
    .stats-grid[style*="repeat(3, 1fr)"] {
        grid-template-columns: 1fr 1fr !important;
    }

    /* تحسين الجداول العامة في التقارير */
    .table-responsive {
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .table {
        width: 100%;
        min-width: 500px; /* لضمان التمرير الأفقي بدلاً من الضغط */
    }

    /* --- تحسينات حساب المورد الجديدة --- */
    .supplier-stats-grid {
        grid-template-columns: 1fr 1fr !important;
        gap: 12px !important;
    }

    .dashboard-grid {
        grid-template-columns: 1fr !important;
        gap: 15px !important;
    }

    .supplier-quick-links {
        grid-template-columns: 1fr 1fr !important;
        gap: 10px !important;
    }

    .quick-link-btn {
        padding: 15px !important;
        min-height: 100px !important;
    }

    .quick-link-btn i {
        font-size: 1.2rem !important;
    }

    .quick-link-btn span {
        font-size: 0.85rem !important;
    }

    #newOrderToast {
        right: 10px !important;
        left: 10px !important;
        bottom: 70px !important; /* فوق القائمة السفلية */
        width: auto !important;
        padding: 15px !important;
    }

    /* تحسين فلاتر المخزون للمورد */
    .filter-container {
        flex-direction: column !important;
        align-items: stretch !important;
    }

    .filter-group {
        overflow-x: auto;
        padding-bottom: 5px;
        justify-content: flex-start !important;
        -webkit-overflow-scrolling: touch;
        display: flex !important;
        gap: 10px !important;
    }

    .filter-btn {
        white-space: nowrap;
        flex-shrink: 0;
    }

    /* شريط البحث المثبت */
    .sticky-search {
        position: sticky;
        top: 60px;
        z-index: 900;
        background: var(--bg-color);
        padding: 10px 0;
    }

    /* تحسينات عامة */
    .hide-on-mobile { display: none !important; }
    
    input, select, textarea { font-size: 16px !important; } /* يمنع الزووم في آيفون */

    /* شريط التنقل السفلي */
    .mobile-bottom-nav {
        display: flex !important;
        position: fixed;
        bottom: 0;
        left: 0;
        width: 100%;
        background: white;
        height: 65px;
        box-shadow: 0 -2px 15px rgba(0,0,0,0.1);
        z-index: 9999;
        justify-content: space-around;
        align-items: center;
        padding: 0 10px;
        border-top-left-radius: 20px;
        border-top-right-radius: 20px;
        animation: slideUp 0.4s ease-out;
    }

    @keyframes slideUp {
        from {
            transform: translateY(100%);
            opacity: 0;
        }
        to {
            transform: translateY(0);
            opacity: 1;
        }
    }

    .mobile-nav-item {
        display: flex;
        flex-direction: column;
        align-items: center;
        text-decoration: none;
        color: #888;
        font-size: 0.7rem;
        gap: 4px;
        transition: all 0.3s ease;
        position: relative;
        padding: 8px 12px;
        border-radius: 12px;
    }

    .mobile-nav-item:hover {
        color: var(--primary-color);
        background: rgba(0, 0, 0, 0.03);
        transform: scale(1.1);
    }

    .mobile-nav-item.active {
        color: var(--primary-color);
        background: rgba(0, 98, 102, 0.1);
        animation: navPulse 0.6s ease;
    }

    @keyframes navPulse {
        0%, 100% { transform: scale(1); }
        50% { transform: scale(1.05); }
    }

    .mobile-nav-item i {
        font-size: 1.3rem;
        transition: transform 0.3s ease;
    }

    .mobile-nav-item:hover i {
        transform: scale(1.2) rotate(5deg);
    }

    .mobile-nav-item.active i {
        animation: iconBounce 0.6s ease;
    }

    @keyframes iconBounce {
        0%, 100% { transform: translateY(0); }
        50% { transform: translateY(-5px); }
    }

    /* القائمة الجانبية في الجوال */
    .mobile-hamburger {
        display: flex !important;
        align-items: center;
        justify-content: center;
        width: 40px;
        height: 40px;
        background: #f8f9fa;
        border-radius: 10px;
        cursor: pointer;
        transition: all 0.3s ease;
        position: relative;
        overflow: hidden;
    }

    .mobile-hamburger:hover {
        background: #e8e9eb;
        transform: scale(1.05);
    }

    .mobile-hamburger i {
        transition: transform 0.3s ease;
    }

    .mobile-hamburger:hover i {
        transform: rotate(90deg);
    }
    
    body.dark-mode .mobile-bottom-nav {
        background: #1e272e;
        border-top: 1px solid #2d3436;
    }

    body.dark-mode .mobile-hamburger {
        background: #2d3436;
        color: white;
    }

    body.dark-mode .mobile-hamburger:hover {
        background: #3d4446;
    }

    body.dark-mode .mobile-nav-item {
        color: #a4b0be;
    }

    body.dark-mode .mobile-nav-item.active {
        color: var(--primary-color);
        background: rgba(0, 98, 102, 0.2);
    }
}

/* Default hidden elements */
.mobile-bottom-nav, .mobile-hamburger { display: none; }

/* --- تحسينات صفحة تسجيل الدخول والإنشاء للجوال --- */
@media (max-width: 500px) {
    .login-container {
        padding: 15px !important;
        align-items: center !important;
        display: flex !important;
        min-height: 100vh !important;
    }
    
    .login-card {
        width: 100% !important;
        max-width: 400px !important;
        padding: 30px 20px !important;
        border-radius: 25px !important;
        box-shadow: 0 15px 35px rgba(0,0,0,0.2) !important;
    }
    
    .login-card .logo i {
        font-size: 2.5rem !important;
    }
    
    .login-card h1 {
        font-size: 1.6rem !important;
    }
    
    .login-card p {
        font-size: 0.9rem !important;
        margin-bottom: 20px !important;
    }
    
    .input-group label {
        font-size: 0.9rem !important;
    }
    
    .btn-login {
        height: 50px !important;
        font-size: 1rem !important;
        margin-top: 10px !important;
    }
}

@media (max-width: 400px) {
    .login-card {
        padding: 25px 15px !important;
    }
    
    .login-card h1 {
        font-size: 1.4rem !important;
    }
}
