/* ===================================
   Markdown Viewer - Main Styles
   markdownviewer.dev
   =================================== */

/* ===================================
   Base Styles & Reset
   =================================== */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    transition: background-color 0.3s ease, color 0.3s ease;
    overflow: hidden;
}

/* Custom Scrollbar */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--scrollbar-track);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb {
    background: var(--scrollbar-thumb);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--scrollbar-thumb-hover);
}

/* Firefox scrollbar */
* {
    scrollbar-width: thin;
    scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
}

/* ===================================
   App Container
   =================================== */
.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
}

/* ===================================
   Header Styles
   =================================== */
.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.6rem 1.25rem;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
    z-index: 100;
    gap: 1rem;
    flex-wrap: wrap;
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.logo-icon {
    width: 28px;
    height: 28px;
    color: var(--accent-primary);
}

.logo-text {
    font-size: 1.1rem;
    font-weight: 700;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

/* Stats Display */
.stats-display {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 0.75rem;
    background: var(--bg-tertiary);
    border-radius: 8px;
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-variant-numeric: tabular-nums;
}

.stat-divider {
    color: var(--text-muted);
}

/* ===================================
   Button Styles
   =================================== */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.45rem 0.9rem;
    font-size: 0.8rem;
    font-weight: 500;
    font-family: inherit;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.btn-primary {
    background: var(--accent-gradient);
    color: white;
    box-shadow: var(--shadow-sm);
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-glow);
}

.btn-secondary {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background: var(--border-color);
    border-color: var(--border-hover);
}

.btn-icon {
    width: 36px;
    height: 36px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-icon:hover {
    background: var(--border-color);
    border-color: var(--border-hover);
}

.btn-sm {
    padding: 0.3rem 0.5rem;
    font-size: 0.75rem;
    background: transparent;
    color: var(--text-secondary);
    border: none;
}

.btn-sm:hover {
    color: var(--accent-primary);
    background: var(--bg-tertiary);
}

/* Command Hint Button */
.command-hint {
    padding: 0.35rem 0.6rem;
    font-size: 0.7rem;
}

.command-hint kbd {
    padding: 0.15rem 0.35rem;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.65rem;
}

/* ===================================
   Theme Selector Dropdown
   =================================== */
.theme-selector {
    position: relative;
}

.theme-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 0.5rem;
    width: 240px;
    max-height: 400px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: all 0.2s ease;
    z-index: 200;
    overflow: hidden;
}

.theme-dropdown.show {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.theme-dropdown-header {
    padding: 0.75rem 1rem;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border-color);
}

.theme-list {
    max-height: 340px;
    overflow-y: auto;
    padding: 0.5rem;
}

.theme-option {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.6rem 0.75rem;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.15s ease;
}

.theme-option:hover {
    background: var(--bg-tertiary);
}

.theme-option.active {
    background: var(--accent-primary);
    color: white;
}

.theme-preview {
    display: flex;
    gap: 2px;
    padding: 2px;
    background: var(--bg-primary);
    border-radius: 4px;
}

.theme-preview-color {
    width: 12px;
    height: 12px;
    border-radius: 2px;
}

.theme-option-name {
    font-size: 0.85rem;
    font-weight: 500;
}

/* ===================================
   Export Dropdown
   =================================== */
.export-dropdown-container {
    position: relative;
}

.export-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 0.5rem;
    width: 200px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: all 0.2s ease;
    z-index: 200;
    overflow: hidden;
    padding: 0.5rem;
}

.export-dropdown.show {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.export-option {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    width: 100%;
    padding: 0.65rem 0.75rem;
    background: transparent;
    border: none;
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s ease;
    font-family: inherit;
}

.export-option:hover {
    background: var(--bg-tertiary);
}

.export-option svg {
    color: var(--text-secondary);
}

/* ===================================
   Floating Toolbar
   =================================== */
.floating-toolbar {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.5rem 0.75rem;
    background: var(--toolbar-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    box-shadow: var(--shadow-lg);
    z-index: 90;
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.floating-toolbar.hidden {
    opacity: 0;
    transform: translateX(-50%) translateY(20px);
    pointer-events: none;
}

.toolbar-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    background: transparent;
    border: none;
    border-radius: 8px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.15s ease;
    font-size: 0.75rem;
    font-weight: 600;
    font-family: 'JetBrains Mono', monospace;
}

.toolbar-btn:hover {
    background: var(--bg-tertiary);
    color: var(--accent-primary);
}

.toolbar-btn:active {
    transform: scale(0.95);
}

.toolbar-divider {
    width: 1px;
    height: 20px;
    background: var(--border-color);
    margin: 0 0.25rem;
}

/* ===================================
   Main Content Area
   =================================== */
.main-content {
    display: flex;
    flex: 1;
    overflow: hidden;
    padding: 0.75rem;
    gap: 0.75rem;
    background: var(--bg-primary);
}

/* ===================================
   Table of Contents Sidebar
   =================================== */
.toc-sidebar {
    width: 0;
    min-width: 0;
    background: var(--bg-secondary);
    border-radius: 12px;
    border: 1px solid var(--border-color);
    overflow: hidden;
    transition: all 0.3s ease;
    display: flex;
    flex-direction: column;
}

.toc-sidebar.show {
    width: 260px;
    min-width: 260px;
}

.toc-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border-color);
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.toc-close {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: 4px;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 1.2rem;
    line-height: 1;
}

.toc-close:hover {
    background: var(--border-color);
    color: var(--text-primary);
}

.toc-content {
    flex: 1;
    padding: 0.75rem;
    overflow-y: auto;
}

.toc-empty {
    color: var(--text-muted);
    font-size: 0.85rem;
    font-style: italic;
    text-align: center;
    padding: 1rem;
}

.toc-item {
    display: block;
    padding: 0.4rem 0.6rem;
    font-size: 0.85rem;
    color: var(--text-secondary);
    text-decoration: none;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.15s ease;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.toc-item:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.toc-item.active {
    background: var(--accent-primary);
    color: white;
}

.toc-item.toc-h1 {
    padding-left: 0.6rem;
    font-weight: 600;
}

.toc-item.toc-h2 {
    padding-left: 1.2rem;
}

.toc-item.toc-h3 {
    padding-left: 1.8rem;
    font-size: 0.8rem;
}

.toc-item.toc-h4 {
    padding-left: 2.4rem;
    font-size: 0.75rem;
}

.toc-item.toc-h5 {
    padding-left: 3rem;
    font-size: 0.75rem;
}

.toc-item.toc-h6 {
    padding-left: 3.6rem;
    font-size: 0.75rem;
}

/* ===================================
   Panel Styles
   =================================== */
.panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-secondary);
    border-radius: 12px;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-md);
    overflow: hidden;
    transition: box-shadow 0.3s ease, border-color 0.3s ease;
    min-width: 0;
}

.panel:hover {
    border-color: var(--border-hover);
}

.panel:focus-within {
    border-color: var(--accent-primary);
    box-shadow: var(--shadow-glow);
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.6rem 1rem;
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border-color);
}

.panel-title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.panel-title svg {
    opacity: 0.7;
}

.panel-actions {
    display: flex;
    gap: 0.25rem;
}

/* Resize Handle */
.resize-handle {
    width: 6px;
    cursor: col-resize;
    background: transparent;
    position: relative;
    flex-shrink: 0;
}

.resize-handle::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 4px;
    height: 40px;
    background: var(--border-color);
    border-radius: 2px;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.resize-handle:hover::after {
    opacity: 1;
}

/* ===================================
   Editor Textarea
   =================================== */
#markdownInput {
    flex: 1;
    width: 100%;
    padding: 1.25rem;
    font-family: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;
    font-size: 0.9rem;
    line-height: 1.7;
    color: var(--text-primary);
    background: var(--bg-secondary);
    border: none;
    outline: none;
    resize: none;
    tab-size: 4;
}

#markdownInput::placeholder {
    color: var(--text-muted);
}

#markdownInput::selection {
    background: rgba(99, 102, 241, 0.3);
}

/* ===================================
   Preview Content
   =================================== */
.preview-content {
    flex: 1;
    padding: 1.25rem;
    overflow-y: auto;
    overflow-x: hidden;
}

.placeholder-text {
    color: var(--text-muted);
    font-style: italic;
}

/* Markdown Rendered Styles */
.preview-content h1,
.preview-content h2,
.preview-content h3,
.preview-content h4,
.preview-content h5,
.preview-content h6 {
    color: var(--text-primary);
    margin-top: 1.5em;
    margin-bottom: 0.5em;
    font-weight: 600;
    line-height: 1.3;
    scroll-margin-top: 1rem;
}

.preview-content h1:first-child,
.preview-content h2:first-child,
.preview-content h3:first-child {
    margin-top: 0;
}

.preview-content h1 {
    font-size: 2rem;
    padding-bottom: 0.3em;
    border-bottom: 2px solid var(--border-color);
}

.preview-content h2 {
    font-size: 1.5rem;
    padding-bottom: 0.2em;
    border-bottom: 1px solid var(--border-color);
}

.preview-content h3 {
    font-size: 1.25rem;
}

.preview-content h4 {
    font-size: 1rem;
}

.preview-content h5 {
    font-size: 0.9rem;
}

.preview-content h6 {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.preview-content p {
    margin-bottom: 1em;
}

.preview-content a {
    color: var(--accent-primary);
    text-decoration: none;
    border-bottom: 1px solid transparent;
    transition: border-color 0.2s ease;
}

.preview-content a:hover {
    border-bottom-color: var(--accent-primary);
}

.preview-content strong {
    font-weight: 600;
    color: var(--text-primary);
}

.preview-content em {
    font-style: italic;
}

.preview-content del {
    text-decoration: line-through;
    color: var(--text-muted);
}

.preview-content code {
    font-family: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;
    font-size: 0.875em;
    padding: 0.2em 0.4em;
    background: var(--code-bg);
    color: var(--code-text);
    border-radius: 4px;
}

.preview-content pre {
    margin: 1em 0;
    padding: 1rem;
    background: var(--pre-bg);
    border-radius: 8px;
    overflow-x: auto;
    position: relative;
}

.preview-content pre code {
    padding: 0;
    background: transparent;
    color: var(--pre-text);
    font-size: 0.85rem;
    line-height: 1.6;
}

/* Code block language label */
.preview-content pre[data-language]::before {
    content: attr(data-language);
    position: absolute;
    top: 0.5rem;
    right: 0.75rem;
    font-size: 0.7rem;
    font-weight: 500;
    color: var(--text-muted);
    text-transform: uppercase;
}

.preview-content blockquote {
    margin: 1em 0;
    padding: 0.75em 1em;
    border-left: 4px solid var(--accent-primary);
    background: var(--bg-tertiary);
    border-radius: 0 8px 8px 0;
    color: var(--text-secondary);
}

.preview-content blockquote p:last-child {
    margin-bottom: 0;
}

.preview-content ul,
.preview-content ol {
    margin: 1em 0;
    padding-left: 2em;
}

.preview-content li {
    margin: 0.25em 0;
}

.preview-content li>ul,
.preview-content li>ol {
    margin: 0.25em 0;
}

.preview-content hr {
    margin: 2em 0;
    border: none;
    height: 2px;
    background: linear-gradient(90deg, transparent, var(--border-color), transparent);
}

.preview-content table {
    width: 100%;
    margin: 1em 0;
    border-collapse: collapse;
    border-radius: 8px;
    overflow: hidden;
}

.preview-content th,
.preview-content td {
    padding: 0.75rem 1rem;
    text-align: left;
    border: 1px solid var(--border-color);
}

.preview-content th {
    background: var(--bg-tertiary);
    font-weight: 600;
}

.preview-content tr:nth-child(even) {
    background: var(--bg-tertiary);
}

.preview-content img {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
    margin: 1em 0;
}

/* Task List Styles */
.preview-content input[type="checkbox"] {
    margin-right: 0.5em;
    accent-color: var(--accent-primary);
    cursor: pointer;
}

.preview-content li.task-list-item {
    list-style: none;
    margin-left: -1.5em;
}

/* Custom Syntax Extensions */
.text-center {
    text-align: center;
}

.text-right {
    text-align: right;
}

.page-break {
    page-break-after: always;
    margin: 2em 0;
    border-top: 2px dashed var(--border-color);
    position: relative;
}

.page-break::after {
    content: 'Page Break';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    padding: 0.25em 0.75em;
    background: var(--bg-secondary);
    color: var(--text-muted);
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* Mermaid diagrams */
.mermaid {
    background: var(--bg-tertiary);
    padding: 1rem;
    border-radius: 8px;
    margin: 1em 0;
    text-align: center;
}

/* KaTeX math */
.katex-display {
    margin: 1em 0;
    overflow-x: auto;
    overflow-y: hidden;
}

/* ===================================
   Mobile View Toggle
   =================================== */
.mobile-view-toggle {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 0.5rem;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
    z-index: 100;
}

.mobile-view-toggle .view-btn {
    flex: 1;
    padding: 0.75rem;
    background: var(--bg-tertiary);
    border: none;
    border-radius: 8px;
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: inherit;
}

.mobile-view-toggle .view-btn.active {
    background: var(--accent-primary);
    color: white;
}

/* ===================================
   Command Palette
   =================================== */
.command-palette-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding-top: 15vh;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: all 0.2s ease;
}

.command-palette-overlay.show {
    opacity: 1;
    visibility: visible;
}

.command-palette {
    width: 100%;
    max-width: 560px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    transform: scale(0.95) translateY(-20px);
    transition: transform 0.2s ease;
}

.command-palette-overlay.show .command-palette {
    transform: scale(1) translateY(0);
}

.command-search {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border-color);
}

.command-search svg {
    color: var(--text-muted);
    flex-shrink: 0;
}

.command-search input {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    font-size: 1rem;
    color: var(--text-primary);
    font-family: inherit;
}

.command-search input::placeholder {
    color: var(--text-muted);
}

.command-list {
    max-height: 320px;
    overflow-y: auto;
    padding: 0.5rem;
}

.command-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.15s ease;
}

.command-item:hover,
.command-item.selected {
    background: var(--bg-tertiary);
}

.command-item-icon {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-primary);
    border-radius: 8px;
    color: var(--accent-primary);
}

.command-item-content {
    flex: 1;
}

.command-item-title {
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-primary);
}

.command-item-desc {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.command-item-shortcut {
    display: flex;
    gap: 0.25rem;
}

.command-item-shortcut kbd {
    padding: 0.2rem 0.4rem;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 0.7rem;
    font-family: 'JetBrains Mono', monospace;
    color: var(--text-secondary);
}

.command-footer {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1.5rem;
    padding: 0.75rem;
    background: var(--bg-tertiary);
    border-top: 1px solid var(--border-color);
    font-size: 0.75rem;
    color: var(--text-muted);
}

.command-footer kbd {
    padding: 0.15rem 0.35rem;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.65rem;
    margin-right: 0.25rem;
}

/* ===================================
   Reading Mode
   =================================== */
.reading-mode-container {
    position: fixed;
    inset: 0;
    background: var(--bg-primary);
    z-index: 500;
    display: flex;
    flex-direction: column;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.reading-mode-container.show {
    opacity: 1;
    visibility: visible;
}

.reading-mode-close {
    position: fixed;
    top: 1.5rem;
    right: 1.5rem;
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 50%;
    color: var(--text-secondary);
    cursor: pointer;
    z-index: 10;
    transition: all 0.2s ease;
}

.reading-mode-close:hover {
    background: var(--border-color);
    color: var(--text-primary);
}

.reading-mode-content {
    flex: 1;
    max-width: 720px;
    margin: 0 auto;
    padding: 3rem 2rem;
    overflow-y: auto;
    line-height: 1.8;
    font-size: 1.1rem;
}

/* Copy styles from preview-content */
.reading-mode-content h1,
.reading-mode-content h2,
.reading-mode-content h3,
.reading-mode-content h4,
.reading-mode-content h5,
.reading-mode-content h6 {
    color: var(--text-primary);
    margin-top: 1.5em;
    margin-bottom: 0.5em;
    font-weight: 600;
    line-height: 1.3;
}

.reading-mode-content h1 {
    font-size: 2.5rem;
    padding-bottom: 0.3em;
    border-bottom: 2px solid var(--border-color);
}

.reading-mode-content h2 {
    font-size: 2rem;
    padding-bottom: 0.2em;
    border-bottom: 1px solid var(--border-color);
}

.reading-mode-content h3 {
    font-size: 1.5rem;
}

.reading-mode-content h4 {
    font-size: 1.25rem;
}

.reading-mode-content p {
    margin-bottom: 1.2em;
}

.reading-mode-content a {
    color: var(--accent-primary);
}

.reading-mode-content code {
    font-family: 'JetBrains Mono', monospace;
    background: var(--code-bg);
    color: var(--code-text);
    padding: 0.2em 0.4em;
    border-radius: 4px;
}

.reading-mode-content pre {
    margin: 1.5em 0;
    padding: 1.25rem;
    background: var(--pre-bg);
    border-radius: 12px;
    overflow-x: auto;
}

.reading-mode-content pre code {
    padding: 0;
    background: transparent;
    color: var(--pre-text);
}

.reading-mode-content blockquote {
    margin: 1.5em 0;
    padding: 1em 1.5em;
    border-left: 4px solid var(--accent-primary);
    background: var(--bg-tertiary);
    border-radius: 0 12px 12px 0;
}

.reading-mode-content table {
    width: 100%;
    margin: 1.5em 0;
    border-collapse: collapse;
}

.reading-mode-content th,
.reading-mode-content td {
    padding: 0.75rem 1rem;
    border: 1px solid var(--border-color);
}

.reading-mode-content th {
    background: var(--bg-tertiary);
}

/* ===================================
   Toast Notification
   =================================== */
.toast {
    position: fixed;
    bottom: 6rem;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1.25rem;
    background: var(--accent-primary);
    color: white;
    border-radius: 10px;
    box-shadow: var(--shadow-lg);
    font-size: 0.875rem;
    font-weight: 500;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    z-index: 1000;
}

.toast.show {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(0);
}

.toast.error {
    background: #ef4444;
}

.toast-icon {
    display: none;
}

.toast .toast-success {
    display: block;
}

.toast.error .toast-success {
    display: none;
}

.toast.error .toast-error {
    display: block;
}

/* ===================================
   Responsive Design
   =================================== */
@media (max-width: 1024px) {
    .stats-display {
        display: none;
    }

    .command-hint {
        display: none;
    }
}

@media (max-width: 768px) {
    .header {
        padding: 0.5rem 0.75rem;
    }

    .logo-text {
        display: none;
    }

    .main-content {
        flex-direction: column;
        padding: 0;
        padding-bottom: 60px;
    }

    .panel {
        border-radius: 0;
        border-left: none;
        border-right: none;
    }

    .toc-sidebar {
        display: none;
    }

    .resize-handle {
        display: none;
    }

    .floating-toolbar {
        bottom: 70px;
        padding: 0.4rem 0.5rem;
        gap: 0.15rem;
        max-width: calc(100% - 2rem);
        overflow-x: auto;
    }

    .toolbar-btn {
        width: 28px;
        height: 28px;
    }

    .mobile-view-toggle {
        display: flex;
        gap: 0.5rem;
    }

    .editor-panel,
    .preview-panel {
        display: none;
    }

    .editor-panel.mobile-active,
    .preview-panel.mobile-active {
        display: flex;
    }
}

@media (max-width: 480px) {
    .btn-primary span {
        display: none;
    }

    .export-dropdown {
        right: -50px;
    }

    .theme-dropdown {
        right: -100px;
    }
}

/* ===================================
   Print Styles
   =================================== */
@media print {

    .header,
    .floating-toolbar,
    .toc-sidebar,
    .toast,
    .editor-panel,
    .mobile-view-toggle,
    .command-palette-overlay,
    .reading-mode-container,
    .resize-handle {
        display: none !important;
    }

    body {
        background: white;
        color: black;
    }

    .app-container {
        height: auto;
        overflow: visible;
    }

    .main-content {
        display: block;
        padding: 0;
    }

    .preview-panel {
        box-shadow: none;
        border: none;
        border-radius: 0;
    }

    .preview-content {
        padding: 0;
    }

    .page-break {
        page-break-after: always;
        border: none;
    }

    .page-break::after {
        display: none;
    }
}

/* ===================================
   Animations
   =================================== */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes pulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.5;
    }
}

.panel {
    animation: fadeIn 0.4s ease forwards;
}

.editor-panel {
    animation-delay: 0.1s;
}

.preview-panel {
    animation-delay: 0.2s;
}

/* Loading state */
.loading {
    animation: pulse 1.5s ease-in-out infinite;
}

/* ===================================
   Phase 2: AI Sidebar
   =================================== */
.ai-btn {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%) !important;
    border-color: #059669 !important;
    color: white !important;
}

.ai-btn:hover {
    box-shadow: 0 0 15px rgba(16, 185, 129, 0.4);
}

.ai-sidebar {
    position: fixed;
    top: 0;
    right: 0;
    width: 380px;
    height: 100vh;
    background: var(--bg-secondary);
    border-left: 1px solid var(--border-color);
    box-shadow: var(--shadow-lg);
    z-index: 300;
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    transition: transform 0.3s ease;
}

.ai-sidebar.show {
    transform: translateX(0);
}

.ai-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    color: white;
}

.ai-title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 600;
    font-size: 1rem;
}

.ai-close {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.2);
    border: none;
    border-radius: 6px;
    color: white;
    font-size: 1.2rem;
    cursor: pointer;
    transition: background 0.2s;
}

.ai-close:hover {
    background: rgba(255, 255, 255, 0.3);
}

.ai-actions {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.5rem;
    padding: 0.75rem;
    border-bottom: 1px solid var(--border-color);
}

.ai-action-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.35rem;
    padding: 0.6rem 0.5rem;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-secondary);
    font-size: 0.7rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
}

.ai-action-btn:hover {
    background: var(--accent-primary);
    color: white;
    border-color: var(--accent-primary);
}

.ai-action-btn svg {
    width: 18px;
    height: 18px;
}

.ai-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.ai-message {
    max-width: 90%;
    padding: 0.75rem 1rem;
    border-radius: 12px;
    font-size: 0.875rem;
    line-height: 1.6;
    white-space: pre-line;
}

.ai-message-user {
    align-self: flex-end;
    background: var(--accent-primary);
    color: white;
    border-bottom-right-radius: 4px;
}

.ai-message-assistant {
    align-self: flex-start;
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border-bottom-left-radius: 4px;
}

.ai-message-content ul {
    margin: 0.5rem 0 0 1rem;
    padding: 0;
}

.ai-message-content li {
    margin: 0.25rem 0;
}

.ai-message-loading {
    display: flex;
    gap: 0.3rem;
    padding: 1rem;
}

.ai-message-loading span {
    width: 8px;
    height: 8px;
    background: var(--accent-primary);
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out;
}

.ai-message-loading span:nth-child(1) {
    animation-delay: -0.32s;
}

.ai-message-loading span:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes bounce {

    0%,
    80%,
    100% {
        transform: scale(0);
    }

    40% {
        transform: scale(1);
    }
}

.ai-input-container {
    display: flex;
    gap: 0.5rem;
    padding: 0.75rem;
    border-top: 1px solid var(--border-color);
    background: var(--bg-tertiary);
}

#aiInput {
    flex: 1;
    padding: 0.6rem 0.75rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.875rem;
    resize: none;
    outline: none;
}

#aiInput:focus {
    border-color: var(--accent-primary);
}

.ai-send-btn {
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    border: none;
    border-radius: 8px;
    color: white;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}

.ai-send-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
}

.ai-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ===================================
   Phase 2: Version History Sidebar
   =================================== */
.history-sidebar {
    position: fixed;
    top: 0;
    right: 0;
    width: 320px;
    height: 100vh;
    background: var(--bg-secondary);
    border-left: 1px solid var(--border-color);
    box-shadow: var(--shadow-lg);
    z-index: 300;
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    transition: transform 0.3s ease;
}

.history-sidebar.show {
    transform: translateX(0);
}

.history-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border-color);
}

.history-title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--text-primary);
}

.history-close {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: 6px;
    color: var(--text-muted);
    font-size: 1.2rem;
    cursor: pointer;
    transition: all 0.2s;
}

.history-close:hover {
    background: var(--border-color);
    color: var(--text-primary);
}

.history-actions {
    display: flex;
    gap: 0.5rem;
    padding: 0.75rem;
    border-bottom: 1px solid var(--border-color);
}

.history-actions .btn {
    flex: 1;
}

.history-list {
    flex: 1;
    overflow-y: auto;
    padding: 0.75rem;
}

.history-empty {
    text-align: center;
    color: var(--text-muted);
    font-size: 0.85rem;
    padding: 2rem 1rem;
    line-height: 1.6;
}

.history-item {
    padding: 0.75rem;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    margin-bottom: 0.5rem;
    cursor: pointer;
    transition: all 0.2s;
}

.history-item:hover {
    border-color: var(--accent-primary);
}

.history-item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.35rem;
}

.history-item-time {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-primary);
}

.history-item-actions {
    display: flex;
    gap: 0.25rem;
}

.history-item-btn {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: 4px;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.2s;
}

.history-item-btn:hover {
    background: var(--accent-primary);
    color: white;
}

.history-item-preview {
    font-size: 0.75rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.history-item-stats {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
}

/* ===================================
   Phase 2: Share Modal
   =================================== */
.share-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: all 0.2s ease;
}

.share-modal-overlay.show {
    opacity: 1;
    visibility: visible;
}

.share-modal {
    width: 100%;
    max-width: 500px;
    margin: 1rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    box-shadow: var(--shadow-lg);
    transform: scale(0.95);
    transition: transform 0.2s ease;
}

.share-modal-overlay.show .share-modal {
    transform: scale(1);
}

.share-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border-color);
}

.share-header h3 {
    font-size: 1.1rem;
    font-weight: 600;
}

.share-close {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: 6px;
    color: var(--text-muted);
    font-size: 1.2rem;
    cursor: pointer;
}

.share-close:hover {
    background: var(--border-color);
}

.share-content {
    padding: 1.25rem;
}

.share-content p {
    margin-bottom: 0.75rem;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.share-link-container {
    display: flex;
    gap: 0.5rem;
}

.share-link-container input {
    flex: 1;
    padding: 0.6rem 0.75rem;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.8rem;
}

.share-note {
    font-size: 0.75rem !important;
    color: var(--text-muted) !important;
    margin-top: 1rem !important;
    margin-bottom: 0 !important;
}

/* ===================================
   Phase 2: Find & Replace Bar
   =================================== */
.find-replace-bar {
    position: fixed;
    top: 60px;
    right: 1rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    padding: 0.75rem;
    z-index: 200;
    display: none;
    flex-direction: column;
    gap: 0.5rem;
    min-width: 360px;
}

.find-replace-bar.show {
    display: flex;
}

.find-replace-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.find-replace-row input {
    flex: 1;
    padding: 0.5rem 0.75rem;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.85rem;
    outline: none;
}

.find-replace-row input:focus {
    border-color: var(--accent-primary);
}

.find-count {
    font-size: 0.75rem;
    color: var(--text-muted);
    white-space: nowrap;
    min-width: 60px;
}

.find-btn {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s;
}

.find-btn:hover {
    background: var(--accent-primary);
    color: white;
    border-color: var(--accent-primary);
}

.find-close {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: 4px;
    color: var(--text-muted);
    font-size: 1.1rem;
    cursor: pointer;
}

.find-close:hover {
    background: var(--border-color);
}

/* ===================================
   Responsive adjustments for Phase 2
   =================================== */
@media (max-width: 768px) {

    .ai-sidebar,
    .history-sidebar {
        width: 100%;
    }

    .find-replace-bar {
        right: 0.5rem;
        left: 0.5rem;
        min-width: auto;
    }
}

/* ===================================
   GitHub Link
   =================================== */
.github-link {
    display: flex;
    align-items: center;
    justify-content: center;
    margin-left: 0.75rem;
    padding: 0.4rem;
    color: var(--text-muted);
    opacity: 0.7;
    border-radius: 6px;
    transition: all 0.2s ease;
}

.github-link:hover {
    color: var(--text-primary);
    opacity: 1;
    background: var(--bg-tertiary);
}

.github-link svg {
    fill: currentColor;
}