/* Memory Assistant v2 — macOS Sonoma Design */

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

:root {
    --bg-primary: #ffffff;
    --bg-secondary: rgba(246, 246, 246, 0.72);
    --bg-tertiary: rgba(238, 238, 238, 0.65);
    --bg-elevated: rgba(255, 255, 255, 0.85);
    --bg-vibrancy: rgba(255, 255, 255, 0.55);

    --border-color: rgba(0, 0, 0, 0.06);
    --border-divider: rgba(0, 0, 0, 0.09);
    --border-focus: rgba(0, 122, 255, 0.45);

    --text-primary: #1d1d1f;
    --text-secondary: rgba(60, 60, 67, 0.6);
    --text-tertiary: rgba(60, 60, 67, 0.3);

    --accent: #007AFF;
    --accent-hover: #0066DD;
    --accent-subtle: rgba(0, 122, 255, 0.08);

    --destructive: #FF3B30;
    --success: #34C759;

    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.04), 0 1px 2px rgba(0, 0, 0, 0.06);
    --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.08), 0 2px 6px rgba(0, 0, 0, 0.04);
    --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.12), 0 4px 12px rgba(0, 0, 0, 0.06);
    --shadow-float: 0 20px 60px rgba(0, 0, 0, 0.15), 0 8px 20px rgba(0, 0, 0, 0.08);

    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;
    --radius-xl: 20px;

    /* Layout panel widths (JS sets these via CSS vars for split editor) */
    --tree-panel-width: 20%;
    --editor-panel-width: 30%;

    --warning: #FF9500;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Helvetica Neue', Arial, sans-serif;
    background: linear-gradient(180deg, #f5f5f7 0%, #fafafa 100%);
    color: var(--text-primary);
    height: 100vh;
    overflow: hidden;
    font-size: 14px;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

#app {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

/* ─── Header ─── */
#header {
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    background: var(--bg-vibrancy);
    box-shadow: inset 0 -0.5px 0 var(--border-divider);
    padding: 10px 20px;
    display: flex;
    align-items: center;
    gap: 20px;
    border-bottom: none;
    position: relative;
    z-index: 100;
}

#header h1 {
    font-size: 17px;
    font-weight: 600;
    letter-spacing: -0.03em;
}

#context-indicator {
    flex: 1;
    font-size: 14px;
    color: var(--text-secondary);
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 8px;
}

#context-indicator.has-context {
    cursor: pointer;
    border-radius: var(--radius-sm);
    padding: 4px 10px;
    transition: background 0.15s;
}

#context-indicator.has-context:hover {
    background: rgba(255, 59, 48, 0.06);
    color: var(--text-primary);
}

.context-clear-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.06);
    color: var(--text-secondary);
    font-size: 11px;
    font-weight: 700;
    flex-shrink: 0;
    transition: all 0.15s;
}

#context-indicator.has-context:hover .context-clear-btn {
    background: var(--destructive);
    color: white;
}

#export-btn,
#api-settings-btn {
    background: rgba(0, 0, 0, 0.04);
    border: none;
    color: var(--text-primary);
    padding: 8px 16px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s;
}

#export-btn:hover {
    background: rgba(0, 0, 0, 0.08);
}

/* ─── Profile Menu ─── */
#profile-menu-wrapper {
    position: relative;
}

#profile-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(0, 0, 0, 0.04);
    border: none;
    color: var(--text-primary);
    padding: 6px 14px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    transition: all 0.2s;
}

#profile-btn:hover {
    background: rgba(0, 0, 0, 0.08);
}

#profile-btn .user-avatar {
    width: 24px;
    height: 24px;
    border-radius: 50%;
}

.profile-dropdown {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    min-width: 220px;
    background: var(--bg-primary, #fff);
    border: 1px solid var(--border, #e5e5e5);
    border-radius: 10px;
    box-shadow: 0 8px 30px rgba(0,0,0,0.12), 0 2px 8px rgba(0,0,0,0.06);
    z-index: 1000;
    overflow: hidden;
}

.profile-dropdown-header {
    padding: 12px 16px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.profile-dropdown-divider {
    height: 1px;
    background: var(--border, #e5e5e5);
}

.profile-dropdown-item {
    display: block;
    width: 100%;
    padding: 10px 16px;
    background: none;
    border: none;
    text-align: left;
    font-size: 13px;
    color: var(--text-primary);
    cursor: pointer;
    transition: background 0.15s;
}

.profile-dropdown-item:hover {
    background: rgba(0, 0, 0, 0.04);
}

.profile-dropdown-signout {
    color: var(--destructive, #e74c3c);
}

/* ─── Main Layout ─── */
#main-layout {
    display: flex;
    flex: 1;
    overflow: hidden;
    padding: 6px;
    gap: 0;
}

/* ─── Resize handles ─── */
.resize-handle {
    width: 6px;
    flex-shrink: 0;
    cursor: col-resize;
    background: var(--border-divider);
    transition: background 0.15s;
    position: relative;
    z-index: 20;
}

.resize-handle::after {
    content: '';
    position: absolute;
    inset: 0 -4px; /* wider hit area without affecting layout */
}

.resize-handle:hover,
.resize-handle.dragging {
    background: var(--accent);
}

/* Split handle only visible in split mode */
#handle-split {
    background: var(--border-divider);
}

/* ─── Tree Panel (20%) ─── */
#tree-panel {
    width: var(--tree-panel-width);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    background: rgba(246, 246, 246, 0.72);
    box-shadow: inset -0.5px 0 0 var(--border-divider);
    overflow-y: auto;
    padding: 12px;
    border-right: none;
    min-width: 0;
    flex-shrink: 0;
    transition: width 0.3s ease;
}

/* ─── Projects Path Bar ─── */
#projects-path-bar {
    margin-bottom: 12px;
}

#projects-path-bar label {
    display: block;
    font-size: 11px;
    color: var(--text-secondary);
    margin-bottom: 4px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

#projects-path-row {
    display: flex;
    gap: 4px;
}

#projects-path-input {
    flex: 1;
    padding: 6px 8px;
    background: rgba(255, 255, 255, 0.7);
    border: 0.5px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 12px;
    font-family: 'Monaco', 'Menlo', 'Consolas', monospace;
    min-width: 0;
    transition: border-color 0.2s, box-shadow 0.2s;
}

#projects-path-input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--border-focus);
}

#projects-path-input.saved {
    border-color: var(--success);
}

#projects-path-btn {
    padding: 6px 10px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 500;
    white-space: nowrap;
    transition: background 0.2s;
}

#projects-path-btn:hover {
    background: var(--accent-hover);
}

#projects-path-btn:disabled {
    background: rgba(0, 0, 0, 0.06);
    color: var(--text-tertiary);
    cursor: not-allowed;
}

/* ─── Extra Folders Bar ─── */
#extra-folders-bar {
    margin-bottom: 12px;
}

#extra-folders-bar > label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    color: var(--text-secondary);
    margin-bottom: 6px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

#add-folder-btn {
    width: 22px;
    height: 22px;
    padding: 0;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 14px;
    font-weight: 700;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

#add-folder-btn:hover {
    background: var(--accent-hover);
}

#extra-folders-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

#extra-folders-list:empty {
    display: none;
}

.extra-folder-item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    background: var(--accent-subtle);
    border: 0.5px solid rgba(0, 122, 255, 0.15);
    border-radius: var(--radius-xl);
    font-size: 12px;
    color: var(--text-primary);
    max-width: 100%;
}

.extra-folder-item .folder-label {
    font-weight: 500;
}

.extra-folder-item .folder-path {
    color: var(--text-secondary);
    font-size: 11px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 120px;
}

.extra-folder-item .remove-folder-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 14px;
    padding: 0 2px;
    line-height: 1;
    flex-shrink: 0;
    transition: color 0.2s;
}

.extra-folder-item .remove-folder-btn:hover {
    color: var(--destructive);
}

/* ─── Tree Source Divider ─── */
.tree-source-divider {
    height: 0.5px;
    background: var(--border-divider);
    margin: 14px 0 10px;
}

.tree-source-header {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--text-secondary);
}

.tree-source-header .source-icon {
    font-size: 14px;
}

.tree-source-collapsible {
    cursor: pointer;
    user-select: none;
}

.tree-source-collapsible:hover {
    opacity: 0.8;
}

.tree-source-collapsible .source-toggle {
    font-size: 10px;
    width: 12px;
    display: inline-flex;
    justify-content: center;
}

/* .gdoc file icon styling */
.tree-node-icon.gdoc-icon {
    color: #4285F4;
}

.gdoc-label {
    color: var(--text-secondary);
    font-style: italic;
}

.gdoc-open-btn {
    opacity: 1 !important;
    cursor: pointer;
}

/* ─── Tree Hint ─── */
/* ─── Tree Search ─── */
.tree-search-wrapper {
    position: relative;
    margin-bottom: 8px;
}
#tree-search-input {
    width: 100%;
    padding: 7px 28px 7px 10px;
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-md);
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 13px;
    outline: none;
    box-sizing: border-box;
}
#tree-search-input:focus {
    border-color: var(--accent, #6b9eff);
    box-shadow: 0 0 0 2px rgba(107, 158, 255, 0.15);
}
#tree-search-input::placeholder {
    color: var(--text-tertiary);
}
.tree-search-clear {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    cursor: pointer;
    color: var(--text-tertiary);
    font-size: 14px;
    line-height: 1;
    padding: 2px;
}
.tree-search-clear:hover {
    color: var(--text-primary);
}

#tree-search-results {
    font-size: 13px;
    max-height: calc(100vh - 200px);
    overflow-y: auto;
}
.tree-search-section {
    margin-bottom: 8px;
}
.tree-search-section-header {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-tertiary);
    padding: 4px 8px;
    margin-bottom: 2px;
}
.tree-search-result {
    display: flex;
    flex-direction: column;
    padding: 6px 10px;
    border-radius: var(--radius-sm, 4px);
    cursor: pointer;
    gap: 1px;
}
.tree-search-result:hover {
    background: var(--bg-hover, rgba(255,255,255,0.06));
}
.tree-search-result-name {
    color: var(--text-primary);
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.tree-search-result-path {
    font-size: 11px;
    color: var(--text-tertiary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.tree-search-result-snippet {
    font-size: 11px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 1px;
}
.tree-search-empty {
    color: var(--text-tertiary);
    font-size: 12px;
    padding: 12px 8px;
    text-align: center;
}

.tree-hint {
    font-size: 11px;
    color: var(--text-secondary);
    padding: 8px 12px;
    background: rgba(0, 122, 255, 0.04);
    border: 0.5px solid rgba(0, 122, 255, 0.08);
    border-radius: var(--radius-md);
    margin-bottom: 12px;
    line-height: 1.4;
}

#tree-container {
    font-size: 14px;
}

/* ─── Tree Nodes ─── */
.tree-node {
    margin: 2px 0;
}

.tree-node-header {
    display: flex;
    align-items: center;
    padding: 8px 12px;
    cursor: pointer;
    border-radius: 8px;
    user-select: none;
    transition: background 0.15s ease;
    gap: 8px;
    min-height: 36px;
}

.tree-node-header:hover {
    background: rgba(0, 0, 0, 0.04);
}

.tree-node-header:hover .tree-node-label {
    color: var(--text-primary);
}

.tree-node-header.selected {
    background: var(--accent-subtle);
    border-left: 2.5px solid var(--accent);
    padding-left: 9.5px;
}

.tree-node-header.selected:hover {
    background: rgba(0, 122, 255, 0.12);
}

.tree-node-header.selected .tree-node-label {
    color: var(--accent);
    font-weight: 500;
}

.tree-node-toggle {
    width: 16px;
    margin-right: 4px;
    font-size: 12px;
    color: var(--text-secondary);
    transition: transform 0.2s ease;
}

.tree-node-icon {
    font-size: 18px;
    line-height: 1;
}

.tree-node-checkbox {
    width: 18px;
    height: 18px;
    cursor: pointer;
    flex-shrink: 0;
    accent-color: var(--accent);
}

.tree-node-label {
    flex: 1;
    font-size: 13px;
    line-height: 1.5;
    font-weight: 400;
}

.tree-node-children {
    margin-left: 20px;
}

.tree-node-children.collapsed {
    display: none;
}

.tree-node.file .tree-node-header {
    padding-left: 24px;
}

.tree-node.file .tree-node-toggle {
    visibility: hidden;
}

/* ─── Editor Panel (30%) ─── */
#editor-panel {
    width: var(--editor-panel-width);
    background: var(--bg-primary);
    box-shadow: inset -0.5px 0 0 var(--border-divider);
    display: flex;
    flex-direction: row;
    overflow: hidden;
    border-right: none;
}

/* Left pane — always present, fills panel when not split */
#editor-pane-left {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 0;
}

/* Right pane — revealed in split mode */
#editor-pane-right {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 0;
    border-left: 1px solid var(--border-divider);
}

/* Split mode: editor panel expands to fill more horizontal space */
#editor-panel.split-mode {
    width: calc(var(--editor-panel-width) * 2);
    max-width: 60%;
}

/* Right pane header */
#right-pane-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-divider);
    min-height: 42px;
    flex-shrink: 0;
}

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

#split-close-btn, #right-save-btn {
    padding: 4px 10px;
    font-size: 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-elevated);
    color: var(--text-secondary);
    cursor: pointer;
    transition: background 0.15s;
    flex-shrink: 0;
}

#split-close-btn:hover, #right-save-btn:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

#right-save-btn:disabled {
    opacity: 0.4;
    cursor: default;
}

/* Right pane content area */
#right-pane-content {
    flex: 1;
    overflow: hidden;
    position: relative;
}

#right-pane-content .editor-textarea,
#right-pane-content .editor-preview {
    display: none;
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
}

#right-pane-content .editor-textarea.active,
#right-pane-content .editor-preview.active {
    display: block;
}

/* Create-delivery placeholder in right pane */
.create-delivery-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    gap: 16px;
    color: var(--text-secondary);
    text-align: center;
    padding: 32px;
}

.create-delivery-placeholder p {
    font-size: 14px;
    line-height: 1.5;
}

.create-delivery-btn {
    padding: 10px 20px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 14px;
    cursor: pointer;
    transition: background 0.15s;
}

.create-delivery-btn:hover {
    background: var(--accent-hover);
}

/* ─── Editor Tabs ─── */
#editor-tabs {
    display: flex;
    background: var(--bg-secondary);
    border-bottom: none;
    overflow-x: auto;
    min-height: 42px;
    align-items: flex-end;
    padding: 0 4px;
}

#editor-tabs:empty::after {
    content: 'No files open';
    padding: 12px 15px;
    color: var(--text-secondary);
    font-size: 13px;
}

.editor-tab {
    display: flex;
    align-items: center;
    padding: 8px 16px;
    background: transparent;
    border: none;
    cursor: pointer;
    font-size: 13px;
    white-space: nowrap;
    transition: all 0.2s;
    gap: 8px;
    font-weight: 500;
    color: var(--text-secondary);
    border-radius: 8px 8px 0 0;
    margin: 4px 2px 0;
}

.editor-tab:hover {
    background: rgba(0, 0, 0, 0.04);
    color: var(--text-primary);
}

.editor-tab.active {
    background: white;
    color: var(--text-primary);
    box-shadow: var(--shadow-sm);
}

.editor-tab-label {
    margin-right: 4px;
}

.editor-tab-close {
    color: var(--text-tertiary);
    font-size: 14px;
    cursor: pointer;
    width: 18px;
    height: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    line-height: 1;
    transition: all 0.2s;
}

.editor-tab-close:hover {
    color: var(--text-primary);
    background: rgba(0, 0, 0, 0.08);
}

/* ─── Editor Mode Toggle (Segmented Control) ─── */
#editor-mode-toggle {
    display: flex;
    gap: 0;
    padding: 8px 12px;
    background: var(--bg-secondary);
    border-bottom: none;
    box-shadow: inset 0 -0.5px 0 var(--border-divider);
}

.mode-btn {
    padding: 6px 16px;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 12px;
    font-weight: 500;
    transition: all 0.2s ease;
    border-radius: 7px;
}

.mode-btn:first-child {
    border-radius: 7px;
}

.mode-btn:last-child {
    border-radius: 7px;
}

.mode-btn:hover {
    color: var(--text-primary);
}

.mode-btn.active {
    background: white;
    color: var(--text-primary);
    box-shadow: var(--shadow-sm);
}

/* Segmented control wrapper */
#editor-mode-toggle {
    background: rgba(0, 0, 0, 0.05);
    border-radius: 8px;
    padding: 2px;
    margin: 8px 12px;
    display: inline-flex;
    box-shadow: none;
}

/* ─── Editor Toolbar ─── */
#editor-toolbar {
    display: flex;
    gap: 4px;
    padding: 8px 12px;
    background: var(--bg-primary);
    box-shadow: inset 0 -0.5px 0 var(--border-divider);
    align-items: center;
    border-bottom: none;
}

#editor-toolbar button {
    padding: 6px 10px;
    background: transparent;
    border: none;
    color: var(--text-primary);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    transition: all 0.2s;
}

#editor-toolbar button:hover:not(:disabled) {
    background: rgba(0, 0, 0, 0.05);
}

#editor-toolbar button:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

#editor-save-btn:not(:disabled) {
    background: var(--accent);
    color: white;
    border-radius: 8px;
}

#editor-save-btn:not(:disabled):hover {
    background: var(--accent-hover);
}

.toolbar-separator {
    width: 0.5px;
    height: 16px;
    background: var(--border-divider);
    margin: 0 4px;
}

.fmt-btn {
    padding: 4px 6px !important;
    min-width: 28px;
    font-size: 12px !important;
    font-weight: 600;
}

.fmt-btn:hover:not(:disabled) {
    background: rgba(0, 0, 0, 0.05) !important;
    color: var(--accent) !important;
}

/* ─── Editor Content ─── */
#editor-content {
    flex: 1;
    overflow: hidden;
    position: relative;
}

.editor-empty-state {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-tertiary);
    font-size: 14px;
}

.editor-textarea {
    width: 100%;
    height: 100%;
    background: var(--bg-primary);
    border: none;
    color: var(--text-primary);
    font-size: 15px;
    font-family: 'Monaco', 'Menlo', 'Consolas', 'Courier New', monospace;
    line-height: 1.7;
    padding: 20px;
    resize: none;
    display: none;
}

.editor-textarea.active {
    display: block;
}

.editor-textarea:focus {
    outline: none;
}

/* ─── Preview Mode ─── */
.editor-preview {
    width: 100%;
    height: 100%;
    background: var(--bg-primary);
    display: none;
    color: var(--text-primary);
    padding: 30px;
    overflow-y: auto;
    display: none;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    line-height: 1.7;
    font-size: 15px;
}

.editor-preview.active {
    display: block;
}

.editor-preview h1 {
    font-size: 32px;
    font-weight: 700;
    letter-spacing: -0.03em;
    margin: 20px 0 16px;
    border-bottom: 0.5px solid var(--border-divider);
    padding-bottom: 8px;
}

.editor-preview h2 {
    font-size: 24px;
    font-weight: 600;
    letter-spacing: -0.03em;
    margin: 16px 0 12px;
}

.editor-preview h3 {
    font-size: 20px;
    font-weight: 600;
    letter-spacing: -0.03em;
    margin: 12px 0 8px;
}

.editor-preview p {
    margin: 8px 0;
}

.editor-preview a {
    color: var(--accent);
    text-decoration: none;
}

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

.editor-preview ul, .editor-preview ol {
    margin: 8px 0;
    padding-left: 24px;
}

.editor-preview li {
    margin: 4px 0;
}

.editor-preview code {
    background: rgba(0, 0, 0, 0.04);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Monaco', 'Courier New', monospace;
    font-size: 13px;
}

.editor-preview pre {
    background: rgba(0, 0, 0, 0.03);
    padding: 14px;
    border-radius: var(--radius-md);
    overflow-x: auto;
    margin: 12px 0;
}

.editor-preview pre code {
    background: none;
    padding: 0;
}

.editor-preview blockquote {
    border-left: 3px solid var(--accent);
    padding-left: 16px;
    margin: 12px 0;
    color: var(--text-secondary);
}

.editor-preview table {
    border-collapse: collapse;
    margin: 12px 0;
    width: 100%;
}

.editor-preview table th,
.editor-preview table td {
    border: 0.5px solid var(--border-divider);
    padding: 8px 12px;
    text-align: left;
}

.editor-preview table th {
    background: rgba(0, 0, 0, 0.03);
    font-weight: 600;
}

.editor-preview hr {
    border: none;
    border-top: 0.5px solid var(--border-divider);
    margin: 20px 0;
}

/* ─── Mermaid Diagrams ─── */
.mermaid-diagram {
    background: rgba(0, 0, 0, 0.02);
    padding: 20px;
    border-radius: var(--radius-md);
    margin: 20px 0;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    border: 0.5px solid var(--border-color);
}

.mermaid-diagram:hover {
    border-color: var(--accent);
    box-shadow: var(--shadow-md);
}

.mermaid-diagram svg {
    max-width: 100%;
    height: auto;
}

.mermaid-diagram svg rect[class*="section"],
.mermaid-diagram svg rect[class*="grid"] {
    fill: #f5f5f7 !important;
}

.mermaid-diagram svg .grid line {
    stroke: var(--border-divider) !important;
    stroke-width: 0.5;
}

/* ─── Diagram Modal ─── */
#diagram-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.3);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.2s;
}

.diagram-modal-content {
    width: 90%;
    height: 90%;
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    background: var(--bg-elevated);
    border-radius: var(--radius-lg);
    border: 0.5px solid var(--border-color);
    box-shadow: var(--shadow-float);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.diagram-modal-header {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    gap: 12px;
}

.diagram-controls {
    display: flex;
    gap: 6px;
    align-items: center;
}

.diagram-btn {
    padding: 6px 12px;
    background: rgba(0, 0, 0, 0.04);
    border: none;
    color: var(--text-primary);
    border-radius: 8px;
    cursor: pointer;
    font-size: 13px;
    transition: all 0.2s;
}

.diagram-btn:hover {
    background: rgba(0, 0, 0, 0.08);
}

.diagram-btn:active {
    transform: scale(0.95);
}

#diagram-zoom-level {
    font-size: 12px;
    color: var(--text-secondary);
    min-width: 50px;
    text-align: center;
}

.diagram-btn-close {
    margin-left: auto;
    padding: 6px 12px;
    background: rgba(255, 59, 48, 0.1);
    border: none;
    color: var(--destructive);
    border-radius: 50%;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 16px;
    font-weight: bold;
    transition: all 0.2s;
}

.diagram-btn-close:hover {
    background: rgba(255, 59, 48, 0.15);
}

.diagram-modal-body {
    flex: 1;
    overflow: auto;
    padding: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s;
    background: rgba(0, 0, 0, 0.02);
}

.diagram-modal-body svg {
    max-width: 100%;
    height: auto;
}

.diagram-modal-body svg rect[class*="section"],
.diagram-modal-body svg rect[class*="grid"] {
    fill: #f5f5f7 !important;
}

.diagram-modal-body svg .grid line {
    stroke: var(--border-divider) !important;
    stroke-width: 0.5;
}

/* ─── Chat Panel (50%) ─── */
#chat-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--bg-primary);
}

/* ─── Chat Toolbar ─── */
#chat-toolbar {
    display: flex;
    gap: 8px;
    padding: 8px 12px;
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    background: var(--bg-vibrancy);
    box-shadow: inset 0 -0.5px 0 var(--border-divider);
    border-bottom: none;
}

#chat-toolbar button {
    padding: 6px 12px;
    background: rgba(0, 0, 0, 0.04);
    border: none;
    color: var(--text-primary);
    border-radius: 8px;
    cursor: pointer;
    font-size: 12px;
    transition: all 0.2s;
}

#chat-toolbar button:hover {
    background: rgba(0, 0, 0, 0.08);
}

#save-chat-btn {
    background: var(--accent);
    color: white;
    border: none;
}

#save-chat-btn:hover {
    background: var(--accent-hover);
}

#clear-chat-btn:hover {
    background: rgba(255, 59, 48, 0.08);
    color: var(--destructive);
}

#chat-render-btn.active {
    background: var(--accent);
    color: white;
}

/* ─── Chat Markdown Rendered Styles ─── */
.chat-text-content.md-rendered { white-space: normal; }
.chat-text-content.md-rendered p { margin: 6px 0; }
.chat-text-content.md-rendered h1,
.chat-text-content.md-rendered h2,
.chat-text-content.md-rendered h3 { margin: 12px 0 6px; font-weight: 600; }
.chat-text-content.md-rendered ul,
.chat-text-content.md-rendered ol { padding-left: 20px; margin: 6px 0; }
.chat-text-content.md-rendered table { border-collapse: collapse; width: 100%; margin: 8px 0; font-size: 13px; }
.chat-text-content.md-rendered th,
.chat-text-content.md-rendered td { border: 1px solid var(--border-divider); padding: 6px 10px; text-align: left; }
.chat-text-content.md-rendered th { background: rgba(0,0,0,0.04); font-weight: 600; }
.chat-text-content.md-rendered pre { background: rgba(0,0,0,0.06); padding: 10px 12px; border-radius: 6px; overflow-x: auto; margin: 8px 0; }
.chat-text-content.md-rendered pre code { background: none; padding: 0; font-size: 12px; }
.chat-text-content.md-rendered hr { border: none; border-top: 1px solid var(--border-divider); margin: 12px 0; }
.chat-text-content.md-rendered blockquote { border-left: 3px solid var(--border-divider); margin: 8px 0; padding-left: 12px; color: var(--text-secondary); }

/* ─── Chat History Controls ─── */
#chat-history-controls {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    color: var(--text-secondary);
    margin-left: auto;
}

#message-counter {
    font-weight: 500;
    cursor: help;
}

#history-limit-input {
    background: rgba(255, 255, 255, 0.7);
    border: 0.5px solid var(--border-color);
    color: var(--text-primary);
    padding: 4px 6px;
    border-radius: var(--radius-sm);
    font-size: 12px;
    text-align: center;
    transition: border-color 0.2s, box-shadow 0.2s;
}

#history-limit-input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--border-focus);
}

/* ─── Chat Messages ─── */
#chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background: var(--bg-primary);
}

.chat-message {
    margin-bottom: 16px;
    max-width: 75%;
    padding: 12px 16px;
    animation: fadeIn 0.3s;
    line-height: 1.5;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.chat-message.user {
    background: var(--accent);
    color: white;
    margin-left: auto;
    border-radius: 18px 18px 4px 18px;
}

.chat-message.assistant {
    background: rgba(0, 0, 0, 0.04);
    border-radius: 18px 18px 18px 4px;
}

.chat-message-role {
    font-size: 10px;
    color: var(--text-tertiary);
    text-transform: uppercase;
    margin-bottom: 4px;
    letter-spacing: 0.03em;
}

.chat-message.user .chat-message-role {
    color: rgba(255, 255, 255, 0.7);
}

.chat-message-content {
    line-height: 1.5;
    white-space: pre-wrap;
}

.chat-message-content code {
    background: rgba(0, 0, 0, 0.06);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Monaco', 'Courier New', monospace;
    font-size: 13px;
}

.chat-message.user .chat-message-content code {
    background: rgba(255, 255, 255, 0.2);
}

/* ─── Memory Update Suggestion ─── */
.memory-update-suggestion {
    margin-top: 12px;
    padding: 12px;
    background: rgba(0, 122, 255, 0.04);
    border: 0.5px solid rgba(0, 122, 255, 0.15);
    border-radius: 12px;
}

.memory-update-buttons {
    margin-top: 8px;
    display: flex;
    gap: 8px;
}

.memory-update-buttons button {
    padding: 6px 16px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    transition: all 0.2s;
}

.memory-update-buttons .yes-btn,
.memory-update-buttons .memory-update-approve {
    background: var(--accent);
    color: white;
}

.memory-update-buttons .yes-btn:hover,
.memory-update-buttons .memory-update-approve:hover:not(:disabled) {
    background: var(--accent-hover);
}

.memory-update-buttons .no-btn,
.memory-update-buttons .memory-update-reject {
    background: rgba(0, 0, 0, 0.04);
    color: var(--text-primary);
    border: 0.5px solid var(--border-color);
}

.memory-update-buttons .no-btn:hover,
.memory-update-buttons .memory-update-reject:hover:not(:disabled) {
    background: rgba(0, 0, 0, 0.08);
}

.memory-update-buttons button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ─── Chat Input Area ─── */
#chat-input-area {
    padding: 12px 16px;
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    background: var(--bg-secondary);
    border-top: none;
    box-shadow: inset 0 0.5px 0 var(--border-divider);
    display: flex;
    flex-direction: column;
    gap: 8px;
}

#chat-input-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 8px;
    position: relative;
}

/* ─── Attached File Badges ─── */
#attached-files-container {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

#attached-files-container:empty {
    display: none;
}

.attached-file-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    background: var(--accent-subtle);
    border: 0.5px solid rgba(0, 122, 255, 0.12);
    border-radius: var(--radius-xl);
    font-size: 12px;
    color: var(--accent);
    max-width: 200px;
}

.attached-file-badge .file-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.attached-file-badge .remove-file-btn {
    background: none;
    border: none;
    color: var(--accent);
    cursor: pointer;
    font-size: 14px;
    padding: 0 2px;
    line-height: 1;
    flex-shrink: 0;
    transition: color 0.2s;
}

.attached-file-badge .remove-file-btn:hover {
    color: var(--destructive);
}

.clear-all-attachments-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 11px;
    padding: 4px 8px;
    text-decoration: underline;
}

.clear-all-attachments-btn:hover {
    color: var(--text-primary);
}

/* ─── Slash Command Dropdown ─── */
.slash-dropdown {
    position: absolute;
    bottom: 100%;
    left: 0;
    right: 0;
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    background: var(--bg-elevated);
    border: 0.5px solid var(--border-color);
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    max-height: 280px;
    overflow-y: auto;
    z-index: 100;
    margin-bottom: 4px;
}

.slash-dropdown-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    margin: 2px 4px;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.1s;
}

.slash-dropdown-item:first-child {
    margin-top: 4px;
}

.slash-dropdown-item:last-child {
    margin-bottom: 4px;
}

.slash-dropdown-item:hover,
.slash-dropdown-item.selected {
    background: var(--accent-subtle);
}

.slash-dropdown-item .cmd-icon {
    font-size: 18px;
    flex-shrink: 0;
    width: 24px;
    text-align: center;
}

.slash-dropdown-item .cmd-info {
    flex: 1;
    min-width: 0;
}

.slash-dropdown-item .cmd-name {
    font-weight: 600;
    font-size: 13px;
    color: var(--accent);
}

.slash-dropdown-item .cmd-desc {
    font-size: 12px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ─── Chat Input ─── */
#chat-input {
    width: 100%;
    padding: 14px 16px;
    background: rgba(255, 255, 255, 0.8);
    border: 0.5px solid var(--border-color);
    border-radius: 12px;
    color: var(--text-primary);
    font-size: 14px;
    font-family: inherit;
    resize: vertical;
    min-height: 60px;
    transition: border-color 0.2s, box-shadow 0.2s;
}

#chat-input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--border-focus);
}

#chat-buttons {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 6px;
}

#attach-btn,
#open-claude-btn {
    width: 32px;
    height: 32px;
    padding: 0;
    background: transparent;
    color: var(--text-secondary);
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, color 0.15s;
    flex-shrink: 0;
}

#attach-btn:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

#open-claude-btn:hover {
    background: rgba(204, 119, 34, 0.1);
    color: #cc7722;
}

#send-btn {
    width: 34px;
    height: 34px;
    padding: 0;
    margin-left: auto;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, opacity 0.15s;
    flex-shrink: 0;
}

#send-btn:hover {
    background: var(--accent-hover);
}

#send-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

/* Spinner shown inside send button while streaming */
@keyframes btn-spin {
    to { transform: rotate(360deg); }
}

#send-btn.streaming svg {
    display: none;
}

#send-btn.streaming::after {
    content: '';
    display: block;
    width: 14px;
    height: 14px;
    border: 2px solid rgba(255, 255, 255, 0.35);
    border-top-color: white;
    border-radius: 50%;
    animation: btn-spin 0.65s linear infinite;
}

/* ─── Scrollbars ─── */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

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

::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.15);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.3);
}

/* ─── Loading ─── */
.loading {
    color: var(--text-secondary);
    font-style: italic;
}

/* ─── Explorer Icon ─── */
.tree-node-explorer {
    opacity: 0;
    margin-left: auto;
    padding: 2px 6px;
    cursor: pointer;
    font-size: 14px;
    transition: opacity 0.2s, background 0.2s;
    border-radius: var(--radius-sm);
    flex-shrink: 0;
}

.tree-node-header:hover .tree-node-explorer {
    opacity: 1;
}

.tree-node-explorer:hover {
    background: var(--accent-subtle);
}

.tree-node-delete:hover {
    background: rgba(220, 60, 60, 0.15);
}

/* ─── Cloud section action buttons ─── */
.tree-section-actions {
    display: flex;
    gap: 6px;
    padding: 4px 8px 6px 24px;
}

.tree-action-btn {
    font-size: 11px;
    padding: 2px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-secondary);
    color: var(--text-secondary);
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

.tree-action-btn:hover {
    background: var(--accent-subtle);
    color: var(--text-primary);
}

/* ─── Workspace tree extras ─── */
.workspace-stat-dot {
    font-size: 11px;
    margin-left: 6px;
    white-space: nowrap;
    flex-shrink: 0;
    opacity: 0.75;
}

.tree-node-concat-btn {
    opacity: 0;
    margin-left: 4px;
    padding: 2px 5px;
    cursor: pointer;
    font-size: 13px;
    transition: opacity 0.2s, background 0.2s;
    border-radius: var(--radius-sm);
    flex-shrink: 0;
    title: 'View all files as one document';
}

.tree-node-header:hover .tree-node-concat-btn {
    opacity: 1;
}

.tree-node-concat-btn:hover {
    background: var(--accent-subtle);
}

/* ─── Concat view ─── */
.concat-view-wrapper {
    padding: 20px 24px;
    overflow-y: auto;
    height: 100%;
}

/* Each REQ or DEL section — height is equalized between split panes after render */
.concat-section {
    box-sizing: border-box;
    overflow: hidden; /* prevent margin-collapse between sections */
}

.concat-view-wrapper h1 {
    padding: 6px 10px;
    margin: 16px 0 8px;
    border-radius: var(--radius-sm);
}

.concat-view-wrapper h1.concat-clickable-heading {
    cursor: pointer;
    transition: background 0.15s;
}

.concat-view-wrapper h1.concat-clickable-heading:hover {
    background: var(--accent-subtle);
}

/* Linked heading states (cross-pane hover/scroll) */
.concat-view-wrapper h1.linked-highlight {
    background: rgba(255, 149, 0, 0.12);
    outline: 1px solid rgba(255, 149, 0, 0.35);
}

.concat-view-wrapper h1.linked-active {
    background: rgba(255, 149, 0, 0.22);
    transition: background 0.6s ease-out;
}

/* ─── PDF Preview ─── */
.pdf-preview-frame {
    width: 100%;
    height: 100%;
    border: none;
    display: none;
}

.pdf-preview-frame.active {
    display: block;
}

/* Scroll sync button */
#scroll-sync-btn {
    padding: 3px 10px;
    font-size: 11px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-elevated);
    color: var(--text-secondary);
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    flex-shrink: 0;
}

#scroll-sync-btn:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

#scroll-sync-btn.active {
    background: rgba(255, 149, 0, 0.12);
    color: #FF9500;
    border-color: rgba(255, 149, 0, 0.4);
}

/* ─── Modals ─── */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    animation: modalFadeIn 0.2s;
}

@keyframes modalFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-content {
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    background: var(--bg-elevated);
    border: 0.5px solid var(--border-color);
    border-radius: var(--radius-lg);
    min-width: 400px;
    max-width: 500px;
    box-shadow: var(--shadow-float);
    animation: modalSlideIn 0.2s;
}

@keyframes modalSlideIn {
    from { transform: translateY(-20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.modal-header {
    padding: 20px 20px 8px;
}

.modal-header h3 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    letter-spacing: -0.03em;
    color: var(--text-primary);
}

.modal-body {
    padding: 12px 20px 20px;
    color: var(--text-primary);
    line-height: 1.6;
}

.modal-body p {
    margin: 8px 0;
}

.modal-body strong {
    color: var(--accent);
}

.modal-footer {
    padding: 16px 20px;
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

.modal-btn {
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    transition: all 0.2s;
}

.modal-btn-primary {
    background: var(--accent);
    color: white;
}

.modal-btn-primary:hover {
    background: var(--accent-hover);
}

.modal-btn-secondary {
    background: var(--destructive);
    color: white;
}

.modal-btn-secondary:hover {
    background: #E0352B;
}

.modal-btn-tertiary {
    background: rgba(0, 0, 0, 0.04);
    color: var(--text-primary);
    border: 0.5px solid var(--border-color);
}

.modal-btn-tertiary:hover {
    background: rgba(0, 0, 0, 0.08);
}

/* ─── Progress Bar ─── */
.progress-bar {
    width: 100%;
    height: 6px;
    background: rgba(0, 0, 0, 0.06);
    border-radius: var(--radius-md);
    overflow: hidden;
    margin: 16px 0;
    border: none;
}

.progress-bar-fill {
    height: 100%;
    background: var(--accent);
    border-radius: var(--radius-md);
    transition: width 0.3s ease;
    width: 0%;
}

#export-progress-text {
    text-align: center;
    font-size: 14px;
    color: var(--text-secondary);
    margin-top: 8px;
}

/* ─── Streaming Chat ─── */
.chat-message.streaming {
    border-left: 3px solid var(--accent);
}

.chat-stream-status {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--text-secondary);
    font-style: italic;
    padding: 4px 0;
}

.chat-stream-status::before {
    content: '';
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--accent);
    animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 0.3; transform: scale(0.85); }
    50% { opacity: 1; transform: scale(1.1); }
}

.chat-stream-content {
    white-space: pre-wrap;
    line-height: 1.5;
}

/* ─── Claude Handoff Message ─── */
.claude-handoff-message {
    padding: 14px;
    background: rgba(204, 119, 34, 0.06);
    border: 0.5px solid rgba(204, 119, 34, 0.2);
    border-radius: 12px;
}

.open-in-claude-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 18px;
    background: #cc7722;
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    transition: background 0.2s;
}

.open-in-claude-btn:hover:not(:disabled) {
    background: #b5691e;
}

.open-in-claude-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* ─── Approve All Bar ─── */
.memory-update-approve-all {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-top: 12px;
    margin-bottom: 4px;
    padding: 10px 14px;
    background: rgba(0, 122, 255, 0.06);
    border: 0.5px solid rgba(0, 122, 255, 0.18);
    border-radius: 10px;
}

.memory-update-approve-all span {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
}

.memory-update-approve-all .memory-update-approve {
    padding: 8px 20px;
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
}

/* ─── RAG Pipeline Details (collapsible) ─── */
.rag-pipeline-details {
    margin-bottom: 10px;
    padding: 6px 10px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-sm);
    font-size: 11px;
    color: var(--text-secondary);
    cursor: pointer;
}

.rag-pipeline-details summary {
    font-weight: 600;
    font-size: 11px;
    color: var(--text-secondary);
    list-style: none;
    display: flex;
    align-items: center;
    gap: 4px;
}

.rag-pipeline-details summary::before {
    content: '▸';
    display: inline-block;
    transition: transform 0.15s ease;
}

.rag-pipeline-details[open] summary::before {
    transform: rotate(90deg);
}

.rag-pipeline-steps {
    margin-top: 6px;
    padding-top: 6px;
    border-top: 0.5px solid var(--border-divider);
}

.rag-pipeline-step {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 2px 0;
    font-size: 11px;
    color: var(--text-secondary);
}

.rag-pipeline-time {
    color: var(--text-tertiary);
    font-variant-numeric: tabular-nums;
    margin-left: 12px;
    flex-shrink: 0;
}

.rag-pipeline-intent {
    color: var(--text-tertiary);
    font-style: italic;
    margin-top: 4px;
    padding-top: 4px;
    border-top: 0.5px solid var(--border-divider);
}

/* RAG citation superscripts */
.rag-citation {
    color: var(--accent, #6b9eff);
    cursor: pointer;
    font-size: 0.75em;
    font-weight: 600;
    vertical-align: super;
    margin: 0 1px;
    padding: 0 2px;
    border-radius: 3px;
    transition: background 0.15s;
}
.rag-citation:hover {
    background: rgba(107, 158, 255, 0.15);
    text-decoration: underline;
}

/* Sources footer */
.rag-sources-footer {
    margin-top: 12px;
    padding-top: 8px;
    border-top: 0.5px solid var(--border-divider);
    font-size: 0.85em;
}
.rag-sources-footer summary {
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 0.85em;
    user-select: none;
}
.rag-sources-footer summary:hover {
    color: var(--text-primary);
}
.rag-sources-list {
    margin: 6px 0 0 0;
    padding-left: 24px;
    color: var(--text-secondary);
}
.rag-sources-list li {
    margin: 3px 0;
    font-size: 0.9em;
}
.rag-source-link {
    color: var(--accent, #6b9eff);
    text-decoration: none;
    cursor: pointer;
}
.rag-source-link:hover {
    text-decoration: underline;
}
.file-update-link {
    color: var(--accent, #6b9eff);
    text-decoration: none;
    cursor: pointer;
}
.file-update-link:hover {
    text-decoration: underline;
}

/* Chat text content wrapper (for citation rendering) */
.chat-text-content {
    white-space: pre-wrap;
    word-wrap: break-word;
}

/* ─── Toast Notifications ─── */
#toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 9999;
    pointer-events: none;
}

.toast {
    padding: 10px 16px;
    border-radius: var(--radius-md);
    font-size: 13px;
    font-weight: 500;
    color: #fff;
    box-shadow: var(--shadow-md);
    opacity: 0;
    transform: translateY(8px);
    transition: opacity 0.2s ease, transform 0.2s ease;
    max-width: 320px;
}

.toast.toast-visible {
    opacity: 1;
    transform: translateY(0);
}

.toast-success { background: var(--success, #34C759); }
.toast-error   { background: var(--destructive, #FF3B30); }
.toast-info    { background: var(--accent, #007AFF); }

/* ── Change Tracking (Phase 3) ─────────────────────────────────────────────── */

/* Open changes badge in tree panel */
#open-changes-bar {
    padding: 6px 12px 2px;
}

.open-changes-badge {
    display: inline-block;
    background: var(--warning, #FF9500);
    color: #fff;
    font-size: 11px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 10px;
    cursor: default;
    letter-spacing: 0.02em;
}

/* Change badge on concat-view headings */
.change-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--warning, #FF9500);
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    margin-left: 6px;
    cursor: pointer;
    vertical-align: middle;
    flex-shrink: 0;
    transition: background 0.15s, transform 0.1s;
}

.change-badge:hover {
    background: #e08400;
    transform: scale(1.1);
}

/* REQ heading → DEL link chip */
.heading-del-link {
    display: inline-block;
    font-size: 11px;
    font-weight: 500;
    color: var(--accent, #6366f1);
    background: rgba(99, 102, 241, 0.09);
    border: 1px solid rgba(99, 102, 241, 0.2);
    padding: 1px 7px;
    border-radius: var(--radius-sm, 4px);
    margin-left: 8px;
    cursor: pointer;
    vertical-align: middle;
    transition: background 0.15s;
}
.heading-del-link:hover {
    background: rgba(99, 102, 241, 0.18);
}

/* DEL heading status chip */
.heading-status-chip {
    display: inline-block;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 1px 6px;
    border-radius: var(--radius-sm, 4px);
    margin-left: 8px;
    vertical-align: middle;
}
.heading-status-draft {
    background: rgba(156, 163, 175, 0.18);
    color: var(--text-secondary, #777);
}
.heading-status-approved {
    background: rgba(16, 185, 129, 0.14);
    color: #059669;
}

/* DEL heading stale badge */
.heading-stale-badge {
    display: inline-block;
    font-size: 10px;
    font-weight: 700;
    color: #d97706;
    background: rgba(217, 119, 6, 0.12);
    border: 1px solid rgba(217, 119, 6, 0.25);
    padding: 1px 6px;
    border-radius: var(--radius-sm, 4px);
    margin-left: 6px;
    vertical-align: middle;
}

/* Change diff modal overlay */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.change-diff-panel {
    background: var(--surface, #fff);
    border-radius: var(--radius-lg, 12px);
    box-shadow: var(--shadow-xl, 0 20px 60px rgba(0,0,0,0.25));
    width: min(800px, 92vw);
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.diff-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border, #e5e5e5);
    background: var(--surface-raised, #f9f9f9);
}

.diff-req-id {
    font-weight: 700;
    font-size: 14px;
}

.diff-source {
    font-size: 12px;
    color: var(--text-secondary, #666);
    flex: 1;
}

.diff-date {
    font-size: 11px;
    color: var(--text-tertiary, #999);
}

.diff-close-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 16px;
    color: var(--text-secondary, #666);
    padding: 2px 6px;
    border-radius: var(--radius-sm, 4px);
    line-height: 1;
}

.diff-close-btn:hover {
    background: var(--surface-hover, #eee);
}

.diff-linked-del {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 16px;
    border-bottom: 1px solid var(--border, #e5e5e5);
    background: var(--surface-raised, #f9f9f9);
    font-size: 12px;
}
.diff-linked-del-label { color: var(--text-secondary, #666); }
.diff-linked-del-chip {
    background: var(--accent, #6366f1);
    color: #fff;
    padding: 2px 8px;
    border-radius: var(--radius-sm, 4px);
    font-weight: 600;
    font-size: 12px;
}
.diff-open-del-btn {
    background: none;
    border: 1px solid var(--border, #e5e5e5);
    border-radius: var(--radius-sm, 4px);
    padding: 2px 8px;
    font-size: 11px;
    cursor: pointer;
    color: var(--text-secondary, #666);
}
.diff-open-del-btn:hover { background: var(--surface-hover, #eee); }

.diff-body {
    display: flex;
    flex: 1;
    overflow: hidden;
    min-height: 0;
}

.diff-col {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.diff-col + .diff-col {
    border-left: 1px solid var(--border, #e5e5e5);
}

.diff-label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 8px 14px 4px;
    color: var(--text-secondary, #666);
    background: var(--surface-raised, #f9f9f9);
    border-bottom: 1px solid var(--border, #e5e5e5);
}

.diff-before .diff-label { color: #c0392b; }
.diff-after  .diff-label { color: #27ae60; }

.diff-text {
    flex: 1;
    overflow-y: auto;
    padding: 12px 14px;
    font-size: 13px;
    line-height: 1.55;
    white-space: pre-wrap;
    word-break: break-word;
    color: var(--text, #1c1c1e);
}

.diff-before .diff-text { background: rgba(192, 57, 43, 0.04); }
.diff-after  .diff-text { background: rgba(39, 174, 96, 0.04); }

.diff-actions {
    display: flex;
    gap: 8px;
    padding: 12px 16px;
    border-top: 1px solid var(--border, #e5e5e5);
    background: var(--surface-raised, #f9f9f9);
    justify-content: flex-end;
}

/* Open changes dropdown list */
#open-changes-bar {
    position: relative;
}

.open-changes-list {
    position: absolute;
    left: 0;
    right: 0;
    top: 100%;
    background: var(--surface, #fff);
    border: 1px solid var(--border, #e5e5e5);
    border-radius: var(--radius-md, 8px);
    box-shadow: var(--shadow-md, 0 4px 16px rgba(0,0,0,0.12));
    z-index: 200;
    overflow: hidden;
    margin-top: 4px;
}

.open-changes-list-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 12px;
    cursor: pointer;
    font-size: 12px;
    border-bottom: 1px solid var(--border-subtle, #f0f0f0);
}

.open-changes-list-row:last-child { border-bottom: none; }
.open-changes-list-row:hover { background: var(--accent-subtle, #f0f6ff); }

.ocl-req {
    font-weight: 700;
    color: var(--warning, #e08400);
    flex-shrink: 0;
    min-width: 60px;
}

.ocl-source {
    flex: 1;
    color: var(--text-secondary, #555);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ocl-date {
    flex-shrink: 0;
    color: var(--text-tertiary, #999);
    font-size: 11px;
}

/* ── DEL action buttons in concat view ─────────────────────────────────────── */
.del-action-btn {
    display: inline-block;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding: 2px 8px;
    border-radius: var(--radius-sm, 4px);
    border: 1px solid currentColor;
    cursor: pointer;
    margin-left: 8px;
    vertical-align: middle;
    transition: opacity 0.15s, transform 0.1s;
}
.del-action-btn:disabled { opacity: 0.45; cursor: not-allowed; }
.del-action-btn:not(:disabled):hover { transform: scale(1.04); opacity: 0.85; }

.del-commit-btn {
    color: #2563eb;
    background: rgba(37, 99, 235, 0.07);
}
.del-done-btn {
    color: #059669;
    background: rgba(5, 150, 105, 0.07);
}

/* DEL heading status chips (committed / stale / done) */
.heading-status-committed {
    background: rgba(37, 99, 235, 0.1);
    color: #2563eb;
}
.heading-status-stale {
    background: rgba(217, 119, 6, 0.12);
    color: #d97706;
}
.heading-status-done {
    background: rgba(5, 150, 105, 0.1);
    color: #059669;
}

/* ── Tree status dots ───────────────────────────────────────────────────────── */
.tree-status-dot {
    display: inline-block;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    margin-left: 5px;
    flex-shrink: 0;
    vertical-align: middle;
    position: relative;
    top: -1px;
}
.tree-status-changed {
    background: var(--warning, #f59e0b);
    box-shadow: 0 0 0 2px rgba(245,158,11,0.18);
}
.tree-status-stale {
    background: #d97706;
    box-shadow: 0 0 0 2px rgba(217,119,6,0.18);
}

/* ── History button ─────────────────────────────────────────────────────────── */
.history-btn {
    background: none;
    border: 1px solid var(--border, #ddd);
    border-radius: var(--radius-sm, 4px);
    font-size: 10px;
    font-weight: 600;
    color: var(--text-secondary, #666);
    padding: 2px 7px;
    cursor: pointer;
    margin-left: 6px;
    vertical-align: middle;
    letter-spacing: 0.03em;
}
.history-btn:hover {
    background: var(--surface-hover, #eee);
    color: var(--text, #333);
}

/* ── History panel modal ────────────────────────────────────────────────────── */
.history-panel {
    background: var(--surface, #fff);
    border-radius: var(--radius-lg, 12px);
    box-shadow: var(--shadow-xl, 0 20px 60px rgba(0,0,0,0.25));
    width: min(900px, 94vw);
    max-height: 82vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.history-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border, #e5e5e5);
    background: var(--surface-raised, #f9f9f9);
    flex-shrink: 0;
}

.history-title {
    font-weight: 700;
    font-size: 15px;
    margin-right: 6px;
}

.history-filters {
    display: flex;
    gap: 4px;
}

.history-filter-btn {
    background: none;
    border: 1px solid var(--border, #ddd);
    border-radius: 20px;
    font-size: 11px;
    padding: 2px 10px;
    cursor: pointer;
    color: var(--text-secondary, #666);
    transition: background 0.15s, color 0.15s;
}
.history-filter-btn.active,
.history-filter-btn:hover {
    background: var(--accent, #6366f1);
    border-color: var(--accent, #6366f1);
    color: #fff;
}

.history-export-btn {
    margin-left: auto;
    background: none;
    border: 1px solid var(--border, #ddd);
    border-radius: var(--radius-sm, 4px);
    font-size: 11px;
    padding: 3px 9px;
    cursor: pointer;
    color: var(--text-secondary, #666);
}
.history-export-btn:hover { background: var(--surface-hover, #eee); }

.history-table-wrap {
    flex: 1;
    overflow: auto;
    min-height: 0;
}

.history-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}

.history-table thead th {
    position: sticky;
    top: 0;
    background: var(--surface-raised, #f9f9f9);
    border-bottom: 1px solid var(--border, #e5e5e5);
    padding: 8px 12px;
    text-align: left;
    font-weight: 600;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary, #666);
    white-space: nowrap;
}

.history-table tbody tr {
    border-bottom: 1px solid var(--border-subtle, #f0f0f0);
    cursor: pointer;
    transition: background 0.1s;
}
.history-table tbody tr:last-child { border-bottom: none; }
.history-table tbody tr:hover { background: var(--accent-subtle, #f0f6ff); }

.history-table td {
    padding: 7px 12px;
    vertical-align: middle;
    white-space: nowrap;
}

.history-td-id {
    font-family: monospace;
    font-size: 11px;
    color: var(--text-tertiary, #999);
}

.history-td-req {
    font-weight: 700;
    color: var(--warning, #d97706);
}

.history-td-source {
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--text-secondary, #555);
}

.history-td-date {
    color: var(--text-tertiary, #999);
    font-size: 11px;
}

.history-td-status-open {
    color: var(--warning, #e08400);
    font-weight: 600;
    font-size: 10px;
    text-transform: uppercase;
}
.history-td-status-resolved {
    color: #059669;
    font-weight: 600;
    font-size: 10px;
    text-transform: uppercase;
}

.history-td-delivery {
    font-size: 11px;
    color: var(--accent, #6366f1);
}

.history-empty {
    text-align: center;
    padding: 32px;
    color: var(--text-tertiary, #aaa);
    font-size: 13px;
}

/* ── Pipeline progress bar ──────────────────────────────────────────────────── */
.pipeline-progress { margin-top: 6px; width: 100%; }
.pipeline-step-label { font-size: 12px; color: var(--text-secondary, #555); }
.pipeline-count { font-size: 12px; color: var(--accent, #0066cc); }
.pipeline-progress-bar-track { height: 4px; background: var(--bg-tertiary, #e5e5e5); border-radius: 2px; overflow: hidden; margin-top: 4px; }
.pipeline-progress-bar-fill { height: 100%; background: var(--accent, #0066cc); border-radius: 2px; transition: width 0.4s ease; width: 0%; }

/* ── API Settings Modal ────────────────────────────────────────────────────── */
#api-settings-btn {
    position: relative;
}
#api-settings-btn.api-active::after {
    content: '';
    position: absolute;
    top: 4px;
    right: 4px;
    width: 7px;
    height: 7px;
    background: var(--success, #34C759);
    border-radius: 50%;
    border: 1px solid white;
}
.settings-group {
    margin-bottom: 16px;
}
.settings-label {
    display: block;
    font-weight: 600;
    font-size: 13px;
    margin-bottom: 6px;
    color: var(--text-primary);
}
.settings-radio-group {
    display: flex;
    gap: 16px;
}
.settings-radio {
    font-size: 13px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 4px;
}
.settings-hint {
    font-size: 11px;
    color: var(--text-secondary);
    margin-top: 4px;
}
.settings-checkbox {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--text-secondary);
    cursor: pointer;
}
.settings-input-row {
    display: flex;
    align-items: center;
}
.settings-input {
    flex: 1;
    padding: 6px 10px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 13px;
    background: var(--bg-primary);
    color: var(--text-primary);
}
.settings-input:focus {
    outline: none;
    border-color: var(--border-focus);
}
.settings-select {
    width: 100%;
    padding: 6px 10px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 13px;
    background: var(--bg-primary);
    color: var(--text-primary);
}
.settings-status {
    font-size: 12px;
    margin-top: 4px;
}
.settings-status.ok {
    color: var(--success, #34C759);
}
.settings-status.error {
    color: var(--destructive, #FF3B30);
}

/* ── Import modal project list ─────────────────────────────────────────────── */
.import-project-item {
    padding: 8px 12px;
    cursor: pointer;
    font-size: 13px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 6px;
    transition: background 0.15s;
}
.import-project-item:last-child { border-bottom: none; }
.import-project-item:hover { background: var(--hover-bg, rgba(0,0,0,0.04)); }
.import-project-item.selected {
    background: var(--accent-bg, rgba(0, 122, 255, 0.1));
    color: var(--accent, #007AFF);
    font-weight: 500;
}

/* ── Reasoning block (Hybrid mode) ─────────────────────────────────────────── */
.reasoning-block {
    background: rgba(0, 122, 255, 0.06);
    border-left: 3px solid var(--accent, #007AFF);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    padding: 10px 14px;
    margin-bottom: 12px;
    font-size: 13px;
    color: var(--text-primary);
    white-space: pre-wrap;
}
.reasoning-header {
    font-size: 11px;
    font-weight: 600;
    color: var(--accent, #007AFF);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 6px;
}
.reasoning-divider {
    border: none;
    border-top: 1px dashed var(--border-divider);
    margin: 12px 0;
}

/* ── File History Modal ────────────────────────────────────────────────────── */

.file-history-panel {
    background: var(--surface, #fff);
    border-radius: var(--radius-lg, 12px);
    box-shadow: var(--shadow-xl, 0 20px 60px rgba(0,0,0,0.25));
    width: min(960px, 94vw);
    height: min(600px, 80vh);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.file-history-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border, #e5e5e5);
    background: var(--surface-raised, #f9f9f9);
}

.file-history-title {
    font-weight: 700;
    font-size: 14px;
}

.file-history-info {
    padding: 6px 16px;
    font-size: 11px;
    color: var(--text-secondary, #888);
    background: var(--surface, #f5f5f5);
    border-bottom: 1px solid var(--border, #e5e5e5);
}

.file-history-filename {
    font-size: 12px;
    color: var(--text-secondary, #666);
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.file-history-body {
    display: flex;
    flex: 1;
    overflow: hidden;
}

.file-history-list {
    width: 280px;
    min-width: 200px;
    border-right: 1px solid var(--border, #e5e5e5);
    overflow-y: auto;
    flex-shrink: 0;
}

.file-history-empty {
    padding: 24px 16px;
    text-align: center;
    color: var(--text-tertiary, #999);
    font-size: 13px;
}

.file-history-entry {
    padding: 10px 14px;
    border-bottom: 1px solid var(--border-light, #f0f0f0);
    cursor: pointer;
    font-size: 12px;
    transition: background 0.1s;
}

.file-history-entry:hover {
    background: var(--surface-hover, #f5f5f5);
}

.file-history-entry.active {
    background: var(--accent-bg, #e8f0fe);
    border-left: 3px solid var(--accent, #3b82f6);
}

.file-history-entry-date {
    font-weight: 600;
    color: var(--text-primary, #222);
    margin-bottom: 2px;
}

.file-history-entry-source {
    color: var(--text-secondary, #666);
    font-size: 11px;
}

.file-history-preview {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.file-history-preview-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    border-bottom: 1px solid var(--border-light, #f0f0f0);
    font-size: 12px;
    color: var(--text-secondary, #666);
}

.file-history-diff {
    flex: 1;
    overflow-y: auto;
    padding: 12px 16px;
    font-family: var(--font-mono, 'SF Mono', 'Menlo', monospace);
    font-size: 12px;
    line-height: 1.5;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.diff-line { padding: 1px 6px; }
.diff-line-add { background: #e6ffec; color: #1a7f37; }
.diff-line-del { background: #ffebe9; color: #cf222e; }
.diff-line-ctx { color: var(--text-secondary, #666); }
.diff-line-hdr { color: var(--accent, #3b82f6); font-weight: 600; padding-top: 8px; }
