/* ========================================
   CSS Variables & Theme System
   ======================================== */
:root {
    /* Light Mode Colors */
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --primary-light: #dbeafe;
    --secondary: #7c3aed;
    --secondary-hover: #6d28d9;
    --accent: #10b981;
    --accent-hover: #059669;
    
    --bg: #f8fafc;
    --surface: #ffffff;
    --surface-elevated: #ffffff;
    --text: #1e293b;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    
    --border: #e2e8f0;
    --border-light: #f1f5f9;
    --border-focus: #2563eb;
    
    --editor-bg: #ffffff;
    --editor-text: #1e293b;
    --editor-line-num: #94a3b8;
    --editor-selection: #dbeafe;
    --editor-cursor: #2563eb;
    
    --preview-bg: #ffffff;
    --preview-text: #1e293b;
    --preview-link: #2563eb;
    --preview-code-bg: #f1f5f9;
    --preview-code-border: #e2e8f0;
    --preview-blockquote: #f8fafc;
    --preview-blockquote-border: #2563eb;
    
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    
    --radius-sm: 4px;
    --radius: 8px;
    --radius-lg: 12px;
    --radius-xl: 16px;
    
    --transition-fast: 150ms ease;
    --transition: 200ms ease;
    --transition-slow: 300ms ease;
    --transition-theme: 400ms ease;
    
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;
    --font-serif: 'Georgia', 'Times New Roman', serif;
    
    --header-height: 56px;
    --toolbar-height: 44px;
    --footer-height: 40px;
    --status-height: 32px;
    
    --editor-font-size: 14px;
    --preview-font-size: 16px;
}

/* Dark Mode */
body.dark {
    --primary: #3b82f6;
    --primary-hover: #60a5fa;
    --primary-light: #1e3a5f;
    --secondary: #8b5cf6;
    --secondary-hover: #a78bfa;
    --accent: #34d399;
    --accent-hover: #6ee7b7;
    
    --bg: #0f172a;
    --surface: #1e293b;
    --surface-elevated: #334155;
    --text: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    
    --border: #334155;
    --border-light: #1e293b;
    --border-focus: #3b82f6;
    
    --editor-bg: #0d1421;
    --editor-text: #e2e8f0;
    --editor-line-num: #475569;
    --editor-selection: #1e3a5f;
    --editor-cursor: #3b82f6;
    
    --preview-bg: #1e293b;
    --preview-text: #e2e8f0;
    --preview-link: #60a5fa;
    --preview-code-bg: #0d1421;
    --preview-code-border: #334155;
    --preview-blockquote: #0d1421;
    --preview-blockquote-border: #3b82f6;
    
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.4), 0 2px 4px -1px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.4), 0 4px 6px -2px rgba(0, 0, 0, 0.3);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.5), 0 10px 10px -5px rgba(0, 0, 0, 0.4);
}

/* ========================================
   Reset & Base Styles
   ======================================== */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-sans);
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
    overflow: hidden;
    transition: background var(--transition-theme), color var(--transition-theme);
}

/* Custom Scrollbar */
::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

::-webkit-scrollbar-track {
    background: var(--border-light);
    border-radius: 5px;
}

::-webkit-scrollbar-thumb {
    background: var(--text-muted);
    border-radius: 5px;
    border: 2px solid var(--border-light);
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

/* Firefox Scrollbar */
* {
    scrollbar-width: thin;
    scrollbar-color: var(--text-muted) var(--border-light);
}

/* Selection */
::selection {
    background: var(--primary-light);
    color: var(--primary);
}

body.dark ::selection {
    background: var(--primary-light);
    color: var(--primary-hover);
}

/* ========================================
   Loading Screen
   ======================================== */
.loading-screen {
    position: fixed;
    inset: 0;
    background: linear-gradient(135deg, var(--bg) 0%, var(--surface) 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    transition: opacity var(--transition-slow), visibility var(--transition-slow);
}

.loading-screen.hidden {
    opacity: 0;
    visibility: hidden;
}

.loader {
    text-align: center;
}

.loader-icon {
    animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.05); opacity: 0.8; }
}

.loader-text {
    margin-top: 16px;
    font-size: 14px;
    color: var(--text-secondary);
}

.loader-bar {
    width: 200px;
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    margin-top: 16px;
    overflow: hidden;
}

.loader-progress {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), var(--secondary));
    border-radius: 2px;
    animation: loading 1.5s ease-in-out infinite;
}

@keyframes loading {
    0% { width: 0; margin-left: 0; }
    50% { width: 70%; margin-left: 15%; }
    100% { width: 0; margin-left: 100%; }
}

/* ========================================
   App Container
   ======================================== */
.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    opacity: 0;
    animation: fadeIn 0.5s ease forwards;
    animation-delay: 0.3s;
}

@keyframes fadeIn {
    to { opacity: 1; }
}

/* ========================================
   Header
   ======================================== */
.header {
    height: var(--header-height);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    gap: 16px;
    z-index: 100;
    transition: background var(--transition-theme), border-color var(--transition-theme);
}

.header-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    color: var(--text);
}

.logo-icon {
    transition: transform var(--transition);
}

.logo:hover .logo-icon {
    transform: scale(1.1) rotate(5deg);
}

.logo-text {
    font-weight: 700;
    font-size: 18px;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.greeting {
    font-size: 13px;
    color: var(--text-secondary);
    padding-left: 16px;
    border-left: 1px solid var(--border);
}

.header-center {
    flex: 1;
    display: flex;
    justify-content: center;
}

.status-bar {
    display: flex;
    align-items: center;
    gap: 16px;
    background: var(--surface-elevated);
    padding: 6px 16px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
}

.status-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--text-secondary);
    transition: color var(--transition);
}

.status-item:hover {
    color: var(--text);
}

.status-item svg {
    opacity: 0.7;
}

.render-status {
    position: relative;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--accent);
    animation: statusPulse 2s ease-in-out infinite;
}

@keyframes statusPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.render-status.rendering .status-dot {
    background: var(--primary);
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.header-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.view-tabs {
    display: flex;
    background: var(--surface-elevated);
    border-radius: var(--radius);
    padding: 3px;
    border: 1px solid var(--border);
}

.view-tab {
    padding: 6px 10px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
}

.view-tab:hover {
    color: var(--text);
    background: var(--border-light);
}

.view-tab.active {
    background: var(--primary);
    color: white;
}

.font-controls {
    display: flex;
    align-items: center;
    gap: 4px;
    background: var(--surface-elevated);
    padding: 3px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
}

.font-size-display {
    font-size: 11px;
    color: var(--text-secondary);
    min-width: 32px;
    text-align: center;
    font-family: var(--font-mono);
}

.icon-btn {
    width: 36px;
    height: 36px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    border-radius: var(--radius);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
    position: relative;
}

.icon-btn:hover {
    background: var(--surface-elevated);
    color: var(--text);
    transform: translateY(-1px);
}

.icon-btn:active {
    transform: translateY(0);
}

.icon-btn.active {
    background: var(--primary-light);
    color: var(--primary);
}

/* Theme Toggle */
#theme-toggle .moon-icon {
    display: none;
}

body.dark #theme-toggle .sun-icon {
    display: none;
}

body.dark #theme-toggle .moon-icon {
    display: block;
}

/* ========================================
   Formatting Toolbar
   ======================================== */
.formatting-toolbar {
    height: var(--toolbar-height);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 16px;
    gap: 4px;
    overflow-x: auto;
    transition: background var(--transition-theme), border-color var(--transition-theme);
}

.toolbar-group {
    display: flex;
    align-items: center;
    gap: 2px;
}

.toolbar-btn {
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    border-radius: var(--radius-sm);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
}

.toolbar-btn:hover {
    background: var(--surface-elevated);
    color: var(--text);
    transform: scale(1.1);
}

.toolbar-btn:active {
    transform: scale(0.95);
}

.toolbar-divider {
    width: 1px;
    height: 24px;
    background: var(--border);
    margin: 0 8px;
}

/* ========================================
   Find Bar
   ======================================== */
.find-bar {
    height: 52px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: none;
    align-items: center;
    padding: 0 16px;
    gap: 12px;
    animation: slideDown 0.2s ease;
}

.find-bar.active {
    display: flex;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.find-input-wrapper {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
    max-width: 250px;
    background: var(--surface-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0 12px;
    transition: border-color var(--transition);
}

.find-input-wrapper:focus-within {
    border-color: var(--primary);
}

.find-input-wrapper svg {
    color: var(--text-muted);
    flex-shrink: 0;
}

.find-input-wrapper input {
    flex: 1;
    border: none;
    background: transparent;
    padding: 8px 0;
    font-size: 13px;
    color: var(--text);
    outline: none;
    font-family: var(--font-sans);
}

.find-input-wrapper input::placeholder {
    color: var(--text-muted);
}

.find-count {
    font-size: 11px;
    color: var(--text-muted);
    white-space: nowrap;
}

.find-actions {
    display: flex;
    align-items: center;
    gap: 4px;
}

.find-action-btn {
    width: 28px;
    height: 28px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    border-radius: var(--radius-sm);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
}

.find-action-btn:hover {
    background: var(--surface-elevated);
    color: var(--text);
}

.find-action-btn.close-btn {
    margin-left: 8px;
}

/* ========================================
   Main Content
   ======================================== */
.main-content {
    flex: 1;
    display: flex;
    overflow: hidden;
    position: relative;
}

/* ========================================
   Panels
   ======================================== */
.panel {
    display: flex;
    flex-direction: column;
    background: var(--surface);
    overflow: hidden;
    transition: background var(--transition-theme);
}

.editor-panel {
    flex: 1;
    min-width: 300px;
}

.preview-panel {
    flex: 1;
    min-width: 300px;
}

.panel-header {
    height: 40px;
    background: var(--surface-elevated);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 12px;
    flex-shrink: 0;
}

.panel-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.panel-actions {
    display: flex;
    align-items: center;
    gap: 4px;
}

.panel-btn {
    width: 28px;
    height: 28px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    border-radius: var(--radius-sm);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
}

.panel-btn:hover {
    background: var(--border-light);
    color: var(--text);
}

.panel-btn.active {
    background: var(--primary-light);
    color: var(--primary);
}

.file-upload-btn {
    width: 28px;
    height: 28px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    border-radius: var(--radius-sm);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
}

.file-upload-btn:hover {
    background: var(--border-light);
    color: var(--text);
}

.auto-save-indicator {
    display: flex;
    align-items: center;
    gap: 4px;
    width: auto;
    padding: 0 8px;
    font-size: 11px;
    color: var(--accent);
}

.auto-save-indicator .save-status {
    font-weight: 500;
}

/* ========================================
   Editor Container
   ======================================== */
.editor-container {
    flex: 1;
    display: flex;
    overflow: hidden;
    position: relative;
}

.line-numbers {
    width: 50px;
    background: var(--editor-bg);
    border-right: 1px solid var(--border);
    padding: 12px 0;
    font-family: var(--font-mono);
    font-size: var(--editor-font-size);
    line-height: 1.7;
    color: var(--editor-line-num);
    text-align: right;
    overflow: hidden;
    user-select: none;
    transition: background var(--transition-theme), color var(--transition-theme);
}

.line-numbers span {
    display: block;
    padding-right: 12px;
}

#editor {
    flex: 1;
    border: none;
    background: var(--editor-bg);
    color: var(--editor-text);
    padding: 12px 16px;
    font-family: var(--font-mono);
    font-size: var(--editor-font-size);
    line-height: 1.7;
    resize: none;
    outline: none;
    overflow: auto;
    transition: background var(--transition-theme), color var(--transition-theme);
}

#editor::placeholder {
    color: var(--text-muted);
}

#editor::selection {
    background: var(--editor-selection);
}

/* ========================================
   Panel Resizer
   ======================================== */
.panel-resizer {
    width: 6px;
    background: var(--border);
    cursor: col-resize;
    position: relative;
    transition: background var(--transition);
    flex-shrink: 0;
}

.panel-resizer:hover,
.panel-resizer.active {
    background: var(--primary);
}

.resizer-handle {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 2px;
    height: 40px;
    background: var(--text-muted);
    border-radius: 1px;
    opacity: 0.5;
    transition: opacity var(--transition);
}

.panel-resizer:hover .resizer-handle {
    opacity: 1;
    background: white;
}

/* ========================================
   Preview Container
   ======================================== */
.preview-container {
    flex: 1;
    overflow: auto;
    background: var(--preview-bg);
    transition: background var(--transition-theme);
}

.preview-content {
    padding: 24px 32px;
    max-width: 900px;
    margin: 0 auto;
    color: var(--preview-text);
    font-family: var(--font-serif);
    font-size: var(--preview-font-size);
    line-height: 1.8;
    transition: color var(--transition-theme);
}

/* ========================================
   Table of Contents
   ======================================== */
.toc-sidebar {
    position: absolute;
    top: 40px;
    right: 0;
    width: 260px;
    max-height: calc(100% - 40px);
    background: var(--surface);
    border-left: 1px solid var(--border);
    transform: translateX(100%);
    transition: transform var(--transition-slow), background var(--transition-theme);
    z-index: 10;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.toc-sidebar.active {
    transform: translateX(0);
    box-shadow: var(--shadow-lg);
}

.toc-header {
    padding: 12px 16px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.toc-close {
    width: 24px;
    height: 24px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    transition: all var(--transition);
}

.toc-close:hover {
    background: var(--border-light);
    color: var(--text);
}

.toc-nav {
    flex: 1;
    overflow-y: auto;
    padding: 12px 0;
}

.toc-nav a {
    display: block;
    padding: 6px 16px;
    font-size: 13px;
    color: var(--text-secondary);
    text-decoration: none;
    border-left: 2px solid transparent;
    transition: all var(--transition);
}

.toc-nav a:hover {
    color: var(--primary);
    background: var(--primary-light);
    border-left-color: var(--primary);
}

.toc-nav a.h2 {
    padding-left: 28px;
    font-size: 12px;
}

.toc-nav a.h3 {
    padding-left: 40px;
    font-size: 12px;
}

/* ========================================
   Markdown Preview Styles
   ======================================== */
.preview-content h1,
.preview-content h2,
.preview-content h3,
.preview-content h4,
.preview-content h5,
.preview-content h6 {
    font-family: var(--font-sans);
    color: var(--preview-text);
    margin-top: 1.5em;
    margin-bottom: 0.5em;
    line-height: 1.3;
}

.preview-content h1 { font-size: 2em; border-bottom: 2px solid var(--border); padding-bottom: 0.3em; }
.preview-content h2 { font-size: 1.5em; border-bottom: 1px solid var(--border); padding-bottom: 0.3em; }
.preview-content h3 { font-size: 1.25em; }
.preview-content h4 { font-size: 1em; }
.preview-content h5 { font-size: 0.875em; }
.preview-content h6 { font-size: 0.85em; color: var(--text-muted); }

.preview-content p {
    margin-bottom: 1em;
}

.preview-content a {
    color: var(--preview-link);
    text-decoration: none;
    border-bottom: 1px solid transparent;
    transition: border-color var(--transition);
}

.preview-content a:hover {
    border-bottom-color: var(--preview-link);
}

.preview-content strong {
    font-weight: 700;
    color: var(--preview-text);
}

.preview-content em {
    font-style: italic;
}

.preview-content ul,
.preview-content ol {
    margin-bottom: 1em;
    padding-left: 2em;
}

.preview-content li {
    margin-bottom: 0.25em;
}

.preview-content li > ul,
.preview-content li > ol {
    margin-top: 0.25em;
    margin-bottom: 0;
}

.preview-content blockquote {
    margin: 1em 0;
    padding: 0.5em 1em;
    border-left: 4px solid var(--preview-blockquote-border);
    background: var(--preview-blockquote);
    color: var(--text-secondary);
    border-radius: 0 var(--radius) var(--radius) 0;
}

.preview-content blockquote p:last-child {
    margin-bottom: 0;
}

.preview-content code {
    font-family: var(--font-mono);
    font-size: 0.9em;
    background: var(--preview-code-bg);
    padding: 0.2em 0.4em;
    border-radius: var(--radius-sm);
    border: 1px solid var(--preview-code-border);
    color: var(--primary);
}

.preview-content pre {
    margin: 1em 0;
    padding: 1em;
    background: var(--preview-code-bg);
    border-radius: var(--radius);
    border: 1px solid var(--preview-code-border);
    overflow-x: auto;
}

.preview-content pre code {
    background: transparent;
    padding: 0;
    border: none;
    color: var(--preview-text);
    font-size: 0.875em;
    line-height: 1.6;
}

.preview-content hr {
    border: none;
    border-top: 2px solid var(--border);
    margin: 2em 0;
}

.preview-content img {
    max-width: 100%;
    height: auto;
    border-radius: var(--radius);
    margin: 1em 0;
    box-shadow: var(--shadow);
}

.preview-content table {
    width: 100%;
    border-collapse: collapse;
    margin: 1em 0;
    font-size: 0.9em;
}

.preview-content th,
.preview-content td {
    padding: 0.75em 1em;
    border: 1px solid var(--border);
    text-align: left;
}

.preview-content th {
    background: var(--surface-elevated);
    font-weight: 600;
    font-family: var(--font-sans);
}

.preview-content tr:nth-child(even) {
    background: var(--border-light);
}

/* Task Lists */
.preview-content input[type="checkbox"] {
    margin-right: 0.5em;
    accent-color: var(--primary);
}

/* ========================================
   Footer
   ======================================== */
.footer {
    height: var(--footer-height);
    background: var(--surface);
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    font-size: 12px;
    color: var(--text-secondary);
    transition: background var(--transition-theme), border-color var(--transition-theme);
}

.footer-left {
    display: flex;
    align-items: center;
    gap: 8px;
}

.footer-divider {
    color: var(--border);
}

.footer-link {
    color: var(--text-secondary);
    text-decoration: none;
    transition: color var(--transition);
}

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

.footer a {
    color: var(--primary);
    text-decoration: none;
}

.footer a:hover {
    text-decoration: underline;
}

.offline-badge {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    background: var(--accent);
    color: white;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 500;
    animation: fadeIn 0.5s ease;
}

.offline-badge svg {
    animation: checkmark 0.3s ease;
}

@keyframes checkmark {
    from { transform: scale(0); }
    to { transform: scale(1); }
}

.offline-badge.offline {
    background: var(--text-muted);
}

.github-link {
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    transition: color var(--transition), transform var(--transition);
}

.github-link:hover {
    color: var(--text);
    transform: scale(1.1);
}

/* ========================================
   Modals
   ======================================== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--transition), visibility var(--transition);
}

.modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.modal {
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xl);
    width: 90%;
    max-width: 700px;
    max-height: 85vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transform: scale(0.9) translateY(20px);
    transition: transform var(--transition-slow);
}

.modal-overlay.active .modal {
    transform: scale(1) translateY(0);
}

.modal-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-header h2 {
    font-size: 18px;
    font-weight: 700;
    color: var(--text);
}

.modal-close {
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius);
    transition: all var(--transition);
}

.modal-close:hover {
    background: var(--border-light);
    color: var(--text);
}

.modal-body {
    padding: 24px;
    overflow-y: auto;
    flex: 1;
}

.help-section {
    margin-bottom: 24px;
}

.help-section:last-child {
    margin-bottom: 0;
}

.help-section h3 {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 12px;
}

.help-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 0;
    border-bottom: 1px solid var(--border-light);
}

.help-item:last-child {
    border-bottom: none;
}

.help-item code {
    font-family: var(--font-mono);
    font-size: 13px;
    background: var(--preview-code-bg);
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    min-width: 140px;
    color: var(--primary);
}

.help-item span {
    color: var(--text-muted);
}

.help-item .h1-sample { font-size: 24px; font-weight: bold; }
.help-item .h2-sample { font-size: 20px; font-weight: bold; }
.help-item .h3-sample { font-size: 16px; font-weight: bold; }

.modal-footer {
    padding: 20px 24px;
    border-top: 1px solid var(--border);
    background: var(--surface-elevated);
}

.modal-footer h3 {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 16px;
}

.shortcuts-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 8px;
}

.shortcut {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
}

.shortcut kbd {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 24px;
    height: 24px;
    padding: 0 6px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--text-secondary);
    box-shadow: 0 1px 2px var(--shadow-sm);
}

.shortcut span {
    color: var(--text-secondary);
    margin-left: auto;
}

/* Confirm Dialog */
.confirm-dialog {
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: 32px;
    text-align: center;
    max-width: 400px;
    box-shadow: var(--shadow-xl);
    transform: scale(0.9);
    transition: transform var(--transition);
}

.modal-overlay.active .confirm-dialog {
    transform: scale(1);
}

.confirm-icon {
    width: 64px;
    height: 64px;
    margin: 0 auto 16px;
    background: #fef3c7;
    color: #f59e0b;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.confirm-dialog h3 {
    font-size: 18px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 8px;
}

.confirm-dialog p {
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 24px;
}

.confirm-actions {
    display: flex;
    gap: 12px;
    justify-content: center;
}

.btn {
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
}

.btn-secondary {
    background: var(--surface-elevated);
    color: var(--text);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background: var(--border-light);
}

.btn-danger {
    background: #ef4444;
    color: white;
}

.btn-danger:hover {
    background: #dc2626;
    transform: translateY(-1px);
}

/* ========================================
   Toast Notifications
   ======================================== */
.toast-container {
    position: fixed;
    bottom: 60px;
    right: 20px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    font-size: 13px;
    color: var(--text);
    animation: toastIn 0.3s ease;
    min-width: 250px;
}

.toast.removing {
    animation: toastOut 0.3s ease forwards;
}

@keyframes toastIn {
    from {
        opacity: 0;
        transform: translateX(100px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes toastOut {
    to {
        opacity: 0;
        transform: translateX(100px);
    }
}

.toast-icon {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.toast.success .toast-icon {
    background: #d1fae5;
    color: #059669;
}

.toast.info .toast-icon {
    background: var(--primary-light);
    color: var(--primary);
}

.toast.warning .toast-icon {
    background: #fef3c7;
    color: #f59e0b;
}

.toast-message {
    flex: 1;
    font-weight: 500;
}

.toast-close {
    width: 20px;
    height: 20px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    transition: all var(--transition);
}

.toast-close:hover {
    background: var(--border-light);
    color: var(--text);
}

/* ========================================
   View States
   ======================================== */
.main-content.editor-only .preview-panel,
.main-content.editor-only .panel-resizer {
    display: none;
}

.main-content.editor-only .editor-panel {
    flex: 1;
}

.main-content.preview-only .editor-panel,
.main-content.preview-only .panel-resizer {
    display: none;
}

.main-content.preview-only .preview-panel {
    flex: 1;
}

/* ========================================
   Highlight.js Theme Override
   ======================================== */
.hljs {
    background: transparent !important;
    padding: 0 !important;
}

/* ========================================
   Responsive Design
   ======================================== */
@media (max-width: 1024px) {
    .header-center {
        display: none;
    }
    
    .greeting {
        display: none;
    }
    
    .logo-text {
        font-size: 16px;
    }
    
    .view-tabs {
        display: none;
    }
    
    .font-controls {
        display: none;
    }
}

@media (max-width: 768px) {
    .formatting-toolbar {
        padding: 0 8px;
    }
    
    .toolbar-divider {
        margin: 0 4px;
    }
    
    .preview-content {
        padding: 16px;
    }
    
    .toc-sidebar {
        width: 100%;
        max-height: 50%;
    }
    
    .main-content {
        flex-direction: column;
    }
    
    .panel-resizer {
        width: 100%;
        height: 6px;
        cursor: row-resize;
    }
    
    .resizer-handle {
        width: 40px;
        height: 2px;
    }
    
    .editor-panel,
    .preview-panel {
        min-width: 100%;
    }
    
    .main-content.mobile-editor .preview-panel {
        display: none;
    }
    
    .main-content.mobile-preview .editor-panel {
        display: none;
    }
    
    .footer-left span:first-child {
        display: none;
    }
}

/* ========================================
   Print Styles
   ======================================== */
@media print {
    .header,
    .formatting-toolbar,
    .find-bar,
    .panel-header,
    .panel-resizer,
    .footer,
    .toc-sidebar {
        display: none !important;
    }
    
    .main-content {
        display: block;
    }
    
    .preview-container {
        overflow: visible;
    }
    
    .preview-content {
        max-width: 100%;
        padding: 0;
    }
}

/* ========================================
   Animations
   ======================================== */
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

.shake {
    animation: shake 0.3s ease;
}

/* Highlight found text */
.highlight-found {
    background: #fef08a !important;
    color: #000 !important;
    border-radius: 2px;
    padding: 1px 2px;
}

body.dark .highlight-found {
    background: #854d0e !important;
    color: #fef08a !important;
}
