:root {
  --bg: #0f0f0f;
  --panel: #161616;
  --raised: #1d1d1d;
  --hover: #242424;
  --line: #2a2a2a;
  --line-strong: #383838;
  --text: #ececec;
  --muted: #9b9b9b;
  --faint: #6c6c6c;
  --accent: #f2f2f2;
  --ok: #4ec27a;
  --warn: #e3b341;
  --bad: #f0645c;
  --add-bg: rgba(46, 160, 67, 0.16);
  --add-fg: #7ee2a0;
  --del-bg: rgba(248, 81, 73, 0.14);
  --del-fg: #ff9a93;
  --mono: "Cascadia Code", "Cascadia Mono", Consolas, ui-monospace, monospace;
  --sans: "Segoe UI Variable Text", "Segoe UI", system-ui, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  display: grid;
  grid-template-columns: 264px minmax(0, 1fr);
  background: var(--bg);
  color: var(--text);
  font: 14px/1.55 var(--sans);
  -webkit-font-smoothing: antialiased;
}
button, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.45; }
:focus-visible { outline: 2px solid #7aa7ff; outline-offset: 2px; }
svg { width: 15px; height: 15px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
code, pre, kbd { font-family: var(--mono); }
[hidden] { display: none !important; }

/* ---------- Barra lateral ---------- */
#sidebar {
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 14px 10px 10px;
  background: var(--panel);
  border-right: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 9px; padding: 2px 8px 14px; font-weight: 600; letter-spacing: 0.01em; }
.logo, .mark {
  display: inline-grid; place-items: center;
  font-family: var(--mono); font-weight: 700;
  background: var(--accent); color: #111; border-radius: 7px;
}
.logo { width: 24px; height: 24px; font-size: 12px; }
.new-task {
  display: flex; align-items: center; gap: 8px;
  width: 100%; padding: 8px 10px;
  background: transparent; border: 1px solid var(--line-strong); border-radius: 9px;
}
.new-task:hover { background: var(--hover); }
.section-label { padding: 16px 10px 6px; color: var(--faint); font-size: 12px; }
#tasks { flex: 1; min-height: 0; overflow-y: auto; display: grid; align-content: start; gap: 1px; }
.task { position: relative; display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; border-radius: 8px; }
.task:hover, .task[aria-current="true"] { background: var(--hover); }
.task-open { min-width: 0; padding: 7px 10px; text-align: left; background: none; border: 0; }
.task-title { display: block; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.task-meta { display: flex; gap: 6px; color: var(--faint); font-size: 12px; overflow: hidden; white-space: nowrap; }
.task-meta .dot { width: 6px; height: 6px; margin-top: 7px; border-radius: 50%; background: var(--warn); animation: pulse 1.2s infinite; }
.task-remove { margin-right: 6px; padding: 2px 7px; background: none; border: 0; border-radius: 6px; color: var(--faint); opacity: 0; }
.task:hover .task-remove, .task-remove:focus-visible { opacity: 1; }
.task-remove:hover { background: var(--line); color: var(--text); }
.sidebar-foot { display: grid; gap: 2px; padding: 10px 10px 2px; border-top: 1px solid var(--line); font-size: 12px; }
.status { display: flex; align-items: center; gap: 7px; color: var(--muted); }
.status::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--warn); animation: pulse 1.2s infinite; }
.status[data-state="idle"]::before, .status[data-state="ready"]::before { background: var(--ok); animation: none; }
.status[data-state="error"]::before, .status[data-state="offline"]::before { background: var(--bad); animation: none; }
.model-pick { display: flex; align-items: center; gap: 6px; margin: 2px -6px 0; padding: 3px 6px; border-radius: 7px; color: var(--muted); }
.model-pick:hover { background: var(--hover); color: var(--text); }
.model-pick select { flex: 1; min-width: 0; padding: 0; border: 0; outline: 0; background: transparent; font-family: var(--mono); font-size: 11.5px; cursor: pointer; appearance: none; }
.model-pick select option { background: var(--raised); color: var(--text); }
.model-standby { display: flex; align-items: center; gap: 7px; margin-top: 4px; color: var(--muted); }
.model-standby input { margin: 0; accent-color: var(--ok); }
@keyframes pulse { 50% { opacity: 0.35; } }

/* ---------- Principal ---------- */
main { display: grid; grid-template-rows: auto minmax(0, 1fr) auto; min-width: 0; height: 100vh; }
.topbar { display: flex; align-items: center; gap: 8px; min-width: 0; padding: 10px 16px; border-bottom: 1px solid var(--line); }
.topbar h1 { margin: 0 6px 0 0; max-width: 40%; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-size: 14px; font-weight: 600; }
.grow { flex: 1; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; max-width: 320px;
  padding: 4px 10px; border: 1px solid var(--line-strong); border-radius: 999px;
  background: transparent; color: var(--muted); font-size: 12.5px; white-space: nowrap;
}
.chip span { overflow: hidden; text-overflow: ellipsis; }
button.chip:hover { background: var(--hover); color: var(--text); }
.chip.quiet { border-color: transparent; }
.chip[aria-expanded="true"] { background: var(--raised); color: var(--text); }
.count { padding: 0 6px; border-radius: 999px; background: var(--line); color: var(--text); font-size: 11px; }

.workspace { display: grid; grid-template-columns: minmax(0, 1fr) auto; min-height: 0; }
#thread { overflow-y: auto; padding: 24px 20px 12px; scroll-behavior: auto; }
.column { width: min(780px, 100%); margin: 0 auto; }

#empty { display: grid; justify-items: center; gap: 10px; padding: 12vh 0 0; text-align: center; }
.mark { width: 44px; height: 44px; font-size: 18px; border-radius: 12px; }
#empty h2 { margin: 6px 0 0; font-size: 24px; font-weight: 600; letter-spacing: -0.01em; }
#empty p { margin: 0 0 6px; max-width: 460px; color: var(--muted); }
.suggestions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 8px; }
.suggestions button { padding: 7px 12px; border: 1px solid var(--line-strong); border-radius: 999px; background: transparent; color: var(--muted); }
.suggestions button:hover { background: var(--hover); color: var(--text); }
.primary { padding: 8px 16px; border: 0; border-radius: 9px; background: var(--accent); color: #111; font-weight: 600; }
.primary:hover { background: #fff; }
.secondary { padding: 7px 14px; border: 1px solid var(--line-strong); border-radius: 9px; background: transparent; }
.secondary:hover { background: var(--hover); }

/* ---------- Mensajes ---------- */
#messages, #live { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; }
.assistant { grid-template-columns: minmax(0, 1fr); }
#live:not(:empty) { margin-top: 14px; }
.user {
  justify-self: end; max-width: 85%;
  padding: 9px 14px; border-radius: 14px; background: var(--raised);
  white-space: pre-wrap; overflow-wrap: anywhere;
}
.assistant { display: grid; gap: 8px; min-width: 0; }
.notice { color: var(--muted); font-size: 13px; font-style: italic; }

.thinking { color: var(--faint); font-size: 13px; }
.thinking summary { width: fit-content; cursor: pointer; list-style: none; }
.thinking summary::-webkit-details-marker { display: none; }
.thinking summary::before { content: "▸ "; }
.thinking[open] summary::before { content: "▾ "; }
.thinking .body { margin: 6px 0 0; padding-left: 12px; border-left: 2px solid var(--line); white-space: pre-wrap; overflow-wrap: anywhere; max-height: 280px; overflow-y: auto; }
.thinking.live summary { animation: pulse 1.4s infinite; }

.md { overflow-wrap: anywhere; }
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p { margin: 0 0 10px; }
.md h3, .md h4, .md h5, .md h6 { margin: 16px 0 6px; font-size: 15px; }
.md ul, .md ol { margin: 0 0 10px; padding-left: 22px; }
.md li { margin: 2px 0; }
.md hr { border: 0; border-top: 1px solid var(--line); margin: 14px 0; }
.md :not(pre) > code { padding: 1px 5px; border-radius: 5px; background: var(--raised); font-size: 12.5px; }
.md table { width: 100%; margin: 0 0 10px; border-collapse: collapse; font-size: 13px; }
.md th, .md td { padding: 6px 9px; border: 1px solid var(--line); text-align: left; vertical-align: top; }
.md th { background: var(--panel); }
.code { margin: 0 0 10px; overflow: hidden; border: 1px solid var(--line); border-radius: 10px; background: #121212; }
.code-bar { display: flex; justify-content: space-between; align-items: center; padding: 5px 10px; border-bottom: 1px solid var(--line); color: var(--faint); font-size: 12px; }
.code-bar button { padding: 1px 8px; border: 0; border-radius: 5px; background: none; color: var(--muted); font-size: 12px; }
.code-bar button:hover { background: var(--hover); color: var(--text); }
.code-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 3px; }
.image-variants { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 230px), 1fr)); gap: 10px; }
pre { margin: 0; padding: 11px 13px; overflow-x: auto; font-size: 12.5px; line-height: 1.55; }

/* ---------- Acciones de herramientas ---------- */
.tool { min-width: 0; }
.action { display: flex; align-items: center; gap: 8px; min-width: 0; color: var(--muted); font-size: 13px; }
.action .label { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.action .label code { color: var(--text); font-size: 12.5px; }
.action .tag { padding: 0 7px; border-radius: 999px; background: var(--raised); color: var(--faint); font-size: 11.5px; }
.action .tag.bad { color: var(--bad); }
.action .tag.warn { color: var(--warn); }
.action .tag.ok { color: var(--ok); }
details.action-details > summary { list-style: none; cursor: pointer; }
details.action-details > summary::-webkit-details-marker { display: none; }
details.action-details > summary:hover .label { color: var(--text); }
details.action-details > summary .chev { color: var(--faint); transition: transform 0.15s; }
details.action-details[open] > summary .chev { transform: rotate(90deg); }
.output { margin: 6px 0 0 23px; max-height: 320px; overflow: auto; border: 1px solid var(--line); border-radius: 8px; background: #121212; font-size: 12px; white-space: pre; }
.spinner { width: 13px; height: 13px; border: 2px solid var(--line-strong); border-top-color: var(--text); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.card { overflow: hidden; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); }
.card-head { display: flex; align-items: center; gap: 8px; min-width: 0; padding: 8px 12px; border-bottom: 1px solid var(--line); font-size: 13px; }
.card-head .path { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-family: var(--mono); font-size: 12.5px; }
.card-head .stats { font-family: var(--mono); font-size: 12px; }
.plus { color: var(--add-fg); }
.minus { color: var(--del-fg); }
.card.rejected { opacity: 0.6; }
.card .cmd { padding: 10px 12px; font-family: var(--mono); font-size: 12.5px; white-space: pre-wrap; overflow-wrap: anywhere; }
.card .cmd::before { content: "$ "; color: var(--faint); }
.card .output { margin: 0; border: 0; border-top: 1px solid var(--line); border-radius: 0; }
.card-foot { display: flex; align-items: center; gap: 8px; padding: 9px 12px; border-top: 1px solid var(--line); background: var(--raised); }
.card-foot .question { flex: 1; color: var(--muted); font-size: 13px; }
.approval { border-color: #5a4a1d; }
.image-link { display: block; background: #0b0b0b; }
.audio-card audio { display: block; width: calc(100% - 24px); margin: 10px 12px 12px; color-scheme: dark; }
.image-card img { display: block; width: 100%; max-height: 560px; object-fit: contain; }
.card .cmd.prompt::before { content: none; }
.card .cmd.prompt { color: var(--muted); font-family: var(--sans); font-size: 13px; border-top: 1px solid var(--line); }

.diff { max-height: 420px; overflow: auto; font-family: var(--mono); font-size: 12px; line-height: 1.5; font-variant-ligatures: none; }
pre, code, .cmd { font-variant-ligatures: none; }
.diff table { width: 100%; border-collapse: collapse; }
.diff td { padding: 0 10px 0 0; white-space: pre; vertical-align: top; }
.diff td.no { width: 1%; min-width: 38px; padding: 0 8px; color: var(--faint); text-align: right; user-select: none; }
.diff tr.add { background: var(--add-bg); }
.diff tr.add td.text { color: var(--add-fg); }
.diff tr.del { background: var(--del-bg); }
.diff tr.del td.text { color: var(--del-fg); }
.diff tr.gap td { padding: 2px 10px; background: var(--raised); color: var(--faint); }
.diff .sign { width: 1%; padding: 0 4px; color: var(--faint); user-select: none; }

/* ---------- Panel de cambios ---------- */
#changes { display: flex; flex-direction: column; width: min(520px, 42vw); min-height: 0; border-left: 1px solid var(--line); background: var(--panel); }
#changes > header { display: flex; justify-content: space-between; align-items: center; padding: 12px 14px; border-bottom: 1px solid var(--line); }
#changes-summary { color: var(--muted); font-family: var(--mono); font-size: 12px; }
#changes-list { flex: 1; overflow-y: auto; display: grid; align-content: start; gap: 12px; padding: 12px; }
#changes-list .card { background: var(--bg); }
#changes-list .empty-note { padding: 24px 6px; color: var(--muted); text-align: center; }

/* ---------- Compositor ---------- */
.composer { padding: 8px 20px 12px; }
#error { margin-bottom: 8px; padding: 8px 12px; border: 1px solid #6b2a26; border-radius: 9px; background: #2a1514; color: #ffb4ae; font-size: 13px; }
.box { border: 1px solid var(--line-strong); border-radius: 16px; background: var(--panel); }
.box:focus-within { border-color: #4a4a4a; }
#prompt { display: block; width: 100%; min-height: 52px; max-height: 260px; padding: 12px 14px 4px; resize: none; border: 0; outline: 0; background: transparent; line-height: 1.5; }
#prompt::placeholder { color: var(--faint); }
.bar { display: flex; align-items: center; gap: 6px; padding: 6px 8px 8px; }
.select { position: relative; display: inline-flex; align-items: center; gap: 5px; padding: 3px 8px; border-radius: 8px; color: var(--muted); font-size: 12.5px; }
.select:hover { background: var(--hover); color: var(--text); }
.select select { padding: 0; border: 0; outline: 0; background: transparent; cursor: pointer; appearance: none; }
.select select option { background: var(--raised); color: var(--text); }
.select[data-mode="auto"] { color: var(--warn); }
.toggle { cursor: pointer; user-select: none; }
.toggle input { position: absolute; opacity: 0; pointer-events: none; }
.toggle svg { padding: 1px; border: 1px solid var(--line-strong); border-radius: 4px; stroke: transparent; }
.toggle:has(input:checked) { color: var(--text); }
.toggle:has(input:checked) svg { background: var(--accent); border-color: var(--accent); stroke: #111; stroke-width: 2.2; }
.toggle:has(input:focus-visible) { outline: 2px solid #7aa7ff; outline-offset: 2px; }
.review-divider { display: flex; align-items: center; gap: 10px; color: var(--faint); font-size: 12px; }
.review-divider::before, .review-divider::after { content: ""; flex: 1; border-top: 1px dashed var(--line-strong); }
.summary-block > summary { cursor: pointer; list-style: none; }
.summary-block > summary::-webkit-details-marker { display: none; }
.summary-block > .md { margin-top: 10px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); font-size: 13px; color: var(--muted); }
.send, .stop { display: grid; place-items: center; width: 32px; height: 32px; padding: 0; border: 0; border-radius: 50%; }
.send { background: var(--accent); color: #111; }
.send svg { stroke-width: 2; }
.stop { background: var(--line-strong); }
.mic { display: grid; place-items: center; height: 32px; min-width: 32px; padding: 0 9px; gap: 6px; border: 0; border-radius: 999px; background: transparent; color: var(--muted); font-size: 12px; }
.mic:hover { background: var(--hover); color: var(--text); }
.mic[data-state="recording"] { grid-auto-flow: column; background: #5c1e1b; color: #ffb4ae; animation: pulse 1.2s infinite; }
.mic[data-state="working"] { grid-auto-flow: column; color: var(--warn); }
.stop svg { fill: currentColor; stroke: none; }
.hint { margin: 6px 0 0; color: var(--faint); font-size: 11.5px; text-align: center; }

@media (max-width: 860px) {
  body { grid-template-columns: 1fr; }
  #sidebar { display: none; }
  #changes { position: fixed; inset: 49px 0 0 auto; width: min(520px, 100vw); z-index: 5; }
}
