:root {
  --bg-deep:   #0b1220;
  --bg:        #0f172a;
  --bg-elev:   #111827;
  --bg-panel:  #1f2937;
  --border:    #374151;
  --border-hi: #4b5563;
  --border-lo: #1f2937;
  --text:      #ffffff;
  --text-2:    #e5e7eb;
  --text-3:    #9ca3af;
  --text-4:    #6b7280;
  --text-5:    #4b5563;
  --accent:    #60a5fa;
  --accent-bg: #2563eb;
  --accent-hi: #3b82f6;
  --accent-lo: rgba(96, 165, 250, 0.12);
  --ok:        #34d399;
  --warn:      #fbbf24;
  --err:       #f87171;
  --font-sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --top-h: 48px;
  --foot-h: 36px;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; background: var(--bg-deep); color: var(--text-2); font-family: var(--font-sans); }
body { font-size: 14px; line-height: 1.5; -webkit-font-smoothing: antialiased; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-hi); }

/* ------- shell ------- */
.shell { display: grid; grid-template-rows: var(--top-h) 1fr; height: 100vh; }
.topbar {
  display: grid; grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 0 16px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(to bottom, var(--bg-elev), var(--bg));
}
.brand {
  display: flex; align-items: center; gap: 8px;
  font-weight: 600; letter-spacing: 0.01em;
  color: var(--text);
}
.brand-glyph {
  width: 22px; height: 22px;
  display: inline-grid; place-items: center;
  background: radial-gradient(circle at 30% 30%, var(--accent-hi), #1e3a8a 75%);
  border-radius: 50%;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.06), 0 0 0 1px var(--border);
}
.brand-glyph svg { width: 14px; height: 14px; }
.topbar-mid {
  display: flex; align-items: center; gap: 10px;
  color: var(--text-2);
  font-weight: 500;
}
.project-title {
  background: transparent; border: 0;
  color: var(--text); font: inherit; font-weight: 500;
  padding: 4px 8px; border-radius: 6px;
  min-width: 240px; text-align: center;
}
.project-title:hover { background: rgba(255,255,255,0.04); }
.project-title:focus { background: rgba(255,255,255,0.04); outline: 1px solid var(--border-hi); }
.topbar-right { display: flex; align-items: center; justify-content: flex-end; gap: 10px; }
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px; border-radius: 6px;
  font-size: 13px; font-weight: 500;
  border: 1px solid var(--border);
  background: var(--bg-panel); color: var(--text-2);
  cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease;
}
.btn:hover { background: var(--bg-elev); border-color: var(--border-hi); }
.btn-primary { background: var(--accent-bg); border-color: var(--accent-hi); color: white; }
.btn-primary:hover { background: var(--accent-hi); }
.btn svg { width: 14px; height: 14px; }
.avatar {
  width: 28px; height: 28px; border-radius: 50%;
  background: linear-gradient(135deg, #4b5563, #1f2937);
  border: 1px solid var(--border);
  display: grid; place-items: center;
  font-size: 12px; font-weight: 600; color: var(--text-2);
}

/* ------- main two-pane ------- */
.main { display: grid; grid-template-columns: 40% 60%; min-height: 0; }
.chat-pane {
  display: grid; grid-template-rows: 1fr auto;
  border-right: 1px solid var(--border);
  background: var(--bg);
  min-height: 0;
}
.preview-pane {
  display: grid; grid-template-rows: 1fr var(--foot-h);
  background: var(--bg-deep);
  min-height: 0;
}

/* ------- chat list ------- */
.chat-list { overflow-y: auto; padding: 16px 18px 20px; display: flex; flex-direction: column; gap: 16px; }
.msg { display: flex; flex-direction: column; gap: 6px; }
.msg-role {
  font-size: 11px; font-weight: 600;
  letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--text-4);
}
.msg-role.assistant { color: var(--accent); }
.msg-body {
  color: var(--text-2);
  white-space: pre-wrap; word-wrap: break-word;
}
.msg-body p + p { margin-top: 8px; }
.tool-call {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-elev);
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-3);
  width: fit-content;
}
.tool-call .check { color: var(--ok); }
.tool-call .name { color: var(--text-2); }
.tool-call .arrow { color: var(--text-5); margin-left: 4px; cursor: pointer; }

/* ------- chat input ------- */
.chat-input {
  border-top: 1px solid var(--border);
  padding: 12px 14px 14px;
  background: var(--bg);
}
.chat-input-row {
  display: grid; grid-template-columns: 1fr auto;
  align-items: end;
  gap: 8px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 8px 8px 12px;
  transition: border-color 120ms ease;
}
.chat-input-row:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-lo); }
textarea.prompt {
  background: transparent; border: 0;
  color: var(--text); font: inherit; font-size: 14px;
  resize: none; min-height: 22px; max-height: 180px;
  padding: 4px 0;
  outline: none;
}
textarea.prompt::placeholder { color: var(--text-4); }
.send-btn {
  width: 32px; height: 32px; border-radius: 6px;
  display: grid; place-items: center;
  background: var(--accent-bg); color: white;
  border: 0; cursor: pointer;
  transition: background 120ms ease;
}
.send-btn:hover { background: var(--accent-hi); }
.send-btn svg { width: 16px; height: 16px; }
.chat-hint {
  margin-top: 8px;
  font-size: 11px; color: var(--text-4);
  display: flex; gap: 12px; align-items: center;
}
.chat-hint kbd {
  font-family: var(--font-mono); font-size: 10px;
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: 3px; padding: 1px 5px; color: var(--text-3);
}

/* ------- preview ------- */
.preview-frame-wrap {
  padding: 18px;
  min-height: 0;
  display: grid;
  place-items: stretch;
}
.preview-frame {
  width: 100%; height: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: white;
  box-shadow: 0 12px 32px rgba(0,0,0,0.55);
  overflow: hidden;
}
.preview-frame iframe { width: 100%; height: 100%; border: 0; display: block; }
.preview-foot {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 18px 12px;
  gap: 12px;
  color: var(--text-4); font-size: 12px;
}
.share-url {
  font-family: var(--font-mono); font-size: 12px;
  color: var(--text-3);
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 10px;
  flex: 1 1 auto;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.preview-status {
  display: flex; align-items: center; gap: 6px;
  flex: 0 0 auto;
}
.status-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 8px rgba(52, 211, 153, 0.7);
}

/* ------- toast ------- */
.toast {
  position: fixed; right: 24px; bottom: 24px;
  background: var(--bg-panel); border: 1px solid var(--border);
  border-radius: 8px; padding: 10px 14px;
  color: var(--text); font-size: 13px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
  display: none;
}
.toast.show { display: flex; align-items: center; gap: 8px; }
.toast .check { color: var(--ok); }
