:root {
  --bg0: #0c0b0a;
  --bg1: #161311;
  --panel: #12100e;
  --ink: #f2ebe3;
  --muted: #a8998c;
  --ember: #e08a3c;
  --line: rgba(242, 235, 227, 0.12);
  --danger: #e07060;
  --ok: #7dba7a;
  --code-bg: #0e0d0c;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
html {
  color-scheme: dark;
  scrollbar-width: thin;
  scrollbar-color: rgba(168, 153, 140, 0.45) transparent;
}
body {
  color: var(--ink);
  font-family: Outfit, system-ui, sans-serif;
  background: var(--bg0);
  overflow: hidden;
}
*::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
*::-webkit-scrollbar-track {
  background: transparent;
}
*::-webkit-scrollbar-thumb {
  background: rgba(168, 153, 140, 0.35);
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
*::-webkit-scrollbar-thumb:hover {
  background: rgba(224, 138, 60, 0.55);
  border: 2px solid transparent;
  background-clip: padding-box;
}
*::-webkit-scrollbar-corner {
  background: transparent;
}
.shell {
  --chat-w: 360px;
  display: grid;
  grid-template-columns: var(--chat-w) 5px 1fr;
  height: 100vh;
  height: 100dvh;
}
.shell-split {
  position: relative;
  z-index: 4;
  cursor: col-resize;
  background: var(--line);
  touch-action: none;
  outline: none;
}
.shell-split::after {
  content: "";
  position: absolute;
  inset: 0 -4px;
}
.shell-split:hover,
.shell-split:focus-visible,
.shell.resizing .shell-split {
  background: var(--ember);
}
body.shell-resizing {
  cursor: col-resize;
  user-select: none;
}
body.shell-resizing iframe {
  pointer-events: none;
}
.chat {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background:
    radial-gradient(420px 240px at 0% 0%, rgba(224, 138, 60, 0.14), transparent 60%),
    linear-gradient(180deg, var(--bg1), var(--panel));
}
.chat-head {
  padding: 1.15rem 1.2rem 0.85rem;
  border-bottom: 1px solid var(--line);
}
.brand {
  font-family: "Instrument Serif", Georgia, serif;
  font-size: 2.2rem;
  line-height: 0.95;
  margin: 0;
}
.brand span { color: var(--ember); font-style: italic; }
.sub {
  margin: 0.35rem 0 0;
  color: var(--muted);
  font-size: 0.85rem;
}
.messages {
  flex: 1;
  overflow: auto;
  padding: 1rem 1.1rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}
.bubble {
  max-width: 100%;
  padding: 0.75rem 0.9rem;
  border-radius: 10px;
  font-size: 0.92rem;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}
.bubble.user {
  align-self: flex-end;
  background: rgba(224, 138, 60, 0.16);
  border: 1px solid rgba(224, 138, 60, 0.28);
}
.bubble.assistant {
  align-self: flex-start;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--line);
  white-space: normal;
}
.bubble.assistant .agent-who {
  font-weight: 700;
  font-size: 0.95rem;
  letter-spacing: -0.02em;
  margin-bottom: 0.4rem;
}
.bubble.assistant code {
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 0.84em;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 0.05em 0.35em;
}
.trace-bar {
  align-self: stretch;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  font-size: 0.82rem;
}
.trace-bar summary {
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  user-select: none;
}
.trace-bar summary::-webkit-details-marker { display: none; }
.trace-bar summary::after {
  content: "▾";
  margin-left: auto;
  opacity: 0.55;
  font-size: 0.7rem;
}
.trace-bar:not([open]) summary::after { content: "▸"; }
.trace-bar .trace-ico { opacity: 0.8; flex: 0 0 auto; }
.trace-bar ul {
  margin: 0;
  padding: 0 0.75rem 0.55rem 2.1rem;
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 0.74rem;
  line-height: 1.45;
}
.trace-bar li { word-break: break-word; }
.bubble.system {
  align-self: center;
  color: var(--muted);
  font-size: 0.8rem;
  padding: 0.35rem 0.6rem;
  border: 0;
  background: transparent;
}
.preview-shot-note {
  align-self: flex-start;
  max-width: 280px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
}
.preview-shot-note img {
  display: block;
  width: 100%;
  height: auto;
  max-height: 180px;
  object-fit: cover;
  object-position: top;
  background: #0a0908;
}
.preview-shot-note p {
  margin: 0;
  padding: 0.45rem 0.65rem 0.55rem;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.35;
}
.bubble.tool {
  align-self: flex-start;
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 0.75rem;
  color: var(--muted);
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--line);
  padding: 0.45rem 0.65rem;
}
.bubble.tool strong {
  color: var(--ember);
  font-weight: 500;
}
.row {
  display: flex;
  gap: 0.55rem;
  align-items: center;
  flex-wrap: wrap;
}
button, .btn {
  appearance: none;
  border: 0;
  cursor: pointer;
  font: inherit;
  font-weight: 600;
  border-radius: 999px;
  padding: 0.65rem 1.1rem;
}
.btn-primary {
  background: linear-gradient(180deg, #f0a35a, var(--ember));
  color: #1a1008;
}
.btn-primary:disabled { opacity: 0.5; cursor: wait; }
.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
  padding: 0.45rem 0.8rem;
  font-weight: 500;
  font-size: 0.85rem;
}
.btn-ghost.active {
  color: var(--ink);
  border-color: rgba(224, 138, 60, 0.45);
  background: rgba(224, 138, 60, 0.1);
}
.btn-ghost:disabled { opacity: 0.4; cursor: not-allowed; }
.workspace {
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-width: 0;
  min-height: 0;
  background: #090807;
}
.topbar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.45rem 0.75rem;
  border-bottom: 1px solid var(--line);
  background: rgba(18, 16, 14, 0.96);
  min-height: 2.7rem;
}
.tabs { display: flex; gap: 0.35rem; }
.url {
  flex: 1;
  min-width: 0;
  font-size: 0.78rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar a {
  color: var(--ember);
  font-size: 0.78rem;
  text-decoration: none;
  white-space: nowrap;
}
.topbar a[hidden] { display: none; }
.stage {
  min-height: 0;
  position: relative;
  display: flex;
  overflow: hidden;
}
.preview-stage, .code-stage {
  flex: 1;
  min-width: 0;
  min-height: 0;
  position: relative;
}
.preview-stage[hidden], .code-stage[hidden] { display: none !important; }
.placeholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 0.4rem;
  text-align: center;
  color: var(--muted);
  padding: 2rem;
  z-index: 1;
  background: #090807;
}
/* class { display } beats the [hidden] UA rule — must override */
.placeholder[hidden] { display: none !important; }
iframe[hidden] { display: none !important; }
.placeholder strong {
  color: var(--ink);
  font-family: "Instrument Serif", Georgia, serif;
  font-size: 1.6rem;
  font-weight: 400;
}
iframe {
  width: 100%;
  height: 100%;
  border: 0;
  background: #fff;
  display: block;
}
.code-stage {
  display: grid;
  grid-template-columns: 240px 1fr;
  grid-template-rows: auto 1fr;
}
.tree {
  grid-row: 1 / -1;
  border-right: 1px solid var(--line);
  overflow: auto;
  background: var(--code-bg);
  padding: 0.4rem 0;
  font-size: 0.82rem;
}
.tree-item {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  color: var(--muted);
  padding: 0.22rem 0.55rem;
  font: inherit;
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 0.76rem;
  cursor: pointer;
  border-radius: 0;
}
.tree-item:hover { background: rgba(255,255,255,0.04); color: var(--ink); }
.tree-item.active {
  background: rgba(224, 138, 60, 0.12);
  color: var(--ember);
}
.tree-item.dir { color: #c4b5a5; }
.tree-chevron {
  width: 0.9rem;
  flex: 0 0 auto;
  opacity: 0.6;
  font-size: 0.65rem;
}
.editor-bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0.65rem;
  border-bottom: 1px solid var(--line);
  background: rgba(18, 16, 14, 0.9);
  min-height: 2.2rem;
}
.editor-bar .path {
  flex: 1;
  min-width: 0;
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 0.75rem;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.editor-bar .dirty { color: var(--ember); }
.editor-wrap {
  min-height: 0;
  display: flex;
  flex-direction: column;
}
#editor {
  flex: 1;
  min-height: 0;
  width: 100%;
  border: 0;
  resize: none;
  outline: none;
  background: var(--code-bg);
  margin: 0;
  padding: 1rem 1.1rem;
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 0.8rem;
  line-height: 1.5;
  color: #e8dfd4;
  tab-size: 2;
  white-space: pre;
}
#editor:disabled {
  opacity: 0.55;
}
.bottom {
  border-top: 1px solid var(--line);
  background: #0a0908;
  display: flex;
  flex-direction: column;
  height: min(22vh, 180px);
  max-height: min(22vh, 180px);
  min-height: 0;
  flex-shrink: 0;
  z-index: 2;
}
.bottom-tabs {
  display: flex;
  gap: 0.25rem;
  padding: 0.3rem 0.55rem;
  border-bottom: 1px solid var(--line);
  align-items: center;
}
.bottom-tabs .label {
  margin-left: auto;
  font-size: 0.72rem;
  color: var(--muted);
}
.model-select {
  margin-left: auto;
  flex: 0 0 auto;
  width: auto;
  max-width: 16rem;
  font-size: 0.72rem;
  padding: 0.25rem 0.45rem;
  border-radius: 6px;
  color: var(--muted);
  background: rgba(12, 11, 10, 0.75);
}
.model-select:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}
#activity {
  flex: 1;
  overflow: auto;
  margin: 0;
  padding: 0.55rem 0.75rem;
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 0.72rem;
  line-height: 1.45;
  color: #b8aa9c;
  white-space: pre-wrap;
  word-break: break-word;
}
#history {
  flex: 1;
  overflow: auto;
  margin: 0;
  padding: 0.35rem 0.55rem 0.5rem;
}
#history[hidden] { display: none; }
.hist-row {
  display: grid;
  grid-template-columns: 4.4rem 1fr auto;
  gap: 0.45rem;
  align-items: center;
  padding: 0.28rem 0.15rem;
  border-bottom: 1px solid rgba(255,255,255,0.04);
  font-size: 0.72rem;
}
.hist-row .sha { font-family: "IBM Plex Mono", ui-monospace, monospace; color: var(--ember); }
.hist-row .msg { color: #d8cfc4; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hist-row .when { color: var(--muted); font-size: 0.68rem; }
.hist-empty { color: var(--muted); font-size: 0.75rem; padding: 0.5rem; }
.dot {
  display: inline-block;
  width: 0.45rem;
  height: 0.45rem;
  border-radius: 50%;
  background: var(--ember);
  margin-right: 0.35rem;
  animation: pulse 1.4s ease-out infinite;
  vertical-align: middle;
}
.dot.ok { background: var(--ok); animation: none; }
.dot.err { background: var(--danger); animation: none; }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(224, 138, 60, 0.45); }
  70% { box-shadow: 0 0 0 8px rgba(224, 138, 60, 0); }
  100% { box-shadow: 0 0 0 0 rgba(224, 138, 60, 0); }
}
@media (max-width: 900px) {
  body { overflow: auto; }
  .shell {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(38vh, auto) minmax(55vh, 1fr);
    height: auto;
    min-height: 100dvh;
  }
  .shell-split { display: none; }
  .code-stage { grid-template-columns: 140px 1fr; }
  .bottom { max-height: 22vh; }
}
.auth-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-content: center;
  background:
    radial-gradient(600px 320px at 50% 0%, rgba(224, 138, 60, 0.16), transparent 65%),
    var(--bg0);
}
.auth-overlay[hidden] { display: none; }
.auth-card {
  width: min(92vw, 360px);
  text-align: center;
  display: grid;
  gap: 0.9rem;
}
.auth-card .brand { font-size: 3rem; }
.auth-card p { color: var(--muted); margin: 0; font-size: 0.9rem; }
.auth-card input {
  width: 100%;
  border: 1px solid var(--line);
  background: rgba(12, 11, 10, 0.6);
  color: var(--ink);
  border-radius: 8px;
  padding: 0.75rem 0.85rem;
  font: inherit;
  outline: none;
}
.auth-card input:focus {
  border-color: rgba(224, 138, 60, 0.5);
  box-shadow: 0 0 0 3px rgba(224, 138, 60, 0.12);
}
.auth-err { color: var(--danger); font-size: 0.82rem; min-height: 1.1em; }
.auth-invite { color: var(--muted); font-size: 0.82rem; }
.btn-supabase {
  display: block;
  text-decoration: none;
  background: #171717;
  color: #ededed;
  border: 1px solid #3ecf8e;
  padding: 0.7rem 1.1rem;
  font-weight: 600;
}
.btn-supabase[hidden] { display: none; }
.auth-card [hidden] { display: none !important; }
.auth-or {
  color: var(--muted);
  font-size: 0.75rem;
  letter-spacing: 0.04em;
}
.auth-admin {
  background: none;
  border: 0;
  padding: 0;
  color: var(--muted);
  font: inherit;
  font-size: 0.78rem;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 0.18em;
}
.auth-admin:hover { color: var(--ink); }
.logout {
  margin-left: auto;
  font-size: 0.72rem;
  color: var(--muted);
  background: transparent;
  border: 0;
  cursor: pointer;
  padding: 0.2rem 0.4rem;
}
.logout:hover { color: var(--ink); }
.head-top { display: flex; align-items: flex-start; }
.proj-bar {
  display: flex;
  gap: 0.4rem;
  align-items: center;
  margin-top: 0.5rem;
}
.mini-select {
  flex: 1;
  min-width: 0;
  background: rgba(12, 11, 10, 0.6);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.4rem 0.5rem;
  font: inherit;
  font-size: 0.82rem;
  outline: none;
}
.mini-select:focus { border-color: rgba(224, 138, 60, 0.5); }
.btn-ghost.mini {
  padding: 0.4rem 0.6rem;
  font-size: 0.75rem;
  white-space: nowrap;
}
