/**
 * Quantum Computing Curriculum - Responsive Stylesheet
 * Mobile-First Design Approach
 * Breakpoints: 480px, 768px, 1024px, 1440px
 */

/* ========== RESET & BASE STYLES ========== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
    font-size: 16px;
    height: 100%; /* establish percent-height basis for children */
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background-color: #f5f5f5;
    color: #333;
    line-height: 1.6;
    display: flex;
    height: 100%;
    min-height: 100%;
    flex-direction: column;
    /* Prevent double-scrolling; make .content-area the primary scroll container */
    /* overflow: hidden; */
}

/* Respect user motion preferences */
@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;
    }
}

/* ========== MOBILE LAYOUT (< 768px) ========== */

.sidebar {
    position: fixed;
    left: -100%;
    top: 0;
    width: 100%;
    height: 100vh;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    padding: 0;
    z-index: 1000;
    transition: left 0.3s ease-out;
}

.sidebar.open {
    left: 0;
}

.sidebar::-webkit-scrollbar {
    width: 6px;
}

.sidebar::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.1);
}

.sidebar::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.3);
    border-radius: 3px;
}

.sidebar-header {
    position: sticky;
    top: 0;
    padding: 20px 15px;
    border-bottom: 2px solid rgba(255, 255, 255, 0.2);
    background: rgba(0, 0, 0, 0.1);
    text-align: center;
    z-index: 100;
}

.sidebar-header h1 {
    font-size: 1.2em;
    margin-bottom: 5px;
    font-weight: 700;
}

.sidebar-header p {
    font-size: 0.75em;
    opacity: 0.85;
    font-weight: 500;
}

.search-box {
    padding: 12px 15px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.2);
}

.search-box input {
    width: 100%;
    padding: 8px 12px;
    border: none;
    border-radius: 4px;
    background-color: rgba(255, 255, 255, 0.15);
    color: white;
    font-size: 0.9em;
}

/* Quick Navigation */
.quick-nav {
    padding: 12px 15px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.2);
}

.quick-nav-title {
    font-size: 0.75em;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 8px;
    opacity: 0.7;
    font-weight: 600;
}

.quick-nav-link {
    display: block;
    padding: 10px 12px;
    color: white;
    text-decoration: none;
    border-radius: 4px;
    margin-bottom: 6px;
    font-size: 0.95em;
    transition: all 0.2s ease;
    background: rgba(255, 255, 255, 0.1);
    border-left: 3px solid transparent;
    min-height: 44px;
    display: flex;
    align-items: center;
}

.quick-nav-link:focus {
    outline: 2px solid #ffd700;
    outline-offset: 2px;
    background: rgba(255, 255, 255, 0.2);
}

.quick-nav-link:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: translateX(4px);
}

.quick-nav-link.active {
    background: rgba(255, 255, 255, 0.25);
    border-left-color: white;
    font-weight: 600;
}

.search-box input::placeholder {
    color: rgba(255, 255, 255, 0.6);
}

.search-box input:focus {
    outline: none;
    background-color: rgba(255, 255, 255, 0.25);
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.2);
}

.sidebar-nav {
    padding: 8px 0;
}

.nav-item {
    padding: 0;
    margin: 0;
}

.nav-link {
    display: block;
    padding: 10px 15px;
    color: rgba(255, 255, 255, 0.9);
    text-decoration: none;
    cursor: pointer;
    transition: all 0.15s ease;
    border-left: 3px solid transparent;
    font-size: 0.9em;
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    min-height: 44px;
    display: flex;
    align-items: center;
}

.nav-link:focus {
    outline: 2px solid #ffd700;
    outline-offset: 2px;
    background-color: rgba(255, 255, 255, 0.15);
}

.nav-link:active {
    background-color: rgba(255, 255, 255, 0.15);
    border-left-color: #ffd700;
}

.nav-link.active {
    background-color: rgba(255, 255, 255, 0.15);
    border-left-color: #ffd700;
    font-weight: 600;
    color: white;
}

.nav-folder {
    padding: 10px 15px;
    font-weight: 600;
    font-size: 0.85em;
    color: #ffd700;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: background-color 0.15s ease;
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    min-height: 44px;
}

.nav-folder:focus {
    outline: 2px solid #ffd700;
    outline-offset: 2px;
    background-color: rgba(255, 255, 255, 0.12);
}

.nav-folder:active,
.nav-folder:hover {
    background-color: rgba(255, 255, 255, 0.12);
}

.nav-folder.open {
    background-color: rgba(255, 255, 255, 0.1);
}

.nav-folder-icon {
    font-size: 0.8em;
    transition: transform 0.15s ease;
    margin-left: 10px;
    display: inline-block;
}

.nav-folder.open .nav-folder-icon {
    transform: rotate(90deg);
}

.nav-subfolder {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.2s ease, opacity 0.2s ease;
    background-color: rgba(0, 0, 0, 0.15);
    opacity: 0;
    pointer-events: none;
}

.nav-subfolder.open {
    max-height: 3000px;
    opacity: 1;
    pointer-events: auto;
}

.nav-subitem {
    padding-left: 30px;
    font-size: 0.85em;
}

.main-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    background-color: white;
    width: 100%;
}

.topbar {
    background-color: #2c3e50;
    color: white;
    padding: 12px 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
    gap: 10px;
}

.topbar h2 {
    font-size: 1em;
    font-weight: 600;
}

.breadcrumb {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    font-size: 0.8em;
}

.breadcrumb-item {
    color: #aaa;
}

.breadcrumb-item a {
    color: #ccc;
    text-decoration: none;
    transition: color 0.2s ease;
}

.breadcrumb-item a:active {
    color: white;
}

.breadcrumb-item.active {
    color: white;
    font-weight: 600;
}

.breadcrumb-separator {
    color: #666;
    margin: 0 2px;
}

.toggle-sidebar {
    background: none;
    border: none;
    color: white;
    font-size: 1.3em;
    cursor: pointer;
    padding: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.2s ease;
    min-width: 44px;
    min-height: 44px;
}

.toggle-sidebar:focus {
    outline: 2px solid #ffd700;
    outline-offset: 2px;
    background-color: rgba(255, 255, 255, 0.1);
}

.toggle-sidebar:active {
    opacity: 0.7;
}

.content-area {
    flex: 1;
    min-height: 0; /* allow the flex child to shrink and enable inner scrolling on iOS/Android */
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch; /* smooth native scrolling on iOS */
    touch-action: pan-y; /* allow vertical touch scrolling */
    overscroll-behavior: contain; /* avoid accidental navigation gestures */
    padding: 15px;
    background-color: #f9f9f9;
    /* iOS specific optimizations */
    -webkit-transform: translateZ(0); /* force hardware acceleration */
    transform: translateZ(0);
}

.content-area::-webkit-scrollbar {
    width: 6px;
}

.content-area::-webkit-scrollbar-track {
    background: #f0f0f0;
}

.content-area::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 3px;
}

.content {
    background: white;
    padding: 20px;
    border-radius: 6px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
    line-height: 1.7;
}

.content h1 {
    color: #667eea;
    margin-top: 0;
    margin-bottom: 15px;
    padding-bottom: 12px;
    border-bottom: 2px solid #667eea;
    font-size: 1.5em;
    font-weight: 700;
}

.content h2 {
    color: #764ba2;
    margin-top: 20px;
    margin-bottom: 12px;
    font-size: 1.25em;
    font-weight: 700;
}

.content h3 {
    color: #667eea;
    margin-top: 15px;
    margin-bottom: 8px;
    font-size: 1.1em;
    font-weight: 600;
}

.content h4,
.content h5,
.content h6 {
    color: #555;
    margin-top: 12px;
    margin-bottom: 8px;
    font-weight: 600;
}

.content p {
    margin-bottom: 12px;
    color: #444;
}

.content ul,
.content ol {
    margin-left: 20px;
    margin-bottom: 15px;
}

.content li {
    margin-bottom: 6px;
    color: #444;
}

.content code {
    background-color: #f4f4f4;
    padding: 2px 6px;
    border-radius: 3px;
    font-family: 'Courier New', 'Monaco', monospace;
    color: #d63384;
    font-size: 0.9em;
}

.content pre {
    background-color: #2d2d2d;
    color: #f8f8f2;
    padding: 12px;
    border-radius: 5px;
    overflow-x: auto;
    margin: 12px 0;
    font-family: 'Courier New', 'Monaco', monospace;
    font-size: 0.85em;
    line-height: 1.4;
}

.content pre code {
    background-color: transparent;
    color: #f8f8f2;
    padding: 0;
    border-radius: 0;
}

.content a {
    color: #667eea;
    text-decoration: none;
    border-bottom: 1px solid transparent;
    transition: border-color 0.2s ease;
}

.content a:active {
    color: #764ba2;
    border-bottom-color: #764ba2;
}

.content a:hover {
    border-bottom-color: #667eea;
}

.content table {
    width: 100%;
    border-collapse: collapse;
    margin: 15px 0;
    font-size: 0.9em;
}

.content table th,
.content table td {
    border: 1px solid #ddd;
    padding: 8px;
    text-align: left;
}

.content table th {
    background-color: #667eea;
    color: white;
    font-weight: 600;
}

.content table tr:nth-child(even) {
    background-color: #f9f9f9;
}

.content hr {
    border: none;
    border-top: 1px solid #ddd;
    margin: 20px 0;
}

.empty-state {
    text-align: center;
    color: #999;
    padding: 40px 20px;
}

.empty-state-icon {
    font-size: 3em;
    margin-bottom: 15px;
    opacity: 0.4;
}

.empty-state h2 {
    color: #666;
    font-size: 1.3em;
    margin-bottom: 8px;
}

.empty-state p {
    color: #999;
    font-size: 0.95em;
}

.math {
    display: inline-block;
}

.katex-display {
    display: block;
    text-align: center;
    margin: 15px 0;
    overflow-x: auto;
}

/* ========== TABLET LAYOUT (768px+) ========== */
@media (min-width: 768px) {
    body {
        flex-direction: row;
        overflow: hidden;
    }

    .sidebar {
        position: relative;
        left: 0;
        width: 280px;
        height: 100vh;
        border-right: 1px solid #ddd;
        overflow-y: auto;
        overflow-x: hidden;
        padding: 0;
    }

    .sidebar.open {
        left: 0;
    }

    .toggle-sidebar {
        display: none;
    }

    .main-container {
        flex: 1;
        width: calc(100% - 280px);
    }

    .topbar {
        padding: 15px 25px;
        gap: 20px;
    }

    .topbar h2 {
        font-size: 1.1em;
    }

    .breadcrumb {
        gap: 8px;
        font-size: 0.85em;
    }

    .content-area {
        padding: 30px;
    }

    .content {
        padding: 30px;
    }

    .content h1 {
        font-size: 1.8em;
        margin-bottom: 20px;
        padding-bottom: 15px;
    }

    .content h2 {
        font-size: 1.4em;
        margin-top: 25px;
        margin-bottom: 15px;
    }

    .content h3 {
        font-size: 1.2em;
        margin-top: 20px;
    }

    .content ul,
    .content ol {
        margin-left: 30px;
    }

    .content table {
        font-size: 0.95em;
    }

    .content table th,
    .content table td {
        padding: 10px;
    }

    .search-box {
        padding: 15px 20px;
    }

    .search-box input {
        padding: 10px 14px;
        font-size: 0.95em;
    }

    .nav-link {
        padding: 8px 20px;
        font-size: 0.95em;
    }

    .nav-folder {
        padding: 10px 20px;
        font-size: 0.9em;
    }

    .nav-subitem {
        padding-left: 40px;
    }

    .sidebar-header {
        padding: 20px;
    }

    .sidebar-header h1 {
        font-size: 1.3em;
    }
}

/* ========== LAPTOP LAYOUT (1024px+) ========== */
@media (min-width: 1024px) {
    .sidebar {
        width: 320px;
    }

    .main-container {
        width: calc(100% - 320px);
    }

    .topbar {
        padding: 15px 35px;
    }

    .content-area {
        padding: 40px;
    }

    .content {
        padding: 40px;
    }

    .content h1 {
        font-size: 2em;
        margin-bottom: 25px;
    }

    .content h2 {
        font-size: 1.5em;
        margin-top: 30px;
    }

    .content h3 {
        font-size: 1.25em;
    }

    .content p {
        margin-bottom: 15px;
    }

    .content ul,
    .content ol {
        margin-bottom: 20px;
    }
}

/* ========== WIDE DESKTOP LAYOUT (1440px+) ========== */
@media (min-width: 1440px) {
    .sidebar {
        width: 350px;
    }

    .main-container {
        width: calc(100% - 350px);
    }

    .topbar {
        padding: 18px 40px;
    }

    .content-area {
        padding: 50px;
    }

    .content {
        max-width: 1200px;
        margin: 0 auto;
        padding: 50px;
    }

    .content h1 {
        font-size: 2.2em;
    }

    .content h2 {
        font-size: 1.7em;
    }

    .content h3 {
        font-size: 1.3em;
    }
}

/* ========== SMALL PHONES (< 480px) ========== */
@media (max-width: 479px) {
    .sidebar-header h1 {
        font-size: 1em;
    }

    .sidebar-header p {
        font-size: 0.7em;
    }

    .topbar {
        padding: 10px 12px;
    }

    .topbar h2 {
        font-size: 0.9em;
    }

    .breadcrumb {
        font-size: 0.75em;
        gap: 3px;
    }

    .content-area {
        padding: 12px;
    }

    .content {
        padding: 15px;
        border-radius: 4px;
    }

    .content h1 {
        font-size: 1.3em;
        margin-bottom: 12px;
    }

    .content h2 {
        font-size: 1.1em;
        margin-top: 15px;
    }

    .content table {
        font-size: 0.8em;
    }

    .content table th,
    .content table td {
        padding: 6px;
    }

    .empty-state {
        padding: 30px 15px;
    }

    .empty-state-icon {
        font-size: 2.5em;
    }

    .empty-state h2 {
        font-size: 1.1em;
    }
}

/* ========== PRINT STYLES ========== */
@media print {
    .sidebar,
    .topbar,
    .toggle-sidebar {
        display: none;
    }

    body {
        flex-direction: column;
    }

    .main-container {
        width: 100%;
    }

    .content-area {
        padding: 0;
        background: white;
    }

    .content {
        box-shadow: none;
        padding: 0;
    }
}
