/* ========================= */
/* MOBILE & RESPONSIVE       */
/* ========================= */

html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

body {
    overflow-x: hidden;
}

body.nav-open {
    overflow: hidden;
}

/* Mobile menu toggle */
.mobile-menu-btn {
    display: none;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    margin-right: 8px;
    padding: 0;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    background: #fff;
    cursor: pointer;
    flex-shrink: 0;
    -webkit-tap-highlight-color: transparent;
}

.mobile-menu-btn .hamburger-icon,
.mobile-menu-btn .hamburger-icon::before,
.mobile-menu-btn .hamburger-icon::after {
    display: block;
    width: 20px;
    height: 2px;
    background: #111;
    border-radius: 2px;
    position: relative;
    transition: transform 0.2s ease, opacity 0.2s ease;
}

.mobile-menu-btn .hamburger-icon::before,
.mobile-menu-btn .hamburger-icon::after {
    content: "";
    position: absolute;
    left: 0;
}

.mobile-menu-btn .hamburger-icon::before {
    top: -6px;
}

.mobile-menu-btn .hamburger-icon::after {
    top: 6px;
}

.layout.sidebar-open .mobile-menu-btn .hamburger-icon {
    background: transparent;
}

.layout.sidebar-open .mobile-menu-btn .hamburger-icon::before {
    top: 0;
    transform: rotate(45deg);
}

.layout.sidebar-open .mobile-menu-btn .hamburger-icon::after {
    top: 0;
    transform: rotate(-45deg);
}

.sidebar-overlay {
    display: none;
}

.topbar-left {
    display: flex;
    align-items: center;
    min-width: 0;
}

.topbar-app-title {
    display: none;
    font-size: 14px;
    font-weight: 600;
    color: #111;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.pwa-install-btn {
    display: none;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    border-radius: 10px;
    border: 1px solid #ff7a00;
    background: #fff7ed;
    color: #c2410c;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    flex-shrink: 0;
}

.pwa-install-btn[hidden] {
    display: none !important;
}

.pwa-install-btn:not([hidden]) {
    display: inline-flex;
}

/* Tablet and below */
@media (max-width: 1024px) {
    .kpi-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .form-grid,
    .form-grid2 {
        grid-template-columns: repeat(2, 1fr);
    }

    .card-grid--student-metrics {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}

/* Mobile */
@media (max-width: 900px) {
    .mobile-menu-btn {
        display: inline-flex;
    }

    .topbar-app-title {
        display: block;
        max-width: min(42vw, 180px);
    }

    .sidebar-overlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.45);
        z-index: 90;
        backdrop-filter: blur(2px);
    }

    .layout.sidebar-open .sidebar-overlay {
        display: block;
    }

    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: min(280px, 88vw);
        min-height: 100vh;
        min-height: 100dvh;
        transform: translateX(-105%);
        transition: transform 0.28s ease;
        z-index: 100;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        padding-bottom: env(safe-area-inset-bottom, 0);
    }

    .layout.sidebar-open .sidebar {
        transform: translateX(0);
    }

    .content-area {
        width: 100%;
        min-width: 0;
    }

    .page {
        padding: 16px;
        padding-left: max(16px, env(safe-area-inset-left));
        padding-right: max(16px, env(safe-area-inset-right));
    }

    .topbar {
        padding: 0 12px;
        padding-top: env(safe-area-inset-top, 0);
        min-height: 52px;
        height: auto;
        flex-wrap: wrap;
        gap: 8px;
    }

    .user-info strong {
        max-width: 120px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        display: block;
    }

    .kpi-grid {
        grid-template-columns: 1fr 1fr;
        gap: 12px;
    }

    .kpi h2 {
        font-size: 22px;
    }

    .form-grid,
    .form-grid2 {
        grid-template-columns: 1fr;
        gap: 16px;
    }

    .form-container {
        padding: 20px 16px;
        max-width: 100%;
    }

    .page-header-split {
        flex-direction: column;
        align-items: stretch;
    }

    .page-header-actions {
        width: 100%;
    }

    .header-actions {
        flex-direction: column;
        align-items: stretch;
    }

    .search-bar {
        flex-direction: column;
        width: 100%;
    }

    .search-bar input {
        width: 100%;
    }

    .styled-table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        white-space: nowrap;
    }

    .styled-table thead,
    .styled-table tbody,
    .styled-table tr {
        display: table;
        width: 100%;
        table-layout: auto;
    }

    .table-scroll-wrap {
        max-height: none;
    }

    .toast-container {
        left: 12px;
        right: 12px;
        top: max(12px, env(safe-area-inset-top));
    }

    .toast {
        min-width: 0;
        width: 100%;
    }

    .calendar-grid {
        gap: 4px;
        font-size: 11px;
    }

    .calendar-day {
        min-height: 72px;
    }

    .calendar-day a {
        padding: 4px;
    }

    .feed-wrapper {
        max-width: 100%;
    }

    .student-detail-head {
        flex-direction: column;
    }

    .student-detail-status {
        margin-left: 0;
        align-self: flex-start;
    }

    .modal-box {
        width: min(350px, calc(100vw - 32px));
        margin: 16px;
    }

    .select2-container {
        max-width: 100% !important;
    }
}

@media (max-width: 600px) {
    .kpi-grid {
        grid-template-columns: 1fr;
    }

    .card-grid--student-metrics {
        grid-template-columns: 1fr 1fr;
    }

    .login-container {
        flex-direction: column;
        height: auto;
        min-height: 100vh;
        min-height: 100dvh;
    }

    .login-left,
    .login-right {
        width: 100%;
    }

    .login-left {
        min-height: 28vh;
        padding: 24px;
    }

    .login-right {
        flex: 1;
        padding: 32px 20px 40px;
    }

    .login-logo {
        width: 200px;
    }

    .login-right-content h2 {
        margin-left: 0;
        text-align: center;
        font-size: 22px;
    }

    .login-right form {
        max-width: 100%;
    }

    .brand img {
        width: 120px;
        margin-left: 0;
    }

    .pagination-row {
        flex-wrap: wrap;
        justify-content: center;
    }

    .compact-actions .btn {
        min-width: 0;
        flex: 1 1 auto;
    }

    .pwa-install-btn:not([hidden]) {
        display: none;
    }
}

@media (max-width: 400px) {
    .card-grid--student-metrics {
        grid-template-columns: 1fr;
    }
}

/* Offline fallback page */
.offline-page {
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 24px;
    text-align: center;
    background: var(--light-bg);
}

.offline-page h1 {
    font-size: 1.5rem;
    margin-bottom: 8px;
}

.offline-page p {
    color: #6b7280;
    margin-bottom: 20px;
}

.login-pwa-hint {
    margin-top: 20px;
    text-align: center;
}

.login-pwa-hint .pwa-install-btn:not([hidden]) {
    display: inline-flex;
    width: 100%;
    justify-content: center;
}
