/* Lukenya Premier Academy — mobile app shell (phones & small tablets) */

:root {
    --mobile-nav-h: 4.25rem;
    --mobile-header-h: 3.5rem;
    --mobile-safe-bottom: env(safe-area-inset-bottom, 0px);
    --mobile-safe-top: env(safe-area-inset-top, 0px);
}

.mobile-only {
    display: none;
}

.mobile-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(7, 20, 40, 0.55);
    backdrop-filter: blur(2px);
    z-index: 1040;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.22s ease;
}

.mobile-overlay.is-visible {
    opacity: 1;
    pointer-events: auto;
}

.mobile-topbar {
    display: none;
}

.mobile-bottom-nav {
    display: none;
}

@media (max-width: 900px) {
    .mobile-only {
        display: flex;
    }

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

    body.app-mobile {
        overscroll-behavior-y: none;
    }

    body.drawer-open {
        overflow: hidden;
    }

    .mobile-sidebar-close {
        position: absolute;
        top: calc(0.65rem + var(--mobile-safe-top));
        right: 0.75rem;
        z-index: 2;
    }

    .shell {
        display: block;
        min-height: 100vh;
        min-height: 100dvh;
    }

    .mobile-overlay {
        display: block;
    }

    .sidebar {
        position: fixed;
        padding-top: calc(2.75rem + var(--mobile-safe-top));
        top: 0;
        left: 0;
        bottom: 0;
        width: min(86vw, 320px);
        min-height: 100dvh;
        z-index: 1050;
        transform: translateX(-105%);
        transition: transform 0.24s ease;
        box-shadow: 0 0 0 rgba(0, 0, 0, 0);
        overflow-y: auto;
    }

    .sidebar.is-open {
        transform: translateX(0);
        box-shadow: 0 24px 80px rgba(0, 0, 0, 0.35);
    }

    .main {
        padding: 0.75rem;
        padding-top: calc(var(--mobile-header-h) + var(--mobile-safe-top) + 0.5rem);
        padding-bottom: calc(var(--mobile-nav-h) + var(--mobile-safe-bottom) + 1rem);
        min-height: 100dvh;
    }

    .topbar.topbar-elevated {
        display: none;
    }

    .mobile-topbar {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 0.75rem;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        z-index: 1030;
        min-height: calc(var(--mobile-header-h) + var(--mobile-safe-top));
        padding: calc(0.55rem + var(--mobile-safe-top)) 0.75rem 0.55rem;
        background: rgba(255, 255, 255, 0.94);
        backdrop-filter: blur(12px);
        border-bottom: 1px solid var(--border);
    }

    .mobile-topbar-brand {
        display: flex;
        align-items: center;
        gap: 0.65rem;
        min-width: 0;
        flex: 1;
    }

    .mobile-topbar-brand img {
        width: 36px;
        height: 36px;
        object-fit: contain;
        flex-shrink: 0;
    }

    .mobile-topbar-brand strong {
        display: block;
        font-size: 0.95rem;
        line-height: 1.2;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .mobile-topbar-brand small {
        display: block;
        color: var(--muted);
        font-size: 0.72rem;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .mobile-icon-btn {
        width: 2.75rem;
        height: 2.75rem;
        border: 1px solid var(--border);
        border-radius: 12px;
        background: var(--surface);
        color: var(--text);
        display: inline-flex;
        align-items: center;
        justify-content: center;
        font-size: 1.15rem;
        cursor: pointer;
        flex-shrink: 0;
        -webkit-tap-highlight-color: transparent;
    }

    .mobile-icon-btn:active {
        transform: scale(0.97);
        background: var(--surface-alt);
    }

    .mobile-bottom-nav {
        display: grid;
        grid-auto-flow: column;
        grid-auto-columns: 1fr;
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 1035;
        min-height: calc(var(--mobile-nav-h) + var(--mobile-safe-bottom));
        padding: 0.35rem 0.35rem calc(0.35rem + var(--mobile-safe-bottom));
        background: rgba(255, 255, 255, 0.96);
        backdrop-filter: blur(14px);
        border-top: 1px solid var(--border);
        box-shadow: 0 -8px 32px rgba(7, 20, 40, 0.08);
    }

    .mobile-bottom-nav a {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 0.15rem;
        padding: 0.35rem 0.2rem;
        border-radius: 12px;
        color: var(--muted);
        font-size: 0.62rem;
        font-weight: 600;
        text-align: center;
        line-height: 1.15;
        min-height: 3.25rem;
        -webkit-tap-highlight-color: transparent;
    }

    .mobile-bottom-nav a .nav-icon {
        width: 1.65rem;
        height: 1.65rem;
        font-size: 1.05rem;
        background: transparent;
        border-radius: 8px;
    }

    .mobile-bottom-nav a.active {
        color: var(--primary);
        background: var(--primary-soft);
    }

    .flash-stack {
        margin-bottom: 0.75rem;
    }

    .panel {
        padding: 1rem;
        border-radius: 18px;
    }

    .erp-titlebar,
    .module-hero-header,
    .section-header {
        gap: 0.75rem;
    }

    .erp-titlebar h2,
    .erp-titlebar h3,
    .module-hero-header h2 {
        font-size: 1.15rem;
    }

    .metric-row,
    .dashboard-card-grid,
    .module-quick-actions,
    .card-grid,
    .finance-exec-grid,
    .invoice-exec-grid {
        grid-template-columns: 1fr !important;
    }

    .dashboard-card,
    .invoice-exec-card,
    .finance-learner-chip {
        min-height: 48px;
    }

    .form-grid {
        grid-template-columns: 1fr !important;
        gap: 0.85rem;
    }

    .form-grid label span,
    .form-grid .checkbox-label span {
        font-size: 0.88rem;
        font-weight: 600;
    }

    .form-grid input,
    .form-grid select,
    .form-grid textarea,
    .finance-filter-chips select,
    .residence-area-select {
        width: 100%;
        min-height: 48px;
        font-size: 16px;
        border-radius: 12px;
        padding: 0.7rem 0.85rem;
    }

    .form-grid textarea {
        min-height: 120px;
    }

    .form-grid .full-span,
    .comm-compose-form .full-span {
        grid-column: 1 / -1;
    }

    .mobile-sticky-actions {
        position: sticky;
        bottom: calc(var(--mobile-nav-h) + var(--mobile-safe-bottom) + 0.5rem);
        z-index: 1020;
        display: grid;
        gap: 0.5rem;
        padding-top: 0.5rem;
        margin-top: 0.5rem;
        background: linear-gradient(180deg, rgba(255, 255, 255, 0), rgba(255, 255, 255, 0.95) 24%);
    }

    .form-grid > button,
    .form-grid .marks-save-btn,
    .mobile-sticky-actions button,
    .action-link,
    .table-action {
        min-height: 48px;
        font-size: 1rem;
        border-radius: 14px;
        touch-action: manipulation;
    }

    .form-grid > button,
    .form-grid .marks-save-btn {
        width: 100%;
    }

    .table-wrap {
        overflow: visible;
    }

    table.data-table:not(.mobile-table-keep) {
        border: 0;
    }

    table.data-table:not(.mobile-table-keep) thead {
        display: none;
    }

    table.data-table:not(.mobile-table-keep) tbody {
        display: grid;
        gap: 0.75rem;
    }

    table.data-table:not(.mobile-table-keep) tr {
        display: block;
        background: var(--surface);
        border: 1px solid var(--border);
        border-radius: 16px;
        padding: 0.85rem 1rem;
        box-shadow: var(--shadow-soft);
    }

    table.data-table:not(.mobile-table-keep) td {
        display: flex;
        align-items: flex-start;
        justify-content: space-between;
        gap: 1rem;
        padding: 0.45rem 0;
        border: 0;
        font-size: 0.92rem;
    }

    table.data-table:not(.mobile-table-keep) td::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--muted);
        font-size: 0.78rem;
        flex: 0 0 42%;
        max-width: 42%;
    }

    table.data-table:not(.mobile-table-keep) td.mobile-card-title {
        display: block;
        padding-bottom: 0.55rem;
        margin-bottom: 0.35rem;
        border-bottom: 1px solid var(--border);
        font-size: 1rem;
        font-weight: 700;
    }

    table.data-table:not(.mobile-table-keep) td.mobile-card-title::before {
        display: none;
    }

    table.data-table:not(.mobile-table-keep) td.mobile-card-actions {
        display: flex;
        flex-wrap: wrap;
        gap: 0.5rem;
        padding-top: 0.55rem;
        margin-top: 0.35rem;
        border-top: 1px solid var(--border);
    }

    table.data-table:not(.mobile-table-keep) td.mobile-card-actions::before {
        display: none;
    }

    .comm-workspace.grid.two {
        grid-template-columns: 1fr !important;
    }

    .comm-message-list {
        max-height: none;
    }

    .finance-portal-hero,
    .finance-executive-strip {
        grid-template-columns: 1fr 1fr !important;
    }

    .finance-portal-balance-card {
        grid-column: 1 / -1;
    }

    .finance-learner-scroll {
        display: flex;
        overflow-x: auto;
        gap: 0.65rem;
        padding-bottom: 0.25rem;
        scroll-snap-type: x mandatory;
        -webkit-overflow-scrolling: touch;
    }

    .finance-learner-chip {
        scroll-snap-align: start;
        min-width: 11rem;
    }

    .marks-entry-grid input[type="number"],
    .marks-entry-grid input[type="text"] {
        min-height: 44px;
        font-size: 16px;
    }

    .attendance-status-toggle label {
        min-height: 44px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        padding: 0.5rem 0.75rem;
    }

    .pwa-install-banner {
        bottom: calc(var(--mobile-nav-h) + var(--mobile-safe-bottom) + 0.5rem);
    }
}

@media (max-width: 900px) {
    .auth-shell {
        min-height: 100dvh;
    }

    .auth-main {
        padding: 1rem;
        padding-bottom: calc(1rem + var(--mobile-safe-bottom));
    }

    .auth-panel {
        border-radius: 20px;
    }

    .auth-panel input {
        min-height: 48px;
        font-size: 16px;
    }

    .auth-panel button {
        min-height: 50px;
        font-size: 1rem;
        border-radius: 14px;
    }
}

@media (min-width: 901px) {
    .mobile-overlay,
    .mobile-topbar,
    .mobile-bottom-nav {
        display: none !important;
    }
}
