/**
 * Responsive Design Styles
 * Mobile-first approach with breakpoints for tablet and desktop
 * Breakpoints: Mobile (<576px), Tablet (576px-991px), Desktop (992px+)
 */

/* ========================================
   HEADER RESPONSIVE
   ======================================== */

/* Hide statistics and some items on mobile */
@media (max-width: 991.98px) {
    #statistics-container {
        display: none !important;
    }
    
    .app-navbar-item .bullet {
        display: none !important;
    }
    
    /* Stack header items on mobile */
    .app-navbar {
        flex-wrap: wrap;
        gap: 10px !important;
    }
    
    /* Make USD rate smaller on mobile */
    .app-navbar-item .d-flex.flex-column span {
        font-size: 0.8rem !important;
    }
}

/* Tablet view - show some stats */
@media (min-width: 768px) and (max-width: 991.98px) {
    #statistics-container {
        display: flex !important;
        gap: 1rem !important;
    }
    
    #statistics-container .d-flex {
        font-size: 0.85rem;
    }
}

/* ========================================
   SIDEBAR RESPONSIVE
   ======================================== */

/* Mobile sidebar should use drawer mode */
@media (max-width: 991.98px) {
    #kt_app_sidebar {
        position: fixed !important;
        left: -100% !important;
        z-index: 1000;
        transition: left 0.3s ease;
    }
    
    #kt_app_sidebar.drawer-on {
        left: 0 !important;
    }
    
    /* Hide desktop toggle button on mobile */
    .sidebar-toggle-btn {
        display: none !important;
    }
    
    /* Overlay for mobile sidebar */
    body.drawer-on::before {
        content: '';
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0, 0, 0, 0.5);
        z-index: 999;
    }
}

/* ========================================
   TABLES RESPONSIVE
   ======================================== */

@media (max-width: 767.98px) {
    /* Make tables scrollable horizontally */
    .table-responsive {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    /* Reduce table font size on mobile */
    table {
        font-size: 0.8rem !important;
    }
    
    /* Hide less important columns on mobile */
    table th:nth-child(n+6),
    table td:nth-child(n+6) {
        display: none;
    }
    
    /* Make action buttons smaller */
    .btn-sm {
        padding: 0.25rem 0.5rem;
        font-size: 0.75rem;
    }
    
    /* Stack filter inputs */
    .filter-inputs .row {
        flex-direction: column;
    }
    
    .filter-inputs .col-lg-3,
    .filter-inputs .col-lg-4,
    .filter-inputs .col-lg-6 {
        width: 100% !important;
        margin-bottom: 10px;
    }
}

/* Tablet view - show more columns */
@media (min-width: 768px) and (max-width: 991.98px) {
    table {
        font-size: 0.9rem !important;
    }
    
    /* Hide only very specific columns on tablet */
    table th:nth-child(n+8),
    table td:nth-child(n+8) {
        display: table-cell;
    }
}

/* ========================================
   FORMS RESPONSIVE
   ======================================== */

@media (max-width: 991.98px) {
    /* Stack form columns on mobile/tablet */
    .d-flex.flex-column.flex-lg-row {
        flex-direction: column !important;
    }
    
    /* Full width on mobile */
    .w-lg-75,
    .w-lg-25,
    .w-lg-400px,
    .w-lg-300px {
        width: 100% !important;
        max-width: 100% !important;
        min-width: auto !important;
    }
    
    /* Remove side margins on mobile */
    .me-lg-10 {
        margin-right: 0 !important;
    }
    
    /* Disable sticky behavior on mobile */
    [data-kt-sticky] {
        position: relative !important;
        top: auto !important;
    }
    
    /* Stack form rows */
    .row .col-lg-2,
    .row .col-lg-3,
    .row .col-lg-4,
    .row .col-lg-5,
    .row .col-lg-6,
    .row .col-lg-8,
    .row .col-lg-10,
    .row .col-lg-12 {
        width: 100% !important;
        margin-bottom: 10px;
    }
    
    /* Make input groups stack vertically */
    .input-group {
        flex-wrap: wrap;
    }
    
    .input-group .form-control {
        flex: 1 1 100%;
        margin-bottom: 5px;
    }
    
    .input-group-text,
    .input-group .btn {
        flex: 1 1 auto;
        min-width: 120px;
    }
}

/* Tablet optimizations */
@media (min-width: 768px) and (max-width: 991.98px) {
    .w-lg-75 {
        width: 100% !important;
    }
    
    .w-lg-25 {
        width: 100% !important;
    }
}

/* ========================================
   CARDS RESPONSIVE
   ======================================== */

@media (max-width: 767.98px) {
    /* Reduce card padding on mobile */
    .card-body {
        padding: 1rem !important;
    }
    
    .card-header {
        padding: 0.75rem !important;
    }
    
    /* Make card titles smaller */
    .card-title h2 {
        font-size: 1.1rem !important;
    }
    
    /* Stack card actions */
    .card .d-flex.gap-2,
    .card .d-flex.gap-3,
    .card .d-flex.gap-4 {
        flex-direction: column;
        gap: 0.5rem !important;
    }
}

/* ========================================
   BUTTONS RESPONSIVE
   ======================================== */

@media (max-width: 767.98px) {
    /* Make buttons full width on mobile */
    .btn {
        width: 100%;
        margin-bottom: 5px;
    }
    
    /* Button groups should stack */
    .d-flex.gap-2.gap-lg-3 {
        flex-direction: column;
        gap: 0.5rem !important;
    }
    
    /* Toolbar buttons */
    #kt_app_toolbar_container .d-flex.gap-2 {
        flex-direction: column;
    }
    
    #kt_app_toolbar_container .btn {
        width: 100%;
    }
}

/* Tablet - keep some buttons inline */
@media (min-width: 768px) and (max-width: 991.98px) {
    .btn {
        width: auto;
    }
}

/* ========================================
   MODALS RESPONSIVE
   ======================================== */

@media (max-width: 767.98px) {
    .modal-dialog {
        margin: 0.5rem;
        max-width: calc(100% - 1rem);
    }
    
    .modal-content {
        border-radius: 0.5rem;
    }
    
    .modal-body {
        padding: 1rem;
    }
    
    .modal-header,
    .modal-footer {
        padding: 0.75rem 1rem;
    }
}

/* ========================================
   TOOLBAR & BREADCRUMBS RESPONSIVE
   ======================================== */

@media (max-width: 767.98px) {
    /* Stack toolbar items */
    #kt_app_toolbar_container {
        flex-direction: column;
        align-items: flex-start !important;
    }
    
    .page-title {
        margin-bottom: 1rem !important;
    }
    
    /* Smaller page headings */
    .page-heading {
        font-size: 1.5rem !important;
    }
    
    /* Breadcrumbs smaller */
    .breadcrumb {
        font-size: 0.75rem !important;
    }
}

/* ========================================
   TABS RESPONSIVE
   ======================================== */

@media (max-width: 767.98px) {
    /* Make tabs scrollable */
    .nav-tabs {
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .nav-tabs .nav-link {
        white-space: nowrap;
        font-size: 0.85rem;
        padding: 0.5rem 0.75rem;
    }
}

/* ========================================
   IMAGE GALLERY RESPONSIVE
   ======================================== */

@media (max-width: 767.98px) {
    .form-check-clip {
        width: calc(50% - 0.5rem) !important;
    }
    
    .form-check-clip img {
        height: 80px !important;
        width: 80px !important;
    }
}

@media (min-width: 768px) and (max-width: 991.98px) {
    .form-check-clip {
        width: calc(33.333% - 0.5rem) !important;
    }
}

/* ========================================
   STOCK TABLE RESPONSIVE
   ======================================== */

@media (max-width: 767.98px) {
    .serial-numbers-table {
        font-size: 0.75rem;
    }
    
    .serial-numbers-table th,
    .serial-numbers-table td {
        padding: 0.5rem 0.25rem;
    }
    
    .serial-numbers-table .btn {
        padding: 0.25rem 0.5rem;
        font-size: 0.7rem;
        width: auto;
    }
}

/* ========================================
   SPACING ADJUSTMENTS
   ======================================== */

@media (max-width: 767.98px) {
    /* Reduce gaps and spacing */
    .gap-5 {
        gap: 1rem !important;
    }
    
    .gap-7 {
        gap: 1.5rem !important;
    }
    
    .gap-lg-10 {
        gap: 1.5rem !important;
    }
    
    /* Reduce margins */
    .mb-5,
    .mb-7 {
        margin-bottom: 1rem !important;
    }
    
    .mb-lg-0 {
        margin-bottom: 1rem !important;
    }
}

/* ========================================
   SELECT2 DROPDOWN RESPONSIVE
   ======================================== */

@media (max-width: 767.98px) {
    .select2-container {
        width: 100% !important;
    }
    
    .select2-dropdown {
        font-size: 0.9rem;
    }
}

/* ========================================
   DATATABLE SPECIFIC RESPONSIVE
   ======================================== */

@media (max-width: 767.98px) {
    /* DataTable controls */
    .dataTables_length,
    .dataTables_filter {
        float: none !important;
        text-align: left !important;
        margin-bottom: 10px;
    }
    
    .dataTables_info,
    .dataTables_paginate {
        float: none !important;
        text-align: center !important;
        margin-top: 10px;
    }
    
    /* Pagination */
    .pagination {
        justify-content: center;
    }
    
    .pagination .page-item .page-link {
        padding: 0.25rem 0.5rem;
        font-size: 0.8rem;
    }
}

/* ========================================
   FILTER CARD RESPONSIVE
   ======================================== */

@media (max-width: 767.98px) {
    .filter-card .card-body {
        padding: 1rem;
    }
    
    .filter-card .form-label {
        font-size: 0.85rem;
        margin-bottom: 0.25rem;
    }
    
    .filter-card .btn {
        width: 100%;
        margin-bottom: 0.5rem;
    }
}

/* ========================================
   UTILITY CLASSES
   ======================================== */

/* Hide on mobile */
@media (max-width: 767.98px) {
    .d-mobile-none {
        display: none !important;
    }
}

/* Hide on tablet */
@media (min-width: 768px) and (max-width: 991.98px) {
    .d-tablet-none {
        display: none !important;
    }
}

/* Show only on mobile */
.d-mobile-only {
    display: none !important;
}

@media (max-width: 767.98px) {
    .d-mobile-only {
        display: block !important;
    }
}

/* Full width on mobile */
@media (max-width: 767.98px) {
    .w-mobile-100 {
        width: 100% !important;
    }
}

/* ========================================
   PRINT STYLES
   ======================================== */

@media print {
    /* Hide navigation and non-essential elements */
    #kt_app_sidebar,
    #kt_app_header,
    #kt_app_toolbar,
    .sidebar-toggle-btn,
    .btn,
    .d-print-none {
        display: none !important;
    }
    
    /* Full width for content */
    .app-wrapper,
    .app-main,
    .card {
        width: 100% !important;
        margin: 0 !important;
        padding: 0 !important;
        box-shadow: none !important;
    }
    
    /* Black and white for better printing */
    body {
        background: white !important;
        color: black !important;
    }
    
    /* Page breaks */
    .card {
        page-break-inside: avoid;
    }
}

/* ========================================
   LANDSCAPE ORIENTATION (Mobile)
   ======================================== */

@media (max-width: 991.98px) and (orientation: landscape) {
    /* Reduce header height in landscape */
    #kt_app_header {
        min-height: 50px !important;
    }
    
    /* Adjust toolbar */
    #kt_app_toolbar {
        padding: 0.5rem 0 !important;
    }
    
    .page-heading {
        font-size: 1.2rem !important;
    }
}

/* ========================================
   HIGH DPI SCREENS
   ======================================== */

@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    /* Sharper borders and shadows */
    .card,
    .btn,
    .form-control {
        border-width: 0.5px;
    }
}

/* ========================================
   TOUCH DEVICE OPTIMIZATIONS
   ======================================== */

@media (hover: none) and (pointer: coarse) {
    /* Larger touch targets */
    .btn,
    .form-check-input,
    .menu-link {
        min-height: 44px;
        min-width: 44px;
    }
    
    /* Remove hover effects on touch devices */
    .btn:hover,
    .menu-link:hover {
        transform: none;
    }
    
    /* Larger form controls */
    .form-control,
    .form-select {
        min-height: 44px;
        font-size: 16px; /* Prevents zoom on iOS */
    }
}

/* ========================================
   ACCESSIBILITY IMPROVEMENTS
   ======================================== */

/* Focus states for keyboard navigation */
@media (prefers-reduced-motion: no-preference) {
    .btn:focus,
    .form-control:focus,
    .menu-link:focus {
        outline: 2px solid #667eea;
        outline-offset: 2px;
    }
}

/* Reduced motion for users who prefer it */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Dark mode adjustments for responsive elements */
@media (prefers-color-scheme: dark) {
    .table-responsive {
        scrollbar-color: #4a5568 #2d3748;
    }
}

/* ========================================
   CONTAINER QUERIES (Modern Browsers)
   ======================================== */

@container (max-width: 600px) {
    .card-body {
        padding: 0.75rem;
    }
}
