:root {
  --bg: #f4f5f7; --panel: #ffffff; --panel-2: #f8f9fb; --line: #e3e6eb; --text: #1b1f27; --muted: #6a7282;
  --accent: #2557d6; --accent-ink: #fff; --accent-soft: #e8eefc; --danger: #c2372d; --ok: #1f8a4c; --warn: #b26b00;
  --user: #eef2fb; --code: #f3f4f6; --add: #e6f6ec; --add-ink: #146c37; --del: #fdecea; --del-ink: #a8261c;
  --radius: 10px; --shadow: 0 8px 30px rgba(20, 22, 26, .12);
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1114; --panel: #16191e; --panel-2: #1b1f25; --line: #2a2f37; --text: #e7e9ee; --muted: #949cab;
    --accent: #5b8cff; --accent-ink: #0b0d10; --accent-soft: #1c2740; --danger: #ff6b5f; --ok: #46c27b; --warn: #f0a63a;
    --user: #1c2433; --code: #1d2128; --add: #12301f; --add-ink: #7be0a4; --del: #3a1714; --del-ink: #ff9b91;
    --shadow: 0 8px 30px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
[hidden] { display: none !important; }
button, input, textarea, select { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.error { color: var(--danger); min-height: 1.5em; margin: 0; }

/* buttons */
.btn { border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 7px 14px; cursor: pointer; white-space: nowrap; display: inline-flex; align-items: center; gap: 6px; }
.btn:hover { border-color: var(--muted); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { background: transparent; }
.btn.small { padding: 4px 10px; font-size: 13.5px; }
.btn.icon { padding: 6px 10px; }
.badge { background: var(--accent-ink); color: var(--accent); border-radius: 99px; font-size: 12px; padding: 0 7px; font-weight: 700; }

/* login */
.login { min-height: 100%; display: grid; place-items: center; padding: 20px; }
.login-card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 32px; width: min(380px, 100%); display: grid; gap: 14px; box-shadow: var(--shadow); }
.login-card label { display: grid; gap: 6px; font-weight: 600; }
.login-card input { padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel-2); }

.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: -.01em; }
.brand.big { font-size: 1.3rem; }
.logo { width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center; background: var(--accent); color: var(--accent-ink); font-weight: 800; }

/* layout */
/* Column layout: whichever bars are visible take their natural height and
   the workspace always fills the rest (a hidden banner must not shift rows). */
.app { height: 100%; height: 100dvh; display: flex; flex-direction: column; }
.app > .topbar, .app > .banner, .app > .mobile-nav { flex: none; }
.app > .workspace { flex: 1; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 8px 12px; background: var(--panel); border-bottom: 1px solid var(--line); position: relative; }
.top-status { display: flex; gap: 8px; flex: 1; min-width: 0; }
.top-actions { display: flex; gap: 6px; align-items: center; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 99px; background: var(--panel-2); border: 1px solid var(--line); font-size: 13px; color: var(--muted); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.chip.running .dot { background: var(--ok); }
.chip.starting .dot { background: var(--warn); animation: pulse 1s infinite; }
.chip.error .dot { background: var(--danger); }
@keyframes pulse { 50% { opacity: .3; } }
.menu { position: absolute; right: 12px; top: 48px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); padding: 6px; display: grid; min-width: 250px; z-index: 20; }
.menu button { text-align: left; border: 0; background: none; padding: 8px 10px; border-radius: 6px; cursor: pointer; }
.menu button:hover { background: var(--panel-2); }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 4px 0; }
.banner { padding: 8px 14px; background: var(--accent-soft); border-bottom: 1px solid var(--line); font-size: 14px; }
.banner.warn { background: #fff3dc; color: #6a4300; }
@media (prefers-color-scheme: dark) { .banner.warn { background: #3a2a0c; color: #ffd28a; } }

.workspace { display: grid; grid-template-columns: minmax(340px, 34%) 1fr; min-height: 0; }
.pane { min-height: 0; display: flex; flex-direction: column; }
.chat-pane { border-right: 1px solid var(--line); background: var(--panel); }
.side-pane { background: var(--bg); }

/* chat */
.messages { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 14px; }
.msg { max-width: 100%; }
.msg.user { align-self: flex-end; background: var(--user); padding: 9px 13px; border-radius: 12px 12px 3px 12px; max-width: 90%; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.user .imgs { font-size: 12.5px; color: var(--muted); margin-top: 4px; }
.msg.assistant { overflow-wrap: anywhere; }
.msg.assistant p { margin: 0 0 .6em; }
.msg.assistant p:last-child { margin-bottom: 0; }
.msg.assistant ul, .msg.assistant ol { margin: 0 0 .6em; padding-left: 1.3em; }
.msg.assistant pre { background: var(--code); padding: 10px; border-radius: 8px; overflow-x: auto; font: 13px/1.45 var(--mono); }
.msg.assistant code { font: 13px var(--mono); background: var(--code); padding: 1px 4px; border-radius: 4px; }
.msg.assistant pre code { background: none; padding: 0; }
.steps { font-size: 13px; color: var(--muted); margin: 0 0 8px; }
.steps summary { cursor: pointer; }
.steps ol { margin: 6px 0 0; padding-left: 1.4em; }
.live-step { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 8px; }
.spinner { width: 12px; height: 12px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }
.saved { margin-top: 8px; font-size: 13px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.saved .tag { background: var(--accent-soft); color: var(--accent); border-radius: 6px; padding: 1px 8px; font-weight: 600; }
.link { background: none; border: 0; color: var(--accent); cursor: pointer; padding: 0; text-decoration: underline; font-size: inherit; }
.notice { font-size: 13px; color: var(--warn); }
.msg-error { color: var(--danger); font-size: 13.5px; margin-top: 6px; }
.empty-chat { margin: auto; text-align: center; color: var(--muted); max-width: 30em; }
.empty-chat h2 { color: var(--text); font-size: 1.15rem; }
.suggestions { display: grid; gap: 8px; margin-top: 14px; }
.suggestions button { text-align: left; border: 1px solid var(--line); background: var(--panel-2); border-radius: 8px; padding: 9px 12px; cursor: pointer; }
.suggestions button:hover { border-color: var(--accent); }

.composer { border-top: 1px solid var(--line); padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); display: grid; gap: 8px; }
.composer textarea { width: 100%; resize: none; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; background: var(--panel-2); max-height: 40vh; }
.composer textarea:focus, .preview-bar input:focus, #file-filter:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.composer-row { display: flex; align-items: center; gap: 8px; }
.composer-row .hint { flex: 1; font-size: 12.5px; }
#btn-send, #btn-stop { margin-left: auto; }
.attachments { display: flex; gap: 8px; flex-wrap: wrap; }
.attachments:empty { display: none; }
.thumb { position: relative; }
.thumb img { width: 64px; height: 64px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); display: block; }
.thumb button { position: absolute; top: -6px; right: -6px; width: 20px; height: 20px; border-radius: 50%; border: 0; background: var(--text); color: var(--panel); cursor: pointer; font-size: 12px; line-height: 1; }

/* tabs */
.tabs { display: flex; gap: 2px; padding: 6px 10px 0; background: var(--panel); border-bottom: 1px solid var(--line); }
.tab { border: 0; background: none; padding: 8px 14px; border-bottom: 2px solid transparent; cursor: pointer; color: var(--muted); font-weight: 600; }
.tab.active { color: var(--text); border-bottom-color: var(--accent); }
.tab-body { flex: 1; min-height: 0; display: flex; flex-direction: column; }

/* preview */
.preview-bar { display: flex; gap: 6px; padding: 8px 10px; background: var(--panel); border-bottom: 1px solid var(--line); }
.preview-bar input { flex: 1; min-width: 0; border: 1px solid var(--line); border-radius: 8px; padding: 4px 10px; background: var(--panel-2); font: 13.5px var(--mono); }
.preview-stage { position: relative; flex: 1; min-height: 0; background: #fff; }
.preview-stage iframe { width: 100%; height: 100%; border: 0; display: block; background: #fff; }
.overlay { position: absolute; inset: 0; display: grid; place-items: center; background: var(--bg); padding: 20px; }
.overlay-card { text-align: center; max-width: 26rem; }
.overlay-card h2 { font-size: 1.1rem; margin: 0 0 6px; }
.logs { position: absolute; inset: auto 0 0 0; height: 45%; background: var(--panel); border-top: 1px solid var(--line); display: flex; flex-direction: column; box-shadow: var(--shadow); }
.logs-bar { display: flex; justify-content: space-between; padding: 6px 10px; border-bottom: 1px solid var(--line); }
.logs pre { flex: 1; overflow: auto; margin: 0; padding: 10px; font: 12px/1.45 var(--mono); white-space: pre-wrap; }

/* versions / code */
.split { display: grid; grid-template-columns: minmax(240px, 34%) 1fr; flex: 1; min-height: 0; }
.list { list-style: none; margin: 0; padding: 0; overflow-y: auto; border-right: 1px solid var(--line); background: var(--panel); }
.list li { padding: 9px 12px; border-bottom: 1px solid var(--line); cursor: pointer; }
.list li:hover { background: var(--panel-2); }
.list li.active { background: var(--accent-soft); }
.v-title { font-weight: 600; font-size: 14px; overflow-wrap: anywhere; }
.v-meta { font-size: 12.5px; color: var(--muted); display: flex; gap: 8px; align-items: center; }
.pill { font-size: 11.5px; border-radius: 99px; padding: 0 7px; border: 1px solid var(--line); }
.pill.live { color: var(--ok); border-color: currentColor; }
.pill.draft { color: var(--warn); border-color: currentColor; }
.detail { overflow: auto; min-width: 0; padding: 14px; }
.detail.empty { display: grid; place-items: center; color: var(--muted); }
.detail h3 { margin: 0 0 4px; font-size: 1rem; }
.detail .msg-body { white-space: pre-wrap; font-size: 14px; color: var(--muted); margin: 0 0 12px; }
.detail-actions { display: flex; gap: 8px; margin: 10px 0 14px; }
.diff { font: 12.5px/1.5 var(--mono); border: 1px solid var(--line); border-radius: 8px; overflow: auto; background: var(--panel); }
.diff div { white-space: pre; padding: 0 10px; min-height: 1.5em; }
.diff .file { background: var(--panel-2); font-weight: 700; padding: 6px 10px; border-top: 1px solid var(--line); position: sticky; left: 0; }
.diff .add { background: var(--add); color: var(--add-ink); }
.diff .del { background: var(--del); color: var(--del-ink); }
.diff .hunk { color: var(--muted); }
.files-col { display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--line); background: var(--panel); }
.files-col input { margin: 8px; padding: 6px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel-2); }
.files li { font: 12.5px var(--mono); padding: 5px 12px; overflow-wrap: anywhere; }
.files { border-right: 0; flex: 1; }
.code { margin: 0; font: 12.5px/1.5 var(--mono); border: 1px solid var(--line); border-radius: 8px; overflow: auto; }
.code code.hljs { padding: 12px; }

/* publish */
.publish { padding: 18px; overflow-y: auto; max-width: 760px; }
.publish h2 { font-size: 1.1rem; margin: 0 0 6px; }
.publish ul { padding-left: 1.2em; }
.publish .card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin: 12px 0; }
.publish .card.db { border-color: var(--warn); }
.publish label.confirm { display: flex; gap: 8px; align-items: flex-start; margin-top: 8px; }
.publish-log { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 12px; font: 12.5px/1.5 var(--mono); white-space: pre-wrap; overflow-wrap: anywhere; }

.mobile-nav { display: none; }

@media (max-width: 860px) {
  .workspace { grid-template-columns: 1fr; }
  .chat-pane { border-right: 0; }
  .workspace[data-mobile="chat"] .side-pane { display: none; }
  .workspace:not([data-mobile="chat"]) .chat-pane { display: none; }
  .tabs { display: none; }
  .brand-text, .top-actions .label, .composer-row .hint { display: none; }
  .split { grid-template-columns: 1fr; grid-template-rows: 40% 1fr; }
  .list, .files-col { border-right: 0; border-bottom: 1px solid var(--line); }
  .mobile-nav { display: flex; background: var(--panel); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
  .mobile-nav button { flex: 1; border: 0; background: none; padding: 11px 0; color: var(--muted); font-weight: 600; font-size: 13.5px; }
  .mobile-nav button.active { color: var(--accent); }
}
