/* --- 1. Theming and Variables --- */
:root {
    /* Fonts */
    --font-sans: 'Lexend', sans-serif;
    --font-header: 'Outfit', sans-serif;
    --font-mono: 'PT Mono', monospace;

    /* Light Theme */
    --bg-primary: oklch(0.99 0.002 270);
    --bg-secondary: oklch(0.98 0.004 270);
    --text-primary: oklch(0.18 0.020 270);
    --text-secondary: oklch(0.55 0.025 270);
    --border-color: oklch(0.92 0.010 270);
    --accent-color: oklch(0.20 0.000 0);
    --accent-hover: oklch(0.40 0.000 0);
    
    --code-bg: oklch(0.96 0.005 270);
    --code-text: oklch(0.35 0.030 270);
    --hljs-bg: oklch(0.97 0.003 270);
    --hljs-text: oklch(0.45 0.025 270);

    --primary: var(--accent-color);
    --primary-dark: oklch(0.10 0.000 0);
    --secondary: oklch(0.45 0.015 270);
    --user-bg: oklch(0.95 0.005 270);
    --ai-bg: oklch(1.00 0.000 0);
    --error-color: oklch(0.60 0.150 25);
    --success-color: oklch(0.65 0.120 150);
    --warning-color: oklch(0.85 0.140 85);
    
    --shadow-light: 0 1px 3px 0 oklch(0 0 0 / 0.05);
    --shadow-medium: 0 4px 6px -1px oklch(0 0 0 / 0.1);
    --float-shadow: 0 8px 20px oklch(0 0 0 / 0.08);
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    
    /* Workspace card radius */
    --card-radius: 16px;
}

[data-theme='dark'] {
    --bg-primary: oklch(0.12 0.005 270);
    --bg-secondary: oklch(0.16 0.008 270);
    --text-primary: oklch(0.95 0.010 270);
    --text-secondary: oklch(0.75 0.020 270);
    --border-color: oklch(0.24 0.015 270);
    --accent-color: oklch(0.75 0.120 250);
    --accent-hover: oklch(0.65 0.150 255);
    
    --code-bg: oklch(0.18 0.015 270);
    --code-text: oklch(0.88 0.020 270);
    --hljs-bg: oklch(0.14 0.010 270);
    --hljs-text: oklch(0.85 0.025 270);

    --user-bg: oklch(0.20 0.015 270);
    --ai-bg: oklch(0.14 0.008 270);
    --shadow-light: 0 1px 3px 0 oklch(0 0 0 / 0.3);
    --shadow-medium: 0 4px 12px oklch(0 0 0 / 0.5);
}


/* --- 2. Global Styles & Reset --- */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    height: 100%;
}

body {
    font-family: var(--font-sans);
    background-color: var(--bg-primary);
    color: var(--text-primary);
    transition: background-color 0.2s, color 0.2s;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* --- 3. Responsive Utility Classes --- */
.desktop-only {
    display: flex;
}
.mobile-only {
    display: none;
}

@media (max-width: 768px) {
    .desktop-only {
        display: none !important;
    }
    .mobile-only {
        display: flex !important;
    }
}

/* --- 4. App Layout --- */
#app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
}

/* 2026 Design: Header seamlessly sits on the page bg — no bottom border */
#app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.6rem 1rem;
    background-color: var(--bg-primary);
    flex-shrink: 0;
    /* No border-bottom — workspace card provides visual grounding */
}

#app-title {
    font-size: 1.0rem;
    font-weight: 600;
    letter-spacing: -0.01em;
}

#app-header .controls {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

/* Unified header icon button style — all circles, consistent */
#app-header .controls button,
#sidebar-toggle,
.back-to-dashboard,
#ai-modal-close-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1rem;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 50%;
    width: 38px;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.15s, color 0.15s;
    text-decoration: none;
}

#app-header .controls button:hover,
#sidebar-toggle:hover,
.back-to-dashboard:hover,
#ai-modal-close-btn:hover {
    background-color: var(--bg-secondary);
    color: var(--text-primary);
}

/* Theme toggle: full icon-button, consistent on editor AND dashboard */
#theme-toggle {
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    font-size: 1rem;
    cursor: pointer;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.15s, color 0.15s, border-color 0.15s;
    padding: 0;
    flex-shrink: 0;
}

#theme-toggle:hover {
    background-color: var(--border-color);
    color: var(--text-primary);
    border-color: var(--text-secondary);
}

#app-header .header-left {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

#sidebar-toggle {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1rem;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 50%;
    width: 38px;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.15s, color 0.15s;
}

#sidebar-toggle:hover {
    background-color: var(--bg-secondary);
    color: var(--text-primary);
}

/* 2026 Design: App body as a workspace card — box with top radius, border */
#app-body {
    display: flex;
    flex-grow: 1;
    overflow: hidden;
    margin: 0 1rem;
    border-radius: var(--card-radius) var(--card-radius) 0 0;
    border: 1px solid var(--border-color);
    border-bottom: none;
}

/* 2026 Design: Footer closes the card with bottom radius */
#app-footer {
    margin: 0 1rem 1rem;
    padding: 0.45rem 1.25rem;
    border: 1px solid var(--border-color);
    border-top: 1px solid var(--border-color);
    border-radius: 0 0 var(--card-radius) var(--card-radius);
    font-size: 0.8rem;
    color: var(--text-secondary);
    text-align: right;
    flex-shrink: 0;
    background-color: var(--bg-secondary);
}

#sidebar {
    width: 270px;
    background-color: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    transition: margin-left 0.3s ease;
}

#sidebar.hidden {
    margin-left: -270px;
}

#sidebar-header {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.sidebar-tabs {
    display: flex;
    background-color: var(--bg-primary);
    border-radius: 999px;
    padding: 0.25rem;
    width: 100%;
    border: 1px solid var(--border-color);
}

.tab-btn {
    flex: 1;
    border: none;
    background: none;
    padding: 0.4rem;
    font-family: var(--font-sans);
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: 999px;
    transition: var(--transition);
}

.tab-btn.active {
    background-color: var(--accent-color);
    color: white;
}

[data-theme='dark'] .tab-btn.active {
    color: var(--bg-primary);
}

#new-file-btn-sidebar {
    background-color: var(--bg-primary);
    border: 1px solid var(--border-color);
    color: var(--accent-color);
    width: 100%;
    border-radius: 999px;
    padding: 0.5rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    font-family: var(--font-sans);
    font-size: 0.9rem;
    transition: var(--transition);
}

#new-file-btn-sidebar:hover {
    background-color: var(--border-color);
}

#new-file-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1rem;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 12px;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s, color 0.2s;
}

#new-file-btn:hover {
    background-color: var(--border-color);
    color: var(--text-primary);
}

.sidebar-content {
    flex-grow: 1;
    overflow-y: auto;
}

#file-list {
    list-style: none;
    padding: 0.5rem;
}

.file-item {
    display: flex;
    align-items: center;
    padding: 0.6rem 0.8rem;
    border-radius: 12px;
    cursor: pointer;
    margin-bottom: 0.25rem;
    position: relative;
}

.file-item:hover {
    background-color: var(--border-color);
}

.file-item.active {
    background-color: var(--accent-color);
    color: white;
}

[data-theme='dark'] .file-item.active {
    background-color: var(--accent-color);
    color: var(--bg-primary);
}

.file-item-name {
    flex-grow: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 0.9rem;
}

.file-date-chip {
    font-size: 0.7rem;
    background-color: var(--bg-primary);
    padding: 0.1rem 0.4rem;
    border-radius: 4px;
    color: var(--text-secondary);
    margin-right: 0.5rem;
}

.file-item-actions {
    display: none;
    position: absolute;
    right: 0.5rem;
    top: 50%;
    transform: translateY(-50%);
    gap: 0.25rem;
    background-color: var(--border-color);
    padding: 0.25rem;
    border-radius: 6px;
}

.file-item:hover .file-item-actions,
.file-item .file-item-actions.visible {
    display: flex;
}

.file-item.active .file-item-actions {
    background-color: transparent;
}

.file-item-actions button {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 0.85rem;
    padding: 0.4rem;
    border-radius: 4px;
    color: var(--text-secondary);
    transition: background-color 0.2s, color 0.2s;
}

.file-item.active .file-item-actions button {
    color: var(--text-primary);
}

[data-theme='dark'] .file-item.active .file-item-actions button {
    color: var(--text-primary);
}

.file-item-actions button:hover {
    background-color: var(--bg-secondary);
    color: var(--text-primary);
}

.file-item.active .file-item-actions button:hover {
    background-color: rgba(255, 255, 255, 0.2);
}
[data-theme='dark'] .file-item.active .file-item-actions button:hover {
    background-color: rgba(0, 0, 0, 0.2);
}

#app-main {
    flex-grow: 1;
    position: relative;
    overflow-y: hidden;
    background-color: var(--bg-primary);
}

#editor-container {
    position: relative;
    width: 100%;
    height: 100%;
}

#editor-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    padding: 1.2rem 1.2rem;
    font-family: var(--font-mono);
    font-size: 1rem;
    line-height: 1.7;
    white-space: pre-wrap;
    word-wrap: break-word;
    color: transparent;
    pointer-events: none;
    overflow-y: auto;
    border: none;
}

.search-match {
    background-color: rgba(255, 255, 0, 0.3);
    border-radius: 2px;
}

.search-match.current {
    background-color: rgba(255, 165, 0, 0.6);
}

/* --- 5. Editor & Preview Panes --- */
#editor, #preview {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    padding: 1.2rem 1.2rem;
    overflow-y: auto;
    transition: opacity 0.2s ease-in-out;
}

#editor {
    background-color: transparent;
    color: var(--text-primary);
    border: none;
    resize: none;
    font-family: var(--font-mono);
    font-size: 1rem;
    line-height: 1.7;
    z-index: 1;
    display: block;
}

#editor:focus {
    outline: none;
}

#preview {
    line-height: 1.8;
    max-width: 800px;
    margin: 0 auto;
}

.hidden {
    opacity: 0;
    pointer-events: none;
}

/* --- 6. Preview Typography & Elements --- */
#preview > *:first-child {
    margin-top: 0;
}

#preview h1, #preview h2, #preview h3, #preview h4, #preview h5, #preview h6 {
    font-family: var(--font-header);
    font-weight: 700;
    margin-top: 1.5em;
    margin-bottom: 0.5em;
    color: var(--text-primary);
}
#preview h1 { font-size: 2.25rem; }
#preview h2 { font-size: 1.75rem; }
#preview h3 { font-size: 1.5rem; }
#preview p { margin-bottom: 1.25em; }
#preview a { color: var(--accent-color); text-decoration: none; font-weight: 500; }
#preview a:hover { text-decoration: underline; }
#preview ul, #preview ol { margin-left: 1.5rem; margin-bottom: 1em; }
#preview li { margin-bottom: 0.5em; }

#preview blockquote {
    border-left: 4px solid var(--border-color);
    padding-left: 1em;
    margin: 1.5em 0;
    color: var(--text-secondary);
    font-style: italic;
}
#preview hr {
    border: none;
    border-top: 1px solid var(--border-color);
    margin: 2em 0;
}
#preview table {
    width: 100%;
    border-collapse: collapse;
    margin: 1.5em 0;
    font-size: 0.95rem;
}
#preview th, #preview td {
    border: 1px solid var(--border-color);
    padding: 0.75em;
    text-align: left;
}
#preview th {
    font-weight: bold;
    background-color: var(--bg-secondary);
}
#preview tr:nth-child(2n) {
    background-color: var(--bg-secondary);
}

/* --- 7. Task Lists & Code Blocks --- */
#preview .task-list-item {
    list-style-type: none;
}
#preview .task-list-item input[type="checkbox"] {
    appearance: none;
    -webkit-appearance: none;
    width: 1.15em;
    height: 1.15em;
    border: 2px solid var(--text-secondary);
    border-radius: 3px;
    vertical-align: middle;
    position: relative;
    top: -0.1em;
    margin-right: 0.5em;
    cursor: default;
}
#preview .task-list-item input[type="checkbox"]:checked {
    background-color: var(--accent-color);
    border-color: var(--accent-color);
}
#preview .task-list-item input[type="checkbox"]:checked::after {
    content: '✔';
    color: var(--bg-primary);
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    font-size: 0.8em;
}

#preview code {
    font-family: var(--font-mono);
    background-color: var(--code-bg);
    color: var(--code-text);
    padding: 0.2em 0.4em;
    border-radius: 4px;
    font-size: 0.9em;
}

#preview pre {
    background-color: var(--hljs-bg);
    padding: 1em;
    border-radius: 8px;
    overflow-x: auto;
    margin-bottom: 1.5em;
}

#preview pre code {
    padding: 0;
    background: none;
}

#preview .code-block-container {
    margin-bottom: 1.5em;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid var(--border-color);
}

#preview .code-block-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: var(--bg-secondary);
    padding: 0.5em 1em;
    border-bottom: 1px solid var(--border-color);
}

#preview .lang-name {
    font-size: 0.8em;
    font-family: var(--font-mono);
    color: var(--text-secondary);
    text-transform: uppercase;
}

#preview .copy-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 0.85em;
    padding: 0.3em 0.6em;
    border-radius: 4px;
    transition: background-color 0.2s, color 0.2s;
    font-family: var(--font-sans);
}

#preview .copy-btn:hover {
    background-color: var(--border-color);
    color: var(--text-primary);
}

#preview .copy-btn .fas,
#preview .copy-btn .far {
    margin-right: 0.5em;
}

#preview .code-block-container pre {
    margin-bottom: 0;
    border-radius: 0;
    border: none;
    background-color: var(--hljs-bg);
}

/* GitHub Dark Theme for highlight.js */
[data-theme='dark'] .hljs{color:#c9d1d9;background:#0d1117}
[data-theme='dark'] .hljs-doctag,[data-theme='dark'] .hljs-keyword,[data-theme='dark'] .hljs-meta .hljs-keyword,[data-theme='dark'] .hljs-template-tag,[data-theme='dark'] .hljs-template-variable,[data-theme='dark'] .hljs-type,[data-theme='dark'] .hljs-variable.language_{color:#ff7b72}
[data-theme='dark'] .hljs-title,[data-theme='dark'] .hljs-title.class_,[data-theme='dark'] .hljs-title.class_.inherited__,[data-theme='dark'] .hljs-title.function_{color:#d2a8ff}
[data-theme='dark'] .hljs-attr,[data-theme='dark'] .hljs-attribute,[data-theme='dark'] .hljs-literal,[data-theme='dark'] .hljs-meta,[data-theme='dark'] .hljs-number,[data-theme='dark'] .hljs-operator,[data-theme='dark'] .hljs-selector-attr,[data-theme='dark'] .hljs-selector-class,[data-theme='dark'] .hljs-selector-id,[data-theme='dark'] .hljs-variable{color:#79c0ff}
[data-theme='dark'] .hljs-regexp,[data-theme='dark'] .hljs-string,[data-theme='dark'] .hljs-symbol{color:#a5d6ff}
[data-theme='dark'] .hljs-built_in,[data-theme='dark'] .hljs-code,[data-theme='dark'] .hljs-comment,[data-theme='dark'] .hljs-formula,[data-theme='dark'] .hljs-name,[data-theme='dark'] .hljs-quote,[data-theme='dark'] .hljs-selector-pseudo,[data-theme='dark'] .hljs-selector-tag,[data-theme='dark'] .hljs-subst,[data-theme='dark'] .hljs-tag{color:#8b949e}
[data-theme='dark'] .hljs-section{color:#1f6feb;font-weight:700}
[data-theme='dark'] .hljs-bullet{color:#f2cc60}
[data-theme='dark'] .hljs-emphasis{color:#c9d1d9;font-style:italic}
[data-theme='dark'] .hljs-strong{color:#c9d1d9;font-weight:700}
[data-theme='dark'] .hljs-addition{color:#aff5b4;background-color:#033a16}
[data-theme='dark'] .hljs-deletion{color:#ffdcd7;background-color:#67060c}

/* GitHub Light Theme for highlight.js */
[data-theme='light'] .hljs{color:#24292e;background:#fff}
[data-theme='light'] .hljs-doctag,[data-theme='light'] .hljs-keyword,[data-theme='light'] .hljs-meta .hljs-keyword,[data-theme='light'] .hljs-template-tag,[data-theme='light'] .hljs-template-variable,[data-theme='light'] .hljs-type,[data-theme='light'] .hljs-variable.language_{color:#d73a49}
[data-theme='light'] .hljs-title,[data-theme='light'] .hljs-title.class_,[data-theme='light'] .hljs-title.class_.inherited__,[data-theme='light'] .hljs-title.function_{color:#6f42c1}
[data-theme='light'] .hljs-attr,[data-theme='light'] .hljs-attribute,[data-theme='light'] .hljs-literal,[data-theme='light'] .hljs-meta,[data-theme='light'] .hljs-number,[data-theme='light'] .hljs-operator,[data-theme='light'] .hljs-selector-attr,[data-theme='light'] .hljs-selector-class,[data-theme='light'] .hljs-selector-id,[data-theme='light'] .hljs-variable{color:#005cc5}
[data-theme='light'] .hljs-regexp,[data-theme='light'] .hljs-string,[data-theme='light'] .hljs-symbol{color:#032f62}
[data-theme='light'] .hljs-built_in,[data-theme='light'] .hljs-code,[data-theme='light'] .hljs-comment,[data-theme='light'] .hljs-formula,[data-theme='light'] .js-name,[data-theme='light'] .hljs-quote,[data-theme='light'] .hljs-selector-pseudo,[data-theme='light'] .hljs-selector-tag,[data-theme='light'] .hljs-subst,[data-theme='light'] .hljs-tag{color:#6a737d}
[data-theme='light'] .hljs-section{color:#005cc5;font-weight:700}
[data-theme='light'] .hljs-bullet{color:#735c0f}
[data-theme='light'] .hljs-emphasis{color:#24292e;font-style:italic}
[data-theme='light'] .hljs-strong{color:#24292e;font-weight:700}
[data-theme='light'] .hljs-addition{color:#22863a;background-color:#f0fff4}
[data-theme='light'] .hljs-deletion{color:#b31d28;background-color:#ffeef0}


/* --- 8. Scrollbar --- */
::-webkit-scrollbar {
    width: 12px;
}
::-webkit-scrollbar-track {
    background: var(--bg-primary);
}
::-webkit-scrollbar-thumb {
    background-color: var(--border-color);
    border-radius: 6px;
    border: 3px solid var(--bg-primary);
}
::-webkit-scrollbar-thumb:hover {
    background-color: var(--text-secondary);
}

/* --- 9. Custom Modal --- */
#modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    transition: opacity 0.2s;
}

#modal-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

#modal {
    background-color: var(--bg-primary);
    padding: 1.5rem 2rem;
    border-radius: 20px;
    width: 90%;
    max-width: 400px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.2);
    transform: scale(0.95);
    transition: transform 0.2s;
}

#modal-overlay:not(.hidden) #modal {
    transform: scale(1);
}

#modal-title {
    font-family: var(--font-header);
    font-size: 1.25rem;
    margin-bottom: 0.75rem;
    color: var(--text-primary);
}

#modal-message {
    font-size: 0.95rem;
    margin-bottom: 1rem;
    color: var(--text-secondary);
    line-height: 1.6;
}

#modal-input {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    background-color: var(--bg-secondary);
    color: var(--text-primary);
    border-radius: 12px;
    font-size: 1rem;
    margin-bottom: 1.5rem;
}

#modal-input:focus {
    outline: none;
    border-color: var(--accent-color);
    box-shadow: 0 0 0 2px var(--accent-color-translucent, rgba(59, 130, 246, 0.3));
}

#modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
}

#modal-actions button {
    font-family: var(--font-sans);
    font-weight: 500;
    padding: 0.6rem 1.2rem;
    border: none;
    border-radius: 20px;
    cursor: pointer;
    transition: background-color 0.2s, color 0.2s;
    font-size: 0.9rem;
}

#modal-cancel-btn {
    background-color: var(--bg-secondary);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
}

#modal-cancel-btn:hover {
    background-color: var(--border-color);
    color: var(--text-primary);
}

#modal-confirm-btn {
    background-color: var(--accent-color);
    color: white;
}
[data-theme='dark'] #modal-confirm-btn {
    color: var(--bg-primary);
}

#modal-confirm-btn:hover {
    background-color: var(--accent-hover);
}

/* --- 10. Dashboard Styles --- */
/* =============================================
   DASHBOARD — Redesigned 2026
   ============================================= */

.dashboard-container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 1.5rem 2rem 3rem;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* --- Nav Bar --- */
.dashboard-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0;
    margin-bottom: 2.5rem;
}

.dashboard-wordmark {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    text-decoration: none;
}

.dashboard-logo-mark {
    width: 36px;
    height: 36px;
    background-color: var(--accent-color);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 0.9rem;
    flex-shrink: 0;
}

[data-theme='dark'] .dashboard-logo-mark {
    color: var(--bg-primary);
}

.dashboard-logo-text {
    font-family: var(--font-header);
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.02em;
}

.dashboard-header .controls {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* --- Hero / Page Title --- */
.dashboard-hero {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.75rem;
    gap: 0.75rem;
}

.dashboard-title {
    font-family: var(--font-header);
    font-size: 1.75rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--text-primary);
}

.dashboard-doc-count {
    font-size: 0.875rem;
    color: var(--text-secondary);
    font-weight: 500;
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    padding: 0.2rem 0.65rem;
    border-radius: 999px;
    line-height: 1;
}

/* --- Documents Grid --- */
.documents-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 1.25rem;
    flex-grow: 1;
}

/* --- Document Card --- */
.document-card {
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
    position: relative;
}

.document-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 10px 28px oklch(0 0 0 / 0.08);
    border-color: var(--accent-color);
}

[data-theme='dark'] .document-card:hover {
    box-shadow: 0 10px 28px oklch(0 0 0 / 0.35);
}

/* Card inner link covers preview + body, not footer */
.document-card-inner {
    display: flex;
    flex-direction: column;
    text-decoration: none;
    color: inherit;
    flex-grow: 1;
}

/* Preview strip — accent-tinted with faint document lines */
.document-card-preview {
    height: 88px;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    flex-shrink: 0;
}

/* Accent color backgrounds per card */
.card-accent-blue   .document-card-preview { background-color: oklch(0.92 0.04 250); }
.card-accent-purple .document-card-preview { background-color: oklch(0.92 0.04 290); }
.card-accent-green  .document-card-preview { background-color: oklch(0.92 0.04 155); }
.card-accent-amber  .document-card-preview { background-color: oklch(0.93 0.06 85);  }
.card-accent-rose   .document-card-preview { background-color: oklch(0.92 0.04 15);  }
.card-accent-teal   .document-card-preview { background-color: oklch(0.92 0.04 195); }

[data-theme='dark'] .card-accent-blue   .document-card-preview { background-color: oklch(0.20 0.04 250); }
[data-theme='dark'] .card-accent-purple .document-card-preview { background-color: oklch(0.20 0.04 290); }
[data-theme='dark'] .card-accent-green  .document-card-preview { background-color: oklch(0.20 0.04 155); }
[data-theme='dark'] .card-accent-amber  .document-card-preview { background-color: oklch(0.20 0.05 85);  }
[data-theme='dark'] .card-accent-rose   .document-card-preview { background-color: oklch(0.20 0.04 15);  }
[data-theme='dark'] .card-accent-teal   .document-card-preview { background-color: oklch(0.20 0.04 195); }

/* Faint horizontal document lines */
.doc-preview-lines {
    display: flex;
    flex-direction: column;
    gap: 7px;
    width: 100px;
}

.doc-preview-lines span {
    display: block;
    height: 5px;
    border-radius: 3px;
    background-color: oklch(0 0 0 / 0.10);
}

[data-theme='dark'] .doc-preview-lines span {
    background-color: oklch(1 0 0 / 0.12);
}

.doc-preview-lines span.short {
    width: 60%;
}

/* MD Badge in corner */
.doc-preview-badge {
    position: absolute;
    top: 10px;
    right: 12px;
    font-family: var(--font-mono);
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    background-color: oklch(0 0 0 / 0.08);
    color: oklch(0 0 0 / 0.45);
    padding: 0.2rem 0.45rem;
    border-radius: 5px;
}

[data-theme='dark'] .doc-preview-badge {
    background-color: oklch(1 0 0 / 0.08);
    color: oklch(1 0 0 / 0.35);
}

/* Card body — title + preview text */
.document-card-body {
    padding: 1rem 1.1rem 0.75rem;
    flex-grow: 1;
}

.document-title {
    font-family: var(--font-header);
    font-size: 1rem;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0 0 0.35rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    letter-spacing: -0.01em;
}

.document-preview-text {
    font-size: 0.8rem;
    color: var(--text-secondary);
    line-height: 1.5;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    margin: 0;
}

/* Card footer — date + actions */
.document-card-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.55rem 0.85rem 0.65rem;
    border-top: 1px solid var(--border-color);
    gap: 0.5rem;
}

.document-date {
    font-size: 0.72rem;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 0.3rem;
    white-space: nowrap;
    flex-shrink: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
}

.document-date i {
    font-size: 0.68rem;
    opacity: 0.7;
    flex-shrink: 0;
}

.document-actions {
    display: flex;
    gap: 0.1rem;
    flex-shrink: 0;
    margin-left: auto;
}

.action-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 0.78rem;
    cursor: pointer;
    width: 30px;
    height: 30px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.15s, color 0.15s;
    opacity: 0.65;
    flex-shrink: 0;
    cursor: pointer;
    width: 30px;
    height: 30px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.15s, color 0.15s;
    opacity: 0.7;
}

.action-btn:hover {
    background-color: var(--border-color);
    color: var(--text-primary);
    opacity: 1;
}

.action-btn.delete-btn:hover {
    background-color: oklch(0.95 0.03 15);
    color: oklch(0.55 0.18 15);
}

[data-theme='dark'] .action-btn.delete-btn:hover {
    background-color: oklch(0.22 0.04 15);
    color: oklch(0.72 0.18 15);
}

/* CTA Button */
.cta-button {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    background-color: var(--accent-color);
    color: white;
    padding: 0 1.5rem;
    height: 44px;
    font-size: 0.95rem;
    font-weight: 600;
    text-decoration: none;
    border-radius: 30px;
    transition: background-color 0.15s, opacity 0.15s;
    white-space: nowrap;
    flex-shrink: 0;
    border: none;
    cursor: pointer;
    font-family: var(--font-sans);
}

.cta-button:hover {
    background-color: var(--accent-hover);
}

[data-theme='dark'] .cta-button {
    color: var(--bg-primary);
}

/* --- Empty State --- */
.no-documents-message {
    grid-column: 1 / -1;
    text-align: center;
    padding: 5rem 2rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
}

.no-docs-icon {
    width: 64px;
    height: 64px;
    border-radius: 18px;
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}

.no-documents-message h3 {
    font-family: var(--font-header);
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0;
}

.no-documents-message p {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin: 0;
}

.no-docs-cta {
    margin-top: 0.5rem;
    font-size: 0.9rem;
    padding: 0 1.25rem;
    height: 40px;
}

/* --- Dashboard Footer --- */
.dashboard-footer {
    text-align: center;
    margin-top: 3rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border-color);
    color: var(--text-secondary);
    font-size: 0.8rem;
}

/* --- Mobile --- */
@media (max-width: 600px) {
    .dashboard-container {
        padding: 1rem 1rem 2rem;
    }

    .dashboard-header {
        margin-bottom: 1.75rem;
    }

    /* Hero stays in one row on mobile — badge stays right */
    .dashboard-hero {
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
        margin-bottom: 1.25rem;
    }

    .dashboard-title {
        font-size: 1.4rem;
    }

    .documents-grid {
        grid-template-columns: 1fr 1fr;
        gap: 0.85rem;
    }

    .document-card-preview {
        height: 68px;
    }

    /* On narrow 2-col cards, hide the date — 3 action buttons need the full footer width */
    .document-date {
        display: none;
    }

    /* Give action buttons full footer width, center them */
    .document-actions {
        width: 100%;
        justify-content: center;
        gap: 0.25rem;
        margin-left: 0;
    }

    .action-btn {
        width: 32px;
        height: 32px;
        opacity: 0.75;
    }

    .cta-button-text {
        display: none;
    }

    .cta-button {
        width: 44px;
        height: 44px;
        padding: 0;
        justify-content: center;
        border-radius: 50%;
    }
}

@media (max-width: 380px) {
    .documents-grid {
        grid-template-columns: 1fr;
    }
}

/* --- 11. Find & Replace Panel --- */
#find-replace-panel {
    background-color: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    padding: 0.75rem 1.5rem;
    z-index: 10;
    transition: all 0.2s ease;
    transform: translateY(0);
    opacity: 1;
    height: auto;
}

#find-replace-panel.hidden {
    height: 0;
    padding-top: 0;
    padding-bottom: 0;
    overflow: hidden;
    border-bottom-width: 0;
    transform: translateY(-20px);
    opacity: 0;
    pointer-events: none;
}

.find-replace-container {
    display: flex;
    align-items: center;
    gap: 12px;
    max-width: 1200px;
    margin: 0 auto;
}

.find-replace-inputs {
    flex-grow: 1;
}

.input-group {
    display: flex;
    align-items: center;
    gap: 8px;
    background-color: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 0.25rem 0.75rem;
}

.input-group input {
    background: none;
    border: none;
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: 0.9rem;
    padding: 0.5rem;
    flex: 1;
}

.input-group input:focus {
    outline: none;
}

#find-counter {
    font-size: 0.8rem;
    color: var(--text-secondary);
    white-space: nowrap;
    min-width: 80px;
    text-align: right;
}

.find-replace-actions {
    display: flex;
    gap: 8px;
}

.pill-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background-color: var(--bg-primary);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 0.5rem 1rem;
    border-radius: 999px;
    font-family: var(--font-sans);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    white-space: nowrap;
}

.pill-btn:hover {
    background-color: var(--border-color);
}

.pill-btn i {
    font-size: 0.8rem;
}

#close-find-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0.5rem;
    font-size: 1.125rem;
    transition: var(--transition);
}

#close-find-btn:hover {
    color: var(--text-primary);
}

/* --- 12. Floating Toolbar --- */
.floating-toolbar {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 30px;
    box-shadow: var(--shadow-medium);
    display: flex;
    align-items: center;
    padding: 0.5rem;
    z-index: 100;
    transition: opacity 0.3s, transform 0.3s;
}

.floating-toolbar.hidden {
    opacity: 0;
    transform: translateX(-50%) translateY(150%);
    pointer-events: none;
}

.toolbar-drag-handle {
    cursor: move;
    color: var(--text-secondary);
    padding: 0 0.5rem;
}

.toolbar-actions {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

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

.toolbar-btn, .toolbar-close-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1rem;
    cursor: pointer;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.15s, color 0.15s, transform 0.1s;
}

.toolbar-btn:hover, .toolbar-close-btn:hover {
    background-color: var(--border-color);
    color: var(--text-primary);
}

.toolbar-btn:active, .toolbar-close-btn:active {
    transform: scale(0.9);
}

.toolbar-close-btn {
    margin-left: 0.5rem;
}

.show-toolbar-btn {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background-color: var(--accent-color);
    color: white;
    border: none;
    box-shadow: var(--shadow-medium);
    font-size: 1.25rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 99;
    transition: opacity 0.3s, transform 0.3s;
}

[data-theme='dark'] .show-toolbar-btn {
    color: var(--bg-primary);
}

.show-toolbar-btn:hover {
    background-color: var(--accent-hover);
}

.show-toolbar-btn.hidden {
    opacity: 0;
    transform: scale(0.8);
    pointer-events: none;
}

.is-dragging-toolbar {
    user-select: none;
}

@media (max-width: 768px) {
    #app-body {
        margin: 0 0.5rem;
        border-radius: 12px 12px 0 0;
    }
    #app-footer {
        margin: 0 0.5rem 0.5rem;
        border-radius: 0 0 12px 12px;
    }
    #app-header {
        padding: 0.5rem 0.75rem;
    }
    #app-title {
        font-size: 0.9rem;
    }

    .floating-toolbar {
        width: auto;
        max-width: calc(100vw - 20px);
        bottom: 10px;
        padding: 0.5rem 1rem;
        justify-content: flex-start;
        overflow: hidden;
    }

    .floating-toolbar.hidden {
        transform: translateX(-50%) translateY(150%);
    }

    .toolbar-actions {
        display: flex;
        overflow-x: auto;
        overflow-y: hidden;
        flex-wrap: nowrap;
        justify-content: flex-start;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        white-space: nowrap;
    }

    .toolbar-actions::-webkit-scrollbar {
        display: none;
    }

    .toolbar-actions > .toolbar-button,
    .toolbar-actions > button,
    .toolbar-actions > .icon-btn {
        flex: 0 0 auto;
        flex-shrink: 0;
        border-radius: 999px;
        min-width: 40px;
        min-height: 40px;
    }

    .toolbar-drag-handle {
        display: none;
    }
}

/* --- 13. AI Modal --- */
#ai-modal-overlay, #settings-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    transition: opacity 0.2s;
}

#ai-modal-overlay.hidden, #settings-modal-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

#ai-modal, #settings-modal {
    background-color: var(--bg-primary);
    border-radius: 20px;
    width: 90%;
    max-width: 600px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.2);
    transform: scale(0.95);
    transition: transform 0.2s;
    display: flex;
    flex-direction: column;
}

#ai-modal {
    height: 80vh;
    max-height: 700px;
}

#settings-modal {
    max-width: 400px;
}

#ai-modal-overlay:not(.hidden) #ai-modal, #settings-modal-overlay:not(.hidden) #settings-modal {
    transform: scale(1);
}

#ai-modal-header, #settings-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
}

#ai-modal-header h2, #settings-modal-header h2 {
    font-family: var(--font-header);
    font-size: 1.25rem;
    color: var(--text-primary);
}

#ai-modal-close-btn, #ai-new-chat-btn, #settings-modal-close-btn {
    background: none;
    border: none;
    font-size: 1.125rem;
    color: var(--text-secondary);
    cursor: pointer;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s, color 0.2s;
}

#ai-modal-close-btn:hover, #ai-new-chat-btn:hover, #settings-modal-close-btn:hover {
    background-color: var(--bg-secondary);
    color: var(--text-primary);
}

#ai-modal-body {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding: 1rem;
}

#ai-chat-container {
    flex-grow: 1;
    overflow-y: auto;
    padding: 0 1rem;
    margin-bottom: 1rem;
}

#ai-input-container {
    display: flex;
    gap: 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: 20px;
    padding: 0.5rem;
    align-items: center;
    transition: border-color 0.3s, box-shadow 0.3s;
}

#ai-input-container.streaming {
    animation: pulse-border 1.5s infinite;
}

@keyframes pulse-border {
    0% { border-color: var(--border-color); box-shadow: 0 0 0 0 oklch(0.75 0.12 250 / 0.2); }
    50% { border-color: var(--accent-color); box-shadow: 0 0 0 4px oklch(0.75 0.12 250 / 0.2); }
    100% { border-color: var(--border-color); box-shadow: 0 0 0 0 oklch(0.75 0.12 250 / 0.2); }
}

#ai-input {
    flex-grow: 1;
    border: none;
    background: none;
    resize: none;
    font-family: var(--font-sans);
    font-size: 1rem;
    color: var(--text-primary);
    height: 35px;
    padding: 0.5rem;
}

#ai-input:focus {
    outline: none;
}

#ai-button-wrapper {
    position: relative;
    width: 40px;
    height: 40px;
}

#ai-send-btn, #ai-stop-btn {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: var(--accent-color);
    color: white;
    border: none;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background-color 0.2s, opacity 0.2s, transform 0.2s;
}

[data-theme='dark'] #ai-send-btn, [data-theme='dark'] #ai-stop-btn {
    color: var(--bg-primary);
}

#ai-send-btn i, #ai-stop-btn i {
    font-size: 1rem;
}

#ai-send-btn:hover, #ai-stop-btn:hover {
    background-color: var(--accent-hover);
}

#ai-stop-btn {
    background-color: var(--error-color);
}

#settings-modal-body {
    padding: 1.5rem;
}

.settings-field {
    margin-bottom: 1rem;
}

.settings-field label {
    display: block;
    margin-bottom: 0.5rem;
    color: var(--text-secondary);
}

#api-key-input {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    background-color: var(--bg-secondary);
    color: var(--text-primary);
    border-radius: 12px;
    font-size: 1rem;
}

#settings-modal-actions {
    display: flex;
    justify-content: flex-end;
    margin-top: 1rem;
}

#settings-save-btn {
    background-color: var(--accent-color);
    color: white;
    border: none;
    border-radius: 20px;
    padding: 0.6rem 1.2rem;
    cursor: pointer;
}

.chat-message {
    padding: 0.75rem 1rem;
    border-radius: 1rem;
    margin-bottom: 0.5rem;
    max-width: 80%;
    line-height: 1.5;
}

.user-message {
    background-color: var(--accent-color);
    color: white;
    align-self: flex-end;
    margin-left: auto;
    width: auto;
    border-radius: 1.5rem;
    max-width: 70%;
}

.ai-message {
    background-color: transparent;
    color: var(--text-primary);
    align-self: flex-start;
    max-width: 90%;
}

.loading-spinner {
    border: 4px solid var(--border-color);
    border-top: 4px solid var(--accent-color);
    border-radius: 50%;
    width: 20px;
    height: 20px;
    animation: spin 1s linear infinite;
}

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

#ai-actions-template {
    display: flex;
    gap: 0.5rem;
    margin-top: 1rem;
    justify-content: flex-start;
}

.ai-action-btn {
    background: none;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    font-size: 1rem;
    cursor: pointer;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.15s, color 0.15s;
}

.ai-action-btn:hover {
    background-color: var(--border-color);
    color: var(--text-primary);
}

/* Markdown styling inside AI messages */
.ai-message h1, .ai-message h2, .ai-message h3,
.user-message h1, .user-message h2, .user-message h3 {
    font-family: var(--font-header);
    margin-top: 1em;
    margin-bottom: 0.5em;
}
.ai-message p, .user-message p { margin-bottom: 0.5em; }
.ai-message ul, .ai-message ol, .user-message ul, .user-message ol {
    margin-left: 1.5rem;
    margin-bottom: 0.5em;
}
.ai-message pre {
    background-color: var(--hljs-bg);
    padding: 0.75em;
    border-radius: 8px;
    overflow-x: auto;
    margin: 0.5em 0;
}
.ai-message code {
    font-family: var(--font-mono);
    background-color: var(--code-bg);
    color: var(--code-text);
    padding: 0.2em 0.4em;
    border-radius: 4px;
}

/* --- 14. Export Dropdown --- */
.export-dropdown {
    position: relative;
    display: flex;
    align-items: center;
}

/* Export pill group — two buttons forming a capsule */
#export-btn {
    border-radius: 999px 0 0 999px !important;
    border-right: none !important;
    background-color: var(--bg-secondary) !important;
    border: 1px solid var(--border-color) !important;
    width: 38px;
    height: 38px;
}

#export-dropdown-toggle {
    border-radius: 0 999px 999px 0 !important;
    background-color: var(--bg-secondary) !important;
    border: 1px solid var(--border-color) !important;
    border-left: none !important;
    width: 28px;
    height: 38px;
    padding: 0 0.5rem;
}

#export-menu {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    box-shadow: var(--shadow-medium);
    padding: 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 4px;
    z-index: 1000;
    min-width: 180px;
    transition: opacity 0.2s, transform 0.2s;
}

#export-menu.hidden {
    opacity: 0;
    transform: translateY(-10px);
    pointer-events: none;
}

#export-menu button {
    background: none;
    border: none;
    color: var(--text-primary);
    padding: 0.6rem 1rem;
    border-radius: 8px;
    cursor: pointer;
    text-align: left;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    transition: background-color 0.2s;
    white-space: nowrap;
}

#export-menu button:hover {
    background-color: var(--border-color);
}

#export-menu button i {
    color: var(--text-secondary);
    width: 16px;
    text-align: center;
}

/* --- 15. More Menu (Mobile) --- */
.more-menu-wrapper {
    position: relative;
    align-items: center;
}

#more-menu-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.1rem;
    cursor: pointer;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.15s, color 0.15s;
}

#more-menu-btn:hover {
    background-color: var(--bg-secondary);
    color: var(--text-primary);
}

.more-dropdown {
    position: fixed;
    /* top + left are set by JS — do not set them here */
    width: 210px;
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 14px;
    box-shadow: 0 8px 28px oklch(0 0 0 / 0.18), 0 2px 8px oklch(0 0 0 / 0.10);
    padding: 0.4rem;
    display: flex;
    flex-direction: column;
    gap: 2px;
    z-index: 9999;
    /* Animate in */
    opacity: 1;
    visibility: visible;
    transform: scale(1) translateY(0);
    transition: opacity 0.15s ease, transform 0.15s ease, visibility 0.15s;
    transform-origin: top right;
}

.more-dropdown.hidden {
    opacity: 0;
    visibility: hidden;
    transform: scale(0.93) translateY(-5px);
    pointer-events: none;
}

.more-dropdown button {
    background: none;
    border: none;
    color: var(--text-primary);
    padding: 0.6rem 0.85rem;
    border-radius: 9px;
    cursor: pointer;
    text-align: left;
    font-size: 0.9rem;
    font-family: var(--font-sans);
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    transition: background-color 0.12s;
    white-space: nowrap;
}

.more-dropdown button:hover {
    background-color: var(--border-color);
}

.more-dropdown button:active {
    background-color: var(--border-color);
    opacity: 0.85;
}

.more-dropdown button i {
    color: var(--text-secondary);
    width: 15px;
    text-align: center;
    font-size: 0.88rem;
    flex-shrink: 0;
}

.more-dropdown-divider {
    height: 1px;
    background-color: var(--border-color);
    margin: 0.25rem 0.5rem;
}

/* Print Styles */
@media print {
    body * {
        visibility: hidden;
    }
    #print-iframe-content, #print-iframe-content * {
        visibility: visible;
    }
    #print-iframe-content {
        position: absolute;
        left: 0;
        top: 0;
        width: 100%;
        background: white !important;
        color: black !important;
    }
}

/* --- 16. Toast Notifications --- */
#toast-container {
    position: fixed;
    bottom: 24px;
    left: 24px;
    display: flex;
    flex-direction: column-reverse;
    gap: 8px;
    z-index: 9999;
}

.toast {
    padding: 12px 20px;
    border-radius: 30px;
    background-color: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 0.9rem;
    font-weight: 500;
    box-shadow: var(--shadow-medium);
    border-left: 3px solid transparent;
    display: flex;
    align-items: center;
    gap: 10px;
    animation: toast-in 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
    cursor: pointer;
    max-width: 320px;
}

.toast.toast-success { border-left-color: oklch(0.65 0.12 150); }
.toast.toast-error { border-left-color: oklch(0.60 0.15 25); }
.toast.toast-info { border-left-color: var(--accent-color); }
.toast.toast-warning { border-left-color: var(--warning-color); }

.toast.fade-out {
    animation: toast-out 0.3s cubic-bezier(0.4, 0, 1, 1) forwards;
}

@keyframes toast-in {
    from { opacity: 0; transform: translateX(-20px) scale(0.9); }
    to { opacity: 1; transform: translateX(0) scale(1); }
}

@keyframes toast-out {
    from { opacity: 1; transform: translateX(0) scale(1); }
    to { opacity: 0; transform: translateX(-20px) scale(0.9); }
}

.user-message code {
    background-color: rgba(255, 255, 255, 0.1);
    padding: 0.2em 0.4em;
    border-radius: 4px;
}

/* --- Sidebar TOC --- */
#table-of-contents {
    padding: 1rem;
    overflow-y: auto;
}

.toc-link {
    display: block;
    padding: 0.5rem 1rem;
    color: var(--text-secondary);
    text-decoration: none;
    border-radius: 8px;
    font-size: 0.875rem;
    transition: background-color 0.2s, color 0.2s;
}

.toc-link:hover {
    background-color: var(--border-color);
    color: var(--text-primary);
}

.toc-level-2 { padding-left: 2rem; }
.toc-level-3 { padding-left: 3rem; }
.toc-level-4 { padding-left: 4rem; }
.toc-level-5 { padding-left: 5rem; }
.toc-level-6 { padding-left: 6rem; }

.no-outline {
    color: var(--text-secondary);
    font-size: 0.875rem;
    padding: 0.5rem;
}