:root {
  --bg: #e7e7e4;          /* light grey page */
  --panel: #ffffff;       /* cards / chat bubbles */
  --panel-2: #f1f1ef;     /* rail, history, artifacts */
  --line: rgba(0, 0, 0, 0.10);
  --line-strong: rgba(0, 0, 0, 0.17);
  --text: #1a1a1a;        /* near-black type */
  --muted: #565656;
  --faint: #8a8a8a;
  --accent: #c62828;      /* red */
  --accent-dim: rgba(198, 40, 40, 0.10);
  --warm: #e0a24e;
  --ok: #1f9d57; --ok-bg: rgba(31, 157, 87, 0.13);
  --warn: #b26a00; --warn-bg: rgba(178, 106, 0, 0.13);
  --bad: #c62828; --bad-bg: rgba(198, 40, 40, 0.10);
  --radius: 12px;
  font-synthesis: none;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; cursor: pointer; color: inherit; }

.app {
  height: 100vh;
  display: grid;
  grid-template-columns: 60px 248px 1fr 1.45fr;
  overflow: hidden;
}
.app.hide-history { grid-template-columns: 60px 0 1fr 1.45fr; }

/* ---- Chat history sidebar ---- */
.history { display: flex; flex-direction: column; min-height: 0; overflow: hidden;
  background: var(--panel-2); border-right: 1px solid var(--line); }
/* When collapsed, shrink the track to 0 but KEEP the sidebar in the grid — if it
   were display:none the chat column would slide into the 0-width track and
   collapse. overflow:hidden already clips its contents at 0 width. */
.app.hide-history .history { border-right: 0; }
.history-head { flex-shrink: 0; display: flex; align-items: center; justify-content: space-between;
  gap: 8px; padding: 14px 14px 11px; border-bottom: 1px solid var(--line);
  font-size: 12.5px; font-weight: 600; color: var(--muted); letter-spacing: .3px; }
.history-list { flex: 1; min-height: 0; overflow-y: auto; padding: 6px; }
.history-item { display: flex; align-items: center; gap: 4px; border-radius: 8px; margin-bottom: 2px; }
.history-item:hover { background: rgba(0,0,0,.04); }
.history-item.active { background: var(--accent-dim); }
.h-open { flex: 1; min-width: 0; text-align: left; background: transparent; border: 0;
  color: var(--text); padding: 9px 10px; border-radius: 8px; }
.h-title { font-size: 13px; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.h-meta { font-size: 11px; color: var(--faint); }
.h-del { flex-shrink: 0; background: transparent; border: 0; color: var(--faint); font-size: 15px;
  line-height: 1; padding: 5px 9px; margin-right: 4px; border-radius: 6px; opacity: 0; }
.history-item:hover .h-del { opacity: .8; }
.h-del:hover { opacity: 1; color: var(--bad); background: var(--bad-bg); }
.h-del.armed { opacity: 1; color: var(--bad); background: var(--bad-bg); font-size: 11px; font-weight: 600; }
.history-empty { padding: 18px 12px; color: var(--faint); font-size: 12.5px; text-align: center; line-height: 1.5; }

.chatbtn { background: rgba(0,0,0,.04); border: 1px solid var(--line-strong); border-radius: 8px;
  padding: 4px 11px; font-size: 12px; color: var(--muted); white-space: nowrap; }
.chatbtn:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-dim); }
.chatbtn.small { padding: 3px 8px; font-size: 11.5px; }

/* ---- Left rail ---- */
.rail {
  background: var(--panel-2);
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column; align-items: center;
  padding: 14px 0; gap: 6px;
}
.rail-logo {
  width: 34px; height: 34px; border-radius: 9px; margin-bottom: 10px;
  display: grid; place-items: center; font-size: 16px; color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--warm));
}
.rail-btn, .rail-avatar {
  width: 38px; height: 38px; border: 0; border-radius: 10px; background: transparent;
  color: var(--faint); font-size: 16px; display: grid; place-items: center;
  transition: background .15s, color .15s;
}
.rail-btn:hover { background: rgba(0,0,0,.05); color: var(--muted); }
.rail-btn.active { background: var(--accent-dim); color: var(--accent); }
.rail-spacer { flex: 1; }
.rail-avatar { background: rgba(0,0,0,.06); color: var(--muted); font-size: 12px; font-weight: 600; }

/* ---- Center: chat ---- */
/* min-height:0 is load-bearing: without it the flex column refuses to shrink
   below its content, so .chat grows instead of scrolling and shoves the
   composer off the bottom of the 100vh grid (the "chat box disappeared" bug). */
.center { display: flex; flex-direction: column; min-width: 0; min-height: 0; overflow: hidden;
  border-right: 1px solid var(--line);
  background: radial-gradient(120% 60% at 50% -10%, rgba(198,40,40,.05), transparent 60%), var(--bg); }
.topbar {
  flex-shrink: 0;
  display: flex; align-items: baseline; justify-content: space-between; gap: 12px;
  padding: 14px 20px; border-bottom: 1px solid var(--line);
}
.agent { display: flex; align-items: center; gap: 10px; min-width: 0; }
.agent-name { font-weight: 650; letter-spacing: .2px; white-space: nowrap; }
.agent-sub { color: var(--muted); font-size: 12.5px; white-space: nowrap; }
.proj { color: var(--faint); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }

.chat { flex: 1; min-height: 0; overflow-y: auto; padding: 22px 20px; display: flex; flex-direction: column; gap: 18px; }
.msg { display: flex; flex-direction: column; gap: 6px; max-width: 92%; }
.msg.user { align-self: flex-end; align-items: flex-end; }
.who { font-size: 11px; color: var(--faint); text-transform: uppercase; letter-spacing: .6px; }
.bubble { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 15px; box-shadow: 0 1px 2px rgba(0,0,0,.04); }
.msg.user .bubble { background: var(--accent-dim); border-color: rgba(198,40,40,.22); }
.bubble p { margin: 0 0 8px; }
.bubble p:last-child { margin-bottom: 0; }
.bubble .hint { color: var(--muted); font-size: 12.5px; margin-top: 10px; display: flex; flex-wrap: wrap; gap: 6px; }
.thinking { color: var(--muted); font-style: italic; }
.thinking::after { content: "▋"; animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }

.chip { background: #fff; border: 1px solid var(--line-strong); border-radius: 999px;
  padding: 5px 11px; font-size: 12px; color: var(--muted); text-align: left; }
.chip:hover { border-color: var(--accent); color: var(--accent); }

.cites { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.cite { background: var(--accent-dim); border: 1px solid rgba(198,40,40,.3); color: #a01c1c;
  border-radius: 7px; padding: 3px 9px; font-size: 11.5px; font-family: ui-monospace, monospace; }
.cite:hover { background: rgba(198,40,40,.16); }

.composer { flex-shrink: 0; display: flex; gap: 10px; padding: 14px 20px; border-top: 1px solid var(--line); }
.composer input { flex: 1; background: #fff; border: 1px solid var(--line-strong); border-radius: 10px;
  padding: 11px 14px; color: var(--text); outline: none; }
.composer input:focus { border-color: var(--accent); }
.composer button { background: linear-gradient(135deg, #c62828, #8e1c1c); color: #fff; border: 0;
  border-radius: 10px; padding: 0 18px; font-weight: 600; }
.composer button:disabled { opacity: .5; cursor: default; }

/* ---- Right: artifacts ---- */
.right { display: flex; flex-direction: column; min-width: 0; min-height: 0; overflow: hidden; background: var(--panel-2); }
.artifacts-bar { flex-shrink: 0; padding: 12px 18px; border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.artifacts-title { font-weight: 600; color: var(--muted); font-size: 12.5px; letter-spacing: .3px; }
.workflow { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.wf-label { color: var(--faint); font-size: 11.5px; }
.wf-btn { background: #fff; border: 1px solid var(--line-strong); border-radius: 8px;
  padding: 6px 12px; font-size: 12.5px; color: var(--text); transition: .15s; }
.wf-btn:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-dim); }

.artifacts { flex: 1; min-height: 0; overflow-y: auto; padding: 22px 24px; }
.empty { height: 100%; display: grid; place-content: center; text-align: center; color: var(--faint); gap: 4px; }
.empty-mark { font-size: 34px; background: linear-gradient(135deg, var(--accent), var(--warm));
  -webkit-background-clip: text; background-clip: text; color: transparent; }
.empty-sub { font-size: 12.5px; }

/* rendered markdown */
.md h1, .md h2, .md h3 { line-height: 1.25; margin: 18px 0 8px; }
.md h1 { font-size: 20px; } .md h2 { font-size: 16px; } .md h3 { font-size: 14px; color: var(--muted); }
.md h1:first-child, .md h2:first-child { margin-top: 0; }
.md p { margin: 8px 0; } .md ul { margin: 8px 0; padding-left: 20px; } .md li { margin: 3px 0; }
.md strong { color: #000; }
.md code { background: rgba(0,0,0,.06); padding: 1px 5px; border-radius: 5px; font-size: 12.5px; }
.md hr { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }
.md table { border-collapse: collapse; width: 100%; margin: 12px 0; font-size: 12.5px; }
.md th, .md td { border: 1px solid var(--line); padding: 7px 10px; text-align: left; vertical-align: top; }
.md th { background: rgba(0,0,0,.03); color: var(--muted); font-weight: 600; }
.src-head { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; padding-bottom: 12px;
  border-bottom: 1px solid var(--line); }
.src-slug { font-family: ui-monospace, monospace; color: var(--accent); font-size: 12.5px; }
.src-body { white-space: pre-wrap; font-family: ui-monospace, monospace; font-size: 12px; color: #333;
  line-height: 1.5; }
.src-head .wf-btn { margin-left: auto; padding: 4px 10px; font-size: 11.5px; }
.src-head .wf-btn + .wf-btn { margin-left: 8px; }

/* Cited-text document — reads like a formatted page, not a monospace dump */
.doc { max-width: 860px; }
.doc-title { font-size: 21px; font-weight: 650; line-height: 1.3; margin: 2px 0 16px;
  padding-bottom: 14px; border-bottom: 1px solid var(--line); color: #111; }
.doc .md { font-size: 13.5px; line-height: 1.7; color: #2a2a2a; }
.doc .md p { margin: 11px 0; }
.doc .md h1, .doc .md h2 { color: #111; }
.doc .md h3 { color: var(--accent); font-size: 13px; letter-spacing: .3px;
  text-transform: uppercase; margin: 22px 0 8px; }
.doc .md ul { padding-left: 4px; list-style: none; }
.doc .md li { margin: 5px 0; padding-left: 2px; }
.doc .md li strong { color: var(--accent); font-variant-numeric: tabular-nums; margin-right: 4px; }
.doc .md strong { color: #000; }
.doc .md table { font-size: 13px; }
.doc .md th { color: var(--muted); }
.pdf { width: 100%; height: calc(100vh - 132px); border: 0; border-radius: 8px;
  background: #fff; box-shadow: 0 6px 22px rgba(0,0,0,.14); }
.sheet-wrap { overflow: auto; height: calc(100vh - 132px); background: #f4f4f0;
  border-radius: 8px; box-shadow: 0 6px 22px rgba(0,0,0,.14); }
.sheet { display: block; }
.sheet.fit { width: 100%; cursor: zoom-in; }
.sheet.full { width: auto; max-width: none; cursor: zoom-out; }  /* natural size → scroll to pan */

/* status pills + banners */
.pill { border-radius: 999px; padding: 2px 10px; font-size: 11.5px; font-weight: 600; display: inline-block; }
.pill.ok { color: var(--ok); background: var(--ok-bg); }
.pill.warn { color: var(--warn); background: var(--warn-bg); }
.pill.bad { color: var(--bad); background: var(--bad-bg); }
.banner { border-radius: 10px; padding: 14px 16px; margin-bottom: 16px; border: 1px solid var(--line-strong); }
.banner.hold { background: var(--warn-bg); border-color: rgba(178,106,0,.35); }
.banner.ready { background: var(--ok-bg); border-color: rgba(31,157,87,.35); }
.banner h2 { margin: 0 0 4px; font-size: 17px; }
.banner .sub { color: var(--muted); font-size: 12.5px; }
.rollup { display: flex; gap: 14px; margin: 6px 0 0; font-size: 12px; color: var(--muted); }
