/* --- Enhanced Mobile Responsive Design --- */

/* Mobile First Base Styles */
html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    -webkit-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
}

/* Improved Touch Targets */
button, .btn, a {
    min-height: 44px;
    min-width: 44px;
    padding: 0.75rem 1rem;
    border-radius: 0.5rem;
    transition: all 0.3s ease;
    cursor: pointer;
}

/* Focus and Active States for Mobile */
button:focus,
.btn:focus,
a:focus {
    outline: 2px solid var(--primary-color, #00B4D8);
    outline-offset: 2px;
}

button:active,
.btn:active {
    transform: scale(0.98);
}

/* Typography Responsive Adjustments */
h1 {
    font-size: clamp(1.75rem, 5vw, 3rem);
    line-height: 1.2;
}

h2 {
    font-size: clamp(1.5rem, 4vw, 2.5rem);
    line-height: 1.3;
}

h3 {
    font-size: clamp(1.25rem, 3vw, 2rem);
    line-height: 1.4;
}

p {
    font-size: clamp(0.9rem, 2.5vw, 1.1rem);
    line-height: 1.6;
}

/* Navigation Container */
.nav-container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    padding: 0.75rem 1rem;
}

/* Desktop Navigation */
.desktop-nav {
    display: block;
}

.desktop-nav ul {
    display: flex;
    gap: 2rem;
    list-style: none;
    margin: 0;
    padding: 0;
}

.desktop-nav a {
    color: var(--primary-color, #00B4D8);
    text-decoration: none;
    font-weight: 500;
    padding: 0.5rem 1rem;
    border-radius: 4px;
    transition: all 0.3s ease;
}

.desktop-nav a:hover,
.desktop-nav a.active {
    background: var(--primary-color);
    color: #fff;
}

/* Mobile Navigation Styles */
.hamburger {
    display: none;
}

@media (max-width: 768px) {
    /* Hide desktop nav */
    .desktop-nav {
        display: none;
    }
    
    /* Show hamburger in mobile view */
    .hamburger {
        display: flex;
        flex-direction: column;
        justify-content: space-around;
        width: 2.5rem;
        height: 2.5rem;
        background: transparent;
        border: none;
        cursor: pointer;
        padding: 0.5rem;
        z-index: 1001;
        position: relative;
        margin-right: -0.5rem;
    }

    /* Hamburger lines */
    .hamburger-line {
        width: 100%;
        height: 3px;
        background: var(--primary-color); /* Use brand color for better visibility */
        border-radius: 10px;
        transition: all 0.3s ease;
        position: relative;
        transform-origin: center;
    }

    /* Animation for hamburger to X */
    .hamburger.active .hamburger-line:nth-child(1) {
        transform: translateY(8px) rotate(45deg);
        background: var(--text-primary);
    }

    .hamburger.active .hamburger-line:nth-child(2) {
        opacity: 0;
        transform: translateX(-20px);
    }

    .hamburger.active .hamburger-line:nth-child(3) {
        transform: translateY(-8px) rotate(-45deg);
        background: var(--text-primary);
    }

    /* Mobile Navigation Panel - neutralized visibility gating to avoid conflicts */
    .mobile-nav {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100vh;
        background: rgba(10, 25, 41, 0.95);
        z-index: 1000;
        /* Let css/navigation.css control visibility with display: none/flex */
        opacity: 1 !important;
        visibility: visible !important;
        pointer-events: auto !important;
        display: none; /* default hidden; shown via #mobile-nav.active in css/navigation.css */
        justify-content: center;
        align-items: center;
        backdrop-filter: blur(10px);
        -webkit-backdrop-filter: blur(10px);
    }

    /* Active state now handled by css/navigation.css (#mobile-nav.active { display:flex }) */
    .mobile-nav.active {
        display: flex;
    }

    /* Mobile Navigation Content */
    .mobile-nav-content {
        width: 100%;
        max-width: 400px;
        padding: 2rem;
    }

    /* Mobile Navigation List */
    .mobile-nav ul {
        list-style: none;
        padding: 0;
        margin: 0;
        text-align: center;
        display: flex;
        flex-direction: column;
        gap: 1.5rem;
    }

    /* Remove hidden/animation state that kept items invisible */
    .mobile-nav li {
        opacity: 1 !important;
        transform: none !important;
        transition: none !important;
    }

    /* Mobile Navigation Links */
    .mobile-nav a {
        color: var(--text-primary);
        font-size: 1.5rem;
        font-weight: 600;
        text-decoration: none;
        display: block;
        padding: 1rem;
        transition: all 0.3s ease;
        border-radius: 8px;
        background: rgba(255, 255, 255, 0.05);
    }

    .mobile-nav a:active,
    .mobile-nav a.active {
        background: var(--primary-color);
        color: white;
    }
}

/* Card Layouts */
.card {
    width: 100%;
    margin-bottom: 1rem;
}

/* Forms */
input, select, textarea {
    font-size: 16px; /* Prevents iOS zoom on focus */
}

/* Touch-friendly Buttons */
button, .btn {
    min-height: 44px;
    min-width: 44px;
    padding: 0.75rem 1rem;
}

/* Responsive Tables */
.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* Responsive Images */
img {
    max-width: 100%;
    height: auto;
}

/* Grid System */
.grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1rem;
}

/* Media Queries */

/* Small devices (640px and up) */
@media (min-width: 640px) {
    html {
        font-size: 16px;
    }

    h1 {
        font-size: var(--h1-size-tablet);
    }

    h2 {
        font-size: var(--h2-size-tablet);
    }

    .grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* Medium devices (768px and up) */
@media (min-width: 768px) {
    .hamburger {
        display: none;
    }

    .mobile-nav {
        display: none;
    }

    .desktop-nav {
        display: flex;
    }

    .grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

/* Large devices (1024px and up) */
@media (min-width: 1024px) {
    html {
        font-size: 16px;
    }

    h1 {
        font-size: var(--h1-size-desktop);
    }

    h2 {
        font-size: var(--h2-size-desktop);
    }

    p {
        font-size: var(--body-size-desktop);
    }

    .grid {
        grid-template-columns: repeat(4, 1fr);
    }
}

/* Touch Device Optimizations */
@media (hover: none) {
    a:hover, button:hover {
        transform: none !important;
    }
    
    nav a, button {
        padding: 0.75rem 1rem;
    }
}

/* Landscape Mode */
@media (orientation: landscape) and (max-height: 500px) {
    .mobile-nav {
        overflow-y: scroll;
    }
}

/* Prevent zoom on input focus for iOS */
@media screen and (max-width: 768px) {
    input[type="text"],
    input[type="email"],
    input[type="search"],
    textarea,
    select {
        font-size: 16px;
        -webkit-appearance: none;
        appearance: none;
    }
}

/* Improve scroll performance */
* {
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
}

/* Safe area for notched devices */
@supports (padding: max(0px)) {
    .container,
    header,
    .nav-container {
        padding-left: max(1rem, env(safe-area-inset-left));
        padding-right: max(1rem, env(safe-area-inset-right));
    }
    
    header {
        padding-top: max(0.75rem, env(safe-area-inset-top));
    }
}

/* Reduce motion for accessibility */
@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;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .btn,
    button {
        border: 2px solid currentColor;
    }
    
    .resource-card,
    .chat-container {
        border: 1px solid currentColor;
    }
}

/* Touch-friendly spacing */
.resource-card,
.chat-container,
.search-container {
    margin-bottom: 1rem;
}

@media (max-width: 480px) {
    .resource-card,
    .chat-container,
    .search-container {
        margin-bottom: 0.75rem;
    }
}

/* Improved form controls for mobile */
input,
textarea,
select {
    border-radius: 0.5rem;
    border: 1px solid rgba(0, 0, 0, 0.2);
    transition: border-color 0.3s ease, box-shadow 0.3s ease;
}

input:focus,
textarea:focus,
select:focus {
    border-color: var(--primary-color, #00B4D8);
    box-shadow: 0 0 0 3px rgba(0, 180, 216, 0.1);
}

/* Sticky positioning fixes for mobile */
@media (max-width: 768px) {
  header {
    position: sticky;
    top: 0;
    z-index: 1000;
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
  }
}
