/* CC&L Financial Group theme: palette and type follow cclfg.cclgroup.com. */
:root {
  --ccl-green: #005c42;
  --ccl-green-dark: #003929;
  --ccl-green-soft: #e7efeb;
  --ccl-navy: #002b5c;
  --ccl-slate: #5b6770;
  --ccl-amber: #e58e1a;

  --bg: #f2f5f3;
  --surface: #ffffff;
  --surface-2: #eaefec;
  --border: #d7ded9;
  --text: #19211c;
  --muted: var(--ccl-slate);
  --accent: var(--ccl-green);
  --accent-hover: var(--ccl-green-dark);
  --danger: #b3261e;
  --danger-soft: #fdf3f2;
  --success: #439539;
  --radius: 4px;
  --shadow: 0 1px 2px rgba(25, 33, 28, .06);

  --font-sans: "Montserrat", "Segoe UI", system-ui, -apple-system, sans-serif;
  --font-serif: "Libre Baskerville", Georgia, "Times New Roman", serif;

  /* conversation column; the shell (header) is allowed to run a little wider */
  --content-max: 880px;
  --shell-max: 1200px;
  --gutter: 20px;

  --scrollbar-size: 10px;
  --scrollbar-thumb: #c2ccc6;
  --scrollbar-thumb-hover: var(--accent);
}

* { box-sizing: border-box; }

/* ---------- scrollbars ---------- */
html { scrollbar-width: thin; scrollbar-color: var(--scrollbar-thumb) transparent; }
* { scrollbar-width: thin; scrollbar-color: var(--scrollbar-thumb) transparent; }
::-webkit-scrollbar { width: var(--scrollbar-size); height: var(--scrollbar-size); }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background-color: var(--scrollbar-thumb);
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: content-box;
}
::-webkit-scrollbar-thumb:hover { background-color: var(--scrollbar-thumb-hover); }
::-webkit-scrollbar-corner { background: transparent; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ---------- shared ---------- */
.brand { display: flex; align-items: center; gap: 14px; }
.brand h1 { font-family: var(--font-serif); font-size: 20px; margin: 0; font-weight: 400; }
.brand-sub { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.brand-mark {
  width: 42px; height: 42px; flex: 0 0 42px;
  display: grid; place-items: center;
  background: var(--ccl-green); color: #fff;
  border-radius: var(--radius); font-weight: 600; letter-spacing: 1px;
}
.brand-compact .brand-mark { width: 32px; height: 32px; flex-basis: 32px; font-size: 13px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 9px;
  padding: 10px 18px; border-radius: var(--radius);
  border: 2px solid var(--border); background: var(--surface); color: var(--text);
  font-family: inherit; font-size: 14px; font-weight: 500; letter-spacing: .02em;
  cursor: pointer; text-decoration: none;
  transition: background .15s ease, border-color .15s ease, color .15s ease;
}
.btn:hover { background: var(--surface-2); border-color: var(--ccl-slate); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: #fff; }
.btn-primary:disabled { opacity: .5; cursor: not-allowed; }
.btn-github { width: 100%; background: var(--ccl-navy); border-color: var(--ccl-navy); color: #fff; }
.btn-github:hover { background: #001f43; border-color: #001f43; }
.btn-ghost { background: transparent; border-color: transparent; padding: 7px 12px; }
.btn-ghost:hover { background: var(--ccl-green-soft); border-color: transparent; color: var(--accent); }

.alert { padding: 10px 14px; border-radius: var(--radius); font-size: 14px; margin-bottom: 18px; }
.alert-error { background: var(--danger-soft); border: 1px solid rgba(179, 38, 30, .35); color: #8c1d18; }
.alert-notice { background: var(--ccl-green-soft); border: 1px solid rgba(0, 92, 66, .3); color: var(--ccl-green-dark); }
.hint { color: var(--muted); font-size: 13px; margin: 10px 0 0; }

/* ---------- login ---------- */
.login-body {
  display: grid; place-items: center; min-height: 100vh; padding: 24px;
  background: linear-gradient(160deg, var(--ccl-green-soft) 0%, var(--bg) 55%);
}
.login-card {
  width: 100%; max-width: 420px; background: var(--surface);
  border: 1px solid var(--border); border-top: 4px solid var(--ccl-green);
  border-radius: var(--radius); padding: 32px; box-shadow: 0 10px 30px rgba(25, 33, 28, .08);
}
.login-card .brand { margin-bottom: 26px; }
.divider { display: flex; align-items: center; gap: 12px; margin: 22px 0; color: var(--muted); font-size: 12px; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }

.local-auth { border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.local-auth summary { cursor: pointer; font-weight: 500; }
.local-auth[open] summary { margin-bottom: 6px; }
.stack { display: flex; flex-direction: column; gap: 6px; margin-top: 14px; }
.stack label { font-size: 13px; color: var(--muted); }
.stack input {
  padding: 10px 12px; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font-family: inherit; font-size: 14px;
}
.stack input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.stack .btn { margin-top: 12px; }
.login-footer { margin-top: 24px; color: var(--muted); font-size: 12px; text-align: center; }

/* ---------- chat ---------- */
.chat-body { display: flex; flex-direction: column; height: 100vh; background: var(--bg); }
.topbar { border-bottom: 1px solid var(--border); background: var(--surface); box-shadow: var(--shadow); }
.topbar-inner {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  width: 100%; max-width: var(--shell-max); margin: 0 auto; padding: 12px var(--gutter);
}
.topbar-sub { display: block; color: var(--muted); font-size: 12px; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.topbar-actions form { margin: 0; }
.user-chip { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }
.badge {
  background: var(--ccl-green-soft); border: 1px solid rgba(0, 92, 66, .2); color: var(--accent);
  border-radius: 999px; padding: 1px 9px; font-size: 11px; text-transform: uppercase; letter-spacing: .04em;
}

.transcript {
  flex: 1; min-height: 0; overflow-y: auto;
  padding: 24px var(--gutter); display: flex; flex-direction: column; gap: 16px;
}
/* Every row the chat client appends shares one centred, width-capped column. */
.transcript > * { width: 100%; max-width: var(--content-max); margin-inline: auto; }

.message { display: flex; }
.message.user { justify-content: flex-end; }
.bubble {
  max-width: 100%;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 18px; white-space: pre-wrap; word-wrap: break-word;
  box-shadow: var(--shadow);
}
.message.user .bubble {
  max-width: 88%;
  background: var(--accent); border-color: var(--accent); color: #fff; white-space: pre-wrap;
}
.bubble p { margin: 0 0 10px; }
.bubble p:last-child { margin-bottom: 0; }
.examples { color: var(--muted); font-size: 13px; }
.bubble.error { border-color: rgba(179, 38, 30, .4); background: var(--danger-soft); color: #8c1d18; }

.status { color: var(--muted); font-size: 13px; font-style: italic; }
.cursor::after {
  content: "▍"; margin-left: 2px; opacity: .7;
  animation: blink 1s steps(2, start) infinite;
}
@keyframes blink { to { visibility: hidden; } }

.composer { border-top: 1px solid var(--border); background: var(--surface); }
.composer-inner {
  display: flex; gap: 10px; align-items: flex-end;
  /* +2 gutters so the textarea lines up with the transcript column */
  width: 100%; max-width: calc(var(--content-max) + 2 * var(--gutter));
  margin: 0 auto; padding: 14px var(--gutter);
}
.composer textarea {
  flex: 1; resize: none; max-height: 200px;
  padding: 11px 14px; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; line-height: 1.5;
}
.composer textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.composer .attach { padding: 9px 11px; }

/* ---------- reasoning trail ---------- */
.steps {
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface-2); margin-bottom: 12px; font-size: 13px;
}
.steps summary {
  cursor: pointer; padding: 8px 12px; color: var(--muted);
  display: flex; align-items: center; gap: 8px; list-style: none;
}
.steps summary::-webkit-details-marker { display: none; }
.steps summary::before { content: "▸"; font-size: 11px; }
.steps[open] summary::before { content: "▾"; }
.step-list { margin: 0; padding: 0 12px 10px 34px; display: flex; flex-direction: column; gap: 5px; }
.step { color: var(--muted); }
.step-name { color: var(--text); }
.step.done .step-name::after { content: " ✓"; color: var(--success); }
.step.failed .step-name::after { content: " ✕"; color: var(--danger); }
.step.running .step-name::after { content: " …"; }
.step-detail { display: block; opacity: .75; font-size: 12px; word-break: break-word; }
.step-detail.error { color: var(--danger); opacity: 1; }
.reasoning-body {
  white-space: pre-wrap; font-size: 12px; opacity: .8;
  margin-top: 4px; max-height: 200px; overflow-y: auto;
}
.spinner {
  width: 11px; height: 11px; border-radius: 50%;
  border: 2px solid var(--border); border-top-color: var(--accent);
  animation: spin .8s linear infinite; flex: 0 0 auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- rendered markdown ---------- */
.answer > *:first-child { margin-top: 0; }
.answer > *:last-child { margin-bottom: 0; }
.answer h3, .answer h4, .answer h5, .answer h6 {
  margin: 14px 0 8px; line-height: 1.3;
  font-family: var(--font-serif); font-weight: 400;
}
.answer h3 { font-size: 17px; }
.answer h4 { font-size: 15px; }
.answer ul, .answer ol { margin: 8px 0; padding-left: 22px; }
.answer li { margin: 3px 0; }
.answer code {
  background: var(--surface-2); padding: 1px 5px;
  border-radius: 3px; font-size: 13px; font-family: Consolas, "Courier New", monospace;
}
.answer pre {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px; overflow-x: auto; margin: 10px 0;
}
.answer pre code { background: none; padding: 0; }
.answer a { color: var(--accent); }
.answer blockquote {
  margin: 10px 0; padding: 4px 14px;
  border-left: 3px solid var(--border); color: var(--muted);
}
.answer table { border-collapse: collapse; margin: 10px 0; width: 100%; font-size: 13.5px; }
.answer th, .answer td { border: 1px solid var(--border); padding: 7px 10px; text-align: left; }
.answer th { background: var(--surface-2); }
.answer hr { border: none; border-top: 1px solid var(--border); margin: 14px 0; }
.answer.status { color: var(--muted); font-style: italic; }
.answer.error { color: var(--danger); }

/* ---------- artifacts ---------- */
.artifact {
  margin-top: 12px; border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden; background: var(--surface);
}
.artifact-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 8px 12px; background: var(--surface-2); border-bottom: 1px solid var(--border);
}
.artifact-title { font-size: 13px; font-weight: 600; }
.btn-small { padding: 4px 10px; font-size: 12px; }
.artifact-body { padding: 12px 14px; overflow-x: auto; }
.mermaid-render svg { max-width: 100%; height: auto; }
.mermaid-fallback {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px; overflow-x: auto; font-size: 12.5px;
}

/* ---------- attachments ---------- */
.attachment-previews {
  display: none; gap: 10px; flex-wrap: wrap;
  width: 100%; max-width: calc(var(--content-max) + 2 * var(--gutter));
  margin: 0 auto; padding: 10px var(--gutter) 0;
}
.attachment-previews.has-items { display: flex; }
.preview { position: relative; width: 68px; height: 68px; }
.preview img {
  width: 100%; height: 100%; object-fit: cover;
  border-radius: 8px; border: 1px solid var(--border);
}
.preview-remove {
  position: absolute; top: -6px; right: -6px; width: 20px; height: 20px;
  border-radius: 50%; border: 1px solid var(--border); background: var(--surface);
  color: var(--text); cursor: pointer; line-height: 1; font-size: 14px;
}
.sent-images { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.sent-images img {
  max-width: 190px; max-height: 190px;
  border-radius: 8px; border: 1px solid rgba(255, 255, 255, .25);
}

.quota-chip {
  font-size: 12px; color: var(--muted);
  border: 1px solid var(--border); border-radius: 999px; padding: 3px 10px;
}
.quota-chip.near-limit { color: #8a5300; background: #fdf6ec; border-color: rgba(229, 142, 26, .55); }
