/* ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
   Pháp chế Kiểm soát — Dark Imperial Legal Theme
   Warm charcoal × Amber gold × Playfair Display serif
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root, [data-theme="dark"] {
  /* ── Backgrounds — warm dark ── */
  --bg:         #0e0d0b;
  --bg-2:       #141210;
  --bg-3:       #1c1917;
  --bg-4:       #242118;
  --bg-5:       #2d2920;

  /* ── Borders — warm stone ── */
  --border:     #302c23;
  --border-2:   #403928;
  --border-3:   #574e38;

  /* ── Text — parchment tones ── */
  --text:       #ede5d4;
  --text-2:     #a8967a;
  --text-3:     #6b5c44;

  /* ── Accent — amber gold ── */
  --accent:     #c4882a;
  --accent-2:   #9f6d1e;
  --accent-3:   #e8aa3a;
  --accent-dim: rgba(196, 136, 42, 0.11);
  --accent-glow: rgba(196, 136, 42, 0.055);
  --cite-bg:     rgba(196, 136, 42, 0.13);
  --cite-border: rgba(196, 136, 42, 0.42);
  --cite-text:   #e8aa3a;
  --highlight:   rgba(232, 170, 58, 0.35);

  /* ── Status ── */
  --green:   #4ade80;
  --yellow:  #fbbf24;
  --red:     #f87171;
  --purple:  #c084fc;
  --blue:    #60a5fa;

  /* ── Geometry ── */
  --radius:    8px;
  --radius-sm: 5px;
  --radius-lg: 14px;
  --shadow:    0 4px 24px rgba(0,0,0,0.55);
  --shadow-sm: 0 2px 8px rgba(0,0,0,0.3);

  /* ── Typography ── */
  --font-display: 'Playfair Display', Georgia, 'Times New Roman', serif;
  --font-body:    'DM Sans', system-ui, -apple-system, sans-serif;
  --font-mono:    'JetBrains Mono', 'Fira Code', monospace;
}

/* ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
   LIGHT THEME — Paper Imperial (cream parchment + dark amber)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ */
[data-theme="light"] {
  --bg:         #faf6ec;
  --bg-2:       #f3ecd9;
  --bg-3:       #ebe2c8;
  --bg-4:       #e0d4b3;
  --bg-5:       #d4c596;

  --border:     #ddd1ad;
  --border-2:   #c5b585;
  --border-3:   #9c8a5b;

  --text:       #2a2218;
  --text-2:     #6b5e44;
  --text-3:     #8e7e5d;

  --accent:     #9b5e0c;
  --accent-2:   #7a4a08;
  --accent-3:   #c4882a;
  --accent-dim: rgba(155, 94, 12, 0.10);
  --accent-glow: rgba(155, 94, 12, 0.04);
  --cite-bg:     rgba(155, 94, 12, 0.13);
  --cite-border: rgba(155, 94, 12, 0.4);
  --cite-text:   #7a4a08;
  --highlight:   rgba(255, 214, 102, 0.55);

  --green:   #16a34a;
  --yellow:  #ca8a04;
  --red:     #dc2626;
  --purple:  #9333ea;
  --blue:    #2563eb;

  --shadow:    0 4px 20px rgba(74, 51, 8, 0.12);
  --shadow-sm: 0 2px 6px rgba(74, 51, 8, 0.08);
}

html, body { height: 100%; overflow: hidden; }

body {
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.65;
  background: var(--bg);
  color: var(--text);
}

/* ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
   APP SHELL
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ */
.app { display: flex; flex-direction: column; height: 100vh; }

/* ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
   HEADER
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  height: 58px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 10;
  position: relative;
}

/* Amber gradient rule at the very bottom */
.header::after {
  content: '';
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 1px;
  background: linear-gradient(90deg,
    transparent 0%,
    var(--accent-2) 20%,
    var(--accent-3) 50%,
    var(--accent-2) 80%,
    transparent 100%
  );
  opacity: 0.55;
}

.header-left { display: flex; align-items: center; gap: 12px; }

.logo-icon {
  width: 34px; height: 34px;
  flex-shrink: 0;
  object-fit: contain;
  border-radius: 5px;
  filter: drop-shadow(0 0 10px rgba(196,136,42,0.35));
}

.header-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 16px;
  color: var(--text);
  letter-spacing: 0.01em;
}

.header-sub {
  font-size: 11.5px;
  color: var(--text-3);
  padding-left: 12px;
  border-left: 1px solid var(--border-2);
  font-weight: 300;
  letter-spacing: 0.025em;
}

.header-right { display: flex; gap: 8px; }

.btn-icon {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-3);
  cursor: pointer;
  padding: 7px;
  display: flex;
  align-items: center;
  transition: background 0.18s, color 0.18s, border-color 0.18s;
}
.btn-icon svg { width: 15px; height: 15px; }
.btn-icon:hover {
  background: var(--accent-dim);
  color: var(--accent);
  border-color: var(--border-3);
}

/* ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
   MAIN LAYOUT
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ */
.main { display: flex; flex: 1; overflow: hidden; }

/* ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
   SIDEBAR
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ */
.sidebar {
  width: 272px;
  flex-shrink: 0;
  background: var(--bg-2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-section {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 16px 14px;
  border-bottom: 1px solid var(--border);
}
.sidebar-section:last-child {
  border-bottom: none;
  flex: 1;
  overflow: hidden;
}

.sidebar-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.13em;
  color: var(--text-3);
  margin-bottom: 10px;
}

/* ── Session list ── */
.sessions-section {
  max-height: 42vh;
  flex: 0 0 auto;
}

.sidebar-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.sidebar-section-header .sidebar-label { margin-bottom: 0; }

.btn-new-session {
  background: var(--accent-dim);
  border: 1px solid var(--border-3);
  color: var(--accent);
  border-radius: 4px;
  width: 22px; height: 22px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.18s, color 0.18s, border-color 0.18s;
  padding: 0;
}
.btn-new-session:hover {
  background: var(--accent);
  color: var(--bg);
  border-color: var(--accent);
}
.btn-new-session svg { width: 12px; height: 12px; }

.session-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
  flex: 1;
  padding-right: 2px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.session-item {
  position: relative;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.15s;
  display: flex;
  flex-direction: column;
  gap: 2px;
  border: 1px solid transparent;
}
.session-item:hover { background: var(--bg-3); }
.session-item.active {
  background: var(--accent-dim);
  border-color: rgba(196, 136, 42, 0.28);
}

.session-item-title {
  font-size: 12.5px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding-right: 18px;
  font-weight: 400;
}

.session-item-meta {
  font-size: 10px;
  color: var(--text-3);
  font-family: var(--font-mono);
}

.session-delete-btn {
  position: absolute;
  top: 6px; right: 5px;
  background: none;
  border: none;
  color: var(--text-3);
  cursor: pointer;
  padding: 2px;
  border-radius: 3px;
  opacity: 0;
  transition: opacity 0.12s, color 0.12s, background 0.12s;
  line-height: 0;
}
.session-item:hover .session-delete-btn { opacity: 1; }
.session-delete-btn:hover { color: var(--red); background: rgba(248,113,113,.1); }
.session-delete-btn svg { width: 11px; height: 11px; }

.session-empty {
  font-size: 11.5px;
  color: var(--text-3);
  padding: 4px 0;
  font-style: italic;
}

/* ── Document cards ── */
.doc-list { display: flex; flex-direction: column; gap: 6px; }
.loading-hint { color: var(--text-3); font-size: 13px; padding: 4px 0; }

.doc-card {
  padding: 10px 12px 10px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-3);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  position: relative;
}
/* Left bookmark stripe */
.doc-card::before {
  content: '';
  position: absolute;
  left: 0; top: 4px; bottom: 4px;
  width: 2.5px;
  border-radius: 0 2px 2px 0;
  background: var(--border-2);
  transition: background 0.18s;
}
.doc-card:hover { border-color: var(--border-3); background: var(--bg-4); }
.doc-card:hover::before { background: var(--accent); }
.doc-card.active { border-color: rgba(196,136,42,.32); background: var(--accent-dim); }
.doc-card.active::before { background: var(--accent-3); }

.doc-card-name {
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.doc-card-desc {
  font-size: 11px;
  color: var(--text-3);
  line-height: 1.45;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.doc-card-meta {
  font-size: 10px;
  color: var(--text-3);
  margin-top: 5px;
  font-family: var(--font-mono);
}

/* ── Structure tree ── */
.doc-structure {
  overflow-y: auto;
  flex: 1;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.tree-node {
  padding: 3px 0 3px 12px;
  border-left: 1px solid var(--border);
  margin-left: 6px;
  font-size: 12px;
  color: var(--text-3);
  cursor: pointer;
  transition: color 0.12s, border-left-color 0.12s;
  line-height: 1.45;
}
.tree-node:hover { color: var(--accent); border-left-color: var(--accent); }
.tree-node.depth-0 {
  font-weight: 600;
  font-size: 12px;
  color: var(--text-2);
  border-left: none;
  margin-left: 0;
  padding-left: 0;
}
.tree-node.depth-0:hover { color: var(--accent); }
.tree-node.depth-1 { color: var(--text-2); }
.tree-node.depth-2 { font-size: 11.5px; padding-left: 20px; }
.tree-node.depth-3 { font-size: 11px; padding-left: 32px; }

/* ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
   CHAT PANEL
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ */
.chat-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
}

/* ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
   MESSAGES
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 28px 0 12px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.messages::-webkit-scrollbar { width: 5px; }
.messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ── Welcome screen ── */
.welcome {
  max-width: 580px;
  margin: 52px auto;
  padding: 0 28px;
  text-align: center;
}

.welcome-icon {
  font-size: 46px;
  margin-bottom: 20px;
  display: block;
  filter: drop-shadow(0 4px 14px rgba(196,136,42,0.35));
}

.welcome h2 {
  font-family: var(--font-display);
  font-size: 23px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: 0.01em;
  margin-bottom: 0;
}

/* Ornamental rule below heading */
.welcome h2::after {
  content: '';
  display: block;
  width: 52px;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  margin: 14px auto 0;
}

.welcome p {
  color: var(--text-2);
  font-size: 13.5px;
  line-height: 1.82;
  margin-top: 16px;
  margin-bottom: 28px;
  font-weight: 300;
}

.suggestion-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.chip {
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-2);
  background: var(--bg-2);
  color: var(--text-2);
  font-size: 12.5px;
  cursor: pointer;
  transition: border-color 0.18s, color 0.18s, background 0.18s;
  text-align: left;
  font-family: var(--font-body);
  font-weight: 400;
  position: relative;
  overflow: hidden;
}
/* Left accent stripe on chip */
.chip::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 2px;
  background: var(--accent);
  opacity: 0;
  transition: opacity 0.18s;
}
.chip:hover {
  border-color: var(--border-3);
  color: var(--text);
  background: var(--bg-3);
}
.chip:hover::before { opacity: 1; }

/* ── Message bubbles ── */
@keyframes msgIn {
  from { opacity: 0; transform: translateY(7px); }
  to   { opacity: 1; transform: translateY(0); }
}

.message {
  max-width: 880px;
  margin: 0 auto 20px;
  padding: 0 28px;
  animation: msgIn 0.22s ease forwards;
}

.message-role {
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.message.user .message-role { color: var(--accent); }
.message.assistant .message-role { color: var(--text-3); }

.message-content {
  border-radius: var(--radius);
  padding: 16px 20px;
  line-height: 1.78;
  overflow-wrap: break-word;
  word-wrap: break-word;
}

/* User: warm left-border accent */
.message.user .message-content {
  background: var(--bg-3);
  border: 1px solid var(--border-2);
  border-left: 3px solid var(--accent);
  padding-left: 17px;
}

/* Assistant: clean dark card */
.message.assistant .message-content {
  background: var(--bg-2);
  border: 1px solid var(--border);
}

/* ── Markdown inside messages ── */
.message-content p { margin-bottom: 10px; }
.message-content p:last-child { margin-bottom: 0; }
.message-content strong { color: var(--text); font-weight: 600; }
.message-content em { font-style: italic; color: var(--text-2); }
.message-content ul,
.message-content ol { padding-left: 20px; margin-bottom: 10px; }
.message-content li { margin-bottom: 4px; }

.message-content h1,
.message-content h2,
.message-content h3 {
  font-family: var(--font-display);
  margin: 16px 0 8px;
  color: var(--text);
}
.message-content h1 { font-size: 18px; font-weight: 700; }
.message-content h2 { font-size: 16px; font-weight: 600; }
.message-content h3 { font-size: 14.5px; font-weight: 600; }

.message-content code {
  background: var(--bg-4);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 6px;
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: var(--accent-3);
}
.message-content pre {
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px;
  overflow-x: auto;
  margin: 12px 0;
}
.message-content pre code {
  background: none;
  border: none;
  padding: 0;
  font-size: 13px;
  color: var(--text);
}
.message-content blockquote {
  border-left: 2px solid var(--accent);
  margin: 12px 0;
  padding: 8px 16px;
  background: var(--accent-glow);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--text-2);
}

/* Tables */
.message-content table {
  border-collapse: collapse;
  margin: 14px 0;
  font-size: 13px;
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  display: table;
}
.message-content thead { background: var(--bg-4); }
.message-content thead th {
  font-weight: 600;
  color: var(--text);
  text-align: left;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-2);
  border-right: 1px solid var(--border);
  font-size: 12.5px;
  letter-spacing: 0.025em;
}
.message-content thead th:last-child { border-right: none; }
.message-content tbody td {
  padding: 9px 14px;
  border-top: 1px solid var(--border);
  border-right: 1px solid var(--border);
  color: var(--text-2);
  vertical-align: top;
  line-height: 1.55;
}
.message-content tbody td:last-child { border-right: none; }
.message-content tbody tr:hover { background: var(--accent-glow); }
.message-content table strong { color: var(--text); }

/* ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
   PIPELINE STATUS
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ */
.pipeline-status {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.status-line {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-3);
}

@keyframes spin { to { transform: rotate(360deg); } }

.status-line .spinner {
  width: 12px; height: 12px;
  border: 1.5px solid var(--border-2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.85s linear infinite;
  flex-shrink: 0;
}
.status-text { color: var(--text-3); }

.thinking-block {
  font-size: 12px;
  color: var(--text-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-3);
  overflow: hidden;
}
.thinking-block summary {
  padding: 6px 10px;
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: baseline;
  gap: 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.thinking-block summary::-webkit-details-marker { display: none; }
.thinking-block summary::before { content: '▶'; font-size: 9px; color: var(--accent); flex-shrink: 0; }
.thinking-block[open] summary::before { content: '▼'; }
.thinking-label { color: var(--accent); font-weight: 600; flex-shrink: 0; }
.thinking-body {
  padding: 8px 10px;
  border-top: 1px solid var(--border);
  white-space: pre-wrap;
  line-height: 1.62;
  color: var(--text-2);
}

.nodes-found {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 5px;
  font-size: 12px;
}
.nodes-label { color: var(--text-3); font-weight: 600; flex-shrink: 0; }
.refs-label-ext { color: var(--purple); }

.node-chip {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 4px;
  font-size: 11px;
  border: 1px solid var(--border-2);
  background: var(--bg-4);
  color: var(--text-2);
  font-family: var(--font-mono);
}
.ref-chip-resolved {
  border-color: rgba(192, 132, 252, 0.32);
  background: rgba(192, 132, 252, 0.07);
  color: #c084fc;
}

/* ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
   CITATIONS
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ */
.citations-area {
  margin-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.citations-header {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-3);
  margin-bottom: 2px;
}

.citation-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-3);
  overflow: hidden;
  transition: border-color 0.15s;
}
.citation-card:hover { border-color: var(--border-2); }

.citation-card-header {
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  grid-template-rows: auto auto;
  align-items: center;
  column-gap: 8px;
  row-gap: 2px;
  padding: 8px 12px;
  cursor: pointer;
  transition: background 0.15s;
  background: var(--bg-4);
}
.citation-card-header:hover { background: var(--bg-5); }

.citation-card-icon { font-size: 12px; grid-row: 1; grid-column: 1; }

.citation-card-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  grid-row: 1; grid-column: 2;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.citation-card.open .citation-card-title { white-space: normal; }

.citation-card-doc {
  font-size: 10px;
  color: var(--text-3);
  grid-row: 1; grid-column: 3;
  white-space: nowrap;
  font-family: var(--font-mono);
}

.citation-ref-from {
  font-size: 10px;
  color: var(--purple);
  font-style: italic;
  grid-row: 2; grid-column: 2 / span 2;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.citation-card-ref { border-color: rgba(192, 132, 252, 0.2); }
.citation-card-ref .citation-card-header { background: rgba(192, 132, 252, 0.05); }

.citation-card-toggle {
  color: var(--text-3);
  font-size: 11px;
  transition: transform 0.22s;
  grid-row: 1; grid-column: 4;
}
.citation-card.open .citation-card-toggle { transform: rotate(180deg); }

.citation-card-body {
  display: none;
  padding: 10px 12px;
  border-top: 1px solid var(--border);
}
.citation-card.open .citation-card-body { display: block; }

.citation-content-text {
  font-size: 12.5px;
  color: var(--text-2);
  line-height: 1.78;
  white-space: pre-wrap;
  max-height: 320px;
  overflow-y: auto;
  scrollbar-width: thin;
}

.status-badge {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 3px;
  font-size: 10px;
  font-weight: 600;
  margin-left: 6px;
  font-family: var(--font-body);
}
.status-badge.active   { background: rgba(74,222,128,.1);  color: var(--green);  border: 1px solid rgba(74,222,128,.25);  }
.status-badge.abolished{ background: rgba(248,113,113,.1); color: var(--red);    border: 1px solid rgba(248,113,113,.25); }
.status-badge.amended  { background: rgba(251,191,36,.1);  color: var(--yellow); border: 1px solid rgba(251,191,36,.25);  }

/* References section inside citation body */
.refs-section { margin-top: 10px; }
.refs-label { font-size: 11px; color: var(--text-3); margin-bottom: 6px; font-weight: 600; }
.ref-chips { display: flex; flex-wrap: wrap; gap: 5px; }
.ref-chip {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 4px;
  font-size: 11px;
  border: 1px solid var(--border-2);
  background: var(--bg-4);
  color: var(--text-2);
  cursor: default;
  font-family: var(--font-mono);
}
.ref-chip.external {
  border-color: rgba(96,165,250,.32);
  color: var(--blue);
  background: rgba(96,165,250,.07);
}

/* ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
   MESSAGE ACTIONS (copy / export)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ */
.message-actions {
  display: flex;
  gap: 6px;
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
}

.msg-action-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 11px;
  font-size: 11px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-3);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  font-family: var(--font-body);
  letter-spacing: 0.025em;
}
.msg-action-btn:hover {
  background: var(--accent-dim);
  border-color: var(--border-3);
  color: var(--accent);
}
.msg-action-btn:disabled { opacity: .4; cursor: not-allowed; }
.msg-action-btn svg { width: 11px; height: 11px; flex-shrink: 0; }
.msg-action-btn.copied {
  background: rgba(74,222,128,.1);
  border-color: rgba(74,222,128,.28);
  color: var(--green);
}

/* ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
   STREAMING CURSOR
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ */
@keyframes blink { 50% { opacity: 0; } }

.cursor {
  display: inline-block;
  width: 2px;
  height: 1em;
  background: var(--accent);
  margin-left: 2px;
  vertical-align: text-bottom;
  animation: blink 1s step-end infinite;
}

/* ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
   INPUT AREA
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ */
.input-area {
  border-top: 1px solid var(--border);
  padding: 16px 28px;
  background: var(--bg);
  flex-shrink: 0;
}

.input-box {
  max-width: 880px;
  margin: 0 auto;
  display: flex;
  gap: 10px;
  align-items: flex-end;
  background: var(--bg-2);
  border: 1px solid var(--border-2);
  border-radius: var(--radius);
  padding: 10px 14px;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.input-box:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

textarea#user-input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  resize: none;
  font-family: var(--font-body);
  font-size: 14px;
  color: var(--text);
  line-height: 1.6;
  max-height: 160px;
  overflow-y: auto;
  scrollbar-width: thin;
}
textarea#user-input::placeholder { color: var(--text-3); }

.send-btn {
  width: 36px; height: 36px;
  border-radius: 7px;
  background: var(--accent);
  border: none;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: background 0.18s;
}
.send-btn:disabled { background: var(--bg-4); cursor: not-allowed; opacity: .45; }
.send-btn:not(:disabled):hover { background: var(--accent-3); }
.send-btn svg { width: 15px; height: 15px; color: var(--bg); }

.input-hint {
  max-width: 880px;
  margin: 6px auto 0;
  font-size: 11px;
  color: var(--text-3);
  text-align: center;
  letter-spacing: 0.01em;
}

/* ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
   SCROLLBARS
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-track { background: transparent; }

/* ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
   INLINE CITATION CHIPS (trong câu trả lời)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ */
.cite-chip {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 1px 7px;
  margin: 0 2px;
  font-size: 11px;
  font-family: var(--font-body);
  font-weight: 500;
  line-height: 1.4;
  border: 1px solid var(--cite-border);
  background: var(--cite-bg);
  color: var(--cite-text);
  border-radius: 4px;
  cursor: pointer;
  vertical-align: baseline;
  position: relative;
  top: -1px;
  transition: background 0.15s, transform 0.1s;
  white-space: nowrap;
}
.cite-chip::before {
  content: '§';
  font-weight: 700;
  font-family: var(--font-display);
  opacity: 0.7;
  margin-right: 1px;
}
.cite-chip:hover {
  background: var(--accent);
  color: var(--bg);
  transform: translateY(-1px);
}
.cite-chip:active { transform: translateY(0); }

/* Flash highlight khi nhảy đến trong doc viewer */
@keyframes citeFlash {
  0%   { background-color: var(--highlight); }
  100% { background-color: transparent; }
}
.cite-target-flash {
  animation: citeFlash 2s ease-out;
  border-radius: 4px;
}

/* ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
   DOC VIEWER PANEL (slide-in từ phải)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ */
.doc-viewer {
  width: 0;
  flex-shrink: 0;
  background: var(--bg-2);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: width 0.28s cubic-bezier(0.4, 0, 0.2, 1);
}
.doc-viewer.open { width: 44%; min-width: 420px; max-width: 720px; }

.doc-viewer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 8px 0 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  position: relative;
}
.doc-viewer-header::after {
  content: '';
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--accent-2) 40%, var(--accent) 50%, var(--accent-2) 60%, transparent);
  opacity: 0.35;
}

.doc-viewer-tabs {
  display: flex;
  gap: 2px;
  flex: 1;
  overflow-x: auto;
  scrollbar-width: none;
}
.doc-viewer-tabs::-webkit-scrollbar { display: none; }
.doc-tab {
  padding: 7px 14px;
  font-size: 12px;
  font-weight: 500;
  font-family: var(--font-body);
  color: var(--text-3);
  cursor: pointer;
  border-radius: 6px 6px 0 0;
  border: 1px solid transparent;
  border-bottom: none;
  background: transparent;
  transition: all 0.15s;
  white-space: nowrap;
}
.doc-tab:hover { color: var(--text-2); background: var(--bg-3); }
.doc-tab.active {
  color: var(--accent);
  background: var(--bg);
  border-color: var(--border);
  position: relative;
}
.doc-tab.active::after {
  content: '';
  position: absolute;
  bottom: -1px; left: 0; right: 0;
  height: 2px;
  background: var(--accent);
}

.doc-viewer-close {
  flex-shrink: 0;
  margin-bottom: 4px;
}

/* Search bar trong doc viewer */
.doc-viewer-search {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-2);
  flex-shrink: 0;
}
.doc-viewer-search svg { width: 13px; height: 13px; color: var(--text-3); flex-shrink: 0; }
.doc-viewer-search input {
  flex: 1;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 5px 9px;
  font-size: 12.5px;
  color: var(--text);
  outline: none;
  font-family: var(--font-body);
  transition: border-color 0.15s;
}
.doc-viewer-search input:focus { border-color: var(--accent); }
.doc-viewer-search input::placeholder { color: var(--text-3); }
.doc-search-count {
  font-size: 11px;
  color: var(--text-3);
  font-family: var(--font-mono);
  white-space: nowrap;
  min-width: 38px;
  text-align: right;
}

/* Content area */
.doc-viewer-content {
  flex: 1;
  overflow-y: auto;
  padding: 18px 22px 60px;
  font-family: var(--font-body);
  font-size: 13.5px;
  line-height: 1.72;
  color: var(--text);
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

/* Render markdown trong doc viewer */
.doc-viewer-content h1,
.doc-viewer-content h2,
.doc-viewer-content h3,
.doc-viewer-content h4 {
  font-family: var(--font-display);
  color: var(--text);
  margin: 18px 0 8px;
  scroll-margin-top: 12px;
}
.doc-viewer-content h1 { font-size: 19px; font-weight: 700; border-bottom: 1px solid var(--border); padding-bottom: 6px; }
.doc-viewer-content h2 { font-size: 16.5px; font-weight: 600; color: var(--accent); }
.doc-viewer-content h3 { font-size: 15px; font-weight: 600; }
.doc-viewer-content h4 { font-size: 14px; font-weight: 600; color: var(--text-2); }
.doc-viewer-content p { margin-bottom: 10px; }
.doc-viewer-content ul,
.doc-viewer-content ol { padding-left: 22px; margin-bottom: 10px; }
.doc-viewer-content li { margin-bottom: 3px; }
.doc-viewer-content strong { color: var(--text); font-weight: 600; }
.doc-viewer-content blockquote {
  border-left: 2px solid var(--accent);
  margin: 10px 0;
  padding: 6px 14px;
  background: var(--accent-glow);
  color: var(--text-2);
}
.doc-viewer-content table {
  border-collapse: collapse;
  margin: 12px 0;
  font-size: 12.5px;
  width: 100%;
  border: 1px solid var(--border);
}
.doc-viewer-content th,
.doc-viewer-content td {
  padding: 7px 10px;
  border: 1px solid var(--border);
  text-align: left;
}
.doc-viewer-content thead { background: var(--bg-4); }

/* Highlight Điều khi nhảy đến */
.doc-viewer-content .dieu-highlight {
  animation: dieuHighlight 2.4s ease-out;
  border-radius: 4px;
  padding: 2px 6px;
  margin: -2px -6px;
}
@keyframes dieuHighlight {
  0%   { background: var(--highlight); }
  100% { background: transparent; }
}

/* Search highlight */
.doc-viewer-content mark.search-hit {
  background: var(--highlight);
  color: var(--text);
  padding: 0 2px;
  border-radius: 2px;
}
.doc-viewer-content mark.search-hit.current {
  background: var(--accent);
  color: var(--bg);
}

/* Empty / loading state cho doc viewer */
.doc-viewer-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-3);
  font-size: 13px;
  padding: 40px;
  text-align: center;
}
.doc-viewer-empty-icon {
  font-size: 36px;
  margin-bottom: 12px;
  opacity: 0.5;
}

/* Theme toggle icons swap */
[data-theme="light"] .btn-icon .icon-moon { display: none; }
[data-theme="light"] .btn-icon .icon-sun  { display: block !important; }

/* Sidebar khi sáng — slightly more contrast */
[data-theme="light"] .session-item.active,
[data-theme="light"] .doc-card.active {
  background: var(--accent-dim);
}

/* Trong light theme: header amber line đậm hơn vì nền sáng dễ chìm */
[data-theme="light"] .header::after { opacity: 0.7; }
[data-theme="light"] .doc-viewer-header::after { opacity: 0.5; }
