/* ── DocuGen Studio — Light & Clean Design System ─────────────────────────── */

/* ── CSS Variables ─────────────────────────────────────────────────────────── */
:root {
    --background: #f6f8fa;
    --foreground: #24292e;
    --card: #ffffff;
    --card-hover: #f6f8fa;
    --border: #d1d9e0;
    --border-light: #e8ecf0;
    --input: #ffffff;
    --input-border: #d1d9e0;
    --primary: #0969da;
    --primary-hover: #0860ca;
    --primary-foreground: #ffffff;
    --primary-light: #dbeafe;
    --muted-foreground: #57606a;
    --muted: #f6f8fa;
    --success: #1a7f37;
    --success-light: #dcfce7;
    --warning: #9a6700;
    --warning-light: #fff8c5;
    --destructive: #cf222e;
    --destructive-light: #fee2e2;
    --radius: 6px;
    --radius-lg: 10px;

    /* Category colors */
    --cat-arch: #3b82f6;
    --cat-uml: #8b5cf6;
    --cat-deploy: #f59e0b;
    --cat-code: #ef4444;
    --cat-data: #14b8a6;
    --cat-strategic: #6366f1;
    --cat-ai: #10b981;
    --cat-doc: #0ea5e9;

    /* Layout */
    --header-height: 52px;
    --drawer-width: 272px;
    --drawer-collapsed-width: 44px;
    --gen-log-height: 40px;
    --gen-log-expanded-height: 340px;
}

/* ── Reset ─────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { height: 100%; }
body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    font-size: 13px;
    color: var(--foreground);
    background: var(--background);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* ── App Header ─────────────────────────────────────────────────────────────── */
.app-header {
    height: var(--header-height);
    background: var(--card);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0 1rem;
    flex-shrink: 0;
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
    z-index: 100;
}

.header-brand { display: flex; align-items: center; gap: 0.6rem; flex-shrink: 0; }
.header-logo {
    width: 30px; height: 30px;
    background: var(--primary);
    border-radius: 7px;
    display: flex; align-items: center; justify-content: center;
}
.header-logo svg { width: 16px; height: 16px; stroke: #fff; }
.header-title { display: flex; flex-direction: column; }
.header-product { font-size: 0.875rem; font-weight: 700; color: var(--foreground); line-height: 1.1; }
.header-tagline { font-size: 0.65rem; color: var(--muted-foreground); }

.header-center { flex: 1; display: flex; justify-content: center; position: relative; }

/* Project Switcher */
.project-switcher {
    display: flex; align-items: center; gap: 0.4rem;
    padding: 0.35rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 0.8rem;
    color: var(--foreground);
    background: var(--background);
    transition: border-color 0.15s, background 0.15s;
    user-select: none;
}
.project-switcher:hover { border-color: var(--primary); background: var(--card); }
.project-icon { width: 14px; height: 14px; color: var(--muted-foreground); }
.chevron-icon { width: 12px; height: 12px; color: var(--muted-foreground); }

.project-dropdown {
    position: absolute; top: calc(100% + 6px); left: 50%; transform: translateX(-50%);
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: 0 8px 24px rgba(0,0,0,0.12);
    min-width: 260px;
    z-index: 1000;
    overflow: hidden;
}
.project-dropdown-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 0.6rem 0.875rem;
    border-bottom: 1px solid var(--border);
    font-size: 0.75rem; font-weight: 600; color: var(--muted-foreground);
    background: var(--muted);
}
.btn-new-project {
    font-size: 0.72rem; font-weight: 500; color: var(--primary);
    background: none; border: none; cursor: pointer; padding: 0;
}
.btn-new-project:hover { text-decoration: underline; }
.project-list { max-height: 280px; overflow-y: auto; }
.project-list-loading { padding: 1rem; text-align: center; color: var(--muted-foreground); font-size: 0.75rem; }
.project-item {
    display: flex; align-items: center; gap: 0.5rem;
    padding: 0.6rem 0.875rem;
    cursor: pointer;
    transition: background 0.1s;
    border-bottom: 1px solid var(--border-light);
}
.project-item:hover { background: var(--muted); }
.project-item.active { background: var(--primary-light); }
.project-item-name { font-size: 0.82rem; font-weight: 500; flex: 1; }
.project-item-meta { font-size: 0.7rem; color: var(--muted-foreground); }

.header-actions { display: flex; align-items: center; gap: 0.75rem; flex-shrink: 0; }
.header-user { display: flex; align-items: center; gap: 0.35rem; font-size: 0.78rem; color: var(--muted-foreground); }
.btn-logout {
    font-size: 0.75rem; padding: 0.3rem 0.6rem;
    border: 1px solid var(--border); border-radius: var(--radius);
    color: var(--muted-foreground); text-decoration: none;
    transition: color 0.15s, border-color 0.15s;
}
.btn-logout:hover { color: var(--foreground); border-color: var(--foreground); }

/* ── Panel Container ─────────────────────────────────────────────────────────── */
.panel-container {
    flex: 1;
    display: flex;
    overflow: hidden;
    position: relative;
}

/* ── Drawers ─────────────────────────────────────────────────────────────────── */
.drawer {
    width: var(--drawer-width);
    flex-shrink: 0;
    background: var(--card);
    border-color: var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: width 0.25s ease;
    position: relative;
    z-index: 10;
}
.drawer-left { border-right: 1px solid var(--border); }
.drawer-right { border-left: 1px solid var(--border); }

.drawer.collapsed { width: var(--drawer-collapsed-width); }
.drawer.collapsed .drawer-body { display: none; }
.drawer.collapsed .drawer-title { display: none; }

/* Right drawer collapsed — only show the toggle button, centered */
.drawer-right.collapsed .drawer-header {
    padding: 0;
    justify-content: center;
}
.drawer-right.collapsed .drawer-header-icon { display: none; }

.drawer-header {
    height: 44px;
    display: flex; align-items: center; gap: 0.5rem;
    padding: 0 0.75rem;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    background: var(--muted);
}
.drawer-header-icon {
    width: 26px; height: 26px; border-radius: 6px;
    display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.knowledge-icon { background: #eff6ff; }
.knowledge-icon svg { width: 14px; height: 14px; stroke: var(--cat-arch); }
.context-icon { background: #f0fdf4; }
.context-icon svg { width: 14px; height: 14px; stroke: var(--cat-ai); }

.drawer-title { font-size: 0.8rem; font-weight: 600; flex: 1; white-space: nowrap; overflow: hidden; }
.drawer-collapse-btn {
    background: none; border: none; cursor: pointer; padding: 4px;
    color: var(--muted-foreground); border-radius: 4px;
    display: flex; align-items: center; transition: color 0.15s;
}
.drawer-collapse-btn:hover { color: var(--foreground); }

.drawer-body { flex: 1; overflow-y: auto; display: flex; flex-direction: column; }

/* Drawer Tabs */
.drawer-tabs {
    display: flex; border-bottom: 1px solid var(--border);
    flex-shrink: 0; background: var(--card);
}
.drawer-tab {
    flex: 1; padding: 0.5rem 0;
    font-size: 0.75rem; font-weight: 500;
    color: var(--muted-foreground); background: none; border: none;
    border-bottom: 2px solid transparent;
    cursor: pointer; transition: color 0.15s, border-color 0.15s;
}
.drawer-tab:hover { color: var(--foreground); }
.drawer-tab.active { color: var(--primary); border-bottom-color: var(--primary); }

.drawer-tab-panel { flex: 1; overflow-y: auto; }

/* ── Knowledge Store Doc List ────────────────────────────────────────────────── */
.ks-doc-list { padding: 0.5rem 0; }
.ks-empty { padding: 1.5rem 1rem; text-align: center; color: var(--muted-foreground); font-size: 0.75rem; line-height: 1.6; }

.ks-folder { }
.ks-folder-name {
    display: flex; align-items: center; gap: 0.4rem;
    padding: 0.35rem 0.875rem;
    font-size: 0.7rem; font-weight: 600; text-transform: uppercase;
    letter-spacing: 0.05em; color: var(--muted-foreground);
    background: var(--muted);
}
.ks-folder-name svg { width: 12px; height: 12px; }

.ks-doc-item {
    display: flex; align-items: center; gap: 0.5rem;
    padding: 0.45rem 0.875rem;
    border-left: 2px solid transparent;
    transition: background 0.1s, border-color 0.15s;
    cursor: pointer;
}
.ks-doc-item:hover { background: var(--muted); }
.ks-doc-item.included { border-left-color: var(--success); background: #f0fdf4; }
.ks-doc-name { flex: 1; font-size: 0.78rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Toggle Switch */
.toggle-switch { position: relative; width: 28px; height: 16px; flex-shrink: 0; }
.toggle-switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.toggle-track {
    position: absolute; inset: 0;
    background: var(--border); border-radius: 8px;
    cursor: pointer; transition: background 0.2s;
}
.toggle-track::after {
    content: ''; position: absolute;
    width: 12px; height: 12px; left: 2px; top: 2px;
    background: #fff; border-radius: 50%;
    transition: transform 0.2s;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
.toggle-switch input:checked + .toggle-track { background: var(--success); }
.toggle-switch input:checked + .toggle-track::after { transform: translateX(12px); }

/* Add tab */
.ks-add-content { padding: 0.875rem; display: flex; flex-direction: column; gap: 0.875rem; }
.ks-add-hint { font-size: 0.75rem; color: var(--muted-foreground); }

/* ── Context Drawer ─────────────────────────────────────────────────────────── */
.ctx-section { padding: 0.875rem; border-bottom: 1px solid var(--border-light); }
.ctx-section-label {
    font-size: 0.7rem; font-weight: 600; text-transform: uppercase;
    letter-spacing: 0.05em; color: var(--muted-foreground);
    margin-bottom: 0.5rem; display: flex; align-items: center; gap: 0.4rem;
}
.ctx-token-row { display: flex; align-items: center; gap: 0.5rem; }
.ctx-token-bar {
    flex: 1; height: 6px; background: var(--border);
    border-radius: 3px; overflow: hidden;
}
.ctx-token-bar-fill {
    height: 100%; background: var(--primary); border-radius: 3px;
    transition: width 0.3s, background 0.3s;
}
.ctx-token-bar-fill.amber { background: #f59e0b; }
.ctx-token-bar-fill.red { background: var(--destructive); }
.ctx-token-label { font-size: 0.7rem; color: var(--muted-foreground); white-space: nowrap; }

.ctx-included-list { display: flex; flex-direction: column; gap: 0.25rem; }
.ctx-empty { font-size: 0.73rem; color: var(--muted-foreground); line-height: 1.5; }

/* Context doc rows */
.ctx-doc-row { border-radius: 5px; overflow: hidden; background: var(--primary-light); }
.ctx-doc-main {
    display: flex; align-items: center; gap: 0.35rem;
    padding: 0.32rem 0.45rem;
    font-size: 0.72rem; color: var(--primary);
}
.ctx-doc-expand {
    background: none; border: none; cursor: pointer; padding: 1px;
    color: var(--muted-foreground); display: flex; align-items: center;
    transition: transform 0.15s, color 0.15s; flex-shrink: 0;
}
.ctx-doc-expand:hover { color: var(--primary); }
.ctx-doc-expand.open { transform: rotate(180deg); color: var(--primary); }
.ctx-doc-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.ctx-doc-tokens { font-size: 0.65rem; color: var(--muted-foreground); white-space: nowrap; flex-shrink: 0; }
.ctx-doc-remove {
    background: none; border: none; cursor: pointer;
    color: var(--muted-foreground); padding: 0; line-height: 1;
    transition: color 0.15s; flex-shrink: 0;
}
.ctx-doc-remove:hover { color: var(--destructive); }

/* Sections list (collapsed by default, expands with .open) */
.ctx-doc-sections {
    display: none; padding: 0.3rem 0.5rem 0.4rem 1.6rem;
    border-top: 1px solid rgba(0,0,0,0.06);
}
.ctx-doc-sections.open { display: block; }
.ctx-sec-item {
    display: flex; align-items: baseline; gap: 0.35rem;
    padding: 0.15rem 0; font-size: 0.69rem; color: var(--muted-foreground);
}
.ctx-sec-h2 { color: var(--foreground); font-weight: 500; }
.ctx-sec-h3 { padding-left: 0.75rem; }
.ctx-sec-bullet {
    width: 4px; height: 4px; border-radius: 50%;
    background: currentColor; flex-shrink: 0; margin-top: 1px;
}
.ctx-sec-h3 .ctx-sec-bullet { width: 3px; height: 3px; opacity: 0.5; }
.ctx-sec-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Settings button (gear icon) */
.ctx-doc-settings-btn {
    background: none; border: none; cursor: pointer; padding: 1px;
    color: var(--muted-foreground); display: flex; align-items: center;
    transition: color 0.15s; flex-shrink: 0; border-radius: 3px;
}
.ctx-doc-settings-btn:hover, .ctx-doc-settings-btn.open { color: var(--primary); }
.ctx-doc-settings-btn.active { color: var(--primary); opacity: 0.8; }

/* Per-doc settings panel */
.ctx-doc-settings {
    display: none; padding: 0.5rem 0.6rem 0.55rem;
    border-top: 1px solid rgba(0,0,0,0.06);
    background: rgba(255,255,255,0.6);
}
.ctx-doc-settings.open { display: block; }
.ctx-sett-field { margin-bottom: 0.4rem; }
.ctx-sett-field:last-of-type { margin-bottom: 0; }
.ctx-sett-label {
    display: block; font-size: 0.62rem; font-weight: 600;
    text-transform: uppercase; letter-spacing: 0.04em;
    color: var(--muted-foreground); margin-bottom: 0.2rem;
}
.ctx-sett-input, .ctx-sett-textarea {
    width: 100%; font-size: 0.72rem; line-height: 1.45;
    color: var(--foreground); background: var(--background);
    border: 1px solid var(--border); border-radius: 4px;
    padding: 0.28rem 0.4rem; resize: none;
    font-family: inherit; transition: border-color 0.15s;
}
.ctx-sett-input:focus, .ctx-sett-textarea:focus {
    outline: none; border-color: var(--primary);
}
.ctx-sett-saved {
    font-size: 0.62rem; color: var(--primary); margin-top: 0.25rem;
    display: none; text-align: right;
}
.ctx-sett-saved.visible { display: block; }

/* Generation Themes section */
.ctx-themes-section {}
.ctx-themes-grid {
    display: grid; grid-template-columns: 1fr 1fr; gap: 0.35rem;
}
.ctx-theme-field {}
.ctx-theme-full { grid-column: 1 / -1; }
.ctx-theme-label {
    display: block; font-size: 0.62rem; font-weight: 600;
    text-transform: uppercase; letter-spacing: 0.04em;
    color: var(--muted-foreground); margin-bottom: 0.15rem;
}
.ctx-theme-input {
    width: 100%; font-size: 0.72rem; padding: 0.28rem 0.4rem;
    border: 1px solid var(--border); border-radius: 4px;
    background: var(--input); color: var(--foreground);
    font-family: inherit; transition: border-color 0.15s;
}
.ctx-theme-input:focus { outline: none; border-color: var(--primary); }

.ctx-instructions { flex: 1; }
.ctx-instructions-editor {
    width: 100%; min-height: 120px; max-height: 300px;
    padding: 0.5rem; font-size: 0.78rem; line-height: 1.5;
    color: var(--foreground); background: var(--input);
    border: 1px solid var(--input-border); border-radius: var(--radius);
    resize: vertical; outline: none;
    transition: border-color 0.15s, box-shadow 0.15s;
    font-family: inherit;
}
.ctx-instructions-editor:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(9,105,218,0.1); }
.ctx-autosave-badge {
    font-size: 0.65rem; font-weight: 500; color: var(--success);
    background: var(--success-light); padding: 0.1rem 0.4rem; border-radius: 3px;
}

/* ── Catalog Panel ─────────────────────────────────────────────────────────── */
.catalog-panel {
    flex: 1;
    display: flex; flex-direction: column;
    overflow: hidden;
    background: var(--background);
}

/* Catalog Toolbar */
.catalog-toolbar {
    display: flex; align-items: center; gap: 0.75rem;
    padding: 0.625rem 1rem;
    background: var(--card);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.catalog-search-wrap {
    position: relative; display: flex; align-items: center; flex-shrink: 0;
}
.search-icon {
    position: absolute; left: 0.6rem; width: 14px; height: 14px;
    color: var(--muted-foreground); pointer-events: none;
}
.catalog-search {
    padding: 0.375rem 0.75rem 0.375rem 2rem;
    font-size: 0.8rem; width: 200px;
    border: 1px solid var(--border); border-radius: var(--radius);
    background: var(--input); outline: none;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.catalog-search:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(9,105,218,0.1); }

.category-pills { display: flex; gap: 0.35rem; flex: 1; flex-wrap: wrap; overflow: hidden; }
.category-pill {
    padding: 0.25rem 0.6rem; font-size: 0.72rem; font-weight: 500;
    border: 1px solid var(--border); border-radius: 20px;
    background: var(--card); color: var(--muted-foreground);
    cursor: pointer; white-space: nowrap; transition: all 0.15s;
}
.category-pill:hover { border-color: var(--primary); color: var(--primary); }
.category-pill.active { background: var(--primary); border-color: var(--primary); color: var(--primary-foreground); }

.catalog-actions { display: flex; align-items: center; gap: 0.6rem; flex-shrink: 0; }
.selection-badge {
    font-size: 0.75rem; font-weight: 600;
    color: var(--primary); background: var(--primary-light);
    padding: 0.2rem 0.6rem; border-radius: 20px;
    white-space: nowrap;
}

/* Catalog Grid Container */
.catalog-grid-container {
    flex: 1; overflow-y: auto;
    padding: 1rem;
}

.catalog-loading {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    height: 200px; gap: 0.75rem; color: var(--muted-foreground);
}
.loading-spinner {
    width: 24px; height: 24px;
    border: 2px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.75s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Category section */
.catalog-category { margin-bottom: 1.5rem; }
.catalog-category-header {
    display: flex; align-items: center; gap: 0.5rem;
    margin-bottom: 0.75rem;
}
.catalog-category-dot {
    width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0;
}
.catalog-category-name {
    font-size: 0.8rem; font-weight: 600; color: var(--foreground);
}
.catalog-category-count {
    font-size: 0.7rem; color: var(--muted-foreground);
    background: var(--border-light); padding: 0.1rem 0.4rem; border-radius: 20px;
}

/* Card Grid */
.catalog-card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 0.75rem;
}

/* Catalog Card */
.catalog-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.875rem;
    cursor: pointer;
    transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
    position: relative;
    overflow: hidden;
}
.catalog-card:hover { border-color: var(--primary); box-shadow: 0 2px 8px rgba(9,105,218,0.1); }
.catalog-card.selected {
    border-color: var(--primary);
    background: #f0f7ff;
    box-shadow: 0 0 0 2px rgba(9,105,218,0.2);
}

.catalog-card-checkbox {
    position: absolute; top: 0.6rem; right: 0.6rem;
    width: 16px; height: 16px;
    border: 1.5px solid var(--border); border-radius: 4px;
    background: var(--card); display: flex; align-items: center; justify-content: center;
    transition: background 0.15s, border-color 0.15s;
}
.catalog-card.selected .catalog-card-checkbox {
    background: var(--primary); border-color: var(--primary);
}
.catalog-card-checkbox-check {
    width: 10px; height: 10px;
    stroke: #fff; display: none;
}
.catalog-card.selected .catalog-card-checkbox-check { display: block; }

.catalog-card-icon {
    width: 32px; height: 32px; border-radius: 7px;
    display: flex; align-items: center; justify-content: center;
    margin-bottom: 0.6rem;
}
.catalog-card-icon svg { width: 16px; height: 16px; }

.catalog-card-title { font-size: 0.8rem; font-weight: 600; margin-bottom: 0.3rem; line-height: 1.3; padding-right: 1.2rem; }
.catalog-card-desc { font-size: 0.72rem; color: var(--muted-foreground); line-height: 1.4; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.catalog-card-file { font-size: 0.65rem; color: var(--muted-foreground); margin-top: 0.5rem; font-family: monospace; }

/* State Pills (Current/Future) */
.catalog-card-states {
    display: flex; gap: 0.3rem; margin-top: 0.6rem;
}
.state-pill {
    padding: 0.15rem 0.5rem; font-size: 0.65rem; font-weight: 500;
    border-radius: 20px; border: 1px solid; cursor: pointer;
    transition: all 0.15s;
}
.state-pill.current { border-color: var(--primary); color: var(--primary); background: transparent; }
.state-pill.current.active { background: var(--primary); color: #fff; }
.state-pill.future { border-color: var(--cat-uml); color: var(--cat-uml); background: transparent; }
.state-pill.future.active { background: var(--cat-uml); color: #fff; }

/* ── Output Navigator (right drawer cards) ───────────────────────────────────── */
.output-icon { background: #fef3c7; }
.output-icon svg { stroke: #d97706; }

.output-cards {
    overflow-y: auto;
    flex: 1;
    padding: 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}
.output-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    padding: 2rem 1rem;
    font-size: 0.75rem;
    color: var(--muted-foreground);
    text-align: center;
    line-height: 1.6;
}
.out-card {
    background: var(--card);
    border: 1px solid var(--border-light);
    border-radius: 8px;
    padding: 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}
.out-card-cat {
    display: inline-flex;
    align-items: center;
    padding: 0.15rem 0.5rem;
    border-radius: 20px;
    border: 1px solid;
    font-size: 0.65rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    width: fit-content;
}
.out-card-title {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--foreground);
    line-height: 1.3;
}
.out-card-desc {
    font-size: 0.7rem;
    color: var(--muted-foreground);
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.out-card-meta {
    font-size: 0.67rem;
    color: var(--muted-foreground);
}
.out-card-actions {
    display: flex;
    gap: 0.4rem;
    margin-top: 0.25rem;
}
.out-card-open {
    flex: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.3rem;
    padding: 0.3rem 0.5rem;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 5px;
    font-size: 0.72rem;
    font-weight: 500;
    cursor: pointer;
}
.out-card-open:hover { opacity: 0.88; }
.out-card-dl {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.3rem;
    padding: 0.3rem 0.5rem;
    background: none;
    border: 1px solid var(--border);
    border-radius: 5px;
    font-size: 0.72rem;
    color: var(--muted-foreground);
    cursor: pointer;
}
.out-card-dl:hover { border-color: var(--primary); color: var(--primary); }
.out-card-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.4rem;
}
.out-card-del {
    flex-shrink: 0;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--muted-foreground);
    padding: 0.2rem;
    border-radius: 4px;
    line-height: 1;
    opacity: 0;
    transition: opacity 0.15s, color 0.15s;
}
.out-card:hover .out-card-del { opacity: 1; }
.out-card-del:hover { color: #dc2626; }
.out-card-share {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.3rem;
    padding: 0.3rem 0.5rem;
    background: none;
    border: 1px solid #a7f3d0;
    border-radius: 5px;
    font-size: 0.72rem;
    color: #065f46;
    cursor: pointer;
}
.out-card-share:hover { background: #ecfdf5; border-color: #059669; }

/* ── Task Panel (right drawer, during generation) ────────────────────────────── */
.task-panel {
    border-bottom: 1px solid var(--border);
    background: var(--muted);
    flex-shrink: 0;
}
.task-panel-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--border-light);
}
.task-panel-title {
    flex: 1;
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--foreground);
    letter-spacing: 0.03em;
}
.task-cancel-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.2rem 0.45rem;
    font-size: 0.67rem;
    background: none;
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--muted-foreground);
    cursor: pointer;
}
.task-cancel-btn:hover { border-color: #ef4444; color: #ef4444; }

.task-list { padding: 0.35rem 0.5rem; display: flex; flex-direction: column; gap: 0.2rem; }

.task-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.35rem 0.4rem;
    border-radius: 6px;
    font-size: 0.75rem;
    transition: background 0.15s;
}
.task-item.running { background: #eff6ff; }
.task-item.done    { background: #f0fdf4; }
.task-item.warning { background: #fff7ed; }
.task-item.error   { background: #fef2f2; }

.task-item-icon { flex-shrink: 0; width: 16px; height: 16px; display: flex; align-items: center; justify-content: center; }
.task-item-title { flex: 1; line-height: 1.3; color: var(--foreground); }
.task-item.done    .task-item-title { color: #15803d; }
.task-item.running .task-item-title { color: #1d4ed8; font-weight: 600; }
.task-item.warning .task-item-title { color: #c2410c; }
.task-item.error   .task-item-title { color: #b91c1c; }

/* Spinner for running task */
@keyframes task-spin { to { transform: rotate(360deg); } }
.task-spinner {
    width: 13px; height: 13px;
    border: 2px solid #bfdbfe;
    border-top-color: #1d4ed8;
    border-radius: 50%;
    animation: task-spin 0.7s linear infinite;
}

/* ── Generation Log ─────────────────────────────────────────────────────────── */
.generation-log {
    height: var(--gen-log-height);
    border-top: 1px solid var(--border);
    background: var(--card);
    flex-shrink: 0;
    overflow: hidden;
    transition: height 0.25s ease;
}
.generation-log.expanded { height: var(--gen-log-expanded-height); }

.generation-log-bar {
    height: var(--gen-log-height);
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 1rem;
    cursor: pointer;
    user-select: none;
}
.gen-log-left { display: flex; align-items: center; gap: 0.5rem; }
.gen-log-title { font-size: 0.78rem; font-weight: 600; }
.gen-log-status {
    font-size: 0.7rem; padding: 0.15rem 0.5rem;
    border-radius: 20px; font-weight: 500;
}
.gen-log-status.running { background: #fef9c3; color: #92400e; }
.gen-log-status.complete { background: var(--success-light); color: var(--success); }
.gen-log-status.error { background: var(--destructive-light); color: var(--destructive); }

.gen-log-right { display: flex; align-items: center; gap: 0.4rem; }
.gen-log-expand-hint { font-size: 0.7rem; color: var(--muted-foreground); }
.gen-log-chevron { transition: transform 0.2s; }
.generation-log.expanded .gen-log-chevron { transform: rotate(180deg); }

.generation-log-content {
    height: calc(var(--gen-log-expanded-height) - var(--gen-log-height));
    overflow-y: auto; padding: 0.5rem 1rem;
    font-family: 'SF Mono', 'Cascadia Code', Consolas, monospace;
    font-size: 0.72rem; line-height: 1.6;
    background: #fafbfc;
}
.log-entry { padding: 0.15rem 0; border-bottom: 1px solid var(--border-light); }
.log-entry:last-child { border-bottom: none; }
.log-entry.log-message { color: var(--foreground); }
.log-entry.log-tool { color: var(--muted-foreground); }
.log-entry.log-success { color: var(--success); }
.log-entry.log-error { color: var(--destructive); }
.log-entry.log-init { color: var(--primary); }

/* gen-log-entry classes used by generation-log.js */
.gen-log-entry { display: flex; gap: 0.5rem; padding: 0.18rem 0; align-items: baseline; }
.gen-log-time { color: var(--muted-foreground); flex-shrink: 0; font-size: 0.67rem; }
.gen-log-text { flex: 1; word-break: break-word; }
.gen-log-entry-log .gen-log-text { color: var(--foreground); }
.gen-log-entry-tool .gen-log-text { color: #6366f1; font-size: 0.68rem; }
.gen-log-entry-status .gen-log-text { color: var(--primary); font-weight: 500; }
.gen-log-entry-step .gen-log-text { color: var(--foreground); font-weight: 600; border-left: 2px solid var(--primary); padding-left: 0.4rem; }
.gen-log-entry-success .gen-log-text { color: var(--success); }
.gen-log-entry-complete .gen-log-text { color: var(--success); font-weight: 600; }
.gen-log-entry-error .gen-log-text { color: var(--destructive); font-weight: 500; }

/* ── Forms ──────────────────────────────────────────────────────────────────── */
.form-field { display: flex; flex-direction: column; gap: 0.35rem; }
.field-label { font-size: 0.78rem; font-weight: 500; color: var(--foreground); }
.field-input {
    padding: 0.45rem 0.625rem; font-size: 0.8rem;
    border: 1px solid var(--input-border); border-radius: var(--radius);
    background: var(--input); outline: none; color: var(--foreground);
    transition: border-color 0.15s, box-shadow 0.15s;
}
.field-input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(9,105,218,0.1); }
.field-textarea {
    padding: 0.45rem 0.625rem; font-size: 0.78rem;
    border: 1px solid var(--input-border); border-radius: var(--radius);
    background: var(--input); outline: none; color: var(--foreground);
    resize: vertical; font-family: inherit; line-height: 1.5;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.field-textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(9,105,218,0.1); }
.field-hint { font-size: 0.7rem; color: var(--muted-foreground); }

/* ── Upload Zone ─────────────────────────────────────────────────────────────── */
.upload-zone {
    border: 1.5px dashed var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    display: flex; flex-direction: column; align-items: center; gap: 0.4rem;
    cursor: pointer; text-align: center;
    color: var(--muted-foreground); font-size: 0.75rem;
    transition: border-color 0.15s, background 0.15s;
}
.upload-zone:hover { border-color: var(--primary); background: var(--primary-light); }

/* ── Buttons ─────────────────────────────────────────────────────────────────── */
.btn-primary {
    display: inline-flex; align-items: center; gap: 0.35rem;
    padding: 0.45rem 0.875rem; font-size: 0.8rem; font-weight: 600;
    color: var(--primary-foreground); background: var(--primary);
    border: none; border-radius: var(--radius); cursor: pointer;
    transition: background 0.15s, opacity 0.15s;
}
.btn-primary:hover { background: var(--primary-hover); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary.btn-full { width: 100%; justify-content: center; }

.btn-ghost {
    display: inline-flex; align-items: center; gap: 0.35rem;
    padding: 0.45rem 0.875rem; font-size: 0.8rem; font-weight: 500;
    color: var(--foreground); background: none;
    border: 1px solid var(--border); border-radius: var(--radius); cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}
.btn-ghost:hover { background: var(--muted); }

/* ── Modal ──────────────────────────────────────────────────────────────────── */
.modal-overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.45);
    display: flex; align-items: center; justify-content: center;
    z-index: 9000; padding: 1rem;
}
.modal-box {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: 0 8px 40px rgba(0,0,0,0.18);
    width: 100%; max-width: 480px;
    display: flex; flex-direction: column;
    overflow: hidden;
}
.modal-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
}
.modal-title { font-size: 0.95rem; font-weight: 600; }
.modal-close {
    background: none; border: none; cursor: pointer; padding: 4px;
    color: var(--muted-foreground); border-radius: 4px;
    display: flex; align-items: center; transition: color 0.15s;
}
.modal-close:hover { color: var(--foreground); }
.modal-body { padding: 1.25rem; display: flex; flex-direction: column; gap: 0.875rem; }
.modal-footer {
    display: flex; justify-content: flex-end; gap: 0.5rem;
    padding: 0.875rem 1.25rem;
    border-top: 1px solid var(--border);
    background: var(--muted);
}
.modal-error {
    padding: 0.5rem 0.75rem;
    background: var(--destructive-light); border: 1px solid #fca5a5;
    border-radius: var(--radius); color: var(--destructive); font-size: 0.78rem;
}

/* ── Scrollbar Styling ──────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #a0a8b0; }

/* ── No-project empty state ─────────────────────────────────────────────────── */
.empty-state {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    height: 100%; gap: 1rem; color: var(--muted-foreground); text-align: center;
    padding: 2rem;
}
.empty-state-icon {
    width: 64px; height: 64px; border-radius: 16px;
    background: var(--primary-light); display: flex; align-items: center; justify-content: center;
}
.empty-state-icon svg { width: 32px; height: 32px; stroke: var(--primary); }
.empty-state h3 { font-size: 1rem; font-weight: 600; color: var(--foreground); }
.empty-state p { font-size: 0.82rem; max-width: 320px; line-height: 1.6; }

/* ── Project Splash Screen ──────────────────────────────────────────────────── */
.project-splash {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: none;
    align-items: center;
    justify-content: center;
    background:
        radial-gradient(ellipse at 15% 40%, hsla(220,80%,94%,0.7) 0%, transparent 55%),
        radial-gradient(ellipse at 85% 20%, hsla(160,60%,92%,0.6) 0%, transparent 50%),
        radial-gradient(ellipse at 60% 80%, hsla(260,60%,94%,0.5) 0%, transparent 50%),
        #f0f4f8;
    opacity: 0;
    transition: opacity 0.3s ease;
    overflow-y: auto;
    padding: 2rem 1rem;
}
.project-splash.splash-visible { opacity: 1; }
.project-splash.splash-hiding  { opacity: 0; pointer-events: none; }

.splash-inner {
    width: 100%;
    max-width: 680px;
    display: flex;
    flex-direction: column;
    gap: 2rem;
    margin: auto;
    transform: translateY(0);
    transition: transform 0.3s ease;
}
.project-splash:not(.splash-visible) .splash-inner { transform: translateY(12px); }

/* Hero */
.splash-hero {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding-bottom: 0.5rem;
}
.splash-logo {
    width: 52px; height: 52px;
    background: var(--primary);
    border-radius: 14px;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
    box-shadow: 0 4px 16px rgba(9,105,218,0.25);
}
.splash-logo svg { width: 26px; height: 26px; stroke: #fff; }
.splash-hero-text { display: flex; flex-direction: column; gap: 0.2rem; }
.splash-title {
    font-size: 1.45rem;
    font-weight: 700;
    color: var(--foreground);
    letter-spacing: -0.02em;
    line-height: 1.2;
}
.splash-subtitle {
    font-size: 0.82rem;
    color: var(--muted-foreground);
}

/* Section heading */
.splash-section-heading {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--muted-foreground);
    margin-bottom: -0.75rem;
}
.splash-section-heading::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border);
}

/* Project cards grid */
.splash-project-grid {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}
.splash-project-card {
    display: flex;
    align-items: center;
    gap: 0.875rem;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 0.875rem 1rem;
    cursor: pointer;
    transition: box-shadow 0.15s, border-color 0.15s, transform 0.15s;
}
.splash-project-card:hover {
    border-color: var(--primary);
    box-shadow: 0 2px 12px rgba(9,105,218,0.1);
    transform: translateY(-1px);
}
.splash-project-card:hover .spc-arrow { color: var(--primary); opacity: 1; }

.spc-avatar {
    width: 40px; height: 40px;
    border-radius: 10px;
    background: hsl(var(--hue, 210), 65%, 90%);
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}
.spc-avatar span {
    font-size: 0.8rem;
    font-weight: 700;
    color: hsl(var(--hue, 210), 60%, 35%);
    letter-spacing: 0.02em;
}
.spc-body { flex: 1; overflow: hidden; min-width: 0; }
.spc-name {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--foreground);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.spc-desc {
    font-size: 0.76rem;
    color: var(--muted-foreground);
    margin-top: 0.15rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.spc-meta {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    font-size: 0.72rem;
    color: var(--muted-foreground);
    margin-top: 0.25rem;
}
.spc-arrow {
    color: var(--border);
    opacity: 0.5;
    flex-shrink: 0;
    transition: color 0.15s, opacity 0.15s;
}

/* New project form card */
.splash-form-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: 0 1px 6px rgba(0,0,0,0.05);
}
.splash-form-heading {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.875rem 1rem;
    border-bottom: 1px solid var(--border-light);
    background: var(--muted);
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--foreground);
}
.splash-form-icon {
    width: 24px; height: 24px;
    background: var(--primary);
    border-radius: 6px;
    display: flex; align-items: center; justify-content: center;
}
.splash-form-icon svg { stroke: #fff; }
.splash-form-body {
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}
.splash-field { display: flex; flex-direction: column; gap: 0.35rem; }
.splash-label {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--foreground);
}
.splash-input {
    width: 100%;
    padding: 0.55rem 0.75rem;
    border: 1px solid var(--input-border);
    border-radius: var(--radius);
    background: var(--input);
    font-size: 0.84rem;
    color: var(--foreground);
    font-family: inherit;
    outline: none;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.splash-input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(9,105,218,0.12);
}
.splash-input::placeholder { color: var(--muted-foreground); }
.splash-textarea { resize: none; }
.splash-hint {
    font-size: 0.72rem;
    color: var(--muted-foreground);
}
.splash-error {
    font-size: 0.78rem;
    color: var(--destructive);
    background: var(--destructive-light);
    border: 1px solid rgba(207,34,46,0.2);
    border-radius: var(--radius);
    padding: 0.5rem 0.75rem;
}
.splash-create-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    width: 100%;
    padding: 0.65rem 1.25rem;
    background: var(--primary);
    color: var(--primary-foreground);
    border: none;
    border-radius: var(--radius);
    font-size: 0.84rem;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    transition: background 0.15s, transform 0.1s, box-shadow 0.15s;
    box-shadow: 0 2px 8px rgba(9,105,218,0.2);
}
.splash-create-btn:hover:not(:disabled) {
    background: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 14px rgba(9,105,218,0.28);
}
.splash-create-btn:active { transform: translateY(0); }
.splash-create-btn:disabled {
    opacity: 0.65;
    cursor: not-allowed;
    transform: none;
}
.btn-spinner {
    display: inline-block;
    width: 14px; height: 14px;
    border: 2px solid rgba(255,255,255,0.4);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Source Code File Tree ──────────────────────────────────────────────────── */
.ks-source-content {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}
.ks-source-toolbar {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 0.75rem;
    border-bottom: 1px solid var(--border-light);
    flex-shrink: 0;
}
.ks-source-label {
    flex: 1;
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--muted-foreground);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.ks-source-upload-btn {
    display: flex; align-items: center; gap: 0.3rem;
    padding: 0.3rem 0.6rem;
    background: var(--primary-light);
    color: var(--primary);
    border: 1px solid rgba(9,105,218,0.2);
    border-radius: var(--radius);
    font-size: 0.72rem;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    transition: background 0.15s;
}
.ks-source-upload-btn:hover { background: #c7dbf9; }

.source-tree-container {
    flex: 1;
    overflow-y: auto;
    padding: 0.25rem 0;
}

.src-tree-item {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.3rem 0.5rem;
    border-radius: 4px;
    cursor: pointer;
    user-select: none;
    transition: background 0.1s;
    min-height: 26px;
}
.src-tree-item:hover { background: var(--muted); }
.src-tree-item.src-selected {
    background: var(--primary-light);
    color: var(--primary);
}

.src-expand-icon {
    display: flex; align-items: center; justify-content: center;
    width: 14px; flex-shrink: 0;
    color: var(--muted-foreground);
    transition: transform 0.15s;
}
.src-expand-icon.open { transform: rotate(90deg); }

.src-icon {
    width: 13px; height: 13px;
    flex-shrink: 0;
}
.src-folder-icon { stroke: var(--warning); }
.src-file-icon { stroke: var(--muted-foreground); }
.src-tree-item.src-selected .src-file-icon { stroke: var(--primary); }

.src-name {
    font-size: 0.78rem;
    color: var(--foreground);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
}
.src-tree-item.src-selected .src-name { color: var(--primary); font-weight: 500; }

.src-children {
    display: none;
}
.src-children.open { display: block; }

/* ── KS Browse Toolbar ───────────────────────────────────────────────────────── */
.ks-browse-toolbar {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.625rem 0.375rem;
    border-bottom: 1px solid var(--border-light);
}
.ks-index-all-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.3rem 0.625rem;
    font-size: 0.72rem;
    font-weight: 500;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    transition: opacity 0.15s;
    white-space: nowrap;
}
.ks-index-all-btn:hover:not(:disabled) { opacity: 0.85; }
.ks-index-all-btn:disabled { opacity: 0.55; cursor: not-allowed; }
.ks-index-all-btn.indexing svg { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.ks-index-status {
    font-size: 0.7rem;
    color: var(--muted-foreground);
    flex: 1;
    text-align: right;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ── Browse tab source summary bar ───────────────────────────────────────────── */
.ks-src-summary {
    border-top: 1px solid var(--border-light);
    padding: 0.45rem 0.625rem;
    background: var(--muted);
    min-height: 32px;
}
.ks-src-summary-row {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}
.ks-src-summary-text {
    flex: 1;
    font-size: 0.7rem;
    color: var(--muted-foreground);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.ks-src-index-link {
    background: none;
    border: none;
    padding: 0;
    font-size: 0.68rem;
    color: var(--primary);
    cursor: pointer;
    white-space: nowrap;
    text-decoration: underline;
    text-underline-offset: 2px;
}
.ks-src-index-link:hover { opacity: 0.75; }

/* ── KS Item Rows (new clean design) ─────────────────────────────────────────── */
.ks-item {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.45rem 0.625rem;
    cursor: pointer;
    border-radius: var(--radius);
    margin: 1px 0.25rem;
    transition: background 0.1s;
}
.ks-item:hover { background: var(--muted); }
.ks-item:hover .ks-item-chevron { opacity: 1; }

.ks-item-icon {
    color: var(--muted-foreground);
    flex-shrink: 0;
    display: flex;
    align-items: center;
}
.ks-item-info {
    flex: 1;
    min-width: 0;
}
.ks-item-name {
    display: block;
    font-size: 0.775rem;
    font-weight: 500;
    color: var(--foreground);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    line-height: 1.3;
}
.ks-item-meta {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    margin-top: 0.1rem;
}
.ks-item-tokens {
    font-size: 0.68rem;
    color: var(--muted-foreground);
}
.ks-item-chunks {
    font-size: 0.68rem;
    padding: 0.05rem 0.35rem;
    border-radius: 999px;
    font-weight: 500;
}
.ks-item-chunks.is-indexed {
    background: #dcfce7;
    color: #166534;
}
.ks-item-chunks.is-pending {
    background: var(--muted);
    color: var(--muted-foreground);
}
.ks-item-chevron {
    width: 12px;
    height: 12px;
    flex-shrink: 0;
    color: var(--muted-foreground);
    opacity: 0;
    transition: opacity 0.1s;
}

/* ── KS Document Viewer Overlay ──────────────────────────────────────────────── */
.ksdv-overlay {
    position: fixed;
    inset: 0;
    z-index: 910;
    display: none;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.5);
    opacity: 0;
    transition: opacity 0.2s ease;
    padding: 1.5rem;
}
.ksdv-overlay.ksdv-visible { opacity: 1; }

.ksdv-panel {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: 0 24px 64px rgba(0,0,0,0.22);
    width: 100%;
    max-width: 1100px;
    height: 88vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.ksdv-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border);
    gap: 1rem;
    flex-shrink: 0;
}
.ksdv-header-left {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    min-width: 0;
}
.ksdv-close-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.3rem 0.625rem;
    font-size: 0.75rem;
    font-weight: 500;
    background: none;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    color: var(--muted-foreground);
    white-space: nowrap;
    flex-shrink: 0;
    transition: background 0.1s, color 0.1s;
}
.ksdv-close-btn:hover { background: var(--muted); color: var(--foreground); }

.ksdv-filename {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--foreground);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.ksdv-meta {
    font-size: 0.72rem;
    color: var(--muted-foreground);
    white-space: nowrap;
    flex-shrink: 0;
}

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

.ksdv-content-pane {
    flex: 0 0 42%;
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border);
    overflow: hidden;
}
.ksdv-chunks-pane {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.ksdv-pane-label {
    padding: 0.5rem 1rem;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--muted-foreground);
    border-bottom: 1px solid var(--border-light);
    flex-shrink: 0;
    background: var(--muted);
}

.ksdv-content {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    font-size: 0.78rem;
    line-height: 1.65;
    color: var(--foreground);
    font-family: 'JetBrains Mono', 'Fira Code', ui-monospace, monospace;
    white-space: pre-wrap;
    word-break: break-word;
    margin: 0;
}

.ksdv-chunks {
    flex: 1;
    overflow-y: auto;
    padding: 0.625rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.ksdv-loading, .ksdv-no-chunks, .ksdv-no-sections {
    padding: 1rem;
    font-size: 0.75rem;
    color: var(--muted-foreground);
    text-align: center;
    line-height: 1.6;
}

/* ── Chunk Block ─────────────────────────────────────────────────────────────── */
.ksdv-chunk {
    display: flex;
    gap: 0.5rem;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.625rem;
}
.ksdv-chunk-num {
    font-size: 0.65rem;
    font-weight: 700;
    color: var(--muted-foreground);
    background: var(--muted);
    border-radius: 99px;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    margin-top: 1px;
}
.ksdv-chunk-body {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}
.ksdv-chunk-heading {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--primary);
}
.ksdv-chunk-text {
    font-size: 0.73rem;
    color: var(--muted-foreground);
    line-height: 1.55;
}
.ksdv-chunk-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
}
.ksdv-tag-pill {
    display: inline-block;
    padding: 0.1rem 0.4rem;
    font-size: 0.65rem;
    background: #eff6ff;
    color: #1d4ed8;
    border-radius: 999px;
    font-weight: 500;
}
.ksdv-no-tags {
    font-size: 0.65rem;
    color: var(--muted-foreground);
    font-style: italic;
}

/* ── Section Matches ─────────────────────────────────────────────────────────── */
.ksdv-chunk-sections {
    border-top: 1px solid var(--border-light);
    padding-top: 0.35rem;
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}
.ksdv-sections-label {
    font-size: 0.62rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--muted-foreground);
}
.ksdv-chunk-doc {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}
.ksdv-chunk-doc-id {
    font-size: 0.67rem;
    font-weight: 600;
    color: var(--foreground);
    font-family: ui-monospace, monospace;
}
.ksdv-chunk-sec-list {
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
    padding-left: 0.5rem;
}
.ksdv-chunk-sec {
    font-size: 0.65rem;
    color: var(--muted-foreground);
    line-height: 1.4;
}
.ksdv-chunk-sec-more, .ksdv-more-docs {
    font-size: 0.63rem;
    color: var(--muted-foreground);
    font-style: italic;
}

/* ── Source File Viewer ──────────────────────────────────────────────────────── */
.sfv-overlay {
    position: fixed;
    inset: 0;
    z-index: 900;
    display: none;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.45);
    opacity: 0;
    transition: opacity 0.2s ease;
    padding: 2rem;
}
.sfv-overlay.sfv-visible { opacity: 1; }

.sfv-panel {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: 0 20px 60px rgba(0,0,0,0.25);
    width: 100%;
    max-width: 860px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sfv-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border);
    background: var(--muted);
    flex-shrink: 0;
}
.sfv-title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.84rem;
    font-weight: 600;
    color: var(--foreground);
    overflow: hidden;
}
.sfv-title span {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.sfv-header-right {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-shrink: 0;
}
.sfv-meta {
    font-size: 0.72rem;
    color: var(--muted-foreground);
}
.sfv-close {
    display: flex; align-items: center; justify-content: center;
    width: 26px; height: 26px;
    background: none;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    color: var(--muted-foreground);
    transition: background 0.1s, color 0.1s;
}
.sfv-close:hover { background: var(--border-light); color: var(--foreground); }

.sfv-body {
    flex: 1;
    display: flex;
    overflow: hidden;
    min-height: 0;
}
.sfv-content-pane {
    flex: 1 1 55%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border-right: 1px solid var(--border-light);
    min-width: 0;
}
.sfv-info-pane {
    flex: 0 0 300px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--muted);
    min-width: 220px;
    max-width: 360px;
}
.sfv-pane-label {
    padding: 0.5rem 0.875rem;
    font-size: 0.68rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--muted-foreground);
    border-bottom: 1px solid var(--border-light);
    flex-shrink: 0;
}
.sfv-code {
    flex: 1;
    margin: 0;
    padding: 1rem;
    font-family: 'SFMono-Regular', 'Consolas', 'Liberation Mono', monospace;
    font-size: 0.78rem;
    line-height: 1.6;
    color: var(--foreground);
    white-space: pre;
    tab-size: 4;
    overflow: auto;
}
.sfv-info-content {
    flex: 1;
    overflow-y: auto;
    padding: 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.875rem;
}
.sfv-info-hint {
    font-size: 0.75rem;
    color: var(--muted-foreground);
    text-align: center;
    padding-top: 1rem;
}
.sfv-not-indexed {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    padding-top: 1.5rem;
    font-size: 0.75rem;
    color: var(--muted-foreground);
    text-align: center;
    line-height: 1.5;
}
.sfv-info-meta {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    flex-wrap: wrap;
}
.sfv-lang-badge {
    display: inline-block;
    padding: 0.15rem 0.45rem;
    background: var(--primary-light);
    color: var(--primary);
    border-radius: 4px;
    font-size: 0.68rem;
    font-weight: 600;
    letter-spacing: 0.04em;
}
.sfv-size-label {
    font-size: 0.7rem;
    color: var(--muted-foreground);
}
.sfv-info-section {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}
.sfv-info-label {
    font-size: 0.68rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--muted-foreground);
}
.sfv-tag-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem;
}
.sfv-tag-pill {
    display: inline-block;
    padding: 0.18rem 0.5rem;
    background: var(--accent-light, #ede9fe);
    color: var(--accent, #7c3aed);
    border-radius: 10px;
    font-size: 0.68rem;
    font-weight: 500;
}
.sfv-no-tags { font-size: 0.72rem; color: var(--muted-foreground); font-style: italic; }
.sfv-sections-wrap {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}
.sfv-section-doc {
    background: var(--card);
    border: 1px solid var(--border-light);
    border-radius: 6px;
    padding: 0.4rem 0.6rem;
}
.sfv-section-doc-id {
    display: block;
    font-size: 0.68rem;
    font-weight: 600;
    color: var(--primary);
    margin-bottom: 0.25rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.sfv-section-list {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}
.sfv-section-item {
    font-size: 0.7rem;
    color: var(--foreground);
    padding: 0.1rem 0;
    border-left: 2px solid var(--primary-light);
    padding-left: 0.4rem;
}
.sfv-no-sections { font-size: 0.72rem; color: var(--muted-foreground); font-style: italic; }

/* ── Doc Config Panel ────────────────────────────────────────────────────────── */
.doc-config-panel {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow-y: auto;
    padding: 1.25rem 1.75rem 2rem;
    background: var(--background);
}
.doc-config-panel.hidden { display: none; }

/* Header */
.dcp-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1.25rem;
    flex-wrap: wrap;
}
.dcp-back-btn {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.35rem 0.75rem;
    background: none;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 0.75rem;
    color: var(--muted-foreground);
    transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.dcp-back-btn:hover { background: var(--card-hover); color: var(--foreground); border-color: var(--muted-foreground); }
.dcp-header-title { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 0.2rem; }
.dcp-category-badge {
    font-size: 0.65rem;
    font-weight: 600;
    color: var(--muted-foreground);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}
.dcp-title {
    font-size: 1rem;
    font-weight: 700;
    color: var(--foreground);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.dcp-header-actions { display: flex; gap: 0.5rem; flex-shrink: 0; }
.dcp-generate-btn, .dcp-batch-btn {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.4rem 0.85rem;
    border-radius: var(--radius);
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: background 0.12s;
}
.dcp-generate-btn {
    background: var(--primary);
    color: var(--primary-foreground);
}
.dcp-generate-btn:hover { background: var(--primary-hover); }
.dcp-batch-btn {
    background: var(--card);
    color: var(--foreground);
    border: 1px solid var(--border);
}
.dcp-batch-btn:hover { background: var(--card-hover); }

/* Meta card */
.dcp-meta-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1rem 1.25rem;
    margin-bottom: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}
.dcp-meta-row { display: flex; flex-direction: column; gap: 0.3rem; }
.dcp-meta-label {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--muted-foreground);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.dcp-meta-input, .dcp-meta-textarea {
    width: 100%;
    padding: 0.4rem 0.6rem;
    border: 1px solid var(--input-border);
    border-radius: var(--radius);
    font-size: 0.8rem;
    background: var(--input);
    color: var(--foreground);
    font-family: inherit;
    transition: border-color 0.12s;
}
.dcp-meta-input:focus, .dcp-meta-textarea:focus {
    outline: none;
    border-color: var(--primary);
}
.dcp-meta-textarea { resize: vertical; min-height: 52px; }

/* No-index banner */
.dcp-no-index-banner {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 0.9rem;
    background: var(--warning-light);
    border: 1px solid #f6d860;
    border-radius: var(--radius);
    font-size: 0.75rem;
    color: var(--warning);
    margin-bottom: 1rem;
}

/* Section list */
.dcp-sections-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.6rem;
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--muted-foreground);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}
.dcp-sections-count {
    font-weight: 400;
    font-size: 0.7rem;
}
.dcp-section-list {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}
.dcp-section-card {
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background: var(--card);
    padding: 0.85rem 1rem;
}
.dcp-section-header {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin-bottom: 0.6rem;
}
.dcp-section-num {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--primary);
    color: var(--primary-foreground);
    font-size: 0.65rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.dcp-section-info { flex: 1; min-width: 0; display: flex; align-items: center; gap: 0.4rem; }
.dcp-section-title { font-size: 0.82rem; font-weight: 600; color: var(--foreground); }
.dcp-component-chip {
    font-size: 0.62rem;
    font-weight: 500;
    padding: 0.1rem 0.4rem;
    border-radius: 10px;
    background: var(--muted);
    color: var(--muted-foreground);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    flex-shrink: 0;
}
.dcp-section-tags { display: flex; gap: 0.25rem; flex-wrap: wrap; }
.dcp-ks-tag-pill {
    font-size: 0.6rem;
    padding: 0.1rem 0.4rem;
    background: var(--primary-light);
    color: var(--primary);
    border-radius: 8px;
    font-weight: 500;
}

/* KS items */
.dcp-ks-items {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    align-items: center;
}
.dcp-ks-chip {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    background: var(--muted);
    border: 1px solid var(--border-light);
    border-radius: 6px;
    padding: 0.2rem 0.35rem 0.2rem 0.5rem;
    font-size: 0.72rem;
}
.dcp-ks-chip.dcp-ks-excluded {
    opacity: 0.5;
    text-decoration: line-through;
    border-style: dashed;
}
.dcp-ks-chip-label {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    max-width: 160px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.dcp-ks-chunk-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 16px;
    height: 16px;
    background: var(--border);
    border-radius: 8px;
    font-size: 0.6rem;
    font-weight: 700;
    padding: 0 3px;
    flex-shrink: 0;
}
.dcp-ks-chip-remove, .dcp-ks-chip-restore {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 0.9rem;
    line-height: 1;
    color: var(--muted-foreground);
    padding: 0 1px;
    flex-shrink: 0;
    transition: color 0.1s;
}
.dcp-ks-chip-remove:hover { color: var(--destructive); }
.dcp-ks-chip-restore:hover { color: var(--success); }
.dcp-ks-none-hint {
    font-size: 0.72rem;
    color: var(--muted-foreground);
    font-style: italic;
}
.dcp-add-ks-btn {
    font-size: 0.7rem;
    padding: 0.2rem 0.5rem;
    background: none;
    border: 1px dashed var(--border);
    border-radius: 6px;
    cursor: pointer;
    color: var(--muted-foreground);
    transition: color 0.12s, border-color 0.12s, background 0.12s;
}
.dcp-add-ks-btn:hover {
    color: var(--primary);
    border-color: var(--primary);
    background: var(--primary-light);
}

/* Add KS panel (inline mini panel) */
.dcp-add-ks-panel {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--card);
    box-shadow: 0 4px 12px rgba(0,0,0,0.08);
    margin-top: 0.35rem;
    overflow: hidden;
}
.dcp-add-ks-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 0.75rem;
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--muted-foreground);
    border-bottom: 1px solid var(--border-light);
}
.dcp-add-ks-close {
    background: none; border: none; cursor: pointer;
    font-size: 1rem; line-height: 1; color: var(--muted-foreground);
    transition: color 0.1s;
}
.dcp-add-ks-close:hover { color: var(--foreground); }
.dcp-add-ks-list { max-height: 180px; overflow-y: auto; }
.dcp-add-ks-item {
    padding: 0.4rem 0.75rem;
    font-size: 0.75rem;
    cursor: pointer;
    transition: background 0.1s;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.dcp-add-ks-item:hover { background: var(--primary-light); color: var(--primary); }

/* Loading / error states */
.dcp-loading, .dcp-error {
    padding: 2rem;
    text-align: center;
    font-size: 0.82rem;
    color: var(--muted-foreground);
}
.dcp-error { color: var(--destructive); }

/* ── Batch checkbox on catalog cards ────────────────────────────────────────── */
.card-batch-check {
    position: absolute;
    top: 0.5rem;
    left: 0.5rem;
    width: 14px;
    height: 14px;
    cursor: pointer;
    z-index: 2;
    accent-color: var(--primary);
}

/* Card hover arrow indicator */
.catalog-card::after {
    content: '›';
    position: absolute;
    bottom: 0.5rem;
    right: 0.6rem;
    font-size: 1rem;
    color: var(--border);
    transition: color 0.15s, transform 0.15s;
    pointer-events: none;
}
.catalog-card:hover::after { color: var(--primary); transform: translateX(2px); }

/* ── Generation status indicators on catalog cards ────────────────────────────── */
@keyframes card-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(9,105,218,0); }
    50%       { box-shadow: 0 0 0 3px rgba(9,105,218,0.18); }
}
.catalog-card.gen-pending {
    border-left: 3px solid #94a3b8;
    opacity: 0.7;
}
.catalog-card.gen-running {
    border-left: 3px solid var(--primary);
    background: #f5f9ff;
    animation: card-pulse 1.6s ease-in-out infinite;
}
.catalog-card.gen-running::after {
    content: '';
    width: 11px; height: 11px;
    border: 2px solid #bfdbfe;
    border-top-color: #1d4ed8;
    border-radius: 50%;
    animation: task-spin 0.7s linear infinite;
    bottom: 0.5rem; right: 0.5rem;
}
.catalog-card.gen-done {
    border-left: 3px solid #16a34a;
    background: #f0fdf4;
}
.catalog-card.gen-done::after {
    content: '✓';
    color: #16a34a;
    font-size: 0.9rem;
    font-weight: 700;
    transition: none;
}
.catalog-card.gen-done:hover::after { color: #16a34a; transform: none; }
.catalog-card.gen-warning {
    border-left: 3px solid #ea580c;
}
.catalog-card.gen-warning::after {
    content: '⚠';
    color: #ea580c;
    font-size: 0.78rem;
    transition: none;
}
.catalog-card.gen-warning:hover::after { color: #ea580c; transform: none; }
