:root {
  --ink: #18201f;
  --muted: #66706e;
  --line: #dce2df;
  --paper: #ffffff;
  --wash: #f4f6f4;
  --panel: #eef2ef;
  --accent: #147568;
  --accent-dark: #0d594f;
  --amber: #bd7a18;
  --danger: #b3483d;
  --sidebar: 248px;
  --evidence: 340px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  color: var(--ink);
  background: var(--wash);
  font-family: Inter, "Segoe UI", "Microsoft YaHei", sans-serif;
  letter-spacing: 0;
}
button, textarea, select { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }

.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar) minmax(440px, 1fr) var(--evidence);
  width: 100%;
  height: 100vh;
  overflow: hidden;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 22px;
  padding: 22px 18px 18px;
  border-right: 1px solid var(--line);
  background: #f8faf8;
  overflow-y: auto;
  min-height: 0;
  height: 100vh;
}
.brand { display: flex; align-items: center; gap: 11px; min-height: 42px; }
.brand-mark, .avatar {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
  color: white;
  background: var(--accent);
  border-radius: 6px;
  font-weight: 750;
}
.brand strong { display: block; font-size: 15px; }
.brand span { display: block; margin-top: 2px; color: var(--muted); font-size: 12px; }
.new-chat {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 40px;
  border: 1px solid var(--ink);
  border-radius: 6px;
  color: var(--ink);
  background: var(--paper);
  font-weight: 650;
}
.new-chat:hover { background: var(--panel); }
.control-section h2, .control-section label, .kb-summary h2 {
  display: block;
  margin: 0 0 9px;
  font-size: 12px;
  color: #48514f;
  font-weight: 700;
}
.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px;
}
.segmented button {
  min-height: 34px;
  padding: 5px 6px;
  border: 1px solid transparent;
  border-radius: 5px;
  color: #4d5855;
  background: #e9eeeb;
  font-size: 12px;
}
.segmented button:hover { border-color: #aebbb7; }
.segmented button.active { color: white; background: var(--accent); }
select {
  width: 100%;
  min-height: 38px;
  padding: 0 10px;
  border: 1px solid #cbd4d1;
  border-radius: 5px;
  color: var(--ink);
  background: var(--paper);
}
.section-heading { display: flex; align-items: center; justify-content: space-between; }
.status-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: #aab2b0; }
.status-dot.ready { background: var(--accent); }
.status-dot.warning { background: var(--amber); }
.status-dot.error { background: var(--danger); }
.kb-summary { padding-top: 4px; border-top: 1px solid var(--line); }
.kb-summary h2 { margin-top: 13px; }
.kb-summary dl { margin: 0; }
.kb-summary dl div { display: flex; justify-content: space-between; padding: 6px 0; }
.kb-summary dt { color: var(--muted); font-size: 12px; }
.kb-summary dd { margin: 0; font-size: 12px; font-weight: 700; }
.service-status {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-top: auto;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 11px;
}

.chat-column { display: grid; grid-template-rows: 70px minmax(0, 1fr) auto; min-width: 0; min-height: 0; height: 100vh; overflow: hidden; background: var(--paper); }
.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  border-bottom: 1px solid var(--line);
}
.chat-header h1 { margin: 0; font-size: 17px; line-height: 1.25; }
.chat-header p { margin: 4px 0 0; color: var(--muted); font-size: 11px; }
.mobile-evidence { display: none; }
.messages { min-height: 0; overflow-y: auto; padding: 30px clamp(22px, 6vw, 88px) 28px; scroll-behavior: smooth; }
.message { display: flex; gap: 13px; width: min(820px, 100%); margin: 0 auto 28px; }
.message.user { justify-content: flex-end; }
.message.user .avatar { display: none; }
.message-body { min-width: 0; max-width: 100%; }
.message.user .message-body { max-width: min(680px, 88%); }
.message-meta { margin-bottom: 6px; color: var(--muted); font-size: 11px; font-weight: 650; }
.message.user .message-meta { text-align: right; }
.message-content { font-size: 14px; line-height: 1.8; overflow-wrap: anywhere; }
.message-content p { margin: 0 0 12px; }
.message-content p:last-child { margin-bottom: 0; }
.message.user .message-content { padding: 11px 14px; border-radius: 7px; background: #e7efec; }
.message-content h2, .message-content h3 { margin: 18px 0 8px; font-size: 15px; }
.message-content pre { overflow-x: auto; padding: 13px; border: 1px solid var(--line); border-radius: 5px; background: #f4f6f5; font-size: 12px; line-height: 1.55; }
.message-content code { font-family: "Cascadia Code", Consolas, monospace; font-size: .92em; }
.citation-link { border: 0; padding: 0 2px; color: var(--accent-dark); background: transparent; font-weight: 750; }
.citation-link:hover { text-decoration: underline; }
.suggestions { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 16px; }
.suggestions button {
  padding: 7px 10px;
  border: 1px solid #c9d3d0;
  border-radius: 5px;
  color: #35413e;
  background: var(--paper);
  font-size: 12px;
  text-align: left;
}
.suggestions button:hover { border-color: var(--accent); color: var(--accent-dark); }
.thinking { display: inline-flex; gap: 4px; padding-top: 8px; }
.thinking span { width: 5px; height: 5px; border-radius: 50%; background: var(--accent); animation: pulse 1.1s infinite ease-in-out; }
.thinking span:nth-child(2) { animation-delay: .15s; }
.thinking span:nth-child(3) { animation-delay: .3s; }
@keyframes pulse { 0%, 80%, 100% { opacity: .25; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }
.error-text { color: var(--danger); }
.composer-wrap { padding: 12px clamp(22px, 6vw, 88px) 17px; border-top: 1px solid #edf0ee; background: var(--paper); }
.composer { display: flex; align-items: flex-end; gap: 10px; width: min(820px, 100%); margin: 0 auto; padding: 9px 9px 9px 14px; border: 1px solid #aebbb7; border-radius: 7px; background: var(--paper); }
.composer:focus-within { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(20,117,104,.12); }
.composer textarea { flex: 1; max-height: 150px; resize: none; padding: 6px 0; border: 0; outline: 0; color: var(--ink); background: transparent; line-height: 1.5; }
.send-button { display: grid; place-items: center; flex: 0 0 auto; width: 34px; height: 34px; border: 0; border-radius: 5px; color: white; background: var(--accent); font-size: 20px; }
.send-button:hover { background: var(--accent-dark); }
.send-button:disabled { cursor: default; opacity: .45; }
.composer-note { width: min(820px, 100%); margin: 6px auto 0; color: #7a8381; font-size: 10px; text-align: center; }

.evidence-panel { display: flex; flex-direction: column; min-width: 0; min-height: 0; height: 100vh; overflow: hidden; border-left: 1px solid var(--line); background: #f7f9f7; }
.evidence-panel > header { display: flex; align-items: center; justify-content: space-between; min-height: 70px; padding: 0 18px; border-bottom: 1px solid var(--line); }
.evidence-panel h2 { margin: 2px 0 0; font-size: 15px; }
.eyebrow { color: var(--accent); font-size: 9px; font-weight: 800; }
.evidence-panel header button { display: none; border: 0; background: transparent; font-size: 24px; }
.evidence-empty { margin: auto 24px; color: var(--muted); text-align: center; }
.evidence-empty strong { color: #47514f; font-size: 13px; }
.evidence-empty p { margin: 6px 0; font-size: 11px; line-height: 1.6; }
.evidence-list { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 14px; }
.source-item { margin-bottom: 9px; padding: 12px; border: 1px solid #d4dcda; border-radius: 6px; background: var(--paper); }
.source-item.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.source-top { display: flex; align-items: flex-start; gap: 8px; }
.source-id { flex: 0 0 auto; padding: 2px 5px; border-radius: 3px; color: white; background: var(--accent); font-size: 10px; font-weight: 800; }
.source-title { margin: 0; font-size: 12px; line-height: 1.45; overflow-wrap: anywhere; }
.source-meta { margin: 7px 0; color: var(--muted); font-size: 10px; line-height: 1.5; }
.source-content { display: -webkit-box; margin: 0; overflow: hidden; color: #46504e; font-size: 11px; line-height: 1.65; -webkit-line-clamp: 5; -webkit-box-orient: vertical; }
.source-item.expanded .source-content { display: block; }
.source-toggle { margin-top: 7px; padding: 0; border: 0; color: var(--accent-dark); background: transparent; font-size: 10px; }

@media (max-width: 1080px) {
  .app-shell { grid-template-columns: 220px minmax(0, 1fr); }
  .evidence-panel { position: fixed; z-index: 10; top: 0; right: 0; bottom: 0; width: min(380px, 92vw); transform: translateX(100%); transition: transform .2s ease; box-shadow: -12px 0 30px rgba(30,45,41,.12); }
  .evidence-panel.open { transform: translateX(0); }
  .evidence-panel header button, .mobile-evidence { display: block; }
  .mobile-evidence { padding: 6px 9px; border: 1px solid #c9d3d0; border-radius: 5px; background: var(--paper); font-size: 11px; }
}
@media (max-width: 720px) {
  .app-shell { display: block; }
  .sidebar { display: none; }
  .chat-column { height: 100vh; grid-template-rows: 64px minmax(0, 1fr) auto; }
  .chat-header { padding: 0 16px; }
  .messages { padding: 22px 15px; }
  .composer-wrap { padding: 10px 12px 12px; }
  .message { gap: 9px; }
  .avatar { width: 30px; height: 30px; }
  .suggestions { display: grid; }
}
