/* Forge Studio — design system
   Surface: Operate/Monitor console. Warm-neutral dark, molten amber accent,
   density over decoration. No gradients, no glass, no indigo slop. */

:root {
  --bg: #0a0b0d;
  --surface: #121417;
  --surface-2: #1a1d22;
  --surface-3: #22262d;
  --border: #26292f;
  --border-strong: #33373f;
  --text: #e8eaed;
  --muted: #9aa3ad;
  --faint: #6b7280;
  --accent: #f5a524;
  --accent-soft: rgba(245, 165, 36, 0.12);
  --accent-ink: #1a1206;
  --green: #34d399;
  --green-soft: rgba(52, 211, 153, 0.12);
  --red: #f87171;
  --red-soft: rgba(248, 113, 113, 0.12);
  --blue: #38bdf8;
  --radius: 10px;
  --radius-sm: 7px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", Menlo, Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
button { font-family: inherit; cursor: pointer; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #2c3037; border-radius: 6px; border: 2px solid var(--bg); }
::-webkit-scrollbar-track { background: transparent; }

#app { display: flex; flex-direction: column; height: 100vh; }
.body { display: grid; grid-template-columns: 232px minmax(0, 1fr) minmax(400px, 44%); flex: 1; min-height: 0; }

/* ---------------------------------------------------------------- topbar */

.topbar {
  display: flex; align-items: center; gap: 18px;
  height: 54px; padding: 0 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 150px; }
.brand-mark {
  width: 26px; height: 26px; border-radius: 7px;
  background: var(--accent); color: var(--accent-ink);
  font-family: var(--mono); font-weight: 700; font-size: 15px;
  display: grid; place-items: center;
}
.brand-name { font-weight: 650; letter-spacing: -0.01em; font-size: 15px; white-space: nowrap; }
.brand-name em { font-style: normal; color: var(--muted); font-weight: 500; }

.mode-switch {
  display: flex; gap: 2px; padding: 3px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 9px;
}
.mode-switch button {
  border: 0; background: transparent; color: var(--muted);
  font-size: 12.5px; font-weight: 550; padding: 5px 12px; border-radius: 6px;
}
.mode-switch button:hover { color: var(--text); }
.mode-switch button.active { background: var(--surface-3); color: var(--text); }

.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
select {
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  font-size: 12.5px; padding: 6px 8px; max-width: 210px;
}
.status-pill {
  display: flex; align-items: center; gap: 7px;
  font-size: 12px; font-weight: 600; color: var(--muted);
  background: var(--surface-2); border: 1px solid var(--border);
  padding: 5px 11px; border-radius: 999px; white-space: nowrap;
}
.status-pill .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--faint); }
.status-pill.planning, .status-pill.building, .status-pill.assembling { color: var(--accent); }
.status-pill.planning .dot, .status-pill.building .dot, .status-pill.assembling .dot {
  background: var(--accent); animation: blink 1.2s ease-in-out infinite;
}
.status-pill.live { color: var(--green); }
.status-pill.live .dot { background: var(--green); box-shadow: 0 0 8px rgba(52, 211, 153, 0.6); }
.status-pill.error { color: var(--red); }
.status-pill.error .dot { background: var(--red); }
@keyframes blink { 50% { opacity: 0.35; } }

.btn {
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  font-size: 12.5px; font-weight: 600; padding: 7px 13px; border-radius: 8px;
}
.btn:hover { background: var(--surface-3); border-color: var(--border-strong); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: #ffb83d; }
.btn.danger { background: var(--red-soft); border-color: rgba(248, 113, 113, 0.4); color: var(--red); }
.btn.ghost { background: transparent; }
.btn.small { padding: 4px 9px; font-size: 11.5px; }

/* ---------------------------------------------------------------- sidebar */

.sidebar {
  background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; min-height: 0;
}
.sidebar-head {
  padding: 12px 14px 8px; font-size: 10.5px; font-weight: 700;
  letter-spacing: 0.09em; color: var(--faint);
}
.session-list { overflow-y: auto; padding: 0 8px 10px; display: flex; flex-direction: column; gap: 3px; }
.session-item {
  display: flex; align-items: center; gap: 9px; padding: 8px 9px;
  border-radius: 8px; border: 1px solid transparent; text-align: left;
  background: transparent; color: var(--text); width: 100%;
}
.session-item:hover { background: var(--surface-2); }
.session-item.active { background: var(--surface-2); border-color: var(--border-strong); }
.session-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--faint); flex-shrink: 0; }
.session-item[data-status="live"] .session-dot { background: var(--green); }
.session-item[data-status="planning"] .session-dot,
.session-item[data-status="building"] .session-dot,
.session-item[data-status="assembling"] .session-dot { background: var(--accent); animation: blink 1.2s infinite; }
.session-item[data-status="error"] .session-dot { background: var(--red); }
.session-meta { min-width: 0; flex: 1; }
.session-title { font-size: 12.5px; font-weight: 550; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.session-sub { font-size: 10.5px; color: var(--faint); display: flex; gap: 6px; align-items: center; }
.session-mode {
  font-size: 9.5px; font-weight: 700; letter-spacing: 0.04em;
  padding: 1px 5px; border-radius: 4px; background: var(--surface-3); color: var(--muted);
}
.empty-sessions { padding: 18px 12px; color: var(--faint); font-size: 12px; }

/* ---------------------------------------------------------------- timeline */

.chat-pane { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.timeline { flex: 1; overflow-y: auto; padding: 22px 26px 12px; }
.timeline-inner { max-width: 760px; margin: 0 auto; display: flex; flex-direction: column; gap: 14px; }

.stage-head {
  display: flex; align-items: center; gap: 12px; color: var(--faint);
  font-size: 11px; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase;
  margin: 12px 0 2px;
}
.stage-head::before, .stage-head::after {
  content: ""; flex: 1; height: 1px; background: var(--border);
}
.stage-head .stage-icon { font-size: 13px; }

.msg { display: flex; gap: 11px; }
.msg-avatar {
  width: 30px; height: 30px; border-radius: 9px; flex-shrink: 0;
  display: grid; place-items: center; font-size: 12px; font-weight: 700;
  font-family: var(--mono); color: #0a0b0d; margin-top: 2px;
}
.msg-body { min-width: 0; flex: 1; }
.msg-head { display: flex; align-items: baseline; gap: 8px; margin-bottom: 3px; flex-wrap: wrap; }
.msg-name { font-size: 13px; font-weight: 650; }
.msg-role { font-size: 11px; color: var(--muted); }
.msg-section {
  font-size: 10px; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase;
  color: var(--muted); background: var(--surface-2); border: 1px solid var(--border);
  padding: 1px 6px; border-radius: 5px;
}
.msg-text { font-size: 13.5px; color: var(--text); overflow-wrap: break-word; }
.msg-text p { margin: 0 0 7px; }
.msg-text p:last-child { margin-bottom: 0; }
.msg-text ul, .msg-text ol { margin: 4px 0 8px; padding-left: 19px; }
.msg-text li { margin-bottom: 3px; }
.msg-text strong { font-weight: 650; }
.msg-text code {
  font-family: var(--mono); font-size: 12px; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 4px; padding: 1px 5px;
}
.msg-text pre {
  background: #0d0f12; border: 1px solid var(--border); border-radius: 8px;
  padding: 11px 13px; overflow-x: auto; margin: 7px 0;
}
.msg-text pre code { background: none; border: 0; padding: 0; font-size: 12px; line-height: 1.55; }
.msg-text a { color: var(--blue); }
.msg-text h1, .msg-text h2, .msg-text h3 { margin: 9px 0 5px; font-size: 14px; }

.msg.user { flex-direction: row-reverse; }
.msg.user .msg-body { max-width: 82%; }
.msg.user .msg-text {
  background: var(--accent-soft); border: 1px solid rgba(245, 165, 36, 0.28);
  border-radius: 12px 12px 4px 12px; padding: 10px 13px;
}
.msg.user .msg-avatar { background: var(--surface-3); color: var(--text); border: 1px solid var(--border-strong); }
.msg.user .msg-head { justify-content: flex-end; }

.msg.assistant .msg-avatar { background: var(--accent); color: var(--accent-ink); }

details.raw {
  margin-top: 6px; font-size: 11.5px; color: var(--faint);
}
details.raw summary { cursor: pointer; font-weight: 600; }
details.raw summary:hover { color: var(--muted); }
details.raw pre {
  background: #0d0f12; border: 1px solid var(--border); border-radius: 7px;
  padding: 9px 11px; overflow-x: auto; font-family: var(--mono); font-size: 11px;
  max-height: 260px; overflow-y: auto; white-space: pre-wrap; word-break: break-word;
}

.file-row {
  display: flex; flex-wrap: wrap; gap: 6px; align-items: center;
  font-size: 11.5px; color: var(--muted); padding: 2px 0 2px 41px;
}
.file-chip {
  font-family: var(--mono); font-size: 11px; color: var(--text);
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 6px; padding: 2px 7px;
}

.system-note {
  text-align: center; font-size: 12px; color: var(--faint); padding: 3px 0;
}
.error-note { color: var(--red); }

/* CEO card */
.ceo-card {
  border: 1px solid rgba(245, 165, 36, 0.35); border-radius: var(--radius);
  background: linear-gradient(0deg, var(--accent-soft), var(--accent-soft)), var(--surface);
  padding: 13px 15px; margin: 4px 0;
}
.ceo-head { display: flex; align-items: center; gap: 9px; margin-bottom: 9px; }
.ceo-badge {
  font-size: 10px; font-weight: 800; letter-spacing: 0.09em;
  background: var(--accent); color: var(--accent-ink); border-radius: 5px; padding: 2px 7px;
}
.ceo-title { font-size: 13px; font-weight: 650; }
.ceo-stamp {
  margin-left: auto; font-size: 10.5px; font-weight: 800; letter-spacing: 0.07em;
  border-radius: 6px; padding: 3px 9px; text-transform: uppercase;
}
.ceo-stamp.approved { background: var(--green-soft); color: var(--green); border: 1px solid rgba(52, 211, 153, 0.35); }
.ceo-stamp.revise { background: var(--accent-soft); color: var(--accent); border: 1px solid rgba(245, 165, 36, 0.4); }
.ceo-stamp.ship { background: var(--green-soft); color: var(--green); border: 1px solid rgba(52, 211, 153, 0.35); }
.ceo-stamp.hold { background: var(--red-soft); color: var(--red); border: 1px solid rgba(248, 113, 113, 0.35); }
.ceo-app { font-size: 16px; font-weight: 700; letter-spacing: -0.01em; margin-bottom: 2px; }
.ceo-tagline { font-size: 12.5px; color: var(--muted); margin-bottom: 10px; }
.ceo-sections { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
.ceo-section { display: flex; gap: 8px; font-size: 12.5px; align-items: baseline; }
.ceo-section .n { color: var(--accent); font-family: var(--mono); font-size: 11px; flex-shrink: 0; }
.ceo-list { margin: 6px 0 0; padding-left: 18px; font-size: 12.5px; color: var(--muted); }
.ceo-list li { margin-bottom: 2px; }
.ceo-statement { font-size: 13px; margin-top: 9px; padding-top: 9px; border-top: 1px solid var(--border); }

/* welcome / empty states */
.welcome { text-align: center; padding: 70px 20px; color: var(--muted); }
.welcome h2 { color: var(--text); font-size: 21px; letter-spacing: -0.02em; margin: 0 0 8px; }
.welcome p { margin: 0 auto 22px; max-width: 420px; font-size: 13.5px; }
.example-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px; max-width: 640px; margin: 0 auto; text-align: left; }
.example-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 13px 14px; color: var(--text); font-size: 13px; text-align: left;
}
.example-card:hover { border-color: var(--border-strong); background: var(--surface-2); }
.example-card .t { font-weight: 650; margin-bottom: 3px; }
.example-card .d { font-size: 11.5px; color: var(--faint); }

/* ---------------------------------------------------------------- composer */

.composer { border-top: 1px solid var(--border); padding: 11px 16px 12px; background: var(--surface); flex-shrink: 0; }
.composer-row { display: flex; gap: 10px; align-items: flex-end; max-width: 900px; margin: 0 auto; }
.composer textarea {
  flex: 1; resize: none; background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px; padding: 10px 13px;
  font-family: inherit; font-size: 13.5px; line-height: 1.45; max-height: 160px;
}
.composer textarea:focus { outline: none; border-color: var(--accent); }
.composer textarea:disabled { opacity: 0.6; }
.composer-buttons { display: flex; gap: 8px; }
.composer-buttons .btn { padding: 10px 17px; font-size: 13px; }
.composer-hint { max-width: 900px; margin: 7px auto 0; font-size: 11px; color: var(--faint); }
.thinking {
  max-width: 900px; margin: 0 auto 8px; display: flex; align-items: center; gap: 8px;
  font-size: 12px; color: var(--muted);
}
.pulse {
  width: 8px; height: 8px; border-radius: 50%; background: var(--accent);
  animation: blink 1s ease-in-out infinite; flex-shrink: 0;
}

/* ---------------------------------------------------------------- preview */

.preview-pane {
  background: var(--surface); border-left: 1px solid var(--border);
  display: flex; flex-direction: column; min-height: 0; min-width: 0;
}
.preview-tabs {
  display: flex; align-items: center; gap: 6px; padding: 8px 10px;
  border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.tabs-left { display: flex; gap: 3px; }
.tabs-left button {
  border: 0; background: transparent; color: var(--muted); font-size: 12.5px;
  font-weight: 600; padding: 5px 10px; border-radius: 7px;
}
.tabs-left button.active { background: var(--surface-2); color: var(--text); }
.preview-actions { margin-left: auto; display: flex; gap: 4px; }
.preview-actions button {
  border: 1px solid var(--border); background: var(--surface-2); color: var(--muted);
  font-size: 11px; font-weight: 600; padding: 4px 8px; border-radius: 7px;
}
.preview-actions button:hover { color: var(--text); background: var(--surface-3); }

.preview-stage { flex: 1; min-height: 0; display: flex; padding: 14px; overflow: hidden; }
.empty-preview {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  color: var(--faint); text-align: center; gap: 4px;
}
.empty-mark { font-size: 30px; color: var(--border-strong); margin-bottom: 8px; }
.empty-title { font-size: 14px; font-weight: 650; color: var(--muted); }
.empty-sub { font-size: 12px; max-width: 280px; }
.example-chips { display: flex; flex-wrap: wrap; gap: 7px; justify-content: center; margin-top: 16px; }
.example-chip {
  font-size: 11.5px; color: var(--muted); background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 999px; padding: 5px 11px;
}
.example-chip:hover { color: var(--text); border-color: var(--border-strong); }

.browser-frame {
  flex: 1; display: flex; flex-direction: column; border: 1px solid var(--border-strong);
  border-radius: 12px; overflow: hidden; background: #0d0f12; min-width: 0;
}
.browser-bar {
  display: flex; align-items: center; gap: 10px; padding: 8px 12px;
  background: var(--surface-2); border-bottom: 1px solid var(--border);
}
.dots { display: flex; gap: 5px; }
.dots i { width: 9px; height: 9px; border-radius: 50%; background: var(--border-strong); }
.dots i:first-child { background: #3a3f47; }
.url {
  flex: 1; font-family: var(--mono); font-size: 10.5px; color: var(--faint);
  background: var(--surface); border: 1px solid var(--border); border-radius: 6px;
  padding: 3px 9px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.browser-body { flex: 1; min-height: 0; }
.browser-body iframe, .phone-body iframe {
  width: 100%; height: 100%; border: 0; display: block; background: #0d0f12;
}

.phone-frame {
  flex: 1; display: flex; flex-direction: column; align-items: center; min-width: 0;
}
.phone-notch {
  width: 250px; height: 22px; background: #050607;
  border: 1px solid var(--border-strong); border-bottom: 0;
  border-radius: 16px 16px 0 0; position: relative; z-index: 2;
}
.phone-notch::after {
  content: ""; position: absolute; top: 7px; left: 50%; transform: translateX(-50%);
  width: 74px; height: 8px; border-radius: 5px; background: #1c1f24;
}
.phone-body {
  width: min(390px, 100%); height: 100%; min-height: 0;
  border: 1px solid var(--border-strong); border-top: 0;
  border-radius: 0 0 26px 26px; overflow: hidden; background: #0d0f12;
}
.phone-body iframe { border-radius: 0 0 26px 26px; }

.code-view { flex: 1; display: flex; min-height: 0; }
.code-tree {
  width: 185px; flex-shrink: 0; overflow-y: auto; border-right: 1px solid var(--border);
  padding: 8px 6px; background: var(--surface);
}
.tree-group { font-size: 10px; font-weight: 700; letter-spacing: 0.08em; color: var(--faint); padding: 8px 8px 3px; text-transform: uppercase; }
.tree-file {
  display: block; width: 100%; text-align: left; border: 0; background: transparent;
  color: var(--muted); font-family: var(--mono); font-size: 11px; padding: 4px 8px;
  border-radius: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.tree-file:hover { background: var(--surface-2); color: var(--text); }
.tree-file.active { background: var(--surface-3); color: var(--text); }
.code-content { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.code-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 7px 12px; border-bottom: 1px solid var(--border); font-family: var(--mono);
  font-size: 11px; color: var(--muted); flex-shrink: 0;
}
.code-content pre {
  flex: 1; overflow: auto; margin: 0; padding: 13px 15px;
  font-family: var(--mono); font-size: 11.5px; line-height: 1.6; color: var(--text);
}
.code-content code { font-family: inherit; white-space: pre; }

/* ---------------------------------------------------------------- responsive */

#previewToggle { display: none; }
@media (max-width: 1180px) {
  .body { grid-template-columns: 210px minmax(0, 1fr); }
  .preview-pane {
    position: fixed; top: 54px; right: 0; bottom: 0; width: min(560px, 92vw);
    z-index: 40; box-shadow: -14px 0 40px rgba(0, 0, 0, 0.5);
    transform: translateX(105%); transition: transform 0.22s ease;
  }
  .preview-pane.open { transform: translateX(0); }
  #previewToggle { display: inline-block; }
}
@media (max-width: 760px) {
  .body { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .brand-name { display: none; }
  .mode-switch { margin-right: auto; }
  .topbar { gap: 10px; }
}
