:root {
  color-scheme: dark;
  font: 15px/1.5 system-ui, sans-serif;
  color: #ebefff;
  background: #0c101b;
  --panel: #151b2b;
  --line: #343e55;
  --muted: #abb8d3;
  --focus: #a6bbff;
}
* { box-sizing: border-box; }
body { margin: 0; }
.top, main, footer { max-width: 1440px; margin: auto; padding: 1rem clamp(.8rem, 3vw, 2rem); }
.top, .workspace-title, .actions, .toolbar { display: flex; align-items: center; gap: .65rem; }
.top, .workspace-title { justify-content: space-between; }
.brand { display: inline-flex; align-items: center; gap: .7rem; color: inherit; text-decoration: none; font-weight: 750; }
.brand span { background: #b6c5ff; color: #151b2b; padding: .15rem .55rem; border-radius: .45rem; }
main { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: 1rem; padding-top: .25rem; }
.chat, .workspace, dialog { background: var(--panel); border: 1px solid var(--line); border-radius: 1rem; padding: 1rem; }
.chat, .workspace { display: flex; flex-direction: column; gap: .85rem; min-width: 0; }
.toolbar > label { flex: 1; min-width: 0; }
.conversation { min-height: 20rem; max-height: 52vh; overflow-y: auto; display: flex; flex-direction: column; gap: .75rem; }
.welcome { margin: auto; text-align: center; max-width: 32rem; padding: 1rem; }
h1, h2, p { margin: 0; }
h1 { font-size: clamp(1.45rem, 4vw, 2.25rem); line-height: 1.15; margin-bottom: .75rem; }
h2 { font-size: 1.1rem; }
p, label { color: var(--muted); }
label { display: block; }
button, .button, select, textarea, input[type="password"] { font: inherit; color: inherit; border: 1px solid var(--line); border-radius: .55rem; background: #101625; }
select, textarea, input[type="password"] { width: 100%; display: block; margin-top: .2rem; padding: .6rem .7rem; min-width: 0; }
textarea { resize: vertical; }
button, .button { cursor: pointer; padding: .55rem .75rem; color: #ebefff; }
button:disabled { opacity: .48; cursor: default; }
button:hover:enabled, .button:hover { border-color: var(--focus); }
:focus-visible, .button:focus-within { outline: 2px solid var(--focus); outline-offset: 2px; }
.primary { background: #b6c5ff; border-color: #b6c5ff; color: #101625; font-weight: 700; }
.actions { flex-wrap: wrap; justify-content: flex-end; margin-top: .6rem; }
.actions label { margin-right: auto; }
#editor, .versions textarea { font: .88rem/1.5 ui-monospace, Consolas, monospace; }
#editor { flex: 1; }
.message { padding: .7rem .9rem; border-radius: .65rem; background: #202a40; white-space: pre-wrap; overflow-wrap: anywhere; }
.message.user { align-self: end; max-width: 95%; background: #2d3b61; }
.chat-image { display: block; max-width: min(100%, 30rem); max-height: 24rem; object-fit: contain; margin-top: .5rem; border-radius: .4rem; }
dialog { color: inherit; width: min(92vw, 30rem); max-height: 90dvh; overflow: auto; }
dialog::backdrop { background: #070b14cc; }
dialog h2, dialog p, dialog #opencode { margin-bottom: .65rem; }
dialog #opencode { margin-top: .65rem; }
#proposal { width: min(94vw, 70rem); }
.versions { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
.versions label { min-width: 0; }
.sr-only { position: absolute; width: 1px; height: 1px; clip-path: inset(50%); overflow: hidden; white-space: nowrap; }
[hidden] { display: none !important; }
.top-actions { display: flex; align-items: center; gap: .8rem; flex-wrap: wrap; justify-content: flex-end; }
.top-actions a { color: var(--focus); }
.admin { display: block; }
.admin nav { display: flex; flex-wrap: wrap; gap: .4rem; border-bottom: 1px solid var(--line); padding-bottom: .7rem; }
.admin nav [aria-current] { background: #2d3b61; border-color: var(--focus); }
.admin #admin-status { margin: .6rem 0; }
.admin-card { background: var(--panel); border: 1px solid var(--line); border-radius: .8rem; padding: 1rem; margin-bottom: .8rem; }
.admin-card > * + * { margin-top: .65rem; }
#login { max-width: 32rem; margin: 2rem auto; }
.admin input:not([type="checkbox"]) { width: 100%; display: block; margin-top: .2rem; padding: .6rem .7rem; color: inherit; background: #101625; border: 1px solid var(--line); border-radius: .55rem; font: inherit; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit,minmax(min(100%, 14rem),1fr)); align-items: end; gap: .65rem; }
.table-scroll { overflow: auto; }
.admin table { width: 100%; border-collapse: collapse; text-align: left; }
.admin th, .admin td { padding: .55rem; border-bottom: 1px solid var(--line); }
.admin th { color: var(--muted); white-space: nowrap; }
.admin td code { overflow-wrap: anywhere; }
.admin .inline { display: flex; align-items: center; flex-wrap: wrap; gap: .55rem; }
.admin .danger { color: #ffb8bd; }
.admin .good { color: #a1e6be; }
.admin .test-output { white-space: pre-wrap; overflow-wrap: anywhere; }
@media (max-width: 760px) {
  main, .versions { grid-template-columns: 1fr; }
  .conversation { min-height: 14rem; max-height: 45vh; }
  select, textarea, input[type="password"] { font-size: 16px; }
}

/* ---- chat and workspace extensions ---- */
input[type="search"], .chat input[type="text"], .workspace input[type="text"], dialog input[type="text"], dialog input[type="password"] { width: 100%; display: block; margin-top: .2rem; padding: .6rem .7rem; font: inherit; color: inherit; border: 1px solid var(--line); border-radius: .55rem; background: #101625; }
.chip { border: 1px solid var(--line); border-radius: 1rem; padding: .15rem .65rem; color: var(--muted); font-size: .85rem; }
.banner { max-width: 1440px; margin: 0 auto .5rem; padding: .55rem .9rem; border: 1px solid #7a5b2a; background: #2a2210; color: #ffe2a8; border-radius: .6rem; }
.viewer .banner { margin: .4rem 0; }
.note { font-size: .85rem; color: var(--muted); }
.check { display: inline-flex; align-items: center; gap: .35rem; margin-right: 0; }
.actions.left { justify-content: flex-start; }
.actions .danger, button.danger { color: #ffb8bd; }
.more { margin-top: .5rem; }
.more summary { cursor: pointer; color: var(--muted); }
.attachments { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .5rem; }
.attachment { display: inline-flex; align-items: center; gap: .4rem; border: 1px solid var(--line); border-radius: .5rem; padding: .2rem .5rem; font-size: .85rem; }
.attachment button { padding: 0 .35rem; }
.message { position: relative; }
.message .meta { display: flex; flex-wrap: wrap; gap: .5rem; font-size: .78rem; color: var(--muted); margin-bottom: .35rem; }
.message .tools { display: flex; gap: .4rem; margin-top: .5rem; }
.message .tools button { font-size: .8rem; padding: .2rem .5rem; }
.message .prose { white-space: pre-wrap; }
.message code { font: .88em ui-monospace, Consolas, monospace; background: #0e1424; padding: 0 .25rem; border-radius: .25rem; }
.code { margin: .5rem 0; border: 1px solid var(--line); border-radius: .5rem; overflow: hidden; background: #0b1020; }
.code-head { display: flex; justify-content: space-between; align-items: center; padding: .2rem .6rem; background: #151d33; font-size: .78rem; color: var(--muted); }
.code-head button { font-size: .75rem; padding: .1rem .5rem; }
.code pre { margin: 0; padding: .6rem; overflow: auto; font: .85rem/1.45 ui-monospace, Consolas, monospace; white-space: pre; }
.code pre code { background: none; padding: 0; }
.job-steps, .job-progress { font-size: .85rem; color: var(--muted); }
.job-progress { margin: .35rem 0 0 1rem; padding: 0; }
.tabs { display: flex; gap: .4rem; border-bottom: 1px solid var(--line); padding-bottom: .5rem; }
.tabs [aria-current] { background: #2d3b61; border-color: var(--focus); }
.tree { max-height: 18rem; overflow: auto; border: 1px solid var(--line); border-radius: .6rem; padding: .35rem; background: #101625; }
.tree ul { list-style: none; margin: 0; padding-left: 1rem; }
.tree > ul { padding-left: 0; }
.tree summary { cursor: pointer; padding: .15rem .3rem; }
.tree .file { display: flex; justify-content: space-between; gap: .5rem; width: 100%; text-align: left; border: 0; background: none; padding: .2rem .35rem; border-radius: .35rem; }
.tree .file[aria-selected="true"] { background: #2d3b61; }
.tree .size { color: var(--muted); font-size: .78rem; white-space: nowrap; }
.viewer { display: flex; flex-direction: column; gap: .5rem; }
.viewer-head { display: flex; justify-content: space-between; gap: .5rem; align-items: baseline; }
.media img, .media video { max-width: 100%; max-height: 24rem; border-radius: .5rem; }
.diff { font: .82rem/1.4 ui-monospace, Consolas, monospace; max-height: 50vh; overflow: auto; border: 1px solid var(--line); border-radius: .5rem; background: #0b1020; }
.diff-line { white-space: pre-wrap; overflow-wrap: anywhere; padding: 0 .5rem; }
.diff-add { background: #12341f; color: #b4f0c8; }
.diff-del { background: #3a1820; color: #ffc1c9; }
.diff-fold { color: var(--muted); padding: .1rem .5rem; text-align: center; background: #151d33; }
#versions-dialog, #proposal { width: min(94vw, 60rem); }
.version-row { display: flex; gap: .5rem; align-items: center; padding: .25rem 0; border-bottom: 1px solid var(--line); }
.version-row label { margin-right: auto; }
.history-row { padding: .35rem 0; border-bottom: 1px solid var(--line); font-size: .88rem; overflow-wrap: anywhere; white-space: pre-wrap; }
.inline-select { display: flex; align-items: center; gap: .4rem; }
.inline-select select { margin-top: 0; }
#account h3 { margin: .8rem 0 .3rem; }
.session-row { display: flex; gap: .5rem; align-items: center; justify-content: space-between; padding: .3rem 0; border-bottom: 1px solid var(--line); font-size: .85rem; }
.note-line { margin-top: .4rem; }
@media (max-width: 760px) {
  dialog input { font-size: 16px; }
  .tree { max-height: 14rem; }
  input[type="search"], .chat input[type="text"] { font-size: 16px; }
}
.admin .bad { color: #ffb8bd; }
.badge { display: inline-block; border: 1px solid var(--line); border-radius: 1rem; padding: .05rem .55rem; font-size: .8rem; white-space: nowrap; }
.badge.cost-free, .badge.cost-quota { color: #a1e6be; }
.badge.cost-paid, .badge.cost-unknown { color: #ffe2a8; }
.admin dialog, body > dialog { max-width: 56rem; }

#admin-status { position: sticky; top: 0; z-index: 10; margin: 0; }
#admin-status:not(:empty) { padding: .6rem .9rem; border: 1px solid var(--focus); border-radius: .6rem; background: #17213a; }
