/**
 * EduSync — Global Responsive Layer
 * Applies to ALL authenticated (_Layout) and public (_PublicLayout) views.
 * Do not duplicate per-page mobile hacks; extend this file instead.
 */

/* ─── Base & overflow ─── */
html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

/* Content images scale; brand logos keep fixed size (see .brand-logo below) */
img:not(.brand-logo):not([width]),
svg:not(.brand-logo):not(.hero-visual-image),
video,
canvas {
    max-width: 100%;
    height: auto;
}

.brand-logo {
    width: auto;
    object-fit: contain;
    flex-shrink: 0;
    display: inline-block;
    vertical-align: middle;
}

.brand-logo--xs {
    height: 28px;
    max-width: 32px;
}

.brand-logo--sm {
    height: 30px;
    max-width: 36px;
}

.brand-logo--md {
    height: 34px;
    max-width: 40px;
}

.brand-logo--lg {
    height: 40px;
    max-width: 48px;
}

@media (min-width: 768px) {
    .brand-logo--md {
        height: 36px;
        max-width: 42px;
    }

    .brand-logo--lg {
        height: 42px;
        max-width: 50px;
    }
}

/* ─── App shell (_Layout) ─── */
@media (max-width: 991.98px) {
    #page-content-wrapper .container-fluid {
        padding-left: 0.75rem !important;
        padding-right: 0.75rem !important;
        padding-top: 1rem !important;
        padding-bottom: 1rem !important;
    }

    #page-content-wrapper .navbar .container-fluid {
        padding-left: 0.75rem;
        padding-right: 0.75rem;
    }

    .navbar .dropdown-menu {
        max-width: calc(100vw - 1.5rem);
    }
}

@media (max-width: 575.98px) {
    #page-content-wrapper .container-fluid {
        padding-left: 0.5rem !important;
        padding-right: 0.5rem !important;
    }

    .footer .container-fluid {
        text-align: center !important;
    }
}

/* ─── Page headers & toolbars ─── */
.page-header,
.profile-header,
[class*="page-header"] {
    flex-wrap: wrap;
    gap: 1rem;
}

@media (max-width: 767.98px) {
    .page-header,
    .profile-header {
        padding: 1.25rem !important;
        border-radius: 1rem !important;
    }

    .page-header h1,
    .page-header h2,
    .profile-header h1 {
        font-size: 1.35rem !important;
    }

    .page-header .btn,
    .profile-header .btn,
    .d-flex.gap-2 .btn,
    .d-flex.gap-3 .btn {
        width: 100%;
        justify-content: center;
    }

    .page-header .d-flex.gap-2,
    .page-header .d-flex.gap-3,
    .profile-header .d-flex.gap-2 {
        width: 100%;
        flex-direction: column;
    }
}

/* Stack header action rows on tablet */
@media (max-width: 991.98px) {
    .d-flex.flex-column.flex-md-row.justify-content-between > .d-flex.gap-2,
    .d-flex.flex-column.flex-md-row.align-items-md-center.justify-content-between > .d-flex.gap-2 {
        flex-wrap: wrap;
        width: 100%;
    }
}

/* ─── Cards & stats ─── */
@media (max-width: 575.98px) {
    .card-body.p-4,
    .card-body.p-5,
    .info-card.p-4,
    .info-card.p-5 {
        padding: 1rem !important;
    }

    .row.g-4 {
        --bs-gutter-y: 1rem;
    }

    .profile-avatar {
        width: 88px !important;
        height: 88px !important;
    }
}

/* ─── Tables ─── */
.edusync-table-wrap,
.table-responsive {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-bottom: 0.5rem;
}

.edusync-table-wrap > table,
.table-responsive > table {
    margin-bottom: 0;
}

@media (max-width: 767.98px) {
    table.table {
        font-size: 0.82rem;
    }

    table.table thead th,
    table.table tbody td {
        padding: 0.65rem 0.5rem !important;
        white-space: nowrap;
    }

    table.table th.ps-4,
    table.table td.ps-4 {
        padding-left: 0.75rem !important;
    }

    table.table th.pe-4,
    table.table td.pe-4 {
        padding-right: 0.75rem !important;
    }

    /* DataTables controls stack */
    .dataTables_wrapper .dataTables_length,
    .dataTables_wrapper .dataTables_filter {
        text-align: left !important;
        margin-bottom: 0.75rem;
    }

    .dataTables_wrapper .dataTables_filter input,
    .dataTables_wrapper .dataTables_length select {
        width: 100% !important;
        max-width: 100% !important;
        margin-left: 0 !important;
    }

    .dataTables_wrapper .row:first-child > [class*="col-"] {
        width: 100%;
    }

    .dataTables_wrapper .dataTables_info,
    .dataTables_wrapper .dataTables_paginate {
        text-align: center !important;
        margin-top: 0.5rem;
    }

    .dataTables_wrapper .dataTables_paginate .pagination {
        justify-content: center;
        flex-wrap: wrap;
    }

    /* Child row details (responsive extension) */
    table.dataTable.dtr-inline.collapsed > tbody > tr > td.dtr-control:before,
    table.dataTable.dtr-inline.collapsed > tbody > tr > th.dtr-control:before {
        line-height: 1.1em;
    }
}

/* Filter chips / pill buttons in table headers */
@media (max-width: 575.98px) {
    .card-header .d-flex.flex-wrap.gap-2 .btn,
    .card-header .d-flex.flex-wrap.gap-2 a.btn {
        flex: 1 1 auto;
        min-width: calc(50% - 0.5rem);
        font-size: 0.75rem;
    }

    .filter-control,
    .w-150px {
        width: 100% !important;
        max-width: 100% !important;
    }
}

/* ─── Modals ─── */
@media (max-width: 575.98px) {
    .modal-dialog {
        margin: 0.5rem;
        max-width: calc(100% - 1rem);
    }

    .modal-dialog.modal-lg,
    .modal-dialog.modal-xl {
        max-width: calc(100% - 1rem);
    }

    .modal-body {
        padding: 1rem !important;
    }

    .modal-footer {
        flex-direction: column;
        gap: 0.5rem;
    }

    .modal-footer .btn {
        width: 100%;
        margin: 0 !important;
    }
}

/* ─── Forms ─── */
@media (max-width: 575.98px) {
    .form-control,
    .form-select,
    .select2-container {
        font-size: 16px !important; /* prevents iOS zoom on focus */
    }

    .step-indicator {
        padding: 0.75rem !important;
        gap: 0.25rem;
    }

    .step-indicator .step-number {
        width: 28px !important;
        height: 28px !important;
        font-size: 0.75rem !important;
    }
}

/* ─── Action buttons in tables ─── */
@media (max-width: 575.98px) {
    .btn-action,
    .btn-xs {
        min-width: 2rem;
        min-height: 2rem;
        padding: 0.35rem 0.5rem !important;
    }

    td .d-flex.gap-2,
    td .d-flex.gap-1 {
        flex-wrap: wrap;
        justify-content: center;
    }
}

/* ─── Breadcrumbs ─── */
@media (max-width: 575.98px) {
    .breadcrumb {
        font-size: 0.75rem;
        flex-wrap: wrap;
    }
}

/* ─── Charts ─── */
.chart-container,
canvas {
    max-width: 100%;
}

@media (max-width: 767.98px) {
    .chart-container {
        min-height: 220px;
    }
}

/* ─── SweetAlert2 mobile ─── */
@media (max-width: 575.98px) {
    .swal2-popup {
        width: calc(100% - 1.5rem) !important;
        font-size: 0.95rem !important;
        padding: 1.25rem !important;
    }

    .swal2-actions {
        flex-direction: column-reverse;
        width: 100%;
    }

    .swal2-actions button {
        width: 100%;
    }
}

/* ─── Select2 dropdown ─── */
@media (max-width: 575.98px) {
    .select2-container--bootstrap-5 .select2-dropdown {
        max-width: calc(100vw - 1rem);
    }
}

/* ─── Auth pages (Layout = null) ─── */
.auth-wrapper .brand-logo {
    margin-left: auto;
    margin-right: auto;
}

@media (max-width: 575.98px) {
    .auth-wrapper {
        padding: 1rem 0.75rem !important;
        align-items: flex-start !important;
        padding-top: 2rem !important;
    }

    .auth-card {
        padding: 1.75rem 1.25rem !important;
        border-radius: 0.85rem !important;
    }
}

/* ─── Public marketing (_PublicLayout) ─── */
@media (max-width: 991.98px) {
    body.public-site .public-main {
        padding-top: 72px;
    }

    .hero-section {
        padding: 2.5rem 0 3rem !important;
        text-align: center;
    }

    .hero-section h1 {
        font-size: clamp(1.75rem, 6vw, 2.5rem) !important;
    }

    .public-navbar .btn-cta {
        width: 100%;
        text-align: center;
        margin-top: 0.5rem;
        display: block;
    }

    .public-navbar .navbar-nav .dropdown-menu {
        width: 100%;
        position: static !important;
        transform: none !important;
        margin-top: 0.5rem !important;
        box-shadow: none !important;
        border: 1px solid rgba(15, 23, 42, 0.08) !important;
    }

    .public-navbar #languageToggle {
        width: 100% !important;
        margin-top: 0.35rem;
    }
}

@media (max-width: 575.98px) {
    body {
        font-size: 1rem;
    }

    .footer {
        padding: 3rem 0 1.5rem !important;
        text-align: center;
    }

    .footer .row > [class*="col-"] {
        margin-bottom: 1.5rem;
    }

    .pricing-card,
    .feature-card {
        margin-bottom: 1rem;
    }
}

/* ─── Admission create hero ─── */
@media (max-width: 767.98px) {
    .admission-header {
        padding: 2rem 0 4rem 0 !important;
        margin-bottom: -3rem !important;
    }

    .portal-card {
        padding: 1rem !important;
    }
}

/* ─── Teacher dashboard ─── */
@media (max-width: 575.98px) {
    .td-hero {
        padding: 1.15rem !important;
        border-radius: 1.15rem !important;
    }

    .td-avatar {
        width: 60px !important;
        height: 60px !important;
    }

    .td-hero h1 {
        font-size: 1.35rem !important;
    }

    .td-stat-num {
        font-size: 1.55rem !important;
    }

    .td-wrap canvas {
        height: 210px !important;
    }
}

@media (min-width: 576px) and (max-width: 991.98px) {
    .td-hero {
        padding: 1.5rem !important;
    }
}

/* ─── Student / Parent portal dashboards ─── */
@media (max-width: 575.98px) {
    .sd-hero,
    .pd-hero,
    .cd-hero {
        padding: 1.15rem !important;
        border-radius: 1.15rem !important;
    }

    .sd-avatar,
    .pd-avatar,
    .cd-avatar {
        width: 56px !important;
        height: 56px !important;
    }

    .sd-hero h1,
    .pd-hero h1,
    .cd-hero h2 {
        font-size: 1.3rem !important;
    }

    .sd-wrap canvas,
    .pd-wrap canvas {
        height: 210px !important;
    }

    .sd-week {
        grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
    }

    .rt-hero {
        padding: 1.15rem !important;
        border-radius: 1.15rem !important;
    }

    .rt-hero h1 {
        font-size: 1.3rem !important;
    }
}

/* ─── Leaflet maps (campus) ─── */
@media (max-width: 575.98px) {
    #branchMap,
    .leaflet-container {
        min-height: 220px !important;
        height: 220px !important;
    }
}

/* ─── Utility: hide on mobile / desktop ─── */
@media (max-width: 575.98px) {
    .d-none-mobile {
        display: none !important;
    }
}

@media (min-width: 576px) {
    .d-only-mobile {
        display: none !important;
    }
}

/* ─── Print: keep A4 layouts untouched ─── */
@media print {
    #sidebar-wrapper,
    .navbar,
    .footer,
    #sidebar-overlay,
    .btn,
    .dataTables_filter,
    .dataTables_length,
    .dataTables_paginate {
        display: none !important;
    }

    #page-content-wrapper,
    #page-content-wrapper .container-fluid {
        padding: 0 !important;
        margin: 0 !important;
        width: 100% !important;
    }
}
