/* Global Mobile Optimization CSS for St. Karolo Boromeo Secondary School */

/* Mobile-first approach with enhanced touch targets and readability */

/* Base mobile optimizations */
* {
    box-sizing: border-box;
}

body {
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    /* Prevent horizontal scroll on Android */
    overflow-x: hidden;
    /* Improve scrolling performance */
    -webkit-overflow-scrolling: touch;
    width: 100%;
    max-width: 100vw;
    position: relative;
}

/* Global overflow fix */
html {
    overflow-x: hidden !important;
    width: 100% !important;
    max-width: 100vw !important;
}

/* Enhanced touch targets for mobile - Android optimized */
a, button, input, select, textarea {
    min-height: 48px; /* Increased for better Android touch */
    min-width: 48px;
    /* Better touch feedback */
    -webkit-tap-highlight-color: rgba(67, 160, 71, 0.3);
}

/* Android-specific optimizations */
@media screen and (-webkit-min-device-pixel-ratio: 0) {
    body {
        /* Prevent zoom on Android */
        -webkit-text-size-adjust: none;
    }
    
    input, select, textarea {
        /* Prevent zoom on focus for Android */
        font-size: 16px;
    }
}

/* Improved font rendering on mobile */
body {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

/* Mobile navigation improvements - Android optimized */
@media (max-width: 768px) {
    /* Global overflow and width fixes */
    html, body {
        overflow-x: hidden !important;
        width: 100% !important;
        max-width: 100vw !important;
    }
    
    /* Ensure all containers don't exceed viewport width */
    .container, .container-fluid, .row, .col, [class*="col-"] {
        max-width: 100vw !important;
        overflow-x: hidden !important;
        box-sizing: border-box !important;
    }
    
    /* Fix any elements that might cause horizontal overflow */
    * {
        max-width: 100% !important;
        box-sizing: border-box !important;
    }
    .navbar-toggler {
        border: none;
        padding: 12px 16px; /* Larger touch target */
        min-height: 48px;
        min-width: 48px;
    }
    
    .navbar-toggler:focus {
        box-shadow: 0 0 0 3px rgba(67, 160, 71, 0.3);
    }
    
    .navbar-collapse {
        background: rgba(0, 0, 0, 0.95);
        margin-top: 10px;
        border-radius: 8px;
        padding: 20px; /* More padding for easier touch */
        /* Better backdrop for Android */
        backdrop-filter: blur(10px);
        -webkit-backdrop-filter: blur(10px);
    }
    
    .navbar-nav .nav-link {
        padding: 16px 0; /* Larger touch targets */
        border-bottom: 1px solid rgba(255, 255, 255, 0.1);
        font-size: 16px; /* Prevent zoom on Android */
        min-height: 48px;
        display: flex;
        align-items: center;
    }
    
    .navbar-nav .nav-link:last-child {
        border-bottom: none;
    }
    
    .dropdown-menu {
        position: static !important;
        float: none;
        width: 100%;
        margin-top: 0;
        background-color: rgba(255, 255, 255, 0.1);
        border: none;
        box-shadow: none;
        padding: 10px 0;
    }
    
    .dropdown-item {
        color: white !important;
        padding: 16px 20px; /* Larger touch targets */
        font-size: 16px;
        min-height: 48px;
        display: flex;
        align-items: center;
    }
    
    /* Mega menu mobile optimization */
    .has-mega-menu .dropdown-menu {
        position: static !important;
        transform: none !important;
        width: 100% !important;
        min-width: auto !important;
    }
    
    .tp-megamenu-main {
        padding: 15px !important;
    }
    
    .tp-megamenu-academics-content {
        flex-direction: column !important;
        gap: 20px !important;
    }
    
    .tp-megamenu-section {
        border-right: none !important;
        border-bottom: 1px solid rgba(255, 255, 255, 0.1);
        padding: 15px 0 !important;
    }
    
    .tp-megamenu-section:last-child {
        border-bottom: none !important;
    }
}

/* Image optimization for mobile */
img {
    max-width: 100%;
    height: auto;
    display: block;
}

/* Video optimization for mobile */
video {
    max-width: 100%;
    height: auto;
}

/* Form improvements for mobile - Android optimized */
@media (max-width: 768px) {
    .form-control, .form-select {
        font-size: 16px; /* Prevents zoom on Android and iOS */
        padding: 16px 20px; /* Larger padding for easier touch */
        border-radius: 8px;
        min-height: 48px; /* Larger touch target */
        /* Better focus state for Android */
        border: 2px solid #ddd;
        transition: border-color 0.3s ease;
    }
    
    .form-control:focus, .form-select:focus {
        border-color: #43A047;
        box-shadow: 0 0 0 3px rgba(67, 160, 71, 0.1);
        outline: none;
    }
    
    .btn {
        padding: 16px 24px; /* Larger padding */
        font-size: 16px;
        border-radius: 8px;
        min-height: 48px; /* Larger touch target */
        /* Better touch feedback */
        transition: all 0.2s ease;
        -webkit-tap-highlight-color: rgba(67, 160, 71, 0.3);
    }
    
    .btn:active {
        transform: scale(0.98); /* Touch feedback */
    }
    
    /* Special button optimizations */
    .enroll-btn, .apply-btn, .nav-btn {
        min-height: 48px;
        padding: 16px 24px;
        font-size: 16px;
    }
    
    .round-btn {
        min-height: 48px;
        min-width: 48px;
        font-size: 18px;
    }
}

/* Card and content spacing for mobile */
@media (max-width: 768px) {
    .card {
        margin-bottom: 15px;
        border-radius: 12px;
    }
    
    .container {
        padding-left: 15px;
        padding-right: 15px;
    }
    
    .row {
        margin-left: -10px;
        margin-right: -10px;
    }
    
    .col, [class*="col-"] {
        padding-left: 10px;
        padding-right: 10px;
    }
}

/* Typography improvements for mobile */
@media (max-width: 768px) {
    h1 {
        font-size: 1.8rem;
        line-height: 1.2;
    }
    
    h2 {
        font-size: 1.5rem;
        line-height: 1.3;
    }
    
    h3 {
        font-size: 1.3rem;
        line-height: 1.3;
    }
    
    h4 {
        font-size: 1.1rem;
        line-height: 1.4;
    }
    
    p {
        font-size: 0.95rem;
        line-height: 1.6;
    }
    
    .lead {
        font-size: 1.1rem;
        line-height: 1.5;
    }
}

/* Footer mobile optimization */
@media (max-width: 768px) {
    .footer-container {
        flex-direction: column;
        text-align: center;
        gap: 20px;
    }
    
    .footer-column {
        width: 100%;
        margin-bottom: 20px;
    }
    
    .footer-column ul {
        display: flex;
        flex-wrap: wrap;
        justify-content: center;
        gap: 15px;
    }
    
    .footer-column ul li {
        margin-bottom: 0;
    }
}

/* Loading and performance optimizations - Android focused */
@media (max-width: 768px) {
    /* Optimize animations for Android performance */
    *, *::before, *::after {
        /* Reduce complex animations on slower Android devices */
        animation-duration: 0.3s !important;
        transition-duration: 0.2s !important;
    }
    
    /* Optimize scrolling for Android */
    .container, .row, .col {
        -webkit-overflow-scrolling: touch;
        /* Better scrolling performance */
        transform: translateZ(0);
        will-change: scroll-position;
    }
    
    /* Video optimization for Android */
    video {
        /* Optimize video playback on Android */
        object-fit: cover;
        /* Reduce video quality on mobile for better performance */
        -webkit-transform: translateZ(0);
        transform: translateZ(0);
    }
    
    /* Hero video specific optimizations */
    .hero-video {
        /* Disable video on very small screens for performance */
        display: block;
    }
    
    /* Image lazy loading optimization */
    img {
        /* Better image loading on Android */
        loading: lazy;
        /* Prevent layout shift */
        aspect-ratio: attr(width) / attr(height);
    }
    
    /* Font loading optimization */
    @font-face {
        font-display: swap; /* Better font loading on Android */
    }
}

/* Accessibility improvements for mobile */
@media (max-width: 768px) {
    /* Ensure sufficient color contrast */
    .text-muted {
        color: #6c757d !important;
    }
    
    /* Improve focus indicators */
    a:focus, button:focus, input:focus, select:focus, textarea:focus {
        outline: 2px solid #43A047;
        outline-offset: 2px;
    }
    
    /* Ensure readable text sizes */
    small, .small {
        font-size: 0.85rem;
    }
}

/* Landscape orientation optimizations */
@media (max-width: 768px) and (orientation: landscape) {
    .hero-section {
        min-height: 60vh;
    }
    
    .page-hero {
        padding: 40px 0;
    }
    
    .navbar {
        padding: 8px 0;
    }
}

/* Very small screens (320px and below) */
@media (max-width: 320px) {
    .container {
        padding-left: 10px;
        padding-right: 10px;
    }
    
    h1 {
        font-size: 1.5rem;
    }
    
    h2 {
        font-size: 1.3rem;
    }
    
    .btn {
        padding: 10px 16px;
        font-size: 14px;
    }
    
    .form-control, .form-select {
        font-size: 14px;
        padding: 10px 12px;
    }
}

/* High DPI display optimizations */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    /* Ensure crisp text rendering */
    body {
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
    }
}

/* Dark mode support for mobile */
@media (prefers-color-scheme: dark) and (max-width: 768px) {
    .card {
        background-color: #2d3748;
        color: #e2e8f0;
    }
    
    .form-control, .form-select {
        background-color: #4a5568;
        color: #e2e8f0;
        border-color: #718096;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* Android-specific optimizations */
@media screen and (-webkit-min-device-pixel-ratio: 0) {
    /* Android Chrome optimizations */
    body {
        /* Prevent text selection issues on Android */
        -webkit-user-select: none;
        -moz-user-select: none;
        -ms-user-select: none;
        user-select: none;
    }
    
    /* Allow text selection in input fields */
    input, textarea, [contenteditable] {
        -webkit-user-select: text;
        -moz-user-select: text;
        -ms-user-select: text;
        user-select: text;
    }
    
    /* Better touch handling for Android */
    .btn, .nav-link, .dropdown-item {
        /* Prevent double-tap zoom on Android */
        touch-action: manipulation;
    }
    
    /* Optimize video for Android */
    video {
        /* Better video performance on Android */
        -webkit-transform: translate3d(0, 0, 0);
        transform: translate3d(0, 0, 0);
        /* Hardware acceleration */
        -webkit-backface-visibility: hidden;
        backface-visibility: hidden;
    }
}

/* Enhanced Hero Section Mobile Optimization for Android */
@media (max-width: 768px) {
    .hero-section {
        min-height: 100vh;
        min-height: -webkit-fill-available; /* Android viewport fix */
        position: relative;
        overflow: hidden;
    }
    
    .hero-video {
        position: absolute;
        top: 0;
        left: 0;
        width: 100% !important;
        height: 100% !important;
        object-fit: cover !important;
        object-position: center center !important;
        z-index: 1;
        /* Ensure video is visible on Android */
        display: block !important;
        min-width: 100% !important;
        min-height: 100% !important;
    }
    
    .hero-overlay {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0, 0, 0, 0.4);
        z-index: 2;
    }
    
    .hero-text {
        position: relative;
        z-index: 3;
        padding: 60px 0 40px 0 !important;
        text-align: center;
    }
    
    .hero-text h1 {
        font-size: 2.2rem !important;
        line-height: 1.2 !important;
        margin-bottom: 15px !important;
        text-shadow: 2px 2px 4px rgba(0,0,0,0.8) !important;
    }
    
    .hero-text .lead {
        font-size: 1.1rem !important;
        line-height: 1.4 !important;
        margin-bottom: 25px !important;
        padding: 0 15px;
        text-shadow: 1px 1px 2px rgba(0,0,0,0.8) !important;
    }
    
    .hero-buttons {
        display: flex;
        flex-direction: column;
        gap: 15px;
        align-items: center;
        padding: 0 15px;
    }
    
    .hero-buttons .btn {
        width: 100%;
        max-width: 280px;
        padding: 16px 24px !important;
        font-size: 16px !important;
        border-radius: 50px !important;
        min-height: 48px;
    }
}

/* Feature Cards Mobile Optimization - Prevent Overflow */
@media (max-width: 768px) {
    .feature-cards {
        margin-top: -80px !important;
        padding: 0 15px;
    }
    
    .feature-card {
        margin-bottom: 15px !important;
        padding: 15px 10px !important; /* Reduced padding */
        border-radius: 12px;
        box-shadow: 0 4px 20px rgba(0,0,0,0.1) !important;
        background: rgba(255,255,255,0.98) !important;
        height: 140px !important; /* Reduced height */
    }
    
    .feature-card h3 {
        font-size: 0.9rem !important; /* Reduced font size */
        line-height: 1.2 !important; /* Tighter line height */
        margin-bottom: 4px !important; /* Reduced margin */
    }
    
    .feature-card p {
        font-size: 0.8rem !important; /* Reduced font size */
        line-height: 1.3 !important; /* Tighter line height */
        margin-bottom: 8px !important; /* Reduced margin */
        /* Limit paragraph height to prevent overflow */
        max-height: 40px !important;
        overflow: hidden !important;
        display: -webkit-box !important;
        -webkit-line-clamp: 2 !important; /* Reduced to 2 lines */
        -webkit-box-orient: vertical !important;
    }
    
    .feature-card .btn {
        font-size: 14px !important;
        padding: 10px 20px !important;
        min-height: 40px;
    }
}

/* About School Section Mobile Optimization */
@media (max-width: 768px) {
    .about-section {
        padding: 40px 0 !important;
        margin-top: 0 !important;
    }
    
    .about-content {
        flex-direction: column !important;
        gap: 30px;
    }
    
    .about-image {
        order: 1;
        flex: none !important;
        width: 100%;
        max-width: 100%;
    }
    
    .about-text {
        order: 2;
        flex: none !important;
        width: 100%;
        padding: 0 15px;
    }
    
    .about-text h2 {
        font-size: 2rem !important;
        line-height: 1.2 !important;
        margin: 15px 0 20px 0 !important;
    }
    
    .about-text p {
        font-size: 1rem !important;
        line-height: 1.5 !important;
        margin-bottom: 20px !important;
    }
    
    .about-text .feature-item {
        margin-bottom: 20px !important;
        padding: 15px;
        background: rgba(67, 160, 71, 0.05);
        border-radius: 8px;
    }
    
    .about-text .feature-item strong {
        font-size: 1rem !important;
        display: block;
        margin-bottom: 8px;
    }
    
    .about-text .feature-item p {
        font-size: 0.9rem !important;
        line-height: 1.4 !important;
        margin: 0 !important;
    }
}

/* Carousel Cards Mobile Optimization - Prevent Overflow */
@media (max-width: 768px) {
    .carousel-container {
        padding: 0 15px;
        margin: 20px 0;
    }
    
    .card {
        min-height: auto !important;
        max-height: 400px !important;
        margin: 0 10px;
        border-radius: 12px;
        overflow: hidden;
    }
    
    .card-content {
        padding: 15px !important;
    }
    
    .card-content img {
        width: 100%;
        height: 120px !important;
        object-fit: cover;
        border-radius: 8px;
    }
    
    .card-content h3 {
        font-size: 1rem !important;
        line-height: 1.3 !important;
        margin: 12px 0 8px 0 !important;
        /* Limit title height */
        max-height: 40px;
        overflow: hidden;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
    }
    
    .card-content p {
        font-size: 0.85rem !important;
        line-height: 1.4 !important;
        margin-bottom: 12px !important;
        /* Limit paragraph height to prevent overflow */
        max-height: 80px;
        overflow: hidden;
        display: -webkit-box;
        -webkit-line-clamp: 3;
        -webkit-box-orient: vertical;
    }
    
    .subjects {
        font-size: 0.8rem !important;
        padding: 4px 8px !important;
        margin-bottom: 8px !important;
    }
    
    .read-more {
        font-size: 0.8rem !important;
        padding: 6px 12px !important;
    }
}

/* Statistics Section Mobile Optimization */
@media (max-width: 768px) {
    .stats-container {
        padding: 30px 15px !important;
        margin: 20px 0;
        flex-wrap: wrap;
        gap: 15px;
    }
    
    .stat-box {
        flex: 1 1 calc(50% - 7.5px);
        min-width: calc(50% - 7.5px);
        padding: 20px 10px !important;
    }
    
    .stat-number {
        font-size: 1.8rem !important;
        margin-bottom: 5px !important;
    }
    
    .stat-label {
        font-size: 0.8rem !important;
        line-height: 1.2 !important;
    }
}

/* Very Small Android Screens (320px and below) */
@media (max-width: 320px) {
    .hero-text h1 {
        font-size: 1.8rem !important;
    }
    
    .hero-text .lead {
        font-size: 1rem !important;
    }
    
    .feature-card p {
        max-height: 100px !important;
        -webkit-line-clamp: 3 !important;
    }
    
    .card-content p {
        max-height: 60px !important;
        -webkit-line-clamp: 2 !important;
    }
    
    .about-text h2 {
        font-size: 1.6rem !important;
    }
}

/* Low-end Android device optimizations */
@media (max-width: 480px) and (max-height: 800px) {
    /* Reduce visual complexity for low-end devices */
    .hero-video {
        /* Disable video on very small/low-end devices */
        display: none;
    }
    
    .hero-section {
        /* Use background image instead of video */
        background: linear-gradient(135deg, #43A047 0%, #2E7D32 100%);
        background-size: cover;
        background-position: center;
    }
    
    /* Reduce animations for better performance */
    .feature-card:hover,
    .blog-card:hover,
    .card:hover {
        transform: none !important;
    }
    
    /* Simplify carousel animations */
    .carousel-track,
    .blog-carousel-track {
        animation: none !important;
    }
}

/* Android landscape optimizations */
@media (max-width: 768px) and (orientation: landscape) {
    .hero-section {
        min-height: 70vh;
    }
    
    .navbar {
        padding: 8px 0;
    }
    
    .top-bar {
        display: none; /* Hide top bar in landscape */
    }
    
    body {
        padding-top: 60px;
    }
}

/* Android keyboard handling */
@media (max-width: 768px) {
    /* Prevent viewport issues when keyboard appears */
    .container {
        min-height: 100vh;
        min-height: -webkit-fill-available;
    }
    
    /* Better form handling when keyboard is open */
    .form-control:focus {
        /* Ensure form stays visible when keyboard opens */
        scroll-margin-top: 100px;
    }
}

/* Android status bar handling */
@media (max-width: 768px) {
    /* Account for Android status bar */
    .navbar {
        padding-top: env(safe-area-inset-top, 0);
    }
    
    .top-bar {
        padding-top: env(safe-area-inset-top, 0);
    }
}
