/**
 * ADF mobile & tablet styles only (max-width: 1023px).
 * Desktop layout (1024px+) is unchanged.
 */

@media (max-width: 1023px) {
    html {
        overflow-x: clip;
    }

    body {
        overflow-x: clip;
    }

    .container {
        width: min(1150px, calc(100% - 1.5rem));
    }

    /* —— Mobile header toolbar —— */
    .mobile-header-bar {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 0.65rem;
        padding: 0.6rem 1.15rem;
        min-height: 58px;
        position: sticky;
        top: 0;
        z-index: 201;
        background: rgba(255, 255, 255, 0.96);
        backdrop-filter: blur(10px);
        -webkit-backdrop-filter: blur(10px);
        border-bottom: 1px solid var(--border);
        box-shadow: 0 4px 18px rgba(15, 23, 42, 0.07);
    }

    .header-top-bar--desktop,
    .header-nav-bar--desktop {
        display: none !important;
    }

    .mobile-header-apply {
        flex: 0 0 auto;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        gap: 0.35rem;
        min-height: 40px;
        padding: 0.42rem 1rem;
        font-size: 0.72rem;
        font-weight: 700;
        letter-spacing: 0.09em;
        text-transform: uppercase;
        color: #0f766e;
        background: linear-gradient(180deg, #ffffff 0%, #f0fdf9 100%);
        border: 1.5px solid rgba(15, 118, 110, 0.38);
        border-radius: 10px;
        box-shadow:
            inset 0 1px 0 rgba(255, 255, 255, 0.85),
            0 1px 2px rgba(15, 23, 42, 0.06);
        text-decoration: none;
        transition:
            background 0.2s ease,
            border-color 0.2s ease,
            color 0.2s ease,
            box-shadow 0.2s ease,
            transform 0.15s ease;
    }

    .mobile-header-apply:active {
        transform: scale(0.97);
        background: #ecfdf5;
    }

    .mobile-header-apply:focus-visible {
        outline: 2px solid rgba(15, 118, 110, 0.55);
        outline-offset: 2px;
    }

    .mobile-header-logo {
        flex: 1 1 auto;
        display: flex;
        justify-content: center;
        min-width: 0;
    }

    .mobile-header-logo .brand-logo {
        height: 44px;
        max-width: min(180px, 52vw);
        width: auto;
        object-fit: contain;
    }

    .mobile-nav-toggle {
        flex: 0 0 auto;
        width: 44px;
        height: 44px;
        border: 1px solid var(--border);
        border-radius: 12px;
        background: #fff;
        color: var(--text);
        font-size: 1.15rem;
        display: grid;
        place-items: center;
        cursor: pointer;
        transition: background 0.2s ease, border-color 0.2s ease, transform 0.15s ease;
    }

    .mobile-nav-toggle:active {
        transform: scale(0.96);
        background: #f0fdf9;
    }

    .site-header {
        position: relative;
        z-index: 200;
    }

    /* —— Mobile drawer —— */
    .mobile-nav-overlay {
        position: fixed;
        inset: 0;
        background: rgba(15, 23, 42, 0.55);
        z-index: 250;
        opacity: 0;
        visibility: hidden;
        transition: opacity 0.28s ease, visibility 0.28s ease;
    }

    .mobile-nav-overlay.is-visible {
        opacity: 1;
        visibility: visible;
    }

    .mobile-nav-drawer {
        position: fixed;
        top: 0;
        right: 0;
        width: min(75vw, 320px);
        max-width: 320px;
        height: 100dvh;
        height: 100vh;
        background: #fff;
        z-index: 260;
        display: flex;
        flex-direction: column;
        box-shadow: -12px 0 40px rgba(15, 23, 42, 0.18);
        transform: translateX(100%);
        transition: transform 0.32s cubic-bezier(0.22, 1, 0.36, 1);
        overflow: hidden;
    }

    .mobile-nav-drawer.is-open {
        transform: translateX(0);
    }

    .mobile-nav-drawer-head {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 1rem 1.1rem;
        border-bottom: 1px solid var(--border);
        flex-shrink: 0;
    }

    .mobile-nav-drawer-title {
        font-weight: 700;
        font-size: 1.05rem;
        color: #0f172a;
    }

    .mobile-nav-close {
        width: 42px;
        height: 42px;
        border: none;
        border-radius: 10px;
        background: #f1f5f9;
        color: #334155;
        font-size: 1.25rem;
        cursor: pointer;
    }

    .mobile-nav-links {
        flex: 1 1 auto;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        padding: 0.75rem 0.85rem 1rem;
        display: flex;
        flex-direction: column;
        gap: 0.2rem;
    }

    .mobile-nav-links a {
        display: block;
        padding: 0.85rem 0.95rem;
        border-radius: 12px;
        font-weight: 600;
        font-size: 1rem;
        color: #1e293b;
        transition: background 0.2s ease, color 0.2s ease;
    }

    .mobile-nav-links a:hover,
    .mobile-nav-links a.active {
        background: #e6f5f2;
        color: var(--primary-dark);
    }

    .mobile-nav-social {
        flex-shrink: 0;
        display: flex;
        flex-wrap: wrap;
        justify-content: center;
        gap: 0.85rem;
        padding: 1rem 1.1rem 1.35rem;
        border-top: 1px solid var(--border);
        background: #f8fafc;
    }

    .mobile-nav-social a {
        width: 44px;
        height: 44px;
        border-radius: 50%;
        display: grid;
        place-items: center;
        background: #fff;
        border: 1px solid var(--border);
        color: var(--primary);
        font-size: 1.05rem;
        transition: transform 0.2s ease, background 0.2s ease;
    }

    .mobile-nav-social a:active {
        transform: scale(0.94);
    }

    body.mobile-nav-open {
        overflow: hidden;
    }

    /* —— Hero (home video) —— */
    .header-video-wrap {
        height: min(72vh, 520px);
        min-height: 360px;
    }

    .header-video {
        object-fit: cover;
    }

    .hero-video-content {
        padding: 1.25rem 1rem;
        border-radius: 14px;
        max-width: calc(100% - 0.5rem);
    }

    .hero-video-content h1 {
        font-size: clamp(1.35rem, 6.5vw, 2rem);
        letter-spacing: 0.12em;
        line-height: 1.15;
    }

    .hero-video-content p {
        font-size: clamp(0.72rem, 3.2vw, 0.9rem);
        letter-spacing: 0.18em;
        gap: 0.5rem;
        flex-wrap: wrap;
        justify-content: center;
    }

    .hero-video-content p::before,
    .hero-video-content p::after {
        width: 20px;
    }

    .hero-video-actions {
        flex-direction: column;
        align-items: stretch;
        gap: 0.65rem;
        margin-top: 1.1rem;
    }

    .hero-video-actions .btn {
        width: 100%;
        min-height: 48px;
        justify-content: center;
    }

    .header-title-banner {
        height: min(42vh, 220px);
        min-height: 160px;
    }

    .header-title-overlay h1 {
        font-size: clamp(1.25rem, 5.5vw, 1.65rem);
    }

    /* —— Handwriting / founder sections —— */
    .home-founder-sub,
    .home-founder-body,
    .home-founder-signature {
        font-size: clamp(1.22rem, 4.2vw, 1.55rem) !important;
        line-height: 1.65 !important;
    }

    .home-founder-body {
        padding-top: 0.5rem;
    }

    .home-founder-card {
        padding: 1rem;
    }

    .home-key-elements-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    .home-key-element p {
        font-size: 1rem;
        line-height: 1.55;
    }

    .home-story-grid {
        grid-template-columns: 1fr;
    }

    /* —— Footer: Foundation | Useful Links side by side —— */
    .site-footer > .container {
        width: 100%;
        max-width: 100%;
        padding-left: 1.25rem;
        padding-right: 1.25rem;
        box-sizing: border-box;
    }

    .footer-grid {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 1.65rem 1.35rem;
        padding: 1.85rem 0 1.1rem;
    }

    .footer-col-foundation {
        grid-column: 1;
        grid-row: 1;
        padding-right: 0.35rem;
    }

    .footer-col-links {
        grid-column: 2;
        grid-row: 1;
        padding-left: 0.35rem;
    }

    .footer-col-contact {
        grid-column: 1 / -1;
        grid-row: 2;
    }

    .footer-col-message {
        grid-column: 1 / -1;
        grid-row: 3;
    }

    .site-footer h4 {
        font-size: 1.2rem;
        font-weight: 700;
        line-height: 1.25;
        margin: 0 0 0.8rem;
        color: #f8fafc;
        letter-spacing: 0.02em;
    }

    .site-footer p {
        font-size: 0.875rem;
        line-height: 1.55;
        margin: 0 0 0.45rem;
        color: #c5d0e0;
    }

    .site-footer .footer-grid a {
        font-size: 0.875rem;
        font-weight: 500;
    }

    .footer-copy {
        font-size: 0.82rem;
        padding-left: 0;
        padding-right: 0;
    }

    /* —— Portal mobile: WhatsApp-style bottom tabs —— */
    body.is-portal .portal-sidebar,
    body.is-portal .portal-mobile-menu-btn,
    body.is-portal .portal-overlay {
        display: none !important;
    }

    body.is-portal .site-footer,
    body.is-portal #back-to-top {
        display: none !important;
    }

    body.is-portal > main {
        padding-bottom: calc(4.35rem + env(safe-area-inset-bottom, 0px));
    }

    .portal-layout:not(:has(.messages-portal-main)) {
        grid-template-columns: 1fr !important;
        height: auto !important;
        max-height: none !important;
        overflow: visible !important;
        padding-top: 0.35rem;
        gap: 0.65rem;
    }

    .portal-layout:not(:has(.messages-portal-main)) .portal-main {
        max-height: none !important;
        overflow: visible !important;
        position: static !important;
        height: auto !important;
    }

    .portal-bottom-nav {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 300;
        display: flex;
        align-items: stretch;
        justify-content: space-around;
        gap: 0.15rem;
        min-height: 3.65rem;
        padding: 0.35rem 0.4rem calc(0.35rem + env(safe-area-inset-bottom, 0px));
        background: #fff;
        border-top: 1px solid var(--border);
        box-shadow: 0 -8px 28px rgba(15, 23, 42, 0.1);
    }

    .portal-bottom-nav__item {
        flex: 1 1 0;
        min-width: 0;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 0.2rem;
        padding: 0.2rem 0.15rem;
        border: 0;
        background: transparent;
        color: #64748b;
        text-decoration: none;
        font: inherit;
        font-size: 0.68rem;
        font-weight: 600;
        line-height: 1.1;
        border-radius: 10px;
        cursor: pointer;
        transition: color 0.2s ease, background 0.2s ease;
    }

    .portal-bottom-nav__item i {
        font-size: 1.15rem;
    }

    .portal-bottom-nav__item.is-active {
        color: #0f766e;
        background: #ecfdf5;
    }

    .portal-more-overlay {
        position: fixed;
        inset: 0;
        z-index: 310;
        background: rgba(15, 23, 42, 0.45);
        opacity: 0;
        visibility: hidden;
        transition: opacity 0.25s ease, visibility 0.25s ease;
    }

    .portal-more-overlay.is-visible {
        opacity: 1;
        visibility: visible;
    }

    .portal-more-sheet {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 320;
        background: #fff;
        border-radius: 18px 18px 0 0;
        padding: 0.75rem 1rem calc(1rem + env(safe-area-inset-bottom, 0px));
        box-shadow: 0 -12px 40px rgba(15, 23, 42, 0.18);
        transform: translateY(105%);
        transition: transform 0.28s cubic-bezier(0.22, 1, 0.36, 1);
    }

    .portal-more-sheet.is-open {
        transform: translateY(0);
    }

    .portal-more-sheet-handle {
        width: 42px;
        height: 4px;
        margin: 0 auto 0.75rem;
        border-radius: 999px;
        background: #cbd5e1;
    }

    .portal-more-sheet-title {
        margin: 0 0 0.65rem;
        font-size: 1rem;
        font-weight: 700;
        color: #0f172a;
    }

    .portal-more-sheet-links {
        display: grid;
        gap: 0.35rem;
    }

    .portal-more-sheet-link {
        display: flex;
        align-items: center;
        gap: 0.75rem;
        padding: 0.75rem 0.85rem;
        border-radius: 12px;
        text-decoration: none;
        color: #0f172a;
        font-weight: 600;
    }

    .portal-more-sheet-link i {
        width: 1.35rem;
        color: #0f766e;
        text-align: center;
    }

    .portal-more-sheet-link.is-active,
    .portal-more-sheet-link:active {
        background: #ecfdf5;
    }

    body.portal-more-open {
        overflow: hidden;
    }

    /* Portal chat pages (messages + groups) */
    body.is-portal-chat {
        height: 100dvh;
        height: 100vh;
        overflow: hidden;
        display: flex;
        flex-direction: column;
    }

    body.is-portal-chat > main {
        flex: 1 1 auto;
        min-height: 0;
        overflow: hidden;
        padding-bottom: calc(3.65rem + env(safe-area-inset-bottom, 0px));
        box-sizing: border-box;
        display: flex;
        flex-direction: column;
    }

    body.is-portal-chat .section.container.portal-layout {
        flex: 1 1 auto;
        min-height: 0;
        display: flex;
        flex-direction: column;
        padding: 0 !important;
        margin: 0 auto;
        width: 100%;
        max-width: 100%;
        overflow: hidden;
    }

    body.is-portal-chat .portal-main {
        flex: 1 1 auto;
        min-height: 0;
        overflow: hidden;
        display: flex;
        flex-direction: column;
    }

    body.is-portal-messages .portal-layout:has(.messages-portal-main) {
        grid-template-columns: 1fr !important;
        grid-template-rows: minmax(0, 1fr) !important;
        gap: 0 !important;
        height: 100%;
        max-height: 100%;
    }

    body.is-portal-messages .messages-shell {
        flex: 1 1 auto;
        min-height: 0;
        max-height: 100%;
        height: 100%;
        display: flex;
        flex-direction: column;
    }

    body.is-portal-messages .messages-thread-pane.messenger-pane {
        border-radius: 0;
        border-left: 0;
        border-right: 0;
        margin: 0;
        height: 100%;
        max-height: 100%;
        display: flex;
        flex-direction: column;
        flex: 1 1 auto;
        min-height: 0;
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
    }

    body.is-portal-groups .portal-layout {
        padding-left: 0 !important;
        padding-right: 0 !important;
        margin-left: auto;
        margin-right: auto;
        width: 100%;
        max-width: 100%;
    }

    body.is-portal-groups .portal-main {
        width: 100%;
        max-width: 100%;
        min-width: 0;
        padding-left: 0;
        padding-right: 0;
        box-sizing: border-box;
    }

    body.is-portal-groups .groups-layout {
        flex: 1 1 auto;
        min-height: 0;
        height: 100%;
        width: 100%;
        max-width: 100%;
        min-width: 0;
        display: flex;
        flex-direction: column;
        gap: 0.65rem;
        overflow-x: hidden;
        box-sizing: border-box;
    }

    body.is-portal-groups .groups-feed-card {
        border-radius: 0;
        border-left: 0;
        border-right: 0;
        flex: 1 1 auto;
        min-height: 0;
        width: 100%;
        max-width: 100%;
    }

    body.is-portal-groups .groups-feed-shell {
        min-height: 0;
        height: 100%;
        max-height: 100%;
    }

    body.is-portal-groups .groups-feed-shell.is-feed-open {
        max-height: 100%;
    }

    body.is-portal-groups .groups-right-column {
        display: flex;
        flex-direction: column;
        gap: 0.65rem;
        flex: 0 0 auto;
        width: 100%;
        max-width: 100%;
        min-width: 0;
        padding: 0 0.75rem 0.75rem;
        box-sizing: border-box;
    }

    body.is-portal-groups .groups-right-column .card {
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
    }

    body.is-portal-groups .groups-panel-scroll {
        max-height: none;
    }

    body.is-portal-groups .groups-layout:has(.groups-feed-shell.is-feed-open) .groups-right-column {
        display: none;
    }

    body.is-portal-groups .group-feed-conversations-top h3 {
        font-size: 1.35rem;
    }

    .dashboard-summary-grid {
        grid-template-columns: 1fr 1fr;
        gap: 0.65rem;
    }

    .dashboard-summary-card {
        padding: 0.85rem;
    }

    .table-scroll,
    .news-feed-list {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .full-articles-section .container > div:first-child {
        margin-bottom: 1rem !important;
    }

    .full-articles-board {
        display: flex;
        flex-direction: column;
        gap: 0.65rem;
        overflow: visible;
    }

    #full-articles-middle {
        order: 1;
    }

    #full-articles-left {
        order: 0;
    }

    #full-articles-right {
        order: 2;
    }

    .full-articles-column {
        max-height: none;
        overflow: visible;
        padding: 0;
    }

    .full-articles-main {
        padding: 1rem;
    }

    .full-articles-main .full-articles-heading {
        font-size: 1.2rem;
        line-height: 1.3;
    }

    .full-articles-main #middle-description {
        margin-bottom: 0.75rem;
    }

    .full-articles-panel-backdrop {
        position: fixed;
        inset: 0;
        z-index: 384;
        background: rgba(15, 23, 42, 0.48);
        backdrop-filter: blur(12px);
        -webkit-backdrop-filter: blur(12px);
        opacity: 0;
        visibility: hidden;
        transition:
            opacity 0.28s ease,
            visibility 0.28s ease;
        pointer-events: none;
    }

    .full-articles-panel-backdrop.is-visible {
        opacity: 1;
        visibility: visible;
        pointer-events: auto;
    }

    body.fa-panel-overlay-open {
        overflow: hidden;
    }

    .full-articles-panel {
        border-radius: 14px;
        overflow: visible;
        position: relative;
        z-index: 388;
    }

    .full-articles-panel-toggle {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 0.5rem;
        width: 100%;
        min-height: 48px;
        padding: 0.8rem 1rem;
        border: 0;
        background: #fff;
        font: inherit;
        cursor: pointer;
        text-align: left;
        border-radius: 14px;
        box-shadow: 0 2px 12px rgba(15, 23, 42, 0.06);
    }

    /* Floating sheet: list overlays blurred backdrop (menu-style) */
    .full-articles-panel.is-open .full-articles-panel__body {
        display: grid !important;
        position: fixed !important;
        left: max(0.75rem, env(safe-area-inset-left, 0px));
        right: max(0.75rem, env(safe-area-inset-right, 0px));
        top: calc(max(5rem, env(safe-area-inset-top, 0px)) + 2.85rem);
        max-height: min(72vh, 560px);
        margin: 0;
        padding: 0.75rem 1rem 1.1rem;
        z-index: 390;
        background: #fff;
        border-radius: 16px;
        box-shadow:
            0 24px 64px rgba(15, 23, 42, 0.28),
            0 0 0 1px rgba(226, 232, 240, 0.9);
        overflow-x: hidden;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    .full-articles-papers .full-article-tile {
        padding: 1rem;
    }

    .full-articles-papers .full-article-tile h4 {
        font-size: 1.08rem;
        line-height: 1.35;
    }

    .full-articles-papers .paper-controls {
        grid-template-columns: 1fr;
        gap: 0.5rem;
    }

    .full-articles-papers .paper-action-btn {
        width: 100%;
    }

    .news-layout {
        grid-template-columns: 1fr !important;
    }

    .news-main,
    .news-side {
        max-height: none !important;
    }

    .scholarship-grid {
        grid-template-columns: 1fr;
    }

    .scholarship-apply-panel {
        grid-template-columns: 1fr;
    }

    .auth-modal-overlay,
    .scholarship-modal-overlay {
        padding: 1rem;
        align-items: flex-end;
    }

    .auth-modal,
    .scholarship-modal {
        width: 100%;
        max-width: 100%;
        max-height: 90dvh;
        overflow-y: auto;
        border-radius: 16px 16px 0 0;
    }

    .card {
        border-radius: 14px;
    }

    .btn,
    .btn-sm {
        min-height: 44px;
    }

    img,
    video {
        max-width: 100%;
        height: auto;
    }

    .grid-3,
    .grid-2 {
        grid-template-columns: 1fr !important;
    }
}

@media (min-width: 1024px) {
    .mobile-header-bar,
    .mobile-nav-drawer,
    .mobile-nav-overlay,
    .portal-mobile-menu-btn,
    .portal-overlay,
    .portal-bottom-nav,
    .portal-more-overlay,
    .portal-more-sheet {
        display: none !important;
    }
}

@media (max-width: 1023px) and (min-width: 768px) {
    .dashboard-summary-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .home-key-elements-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .full-articles-board {
        display: flex;
        flex-direction: column;
    }

    #full-articles-middle {
        order: 1;
    }

    #full-articles-left {
        order: 0;
    }

    #full-articles-right {
        order: 2;
    }
}

@media (max-width: 430px) {
    .dashboard-summary-grid {
        grid-template-columns: 1fr;
    }

    .site-footer > .container {
        padding-left: 1.35rem;
        padding-right: 1.35rem;
    }

    .footer-grid {
        gap: 1.35rem 1rem;
    }

    .site-footer h4 {
        font-size: 1.15rem;
    }
}

@media (prefers-reduced-motion: reduce) {
    .mobile-nav-drawer,
    .mobile-nav-overlay,
    .portal-sidebar {
        transition: none;
    }
}
