/* ===================================================================
   JBSAPS - Mobile Enhancements & Optimizations
   Professional Premium Mobile-First Responsive Design
   =================================================================== */

/* ===================================
   MOBILE-FIRST UTILITIES
   =================================== */

/* Prevent horizontal scroll on mobile */
html,
body {
    overflow-x: hidden;
    overflow-y: auto;
    width: 100%;
    min-height: 100%;
}

/* iOS momentum scrolling */
body {
    -webkit-overflow-scrolling: touch;
}

.mobile-menu-head,
.mobile-menu-actions {
    display: none;
}

/* ===================================
   TOUCH-FRIENDLY INTERACTIONS
   =================================== */

@media (max-width: 768px) {
    html,
    body {
        height: auto !important;
        min-height: 100% !important;
        max-height: none !important;
        overflow-x: hidden !important;
        overflow-y: auto !important;
        position: static;
    }

    body {
        overscroll-behavior-y: auto !important;
        touch-action: pan-y;
    }

    body.menu-open::before {
        content: '';
        position: fixed;
        inset: 0;
        z-index: 998;
        background: rgba(10, 22, 40, 0.46);
        backdrop-filter: blur(5px);
        animation: drawerBackdrop 260ms ease both;
    }

    .nav-links {
        left: auto !important;
        right: 0;
        width: min(88vw, 380px) !important;
        max-width: 380px;
        height: 100dvh;
        padding: 0 1rem 1.25rem !important;
        gap: 0.4rem !important;
        background: linear-gradient(180deg, #ffffff 0%, #f4fbfd 100%) !important;
        border-left: 1px solid rgba(8, 145, 178, 0.16);
        box-shadow: -20px 0 48px rgba(10, 22, 40, 0.24) !important;
        transform: translateX(105%) scale(0.98) !important;
        opacity: 0;
        visibility: hidden;
        pointer-events: none !important;
        transition:
            transform 420ms cubic-bezier(0.22, 1, 0.36, 1),
            opacity 260ms ease,
            visibility 0s linear 420ms !important;
        z-index: 1200 !important;
    }

    .nav-links.active {
        display: flex !important;
        transform: translateX(0) scale(1) !important;
        opacity: 1;
        visibility: visible;
        pointer-events: auto !important;
        transition:
            transform 420ms cubic-bezier(0.22, 1, 0.36, 1),
            opacity 260ms ease,
            visibility 0s linear 0s !important;
    }

    .nav-links.active > li {
        animation: drawerItemIn 420ms cubic-bezier(0.22, 1, 0.36, 1) both;
    }

    .nav-links.active > li:nth-child(2) { animation-delay: 40ms; }
    .nav-links.active > li:nth-child(3) { animation-delay: 75ms; }
    .nav-links.active > li:nth-child(4) { animation-delay: 110ms; }
    .nav-links.active > li:nth-child(5) { animation-delay: 145ms; }
    .nav-links.active > li:nth-child(6) { animation-delay: 180ms; }
    .nav-links.active > li:nth-child(7) { animation-delay: 215ms; }

    .mobile-menu-head {
        display: flex;
        flex-direction: column;
        align-items: flex-start;
        justify-content: flex-end;
        min-height: 122px;
        margin: 0 -1rem 0.6rem;
        padding: 1.25rem 4.75rem 1.1rem 1.25rem;
        background:
            radial-gradient(circle at 90% 10%, rgba(251, 191, 36, 0.28), transparent 34%),
            linear-gradient(135deg, #0A1628 0%, #0E7490 100%);
        color: #fff;
        border-bottom: 1px solid rgba(255, 255, 255, 0.18);
    }

    .drawer-brand {
        font-family: var(--font-heading);
        font-size: 1.75rem;
        font-weight: 900;
        line-height: 1;
        letter-spacing: 0;
    }

    .drawer-tag {
        margin-top: 0.38rem;
        color: rgba(255, 255, 255, 0.76);
        font-size: 0.72rem;
        font-weight: 800;
        letter-spacing: 1px;
        text-transform: uppercase;
    }

    /* Topbar mobile optimization */
    .topbar {
        padding: 0.55rem 0;
    }

    .topbar .container {
        flex-direction: column;
        gap: 0.4rem;
        text-align: center;
    }

    .topbar-left,
    .topbar-right {
        justify-content: center;
        width: 100%;
        gap: 0.75rem;
        font-size: 0.75rem;
    }

    .topbar .issn {
        font-size: 0.75rem;
    }

    .topbar .divider {
        margin: 0 0.15rem;
    }

    .topbar a {
        font-size: 0.75rem;
    }

    /* Better tap targets */
    button,
    a,
    input[type="submit"],
    input[type="button"] {
        min-height: 44px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    /* Remove tap highlight on Android */
    * {
        -webkit-tap-highlight-color: rgba(8, 145, 178, 0.15);
    }

    /* Improve button spacing on mobile */
    .btn+.btn {
        margin-top: 0.5rem;
    }

    /* Better spacing for mobile cards */
    .article-card,
    .feature-card,
    .category-card,
    .editor-card,
    .news-card {
        margin-bottom: 1rem;
    }

    /* Mobile-optimized padding */
    .modal-body,
    .form-card,
    .sidebar-box {
        padding: 1.25rem;
    }

    /* Better mobile table handling */
    table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        white-space: nowrap;
    }

    /* Mobile-friendly images */
    img {
        max-width: 100%;
        height: auto;
    }

    /* Prevent zoom on input focus (iOS) */
    input[type="text"],
    input[type="email"],
    input[type="tel"],
    input[type="password"],
    input[type="search"],
    select,
    textarea {
        font-size: 16px !important;
    }

    /* Better form control spacing */
    .form-group+.form-group {
        margin-top: 1rem;
    }

    /* Mobile badge adjustments */
    .badge,
    .cat-badge,
    .pill-badge {
        font-size: 0.75rem;
        padding: 0.3rem 0.75rem;
    }

    /* Better readability on mobile */
    p {
        line-height: 1.7;
        margin-bottom: 1rem;
    }

    /* Mobile-friendly lists */
    ul,
    ol {
        padding-left: 1.25rem;
    }

    /* Better mobile headings */
    h1 {
        font-size: 1.75rem;
        line-height: 1.2;
    }

    h2 {
        font-size: 1.5rem;
        line-height: 1.25;
    }

    h3 {
        font-size: 1.25rem;
        line-height: 1.3;
    }

    h4 {
        font-size: 1.1rem;
        line-height: 1.35;
    }

    h5 {
        font-size: 1rem;
        line-height: 1.4;
    }

    h6 {
        font-size: 0.9rem;
        line-height: 1.4;
    }
}

/* ===================================
   MOBILE NAVIGATION FIXES
   =================================== */

@media (max-width: 768px) {

    .hamburger {
        border: 1px solid rgba(8, 145, 178, 0.18);
        background: rgba(255, 255, 255, 0.76);
        box-shadow: 0 8px 22px rgba(10, 22, 40, 0.09);
    }

    .hamburger.active {
        position: fixed;
        top: 1.2rem;
        right: 1.2rem;
        z-index: 1250 !important;
        background: rgba(255, 255, 255, 0.92);
        border-color: rgba(255, 255, 255, 0.44);
        box-shadow: 0 14px 30px rgba(10, 22, 40, 0.24);
    }

    .hamburger.active span {
        background: #0A1628;
    }

    body.menu-open .search-toggle {
        opacity: 0;
        transform: scale(0.84);
        pointer-events: none;
    }

    /* Keep the page scrollable on mobile; the menu panel has its own scroll area. */
    body.menu-open {
        overflow-x: hidden;
        overflow-y: auto;
        width: 100%;
    }

    .nav-links.active::before {
        content: none !important;
    }

    .nav-links > li {
        width: 100%;
        border: 0 !important;
    }

    .nav-links > li:first-child {
        border-top: 0 !important;
    }

    .nav-links > li > a {
        min-height: 54px;
        width: 100%;
        justify-content: space-between;
        padding: 0.92rem 1rem !important;
        border: 1px solid rgba(10, 22, 40, 0.07);
        border-radius: 12px !important;
        background: rgba(255, 255, 255, 0.78);
        color: #173244 !important;
        font-size: 0.94rem !important;
        font-weight: 800 !important;
        box-shadow: 0 1px 0 rgba(10, 22, 40, 0.02);
    }

    .nav-links > li > a::before {
        content: none !important;
    }

    .nav-links > li > a:hover,
    .nav-links > li > a:focus {
        background: #eefaff !important;
        border-color: rgba(8, 145, 178, 0.2);
        color: #076f8e !important;
        padding-left: 1rem !important;
        transform: translateY(-1px);
    }

    .nav-links > li > a.active {
        background: linear-gradient(135deg, rgba(8, 145, 178, 0.12), rgba(6, 182, 212, 0.1)) !important;
        border-color: rgba(8, 145, 178, 0.35);
        color: #087f9f !important;
        box-shadow: inset 3px 0 0 #0891B2, 0 8px 18px rgba(8, 145, 178, 0.08);
        padding-left: 1rem !important;
    }

    .nav-links .caret {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 24px;
        height: 24px;
        border-radius: 999px;
        background: rgba(8, 145, 178, 0.09);
        color: #0E7490;
        font-size: 0.58rem;
        transform: rotate(0deg) !important;
        transition: transform 220ms ease, background 220ms ease;
    }

    .nav-links li.open .caret {
        transform: rotate(180deg) !important;
        background: rgba(8, 145, 178, 0.18);
    }

    .dropdown-menu {
        display: grid !important;
        grid-template-rows: 0fr;
        margin: 0 0.4rem !important;
        padding: 0 !important;
        overflow: hidden;
        border: 0 !important;
        border-radius: 0 0 14px 14px !important;
        background: transparent !important;
        box-shadow: none !important;
        opacity: 1 !important;
        visibility: visible !important;
        transform: none !important;
        transition: grid-template-rows 280ms cubic-bezier(0.22, 1, 0.36, 1), margin 280ms ease;
        animation: none !important;
    }

    .dropdown-menu::before {
        content: '';
        display: block;
        min-height: 0;
    }

    .nav-links li.open .dropdown-menu {
        grid-template-rows: 1fr;
        margin: 0.35rem 0.4rem 0.55rem !important;
    }

    .dropdown-menu > li {
        overflow: hidden;
        min-height: 0;
        border: 0 !important;
    }

    .dropdown-menu li a {
        min-height: 42px;
        justify-content: flex-start;
        margin: 0;
        padding: 0.72rem 0.85rem 0.72rem 1rem !important;
        border: 0;
        border-left: 2px solid rgba(8, 145, 178, 0.25);
        border-radius: 0 !important;
        background: rgba(8, 145, 178, 0.06) !important;
        color: #315466 !important;
        font-size: 0.86rem !important;
        font-weight: 700 !important;
        box-shadow: none;
    }

    .dropdown-menu li:first-child a {
        border-top-left-radius: 10px !important;
        border-top-right-radius: 10px !important;
    }

    .dropdown-menu li:last-child a {
        border-bottom-left-radius: 10px !important;
        border-bottom-right-radius: 10px !important;
    }

    .dropdown-menu li a:hover,
    .dropdown-menu li a:focus {
        background: rgba(8, 145, 178, 0.12) !important;
        color: #087f9f !important;
        padding-left: 1.15rem !important;
    }

    .mobile-menu-actions {
        display: grid;
        grid-template-columns: 1fr;
        gap: 0.65rem;
        margin-top: auto;
        padding: 1rem 0 0;
    }

    .drawer-action {
        min-height: 48px;
        border-radius: 12px;
        font-size: 0.9rem;
        font-weight: 850;
    }

    .drawer-action-outline {
        border: 1px solid rgba(8, 145, 178, 0.22);
        background: #fff;
        color: #087f9f;
    }

    .drawer-action-primary {
        background: linear-gradient(135deg, #0891B2 0%, #06B6D4 100%);
        color: #fff;
        box-shadow: 0 12px 24px rgba(8, 145, 178, 0.24);
    }

    @keyframes drawerBackdrop {
        from { opacity: 0; }
        to { opacity: 1; }
    }

    @keyframes drawerItemIn {
        from {
            opacity: 0;
            transform: translateX(18px);
        }
        to {
            opacity: 1;
            transform: translateX(0);
        }
    }

    /* Mobile dropdown improvements */
    .dropdown-menu {
        animation: none !important;
    }

    @keyframes slideDown {
        from {
            opacity: 0;
            transform: translateY(-10px);
        }

        to {
            opacity: 1;
            transform: translateY(0);
        }
    }

    /* Better mobile search */
    .search-bar {
        position: fixed;
        top: 70px;
        left: 1rem;
        right: 1rem;
        z-index: 999;
        box-shadow: 0 8px 32px rgba(10, 22, 40, 0.2);
    }
}

/* ===================================
   MOBILE CARD OPTIMIZATIONS
   =================================== */

@media (max-width: 768px) {
    /* Prevent card transform on touch devices */
    @media (hover: none) {

        .article-card:hover,
        .feature-card:hover,
        .category-card:hover,
        .editor-card:hover,
        .news-card:hover {
            transform: none;
            box-shadow: 0 4px 16px rgba(10, 22, 40, 0.08);
        }
    }

    /* Better mobile card titles */
    .article-card h3 {
        font-size: 1.05rem;
        line-height: 1.35;
        margin-bottom: 0.5rem;
    }

    /* Mobile-optimized card buttons */
    .article-card .card-actions {
        margin-top: auto;
        padding-top: 1rem;
    }

    .article-card .card-actions .btn {
        font-size: 0.875rem;
        padding: 0.65rem 1.1rem;
    }
}

/* ===================================
   MOBILE HERO SECTION
   =================================== */

@media (max-width: 768px) {

    /* Better hero spacing */
    .hero {
        text-align: center;
    }

    .hero-content {
        padding: 0;
        width: 100%;
    }

    /* Hide hero card on mobile - full width content */
    .hero-card {
        display: none !important;
    }

    /* Mobile-optimized hero buttons */
    .hero-cta {
        display: flex;
        flex-direction: column;
        gap: 0.75rem;
    }

    .hero-cta .btn {
        width: 100%;
        padding: 1rem 1.5rem;
        font-size: 1rem;
    }

    /* Better hero text optimization */
    .hero-text {
        font-size: 0.95rem;
        line-height: 1.7;
        text-align: center;
        width: 100%;
    }
}

/* ===================================
   MOBILE STATS & METRICS
   =================================== */

@media (max-width: 768px) {

    /* Better stats layout */
    .stats-grid {
        padding: 0;
    }

    .stat-item {
        padding: 1rem 0.5rem;
    }

    .stat-number {
        font-size: 2.25rem;
        margin-bottom: 0.35rem;
    }

    .stat-label {
        font-size: 0.85rem;
        line-height: 1.3;
    }
}

/* ===================================
   MOBILE FILTER & TABS
   =================================== */

@media (max-width: 768px) {

    /* Horizontal scroll for filter tabs */
    .filter-tabs {
        display: flex;
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: thin;
        scroll-behavior: smooth;
        padding-bottom: 0.75rem;
        margin-bottom: 1.5rem;
    }

    .filter-tabs::-webkit-scrollbar {
        height: 3px;
    }

    .filter-tabs::-webkit-scrollbar-track {
        background: rgba(8, 145, 178, 0.1);
        border-radius: 2px;
    }

    .filter-tabs::-webkit-scrollbar-thumb {
        background: rgba(8, 145, 178, 0.4);
        border-radius: 2px;
    }

    .filter-tab {
        flex-shrink: 0;
        white-space: nowrap;
    }

    /* Better tab navigation */
    .tabs-nav {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: thin;
    }

    .tab-btn {
        flex-shrink: 0;
    }
}

/* ===================================
   MOBILE MODAL IMPROVEMENTS
   =================================== */

@media (max-width: 768px) {

    /* Full-screen modal on mobile */
    .modal {
        max-width: 95%;
        max-height: 85vh;
        margin: auto;
    }

    .modal-overlay {
        padding: 1rem;
        align-items: center;
    }

    .modal-head {
        position: sticky;
        top: 0;
        background: white;
        z-index: 10;
    }

    /* Better modal scrolling */
    .modal-body {
        max-height: calc(85vh - 120px);
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Mobile cite tabs */
    .cite-tabs {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        display: flex;
        gap: 0.35rem;
        padding-bottom: 0.5rem;
    }

    .cite-tab {
        flex-shrink: 0;
    }
}

/* ===================================
   MOBILE NEWSLETTER & FORMS
   =================================== */

@media (max-width: 768px) {

    /* Better newsletter on mobile */
    .newsletter {
        padding: 1.75rem 1.25rem;
        text-align: center;
    }

    .newsletter h2 {
        font-size: 1.5rem;
        margin-bottom: 0.5rem;
    }

    .newsletter p {
        font-size: 0.9rem;
    }

    .newsletter-form {
        flex-direction: column;
        gap: 0.75rem;
    }

    .newsletter-form input {
        width: 100%;
        padding: 0.95rem 1.25rem;
    }

    .newsletter-form button {
        width: 100%;
    }

    /* Better form layouts */
    .form-row {
        grid-template-columns: 1fr;
    }

    .form-control {
        padding: 0.85rem 1rem;
        font-size: 16px;
    }
}

/* ===================================
   MOBILE FOOTER OPTIMIZATIONS
   =================================== */

@media (max-width: 768px) {

    /* Center-aligned footer */
    .footer {
        text-align: center;
    }

    .footer-grid {
        gap: 2rem;
    }

    .footer-col {
        text-align: center;
    }

    .footer-social {
        justify-content: center;
        gap: 0.5rem;
    }

    .footer-info-row {
        flex-direction: column;
        align-items: center;
        gap: 0.25rem;
        text-align: center;
    }

    .footer-bottom {
        flex-direction: column;
        text-align: center;
        gap: 1rem;
    }

    .footer-bottom-links {
        flex-direction: column;
        gap: 0.75rem;
    }
}

/* ===================================
   SMALL MOBILE (480px and below)
   =================================== */

@media (max-width: 480px) {

    /* Extra small adjustments */
    .section {
        padding: 2rem 0;
    }

    .section-title {
        font-size: 1.5rem;
        margin-bottom: 0.5rem;
    }

    .section-subtitle {
        font-size: 0.9rem;
    }

    /* Compact buttons */
    .btn {
        padding: 0.75rem 1.25rem;
        font-size: 0.875rem;
    }

    .btn-lg {
        padding: 0.85rem 1.5rem;
        font-size: 0.95rem;
    }

    /* Tighter card padding */
    .article-card,
    .feature-card,
    .news-card {
        padding: 1rem;
    }

    /* Smaller icons */
    .feature-icon,
    .category-card .cat-icon {
        width: 48px;
        height: 48px;
        font-size: 1.35rem;
    }

    /* Compact stats */
    .stat-number {
        font-size: 2rem;
    }

    /* Smaller modals */
    .modal {
        max-width: 98%;
    }
}

/* ===================================
   LANDSCAPE ORIENTATION FIXES
   =================================== */

@media (max-width: 768px) and (orientation: landscape) {

    /* Reduce vertical spacing in landscape */
    .hero {
        padding-top: calc(1.5rem + 60px);
        padding-bottom: 1.5rem;
    }

    .section {
        padding: 2rem 0;
    }

    /* Compact hero in landscape */
    .hero h1 {
        font-size: 1.5rem;
        margin-bottom: 0.75rem;
    }

    .hero-text {
        font-size: 0.875rem;
        margin-bottom: 1rem;
    }

    /* Horizontal stats in landscape */
    .stats-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}

/* ===================================
   HIGH DPI / RETINA DISPLAYS
   =================================== */

@media (-webkit-min-device-pixel-ratio: 2),
(min-resolution: 192dpi) {

    /* Sharper text rendering */
    body {
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
        text-rendering: optimizeLegibility;
    }
}

/* ===================================
   DARK MODE SUPPORT (Optional)
   =================================== */

@media (prefers-color-scheme: dark) {
    /* Optional: Add dark mode styles for better mobile experience */
    /* Uncomment if needed
    body {
        background: #0A1628;
        color: rgba(255, 255, 255, 0.9);
    }
    */
}

/* ===================================
   REDUCED MOTION SUPPORT
   =================================== */

@media (prefers-reduced-motion: reduce) {

    /* Disable animations for accessibility */
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }

    .reveal {
        opacity: 1;
        transform: none;
    }
}

/* ===================================
   SAFE AREA INSETS (iPhone X+)
   =================================== */

@supports (padding: max(0px)) {
    body {
        padding-left: max(0px, env(safe-area-inset-left));
        padding-right: max(0px, env(safe-area-inset-right));
    }

    .topbar,
    .navbar,
    .footer {
        padding-left: max(1rem, env(safe-area-inset-left));
        padding-right: max(1rem, env(safe-area-inset-right));
    }

    .footer {
        padding-bottom: max(1rem, env(safe-area-inset-bottom));
    }
}
