:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #1a1d21;
  --muted: #4b5563;
  --border: #c9ced6;
  --accent: #1d4ed8;
  --accent-text: #ffffff;
  --danger: #991b1b;
  --ok: #166534;
  --warn-bg: #fef3c7;
  --warn-text: #78350f;
  --warn-border: #b45309;
  --info-bg: #e0ecff;
  --info-text: #1e3a8a;
  --add-bg: #dcfce7;
  --add-text: #14532d;
  --del-bg: #fee2e2;
  --del-text: #7f1d1d;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
h1 { font-size: 1.4rem; margin: 0 0 .75rem; }
h2 { font-size: 1.05rem; margin: 0 0 .5rem; }
h3 { font-size: 1rem; margin: 0 0 .5rem; }
h4 { font-size: .9rem; margin: 0 0 .25rem; overflow-wrap: anywhere; }
a { color: var(--accent); }
code, pre { font-family: var(--mono); font-size: .85em; }
pre { white-space: pre-wrap; overflow-wrap: anywhere; margin: .25rem 0 0; }
.muted { color: var(--muted); }
.spacer { flex: 1; }

:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.skip { position: absolute; left: -999px; top: 0; background: var(--surface); padding: .5rem 1rem; z-index: 10; }
.skip:focus { left: 0; }

.banner { padding: .6rem 1rem; border-bottom: 2px solid; }
.banner-warn { background: var(--warn-bg); color: var(--warn-text); border-color: var(--warn-border); font-weight: 600; }
.banner-info { background: var(--info-bg); color: var(--info-text); border: 1px solid var(--info-text); border-radius: 6px; margin-bottom: 1rem; }

.top { display: flex; align-items: center; gap: 1rem; padding: .5rem 1rem; background: var(--surface); border-bottom: 1px solid var(--border); }
.brand { font-weight: 700; text-decoration: none; color: var(--text); font-size: 1.1rem; }

.page { max-width: 60rem; margin: 0 auto; padding: 1.25rem 1rem; }

button {
  font: inherit; padding: .45rem .9rem; border-radius: 6px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); cursor: pointer; min-height: 2.25rem;
}
button:disabled { cursor: not-allowed; opacity: .6; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
button.danger { border-color: var(--danger); color: var(--danger); }
button.link { border: 0; background: none; padding: 0; min-height: 0; color: var(--accent); text-decoration: underline; text-align: left; overflow-wrap: anywhere; }
button.jump { align-self: center; }

label { display: block; font-weight: 600; margin: .5rem 0 .25rem; }
input[type="text"], textarea {
  width: 100%; font: inherit; padding: .4rem .5rem; border: 1px solid var(--muted); border-radius: 6px;
  background: var(--surface); color: var(--text);
}
textarea { resize: vertical; }
textarea:disabled { background: #eceef2; }

.error { color: var(--danger); font-weight: 600; }
.success { color: var(--ok); font-weight: 600; }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: .75rem; margin-top: .5rem; }

.cards { list-style: none; margin: 0 0 1rem; padding: 0; display: grid; gap: 1rem; grid-template-columns: repeat(auto-fill, minmax(16rem, 1fr)); }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 1rem; }
.cards .card h2 { overflow-wrap: anywhere; }
.fields { margin: 0 0 .75rem; }
.fields > div { display: flex; flex-wrap: wrap; gap: .25rem .75rem; }
.fields dt { color: var(--muted); min-width: 9rem; }
.fields dd { margin: 0; font-weight: 600; overflow-wrap: anywhere; }

/* Workspace: three columns, stacked below 1000px (chat first, then changes, then behind the scenes). */
.workspace { padding: .75rem 1rem 1rem; }
.ws-bar { display: flex; flex-wrap: wrap; align-items: center; gap: .75rem 1rem; margin-bottom: .5rem; }
.ws-bar h1 { margin: 0; }
.columns { display: grid; gap: 1rem; grid-template-columns: 1fr; }
.col { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: .75rem; display: flex; flex-direction: column; min-width: 0; }
@media (min-width: 1000px) {
  .columns { grid-template-columns: minmax(0, 1.1fr) minmax(0, 1.3fr) minmax(0, 1fr); height: calc(100vh - 11rem); min-height: 28rem; }
  .col { min-height: 0; }
}

.chat, .trace { list-style: none; margin: 0 0 .5rem; padding: 0; overflow-y: auto; flex: 1; min-height: 8rem; max-height: 24rem; }
@media (min-width: 1000px) { .chat, .trace { max-height: none; } }
.chat > li { margin-bottom: .6rem; }
.msg .who { font-weight: 700; font-size: .85rem; color: var(--muted); }
.msg .text { white-space: pre-wrap; overflow-wrap: anywhere; }
.msg-user .text { background: #e8eefc; border-radius: 6px; padding: .4rem .6rem; }
.msg-assistant .text { padding: .1rem 0; }
.tool { font-size: .9rem; color: var(--muted); }
.tool summary { cursor: pointer; }
.usage, .busy { font-size: .85rem; color: var(--muted); }
.msg-error { color: var(--danger); border-left: 4px solid var(--danger); padding-left: .5rem; overflow-wrap: anywhere; }
.prompt { border-top: 1px solid var(--border); padding-top: .25rem; }

.scroll { overflow-y: auto; flex: 1; min-height: 8rem; max-height: 28rem; margin-bottom: .5rem; }
@media (min-width: 1000px) { .scroll { max-height: none; } }
.filelist { list-style: none; padding: 0; margin: 0 0 .75rem; font-size: .9rem; }
.filelist li { margin-bottom: .2rem; }
.count { font-family: var(--mono); font-size: .8rem; font-weight: 700; }
.count.add { color: var(--add-text); }
.count.del { color: var(--del-text); }
.file { margin-bottom: 1rem; }
.hunk { font-family: var(--mono); font-size: .8rem; border: 1px solid var(--border); border-radius: 4px; margin-bottom: .5rem; overflow-x: auto; }
.hunk-head { background: #eceef2; color: var(--muted); padding: .1rem .4rem; }
.line { display: flex; white-space: pre; min-width: max-content; }
.line .sign { width: 1.5rem; text-align: center; flex: none; user-select: none; }
.line.add { background: var(--add-bg); color: var(--add-text); }
.line.del { background: var(--del-bg); color: var(--del-text); }
.submit { border-top: 1px solid var(--border); padding-top: .5rem; }

.legend { margin: 0 0 .25rem; font-size: .9rem; }
.trace-line { border-bottom: 1px solid #e5e7eb; padding: .3rem 0; font-size: .85rem; }
.trace-main { display: flex; flex-wrap: wrap; align-items: baseline; gap: .15rem .4rem; }
.trace-line .clock { color: var(--muted); font-family: var(--mono); font-size: .75rem; }
.trace-line .sep { color: var(--muted); }
.trace-line .dur { color: var(--muted); }
.trace-line.failed { background: #fff5f5; }
.trace-line .fail { color: var(--danger); font-weight: 700; }
.detail { margin-top: .15rem; display: flex; flex-wrap: wrap; gap: .1rem .75rem; color: var(--muted); font-size: .8rem; overflow-wrap: anywhere; }
.detail .k { font-weight: 600; }
.port { padding: 0 .4rem; border-radius: 4px; font-weight: 700; font-size: .78rem; border: 1px solid currentColor; }
.port-ProjectSource { background: #e0e7ff; color: #312e81; }
.port-WorkspaceRunner { background: #dcfce7; color: #14532d; }
.port-GitHost { background: #ffedd5; color: #7c2d12; }
.port-Agent { background: #f3e8ff; color: #581c87; }
.port-ModelEndpoint { background: #cffafe; color: #164e63; }
.port-Knowledge { background: #fce7f3; color: #831843; }
