/* Rune WebUI — Three-panel layout */
:root {
    --bg-primary: #1e1e2e;
    --bg-secondary: #181825;
    --bg-surface: #11111b;
    --text-primary: #cdd6f4;
    --text-secondary: #a6adc8;
    --text-muted: #6c7086;
    --accent: #89b4fa;
    --accent-dim: #313244;
    --border: #313244;
    --success: #a6e3a1;
    --warning: #f9e2af;
    --error: #f38ba8;
    --panel-width: 280px;
    --chat-input-height: 80px;
    --font-mono: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;
    --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

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

body {
    background: var(--bg-primary);
    color: var(--text-primary);
    font-family: var(--font-sans);
    height: 100vh;
    height: 100dvh; /* mobile: excludes browser chrome */
    overflow: hidden;
}

#app {
    display: flex;
    height: 100vh;
    height: 100dvh; /* mobile: excludes browser chrome */
    width: 100vw;
}

/* Panels */
.panel {
    display: flex;
    flex-direction: row;
    background: var(--bg-secondary);
    border-color: var(--border);
    transition: width 0.2s ease;
    position: relative;
}

.panel-left {
    display: flex;
    width: var(--panel-width);
    min-width: 160px;
    max-width: 520px;
    border-right: 1px solid var(--border);
    flex-shrink: 0;
    flex-direction: column;
}

.panel-left.fullscreen {
    width: 100%;
    max-width: none;
    border-right: none;
}

.panel-left.fullscreen .resize-handle {
    display: none;
}

.panel-right {
    width: var(--panel-width);
    min-width: 160px;
    max-width: 600px;
    border-left: 1px solid var(--border);
    flex-shrink: 0;
}

/* When center is hidden, chat fills all remaining space */
#panel-center.hidden ~ #panel-right {
    flex: 1 1 auto !important;
    max-width: none !important;
    width: auto !important;
}

.panel.collapsed {
    width: 20px !important;
    min-width: 20px !important;
}

.panel.collapsed .panel-content {
    display: none;
}

/* Resize + collapse combo handle */
.resize-handle {
    position: absolute;
    top: 0;
    width: 12px;
    height: 100%;
    cursor: col-resize;
    z-index: 10;
    background: transparent;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
    flex-shrink: 0;
}
.resize-handle:hover {
    background: rgba(137,180,250,0.08);
}
.resize-handle.dragging {
    background: rgba(137,180,250,0.15);
}
.panel-left  .resize-handle { right: 0; }
.panel-right .resize-handle { left: 0; }

/* Arrow icon inside the handle */
.resize-handle .toggle-icon {
    font-size: 10px;
    color: var(--text-muted);
    pointer-events: none;
    transition: color 0.15s, opacity 0.15s;
    opacity: 0;
    line-height: 1;
    user-select: none;
}
.resize-handle:hover .toggle-icon {
    opacity: 1;
    color: var(--accent);
}
/* Keep arrow visible when collapsed */
.panel.collapsed .resize-handle .toggle-icon {
    opacity: 1;
    color: var(--text-muted);
}
.panel.collapsed .resize-handle:hover .toggle-icon {
    color: var(--accent);
}
/* Collapsed: widen the hit area to be the full 20px strip */
.panel.collapsed .resize-handle {
    width: 20px;
    cursor: pointer;
}

/* Collapse toggle — smaller, pill shape */


.panel-content {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding: 12px;
}

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

/* Note list */
.note-list {
    flex: 1;
    overflow-y: auto;
}


.note-item:hover {
    background: var(--accent-dim);
}

.note-item.active {
    background: var(--accent-dim);
    color: var(--accent);
}

.note-dot {
    font-size: 8px;
    color: var(--success);
}

/* Center panel */
#panel-center {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}



.doc-title {
    font-family: var(--font-mono);
    font-size: 13px;
    color: var(--text-secondary);
}





/* Editor — textarea + highlight.js overlay */
#editor-container {
    flex: 1;
    min-height: 0;        /* allow flex child to shrink; critical for absolute children */
    overflow: hidden;
    position: relative;
}

/* ── Editor overlay: pixel-perfect alignment ── */

/* Reset both layers to identical box model */
#editor-highlight,
#editor {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    margin: 0;
    border: 0;
    padding: 20px 24px;
    box-sizing: border-box;

    font-family: var(--font-mono);
    font-size: 14px;
    line-height: 1.6;
    letter-spacing: normal;
    word-spacing: normal;

    tab-size: 4;
    -moz-tab-size: 4;
    white-space: pre-wrap;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

/* Highlight layer (bottom) */
#editor-highlight {
    overflow: hidden;           /* JS-driven scroll sync */
    background: var(--bg-primary);
    color: var(--text-primary);
    pointer-events: none;
    z-index: 0;
    /* Remove <pre> browser default styles */
    border-radius: 0;
}
#editor-highlight code {
    /* inherit everything from pre; add no extra spacing */
    display: block;
    font: inherit;
    letter-spacing: inherit;
    line-height: inherit;
    tab-size: inherit;
    white-space: inherit;
    word-wrap: inherit;
    overflow-wrap: inherit;
    background: transparent;
    padding: 0;
    margin: 0;
    border: 0;
    color: inherit;
}

/* Input layer (top) */
#editor {
    overflow: auto;
    background: transparent;
    color: transparent;
    caret-color: var(--text-primary);
    outline: none;
    resize: none;
    z-index: 1;
    -webkit-text-fill-color: transparent;
    /* Prevent textarea from adding its own border/outline on focus */
    appearance: none;
    -webkit-appearance: none;
}

/* Preview */
#preview-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    overflow-y: auto;
    padding: 20px 24px;
    box-sizing: border-box;
    width: 100%;
    min-width: 0;
}

#preview {
    font-size: 15px;
    line-height: 1.7;
    width: 100%;
    min-width: 0;
    box-sizing: border-box;
}

#preview h1, #preview h2, #preview h3 {
    color: var(--accent);
    margin: 1.2em 0 0.6em;
}

#preview h1 { font-size: 1.8em; }
#preview h2 { font-size: 1.4em; }
#preview h3 { font-size: 1.1em; }

#preview p { margin: 0.6em 0; }

#preview code {
    background: var(--bg-surface);
    padding: 2px 6px;
    border-radius: 3px;
    font-family: var(--font-mono);
    font-size: 0.9em;
}

#preview pre {
    background: var(--bg-surface);
    padding: 16px;
    border-radius: 6px;
    overflow-x: auto;
    margin: 1em 0;
}

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

#preview a { color: var(--accent); }
#preview blockquote {
    border-left: 3px solid var(--accent-dim);
    padding-left: 12px;
    color: var(--text-secondary);
}

.hidden { display: none !important; }

/* Chat */
.chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.status {
    font-size: 11px;
    font-family: var(--font-mono);
}

.status.idle { }
.status.thinking { animation: pulse 0.8s infinite; }
.status.typing { animation: pulse 0.5s infinite; }
.status.tool { animation: pulse 0.6s infinite; }

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

.chat-messages {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding-bottom: 8px;
}

.chat-msg {
    font-size: 13px;
    line-height: 1.5;
    padding: 8px 12px;
    border-radius: 8px;
    max-width: 100%;
    word-break: break-word;
}

.chat-msg.user {
    background: var(--accent-dim);
    border: 1px solid var(--border);
    align-self: flex-end;
}

.chat-msg.assistant {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    align-self: flex-start;
}

.chat-msg .sender {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.chat-input-area {
    display: flex;
    gap: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--border);
}

#chat-input {
    flex: 1;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: 13px;
    padding: 8px 12px;
    resize: none;
    outline: none;
    transition: border-color 0.15s;
}

#chat-input:focus {
    border-color: var(--accent);
}

#chat-send {
    background: var(--accent);
    border: none;
    color: var(--bg-primary);
    width: 36px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 16px;
    font-weight: bold;
    transition: opacity 0.15s;
}

#chat-send:hover { opacity: 0.8; }
#chat-send:active { transform: scale(0.95); }

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }
/* Phase 3 additions — append to style.css */

/* Spec updated flash */

@keyframes spec-flash {
    0% { background: var(--bg-surface); }
    20% { background: rgba(137, 180, 250, 0.15); }
    100% { background: var(--bg-surface); }
}

/* Code block copy button */
.copy-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 12px;
    padding: 2px 6px;
    opacity: 0;
    transition: opacity 0.2s;
    z-index: 2;
}

pre:hover .copy-btn,
pre.hljs-pre:hover .copy-btn {
    opacity: 1;
}

.copy-btn:hover {
    color: var(--accent);
    border-color: var(--accent);
    opacity: 1 !important;
}

/* Approval buttons */
.btn-approve {
    background: var(--success);
    color: #000;
    border: none;
    padding: 4px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
}

.btn-deny {
    background: var(--error);
    color: #000;
    border: none;
    padding: 4px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
}

.btn-approve:hover { opacity: 0.8; }
.btn-deny:hover { opacity: 0.8; }

/* Chat markdown rendering */
.chat-msg .body p {
    margin: 0.3em 0;
}

.chat-msg .body code {
    background: var(--bg-primary);
    padding: 1px 4px;
    border-radius: 3px;
    font-family: var(--font-mono);
    font-size: 0.85em;
}

.chat-msg .body pre {
    background: var(--bg-primary);
    padding: 8px 12px;
    border-radius: 4px;
    overflow-x: auto;
    margin: 0.5em 0;
    font-size: 0.85em;
}

.chat-msg .body pre code {
    background: none;
    padding: 0;
}

.chat-msg .body ul, .chat-msg .body ol {
    padding-left: 1.2em;
    margin: 0.3em 0;
}

.chat-msg .body blockquote {
    border-left: 2px solid var(--accent-dim);
    padding-left: 8px;
    color: var(--text-secondary);
    margin: 0.3em 0;
}

.chat-msg .body a {
    color: var(--accent);
}

.chat-msg .body table {
    border-collapse: collapse;
    margin: 0.5em 0;
    font-size: 0.9em;
}

.chat-msg .body th, .chat-msg .body td {
    border: 1px solid var(--border);
    padding: 4px 8px;
}

.chat-msg .body th {
    background: var(--bg-surface);
}

/* Disconnected status */
.status.disconnected {
    color: var(--error);
}

/* Preview table styling */
#preview table {
    border-collapse: collapse;
    margin: 1em 0;
    width: 100%;
}

#preview th, #preview td {
    border: 1px solid var(--border);
    padding: 8px 12px;
    text-align: left;
}

#preview th {
    background: var(--bg-surface);
    font-weight: 600;
}

#preview tr:hover {
    background: rgba(137, 180, 250, 0.05);
}

/* Preview list styling */
#preview ul, #preview ol {
    padding-left: 1.5em;
    margin: 0.6em 0;
}

#preview li {
    margin: 0.3em 0;
}

/* Preview horizontal rule */
#preview hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 1.5em 0;
}

/* --- Nickname Modal --- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.75);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}
.modal-overlay.hidden { display: none; }
#dir-browser-modal { z-index: 1100; }
.modal-box {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 36px 32px;
    width: 300px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    text-align: center;
}
.modal-title {
    font-size: 32px;
    color: var(--accent);
    letter-spacing: 3px;
}
.modal-subtitle {
    font-size: 13px;
    color: var(--text-muted);
}
.modal-box input {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 14px;
    padding: 10px 14px;
    text-align: center;
    outline: none;
    transition: border-color 0.15s;
}
.modal-box input:focus { border-color: var(--accent); }
.modal-box button {
    background: var(--accent);
    border: none;
    border-radius: 6px;
    color: var(--bg-primary);
    font-size: 14px;
    font-weight: 700;
    padding: 10px;
    cursor: pointer;
    transition: opacity 0.15s;
}
.modal-box button:hover { opacity: 0.85; }

/* Other user's chat bubble */
.chat-msg.other {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    align-self: flex-start;
}



/* --- highlight.js in Preview --- */
/* Override generic #preview pre with hljs-specific styles */
#preview pre.hljs-pre {
    background: #0d1117;   /* github-dark background */
    border-radius: 6px;
    padding: 0;
    margin: 1em 0;
    overflow: hidden;
}
#preview pre.hljs-pre code.hljs {
    display: block;
    padding: 16px;
    font-family: var(--font-mono);
    font-size: 13px;
    line-height: 1.6;
    overflow-x: auto;
    background: transparent; /* let pre background show */
    border-radius: 0;
}
/* chat bubble code blocks */
.chat-msg .body pre.hljs-pre {
    background: #0d1117;
    border-radius: 4px;
    margin: 0.5em 0;
    overflow: hidden;
}
.chat-msg .body pre.hljs-pre code.hljs {
    display: block;
    padding: 10px 14px;
    font-size: 12px;
    overflow-x: auto;
    background: transparent;
}


/* Fence opening/closing markers ```lang */
.cm-s-dracula .cm-formatting-code-block {
    color: #6272a4;
}

/* --- highlight.js Markdown token colors in editor --- */
/* These map to hljs class names emitted by highlight.js markdown grammar */
#editor-highlight .hljs-section,
#editor-highlight .hljs-title        { color: #ff79c6; font-weight: bold; } /* # headers */
#editor-highlight .hljs-bullet       { color: #ff79c6; }                    /* - * list */
#editor-highlight .hljs-strong       { color: #f8f8f2; font-weight: bold; } /* **bold** */
#editor-highlight .hljs-emphasis     { color: #f1fa8c; font-style: italic; }/* *italic* */
#editor-highlight .hljs-code         { color: #50fa7b; }                    /* `inline` */
#editor-highlight .hljs-link         { color: #8be9fd; }                    /* [text](url) */
#editor-highlight .hljs-string       { color: #f1fa8c; }                    /* "strings" */
#editor-highlight .hljs-quote        { color: #6272a4; font-style: italic; }/* > blockquote */
#editor-highlight .hljs-comment      { color: #6272a4; }
#editor-highlight .hljs-attr         { color: #50fa7b; }
#editor-highlight .hljs-keyword      { color: #ff79c6; }
#editor-highlight .hljs-number       { color: #bd93f9; }
#editor-highlight .hljs-literal      { color: #bd93f9; }
#editor-highlight .hljs-deletion     { color: #f38ba8; }                    /* diff - */
#editor-highlight .hljs-addition     { color: #a6e3a1; }                    /* diff + */

/* --- Editor: fenced code block background --- */
#editor-highlight .hljs-meta {
    color: #6272a4;   /* fence ticks + language label */
}

/* --- Mermaid diagrams --- */
.mermaid-block {
    margin: 16px 0;
    padding: 12px;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    overflow-x: auto;
    text-align: center;
}
.mermaid-block svg {
    max-width: 100%;
    height: auto;
}

/* --- Inline SVG in preview --- */
#preview svg {
    max-width: 100%;
    height: auto;
    display: block;
    margin: 8px 0;
}

/* --- Edit/Preview toggle layout --- */

/* Split view: editor + preview side by side */
#panel-center.split-view #editor-container,
#panel-center.split-view #preview-container {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Make center main a flex row when split */
#panel-center.split-view {
    flex-direction: row !important;
}
#panel-center.split-view #editor-container {
    border-right: 1px solid var(--border);
}

/* When both panels off: shrink center to nothing */
/* Both Edit+Preview off: shrink center to zero; chat fills remaining space */
#panel-center.hidden {
    flex: 0 0 0 !important;
    min-width: 0 !important;
    overflow: hidden !important;
    width: 0 !important;
    padding: 0 !important;
    border: none !important;
}

/* --- split-title bar (visible when editor or preview is shown) --- */
#split-title {
    display: none;
    height: 36px;
    min-height: 36px;
    flex-shrink: 0;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    padding: 0 12px;
    width: 100%;
}

.title-public-link {
    color: inherit;
    text-decoration: none;
}
.title-public-link:hover {
    text-decoration: underline;
}

/* --- split-body: contains editor + preview side-by-side --- */
#split-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}

/* --- center-body --- */
#center-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}
#center-body.split-view #split-body {
    flex-direction: row;
}
#center-body.split-view #editor-container {
    border-right: 1px solid var(--border);
    flex: 1;
    order: 1;
}
#center-body.split-view #preview-container {
    flex: 1;
    overflow-y: auto;
    order: 2;
}

/* --- Chat header with toggle buttons --- */
.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 4px;
}
.chat-header h3 {
    display: flex;
    align-items: center;
    gap: 4px;
    margin: 0;
    white-space: nowrap;
}
.chat-header-right {
    display: flex;
    align-items: center;
    gap: 4px;
}
.chat-header-right 
}

.chat-header-actions {
    display: flex;
    align-items: center;
    gap: 2px;
    margin-left: auto;
}

.chat-action-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 13px;
    padding: 3px 6px;
    border-radius: 4px;
    color: var(--text-muted);
    opacity: 0.7;
    transition: background 0.1s, opacity 0.1s;
}

.chat-action-btn:hover {
    background: var(--bg-hover, rgba(255,255,255,0.08));
    opacity: 1;
    color: var(--text-primary);
}
/* --- Multi-file markdown manager --- */
.doc-title-area {
    display: flex;
    align-items: center;
    gap: 6px;
    position: relative;
}

.file-add-btn {
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 14px;
    font-weight: bold;
    line-height: 1;
    padding: 1px 6px;
    transition: color 0.15s, border-color 0.15s;
}
.file-add-btn:hover {
    color: var(--accent);
    border-color: var(--accent);
}

.doc-title {
    cursor: pointer;
    font-weight: 600;
    color: var(--text-primary);
    padding: 1px 4px;
    border-radius: 3px;
    border: 1px solid transparent;
    min-width: 60px;
    outline: none;
}
.doc-title:hover {
    border-color: var(--border);
}
[contenteditable="true"].doc-title {
    border-color: var(--accent);
    background: var(--bg-surface);
}

.file-del-btn {
    background: transparent;
    border: 1px solid transparent;
    border-radius: 4px;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
    padding: 0px 5px;
    opacity: 0;
    transition: opacity 0.15s, color 0.15s;
}
.doc-title-area:hover .file-del-btn {
    opacity: 1;
}
.file-del-btn:hover {
    color: var(--error, #f38ba8);
    border-color: var(--error, #f38ba8);
}

/* --- Logout button --- */
.logout-btn {
    margin-left: 4px;
    font-size: 16px;
    opacity: 0.6;
    transition: opacity 0.15s, color 0.15s;
}
.logout-btn:hover {
    opacity: 1;
    color: var(--error, #f38ba8);
}

/* --- Modal actions row --- */
.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 20px;
}
.btn-primary {
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 6px;
    padding: 7px 18px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    transition: opacity 0.15s;
}
.btn-primary:hover { opacity: 0.85; }
.btn-secondary {
    background: transparent;
    color: var(--text-muted);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 7px 18px;
    cursor: pointer;
    font-size: 14px;
    transition: border-color 0.15s, color 0.15s;
}
.btn-secondary:hover {
    border-color: var(--text-primary);
    color: var(--text-primary);
}

/* --- Archive / Search --- */
.modal-wide {
    width: min(680px, 92vw);
}
.search-input-row {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
}
.search-input-row input {
    flex: 1;
    background: var(--bg-input, var(--bg-surface));
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 14px;
    padding: 7px 12px;
    outline: none;
}
.search-input-row input:focus {
    border-color: var(--accent);
}
.search-results {
    max-height: 380px;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 8px;
    margin-bottom: 8px;
    background: var(--bg-base, var(--bg));
}
.search-count {
    color: var(--text-muted);
    font-size: 12px;
    margin-bottom: 8px;
}
.search-empty, .search-loading {
    color: var(--text-muted);
    text-align: center;
    padding: 24px 0;
    font-size: 14px;
}
.search-item {
    border-bottom: 1px solid var(--border);
    padding: 8px 4px;
}
.search-item:last-child { border-bottom: none; }
.search-meta {
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 4px;
}
.search-time {
    font-size: 11px;
    opacity: 0.7;
    margin-left: 6px;
}
.search-content {
    font-size: 13px;
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-word;
}
.search-content mark {
    background: rgba(250, 219, 20, 0.35);
    color: inherit;
    border-radius: 2px;
    padding: 0 1px;
}

/* --- Title link --- */
.title-link {
    color: inherit;
    text-decoration: none;
}
.title-link:hover {
    opacity: 0.75;
    text-decoration: underline;
}

/* --- Status indicator inline in h3 title --- */
.chat-header h3 {
    display: flex;
    align-items: center;
    gap: 6px;
}
.chat-header h3 #status-indicator {
    font-size: 12px;
    font-weight: normal;
    opacity: 0.8;
    vertical-align: middle;
}

/* --- Model indicator (next to title) --- */
.model-indicator {
    display: flex;
    align-items: center;
    gap: 2px;
    margin-left: 8px;
}
.model-name {
    font-size: 11px;
    color: var(--text-muted, #888);
    max-width: 160px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* --- Model list in modal --- */
.model-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin: 12px 0;
    max-height: 300px;
    overflow-y: auto;
}
.model-option {
    padding: 8px 14px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg-surface);
    color: var(--text);
    cursor: pointer;
    text-align: left;
    font-size: 13px;
    transition: background 0.15s;
}
.model-option:hover {
    background: var(--bg-hover, #2a2a2a);
}
.model-option.active {
    border-color: var(--accent);
    color: var(--accent);
    font-weight: 600;
}

/* --- model-name clickable hover (admin) --- */
.model-name[style*="pointer"]:hover {
    color: var(--accent);
    text-decoration: underline;
}

/* --- Message metadata (model + tokens + time) --- */
.sender {
    display: flex;
    align-items: baseline;
    gap: 6px;
}


















/* ─── VSCode Explorer ─── */
.note-tree {
    flex: 1;
    overflow-y: auto;
    font-size: 13px;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    user-select: none;
}

.explorer-row {
    display: flex;
    align-items: center;
    padding: 2px 0;
    padding-right: 8px;
    cursor: pointer;
    border-radius: 3px;
    height: 22px;
    position: relative;
}

.explorer-row:hover {
    background: var(--bg-hover, rgba(255,255,255,0.05));
}

.explorer-row.active {
    background: var(--accent-dim, rgba(99,102,241,0.18));
}

.explorer-row .indent {
    flex-shrink: 0;
}

.explorer-row .chevron {
    width: 16px;
    height: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 10px;
    color: var(--text-muted);
    transition: transform 0.12s;
}

.explorer-row .chevron.open {
    transform: rotate(90deg);
}

.explorer-row .icon {
    width: 16px;
    height: 16px;
    margin-right: 4px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
}

.explorer-row .label {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 13px;
    color: var(--text-primary);
}

.explorer-row .actions {
    opacity: 0;
    display: flex;
    gap: 2px;
    margin-left: auto;
    flex-shrink: 0;
}

.explorer-row:hover .actions {
    opacity: 1;
}

.explorer-row .actions button {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 12px;
    padding: 0 3px;
    border-radius: 3px;
    color: var(--text-muted);
    line-height: 1;
}

.explorer-row .actions button:hover {
    background: rgba(255,255,255,0.1);
    color: var(--text-primary);
}

.explorer-section {
    margin-bottom: 2px;
}

.explorer-children {
    overflow: hidden;
}

.explorer-children.collapsed {
    display: none;
}

.explorer-empty {
    padding: 20px 12px;
    color: var(--text-muted);
    font-size: 12px;
    text-align: center;
}


/* ─── Explorer Action Bar ─── */
.explorer-actions {
    margin-top: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 2px;
    padding: 8px 6px;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

.explorer-action-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 14px;
    padding: 4px 8px;
    border-radius: 4px;
    color: var(--text-muted);
    transition: background 0.1s, color 0.1s;
    opacity: 0.7;
}

.explorer-action-btn:hover {
    background: var(--bg-hover, rgba(255,255,255,0.08));
    color: var(--text-primary);
    opacity: 1;
}

.explorer-action-btn.active {
    color: var(--accent, #6366f1);
    opacity: 1;
}

/* Dir browser */
.dir-browser-path-row {
    display: flex;
    gap: 6px;
    margin-bottom: 10px;
}

.dir-browser-path-row input {
    flex: 1;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 5px;
    color: var(--text-primary);
    font-family: var(--font-mono, monospace);
    font-size: 12px;
    padding: 6px 10px;
}

.dir-browser-list {
    max-height: 300px;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg-deep, #111);
}

.dir-entry {
    padding: 6px 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    transition: background 0.1s;
}

.dir-entry:hover {
    background: var(--bg-hover, rgba(255,255,255,0.05));
}

.dir-entry-icon {
    flex-shrink: 0;
}

.dir-entry-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Form groups for modals */
.form-group {
    margin-bottom: 12px;
}

.form-group label {
    display: block;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.form-group input[type="text"] {
    width: 100%;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 5px;
    color: var(--text-primary);
    font-size: 13px;
    padding: 8px 10px;
    box-sizing: border-box;
}

.path-input-row {
    display: flex;
    gap: 6px;
}

.path-input-row input {
    flex: 1;
}

.btn-danger {
    background: #dc3545;
    color: white;
    border: none;
    padding: 8px 14px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
}

.btn-danger:hover {
    background: #c82333;
}

.chat-body {
    position: relative;
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 0;
}

.context-overlay {
    position: absolute;
    bottom: 6px;
    right: 10px;
    z-index: 10;
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 3px 8px;
    border-radius: 10px;
    background: rgba(0, 0, 0, 0.45);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    border: 1px solid rgba(255,255,255,0.08);
    font-size: 10px;
    font-family: var(--font-mono, monospace);
    color: rgba(255,255,255,0.65);
    pointer-events: none;
    transition: opacity 0.3s;
    white-space: nowrap;
}

.context-overlay.hidden {
    display: none;
}

.context-overlay.warn {
    color: #f0c040;
    border-color: rgba(240,192,64,0.3);
}

.context-overlay.danger {
    color: #ff6b6b;
    border-color: rgba(255,107,107,0.3);
}

.context-sep {
    opacity: 0.5;
}

.msg-meta {
    font-size: 10px;
    color: var(--text-muted, #777);
    font-weight: normal;
    opacity: 0.75;
    white-space: nowrap;
}
.msg-time {
    margin-left: auto;
    font-size: 10px;
    color: var(--text-muted, #777);
    opacity: 0.6;
    white-space: nowrap;
    padding-left: 8px;
}

/* ─── Rainbow Title (admin only) ─── */
@keyframes rainbow-shift {
    0%   { color: #ff6b6b; }
    16%  { color: #ffa94d; }
    33%  { color: #ffd43b; }
    50%  { color: #69db7c; }
    66%  { color: #4dabf7; }
    83%  { color: #9775fa; }
    100% { color: #ff6b6b; }
}

.rune-char {
    display: inline-block;
    transition: color 0.3s;
}

.rune-title-rainbow .rune-char {
    animation: rainbow-shift 4s infinite ease-in-out;
}

.rune-title-rainbow .rune-char:nth-child(1) { animation-delay: 0s; }
.rune-title-rainbow .rune-char:nth-child(2) { animation-delay: -1s; }
.rune-title-rainbow .rune-char:nth-child(3) { animation-delay: -2s; }
.rune-title-rainbow .rune-char:nth-child(4) { animation-delay: -3s; }


/* ─── Search Copy Button ─── */
.search-copy-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 12px;
    padding: 1px 4px;
    margin-left: 8px;
    border-radius: 3px;
    opacity: 0.5;
    transition: opacity 0.15s, background 0.15s;
    vertical-align: middle;
}

.search-copy-btn:hover {
    opacity: 1;
    background: var(--bg-hover, rgba(255,255,255,0.08));
}

/* ─── Visibility Icons ─── */
.visibility-icon { cursor: pointer; opacity: 0.8; font-size: 12px; margin-left: auto; padding: 2px 4px; }
.visibility-icon:hover { opacity: 1; }
.visibility-icon.readonly { cursor: not-allowed; opacity: 0.4; }


/* Mobile editor (contenteditable) — hidden on desktop */
#mobile-editor { display: none; }

/* ═══════════════════════════════════════════════════════════════════════════
   MOBILE RESPONSIVE UI (≤ 768px)
   ═══════════════════════════════════════════════════════════════════════════ */

#mobile-header { display: none; }
.mobile-drawer { display: none; }
.mobile-section-header { display: none; }
/* Desktop: mobile section/body wrappers are transparent to flex layout,
   so #editor-container and #preview-container participate directly in #center-body.
   Chat section is hidden on desktop entirely. */
.mobile-section                     { display: contents; }
.mobile-section-body                { display: contents; }
#mobile-section-chat                { display: none; }

@media (max-width: 768px) {
    /* ─── Hide desktop panels ─── */
    .panel-left, .panel-right, .resize-handle { display: none !important; }

    /* ─── Hide desktop editor textarea + highlight overlay (replaced by #mobile-editor) ─── */
    #editor, #editor-highlight { display: none !important; }

    /* ─── Mobile header ─── */
    #mobile-header {
        display: flex;
        align-items: center;
        height: 44px;
        padding: 0 12px;
        background: var(--bg-surface);
        border-bottom: 1px solid var(--border);
        position: fixed;
        top: 0; left: 0; right: 0;
        z-index: 900;
        gap: 8px;
    }
    #mobile-drawer-btn {
        background: none; border: none;
        color: var(--text-primary); font-size: 22px;
        cursor: pointer; padding: 4px 8px; border-radius: 4px;
    }
    #mobile-drawer-btn:active { background: var(--accent-dim); }
    #mobile-rune-title {
        font-weight: 600; font-size: 14px;
        text-decoration: none; color: var(--accent);
        display: flex; gap: 1px;
    }
    .mobile-model-name {
        font-size: 11px; color: var(--text-muted);
        cursor: pointer;
        overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
        max-width: 120px; text-align: center;
    }
    .mobile-model-name:active { color: var(--accent); }
    .mobile-header-action {
        background: none; border: none;
        font-size: 16px; padding: 4px 8px;
        cursor: pointer; color: var(--text-muted);
        border-radius: 4px;
    }
    .mobile-header-action:active { background: var(--bg-tertiary); }
    /* Chat banner: flex row with left (toggle) + center (model) + right (actions) */
    .mobile-chat-banner {
        align-items: center;
        justify-content: space-between;
    }
    .mobile-chat-banner-left {
        display: flex; align-items: center; gap: 6px;
        cursor: pointer; flex: 1;
    }
    .mobile-chat-banner-center {
        display: flex; align-items: center; justify-content: center;
        flex: 1; cursor: pointer;
    }
    .mobile-chat-banner-right {
        display: flex; align-items: center; gap: 4px; flex: 1; justify-content: flex-end;
    }
    .mobile-chat-action {
        background: none; border: none;
        font-size: 14px; padding: 2px 6px;
        cursor: pointer; border-radius: 4px;
    }
    .mobile-chat-action:active { background: var(--bg-tertiary); }
    #mobile-filename {
        flex: 1;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 13px; color: var(--text-secondary);
        overflow: hidden; white-space: nowrap;
        min-width: 0;
    }
    #mobile-filename a.title-public-link {
        color: inherit;
        text-decoration: none;
        flex-shrink: 1;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        min-width: 0;
    }
    #mobile-filename a.title-public-link:hover { text-decoration: underline; }
    #mobile-filename span { flex-shrink: 0; }
    #mobile-status { font-size: 10px; }

    /* ─── App vertical layout ─── */
    #app { flex-direction: column; padding-top: 44px; height: var(--mobile-vh, 100dvh); }
    #panel-center, #panel-center.hidden { flex: 1 !important; display: flex !important; flex-direction: column; overflow: hidden; width: auto !important; min-width: auto !important; height: auto !important; padding: 0 !important; }
    #center-body { flex: 1; display: flex !important; flex-direction: column; overflow: hidden; }
    #center-body.split-view #split-body { flex-direction: column !important; }
    #split-title { display: none !important; }
    #split-body { flex: 1; min-height: 0; overflow: hidden; }

    /* ─── Accordion sections ─── */
    .mobile-section,
    #mobile-section-chat {
        display: flex; flex-direction: column;
        overflow: hidden;
        border-bottom: 1px solid var(--border);
        flex: 0 0 36px; /* collapsed: just the header */
    }
    .mobile-section.expanded,
    #mobile-section-chat.expanded {
        flex: 1 1 0; /* expanded: share remaining space equally */
        min-height: 80px;
    }

    .mobile-section-header {
        display: flex;
        align-items: center;
        height: 36px; min-height: 36px;
        padding: 0 12px;
        background: var(--bg-secondary);
        cursor: pointer;
        font-size: 13px; font-weight: 500;
        color: var(--text-secondary);
        gap: 6px; user-select: none; flex-shrink: 0;
    }
    .mobile-section-header:active { background: var(--accent-dim); }
    .mobile-section-chevron { font-size: 10px; transition: transform 0.15s; }
    .mobile-section:not(.expanded) .mobile-section-chevron { transform: rotate(-90deg); }

    .mobile-section-body {
        flex: 1; overflow-y: auto;
        display: flex; flex-direction: column;
    }
    .mobile-section:not(.expanded) .mobile-section-body { display: none; }

    /* Preview in mobile */
    #mobile-section-preview.expanded #preview-container, #mobile-section-preview.expanded #preview-container.hidden {
        display: block !important;
        flex: 1; overflow-y: auto; padding: 12px;
    }
    #mobile-section-preview.expanded #preview-container #preview { max-width: 100%; }

    /* Editor in mobile: contenteditable with highlight.js */
    #mobile-section-editor.expanded #editor-container, #mobile-section-editor.expanded #editor-container.hidden {
        flex: 1; display: flex !important; flex-direction: column;
        position: relative; overflow: hidden;
    }
    #mobile-section-editor.expanded #editor-highlight { display: none !important; }
    #mobile-section-editor.expanded #editor { display: none !important; }
    #mobile-section-editor.expanded #mobile-editor {
        display: block !important;
        flex: 1;
        min-height: 80px;
        font-family: var(--font-mono);
        font-size: 14px;
        line-height: 1.6;
        padding: 12px;
        background: var(--bg-primary);
        color: var(--text-primary);
        caret-color: var(--accent);
        overflow-y: auto;
        white-space: pre-wrap;
        word-wrap: break-word;
        overflow-wrap: break-word;
        outline: none;
        tab-size: 4;
        -moz-tab-size: 4;
        -webkit-user-modify: read-write-plaintext-only;
    }
    #mobile-section-editor.expanded #mobile-editor:empty::before {
        content: "Start typing...";
        color: var(--text-muted);
        font-style: italic;
    }

    /* Chat in mobile — input always visible at bottom */
    #mobile-section-chat .mobile-section-body {
        display: flex; flex-direction: column;
        overflow: hidden !important;
    }
    #mobile-section-chat.expanded .mobile-section-body { display: flex; }
    #mobile-section-chat .chat-messages {
        flex: 1 1 0;
        min-height: 0;
        overflow-y: auto;
        padding: 8px;
    }
    #mobile-section-chat .chat-input-area {
        display: flex;
        flex-shrink: 0;
        padding: 8px;
        border-top: 1px solid var(--border);
        background: var(--bg-secondary);
        gap: 6px;
        align-items: stretch;
    }
    #mobile-section-chat .chat-input-area textarea {
        flex: 1; resize: none; font-size: 14px; padding: 8px;
        border-radius: 6px; border: 1px solid var(--border);
        background: var(--bg-primary); color: var(--text-primary);
        min-height: 36px; max-height: 80px;
        font-family: var(--font-sans);
        align-self: stretch;
    }
    #mobile-section-chat .chat-input-area button {
        padding: 0 14px; background: var(--accent); color: var(--bg-primary);
        border: none; border-radius: 6px; font-size: 16px; cursor: pointer;
        flex-shrink: 0; min-height: 36px; align-self: stretch;
    }

    /* ─── Notes Drawer ─── */
    .mobile-drawer.hidden { display: none !important; }
    .mobile-drawer:not(.hidden) {
        display: flex;
        position: fixed; inset: 0; z-index: 1000;
        background: var(--bg-primary);
        flex-direction: column;
    }
    .mobile-drawer-header {
        display: flex; align-items: center; justify-content: space-between;
        height: 52px; padding: 0 16px;
        border-bottom: 1px solid var(--border);
        background: var(--bg-surface);
    }
    .mobile-drawer-title { font-size: 18px; font-weight: 600; color: var(--text-primary); }
    .mobile-drawer-header button {
        background: none; border: none; color: var(--text-secondary);
        font-size: 24px; cursor: pointer; padding: 4px 10px; border-radius: 4px;
    }
    .mobile-drawer-header button:active { background: var(--accent-dim); }
    .mobile-drawer-body { flex: 1; overflow-y: auto; padding: 8px 0; }
    .mobile-drawer-actions {
        padding: 12px 16px; border-top: 1px solid var(--border);
    }
    .mobile-drawer-actions button {
        width: 100%; padding: 12px; background: var(--accent-dim);
        color: var(--text-primary); border: 1px solid var(--border);
        border-radius: 8px; font-size: 15px; cursor: pointer;
    }
    .mobile-drawer-actions button:active { background: var(--accent); color: var(--bg-primary); }

    /* ─── Drawer note tree (mobile-optimized) ─── */
    .mobile-note-section { margin-bottom: 2px; }
    .mobile-note-header {
        display: flex; align-items: center; gap: 10px;
        padding: 12px 16px; cursor: pointer;
        font-size: 15px; font-weight: 500; color: var(--text-primary);
        border-radius: 6px; margin: 0 8px;
    }
    .mobile-note-header:active, .mobile-note-header.active { background: var(--accent-dim); }
    .mobile-note-icon { font-size: 18px; }
    .mobile-note-name { flex: 1; }
    .mobile-file-row {
        display: flex; align-items: center; gap: 10px;
        padding: 10px 16px 10px 44px; cursor: pointer;
        font-size: 14px; color: var(--text-secondary);
        border-radius: 6px; margin: 0 8px;
    }
    .mobile-file-row:active, .mobile-file-row.active {
        background: var(--accent-dim); color: var(--text-primary);
    }
    .mobile-file-icon { font-size: 14px; }
    .mobile-file-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}
