:root {
    --bg: #0F1117;
    --bg2: #161922;
    --bg3: #1E2230;
    --border: #2A2E3C;
    --text: #E4E6EB;
    --text2: #9CA3AF;
    --accent: #6366F1;
    --accent2: #818CF8;
    --accent-bg: rgba(99,102,241,0.12);
    --danger: #EF4444;
    --success: #22C55E;
    --warning: #F59E0B;
    --radius: 10px;
    --sidebar-w: 280px;
    --transition: 0.15s ease;
}

*,*::before,*::after { box-sizing: border-box; margin: 0; padding: 0; }
.hidden { display: none !important; }
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg); color: var(--text); height: 100vh; overflow: hidden; font-size: 14px;
}
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* LOGIN */
.login-screen { display: flex; align-items: center; justify-content: center; height: 100vh; background: linear-gradient(135deg, #161922, #0F1117); }
.login-card { background: var(--bg2); padding: 2.5rem; border-radius: 16px; text-align: center; max-width: 380px; width: 90%; border: 1px solid var(--border); }
.login-icon { font-size: 3rem; margin-bottom: 0.5rem; }
.login-card h1 { font-size: 1.4rem; color: var(--accent2); margin-bottom: 0.3rem; }
.login-subtitle { color: var(--text2); font-size: 0.85rem; margin-bottom: 1.5rem; }
#login-form { display: flex; flex-direction: column; gap: 0.8rem; }
#password-input { padding: 0.7rem 1rem; background: var(--bg3); border: 1px solid var(--border); border-radius: var(--radius); color: var(--text); font-size: 0.9rem; text-align: center; outline: none; }
#password-input:focus { border-color: var(--accent); }
#login-form button { padding: 0.7rem; background: var(--accent); color: white; border: none; border-radius: var(--radius); font-size: 0.9rem; cursor: pointer; font-weight: 600; transition: var(--transition); }
#login-form button:hover { background: var(--accent2); }
.login-error { color: var(--danger); font-size: 0.8rem; margin-top: 0.5rem; }

/* APP */
.app-screen { display: flex; height: 100vh; }

/* SIDEBAR */
.sidebar { width: var(--sidebar-w); min-width: var(--sidebar-w); background: var(--bg2); border-right: 1px solid var(--border); display: flex; flex-direction: column; overflow-y: auto; transition: transform var(--transition); }
.sidebar.collapsed { transform: translateX(-100%); width: 0; min-width: 0; }
.sidebar-header { padding: 0.8rem; border-bottom: 1px solid var(--border); }
.sidebar-logo { font-size: 0.95rem; font-weight: 700; color: var(--accent2); }
.sidebar-section { padding: 0.6rem 0.8rem; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.sidebar-flex { flex: 1 1 0; overflow-y: auto; min-height: 80px; }
.section-label { font-size: 0.7rem; color: var(--text2); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 0.4rem; font-weight: 600; }
.sidebar-footer { display: flex; gap: 0.4rem; }

.workspace-row { display: flex; gap: 0.3rem; }
.ws-select { width: 100%; padding: 0.4rem 0.5rem; background: var(--bg3); border: 1px solid var(--border); border-radius: 6px; color: var(--text); font-size: 0.8rem; outline: none; margin-bottom: 0.3rem; }
.ws-select:focus { border-color: var(--accent); }
.ws-btn { padding: 0.4rem 0.8rem; background: var(--bg3); border: 1px solid var(--border); border-radius: 6px; color: var(--text); font-size: 0.8rem; cursor: pointer; transition: var(--transition); flex: 1; text-align: center; }
.ws-btn:hover { background: var(--accent-bg); border-color: var(--accent); }
.ws-danger:hover { background: rgba(239,68,68,0.12); border-color: var(--danger); color: var(--danger); }

/* AGENTS */
.agents-list { display: flex; flex-direction: column; gap: 0.3rem; max-height: 200px; overflow-y: auto; }
.agent-item { display: flex; align-items: center; gap: 0.4rem; padding: 0.5rem 0.6rem; border-radius: 6px; cursor: pointer; transition: var(--transition); border: 1px solid transparent; font-size: 0.8rem; }
.agent-item:hover { background: var(--bg3); border-color: var(--border); }
.agent-item.active { background: var(--accent-bg); border-color: var(--accent); }
.agent-icon { font-size: 1rem; }
.agent-info { flex: 1; min-width: 0; }
.agent-name { font-weight: 600; }
.agent-desc { font-size: 0.7rem; color: var(--text2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* CONVERSATIONS */
.conv-list { display: flex; flex-direction: column; gap: 0.2rem; max-height: 40vh; overflow-y: auto; }
.conv-item { display: flex; align-items: center; padding: 0.4rem 0.5rem; border-radius: 6px; cursor: pointer; font-size: 0.78rem; transition: var(--transition); border: 1px solid transparent; }
.conv-item:hover { background: var(--bg3); }
.conv-item.active { background: var(--accent-bg); border-color: var(--accent); }
.conv-item-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-item-actions { display: flex; gap: 0.2rem; opacity: 0; transition: var(--transition); }
.conv-item:hover .conv-item-actions { opacity: 1; }
.conv-item-btn { background: none; border: none; cursor: pointer; font-size: 0.7rem; padding: 0.1rem 0.2rem; border-radius: 4px; color: var(--text2); }
.conv-item-btn:hover { background: var(--border); }
.conv-item-btn.delete:hover { color: var(--danger); }

/* CASES */
.case-info { margin-top: 0.4rem; display: flex; flex-direction: column; gap: 0.3rem; }
.si { padding: 0.35rem 0.5rem; background: var(--bg3); border: 1px solid var(--border); border-radius: 6px; color: var(--text); font-size: 0.78rem; outline: none; }
.si:focus { border-color: var(--accent); }
.case-docs-list { display: flex; flex-direction: column; gap: 0.3rem; max-height: 50vh; overflow-y: auto; }
.case-doc-item { display: flex; align-items: center; justify-content: space-between; padding: 0.5rem 0.7rem; border: 1px solid var(--border); border-radius: 6px; cursor: pointer; transition: var(--transition); }
.case-doc-item:hover { background: var(--bg3); }
.case-doc-item-title { font-size: 0.82rem; font-weight: 600; color: var(--accent2); }
.case-doc-item-date { font-size: 0.7rem; color: var(--text2); }

/* TEMP SLIDER */
.temp-row { display: flex; align-items: center; gap: 0.5rem; font-size: 0.75rem; color: var(--text2); }
.temp-slider { flex: 1; accent-color: var(--accent); }

/* MAIN */
.main-area { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--bg); }

/* TOPBAR */
.topbar { height: 50px; display: flex; align-items: center; gap: 0.5rem; padding: 0 1rem; border-bottom: 1px solid var(--border); background: var(--bg2); flex-shrink: 0; }
.topbar-title { font-size: 0.95rem; font-weight: 600; color: var(--accent2); flex: 1; }
.topbar-actions { display: flex; gap: 0.3rem; }
.icon-btn { background: var(--bg3); border: 1px solid var(--border); border-radius: 6px; width: 34px; height: 34px; display: flex; align-items: center; justify-content: center; cursor: pointer; font-size: 1rem; color: var(--text); transition: var(--transition); }
.icon-btn:hover { background: var(--accent-bg); border-color: var(--accent); }

/* TOOL BAR */
.tool-bar { display: flex; align-items: center; gap: 0.3rem; padding: 0.4rem 1rem; border-bottom: 1px solid var(--border); background: var(--bg2); flex-shrink: 0; flex-wrap: wrap; }
.tool-btn { padding: 0.3rem 0.7rem; background: var(--bg3); border: 1px solid var(--border); border-radius: 6px; font-size: 0.78rem; cursor: pointer; color: var(--text); transition: var(--transition); }
.tool-btn:hover { background: var(--accent-bg); border-color: var(--accent); }
.upload-progress { width: 100%; height: 2px; background: var(--border); border-radius: 1px; overflow: hidden; margin-top: 0.2rem; }
.upload-bar { height: 100%; background: var(--accent); animation: indet 1.5s infinite; border-radius: 1px; }
@keyframes indet { 0%{width:30%;margin-left:-30%} 50%{width:50%;margin-left:50%} 100%{width:30%;margin-left:100%} }

/* AGENT BANNER */
.agent-banner { padding: 0.4rem 1rem; background: var(--accent-bg); border-bottom: 1px solid var(--border); font-size: 0.8rem; color: var(--accent2); display: flex; align-items: center; gap: 0.5rem; }
.agent-clear { margin-left: auto; background: none; border: none; color: var(--text2); cursor: pointer; font-size: 0.9rem; }

/* SEARCH */
.search-bar { display: flex; align-items: center; gap: 0.3rem; padding: 0.4rem 1rem; border-bottom: 1px solid var(--border); background: var(--bg2); }
#search-input { flex: 1; padding: 0.3rem 0.6rem; background: var(--bg3); border: 1px solid var(--border); border-radius: 6px; color: var(--text); font-size: 0.8rem; outline: none; }
#search-input:focus { border-color: var(--accent); }
.search-count { font-size: 0.72rem; color: var(--text2); min-width: 30px; text-align: center; }
.icon-btn-sm { background: var(--bg3); border: 1px solid var(--border); border-radius: 4px; width: 24px; height: 24px; display: flex; align-items: center; justify-content: center; cursor: pointer; font-size: 0.65rem; color: var(--text2); }
.icon-btn-sm:hover { background: var(--accent-bg); }

/* CHAT */
.chat-container { flex: 1; overflow-y: auto; padding: 1rem; }
.chat-messages { max-width: 800px; margin: 0 auto; display: flex; flex-direction: column; gap: 0.8rem; }
.message { display: flex; gap: 0.6rem; animation: fadeIn 0.2s; }
@keyframes fadeIn { from{opacity:0;transform:translateY(4px)} to{opacity:1;transform:translateY(0)} }
.message.user { flex-direction: row-reverse; }
.msg-avatar { width: 32px; height: 32px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 1rem; flex-shrink: 0; background: var(--bg3); }
.message.assistant .msg-avatar { background: var(--accent-bg); }
.msg-content { max-width: 75%; padding: 0.6rem 0.9rem; border-radius: var(--radius); font-size: 0.85rem; line-height: 1.6; word-wrap: break-word; }
.message.assistant .msg-content { background: var(--bg2); border: 1px solid var(--border); border-top-left-radius: 4px; }
.message.user .msg-content { background: var(--accent); color: white; border-top-right-radius: 4px; }
.msg-content p { margin-bottom: 0.4rem; } .msg-content p:last-child { margin: 0; }
.msg-content ul, .msg-content ol { padding-left: 1.3rem; margin: 0.3rem 0; }
.msg-content li { margin-bottom: 0.1rem; }
.msg-content strong { color: var(--accent2); }
.msg-content code { background: var(--bg3); padding: 0.1rem 0.3rem; border-radius: 4px; font-size: 0.82em; }
.msg-content pre { background: var(--bg3); padding: 0.8rem; border-radius: var(--radius); overflow-x: auto; font-size: 0.78rem; margin: 0.3rem 0; border: 1px solid var(--border); }
.msg-content pre code { background: none; padding: 0; }
.msg-copy-btn { align-self: flex-start; background: none; border: 1px solid var(--border); border-radius: 4px; cursor: pointer; font-size: 0.7rem; padding: 0.1rem 0.3rem; opacity: 0; transition: var(--transition); color: var(--text2); }
.message:hover .msg-copy-btn { opacity: 1; }
.msg-copy-btn:hover { background: var(--bg3); }

/* SUGGESTIONS */
.suggestions { max-width: 800px; margin: 0 auto 0.5rem; padding: 0 1rem; }
.suggestions-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.4rem; }
.suggestion-btn { padding: 0.5rem 0.7rem; background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); font-size: 0.78rem; text-align: left; cursor: pointer; color: var(--text); transition: var(--transition); }
.suggestion-btn:hover { border-color: var(--accent); background: var(--accent-bg); }

/* INPUT */
.input-area { display: flex; gap: 0.5rem; padding: 0.6rem 1rem; border-top: 1px solid var(--border); background: var(--bg2); flex-shrink: 0; }
#chat-input { flex: 1; padding: 0.6rem 0.9rem; background: var(--bg3); border: 1px solid var(--border); border-radius: 20px; color: var(--text); font-size: 0.85rem; font-family: inherit; resize: none; outline: none; max-height: 120px; }
#chat-input:focus { border-color: var(--accent); }
.btn-send { width: 40px; height: 40px; border-radius: 50%; background: var(--accent); color: white; border: none; cursor: pointer; font-size: 0.9rem; transition: var(--transition); display: flex; align-items: center; justify-content: center; }
.btn-send:hover { background: var(--accent2); }
.btn-send:disabled { background: var(--border); cursor: not-allowed; }

/* TYPING */
.typing-indicator { display: flex; gap: 3px; padding: 0.3rem 0; }
.typing-indicator span { width: 6px; height: 6px; border-radius: 50%; background: var(--accent2); animation: bounce 1.4s infinite; }
.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }
@keyframes bounce { 0%,80%,100%{transform:scale(0.5);opacity:0.3} 40%{transform:scale(1);opacity:1} }

/* MODALS */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,0.6); display: flex; align-items: center; justify-content: center; z-index: 100; animation: fadeIn 0.15s; }
.modal-card { background: var(--bg2); padding: 1.2rem; border-radius: 12px; border: 1px solid var(--border); max-width: 450px; width: 90%; max-height: 80vh; display: flex; flex-direction: column; gap: 0.8rem; }
.modal-wide { max-width: 700px; }
.modal-fullscreen { max-width: 90vw; width: 90vw; height: 90vh; padding: 0; overflow: hidden; }
.modal-card h3 { font-size: 0.95rem; color: var(--accent2); }
.modal-actions { display: flex; gap: 0.4rem; justify-content: flex-end; }
.fix-options { display: flex; flex-wrap: wrap; gap: 0.6rem; font-size: 0.78rem; }
.fix-options label { display: flex; align-items: center; gap: 0.2rem; cursor: pointer; }
.fix-options input { accent-color: var(--accent); }
.fix-doc-input { width: 100%; min-height: 150px; background: var(--bg3); border: 1px solid var(--border); border-radius: var(--radius); color: var(--text); font-size: 0.82rem; padding: 0.6rem; font-family: monospace; resize: vertical; outline: none; }
.fix-doc-input:focus { border-color: var(--accent); }

/* TEMPLATES */
.templates-list { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; max-height: 50vh; overflow-y: auto; }
.template-item { padding: 0.7rem; border: 1px solid var(--border); border-radius: var(--radius); cursor: pointer; transition: var(--transition); }
.template-item:hover { border-color: var(--accent); background: var(--accent-bg); }
.template-item h4 { font-size: 0.82rem; color: var(--accent2); }
.template-item p { font-size: 0.72rem; color: var(--text2); }

/* SOURCES */
.sources-list { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; max-height: 50vh; overflow-y: auto; }
.source-item { padding: 0.6rem; border: 1px solid var(--border); border-radius: var(--radius); cursor: pointer; transition: var(--transition); }
.source-item:hover { border-color: var(--accent); background: var(--accent-bg); }
.source-item h4 { font-size: 0.78rem; color: var(--accent2); }
.source-item p { font-size: 0.68rem; color: var(--text2); }
.sources-category { grid-column: 1/-1; font-size: 0.68rem; font-weight: 700; color: var(--text2); text-transform: uppercase; padding-top: 0.3rem; border-top: 1px solid var(--border); }

/* IMAGE */
.img-preview { text-align: center; max-height: 40vh; overflow-y: auto; margin-bottom: 0.5rem; }
.img-preview img { max-width: 100%; border-radius: var(--radius); }
.img-actions { display: flex; flex-wrap: wrap; gap: 0.3rem; }
.img-actions .ws-btn { width: auto; }

/* RICH EDITOR */
.rich-header { display: flex; align-items: center; gap: 0.3rem; padding: 0.5rem 0.8rem; background: var(--bg2); border-bottom: 1px solid var(--border); }
.rich-title { flex: 1; background: var(--bg3); border: 1px solid var(--border); border-radius: 6px; color: var(--text); padding: 0.3rem 0.6rem; font-size: 0.85rem; font-weight: 600; outline: none; }
.rich-container { flex: 1; overflow: hidden; background: var(--bg); }
#quill-editor { height: calc(90vh - 60px); }
.rich-container .ql-toolbar { border: none; border-bottom: 1px solid var(--border); background: var(--bg2); }
.rich-container .ql-container { border: none; font-family: inherit; }
.rich-container .ql-editor { min-height: 400px; color: var(--text); font-size: 14px; line-height: 1.6; }

/* TOAST */
.toast-container { position: fixed; bottom: 80px; right: 20px; z-index: 200; display: flex; flex-direction: column; gap: 0.4rem; }
.toast { padding: 0.6rem 1rem; border-radius: 8px; font-size: 0.8rem; max-width: 320px; animation: slideIn 0.2s; }
.toast.success { background: var(--success); color: white; }
.toast.error { background: var(--danger); color: white; }
.toast.info { background: var(--accent); color: white; }
.toast.warning { background: var(--warning); color: white; }
@keyframes slideIn { from{transform:translateX(100%);opacity:0} to{transform:translateX(0);opacity:1} }

/* RESPONSIVE */
@media (max-width: 768px) {
    .sidebar { position: fixed; top: 0; left: 0; height: 100vh; z-index: 100; }
    .topbar-title { font-size: 0.8rem; }
    .suggestions-grid, .templates-list, .sources-list { grid-template-columns: 1fr; }
    .msg-content { max-width: 88%; }
}
/* SIDEBAR ROW (label + button) */
.sidebar-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 0.4rem; }
.ws-btn-sm { background: var(--bg3); border: 1px solid var(--border); border-radius: 6px; width: 28px; height: 28px; cursor: pointer; color: var(--text); font-size: 1rem; display: flex; align-items: center; justify-content: center; transition: var(--transition); }
.ws-btn-sm:hover { background: var(--accent-bg); border-color: var(--accent); }
.ws-btn.full { width: 100%; margin-top: 0.3rem; }

/* COLLAPSIBLE DETAILS */
.sidebar-details { padding: 0 !important; border-bottom: 1px solid var(--border); }
.sidebar-details summary { padding: 0.6rem 0.8rem; cursor: pointer; font-size: 0.7rem; color: var(--text2); text-transform: uppercase; letter-spacing: 0.05em; font-weight: 600; list-style: none; display: flex; align-items: center; gap: 0.3rem; }
.sidebar-details summary::-webkit-details-marker { display: none; }
.sidebar-details summary::before { content: '▶'; font-size: 0.6rem; transition: transform 0.15s; }
.sidebar-details[open] summary::before { transform: rotate(90deg); }
.sidebar-details[open] summary { border-bottom: 1px solid var(--border); }
.case-section-content, .settings-content { padding: 0.6rem 0.8rem; display: flex; flex-direction: column; gap: 0.3rem; }
.setting-label { font-size: 0.72rem; color: var(--text2); margin-top: 0.2rem; }
