:root{
  --bg:#f5f7fb; --surface:#ffffff; --surface-2:#f8fafc; --line:#e5e9f2;
  --text:#172033; --muted:#667085; --brand:#2563eb; --brand-2:#7c3aed;
  --ok:#0f9d58; --warn:#b45309; --danger:#c2410c; --shadow:0 8px 30px rgba(29,41,70,.10);
}
*{box-sizing:border-box}
html,body{height:100%}
body{margin:0;background:var(--bg);color:var(--text);font:15px/1.65 -apple-system,BlinkMacSystemFont,"Segoe UI","PingFang SC","Microsoft YaHei",sans-serif;-webkit-font-smoothing:antialiased}
button,input,textarea{font:inherit}
button{cursor:pointer}
a{color:var(--brand);text-decoration:none}
a:hover{text-decoration:underline}
.sr-only{position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;border:0}
:focus-visible{outline:3px solid rgba(37,99,235,.45);outline-offset:2px}

.app-shell{height:100dvh;display:flex;flex-direction:column;max-width:1440px;margin:0 auto;background:var(--surface)}
.topbar{flex:0 0 auto;display:flex;align-items:center;justify-content:space-between;gap:16px;padding:14px 22px;background:linear-gradient(100deg,#eff4ff 0%,#f6f1ff 100%);border-bottom:1px solid var(--line)}
.brand{display:flex;align-items:center;gap:12px;min-width:0}
.brand-mark{width:42px;height:42px;flex:0 0 42px;border-radius:13px;display:grid;place-items:center;color:#fff;font-weight:800;font-size:21px;background:linear-gradient(135deg,var(--brand),var(--brand-2));box-shadow:0 5px 14px rgba(37,99,235,.24)}
.brand-text{min-width:0}
.brand-text h1{font-size:17px;margin:0;line-height:1.3;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.brand-text p{margin:2px 0 0;font-size:12px;color:var(--muted);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.top-actions{display:flex;align-items:center;gap:9px;flex:0 0 auto}
.status-pill{display:inline-flex;align-items:center;gap:7px;padding:6px 11px;border-radius:999px;background:#fff;border:1px solid var(--line);font-size:12px;color:var(--muted);white-space:nowrap}
.status-pill i{width:8px;height:8px;border-radius:50%;background:#f59e0b;flex:0 0 8px}
.status-pill.online i{background:var(--ok)}
.status-pill.kb i{background:var(--brand)}
.ghost-btn,.human-btn{border-radius:9px;padding:8px 12px;font-size:13px;min-height:38px;white-space:nowrap}
.ghost-btn{background:#fff;border:1px solid var(--line);color:var(--text)}
.ghost-btn:hover{background:var(--surface-2)}
.human-btn{background:linear-gradient(135deg,var(--brand),var(--brand-2));color:#fff;border:1px solid transparent;font-weight:600}
.human-btn:hover{opacity:.92;text-decoration:none}
.menu-btn{display:none}

.workspace{flex:1 1 auto;display:flex;min-height:0}
.sidebar{width:300px;flex:0 0 300px;border-right:1px solid var(--line);background:var(--surface-2);display:flex;flex-direction:column;min-height:0;padding:16px 14px 10px}
.side-title{display:flex;align-items:baseline;justify-content:space-between;margin-bottom:10px}
.side-title strong{font-size:14px}
.side-title small{color:var(--muted);font-size:12px}
.search-wrap{display:block;margin-bottom:10px}
.search-wrap input{width:100%;padding:9px 11px;border:1px solid var(--line);border-radius:9px;background:#fff;color:var(--text);font-size:13px;min-height:40px}
.cats{display:flex;flex-wrap:wrap;gap:6px;margin-bottom:10px}
.cat-chip{border:1px solid var(--line);background:#fff;color:var(--muted);border-radius:999px;padding:5px 10px;font-size:12px;min-height:32px}
.cat-chip.active{background:#eaf0ff;border-color:#b9ccff;color:var(--brand);font-weight:600}
.kb-list{flex:1 1 auto;overflow:auto;display:flex;flex-direction:column;gap:2px;padding-right:2px}
.kb-item{text-align:left;border:0;background:transparent;border-radius:8px;padding:8px 10px;color:var(--text);font-size:13px;line-height:1.45;min-height:38px}
.kb-item:hover{background:#eef2ff;color:var(--brand)}
.kb-item .tag{display:block;font-size:11px;color:var(--muted);margin-bottom:1px}
.kb-empty{padding:14px 8px;color:var(--muted);font-size:13px}
.side-foot{border-top:1px solid var(--line);padding-top:10px;margin-top:8px;font-size:12px}

.chat{flex:1 1 auto;display:flex;flex-direction:column;min-width:0;min-height:0;background:#fff}
.chat-head{display:flex;align-items:center;gap:10px;padding:11px 22px;border-bottom:1px solid var(--line);background:#fff}
.chat-head strong{display:block;font-size:14px}
.chat-head small{display:block;color:var(--muted);font-size:12px}
.bot-avatar{width:34px;height:34px;border-radius:50%;display:grid;place-items:center;background:#eef2ff;font-size:17px}
.messages{flex:1 1 auto;overflow:auto;padding:22px clamp(16px,4vw,42px);display:flex;flex-direction:column;gap:14px;background:linear-gradient(180deg,#fff 0%,#fbfcff 100%)}
.msg{display:flex;gap:10px;max-width:min(760px,92%)}
.msg.bot{align-self:flex-start}
.msg.me{align-self:flex-end;flex-direction:row-reverse}
.msg .avatar{width:30px;height:30px;flex:0 0 30px;border-radius:50%;display:grid;place-items:center;background:#eef2ff;font-size:15px}
.msg.me .avatar{background:#e8f5ee}
.bubble{padding:11px 15px;border-radius:14px;background:var(--surface-2);border:1px solid var(--line);white-space:pre-wrap;word-break:break-word;font-size:14px;line-height:1.7}
.msg.bot .bubble{border-top-left-radius:4px}
.msg.me .bubble{background:#eaf0ff;border-color:#cddcff;border-top-right-radius:4px}
.bubble b{color:var(--brand)}
.bubble .tiny{color:var(--muted);font-size:12px}
.bubble .src{display:inline-block;margin-top:8px;padding:3px 8px;border-radius:6px;background:#eef2ff;color:var(--brand);font-size:11px}
.bubble .entry{display:inline-block;margin:8px 0 0 6px;padding:3px 9px;border-radius:6px;background:#fff;border:1px solid #cddcff;font-size:12px}
.bubble .related{margin:9px 0 0;padding:8px 10px;background:#fff;border:1px dashed var(--line);border-radius:8px;font-size:12px;color:var(--muted)}
.bubble .related button{display:block;text-align:left;border:0;background:transparent;padding:3px 0;color:var(--brand);font-size:12px}
.typing{display:inline-flex;gap:4px;align-items:center}
.typing i{width:6px;height:6px;border-radius:50%;background:#94a3b8;animation:blink 1.1s infinite}
.typing i:nth-child(2){animation-delay:.15s}.typing i:nth-child(3){animation-delay:.3s}
@keyframes blink{0%,60%,100%{opacity:.25}30%{opacity:1}}

.quick{flex:0 0 auto;display:flex;gap:7px;flex-wrap:wrap;padding:0 clamp(16px,4vw,42px) 10px}
.quick button{border:1px solid #d8e1f5;background:#fff;border-radius:999px;padding:6px 12px;color:var(--brand);font-size:12px;min-height:34px}
.quick button:hover{background:#eef2ff}
.composer{flex:0 0 auto;display:flex;gap:9px;align-items:flex-end;padding:12px clamp(16px,4vw,42px) 6px;border-top:1px solid var(--line)}
.composer textarea{flex:1 1 auto;resize:none;max-height:120px;min-height:44px;padding:11px 13px;border:1px solid var(--line);border-radius:11px;background:#fff;color:var(--text);font-size:14px}
.composer button{border:0;border-radius:11px;padding:0 20px;min-height:44px;background:linear-gradient(135deg,var(--brand),var(--brand-2));color:#fff;font-weight:600;white-space:nowrap}
.composer button[hidden]{display:none}
#stopBtn{background:#fff;color:var(--danger);border:1px solid #fecaca}
.disclaimer{flex:0 0 auto;margin:0;padding:0 clamp(16px,4vw,42px) 12px;color:var(--muted);font-size:11px;line-height:1.5}

@media(max-width:900px){
  .menu-btn{display:inline-block}
  .brand-text p{display:none}
  .status-pill{display:none}
  .sidebar{position:absolute;z-index:20;top:70px;bottom:0;left:0;width:min(86vw,320px);transform:translateX(-102%);transition:transform .22s ease;box-shadow:var(--shadow)}
  .sidebar.open{transform:translateX(0)}
  .workspace{position:relative}
  .topbar{padding:11px 14px}
  .top-actions{gap:6px}
  .ghost-btn,.human-btn{padding:7px 9px;font-size:12px}
}
@media(max-width:520px){
  .brand-text h1{font-size:15px}
  .brand-mark{width:36px;height:36px;flex-basis:36px;font-size:18px}
  .messages{padding:16px 12px}
  .quick{padding:0 12px 8px}
  .composer{padding:10px 12px 4px}
  .composer button{padding:0 14px}
  .disclaimer{padding:0 12px 10px}
  .msg{max-width:96%}
}
