/* ===================================
   COMPLETE RESPONSIVE SYSTEM
   نظام الاستجابة الكامل لجميع الشاشات
   =================================== */

/* ===================================
   1. BASE RESPONSIVE UTILITIES
   =================================== */

/* Container Max Width */
.container {
    width: 100%;
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 20px;
}

/* Flex Utilities */
.flex-wrap {
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
}

.flex-column-mobile {
    display: flex;
}

/* ===================================
   2. LARGE DESKTOP (> 1440px)
   =================================== */

@media (min-width: 1441px) {
    .dashboard-stats {
        grid-template-columns: repeat(5, 1fr);
    }
    
    .dashboard-grid {
        grid-template-columns: repeat(4, 1fr);
    }
    
    .products-grid {
        grid-template-columns: repeat(5, 1fr);
    }
}

/* ===================================
   3. DESKTOP (1025px - 1440px)
   =================================== */

@media (min-width: 1025px) and (max-width: 1440px) {
    .dashboard-stats {
        grid-template-columns: repeat(4, 1fr);
    }
    
    .dashboard-grid {
        grid-template-columns: repeat(3, 1fr);
    }
    
    .products-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}

/* ===================================
   4. TABLET (769px - 1024px)
   =================================== */

@media (min-width: 769px) and (max-width: 1024px) {
    /* Header */
    .page-header {
        flex-direction: row;
        align-items: center;
    }
    
    .page-header h1 {
        font-size: 22px;
    }
    
    /* Stats */
    .dashboard-stats {
        grid-template-columns: repeat(2, 1fr);
        gap: 15px;
    }
    
    .stat-card {
        padding: 15px;
    }
    
    /* Grid */
    .dashboard-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 15px;
    }
    
    .products-grid {
        grid-template-columns: repeat(3, 1fr);
    }
    
    /* Sidebar */
    #app-sidebar {
        width: 240px;
    }
    
    /* Tables */
    .table {
        font-size: 14px;
    }
    
    /* Buttons */
    .btn {
        padding: 10px 16px;
        font-size: 14px;
    }
}

/* ===================================
   5. MOBILE LARGE (481px - 768px)
   =================================== */

@media (min-width: 481px) and (max-width: 768px) {
    /* Header */
    .page-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 15px;
    }
    
    .page-header h1 {
        font-size: 20px;
    }
    
    .header-actions {
        width: 100%;
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }
    
    /* Stats */
    .dashboard-stats {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
    }
    
    .stat-card {
        padding: 12px;
    }
    
    .stat-value {
        font-size: 24px;
    }
    
    /* Grid */
    .dashboard-grid {
        grid-template-columns: 1fr;
        gap: 12px;
    }
    
    .products-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
    }
    
    /* Sidebar - Overlay */
    #app-sidebar {
        position: fixed;
        left: -280px;
        z-index: 1000;
        transition: left 0.3s;
    }
    
    #app-sidebar.open {
        left: 0;
    }
    
    /* Main Content */
    #app-main {
        margin-right: 0;
        padding: 15px;
    }
    
    /* Cards */
    .card {
        padding: 15px;
    }
    
    /* Tables */
    .table-responsive {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .table {
        min-width: 600px;
        font-size: 13px;
    }
    
    .table th,
    .table td {
        padding: 10px 8px;
    }
    
    /* Filters */
    .filters-card {
        flex-direction: column;
        gap: 10px;
    }
    
    .filters-card input,
    .filters-card select {
        width: 100%;
    }
    
    /* POS */
    .pos-container {
        flex-direction: column;
    }
    
    .pos-products,
    .pos-cart {
        width: 100%;
        max-width: 100%;
    }
    
    .pos-products {
        order: 2;
    }
    
    .pos-cart {
        order: 1;
        position: sticky;
        top: 60px;
        z-index: 100;
    }
    
    /* Modal */
    .modal-content {
        width: 90% !important;
        max-width: 90% !important;
        margin: 20px auto;
    }
    
    /* Buttons */
    .btn {
        width: 100%;
        justify-content: center;
    }
    
    .btn-group {
        flex-direction: column;
        gap: 8px;
    }
}

/* ===================================
   6. MOBILE SMALL (max-width: 480px)
   =================================== */

@media (max-width: 480px) {
    /* General */
    body {
        font-size: 14px;
    }
    
    /* Header */
    .page-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
        padding: 12px;
    }
    
    .page-header h1 {
        font-size: 18px;
    }
    
    .page-subtitle {
        font-size: 12px;
    }
    
    .header-actions {
        width: 100%;
        flex-direction: column;
        gap: 8px;
    }
    
    /* Stats */
    .dashboard-stats {
        grid-template-columns: 1fr;
        gap: 10px;
    }
    
    .stat-card {
        padding: 12px;
        flex-direction: row;
        align-items: center;
        gap: 12px;
    }
    
    .stat-icon {
        width: 50px;
        height: 50px;
        font-size: 24px;
    }
    
    .stat-value {
        font-size: 22px;
    }
    
    .stat-label {
        font-size: 12px;
    }
    
    /* Grid */
    .dashboard-grid,
    .products-grid {
        grid-template-columns: 1fr;
        gap: 10px;
    }
    
    /* Cards */
    .card,
    .dashboard-card {
        padding: 12px;
        border-radius: 8px;
    }
    
    .card-header h3 {
        font-size: 14px;
    }
    
    /* Main Content */
    #app-main {
        padding: 10px;
    }
    
    #app-content {
        padding: 10px;
    }
    
    /* Tables */
    .table {
        min-width: 500px;
        font-size: 12px;
    }
    
    .table th,
    .table td {
        padding: 8px 6px;
        white-space: nowrap;
    }
    
    /* Forms */
    .form-group {
        margin-bottom: 15px;
    }
    
    .form-control {
        padding: 10px;
        font-size: 14px;
        /* Prevent iOS zoom */
        font-size: 16px !important;
    }
    
    .form-row {
        grid-template-columns: 1fr;
        gap: 10px;
    }
    
    /* Buttons */
    .btn {
        padding: 10px 16px;
        font-size: 14px;
    }
    
    .btn i {
        font-size: 14px;
    }
    
    /* Modal */
    .modal-overlay {
        padding: 10px;
    }
    
    .modal-content {
        width: 95% !important;
        max-width: 95% !important;
        max-height: 90vh;
        overflow-y: auto;
        padding: 15px;
    }
    
    .modal-header h2 {
        font-size: 18px;
    }
    
    .modal-actions {
        flex-direction: column-reverse;
        gap: 8px;
    }
    
    .modal-actions .btn {
        width: 100%;
    }
    
    /* POS */
    .pos-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
    }
    
    .pos-product-card {
        padding: 10px;
    }
    
    .product-name {
        font-size: 12px;
    }
    
    .product-price {
        font-size: 14px;
    }
    
    /* Cart Items */
    .cart-item {
        padding: 10px;
        font-size: 13px;
    }
    
    .quantity-controls {
        gap: 6px;
    }
    
    .quantity-controls button {
        width: 28px;
        height: 28px;
        font-size: 14px;
    }
    
    /* Filters */
    .filters-card {
        flex-direction: column;
        gap: 8px;
        padding: 10px;
    }
    
    /* Search */
    #productSearch,
    #batchSearch {
        width: 100%;
        padding: 10px;
        font-size: 16px; /* Prevent iOS zoom */
    }
    
    /* Empty State */
    .empty-state i {
        font-size: 48px;
    }
    
    .empty-state p {
        font-size: 14px;
    }
    
    /* Notifications */
    .notification {
        width: 95%;
        left: 2.5%;
        right: 2.5%;
        font-size: 13px;
    }
}

/* ===================================
   7. MOBILE TINY (max-width: 360px)
   =================================== */

@media (max-width: 360px) {
    .page-header h1 {
        font-size: 16px;
    }
    
    .stat-value {
        font-size: 20px;
    }
    
    .btn {
        padding: 8px 12px;
        font-size: 13px;
    }
    
    .pos-grid {
        grid-template-columns: 1fr;
    }
    
    .table {
        min-width: 400px;
        font-size: 11px;
    }
}

/* ===================================
   8. LANDSCAPE MOBILE
   =================================== */

@media (max-height: 500px) and (orientation: landscape) {
    /* Reduce vertical padding */
    .page-header {
        padding: 8px 15px;
    }
    
    .dashboard-stats {
        grid-template-columns: repeat(4, 1fr);
    }
    
    .stat-card {
        padding: 10px;
    }
    
    /* Modal - Scrollable */
    .modal-content {
        max-height: 85vh;
        overflow-y: auto;
    }
    
    /* Ticker - Compact */
    .expiring-ticker {
        position: relative;
        top: 0;
    }
    
    .ticker-content {
        padding: 6px 0;
    }
}

/* ===================================
   9. TABLET LANDSCAPE (768px - 1024px, landscape)
   =================================== */

@media (min-width: 768px) and (max-width: 1024px) and (orientation: landscape) {
    .dashboard-stats {
        grid-template-columns: repeat(4, 1fr);
    }
    
    .dashboard-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

/* ===================================
   10. PRINT STYLES
   =================================== */

@media print {
    /* Hide UI elements */
    #app-sidebar,
    #app-header,
    .expiring-ticker,
    .header-actions,
    .filters-card,
    .btn,
    .modal-overlay,
    .notification {
        display: none !important;
    }
    
    /* Full width content */
    #app-main {
        margin: 0;
        padding: 0;
    }
    
    #app-content {
        padding: 20px;
    }
    
    /* Tables */
    .table {
        page-break-inside: avoid;
        font-size: 10pt;
    }
    
    .table th,
    .table td {
        padding: 6px;
    }
    
    /* Cards */
    .card {
        page-break-inside: avoid;
        box-shadow: none;
        border: 1px solid #ddd;
    }
    
    /* Colors */
    * {
        color: #000 !important;
        background: #fff !important;
    }
}

/* ===================================
   11. TOUCH DEVICE OPTIMIZATIONS
   =================================== */

@media (hover: none) and (pointer: coarse) {
    /* Larger touch targets */
    .btn,
    button,
    a {
        min-height: 44px;
        min-width: 44px;
    }
    
    /* Remove hover effects */
    *:hover {
        transform: none !important;
    }
    
    /* Better tap feedback */
    .btn:active,
    button:active {
        transform: scale(0.98);
        opacity: 0.8;
    }
    
    /* Smooth scrolling */
    * {
        -webkit-overflow-scrolling: touch;
    }
}

/* ===================================
   12. DARK MODE SUPPORT
   =================================== */

@media (prefers-color-scheme: dark) {
    :root {
        --bg-primary: #1F2937;
        --bg-secondary: #374151;
        --text-primary: #F3F4F6;
        --text-secondary: #9CA3AF;
    }
    
    body {
        background: var(--bg-primary);
        color: var(--text-primary);
    }
    
    .card,
    .modal-content {
        background: var(--bg-secondary);
    }
}

/* ===================================
   13. REDUCED MOTION
   =================================== */

@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* ===================================
   14. HIGH CONTRAST MODE
   =================================== */

@media (prefers-contrast: high) {
    * {
        border-width: 2px !important;
    }
    
    .btn {
        border: 3px solid currentColor !important;
        font-weight: 700 !important;
    }
    
    a {
        text-decoration: underline !important;
    }
}

/* ===================================
   15. UTILITY CLASSES
   =================================== */

/* Hide/Show on specific breakpoints */
@media (max-width: 768px) {
    .hide-mobile {
        display: none !important;
    }
    
    .show-mobile {
        display: block !important;
    }
}

@media (min-width: 769px) {
    .hide-desktop {
        display: none !important;
    }
    
    .show-desktop {
        display: block !important;
    }
}

/* Scrollable containers */
.scroll-x {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.scroll-y {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

/* Text truncate */
.truncate {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Aspect ratios */
.aspect-square {
    aspect-ratio: 1 / 1;
}

.aspect-video {
    aspect-ratio: 16 / 9;
}

/* ===================================
   16. SAFE AREAS (iOS Notch Support)
   =================================== */

@supports (padding: max(0px)) {
    body {
        padding-left: max(0px, env(safe-area-inset-left));
        padding-right: max(0px, env(safe-area-inset-right));
    }
    
    #app-header {
        padding-top: max(10px, env(safe-area-inset-top));
    }
    
    .modal-content {
        padding-bottom: max(20px, env(safe-area-inset-bottom));
    }
}

/* ===================================
   17. SPECIAL FIXES
   =================================== */

/* Fix iOS input zoom */
@supports (-webkit-touch-callout: none) {
    input[type="text"],
    input[type="number"],
    input[type="email"],
    input[type="tel"],
    input[type="date"],
    select,
    textarea {
        font-size: 16px !important;
    }
}

/* Fix Android soft keyboard */
@media screen and (max-width: 768px) {
    .keyboard-active {
        position: fixed;
        width: 100%;
    }
}

console.log('✅ Complete Responsive System Loaded');
