/**
 * VFA Christian College LMS — Responsive Design System
 * Breakpoints: mobile ≤575px | tablet 576–991px | desktop ≥992px
 */

:root {
    --bsa-theme: #078f72;
    --bsa-theme-dark: #067a62;
    --bsa-bg: #f5f7fb;
    --bsa-safe-top: env(safe-area-inset-top, 0px);
    --bsa-safe-bottom: env(safe-area-inset-bottom, 0px);
    --bsa-safe-left: env(safe-area-inset-left, 0px);
    --bsa-safe-right: env(safe-area-inset-right, 0px);
    --bsa-bottom-nav-height: 64px;
    --bsa-touch-min: 44px;
    --bsa-sticky-top-height: 56px;
}

/* ─── Global portal shell ─── */
body.portal-responsive {
    background: var(--bsa-bg);
}

body.portal-responsive.has-bottom-nav {
    padding-bottom: calc(var(--bsa-bottom-nav-height) + var(--bsa-safe-bottom));
}

body.portal-responsive .main-content {
    min-height: 100vh;
    min-height: 100dvh;
}

body.portal-responsive .topbar {
    position: sticky;
    top: 0;
    z-index: 900;
    background: #fff;
    padding-top: calc(0.75rem + var(--bsa-safe-top));
    padding-left: calc(1rem + var(--bsa-safe-left));
    padding-right: calc(1rem + var(--bsa-safe-right));
}

body.portal-responsive .content-area {
    padding-left: calc(1rem + var(--bsa-safe-left));
    padding-right: calc(1rem + var(--bsa-safe-right));
}

/* Dashboard stat grids */
.bsa-dash-grid {
    display: grid;
    gap: 1rem;
    grid-template-columns: repeat(4, 1fr);
}

.bsa-dash-grid-auto {
    display: grid;
    gap: 1rem;
    grid-template-columns: repeat(auto-fit, minmax(155px, 1fr));
}

.bsa-dash-grid-3 {
    display: grid;
    gap: 1rem;
    grid-template-columns: repeat(3, 1fr);
}

.bsa-stat-card {
    border-radius: 0.75rem;
    border: 1px solid #e8ecf1;
    background: #fff;
    padding: 1.25rem;
    height: 100%;
}

/* Touch-friendly controls */
.btn-touch,
body.portal-responsive .btn {
    min-height: var(--bsa-touch-min);
}

body.portal-responsive .form-control,
body.portal-responsive .form-select {
    min-height: var(--bsa-touch-min);
}

body.portal-responsive input[type="file"].form-control {
    padding: 0.5rem 0.75rem;
}

/* ─── Sidebar overlay (mobile / tablet) ─── */
.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 999;
    opacity: 0;
    transition: opacity 0.25s ease;
}

.sidebar-backdrop.show {
    display: block;
    opacity: 1;
}

body.sidebar-open {
    overflow: hidden;
}

/* ─── Responsive tables → cards on mobile ─── */
.bsa-table-responsive {
    width: 100%;
}

.bsa-table-cards {
    width: 100%;
}

.bsa-table-card {
    background: #fff;
    border: 1px solid #e8ecf1;
    border-radius: 0.75rem;
    padding: 1rem;
    margin-bottom: 0.75rem;
}

.bsa-table-card-row {
    display: flex;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.35rem 0;
    border-bottom: 1px dashed #eef1f5;
    font-size: 0.9rem;
}

.bsa-table-card-row:last-child {
    border-bottom: none;
}

.bsa-table-card-label {
    color: #6c757d;
    font-weight: 600;
    flex-shrink: 0;
    max-width: 45%;
}

.bsa-table-card-value {
    text-align: right;
    word-break: break-word;
}

/* ─── Responsive form layout ─── */
.bsa-form-grid {
    display: grid;
    gap: 1rem;
    grid-template-columns: repeat(2, 1fr);
}

.bsa-form-grid .bsa-form-full {
    grid-column: 1 / -1;
}

/* ─── Student mobile bottom navigation ─── */
.mobile-bottom-nav {
    display: none;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1100;
    background: #fff;
    border-top: 1px solid #e8ecf1;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.06);
    padding-bottom: var(--bsa-safe-bottom);
    height: calc(var(--bsa-bottom-nav-height) + var(--bsa-safe-bottom));
}

.mobile-bottom-nav-inner {
    display: flex;
    align-items: stretch;
    justify-content: space-around;
    height: var(--bsa-bottom-nav-height);
    max-width: 520px;
    margin: 0 auto;
}

.mobile-bottom-nav a,
.mobile-bottom-nav button.mobile-bottom-nav-install {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.15rem;
    text-decoration: none;
    color: #6c757d;
    font-size: 0.62rem;
    font-weight: 600;
    padding: 0.35rem 0.1rem;
    min-height: var(--bsa-touch-min);
    transition: color 0.15s ease;
    background: transparent;
    border: none;
    cursor: pointer;
    min-width: 0;
}

.mobile-bottom-nav a i,
.mobile-bottom-nav button.mobile-bottom-nav-install i {
    font-size: 1.15rem;
    line-height: 1;
}

.mobile-bottom-nav a span,
.mobile-bottom-nav button.mobile-bottom-nav-install span {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.mobile-bottom-nav a.active {
    color: var(--bsa-theme);
}

.mobile-bottom-nav a.active i,
.mobile-bottom-nav button.mobile-bottom-nav-install.active i {
    color: var(--bsa-theme);
}

.mobile-bottom-nav button.mobile-bottom-nav-install:not(.d-none) {
    color: var(--bsa-theme);
}

/* ─── Timetable / lecture cards on mobile ─── */
.bsa-timetable-cards .timetable-card,
.bsa-lecture-card {
    border: 1px solid #e8ecf1;
    border-radius: 0.75rem;
    background: #fff;
    padding: 1rem;
    margin-bottom: 0.75rem;
}

/* ─── Payment mobile layout ─── */
.bsa-payment-mobile .payment-summary-card {
    border-radius: 0.75rem;
    border: 1px solid #e8ecf1;
    background: #fff;
    padding: 1.25rem;
}

body.portal-responsive #statementSemesterSelect {
    min-width: 0 !important;
    width: 100%;
    max-width: 100%;
}

.bsa-payment-mobile .pay-tuition-cta-btn,
.bsa-payment-mobile .btn-pay {
    width: 100%;
}

@media (min-width: 576px) {
    .bsa-payment-mobile .pay-tuition-cta-btn,
    .bsa-payment-mobile .btn-pay {
        width: auto;
    }
}

/* ─── Exam upload mobile ─── */
.bsa-exam-upload-mobile .upload-zone {
    border: 2px dashed #c5d0dc;
    border-radius: 0.75rem;
    padding: 2rem 1rem;
    text-align: center;
    background: #fafbfc;
}

.bsa-exam-upload-mobile .upload-zone i {
    font-size: 2.5rem;
    color: var(--bsa-theme);
}

/* Login page — layout in assets/css/login.css */
body.login-body.portal-responsive {
    min-height: 100vh;
    min-height: 100dvh;
}
body.pwa-standalone .topbar {
    padding-top: calc(0.5rem + var(--bsa-safe-top));
}

body.pwa-standalone .portal-footer {
    display: none;
}

/* ─── Website public frontend ─── */
body.bsa-website {
    padding-bottom: var(--bsa-safe-bottom);
}

body.bsa-website .navbar {
    padding-top: calc(0.5rem + var(--bsa-safe-top));
}

body.bsa-website .form-card {
    border-radius: 0.85rem;
}

body.bsa-website .bsa-admission-form .form-control,
body.bsa-website .bsa-admission-form .form-select,
body.bsa-website .bsa-contact-form .form-control,
body.bsa-website .bsa-contact-form .form-select,
body.bsa-website .bsa-contact-form .btn {
    min-height: var(--bsa-touch-min);
}

body.bsa-website .bsa-admission-form .btn[type="submit"],
body.bsa-website .bsa-contact-form button[type="submit"] {
    font-weight: 600;
    padding: 0.85rem 1rem;
}

.bsa-upload-zone .form-control[type="file"] {
    border: none;
    background: transparent;
    padding: 0.5rem 0;
}

body.portal-responsive .bsa-upload-zone,
body.bsa-website .bsa-upload-zone {
    border: 2px dashed #c5d0dc;
    border-radius: 0.75rem;
    padding: 1rem;
    background: #fafbfc;
    text-align: center;
}

body.portal-responsive .bsa-exam-upload-mobile .bsa-upload-zone {
    margin-bottom: 0.5rem;
}

/* Website sticky mobile CTA */
.website-mobile-cta {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1050;
    display: flex;
    gap: 0.5rem;
    padding: 0.55rem 0.75rem calc(0.55rem + var(--bsa-safe-bottom));
    background: rgba(255, 255, 255, 0.97);
    border-top: 1px solid #e8ecf1;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.08);
    backdrop-filter: blur(8px);
}

body.bsa-website.has-mobile-cta {
    padding-bottom: calc(4.25rem + var(--bsa-safe-bottom));
}

.website-mobile-cta .btn {
    min-height: var(--bsa-touch-min);
    font-weight: 600;
    font-size: 0.9rem;
}

@media (min-width: 992px) {
    .website-mobile-cta {
        display: none !important;
    }

    body.bsa-website.has-mobile-cta {
        padding-bottom: var(--bsa-safe-bottom);
    }
}

.bsa-upload-zone-label {
    display: block;
    font-weight: 600;
    margin-bottom: 0.35rem;
    font-size: 0.9rem;
}

.bsa-upload-zone-hint {
    font-size: 0.8rem;
    color: #6c757d;
    margin-bottom: 0.5rem;
}

/* PWA install banner */
.pwa-install-banner {
    background: linear-gradient(135deg, #078f72 0%, #067a62 100%);
    color: #fff;
    border-radius: 0.75rem;
    margin-bottom: 1rem;
    box-shadow: 0 4px 16px rgba(7, 143, 114, 0.25);
}

.pwa-install-banner-inner {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.75rem 1rem;
    padding: 0.85rem 1rem;
}

.pwa-install-icon {
    width: 42px;
    height: 42px;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    flex-shrink: 0;
}

.pwa-install-text {
    flex: 1;
    min-width: 180px;
    font-size: 0.9rem;
    line-height: 1.35;
}

.pwa-install-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.35rem 0.5rem;
    margin-left: auto;
}

.pwa-install-dismiss {
    text-decoration: none !important;
    opacity: 0.9;
}

@media (max-width: 575.98px) {
    body.bsa-website .bsa-admission-form .row.g-3 > [class*="col-"] {
        flex: 0 0 100%;
        max-width: 100%;
    }

    .pwa-install-actions {
        width: 100%;
        margin-left: 0;
    }

    .pwa-install-actions .btn-light {
        flex: 1;
        min-height: var(--bsa-touch-min);
    }
}

/* ═══════════════════════════════════════
   TABLET: 576px – 991.98px
   ═══════════════════════════════════════ */
@media (min-width: 576px) and (max-width: 991.98px) {
    .bsa-dash-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .bsa-dash-grid-3 {
        grid-template-columns: repeat(2, 1fr);
    }

    body.portal-responsive .content-area {
        padding-left: calc(1.25rem + var(--bsa-safe-left));
        padding-right: calc(1.25rem + var(--bsa-safe-right));
    }

    .bsa-calendar-weekly .fc-toolbar {
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .table-responsive {
        -webkit-overflow-scrolling: touch;
    }
}

/* ═══════════════════════════════════════
   MOBILE: max 575.98px
   ═══════════════════════════════════════ */
@media (max-width: 575.98px) {
    .bsa-dash-grid {
        grid-template-columns: 1fr;
    }

    .bsa-dash-grid-3 {
        grid-template-columns: 1fr;
    }

    .bsa-dash-grid-auto {
        grid-template-columns: repeat(2, 1fr);
    }

    .bsa-form-grid {
        grid-template-columns: 1fr;
    }

    body.portal-responsive .topbar {
        padding: calc(0.5rem + var(--bsa-safe-top)) calc(0.75rem + var(--bsa-safe-right)) 0.5rem calc(0.75rem + var(--bsa-safe-left));
    }

    body.portal-responsive .topbar .page-heading {
        font-size: 1rem;
        line-height: 1.25;
    }

    body.portal-responsive .content-area {
        padding: 0.75rem calc(0.75rem + var(--bsa-safe-right)) 1rem calc(0.75rem + var(--bsa-safe-left));
    }

    body.portal-responsive .card {
        border-radius: 0.75rem;
    }

    body.portal-responsive .card-body {
        padding: 1rem;
    }

    /* Hide table, show card view */
    .bsa-table-cards-mode table.bsa-responsive-table {
        display: none;
    }

    .bsa-table-cards-mode .bsa-table-card-view {
        display: block;
    }

    .bsa-table-card-view {
        display: none;
    }

    /* Student bottom nav visible */
    body.vclass-layout .mobile-bottom-nav {
        display: block;
    }

    body.vclass-layout.has-bottom-nav .portal-footer {
        margin-bottom: var(--bsa-bottom-nav-height);
    }

    /* Offcanvas sidebar */
    body.portal-responsive .sidebar {
        transform: translateX(-100%);
        width: min(88vw, 300px);
        z-index: 1001;
        box-shadow: 4px 0 24px rgba(0, 0, 0, 0.15);
    }

    body.portal-responsive .sidebar.show {
        transform: translateX(0);
    }

    body.portal-responsive .main-content {
        margin-left: 0 !important;
    }

    body.portal-responsive .btn-logout {
        display: none !important;
    }

    .admin-search-form {
        display: none !important;
    }

    /* Stack action button groups on mobile */
    .card-header-custom {
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .card-header-custom .btn-group {
        flex-wrap: wrap;
        max-width: 100%;
    }

    .card-header-custom .btn-group .btn {
        flex: 1 1 auto;
        min-width: 0;
    }

    .bsa-filter-tabs {
        display: flex;
        flex-wrap: wrap;
        gap: 0.35rem;
        width: 100%;
    }

    .bsa-filter-tabs .btn {
        flex: 1 1 calc(50% - 0.35rem);
        min-width: 0;
    }

    .bsa-actions-mobile-stack {
        display: flex;
        flex-direction: column;
        gap: 0.5rem;
    }

    .bsa-actions-mobile-stack .btn {
        width: 100%;
    }

    /* Finance / admin table horizontal scroll fallback */
    .bsa-table-scroll-mobile .table-responsive {
        margin: 0 -0.75rem;
        padding: 0 0.75rem;
    }
}

/* ═══════════════════════════════════════
   DESKTOP: min 992px
   ═══════════════════════════════════════ */
@media (min-width: 992px) {
    .bsa-dash-grid {
        grid-template-columns: repeat(4, 1fr);
    }

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

    body.portal-responsive .sidebar-backdrop {
        display: none !important;
    }
}

/* Tablet sidebar collapsible */
@media (min-width: 576px) and (max-width: 991.98px) {
    body.portal-responsive .sidebar {
        transform: translateX(-100%);
        z-index: 1001;
    }

    body.portal-responsive .sidebar.show {
        transform: translateX(0);
    }

    body.portal-responsive .main-content {
        margin-left: 0 !important;
    }
}

/* Reports & analytics */
.bsa-report-tabs-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.bsa-report-tabs {
    gap: 0.35rem;
    padding-bottom: 0.25rem;
    min-width: max-content;
}

.bsa-report-tabs .nav-link {
    white-space: nowrap;
    font-size: 0.875rem;
}

.bsa-report-bars {
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
}

.bsa-report-bar-row {
    display: grid;
    grid-template-columns: minmax(72px, 110px) 1fr auto;
    gap: 0.5rem;
    align-items: center;
}

.bsa-report-bar-label {
    font-size: 0.8125rem;
    color: var(--bs-secondary-color, #6c757d);
}

.bsa-report-bar-track {
    height: 8px;
    background: rgba(0, 0, 0, 0.06);
    border-radius: 999px;
    overflow: hidden;
}

.bsa-report-bar-fill {
    height: 100%;
    border-radius: 999px;
    min-width: 2px;
}

.bsa-report-bar-value {
    font-size: 0.8125rem;
    font-weight: 600;
    white-space: nowrap;
}

@media (max-width: 575.98px) {
    .bsa-report-bar-row {
        grid-template-columns: 1fr;
        gap: 0.25rem;
    }

    .bsa-report-bar-value {
        text-align: left;
    }
}

@media print {
    .sidebar,
    .topbar,
    .mobile-bottom-nav,
    .bsa-report-tabs-wrap,
    .btn,
    form {
        display: none !important;
    }

    .main-content {
        margin: 0 !important;
        padding: 0 !important;
    }
}

/* Brand logos — responsive sizing */
.logo,
.site-logo,
.navbar-logo,
.portal-logo {
    max-width: 100%;
    height: auto;
    object-fit: contain;
}

.login-logo img,
.login-logo .site-logo,
.login-brand-logo {
    max-width: 100%;
    height: auto;
    object-fit: contain;
}

@media (max-width: 991.98px) {
    .navbar-logo,
    .sidebar-brand .site-logo,
    .content-card .navbar-logo {
        max-height: 52px;
    }

    .login-logo img,
    .login-logo .site-logo,
    .login-brand-logo,
    .portal-logo {
        max-height: 100px;
    }
}

@media (max-width: 575.98px) {
    .navbar-logo,
    .sidebar-brand .site-logo {
        max-height: 48px;
    }

    .login-logo img,
    .login-logo .site-logo,
    .login-brand-logo,
    .portal-logo {
        max-height: 88px;
    }
}
