:root {
    --bg: #FFFFFF;
    --bg-secondary: #F9FAFB;
    --bg-tertiary: #F3F4F6;
    --text-primary: #111827;
    --text-secondary: #6B7280;
    --text-tertiary: #9CA3AF;
    --border: #E5E7EB;
    --border-light: #F3F4F6;
    --accent: #2563EB;
    --accent-hover: #1D4ED8;
    --accent-light: #EFF6FF;
    --success: #059669;
    --warning: #D97706;
    --danger: #DC2626;
    --danger-light: #FEF2F2;
    --radius: 6px;
    --sidebar-w: 200px;
}

*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
body { font: 15px/1.5 'Inter', system-ui, sans-serif; color: var(--text-primary); background: var(--bg); -webkit-font-smoothing: antialiased; }
h1,h2,h3 { font-family: 'EB Garamond', serif; font-weight: 600; }
h1 { font-size: 18px; }
input,textarea,select { font: 13px 'Inter', sans-serif; }

/* Layout */
.app { display: flex; height: 100dvh; }
.sidebar { width: var(--sidebar-w); background: var(--bg-secondary); border-right: 1px solid var(--border); display: flex; flex-direction: column; flex-shrink: 0; }
.main { flex: 1; display: flex; flex-direction: column; overflow: hidden; min-width: 0; }

/* Sidebar */
.s-head { padding: 10px; border-bottom: 1px solid var(--border-light); display: flex; align-items: center; justify-content: space-between; }
.s-logo { font: 600 16px 'EB Garamond', serif; }
.s-nav { flex: 1; overflow-y: auto; padding: 4px; }
.s-item { display: flex; align-items: center; gap: 10px; padding: 14px 20px; border-radius: var(--radius); cursor: pointer; font-size: 16px; color: var(--text-secondary); }
.s-item:hover { background: var(--bg-tertiary); }
.s-item.on { background: var(--accent-light); color: var(--accent); font-weight: 500; }
.s-item svg { width: 14px; height: 14px; }
.s-foot { padding: 8px; border-top: 1px solid var(--border-light); }
.s-user { display: flex; align-items: center; gap: 10px; padding: 6px; border-radius: var(--radius); cursor: pointer; }
.s-user:hover { background: var(--bg-tertiary); }
.av { width: 36px; height: 36px; border-radius: 50%; background: var(--accent); color: #fff; display: flex; align-items: center; justify-content: center; font-size: 16px; font-weight: 600; flex-shrink: 0; }

/* Auth */
.auth { display: flex; align-items: center; justify-content: center; min-height: 100dvh; background: var(--bg-secondary); padding: 16px; }
.auth-card { background: #fff; border-radius: var(--radius); padding: 24px; width: 100%; max-width: 300px; box-shadow: 0 2px 8px rgba(0,0,0,.08); }
.auth-logo { font: 600 20px 'EB Garamond', serif; text-align: center; margin-bottom: 4px; }
.auth-sub { text-align: center; color: var(--text-secondary); font-size: 16px; margin-bottom: 16px; }
.auth-err { background: var(--danger-light); color: var(--danger); padding: 14px 20px; border-radius: var(--radius); font-size: 16px; margin-bottom: 10px; display: none; }

/* Forms */
.fg { margin-bottom: 8px; }
.fl { display: block; font-size: 16px; font-weight: 500; margin-bottom: 3px; color: var(--text-secondary); }
.fi { width: 100%; padding: 14px 20px; border: 1px solid var(--border); border-radius: var(--radius); font-size: 16px; outline: none; }
.fi:focus { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(37,99,235,.1); }

/* Buttons */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 14px 20px; border-radius: var(--radius); font-size: 16px; font-weight: 500; cursor: pointer; border: none; min-height: 42px; }
.btn-p { background: var(--accent); color: #fff; }
.btn-p:hover { background: var(--accent-hover); }
.btn-s { background: var(--bg-tertiary); color: var(--text-primary); }
.btn-g { background: none; color: var(--text-secondary); }
.btn-g:hover { background: var(--bg-tertiary); }
.btn-sm { padding: 7px 14px; font-size: 16px; min-height: 42px; }
.btn-full { width: 100%; }
.btn svg { width: 12px; height: 12px; }

/* Header */
.hdr { padding: 14px 20px; border-bottom: 1px solid var(--border-light); display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.hdr h1 { flex: 1; }
.hdr-acts { display: flex; gap: 8px; }

/* Projects */
.plist { padding: 14px 20px; }
.pcard { display: flex; align-items: center; gap: 10px; padding: 14px 20px; border: 1px solid var(--border); border-radius: var(--radius); cursor: pointer; margin-bottom: 4px; }
.pcard:hover { border-color: var(--accent); }
.picon { width: 40px; height: 40px; border-radius: var(--radius); background: var(--accent-light); color: var(--accent); display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.picon svg { width: 14px; height: 14px; }
.pname { font-size: 16px; font-weight: 500; }
.pmeta { font-size: 16px; color: var(--text-tertiary); }

/* Documents */
.dlist { padding: 14px 20px; }
.ditem { display: flex; align-items: center; gap: 10px; padding: 14px 20px; border: 1px solid var(--border-light); border-radius: var(--radius); margin-bottom: 3px; }
.dicon { width: 40px; height: 40px; border-radius: 4px; display: flex; align-items: center; justify-content: center; font-size: 8px; font-weight: 700; color: #fff; flex-shrink: 0; }
.dicon.pdf { background: #DC2626; }
.dicon.docx { background: #2563EB; }
.dicon.txt { background: #6B7280; }
.dicon.img { background: #059669; }
.dname { font-size: 16px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dmeta { font-size: 16px; color: var(--text-tertiary); }

/* Chat */
.chat { flex: 1; display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
.chat-msgs { flex: 1; overflow-y: auto; padding: 14px 20px; }
.cmsg { margin-bottom: 8px; max-width: 80%; }
.cmsg.user { margin-left: auto; }
.cbub { padding: 14px 20px; border-radius: 14px; font-size: 16px; line-height: 1.5; }
.cmsg.user .cbub { background: var(--accent); color: #fff; border-bottom-right-radius: 3px; }
.cmsg.assistant .cbub { background: var(--bg-secondary); border-bottom-left-radius: 3px; }
.chat-in { flex-shrink: 0; padding: 6px 14px; border-top: 1px solid var(--border-light); }
.chat-inw { display: flex; gap: 8px; align-items: flex-end; }
.chat-inp { flex: 1; padding: 14px 20px; border: 1px solid var(--border); border-radius: 20px; font-size: 16px; outline: none; min-height: 42px; max-height: 60px; }
.chat-send { width: 36px; height: 36px; border-radius: 50%; background: var(--accent); color: #fff; border: none; cursor: pointer; display: flex; align-items: center; justify-content: center; }
.chat-send svg { width: 12px; height: 12px; }

/* Upload */
.upload { border: 2px dashed var(--border); border-radius: var(--radius); padding: 20px; text-align: center; cursor: pointer; margin: 8px 14px; }
.upload:hover { border-color: var(--accent); background: var(--accent-light); }
.upload svg { width: 20px; height: 20px; color: var(--text-tertiary); }
.upload span { display: block; font-size: 16px; color: var(--text-secondary); margin-top: 4px; }

/* Modal */
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.4); display: flex; align-items: center; justify-content: center; z-index: 1000; padding: 14px; }
.modal { background: #fff; border-radius: var(--radius); width: 100%; max-width: 360px; max-height: 90vh; overflow-y: auto; }
.modal-h { padding: 12px; border-bottom: 1px solid var(--border-light); display: flex; align-items: center; justify-content: space-between; }
.modal-t { font-size: 16px; font-weight: 600; }
.modal-b { padding: 12px; }
.modal-f { padding: 14px 18px; border-top: 1px solid var(--border-light); display: flex; justify-content: flex-end; gap: 8px; }

/* Calendar */
.cal-hdr { display: flex; align-items: center; justify-content: space-between; padding: 6px 14px; }
.cal-title { font-size: 16px; font-weight: 600; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 40px); gap: 1px; padding: 4px 14px; justify-content: center; }
.cal-day { width: 40px; height: 40px; display: flex; align-items: center; justify-content: center; border-radius: var(--radius); font-size: 16px; cursor: pointer; }
.cal-day:hover { background: var(--bg-tertiary); }
.cal-day.today { background: var(--accent); color: #fff; font-weight: 600; }

/* Templates */
.tpl { border: 1px solid var(--border); border-radius: var(--radius); padding: 8px; margin-bottom: 4px; cursor: pointer; }
.tpl:hover { border-color: var(--accent); }
.tpl-name { font-size: 16px; font-weight: 500; }
.tpl-cat { font-size: 10px; color: var(--text-tertiary); background: var(--bg-tertiary); padding: 1px 5px; border-radius: 3px; display: inline-block; margin-top: 2px; }

/* Empty */
.empty { text-align: center; padding: 30px 14px; color: var(--text-tertiary); }
.empty svg { width: 28px !important; height: 28px !important; margin-bottom: 8px; }
.empty p { font-size: 16px; margin-bottom: 10px; }

/* Table */
table { width: 100%; border-collapse: collapse; font-size: 16px; }
th { text-align: left; padding: 14px 20px; font-size: 16px; font-weight: 500; color: var(--text-secondary); border-bottom: 1px solid var(--border); }
td { padding: 14px 20px; border-bottom: 1px solid var(--border-light); }

/* Toast */
#toasts { position: fixed; bottom: 12px; right: 12px; z-index: 9999; display: flex; flex-direction: column; gap: 6px; }
.toast { padding: 6px 10px; border-radius: var(--radius); font-size: 16px; color: #fff; animation: slideIn .2s; }
.toast-success { background: var(--success); }
.toast-error { background: var(--danger); }
.toast-info { background: var(--text-primary); }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } }

/* Mobile */
@media (max-width: 768px) {
    .sidebar { position: fixed; z-index: 100; height: 100dvh; transform: translateX(-100%); transition: transform .2s; width: 220px; }
    .sidebar.open { transform: translateX(0); }
    .sbg { position: fixed; inset: 0; background: rgba(0,0,0,.3); z-index: 99; display: none; }
    .sbg.open { display: block; }
    .mob-h { display: flex !important; align-items: center; gap: 8px; padding: 6px 10px; border-bottom: 1px solid var(--border-light); }
}
@media (min-width: 769px) {
    .mob-h { display: none !important; }
    .sbg { display: none !important; }
}

::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* RAG Bar */
.rag-bar { display: flex; align-items: center; justify-content: space-between; padding: 6px 14px; background: var(--bg-secondary); border-bottom: 1px solid var(--border-light); font-size: 12px; color: var(--text-secondary); }

/* Citations */
.citations { display: flex; flex-wrap: wrap; gap: 4px; padding: 4px 14px 8px; }
.cite { display: inline-block; background: var(--accent-light); color: var(--accent); padding: 2px 8px; border-radius: 10px; font-size: 11px; font-weight: 500; cursor: default; }
.cite:hover { background: var(--accent); color: #fff; }

/* Doc Search */
.doc-search .fi { border-radius: 16px; }

/* Rich Markdown in Chat */
.cbub p.md-p { margin: 0 0 8px; line-height: 1.6; }
.cbub p.md-p:last-child { margin-bottom: 0; }
.cbub .md-h { font-size: 15px; font-weight: 600; margin: 12px 0 4px; color: var(--text-primary); }
.cbub h2.md-h { font-size: 16px; }
.cbub h3.md-h { font-size: 15px; }
.cbub h4.md-h { font-size: 14px; }
.cbub .md-list { margin: 4px 0 8px 18px; padding: 0; }
.cbub .md-list li { margin-bottom: 3px; line-height: 1.5; }
.cbub .md-quote { border-left: 3px solid var(--accent); padding: 4px 10px; margin: 6px 0; color: var(--text-secondary); font-style: italic; background: var(--bg-secondary); border-radius: 0 4px 4px 0; }
.cbub .md-code { background: var(--bg-tertiary); padding: 8px 12px; border-radius: 4px; font-size: 13px; overflow-x: auto; margin: 6px 0; font-family: JetBrains Mono, monospace; }
.cbub .md-inline { background: var(--bg-tertiary); padding: 1px 5px; border-radius: 3px; font-size: 13px; font-family: JetBrains Mono, monospace; }
.cbub .md-hr { border: none; border-top: 1px solid var(--border-light); margin: 8px 0; }
.cbub strong { font-weight: 600; }
.cbub em { font-style: italic; }
.cbub del { text-decoration: line-through; color: var(--text-tertiary); }
