/* ============================================
   MOBILE-FIRST RESPONSIVE ENHANCEMENTS
   ============================================ 
   This file enhances the mobile experience with:
   - Hamburger menu for navigation
   - Slide-out category sidebar
   - Horizontal scrolling hero categories
   - Improved touch targets
   - Better typography scaling
   - Optimized layouts for small screens
   - Viewport overflow prevention
   ============================================ */

/* ============================================
   VIEWPORT OVERFLOW PREVENTION
   ============================================ */
html {
    overflow-x: hidden;
}

body {
    overflow-x: hidden;
    position: relative;
    width: 100%;
}

.container {
    max-width: 100%;
    overflow-x: hidden;
}

/* Prevent any element from causing horizontal scroll */
img,
video,
iframe,
embed,
object {
    max-width: 100%;
    height: auto;
}

/* ============================================
   CATEGORY SIDEBAR TOGGLE BUTTON
   ============================================ */
.category-toggle-btn {
    display: none;
    position: fixed;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    background: linear-gradient(135deg, #1f5a9f 0%, #0f3a6a 100%);
    color: #fff;
    border: none;
    border-radius: 0 8px 8px 0;
    padding: 12px 8px;
    font-size: 1.2rem;
    cursor: pointer;
    z-index: 999;
    box-shadow: 2px 2px 10px rgba(0, 0, 0, 0.2);
    writing-mode: vertical-rl;
    text-orientation: mixed;
    transition: all 0.3s ease;
}

.category-toggle-btn:hover {
    padding-right: 12px;
}

.category-toggle-btn.active {
    left: 280px;
}

/* ============================================
   SLIDE-OUT CATEGORY SIDEBAR
   ============================================ */
.category-sidebar {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 280px;
    height: 100vh;
    background: #fff;
    z-index: 998;
    transform: translateX(-100%);
    transition: transform 0.3s ease-in-out;
    box-shadow: 2px 0 20px rgba(0, 0, 0, 0.15);
    overflow-y: auto;
    padding: 20px 0;
}

.category-sidebar.active {
    transform: translateX(0);
}

.category-sidebar-header {
    padding: 15px 20px;
    border-bottom: 1px solid #eee;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.category-sidebar-header h3 {
    margin: 0;
    font-size: 1.1rem;
    color: #1a1a1a;
}

.category-sidebar-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: #666;
    padding: 5px;
}

.category-sidebar-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.category-sidebar-list li {
    border-bottom: 1px solid #f0f0f0;
}

.category-sidebar-list a {
    display: block;
    padding: 15px 20px;
    color: #333;
    text-decoration: none;
    font-size: 1rem;
    transition: all 0.2s ease;
}

.category-sidebar-list a:hover,
.category-sidebar-list a:focus {
    background-color: #f5f5f5;
    color: #1f5a9f;
    padding-left: 25px;
}

.category-sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 997;
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
}

.category-sidebar-overlay.active {
    display: block;
    opacity: 1;
    pointer-events: auto;
}

/* ============================================
   HAMBURGER MENU BUTTON
   ============================================ */
.hamburger-menu {
    display: none;
    flex-direction: column;
    justify-content: center;
    gap: 6px;
    width: 32px;
    height: 32px;
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 0;
    z-index: 1001;
    position: relative;
    border-radius: 50%;
    transition: background-color 0.3s ease;
}

.hamburger-menu:active {
    background-color: rgba(255, 255, 255, 0.1);
}

.hamburger-menu span {
    width: 24px;
    height: 2px;
    background-color: #ffffff;
    border-radius: 2px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    transform-origin: center;
    margin: 0 auto;
}

/* Hamburger to X animation */
.hamburger-menu.active span:nth-child(1) {
    transform: translateY(8px) rotate(45deg);
}

.hamburger-menu.active span:nth-child(2) {
    opacity: 0;
    transform: translateX(-10px);
}

.hamburger-menu.active span:nth-child(3) {
    transform: translateY(-8px) rotate(-45deg);
}

/* ============================================
   MOBILE NAVIGATION OVERLAY
   ============================================ */
@media (max-width: 768px) {

    /* Show hamburger button */
    .hamburger-menu {
        display: flex;
    }

    /* Header adjustments */
    header {
        padding: 12px 0;
        position: relative;
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding-left: 1rem;
        padding-right: 1rem;
    }

    header h1 {
        position: absolute;
        left: 50%;
        transform: translateX(-50%);
        width: max-content;
        max-width: 60%;
        font-size: 1.0rem !important;
        margin: 0 !important;
        padding: 0;
        text-align: center;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    header .logo-container {
        max-width: 80px;
        /* Smaller logo for mobile */
        margin: 0;
        flex-shrink: 0;
    }

    header .logo {
        height: auto;
        max-height: 40px;
        width: auto;
    }

    /* Navigation overlay styling */
    .main-nav {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(10, 31, 58, 0.98);
        /* Deep blue-black brand color */
        backdrop-filter: blur(10px);
        z-index: 1000;
        transform: translateX(100%);
        transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
        display: flex;
        align-items: center;
        justify-content: center;
        padding: 80px 20px;
    }

    .main-nav.active {
        transform: translateX(0);
    }

    .main-nav ul {
        flex-direction: column;
        align-items: center;
        gap: 1.5rem;
        padding: 0;
        width: 100%;
        max-width: 320px;
    }

    .main-nav ul li {
        width: 100%;
        margin: 0;
        border-bottom: 1px solid rgba(255, 255, 255, 0.08);
        padding-bottom: 0.5rem;
    }

    .main-nav ul li:last-child {
        border-bottom: none;
    }

    .main-nav ul li a {
        display: block;
        padding: 10px 0 !important;
        font-size: 1.2rem !important;
        text-align: center;
        width: 100%;
        color: #fff;
        font-weight: 500;
        letter-spacing: 0.5px;
        transition: color 0.2s ease;
    }

    .main-nav ul li a:hover,
    .main-nav ul li a:focus {
        color: #4fa8df;
        /* Brand blue accent */
        background-color: transparent;
    }

    .main-nav ul li a.donate-btn {
        margin-top: 1rem;
        background: linear-gradient(135deg, #1f5a9f, #0f3a6a) !important;
        border-radius: 50px;
        padding: 14px 30px !important;
        font-weight: 700;
        box-shadow: 0 4px 15px rgba(31, 90, 159, 0.4);
    }

    /* Prevent body scroll when menu is open */
    body.menu-open {
        overflow: hidden;
    }

    /* Hide main filters on mobile (moved to sidebar) */
    .blogs-filters-section {
        display: none;
    }
}

/* ============================================
   MOBILE TYPOGRAPHY
   ============================================ */
@media (max-width: 768px) {

    body,
    html {
        font-size: 15px;
    }

    h1 {
        font-size: 1.8em !important;
        line-height: 1.3;
    }

    h2 {
        font-size: 1.5em !important;
        line-height: 1.3;
    }

    h3 {
        font-size: 1.25em !important;
    }

    .main-content h2 {
        font-size: 1.4em !important;
        margin-top: 2rem;
        margin-bottom: 1.5rem;
    }

    .main-content p {
        font-size: 1rem;
        line-height: 1.7;
        margin-bottom: 1.5rem;
    }
}

/* ============================================
   MOBILE HERO SECTION
   ============================================ */
@media (max-width: 768px) {
    .hero-magazine-section {
        display: flex;
        flex-direction: column;
        gap: 1.5rem;
        padding: 1rem 0;
    }

    .hero-tagline-block {
        padding: 1rem 0;
        text-align: center;
        min-height: auto;
        width: 100%;
    }

    .hero-title {
        font-size: 1.4em !important;
        line-height: 1.4;
        padding: 0 10px;
    }

    .hero-manifesto {
        font-size: 0.95rem;
        padding: 0 10px;
    }

    .magazine-grid-wrapper {
        padding: 0;
    }

    .hero-carousel-arrow {
        display: none;
    }
}

/* ============================================
   MOBILE CARD GRIDS
   ============================================ */
@media (max-width: 768px) {
    .topic-grid {
        grid-template-columns: 1fr;
        gap: 1.5rem;
        padding: 0.5rem 0 2rem 0;
    }

    .topic-card {
        border-radius: 10px;
    }

    .topic-card img {
        height: 100%;
        width: 100%;
        object-fit: cover;
        object-position: center;
        position: absolute;
        top: 0;
        left: 0;
    }

    .topic-card-image-wrapper {
        width: 100%;
        height: 180px;
        position: relative;
        overflow: hidden;
    }

    .topic-card-content {
        padding: 1.25rem;
    }

    .topic-card h3 {
        font-size: 1.15em;
        margin-bottom: 0.6rem;
    }

    .topic-card p {
        font-size: 0.9rem;
        line-height: 1.6;
    }

    /* No hover effects on touch devices */
    .topic-card:hover {
        transform: none;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.06);
    }
}

/* ============================================
   MOBILE MAGAZINE CARDS (HERO SECTION)
   Convert to horizontal scrolling carousel
   ============================================ */
@media (max-width: 768px) {

    /* Show sidebar toggle and overlay on mobile */
    .category-toggle-btn,
    .category-sidebar,
    .category-sidebar-overlay {
        display: block;
    }

    .magazine-grid-wrapper {
        position: relative;
        overflow: visible;
    }

    /* Horizontal Sliding Carousel on Mobile */
    .magazine-grid {
        display: flex;
        flex-direction: row;
        flex-wrap: nowrap;
        overflow-x: auto;
        overflow-y: hidden;
        scroll-snap-type: x mandatory;
        -webkit-overflow-scrolling: touch;
        gap: 0.75rem;
        padding: 0.5rem 0;
        margin: 0 -15px;
        padding-left: 15px;
        padding-right: 15px;
        width: calc(100% + 30px);
        scrollbar-width: none;
    }

    .magazine-grid::-webkit-scrollbar {
        display: none;
    }

    .magazine-card-large,
    .magazine-card-medium,
    .magazine-card-small {
        flex: 0 0 auto;
        width: 180px;
        height: 120px;
        scroll-snap-align: start;
        grid-column: auto;
        grid-row: auto;
    }

    .magazine-card {
        border-radius: 10px;
        width: 180px;
        height: 120px;
    }

    .magazine-card-overlay {
        padding: 0.5rem;
    }

    .magazine-card h4 {
        font-size: 0.72rem;
        line-height: 1.1;
        margin-bottom: 0.2rem;
    }

    .magazine-card .category-description {
        display: none;
    }

    /* Hide hero arrow on mobile - we use scroll instead */
    .hero-carousel-arrow {
        display: none;
    }
}

/* ============================================
   MOBILE PAGE HEADERS
   ============================================ */
@media (max-width: 768px) {
    .page-header {
        padding: 2.5rem 1rem;
        margin-bottom: 2rem;
    }

    .page-header h1 {
        font-size: 1.8em !important;
        line-height: 1.3;
    }

    .page-header p {
        font-size: 1rem;
        line-height: 1.6;
    }
}

/* ============================================
   MOBILE SECTION HEADERS
   ============================================ */
@media (max-width: 768px) {
    .section-header {
        margin: 2rem 0 1rem 0;
        padding: 0;
    }

    .section-header h2 {
        font-size: 1.5em;
        text-align: center;
    }

    .see-more-container {
        text-align: center;
        margin: 1.5rem 0 2.5rem 0;
    }

    .see-more-btn {
        display: inline-block;
        padding: 12px 24px;
        font-size: 0.95rem;
    }
}

/* ============================================
   MOBILE COURSES GRID
   ============================================ */
@media (max-width: 768px) {
    .courses-grid {
        grid-template-columns: 1fr;
        gap: 1.5rem;
    }

    .course-image-container {
        height: 180px;
    }

    .course-card-content {
        padding: 1.25rem;
    }

    .course-card h3 {
        font-size: 1.15em;
    }

    .course-card p {
        font-size: 0.9rem;
    }

    .course-meta {
        flex-direction: column;
        gap: 0.5rem;
    }

    /* Course single page */
    .course-header {
        padding: 2rem 0;
    }

    .course-header-content {
        grid-template-columns: 1fr;
        gap: 1.5rem;
    }

    .course-header-content h1 {
        font-size: 1.8em !important;
    }

    .course-header-image {
        order: -1;
    }

    .course-single-container {
        grid-template-columns: 1fr;
        gap: 2rem;
    }

    .course-tabs {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }

    .course-tabs::-webkit-scrollbar {
        display: none;
    }

    .tab-link {
        padding: 0.9rem 1.25rem;
        font-size: 0.95rem;
        white-space: nowrap;
    }
}

/* ============================================
   MOBILE FOOTER
   ============================================ */
@media (max-width: 768px) {
    .site-footer {
        padding: 2rem 1rem 1.5rem 1rem !important;
        margin-left: 0;
        margin-right: 0;
        width: 100%;
    }

    .footer-content {
        flex-direction: column;
        gap: 2rem;
    }

    .footer-section {
        text-align: center;
    }

    .footer-bottom {
        flex-direction: column;
        gap: 1rem;
        text-align: center;
    }
}

/* ============================================
   CONTAINER PADDING FOR MOBILE
   ============================================ */
@media (max-width: 768px) {
    .container {
        width: 100%;
        padding: 0 15px;
    }
}

/* ============================================
   TOUCH-FRIENDLY INTERACTIONS
   ============================================ */
@media (max-width: 768px) {

    /* Increase touch targets */
    a,
    button {
        min-height: 44px;
        min-width: 44px;
    }

    /* Links in content don't need minimum size */
    p a,
    .main-content a:not(.btn) {
        min-height: auto;
        min-width: auto;
    }

    /* Disable hover transforms on touch */
    .topic-card:active {
        transform: scale(0.98);
        transition: transform 0.1s ease;
    }

    .magazine-card:active {
        transform: scale(0.98);
    }

    .featured-scroll-item:active {
        transform: scale(0.98);
    }
}

/* ============================================
   EXTRA SMALL SCREENS (< 480px)
   ============================================ */
@media (max-width: 480px) {

    body,
    html {
        font-size: 14px;
    }

    header h1 {
        font-size: 1rem !important;
    }

    header .logo-container {
        max-width: 100px;
    }

    .hero-title {
        font-size: 1.2em !important;
    }

    .magazine-grid {
        grid-template-columns: 1fr;
        grid-auto-rows: 150px;
        gap: 0.6rem;
    }

    .magazine-card-overlay {
        padding: 0.75rem;
    }

    .magazine-card h4 {
        font-size: 0.9rem;
    }

    .magazine-card .category-description {
        font-size: 0.75rem;
        -webkit-line-clamp: 1;
    }

    .topic-card img {
        height: 100%;
    }

    .topic-card-image-wrapper {
        height: 150px;
    }

    .topic-card-content {
        padding: 1rem;
    }

    .topic-card h3 {
        font-size: 1.05em;
    }

    .section-header h2 {
        font-size: 1.3em;
    }
}

/* ============================================
   SAFE AREA INSETS (NOTCHES)
   ============================================ */
@supports (padding: env(safe-area-inset-bottom)) {
    .main-nav {
        padding-bottom: calc(60px + env(safe-area-inset-bottom));
    }

    .site-footer {
        padding-bottom: calc(1.5rem + env(safe-area-inset-bottom)) !important;
    }
}

/* ============================================
   REDUCED MOTION (ACCESSIBILITY)
   ============================================ */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }

    .hamburger-menu span {
        transition: none;
    }

    .main-nav {
        transition: none;
    }
}

/* FORCE DESKTOP NAVBAR HEIGHT FIX */
@media (min-width: 769px) {
    .main-nav {
        padding: 8px 0 !important;
        margin-top: 0 !important;
    }
}