/*
  ===================================================================
  FINAL RESPONSIVE.CSS (for screens <= 768px)
  ===================================================================
  This version creates a true responsive hybrid of your main site.
  - Re-stacks header into 3 sections as requested.
  - Brings back the AI Assistant tab.
  - Brings back the notebook paper styling.
  - Brings back the floating tools.
*/

@media (max-width: 768px) {

    /* === 1. Hide Desktop & Unused Mobile Elements === */

    /* Hide desktop sidebars */
    .left-sidebar,
    .right-sidebar {
        display: none !important;
    }

    /* Hide the 4-button "Home/Library/Tools/Profile" footer (it's not the one we style) */
    .mobile-footer {
        display: none !important;
    }

    /* Hide the hamburger toggle (we use the bottom bar) */
    .sidebar-toggle {
        display: none !important;
    }

    /* === 2. Main Layout === */
    .app-container {
        padding: 0;
        display: flex;
        flex-direction: column;
        min-height: 100vh;
        max-width: 100%;
        gap: 0;
    }

    /* Main content area */
    .main-content {
        flex: 1;
        border-radius: 0;
        box-shadow: none;
        height: auto;
        padding: 0;
        border: none;
        display: flex;
        flex-direction: column;
        overflow: hidden;
    }

    /* === 3. New 3-Section Header === */

    /* --- Section 1: Top Bar (Home & Login) --- */
    .chapter-header {
        padding: 12px 15px;
        position: sticky;
        top: 0;
        z-index: 200;
    }

    .header-content {
        display: flex;
        justify-content: space-between;
        align-items: center;
        width: 100%;
    }

    /* Show "StudyVision" text on mobile */
    .back-home span {
        display: inline !important;
        font-size: 1.1rem;
        font-weight: 600;
    }

    .back-home {
        color: white;
        text-decoration: none;
        display: flex;
        align-items: center;
        gap: 8px;
        font-size: 1.1rem;
    }

    /* Style the login/profile buttons */
    .user-actions {
        gap: 8px;
    }

    .login-btn {
        padding: 8px 12px;
        font-size: 0.9rem;
    }

    .login-btn i {
        margin-right: 5px;
    }

    .user-profile {
        gap: 8px;
    }

    #userName {
        display: none;
    }

    /* --- Section 2: Chapter Nav Bar ( < Chapter Title > ) --- */
    .chapter-nav {
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-top: 12px;
        padding-top: 12px;
        border-top: 1px solid rgba(255, 255, 255, 0.1);
    }

    .chapter-title {
        font-size: 1.3rem;
        font-weight: 600;
        flex: 1;
        text-align: center;
        padding: 0 60px;
        margin: 0;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .nav-controls {
        display: flex;
        gap: 10px;
    }

    /* Style the Prev/Next buttons */
    .nav-btn {
        padding: 8px 12px;
        min-width: auto;
        border-radius: 20px;
        font-size: 0.8rem;
        white-space: nowrap;
    }

    .nav-btn i {
        margin: 0 4px;
        font-size: 0.9rem;
    }

    /* --- Section 3: Content Tabs (Notes, PYQs, AI, etc.) --- */
    .tools-header {
        padding: 12px 15px 8px 15px;
        flex-wrap: nowrap;
        overflow-x: auto;
        flex-shrink: 0;
        scrollbar-width: none;
    }

    .tools-header::-webkit-scrollbar {
        display: none;
    }

    /* Make tabs scroll horizontally */
    .content-mode {
        flex-wrap: nowrap;
        gap: 8px;
        padding-bottom: 0;
    }

    .mode-btn {
        padding: 8px 16px;
        white-space: nowrap;
        flex-shrink: 0;
        font-size: 0.85rem;
    }

    /* Hide fullscreen button on mobile */
    .fullscreen-btn {
        display: none;
    }

    /* === 4. Main Content (WITH Notebook Style) === */

    .content-tabs {
        flex: 1;
        overflow-y: auto;
        padding: 0;
        -webkit-overflow-scrolling: touch;
    }

    .content-tab.active {
        display: block;
        padding: 0;
        height: 100%;
        overflow-y: auto;
    }

    /* Notebook container */
    .notebook-container {
        padding: 0;
        height: 100%;
        display: flex;
        flex-direction: column;
    }

    .notebook-paper {
        padding: 1.5rem 1rem 2rem 2.5rem;
        min-height: auto;
        height: auto;
        box-shadow: none;
        margin: 0;
        width: 100%;
        max-width: 100%;
        border-radius: 0;
        flex: 1;
        display: flex;
        flex-direction: column;
    }

    /* Adjust the red margin line position */
    .notebook-paper::before {
        left: 30px;
    }

    .notebook-content {
        padding-right: 10px;
        flex: 1;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Adjust font sizes for mobile readability */
    .notebook-content h1 {
        font-size: 1.7rem;
    }

    .notebook-content h2 {
        font-size: 1.4rem;
        padding-left: 0.8rem;
    }

    .notebook-content h3 {
        font-size: 1.2rem;
    }

    .notebook-content p,
    .notebook-content li {
        font-size: 0.95rem;
        line-height: 1.6;
    }

    /* Ensure content expands properly */
    .notebook-content {
        min-height: 400px;
    }

    /* === 5. Floating Tools === */
    .floating-tools {
        position: fixed;
        bottom: 80px;
        right: 15px;
        z-index: 99;
        display: flex !important;
        flex-direction: column;
        gap: 12px;
    }

    .float-btn {
        width: 50px;
        height: 50px;
        font-size: 1.2rem;
    }

    /* === 6. Bottom Bar (The .mobile-bottom-nav) === */

    .mobile-bottom-nav {
        display: flex;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: white;
        border-top: 1px solid #E0E0E0;
        padding: 12px 0;
        z-index: 100;
    }

    /* Hide the Prev/Next buttons in bottom bar (they are in header now) */
    .mobile-bottom-nav .nav-section.left,
    .mobile-bottom-nav .nav-section.right {
        display: none;
    }

    /* Center the Filters/Tools buttons */
    .mobile-bottom-nav .nav-section.center {
        flex: 1;
        display: flex;
        justify-content: space-around;
        flex-direction: row;
    }

    /* Style the "Filters" and "Study Tools" buttons */
    .tool-btn-mobile {
        background: none;
        border: none;
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 4px;
        font-size: 0.75rem;
        font-weight: 600;
        color: #4A90E2;
        cursor: pointer;
        padding: 5px 10px;
        border-radius: 8px;
        transition: all 0.3s;
    }

    .tool-btn-mobile i {
        font-size: 1.3rem;
    }

    .tool-btn-mobile.active {
        background: #f0f7ff;
        color: #2A5C82;
    }
    /* Mobile responsive adjustments */
@media (max-width: 768px) {
    .unit-converter-container {
        padding: 0 10px;
    }
    
    .conversion-result {
        font-size: 1rem;
        padding: 10px;
    }
    
    .highlight-color-btn {
        width: 40px !important;
        height: 40px !important;
    }
}

    /* === 7. Mobile Sidebars === */
    .sidebar-overlay {
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 500;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.3s ease-in-out;
    }

    .sidebar-overlay.active {
        opacity: 1;
        pointer-events: auto;
    }

    .mobile-sidebar {
        position: fixed;
        top: 0;
        bottom: 0;
        width: 85%;
        max-width: 320px;
        background: #FFF;
        z-index: 600;
        display: flex;
        flex-direction: column;
        transition: transform 0.3s ease-in-out;
    }

    /* Filters sidebar opens from right */
    @media (max-width: 768px) {

        /* Fix sidebar directions */
        #mobileFiltersSidebar {
            left: 0;
            transform: translateX(-100%);
        }

        #mobileToolsSidebar {
            right: 0;
            transform: translateX(100%);
        }

        .mobile-sidebar.active {
            transform: translateX(0) !important;
        }
    }



    .sidebar-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 18px 20px;
        border-bottom: 1px solid #eee;
        flex-shrink: 0;
        background: #f8fafc;
    }

    .sidebar-header h3 {
        margin: 0;
        color: var(--primary);
        font-size: 1.2rem;
    }

    .sidebar-close {
        background: none;
        border: none;
        font-size: 1.4rem;
        color: #666;
        cursor: pointer;
        padding: 5px;
        width: 40px;
        height: 40px;
        display: flex;
        align-items: center;
        justify-content: center;
        border-radius: 50%;
        transition: background 0.3s;
    }

    .sidebar-close:hover {
        background: #f0f0f0;
    }

    .sidebar-content {
        flex: 1;
        overflow-y: auto;
        padding: 20px;
        -webkit-overflow-scrolling: touch;
    }

    /* Re-use desktop styles for content inside mobile sidebar */
    .sidebar-content .sidebar-section {
        margin-bottom: 25px;
    }

    .sidebar-content .sidebar-title {
        font-size: 1rem;
        margin-bottom: 12px;
    }

    .sidebar-content .exam-selector,
    .sidebar-content .subject-selector {
        padding: 12px;
        font-size: 1rem;
        width: 100%;
        margin-bottom: 15px;
        border: 1px solid #ddd;
        border-radius: 8px;
    }

    .sidebar-content .chapter-list {
        height: auto;
        max-height: 400px;
        overflow-y: auto;
    }

    .sidebar-content .chapter-item {
        padding: 12px 15px;
        margin-bottom: 6px;
        border-radius: 6px;
        cursor: pointer;
        transition: all 0.3s;
    }

    .sidebar-content .chapter-item:hover {
        background: #f0f7ff;
    }

    .sidebar-content .chapter-item.active {
        background: #e6f0ff;
        color: var(--primary);
        font-weight: 600;
    }

    .sidebar-content .tools-card {
        padding: 0;
        border: none;
        background: none;
    }

    .sidebar-content .tool-btn {
        padding: 12px 15px;
        margin-bottom: 8px;
        border-radius: 8px;
        border: 1px solid #eee;
    }

    /* === 8. Footer Display === */
    footer {
        display: block !important;
        padding: 40px 5% 20px;
        background: var(--dark);
        color: white;
    }

    .footer-content {
        grid-template-columns: 1fr;
        gap: 30px;
    }

    .footer-logo {
        font-size: 1.5rem;
    }

    .footer-about p {
        font-size: 0.9rem;
    }

    .footer-links h3,
    .footer-contact h3 {
        font-size: 1.1rem;
    }

    .social-icons {
        justify-content: center;
    }

    .copyright {
        font-size: 0.8rem;
    }

    /* === 9. Mobile Optimizations === */

    /* Ensure proper scrolling */
    html,
    body {
        overflow-x: hidden;
        position: relative;
        height: 100%;
    }

    /* Improve touch targets */
    button,
    .chapter-item,
    .mode-btn,
    .tool-btn {
        min-height: 44px;
        cursor: pointer;
    }

    /* Loading states */
    .loader {
        padding: 40px 20px;
    }

    .spinner {
        width: 40px;
        height: 40px;
    }
}

/* Additional mobile-specific improvements */
@media (max-width: 480px) {
    .chapter-title {
        font-size: 1.1rem;
        padding: 0 50px;
    }

    .nav-btn {
        padding: 6px 10px;
        font-size: 0.7rem;
    }

    .mode-btn {
        padding: 6px 12px;
        font-size: 0.8rem;
    }

    .mobile-sidebar {
        width: 90%;
    }

    .notebook-paper {
        padding: 1rem 0.8rem 1.5rem 2rem;
    }

    .notebook-paper::before {
        left: 25px;
    }
}

@media (max-width: 768px) {

    /* Ensure mobile sidebars work properly */
    .mobile-sidebar.active {
        transform: translateX(0) !important;
        display: flex !important;
    }

    /* Ensure content is scrollable */
    .content-tabs,
    .notebook-content {
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch !important;
    }

    /* Prevent body scroll when sidebar is open */
    body.sidebar-open {
        overflow: hidden;
    }
}