:root {
  --ink: #16191d;
  --muted: #5c6570;
  --line: #d9dee4;
  --accent: #1d4ed8;
  --surface: #f5f7fa;
}

* {
  box-sizing: border-box;
}

/* Sidebar beside the conversation, both full height, only the transcript
   scrolling. The composer stays put while a long answer arrives above it. */
body {
  display: grid;
  grid-template-columns: 16rem 1fr;
  height: 100dvh;
  margin: 0;
  font:
    16px / 1.55 system-ui,
    -apple-system,
    "Segoe UI",
    sans-serif;
  color: var(--ink);
}

#column {
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}

#column > header {
  display: flex;
  gap: 0.75rem;
  align-items: baseline;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--line);
}

/* The reading column stays narrow even when the window is not: prose at the
   full width of a desktop monitor is unreadable. */
main {
  display: flex;
  flex-direction: column;
  flex: 1;
  gap: 1rem;
  width: 100%;
  max-width: 44rem;
  min-height: 0;
  margin: 0 auto;
  padding: 1.25rem 1.25rem 1.5rem;
}

#transcript {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

h1 {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
}

#chat-title {
  flex: 1;
  min-width: 0;
  margin: 0;
  overflow: hidden;
  font-size: 0.9375rem;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Sidebar */

#sidebar {
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-right: 1px solid var(--line);
  background: var(--surface);
}

.sidebar-head {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 0.875rem;
  border-bottom: 1px solid var(--line);
}

#conversations {
  flex: 1;
  min-height: 0;
  margin: 0;
  padding: 0.5rem;
  overflow-y: auto;
  list-style: none;
}

#conversations li {
  position: relative;
  display: flex;
  align-items: center;
  border-radius: 6px;
}

#conversations li.current {
  background: #e4e9f2;
}

/* The title is the click target for opening; it fills the row so the whole
   row is clickable without nesting an interactive element inside another. */
.conversation-open {
  flex: 1;
  min-width: 0;
  padding: 0.5rem 0.5rem 0.5rem 0.625rem;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  font-size: 0.875rem;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
  cursor: pointer;
}

.conversation-open time {
  display: block;
  color: var(--muted);
  font-size: 0.75rem;
}

.row-menu > summary {
  padding: 0.25rem 0.5rem;
  color: var(--muted);
  list-style: none;
  cursor: pointer;
}

.row-menu > summary::-webkit-details-marker {
  display: none;
}

.row-menu[open] > summary {
  color: var(--ink);
}

.row-menu .menu {
  position: absolute;
  right: 0.25rem;
  z-index: 2;
  display: flex;
  flex-direction: column;
  min-width: 9rem;
  padding: 0.25rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  box-shadow: 0 4px 14px rgb(0 0 0 / 12%);
}

.row-menu .menu button {
  padding: 0.375rem 0.5rem;
  border: 0;
  border-radius: 4px;
  background: none;
  color: inherit;
  font: inherit;
  font-size: 0.8125rem;
  text-align: left;
  cursor: pointer;
}

.row-menu .menu button:hover {
  background: var(--surface);
}

.row-menu .menu button.danger {
  color: #b42318;
}

/* An inline rename rather than a prompt(): it keeps the title visible while
   it is being changed, and prompt() is blocked in some embedded contexts. */
.conversation-rename {
  flex: 1;
  min-width: 0;
  margin: 0.25rem 0.5rem;
  padding: 0.25rem 0.375rem;
  border: 1px solid var(--accent);
  border-radius: 4px;
  font: inherit;
  font-size: 0.875rem;
}

#sidebar-empty {
  margin: 0;
  padding: 0.75rem 0.875rem;
  border-top: 1px solid var(--line);
  font-size: 0.75rem;
}

.muted {
  color: var(--muted);
}

button.icon {
  display: none;
  padding: 0.125rem 0.375rem;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: none;
  font: inherit;
  cursor: pointer;
}

/* Export dialog */

#export-dialog {
  min-width: min(24rem, 90vw);
  padding: 1.25rem;
  border: 1px solid var(--line);
  border-radius: 10px;
}

#export-dialog::backdrop {
  background: rgb(0 0 0 / 35%);
}

#export-dialog h3 {
  margin: 0 0 1rem;
  font-size: 1rem;
}

#export-dialog fieldset {
  margin: 0 0 1rem;
  padding: 0;
  border: 0;
}

#export-dialog legend {
  padding: 0;
  color: var(--muted);
  font-size: 0.8125rem;
}

#export-dialog label {
  display: block;
  font-size: 0.875rem;
}

#include-calls-row {
  margin-bottom: 1.25rem;
}

#include-calls-row .muted {
  display: block;
  padding-left: 1.5rem;
  font-size: 0.75rem;
}

.dialog-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
}

/* Narrow screens: the sidebar slides over the conversation rather than
   squeezing it, and the header gets a control to bring it back. */
@media (max-width: 46rem) {
  body {
    grid-template-columns: 1fr;
  }

  #sidebar {
    position: fixed;
    z-index: 3;
    width: 16rem;
    height: 100dvh;
    transform: translateX(-100%);
    transition: transform 0.15s ease-out;
  }

  #sidebar.open {
    transform: none;
  }

  button.icon {
    display: block;
  }
}

header p {
  margin: 0;
  color: var(--muted);
  font-size: 0.875rem;
}

/* The sign-in affordance is deliberately not a button: it buys conversation
   persistence, which is worth offering and not worth interrupting for. */
button.link {
  padding: 0;
  border: 0;
  background: none;
  color: var(--accent);
  font: inherit;
  font-weight: 400;
  text-decoration: underline;
  cursor: pointer;
}

a {
  color: var(--accent);
}

section {
  margin-top: 2rem;
}

/* Deliberately quiet: it is context, not a call to action. Someone who never
   looks at it should not notice it, and someone running low should find the
   number without hunting. */
#budget {
  margin-bottom: 1.25rem;
}

#budget-track {
  height: 3px;
  border-radius: 2px;
  background: var(--line);
  overflow: hidden;
}

#budget-fill {
  width: 0;
  height: 100%;
  background: var(--accent);
  transition: width 0.4s ease;
}

#budget.low #budget-fill {
  background: #b45309;
}

#budget.spent #budget-fill {
  background: #b91c1c;
}

#budget-note {
  margin: 0.4rem 0 0;
  font-size: 0.75rem;
  color: var(--muted);
}

button.secondary {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--ink);
  font-weight: 400;
}

#account {
  font-size: 0.875rem;
}

#chat-actions {
  display: flex;
  gap: 0.6rem;
  align-items: center;
  margin-top: 0.75rem;
  font-size: 0.8125rem;
  color: var(--muted);
}

button {
  padding: 0.55rem 1rem;
  border: 0;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

button:disabled {
  background: var(--muted);
  cursor: default;
}

#progress:empty {
  display: none;
}

#progress {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 0.875rem;
}

#transcript {
  margin: 0 0 1rem;
  padding: 0;
  list-style: none;
}

#transcript li {
  margin-bottom: 1.25rem;
}

.who {
  display: block;
  margin-bottom: 0.15rem;
  color: var(--muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

#transcript p {
  margin: 0;
  white-space: pre-wrap;
}

#transcript .user p {
  padding: 0.6rem 0.8rem;
  border-radius: 8px;
  background: var(--surface);
}

.tools {
  margin-top: 0.4rem;
  color: var(--muted);
  font-size: 0.8125rem;
}

#composer {
  display: flex;
  gap: 0.5rem;
}

#composer textarea {
  flex: 1;
  resize: none;
  max-height: 10rem;
  overflow-y: auto;
  font: inherit;
  padding: 0.5rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  line-height: 1.4;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

th,
td {
  padding: 0.4rem 0.5rem;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.pass {
  color: #15803d;
}

.fail {
  color: #b91c1c;
}

/* Content the model chose to show rather than say. format: "code" and "text"
   are shown as the literal string given — that boundary is enforced in
   renderMarkdown(), which never touches innerHTML, not by refusing to parse
   markdown here. format: "markdown" goes through the same renderer as the
   model's own prose, so a table or a ```mermaid block looks identical
   whichever path it arrived by. */
.shown {
  margin-top: 0.4rem;
  padding: 0.6rem 0.8rem;
  border-left: 2px solid var(--line);
  font-size: 0.875rem;
  white-space: pre-wrap;
  overflow-x: auto;
}

/* Rendered markdown supplies its own block layout (p, table, ul, ...); the
   pre-wrap above is for the literal code/text cases and would otherwise
   double up on whitespace already handled by those elements. */
.shown.markdown {
  white-space: normal;
}

.shown.code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  background: var(--surface);
  border-left-color: var(--accent);
}

/* Markdown in an assistant turn. Kept close to the surrounding text: the
   model reaches for headings more readily than a person would, so h3-h6 are
   only slightly larger than body copy. */
#transcript p {
  margin: 0 0 0.6rem;
}
#transcript li > :last-child {
  margin-bottom: 0;
}
#transcript h3,
#transcript h4,
#transcript h5,
#transcript h6 {
  margin: 0.9rem 0 0.35rem;
  font-size: 1rem;
  font-weight: 600;
}
#transcript ul,
#transcript ol {
  margin: 0 0 0.6rem;
  padding-left: 1.3rem;
}
#transcript li li {
  margin-bottom: 0.15rem;
}
#transcript code {
  padding: 0.05rem 0.3rem;
  border-radius: 4px;
  background: var(--surface);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.875em;
}
#transcript pre {
  margin: 0 0 0.6rem;
  padding: 0.6rem 0.8rem;
  border-radius: 6px;
  background: var(--surface);
  overflow-x: auto;
}
#transcript pre code {
  padding: 0;
  background: none;
}

/* A mermaid-diagram container starts as its fallback <pre><code> (styled
   above, same as any other code block) and is swapped for a real <svg> by
   mermaid.js's upgradeMermaidDiagrams(), which is why there's nothing here
   for the un-upgraded state — the fallback already looks right. */
.mermaid-diagram.mermaid-rendered {
  display: flex;
  justify-content: center;
  margin: 0 0 0.6rem;
}
.mermaid-diagram.mermaid-rendered svg {
  max-width: 100%;
  height: auto;
}
/* Invalid Mermaid syntax from the model: the fallback code block stays, with
   a border marking that it didn't render rather than leaving that silent. */
.mermaid-diagram.mermaid-failed pre {
  border-left: 2px solid #b91c1c;
}
#transcript blockquote {
  margin: 0 0 0.6rem;
  padding-left: 0.8rem;
  border-left: 2px solid var(--line);
  color: var(--muted);
}
#transcript table {
  margin-bottom: 0.6rem;
  display: block;
  overflow-x: auto;
}
#transcript hr {
  margin: 1rem 0;
  border: 0;
  border-top: 1px solid var(--line);
}

/* What was asked and what came back. Two levels, both shut: the call is worth
   glancing at, the raw output only when something looks wrong. */
.calls {
  margin-top: 0.6rem;
  font-size: 0.8125rem;
  color: var(--muted);
}

.calls > summary,
.call > summary,
.call-output > summary {
  cursor: pointer;
  padding: 0.15rem 0;
}

.calls > summary:hover,
.call > summary:hover,
.call-output > summary:hover {
  color: var(--ink);
}

.call {
  margin: 0.25rem 0 0.25rem 1rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.75rem;
}

.call-output {
  margin-left: 1rem;
}

.call-output pre {
  max-height: 22rem;
  margin: 0.3rem 0;
  padding: 0.5rem 0.7rem;
  border-radius: 6px;
  background: var(--surface);
  font-size: 0.75rem;
  overflow: auto;
  white-space: pre-wrap;
}

/* Sits beside Send, and only once there is a conversation to be rid of. */
#composer button.secondary {
  padding: 0.55rem 0.8rem;
  color: var(--muted);
}

#composer button.secondary:hover {
  color: var(--ink);
  border-color: var(--muted);
}
