/* mikeos-builderapps — self-contained dark UI. No external fonts/CDNs. */
:root {
  --bg:        #0b0d12;
  --bg-2:      #11141b;
  --panel:     #141821;
  --panel-2:   #1a1f2b;
  --border:    #262c3a;
  --border-2:  #333b4d;
  --text:      #e7ecf3;
  --text-dim:  #9aa4b6;
  --text-mute: #6b7488;
  --accent:    #6d8bff;
  --accent-2:  #8a6dff;
  --accent-ink:#0b0d12;
  --good:      #4ade80;
  --danger:    #f87171;
  --radius:    12px;
  --radius-sm: 8px;
  --shadow:    0 8px 30px rgba(0,0,0,.35);
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", "Fira Code", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: radial-gradient(1200px 600px at 15% -10%, #171b28 0%, var(--bg) 55%) fixed;
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
button { font-family: inherit; }
a { color: var(--accent); }

/* ---------- layout ---------- */
#root { height: 100vh; display: flex; flex-direction: column; }

.topbar {
  display: flex; align-items: center; gap: 14px;
  padding: 10px 18px;
  border-bottom: 1px solid var(--border);
  background: rgba(17,20,27,.8);
  backdrop-filter: blur(8px);
  flex: 0 0 auto;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: .2px; }
.brand .logo {
  width: 26px; height: 26px; border-radius: 7px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: grid; place-items: center; color: var(--accent-ink); font-weight: 800; font-size: 15px;
  box-shadow: 0 2px 10px rgba(109,139,255,.4);
}
.brand small { color: var(--text-mute); font-weight: 500; }
.topbar .spacer { flex: 1; }
.who { color: var(--text-dim); font-size: 13px; display: flex; align-items: center; gap: 10px; }
.who .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--good); }

.split { flex: 1; display: grid; grid-template-columns: 380px 1fr; min-height: 0; }

/* ---------- left panel ---------- */
.left {
  border-right: 1px solid var(--border);
  background: var(--bg-2);
  display: flex; flex-direction: column; min-height: 0;
}
.left .scroll { overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 16px; }

/* ---------- left panel as a chat ---------- */
.left.chat { height: 100%; display: flex; flex-direction: column; min-height: 0; }
.chat-thread {
  flex: 1; min-height: 0; overflow-y: auto;
  padding: 18px 16px 8px; display: flex; flex-direction: column; gap: 14px;
  scroll-behavior: smooth;
}

/* message rows */
.msg { display: flex; gap: 10px; max-width: 100%; }
.msg .avatar {
  width: 26px; height: 26px; flex: 0 0 26px; border-radius: 7px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: grid; place-items: center; color: #fff; font-weight: 800; font-size: 13px;
  box-shadow: 0 2px 8px rgba(109,139,255,.35);
}
.msg.assistant { align-self: flex-start; }
.msg.user { align-self: flex-end; justify-content: flex-end; }
.msg .bubble {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 12px; padding: 10px 13px; font-size: 13.5px; line-height: 1.55;
  max-width: 300px; overflow-wrap: anywhere;
}
.msg.assistant .bubble { border-top-left-radius: 4px; }
.msg.user .bubble {
  background: rgba(109,139,255,.14); border-color: rgba(109,139,255,.4);
  color: var(--text); border-top-right-radius: 4px; white-space: pre-wrap;
}
.msg .bubble.error { border-color: var(--danger); background: rgba(248,113,113,.1); }
.msg .bubble p { margin: 0 0 8px; }
.msg .bubble p:last-child { margin-bottom: 0; }
.msg .bubble strong { color: var(--text); font-weight: 700; }
.msg .bubble code {
  font-family: var(--mono); font-size: 12px; background: var(--panel-2);
  border: 1px solid var(--border); border-radius: 5px; padding: 1px 5px;
}
.msg-text { white-space: pre-wrap; }

/* live checklist inside an assistant bubble */
.chat-steps { display: flex; flex-direction: column; gap: 5px; margin-bottom: 4px; }
.chat-steps:last-child { margin-bottom: 0; }
.chat-step { display: flex; align-items: flex-start; gap: 8px; font-size: 13px; }
.chat-step .chk { color: var(--good); font-weight: 700; flex: 0 0 auto; line-height: 1.55; }
.chat-step.done { color: var(--text-dim); }
.chat-step.active { color: var(--text); }
.chat-step .cs-label { min-width: 0; overflow-wrap: anywhere; }
.spin.sm { width: 12px; height: 12px; border-width: 2px; margin-top: 4px; flex: 0 0 12px;
  border-color: rgba(109,139,255,.35); border-top-color: var(--accent); }

/* empty-state intro hero heading */
.intro-hero { font-size: 19px; font-weight: 700; letter-spacing: -.01em; margin: 0 0 8px; color: var(--text); }

/* empty-state intro chips */
.chat-examples { display: flex; flex-direction: column; gap: 7px; margin-top: 10px; }
.chat-chip {
  display: block; width: 100%; text-align: left; cursor: pointer;
  background: var(--panel-2); color: var(--text-dim);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 9px 12px; font: inherit; font-size: 12.5px; line-height: 1.4;
  transition: border-color .15s, color .15s, background .15s;
}
.chat-chip:hover { border-color: var(--accent); color: var(--text); background: #202636; }
.chat-chip:disabled { opacity: .5; cursor: not-allowed; }
.chat-chip:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* composer pinned at the bottom */
.composer {
  flex: 0 0 auto; border-top: 1px solid var(--border);
  padding: 10px 14px 14px; background: var(--bg-2);
  display: flex; flex-direction: column; gap: 8px;
}
.composer-tools { display: flex; align-items: center; gap: 8px; }
.composer-tools .style-lbl { font-size: 11px; font-weight: 700; color: var(--text-mute);
  text-transform: uppercase; letter-spacing: .5px; }
.chat-style { width: auto; flex: 1; max-width: 180px; font-size: 13px; padding: 6px 28px 6px 10px; }
.chat-style:disabled { opacity: .6; }
.composer-row { display: flex; align-items: flex-end; gap: 8px; }
.chat-input {
  flex: 1; min-height: 42px; max-height: 160px; resize: none; overflow-y: auto;
  padding: 11px 12px; line-height: 1.45;
}
.chat-send { flex: 0 0 auto; width: 42px; height: 42px; padding: 0; border-radius: 10px; font-size: 18px; }
.chat-send .spin { width: 16px; height: 16px; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 12px; font-weight: 600; color: var(--text-dim); text-transform: uppercase; letter-spacing: .5px; }

textarea, input[type=text], select {
  width: 100%;
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-family: inherit; font-size: 14px;
  transition: border-color .15s, box-shadow .15s;
}
textarea { resize: vertical; min-height: 108px; line-height: 1.5; }
textarea:focus, input:focus, select:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(109,139,255,.18);
}
select { appearance: none; cursor: pointer;
  background-image: linear-gradient(45deg, transparent 50%, var(--text-mute) 50%),
                    linear-gradient(135deg, var(--text-mute) 50%, transparent 50%);
  background-position: calc(100% - 18px) 17px, calc(100% - 13px) 17px;
  background-size: 5px 5px, 5px 5px; background-repeat: no-repeat;
}
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.btn {
  border: 1px solid var(--border-2);
  background: var(--panel-2);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 9px 14px;
  font-size: 14px; font-weight: 600; cursor: pointer;
  transition: background .15s, border-color .15s, transform .05s, opacity .15s;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.btn:hover { background: #202636; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border-color: transparent; color: #fff;
  box-shadow: 0 4px 16px rgba(109,139,255,.35);
}
.btn.primary:hover { filter: brightness(1.06); background: linear-gradient(135deg, var(--accent), var(--accent-2)); }
.btn.block { width: 100%; padding: 12px; font-size: 15px; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--text-dim); }
.btn.ghost:hover { background: var(--panel); color: var(--text); }
.btn.sm { padding: 6px 10px; font-size: 12.5px; }

.divider { height: 1px; background: var(--border); margin: 2px 0; }

.section-title { font-size: 12px; font-weight: 700; color: var(--text-dim); text-transform: uppercase; letter-spacing: .6px; display: flex; align-items: center; gap: 8px; }
.section-title .count { color: var(--text-mute); font-weight: 500; }

/* refine chat */
.refine { display: flex; gap: 8px; }
.refine input { flex: 1; }

/* projects list */
.projects { display: flex; flex-direction: column; gap: 6px; }
.proj {
  border: 1px solid var(--border); background: var(--panel);
  border-radius: var(--radius-sm); padding: 10px 12px; cursor: pointer;
  display: flex; align-items: center; gap: 10px;
  transition: border-color .15s, background .15s;
}
.proj:hover { border-color: var(--border-2); background: var(--panel-2); }
.proj.active { border-color: var(--accent); background: rgba(109,139,255,.08); }
.proj .meta { flex: 1; min-width: 0; }
.proj .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.proj .sub { font-size: 12px; color: var(--text-mute); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.proj .del { color: var(--text-mute); background: none; border: none; cursor: pointer; padding: 4px 6px; border-radius: 6px; font-size: 15px; }
.proj .del:hover { color: var(--danger); background: rgba(248,113,113,.12); }
.empty { color: var(--text-mute); font-size: 13px; padding: 8px 2px; }

/* ---------- right panel ---------- */
.right { display: flex; flex-direction: column; min-height: 0; background: var(--bg); }
.right-head {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 16px; border-bottom: 1px solid var(--border); flex: 0 0 auto;
}
.tabs { display: flex; gap: 4px; background: var(--panel); border-radius: 9px; padding: 3px; }
.tab {
  border: none; background: transparent; color: var(--text-dim);
  padding: 6px 16px; border-radius: 7px; cursor: pointer; font-weight: 600; font-size: 13px;
  transition: background .15s, color .15s;
}
.tab.active { background: var(--panel-2); color: var(--text); box-shadow: 0 1px 4px rgba(0,0,0,.3); }
.right-head .spacer { flex: 1; }
.url-pill {
  font-family: var(--mono); font-size: 12px; color: var(--text-dim);
  background: var(--panel); border: 1px solid var(--border); border-radius: 999px;
  padding: 4px 12px; max-width: 340px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.url-pill a { color: var(--text-dim); text-decoration: none; }
.url-pill a:hover { color: var(--accent); }

.right-body { flex: 1; min-height: 0; position: relative; }

/* preview */
.preview-frame { width: 100%; height: 100%; border: 0; background: #fff; display: block; }

/* page subtabs (multi-page) */
.pagebar {
  display: flex; gap: 6px; padding: 8px 16px; border-bottom: 1px solid var(--border);
  overflow-x: auto; background: var(--bg-2); flex: 0 0 auto;
}
.pagebar::-webkit-scrollbar { height: 6px; }
.pagetab {
  border: 1px solid var(--border); background: var(--panel); color: var(--text-dim);
  padding: 4px 12px; border-radius: 999px; cursor: pointer; font-size: 12.5px; font-family: var(--mono); white-space: nowrap;
}
.pagetab.active { border-color: var(--accent); color: var(--text); background: rgba(109,139,255,.1); }

/* code view */
.code-wrap { position: absolute; inset: 0; overflow: auto; background: #0d1017; }
.code-wrap pre { margin: 0; padding: 18px 20px; font-family: var(--mono); font-size: 13px; line-height: 1.6; tab-size: 2; }
.code-wrap code { white-space: pre; }
/* minimal self-written highlighter tokens */
.tok-tag   { color: #7aa2f7; }
.tok-attr  { color: #bb9af7; }
.tok-str   { color: #9ece6a; }
.tok-cmt   { color: #565f89; font-style: italic; }
.tok-doct  { color: #565f89; }
.tok-punct { color: #89ddff; }

/* placeholder / empty preview */
.placeholder {
  position: absolute; inset: 0; display: grid; place-items: center; text-align: center; padding: 24px;
}
.placeholder .inner { max-width: 420px; color: var(--text-dim); }
.placeholder .big { font-size: 42px; margin-bottom: 8px; opacity: .8; }
.placeholder h2 { color: var(--text); font-weight: 700; margin: 0 0 6px; }

/* ---------- login ---------- */
.login { flex: 1; display: grid; place-items: center; padding: 24px; }
.login .card {
  width: 100%; max-width: 420px; text-align: center;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 18px; padding: 40px 34px; box-shadow: var(--shadow);
}
.login .logo-lg {
  width: 60px; height: 60px; border-radius: 16px; margin: 0 auto 20px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: grid; place-items: center; color: #fff; font-weight: 800; font-size: 30px;
  box-shadow: 0 8px 28px rgba(109,139,255,.45);
}
.login h1 { font-size: 24px; margin: 0 0 6px; }
.login p { color: var(--text-dim); margin: 0 0 26px; }

/* ---------- toast ---------- */
.toasts { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 50; }
.toast {
  background: var(--panel-2); border: 1px solid var(--border-2); color: var(--text);
  padding: 11px 16px; border-radius: 10px; box-shadow: var(--shadow); font-size: 13.5px;
  max-width: 340px; animation: slidein .2s ease;
}
.toast.err { border-color: var(--danger); }
.toast.ok  { border-color: var(--good); }
@keyframes slidein { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- spinner ---------- */
.spin {
  width: 15px; height: 15px; border: 2px solid rgba(255,255,255,.35);
  border-top-color: #fff; border-radius: 50%; animation: rot .7s linear infinite; display: inline-block;
}
@keyframes rot { to { transform: rotate(360deg); } }

.gen-overlay {
  position: absolute; inset: 0; display: grid; place-items: center;
  background: rgba(11,13,18,.72); backdrop-filter: blur(3px); z-index: 5;
}
.gen-overlay .box { text-align: center; color: var(--text-dim); }
.gen-overlay .spin { width: 34px; height: 34px; border-width: 3px; border-top-color: var(--accent); margin: 0 auto 14px; }

/* scrollbars */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #2a3140; border-radius: 6px; border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background: #3a4356; }
::-webkit-scrollbar-track { background: transparent; }

/* ---------- responsive ---------- */
@media (max-width: 860px) {
  .split { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .left { border-right: none; border-bottom: 1px solid var(--border); max-height: 46vh; }
  .url-pill { max-width: 140px; }
}

/* ---------- project switcher (topbar) ---------- */
.proj-switcher { display: flex; align-items: center; gap: 8px; margin-left: 18px; }
.proj-select {
  background: var(--panel); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 7px 10px; font: inherit; font-size: 13px;
  max-width: 260px; cursor: pointer;
}
.proj-select:hover { border-color: var(--border-2); }
.proj-select:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
@media (max-width: 720px) { .proj-select { max-width: 150px; } .proj-switcher { margin-left: 8px; } }

/* ---------- generation progress (middle panel) ---------- */
.gen-progress { padding: 40px 28px; max-width: 560px; margin: 0 auto; }
.gen-title { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 15px; margin-bottom: 20px; }
.gen-steps { display: flex; flex-direction: column; gap: 2px; }
.gen-step { display: flex; align-items: center; gap: 12px; padding: 9px 12px; border-radius: var(--radius-sm); font-size: 14px; }
.gen-step .gs-dot {
  width: 18px; height: 18px; flex: 0 0 18px; border-radius: 50%;
  display: grid; place-items: center; font-size: 11px; font-weight: 700;
  border: 1px solid var(--border-2); color: var(--accent-ink);
}
.gen-step.done { color: var(--text-dim); }
.gen-step.done .gs-dot { background: var(--good); border-color: var(--good); color: #04120a; }
.gen-step.active { background: var(--panel); color: var(--text); }
.gen-step.active .gs-dot { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(109,139,255,.18); position: relative; }
.gen-step.active .gs-dot::after {
  content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--accent);
  animation: gs-pulse 1s ease-in-out infinite;
}
@keyframes gs-pulse { 0%,100% { opacity: .35; transform: scale(.8); } 50% { opacity: 1; transform: scale(1); } }
@media (prefers-reduced-motion: reduce) { .gen-step.active .gs-dot::after { animation: none; } }

/* ---------- interactive toggle (switch) ---------- */
.switch { display: flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch .track {
  width: 38px; height: 22px; border-radius: 999px; background: var(--panel-2);
  border: 1px solid var(--border-2); position: relative; transition: background .15s, border-color .15s; flex: 0 0 auto;
}
.switch .knob {
  position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%;
  background: var(--text-dim); transition: transform .15s, background .15s;
}
.switch input:checked + .track { background: rgba(109,139,255,.3); border-color: var(--accent); }
.switch input:checked + .track .knob { transform: translateX(16px); background: var(--accent); }
.switch input:focus-visible + .track { box-shadow: 0 0 0 3px rgba(109,139,255,.18); }
.switch .switch-label { font-size: 13px; font-weight: 600; color: var(--text-dim); }

/* ---------- refine + restyle ---------- */
.refine-hint { font-size: 12px; color: var(--text-mute); line-height: 1.4; }
.restyle { margin-top: 2px; }
.restyle-select { width: 100%; font-size: 13px; }

/* ---------- brief panel ---------- */
.brief { border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--panel); overflow: hidden; }
.brief-head {
  width: 100%; text-align: left; background: transparent; border: 0; color: var(--text);
  padding: 11px 12px; cursor: pointer; font: inherit; font-weight: 700; font-size: 13px;
  display: flex; align-items: baseline; gap: 8px;
}
.brief-head:hover { background: var(--panel-2); }
.brief-sub { color: var(--text-mute); font-weight: 500; font-size: 12px; }
.brief-body { padding: 4px 12px 14px; display: flex; flex-direction: column; gap: 10px; border-top: 1px solid var(--border); }
.brief-body .field label { font-size: 11px; }
.brief-sections { min-height: 84px; font-family: var(--mono); font-size: 12.5px; }
.brief-actions { display: flex; justify-content: flex-end; }

/* ---------- project cards (thumbnails) ---------- */
.projects.cards { gap: 8px; }
.proj.card { align-items: stretch; padding: 8px; gap: 10px; }
.proj.card .thumb {
  width: 76px; height: 50px; flex: 0 0 76px; border-radius: 6px; object-fit: cover;
  background: var(--panel-2); border: 1px solid var(--border);
}
.proj.card .thumb-ph { display: grid; place-items: center; color: var(--text-mute); font-size: 20px; }
.proj.card .meta { display: flex; flex-direction: column; justify-content: center; }

/* ---------- select-mode (click-to-edit) ---------- */
.btn.on { border-color: var(--accent); color: var(--text); background: rgba(109,139,255,.14); }
.select-pop {
  position: fixed; z-index: 60; bottom: 24px; left: 50%; transform: translateX(-50%);
  width: min(460px, 92vw); background: var(--panel-2); border: 1px solid var(--border-2);
  border-radius: 12px; box-shadow: var(--shadow); padding: 12px 14px;
}
.select-pop .sp-head { display: flex; align-items: center; justify-content: space-between; font-weight: 700; font-size: 13px; margin-bottom: 6px; }
.select-pop .sp-x { background: none; border: 0; color: var(--text-mute); font-size: 18px; cursor: pointer; line-height: 1; }
.select-pop .sp-x:hover { color: var(--danger); }
.select-pop .sp-sel { font-family: var(--mono); font-size: 11.5px; color: var(--text-mute);
  background: var(--panel); border: 1px solid var(--border); border-radius: 6px; padding: 5px 8px;
  margin-bottom: 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.select-pop .sp-row { display: flex; gap: 8px; }
.select-pop .sp-row input { flex: 1; }

/* ---------- version history ---------- */
.history { position: relative; }
.history .block-left { }
.history-body {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 40;
  width: 300px; max-height: 320px; overflow-y: auto;
  background: var(--panel-2); border: 1px solid var(--border-2); border-radius: 10px;
  box-shadow: var(--shadow); padding: 6px;
}
.ver { display: flex; align-items: center; gap: 8px; padding: 8px; border-radius: 8px; }
.ver:hover { background: var(--panel); }
.ver-meta { flex: 1; min-width: 0; }
.ver-note { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ver-when { font-size: 11.5px; color: var(--text-mute); }

/* ---------- live streaming view (middle: the preview builds up) ---------- */
.live-view { position: absolute; inset: 0; display: flex; flex-direction: column; min-height: 0; }
.live-preview { flex: 1; min-height: 0; position: relative; background: #fff; }
.live-frame { position: absolute; inset: 0; }

/* ---------- restyle control (preview toolbar) ---------- */
.right-head .restyle { margin: 0; }
.right-head .restyle-select { width: auto; max-width: 170px; font-size: 12.5px; padding: 6px 26px 6px 10px; }

/* ---------- builderapps: right-panel title + status pill ---------- */
.right-title { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 14px; min-width: 0; }
.right-title > span:first-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 260px; }
.status-pill {
  font-size: 11px; font-weight: 700; letter-spacing: .3px; text-transform: uppercase;
  padding: 3px 9px; border-radius: 999px; border: 1px solid var(--border-2);
  color: var(--text-dim); background: var(--panel-2); white-space: nowrap; flex: 0 0 auto;
}
.status-pill.s-creating,
.status-pill.s-building,
.status-pill.s-deploying {
  color: #ffd9a0; border-color: rgba(245,180,90,.5); background: rgba(245,180,90,.12);
}
.status-pill.s-live { color: #b6f5c9; border-color: rgba(74,222,128,.5); background: rgba(74,222,128,.12); }
.status-pill.s-failed { color: #ffc2c2; border-color: rgba(248,113,113,.6); background: rgba(248,113,113,.14); }
.status-pill.s-stopped { color: var(--text-mute); }

/* builderapps: an <a> styled as a button (Open ↗) */
a.btn { text-decoration: none; }

/* builderapps: composer hint line above the input */
.composer-hint { font-size: 11.5px; color: var(--text-mute); line-height: 1.4; }

/* right-head can wrap on narrow screens without clipping the buttons */
.right-head { flex-wrap: wrap; row-gap: 6px; }

/* ============================================================
   builderapps app-shell: persistent left rail + main area
   ============================================================ */
.shell { flex: 1; display: grid; grid-template-columns: 232px 1fr; min-height: 0; }

.rail {
  border-right: 1px solid var(--border); background: var(--bg-2);
  display: flex; flex-direction: column; gap: 10px; padding: 14px 12px; min-height: 0;
}
.rail-brand { display: flex; align-items: center; gap: 9px; font-weight: 700; cursor: pointer;
  padding: 4px 6px; border-radius: 8px; }
.rail-brand:hover { background: var(--panel); }
.rail-new { width: 100%; margin: 4px 0 6px; gap: 6px; }
.rail-nav { display: flex; flex-direction: column; gap: 3px; }
.rail-item {
  display: flex; align-items: center; gap: 11px; width: 100%; text-align: left;
  background: transparent; border: 1px solid transparent; color: var(--text-dim);
  border-radius: 9px; padding: 9px 11px; font: inherit; font-size: 14px; font-weight: 600; cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
}
.rail-item:hover { background: var(--panel); color: var(--text); }
.rail-item.active { background: rgba(109,139,255,.12); border-color: rgba(109,139,255,.35); color: var(--text); }
.rail-ico { width: 18px; text-align: center; font-size: 15px; flex: 0 0 18px; }
.rail-spacer { flex: 1; }
.rail-account { border-top: 1px solid var(--border); padding-top: 10px; display: flex; flex-direction: column; gap: 8px; }
.rail-acct-row { display: flex; align-items: center; gap: 9px; min-width: 0; }
.rail-avatar { width: 30px; height: 30px; flex: 0 0 30px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff;
  display: grid; place-items: center; font-weight: 700; font-size: 14px; }
.rail-acct-meta { min-width: 0; }
.rail-acct-name { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rail-acct-mail { font-size: 11.5px; color: var(--text-mute); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.btn.block { width: 100%; }

.main { min-width: 0; min-height: 0; overflow-y: auto; padding: 30px 34px 48px; }
.main-entry { display: grid; place-items: center; padding: 24px; }

/* ----- entry (hero + prompt + chips) ----- */
.entry-card { width: 100%; max-width: 680px; text-align: center; }
.entry-hero { font-size: clamp(26px, 4.2vw, 40px); font-weight: 800; letter-spacing: -.02em; margin: 0 0 12px; }
.entry-sub { color: var(--text-dim); font-size: 15px; margin: 0 0 26px; }
.entry-composer {
  background: var(--panel); border: 1px solid var(--border-2); border-radius: 16px;
  padding: 14px; box-shadow: var(--shadow); text-align: left;
}
.entry-input {
  width: 100%; border: 0; background: transparent; resize: none; min-height: 68px; max-height: 220px;
  font-size: 15.5px; line-height: 1.5; padding: 4px 4px 0; color: var(--text);
}
.entry-input:focus { outline: none; box-shadow: none; }
.entry-actions { display: flex; justify-content: flex-end; margin-top: 8px; }
.entry-send { padding: 9px 18px; }
.entry-examples { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 22px; }
.entry-chip {
  cursor: pointer; background: var(--panel-2); color: var(--text-dim);
  border: 1px solid var(--border); border-radius: 999px; padding: 8px 14px;
  font: inherit; font-size: 12.5px; line-height: 1.3; max-width: 320px; text-align: left;
  transition: border-color .15s, color .15s, background .15s;
}
.entry-chip:hover { border-color: var(--accent); color: var(--text); background: #202636; }
.entry-chip:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ----- shared view scaffolding (apps/settings/profile/subscription) ----- */
.view-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 0 0 20px; }
.view-head h1 { font-size: 22px; font-weight: 800; letter-spacing: -.01em; margin: 0; }
.card-panel { background: var(--panel); border: 1px solid var(--border); border-radius: 14px; overflow: hidden; }
.muted-note { color: var(--text-mute); font-size: 12.5px; margin: 14px 2px 0; }

/* ----- Apps list ----- */
.app-list { display: flex; flex-direction: column; gap: 10px; max-width: 820px; }
.app-card {
  display: flex; align-items: center; gap: 14px; justify-content: space-between;
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  padding: 14px 16px; cursor: pointer; transition: border-color .15s, background .15s;
}
.app-card:hover { border-color: var(--border-2); background: var(--panel-2); }
.app-card-main { min-width: 0; }
.app-card-title { font-weight: 700; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.app-card-sub { font-size: 12.5px; margin-top: 3px; }
.app-card-sub a { font-family: var(--mono); color: var(--text-dim); text-decoration: none; }
.app-card-sub a:hover { color: var(--accent); }
.app-card-side { display: flex; align-items: center; gap: 12px; flex: 0 0 auto; }
.app-card-when { font-size: 12px; color: var(--text-mute); white-space: nowrap; }

/* ----- Settings ----- */
.set-row { display: flex; align-items: center; justify-content: space-between; gap: 20px;
  padding: 16px 18px; border-bottom: 1px solid var(--border); }
.set-row:last-child { border-bottom: 0; }
.set-label { font-weight: 600; font-size: 14px; }
.set-hint { color: var(--text-mute); font-size: 12.5px; margin-top: 3px; }
.set-select { width: auto; min-width: 120px; }

/* ----- Profile ----- */
.profile-panel { padding: 22px; }
.profile-top { display: flex; align-items: center; gap: 16px; margin-bottom: 18px; }
.profile-avatar, .profile-avatar-img { width: 56px; height: 56px; border-radius: 50%; flex: 0 0 56px; }
.profile-avatar { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff;
  display: grid; place-items: center; font-weight: 800; font-size: 24px; }
.profile-avatar-img { object-fit: cover; border: 1px solid var(--border); }
.profile-name { font-size: 18px; font-weight: 700; }
.profile-mail { color: var(--text-dim); font-size: 13.5px; margin-top: 2px; }
.pf-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 22px; margin-bottom: 18px; }
.pf-label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; color: var(--text-mute); }
.pf-value { font-size: 14px; margin-top: 3px; overflow-wrap: anywhere; }
@media (max-width: 640px) { .pf-fields { grid-template-columns: 1fr; } }

/* ----- Subscription ----- */
.plan-panel { padding: 20px 22px; }
.plan-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.plan-name { font-size: 17px; font-weight: 800; }
.plan-desc { color: var(--text-dim); font-size: 13px; margin-top: 3px; }
.plan-feats { margin: 16px 0 0; padding-left: 18px; color: var(--text-dim); font-size: 13.5px; line-height: 1.8; }
.plan-soon { margin-top: 16px; background: var(--panel-2); border: 1px dashed var(--border-2);
  border-radius: 12px; padding: 14px 16px; font-size: 13.5px; color: var(--text-dim); }
.plan-soon strong { color: var(--text); }

@media (max-width: 760px) {
  .shell { grid-template-columns: 64px 1fr; }
  .rail-lbl, .rail-acct-meta, .rail-brand span, .rail-new span:last-child { display: none; }
  .rail-new { justify-content: center; }
  .main { padding: 20px 16px 40px; }
}

/* ============================================================
   Light theme (Settings -> Theme: Light)
   ============================================================ */
:root[data-theme="light"] {
  --bg: #f7f8fb; --bg-2: #ffffff; --panel: #ffffff;
  --panel-2: #eef1f7; --border: #e2e6ef; --border-2: #d3d9e6;
  --text: #10151f; --text-dim: #4b5568; --text-mute: #7b8598;
  --accent-ink: #ffffff; --shadow: 0 8px 30px rgba(20,30,60,.12);
}
:root[data-theme="light"] body {
  background: radial-gradient(1200px 600px at 15% -10%, #eef1ff 0%, var(--bg) 55%) fixed;
}
:root[data-theme="light"] .entry-chip:hover { background: #eef1fb; }
:root[data-theme="light"] .code-wrap, :root[data-theme="light"] .code-wrap pre { background: #f4f6fb; }

/* =========================================================================
   Builder workspace tabs (right panel) — Site / Goals / Code / Database /
   Secrets / Logs, plus the openable extras from the "+" menu.
   Self-contained: no CDN, no external fonts, matches the dark aesthetic.
   ========================================================================= */

/* ---- tab bar ---- */
.wtabs {
  display: flex; align-items: center; gap: 4px; flex: 0 0 auto;
  padding: 7px 12px; border-bottom: 1px solid var(--border);
  background: var(--bg-2); overflow-x: auto; overflow-y: visible;
  scrollbar-width: thin;
}
.wtabs::-webkit-scrollbar { height: 6px; }
.wtabs::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 3px; }
.wtab {
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
  border: 1px solid transparent; background: transparent; color: var(--text-dim);
  padding: 5px 12px; border-radius: 8px; cursor: pointer;
  font-size: 12.5px; font-weight: 600; font-family: var(--sans);
  transition: background .14s, color .14s, border-color .14s;
}
.wtab:hover { color: var(--text); background: var(--panel); }
.wtab.active {
  color: var(--text); background: var(--panel-2); border-color: var(--border-2);
  box-shadow: 0 1px 4px rgba(0,0,0,.3);
}
.wtab:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.wtab-x {
  color: var(--text-mute); font-size: 14px; line-height: 1; padding: 0 1px;
  border-radius: 4px;
}
.wtab-x:hover { color: var(--danger); background: rgba(248,113,113,.14); }
.wtab.plus { font-size: 14px; padding: 5px 10px; }

.wtab-plus-wrap { position: relative; flex: 0 0 auto; }
.wtab-menu {
  position: absolute; top: calc(100% + 6px); right: 0; z-index: 40;
  min-width: 190px; padding: 5px;
  background: var(--panel); border: 1px solid var(--border-2);
  border-radius: var(--radius); box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 1px;
}
.wtab-menu-item {
  text-align: left; border: none; background: transparent; color: var(--text-dim);
  padding: 7px 10px; border-radius: 7px; cursor: pointer; font-size: 13px; font-family: var(--sans);
}
.wtab-menu-item:hover { background: var(--panel-2); color: var(--text); }
.wtab-menu-empty { padding: 8px 10px; font-size: 12.5px; color: var(--text-mute); }

/* ---- tab body scaffolding ---- */
.tab-root { position: absolute; inset: 0; display: flex; flex-direction: column; min-height: 0; }
.tab-pane {
  flex: 1; min-height: 0; overflow: auto; padding: 16px 18px 22px;
  display: flex; flex-direction: column; gap: 14px;
}
.tab-toolbar {
  position: sticky; top: -16px; z-index: 5; margin: -16px -18px 0; padding: 10px 18px;
  display: flex; align-items: center; gap: 10px;
  background: var(--bg); border-bottom: 1px solid var(--border);
}
.tab-toolbar .spacer { flex: 1; }
.tt-note { font-size: 12.5px; color: var(--text-mute); }
.tt-check { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--text-dim); cursor: pointer; }

.tab-empty {
  flex: 1; min-height: 200px; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 10px; padding: 30px; text-align: center;
}
.te-mark {
  width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center;
  border: 1px solid var(--border-2); color: var(--text-mute); font-size: 17px;
}
.te-mark.bad { color: var(--danger); border-color: rgba(248,113,113,.5); }
.te-text { color: var(--text-dim); font-size: 13.5px; max-width: 400px; line-height: 1.6; }

/* ---- two-pane tabs (Goals, Code): a list on the left, the document on the right ---- */
.split-pane { flex: 1; min-height: 0; display: grid; grid-template-columns: 232px 1fr; }
.doc-list {
  overflow: auto; border-right: 1px solid var(--border); background: var(--bg-2);
  padding: 8px; display: flex; flex-direction: column; gap: 2px;
}
.doc-item {
  text-align: left; border: 1px solid transparent; background: transparent;
  color: var(--text-dim); padding: 7px 9px; border-radius: 8px; cursor: pointer;
  font-family: var(--sans); display: block; width: 100%;
}
.doc-item:hover { background: var(--panel); color: var(--text); }
.doc-item.active { background: rgba(109,139,255,.1); border-color: var(--accent); color: var(--text); }
.doc-title { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-meta { font-size: 11px; color: var(--text-mute); font-family: var(--mono); margin-top: 2px; }
.tree-crumb {
  font-family: var(--mono); font-size: 11.5px; color: var(--text-mute);
  padding: 4px 9px 8px; border-bottom: 1px solid var(--border); margin-bottom: 6px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.pane-body { overflow: auto; min-height: 0; display: flex; flex-direction: column; position: relative; }
.md-scroll { background: var(--bg); }

/* ---- the Markdown renderer's output (Goals) ---- */
.md { padding: 22px 28px 40px; max-width: 780px; color: var(--text-dim); line-height: 1.68; font-size: 14px; }
.md h1, .md h2, .md h3, .md h4, .md h5, .md h6 {
  color: var(--text); font-weight: 700; letter-spacing: -.01em; line-height: 1.3;
  margin: 26px 0 10px;
}
.md > h1:first-child, .md > h2:first-child { margin-top: 0; }
.md h1 { font-size: 23px; padding-bottom: 8px; border-bottom: 1px solid var(--border); }
.md h2 { font-size: 18px; }
.md h3 { font-size: 15.5px; }
.md h4, .md h5, .md h6 { font-size: 14px; color: var(--text-dim); }
.md p { margin: 0 0 12px; }
.md ul, .md ol { margin: 0 0 12px; padding-left: 22px; }
.md li { margin: 4px 0; }
.md strong { color: var(--text); font-weight: 700; }
.md em { color: var(--text); font-style: italic; }
.md a { color: var(--accent); text-decoration: none; }
.md a:hover { text-decoration: underline; }
.md code {
  font-family: var(--mono); font-size: 12.5px; background: var(--panel-2);
  border: 1px solid var(--border); border-radius: 5px; padding: 1px 5px; color: #cbd5f5;
}
.md .md-pre {
  background: #0d1017; border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 14px 16px; overflow-x: auto; margin: 0 0 14px;
}
.md .md-pre code { background: none; border: 0; padding: 0; font-size: 12.5px; line-height: 1.6; color: #cfe0ff; }
.md blockquote {
  margin: 0 0 14px; padding: 6px 14px; border-left: 3px solid var(--accent);
  background: rgba(109,139,255,.06); border-radius: 0 var(--radius-sm) var(--radius-sm) 0; color: var(--text-dim);
}
.md hr { border: 0; border-top: 1px solid var(--border); margin: 22px 0; }
.md .md-tablewrap { overflow-x: auto; margin: 0 0 14px; }
.md .md-table { border-collapse: collapse; font-size: 13px; min-width: 320px; }
.md .md-table th, .md .md-table td { border: 1px solid var(--border); padding: 7px 12px; text-align: left; }
.md .md-table th { background: var(--panel); color: var(--text); font-weight: 700; }

/* ---- Code viewer ---- */
.filepane { display: flex; flex-direction: column; min-height: 0; flex: 1; }
.file-head {
  display: flex; align-items: center; gap: 10px; flex: 0 0 auto;
  padding: 9px 16px; border-bottom: 1px solid var(--border); background: var(--bg-2);
}
.file-path { font-family: var(--mono); font-size: 12.5px; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-size { font-size: 11.5px; color: var(--text-mute); margin-left: auto; flex: 0 0 auto; }
.notice {
  margin: 0; padding: 8px 16px; font-size: 12.5px; color: #ffe0a3;
  background: rgba(255,193,94,.1); border-bottom: 1px solid rgba(255,193,94,.28);
}
.file-body {
  margin: 0; padding: 16px 18px 30px; overflow: auto; flex: 1; min-height: 0;
  background: #0d1017; font-family: var(--mono); font-size: 12.5px; line-height: 1.65;
  color: #cfe0ff; tab-size: 2; white-space: pre;
}

/* ---- data tables (Database, Commits, Deployments, QA, Metrics) ---- */
.dtable-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius-sm); }
.dtable { width: 100%; border-collapse: collapse; font-size: 12.8px; }
.dtable th, .dtable td { padding: 8px 12px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
.dtable th {
  background: var(--panel); color: var(--text-dim); font-weight: 700; font-size: 11px;
  text-transform: uppercase; letter-spacing: .5px; white-space: nowrap; position: sticky; top: 0;
}
.dtable tbody tr:last-child td { border-bottom: 0; }
.dtable tbody tr:hover { background: var(--panel); }
.dtable td { color: var(--text-dim); }
.dtable a { color: var(--accent); text-decoration: none; }
.dtable a:hover { text-decoration: underline; }

/* ---- card blocks (Database sections, Danger Zone) ---- */
.card-block {
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--panel); padding: 14px 16px 16px;
}
.cb-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.cb-title { font-size: 14px; font-weight: 700; color: var(--text); }
.cb-title.bad { color: var(--danger); }
.cb-badge {
  font-size: 11px; color: var(--text-mute); border: 1px solid var(--border-2);
  border-radius: 999px; padding: 2px 9px;
}
.cb-note { margin: 0 0 12px; font-size: 12.8px; color: var(--text-mute); line-height: 1.6; }

/* ---- key/value lists (Secrets, Env, Routes, Cache, Backlog, Domain) ---- */
.kv-list {
  border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden;
  display: flex; flex-direction: column;
}
.kv-row {
  display: flex; align-items: center; gap: 12px; padding: 9px 12px;
  border-bottom: 1px solid var(--border); font-size: 13px;
}
.kv-row:last-child { border-bottom: 0; }
.kv-row:hover { background: var(--panel); }
.kv-key { flex: 0 0 210px; color: var(--text); font-weight: 600; word-break: break-all; }
.kv-val { flex: 1; color: var(--text-dim); word-break: break-all; min-width: 0; }
.mono { font-family: var(--mono); font-size: 12.4px; }

/* ---- Logs ---- */
.logbox {
  margin: 0; flex: 1 0 auto; padding: 14px 16px;
  background: #0d1017; border: 1px solid var(--border); border-radius: var(--radius-sm);
  font-family: var(--mono); font-size: 12.2px; line-height: 1.6; color: #cfe0ff;
  white-space: pre-wrap; word-break: break-word;
}

/* ---- Backlog ---- */
.backlog-row { align-items: center; }
.bl-idx { flex: 0 0 34px; color: var(--text-mute); }
.bl-title { flex: 1; color: var(--text-dim); min-width: 0; }
.bl-status {
  flex: 0 0 auto; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px;
  border: 1px solid var(--border-2); border-radius: 999px; padding: 2px 10px; color: var(--text-mute);
}
.bl-status.s-done { color: #b6f5c9; border-color: rgba(74,222,128,.5); background: rgba(74,222,128,.12); }
.bl-status.s-doing, .bl-status.s-running { color: #cbd5f5; border-color: rgba(109,139,255,.5); background: rgba(109,139,255,.12); }
.bl-status.s-failed { color: #ffc2c2; border-color: rgba(248,113,113,.6); background: rgba(248,113,113,.14); }

/* ---- API routes ---- */
.method {
  flex: 0 0 66px; text-align: center; font-family: var(--mono); font-size: 11px; font-weight: 700;
  border: 1px solid var(--border-2); border-radius: 6px; padding: 3px 0; color: var(--text-dim);
}
.method.m-get { color: #b6f5c9; border-color: rgba(74,222,128,.45); }
.method.m-post { color: #cbd5f5; border-color: rgba(109,139,255,.5); }
.method.m-put, .method.m-patch { color: #ffe0a3; border-color: rgba(255,193,94,.45); }
.method.m-delete { color: #ffc2c2; border-color: rgba(248,113,113,.5); }

/* ---- Cache stats ---- */
.stat-row { display: flex; gap: 12px; flex-wrap: wrap; }
.stat {
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--panel);
  padding: 12px 18px; min-width: 140px;
}
.stat-n { font-size: 20px; font-weight: 700; color: var(--text); font-family: var(--mono); }
.stat-l { font-size: 11.5px; color: var(--text-mute); text-transform: uppercase; letter-spacing: .5px; margin-top: 3px; }

/* ---- Danger Zone ---- */
.danger-block { border-color: rgba(248,113,113,.4); }
.danger-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.danger-input {
  background: var(--panel-2); border: 1px solid var(--border-2); color: var(--text);
  border-radius: var(--radius-sm); padding: 8px 12px; font-family: var(--mono); font-size: 12.5px;
  min-width: 250px;
}
.danger-input:focus { outline: none; border-color: var(--danger); }
.btn.danger { background: rgba(248,113,113,.16); border-color: rgba(248,113,113,.55); color: #ffc2c2; }
.btn.danger:hover:not(:disabled) { background: rgba(248,113,113,.26); }
.btn.danger:disabled { opacity: .45; cursor: not-allowed; }

/* ---- executed-run history bubble (replayed from the server on load) ---- */
.bubble.run-history { border-color: var(--border-2); background: var(--panel-2); }
.run-head { font-size: 12.5px; color: var(--text-dim); margin-bottom: 8px; }
.run-foot { font-size: 12px; color: var(--text-mute); margin-top: 8px; }
.run-foot.bad { color: var(--danger); }
.chat-step.failed { color: #ffc2c2; }
.chat-step .xmk { color: var(--danger); font-weight: 700; flex: 0 0 auto; line-height: 1.55; }
.hydrating { display: flex; align-items: center; gap: 10px; color: var(--text-dim); font-size: 13px; }

@media (max-width: 900px) {
  /* Stacked: the list must never eat the document pane on a short viewport —
     a proportional row keeps the rendered doc / file readable. */
  .split-pane { grid-template-columns: 1fr; grid-template-rows: minmax(84px, 30%) 1fr; }
  .doc-list { border-right: 0; border-bottom: 1px solid var(--border); }
  .kv-key { flex-basis: 130px; }
}
.run-head .run-req { font-style: italic; color: var(--text-mute); }
