:root {
  /* Earth tones: dark umber ground, sand text, moss accent, ochre secondary,
     terracotta warnings, clay errors. */
  --bg: #1e1a15;
  --bg2: #282219;
  --bg3: #352c20;
  --fg: #e8dcc4;
  --dim: #a89878;
  --accent: #a9b665;
  --accent2: #d8a657;
  --warn: #e78a4e;
  --err: #ea6962;
  --radius: 10px;
  --mono: "Cascadia Code", "JetBrains Mono", Consolas, monospace;
  --sans: "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body { background: var(--bg); color: var(--fg); font-family: var(--sans); }
.hidden { display: none !important; }
.dim { color: var(--dim); }
.small { font-size: 0.8rem; }
.err { color: var(--err); min-height: 1.2em; font-size: 0.85rem; }
code { font-family: var(--mono); background: var(--bg3); padding: 0.1em 0.35em; border-radius: 4px; font-size: 0.9em; }
pre { font-family: var(--mono); background: var(--bg3); padding: 0.7em; border-radius: 6px; overflow-x: auto; margin: 0.5em 0; font-size: 0.85em; }

/* Login */
.login { height: 100%; display: flex; align-items: center; justify-content: center; padding: 1rem; }
.login-card { background: var(--bg2); border: 1px solid var(--bg3); border-radius: var(--radius); padding: 2rem; max-width: 380px; width: 100%; display: flex; flex-direction: column; gap: 0.9rem; }
.login-card h1 { font-family: var(--mono); font-size: 1.4rem; color: var(--accent); }
.login-card p { color: var(--dim); font-size: 0.9rem; line-height: 1.4; }

/* App shell */
.app { height: 100%; display: flex; flex-direction: column; max-width: 860px; margin: 0 auto; }
header { display: flex; align-items: center; justify-content: space-between; padding: 0.7rem 1rem; border-bottom: 1px solid var(--bg3); }
.title { font-family: var(--mono); font-weight: 600; }
.title .prompt { color: var(--accent); }
.header-right { display: flex; align-items: center; gap: 0.6rem; }

.chip { font-family: var(--mono); font-size: 0.7rem; padding: 0.2em 0.6em; border-radius: 999px; border: 1px solid; letter-spacing: 0.05em; }
.chip-normal   { color: var(--accent);  border-color: var(--accent); }
.chip-byo      { color: var(--accent2); border-color: var(--accent2); }
.chip-local    { color: var(--warn);    border-color: var(--warn); }
.chip-kbonly   { color: var(--err);     border-color: var(--err); }

/* Chat */
.chat { flex: 1; overflow-y: auto; padding: 1rem; display: flex; flex-direction: column; gap: 0.8rem; }
.msg { display: flex; }
.msg.user { justify-content: flex-end; }
.bubble { max-width: 85%; padding: 0.7rem 0.95rem; border-radius: var(--radius); line-height: 1.5; font-size: 0.95rem; overflow-wrap: break-word; }
.msg.user .bubble { background: #3a3222; border: 1px solid #57492e; }
.msg.bot .bubble { background: var(--bg2); border: 1px solid var(--bg3); }
.bubble ul, .bubble ol { margin: 0.4em 0 0.4em 1.4em; }
.bubble h1, .bubble h2, .bubble h3 { font-size: 1em; margin: 0.6em 0 0.3em; color: var(--accent2); }

.sources { margin-top: 0.6rem; display: flex; flex-wrap: wrap; gap: 0.35rem; }
.source-tag { font-family: var(--mono); font-size: 0.68rem; color: var(--dim); background: var(--bg3); padding: 0.15em 0.5em; border-radius: 4px; }
a.source-tag.web { color: var(--accent2); text-decoration: none; }
a.source-tag.web:hover { text-decoration: underline; }
.research-btn { margin-top: 0.55rem; font-size: 0.8rem; padding: 0.35rem 0.8rem; }
.meta-line { margin-top: 0.45rem; font-family: var(--mono); font-size: 0.68rem; color: var(--dim); }

.escalate-card { margin-top: 0.7rem; border: 1px solid var(--warn); border-radius: 8px; padding: 0.7rem; background: rgba(231, 138, 78, 0.08); font-size: 0.88rem; }
.escalate-card b { color: var(--warn); }
.escalate-card button { margin-top: 0.5rem; margin-right: 0.5rem; }
.esc-form { display: flex; gap: 0.5rem; margin-top: 0.6rem; flex-wrap: wrap; }
.esc-form input, .esc-form select { flex: 1; min-width: 140px; background: var(--bg2); border: 1px solid var(--bg3); border-radius: 6px; color: var(--fg); padding: 0.4rem 0.6rem; font-size: 0.82rem; }

.feedback-row { display: flex; align-items: center; gap: 0.45rem; margin-top: 0.65rem; flex-wrap: wrap; }
.feedback-row button { background: var(--bg3); color: var(--dim); font-size: 0.75rem; padding: 0.28rem 0.7rem; border-radius: 999px; font-weight: 500; }
.feedback-row button:hover { color: var(--fg); }
.feedback-row button.picked { background: var(--accent); color: #211d10; }
.feedback-row button:disabled { opacity: 0.55; cursor: default; }
.feedback-row button.picked:disabled { opacity: 1; }
.feedback-row .regen-btn { font-size: 0.85rem; }

.chats-panel { position: absolute; top: 3rem; right: 0.8rem; z-index: 20; background: var(--bg2); border: 1px solid var(--bg3); border-radius: 10px; min-width: 240px; max-width: 320px; max-height: 60vh; overflow-y: auto; padding: 0.5rem; box-shadow: 0 8px 24px rgba(0,0,0,0.4); }
.chats-new { width: 100%; margin-bottom: 0.4rem; }
.chats-item { display: flex; align-items: center; justify-content: space-between; gap: 0.4rem; padding: 0.45rem 0.6rem; border-radius: 6px; cursor: pointer; font-size: 0.85rem; }
.chats-item:hover { background: var(--bg3); }
.chats-item.active { background: var(--bg3); border-left: 2px solid var(--accent); }
.chats-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chats-del { background: transparent; color: var(--dim); padding: 0 0.3rem; font-size: 0.9rem; }
.chats-del:hover { color: var(--err); }
header { position: relative; }

.typing { color: var(--dim); font-family: var(--mono); font-size: 0.85rem; }

/* Footer */
footer { border-top: 1px solid var(--bg3); padding: 0.6rem 1rem 0.9rem; display: flex; flex-direction: column; gap: 0.5rem; }
.mode-row { display: flex; align-items: center; gap: 0.8rem; font-size: 0.85rem; color: var(--dim); }
.toggle { display: flex; align-items: center; gap: 0.35rem; cursor: pointer; }
.input-row { display: flex; gap: 0.6rem; }
textarea { flex: 1; resize: none; background: var(--bg2); border: 1px solid var(--bg3); border-radius: var(--radius); color: var(--fg); padding: 0.6rem 0.8rem; font-family: var(--sans); font-size: 0.95rem; }
textarea:focus { outline: 1px solid var(--accent2); }

button { background: var(--accent); color: #211d10; border: none; border-radius: 8px; padding: 0.55rem 1.1rem; font-weight: 600; cursor: pointer; font-size: 0.9rem; }
button:hover { filter: brightness(1.1); }
button.secondary { background: var(--bg3); color: var(--fg); }
.icon-btn { background: transparent; color: var(--dim); font-size: 1.1rem; padding: 0.2rem 0.4rem; }
.icon-btn:hover { color: var(--fg); }

input[type="password"], input[type="text"], select { background: var(--bg2); border: 1px solid var(--bg3); border-radius: 8px; color: var(--fg); padding: 0.55rem 0.75rem; font-size: 0.9rem; width: 100%; }

/* Drawer */
.drawer { position: fixed; inset: 0; background: rgba(0,0,0,0.5); display: flex; justify-content: flex-end; z-index: 10; }
.drawer-inner { background: var(--bg2); width: min(360px, 90vw); height: 100%; padding: 1.3rem; overflow-y: auto; display: flex; flex-direction: column; gap: 0.7rem; border-left: 1px solid var(--bg3); }
.drawer-inner h2 { font-size: 1.1rem; font-family: var(--mono); }
.drawer-inner h3 { font-size: 0.85rem; color: var(--dim); text-transform: uppercase; letter-spacing: 0.06em; margin-top: 0.8rem; }
