:root {
  --bg: #f3efe6;
  --ink: #1c1a16;
  --muted: #5c564c;
  --panel: #fffdf8;
  --line: #d9d0c0;
  --fact: #1f6b3a;
  --fact-bg: #e7f5ec;
  --reason: #5a5348;
  --suggest: #8a4b12;
  --suggest-bg: #f8efe4;
  --accent: #0b4f6c;
  --chip: #e8f1f5;
  --user-bubble: #2a2a28;
  --user-ink: #f7f4ee;
  --bot-bubble: #eee8dc;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: "Source Han Serif SC", "Noto Serif SC", "Songti SC", Georgia, serif;
  color: var(--ink);
  background:
    radial-gradient(1200px 600px at 10% -10%, #e7dcc8 0%, transparent 55%),
    linear-gradient(180deg, #efe7d8, var(--bg));
  display: flex;
  flex-direction: column;
  min-height: 100%;
}

.top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 0.85rem 1.25rem;
  border-bottom: 1px solid var(--line);
  background: rgba(255,253,248,0.85);
  backdrop-filter: blur(6px);
  flex-shrink: 0;
}
.brand { font-size: 1.35rem; letter-spacing: 0.04em; }
.sub { color: var(--muted); font-size: 0.85rem; margin-top: 0.15rem; }
.filters { display: flex; gap: 0.75rem; font-size: 0.85rem; flex-wrap: wrap; }

.panes {
  display: grid;
  /* evidence | source | chat(right) */
  grid-template-columns: minmax(220px, 0.95fr) minmax(260px, 1.15fr) minmax(300px, 0.95fr);
  gap: 0.75rem;
  flex: 1;
  min-height: 0;
  padding: 0.75rem;
}
.pane {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  min-height: 0;
  box-shadow: 0 10px 30px rgba(40,30,10,0.05);
}
.pane-title {
  padding: 0.65rem 0.9rem;
  border-bottom: 1px solid var(--line);
  font-weight: 600;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
}
.messages, .evidence-list, .source-text {
  overflow: auto;
  flex: 1;
  min-height: 0;
  padding: 0.9rem;
}

/* Chat bubbles: assistant left, user right */
.messages {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
.msg {
  max-width: 92%;
  line-height: 1.55;
  border-radius: 14px;
  padding: 0.7rem 0.85rem;
}
.msg.user {
  align-self: flex-end;
  background: var(--user-bubble);
  color: var(--user-ink);
  white-space: pre-wrap;
  border-bottom-right-radius: 4px;
}
.msg.bot {
  align-self: flex-start;
  background: var(--bot-bubble);
  color: var(--ink);
  border-bottom-left-radius: 4px;
}
.msg.bot h3 { margin: 0.4rem 0; font-size: 1.05rem; }
.msg.bot.thinking {
  opacity: 0.75;
  font-style: italic;
}

.layer-fact {
  background: var(--fact-bg);
  border-left: 3px solid var(--fact);
  padding: 0.55rem 0.7rem;
  margin: 0.4rem 0;
  color: var(--fact);
  border-radius: 0 6px 6px 0;
}
.layer-reason {
  color: var(--reason);
  font-style: italic;
  margin: 0.35rem 0;
}
.layer-suggest {
  background: var(--suggest-bg);
  border-left: 3px solid var(--suggest);
  padding: 0.55rem 0.7rem;
  margin: 0.4rem 0;
  color: var(--suggest);
  border-radius: 0 6px 6px 0;
}
.chip {
  display: inline-block;
  background: var(--chip);
  color: var(--accent);
  border-radius: 4px;
  padding: 0 0.35rem;
  margin: 0 0.15rem;
  cursor: pointer;
  font-family: ui-monospace, Menlo, monospace;
  font-size: 0.85em;
}
.badge {
  display: inline-block;
  font-size: 0.75rem;
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 0 0.3rem;
  margin-left: 0.35rem;
  color: var(--muted);
}
.ask {
  border-top: 1px solid var(--line);
  padding: 0.65rem;
  display: grid;
  gap: 0.4rem;
  flex-shrink: 0;
  background: #fbf8f1;
  border-radius: 0 0 10px 10px;
}
textarea {
  width: 100%;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.55rem 0.65rem;
  font: inherit;
  background: #fff;
}
.ask-actions { display: flex; gap: 0.4rem; }
button {
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: 6px;
  padding: 0.45rem 0.9rem;
  cursor: pointer;
  font: inherit;
}
button.linkish, .linkish {
  background: transparent;
  color: var(--accent);
  padding: 0;
  text-decoration: underline;
}
#btnThumbsUp, #btnThumbsDown { background: #6b6458; }
.ev-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.6rem 0.7rem;
  margin-bottom: 0.55rem;
  cursor: pointer;
}
.ev-item:hover { border-color: var(--accent); }
.ev-item .why { color: var(--muted); font-size: 0.8rem; margin-top: 0.25rem; }
.ev-item mark, .source-text mark {
  background: #ffe08a;
  padding: 0 0.1rem;
}
.source-meta {
  padding: 0.4rem 0.9rem;
  color: var(--muted);
  font-size: 0.85rem;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.source-text {
  margin: 0;
  white-space: pre-wrap;
  font-family: "SF Mono", ui-monospace, Menlo, monospace;
  font-size: 0.82rem;
  line-height: 1.45;
}
.disclaimer { color: var(--muted); font-size: 0.85rem; margin-top: 0.75rem; }
.status { font-size: 0.85rem; color: var(--accent); }

@media (max-width: 1100px) {
  .panes {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(280px, 42vh) minmax(220px, 28vh) minmax(360px, 1fr);
  }
  .pane.chat { order: 3; }
  .pane.evidence { order: 1; }
  .pane.source { order: 2; }
}
