.kb {max-width:1600px;margin:auto}.kb-layout{display:grid;grid-template-columns:300px minmax(0,1fr);gap:20px;margin-top:0;align-items:stretch}.kb-library,.kb-workspace{background:var(--surface);border:1px solid var(--line);border-radius:8px;min-width:0}.kb-library{display:flex;flex-direction:column}.kb-library-head{padding:16px 20px 0}.kb-library-head p{margin:0;font-size:14px}.kb-library-head h2{margin:0 0 8px}.kb-library-body{padding:12px 20px 20px}.kb-count{color:var(--muted);font-size:13px;font-weight:400;font-variant-numeric:tabular-nums}.kb-library-head .kb-section-heading{justify-content:space-between;gap:10px;margin-bottom:8px}.kb-library-head .kb-section-heading h2{margin:0}.kb-section-heading,.kb-bot-header,.kb-footer{display:flex;justify-content:space-between;align-items:center;gap:16px}.kb h2{font-size:16px;margin:0 0 4px}.kb h3{font-size:15px;font-weight:600}.kb p,.kb small{line-height:1.65}.kb-muted,.kb p,.kb small{color:var(--muted)}.kb-avatar{display:grid;place-items:center;border-radius:6px;background:var(--subtle);color:var(--muted);width:36px;height:36px;flex-shrink:0;font-size:13px}.kb-welcome{padding:32px;display:flex;align-items:flex-start;flex-direction:column;gap:12px;max-width:640px}.kb-welcome h2{font-size:18px;font-weight:600}.kb-welcome p{max-width:560px;margin:0;font-size:14px}.kb-steps{display:grid;gap:0;width:100%;margin:8px 0 8px;padding:0;list-style:none;border-top:1px solid var(--line)}.kb-steps li{display:flex;gap:16px;align-items:baseline;padding:10px 0;border-bottom:1px solid var(--line);font-size:14px}.kb-steps strong{flex:0 0 120px;font-weight:600}.kb-steps span{color:var(--muted)}.kb-bot-header{padding:16px 20px 0}.kb-bot-header p{margin:0;font-size:14px;overflow-wrap:anywhere}.kb-bot-header h2{overflow-wrap:anywhere}.kb-tabs{display:flex;border-bottom:1px solid var(--line);padding:0 20px;gap:20px;overflow:auto}.kb-tabs button{font-size:14px;font-weight:500;background:none;border:0;border-bottom:2px solid transparent;padding:12px 0 10px;color:var(--muted);cursor:pointer;white-space:nowrap}.kb-tabs button:hover{color:var(--ink)}.kb-tabs button.active{color:var(--ink);border-color:var(--ink)}.kb-pane{padding:20px}.kb-pane>.kb-drop{display:flex;flex-direction:column;align-items:center;text-align:center;gap:4px;background:var(--subtle);border:1px dashed var(--line-strong);padding:24px 20px;border-radius:8px;margin-top:16px;cursor:pointer}.kb-pane>.kb-drop.dragover{background:var(--blue-soft);border-color:var(--link)}.kb-pane>.kb-drop:focus-within{outline:2px solid var(--blue);outline-offset:3px}.kb-drop .icon{width:22px;height:22px;margin-bottom:4px;color:var(--muted)}.kb-drop strong{font-size:14px;font-weight:600}.kb-drop span{font-size:13px;color:var(--muted)}.kb-file{display:flex;align-items:center;gap:14px;padding:14px 0;border-bottom:1px solid var(--line)}.kb-file>div{flex:1;min-width:0}.kb-file strong,.kb-file small{display:block;overflow-wrap:anywhere}.kb-file-type{flex-shrink:0;min-width:42px;text-align:center;font-size:11px;font-weight:600;color:var(--muted);background:var(--surface);border:1px solid var(--line);padding:7px 4px;border-radius:4px}.kb-file-meta{display:flex;flex-wrap:wrap;align-items:center;gap:6px 10px;margin-top:6px}.kb-file .kb-file-meta small{display:inline;margin:0}.kb-file .pill{font-size:12px}.kb-progress{margin-top:12px}.kb-progress-label{display:flex;justify-content:space-between;align-items:baseline;gap:12px;margin-bottom:6px;font-size:13px;color:var(--ink)}.kb-file .kb-progress-time{margin-top:6px;font-size:12px;color:var(--muted);font-variant-numeric:tabular-nums}.kb-progress-label b{font-weight:600;font-variant-numeric:tabular-nums}.kb-progress-bar{display:block;width:100%;height:6px;margin:0;border:0;border-radius:3px;overflow:hidden;appearance:none;-webkit-appearance:none;background:var(--line)}.kb-progress-bar::-webkit-progress-bar{background:var(--line);border-radius:3px}.kb-progress-bar::-webkit-progress-value{background:var(--blue);border-radius:3px;transition:width .6s ease}.kb-progress-bar::-moz-progress-bar{background:var(--blue);border-radius:3px}.kb-file .kb-file-error{margin-top:4px;color:var(--red)}.kb-btn-warn{color:var(--amber);border-color:var(--amber-border)}@media(prefers-reduced-motion:reduce){.kb-progress-bar::-webkit-progress-value{transition:none}}.kb-footer{margin-top:24px}.kb-footer p{font-size:14px;max-width:440px}.kb-footer .btn{flex-shrink:0}.kb-pane .note{margin:20px 0}.kb-sample{display:grid;grid-template-columns:minmax(0,1fr) 280px}.kb-source{padding:24px;background:var(--subtle);border-left:1px solid var(--line);border-radius:0 0 8px 0}.kb-source blockquote{margin:24px 0;padding:12px 16px;border-left:3px solid var(--blue);background:var(--blue-soft);line-height:1.8;font-size:15px}.kb-source p{font-size:14px}.kb-source h3{overflow-wrap:anywhere}#kb-error{color:var(--red)}.kb button:focus-visible,.kb-source:focus-visible{outline:2px solid var(--blue);outline-offset:3px}
@media(max-width:1200px){.kb-layout{grid-template-columns:260px minmax(0,1fr)}.kb-sample{grid-template-columns:1fr}.kb-source{border-left:0;border-top:1px solid var(--line)}}
@media(max-width:700px){.kb-layout{grid-template-columns:1fr}.kb-welcome{padding:30px 18px}.kb-steps{gap:12px;font-size:14px}.kb-bot-header,.kb-pane{padding:18px}.kb-footer,.kb-bot-header,.kb-section-heading{flex-wrap:wrap}.kb-tabs{gap:18px;padding:0 18px}.kb .title{flex-wrap:wrap}.kb .title-actions{width:100%}.kb-library-head{padding:18px}.kb-library-body{padding:16px 18px 18px}}
#kb-search{position:relative;margin:0 0 16px}#kb-search .icon{position:absolute;left:11px;top:50%;width:15px;height:15px;transform:translateY(-50%);color:var(--muted);pointer-events:none}#kb-search .input{width:100%;min-width:0;min-height:34px;padding:6px 10px 6px 33px;font-size:14px}#kb-search .input:focus{border-color:var(--blue);background:var(--surface)}#kb-search .input::-webkit-search-cancel-button{cursor:pointer}.kb-file-actions{display:flex;flex-wrap:wrap;gap:6px;max-width:420px;justify-content:flex-end}.kb-file-actions .btn{font-size:13px}.kb-answer-text,.kb-page-text{white-space:pre-wrap;overflow-wrap:anywhere;font-family:inherit;line-height:1.7}.kb-page-text{max-height:50vh;overflow:auto;padding:16px;background:var(--subtle);border-radius:8px}.kb-messages .kb .kb-file strong{word-break:break-word}.kb .error{font-size:14px;overflow-wrap:anywhere}@media(max-width:700px){.kb-file{flex-wrap:wrap}.kb-file>.kb-file-actions{flex:1 1 100%;max-width:none;justify-content:flex-start;padding-left:56px}}

/* Trò chuyện kiểu ChatGPT */
.kb-pane:has(>.kb-chat){padding:0}
/* Khung chat vừa màn hình: trừ thanh trên, tiêu đề trang và đầu thẻ chatbot để ô soạn câu hỏi luôn trong tầm nhìn. */
.kb-chat{display:grid;grid-template-columns:240px minmax(0,1fr);height:clamp(520px,calc(100dvh - 320px),860px)}
.kb-chat-list{display:flex;flex-direction:column;gap:6px;padding:12px;border-right:1px solid var(--line);background:var(--subtle);min-height:0;border-radius:0 0 0 8px}
.kb .kb-chat-new{display:flex;align-items:center;gap:8px;width:100%;padding:8px 10px;margin-bottom:8px;border:1px solid var(--line-strong);border-radius:6px;background:var(--surface);color:var(--ink);font:inherit;font-size:14px;font-weight:550;cursor:pointer}
.kb .kb-chat-new:hover{border-color:var(--line-strong)}
.kb-chat-new .icon{width:16px;height:16px;color:var(--muted)}
.kb-chat-items{flex:1;overflow:auto;display:flex;flex-direction:column;gap:2px;min-height:0}
.kb-chat-item{display:flex;align-items:center;border-radius:6px}
.kb-chat-item:hover{background:var(--hover)}
.kb-chat-item.active{background:var(--active)}
.kb .kb-chat-link{flex:1;min-width:0;padding:9px 10px;border:0;background:none;color:var(--ink);font:inherit;font-size:14px;text-align:left;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;cursor:pointer}
.kb-chat-item.active .kb-chat-link{color:var(--ink);font-weight:500}
.kb .kb-chat-delete{display:grid;place-items:center;width:30px;height:30px;margin-right:4px;border:0;border-radius:6px;background:none;color:var(--muted);cursor:pointer}
.kb .kb-chat-delete:hover{color:var(--red);background:var(--red-bg)}
.kb-chat-delete .icon{width:15px;height:15px}
.kb-chat-none{padding:8px 10px;font-size:13px}
.kb-chat-list .kb-footer{margin-top:8px;flex-wrap:wrap;gap:6px}
.kb-chat-main{display:flex;flex-direction:column;min-width:0;min-height:0}
.kb-thread{flex:1;overflow-y:auto;padding:28px 24px 12px;scroll-behavior:auto}
.kb-thread-inner{max-width:780px;margin:0 auto;display:flex;flex-direction:column;gap:22px}
.kb .kb-chat-older{align-self:center}
.kb-turn.user{display:flex;justify-content:flex-end}
.kb-user-message{max-width:78%;padding:10px 14px;border-radius:12px;background:var(--hover);color:var(--ink);font-size:15px;line-height:1.6;white-space:pre-wrap;overflow-wrap:anywhere}
.kb-turn.assistant{display:flex;gap:14px;align-items:flex-start}
.kb-answer{flex:1;min-width:0}
.kb-answer-text{overflow-wrap:anywhere;word-break:normal;font-size:15px;line-height:1.75;color:var(--ink)}.kb-answer-text>*:first-child{margin-top:0}.kb-answer-text>*:last-child{margin-bottom:0}.kb .kb-answer-text p{margin:0 0 12px;color:var(--ink);line-height:1.75}.kb-answer-text ul,.kb-answer-text ol{margin:4px 0 12px;padding-left:24px}.kb-answer-text li{margin:4px 0;padding-left:2px}.kb-answer-text li::marker{color:var(--muted)}.kb-answer-text h4{margin:16px 0 8px;font-size:16px;font-weight:600}.kb-answer-text strong{font-weight:600}.kb-ref{display:inline-grid;place-items:center;min-width:20px;height:18px;margin:0 2px;padding:0 5px;border:0;border-radius:999px;background:var(--blue-soft);color:var(--link);font:inherit;font-size:11px;font-weight:600;line-height:1;vertical-align:2px;cursor:pointer}.kb-ref:hover{background:var(--link);color:var(--surface)}.kb-caret{display:inline-block;width:8px;height:16px;margin-left:2px;border-radius:2px;background:var(--ink);vertical-align:-2px;animation:kb-blink 1s steps(2) infinite}@keyframes kb-blink{50%{opacity:0}}.kb-answer.typing .kb-cites,.kb-answer.typing .kb-answer-actions,.kb-answer.typing .kb-answer-note{visibility:hidden}
.kb-answer .kb-answer-note{margin:8px 0 0;padding:9px 12px;border-radius:8px;background:var(--amber-bg);color:var(--amber);font-size:14px}
.kb-answer .kb-answer-note.error{background:var(--red-bg);color:var(--red)}
.kb-cites{display:flex;flex-wrap:wrap;gap:6px;margin-top:12px}
.kb .kb-citation{display:inline-flex;align-items:center;gap:6px;max-width:100%;padding:3px 10px 3px 3px;border:1px solid var(--line);border-radius:6px;background:var(--surface);color:var(--ink);font:inherit;font-size:13px;cursor:pointer;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.kb .kb-citation:hover{border-color:var(--blue);color:var(--link)}
.kb-citation b{display:grid;place-items:center;min-width:20px;height:20px;padding:0 5px;border-radius:4px;background:var(--blue-soft);color:var(--link);font-size:12px;font-weight:600}
.kb .kb-chat-ghost{padding:5px 10px;border:1px solid transparent;border-radius:6px;background:none;color:var(--muted);font:inherit;font-size:13px;cursor:pointer}
.kb .kb-chat-ghost:hover{background:var(--hover);color:var(--ink)}
.kb .kb-chat-ghost.on{color:var(--ink);background:var(--active)}
.kb-answer-actions{display:flex;gap:6px;margin-top:10px}
.kb-typing{display:flex;align-items:center;gap:5px;min-height:30px;color:var(--muted)}
.kb-typing span{width:6px;height:6px;border-radius:50%;background:var(--muted);opacity:.35;animation:kb-dot 1.2s infinite ease-in-out}
.kb-typing span:nth-child(2){animation-delay:.15s}.kb-typing span:nth-child(3){animation-delay:.3s}
.kb-typing em{margin-left:8px;font-style:normal;font-size:14px}
@keyframes kb-dot{0%,80%,100%{opacity:.35;transform:none}40%{opacity:1;transform:translateY(-3px)}}
.kb-chat-empty{margin:auto;max-width:620px;min-height:100%;display:flex;flex-direction:column;align-items:center;justify-content:center;text-align:center;gap:10px;padding:24px 0}
.kb-chat-empty h3{font-size:18px;font-weight:600}
.kb-chat-empty p{margin:0;font-size:15px}
.kb-suggest{display:flex;flex-wrap:wrap;justify-content:center;gap:8px;margin-top:14px}
.kb .kb-suggest-item{padding:8px 12px;border:1px solid var(--line);border-radius:6px;background:var(--surface);color:var(--ink);font:inherit;font-size:14px;cursor:pointer}
.kb .kb-suggest-item:hover{border-color:var(--line-strong);background:var(--subtle)}
.kb-composer-wrap{padding:8px 24px 16px}
.kb-composer{max-width:780px;margin:0 auto;padding:10px 10px 8px 14px;border:1px solid var(--line-strong);border-radius:10px;background:var(--surface)}
.kb-composer:focus-within{border-color:var(--link);box-shadow:0 0 0 3px var(--blue-soft)}
.kb-composer textarea{display:block;width:100%;min-height:28px;max-height:220px;padding:4px 0;border:0;outline:0;resize:none;background:transparent;color:var(--ink);font:inherit;font-size:15px;line-height:1.6}
.kb-composer textarea::placeholder{color:var(--muted)}
.kb-composer.disabled{background:var(--subtle)}
.kb-composer-bar{display:flex;align-items:center;justify-content:space-between;gap:12px;margin-top:6px}
.kb-scope{position:relative}
.kb-scope summary{display:inline-flex;align-items:center;gap:6px;padding:4px 10px;border:1px solid var(--line);border-radius:6px;color:var(--muted);font-size:13px;cursor:pointer;list-style:none}
.kb-scope summary::-webkit-details-marker{display:none}
.kb-scope summary:hover,.kb-scope[open] summary{color:var(--ink);background:var(--hover)}
.kb-scope summary .icon{width:14px;height:14px}
.kb-scope-menu{position:absolute;bottom:calc(100% + 8px);left:0;z-index:5;width:min(380px,70vw);max-height:280px;overflow:auto;padding:12px;border:1px solid var(--line);border-radius:12px;background:var(--surface);box-shadow:0 10px 30px #0813231f}
.kb-scope-menu p{margin:0 0 8px;font-size:13px}
.kb-scope-menu label{display:flex;align-items:flex-start;gap:8px;padding:7px 6px;border-radius:6px;font-size:14px;overflow-wrap:anywhere;cursor:pointer}
.kb-scope-menu label:hover{background:var(--hover)}
.kb-send{display:grid;place-items:center;flex-shrink:0;width:34px;height:34px;border:0;border-radius:6px;background:var(--blue);color:var(--on-primary);cursor:pointer}
.kb-send .icon{width:18px;height:18px;transform:rotate(-90deg)}
.kb-send:disabled{background:var(--line-strong);color:var(--surface);cursor:not-allowed}
.kb-chat-hint{max-width:780px;margin:6px auto 0;text-align:center;font-size:12px}
@media(max-width:900px){.kb-chat{grid-template-columns:1fr;height:auto;min-height:0}.kb-chat-list{border-right:0;border-bottom:1px solid var(--line);border-radius:0;max-height:200px}.kb-thread{max-height:62vh;padding:20px 16px 8px}.kb-composer-wrap{padding:8px 16px 16px}.kb-user-message{max-width:88%}}
@media(prefers-reduced-motion:reduce){.kb-typing span{animation:none;opacity:.7}}
.kb-settings-grid{display:grid;grid-template-columns:minmax(0,1fr) minmax(0,1fr);gap:24px}
.kb-settings-col{display:flex;flex-direction:column;gap:18px;margin:0}
.kb-settings .field{margin:0}
.kb-settings .field label{margin-bottom:8px}
.kb-settings textarea{resize:vertical;line-height:1.6}
.kb-settings-col.field{gap:0}
.kb-settings-col.field textarea{flex:1;min-height:160px}
.kb-settings-actions{display:flex;justify-content:space-between;align-items:center;gap:12px;margin-top:24px;padding-top:20px;border-top:1px solid var(--line)}
@media(max-width:900px){.kb-settings-grid{grid-template-columns:1fr;gap:18px}}
.kb-bot{display:flex;gap:10px;align-items:center;width:100%;margin:0 0 2px;padding:8px;border:0;border-radius:6px;background:none;color:var(--ink);text-align:left;font:inherit;cursor:pointer;transition:background-color .15s ease}
.kb-bot:not(.selected):hover{background:var(--hover)}
.kb-bot .kb-avatar{width:34px;height:34px;border-radius:6px;background:var(--surface);color:var(--muted);font-size:12px;font-weight:600;box-shadow:inset 0 0 0 1px var(--line)}
.kb-bot-info{flex:1;min-width:0}
.kb-bot-info strong{display:block;font-size:14px;font-weight:500;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.kb-bot-meta{display:flex;flex-wrap:wrap;align-items:center;gap:2px 10px;margin-top:1px;font-size:12px;color:var(--muted)}
.kb-bot-chip{display:inline-flex;align-items:center;gap:5px;font-weight:400;line-height:18px}
.kb-bot-chip .icon{width:13px;height:13px}
.kb-bot-chip i{width:6px;height:6px;border-radius:50%;background:var(--faint)}
.kb-bot-chip.ok{color:var(--green)}.kb-bot-chip.ok i{background:var(--green)}
.kb-bot-chip.busy{color:var(--amber)}.kb-bot-chip.busy i{background:var(--amber)}
/* Chatbot đang chọn: cùng nền xám với mục điều hướng đang mở. */
.kb-bot.selected{background:var(--active)}
/* Tối đa ~6 chatbot và ~6 file hiển thị cùng lúc, phần còn lại cuộn. */
/* Danh sách chatbot lấp đầy chiều cao cột (bằng khung chatbot bên phải) rồi cuộn; position:absolute để danh sách dài không kéo cột cao thêm. */
.kb-library-body{flex:1;display:flex;flex-direction:column;min-height:0}
.kb-bot-scroll{position:relative;flex:1;min-height:300px;margin:-4px -8px 0 -4px}
.kb-bot-list{position:absolute;inset:0;overflow-y:auto;padding:4px 8px 10px 4px;overscroll-behavior:contain}
@media(max-width:700px){.kb-bot-scroll{min-height:0}.kb-bot-list{position:static;max-height:440px}}
.kb-file-list{max-height:620px;overflow-y:auto;margin:8px 0 0;overscroll-behavior:contain;border-bottom:1px solid var(--line)}.kb-file-list>.kb-muted{padding:12px 0;font-size:14px}
.kb-file-list>.kb-file:last-child{border-bottom:0}
.kb-bot-list,.kb-file-list{scrollbar-width:thin;scrollbar-color:var(--line-strong) transparent}
.kb-bot-list::-webkit-scrollbar,.kb-file-list::-webkit-scrollbar{width:6px}
.kb-bot-list::-webkit-scrollbar-thumb,.kb-file-list::-webkit-scrollbar-thumb{background:var(--line-strong);border-radius:3px}
/* Hộp thoại nhỏ (tạo chatbot) */
#modal.kb-dialog-sm{width:min(520px,calc(100vw - 32px))}
.kb-create{display:flex;flex-direction:column;gap:18px}
.kb-create .field{margin:0}
.kb-create .field label{margin-bottom:8px}
.kb-create textarea{resize:vertical;line-height:1.6}
.kb-create .modalfoot{margin-top:6px}
.kb-optional{color:var(--muted);font-weight:400}
/* Hộp thoại chọn từ lịch sử OCR */
#modal.kb-dialog-md{width:min(680px,calc(100vw - 32px))}
.kb-pick-search{position:relative}
.kb-pick-search .icon{position:absolute;left:12px;top:50%;width:16px;height:16px;transform:translateY(-50%);color:var(--muted);pointer-events:none}
.kb-pick-search .input{width:100%;padding-left:36px}
.kb-pick-search .input:focus{background:var(--surface);border-color:var(--blue)}
.kb-pick-list{max-height:min(52vh,520px);overflow-y:auto;margin:14px -10px 0;padding:0 10px;display:flex;flex-direction:column;gap:2px;scrollbar-width:thin;scrollbar-color:var(--line-strong) transparent}
.kb-pick{display:flex;align-items:center;gap:14px;padding:10px;border-radius:6px;transition:background-color .15s ease}
.kb-pick:hover{background:var(--subtle)}
.kb-pick .kb-file-type{min-width:44px}
.kb-pick-info{flex:1;min-width:0}
.kb-pick-info strong{display:block;font-size:15px;font-weight:550;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.kb-pick-info small{display:block;margin-top:2px;font-size:13px;color:var(--muted)}
.kb-pick.added .kb-pick-info strong{color:var(--muted)}
.kb-pick-add{display:inline-flex;align-items:center;gap:6px;flex-shrink:0;padding:5px 12px;border:1px solid var(--line-strong);border-radius:6px;background:var(--surface);color:var(--ink);font:inherit;font-size:14px;font-weight:600;cursor:pointer;transition:background-color .15s ease,color .15s ease}
.kb-pick-add:hover{background:var(--subtle)}
.kb-pick-add .icon{width:15px;height:15px}
.kb-pick-add:disabled{opacity:.6;cursor:wait}
.kb-pick-done{display:inline-flex;align-items:center;gap:5px;flex-shrink:0;padding:5px 10px;border-radius:6px;background:var(--green-bg);color:var(--green);font-size:13px;font-weight:600}
.kb-pick-done .icon{width:14px;height:14px}
.kb-pick-empty{padding:40px 12px;text-align:center;color:var(--muted);font-size:14px}
.kb-pick-foot{display:flex;align-items:center;justify-content:space-between;gap:12px;margin-top:12px;padding-top:14px;border-top:1px solid var(--line);font-size:13px;color:var(--muted)}
.kb-pick-pager{display:flex;align-items:center;gap:10px}
.kb-pick-pager span{font-variant-numeric:tabular-nums;color:var(--ink)}
/* Tablet: thư viện chatbot nằm trên, khung chatbot dùng trọn bề ngang; danh sách chatbot cuộn trong khung thấp. */
@media(max-width:1100px){.kb-layout{grid-template-columns:1fr}.kb-bot-scroll{min-height:0}.kb-bot-list{position:static;max-height:220px}.kb-bot-list{display:grid;grid-template-columns:repeat(auto-fill,minmax(240px,1fr));gap:2px 8px;align-content:start}.kb-bot{margin:0}}
