:root {
  --bg: #f7f7f5;
  --panel: #ffffff;
  --ink: #18181b;
  --muted: #6b6b73;
  --line: #e4e4e0;
  --accent: #d9152a;
  --accent-ink: #ffffff;
  --soft: #f1f1ee;
  --ok: #157f3b;
  --warn: #9a5b00;
  --warn-bg: #fff6e5;
  --err: #b42318;
  --add: #e9f7ee;
  --del: #fdecec;
  --code: #f3f3f0;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.05), 0 4px 16px rgba(0, 0, 0, 0.04);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d0d0f;
    --panel: #17171a;
    --ink: #ececef;
    --muted: #9b9ba3;
    --line: #2a2a30;
    --accent: #ef2b3f;
    --soft: #1f1f24;
    --ok: #4ade80;
    --warn: #fbbf24;
    --warn-bg: #2a2110;
    --err: #f87171;
    --add: #12301e;
    --del: #3a1517;
    --code: #1d1d22;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; -webkit-text-size-adjust: 100%; }
body { overflow-x: hidden; }
a { color: inherit; }
code, pre { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 8px; }
h3 { font-size: 15px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { display: grid; place-items: center; min-height: 100vh; }
.error { color: var(--err); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.grid2 { display: grid; gap: 12px; margin-top: 12px; }
@media (min-width: 640px) { .grid2 { grid-template-columns: 1fr 1fr; } }

/* buttons and inputs */
.btn { appearance: none; border: 1px solid var(--line); background: var(--panel); color: var(--ink); border-radius: 10px; padding: 9px 14px; font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; justify-content: center; min-height: 40px; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { background: var(--err); border-color: var(--err); color: #fff; }
.btn.ghost { background: transparent; }
.btn.small { padding: 5px 10px; min-height: 32px; font-size: 13px; }
.btn.wide { width: 100%; }
.link { background: none; border: 0; padding: 0; color: var(--muted); text-decoration: underline; cursor: pointer; font: inherit; font-size: 13px; }
.icon-btn { background: none; border: 0; font-size: 22px; color: var(--ink); cursor: pointer; padding: 4px 8px; min-height: 40px; }
input, select, textarea { font: inherit; color: var(--ink); background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px; width: 100%; max-width: 100%; }
textarea { resize: none; }
label { display: grid; gap: 4px; font-size: 13px; font-weight: 600; color: var(--muted); }
label.check { display: flex; gap: 8px; align-items: center; font-weight: 500; color: var(--ink); }
label.check input { width: auto; }
form { display: grid; gap: 12px; }
form.row { display: flex; }
form.row input { flex: 1 1 200px; width: auto; }

/* sign-in */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth-card { width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 24px; box-shadow: var(--shadow); display: grid; gap: 14px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; letter-spacing: -0.01em; }
.logo { display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 8px; background: #0b0b0c; color: #ef2b3f; font-weight: 900; font-size: 13px; }
.or { display: grid; grid-template-columns: 1fr auto 1fr; gap: 10px; align-items: center; color: var(--muted); font-size: 12px; }
.or::before, .or::after { content: ""; height: 1px; background: var(--line); }
.hint { font-size: 13px; color: var(--muted); margin: 0; }
.note { background: var(--soft); padding: 8px 10px; border-radius: 8px; margin: 0; }

/* shell */
.shell { display: grid; grid-template-columns: 1fr; min-height: 100vh; }
.sidebar { position: fixed; inset: 0 auto 0 0; width: min(300px, 86vw); background: var(--panel); border-right: 1px solid var(--line); padding: 14px; display: flex; flex-direction: column; gap: 12px; transform: translateX(-105%); transition: transform 0.2s ease; z-index: 30; overflow-y: auto; }
.menu-open .sidebar { transform: none; }
.scrim { display: none; }
.menu-open .scrim { display: block; position: fixed; inset: 0; background: rgba(0, 0, 0, 0.35); z-index: 20; }
.convs { display: grid; grid-template-columns: minmax(0, 1fr); gap: 2px; flex: 1; align-content: start; }
.conv { display: grid; grid-template-columns: 10px 1fr; column-gap: 8px; padding: 8px; border-radius: 8px; text-decoration: none; }
.conv:hover, .conv.active { background: var(--soft); }
.conv-title { font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.conv-meta { grid-column: 2; font-size: 12px; color: var(--muted); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--line); margin-top: 7px; }
.dot.running, .dot.queued { background: var(--warn); }
.dot.done { background: var(--muted); }
.dot.failed { background: var(--err); }
.dot.live { background: var(--ok); }
.links { display: grid; gap: 2px; border-top: 1px solid var(--line); padding-top: 10px; }
.links a { padding: 7px 8px; border-radius: 8px; text-decoration: none; font-weight: 600; }
.links a:hover { background: var(--soft); }
.me { display: flex; justify-content: space-between; align-items: center; font-size: 13px; border-top: 1px solid var(--line); padding-top: 10px; }
.main { min-width: 0; display: flex; flex-direction: column; min-height: 100vh; }
.topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 8px; padding: 8px 12px; padding-top: max(8px, env(safe-area-inset-top)); background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
.page-title { font-size: 16px; margin: 0; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 700; border: 1px solid var(--line); background: var(--panel); white-space: nowrap; }
.pill.busy { color: var(--warn); border-color: currentColor; }
.queue-count { color: var(--muted); }
.spinner { width: 12px; height: 12px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent; display: inline-block; animation: spin 0.8s linear infinite; vertical-align: -2px; }
.spinner.small { width: 10px; height: 10px; margin-left: 6px; }
@keyframes spin { to { transform: rotate(360deg); } }
.livebar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 8px 12px; font-size: 13px; border-bottom: 1px solid var(--line); background: var(--panel); }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); }
.live-text { flex: 1; min-width: 0; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.page { padding: 16px; max-width: 900px; width: 100%; margin: 0 auto; display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; align-content: start; }
.page > * { min-width: 0; }
.hello { font-size: 24px; margin-top: 12px; }
.banner { padding: 10px 12px; border-radius: 10px; background: var(--soft); margin: 0; }
.banner.warn { background: var(--warn-bg); color: var(--warn); }
.banner.ok { color: var(--ok); }
.recent { display: grid; grid-template-columns: minmax(0, 1fr); gap: 4px; }
.recent-row { display: flex; justify-content: space-between; gap: 12px; padding: 10px 12px; border-radius: 10px; background: var(--panel); border: 1px solid var(--line); text-decoration: none; }
.recent-row span:first-child { min-width: 0; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.recent-row span:last-child { flex-shrink: 0; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; }

/* composer */
.composer { display: grid; gap: 6px; padding: 10px 12px; padding-bottom: max(10px, env(safe-area-inset-bottom)); background: var(--bg); }
.composer-row { display: flex; gap: 8px; align-items: flex-end; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 6px; }
.composer-row textarea { border: 0; padding: 8px; background: transparent; min-height: 44px; flex: 1; min-width: 0; }
.composer-row textarea:focus { outline: none; }
.busy-note { font-size: 13px; color: var(--warn); }

/* conversation */
.conv-page { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.tabs { display: flex; gap: 4px; padding: 8px 12px 0; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tabs button { background: none; border: 0; padding: 8px 10px; font: inherit; font-weight: 700; color: var(--muted); border-bottom: 2px solid transparent; cursor: pointer; white-space: nowrap; }
.tabs button.on { color: var(--ink); border-bottom-color: var(--accent); }
.conv-cols { flex: 1; display: grid; grid-template-columns: 1fr; min-height: 0; }
.conv-cols > section { min-width: 0; }
.conv-cols .chat { display: flex; flex-direction: column; min-height: calc(100vh - 150px); }
.tab-chat .panel, .tab-changes .chat, .tab-changes .ship-panel, .tab-ship .chat, .tab-ship .changes-panel { display: none !important; }
.panel { padding: 14px; }
.messages { flex: 1; padding: 12px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; align-content: start; }
.msg { max-width: 100%; min-width: 0; overflow-wrap: anywhere; }
.msg.user { justify-self: end; max-width: min(85%, 640px); }
.msg.user .who { font-size: 12px; color: var(--muted); text-align: right; }
.msg.user .bubble { background: var(--accent); color: var(--accent-ink); padding: 10px 12px; border-radius: 14px 14px 4px 14px; white-space: pre-wrap; }
.msg.assistant { background: var(--panel); border: 1px solid var(--line); border-radius: 14px 14px 14px 4px; padding: 4px 12px; max-width: min(100%, 760px); }
.msg.streaming .caret { display: inline-block; width: 7px; height: 14px; background: var(--muted); animation: blink 1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.md p { margin: 8px 0; }
.md ul { margin: 8px 0; padding-left: 20px; }
.md code { background: var(--code); padding: 1px 5px; border-radius: 5px; }
.md pre.code, pre.tool-out, pre.diff, .log pre { background: var(--code); padding: 10px; border-radius: 8px; overflow-x: auto; max-width: 100%; white-space: pre; margin: 6px 0; }
.md-h { font-weight: 800; }
.tool { background: transparent; border-left: 3px solid var(--line); padding: 2px 0 2px 10px; font-size: 13px; min-width: 0; }
.tool summary { cursor: pointer; list-style: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); }
.tool summary::-webkit-details-marker { display: none; }
.tool-name { font-weight: 700; color: var(--ink); }
.tool.tool-error { border-left-color: var(--err); }
pre.tool-out { max-height: 320px; overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere; }
.sys { font-size: 13px; color: var(--muted); padding: 2px 0; }
.sys.warn { color: var(--warn); }
.sys.error { color: var(--err); }
.sys.result.done { color: var(--ok); }
.preview-card, .deploy-card, .undo-card { font-size: 14px; }
.preview-card.ready, .deploy-card.live, .undo-card.done { border-color: var(--ok); }
.preview-card.failed, .deploy-card.failed { border-color: var(--err); }
.preview-links { display: inline-flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.run-bar { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 8px 12px; font-size: 13px; color: var(--warn); border-top: 1px solid var(--line); }
.log summary { font-size: 13px; color: var(--muted); cursor: pointer; }
.log pre { max-height: 240px; font-size: 12px; white-space: pre-wrap; overflow-wrap: anywhere; }
.changes { display: grid; grid-template-columns: minmax(0, 1fr); gap: 6px; }
.file { border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--panel); }
.file-row { width: 100%; display: flex; gap: 8px; align-items: center; background: none; border: 0; padding: 10px; font: inherit; cursor: pointer; text-align: left; color: var(--ink); }
.file-path { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: ui-monospace, Menlo, monospace; font-size: 13px; }
.plus { color: var(--ok); font-size: 13px; }
.minus { color: var(--err); font-size: 13px; }
pre.diff { margin: 0; border-radius: 0; padding: 6px 0; font-size: 12px; max-height: 480px; overflow: auto; }
pre.diff div { padding: 0 10px; white-space: pre; }
pre.diff .add { background: var(--add); }
pre.diff .del { background: var(--del); }
pre.diff .hunk { color: var(--muted); }
.ship { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; align-content: start; }
.modal { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.45); display: grid; place-items: center; padding: 16px; z-index: 50; }
.modal-card { width: 100%; max-width: 420px; background: var(--panel); border-radius: 16px; padding: 18px; display: grid; gap: 12px; border: 1px solid var(--line); }
.modal-body { color: var(--muted); }
.audit { list-style: none; padding: 0; margin: 0; display: grid; gap: 2px; }
.audit li { display: grid; grid-template-columns: 1fr; gap: 0 12px; padding: 8px 10px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; font-size: 13px; }
.audit-when, .audit-who { color: var(--muted); }
.audit-what { overflow-wrap: anywhere; }
@media (min-width: 720px) { .audit li { grid-template-columns: 170px 130px 1fr; } }
.doc-list { display: flex; flex-wrap: wrap; gap: 6px; }
.doc { border: 1px solid var(--line); background: var(--panel); border-radius: 999px; padding: 6px 12px; font: inherit; font-size: 13px; cursor: pointer; color: var(--ink); max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.doc.on { border-color: var(--accent); }
.doc-view { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; overflow-wrap: anywhere; min-width: 0; }
.list { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.list li { display: flex; flex-wrap: wrap; gap: 6px; align-items: baseline; }
.settings .card { gap: 8px; }

/* wider screens: sidebar always visible; conversation in three columns */
@media (min-width: 900px) {
  .shell { grid-template-columns: 280px 1fr; }
  .sidebar { position: sticky; top: 0; height: 100vh; transform: none; width: auto; }
  .menu-btn, .scrim { display: none !important; }
}
@media (min-width: 1200px) {
  .tabs { display: none; }
  .conv-cols { grid-template-columns: 1fr 340px; grid-template-rows: auto 1fr; }
  .conv-cols .chat { grid-row: 1 / span 2; border-right: 1px solid var(--line); min-height: calc(100vh - 100px); }
  .tab-chat .panel, .tab-changes .panel, .tab-ship .panel { display: block !important; }
  .tab-changes .chat, .tab-ship .chat { display: flex !important; }
  .conv-cols .ship-panel { grid-column: 2; grid-row: 1; border-bottom: 1px solid var(--line); }
  .conv-cols .changes-panel { grid-column: 2; grid-row: 2; overflow: auto; }
}
