/* Rune WebUI — Three-panel layout */
:root {
    color-scheme: light dark;
    --bg-primary: #1e1e2e;
    --bg-secondary: #181825;
    --bg-surface: #11111b;
    --bg-hover: #2a2a2a;
    --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;
    --drawer-width: min(310px, 84vw);
    --chat-width-medium: clamp(240px, 30vw, 320px);
    --chat-height-stacked: clamp(200px, 34vh, 420px);
    --compact-bar-h: 48px;
    --compact-switch-h: 52px;
    --scrim: rgba(0, 0, 0, 0.55);
    --overlay-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
    --font-mono: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;
    --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

@media (prefers-color-scheme: light) {
    :root {
        --bg-primary: #f6f8fa;
        --bg-secondary: #ffffff;
        --bg-surface: #eaeef2;
        --bg-hover: #dde1e5;
        --text-primary: #24292e;
        --text-secondary: #57606a;
        --text-muted: #8c959f;
        --accent: #0969da;
        --accent-dim: #ddf4ff;
        --border: #d0d7de;
        --success: #1a7f37;
        --warning: #9a6700;
        --error: #cf222e;
        --scrim: rgba(20, 24, 30, 0.42);
        --overlay-shadow: 0 12px 32px rgba(31, 35, 40, 0.18);
    }
}

* {
    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.resizing {
    transition: none;
}

.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;
    /* Without this the column-stacked tier sizes the centre to the document's
       full height and pushes the chat dock past the bottom of the viewport. */
    min-height: 0;
}



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





#editor-container {
    flex: 1;
    min-height: 0;
    min-width: 0;
    overflow: hidden;
    position: relative;
    display: flex;
    flex-direction: column;
}
.editor-toolbar {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    overflow: hidden;
    white-space: nowrap;
    user-select: none;
}
.editor-toolbar button {
    background: transparent;
    border: 0;
    color: var(--text-primary);
    padding: 4px 8px;
    border-radius: 4px;
    cursor: pointer;
    font-family: inherit;
    font-size: 13px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, color 0.15s;
}
.editor-toolbar button:hover {
    background: var(--border);
}
.toolbar-separator {
    color: var(--border);
    margin: 0 4px;
    user-select: none;
}

/* Toolbar overflow ("priority+"): actions that do not fit move into the menu. */
.toolbar-overflow-btn {
    position: absolute;
    top: 4px;
    right: 8px;
    z-index: 3;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-secondary);
    cursor: pointer;
    font-family: inherit;
    font-size: 14px;
    line-height: 1;
    height: 26px;
    padding: 0 9px;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.toolbar-overflow-btn:hover,
.toolbar-overflow-btn[aria-expanded="true"] {
    color: var(--accent);
    border-color: var(--accent);
}

.toolbar-overflow-menu {
    position: absolute;
    top: 38px;
    right: 8px;
    z-index: 40;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 2px;
    min-width: 156px;
    padding: 6px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: var(--overlay-shadow);
}
.toolbar-overflow-menu button {
    background: transparent;
    border: 0;
    border-radius: 5px;
    color: var(--text-primary);
    cursor: pointer;
    font-family: inherit;
    font-size: 13px;
    padding: 7px 10px;
    text-align: left;
    justify-content: flex-start;
    display: flex;
    align-items: center;
    transition: background 0.15s;
}
.toolbar-overflow-menu button:hover {
    background: var(--bg-hover);
}
.toolbar-overflow-menu .toolbar-separator {
    display: none;
}
#editor-wrapper {
    flex: 1;
    position: relative;
    min-height: 0;
}
.CodeMirror {
    height: 100% !important;
    font-family: var(--font-mono);
    font-size: 14px;
    line-height: 1.6;
    background: var(--bg-primary) !important;
    color: var(--text-primary) !important;
}
.CodeMirror-gutters {
    background: var(--bg-secondary) !important;
    border-right: 1px solid var(--border) !important;
}
.CodeMirror-linenumber {
    color: var(--text-secondary) !important;
    opacity: 0.5;
}
.CodeMirror-cursor {
    border-left: 2px solid var(--accent) !important;
}
.CodeMirror-selected {
    background: var(--border) !important;
}

/* Preview */
#preview-container {
    position: relative;
    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;
    padding-top: 8px;
    border-top: 1px solid var(--border);
    position: relative;
    align-items: flex-end;
}

.chat-input-resizer {
    position: absolute;
    top: -4px;
    left: 0;
    right: 0;
    height: 8px;
    cursor: row-resize;
    z-index: 10;
    user-select: none;
}

.chat-input-resizer:hover,
.chat-input-resizer.dragging {
    background: var(--accent);
    opacity: 0.35;
    border-radius: 2px;
}

#chat-input {
    width: 100%;
    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;
    line-height: 1.5;
    padding: 8px 38px 8px 12px;
    height: 56px;
    min-height: 56px;
    max-height: min(400px, 60vh);
    resize: none;
    outline: none;
    transition: border-color 0.15s;
}

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

#chat-send {
    position: absolute;
    bottom: 6px;
    right: 6px;
    background: var(--accent);
    border: none;
    color: var(--bg-primary);
    width: 28px;
    height: 28px;
    border-radius: 5px;
    cursor: pointer;
    font-size: 14px;
    font-weight: bold;
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 5;
    transition: opacity 0.15s, transform 0.1s;
}

#chat-input:not(:placeholder-shown) ~ #chat-send {
    display: flex;
}

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

#chat-send .rune-icon,
#chat-send svg {
    width: 14px;
    height: 14px;
}

#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;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

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 {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 28px;
    width: min(440px, 90vw);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
    display: flex;
    flex-direction: column;
    gap: 16px;
    color: var(--text-primary);
}

.modal h2 {
    font-size: 20px;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
    display: flex;
    align-items: center;
    gap: 8px;
}

.modal p {
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.5;
    margin: 0;
}

.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 (dark mode default) */
    border-radius: 6px;
    padding: 0;
    margin: 1em 0;
    overflow: hidden;
    position: relative;
}
#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;
    position: relative;
}
.chat-msg .body pre.hljs-pre code.hljs {
    display: block;
    padding: 10px 14px;
    font-size: 12px;
    overflow-x: auto;
    background: transparent;
}
/* Light mode: use github-light code block background */
@media (prefers-color-scheme: light) {
    /* Code block: noticeably darker than white container (#fff),
       creates depth: page(#f6f8fa) > card(#fff) > code(#e8ecf0) */
    #preview pre.hljs-pre {
        background: #e8ecf0;
        border: 1px solid #d0d7de;
    }
    .chat-msg .body pre.hljs-pre {
        background: #e8ecf0;
        border: 1px solid #d0d7de;
    }
    /* Also override .hljs background set by github.min.css */
    #preview pre.hljs-pre code.hljs,
    .chat-msg .body pre.hljs-pre code.hljs {
        background: transparent;
    }
}


/* ============================================================
   CodeMirror Themes: rune-dark (GitHub Dark) & rune-light (GitHub Light)
   Token colors match the highlight.js themes used in Preview.
   ============================================================ */

/* --- rune-dark: GitHub Dark palette --- */
.cm-s-rune-dark.CodeMirror {
    background: #0d1117;
    color: #c9d1d9;
}
.cm-s-rune-dark .CodeMirror-gutters {
    background: #161b22;
    border-right: 1px solid #30363d;
}
.cm-s-rune-dark .CodeMirror-linenumber  { color: #484f58; }
.cm-s-rune-dark .CodeMirror-cursor      { border-left: 2px solid #58a6ff; }
.cm-s-rune-dark .CodeMirror-selected,
.cm-s-rune-dark .CodeMirror-focused .CodeMirror-selected { background: #2d3f5e; }
/* Markdown structure */
.cm-s-rune-dark .cm-header     { color: #79c0ff; font-weight: bold; }
.cm-s-rune-dark .cm-strong     { font-weight: bold; }
.cm-s-rune-dark .cm-em         { font-style: italic; }
.cm-s-rune-dark .cm-link       { color: #a5d6ff; text-decoration: underline; }
.cm-s-rune-dark .cm-url        { color: #8b949e; }
.cm-s-rune-dark .cm-hr         { color: #30363d; }
.cm-s-rune-dark .cm-quote      { color: #8b949e; font-style: italic; }
/* Code tokens */
.cm-s-rune-dark .cm-keyword    { color: #ff7b72; }   /* keyword        → red    */
.cm-s-rune-dark .cm-def        { color: #d2a8ff; }   /* function def   → purple */
.cm-s-rune-dark .cm-builtin    { color: #ffa657; }   /* built-in       → orange */
.cm-s-rune-dark .cm-string     { color: #a5d6ff; }   /* string         → blue   */
.cm-s-rune-dark .cm-string-2   { color: #a5d6ff; }   /* regexp/tmpl    → blue   */
.cm-s-rune-dark .cm-number     { color: #79c0ff; }   /* number         → blue   */
.cm-s-rune-dark .cm-atom       { color: #79c0ff; }   /* atom/const     → blue   */
.cm-s-rune-dark .cm-variable   { color: #c9d1d9; }   /* variable       → text   */
.cm-s-rune-dark .cm-variable-2 { color: #79c0ff; }   /* variable-2     → blue   */
.cm-s-rune-dark .cm-variable-3,
.cm-s-rune-dark .cm-type       { color: #ffa657; }   /* type           → orange */
.cm-s-rune-dark .cm-comment    { color: #8b949e; }   /* comment        → grey   */
.cm-s-rune-dark .cm-tag        { color: #7ee787; }   /* HTML tag       → green  */
.cm-s-rune-dark .cm-attribute  { color: #79c0ff; }   /* HTML attr      → blue   */
.cm-s-rune-dark .cm-qualifier  { color: #79c0ff; }   /* CSS class/id   → blue   */
.cm-s-rune-dark .cm-meta       { color: #8b949e; }   /* meta           → grey   */
.cm-s-rune-dark .cm-bracket    { color: #c9d1d9; }   /* bracket        → text   */
.cm-s-rune-dark .cm-operator   { color: #79c0ff; }   /* operator       → blue   */
.cm-s-rune-dark .cm-property   { color: #79c0ff; }   /* property key   → blue   */
.cm-s-rune-dark .cm-error      { color: #f85149; }   /* error          → red    */

/* --- rune-light: GitHub Light palette --- */
.cm-s-rune-light.CodeMirror {
    background: #ffffff;
    color: #24292e;
}
.cm-s-rune-light .CodeMirror-gutters {
    background: #f6f8fa;
    border-right: 1px solid #d0d7de;
}
.cm-s-rune-light .CodeMirror-linenumber  { color: #8c959f; }
.cm-s-rune-light .CodeMirror-cursor      { border-left: 2px solid #0969da; }
.cm-s-rune-light .CodeMirror-selected,
.cm-s-rune-light .CodeMirror-focused .CodeMirror-selected { background: #c8e1ff; }
/* Markdown structure */
.cm-s-rune-light .cm-header    { color: #005cc5; font-weight: bold; }
.cm-s-rune-light .cm-strong    { font-weight: bold; }
.cm-s-rune-light .cm-em        { font-style: italic; }
.cm-s-rune-light .cm-link      { color: #032f62; text-decoration: underline; }
.cm-s-rune-light .cm-url       { color: #6a737d; }
.cm-s-rune-light .cm-hr        { color: #d0d7de; }
.cm-s-rune-light .cm-quote     { color: #6a737d; font-style: italic; }
/* Code tokens */
.cm-s-rune-light .cm-keyword   { color: #d73a49; }   /* keyword        → red    */
.cm-s-rune-light .cm-def       { color: #6f42c1; }   /* function def   → purple */
.cm-s-rune-light .cm-builtin   { color: #e36209; }   /* built-in       → orange */
.cm-s-rune-light .cm-string    { color: #032f62; }   /* string         → navy   */
.cm-s-rune-light .cm-string-2  { color: #032f62; }   /* regexp/tmpl    → navy   */
.cm-s-rune-light .cm-number    { color: #005cc5; }   /* number         → blue   */
.cm-s-rune-light .cm-atom      { color: #005cc5; }   /* atom/const     → blue   */
.cm-s-rune-light .cm-variable  { color: #24292e; }   /* variable       → text   */
.cm-s-rune-light .cm-variable-2{ color: #005cc5; }   /* variable-2     → blue   */
.cm-s-rune-light .cm-variable-3,
.cm-s-rune-light .cm-type      { color: #e36209; }   /* type           → orange */
.cm-s-rune-light .cm-comment   { color: #6a737d; }   /* comment        → grey   */
.cm-s-rune-light .cm-tag       { color: #22863a; }   /* HTML tag       → green  */
.cm-s-rune-light .cm-attribute { color: #005cc5; }   /* HTML attr      → blue   */
.cm-s-rune-light .cm-qualifier { color: #005cc5; }   /* CSS class/id   → blue   */
.cm-s-rune-light .cm-meta      { color: #6a737d; }   /* meta           → grey   */
.cm-s-rune-light .cm-bracket   { color: #24292e; }   /* bracket        → text   */
.cm-s-rune-light .cm-operator  { color: #005cc5; }   /* operator       → blue   */
.cm-s-rune-light .cm-property  { color: #005cc5; }   /* property key   → blue   */
.cm-s-rune-light .cm-error     { color: #cb2431; }   /* error          → red    */

/* --- KaTeX math blocks --- */
.math-block {
    margin: 16px 0;
    overflow-x: auto;
    text-align: center;
}
.math-inline {
    display: inline;
}
.math-error {
    color: var(--error, #cb2431);
    font-style: italic;
}

/* --- 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;
}
/* foreignObject clips HTML content (white-space:nowrap divs) when Mermaid's
   internal text measurement underestimates the rendered width. Allow overflow
   so labels are never cut; SVG viewport still bounds the diagram as a whole. */
.mermaid-block foreignObject,
.mermaid foreignObject {
    overflow: visible;
}
/* Mermaid measures label height (getBoundingClientRect on the div) while its
   temporary SVG lives in <body> outside #preview, so <p> gets the browser
   default margin (1em 0 ≈ 16px).  After we inject the SVG into #preview the
   rule "#preview p { margin: 0.6em 0 }" fires and shrinks each <p> by ~12.8px
   total.  The foreignObject height was fixed at measurement time, so the div
   now only fills the top portion, shifting nodeLabel ~6px above center.
   We need #preview in the selector to reach specificity (1,1,2)=112 and beat
   "#preview p" at (1,0,1)=101; without it our rule loses silently. */
#preview .mermaid-block foreignObject p,
#preview .mermaid foreignObject p,
.chat-msg .mermaid-block foreignObject p,
.chat-msg .mermaid foreignObject p {
    margin: 1em 0;
}

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

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

/* 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-bar {
    display: none;
    height: 38px;
    min-height: 38px;
    flex-shrink: 0;
    align-items: center;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    width: 100%;
    gap: 8px;
    padding: 0 8px 0 12px;
}

#split-title {
    flex: 0 1 auto;
    font-size: 13px;
    font-weight: 500;
    line-height: 36px;
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: min(52ch, 100%);
    margin-right: auto;
    min-width: 0;
}

.split-title-controls {
    display: flex;
    align-items: center;
    gap: 2px;
    flex-shrink: 0;
    padding: 2px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg-surface);
}

.split-title-btn {
    flex-shrink: 0;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 13px;
    padding: 0 9px;
    height: 26px;
    display: flex;
    align-items: center;
    color: var(--text-muted);
    opacity: 0.55;
    transition: background 0.1s, color 0.1s, opacity 0.1s;
    border-radius: 6px;
}

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

.split-title-btn.active {
    color: var(--accent, #6366f1);
    opacity: 1;
    background: var(--accent-dim);
}

.split-title-nav {
    display: none;
}

.split-title-chat {
    display: none;
}

.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;
}


















/* ─── File search / filter input in Notes panel ─── */
.file-search-input {
    width: 100%;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 5px;
    color: var(--text);
    font-size: 12px;
    padding: 5px 10px;
    outline: none;
    transition: border-color 0.15s;
    box-sizing: border-box;
    flex-shrink: 0;
    margin-bottom: 6px;
}
.file-search-input:focus {
    border-color: var(--accent);
}

/* ─── 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 .icon.clickable {
    cursor: pointer;
    transition: opacity 0.15s;
}
.explorer-row .icon.private {
    opacity: 0.45;
}
.explorer-row .icon.clickable:hover {
    opacity: 1.0 !important;
}

.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;
}

.form-group input[type="text"]:focus {
    border-color: var(--accent);
    outline: none;
}

.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: 8px;
    z-index: 4;
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 2px 6px;
    border-radius: 4px;
    background: transparent;
    font-size: 10px;
    font-family: var(--font-mono, monospace);
    color: var(--text-muted);
    pointer-events: none;
    transition: opacity 0.2s;
    white-space: nowrap;
}

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

/* Hide context overlay when chat input contains text */
#chat-input:not(:placeholder-shown) ~ #context-overlay {
    display: none !important;
}


.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;
}
.run-stats {
    font-size: 11px;
    color: var(--text-muted, #777);
    opacity: 0.6;
    margin-top: 8px;
    padding-top: 4px;
    border-top: 1px solid var(--border, #333);
    font-family: monospace;
}
.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; }




/* ─── Compact chrome (revealed only by the <=768px tier) ─── */
#compact-bar,
#pane-switcher,
#compact-menu,
#app-scrim {
    display: none;
}

#compact-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 60;
    height: var(--compact-bar-h);
    align-items: center;
    gap: 4px;
    padding: 0 4px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
}

.compact-bar-btn {
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    border-radius: 8px;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 18px;
    line-height: 1;
    transition: background 0.15s, color 0.15s;
}
.compact-bar-btn:hover,
.compact-bar-btn[aria-expanded="true"] {
    background: var(--bg-hover);
    color: var(--text-primary);
}

#compact-title {
    flex: 1;
    min-width: 0;
    font-size: 14px;
    font-weight: 600;
    line-height: 40px;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    text-align: center;
}

.compact-menu {
    position: fixed;
    top: calc(var(--compact-bar-h) + 4px);
    right: 8px;
    z-index: 80;
    flex-direction: column;
    align-items: stretch;
    gap: 2px;
    min-width: 184px;
    padding: 6px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: var(--overlay-shadow);
}
.compact-menu button {
    background: transparent;
    border: 0;
    border-radius: 6px;
    color: var(--text-primary);
    cursor: pointer;
    font-family: inherit;
    font-size: 14px;
    padding: 10px 12px;
    text-align: left;
}
.compact-menu button:hover { background: var(--bg-hover); }

#app-scrim {
    position: fixed;
    inset: 0;
    z-index: 65;
    background: var(--scrim);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
}
body.tree-open #app-scrim {
    opacity: 1;
    pointer-events: auto;
}

#pane-switcher {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 60;
    gap: 4px;
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom, 0px));
    background: var(--bg-secondary);
    border-top: 1px solid var(--border);
}
#pane-switcher button {
    flex: 1;
    min-width: 0;
    height: 40px;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 8px;
    color: var(--text-muted);
    cursor: pointer;
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}
#pane-switcher button.active {
    background: var(--accent-dim);
    border-color: var(--accent);
    color: var(--accent);
}

/* ─── Tiers below wide: the tree leaves the flex flow (drawer), so the
       editor keeps its width instead of being squeezed to ~200px. ─── */
@media (max-width: 1279px) {
    #app-scrim { display: block; }
    #panel-left.panel {
        position: fixed;
        top: 0;
        bottom: 0;
        left: 0;
        z-index: 70;
        width: var(--drawer-width) !important;
        min-width: 0 !important;
        max-width: none !important;
        border-right: 1px solid var(--border);
        box-shadow: var(--overlay-shadow);
        transform: translateX(-102%);
        transition: transform 0.22s ease;
    }
    body.tree-open #panel-left.panel {
        transform: none;
    }
    #panel-left.panel .panel-content {
        display: flex;
    }
    #panel-left.panel .resize-handle,
    #panel-left.panel.fullscreen .resize-handle {
        display: none;
    }
    #panel-left.panel.fullscreen {
        width: var(--drawer-width) !important;
    }

    /* Editor and preview are mutually exclusive below the wide tier; which one
       renders is decided in applyPanelLayout(), so no CSS override is needed. */
    [data-action="toggle-sync-scroll"] { display: none; }

    .split-title-nav { display: flex; }
}

/* ─── Tier: medium (769–1279px) ─── */
@media (min-width: 769px) and (max-width: 1279px) {
    #panel-right.panel {
        width: var(--chat-width-medium);
        min-width: 220px;
        max-width: var(--chat-width-medium);
    }
    #panel-right.panel.collapsed {
        max-width: 20px;
    }
    #panel-center.hidden ~ #panel-right.panel {
        max-width: none;
    }

    /* Rescue chrome: both panes off collapses the center to zero width, taking
       #split-title-bar — this tier's only drawer trigger and pane toggles — with
       it. Reveal the app-level compact bar exactly then (<=768px always has it). */
    body.center-hidden #app { padding-top: var(--compact-bar-h); }
    body.center-hidden #compact-bar { display: flex; }
    body.center-hidden #compact-menu:not(.hidden) { display: flex; }

    .split-title-chat { display: flex; }
}

/* ─── Tier: medium, portrait — chat docks under the document instead of
       beside it. Aspect ratio rather than width, so a 1024x1366 iPad Pro is
       correctly treated as a tall device and not as a wide one. ─── */
@media (min-width: 769px) and (max-width: 1279px) and (max-aspect-ratio: 1/1) {
    #app { flex-direction: column; }

    #panel-right.panel {
        width: auto !important;
        min-width: 0 !important;
        max-width: none !important;
        height: var(--chat-height-stacked);
        min-height: 140px;
        max-height: 70vh;
        border-left: 0;
        border-top: 1px solid var(--border);
        flex-direction: column;
        transition: height 0.2s ease;
    }
    #panel-right.panel.collapsed {
        width: auto !important;
        height: 20px !important;
        min-height: 20px !important;
        max-height: 20px;
    }
    #panel-center.hidden {
        width: auto !important;
        height: 0 !important;
        min-height: 0 !important;
    }
    #panel-center.hidden ~ #panel-right.panel {
        height: auto !important;
        max-height: none !important;
    }

    #panel-right .resize-handle {
        top: 0;
        left: 0;
        width: 100%;
        height: 12px;
        cursor: row-resize;
    }
}

/* ─── Tier: compact (<=768px) ─── */
@media (max-width: 768px) {
    #app {
        padding-top: var(--compact-bar-h);
        padding-bottom: calc(var(--compact-switch-h) + env(safe-area-inset-bottom, 0px));
    }
    #compact-bar,
    #pane-switcher { display: flex; }
    #compact-menu:not(.hidden) { display: flex; }
    /* The pane switcher owns the editor/preview choice in this tier. */
    .compact-menu .pane-toggle-item { display: none; }

    #panel-center,
    #panel-right.panel {
        flex: 1 1 auto;
        width: 100% !important;
        min-width: 0 !important;
        max-width: none !important;
        border: 0;
    }
    #panel-right.panel.collapsed {
        width: 100% !important;
        min-width: 0 !important;
    }
    #panel-right.panel.collapsed .panel-content { display: flex; }
    #panel-right.panel .resize-handle { display: none; }

    /* Exactly one pane at a time; the switcher owns the choice. */
    #app[data-pane="chat"] #panel-center { display: none; }
    #app:not([data-pane="chat"]) #panel-right.panel { display: none; }
    #app[data-pane="editor"] #preview-container { display: none !important; }
    #app[data-pane="preview"] #editor-container { display: none !important; }

    #split-title-bar { display: none !important; }
    .panel-content { padding: 10px 12px; }
    .chat-msg { font-size: 14px; }
    #chat-input { font-size: 16px; }
    .toolbar-overflow-menu { top: 42px; }
    .modal { padding: 22px 18px; }
}

/* Task 5: Model dialog metadata badges */
.model-option {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}
.model-option-name {
    flex: 1;
    text-align: left;
}
.model-badges {
    display: flex;
    gap: 4px;
    align-items: center;
}
.model-ctx-badge, .model-reasoning-badge {
    font-size: 0.7rem;
    padding: 1px 5px;
    border-radius: 3px;
    background: var(--bg-secondary);
    color: var(--text-muted);
    white-space: nowrap;
}

.model-provider-badge {
    font-size: 0.7rem;
    padding: 1px 5px;
    border-radius: 3px;
    background: var(--accent-dim);
    color: var(--accent);
    white-space: nowrap;
    text-transform: capitalize;
}

.thinking-select {
    font-size: 0.75rem;
    padding: 2px 6px;
    border: 1px solid var(--border, #444);
    border-radius: 4px;
    background: var(--bg-secondary, #2a2a2a);
    color: var(--text-primary, #e0e0e0);
    cursor: pointer;
    margin-left: 8px;
    outline: none;
}
.thinking-select:hover {
    border-color: var(--accent, #007acc);
}

/* Mobile thinking select */
.mobile-thinking-select {
    font-size: 11px;
    padding: 2px 4px;
    margin-left: 0;
}
.mobile-thinking-wrapper {
    display: flex;
    align-items: center;
}

/* Model search/filter input */
.model-search-input {
    width: 100%;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-size: 13px;
    padding: 8px 12px;
    outline: none;
    transition: border-color 0.15s;
    box-sizing: border-box;
}
.model-search-input:focus {
    border-color: var(--accent);
}

/* Emoji Picker Styles */
.emoji-picker-wrapper {
    position: relative;
    display: inline-block;
}
.emoji-picker-trigger {
    font-size: 24px;
    padding: 8px 12px;
    border: 1px solid var(--border);
    background: var(--bg-secondary);
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: border-color 0.2s;
}
.emoji-picker-trigger:hover {
    border-color: var(--accent);
}
.emoji-picker-popover {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    z-index: 1000;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: 6px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.25);
    padding: 10px;
    width: 280px;
    box-sizing: border-box;
}
.emoji-search-input {
    width: 100%;
    padding: 6px 10px;
    border: 1px solid var(--border);
    background: var(--bg-secondary);
    color: var(--text-primary);
    border-radius: 4px;
    font-size: 13px;
    margin-bottom: 8px;
    box-sizing: border-box;
}
.emoji-tabs {
    display: flex;
    justify-content: space-between;
    border-bottom: 1px solid var(--border);
    padding-bottom: 6px;
    margin-bottom: 8px;
}
.emoji-tab-btn {
    background: none;
    border: none;
    font-size: 16px;
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    transition: background 0.15s;
}
.emoji-tab-btn:hover {
    background: var(--bg-hover);
}
.emoji-scroll-area {
    max-height: 220px;
    overflow-y: auto;
    padding-right: 4px;
}
.emoji-clear-btn {
    width: 100%;
    padding: 6px;
    margin-bottom: 10px;
    border: 1px solid var(--border);
    background: var(--bg-secondary);
    color: var(--text-primary);
    border-radius: 4px;
    font-size: 13px;
    cursor: pointer;
}
.emoji-clear-btn:hover {
    background: var(--bg-hover);
    border-color: var(--accent);
}
.emoji-category-section {
    margin-bottom: 12px;
}
.emoji-category-title {
    font-size: 11px;
    font-weight: bold;
    color: var(--text-secondary);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.emoji-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 4px;
}
.emoji-btn {
    font-size: 18px;
    padding: 4px;
    border: 1px solid transparent;
    background: none;
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, border-color 0.15s;
}
.emoji-btn:hover {
    background: var(--bg-hover);
    border-color: var(--border);
}
.emoji-btn.active {
    border-color: var(--accent);
    background: var(--bg-hover);
}


/* ─── Icon system ───
   One inline-SVG family; every glyph inherits currentColor so the existing
   light/dark tokens keep working with no per-theme assets. */
.rune-icon {
    width: 16px;
    height: 16px;
    flex: none;
    display: block;
    pointer-events: none;
}

.split-title-btn .rune-icon,
.chat-action-btn .rune-icon,
.explorer-action-btn .rune-icon,
.toolbar-overflow-btn .rune-icon,
.editor-toolbar button .rune-icon { width: 15px; height: 15px; }

.compact-bar-btn .rune-icon { width: 20px; height: 20px; }
#chat-send .rune-icon { width: 17px; height: 17px; margin: 0 auto; }
.explorer-row .rune-icon { width: 15px; height: 15px; }
.status .rune-icon { width: 10px; height: 10px; }
.copy-btn .rune-icon,
.search-copy-btn .rune-icon { width: 13px; height: 13px; }
.sender .rune-icon { width: 12px; height: 12px; }
.dir-entry-icon .rune-icon { width: 15px; height: 15px; }
.emoji-picker-trigger .rune-icon { width: 22px; height: 22px; }
.palette-item .rune-icon { width: 16px; height: 16px; }

.status.idle    { color: var(--success); }
.status.thinking,
.status.typing  { color: var(--accent); }
.status.tool    { color: var(--warning); }

/* Keyboard reachability has to be visible to be usable. */
:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-radius: 4px;
}

/* ─── Markdown toolbar: glyph in the bar, full label in the overflow menu ─── */
.editor-toolbar button,
.toolbar-overflow-menu button {
    gap: 8px;
}
.tb-glyph {
    font-family: var(--font-sans);
    font-size: 14px;
    line-height: 1;
    width: 15px;
    text-align: center;
}
.tb-label { display: none; }
.toolbar-overflow-menu .tb-label { display: inline; }

/* ─── Note tree: state indicator + one action control per row ─── */
.explorer-row .icon-type { color: var(--text-secondary); }
.explorer-row .icon-vis {
    margin: 0 2px 0 4px;
    padding: 0;
    background: none;
    border: 0;
    color: var(--text-muted);
    width: 20px;
    height: 20px;
    border-radius: 4px;
}
.explorer-row button.icon-vis:hover {
    background: var(--bg-hover, rgba(255, 255, 255, 0.08));
    color: var(--accent);
}
.explorer-row .icon-vis[aria-pressed="true"],
.explorer-row .icon-vis:not(.private) { color: var(--success); }
/* The lock/globe shape already carries the state, so the inherited dimming
   from the emoji era only cost contrast. */
.explorer-row .icon-vis.private { opacity: 1; }
.explorer-row .actions { margin-left: 0; }
.explorer-row .row-menu-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    padding: 0;
    background: none;
    border: 0;
    border-radius: 4px;
    color: var(--text-muted);
    cursor: pointer;
}
.explorer-row .row-menu-btn:hover {
    background: var(--bg-hover, rgba(255, 255, 255, 0.1));
    color: var(--text-primary);
}
.explorer-row:focus-within .actions { opacity: 1; }

.row-menu {
    position: fixed;
    z-index: 1200;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 2px;
    min-width: 168px;
    padding: 6px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: var(--overlay-shadow);
}
.row-menu-item {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 8px 10px;
    background: transparent;
    border: 0;
    border-radius: 5px;
    color: var(--text-primary);
    cursor: pointer;
    font-family: inherit;
    font-size: 13px;
    text-align: left;
}
.row-menu-item:hover { background: var(--bg-hover); }
.row-menu-item.danger { color: var(--error); }

/* ─── Command palette ─── */
.palette-overlay {
    position: fixed;
    inset: 0;
    z-index: 1500;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 12vh 16px 16px;
    background: var(--scrim);
}
.palette {
    width: min(560px, 100%);
    max-height: 62vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: var(--overlay-shadow);
}
.palette-search {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
}
.palette-search-icon { display: flex; color: var(--text-muted); }
.palette-input {
    flex: 1;
    min-width: 0;
    background: transparent;
    border: 0;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 15px;
    outline: none;
}
.palette-list { overflow-y: auto; padding: 6px; }
.palette-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 10px;
    border-radius: 6px;
    color: var(--text-primary);
    cursor: pointer;
    font-size: 13px;
}
.palette-item:hover { background: var(--bg-hover); }
.palette-item.selected { background: var(--accent-dim); color: var(--accent); }
.palette-item-label { flex: 1; min-width: 0; }
.palette-item-keys {
    flex: none;
    color: var(--text-muted);
    font-family: var(--font-mono);
    font-size: 11px;
}
.palette-empty {
    padding: 18px 14px;
    color: var(--text-muted);
    font-size: 13px;
    text-align: center;
}

/* ─── Icon alignment inside existing chrome ─── */
.copy-btn,
.search-copy-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
}
.search-copy-btn { padding: 3px; }
.search-role { display: inline-flex; color: var(--text-muted); margin-right: 6px; vertical-align: middle; }
.sender-name { display: inline-flex; align-items: center; gap: 5px; }
.dir-entry-icon { display: flex; align-items: center; color: var(--text-secondary); }
.btn-approve,
.btn-deny {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.compact-menu button {
    display: flex;
    align-items: center;
    gap: 10px;
}
.emoji-tab-btn { display: inline-flex; align-items: center; justify-content: center; user-select: none; }
.emoji-btn { user-select: none; }
.emoji-picker-trigger {
    display: inline-flex;
    width: 52px;
    height: 46px;
    user-select: none;
}
.emoji-no-results {
    grid-column: 1 / -1;
    padding: 10px 0;
    color: var(--text-secondary);
    font-size: 13px;
}
.model-name[role="button"] { cursor: pointer; }
