:root {
  --bg: #faf8f5;
  --panel: #ffffff;
  --ink: #1c1917;
  --muted: #78716c;
  --line: #e7e2db;
  --brand: #e8551f;
  --brand-ink: #ffffff;
  --user: #1c1917;
  --user-ink: #faf8f5;
  --code: #f4f1ec;
  --good: #15803d;
  --good-bg: #e8f5ec;
  --warn: #a16207;
  --warn-bg: #fdf4dc;
  --bad: #b91c1c;
  --bad-bg: #fdeaea;
  --info: #475569;
  --info-bg: #eef1f5;
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141210;
    --panel: #1c1a17;
    --ink: #f2efe9;
    --muted: #a39d94;
    --line: #2e2a25;
    --user: #f2efe9;
    --user-ink: #141210;
    --code: #24211d;
    --good: #4ade80;
    --good-bg: #13291b;
    --warn: #facc15;
    --warn-bg: #2e260c;
    --bad: #f87171;
    --bad-bg: #2f1414;
    --info: #94a3b8;
    --info-bg: #1e232b;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.55 Inter, system-ui, sans-serif;
  display: flex;
  flex-direction: column;
}
button { font: inherit; color: inherit; cursor: pointer; }
code, pre, textarea { font-family: "JetBrains Mono", ui-monospace, monospace; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }

.top {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}
.brand { display: flex; align-items: center; gap: 10px; color: inherit; text-decoration: none; font-weight: 600; font-size: 16px; }
.brand b { color: var(--brand); font-weight: 700; }
.tagline { margin: 0; color: var(--muted); font-size: 13px; }

.layout { flex: 1; display: grid; grid-template-columns: 1fr 300px; min-height: 0; }
.chat { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.log { flex: 1; overflow-y: auto; padding: 24px 20px 12px; display: flex; flex-direction: column; gap: 14px; }
.log > * { width: 100%; max-width: 760px; margin-left: auto; margin-right: auto; }

.empty { margin-top: 8vh; text-align: center; }
.empty h1 { font-size: 28px; letter-spacing: -0.02em; margin: 0 0 8px; }
.empty p { color: var(--muted); max-width: 520px; margin: 0 auto 20px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.chip { border: 1px solid var(--line); background: var(--panel); border-radius: 999px; padding: 7px 14px; font-size: 13.5px; }
.chip:hover { border-color: var(--brand); color: var(--brand); }

.msg { display: flex; }
.msg .bubble { padding: 10px 14px; border-radius: var(--radius); max-width: 88%; overflow-wrap: anywhere; }
.msg.user { justify-content: flex-end; }
.msg.user .bubble { background: var(--user); color: var(--user-ink); border-bottom-right-radius: 3px; }
.msg.assistant .bubble { background: var(--panel); border: 1px solid var(--line); border-bottom-left-radius: 3px; }
.msg.notice .bubble { background: transparent; color: var(--muted); font-size: 13.5px; padding: 4px 2px; border-left: 3px solid var(--brand); padding-left: 10px; border-radius: 0; }
.bubble p { margin: 0 0 8px; }
.bubble p:last-child { margin-bottom: 0; }
.bubble pre { background: var(--code); border-radius: 8px; padding: 10px 12px; overflow-x: auto; font-size: 12.5px; margin: 8px 0; white-space: pre; }
.bubble code { font-size: 0.9em; background: var(--code); padding: 1px 5px; border-radius: 4px; }
.bubble pre code { background: none; padding: 0; }
.pending .bubble::after { content: ""; display: inline-block; width: 12px; height: 12px; margin-left: 8px; vertical-align: -1px; border: 2px solid var(--line); border-top-color: var(--brand); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.card { width: min(100%, 680px); padding: 0 !important; overflow: hidden; }
.card-head { padding: 12px 14px; border-bottom: 1px solid var(--line); display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; }
.card-head .host { font-family: "JetBrains Mono", monospace; font-weight: 500; }
.card-head .when { margin-left: auto; color: var(--muted); font-size: 12px; }
.pill { font-size: 12px; font-weight: 600; padding: 2px 9px; border-radius: 999px; }
.pill.good { color: var(--good); background: var(--good-bg); }
.pill.warn { color: var(--warn); background: var(--warn-bg); }
.pill.bad { color: var(--bad); background: var(--bad-bg); }
.pill.info { color: var(--info); background: var(--info-bg); }
.card-section { padding: 12px 14px; border-bottom: 1px solid var(--line); }
.card-section:last-child { border-bottom: 0; }
.label { font-size: 11px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); margin-bottom: 6px; display: flex; gap: 6px; align-items: center; }
.label .src { text-transform: none; letter-spacing: 0; font-weight: 500; border: 1px solid var(--line); padding: 0 6px; border-radius: 4px; }
.engine-facts strong { display: block; margin-bottom: 2px; }
.fix { margin-top: 8px; }
.fix-title { font-weight: 600; }
details summary { cursor: pointer; color: var(--muted); font-size: 13px; }
.rejected { font-size: 12.5px; color: var(--warn); margin-top: 6px; }
.sources { margin-top: 10px; padding-top: 8px; border-top: 1px solid var(--line); font-size: 12.5px; }
.sources ol { margin: 4px 0 0; padding-left: 20px; }
.sources a { color: var(--brand); text-decoration: none; }
.sources a:hover { text-decoration: underline; }

.composer { display: flex; gap: 8px; padding: 12px 20px 18px; max-width: 800px; width: 100%; margin: 0 auto; }
.composer textarea {
  flex: 1;
  resize: none;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  border-radius: var(--radius);
  padding: 11px 14px;
  font-size: 14px;
  line-height: 1.45;
  max-height: 160px;
}
.composer textarea:focus { outline: 2px solid var(--brand); outline-offset: -1px; border-color: transparent; }
.send { width: 44px; border: 0; border-radius: var(--radius); background: var(--brand); color: var(--brand-ink); display: grid; place-items: center; }
.send:disabled { opacity: 0.5; cursor: default; }

.memory { border-left: 1px solid var(--line); background: var(--panel); padding: 18px; overflow-y: auto; }
.memory h2 { font-size: 15px; margin: 0; }
.memory h3 { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 18px 0 8px; }
.stack .tag { display: inline-block; border: 1px solid var(--line); border-radius: 6px; padding: 1px 8px; margin: 0 4px 4px 0; font-size: 13px; color: var(--ink); }
.domains { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.domains li { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font-size: 13px; }
.domains .d-host { font-family: "JetBrains Mono", monospace; font-size: 12.5px; display: flex; justify-content: space-between; gap: 6px; align-items: center; overflow-wrap: anywhere; }
.domains .d-meta { color: var(--muted); font-size: 12px; margin-top: 3px; }
.ghost { border: 1px solid var(--line); background: transparent; border-radius: 8px; padding: 6px 12px; font-size: 13px; }
.ghost.danger { margin-top: 20px; color: var(--bad); }
.only-narrow { display: none; margin-left: auto; }

@media (max-width: 860px) {
  .tagline { display: none; }
  .only-narrow { display: inline-block; }
  .layout { grid-template-columns: 1fr; }
  .memory { position: fixed; inset: 57px 0 auto auto; width: min(320px, 100%); max-height: calc(100% - 57px); border-left: 1px solid var(--line); border-bottom: 1px solid var(--line); box-shadow: 0 10px 30px rgb(0 0 0 / 0.15); transform: translateX(100%); transition: transform 0.2s; }
  .memory.open { transform: none; }
  .log { padding: 16px 16px 8px; }
  .composer { padding: 10px 16px 14px; }
  .msg .bubble { max-width: 100%; }
}
