:root {
  color-scheme: light dark;
  --accent: #2f6fde;
  --danger: #c0392b;
  --bg: #ffffff;
  --panel: #f5f6f8;
  --line: #d9dce1;
  --muted: #667085;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #16181c; --panel: #1f2228; --line: #343841; --muted: #9aa1ad; }
}
* { box-sizing: border-box; }
body { font-family: system-ui, sans-serif; margin: 0; line-height: 1.5; background: var(--bg); }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.05rem; margin-top: 2rem; }
button, .button { font: inherit; padding: 0.45rem 0.9rem; border: 1px solid var(--line); border-radius: 6px; background: var(--panel); color: inherit; cursor: pointer; }
button:disabled { opacity: 0.45; cursor: default; }
button.primary, .button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.danger { color: var(--danger); }
button.link { border: 0; background: none; padding: 0; color: var(--accent); }
button.large { font-size: 1.1rem; padding: 0.7rem 1.4rem; }
a { color: var(--accent); }
input, textarea { font: inherit; padding: 0.5rem; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); color: inherit; width: 100%; }
label { display: grid; gap: 0.3rem; margin-bottom: 1rem; }
.notice { padding: 0.75rem 1rem; border-radius: 6px; background: color-mix(in srgb, var(--accent) 12%, transparent); }
.notice.error, .error { color: var(--danger); }
.notice.error { background: color-mix(in srgb, var(--danger) 12%, transparent); }
.muted, .hint { color: var(--muted); }
.buttons { display: flex; gap: 0.75rem; justify-content: flex-end; align-items: center; flex-wrap: wrap; }
form.inline { display: inline; }

/* Login, settings, takeover */
.card { max-width: 28rem; margin: 10vh auto 2rem; padding: 0 1rem; }
.card.wide { max-width: 40rem; margin-top: 4vh; }
.card .buttons { justify-content: flex-start; }

/* Editor: chat left (40 %), preview right (60 %); stacked on narrow screens */
.layout { display: grid; grid-template-columns: minmax(20rem, 2fr) 3fr; height: 100vh; }
.side { display: flex; flex-direction: column; gap: 0.75rem; padding: 0.75rem 1rem; overflow: hidden; border-right: 1px solid var(--line); }
.head { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; }
.head small { display: block; color: var(--muted); }
.head nav { display: flex; gap: 0.9rem; white-space: nowrap; }
.chat { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: 1rem; }
.chat .empty { color: var(--muted); padding: 1rem 0; }
.step .command { align-self: flex-end; margin-left: 15%; background: color-mix(in srgb, var(--accent) 14%, transparent); padding: 0.5rem 0.75rem; border-radius: 10px 10px 2px 10px; }
.step .command .text { white-space: pre-wrap; }
.step .answer { margin-top: 0.4rem; margin-right: 10%; background: var(--panel); padding: 0.5rem 0.75rem; border-radius: 10px 10px 10px 2px; }
.step .answer > :first-child, .summary > :first-child { margin-top: 0; }
.step .answer > :last-child, .summary > :last-child { margin-bottom: 0; }
.step.undone .summary { opacity: 0.55; text-decoration: line-through; }
.uploads { display: flex; flex-wrap: wrap; gap: 0.5rem; font-size: 0.9em; color: var(--muted); }
.badge { display: inline-block; font-size: 0.85em; color: var(--muted); margin: 0 0 0.3rem; }
.details summary { cursor: pointer; color: var(--muted); font-size: 0.9em; }
.details ul, .progress { font-size: 0.9em; color: var(--muted); margin: 0.3rem 0; padding-left: 1.2rem; }
.running .working::after { content: ""; display: inline-block; width: 0.8em; height: 0.8em; margin-left: 0.5em; border: 2px solid var(--muted); border-top-color: transparent; border-radius: 50%; animation: spin 0.8s linear infinite; vertical-align: -0.1em; }
.running .stream { white-space: pre-wrap; }
@keyframes spin { to { transform: rotate(360deg); } }
.command .row { display: flex; gap: 0.75rem; align-items: center; margin-top: 0.4rem; }
.command .files { flex: 1; font-size: 0.9em; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.command .attach { display: inline; margin: 0; cursor: pointer; color: var(--accent); white-space: nowrap; }
.command.dragover textarea { outline: 2px dashed var(--accent); }
.actions { display: flex; gap: 0.5rem; flex-wrap: wrap; border-top: 1px solid var(--line); padding-top: 0.75rem; }
.history { padding-left: 1.2rem; }
.history ul { color: var(--muted); font-size: 0.9em; }

.preview { display: flex; flex-direction: column; min-width: 0; }
.toolbar { display: flex; gap: 0.75rem; align-items: center; padding: 0.5rem 0.75rem; border-bottom: 1px solid var(--line); font-size: 0.9em; }
.toolbar .page { flex: 1; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.toolbar button { padding: 0.2rem 0.6rem; }
.preview iframe { flex: 1; width: 100%; border: 0; background: #fff; }
body.enlarged .layout { grid-template-columns: 0 1fr; }
body.enlarged .side { display: none; }

dialog { border: 1px solid var(--line); border-radius: 10px; max-width: 30rem; background: var(--bg); color: inherit; }
dialog::backdrop { background: rgb(0 0 0 / 0.35); }
#busy { position: fixed; inset: 0; display: grid; place-items: center; background: rgb(0 0 0 / 0.35); z-index: 10; }
#busy[hidden] { display: none; }
#busy p { background: var(--bg); padding: 1rem 1.5rem; border-radius: 10px; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; height: auto; }
  .side { overflow: visible; border-right: 0; }
  .chat { overflow: visible; }
  .preview iframe { height: 75vh; flex: none; }
  body.enlarged .layout { grid-template-columns: 1fr; }
  [data-action="enlarge"] { display: none; }
}
