:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #fbfcfd;
  --ink: #111827;
  --ink-soft: #374151;
  --muted: #667085;
  --faint: #98a2b3;
  --line: #e7e9ee;
  --line-soft: #eef0f3;
  --accent: #e8790f;
  --accent-strong: #c4640a;
  --accent-tint: #fff3e6;
  --user-bubble: #f0f2f6;
  --user-border: #e3e7ee;
  --agent-border: #e9ebf0;
  --abstain: #fff8ee;
  --abstain-border: #f1e0bf;
  --code-bg: #0d1526;
  --code-ink: #dfe7f2;
  --radius: 12px;
  --radius-lg: 16px;
  --radius-sm: 9px;
  --topbar-h: 58px;
  --shadow-xs: 0 1px 2px rgba(17,24,39,.05);
  --shadow-sm: 0 1px 3px rgba(17,24,39,.07), 0 1px 2px rgba(17,24,39,.04);
  --shadow-md: 0 6px 20px rgba(17,24,39,.10);
  --shadow-lg: 0 16px 40px rgba(17,24,39,.18);
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: "SFMono-Regular", ui-monospace, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font); font-size: 15px; line-height: 1.6;
  color: var(--ink); background: var(--bg);
  display: flex; flex-direction: column;
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
  letter-spacing: -0.005em;
}
button { font-family: inherit; }

/* ---- top bar ---- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  height: var(--topbar-h); padding: 0 18px;
  background: var(--surface); color: var(--ink);
  border-bottom: 1px solid var(--line);
  position: relative; z-index: 40;
}
.topbar-left { display: flex; align-items: center; gap: 12px; }
.menu-toggle {
  display: inline-flex; align-items: center; justify-content: center;
  width: 38px; height: 38px; background: none; border: 1px solid transparent;
  color: var(--ink-soft); font-size: 19px; line-height: 1; cursor: pointer;
  border-radius: 10px; transition: background .15s, border-color .15s;
}
.menu-toggle:hover { background: var(--bg); border-color: var(--line); }
.brand { font-weight: 700; font-size: 16px; letter-spacing: -0.01em; color: var(--ink); }
.brand span { color: var(--accent); }
.user { display: flex; align-items: center; gap: 14px; font-size: 13px; color: var(--muted); }
.linkbtn { background: none; border: none; color: var(--accent-strong); cursor: pointer; font: inherit; font-weight: 600; padding: 0; }
.linkbtn:hover { text-decoration: underline; }

/* ---- layout + drawer ---- */
.layout { flex: 1; display: flex; min-height: 0; position: relative; }
.sidebar {
  position: fixed; top: var(--topbar-h); left: 0; bottom: 0; width: 300px;
  background: var(--surface); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; padding: 14px 12px; gap: 4px; overflow-y: auto;
  transform: translateX(-100%); transition: transform .24s cubic-bezier(.32,.72,0,1); z-index: 30;
}
.sidebar.open { transform: translateX(0); box-shadow: var(--shadow-lg); }
.backdrop { position: fixed; inset: var(--topbar-h) 0 0 0; background: rgba(17,24,39,.32); z-index: 25; animation: fade .2s ease both; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.new-chat {
  display: flex; align-items: center; gap: 9px;
  border: 1px solid var(--line); color: var(--ink); background: var(--surface);
  border-radius: 10px; padding: 11px 13px; cursor: pointer; font-size: 14px; font-weight: 600;
  transition: background .15s, border-color .15s;
}
.new-chat::before { content: "+"; font-size: 17px; line-height: 1; color: var(--accent); font-weight: 700; }
.new-chat:hover { background: var(--accent-tint); border-color: #f2d3ad; }
.sidebar-title { font-size: 11px; text-transform: uppercase; letter-spacing: .07em; color: var(--faint); font-weight: 600; padding: 16px 10px 6px; }
.session-list { display: flex; flex-direction: column; gap: 2px; }
.session-item {
  text-align: left; border: none; background: none; border-radius: 9px; padding: 9px 11px;
  cursor: pointer; font-size: 14px; color: var(--ink-soft); white-space: nowrap; overflow: hidden;
  text-overflow: ellipsis; transition: background .12s, color .12s;
}
.session-item:hover { background: var(--bg); color: var(--ink); }
.session-item.active { background: var(--accent-tint); color: var(--accent-strong); font-weight: 600; }

/* ---- chat column ---- */
.app { flex: 1; display: flex; flex-direction: column; max-width: 800px; width: 100%; margin: 0 auto; padding: 22px 20px 12px; min-width: 0; min-height: 0; }
/* min-height:0 lets this flex child actually scroll instead of growing the page. */
.messages { flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 16px; padding: 4px 2px 14px; scroll-behavior: smooth; }

.msg {
  padding: 14px 16px; border-radius: var(--radius-lg); max-width: 86%;
  animation: rise .2s cubic-bezier(.32,.72,0,1) both;
}
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.msg.user { align-self: flex-end; background: var(--user-bubble); border: 1px solid var(--user-border); border-bottom-right-radius: 6px; }
.msg.agent { align-self: flex-start; background: var(--surface); border: 1px solid var(--agent-border); box-shadow: var(--shadow-xs); border-bottom-left-radius: 6px; }
.msg.abstain { align-self: flex-start; background: var(--abstain); border: 1px solid var(--abstain-border); border-bottom-left-radius: 6px; }
.msg.error { align-self: flex-start; background: #fef2f2; border: 1px solid #f6cccc; }
.msg .role { font-size: 10px; text-transform: uppercase; letter-spacing: .09em; color: var(--faint); margin-bottom: 6px; font-weight: 700; }
.msg .body { word-wrap: break-word; overflow-wrap: anywhere; color: var(--ink); min-width: 0; }
/* wide tables scroll within the bubble instead of blowing out the column */
.table-wrap { max-width: 100%; overflow-x: auto; }
.table-tools { display: flex; justify-content: flex-end; margin-top: 6px; }
.csv-btn { background: none; border: 1px solid var(--line); color: var(--muted); border-radius: 999px; padding: 4px 12px; font: inherit; font-size: 12px; font-weight: 600; cursor: pointer; transition: background .15s, border-color .15s, color .15s; }
.csv-btn:hover { background: var(--accent-tint); border-color: #f2d3ad; color: var(--accent-strong); }

/* answer feedback */
.feedback { display: flex; align-items: center; gap: 8px; margin-top: 12px; }
.fb-label { font-size: 12px; color: var(--faint); }
.fb-btn { background: none; border: 1px solid var(--line); color: var(--muted); border-radius: 999px; padding: 3px 11px; font: inherit; font-size: 12px; cursor: pointer; transition: background .15s, border-color .15s, color .15s; }
.fb-btn:hover:not(:disabled) { background: var(--bg); border-color: var(--faint); color: var(--ink-soft); }
.fb-btn.chosen { background: var(--accent-tint); border-color: #f2d3ad; color: var(--accent-strong); font-weight: 600; }
.fb-btn:disabled { cursor: default; opacity: .7; }
.typing { color: var(--muted); }
.typing::after { content: ""; animation: dots 1.2s steps(4,end) infinite; }
@keyframes dots { 0%{content:""} 25%{content:"."} 50%{content:".."} 75%{content:"..."} }

/* tables */
.msg table { border-collapse: separate; border-spacing: 0; width: 100%; margin-top: 10px; font-size: 13px; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.msg th, .msg td { padding: 9px 11px; text-align: left; border-bottom: 1px solid var(--line-soft); }
.msg th { background: var(--surface-2); font-weight: 600; color: var(--ink-soft); font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
.msg tr:last-child td { border-bottom: none; }
.msg tbody tr:nth-child(even) td { background: var(--surface-2); }

/* clarify options */
.options { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.option { border: 1px solid var(--line); color: var(--ink-soft); background: var(--surface); border-radius: 999px; padding: 6px 14px; cursor: pointer; font: inherit; font-size: 13px; transition: background .15s, border-color .15s; }
.option:hover { background: var(--accent-tint); border-color: #f2d3ad; color: var(--accent-strong); }

/* query disclosure */
.query { margin-top: 12px; }
.query summary { cursor: pointer; color: var(--muted); font-size: 12px; font-weight: 500; list-style: none; display: inline-flex; align-items: center; gap: 7px; padding: 5px 11px; border: 1px solid var(--line); border-radius: 999px; user-select: none; transition: background .15s, border-color .15s; }
.query summary::-webkit-details-marker { display: none; }
.query summary::before { content: ""; width: 6px; height: 6px; border-right: 1.5px solid var(--faint); border-bottom: 1.5px solid var(--faint); transform: rotate(-45deg); transition: transform .15s; margin-left: 1px; }
.query[open] summary::before { transform: rotate(45deg); }
.query summary:hover { background: var(--bg); border-color: var(--line); color: var(--ink-soft); }
.query pre { background: var(--code-bg); color: var(--code-ink); padding: 14px 16px; border-radius: 12px; overflow-x: auto; margin: 10px 0 0; font: 12.5px/1.55 var(--mono); }

/* ---- composer ---- */
.composer {
  display: flex; gap: 8px; align-items: center; padding: 7px 7px 7px 8px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 16px;
  box-shadow: var(--shadow-sm); margin-top: 6px; transition: border-color .15s, box-shadow .15s;
}
.composer:focus-within { border-color: var(--accent); box-shadow: 0 0 0 4px rgba(232,121,15,.14); }
.composer input {
  flex: 1; padding: 12px 12px; border: none; background: transparent; font: inherit; font-size: 15px;
  color: var(--ink); font-weight: 500;
}
.composer input::placeholder { color: var(--faint); font-weight: 400; }
.composer input:focus { outline: none; }
.composer button {
  padding: 0 22px; height: 44px; border: none; border-radius: 12px; background: var(--accent); color: #fff;
  font-weight: 600; font-size: 14.5px; cursor: pointer; transition: background .15s, transform .04s;
}
.composer button:hover { background: var(--accent-strong); }
.composer button:active { transform: translateY(1px); }
.composer button:disabled { background: #f0c691; cursor: not-allowed; }
.hint { text-align: center; color: var(--faint); font-size: 12px; margin: 10px 0 2px; }

/* ---- empty-state welcome ---- */
.welcome { margin: auto; text-align: center; max-width: 540px; padding: 28px 16px; }
.welcome .mark { width: 52px; height: 52px; border-radius: 15px; background: linear-gradient(140deg, #f59332, #d9660a); margin: 0 auto 18px; display: flex; align-items: center; justify-content: center; color: #fff; font-weight: 800; font-size: 22px; box-shadow: var(--shadow-md); }
.welcome h2 { margin: 0 0 8px; font-size: 22px; font-weight: 700; letter-spacing: -0.02em; }
.welcome p { margin: 0 0 22px; color: var(--muted); font-size: 15px; }
.examples { display: flex; flex-direction: column; gap: 9px; text-align: left; }
.example { border: 1px solid var(--line); background: var(--surface); border-radius: 12px; padding: 13px 15px; cursor: pointer; font: inherit; font-size: 14px; color: var(--ink-soft); box-shadow: var(--shadow-xs); transition: border-color .15s, box-shadow .15s, transform .04s; }
.example:hover { border-color: #f2d3ad; background: var(--accent-tint); color: var(--accent-strong); box-shadow: var(--shadow-sm); }
.example:active { transform: translateY(1px); }

/* ---- loading ---- */
.loading { flex: 1; display: flex; align-items: center; justify-content: center; color: var(--muted); }

/* scrollbars */
.messages::-webkit-scrollbar, .sidebar::-webkit-scrollbar { width: 10px; }
.messages::-webkit-scrollbar-thumb, .sidebar::-webkit-scrollbar-thumb { background: #d9dde4; border-radius: 8px; border: 3px solid transparent; background-clip: padding-box; }
.messages::-webkit-scrollbar-thumb:hover, .sidebar::-webkit-scrollbar-thumb:hover { background: #c4cad3; background-clip: padding-box; }

@media (max-width: 640px) {
  .sidebar { width: 86vw; }
  .msg { max-width: 92%; }
  .app { padding: 16px 14px 12px; }
}
