/* ==========================================================================
   AskBot AI Assistant — clinic help desk chat (front-end demo)
   Palette: ivory paper, deep indigo sidebar, apricot accents
   Type: Fraunces (display, greeting) + Plus Jakarta Sans (interface)
   ========================================================================== */

:root {
  --bg: #F6F3EC;
  --paper: #FFFFFF;
  --paper-2: #FBF9F4;
  --line: #E6E1D6;
  --line-2: #D9D3C6;
  --ink: #1D1B2E;
  --dim: #555168;
  --faint: #6E6A84;
  --side: #1E1A3A;
  --side-2: #282350;
  --side-3: #342E66;
  --side-line: rgba(255, 255, 255, .09);
  --side-text: #F1EEFF;
  --side-dim: #B9B3DA;
  --indigo: #4B3FD1;
  --indigo-d: #3A2FB4;
  --indigo-soft: #ECEAFE;
  --apricot: #F2A65A;
  --apricot-d: #B4620F;
  --apricot-soft: #FDEEDD;
  --mint: #18885F;
  --mint-soft: #E1F4EC;
  --rose: #C8434F;
  --rose-soft: #FBE7E8;
  --f-display: 'Fraunces', Georgia, 'Times New Roman', serif;
  --f-ui: 'Plus Jakarta Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --r: 18px;
  --ease: cubic-bezier(.2, .8, .2, 1);
  --shadow: 0 24px 60px -30px rgba(30, 26, 58, .35);
  --shadow-sm: 0 2px 6px rgba(30, 26, 58, .06);
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 500 15px/1.55 var(--f-ui); -webkit-font-smoothing: antialiased; overflow: hidden; }
h1, h2, h3, p, ol, ul { margin: 0; }
ul, ol { padding: 0; list-style: none; }
a { color: var(--indigo); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
:focus-visible { outline: 2.5px solid var(--indigo); outline-offset: 2px; border-radius: 8px; }
.sidebar :focus-visible { outline-color: var(--apricot); }
::selection { background: var(--indigo); color: #fff; }
.sprite { position: absolute; }
.ic { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.sr-only { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: 12px; top: -60px; z-index: 100; background: var(--indigo); color: #fff; padding: 10px 16px; border-radius: 10px; font-weight: 700; }
.skip:focus { top: 12px; }
.dim { color: var(--dim); }
.noscript { padding: 20px; margin: 20px; border: 1px solid var(--line-2); border-radius: var(--r); }
.only-m { display: none !important; }

/* ------------------------------ Shell ------------------------------ */
.app { display: grid; grid-template-columns: 300px minmax(0, 1fr); height: 100vh; height: 100dvh; }
.sidebar {
  display: flex; flex-direction: column; gap: 18px; min-height: 0;
  padding: 20px 14px 16px; color: var(--side-text);
  background: radial-gradient(120% 60% at 0% 0%, #2E2766 0%, transparent 60%), var(--side);
}
.brand { display: flex; align-items: center; gap: 12px; padding: 2px 8px; }
.brand-mark { display: grid; place-items: center; width: 42px; height: 42px; border-radius: 13px; background: var(--indigo); box-shadow: 0 10px 24px -10px rgba(75, 63, 209, .9); }
.brand-mark svg { width: 34px; height: 34px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text strong { font: 600 23px/1 var(--f-display); letter-spacing: -.01em; }
.brand-text small { color: var(--side-dim); font-size: 12.5px; margin-top: 4px; }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-link { position: relative; display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 12px; color: var(--side-dim); font-weight: 600; text-decoration: none; transition: background .2s, color .2s; }
.nav-link:hover { background: var(--side-2); color: var(--side-text); }
.nav-link.is-active { background: var(--side-3); color: #fff; }
.nav-link.is-active .ic { color: var(--apricot); }
.nav-count { margin-left: auto; font-size: 11.5px; font-weight: 800; padding: 3px 8px; border-radius: 99px; background: var(--side-2); color: var(--side-dim); }
.nav-count.is-warn { background: var(--apricot); color: #2A1705; }
.nav-count[hidden] { display: none; }

.side-panel { display: flex; flex-direction: column; gap: 16px; flex: 1; min-height: 0; }
.convos { display: flex; flex-direction: column; gap: 10px; flex: 1; min-height: 0; border-top: 1px solid var(--side-line); padding-top: 16px; }
.convos-head { display: flex; align-items: center; justify-content: space-between; padding: 0 8px; }
.convos-head h2 { font-size: 11.5px; font-weight: 800; letter-spacing: .14em; text-transform: uppercase; color: var(--side-dim); }
.btn-new { justify-content: center; background: var(--apricot); color: #2A1705; height: 42px; }
.btn-new:hover { background: #F6B776; }
.convo-search { position: relative; display: flex; align-items: center; }
.convo-search .ic { position: absolute; left: 12px; color: var(--side-dim); }
.convo-search input { width: 100%; height: 38px; padding: 0 12px 0 38px; border-radius: 10px; border: 1px solid var(--side-line); background: rgba(255, 255, 255, .05); color: var(--side-text); outline: none; }
.convo-search input::placeholder { color: var(--side-dim); }
.convo-search input:focus { border-color: var(--apricot); }
.convo-list { flex: 1; min-height: 0; overflow: auto; margin: 0 -6px; padding: 0 6px; scrollbar-width: thin; scrollbar-color: var(--side-3) transparent; }
.convo-day { font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--side-dim); padding: 10px 10px 4px; opacity: .85; }
.convo { display: block; width: 100%; text-align: left; padding: 10px 12px; border-radius: 12px; color: var(--side-text); transition: background .15s; }
.convo:hover { background: var(--side-2); }
.convo.is-active { background: var(--side-3); box-shadow: inset 3px 0 0 var(--apricot); }
.convo-top { display: flex; align-items: baseline; gap: 8px; }
.convo-top b { flex: 1; min-width: 0; font-weight: 700; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.convo-top time { font-size: 11.5px; color: var(--side-dim); white-space: nowrap; }
.convo p { font-size: 12.5px; color: var(--side-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.convo .flagdot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--apricot); margin-right: 6px; vertical-align: middle; }
.convo-empty { color: var(--side-dim); font-size: 13px; padding: 14px 10px; }

.side-foot { display: flex; flex-direction: column; gap: 8px; padding: 12px 6px 0; border-top: 1px solid var(--side-line); }
.btn-reset { display: inline-flex; align-items: center; gap: 8px; align-self: flex-start; font-size: 13px; font-weight: 700; color: var(--side-dim); padding: 8px 12px; border-radius: 10px; border: 1px dashed rgba(255, 255, 255, .22); }
.btn-reset:hover { color: #fff; border-color: var(--apricot); }
.btn-reset .ic { width: 15px; height: 15px; }
.credit { font-size: 12px; color: var(--side-dim); }

.main-col { display: flex; flex-direction: column; min-width: 0; min-height: 0; height: 100vh; height: 100dvh; }
.topbar { display: flex; align-items: center; gap: 16px; padding: 14px 28px; min-height: 70px; border-bottom: 1px solid var(--line); background: rgba(246, 243, 236, .9); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); }
.tb-title { display: flex; align-items: center; gap: 12px; min-width: 0; }
.tb-title h1 { font: 600 22px/1.15 var(--f-display); letter-spacing: -.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.demo-badge { flex: none; font-size: 11px; font-weight: 800; letter-spacing: .05em; text-transform: uppercase; padding: 5px 10px; border-radius: 99px; color: var(--apricot-d); background: var(--apricot-soft); border: 1px solid #F5CFA6; white-space: nowrap; }
.offline-pill { display: inline-flex; align-items: center; gap: 7px; margin-left: auto; font-size: 12.5px; font-weight: 600; color: var(--dim); padding: 6px 12px; border-radius: 99px; background: var(--paper); border: 1px solid var(--line); white-space: nowrap; }
.offline-pill .ic { width: 15px; height: 15px; color: var(--mint); }
.tb-actions { display: flex; gap: 8px; }
main { flex: 1; min-height: 0; overflow: auto; outline: none; }
.view[hidden] { display: none !important; }
#knowledge, #insights { padding: 28px 28px 48px; max-width: 1320px; }
.mobile-foot { display: none; }

/* Buttons */
.btn { display: inline-flex; align-items: center; gap: 8px; height: 40px; padding: 0 16px; border-radius: 12px; font-weight: 700; font-size: 14px; white-space: nowrap; text-decoration: none; transition: background .2s, border-color .2s, color .2s, transform .15s; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--indigo); color: #fff; }
.btn-primary:hover { background: var(--indigo-d); }
.btn-ghost { border: 1px solid var(--line-2); color: var(--ink); background: var(--paper); }
.btn-ghost:hover { border-color: var(--indigo); color: var(--indigo); }
.btn-danger { background: var(--rose); color: #fff; }
.btn-sm { height: 32px; padding: 0 11px; font-size: 13px; border-radius: 10px; }
.btn-wa { background: #E3F6EC; color: #0E6B45; justify-content: center; }
.btn-wa:hover { background: #D2F0E0; }
.icon-btn { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 10px; color: var(--faint); transition: background .15s, color .15s; }
.icon-btn:hover { background: var(--bg); color: var(--ink); }
.sidebar .icon-btn { color: var(--side-dim); }
.sidebar .icon-btn:hover { background: var(--side-2); color: #fff; }

/* ------------------------------ Chat ------------------------------ */
#chat { height: 100%; }
.chat-layout { display: grid; grid-template-columns: minmax(0, 1fr) 300px; height: 100%; }
.chat-col { display: flex; flex-direction: column; min-height: 0; height: 100%; }
.thread { flex: 1; min-height: 0; overflow: auto; padding: 28px 28px 12px; scroll-behavior: smooth; }
.thread > * { max-width: 780px; margin-left: auto; margin-right: auto; }
.day-sep { display: flex; align-items: center; gap: 12px; font-size: 12px; font-weight: 700; color: var(--faint); letter-spacing: .06em; text-transform: uppercase; margin: 6px auto 18px; }
.day-sep::before, .day-sep::after { content: ""; flex: 1; height: 1px; background: var(--line); }

.msg { display: flex; gap: 12px; margin-bottom: 20px; animation: rise .35s var(--ease); }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.msg-av { flex: none; width: 36px; height: 36px; border-radius: 12px; display: grid; place-items: center; background: var(--indigo); color: #fff; }
.msg-av svg { width: 26px; height: 26px; }
.msg-body { min-width: 0; max-width: 620px; }
.msg-meta { display: flex; align-items: baseline; gap: 8px; font-size: 12.5px; color: var(--faint); margin-bottom: 5px; }
.msg-meta b { color: var(--ink); font-weight: 700; font-size: 13px; }
.bubble { padding: 13px 16px; border-radius: 6px 18px 18px 18px; background: var(--paper); border: 1px solid var(--line); box-shadow: var(--shadow-sm); overflow-wrap: anywhere; }
.bubble p + p, .bubble p + ul, .bubble ul + p { margin-top: 8px; }
.bubble ul { margin-top: 6px; display: grid; gap: 4px; }
.bubble li { position: relative; padding-left: 16px; }
.bubble li::before { content: ""; position: absolute; left: 2px; top: .68em; width: 6px; height: 6px; border-radius: 50%; background: var(--apricot); }
.bubble strong { font-weight: 800; }
.bubble a { font-weight: 700; text-underline-offset: 3px; }
.caret { display: inline-block; width: 8px; height: 1.05em; margin-left: 2px; vertical-align: -2px; border-radius: 2px; background: var(--indigo); animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.msg.me { flex-direction: row-reverse; }
.msg.me .msg-body { display: flex; flex-direction: column; align-items: flex-end; }
.msg.me .msg-meta { justify-content: flex-end; }
.msg.me .bubble { background: var(--indigo); color: #fff; border-color: var(--indigo); border-radius: 18px 6px 18px 18px; box-shadow: 0 10px 22px -14px rgba(75, 63, 209, .9); }
.msg.me .msg-av { background: var(--apricot-soft); color: var(--apricot-d); font: 800 13px var(--f-ui); }
.msg.fallback .bubble { background: var(--apricot-soft); border-color: #F5CFA6; }

.msg-foot { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 10px; margin-top: 8px; }
.match { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--dim); background: var(--paper-2); border: 1px solid var(--line); padding: 4px 10px; border-radius: 99px; max-width: 100%; }
.match .ic { width: 13px; height: 13px; color: var(--mint); }
.match.none .ic { color: var(--apricot-d); }
.match b { font-weight: 700; color: var(--ink); }
.fb { display: inline-flex; gap: 2px; margin-left: auto; }
.fb button { display: grid; place-items: center; width: 32px; height: 30px; border-radius: 9px; color: var(--faint); border: 1px solid transparent; transition: background .15s, color .15s; }
.fb button:hover { background: var(--paper); border-color: var(--line); color: var(--ink); }
.fb button .ic { width: 16px; height: 16px; }
.fb button[data-fb="up"][aria-pressed="true"] { background: var(--mint-soft); color: var(--mint); border-color: #BFE6D4; }
.fb button[data-fb="down"][aria-pressed="true"] { background: var(--rose-soft); color: var(--rose); border-color: #F3C6CA; }
.fb-note { width: 100%; font-size: 12.5px; color: var(--dim); }
.related { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.related span { font-size: 12px; font-weight: 700; color: var(--faint); align-self: center; margin-right: 2px; }
.chip-q { font-size: 13px; font-weight: 600; color: var(--indigo); background: var(--indigo-soft); padding: 6px 12px; border-radius: 99px; border: 1px solid transparent; text-align: left; transition: border-color .15s, background .15s; }
.chip-q:hover { border-color: var(--indigo); background: #E2DFFD; }
.stopped { font-size: 12px; color: var(--faint); font-style: italic; }

.typing .bubble { display: inline-flex; gap: 5px; padding: 15px 18px; }
.typing .bubble i { width: 7px; height: 7px; border-radius: 50%; background: var(--indigo); opacity: .35; animation: dot 1.2s infinite; }
.typing .bubble i:nth-child(2) { animation-delay: .15s; }
.typing .bubble i:nth-child(3) { animation-delay: .3s; }
@keyframes dot { 0%, 60%, 100% { opacity: .3; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-4px); } }

.welcome { text-align: center; padding: 40px 0 10px; }
.welcome-mark { display: inline-grid; place-items: center; width: 68px; height: 68px; border-radius: 22px; background: var(--indigo); box-shadow: 0 20px 40px -18px rgba(75, 63, 209, .8); margin-bottom: 20px; }
.welcome-mark svg { width: 52px; height: 52px; }
.welcome h2 { font: 500 clamp(30px, 3.6vw, 44px)/1.1 var(--f-display); letter-spacing: -.02em; }
.welcome h2 em { font-style: italic; color: var(--indigo); }
.welcome p { color: var(--dim); max-width: 520px; margin: 12px auto 0; }
.starter { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-top: 28px; text-align: left; }
.starter button { display: flex; flex-direction: column; gap: 10px; padding: 16px; border-radius: 16px; background: var(--paper); border: 1px solid var(--line); box-shadow: var(--shadow-sm); transition: border-color .2s, transform .2s var(--ease), box-shadow .2s; }
.starter button:hover { border-color: var(--indigo); transform: translateY(-2px); box-shadow: var(--shadow); }
.starter .s-ic { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 10px; background: var(--apricot-soft); color: var(--apricot-d); }
.starter b { font-size: 14px; font-weight: 700; }
.starter small { font-size: 12.5px; color: var(--faint); margin-top: -6px; }

.composer { padding: 10px 28px 18px; background: linear-gradient(180deg, rgba(246, 243, 236, 0), var(--bg) 26%); }
.composer > * { max-width: 780px; margin-left: auto; margin-right: auto; }
.suggest { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 10px; scrollbar-width: none; }
.suggest::-webkit-scrollbar { display: none; }
.suggest .chip-q { flex: none; background: var(--paper); border-color: var(--line); color: var(--ink); }
.suggest .chip-q:hover { border-color: var(--indigo); color: var(--indigo); }
.composer-box { display: flex; align-items: flex-end; gap: 10px; padding: 8px 8px 8px 16px; border-radius: 18px; background: var(--paper); border: 1.5px solid var(--line-2); box-shadow: var(--shadow); transition: border-color .2s; }
.composer-box:focus-within { border-color: var(--indigo); }
.composer-box textarea { flex: 1; min-width: 0; border: 0; outline: none; resize: none; background: transparent; padding: 9px 0; max-height: 160px; line-height: 1.45; }
.send { display: grid; place-items: center; width: 42px; height: 42px; border-radius: 13px; background: var(--indigo); color: #fff; flex: none; transition: background .2s; }
.send:hover { background: var(--indigo-d); }
.send.is-stop { background: var(--ink); }
.composer-note { font-size: 11.5px; color: var(--faint); text-align: center; margin-top: 9px; line-height: 1.45; }

/* Right rail */
.rail { display: flex; flex-direction: column; gap: 14px; padding: 22px 22px 22px 0; overflow: auto; }
.rcard { background: var(--paper); border: 1px solid var(--line); border-radius: var(--r); padding: 18px; }
.rc-h { display: flex; align-items: center; gap: 8px; font: 600 17px/1.2 var(--f-display); margin-bottom: 12px; }
.rc-h .ic { color: var(--indigo); }
.how { background: linear-gradient(160deg, var(--indigo-soft), var(--paper) 70%); }
.steps { counter-reset: s; display: grid; gap: 12px; }
.steps li { counter-increment: s; position: relative; padding-left: 36px; font-size: 13px; color: var(--dim); }
.steps li::before { content: counter(s); position: absolute; left: 0; top: 0; width: 24px; height: 24px; border-radius: 8px; display: grid; place-items: center; background: var(--indigo); color: #fff; font-size: 12px; font-weight: 800; }
.steps b { display: block; color: var(--ink); font-size: 13.5px; }
.steps em { font-style: normal; font-weight: 800; color: var(--indigo); }
.pop { display: grid; gap: 4px; }
.pop button { width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 10px; text-align: left; padding: 8px 10px; border-radius: 10px; font-size: 13.5px; font-weight: 600; }
.pop button:hover { background: var(--bg); color: var(--indigo); }
.pop small { font-size: 11.5px; color: var(--faint); font-weight: 700; white-space: nowrap; }
.desk-hours { font: 600 22px/1.1 var(--f-display); }
.desk-addr { font-size: 13px; color: var(--dim); margin: 6px 0 14px; }
.desk .btn { width: 100%; }

/* ------------------------------ Knowledge base ------------------------------ */
.view-head { margin-bottom: 22px; }
.eyebrow { font-size: 12px; font-weight: 800; letter-spacing: .14em; text-transform: uppercase; color: var(--apricot-d); margin-bottom: 4px; }
.display { font: 500 clamp(30px, 3.2vw, 42px)/1.05 var(--f-display); letter-spacing: -.02em; margin-bottom: 6px; }
.card { background: var(--paper); border: 1px solid var(--line); border-radius: var(--r); padding: 20px; min-width: 0; }
.card-h { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 14px; }
.card-h h3, .kb-form h3 { display: flex; align-items: center; gap: 8px; font: 600 19px/1.2 var(--f-display); }
.card-h h3 .ic { color: var(--apricot-d); }
.sub { font-size: 13px; color: var(--faint); margin-top: 3px; }
.kb-layout { display: grid; grid-template-columns: minmax(300px, 400px) minmax(0, 1fr); gap: 20px; align-items: start; }
.kb-form { display: grid; gap: 14px; position: sticky; top: 0; }
.f { display: grid; gap: 6px; min-width: 0; }
.f-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.f label { font-size: 13px; font-weight: 700; color: var(--dim); }
.f label i { color: var(--rose); font-style: normal; }
.f input, .f textarea, .f select, .kb-tools select, .field-search input { width: 100%; height: 42px; padding: 0 12px; border-radius: 11px; border: 1px solid var(--line-2); background: var(--paper-2); outline: none; transition: border-color .15s, box-shadow .15s; }
.f textarea { height: auto; padding: 10px 12px; resize: vertical; line-height: 1.5; }
.f input:focus, .f textarea:focus, .f select:focus, .kb-tools select:focus, .field-search input:focus { border-color: var(--indigo); box-shadow: 0 0 0 3px var(--indigo-soft); }
.f [aria-invalid="true"] { border-color: var(--rose); }
select { appearance: none; -webkit-appearance: none; padding-right: 34px !important; cursor: pointer; background-image: linear-gradient(45deg, transparent 50%, var(--dim) 50%), linear-gradient(135deg, var(--dim) 50%, transparent 50%); background-position: calc(100% - 17px) 18px, calc(100% - 12px) 18px; background-size: 5px 5px; background-repeat: no-repeat; }
.hint { font-size: 12px; color: var(--faint); }
.err { font-size: 12.5px; color: var(--rose); font-weight: 600; }
.err:empty { display: none; }
.kw-preview { display: flex; flex-wrap: wrap; gap: 6px; min-height: 0; }
.kw-preview:empty { display: none; }
.kw { font-size: 12px; font-weight: 700; color: var(--mint); background: var(--mint-soft); padding: 3px 9px; border-radius: 99px; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.kb-main { display: grid; gap: 16px; min-width: 0; }
.attention { border-color: #F5CFA6; background: linear-gradient(180deg, var(--apricot-soft), var(--paper) 140px); }
.att-list { display: grid; gap: 8px; }
.att-list li { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 12px; background: var(--paper); border: 1px solid var(--line); }
.att-list .grow { flex: 1; min-width: 0; }
.att-list b { display: block; font-weight: 700; font-size: 14px; }
.att-list small { color: var(--faint); font-size: 12px; }
.att-tag { font-size: 11px; font-weight: 800; letter-spacing: .04em; text-transform: uppercase; padding: 3px 8px; border-radius: 99px; white-space: nowrap; }
.att-tag.unanswered { background: var(--apricot-soft); color: var(--apricot-d); }
.att-tag.flagged { background: var(--rose-soft); color: var(--rose); }
.att-empty { padding: 14px; color: var(--dim); font-size: 14px; text-align: center; }
.att-acts { display: flex; gap: 6px; }
.kb-tools { display: flex; gap: 10px; }
.field-search { position: relative; flex: 1; display: flex; align-items: center; }
.field-search .ic { position: absolute; left: 12px; color: var(--faint); }
.field-search input { padding-left: 38px; background: var(--paper); }
.kb-tools select { width: auto; min-width: 180px; background-color: var(--paper); }
.kb-list { display: grid; gap: 10px; }
.kb-item { background: var(--paper); border: 1px solid var(--line); border-radius: 16px; overflow: hidden; transition: border-color .2s; }
.kb-item.is-open { border-color: var(--indigo); box-shadow: var(--shadow-sm); }
.kb-item.is-new { animation: newItem 1.8s var(--ease); }
@keyframes newItem { 0%, 40% { background: var(--indigo-soft); } 100% { background: var(--paper); } }
.kb-q { width: 100%; display: flex; align-items: center; gap: 12px; padding: 14px 16px; text-align: left; }
.kb-q .grow { flex: 1; min-width: 0; }
.kb-q b { display: block; font-weight: 700; }
.kb-q small { font-size: 12px; color: var(--faint); }
.cat { font-size: 11.5px; font-weight: 800; padding: 3px 9px; border-radius: 99px; background: var(--indigo-soft); color: var(--indigo); white-space: nowrap; }
.chev { width: 18px; height: 18px; color: var(--faint); transition: transform .2s; }
.kb-item.is-open .chev { transform: rotate(45deg); }
.kb-a { padding: 0 16px 16px; display: grid; gap: 12px; }
.kb-a .bubble { box-shadow: none; background: var(--paper-2); border-radius: 12px; }
.kb-kws { display: flex; flex-wrap: wrap; gap: 6px; }
.kb-acts { display: flex; gap: 8px; flex-wrap: wrap; }
.kb-empty { padding: 30px; text-align: center; color: var(--dim); border: 1px dashed var(--line-2); border-radius: 16px; }

/* ------------------------------ Insights ------------------------------ */
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 16px; }
.kpi { background: var(--paper); border: 1px solid var(--line); border-radius: var(--r); padding: 18px; }
.kpi.hero { background: var(--side); color: var(--side-text); border-color: var(--side); }
.kpi-l { font-size: 13px; font-weight: 700; color: var(--dim); }
.kpi.hero .kpi-l, .kpi.hero .kpi-f { color: var(--side-dim); }
.kpi-v { font: 500 42px/1 var(--f-display); letter-spacing: -.02em; margin: 12px 0 8px; }
.kpi-v small { font: 700 15px var(--f-ui); color: var(--faint); margin-left: 4px; letter-spacing: 0; }
.kpi.hero .kpi-v small { color: var(--side-dim); }
.kpi-f { font-size: 12.5px; color: var(--faint); font-weight: 600; }
.in-grid { display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(0, 1fr); gap: 16px; margin-bottom: 16px; }
.key { display: flex; gap: 12px; font-size: 12px; color: var(--dim); font-weight: 600; flex-wrap: wrap; }
.key li { display: flex; align-items: center; gap: 6px; }
.key i { width: 10px; height: 10px; border-radius: 3px; }
.k-up { background: var(--indigo); }
.k-down { background: var(--rose); }
.k-line { background: var(--apricot); height: 3px !important; border-radius: 2px !important; }
.chart { position: relative; min-height: 280px; }
.chart svg { display: block; overflow: visible; }
.chart .gl { stroke: var(--line); }
.chart .ax { fill: var(--faint); font: 600 11px var(--f-ui); }
.chart .up { fill: var(--indigo); }
.chart .down { fill: var(--rose); }
.chart .rate { fill: none; stroke: var(--apricot); stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; }
.chart .dot { fill: var(--paper); stroke: var(--apricot); stroke-width: 2.5; }
.chart .col { outline: none; }
.chart .col:hover .hit, .chart .col:focus-visible .hit { fill: rgba(75, 63, 209, .07); }
.chart .today-l { fill: var(--indigo); font-weight: 800; }
.tip { position: fixed; z-index: 80; pointer-events: none; background: var(--ink); color: #fff; font-size: 12.5px; font-weight: 600; padding: 8px 11px; border-radius: 10px; box-shadow: var(--shadow); white-space: nowrap; transform: translate(-50%, calc(-100% - 10px)); }
.topics { display: grid; gap: 14px; }
.topics li { display: grid; gap: 6px; }
.t-top { display: flex; justify-content: space-between; gap: 10px; font-size: 13.5px; font-weight: 600; }
.t-top span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.t-top b { font-weight: 800; color: var(--indigo); }
.t-bar { height: 8px; border-radius: 9px; background: var(--bg); overflow: hidden; }
.t-bar i { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--indigo), #8378F0); }
.fb-list { display: grid; }
.fb-list li { display: flex; gap: 12px; align-items: flex-start; padding: 12px 0; border-top: 1px solid var(--line); }
.fb-list li:first-child { border-top: 0; }
.fb-ic { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 10px; flex: none; }
.fb-ic.up { background: var(--mint-soft); color: var(--mint); }
.fb-ic.down { background: var(--rose-soft); color: var(--rose); }
.fb-list .grow { flex: 1; min-width: 0; }
.fb-list b { display: block; font-weight: 700; font-size: 14px; }
.fb-list small { color: var(--faint); font-size: 12.5px; }
.fb-empty { color: var(--dim); padding: 12px 0; }

/* Dialog + toasts */
.dlg { border: 0; border-radius: 20px; padding: 24px; width: min(420px, calc(100vw - 32px)); background: var(--paper); color: var(--ink); box-shadow: var(--shadow); }
.dlg::backdrop { background: rgba(30, 26, 58, .45); backdrop-filter: blur(3px); }
.dlg[open] { animation: rise .25s var(--ease); }
.dlg h2 { font: 600 22px/1.2 var(--f-display); margin-bottom: 8px; }
.dlg p { color: var(--dim); }
.dlg-f { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }
.toasts { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 90; display: grid; gap: 8px; justify-items: center; width: max-content; max-width: calc(100vw - 32px); }
.toast { display: flex; align-items: center; gap: 10px; padding: 11px 16px; border-radius: 12px; background: var(--ink); color: #fff; font-size: 14px; font-weight: 600; box-shadow: var(--shadow); animation: rise .25s var(--ease); }
.toast .ic { color: #9DE3C4; }

/* ------------------------------ Responsive ------------------------------ */
@media (max-width: 1280px) {
  .chat-layout { grid-template-columns: minmax(0, 1fr); }
  .rail { display: none; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 1100px) {
  .app { grid-template-columns: 264px minmax(0, 1fr); }
  .offline-pill span { display: none; }
  .kb-layout, .in-grid { grid-template-columns: minmax(0, 1fr); }
  .kb-form { position: static; }
}
@media (max-width: 860px) {
  .app { display: block; }
  .only-m { display: flex !important; }
  .sidebar { position: static; padding: 0; background: none; display: block; }
  .brand { display: none; }
  .nav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 60; flex-direction: row; gap: 0;
    padding: 6px 6px calc(6px + env(safe-area-inset-bottom)); background: var(--side); border-top: 1px solid var(--side-line);
  }
  .nav-link { flex: 1; flex-direction: column; gap: 3px; padding: 7px 2px; font-size: 11px; text-align: center; border-radius: 10px; min-width: 0; }
  .nav-link span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
  .nav-link .ic { width: 20px; height: 20px; }
  .nav-count { position: absolute; top: 2px; left: 56%; margin: 0; font-size: 10px; padding: 2px 5px; }
  .side-panel { display: none; position: fixed; left: 0; right: 0; top: 0; bottom: 64px; z-index: 55; padding: 18px 16px 14px; background: var(--side); }
  body.show-convos .side-panel { display: flex; }
  .convos { border-top: 0; padding-top: 0; }
  .main-col { padding-bottom: 64px; }
  .topbar { padding: 10px 16px; min-height: 60px; gap: 10px; }
  .tb-title { flex: 1; }
  .tb-title h1 { font-size: 19px; }
  .offline-pill { display: none; }
  .tb-actions .btn span { display: none; }
  .tb-actions .btn { width: 40px; padding: 0; justify-content: center; }
  .thread { padding: 18px 16px 8px; }
  .composer { padding: 6px 16px 12px; }
  #knowledge, #insights { padding: 20px 16px 30px; }
  .mobile-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 18px 16px 24px; border-top: 1px solid var(--line); }
  #chat:not([hidden]) ~ .mobile-foot { display: none; }
  .mobile-foot .btn-reset { color: var(--dim); border-color: var(--line-2); }
  .mobile-foot .credit { color: var(--faint); }
  .toasts { bottom: 80px; }
}
@media (max-width: 640px) {
  .starter { grid-template-columns: 1fr 1fr; }
  .welcome { padding-top: 20px; }
  .msg-av { width: 30px; height: 30px; border-radius: 10px; }
  .msg-av svg { width: 22px; height: 22px; }
  .msg { gap: 9px; }
  .kpis { gap: 10px; }
  .kpi { padding: 14px; }
  .kpi-v { font-size: 32px; }
  .f-row { grid-template-columns: 1fr; }
  .kb-tools { flex-direction: column; }
  .kb-tools select { width: 100%; }
  .att-list li { flex-wrap: wrap; }
  .att-acts { width: 100%; justify-content: flex-end; }
  .demo-badge { font-size: 10px; padding: 4px 8px; }
  .composer-note { font-size: 11px; }
}
@media (max-width: 400px) {
  .starter { grid-template-columns: 1fr; }
  .starter button { flex-direction: row; align-items: center; padding: 12px; }
  .starter small { display: none; }
  .tb-actions [data-action="delete-chat"] { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; scroll-behavior: auto !important; }
  .caret { display: none; }
}
.tb-actions[hidden] { display: none; }
.btn[hidden] { display: none; }
@media (max-width: 860px) { .hide-m { display: none; } }
@media (max-width: 640px) {
  .topbar { align-items: center; }
  .tb-title { flex-direction: column; align-items: flex-start; gap: 3px; }
  .tb-title h1 { max-width: 100%; font-size: 18px; }
  .card-h { flex-wrap: wrap; }
}
