* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; background: #f5f7fb; color: #1a2236; }
button { font-family: inherit; }

/* ===== Login ===== */
.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: linear-gradient(135deg,#eef2ff,#f5f7fb); }
.login-card { background: #fff; padding: 36px 32px; border-radius: 14px; box-shadow: 0 10px 40px rgba(20,30,80,.08); width: 360px; display: flex; flex-direction: column; gap: 14px; }
.login-card h1 { margin: 0; font-size: 22px; }
.login-card .muted { margin: 0; color: #6b7b99; font-size: 13px; }
.login-card label { display: flex; flex-direction: column; font-size: 13px; gap: 6px; color: #4a5777; }
.login-card input { padding: 10px 12px; border: 1px solid #d8deeb; border-radius: 8px; font-size: 14px; outline: none; }
.login-card input:focus { border-color: #4f6bed; }
.login-card button { margin-top: 6px; padding: 11px; border: none; border-radius: 8px; background: #4f6bed; color: #fff; font-weight: 600; cursor: pointer; }
.login-card button:hover { background: #3b55d4; }
.err { color: #d13a3a; font-size: 13px; min-height: 16px; }

/* ===== App shell ===== */
.app { display: flex; height: 100vh; }

.sidebar { width: 280px; background: #0f172a; color: #cbd5e1; display: flex; flex-direction: column; padding: 16px; gap: 12px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; color: #fff; margin-bottom: 4px; }
.brand .logo { color: #7c9cff; font-size: 18px; }
.section-label { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: #64748b; margin-top: 8px; }

#projectSelect { background: #1e293b; color: #e2e8f0; border: 1px solid #334155; padding: 8px; border-radius: 6px; font-size: 13px; }

.quick-tools { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-top: 4px; }
.tool-btn { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 10px 4px; background: #1e293b; border: 1px solid #334155; border-radius: 8px; text-decoration: none; color: #cbd5e1; font-size: 11px; transition: .15s; }
.tool-btn:hover { background: #273449; color: #fff; border-color: #4f6bed; transform: translateY(-1px); }
.tool-btn .ic { font-size: 20px; }
.tool-btn .lbl { font-weight: 500; }

.chat-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; margin: 0 -8px; padding: 0 8px; }
.chat-item { padding: 9px 11px; border-radius: 6px; cursor: pointer; font-size: 13px; color: #cbd5e1; display: flex; justify-content: space-between; gap: 6px; align-items: center; }
.chat-item:hover { background: #1e293b; }
.chat-item.active { background: #273449; color: #fff; }
.chat-item .del { opacity: 0; color: #94a3b8; font-size: 14px; background: none; border: none; cursor: pointer; padding: 0 4px; }
.chat-item:hover .del { opacity: 1; }
.chat-item .del:hover { color: #f87171; }
.chat-item .title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.sidebar-footer { display: flex; flex-direction: column; gap: 6px; padding-top: 10px; border-top: 1px solid #1e293b; }

.btn { padding: 9px 14px; border-radius: 7px; border: 1px solid transparent; font-size: 13px; cursor: pointer; font-weight: 500; }
.btn.block { width: 100%; }
.btn.primary { background: #4f6bed; color: #fff; border-color: #4f6bed; }
.btn.primary:hover { background: #3b55d4; }
.btn.ghost { background: transparent; color: #cbd5e1; border-color: #334155; }
.btn.ghost:hover { background: #1e293b; color: #fff; }
.btn.small { padding: 4px 8px; font-size: 16px; }

/* ===== Main ===== */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar { padding: 14px 24px; border-bottom: 1px solid #e4e8f1; background: #fff; display: flex; justify-content: space-between; align-items: center; }
.chat-title { font-weight: 600; font-size: 15px; }
.meta { font-size: 12px; color: #6b7b99; }

.messages { flex: 1; overflow-y: auto; padding: 24px 28px; display: flex; flex-direction: column; gap: 16px; }
.empty-state { text-align: center; margin: auto; color: #6b7b99; }
.empty-state h2 { color: #1a2236; }

.msg { max-width: 820px; padding: 12px 16px; border-radius: 12px; white-space: pre-wrap; word-wrap: break-word; line-height: 1.55; font-size: 14px; }
.msg.user { align-self: flex-end; background: #4f6bed; color: #fff; border-bottom-right-radius: 4px; }
.msg.assistant { align-self: flex-start; background: #fff; border: 1px solid #e4e8f1; border-bottom-left-radius: 4px; }
.msg.tool { align-self: flex-start; background: #f3f5fc; border: 1px solid #d4dcf0; color: #4a5777; font-family: ui-monospace, Menlo, monospace; font-size: 12px; max-width: 820px; padding: 10px 14px; border-radius: 10px; width: 820px; }
.msg.tool.running { border-left: 3px solid #f59e0b; background: #fffbeb; animation: pulse-running 2s ease-in-out infinite; }
@keyframes pulse-running { 0%, 100% { box-shadow: 0 0 0 0 rgba(245,158,11,.3); } 50% { box-shadow: 0 0 0 6px rgba(245,158,11,0); } }
.msg.tool.done { border-left: 3px solid #22c55e; background: #f0fdf4; }
.msg.tool.error { border-left: 3px solid #ef4444; background: #fef2f2; }
.msg.tool .tool-status { font-weight: 500; font-size: 11px; color: #64748b; }
.msg.tool.running .tool-status { color: #d97706; }
.msg.tool.done .tool-status { color: #16a34a; }
.msg.tool.error .tool-status { color: #dc2626; }
.msg.tool .tool-body { white-space: pre-wrap; word-break: break-all; color: #334155; }
.msg.tool .tool-result { margin-top: 8px; padding-top: 8px; border-top: 1px dashed #c8d0e4; white-space: pre-wrap; word-break: break-word; max-height: 400px; overflow-y: auto; color: #4a5777; }
.typing { align-self: flex-start; background: #fff; border: 1px solid #e4e8f1; padding: 14px 18px; border-radius: 12px; display: inline-flex; gap: 4px; }
.typing span { width: 7px; height: 7px; background: #8fa0c8; border-radius: 50%; animation: blink 1.3s infinite; }
.typing span:nth-child(2) { animation-delay: .2s; }
.typing span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 60%, 100% { opacity: .3; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-3px); } }
.msg.tool .head { font-weight: 600; color: #4f6bed; margin-bottom: 6px; display: flex; justify-content: space-between; align-items: center; }
.msg .attachment { display: inline-block; background: rgba(255,255,255,.2); padding: 4px 8px; border-radius: 6px; font-size: 12px; margin-top: 6px; }

.composer { display: flex; gap: 10px; padding: 14px 20px; background: #fff; border-top: 1px solid #e4e8f1; align-items: flex-end; }
.composer textarea { flex: 1; resize: none; border: 1px solid #d8deeb; border-radius: 10px; padding: 11px 14px; font-size: 14px; font-family: inherit; outline: none; max-height: 200px; }
.composer textarea:focus { border-color: #4f6bed; }
.file-btn { font-size: 20px; cursor: pointer; padding: 8px 10px; border: 1px solid #d8deeb; border-radius: 10px; background: #f5f7fb; }
.file-btn:hover { background: #edf0fa; }

.attach-preview { padding: 0 20px; display: flex; gap: 8px; flex-wrap: wrap; }
.attach-preview:empty { padding: 0; }
.attach-chip { background: #edf0fa; border: 1px solid #d8deeb; border-radius: 16px; padding: 4px 10px; font-size: 12px; display: flex; align-items: center; gap: 6px; }
.attach-chip button { background: none; border: none; cursor: pointer; color: #6b7b99; font-size: 14px; }

/* ===== Drawer ===== */
.drawer { position: fixed; right: 0; top: 0; bottom: 0; width: 380px; background: #fff; border-left: 1px solid #e4e8f1; box-shadow: -10px 0 40px rgba(20,30,80,.08); display: flex; flex-direction: column; padding: 16px; gap: 10px; z-index: 100; }
.drawer.hidden { display: none; }
.drawer-head { display: flex; justify-content: space-between; align-items: center; }
.drawer textarea { flex: 1; border: 1px solid #d8deeb; border-radius: 8px; padding: 12px; font-family: inherit; font-size: 13px; resize: none; outline: none; }
