/* ═══════════════════════════════════════════════════════════════
   Cerebra Assistant — Enterprise UI
   Built to Cerebra Brand Guidelines 2.0:
   · Dark theme (mandated for digital contexts, p10)
   · Official palette (pp12–17) — Canvas/Surface backgrounds,
     Cerebra Purple accents, Cyan used sparingly, gradients only
     from Deep Navy / Indigo / Sky
   · IBM Plex Sans Arabic, the single brand typeface (p19)
   ═══════════════════════════════════════════════════════════════ */

/* Self-hosted brand typeface: no external font request, so the UI never blocks
   on an air-gapped LAN. Two subsets per weight (arabic + latin) with matching
   unicode-range, so the browser fetches only the script actually rendered.
   font-display: swap keeps text visible while a face loads.
   Files are produced by the download step documented in static/fonts/README.md. */
@font-face {
  font-family: 'IBM Plex Sans Arabic'; font-style: normal; font-weight: 300;
  font-display: swap; src: url('/static/fonts/IBMPlexSansArabic-Light-arabic.woff2') format('woff2');
  unicode-range: U+0600-06FF, U+0750-077F, U+0870-088E, U+0890-0891, U+0897-08E1, U+08E3-08FF, U+200C-200E, U+2010-2011, U+204F, U+2E41, U+FB50-FDFF, U+FE70-FE74, U+FE76-FEFC, U+102E0-102FB, U+10E60-10E7E, U+10EC2-10EC4, U+10EFC-10EFF, U+1EE00-1EE03, U+1EE05-1EE1F, U+1EE21-1EE22, U+1EE24, U+1EE27, U+1EE29-1EE32, U+1EE34-1EE37, U+1EE39, U+1EE3B, U+1EE42, U+1EE47, U+1EE49, U+1EE4B, U+1EE4D-1EE4F, U+1EE51-1EE52, U+1EE54, U+1EE57, U+1EE59, U+1EE5B, U+1EE5D, U+1EE5F, U+1EE61-1EE62, U+1EE64, U+1EE67-1EE6A, U+1EE6C-1EE72, U+1EE74-1EE77, U+1EE79-1EE7C, U+1EE7E, U+1EE80-1EE89, U+1EE8B-1EE9B, U+1EEA1-1EEA3, U+1EEA5-1EEA9, U+1EEAB-1EEBB, U+1EEF0-1EEF1;
}
@font-face {
  font-family: 'IBM Plex Sans Arabic'; font-style: normal; font-weight: 300;
  font-display: swap; src: url('/static/fonts/IBMPlexSansArabic-Light-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'IBM Plex Sans Arabic'; font-style: normal; font-weight: 400;
  font-display: swap; src: url('/static/fonts/IBMPlexSansArabic-Regular-arabic.woff2') format('woff2');
  unicode-range: U+0600-06FF, U+0750-077F, U+0870-088E, U+0890-0891, U+0897-08E1, U+08E3-08FF, U+200C-200E, U+2010-2011, U+204F, U+2E41, U+FB50-FDFF, U+FE70-FE74, U+FE76-FEFC, U+102E0-102FB, U+10E60-10E7E, U+10EC2-10EC4, U+10EFC-10EFF, U+1EE00-1EE03, U+1EE05-1EE1F, U+1EE21-1EE22, U+1EE24, U+1EE27, U+1EE29-1EE32, U+1EE34-1EE37, U+1EE39, U+1EE3B, U+1EE42, U+1EE47, U+1EE49, U+1EE4B, U+1EE4D-1EE4F, U+1EE51-1EE52, U+1EE54, U+1EE57, U+1EE59, U+1EE5B, U+1EE5D, U+1EE5F, U+1EE61-1EE62, U+1EE64, U+1EE67-1EE6A, U+1EE6C-1EE72, U+1EE74-1EE77, U+1EE79-1EE7C, U+1EE7E, U+1EE80-1EE89, U+1EE8B-1EE9B, U+1EEA1-1EEA3, U+1EEA5-1EEA9, U+1EEAB-1EEBB, U+1EEF0-1EEF1;
}
@font-face {
  font-family: 'IBM Plex Sans Arabic'; font-style: normal; font-weight: 400;
  font-display: swap; src: url('/static/fonts/IBMPlexSansArabic-Regular-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'IBM Plex Sans Arabic'; font-style: normal; font-weight: 500;
  font-display: swap; src: url('/static/fonts/IBMPlexSansArabic-Medium-arabic.woff2') format('woff2');
  unicode-range: U+0600-06FF, U+0750-077F, U+0870-088E, U+0890-0891, U+0897-08E1, U+08E3-08FF, U+200C-200E, U+2010-2011, U+204F, U+2E41, U+FB50-FDFF, U+FE70-FE74, U+FE76-FEFC, U+102E0-102FB, U+10E60-10E7E, U+10EC2-10EC4, U+10EFC-10EFF, U+1EE00-1EE03, U+1EE05-1EE1F, U+1EE21-1EE22, U+1EE24, U+1EE27, U+1EE29-1EE32, U+1EE34-1EE37, U+1EE39, U+1EE3B, U+1EE42, U+1EE47, U+1EE49, U+1EE4B, U+1EE4D-1EE4F, U+1EE51-1EE52, U+1EE54, U+1EE57, U+1EE59, U+1EE5B, U+1EE5D, U+1EE5F, U+1EE61-1EE62, U+1EE64, U+1EE67-1EE6A, U+1EE6C-1EE72, U+1EE74-1EE77, U+1EE79-1EE7C, U+1EE7E, U+1EE80-1EE89, U+1EE8B-1EE9B, U+1EEA1-1EEA3, U+1EEA5-1EEA9, U+1EEAB-1EEBB, U+1EEF0-1EEF1;
}
@font-face {
  font-family: 'IBM Plex Sans Arabic'; font-style: normal; font-weight: 500;
  font-display: swap; src: url('/static/fonts/IBMPlexSansArabic-Medium-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'IBM Plex Sans Arabic'; font-style: normal; font-weight: 600;
  font-display: swap; src: url('/static/fonts/IBMPlexSansArabic-SemiBold-arabic.woff2') format('woff2');
  unicode-range: U+0600-06FF, U+0750-077F, U+0870-088E, U+0890-0891, U+0897-08E1, U+08E3-08FF, U+200C-200E, U+2010-2011, U+204F, U+2E41, U+FB50-FDFF, U+FE70-FE74, U+FE76-FEFC, U+102E0-102FB, U+10E60-10E7E, U+10EC2-10EC4, U+10EFC-10EFF, U+1EE00-1EE03, U+1EE05-1EE1F, U+1EE21-1EE22, U+1EE24, U+1EE27, U+1EE29-1EE32, U+1EE34-1EE37, U+1EE39, U+1EE3B, U+1EE42, U+1EE47, U+1EE49, U+1EE4B, U+1EE4D-1EE4F, U+1EE51-1EE52, U+1EE54, U+1EE57, U+1EE59, U+1EE5B, U+1EE5D, U+1EE5F, U+1EE61-1EE62, U+1EE64, U+1EE67-1EE6A, U+1EE6C-1EE72, U+1EE74-1EE77, U+1EE79-1EE7C, U+1EE7E, U+1EE80-1EE89, U+1EE8B-1EE9B, U+1EEA1-1EEA3, U+1EEA5-1EEA9, U+1EEAB-1EEBB, U+1EEF0-1EEF1;
}
@font-face {
  font-family: 'IBM Plex Sans Arabic'; font-style: normal; font-weight: 600;
  font-display: swap; src: url('/static/fonts/IBMPlexSansArabic-SemiBold-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'IBM Plex Sans Arabic'; font-style: normal; font-weight: 700;
  font-display: swap; src: url('/static/fonts/IBMPlexSansArabic-Bold-arabic.woff2') format('woff2');
  unicode-range: U+0600-06FF, U+0750-077F, U+0870-088E, U+0890-0891, U+0897-08E1, U+08E3-08FF, U+200C-200E, U+2010-2011, U+204F, U+2E41, U+FB50-FDFF, U+FE70-FE74, U+FE76-FEFC, U+102E0-102FB, U+10E60-10E7E, U+10EC2-10EC4, U+10EFC-10EFF, U+1EE00-1EE03, U+1EE05-1EE1F, U+1EE21-1EE22, U+1EE24, U+1EE27, U+1EE29-1EE32, U+1EE34-1EE37, U+1EE39, U+1EE3B, U+1EE42, U+1EE47, U+1EE49, U+1EE4B, U+1EE4D-1EE4F, U+1EE51-1EE52, U+1EE54, U+1EE57, U+1EE59, U+1EE5B, U+1EE5D, U+1EE5F, U+1EE61-1EE62, U+1EE64, U+1EE67-1EE6A, U+1EE6C-1EE72, U+1EE74-1EE77, U+1EE79-1EE7C, U+1EE7E, U+1EE80-1EE89, U+1EE8B-1EE9B, U+1EEA1-1EEA3, U+1EEA5-1EEA9, U+1EEAB-1EEBB, U+1EEF0-1EEF1;
}
@font-face {
  font-family: 'IBM Plex Sans Arabic'; font-style: normal; font-weight: 700;
  font-display: swap; src: url('/static/fonts/IBMPlexSansArabic-Bold-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  /* Backgrounds (p12) */
  --canvas:  #121622;
  --surface: #182234;

  /* Text (p15) */
  --text:  #FFFFFF;
  --muted: #979DAE;

  /* Brand accents (p13) */
  --purple:      #6D68FF;
  --soft-purple: #9CA8F2;
  --cyan:        #4DFFE3;

  /* Gradient ingredients only (p14) */
  --grad-brand: linear-gradient(150deg, #1D1C5A 0%, #0D1841 100%);

  /* Borders — no official values in the guidelines; neutral light-alpha */
  --border:        rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.16);

  /* Functional (non-brand, required for UX) */
  --warn-text: #FBBF24;
  --error-text: #FCA5A5;

  /* Elevation */
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.25);
  --shadow-md: 0 6px 20px rgba(0, 0, 0, 0.30);
  --shadow-lg: 0 14px 36px rgba(0, 0, 0, 0.40);

  /* Shape */
  --radius:    16px;
  --radius-sm: 12px;

  /* Type — one typeface across everything (p19) */
  --font: 'IBM Plex Sans Arabic', system-ui, sans-serif;
  --font-mono: 'IBM Plex Mono', 'Cascadia Code', 'Consolas', monospace;
}

html { height: 100%; }

body {
  font-family: var(--font);
  background: var(--canvas);
  color: var(--text);
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

::selection { background: rgba(109, 104, 255, 0.45); color: #fff; }

/* Keyboard focus is always visible */
:focus-visible {
  outline: 2px solid var(--soft-purple);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ═══════════════ HEADER ═══════════════ */

.header {
  position: relative;
  z-index: 10;
  height: 72px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 32px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: center; text-decoration: none; }
.brand-logo { height: 26px; width: auto; display: block; }  /* horizontal logo ≥215px wide */
.brand-mark { height: 30px; width: auto; display: none; }   /* symbol, min 32px incl. padding */

.status-pill {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 16px;
  background: var(--canvas);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text);
}
.status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--cyan);
  box-shadow: 0 0 0 0 rgba(77, 255, 227, 0.40);
  animation: ping 2.4s ease-out infinite;
}
.status-pill.warn .status-dot { background: var(--warn-text); animation: none; }
.status-pill.warn { color: var(--warn-text); border-color: rgba(245, 158, 11, 0.35); }
@keyframes ping {
  0%   { box-shadow: 0 0 0 0 rgba(77, 255, 227, 0.40); }
  70%  { box-shadow: 0 0 0 6px rgba(77, 255, 227, 0); }
  100% { box-shadow: 0 0 0 0 rgba(77, 255, 227, 0); }
}

/* ═══════════════ LAYOUT ═══════════════ */

.layout {
  position: relative;
  z-index: 1;
  flex: 1;
  display: flex;
  gap: 20px;
  width: 100%;
  max-width: 1400px;
  margin: 0 auto;
  padding: 20px 28px 8px;
  min-height: 0;
}

/* ═══════════════ SIDEBAR ═══════════════ */

.sidebar {
  width: 296px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.kb-card { padding: 20px 18px; animation: fadeUp 0.4s ease both; }

.kb-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}
.kb-head-icon {
  width: 38px; height: 38px;
  border-radius: 11px;
  display: flex; align-items: center; justify-content: center;
  color: var(--soft-purple);
  background: rgba(109, 104, 255, 0.14);
}
.kb-head-icon svg { width: 20px; height: 20px; }
.kb-head h2 { font-size: 15px; font-weight: 700; letter-spacing: -0.01em; color: var(--text); }

.kb-list { list-style: none; }

.kb-item,
.kb-status {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 10px 2px;
  border-radius: 10px;
  transition: background 0.2s ease;
}
.kb-item:hover { background: rgba(109, 104, 255, 0.08); }
.kb-item + .kb-item { border-top: 1px solid var(--border); }

.kb-icon {
  width: 30px; height: 30px;
  flex-shrink: 0;
  border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  color: var(--soft-purple);
  background: rgba(109, 104, 255, 0.12);
}
.kb-icon svg { width: 16px; height: 16px; }
.kb-icon.ok { color: var(--cyan); background: rgba(77, 255, 227, 0.10); }

.kb-text {
  flex: 1;
  font-size: 13.5px;
  font-weight: 400;
  color: var(--text);
  line-height: 1.5;
}

.kb-check { color: var(--cyan); flex-shrink: 0; display: flex; }
.kb-check svg { width: 18px; height: 18px; }

.kb-status {
  margin-top: 10px;
  padding: 10px 12px;
  background: rgba(77, 255, 227, 0.06);
  border: 1px solid rgba(77, 255, 227, 0.22);
  border-radius: var(--radius-sm);
}
.kb-status .kb-text { font-weight: 600; }

/* Discreet reset button */
.btn-clear {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 16px;
  font: 500 13px/1 var(--font);
  color: var(--muted);
  background: transparent;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: color 0.2s ease, border-color 0.2s ease, background 0.2s ease;
}
.btn-clear svg { width: 15px; height: 15px; }
.btn-clear:hover { color: var(--soft-purple); border-color: var(--soft-purple); background: rgba(109, 104, 255, 0.08); }

/* ═══════════════ CHAT PANEL ═══════════════ */

.chat-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  overflow: hidden;
  animation: fadeUp 0.4s ease 0.06s both;
}

.messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 32px 36px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  scroll-behavior: smooth;
}
.messages::-webkit-scrollbar { width: 6px; }
.messages::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.14); border-radius: 99px; }
.messages::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, 0.24); }

/* ── Welcome / empty state ── */
.welcome {
  margin: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 14px;
  max-width: 560px;
  padding: 30px 16px;
  animation: fadeUp 0.45s ease both;
}
.welcome-mark {
  width: 92px; height: 92px;
  border-radius: 26px;
  background: var(--grad-brand);
  box-shadow: var(--shadow-lg);
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 6px;
}
.welcome-mark img { width: 44px; height: auto; display: block; }

/* Heading 3 of the brand type scale (32px SemiBold) */
.welcome-title {
  font-size: clamp(24px, 2.8vw, 32px);
  font-weight: 600;
  line-height: 1.3;
  letter-spacing: -0.01em;
  color: var(--text);
}
.welcome-title span { color: var(--soft-purple); }

.welcome-sub {
  font-size: 15px;
  line-height: 1.7;
  color: var(--muted);
}
.welcome-sub b { color: var(--text); font-weight: 600; }

.suggestions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin-top: 8px;
}
.chip {
  padding: 10px 16px;
  font: 400 13.5px/1.5 var(--font);
  color: var(--text);
  background: var(--canvas);
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  cursor: pointer;
  transition: color 0.2s ease, border-color 0.2s ease, background 0.2s ease;
  max-width: 100%;
}
.chip:hover { border-color: var(--soft-purple); background: rgba(109, 104, 255, 0.10); }

/* ── Message rows ── */
.msg {
  display: flex;
  gap: 12px;
  max-width: 78%;
  animation: fadeUp 0.3s ease both;
}
.msg.user { align-self: flex-end; }
.msg.assistant { align-self: flex-start; }

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Gradient orb avatar (Sky → Indigo → Deep Navy, approved gradient palette) */
.avatar {
  width: 34px; height: 34px;
  flex-shrink: 0;
  align-self: flex-end;
  border-radius: 50%;
  background: radial-gradient(circle at 28% 25%, #A7E2FF 0%, #1D1C5A 62%, #0D1841 100%);
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 2px;
}
.avatar img { width: 14px; height: auto; display: block; }

.bubble {
  padding: 14px 18px 9px;
  font-size: 15px;
  line-height: 1.7;
  border-radius: 18px;
  word-break: break-word;
  min-width: 0;
}

.msg.assistant .bubble {
  background: rgba(255, 255, 255, 0.055);
  color: var(--text);
}

.msg.user .bubble {
  background: rgba(109, 104, 255, 0.16);
  color: #fff;
}

/* Error responses (functional colours — outside brand palette by necessity) */
.msg.error .bubble {
  background: rgba(239, 68, 68, 0.10);
  color: var(--error-text);
}
.msg.error .meta { color: var(--error-text); opacity: 0.8; }

/* User text keeps typed line breaks */
.plain { white-space: pre-wrap; }

/* ── Markdown body (assistant answers) ── */
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p { margin: 0 0 10px; }
.md h1, .md h2, .md h3, .md h4, .md h5, .md h6 {
  margin: 14px 0 8px;
  font-weight: 600;
  line-height: 1.4;
  letter-spacing: -0.01em;
  color: var(--text);
}
.md h1 { font-size: 1.2em; font-weight: 700; }
.md h2 { font-size: 1.12em; font-weight: 700; }
.md h3 { font-size: 1.05em; }
.md h4, .md h5, .md h6 { font-size: 1em; }
.md ul, .md ol { margin: 0 0 10px; padding-inline-start: 22px; }
.md li { margin: 4px 0; }
.md li::marker { color: var(--soft-purple); }
.md strong { font-weight: 700; }
.md a {
  color: var(--soft-purple);
  font-weight: 500;
  text-decoration: underline;
  text-underline-offset: 2px;
  word-break: break-all;
}
.md code {
  padding: 1.5px 6px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--border);
  font-family: var(--font-mono);
  font-size: 0.86em;
  direction: ltr;
  unicode-bidi: embed;
}
.md pre {
  margin: 0 0 10px;
  padding: 13px 16px;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border);
  color: var(--text);
  overflow-x: auto;
  direction: ltr;
  text-align: left;
}
.md pre code {
  padding: 0;
  border: none;
  background: transparent;
  color: inherit;
  font-size: 13px;
  line-height: 1.6;
}
.md blockquote {
  margin: 0 0 10px;
  padding: 2px 14px;
  border-inline-start: 3px solid rgba(156, 168, 242, 0.45);
  color: var(--muted);
}
.md hr { border: none; border-top: 1px solid var(--border); margin: 12px 0; }

/* ── Answer source footer ── */
.answer-src {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 10px;
  padding-top: 9px;
  border-top: 1px dashed var(--border-strong);
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  direction: ltr;
}
.answer-src svg { width: 13px; height: 13px; flex-shrink: 0; }
.answer-src .sep { opacity: 0.5; }

/* Link to the document's official NCA page. Kept at the source row's own
   muted weight rather than the accent colour: it is provenance, not a call to
   action, and an answer's own emphasis should stay on the regulation text. The
   underline is what marks it clickable. */
.answer-src .src-link {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
  text-decoration-color: var(--border-strong);
  transition: color 0.15s ease, text-decoration-color 0.15s ease;
}
.answer-src .src-link:hover,
.answer-src .src-link:focus-visible {
  color: var(--soft-purple);
  text-decoration-color: var(--soft-purple);
}
.answer-src .src-link:focus-visible {
  outline: 2px solid var(--purple);
  outline-offset: 2px;
  border-radius: 2px;
}

/* Second source row: paired implementation-guide section */
.answer-src.guide {
  margin-top: 4px;
  padding-top: 0;
  border-top: none;
  color: var(--soft-purple);
}

/* Official term in the other-language twin document */
.answer-src.twin {
  margin-top: 4px;
  padding-top: 0;
  border-top: none;
  font-weight: 400;
}

/* Explicit no-source badge for general answers */
.answer-src.general {
  font-weight: 400;
  font-style: italic;
  opacity: 0.8;
}
.answer-src.general[dir="rtl"] { direction: rtl; }

/* "Show official text" trust toggle + verbatim source block */
.official-toggle {
  margin-top: 10px;
  padding: 6px 12px;
  font: 500 12px/1.4 var(--font);
  color: var(--soft-purple);
  background: transparent;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  cursor: pointer;
  transition: border-color 0.2s ease, background 0.2s ease;
}
.official-toggle:hover { border-color: var(--soft-purple); background: rgba(109, 104, 255, 0.10); }
.official-text {
  display: none;
  margin-top: 8px;
  padding: 10px 12px;
  font-size: 12.5px;
  line-height: 1.7;
  color: var(--muted);
  background: var(--canvas);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  max-height: 300px;
  overflow-y: auto;
}
.official-text.open { display: block; }

/* "How was this answered?" reuses the official-text panel's look but not its
   height cap: that cap exists because a clause can run thousands of
   characters, while this is a six-row list — capping it forced a scrollbar
   onto content that fits. */
.golden-badge {
  margin-top: 8px;
  padding: 5px 10px;
  font-size: 11.5px;
  line-height: 1.5;
  color: var(--ok, #4ade80);
  border: 1px solid var(--ok, #4ade80);
  border-radius: 999px;
  display: inline-block;
  opacity: 0.85;
}

.why-text { max-height: none; overflow: visible; }
.why-text ul { margin: 0; padding-inline-start: 18px; }
.why-text li { margin: 3px 0; }

/* ── Coverage pills + quick questions (sidebar) ── */
.coverage { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.cov-pill {
  padding: 5px 10px;
  font-size: 11.5px;
  line-height: 1.4;
  color: var(--text);
  background: var(--canvas);
  border: 1px solid var(--border-strong);
  border-radius: 999px;
}
/* ── Markdown tables (answers + official text) ── */
.md .tbl-wrap { overflow-x: auto; margin: 8px 0; }
.md table { border-collapse: collapse; font-size: 12.5px; width: 100%; }
.md th, .md td {
  border: 1px solid var(--border-strong);
  padding: 6px 9px;
  text-align: start;
  vertical-align: top;
}
.md th { background: rgba(109, 104, 255, 0.12); font-weight: 600; }

/* Follow-up suggestion chips under an answer */
.followups {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}
.followups .chip {
  padding: 7px 12px;
  font-size: 12.5px;
  line-height: 1.4;
}
.chip.retry {
  color: var(--warn-text, #f59e0b);
  border-color: rgba(245, 158, 11, 0.45);
}
.chip.retry:hover { background: rgba(245, 158, 11, 0.10); border-color: var(--warn-text, #f59e0b); }

/* ── Human-review disclaimer (tracker AI-risk control) ── */
.disclaimer {
  margin-top: 8px;
  text-align: center;
  font-size: 11px;
  color: var(--muted);
  opacity: 0.75;
}
.disclaimer .sep { margin: 0 6px; opacity: 0.6; }

/* ── 👍/👎 answer rating (SME accuracy sample) ── */
.feedback { display: flex; gap: 6px; margin-top: 8px; }
.fb-btn {
  background: transparent;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  padding: 3px 10px;
  font-size: 13px;
  cursor: pointer;
  transition: border-color 0.2s ease, background 0.2s ease;
}
.fb-btn:hover { border-color: var(--soft-purple); background: rgba(109, 104, 255, 0.10); }
.fb-done { font-size: 11.5px; color: var(--muted); }

/* Print-only disclaimer banner (hidden on screen) */
.print-disclaimer { display: none; }

/* ── Print / export: strip the app chrome, force readable light colors,
   keep answers with their sources and citations ── */
@media print {
  .print-disclaimer {
    display: block !important;
    border: 1.5px solid #000;
    border-radius: 6px;
    padding: 8px 12px;
    margin-bottom: 14px;
    font-size: 11px;
    font-weight: 600;
    color: #000 !important;
  }
  .feedback, .disclaimer { display: none !important; }
  body { background: #fff !important; color: #000 !important; }
  .header, .sidebar, .composer, .footer,
  .followups, .official-toggle, .typing { display: none !important; }
  .layout { display: block !important; padding: 0 !important; }
  .chat-panel { display: block !important; border: none !important; background: #fff !important; }
  .messages { overflow: visible !important; height: auto !important; max-height: none !important; padding: 0 !important; }
  .msg { max-width: 100% !important; page-break-inside: avoid; }
  .msg .avatar { display: none !important; }
  .bubble {
    background: #fff !important;
    color: #000 !important;
    border: 1px solid #bbb !important;
    box-shadow: none !important;
  }
  .bubble * { color: #000 !important; }
  .answer-src, .meta, .note { color: #444 !important; border-color: #ccc !important; }
  .answer-src svg { display: none; }
  .official-text.open {
    display: block !important;
    max-height: none !important;
    overflow: visible !important;
    background: #f6f6f6 !important;
    border-color: #ccc !important;
  }
  .md th, .md td { border-color: #999 !important; }
  .md th { background: #eee !important; }
}

/* Meta row (time / checkmarks) inside bubble */
.meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 5px;
  margin-top: 7px;
  font-size: 11.5px;
  direction: ltr;
  color: var(--muted);
}
.msg.user .meta { color: rgba(255, 255, 255, 0.65); }

/* Low-confidence note (functional warning colours) */
.note {
  margin-top: 10px;
  padding: 8px 12px;
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--warn-text);
  background: rgba(245, 158, 11, 0.08);
  border: 1px solid rgba(245, 158, 11, 0.30);
  border-radius: 10px;
}

/* ── Typing indicator ── */
.typing {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 2px 8px;
}
.typing span {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--soft-purple);
  opacity: 0.3;
  animation: bounce 1.2s ease-in-out infinite;
}
.typing span:nth-child(2) { animation-delay: 0.15s; }
.typing span:nth-child(3) { animation-delay: 0.30s; }
@keyframes bounce {
  0%, 70%, 100% { opacity: 0.25; transform: translateY(0); }
  35%           { opacity: 1;    transform: translateY(-4px); }
}

/* ═══════════════ COMPOSER ═══════════════ */

.composer {
  flex-shrink: 0;
  padding: 14px 22px 12px;
  border-top: 1px solid var(--border);
  background: var(--surface);
}

.composer-shell {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 8px 8px 8px 20px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid transparent;
  border-radius: 26px;
  transition: border-color 0.2s ease, background 0.2s ease;
}
.composer-shell:focus-within {
  border-color: rgba(109, 104, 255, 0.55);
  background: rgba(255, 255, 255, 0.075);
}

.composer-field {
  position: relative;
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  min-height: 44px;
}

#questionInput {
  width: 100%;
  max-height: 132px;
  border: none;
  outline: none;
  resize: none;
  overflow-y: hidden;
  background: transparent;
  font: 400 15px/1.55 var(--font);
  color: var(--text);
  caret-color: var(--purple);
  padding: 2px 0;
  display: block;
}
#questionInput.scrollable { overflow-y: auto; }

/* Placeholder */
.composer-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  pointer-events: none;
  transition: opacity 0.15s ease;
}
.composer-placeholder.hidden { opacity: 0; }
.ph-en {
  font-size: 14.5px;
  color: var(--muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.btn-send {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 44px; height: 44px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: var(--purple);
  color: #fff;
  cursor: pointer;
  transition: background 0.2s ease, transform 0.15s ease;
}
.btn-send svg { width: 18px; height: 18px; }
.btn-send:hover { background: #7F7BFF; transform: translateY(-1px); }
.btn-send:active { transform: translateY(0); }
.btn-send:disabled { background: rgba(109, 104, 255, 0.35); cursor: not-allowed; transform: none; }

/* ═══════════════ FOOTER ═══════════════ */

.footer {
  position: relative;
  z-index: 1;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 0 12px;
  font-size: 12.5px;
  color: var(--muted);
}
.footer b { color: var(--text); font-weight: 600; margin-left: 2px; }
.footer-spark { width: 14px; height: 14px; color: var(--purple); }

/* ═══════════════ RESPONSIVE ═══════════════ */

/* Laptop */
@media (max-width: 1180px) {
  .sidebar { width: 260px; }
  .messages { padding: 26px 26px; }
}

/* Tablet — sidebar stacks above chat */
@media (max-width: 900px) {
  body { overflow: auto; height: auto; min-height: 100vh; }
  .layout { flex-direction: column; padding: 16px; }
  .sidebar { width: 100%; flex-direction: row; align-items: stretch; }
  .kb-card { flex: 1; }
  .btn-clear { align-self: flex-end; }
  .chat-panel { min-height: 64vh; }
  .msg { max-width: 88%; }
}

/* Mobile — chat comes first so the composer is immediately usable;
   header switches to the symbol logo (min 32px, p5) */
@media (max-width: 620px) {
  .header { height: 60px; padding: 0 14px; }
  .brand-logo { display: none; }
  .brand-mark { display: block; }
  .status-pill { font-size: 10px; padding: 6px 11px; }
  .layout { padding: 12px; gap: 12px; }
  .chat-panel { order: 1; min-height: 74vh; }
  .sidebar { order: 2; flex-direction: column; }
  .btn-clear { align-self: stretch; }
  .messages { padding: 18px 14px; gap: 16px; }
  .msg { max-width: 94%; gap: 8px; }
  .avatar { width: 30px; height: 30px; }
  .avatar img { width: 13px; }
  .bubble { font-size: 14.5px; padding: 12px 15px 8px; }
  .welcome-mark { width: 76px; height: 76px; border-radius: 22px; }
  .welcome-mark img { width: 36px; }
  .composer { padding: 10px 12px 10px; }
  .btn-send { width: 40px; height: 40px; }
}

/* Respect users who prefer reduced motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  .messages { scroll-behavior: auto; }
}
