/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #2563eb;
    --secondary-color: #f3f4f6;
    --accent-color: #10b981;
    --text-color: #111827;
    --text-primary: #111827;
    --text-muted: #6b7280;
    --border-color: #e5e7eb;
    --border: #e5e7eb;
    --background: #ffffff;
    --surface: #f9fafb;
    --hover-bg: #eff6ff;
    --shadow: rgba(0, 0, 0, 0.1);
    --shadow-lg: rgba(0, 0, 0, 0.15);
    --warning: #f59e0b;
    --error: #ef4444;
    --success: #10b981;
}

html {
    overflow-x: hidden;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Helvetica Neue', Arial, sans-serif;
    background-color: var(--background);
    color: var(--text-color);
    line-height: 1.6;
    overflow-x: hidden;
}

/* Navigation */
.navbar {
    background: linear-gradient(135deg, var(--primary-color), #1d4ed8);
    color: white;
    padding: 0;
    position: fixed;
    top: 0;
    width: 100%;
    z-index: 1000;
    box-shadow: 0 2px 10px var(--shadow-lg);
}

.nav-container {
    max-width: 100%;
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 2rem;
}

.nav-container > * {
    min-width: 0;
}

.nav-logo {
    min-width: 0;
}

.nav-logo h1 {
    font-size: 1.5rem;
    font-weight: 700;
    overflow-wrap: anywhere;
}

.logo-title-mobile {
    display: none;
}

.nav-search {
    flex: 1;
    max-width: 500px;
    min-width: 0;
    position: relative;
}

.nav-search input {
    width: 100%;
    padding: 0.75rem 1rem;
    border: none;
    border-radius: 25px;
    background: rgba(255, 255, 255, 0.15);
    color: white;
    font-size: 1rem;
    backdrop-filter: blur(10px);
    transition: background 0.3s ease;
}

.nav-search input::placeholder {
    color: rgba(255, 255, 255, 0.7);
}

.nav-search input:focus {
    outline: none;
    background: rgba(255, 255, 255, 0.25);
}

.search-results {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: white;
    border-radius: 10px;
    box-shadow: 0 5px 20px var(--shadow-lg);
    margin-top: 0.5rem;
    display: none;
    z-index: 1001;
}

.search-result-item {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: flex-start;
    gap: 0.25rem;
    width: 100%;
    padding: 0.75rem 1rem;
    border: none;
    cursor: pointer;
    background: transparent;
    font: inherit;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-color);
    transition: background 0.2s ease;
}

.search-result-item:hover,
.search-result-item.active {
    background: var(--surface);
}

.search-result-item:last-child {
    border-bottom: none;
    border-radius: 0 0 10px 10px;
}

.search-result-title {
    font-weight: 500;
}

.search-result-category {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.search-result-snippet {
    font-size: 0.8rem;
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    width: 100%;
    margin-top: 5px;
    padding-top: 5px;
    border-top: 1px solid var(--secondary-color);
}

.search-empty {
    padding: 0.75rem 1rem;
    color: var(--text-muted);
}

.nav-toggle {
    display: none;
    flex-direction: column;
    cursor: pointer;
    gap: 3px;
    background: transparent;
    border: none;
    padding: 5px;
}

.nav-toggle span {
    width: 25px;
    height: 3px;
    background: white;
    border-radius: 2px;
    transition: 0.3s;
}

/* Container and Layout */
.container {
    display: flex;
    margin-top: 80px;
    min-height: calc(100vh - 80px);
}

.sidebar {
    width: 320px;
    background: var(--surface);
    border-right: 1px solid var(--border-color);
    padding: 1.5rem;
    height: calc(100vh - 80px);
    overflow-y: auto;
    position: fixed;
    left: 0;
    top: 80px;
    z-index: 950;
    transition: transform 0.3s ease;
}

.sidebar-header {
    margin-bottom: 1.5rem;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 1rem;
}

.sidebar-header h3 {
    font-size: 1.25rem;
    margin-bottom: 1rem;
    color: var(--text-color);
}

.topics-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.category {
    margin-bottom: 0;
}

.category-header {
    width: 100%;
    border: none;
    background: transparent;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 0.5rem;
    padding: 0.5rem 0;
    text-align: left;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.3rem;
}

.collapse-icon {
    font-size: 0.8em;
    transition: transform 0.2s ease;
    display: inline-block;
}

.category-header:hover,
.category-header:focus-visible,
.category-header.highlight {
    color: var(--primary-color);
}

.category-topics {
    list-style: none;
    transition: all 0.3s ease;
}

.category.collapsed .category-topics {
    display: none;
}

.topic-item {
    margin-bottom: 0.15rem;
    border-radius: 6px;
    transition: all 0.2s ease;
}

.topic-item:hover {
    background: rgba(37, 99, 235, 0.05);
}

.topic-item.active {
    background: var(--primary-color);
    color: white;
}

.topic-item a {
    display: flex;
    align-items: center;
    padding: 0.5rem 1rem;
    text-decoration: none;
    color: inherit;
    font-size: 0.9rem;
    border-radius: 6px;
    transition: all 0.2s ease;
    gap: 0.5rem;
}

.topic-item a:focus-visible {
    outline: 2px solid rgba(37, 99, 235, 0.4);
    outline-offset: -2px;
}

.topic-item.bookmarked a::before {
    content: '⭐';
    font-size: 0.8rem;
    flex-shrink: 0;
}

.new-badge {
    font-size: 0.55rem;
    margin-left: 0.4rem;
    padding: 0.05rem 0.25rem;
    background-color: #93c5fd;
    color: #1e40af;
    border-radius: 4px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    display: inline-block;
    opacity: 0.8;
}

@keyframes sparkle {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.7; transform: scale(1.1); }
}

/* Category Overview */
.category-overview {
    padding: 2rem;
    max-width: 1200px;
    margin: 0 auto;
}

.category-overview h1 {
    font-size: 2.5rem;
    margin-bottom: 2rem;
    text-align: center;
    color: var(--text-primary);
}

.category-stats {
    display: flex;
    gap: 2rem;
    justify-content: center;
    margin-bottom: 3rem;
    flex-wrap: wrap;
}

.category-stats .stat-item {
    text-align: center;
    padding: 1rem;
    background: var(--surface);
    border-radius: 12px;
    border: 1px solid var(--border);
    min-width: 120px;
}

.category-topics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 1rem;
}

.topic-card {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: left;
    font-size: 0.9rem;
    color: var(--text-primary);
}

.topic-card:hover {
    background: var(--hover-bg);
    border-color: var(--primary-color);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.1);
}

.topic-card.new-topic {
    border-left: 3px solid var(--primary-color);
}

.topic-card:focus-visible {
    outline: 2px solid rgba(37, 99, 235, 0.45);
    outline-offset: 2px;
}

.topic-title {
    flex: 1;
    font-weight: 500;
}

.new-badge-card {
    font-size: 0.55rem;
    padding: 0.05rem 0.25rem;
    background-color: #93c5fd;
    color: #1e40af;
    border-radius: 4px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    opacity: 0.8;
    margin-left: 0.5rem;
}

.topic-item.active a {
    color: white;
}

/* Main Content */
.main-content {
    flex: 1;
    margin-left: 320px;
    min-width: 0;
    background: var(--background);
    transition: margin-left 0.3s ease;
}

.sidebar-overlay {
    position: fixed;
    top: 80px;
    left: 0;
    width: 100%;
    height: calc(100vh - 80px);
    background: rgba(17, 24, 39, 0.45);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    z-index: 940;
    transition: opacity 0.2s ease, visibility 0.2s ease;
}

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

.welcome-screen {
    padding: 3rem 2rem;
    text-align: center;
    max-width: 800px;
    margin: 0 auto;
}

.welcome-content h1 {
    font-size: 2.5rem;
    font-weight: 700;
    margin-bottom: 1rem;
    background: linear-gradient(135deg, var(--primary-color), var(--accent-color));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.welcome-content p {
    font-size: 1.25rem;
    color: var(--text-muted);
    margin-bottom: 2rem;
}

.stats {
    display: flex;
    justify-content: center;
    gap: 3rem;
    margin: 2rem 0;
}

.stat-item {
    text-align: center;
}

.stat-number {
    display: block;
    font-size: 2rem;
    font-weight: 700;
    color: var(--primary-color);
}

.stat-label {
    font-size: 0.9rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.quick-start {
    margin-top: 3rem;
}

.quick-start h3 {
    margin-bottom: 1.5rem;
    color: var(--text-color);
}

.recommended-topics {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 1rem;
}

.recommend-btn {
    background: linear-gradient(135deg, var(--primary-color), #1d4ed8);
    color: white;
    border: none;
    padding: 0.75rem 1.5rem;
    border-radius: 25px;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 2px 10px rgba(37, 99, 235, 0.3);
}

.recommend-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 20px rgba(37, 99, 235, 0.4);
}

/* Content Area */
.content-area {
    padding: 2rem;
    min-width: 0;
}

.content-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border-color);
}

.breadcrumb {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.4rem;
    font-size: 0.9rem;
    color: var(--text-muted);
}

.breadcrumb-link {
    border: none;
    background: transparent;
    color: inherit;
    font: inherit;
    cursor: pointer;
    padding: 0;
    transition: color 0.2s ease;
}

.breadcrumb-link:hover {
    color: var(--primary-color);
}

.breadcrumb-separator {
    color: var(--text-muted);
}

.breadcrumb span.active {
    color: var(--text-color);
    font-weight: 500;
}

.content-actions {
    display: flex;
    gap: 0.5rem;
}

.action-btn {
    background: var(--surface);
    border: 1px solid var(--border-color);
    padding: 0.5rem 1rem;
    border-radius: 8px;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s ease;
    color: var(--text-color);
}

.action-btn:hover {
    background: var(--secondary-color);
}

.action-btn.bookmarked {
    background: var(--warning);
    color: white;
    border-color: var(--warning);
}

.action-btn:focus-visible,
.nav-btn:focus-visible,
.search-result-item:focus-visible,
.breadcrumb-link:focus-visible,
#searchInput:focus-visible {
    outline: 2px solid rgba(37, 99, 235, 0.45);
    outline-offset: 2px;
}

/* Content Body */
.content-body {
    max-width: none;
    line-height: 1.8;
    min-width: 0;
    overflow-wrap: break-word;
    word-break: break-word;
}

.content-body h1 {
    font-size: 2rem;
    font-weight: 700;
    margin-bottom: 1.5rem;
    color: var(--text-color);
    line-height: 1.2;
}

.content-body h2 {
    font-size: 1.5rem;
    font-weight: 600;
    margin: 2rem 0 1rem 0;
    color: var(--text-color);
}

.content-body h3 {
    font-size: 1.25rem;
    font-weight: 600;
    margin: 1.5rem 0 1rem 0;
    color: var(--text-color);
}

.content-body p {
    margin-bottom: 1.25rem;
    color: var(--text-color);
}

.content-body ul, .content-body ol {
    margin: 1rem 0;
    padding-left: 2rem;
}

.content-body li {
    margin-bottom: 0.5rem;
    color: var(--text-color);
}

.content-body strong {
    font-weight: 600;
    color: var(--text-color);
}

.content-body em {
    font-style: italic;
    color: var(--text-muted);
}

.content-body code {
    background: var(--surface);
    padding: 0.2rem 0.4rem;
    border-radius: 4px;
    font-family: 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', Consolas, 'Courier New', monospace;
    font-size: 0.9em;
    color: var(--primary-color);
}

.content-body pre {
    background: #2d3748;
    color: #e2e8f0;
    padding: 1.5rem;
    border-radius: 12px;
    max-width: 100%;
    overflow-x: auto;
    margin: 1.5rem 0;
    font-family: 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', Consolas, 'Courier New', monospace;
}

.content-body pre code {
    background: none;
    color: inherit;
    padding: 0;
}

.content-body blockquote {
    border-left: 4px solid var(--primary-color);
    margin: 1.5rem 0;
    font-style: italic;
    background: var(--surface);
    padding: 1rem;
    border-radius: 0 8px 8px 0;
}

.content-body img,
.content-body video,
.content-body iframe {
    max-width: 100%;
    height: auto;
}

.content-body table {
    display: block;
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* Content Footer */
.content-footer {
    margin-top: 3rem;
    padding-top: 2rem;
    border-top: 1px solid var(--border-color);
}

.navigation-buttons {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
}

.nav-btn {
    background: var(--primary-color);
    color: white;
    border: none;
    padding: 0.75rem 1.5rem;
    border-radius: 8px;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.3s ease;
    max-width: 200px;
    text-overflow: ellipsis;
    overflow: hidden;
    white-space: nowrap;
}

.nav-btn:hover:not(:disabled) {
    background: #1d4ed8;
    transform: translateY(-1px);
}

.nav-btn:disabled {
    background: var(--text-muted);
    cursor: not-allowed;
    opacity: 0.5;
}

/* Loading Spinner */
.loading-spinner {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.9);
    display: none;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    z-index: 2000;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid var(--border-color);
    border-top: 4px solid var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 1rem;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.loading-spinner p {
    color: var(--text-muted);
    font-size: 0.9rem;
}

/* Error Message */
.error-message {
    text-align: center;
    padding: 2rem;
    color: var(--error);
}

.error-message h2 {
    margin-bottom: 1rem;
}

/* Responsive Design */
@media (max-width: 1024px) {
    .main-content {
        margin-left: 0;
    }

    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar.active {
        transform: translateX(0);
    }

    .nav-toggle {
        display: flex;
    }

    .nav-container {
        padding-top: 1rem;
        padding-bottom: 1rem;
        padding-left: calc(1rem + env(safe-area-inset-left));
        padding-right: calc(1rem + env(safe-area-inset-right));
    }

    .nav-logo h1 {
        font-size: 1.25rem;
    }

    .nav-toggle {
        margin-right: 0.25rem;
    }
}

@media (max-width: 768px) {
    .nav-container {
        flex-wrap: wrap;
        gap: 0.5rem;
        align-items: center;
    }

    .nav-logo {
        order: 1;
        flex: 1;
    }

    .logo-title-desktop {
        display: none;
    }

    .logo-title-mobile {
        display: inline;
    }

    .nav-toggle {
        order: 2;
        flex: 0;
        position: relative;
        left: -20px;
    }

    .nav-search {
        order: 3;
        flex: 0 1 100%;
        max-width: 100%;
    }

    .container {
        margin-top: 120px;
    }

    .sidebar {
        top: 120px;
        height: calc(100vh - 120px);
    }

    .sidebar-overlay {
        top: 120px;
        height: calc(100vh - 120px);
    }

    .content-area {
        padding: 1rem;
    }

    .welcome-content h1 {
        font-size: 2rem;
    }

    .stats {
        gap: 2rem;
    }

    .recommended-topics {
        flex-direction: column;
        align-items: center;
    }

    .recommend-btn {
        width: 100%;
        max-width: 250px;
    }

    .navigation-buttons {
        flex-direction: column;
    }

    .nav-btn {
        max-width: 100%;
    }

    .content-header {
        flex-direction: column;
        align-items: start;
        gap: 1rem;
    }
}

@media (max-width: 480px) {
    .nav-container {
        padding-top: 0.75rem;
        padding-bottom: 0.75rem;
        padding-left: calc(0.75rem + env(safe-area-inset-left));
        padding-right: calc(0.75rem + env(safe-area-inset-right));
    }

    .welcome-screen {
        padding: 2rem 1rem;
    }

    .stats {
        flex-direction: column;
        gap: 1rem;
    }

    .content-body h1 {
        font-size: 1.75rem;
    }

    .content-body h2 {
        font-size: 1.25rem;
    }
}

/* Print Styles */
@media print {
    .navbar,
    .sidebar,
    .content-header,
    .content-footer,
    .loading-spinner {
        display: none !important;
    }

    .main-content {
        margin-left: 0 !important;
    }

    .content-area {
        padding: 0 !important;
    }

    .content-body {
        color: black !important;
    }

    .content-body h1,
    .content-body h2,
    .content-body h3,
    .content-body p,
    .content-body li {
        color: black !important;
    }
}
