/* ========================================
   MD2PDF - Complete Stylesheet
   ======================================== */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
    background: #0d1117;
    color: #c9d1d9;
}

/* ========================================
   Sidebar
   ======================================== */

.sidebar {
    width: 260px;
    height: 100vh;
    background: #0d1117;
    border-right: 1px solid #30363d;
    display: flex;
    flex-direction: column;
    position: fixed;
    left: 0;
    top: 0;
    z-index: 100;
    transition: width 0.25s ease, transform 0.25s ease;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    height: 56px;
    padding: 0 16px;
    font-size: 14px;
    font-weight: 600;
    color: #c9d1d9;
    border-bottom: 1px solid #30363d;
    flex-shrink: 0;
}

.sidebar-brand svg {
    width: 20px;
    height: 20px;
    fill: #c9d1d9;
    flex-shrink: 0;
}

.sidebar-collapse-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    background: none;
    border: none;
    border-radius: 4px;
    color: #8b949e;
    cursor: pointer;
    margin-left: auto;
    flex-shrink: 0;
    transition: background 0.15s, color 0.15s;
}

.sidebar-collapse-btn:hover {
    background: #21262d;
    color: #c9d1d9;
}

.sidebar-collapse-btn svg {
    width: 16px;
    height: 16px;
    transition: transform 0.25s;
}

.sidebar.collapsed .sidebar-collapse-btn svg {
    transform: rotate(180deg);
}

.sidebar-new-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 12px 12px 8px;
    padding: 10px 12px;
    background: #21262d;
    border: 1px solid #30363d;
    border-radius: 6px;
    color: #c9d1d9;
    font-size: 14px;
    cursor: pointer;
    overflow: hidden;
    white-space: nowrap;
    transition: background 0.2s;
}

.sidebar-new-btn:hover {
    background: #30363d;
}

.sidebar-new-btn svg {
    width: 16px;
    height: 16px;
    fill: #c9d1d9;
}

/* Search Button */
.sidebar-search-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0 12px 8px;
    padding: 7px 12px;
    background: #21262d;
    border: 1px solid #30363d;
    border-radius: 6px;
    color: #8b949e;
    font-size: 13px;
    font-family: inherit;
    cursor: pointer;
    width: calc(100% - 24px);
    text-align: left;
    overflow: hidden;
    white-space: nowrap;
    transition: background 0.15s, border-color 0.15s;
}

.sidebar-search-btn:hover {
    background: #30363d;
    border-color: #484f58;
}

.sidebar-search-btn .sidebar-search-icon {
    width: 14px;
    height: 14px;
    fill: #8b949e;
    flex-shrink: 0;
}

.sidebar-search-label {
    flex: 1;
    color: #484f58;
}

.sidebar-search-kbd {
    font-size: 11px;
    padding: 1px 5px;
    background: #0d1117;
    border: 1px solid #30363d;
    border-radius: 4px;
    color: #8b949e;
    font-family: inherit;
    line-height: 1.4;
    flex-shrink: 0;
}

/* Document List */
.sidebar-docs {
    flex: 1;
    overflow-y: auto;
    padding: 4px 0;
}

.sidebar-doc {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px 8px 16px;
    cursor: pointer;
    transition: background 0.15s;
    position: relative;
}

.sidebar-doc:hover {
    background: #161b22;
}

.sidebar-doc.active {
    background: #1c2128;
}

.sidebar-doc.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 4px;
    bottom: 4px;
    width: 3px;
    background: #238636;
    border-radius: 0 3px 3px 0;
}

.sidebar-doc-name {
    flex: 1;
    font-size: 13px;
    color: #c9d1d9;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}

.sidebar-doc-menu {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    background: none;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    color: #8b949e;
    flex-shrink: 0;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s;
}

.sidebar-doc:hover .sidebar-doc-menu,
.sidebar-doc-menu.show {
    opacity: 1;
    pointer-events: auto;
}

.sidebar-doc-menu:hover {
    background: #30363d;
    color: #c9d1d9;
}

.sidebar-doc-menu svg {
    width: 16px;
    height: 16px;
    fill: currentColor;
}

/* Rename Input */
.sidebar-doc-rename {
    flex: 1;
    background: #0d1117;
    border: 1px solid #238636;
    border-radius: 4px;
    padding: 2px 6px;
    color: #c9d1d9;
    font-size: 13px;
    font-family: inherit;
    outline: none;
    min-width: 0;
}

/* Dropdown Menu */
.sidebar-dropdown {
    display: none;
    position: absolute;
    background: #161b22;
    border: 1px solid #30363d;
    border-radius: 8px;
    padding: 4px;
    min-width: 160px;
    z-index: 200;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

.sidebar-dropdown.show {
    display: block;
}

.sidebar-dropdown button {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 8px 12px;
    background: none;
    border: none;
    border-radius: 4px;
    color: #c9d1d9;
    font-size: 13px;
    cursor: pointer;
    text-align: left;
}

.sidebar-dropdown button:hover {
    background: #21262d;
}

.sidebar-dropdown button svg {
    width: 16px;
    height: 16px;
    fill: currentColor;
    flex-shrink: 0;
}

.sidebar-dropdown button.danger {
    color: #f85149;
}

.sidebar-dropdown button.danger:hover {
    background: rgba(248, 81, 73, 0.1);
}

.sidebar-dropdown hr {
    border: none;
    border-top: 1px solid #30363d;
    margin: 4px 0;
}

/* Profile Panel */
.sidebar-profile-wrap {
    position: relative;
    flex-shrink: 0;
    margin-top: auto;
}

.sidebar-profile {
    border-top: 1px solid #30363d;
    padding: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    overflow: hidden;
    transition: background 0.15s;
}

.sidebar-profile:hover {
    background: #161b22;
}

.sidebar-profile-chevron {
    width: 14px;
    height: 14px;
    color: #8b949e;
    flex-shrink: 0;
    transition: transform 0.2s, color 0.15s;
}

.sidebar-profile:hover .sidebar-profile-chevron {
    color: #c9d1d9;
}

.sidebar-profile.menu-open .sidebar-profile-chevron {
    transform: rotate(180deg);
}

.sidebar-profile-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.sidebar-profile-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: #238636;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 600;
    flex-shrink: 0;
}

.sidebar-profile-name {
    font-size: 13px;
    color: #c9d1d9;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Profile Menu (expands upward from wrap) */
.sidebar-profile-menu {
    display: none;
    padding: 4px 8px;
    background: #161b22;
    border-bottom: 1px solid #30363d;
}

.sidebar-profile-menu.show {
    display: block;
}

.sidebar-profile-menu button {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 8px 12px;
    background: none;
    border: none;
    border-radius: 4px;
    color: #c9d1d9;
    font-size: 13px;
    cursor: pointer;
    text-align: left;
}

.sidebar-profile-menu button:hover {
    background: #21262d;
}

.sidebar-profile-menu button svg {
    width: 16px;
    height: 16px;
    fill: currentColor;
    flex-shrink: 0;
}

/* ========================================
   App Layout (sidebar + main)
   ======================================== */

.app-layout {
    display: flex;
    height: 100vh;
}

.app-main {
    flex: 1;
    margin-left: 260px;
    display: flex;
    flex-direction: column;
    height: 100vh;
    min-width: 0;
    transition: margin-left 0.25s ease;
}

/* ========================================
   Header / Topnav
   ======================================== */

.header {
    display: flex;
    align-items: center;
    padding: 12px 20px;
    background: #161b22;
    border-bottom: 1px solid #30363d;
    height: 56px;
    gap: 12px;
}

.sidebar-toggle {
    display: none;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: none;
    border: 1px solid #30363d;
    border-radius: 6px;
    color: #c9d1d9;
    cursor: pointer;
    flex-shrink: 0;
}

.sidebar-toggle:hover {
    background: #21262d;
}

.sidebar-toggle svg {
    width: 20px;
    height: 20px;
    fill: currentColor;
}

.header-doc-name {
    flex: 1;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 6px;
    padding: 6px 10px;
    color: #c9d1d9;
    font-size: 15px;
    font-weight: 500;
    font-family: inherit;
    outline: none;
    min-width: 0;
    transition: border-color 0.2s, background 0.2s;
}

.header-doc-name:hover {
    border-color: #30363d;
    background: #0d1117;
}

.header-doc-name:focus {
    border-color: #238636;
    background: #0d1117;
}

/* View Mode Toggle */
.view-mode-toggle {
    display: flex;
    background: #21262d;
    border: 1px solid #30363d;
    border-radius: 6px;
    overflow: hidden;
    flex-shrink: 0;
}

.view-mode-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 30px;
    background: none;
    border: none;
    color: #8b949e;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

.view-mode-btn:hover {
    background: #30363d;
    color: #c9d1d9;
}

.view-mode-btn.active {
    background: #30363d;
    color: #e6edf3;
}

.view-mode-btn svg {
    width: 16px;
    height: 16px;
    fill: currentColor;
}

.header-actions {
    display: flex;
    gap: 10px;
    flex-shrink: 0;
}

.btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s, opacity 0.2s;
}

.btn:hover {
    opacity: 0.9;
}

.btn-primary {
    background: #238636;
    color: #ffffff;
}

.btn-primary:hover {
    background: #2ea043;
}

.btn-secondary {
    background: #21262d;
    color: #c9d1d9;
    border: 1px solid #30363d;
}

.btn-secondary:hover {
    background: #30363d;
}

.btn svg {
    width: 16px;
    height: 16px;
    fill: currentColor;
}

/* Shortcut tooltip for header buttons */
.header-actions .btn[data-shortcut] {
    position: relative;
}

.header-actions .btn[data-shortcut]::after {
    content: attr(data-shortcut);
    position: absolute;
    top: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    background: #1c2128;
    border: 1px solid #30363d;
    color: #e6edf3;
    padding: 4px 8px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 500;
    white-space: nowrap;
    z-index: 300;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.15s;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

.header-actions .btn[data-shortcut]:hover::after {
    opacity: 1;
}

/* ========================================
   Editor + Preview Container
   ======================================== */

.container {
    display: flex;
    flex: 1;
    min-height: 0;
}

/* Split Handle (drag to resize) */
.split-handle {
    width: 5px;
    cursor: col-resize;
    background: #30363d;
    flex-shrink: 0;
    transition: background 0.15s;
    position: relative;
}

.split-handle:hover,
.split-handle.dragging {
    background: #238636;
}

.split-handle::after {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    left: -4px;
    right: -4px;
}

/* View Mode Classes */
.container.view-editor .preview-pane,
.container.view-editor .split-handle {
    display: none;
}

.container.view-editor .editor-pane {
    border-right: none;
}

.container.view-preview .editor-pane,
.container.view-preview .split-handle {
    display: none;
}

/* Editor Pane */
.editor-pane {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: #0d1117;
    min-width: 0;
}

.pane-header {
    padding: 10px 16px;
    background: #161b22;
    border-bottom: 1px solid #30363d;
    font-size: 12px;
    font-weight: 500;
    color: #8b949e;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.editor-wrapper {
    flex: 1;
    position: relative;
    overflow: hidden;
}

#editor {
    width: 100%;
    height: 100%;
    padding: 16px;
    background: #0d1117;
    border: none;
    outline: none;
    resize: none;
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    font-size: 14px;
    line-height: 1.6;
    color: #c9d1d9;
    tab-size: 4;
}

#editor::placeholder {
    color: #484f58;
}

/* Preview Pane */
.preview-pane {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: #ffffff;
    min-width: 0;
}

.preview-pane .pane-header {
    background: #f6f8fa;
    color: #57606a;
    border-bottom: 1px solid #d0d7de;
}

.preview-wrapper {
    flex: 1;
    overflow: auto;
    padding: 24px 32px;
}

#preview {
    max-width: 900px;
    margin: 0 auto;
    color: #24292f;
    font-size: 16px;
    line-height: 1.6;
}

/* ========================================
   GitHub Markdown Styles (Preview)
   ======================================== */

#preview h1, #preview h2, #preview h3,
#preview h4, #preview h5, #preview h6 {
    margin-top: 24px;
    margin-bottom: 16px;
    font-weight: 600;
    line-height: 1.25;
    color: #24292f;
}

#preview h1 {
    font-size: 2em;
    padding-bottom: 0.3em;
    border-bottom: 1px solid #d0d7de;
}

#preview h2 {
    font-size: 1.5em;
    padding-bottom: 0.3em;
    border-bottom: 1px solid #d0d7de;
}

#preview h3 { font-size: 1.25em; }
#preview h4 { font-size: 1em; }
#preview h5 { font-size: 0.875em; }
#preview h6 { font-size: 0.85em; color: #57606a; }

#preview p {
    margin-top: 0;
    margin-bottom: 16px;
}

#preview a {
    color: #0969da;
    text-decoration: none;
}

#preview a:hover {
    text-decoration: underline;
}

#preview strong { font-weight: 600; }
#preview em { font-style: italic; }
#preview del { text-decoration: line-through; }

#preview ul, #preview ol {
    margin-top: 0;
    margin-bottom: 16px;
    padding-left: 2em;
}

#preview li { margin-top: 4px; }
#preview li + li { margin-top: 4px; }

#preview ul ul, #preview ul ol,
#preview ol ul, #preview ol ol {
    margin-top: 0;
    margin-bottom: 0;
}

/* Task Lists */
#preview ul.contains-task-list {
    list-style: none;
    padding-left: 0;
}

#preview .task-list-item {
    list-style: none;
    padding-left: 28px;
    position: relative;
}

#preview .task-list-item input[type="checkbox"] {
    -webkit-appearance: none;
    appearance: none;
    position: absolute;
    left: 0;
    top: 3px;
    margin: 0;
    width: 16px;
    height: 16px;
    border: 2px solid #d0d7de;
    border-radius: 4px;
    background: #fff;
    cursor: default;
    transition: background 0.15s, border-color 0.15s;
}

#preview .task-list-item input[type="checkbox"]:checked {
    background: #238636;
    border-color: #238636;
}

#preview .task-list-item input[type="checkbox"]:checked::after {
    content: '';
    position: absolute;
    left: 3px;
    top: 0px;
    width: 4px;
    height: 9px;
    border: solid #fff;
    border-width: 0 2px 2px 0;
    transform: rotate(35deg);
}

#preview .task-list-item p {
    margin-bottom: 0;
}

/* Blockquotes */
#preview blockquote {
    margin: 0 0 16px 0;
    padding: 0 16px;
    color: #57606a;
    border-left: 4px solid #d0d7de;
}

#preview blockquote > :first-child { margin-top: 0; }
#preview blockquote > :last-child { margin-bottom: 0; }

/* Code */
#preview code {
    font-family: 'JetBrains Mono', 'Fira Code', ui-monospace, monospace;
    font-size: 85%;
    padding: 0.2em 0.4em;
    margin: 0;
    background: rgba(175, 184, 193, 0.2);
    border-radius: 6px;
}

#preview pre {
    margin-top: 0;
    margin-bottom: 16px;
    padding: 16px;
    overflow: auto;
    font-size: 85%;
    line-height: 1.45;
    background: #0d1117;
    border-radius: 6px;
}

#preview pre code {
    display: block;
    padding: 0;
    margin: 0;
    background: transparent;
    border-radius: 0;
    font-size: 100%;
    color: #c9d1d9;
    overflow-x: auto;
}

/* Tables */
#preview table {
    border-collapse: collapse;
    border-spacing: 0;
    width: 100%;
    margin-top: 0;
    margin-bottom: 16px;
    overflow: auto;
}

#preview table th, #preview table td {
    padding: 6px 13px;
    border: 1px solid #d0d7de;
}

#preview table th {
    font-weight: 600;
    background: #f6f8fa;
}

#preview table tr {
    background: #ffffff;
    border-top: 1px solid #d0d7de;
}

#preview table tr:nth-child(2n) {
    background: #f6f8fa;
}

/* Horizontal Rule */
#preview hr {
    height: 0.25em;
    padding: 0;
    margin: 24px 0;
    background: #d0d7de;
    border: 0;
}

/* Images */
#preview img {
    max-width: 100%;
    height: auto;
    border-radius: 6px;
}

/* ========================================
   Custom Extensions
   ======================================== */

/* Alerts - GitHub Style */
#preview .alert {
    padding: 12px 16px;
    margin-bottom: 16px;
    border-radius: 6px;
    border-left: 4px solid;
}

#preview .alert-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
    margin-bottom: 4px;
}

#preview .alert-note { background: #ddf4ff; border-color: #218bff; }
#preview .alert-note .alert-title { color: #0969da; }
#preview .alert-tip { background: #dafbe1; border-color: #2da44e; }
#preview .alert-tip .alert-title { color: #1a7f37; }
#preview .alert-important { background: #e8d5ff; border-color: #8250df; }
#preview .alert-important .alert-title { color: #8250df; }
#preview .alert-warning { background: #fff8c5; border-color: #bf8700; }
#preview .alert-warning .alert-title { color: #9a6700; }
#preview .alert-caution { background: #ffebe9; border-color: #cf222e; }
#preview .alert-caution .alert-title { color: #cf222e; }

/* Highlight / Mark */
#preview mark {
    background: #fff8c5;
    padding: 0.1em 0.3em;
    border-radius: 3px;
    color: #24292f;
}

/* Badge */
#preview .badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 500;
    line-height: 1.5;
}

#preview .badge-green { background: #dafbe1; color: #1a7f37; }
#preview .badge-red { background: #ffebe9; color: #cf222e; }
#preview .badge-blue { background: #ddf4ff; color: #0969da; }
#preview .badge-yellow { background: #fff8c5; color: #9a6700; }
#preview .badge-purple { background: #e8d5ff; color: #8250df; }
#preview .badge-gray { background: #eaeef2; color: #57606a; }

/* Page Break */
#preview .page-break {
    page-break-after: always;
    break-after: page;
    height: 0;
    margin: 0;
    border: none;
}

@media screen {
    #preview .page-break {
        border-top: 2px dashed #d0d7de;
        margin: 24px 0;
        position: relative;
        height: 0;
    }

    #preview .page-break::after {
        content: 'PAGE BREAK';
        position: absolute;
        top: -10px;
        left: 50%;
        transform: translateX(-50%);
        background: #ffffff;
        padding: 0 12px;
        color: #8b949e;
        font-size: 11px;
        letter-spacing: 1px;
    }
}

/* Footnotes */
#preview .footnotes {
    margin-top: 32px;
    font-size: 14px;
    color: #57606a;
}

#preview .footnotes hr { margin-bottom: 16px; }
#preview .footnotes ol { padding-left: 24px; }

#preview .footnote-ref a {
    color: #0969da;
    text-decoration: none;
    font-size: 12px;
}

#preview .footnote-backref {
    text-decoration: none;
    margin-left: 4px;
}

/* TOC */
#preview .toc {
    background: #f6f8fa;
    border: 1px solid #d0d7de;
    border-radius: 6px;
    padding: 16px 24px;
    margin-bottom: 24px;
}

#preview .toc-title {
    font-weight: 600;
    margin-bottom: 8px;
    color: #24292f;
}

#preview .toc ul {
    list-style: none;
    padding-left: 0;
    margin: 0;
}

#preview .toc ul ul { padding-left: 20px; }
#preview .toc li { margin-top: 4px; }

#preview .toc a {
    color: #0969da;
    text-decoration: none;
}

#preview .toc a:hover { text-decoration: underline; }

/* Headerless Table */
#preview table.no-header thead { display: none; }

/* Mermaid */
#preview .mermaid {
    text-align: center;
    margin-bottom: 16px;
}

/* Date Stamp */
#preview .date-stamp {
    font-style: italic;
    color: #57606a;
}

/* KaTeX Block */
#preview .math-block {
    text-align: center;
    margin: 16px 0;
    overflow-x: auto;
}

/* ========================================
   Editor Toolbar
   ======================================== */

.editor-toolbar {
    display: flex;
    align-items: center;
    gap: 2px;
    padding: 6px 10px;
    background: #161b22;
    border-bottom: 1px solid #30363d;
    overflow-x: auto;
    flex-shrink: 0;
    flex-wrap: wrap;
}

.editor-toolbar::-webkit-scrollbar {
    height: 0;
}

.editor-toolbar > button,
.editor-toolbar .toolbar-dropdown-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 2px;
    min-width: 30px;
    height: 30px;
    padding: 0 6px;
    background: none;
    border: none;
    border-radius: 4px;
    color: #8b949e;
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
    font-family: inherit;
    white-space: nowrap;
    transition: background 0.15s, color 0.15s;
}

.editor-toolbar > button:hover,
.editor-toolbar .toolbar-dropdown-toggle:hover {
    background: #21262d;
    color: #c9d1d9;
}

.editor-toolbar > button:active,
.editor-toolbar .toolbar-dropdown-toggle:active {
    background: #30363d;
}

.editor-toolbar > button svg,
.editor-toolbar .toolbar-dropdown-toggle svg {
    width: 16px;
    height: 16px;
    fill: currentColor;
    flex-shrink: 0;
}

.editor-toolbar .toolbar-caret {
    width: 10px;
    height: 10px;
}

.toolbar-sep {
    width: 1px;
    height: 20px;
    background: #30363d;
    margin: 0 4px;
    flex-shrink: 0;
}

/* Toolbar Dropdown */
.toolbar-dropdown {
    position: relative;
    display: flex;
}

.toolbar-dropdown-menu {
    display: none;
    position: fixed;
    background: #161b22;
    border: 1px solid #30363d;
    border-radius: 8px;
    padding: 4px;
    min-width: 140px;
    z-index: 500;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

.toolbar-dropdown-menu.show {
    display: block;
}

.toolbar-dropdown-menu button {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 7px 12px;
    background: none;
    border: none;
    border-radius: 4px;
    color: #c9d1d9;
    font-size: 13px;
    cursor: pointer;
    text-align: left;
    font-family: inherit;
}

.toolbar-dropdown-menu button:hover {
    background: #21262d;
}

/* Table Grid Picker */
.toolbar-table-menu {
    min-width: 200px;
    padding: 8px;
}

.table-grid {
    display: grid;
    grid-template-columns: repeat(10, 18px);
    grid-template-rows: repeat(10, 18px);
    gap: 2px;
    margin-bottom: 6px;
}

.table-grid-cell {
    width: 18px;
    height: 18px;
    border: 1px solid #30363d;
    border-radius: 2px;
    cursor: pointer;
    transition: background 0.1s, border-color 0.1s;
}

.table-grid-cell.active {
    background: rgba(35, 134, 54, 0.3);
    border-color: #238636;
}

.table-grid-cell:hover {
    border-color: #8b949e;
}

.table-grid-label {
    text-align: center;
    font-size: 12px;
    color: #8b949e;
    margin-bottom: 4px;
}

.toolbar-table-menu hr {
    border: none;
    border-top: 1px solid #30363d;
    margin: 6px 0;
}

.toolbar-date-fmt {
    font-family: 'JetBrains Mono', monospace;
    font-size: 12px;
}

.toolbar-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

/* Heading Dropdown */
.toolbar-heading-menu {
    min-width: 180px;
}

.toolbar-heading-preview {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
    font-weight: 600;
    color: #c9d1d9;
}

.h1-preview { font-size: 17px; }
.h2-preview { font-size: 15px; }
.h3-preview { font-size: 14px; }
.h4-preview { font-size: 13px; }
.h5-preview { font-size: 12px; }
.h6-preview { font-size: 11px; color: #8b949e; }

/* ========================================
   Drag & Drop Overlay
   ======================================== */

.drag-overlay {
    display: none;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(35, 134, 54, 0.1);
    border: 2px dashed #238636;
    border-radius: 6px;
    z-index: 10;
    pointer-events: none;
    align-items: center;
    justify-content: center;
}

.drag-overlay.active {
    display: flex;
}

.drag-overlay-text {
    padding: 16px 24px;
    background: #238636;
    color: white;
    border-radius: 6px;
    font-weight: 500;
}

/* ========================================
   Modal Overlay (Archive / Settings)
   ======================================== */

.modal-backdrop {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 300;
    align-items: center;
    justify-content: center;
}

.modal-backdrop.show {
    display: flex;
}

.modal-panel {
    background: #161b22;
    border: 1px solid #30363d;
    border-radius: 12px;
    width: 90%;
    max-width: 520px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.4);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid #30363d;
}

.modal-header h2 {
    font-size: 16px;
    font-weight: 600;
    color: #c9d1d9;
}

.modal-close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    background: none;
    border: none;
    border-radius: 6px;
    color: #8b949e;
    cursor: pointer;
    font-size: 18px;
}

.modal-close:hover {
    background: #21262d;
    color: #c9d1d9;
}

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

.modal-empty {
    text-align: center;
    color: #8b949e;
    padding: 32px 0;
    font-size: 14px;
}

/* Archive List Item */
.archive-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    border-radius: 6px;
    margin-bottom: 4px;
}

.archive-item:hover {
    background: #21262d;
}

.archive-item-name {
    flex: 1;
    font-size: 14px;
    color: #c9d1d9;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}

.archive-item-actions {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
    margin-left: 12px;
}

.archive-item-actions button {
    padding: 4px 10px;
    border-radius: 4px;
    border: 1px solid #30363d;
    background: #21262d;
    color: #c9d1d9;
    font-size: 12px;
    cursor: pointer;
}

.archive-item-actions button:hover {
    background: #30363d;
}

.archive-item-actions button.danger {
    color: #f85149;
    border-color: rgba(248, 81, 73, 0.3);
}

.archive-item-actions button.danger:hover {
    background: rgba(248, 81, 73, 0.15);
}

/* Settings Form */
.settings-field {
    margin-bottom: 16px;
}

.settings-field label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: #8b949e;
    margin-bottom: 6px;
}

.settings-field input {
    width: 100%;
    padding: 8px 12px;
    background: #0d1117;
    border: 1px solid #30363d;
    border-radius: 6px;
    color: #c9d1d9;
    font-size: 14px;
    font-family: inherit;
    outline: none;
}

.settings-field input:focus,
.settings-field select:focus {
    border-color: #238636;
}

.settings-field select {
    width: 100%;
    padding: 8px 12px;
    background: #0d1117;
    border: 1px solid #30363d;
    border-radius: 6px;
    color: #c9d1d9;
    font-size: 14px;
    font-family: inherit;
    outline: none;
    cursor: pointer;
}

.settings-hint {
    display: block;
    margin-top: 4px;
    font-size: 12px;
    color: #8b949e;
}

.settings-save {
    padding: 8px 16px;
    background: #238636;
    color: #fff;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
}

.settings-save:hover {
    background: #2ea043;
}

/* ========================================
   Search Modal (Command Palette)
   ======================================== */

.search-modal-backdrop {
    align-items: flex-start;
    padding-top: 12vh;
}

.search-modal {
    background: #161b22;
    border: 1px solid #30363d;
    border-radius: 12px;
    width: 90%;
    max-width: 560px;
    max-height: 60vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.5);
    overflow: hidden;
}

.search-modal-input-wrap {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    border-bottom: 1px solid #30363d;
}

.search-modal-icon {
    width: 18px;
    height: 18px;
    fill: #8b949e;
    flex-shrink: 0;
}

.search-modal-input {
    flex: 1;
    background: none;
    border: none;
    outline: none;
    color: #e6edf3;
    font-size: 15px;
    font-family: inherit;
}

.search-modal-input::placeholder {
    color: #484f58;
}

.search-modal-esc {
    font-size: 11px;
    padding: 2px 6px;
    background: #21262d;
    border: 1px solid #30363d;
    border-radius: 4px;
    color: #8b949e;
    font-family: inherit;
    line-height: 1.4;
    flex-shrink: 0;
}

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

.search-modal-section-title {
    font-size: 11px;
    font-weight: 600;
    color: #8b949e;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 8px 8px 4px;
}

.search-modal-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.1s;
}

.search-modal-item:hover,
.search-modal-item.active {
    background: #21262d;
}

.search-modal-item-icon {
    width: 16px;
    height: 16px;
    fill: #8b949e;
    flex-shrink: 0;
}

.search-modal-item-body {
    flex: 1;
    min-width: 0;
}

.search-modal-item-title {
    font-size: 13px;
    color: #c9d1d9;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.search-modal-item-title mark {
    background: rgba(210, 153, 34, 0.35);
    color: #e6edf3;
    padding: 0 1px;
    border-radius: 2px;
}

.search-modal-item-snippet {
    font-size: 12px;
    color: #8b949e;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 2px;
}

.search-modal-item-snippet mark {
    background: rgba(210, 153, 34, 0.25);
    color: #c9d1d9;
    padding: 0 1px;
    border-radius: 2px;
}

.search-modal-item-remove {
    display: none;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    background: none;
    border: none;
    border-radius: 4px;
    color: #8b949e;
    cursor: pointer;
    flex-shrink: 0;
    font-size: 14px;
}

.search-modal-item:hover .search-modal-item-remove {
    display: flex;
}

.search-modal-item-remove:hover {
    background: #30363d;
    color: #f85149;
}

.search-modal-empty {
    text-align: center;
    color: #8b949e;
    padding: 24px 0;
    font-size: 13px;
}

/* ========================================
   Sidebar Overlay (mobile)
   ======================================== */

.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 99;
}

.sidebar-overlay.show {
    display: block;
}

/* ========================================
   Scrollbar Styles
   ======================================== */

::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

.editor-pane ::-webkit-scrollbar-thumb,
.sidebar ::-webkit-scrollbar-thumb,
.sidebar-docs ::-webkit-scrollbar-thumb {
    background: #30363d;
    border-radius: 4px;
}

.preview-pane ::-webkit-scrollbar-thumb {
    background: #d0d7de;
    border-radius: 4px;
}

/* ========================================
   Print Styles for PDF
   ======================================== */

@media print {
    .header, .editor-pane, .pane-header, .sidebar, .sidebar-overlay {
        display: none !important;
    }

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

    .container {
        display: block;
    }

    .preview-pane {
        position: static;
        height: auto;
    }

    .preview-wrapper {
        padding: 0;
    }
}

/* ========================================
   Collapsed Sidebar
   ======================================== */

.sidebar.collapsed {
    width: 56px;
}

.sidebar.collapsed ~ .app-main {
    margin-left: 56px;
}

/* Hide all text labels */
.sidebar.collapsed .sidebar-label {
    display: none;
}

/* Brand collapsed - just icon centered */
.sidebar.collapsed .sidebar-brand {
    justify-content: center;
    gap: 0;
    padding: 0;
    cursor: pointer;
}

.sidebar.collapsed .sidebar-collapse-btn {
    display: none;
}

/* New button collapsed - icon only */
.sidebar.collapsed .sidebar-new-btn {
    justify-content: center;
    margin: 8px auto;
    width: 36px;
    height: 36px;
    padding: 0;
    overflow: visible;
}

/* Search button collapsed - icon only */
.sidebar.collapsed .sidebar-search-btn {
    margin: 0 auto 8px;
    width: 36px;
    height: 36px;
    padding: 0;
    justify-content: center;
    overflow: visible;
}

.sidebar.collapsed .sidebar-search-btn .sidebar-search-icon {
    width: 16px;
    height: 16px;
}

/* Document list hidden */
.sidebar.collapsed .sidebar-docs {
    display: none;
}

/* Profile collapsed - avatar only */
.sidebar.collapsed .sidebar-profile {
    justify-content: center;
    padding: 10px;
}

.sidebar.collapsed .sidebar-profile-name,
.sidebar.collapsed .sidebar-profile-chevron {
    display: none;
}

.sidebar.collapsed .sidebar-profile-wrap {
    margin-top: auto;
}

/* Dropdown menus hidden in collapsed */
.sidebar.collapsed .sidebar-dropdown {
    display: none !important;
}

.sidebar.collapsed .sidebar-profile-menu {
    display: none !important;
}

/* Tooltip popovers (collapsed only) */
.sidebar.collapsed [data-tooltip] {
    position: relative;
}

.sidebar.collapsed [data-tooltip]:hover::after {
    content: attr(data-tooltip);
    position: absolute;
    left: calc(100% + 12px);
    top: 50%;
    transform: translateY(-50%);
    background: #1c2128;
    border: 1px solid #30363d;
    color: #e6edf3;
    padding: 6px 10px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 400;
    white-space: nowrap;
    z-index: 300;
    pointer-events: none;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

.sidebar.collapsed [data-tooltip]:hover::before {
    content: '';
    position: absolute;
    left: calc(100% + 6px);
    top: 50%;
    transform: translateY(-50%);
    border: 4px solid transparent;
    border-right-color: #30363d;
    z-index: 301;
    pointer-events: none;
}

/* ========================================
   Responsive - Mobile (<800px)
   ======================================== */

@media (max-width: 800px) {
    .sidebar {
        transform: translateX(-100%);
    }

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

    .sidebar.collapsed {
        width: 260px;
    }

    .app-main {
        margin-left: 0;
    }

    .sidebar-toggle {
        display: flex;
    }

    .sidebar-collapse-btn {
        display: none;
    }

    .container {
        flex-direction: column;
    }

    .split-handle {
        display: none;
    }

    .view-mode-toggle {
        display: none;
    }

    .editor-pane, .preview-pane {
        flex: none;
        height: 50%;
    }

    .editor-pane {
        border-right: none;
        border-bottom: 1px solid #30363d;
    }

    .header-doc-name {
        font-size: 14px;
    }

    .btn span {
        display: none;
    }

    .btn {
        padding: 8px 10px;
    }
}
