/**
 * Responsive CSS for Serge E-Commerce Management System
 * Optimized for all screen sizes with enhanced Android support
 * Bootstrap-centric approach with minimal overrides
 */

/* Variables for consistent sizing and spacing across the application */
:root {
    --touch-target-size: 44px;
    --mobile-padding: 0.75rem;
    --mobile-border-radius: 0.5rem;
}

/* Global rules for responsive design */
html, body {
    overflow-x: hidden;
    width: 100%;
    max-width: 100%;
}

/* Basic container reset */
.container, 
.container-fluid, 
[class*="container-"],
.wrapper,
.content-wrapper,
.main-content {
    width: 100% !important;
    max-width: 100% !important;
    margin: 0 !important;
    padding: 1rem !important;
    box-sizing: border-box !important;
}

/* Flexible images and media */
img, video, iframe {
    max-width: 100%;
    height: auto;
}

/* Reset Android device styles */
.android-device {
    width: 100% !important;
    max-width: 100% !important;
    overflow-x: hidden;
}

/* Simple body reset */
.android-device body {
    width: 100% !important;
    max-width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow-x: hidden;
}

/* Main content containers */
.android-device .container.py-4 {
    min-height: 100vh;
    width: 100% !important;
    max-width: 100% !important;
    margin: 0 !important;
    padding: 1rem !important;
    background: #fff;
    box-sizing: border-box !important;
}

/* Ensure proper height handling for Android fullscreen mode */
.android-fullscreen-mode {
    min-height: 100vh !important;
    height: 100vh !important;
    display: flex !important;
    flex-direction: column !important;
}

.android-fullscreen-mode .wrapper,
.android-fullscreen-mode .content-wrapper,
.android-fullscreen-mode .main-content,
.android-fullscreen-mode .page-wrapper {
    flex: 1 1 auto !important;
    min-height: 0 !important;
    height: auto !important;
    display: flex !important;
    flex-direction: column !important;
}

.android-fullscreen-mode .container,
.android-fullscreen-mode .container-fluid,
.android-fullscreen-mode [class*="container-"] {
    flex: 1 1 auto !important;
    display: flex !important;
    flex-direction: column !important;
}

/* Full screen mode for Android desktop view */
.android-desktop-mode .container,
.android-desktop-mode .navbar > .container,
.android-desktop-mode .footer > .container,
.desktop-fullwidth-mode .container,
.desktop-fullwidth-mode .navbar > .container,
.desktop-fullwidth-mode .footer > .container,
.android-fullwidth-mode .container,
.android-fullwidth-mode .navbar > .container,
.android-fullwidth-mode .footer > .container {
    max-width: 100vw !important;
    width: 100vw !important;
    padding-left: 1rem !important;
    padding-right: 1rem !important;
    margin-left: 0 !important;
    margin-right: 0 !important;
    box-sizing: border-box !important;
}

/* Compact view for Android mobile devices - make everything smaller to show more content */
.android-device.android-fullscreen-mode,
.android-device.android-minimal-ui {
    /* Remove all possible margins and borders */
    margin: 0 !important;
    padding: 0 !important;
    border: none !important;
    outline: none !important;
    
    /* Make UI more compact */
    --bs-gutter-x: 0.5rem !important;
    --bs-gutter-y: 0.25rem !important;
    --touch-target-size: 36px !important; /* Smaller touch targets */
    --mobile-padding: 0.5rem !important;
    --mobile-border-radius: 0.35rem !important;
}

/* Full width containers */
.android-device .container,
.android-device .container-fluid,
.android-device .container-sm,
.android-device .container-md,
.android-device .container-lg,
.android-device .container-xl,
.android-device .container-xxl,
.android-device .wrapper,
.android-device .content-wrapper,
.android-device .main-content,
.android-device .page-wrapper,
.android-device .site-content,
.android-device .content-area,
.android-device .main-container,
.android-device main > .container,
.android-device section > .container {
    max-width: 100vw !important;
    width: 100vw !important;
    padding-left: 1rem !important;
    padding-right: 1rem !important;
    margin-left: 0 !important;
    margin-right: 0 !important;
    box-sizing: border-box !important;
    overflow-x: hidden !important;
}

/* Compact navbar */
.android-device .navbar {
    /* Make navbar more compact */
    padding: 0.25rem 0.2rem !important;
    min-height: 40px !important;
    border-radius: 0 !important;
}

.android-device .navbar-brand {
    /* Make brand smaller */
    font-size: 0.9rem !important;
    padding: 0.1rem 0.25rem !important;
    margin-right: 0.3rem !important;
}

.android-device .nav-link {
    padding: 0.25rem 0.5rem !important;
}

/* Reduce main content padding */
.android-device .py-4 {
    padding-top: 0.35rem !important;
    padding-bottom: 0.35rem !important;
}

/* Make cards more compact */
.android-device .card {
    margin-bottom: 0.35rem !important;
}

.android-device .card-header,
.android-device .card-body,
.android-device .card-footer {
    padding: 0.5rem !important;
}

/* Make headings smaller */
.android-device h1, .android-device .h1 {
    font-size: 1.5rem !important;
}

.android-device h2, .android-device .h2 {
    font-size: 1.3rem !important;
}

.android-device h3, .android-device .h3 {
    font-size: 1.15rem !important;
}

.android-device h4, .android-device .h4 {
    font-size: 1rem !important;
}

.android-device h5, .android-device .h5 {
    font-size: 0.9rem !important;
}

.android-device h6, .android-device .h6 {
    font-size: 0.85rem !important;
}

/* Make form elements more compact */
.android-device .form-control,
.android-device .form-select,
.android-device .btn {
    padding: 0.25rem 0.5rem !important;
    font-size: 0.85rem !important;
    min-height: 32px !important;
}

.android-device .form-label {
    margin-bottom: 0.25rem !important;
    font-size: 0.85rem !important;
}

/* Make tables more compact */
.android-device .table th,
.android-device .table td {
    padding: 0.35rem !important;
    font-size: 0.85rem !important;
}

/* Apply safe area insets for notched displays */
@supports (padding: max(0px)) {
    .android-fullscreen-mode .container {
        padding-left: max(0.25rem, env(safe-area-inset-left)) !important;
        padding-right: max(0.25rem, env(safe-area-inset-right)) !important;
    }
    
    .android-fullscreen-mode .navbar {
        padding-top: max(0.5rem, env(safe-area-inset-top)) !important;
    }
    
    .android-fullscreen-mode .mobile-action-bar {
        padding-bottom: max(0.75rem, env(safe-area-inset-bottom)) !important;
    }
}

/* Prevent font size adjustment on orientation change */
.android-device body {
    text-size-adjust: 100%;
    -webkit-text-size-adjust: 100%;
    -moz-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
}

/* Optimize tap targets for compact view */
.android-device a,
.android-device button, 
.android-device .btn, 
.android-device .nav-link,
.android-device .form-control,
.android-device select,
.android-device input[type="checkbox"],
.android-device input[type="radio"] {
    min-height: 32px !important; /* Smaller touch targets */
    touch-action: manipulation;
}
/* Ensure buttons are compact */
.android-device .btn-sm {
    padding: 0.15rem 0.3rem !important;
    font-size: 0.75rem !important;
}

/* Make bootstrap columns have less padding */
.android-device .row > [class^="col-"] {
    padding-right: calc(var(--bs-gutter-x) * 0.4) !important;
    padding-left: calc(var(--bs-gutter-x) * 0.4) !important;
}

/* Compact paddings and margins */
.android-device .mb-3,
.android-device .my-3,
.android-device .m-3 {
    margin-bottom: 0.5rem !important;
}

.android-device .mt-3,
.android-device .my-3,
.android-device .m-3 {
    margin-top: 0.5rem !important;
}

.android-device .pb-3,
.android-device .py-3,
.android-device .p-3 {
    padding-bottom: 0.5rem !important;
}

.android-device .pt-3,
.android-device .py-3,
.android-device .p-3 {
    padding-top: 0.5rem !important;
}
/* Prevent input zoom on Android by ensuring at least 16px font size */
.android-device input:not([type="button"]):not([type="submit"]):not([type="reset"]),
.android-device select,
.android-device textarea {
    font-size: 16px !important;
}

/* Improve table responsiveness on Android */
.android-device .table-responsive {
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
}

/* Fix scrollbar visibility on Android */
.android-device ::-webkit-scrollbar {
    height: 6px;
    width: 6px;
    background-color: rgba(0,0,0,0.05);
}

.android-device ::-webkit-scrollbar-thumb {
    background-color: rgba(0,0,0,0.2);
    border-radius: 3px;
}

/* Optimize tables for Android devices */
.android-device .table th,
.android-device .table td {
    vertical-align: middle;
}

/* Force horizontal scrolling with minimum column width for tables */
.android-desktop-mode .table th,
.android-desktop-mode .table td {
    white-space: nowrap;
    min-width: 120px;
}

/* Override fixed widths for cards and elements in full-screen mode */
.android-desktop-mode .card,
.android-desktop-mode .col-lg-6,
.android-desktop-mode .col-md-6 {
    width: 100%;
}

/* Optimize DataTables for Android */
.android-device .dataTables_wrapper {
    width: 100%;
    overflow-x: auto;
    padding-bottom: 10px;
}

/* Button groups horizontal scrolling for overflow content */
.android-device .btn-group,
.android-device .filters-section,
.android-device .status-filters {
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    width: 100%;
    padding-bottom: 5px;
    -webkit-overflow-scrolling: touch;
}

.android-device .btn-group .btn {
    flex-shrink: 0;
    white-space: nowrap;
    margin-right: 2px;
}

/* Card optimizations for Android devices */
.android-device .card {
    width: 100%;
    word-wrap: break-word;
}

/* Scroll indicators for tables and other scrollable content */
.scroll-indicator {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(0,0,0,0.5);
    color: white;
    padding: 5px 10px;
    border-radius: 20px;
    font-size: 12px;
    pointer-events: none;
    animation: fadeInOut 2s infinite;
    z-index: 1000;
}

@keyframes fadeInOut {
    0%, 100% { opacity: 0; }
    50% { opacity: 1; }
}

/* Horizontal scrolling container with indicators */
.mobile-scroll-x {
    -webkit-overflow-scrolling: touch;
    overflow-x: auto;
    white-space: nowrap;
    padding-bottom: 0.5rem;
    position: relative;
    width: 100%;
}

/* Custom horizontal scroll indicators */
.mobile-scroll-x:before,
.mobile-scroll-x:after {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    width: 20px;
    z-index: 1;
    pointer-events: none;
}

.mobile-scroll-x:before {
    left: 0;
    background: linear-gradient(to right, rgba(255,255,255,1), rgba(255,255,255,0));
}

.mobile-scroll-x:after {
    right: 0;
    background: linear-gradient(to left, rgba(255,255,255,1), rgba(255,255,255,0));
}

/* Mobile-optimized table layout for very small screens */
@media (max-width: 480px) {
    .mobile-data-card table,
    .mobile-data-card thead,
    .mobile-data-card tbody,
    .mobile-data-card tfoot,
    .mobile-data-card tr {
        display: block;
        width: 100%;
    }
    
    .mobile-data-card th {
        display: none;
    }
    
    .mobile-data-card td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        text-align: right;
        padding: 0.5rem 0.75rem;
        border: none;
        border-bottom: 1px solid #dee2e6;
    }
    
    .mobile-data-card td:before {
        content: attr(data-label);
        font-weight: 600;
        float: left;
        text-align: left;
    }
    
    .mobile-data-card tbody tr {
        margin-bottom: 1rem;
        border: 1px solid #dee2e6;
        border-radius: var(--mobile-border-radius);
    }
}

/* Bottom fixed action bar for mobile screens */
.mobile-action-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background-color: #fff;
    padding: 0.75rem 1rem;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
    z-index: 1030;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.has-mobile-action-bar {
    padding-bottom: calc(var(--touch-target-size) + 1.5rem);
}

/* Core mobile responsive rules - ensure all containers take full width */
@media (max-width: 768px) {
    /* Full width containers with reasonable padding */
    .container, 
    .container-fluid, 
    .container-sm, 
    .container-md, 
    .container-lg, 
    .container-xl,
    .container-xxl,
    main > .container,
    section > .container,
    .card,
    .table-responsive {
        width: 100% !important;
        max-width: 100% !important;
        margin-left: 0 !important;
        margin-right: 0 !important;
        padding-left: 1rem !important;
        padding-right: 1rem !important;
        overflow-x: hidden !important;
    }
    
    /* Override any fixed-width elements */
    [style*="width"],
    [style*="max-width"] {
        width: 100% !important;
        max-width: 100% !important;
    }
    
    /* Fix Bootstrap grid spacing */
    .row {
        margin-left: -0.5rem !important;
        margin-right: -0.5rem !important;
        width: 100% !important;
    }
    
    .row > [class*="col-"] {
        padding-left: 0.5rem !important;
        padding-right: 0.5rem !important;
    }
    
    /* Prevent any horizontal scroll */
    html, body {
        overflow-x: hidden !important;
        width: 100% !important;
        max-width: 100% !important;
    }
    
    /* Improve flexbox layouts */
    .d-flex {
        flex-wrap: wrap !important;
    }
    
    /* Fix tables */
    table, .table {
        width: 100% !important;
    }
    
    /* Utility classes for mobile spacing optimizations */
    .mobile-mt-0 { margin-top: 0 !important; }
    .mobile-mb-0 { margin-bottom: 0 !important; }
    .mobile-mt-1 { margin-top: 0.25rem !important; }
    .mobile-mb-1 { margin-bottom: 0.25rem !important; }
    .mobile-mt-2 { margin-top: 0.5rem !important; }
    .mobile-mb-2 { margin-bottom: 0.5rem !important; }
    .mobile-mt-3 { margin-top: 1rem !important; }
    .mobile-mb-3 { margin-bottom: 1rem !important; }
    
    .mobile-text-center { text-align: center !important; }
    .mobile-text-left { text-align: left !important; }
    .mobile-text-right { text-align: right !important; }
    
    .mobile-d-none { display: none !important; }
    .mobile-d-block { display: block !important; }
    .mobile-d-flex { display: flex !important; }
    
    .mobile-w-100 { width: 100% !important; }
    .mobile-mx-auto { margin-left: auto !important; margin-right: auto !important; }
    
    /* Add padding to navbar */
    .navbar {
        padding-left: 1rem !important;
        padding-right: 1rem !important;
    }
    
    /* Override any common fixed-width containers */
    .wrapper,
    .content-wrapper,
    .page-wrapper,
    .main-content,
    .site-content,
    .content-area,
    .main-container {
        width: 100% !important;
        max-width: 100% !important;
        padding-left: 1rem !important;
        padding-right: 1rem !important;
        margin-left: 0 !important;
        margin-right: 0 !important;
    }
}

/* Extra small devices - ensure tiny padding on very small screens */
@media (max-width: 480px) {
    .container, .container-fluid, [class*="container-"] {
        padding-left: 0.75rem !important;
        padding-right: 0.75rem !important;
    }
}

/* Better scrolling for overflow content */
.mobile-scroll-container {
    -webkit-overflow-scrolling: touch;
    overflow-y: auto;
    max-height: 50vh;
}

/* Page transitions */
.page-transition {
    transition: opacity 0.3s ease;
}

.page-transition.fade-out {
    opacity: 0;
}

.page-transition.fade-in {
    opacity: 1;
}

/* Loading states */
body.is-loading .main-content {
    opacity: 0.7;
}

body.is-loading .content-loader {
    display: flex;
}

.content-loader {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(255, 255, 255, 0.7);
    z-index: 9999;
    align-items: center;
    justify-content: center;
    flex-direction: column;
}

.android-device .content-loader {
    background-color: rgba(255, 255, 255, 0.9);
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    body.dark-mode-support {
        --body-bg: #121212;
        --dark: #f8f9fa;
        --light: #121212;
        --gray-light: #2a2a2a;
        --gray-dark: #e9ecef;
        
        background-color: var(--body-bg);
        color: var(--dark);
    }
    
    body.dark-mode-support .content-loader {
        background-color: rgba(0, 0, 0, 0.7);
    }
    
    body.dark-mode-support.android-device .content-loader {
        background-color: rgba(0, 0, 0, 0.9);
    }
}

/* Print styles */
@media print {
    body, .card, .table-responsive, .navbar, .footer {
        background: #fff !important;
        box-shadow: none !important;
    }
    
    .container {
        width: 100%;
        max-width: 100%;
        padding: 0 !important;
    }
    
    .navbar-toggler, .breadcrumb, .no-print, 
    .btn:not(.btn-print), .toast-container,
    .mobile-action-bar, .navbar-collapse {
        display: none !important;
    }
    
    table {
        page-break-inside: avoid;
    }
    
    a[href]:after {
        content: " (" attr(href) ")";
        font-size: 10pt;
        font-style: italic;
    }
    
    a[href^="#"]:after,
    a[href^="javascript:"]:after,
    a.btn:after {
        content: "";
    }
}