:root {
  --bg: #f6f7f9; --fg: #1d2330; --muted: #5d6675; --card: #fff; --line: #dde1e7;
  --accent: #0b5cad; --danger: #b42318; --ok-bg: #e8f5ec; --err-bg: #fdecea; --info-bg: #eaf2fb;
}
* { box-sizing: border-box; }
body { margin: 0; font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif; background: var(--bg); color: var(--fg); }
a { color: var(--accent); }
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 1rem;
  padding: .75rem 1.25rem; background: var(--card); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.brand { font-weight: 600; text-decoration: none; color: var(--fg); }
.topbar nav { display: flex; gap: 1rem; align-items: center; flex-wrap: wrap; }
.who { color: var(--muted); }
.page { max-width: 1100px; margin: 0 auto; padding: 1.5rem 1rem; }
.page.narrow { max-width: 420px; }
h1 { font-size: 1.5rem; margin: .5rem 0 1rem; }
h2 { font-size: 1.15rem; margin: 2rem 0 .75rem; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 1rem;
  display: flex; flex-direction: column; gap: .75rem; }
.card.row { flex-direction: row; flex-wrap: wrap; align-items: flex-end; margin-top: 1rem; }
label { display: flex; flex-direction: column; gap: .25rem; font-weight: 500; }
label.check { flex-direction: row; align-items: center; gap: .4rem; font-weight: 400; }
input, textarea { font: inherit; padding: .5rem .6rem; border: 1px solid var(--line); border-radius: 6px; width: 100%; }
textarea { min-height: 10rem; }
button { font: inherit; padding: .5rem 1rem; border: 0; border-radius: 6px; background: var(--accent); color: #fff; cursor: pointer; }
button.danger { background: var(--danger); }
button.small { padding: .25rem .6rem; font-size: .85rem; }
button.link { background: none; color: var(--accent); padding: 0; text-decoration: underline; }
form.inline { display: inline; }
.hint { color: var(--muted); font-size: .9rem; }
.alert { padding: .6rem .8rem; border-radius: 6px; }
.alert.error { background: var(--err-bg); }
.alert.ok { background: var(--ok-bg); }
.alert.info { background: var(--info-bg); }
table { width: 100%; border-collapse: collapse; background: var(--card); border: 1px solid var(--line); display: block; overflow-x: auto; }
th, td { text-align: left; padding: .5rem .6rem; border-bottom: 1px solid var(--line); white-space: nowrap; }
.mono { font-family: ui-monospace, Menlo, monospace; font-size: .85rem; }
.small { font-size: .8rem; }
.pager { display: flex; gap: 1rem; }

/* --- Chat ------------------------------------------------------------------------------- */
a.button, .button { display: inline-block; padding: .45rem .9rem; border-radius: 6px; background: var(--accent);
  color: #fff; text-decoration: none; font-size: .9rem; }
.button.small { padding: .2rem .55rem; font-size: .8rem; }
button.secondary { background: #e7eaf0; color: var(--fg); }
button:disabled { opacity: .55; cursor: wait; }
.danger-link { color: var(--danger); }

.chat-layout { display: grid; grid-template-columns: var(--sidebar-w, 260px) 1fr; height: calc(100vh - 53px); }
html.sidebar-collapsed .chat-layout { grid-template-columns: 1fr; }
html.sidebar-collapsed .sidebar { display: none; }
.sidebar { border-right: 1px solid var(--line); background: var(--card); display: flex; flex-direction: column;
  padding: .75rem; gap: .5rem; overflow: hidden; position: relative; min-width: 0; }
.sidebar-top { display: flex; gap: .4rem; align-items: stretch; }
.new-chat { flex: 1; display: block; text-align: center; padding: .5rem; border: 1px dashed var(--accent); border-radius: 6px;
  text-decoration: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-toggle { background: transparent; color: var(--muted); border: 1px solid var(--line); border-radius: 6px;
  padding: 0 .6rem; font-size: 1rem; line-height: 1; cursor: pointer; }
.sidebar-toggle:hover { color: var(--fg); background: var(--bg); }
.sidebar-show { display: none; position: absolute; top: .75rem; left: .75rem; z-index: 2; height: 2.1rem;
  background: var(--card); }
html.sidebar-collapsed .sidebar-show { display: block; }
html.sidebar-collapsed .messages { padding-left: 3.75rem; }
.chat { position: relative; }
.sidebar-resizer { position: absolute; top: 0; right: 0; width: 6px; height: 100%; cursor: col-resize; }
.sidebar-resizer:hover, .sidebar-resizer:focus-visible, html.sidebar-resizing .sidebar-resizer {
  background: var(--accent); opacity: .35; outline: none; }
html.sidebar-resizing, html.sidebar-resizing * { cursor: col-resize !important; user-select: none !important; }
/* Long titles: one line, left-aligned, cut with «…»; the list never scrolls sideways. */
.conv-list { overflow-y: auto; overflow-x: hidden; display: flex; flex-direction: column; gap: 2px; flex: 1;
  min-width: 0; align-items: stretch; flex-wrap: nowrap; }
.conv-list a { display: block; min-width: 0; text-align: left; padding: .45rem .55rem; border-radius: 6px;
  text-decoration: none; color: var(--fg); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  font-size: .9rem; flex-shrink: 0; }
.conv-list a:hover { background: var(--bg); }
.conv-list a.active { background: var(--info-bg); font-weight: 600; }
.conv-group { display: block; min-width: 0; margin-top: .35rem; text-align: left;
  border-top: 1px solid var(--line); padding-top: .35rem; }
.conv-group > summary { cursor: pointer; padding: .45rem .55rem; border-radius: 6px; font-size: .85rem;
  color: var(--muted); list-style: none; user-select: none; white-space: nowrap; overflow: hidden;
  text-overflow: ellipsis; }
.conv-group > summary::-webkit-details-marker { display: none; }
.conv-group > summary::before { content: "▸"; display: inline-block; width: 1em; transition: transform .15s; }
.conv-group[open] > summary::before { transform: rotate(90deg); }
.conv-group > summary:hover { background: var(--bg); }
.conv-group > a { padding-left: 1.55rem; font-size: .85rem; margin-top: 2px; }
.delete-conv { font-size: .85rem; }

.chat { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.messages { flex: 1; overflow-y: auto; padding: 1.25rem 1.5rem; display: flex; flex-direction: column; gap: 1rem; }
.welcome { max-width: 720px; margin: 2rem auto; }
.welcome h1 { font-size: 1.6rem; }
.examples { list-style: none; padding: 0; display: flex; flex-direction: column; gap: .5rem; }
.example { background: var(--card); color: var(--fg); border: 1px solid var(--line); text-align: left; width: 100%; }
.example:hover { border-color: var(--accent); }

.msg { max-width: 980px; width: 100%; margin: 0 auto; }
.msg.user { display: flex; justify-content: flex-end; }
.msg.user .bubble { background: var(--accent); color: #fff; padding: .6rem .9rem; border-radius: 12px 12px 2px 12px;
  max-width: 75%; white-space: pre-wrap; }
.msg.assistant { display: flex; flex-direction: column; gap: .75rem; }
.msg.assistant .text { line-height: 1.6; }
.msg.assistant .text table { border-collapse: collapse; display: table; width: auto; }
.msg.assistant .text p { margin: .4rem 0; }
.status { color: var(--muted); font-style: italic; }
.status::after { content: " ⋯"; animation: blink 1.2s infinite; }
@keyframes blink { 50% { opacity: .3; } }

/* "Raciocínio e consultas": the model's reasoning and every query it ran, collapsed. */
.trace { font-size: .88rem; color: var(--muted); }
.trace > summary { cursor: pointer; user-select: none; width: fit-content; }
.trace > summary:hover { color: var(--fg); }
.trace.live > summary { font-style: italic; }
.trace.live > summary .label::after { content: " ⋯"; animation: blink 1.2s infinite; }
.trace-body { margin-top: .5rem; border-left: 3px solid var(--line); padding-left: .75rem;
  display: flex; flex-direction: column; gap: .6rem; max-height: 60vh; overflow-y: auto; }
.trace-step .step-head { display: flex; gap: .5rem; flex-wrap: wrap; align-items: baseline; }
.trace-step .step-head strong { color: var(--fg); font-weight: 600; }
.trace-step .thinking { white-space: pre-wrap; margin: .2rem 0 0; font-style: italic; }
.trace-step pre { white-space: pre-wrap; word-break: break-word; margin: .3rem 0 0; padding: .5rem;
  background: var(--card); border: 1px solid var(--line); border-radius: 6px;
  font: .82rem/1.45 ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--fg); }
.trace-step .step-error { color: var(--danger); white-space: pre-wrap; margin: .3rem 0 0; }
.trace-step.error strong { color: var(--danger); }

.block { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: .75rem; }
.block-header { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; margin-bottom: .5rem; }
.block-header .button { margin-left: auto; }
.table-scroll { max-height: 420px; overflow: auto; }
.table-block table { display: table; border: 0; font-size: .85rem; }
.table-block th { position: sticky; top: 0; background: var(--bg); }
td.num { text-align: right; font-variant-numeric: tabular-nums; }
.chart { width: 100%; min-height: 200px; }

.proposal-block { border-left: 4px solid var(--accent); }
.proposal-block.status-done { border-left-color: #2e7d32; }
.proposal-block.status-failed, .proposal-block.status-cancelled { border-left-color: var(--muted); }
.proposal-block dl { display: grid; grid-template-columns: max-content 1fr; gap: .3rem .9rem; margin: .5rem 0; }
.proposal-block dt { font-weight: 600; color: var(--muted); }
.proposal-block dd { margin: 0; }
.proposal-block pre { white-space: pre-wrap; font: inherit; margin: 0; background: var(--bg); padding: .5rem; border-radius: 6px; }
.proposal-block .queues { margin: 0; padding-left: 1.1rem; }
.proposal-block .actions { display: flex; gap: .5rem; margin-top: .5rem; flex-wrap: wrap; }
.badge { background: var(--info-bg); padding: .1rem .5rem; border-radius: 999px; font-size: .8rem; }

.composer { display: flex; gap: .5rem; padding: .75rem 1.5rem 0; max-width: 980px; width: 100%; margin: 0 auto; }
.composer textarea { flex: 1; resize: vertical; min-height: 2.8rem; max-height: 12rem; }
.disclaimer { text-align: center; margin: .35rem 0 .75rem; font-size: .78rem; }

@media (max-width: 760px) {
  .chat-layout { grid-template-columns: 1fr; height: auto; }
  .sidebar { border-right: 0; border-bottom: 1px solid var(--line); max-height: 30vh; }
  .sidebar-resizer { display: none; }
  .messages { padding: 1rem; }
  .composer { padding: .75rem 1rem 0; }
}

.usage { color: var(--muted); font-size: .78rem; border-top: 1px dashed var(--line); padding-top: .35rem;
  font-variant-numeric: tabular-nums; }
