/* Mobile Responsiveness Styles
   Comprehensive mobile optimization for AR Management System
*/

/* ============================================
   BREAKPOINTS
   ============================================
   - Mobile: < 576px (extra small)
   - Tablet: 576px - 768px (small)
   - Desktop: 768px+ (medium and up)
*/

/* ============================================
   GLOBAL MOBILE IMPROVEMENTS
   ============================================ */

/* Base mobile styles */
@media (max-width: 767.98px) {
    /* Improve touch targets - minimum 44x44px */
    .btn, button, a.btn {
        min-height: 44px;
        min-width: 44px;
        padding: 0.5rem 1rem;
    }
    
    /* Better spacing on mobile */
    .container-xl {
        padding-left: 1rem;
        padding-right: 1rem;
    }
    
    .page-body {
        padding-top: 1rem;
    }
    
    /* Reduce font sizes slightly for mobile */
    body {
        font-size: 14px;
    }
    
    h1 { font-size: 1.75rem; }
    h2 { font-size: 1.5rem; }
    h3 { font-size: 1.25rem; }
    h4 { font-size: 1.1rem; }
    h5 { font-size: 1rem; }
    
    /* Better card spacing */
    .card {
        margin-bottom: 1rem;
    }
    
    .card-body {
        padding: 1rem;
    }
    
    /* Stack button groups vertically */
    .btn-group {
        flex-direction: column;
        width: 100%;
    }
    
    .btn-group .btn {
        width: 100%;
        margin-bottom: 0.5rem;
        border-radius: 0.375rem !important;
    }
    
    /* Full-width buttons in lists */
    .btn-list {
        flex-direction: column;
    }
    
    .btn-list .btn {
        width: 100%;
        margin-bottom: 0.5rem;
    }
}

/* Extra small devices (phones, < 576px) */
@media (max-width: 575.98px) {
    /* Even tighter spacing */
    .container-xl {
        padding-left: 0.75rem;
        padding-right: 0.75rem;
    }
    
    .card-body {
        padding: 0.75rem;
    }
    
    /* Smaller headings */
    h1 { font-size: 1.5rem; }
    h2 { font-size: 1.35rem; }
    h3 { font-size: 1.15rem; }
    
    /* Hide less critical elements */
    .text-muted.small {
        font-size: 0.75rem;
    }
}

/* ============================================
   NAVIGATION MOBILE IMPROVEMENTS
   ============================================ */

@media (max-width: 767.98px) {
    /* Smaller logo on mobile */
    .navbar-brand-image,
    img.navbar-brand-image,
    #themeLogo {
        width: 21px !important;
        height: 31px !important;
        max-width: 21px !important;
        max-height: 31px !important;
        object-fit: contain;
    }
    
    .navbar-brand {
        padding: 0.25rem 0;
    }
    
    .navbar-brand a {
        display: inline-block;
    }
    
    /* Better navbar layout */
    .navbar {
        padding: 0.5rem 0;
    }
    
    /* Stack navbar items */
    .navbar-nav.flex-row {
        flex-direction: column;
        width: 100%;
    }
    
    .navbar-nav.flex-row .nav-item {
        width: 100%;
        margin-bottom: 0.5rem;
    }
    
    /* Dark mode toggle - better positioning */
    #darkModeToggle {
        position: fixed;
        top: 1rem;
        right: 1rem;
        z-index: 1050;
        background: var(--tblr-bg-surface);
        border: 1px solid var(--tblr-border-color);
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    }
    
    /* User dropdown - full width on mobile */
    .navbar .dropdown-menu {
        width: 100%;
        max-width: 100%;
        left: 0 !important;
        right: 0 !important;
    }
    
    /* Navigation menu - better mobile experience */
    .navbar-collapse {
        margin-top: 1rem;
    }
    
    .nav-link {
        padding: 0.75rem 1rem;
        border-bottom: 1px solid var(--tblr-border-color);
    }
    
    .nav-link:last-child {
        border-bottom: none;
    }
}

/* ============================================
   TABLE MOBILE IMPROVEMENTS
   ============================================ */

/* Convert tables to card layout on mobile */
@media (max-width: 767.98px) {
    /* Hide table headers on mobile */
    .table-responsive table thead {
        display: none;
    }
    
    /* Convert table rows to cards */
    .table-responsive table tbody tr {
        display: block;
        margin-bottom: 1rem;
        background: var(--tblr-bg-surface);
        border: 1px solid var(--tblr-border-color);
        border-radius: 0.375rem;
        padding: 1rem;
        box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
        transition: box-shadow 0.2s ease;
    }
    
    .table-responsive table tbody tr:active {
        box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
    }
    
    /* Make table cells stack vertically */
    .table-responsive table tbody td {
        display: block;
        text-align: left !important;
        padding: 0.75rem 0;
        border: none;
        border-bottom: 1px solid var(--tblr-border-color);
    }
    
    .table-responsive table tbody td:last-child {
        border-bottom: none;
        padding-bottom: 0;
    }
    
    /* Add labels before each cell */
    .table-responsive table tbody td::before {
        content: attr(data-label);
        font-weight: 600;
        display: inline-block;
        min-width: 120px;
        color: var(--tblr-secondary);
        margin-right: 0.5rem;
        font-size: 0.875rem;
    }
    
    /* Status column - make it prominent */
    .table-responsive table tbody td:first-child {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 0.75rem 0;
        border-bottom: 2px solid var(--tblr-border-color);
        margin-bottom: 0.5rem;
        padding-bottom: 0.75rem;
    }
    
    .table-responsive table tbody td:first-child::before {
        content: "Status";
        font-weight: 700;
        font-size: 1rem;
    }
    
    /* Action buttons - full width on mobile */
    .table-responsive table tbody td .btn {
        width: 100%;
        margin-top: 0.5rem;
        min-height: 44px;
    }
    
    /* Badges in mobile cards */
    .table-responsive table tbody td .badge {
        display: inline-block;
        margin: 0.25rem 0.25rem 0.25rem 0;
        font-size: 0.875rem;
        padding: 0.5rem 0.75rem;
    }
    
    /* Better text wrapping in mobile cards */
    .table-responsive table tbody td {
        word-wrap: break-word;
        overflow-wrap: break-word;
    }
}

/* Keep horizontal scroll for very wide tables as fallback */
@media (max-width: 575.98px) {
    .table-responsive {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    /* Show scroll indicator */
    .table-responsive::after {
        content: "← Swipe to see more →";
        display: block;
        text-align: center;
        padding: 0.5rem;
        color: var(--tblr-secondary);
        font-size: 0.75rem;
    }
}

/* ============================================
   DASHBOARD WIDGETS MOBILE
   ============================================ */

@media (max-width: 767.98px) {
    /* Summary cards - stack and optimize */
    .row-deck .col-sm-6,
    .row-deck .col-lg-3 {
        margin-bottom: 1rem;
    }
    
    /* Summary card content */
    .summary-card .card-body {
        padding: 1rem;
    }
    
    .summary-card .h1 {
        font-size: 2rem;
    }
    
    .summary-card .subheader {
        font-size: 0.875rem;
    }
    
    /* Icons in summary cards - smaller */
    .summary-card i {
        font-size: 1.5rem;
    }
}

/* ============================================
   FORMS MOBILE IMPROVEMENTS
   ============================================ */

@media (max-width: 767.98px) {
    /* Full-width form inputs */
    .form-control,
    .form-select {
        width: 100%;
        font-size: 16px; /* Prevents zoom on iOS */
    }
    
    /* Better form spacing */
    .form-group,
    .mb-3 {
        margin-bottom: 1rem;
    }
    
    /* Stack form rows */
    .row .col-md-6,
    .row .col-md-4,
    .row .col-md-3 {
        margin-bottom: 1rem;
    }
    
    /* Full-width buttons in forms */
    form .btn {
        width: 100%;
        margin-bottom: 0.5rem;
    }
    
    /* Form labels */
    .form-label {
        font-weight: 600;
        margin-bottom: 0.5rem;
    }
    
    /* Checkboxes and radios - larger touch targets */
    .form-check-input {
        width: 1.25rem;
        height: 1.25rem;
        margin-top: 0.25rem;
    }
    
    .form-check-label {
        padding-left: 0.5rem;
        font-size: 1rem;
    }
}

/* ============================================
   MODALS MOBILE IMPROVEMENTS
   ============================================ */

@media (max-width: 767.98px) {
    /* Full-screen modals on mobile */
    .modal-dialog {
        margin: 0;
        max-width: 100%;
        height: 100%;
    }
    
    .modal-content {
        height: 100%;
        border-radius: 0;
        border: none;
    }
    
    .modal-header {
        border-radius: 0;
        padding: 1rem;
    }
    
    .modal-body {
        padding: 1rem;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .modal-footer {
        padding: 1rem;
        border-top: 1px solid var(--tblr-border-color);
    }
    
    /* Stack modal buttons */
    .modal-footer .btn {
        width: 100%;
        margin-bottom: 0.5rem;
    }
    
    .modal-footer .btn:last-child {
        margin-bottom: 0;
    }
}

/* ============================================
   ADMIN PANEL MOBILE
   ============================================ */

@media (max-width: 767.98px) {
    /* Admin action buttons - stack vertically */
    .admin-actions .row .col-md-3,
    .admin-actions .row .col-12 {
        margin-bottom: 0.75rem;
    }
    
    .admin-actions .btn {
        width: 100%;
        min-height: 44px;
        padding: 0.75rem 1rem;
    }
    
    /* Filter forms - stack inputs */
    #auditFilters .row .col-md-3,
    #auditFilters .row .col-md-2 {
        margin-bottom: 1rem;
    }
    
    /* Audit trail table - use card layout */
    .table-responsive table tbody tr {
        padding: 0.75rem;
    }
    
    /* User management table */
    .table-responsive table tbody td {
        font-size: 0.875rem;
    }
    
    /* Admin sections - better spacing */
    .card-header h3,
    .card-header h5 {
        font-size: 1.1rem;
    }
    
    /* Action button groups */
    .btn-group-vertical {
        width: 100%;
    }
    
    /* System status cards */
    .system-status .row .col-md-6 {
        margin-bottom: 1rem;
    }
}

/* ============================================
   CHARTS AND VISUALIZATIONS MOBILE
   ============================================ */

@media (max-width: 767.98px) {
    /* Charts - responsive */
    canvas {
        max-width: 100% !important;
        height: auto !important;
    }
    
    /* Chart containers */
    .chart-container {
        position: relative;
        width: 100%;
        height: 300px;
    }
    
    /* Hide chart legends on very small screens */
    @media (max-width: 575.98px) {
        .chart-legend {
            display: none;
        }
    }
}

/* ============================================
   PAGINATION MOBILE
   ============================================ */

@media (max-width: 767.98px) {
    /* Better pagination on mobile */
    .pagination {
        flex-wrap: wrap;
        justify-content: center;
    }
    
    .pagination .page-link {
        min-width: 44px;
        min-height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
        padding: 0.5rem;
    }
    
    /* Hide page numbers, show only prev/next on very small */
    @media (max-width: 575.98px) {
        .pagination .page-item:not(.prev):not(.next) {
            display: none;
        }
    }
}

/* ============================================
   SEARCH AND FILTERS MOBILE
   ============================================ */

@media (max-width: 767.98px) {
    /* Search inputs - full width */
    .search-input,
    input[type="search"],
    input[type="text"].form-control {
        width: 100%;
        font-size: 16px; /* Prevents iOS zoom */
    }
    
    /* Filter panels - collapsible */
    .filter-panel {
        margin-bottom: 1rem;
    }
    
    /* Filter buttons - stack */
    .filter-buttons {
        flex-direction: column;
    }
    
    .filter-buttons .btn {
        width: 100%;
        margin-bottom: 0.5rem;
    }
}

/* ============================================
   INVOICE REQUESTS MOBILE
   ============================================ */

@media (max-width: 767.98px) {
    /* Invoice request cards - better spacing */
    .invoice-request-card {
        margin-bottom: 1rem;
    }
    
    /* Status badges - larger on mobile */
    .invoice-status-badge {
        font-size: 0.875rem;
        padding: 0.5rem 0.75rem;
    }
    
    /* Action buttons in cards */
    .invoice-request-card .btn {
        width: 100%;
        margin-bottom: 0.5rem;
    }
}

/* ============================================
   CUSTOMER DETAILS MOBILE
   ============================================ */

@media (max-width: 767.98px) {
    /* Customer info cards - stack */
    .customer-info .row .col-md-6 {
        margin-bottom: 1rem;
    }
    
    /* Contact cards - full width */
    .contact-card {
        width: 100%;
        margin-bottom: 1rem;
    }
    
    /* Notes section - better mobile layout */
    .notes-section {
        padding: 1rem;
    }
}

/* ============================================
   TOUCH IMPROVEMENTS
   ============================================ */

/* Better touch targets - apply to all mobile */
@media (max-width: 767.98px) {
    /* Larger touch targets for mobile devices */
    .btn-sm {
        min-height: 44px;
        padding: 0.5rem 1rem;
    }
    
    .btn-xs {
        min-height: 44px;
        padding: 0.5rem 0.75rem;
    }
    
    /* Better spacing for touch */
    .btn + .btn {
        margin-left: 0.5rem;
    }
    
    /* Better dropdown touch targets */
    .dropdown-toggle {
        min-height: 44px;
        padding: 0.5rem 1rem;
    }
    
    /* Table row touch feedback */
    .table tbody tr:active {
        background-color: var(--tblr-bg-surface-hover);
        opacity: 0.8;
    }
    
    /* Clickable elements - better touch feedback */
    a:active,
    button:active,
    .btn:active {
        opacity: 0.7;
        transform: scale(0.98);
    }
    
    /* Better checkbox/radio touch targets */
    .form-check-input {
        width: 1.25rem;
        height: 1.25rem;
        margin-top: 0.25rem;
    }
    
    .form-check-label {
        padding-left: 0.5rem;
        min-height: 44px;
        display: flex;
        align-items: center;
    }
    
    /* Links - better touch targets */
    a:not(.btn) {
        min-height: 44px;
        display: inline-flex;
        align-items: center;
        padding: 0.25rem 0.5rem;
    }
}

/* Touch device specific improvements */
@media (hover: none) and (pointer: coarse) {
    /* Remove hover effects on touch devices */
    .btn:hover {
        transform: none;
    }
    
    /* Better focus states for touch */
    .btn:focus,
    .form-control:focus {
        outline: 2px solid var(--tblr-primary);
        outline-offset: 2px;
    }
}

/* ============================================
   UTILITY CLASSES FOR MOBILE
   ============================================ */

/* Hide on mobile */
@media (max-width: 767.98px) {
    .d-mobile-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;
    }
}

/* Stack on mobile */
@media (max-width: 767.98px) {
    .flex-mobile-column {
        flex-direction: column !important;
    }
}

/* ============================================
   ADDITIONAL MOBILE ENHANCEMENTS
   ============================================ */

@media (max-width: 767.98px) {
    /* Better page header on mobile */
    .page-header {
        padding: 1rem 0;
    }
    
    .page-title {
        font-size: 1.5rem;
        margin-bottom: 0.5rem;
    }
    
    /* Better card headers */
    .card-header {
        padding: 1rem;
    }
    
    .card-title {
        font-size: 1.1rem;
    }
    
    /* Better spacing for action buttons */
    .card-actions {
        margin-top: 0.5rem;
    }
    
    /* Better input groups on mobile */
    .input-group {
        flex-wrap: wrap;
    }
    
    .input-group .btn {
        width: 100%;
        margin-top: 0.5rem;
        border-radius: 0.375rem;
    }
    
    /* Better dropdowns on mobile */
    .dropdown-menu {
        max-width: calc(100vw - 2rem);
        left: 1rem !important;
        right: 1rem !important;
    }
    
    /* Better alerts on mobile */
    .alert {
        padding: 1rem;
        font-size: 0.9rem;
    }
    
    /* Better badges on mobile */
    .badge {
        font-size: 0.875rem;
        padding: 0.5rem 0.75rem;
    }
    
    /* Better list groups */
    .list-group-item {
        padding: 1rem;
    }
    
    /* Better tabs on mobile */
    .nav-tabs {
        flex-wrap: wrap;
    }
    
    .nav-tabs .nav-link {
        min-width: auto;
        padding: 0.75rem 1rem;
    }
    
    /* Better footer on mobile */
    .footer {
        padding: 1rem 0;
        font-size: 0.875rem;
    }
    
    /* Better spacing for page content */
    .page-body {
        padding-bottom: 2rem;
    }
    
    /* Better empty states */
    .empty {
        padding: 2rem 1rem;
    }
    
    .empty-icon {
        font-size: 3rem;
    }
    
    .empty-title {
        font-size: 1.25rem;
    }
    
    /* Better loading states */
    .spinner-border,
    .spinner-grow {
        width: 2rem;
        height: 2rem;
    }
    
    /* Mobile search results */
    #mobileSearchResultsContainer .card {
        border: 1px solid var(--tblr-border-color);
        margin-bottom: 0.75rem;
    }
    
    #mobileSearchResultsContainer .card-body {
        padding: 1rem;
    }
    
    #mobileSearchResultsContainer .badge {
        font-size: 0.75rem;
        padding: 0.375rem 0.5rem;
    }
    
    /* Mobile autocomplete */
    #mobileGlobalSearchAutocomplete {
        position: relative;
        z-index: 1050;
    }
    
    #mobileGlobalSearchAutocomplete .autocomplete-suggestion {
        padding: 1rem;
        font-size: 0.9rem;
    }
}

/* ============================================
   PRINT STYLES (Mobile-friendly)
   ============================================ */

@media print {
    /* Hide navigation and actions */
    .navbar,
    .btn,
    .card-actions,
    .dropdown,
    #darkModeToggle {
        display: none !important;
    }
    
    /* Full width for print */
    .container-xl {
        max-width: 100%;
        padding: 0;
    }
    
    /* Better table printing */
    .table {
        font-size: 10pt;
    }
    
    /* Page breaks */
    .card {
        break-inside: avoid;
        page-break-inside: avoid;
    }
}
