/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    /* Light Theme Colors */
    --primary-color: #3b82f6;
    --primary-hover: #2563eb;
    --secondary-color: #6b7280;
    --background-color: #ffffff;
    --surface-color: #f8fafc;
    --border-color: #e2e8f0;
    --text-primary: #1f2937;
    --text-secondary: #6b7280;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    --radius-sm: 0.375rem;
    --radius-md: 0.5rem;
    --radius-lg: 0.75rem;
    --transition: all 0.2s ease-in-out;
}

[data-theme="dark"] {
    /* Dark Theme Colors */
    --primary-color: #60a5fa;
    --primary-hover: #3b82f6;
    --secondary-color: #9ca3af;
    --background-color: #0f172a;
    --surface-color: #1e293b;
    --border-color: #334155;
    --text-primary: #f1f5f9;
    --text-secondary: #cbd5e1;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.2);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.3), 0 2px 4px -2px rgb(0 0 0 / 0.3);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.4), 0 4px 6px -4px rgb(0 0 0 / 0.4);
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: var(--background-color);
    color: var(--text-primary);
    line-height: 1.6;
    transition: var(--transition);
}

/* App Container */
.app-container {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header */
.header {
    background-color: var(--surface-color);
    border-bottom: 1px solid var(--border-color);
    padding: 1rem 0;
    box-shadow: var(--shadow-sm);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-content {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--primary-color);
}

.logo i {
    font-size: 1.5rem;
}

.header-actions {
    display: flex;
    gap: 0.75rem;
    align-items: center;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    border: none;
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    text-decoration: none;
    font-family: inherit;
}

.btn-primary {
    background-color: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background-color: var(--primary-hover);
    transform: translateY(-1px);
}

.btn-secondary {
    background-color: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background-color: var(--surface-color);
    color: var(--text-primary);
}

.btn-large {
    padding: 0.75rem 1.5rem;
    font-size: 1rem;
}

/* Main Content */
.main-content {
    flex: 1;
    display: flex;
    position: relative;
}

/* Sidebar */
.sidebar {
    width: 280px;
    background-color: var(--surface-color);
    border-right: 1px solid var(--border-color);
    padding: 1.5rem;
    overflow-y: auto;
    transform: translateX(-100%);
    transition: var(--transition);
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    z-index: 200;
    padding-top: 5rem;
}

.sidebar.open {
    transform: translateX(0);
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border-color);
}

.sidebar-header h3 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.sidebar-toggle {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0.25rem;
    border-radius: var(--radius-sm);
    transition: var(--transition);
}

.sidebar-toggle:hover {
    background-color: var(--border-color);
    color: var(--text-primary);
}

/* Table of Contents */
.toc {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.toc-empty {
    color: var(--text-secondary);
    font-style: italic;
    text-align: center;
    padding: 2rem 0;
}

.toc-item {
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition);
    text-decoration: none;
    color: var(--text-secondary);
    font-size: 0.875rem;
    border-left: 3px solid transparent;
}

.toc-item:hover {
    background-color: var(--border-color);
    color: var(--text-primary);
}

.toc-item.active {
    background-color: var(--primary-color);
    color: white;
    border-left-color: var(--primary-hover);
}

.toc-item.level-2 { margin-left: 1rem; }
.toc-item.level-3 { margin-left: 2rem; }
.toc-item.level-4 { margin-left: 3rem; }
.toc-item.level-5 { margin-left: 4rem; }
.toc-item.level-6 { margin-left: 5rem; }

/* Content Area */
.content-area {
    flex: 1;
    transition: var(--transition);
}

/* Welcome Screen */
.welcome-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: calc(100vh - 80px);
    padding: 2rem;
}

.welcome-content {
    text-align: center;
    max-width: 600px;
}

.welcome-icon {
    font-size: 4rem;
    color: var(--primary-color);
    margin-bottom: 1.5rem;
}

.welcome-content h1 {
    font-size: 2.5rem;
    font-weight: 700;
    margin-bottom: 1rem;
    color: var(--text-primary);
}

.welcome-content p {
    font-size: 1.125rem;
    color: var(--text-secondary);
    margin-bottom: 2rem;
}

.welcome-features {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2.5rem;
}

.feature {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    padding: 1rem;
    background-color: var(--surface-color);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
}

.feature i {
    font-size: 1.5rem;
    color: var(--primary-color);
}

.feature span {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-primary);
}

/* Drag and Drop */
.drag-drop-area {
    margin-top: 2rem;
    padding: 2rem;
    border: 2px dashed var(--border-color);
    border-radius: var(--radius-lg);
    background-color: var(--surface-color);
    transition: var(--transition);
}

.drag-drop-area:hover,
.drag-drop-area.drag-over {
    border-color: var(--primary-color);
    background-color: rgba(59, 130, 246, 0.05);
}

.drag-drop-area i {
    font-size: 2rem;
    color: var(--primary-color);
    margin-bottom: 0.5rem;
}

.drag-drop-area p {
    color: var(--text-secondary);
    margin: 0;
}

/* Reader View */
.reader-view {
    padding: 2rem;
    max-width: 900px;
    margin: 0 auto;
}

.reader-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 2rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border-color);
}

.file-info h2 {
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 0.25rem;
}

.file-size {
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.reader-actions {
    display: flex;
    gap: 0.75rem;
}

/* Markdown Content */
.markdown-content {
    line-height: 1.8;
    color: var(--text-primary);
}

.markdown-content h1,
.markdown-content h2,
.markdown-content h3,
.markdown-content h4,
.markdown-content h5,
.markdown-content h6 {
    margin-top: 2rem;
    margin-bottom: 1rem;
    font-weight: 600;
    line-height: 1.3;
    color: var(--text-primary);
}

.markdown-content h1 { font-size: 2.25rem; }
.markdown-content h2 { font-size: 1.875rem; }
.markdown-content h3 { font-size: 1.5rem; }
.markdown-content h4 { font-size: 1.25rem; }
.markdown-content h5 { font-size: 1.125rem; }
.markdown-content h6 { font-size: 1rem; }

.markdown-content p {
    margin-bottom: 1.5rem;
}

.markdown-content a {
    color: var(--primary-color);
    text-decoration: none;
}

.markdown-content a:hover {
    text-decoration: underline;
}

.markdown-content ul,
.markdown-content ol {
    margin-bottom: 1.5rem;
    padding-left: 2rem;
}

.markdown-content li {
    margin-bottom: 0.5rem;
}

.markdown-content blockquote {
    border-left: 4px solid var(--primary-color);
    margin: 1.5rem 0;
    padding: 1rem 1.5rem;
    background-color: var(--surface-color);
    border-radius: 0 var(--radius-md) var(--radius-md) 0;
}

.markdown-content code {
    background-color: var(--surface-color);
    padding: 0.25rem 0.5rem;
    border-radius: var(--radius-sm);
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    font-size: 0.875rem;
}

.markdown-content pre {
    background-color: var(--surface-color);
    padding: 1.5rem;
    border-radius: var(--radius-lg);
    overflow-x: auto;
    margin: 1.5rem 0;
    border: 1px solid var(--border-color);
}

.markdown-content pre code {
    background: none;
    padding: 0;
    border-radius: 0;
}

.markdown-content table {
    width: 100%;
    border-collapse: collapse;
    margin: 1.5rem 0;
    background-color: var(--surface-color);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

.markdown-content th,
.markdown-content td {
    padding: 0.75rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

.markdown-content th {
    background-color: var(--border-color);
    font-weight: 600;
}

.markdown-content img {
    max-width: 100%;
    height: auto;
    border-radius: var(--radius-lg);
    margin: 1.5rem 0;
    box-shadow: var(--shadow-md);
}

.markdown-content hr {
    border: none;
    border-top: 1px solid var(--border-color);
    margin: 2rem 0;
}

/* Loading Overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(4px);
}

.loading-overlay.hidden {
    display: none;
}

.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-overlay p {
    color: white;
    font-size: 1rem;
    font-weight: 500;
}

/* Responsive Design */
@media (min-width: 768px) {
    .sidebar {
        position: static;
        transform: translateX(0);
        padding-top: 1.5rem;
        height: auto;
    }
    
    .content-area {
        margin-left: 0;
    }
    
    .sidebar.open {
        transform: translateX(0);
    }
}

@media (max-width: 767px) {
    .header-content {
        padding: 0 1rem;
    }
    
    .logo span {
        display: none;
    }
    
    .welcome-content h1 {
        font-size: 2rem;
    }
    
    .welcome-features {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .reader-view {
        padding: 1rem;
    }
    
    .reader-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
    }
    
    .reader-actions {
        align-self: stretch;
        justify-content: flex-end;
    }
    
    .markdown-content {
        font-size: 0.9rem;
    }
    
    .markdown-content h1 { font-size: 1.875rem; }
    .markdown-content h2 { font-size: 1.5rem; }
    .markdown-content h3 { font-size: 1.25rem; }
}

/* Smooth scrolling */
html {
    scroll-behavior: smooth;
}

/* Focus styles for accessibility */
.btn:focus,
.toc-item:focus {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

/* Selection styles */
::selection {
    background-color: var(--primary-color);
    color: white;
}