:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #1c2330;
  --muted: #5b6475;
  --border: #dfe3ea;
  --accent: #2f5fd0;
  --accent-text: #ffffff;
  --user: #e8eefc;
  --error: #b42318;
  --ok: #18794e;
  --warn: #9a5b00;
  --code: #f0f2f5;
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111418;
    --surface: #1a1f26;
    --text: #e6e9ef;
    --muted: #9aa3b2;
    --border: #2c333d;
    --accent: #7aa2ff;
    --accent-text: #0d1117;
    --user: #22304a;
    --error: #ff8a80;
    --ok: #6fd3a1;
    --warn: #f0b85a;
    --code: #232a33;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
code, pre, textarea { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
code { background: var(--code); padding: 0 4px; border-radius: 4px; font-size: 0.92em; }
a { color: var(--accent); }

.top {
  display: flex; justify-content: space-between; align-items: baseline; gap: 16px; flex-wrap: wrap;
  max-width: 1280px; margin: 0 auto; padding: 20px 16px 8px;
}
h1 { margin: 0; font-size: 1.5rem; letter-spacing: -0.01em; }
.build { margin: 0; color: var(--muted); font-size: 0.82rem; text-align: right; }

.layout {
  display: grid; grid-template-columns: minmax(280px, 360px) 1fr; gap: 16px;
  max-width: 1280px; margin: 0 auto; padding: 8px 16px 16px;
}
@media (max-width: 860px) { .layout { grid-template-columns: 1fr; } .build { text-align: left; } }

.side { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px;
}
.card h2 { font-size: 1rem; margin: 0 0 8px; display: inline-flex; align-items: center; gap: 8px; }
.optional { color: var(--muted); font-weight: 400; font-size: 0.85rem; }
details summary { cursor: pointer; list-style: none; }
details summary::-webkit-details-marker { display: none; }
details summary h2 { margin: 0; }
details summary::after { content: "Show"; float: right; color: var(--accent); font-size: 0.85rem; margin-top: 2px; }
details[open] summary::after { content: "Hide"; }
details[open] summary { margin-bottom: 8px; }

.note { color: var(--muted); font-size: 0.85rem; margin: 6px 0 10px; }
label { display: block; font-weight: 600; font-size: 0.88rem; margin: 10px 0 4px; }
label.check { font-weight: 400; display: flex; gap: 6px; align-items: center; }
label.check input { width: auto; margin: 0; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row input { flex: 1; min-width: 0; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; padding: 7px 9px; width: 100%;
}
.row input { width: auto; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
button {
  font: inherit; font-weight: 600; cursor: pointer; border-radius: 8px; padding: 7px 14px;
  border: 1px solid var(--accent); background: var(--accent); color: var(--accent-text);
}
button.secondary, .chips button { background: transparent; color: var(--accent); }
button:disabled { opacity: 0.45; cursor: not-allowed; }
.msg { margin: 6px 0 0; font-size: 0.85rem; min-height: 1.2em; }
.msg.error { color: var(--error); }
.msg.ok { color: var(--ok); }

.settings { display: grid; grid-template-columns: 1fr 96px; gap: 6px 10px; align-items: center; }
.settings .group { grid-column: 1 / -1; font-weight: 600; font-size: 0.85rem; margin-top: 8px; color: var(--muted); }
.settings label { margin: 0; font-weight: 400; font-size: 0.86rem; }
.settings label small { display: block; color: var(--muted); font-size: 0.78rem; }
.settings input.changed { border-color: var(--warn); box-shadow: 0 0 0 1px var(--warn); }

.chat {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  display: flex; flex-direction: column; min-width: 0;
  height: 80vh;
}
/* Wide screens: the page fills the window exactly; the chat log and the side panel scroll inside. */
@media (min-width: 861px) {
  body { display: flex; flex-direction: column; height: 100vh; height: 100dvh; overflow: hidden; }
  .top { flex: none; width: 100%; }
  .layout { flex: 1; min-height: 0; width: 100%; grid-template-rows: minmax(0, 1fr); }
  .side { min-height: 0; overflow-y: auto; }
  .chat { height: auto; min-height: 0; }
}
.log { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 12px; min-height: 0; }
.msg-agent, .msg-user, .msg-system {
  max-width: 92%; padding: 10px 13px; border-radius: 12px; white-space: pre-wrap; word-wrap: break-word;
}
.msg-agent { background: var(--code); align-self: flex-start; }
.msg-user { background: var(--user); align-self: flex-end; }
.msg-system { color: var(--muted); font-size: 0.88rem; align-self: center; text-align: center; background: none; }
.msg-agent pre { margin: 6px 0 0; font-size: 0.8rem; white-space: pre-wrap; }
.who { display: block; font-size: 0.75rem; font-weight: 700; color: var(--muted); margin-bottom: 2px; }
.t-red { color: var(--error); }
.t-green { color: var(--ok); }
.t-yellow { color: var(--warn); }
.t-dim { color: var(--muted); }

.status { margin: 0; padding: 0 16px; min-height: 1.4em; color: var(--muted); font-size: 0.85rem; }
.status:not(:empty)::before { content: ""; display: inline-block; width: 8px; height: 8px; margin-right: 8px; border-radius: 50%; background: var(--accent); animation: pulse 1s infinite alternate; }
@keyframes pulse { from { opacity: 0.25; } to { opacity: 1; } }
.chips { display: flex; gap: 6px; flex-wrap: wrap; padding: 4px 16px; }
.chips button { padding: 3px 10px; font-size: 0.82rem; font-family: ui-monospace, Menlo, Consolas, monospace; }
.composer { display: flex; gap: 8px; padding: 10px 16px 16px; }
.composer textarea { resize: vertical; min-height: 46px; font-family: inherit; }


button.link { background: none; border: 0; padding: 0; color: var(--accent); font: inherit; font-weight: 400; cursor: pointer; text-decoration: underline; }
.msg-system button { margin-top: 8px; }
dialog {
  max-width: min(560px, calc(100vw - 32px)); padding: 20px 22px; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text); box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.45); }
dialog h2 { margin: 0 0 10px; font-size: 1.15rem; }
dialog p { margin: 0 0 12px; }
.row.end { justify-content: flex-end; }
