/**
 * SMSPro Web - Mobile-First Responsive Styles
 * Comprehensive mobile optimizations for all screen sizes
 *
 * Breakpoints:
 * - xs: < 576px (Mobile portrait)
 * - sm: 576px - 767px (Mobile landscape)
 * - md: 768px - 991px (Tablet)
 * - lg: 992px - 1199px (Desktop)
 * - xl: >= 1200px (Large desktop)
 */

/* ============================================================================
   MOBILE-FIRST BASE OPTIMIZATIONS
   ============================================================================ */

/* Prevent horizontal scrolling on mobile */
html, body {
    overflow-x: hidden;
    width: 100%;
    max-width: 100vw;
}

/* Better text rendering on mobile */
body {
    -webkit-text-size-adjust: 100%;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

/* Touch-friendly minimum sizes (WCAG AA) */
button,
.btn,
a.btn,
.nav-link,
.page-link,
.dropdown-toggle,
input[type="button"],
input[type="submit"] {
    min-height: 44px;
    min-width: 44px;
    touch-action: manipulation;
}

/* Larger tap targets for form controls */
.form-control,
.form-select,
input[type="text"],
input[type="email"],
input[type="tel"],
input[type="number"],
input[type="date"],
textarea,
select {
    min-height: 48px;
    font-size: 16px; /* Prevents iOS zoom on focus */
    touch-action: manipulation;
}

textarea {
    min-height: 96px;
}

/* Better checkbox and radio button sizes */
input[type="checkbox"],
input[type="radio"] {
    min-width: 20px;
    min-height: 20px;
    cursor: pointer;
}

/* ============================================================================
   MOBILE NAVIGATION (< 992px)
   ============================================================================ */

@media (max-width: 991.98px) {
    /* Navbar optimizations */
    .navbar {
        padding: 0.625rem 1rem;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        z-index: 1050;
    }

    .navbar-brand {
        font-size: 1.125rem;
        gap: 0.5rem;
    }

    .navbar-brand img.logo {
        height: 40px;
    }

    /* Hamburger menu - larger touch target */
    .navbar-toggler {
        padding: 0.75rem;
        min-width: 48px;
        min-height: 48px;
        border-radius: 8px;
    }

    /* Sidebar as drawer */
    .sidebar {
        position: fixed;
        top: 64px; /* Below navbar */
        left: -100%;
        width: 280px;
        height: calc(100vh - 64px);
        z-index: 1045;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        box-shadow: 2px 0 8px rgba(0, 0, 0, 0.1);
    }

    .sidebar.show {
        left: 0;
    }

    /* Mobile overlay */
    .mobile-overlay {
        display: none;
        position: fixed;
        top: 64px;
        left: 0;
        width: 100%;
        height: calc(100vh - 64px);
        background-color: rgba(0, 0, 0, 0.5);
        backdrop-filter: blur(4px);
        z-index: 1040;
        opacity: 0;
        transition: opacity 0.3s ease;
    }

    .mobile-overlay.show {
        display: block;
        opacity: 1;
    }

    /* Main content with proper spacing */
    .main-content {
        padding: 1rem;
        margin-top: 64px;
        min-height: calc(100vh - 64px);
    }

    /* Dropdown menus - full width on mobile */
    .navbar .dropdown-menu {
        position: absolute;
        width: 200px;
        max-width: calc(100vw - 2rem);
    }
}

/* ============================================================================
   MOBILE CARDS AND CONTAINERS
   ============================================================================ */

@media (max-width: 767.98px) {
    /* Card spacing */
    .card {
        margin-bottom: 1rem;
        border-radius: 12px;
    }

    .card-body {
        padding: 1rem;
    }

    .card-header {
        padding: 0.875rem 1rem;
        font-size: 1rem;
    }

    /* Stats cards - stack on mobile */
    .card-stats {
        margin-bottom: 1rem;
    }

    .card-stats .card-body {
        padding: 1.25rem;
    }

    .card-stats h3 {
        font-size: 2rem;
    }

    .card-stats p {
        font-size: 0.875rem;
    }

    /* Container adjustments */
    .container-fluid {
        padding-left: 0.75rem;
        padding-right: 0.75rem;
    }
}

/* ============================================================================
   MOBILE TABLES - CARD VIEW TRANSFORMATION
   ============================================================================ */

@media (max-width: 767.98px) {
    /* Hide table on mobile, show card view instead */
    .table-responsive {
        border: none;
        overflow: visible;
    }

    /* Transform table to cards on mobile */
    .table.mobile-card-view {
        display: block;
    }

    .table.mobile-card-view thead {
        display: none;
    }

    .table.mobile-card-view tbody,
    .table.mobile-card-view tr {
        display: block;
        width: 100%;
    }

    .table.mobile-card-view tr {
        background: white;
        border: 1px solid var(--gray-200, #e0e0e0);
        border-radius: 12px;
        margin-bottom: 1rem;
        padding: 1rem;
        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.08);
    }

    .table.mobile-card-view td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 0.625rem 0;
        border: none;
        border-bottom: 1px solid var(--gray-200, #e0e0e0);
    }

    .table.mobile-card-view td:last-child {
        border-bottom: none;
    }

    .table.mobile-card-view td::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--gray-700, #616161);
        margin-right: 1rem;
        flex-shrink: 0;
    }

    /* Action buttons in mobile cards */
    .table.mobile-card-view .btn-group {
        flex-direction: row;
        gap: 0.5rem;
    }

    .table.mobile-card-view .btn-group .btn {
        padding: 0.5rem 0.75rem;
    }
}

/* ============================================================================
   MOBILE FORMS - VERTICAL TABS
   ============================================================================ */

@media (max-width: 767.98px) {
    /* Vertical tab layout for mobile */
    .nav-tabs {
        flex-direction: column;
        border-bottom: none;
        border-right: 3px solid var(--gray-200, #e0e0e0);
        margin-bottom: 1.5rem;
    }

    .nav-tabs .nav-item {
        width: 100%;
    }

    .nav-tabs .nav-link {
        border: none;
        border-radius: 8px;
        margin-bottom: 0.25rem;
        text-align: left;
        padding: 0.875rem 1rem;
        display: flex;
        align-items: center;
        gap: 0.75rem;
    }

    .nav-tabs .nav-link i {
        font-size: 1.125rem;
        min-width: 24px;
        text-align: center;
    }

    .nav-tabs .nav-link::after {
        display: none;
    }

    .nav-tabs .nav-link.active {
        background: linear-gradient(90deg,
            var(--brand-green-subtle, #e8f5ed) 0%,
            rgba(255, 255, 255, 0.5) 100%);
        border-left: 4px solid var(--brand-green-deep, #1e5631);
        padding-left: calc(1rem - 4px);
    }

    /* Form fields - full width */
    .form-group,
    .mb-3,
    .mb-2 {
        margin-bottom: 1rem !important;
    }

    .row > [class*="col-"] {
        padding-left: 0.75rem;
        padding-right: 0.75rem;
    }

    /* Stacked form layout */
    .row > .col-md-6,
    .row > .col-md-4,
    .row > .col-md-3 {
        width: 100%;
        margin-bottom: 1rem;
    }

    /* Form labels */
    .form-label {
        font-size: 0.9375rem;
        margin-bottom: 0.5rem;
    }

    /* Help text */
    .form-text,
    small.text-muted {
        font-size: 0.8125rem;
    }
}

/* ============================================================================
   MOBILE MODALS - FULL SCREEN ON SMALL DEVICES
   ============================================================================ */

@media (max-width: 575.98px) {
    .modal-dialog {
        margin: 0;
        max-width: 100%;
        height: 100vh;
    }

    .modal-content {
        height: 100vh;
        border-radius: 0;
        border: none;
    }

    .modal-header {
        border-radius: 0;
        padding: 1rem;
        position: sticky;
        top: 0;
        z-index: 1;
        background: white;
    }

    .modal-body {
        padding: 1rem;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        max-height: calc(100vh - 140px);
    }

    .modal-footer {
        border-radius: 0;
        padding: 1rem;
        position: sticky;
        bottom: 0;
        background: white;
        box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.1);
    }

    /* Modal buttons - full width on mobile */
    .modal-footer .btn {
        width: 100%;
        margin: 0.25rem 0 !important;
    }

    .modal-footer .d-flex {
        flex-direction: column;
        width: 100%;
    }
}

/* Desktop reset for modal buttons */
@media (min-width: 769px) {
    .modal-footer .btn {
        width: auto;
        margin: 0 0.25rem;
    }

    .modal-footer .d-flex {
        flex-direction: row;
        width: auto;
    }
}

/* ============================================================================
   MOBILE BUTTONS AND ACTIONS
   ============================================================================ */

@media (max-width: 767.98px) {
    /* Button groups - vertical on mobile */
    .btn-group {
        display: flex;
        flex-direction: row;
        gap: 0.5rem;
        width: 100%;
    }

    .btn-group-sm .btn {
        padding: 0.5rem 0.75rem;
        font-size: 0.875rem;
    }

    /* Action buttons at bottom on mobile */
    .mobile-action-bar {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: white;
        padding: 1rem;
        box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.1);
        z-index: 1030;
        display: flex;
        gap: 0.5rem;
    }

    .mobile-action-bar .btn {
        flex: 1;
    }

    /* Floating action button (FAB) */
    .fab-mobile {
        position: fixed;
        bottom: 1.5rem;
        right: 1.5rem;
        width: 56px;
        height: 56px;
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 1.5rem;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
        z-index: 1030;
    }
}

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

@media (max-width: 767.98px) {
    .pagination {
        flex-wrap: wrap;
        gap: 0.25rem;
    }

    .page-link {
        padding: 0.5rem 0.75rem;
        font-size: 0.875rem;
        min-width: 40px;
        min-height: 40px;
    }

    /* Hide page numbers, show only prev/next on very small screens */
    @media (max-width: 420px) {
        .pagination .page-item:not(:first-child):not(:last-child):not(.active) {
            display: none;
        }

        .pagination .page-item.active {
            order: 1;
        }

        .pagination .page-item:first-child {
            order: 0;
        }

        .pagination .page-item:last-child {
            order: 2;
        }
    }
}

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

@media (max-width: 767.98px) {
    /* Filter controls - full width */
    .filter-controls .row > [class*="col-"] {
        width: 100%;
        margin-bottom: 0.75rem;
    }

    /* Search input with icon */
    .search-input-mobile {
        position: relative;
    }

    .search-input-mobile i {
        position: absolute;
        left: 1rem;
        top: 50%;
        transform: translateY(-50%);
        color: var(--gray-500, #9e9e9e);
    }

    .search-input-mobile input {
        padding-left: 2.75rem;
    }

    /* Collapsible filters */
    .mobile-filters-toggle {
        margin-bottom: 1rem;
    }

    .mobile-filters-collapse {
        background: white;
        border-radius: 12px;
        padding: 1rem;
        margin-bottom: 1rem;
    }
}

/* ============================================================================
   MOBILE TYPOGRAPHY
   ============================================================================ */

@media (max-width: 767.98px) {
    body {
        font-size: 15px;
    }

    h1 { font-size: 1.75rem; }
    h2 { font-size: 1.5rem; }
    h3 { font-size: 1.25rem; }
    h4 { font-size: 1.125rem; }
    h5 { font-size: 1rem; }
    h6 { font-size: 0.9375rem; }

    /* Truncate long text on mobile */
    .mobile-truncate {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        max-width: 100%;
    }

    /* Responsive text utilities */
    .text-mobile-center {
        text-align: center !important;
    }
}

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

@media (max-width: 767.98px) {
    /* Chart containers - responsive height */
    .chart-container {
        position: relative;
        height: 250px;
        margin-bottom: 1rem;
    }

    /* Chart legend - smaller on mobile */
    canvas {
        max-height: 250px;
    }
}

/* ============================================================================
   MOBILE ALERTS AND NOTIFICATIONS
   ============================================================================ */

@media (max-width: 767.98px) {
    .alert {
        border-radius: 8px;
        padding: 0.875rem 1rem;
        font-size: 0.9375rem;
    }

    .alert-dismissible .btn-close {
        padding: 1rem;
    }

    /* Toast notifications - full width on mobile */
    .toast {
        width: calc(100% - 2rem);
        max-width: none;
        margin: 0 1rem;
    }
}

/* ============================================================================
   MOBILE ACCESSIBILITY ENHANCEMENTS
   ============================================================================ */

@media (max-width: 767.98px) {
    /* Focus visible for keyboard navigation */
    *:focus-visible {
        outline: 3px solid var(--brand-green-deep, #1e5631);
        outline-offset: 2px;
    }

    /* Skip to main content link */
    .skip-to-main {
        position: absolute;
        top: -100px;
        left: 0;
        background: var(--brand-green-deep, #1e5631);
        color: white;
        padding: 1rem;
        z-index: 9999;
        transition: top 0.3s;
    }

    .skip-to-main:focus {
        top: 0;
    }

    /* Reduce motion for users with vestibular disorders */
    @media (prefers-reduced-motion: reduce) {
        *,
        *::before,
        *::after {
            animation-duration: 0.01ms !important;
            animation-iteration-count: 1 !important;
            transition-duration: 0.01ms !important;
            scroll-behavior: auto !important;
        }
    }
}

/* ============================================================================
   MOBILE LANDSCAPE OPTIMIZATIONS (576px - 767px)
   ============================================================================ */

@media (min-width: 576px) and (max-width: 767.98px) {
    /* Use two-column layout in landscape */
    .row > .col-sm-6 {
        width: 50%;
    }

    /* Cards in grid */
    .card-grid-mobile {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 1rem;
    }
}

/* ============================================================================
   TABLET OPTIMIZATIONS (768px - 991px)
   ============================================================================ */

@media (min-width: 768px) and (max-width: 991.98px) {
    .main-content {
        padding: 1.5rem;
    }

    /* Three-column layout for stats on tablet */
    .stats-grid-tablet {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        gap: 1rem;
    }

    /* Horizontal tabs on tablet */
    .nav-tabs {
        flex-direction: row;
        flex-wrap: wrap;
    }

    .nav-tabs .nav-link {
        flex: 1 1 auto;
        min-width: 120px;
    }
}

/* ============================================================================
   PRINT STYLES - MOBILE FRIENDLY
   ============================================================================ */

@media print {
    /* Hide non-printable elements */
    .navbar,
    .sidebar,
    .mobile-overlay,
    .btn,
    button,
    .pagination,
    .fab-mobile,
    .mobile-action-bar {
        display: none !important;
    }

    /* Full width for content */
    .main-content,
    .container-fluid {
        margin: 0 !important;
        padding: 0 !important;
        width: 100% !important;
        max-width: 100% !important;
    }

    /* Tables print properly */
    .table.mobile-card-view {
        display: table;
    }

    .table.mobile-card-view thead {
        display: table-header-group;
    }

    .table.mobile-card-view tbody,
    .table.mobile-card-view tr {
        display: table-row;
    }

    .table.mobile-card-view td {
        display: table-cell;
    }

    .table.mobile-card-view td::before {
        display: none;
    }
}

/* ============================================================================
   MOBILE PERFORMANCE OPTIMIZATIONS
   ============================================================================ */

/* GPU acceleration for smooth animations */
.sidebar,
.mobile-overlay,
.navbar,
.modal {
    will-change: transform;
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
}

/* Smooth scrolling on iOS */
.sidebar,
.modal-body,
.table-responsive {
    -webkit-overflow-scrolling: touch;
}

/* Prevent tap highlight on mobile */
a, button, .btn, .nav-link {
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1);
}

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

/* Show/hide on mobile */
.mobile-only {
    display: block !important;
}

.desktop-only {
    display: none !important;
}

@media (min-width: 768px) {
    .mobile-only {
        display: none !important;
    }

    .desktop-only {
        display: block !important;
    }
}

/* ============================================================================
   MERGED FROM mobile-fix.css - Unique rules only
   ============================================================================ */

/* Sticky table headers on mobile */
@media (max-width: 767.98px) {
    thead th {
        position: sticky;
        top: 0;
        background-color: #f8f9fa;
        z-index: 10;
    }

    /* Prevent horizontal scroll */
    body, html {
        overflow-x: hidden;
        max-width: 100vw;
    }

    /* Force text wrap on mobile */
    .card-body, .table td, .table th {
        word-wrap: break-word;
        overflow-wrap: break-word;
    }

    /* Active nav tab - brand color */
    .nav-tabs .nav-link.active {
        background-color: var(--brand-green-deep, #1e5631);
        color: white;
        border-color: var(--brand-green-deep, #1e5631);
    }
}

/* Landscape orientation - compact spacing */
@media (max-width: 767.98px) and (orientation: landscape) {
    .card-body {
        padding: 0.75rem;
    }

    .navbar {
        padding: 0.25rem 1rem;
    }
}
