/**
 * 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
   ============================================================================ */

/* Only *clip* horizontal overflow on true narrow phones (single-column layout that
   shouldn't overflow). On wider / "Desktop site" viewports, allow horizontal scrolling
   instead, so content rendered wider than the physical screen stays reachable rather than
   being silently cut off on the right. */
html, body {
    width: 100%;
}
@media (max-width: 767.98px) {
    html, body {
        overflow-x: hidden;
        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) {
    /* Sleeker, shorter top bar on phones — the 60px desktop header wastes vertical
       space on a small screen. Shrink the bar + logo and drop --navbar-height so the
       fixed sidebar top and content padding-top track it (they all read the var). */
    :root { --navbar-height: 50px; }
    /* Navbar optimizations */
    .navbar {
        padding: 0.2rem 0.75rem;
        min-height: 50px;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        z-index: 1050;
    }

    /* ONE row, always. Below the expand breakpoint Bootstrap lets the bar's
       container wrap and stacks .navbar-nav vertically, so the right-side
       cluster (search/theme/profile) fell onto a second 50px row — the "top
       banner covering the screen" complaint. Force a single nowrap row. */
    .navbar .container-fluid { flex-wrap: nowrap; }
    .navbar .navbar-nav {
        flex-direction: row;
        align-items: center;
    }

    .navbar-brand {
        font-size: 1rem;
        gap: 0.4rem;
    }

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

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

    /* Sidebar as drawer — top tracks the (variable) navbar height */
    .sidebar {
        position: fixed;
        top: var(--navbar-height);
        left: -100%;
        width: 280px;
        height: calc(100vh - var(--navbar-height));
        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: var(--navbar-height);
        left: 0;
        width: 100%;
        height: calc(100vh - var(--navbar-height));
        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. Offset by the (now variable) navbar height —
       a hardcoded 64px left a 14px gap under the slimmed 50px mobile bar. */
    .main-content {
        padding: 1rem;
        margin-top: var(--navbar-height);
        min-height: calc(100vh - var(--navbar-height));
    }

    /* 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) {
    /* Tables that are NOT card-view (wide sheets) must be able to scroll
       sideways — overflow:visible here silently CLIPPED them against the
       body's overflow-x:hidden (the "unreachable data" bug). */
    .table-responsive {
        border: none;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Transform table to cards on mobile — dense: ~8-10 records per screen */
    .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: var(--card-bg, #fff);
        border: 1px solid rgba(30, 86, 49, 0.10);
        border-radius: 10px;
        margin-bottom: 0.5rem;
        padding: 0.5rem 0.75rem;
        box-shadow: 0 1px 2px rgba(30, 86, 49, 0.04);
    }

    .table.mobile-card-view td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        gap: 0.5rem;
        padding: 0.22rem 0;
        border: none;
        font-size: 0.85rem;
        text-align: right;
    }

    .table.mobile-card-view td::before {
        content: attr(data-label);
        font-weight: 600;
        font-size: 0.72rem;
        text-transform: uppercase;
        letter-spacing: 0.04em;
        color: var(--gray-600, #616161);
        margin-right: auto;
        text-align: left;
        flex-shrink: 0;
    }

    .table.mobile-card-view td:first-child {
        font-weight: 600;
        color: var(--brand-green-deep, #1e5631);
    }

    .table.mobile-card-view .btn-group,
    .table.mobile-card-view .sqa-group {
        flex-direction: row;
        gap: 0.4rem;
    }

    [data-theme="dark"] .table.mobile-card-view tr {
        background: var(--gray-100, #1c2a22);
        border-color: rgba(255, 255, 255, 0.08);
    }
    [data-theme="dark"] .table.mobile-card-view td:first-child { color: #cfe3d6; }
}

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

@media (max-width: 767.98px) {
    /* 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: 576px) {
    .modal-footer .btn {
        width: auto;
        margin: 0 0.25rem;
    }

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

/* Wide modals should use the available width on tablet/medium screens.
   Bootstrap only reaches modal-lg's 800px at ≥992px and modal-xl's 1140px at ≥1200px;
   between 576–1199px both fall back to ~500px, wasting side space and clipping wide
   tables/ledger rows. (≤575px is already full-screen above.) Cap on large monitors. */
@media (min-width: 576px) {
    .modal-lg { max-width: min(900px, 96vw); }
    .modal-xl { max-width: min(1500px, 96vw); }
}


/* ============================================================================
   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: 44px;
        min-height: 44px;
    }

    /* 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) {
    /* 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;
    }
}

/* ============================================================================
   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;
    }

}

/* ============================================================================
   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;
    }
}

/* ============================================================================
   LOGIN PAGE MOBILE
   ============================================================================ */

@media (max-width: 575.98px) {
    .login-page {
        padding: 0.75rem;
    }

    .login-card {
        padding: 1.75rem;
        border-radius: 16px;
    }

    .login-title {
        font-size: 1.5rem;
    }

    .login-logo {
        height: 64px;
    }
}

/* ============================================================================
   EMPTY STATE MOBILE
   ============================================================================ */

@media (max-width: 575.98px) {
    .empty-state-container {
        min-height: 300px;
        padding: 1.5rem;
    }

    .empty-state-icon {
        width: 64px;
        height: 64px;
        font-size: 1.5rem;
    }

    .empty-state-container h3 {
        font-size: 1.25rem;
    }
}

/* ============================================================================
   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;
    }

    [data-theme="dark"] thead th {
        background-color: var(--gray-100, #1c2a22);
    }

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

}

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

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

/* ============================================================================
   COMPACT PAGE HEROES (phones) — one line of identity, no lead/meta.
   Reference: StaffAttendanceMain's .sa-hero (the mobile-first surface).
   ============================================================================ */
@media (max-width: 767.98px) {
    /* Dashboard's green band shrinks to a single-line strip */
    .dashboard-header {
        padding: 0.75rem 1rem;
        border-radius: 12px;
        margin-bottom: 0.9rem;
    }
    .dashboard-header h2 { font-size: 1.1rem; gap: 0.5rem; margin-bottom: 0; }
    .dashboard-header p,
    .dashboard-header .dashboard-date { display: none; }
    .dashboard-header::after { display: none; }

    /* Bootstrap-only page headers (Fees, Students, System Health, Classes) */
    .page-header { flex-wrap: wrap; gap: 0.5rem; margin-bottom: 1rem !important; }
    .page-header h2 { font-size: 1.15rem; margin-bottom: 0; }
    .page-header .btn { padding: 0.45rem 0.7rem; font-size: 0.82rem; }
}

/* ============================================================================
   SWIPEABLE TAB STRIP (phones + tablets) — one row, momentum scroll,
   gold underline on the active tab. Half-visible last chip = scroll hint.
   ============================================================================ */
@media (max-width: 991.98px) {
    .nav-tabs {
        flex-direction: row;
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        border-bottom: 1px solid var(--gray-200, #e0e0e0);
        border-right: none;
        gap: 0.25rem;
        margin-bottom: 1rem;
        padding-right: 24px;
        mask-image: linear-gradient(to right, #000 calc(100% - 24px), transparent);
        -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 24px), transparent);
    }
    .nav-tabs::-webkit-scrollbar { display: none; }
    .nav-tabs .nav-item { width: auto; flex: 0 0 auto; }
    .nav-tabs .nav-link {
        white-space: nowrap;
        border: none;
        border-bottom: 2px solid transparent;
        border-radius: 8px 8px 0 0;
        padding: 0.55rem 0.8rem;
        min-height: 44px;
        font-size: 0.875rem;
        display: flex;
        align-items: center;
        gap: 0.4rem;
    }
    /* Suppress the desktop tabs' green->gold ::after bar — the strip's gold
       border-bottom is the single active signal under 992px. */
    .nav-tabs .nav-link::after { display: none; }
    .nav-tabs .nav-link.active {
        background: transparent;
        color: var(--brand-green-deep, #1e5631);
        border-bottom: 2px solid var(--brand-gold, #d4a53a);
        font-weight: 600;
    }
    [data-theme="dark"] .nav-tabs .nav-link.active {
        background: transparent;
        border-color: transparent;
        border-bottom: 2px solid var(--brand-gold, #d4a53a);
        color: var(--brand-gold-light, #e6c563);
    }
}

/* Folding filter card (phone disclosure row). Desktop unaffected (d-md-block). */
.filter-fold-toggle {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    width: 100%;
    min-height: 48px;
    padding: 0.65rem 1rem;
    background: none;
    border: none;
    color: var(--brand-green-deep, #1e5631);
    font-weight: 600;
    font-size: 0.9rem;
}
.filter-fold-toggle .filter-fold-chevron { margin-left: auto; opacity: 0.55; }
.filter-fold-count {
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    border-radius: 10px;
    background: var(--brand-gold-subtle, #fef9f0);
    border: 1px solid var(--brand-gold, #d4a53a);
    color: var(--brand-gold-dark, #b8912e);
    font-size: 0.72rem;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
[data-theme="dark"] .filter-fold-toggle { color: #cfe3d6; }
[data-theme="dark"] .filter-fold-count {
    background: rgba(212, 165, 58, 0.12);
    color: var(--brand-gold-light, #e6c563);
}

/* ============================================================================
   FROZEN-FIRST-COLUMN WIDE GRIDS — sticky name column + right-edge scroll hint
   (pattern proven by StaffAttendanceCalendar).
   Apply .sheet-scroll on the overflow wrapper; .sheet-sticky-col on the first
   th/td of each row.
   ============================================================================ */
.sheet-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    position: relative;
}
.sheet-scroll::after {
    content: '';
    position: sticky;
    right: 0;
    top: 0;
}
.sheet-sticky-col {
    position: sticky;
    left: 0;
    z-index: 5;
    background: var(--card-bg, #fff);
    box-shadow: 2px 0 4px rgba(30, 86, 49, 0.08);
}
thead .sheet-sticky-col {
    z-index: 11;
    background: var(--brand-green-deep, #1e5631);
}
[data-theme="dark"] .sheet-sticky-col { background: var(--gray-100, #1c2a22); }
[data-theme="dark"] thead .sheet-sticky-col { background: var(--brand-green-deep, #1e5631); }
