/* Shared styles for the TransistorKit web-remote. Mobile-first.
   Palette mirrored from the marketing site (which mirrors the Mac
   app's TransistorTheme.swift). */

:root {
  --bg:        #07070C;
  --bg-soft:   #0E0E16;
  --surface:   #14141D;
  --surface-2: #1A1A26;
  --border:        rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.16);
  --text:       rgba(255, 255, 255, 0.92);
  --text-dim:   #98A0B3;
  --text-quiet: #5D6275;
  --indigo:  #6366F1;
  --purple:  #A855F7;
  --cyan:    #22D3EE;
  --green:   #34D399;
  --red:     #EF4444;
  --yellow:  #FACC15;
  --gradient-accent: linear-gradient(135deg, var(--indigo), var(--purple));
  --gradient-soft:   linear-gradient(180deg, var(--surface), var(--surface-2));
  --shadow: 0 30px 80px -30px rgba(0, 0, 0, 0.75);
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "SF Pro Text", system-ui, "Inter",
               "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  background:
    radial-gradient(900px 600px at 20% 10%, rgba(99, 102, 241, 0.18), transparent 60%),
    radial-gradient(700px 500px at 80% 20%, rgba(168, 85, 247, 0.14), transparent 60%),
    var(--bg);
  background-attachment: fixed;
}

a { color: var(--cyan); text-decoration: none; }
a:hover { text-decoration: underline; }

h1 { font-size: 1.6rem; margin: 0 0 8px; letter-spacing: -0.02em; }
h2 { font-size: 1.1rem; margin: 0 0 6px; }
p  { margin: 0; }

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 24px;
  font-weight: 700;
  font-size: 1rem;
  color: var(--text);
}
.brand .mark {
  width: 26px; height: 26px;
  border-radius: 8px;
  background: var(--gradient-accent);
  box-shadow: 0 10px 24px -10px rgba(99, 102, 241, 0.7);
}

.shell {
  min-height: 100%;
  display: flex;
  flex-direction: column;
}

/* ---- login / pair card ---- */

.auth-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
}
.card {
  width: 100%;
  max-width: 380px;
  background: var(--gradient-soft);
  border: 1px solid var(--border-strong);
  border-radius: 16px;
  padding: 28px 24px;
  box-shadow: var(--shadow);
}
.card .sub {
  color: var(--text-dim);
  font-size: 0.92rem;
  margin-bottom: 18px;
}
.card label {
  display: block;
  font-size: 0.78rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-dim);
  font-weight: 600;
  margin: 14px 0 6px;
}
.card input {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  color: var(--text);
  font: inherit;
  font-size: 1rem;
}
.card input:focus {
  outline: none;
  border-color: var(--purple);
  box-shadow: 0 0 0 3px rgba(168, 85, 247, 0.18);
}
.btn {
  margin-top: 20px;
  width: 100%;
  padding: 12px 16px;
  border: none;
  border-radius: 10px;
  background: var(--gradient-accent);
  color: white;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 18px 40px -16px rgba(168, 85, 247, 0.55);
}
.err {
  margin-top: 12px;
  font-size: 0.88rem;
  padding: 8px 10px;
  border-radius: 8px;
  background: rgba(239, 68, 68, 0.12);
  color: var(--red);
  border: 1px solid rgba(239, 68, 68, 0.32);
}

.code-input {
  letter-spacing: 0.3em;
  font-family: "SF Mono", monospace;
  text-align: center;
  font-size: 1.5rem !important;
  font-weight: 600;
}

/* ---- app shell ---- */

.app {
  display: flex;
  flex-direction: column;
  min-height: 100%;
  max-height: 100vh;
}
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: rgba(7, 7, 12, 0.8);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar .brand { margin: 0; font-size: 0.95rem; }
.topbar .brand .mark { width: 22px; height: 22px; }

.status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(52, 211, 153, 0.10);
  border: 1px solid rgba(52, 211, 153, 0.32);
  color: var(--green);
  font-weight: 600;
}
.status.offline {
  background: rgba(239, 68, 68, 0.10);
  border-color: rgba(239, 68, 68, 0.30);
  color: var(--red);
}
.status .dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 8px currentColor;
}

.transcript {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.bubble {
  padding: 10px 14px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.02);
  font-size: 0.94rem;
  line-height: 1.5;
  max-width: 84%;
}
.bubble.user {
  align-self: flex-end;
  background: var(--gradient-accent);
  border-color: rgba(168, 85, 247, 0.45);
  color: white;
}
.bubble.orchestrator { align-self: flex-start; }
.bubble.orchestrator .who {
  display: block;
  font-size: 0.7rem;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--purple);
  font-weight: 700;
  margin-bottom: 4px;
}
.bubble.system {
  align-self: flex-start;
  background: rgba(34, 211, 238, 0.08);
  border-color: rgba(34, 211, 238, 0.30);
  color: var(--cyan);
  font-family: "SF Mono", monospace;
  font-size: 0.78rem;
  padding: 6px 10px;
  max-width: 92%;
}

.composer {
  position: sticky;
  bottom: 0;
  background: rgba(7, 7, 12, 0.85);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--border);
  padding: 12px 14px calc(12px + env(safe-area-inset-bottom, 0px));
  display: flex;
  gap: 8px;
}
.composer textarea {
  flex: 1;
  resize: none;
  min-height: 42px;
  max-height: 200px;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  color: var(--text);
  font: inherit;
  font-size: 1rem;
}
.composer textarea:focus {
  outline: none;
  border-color: var(--purple);
}
.composer button {
  align-self: flex-end;
  height: 42px;
  padding: 0 16px;
  border: none;
  border-radius: 12px;
  background: var(--gradient-accent);
  color: white;
  font-weight: 600;
  font-size: 1rem;
  cursor: pointer;
}
.composer button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.muted-foot {
  font-size: 0.78rem;
  color: var(--text-quiet);
  text-align: center;
  padding: 10px 14px;
  border-top: 1px solid var(--border);
}
.muted-foot a { color: var(--text-dim); }

/* ---- topbar left cluster + back arrow ---- */

.topbar .left {
  display: flex;
  align-items: center;
  gap: 10px;
}
.iconbtn {
  background: transparent;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  width: 30px; height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  cursor: pointer;
  padding: 0;
  transition: color 0.15s ease, border-color 0.15s ease;
}
.iconbtn:hover {
  color: var(--text);
  border-color: var(--purple);
}

/* ---- project picker ---- */

.picker {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px 24px;
}
.picker-head h1 {
  font-size: 1.4rem;
  margin: 4px 0 6px;
  letter-spacing: -0.01em;
}
.picker-head p {
  color: var(--text-dim);
  font-size: 0.92rem;
  margin-bottom: 18px;
}

.project-grid {
  display: grid;
  /* Single column on small phones (<= 480px) so cards have room
     to breathe. Two columns once the viewport can comfortably hold
     two ~200px cards side by side. */
  grid-template-columns: 1fr;
  gap: 10px;
  margin-bottom: 32px;
}
@media (min-width: 480px) {
  .project-grid {
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  }
}
.project-card {
  position: relative;               /* anchor for the unread-activity dot */
  text-align: center;
  background: var(--gradient-soft);
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  padding: 10px;
  color: var(--text);
  cursor: pointer;
  /* App-grid layout: a 1:1 icon tile on top, the project name beneath
     it, and small platform pills below the name. */
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: transform 0.12s ease, border-color 0.12s ease;
}
.project-card:hover {
  transform: translateY(-2px);
  border-color: var(--purple);
}
/* Unread-activity dot — a background Orchestrator/fleet update for a project
   the user is NOT currently viewing marks its row instead of stealing focus
   (SPEC.md "tab jumping"). accent3 (--cyan), 8px per design-tokens activity.*.
   Clears when the user opens that project (showChat). */
.project-card .activity-dot {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--cyan);
  box-shadow: 0 0 6px rgba(34, 211, 238, 0.7);
  pointer-events: none;
}
.project-card .card-icon {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;          /* always square, whatever the column width */
  border-radius: 12px;
  overflow: hidden;
  background: var(--surface-2);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
}
.project-card .card-icon img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.project-card .card-mono {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.4rem;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.92);
}
.project-card .name {
  font-size: 0.96rem;
  font-weight: 600;
  line-height: 1.2;
  word-break: break-word;
}
.project-card .card-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  justify-content: center;
}
.project-card .card-pill {
  font-size: 0.6rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: 999px;
  line-height: 1.5;
  background: rgba(99, 102, 241, 0.15);
  color: var(--indigo);
  border: 1px solid rgba(99, 102, 241, 0.32);
}
.project-card .card-pill.muted {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-dim);
  border-color: var(--border);
}
.project-card .card-pill.plat-android {
  background: rgba(52, 211, 153, 0.14); color: var(--green);
  border-color: rgba(52, 211, 153, 0.32);
}
.project-card .card-pill.plat-web {
  background: rgba(34, 211, 238, 0.14); color: var(--cyan);
  border-color: rgba(34, 211, 238, 0.32);
}
.project-card .card-pill.plat-macos {
  background: rgba(168, 85, 247, 0.15); color: var(--purple);
  border-color: rgba(168, 85, 247, 0.32);
}
.project-card .card-pill.plat-tvos,
.project-card .card-pill.plat-appletv {
  background: rgba(250, 204, 21, 0.14); color: var(--yellow);
  border-color: rgba(250, 204, 21, 0.32);
}
.project-card .card-pill.plat-server {
  background: rgba(255, 255, 255, 0.06); color: var(--text-dim);
  border-color: var(--border);
}

/* "+ New project" tile — same size and weight as a project-card so
   it reads as a sibling action sitting at the end of the row. Dashed
   border tells the eye "this is an empty slot, tap to fill." */
.project-card-plus {
  background: transparent;
  border: 1.5px dashed var(--border-strong);
  align-items: center;
  justify-content: center;
  text-align: center;
  color: var(--text-dim);
  gap: 6px;
}
.project-card-plus:hover {
  border-color: var(--purple);
  color: var(--text);
  background: rgba(168, 85, 247, 0.06);
}
.project-card-plus .plus-glyph {
  font-size: 1.8rem;
  font-weight: 300;
  line-height: 1;
  color: inherit;
}
.project-card-plus .plus-label {
  font-size: 0.92rem;
  font-weight: 600;
}

.picker .empty {
  text-align: center;
  color: var(--text-quiet);
  font-size: 0.9rem;
  padding: 24px 12px;
  border: 1px dashed var(--border-strong);
  border-radius: 12px;
  margin-bottom: 24px;
}

/* Dedicated "new project" page — used when the user taps the "+"
   tile on the picker. Keeps form room separate from the project
   grid so neither has to fight for space on a phone. */
.new-project-page {
  padding: 0 18px 32px;
  max-width: 640px;
  margin: 0 auto;
}
.new-project-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 18px 0 22px;
}
.new-project-head h1 {
  font-size: 1.45rem;
  font-weight: 700;
  margin: 0;
  letter-spacing: -0.01em;
}
.iconbtn-text {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 8px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  color: var(--text-dim);
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
}
.iconbtn-text:hover { color: var(--text); border-color: var(--purple); }

.new-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 18px;
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  background: var(--gradient-soft);
}
.field-label {
  font-size: 0.78rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-dim);
  font-weight: 600;
}
.field-hint {
  color: var(--text-quiet);
  font-size: 0.82rem;
  margin: 4px 0 14px;
  line-height: 1.4;
}
.new-form input {
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  color: var(--text);
  font: inherit;
  font-size: 1rem;
  width: 100%;
  box-sizing: border-box;
}
.new-form input:focus {
  outline: none;
  border-color: var(--purple);
}
.seg {
  display: flex;
  gap: 6px;
}
.kind-btn {
  flex: 1;
  padding: 8px 12px;
  border-radius: 10px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  color: var(--text-dim);
  font: inherit;
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
}
.kind-btn.active {
  background: var(--gradient-accent);
  color: white;
  border-color: rgba(168, 85, 247, 0.5);
}
/* Platform checkboxes on the new-project form. Single column on
   small phones — the cells need room for "Apple TV" without
   truncating; 2-column grid on tablets and up. */
.platforms-block {
  margin-top: 6px;
}
.platform-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
  margin-top: 4px;
}
@media (min-width: 420px) {
  .platform-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (min-width: 640px) {
  .platform-grid { grid-template-columns: repeat(3, 1fr); }
}
/* `label.platform-cell` wraps the checkbox + the label text. The
   previous build let the inner <span> overflow the cell on a
   narrow phone — the cell was a flex row but `min-width: 0` was
   missing, so the span pushed itself past the cell border. The
   `min-width: 0` + `overflow: hidden` here keep the cell honest
   and let the span text-overflow ellipsis instead of escaping. */
.platform-cell {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-radius: 8px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  color: var(--text);
  font-size: 0.95rem;
  cursor: pointer;
  user-select: none;
  min-width: 0;
  overflow: hidden;
  box-sizing: border-box;
}
.platform-cell:hover {
  border-color: rgba(168, 85, 247, 0.5);
}
.platform-cell.is-checked,
.platform-cell:has(input:checked) {
  border-color: var(--purple);
  background: rgba(168, 85, 247, 0.10);
}
.platform-cell input[type="checkbox"] {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
  accent-color: var(--purple);
  margin: 0;
}
.platform-cell > span {
  flex: 1 1 auto;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Live agent strip — sits above the transcript when one or more
   agents are running for the current project. Filled by
   renderAgentsStrip() from fleet_snapshot envelopes. */
.agents-strip {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-strong);
  background: rgba(255, 255, 255, 0.02);
}
/* Header row: "Fleet" label · Active/Finished sub-tabs · Files button. */
.fleet-head {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.agents-label {
  font-size: 0.68rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-weight: 700;
  color: var(--text-quiet);
}
.fleet-tabs {
  display: inline-flex;
  gap: 2px;
  padding: 2px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border-strong);
}
.fleet-tab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  border: none;
  border-radius: 999px;
  background: transparent;
  color: var(--text-dim);
  font-size: 0.74rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.fleet-tab:hover { color: var(--text); }
.fleet-tab.on {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
}
.fleet-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-dim);
  font-size: 0.66rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.fleet-tab.on .fleet-count {
  background: var(--indigo);
  color: #fff;
}
.agents-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
/* Empty-state line for a sub-tab with no builders (e.g. "No finished
   builders yet"). Mirrors product/copy.json orchestrator.fleet*Empty. */
.agents-empty {
  font-size: 0.78rem;
  color: var(--text-quiet);
  padding: 2px 2px 4px;
}
.agent-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px 4px 6px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text);
}
.agent-pill.agent-running { border-color: rgba(34, 211, 238, 0.4); }
.agent-pill.agent-starting { border-color: rgba(99, 102, 241, 0.4); }
.agent-pill.agent-waiting { border-color: rgba(168, 85, 247, 0.4); }
/* Finished builders read quieter than live ones. Failed/stopped get a
   red tint so a bad run is glanceable in the Finished tab. */
.agent-pill.agent-completed,
.agent-pill.agent-succeeded { border-color: rgba(34, 211, 238, 0.3); color: var(--text-dim); }
.agent-pill.agent-failed { border-color: rgba(239, 68, 68, 0.45); color: var(--text-dim); }
.agent-pill.agent-cancelled,
.agent-pill.agent-canceled { border-color: var(--border-strong); color: var(--text-quiet); }
.agent-ring.done.failed {
  background: rgba(239, 68, 68, 0.6);
  border-color: rgba(239, 68, 68, 0.6);
}
.agent-ring {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.18);
  border-top-color: var(--indigo);
  border-right-color: var(--purple);
}
.agent-ring.spin {
  animation: agent-spin 0.9s linear infinite;
}
.agent-ring.done {
  background: rgba(34, 211, 238, 0.55);
  border-color: rgba(34, 211, 238, 0.55);
}
@keyframes agent-spin {
  to { transform: rotate(360deg); }
}

/* "Orchestrator is thinking" indicator — three pulsing dots +
   label. Anchored at the bottom of the transcript when busy.
   Mirrors what iMessage-style typing indicators look like. */
.busy-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  font-size: 0.82rem;
  color: var(--text-dim);
  background: rgba(168, 85, 247, 0.05);
  border-top: 1px solid var(--border-strong);
}
.busy-indicator span[class^="dot"] {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--purple);
  display: inline-block;
  animation: busy-pulse 1.2s ease-in-out infinite;
}
.busy-indicator .dot1 { animation-delay: 0s; }
.busy-indicator .dot2 { animation-delay: 0.18s; }
.busy-indicator .dot3 { animation-delay: 0.36s; }
.busy-label { margin-left: 6px; }
@keyframes busy-pulse {
  0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); }
  40% { opacity: 1; transform: scale(1); }
}

.btn-create {
  padding: 13px 16px;
  border-radius: 10px;
  border: none;
  background: var(--gradient-accent);
  color: white;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  margin-top: 14px;
}
.btn-create:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

#proj-foot { margin-left: 10px; }

/* ---- chat shell wraps the builds drawer + transcript ---- */
.chat-shell {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
#transcript {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* ---- builds drawer ---- */
.builds-drawer {
  border-bottom: 1px solid var(--border-strong);
  background: linear-gradient(180deg,
    rgba(168, 85, 247, 0.10),
    rgba(99, 102, 241, 0.04));
  padding: 10px 14px;
  flex-shrink: 0;
  max-height: 40vh;
  overflow-y: auto;
}
.builds-head {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.78rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  font-weight: 700;
  color: var(--purple);
  margin-bottom: 8px;
}
.builds-head .dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--purple);
  box-shadow: 0 0 8px var(--purple);
}
.builds-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.build-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
}
.build-card .meta {
  flex: 1;
  min-width: 0;
}
.build-card .name {
  font-size: 0.94rem;
  font-weight: 600;
  word-break: break-all;
}
.build-card .sub {
  font-size: 0.74rem;
  color: var(--text-quiet);
  font-family: "SF Mono", monospace;
  margin-top: 2px;
}
.build-card a.download {
  background: var(--gradient-accent);
  color: white;
  font-weight: 600;
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 0.86rem;
  text-decoration: none;
  flex-shrink: 0;
}
.build-card a.download:hover { text-decoration: none; }

.dl-progress {
  flex-shrink: 0;
  width: 180px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.dl-bar {
  height: 8px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  overflow: hidden;
}
.dl-fill {
  height: 100%;
  width: 0%;
  background: var(--gradient-accent);
  border-radius: 999px;
  transition: width 0.15s linear;
}
.dl-label {
  font-size: 0.72rem;
  color: var(--text-dim);
  font-family: "SF Mono", monospace;
  text-align: right;
}



/* ---- Files tray + viewer ----------------------------------- */

.files-btn {
  margin-left: auto;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-dim);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  padding: 4px 10px;
  font-size: 0.78rem;
  cursor: pointer;
}
.files-btn:hover {
  background: rgba(255, 255, 255, 0.10);
  color: var(--text);
}

.files-tray {
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.02);
  max-height: 40vh;
  overflow-y: auto;
  padding: 8px 12px;
}
.files-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 0 8px;
}
.files-title {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.files-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.file-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 6px;
  cursor: pointer;
  font-family: "SF Mono", monospace;
  font-size: 0.78rem;
  color: var(--text);
}
.file-row:hover {
  background: rgba(255, 255, 255, 0.06);
}
.file-row .file-path { flex: 1; }
.file-row .file-size {
  color: var(--text-quiet);
  font-size: 0.7rem;
}

/* Full-screen overlay for the file content viewer. */
.file-viewer {
  position: fixed;
  inset: 0;
  background: rgba(8, 10, 18, 0.94);
  z-index: 1000;
  display: flex;
  flex-direction: column;
}
.viewer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}
.viewer-path {
  font-family: "SF Mono", monospace;
  font-size: 0.85rem;
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.viewer-body {
  flex: 1;
  overflow: auto;
  padding: 14px 18px;
  margin: 0;
  font-family: "SF Mono", monospace;
  font-size: 0.82rem;
  color: var(--text);
  white-space: pre-wrap;
  word-wrap: break-word;
}

/* ---- Emulator viewer (Pro) ---------------------------------- */
.emu-modal {
  position: fixed;
  inset: 0;
  background: rgba(4, 5, 10, 0.97);
  z-index: 1100;
  display: flex;
  flex-direction: column;
}
.emu-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
}
.emu-title { font-weight: 600; color: var(--text); }
.emu-label {
  flex: 1;
  font-size: 0.82rem;
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.emu-status {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--cyan);
  padding: 2px 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  white-space: nowrap;
}
.emu-stage {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  padding: 12px;
}
.emu-canvas {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 10px;
  background: #000;
  box-shadow: var(--shadow);
  /* Touch drags drive the emulator, not the page. */
  touch-action: none;
  cursor: crosshair;
}
.emu-ripple {
  position: absolute;
  width: 26px;
  height: 26px;
  margin: -13px 0 0 -13px;
  border-radius: 50%;
  border: 2px solid var(--cyan);
  pointer-events: none;
  animation: emu-ripple 0.45s ease-out forwards;
}
@keyframes emu-ripple {
  from { transform: scale(0.4); opacity: 0.9; }
  to   { transform: scale(1.6); opacity: 0; }
}
.emu-overlay {
  position: absolute;
  inset: 0;
  margin: auto;
  max-width: 460px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px;
  color: var(--text-dim);
  font-size: 0.95rem;
  line-height: 1.5;
}
.emu-foot {
  padding: 8px 16px 14px;
  font-size: 0.72rem;
  color: var(--text-quiet);
  text-align: center;
  border-top: 1px solid var(--border);
}

/* Emulator picker grid */
.emu-picker {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
}
.emu-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
}
.emu-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  text-align: left;
  background: var(--gradient-soft);
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  padding: 8px;
  color: var(--text);
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.12s ease;
}
.emu-card:hover { transform: translateY(-2px); border-color: var(--purple); }
.emu-thumb {
  width: 100%;
  aspect-ratio: 3 / 4;
  background: #000;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}
.emu-thumb img { width: 100%; height: 100%; object-fit: contain; }
.emu-thumb.is-blank { color: var(--text-quiet); font-size: 0.72rem; }
.emu-card-label {
  font-size: 0.9rem;
  font-weight: 600;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.emu-card-sub {
  font-size: 0.68rem;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.emu-empty {
  text-align: center;
  color: var(--text-dim);
  padding: 44px 24px;
  font-size: 0.92rem;
  line-height: 1.5;
}

/* ============================================================
   Chat & builder attachments (SPEC-Server)
   Composer paperclip + 52px thumbnail tray + viewer lightbox.
   Sizes mirror the macOS composer (52px thumb, radius 6).
   ============================================================ */

/* The composer becomes a column: optional tray on top, input row below. */
.composer { flex-direction: column; gap: 8px; }
.composer-row { display: flex; gap: 8px; align-items: flex-end; }

.attach-btn {
  align-self: flex-end;
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text-dim);
  cursor: pointer;
  font-size: 1.15rem;
  line-height: 1;
  transition: color .15s, border-color .15s;
}
.attach-btn:hover { color: var(--text); border-color: var(--purple); }
.attach-btn:disabled { opacity: 0.45; cursor: not-allowed; }

/* Backlog route button — sits between the textarea and Send. Same 42px
   square as the paperclip; files the message + attachments to the backlog
   instead of the Orchestrator. Goes solid-accent when its panel is open. */
.backlog-btn {
  align-self: flex-end;
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text-dim);
  cursor: pointer;
  line-height: 1;
  transition: color .15s, border-color .15s, background .15s;
}
.backlog-btn:hover { color: var(--text); border-color: var(--purple); }
.backlog-btn:disabled { opacity: 0.45; cursor: not-allowed; }
.backlog-btn.is-open {
  color: white;
  background: var(--gradient-accent);
  border-color: rgba(168, 85, 247, 0.5);
}

/* Backlog composer panel — a card that appears just above the composer. */
.backlog-panel {
  flex: 0 0 auto;
  background: var(--gradient-soft);
  border-top: 1px solid var(--border-strong);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 60vh;
  overflow-y: auto;
}
.backlog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.backlog-title { font-weight: 700; font-size: 1rem; }
.backlog-sub { color: var(--text-dim); font-size: 0.82rem; margin: 0; }
.backlog-field-label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.backlog-input {
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  color: var(--text);
  font: inherit;
  font-size: 0.95rem;
}
.backlog-input:focus { outline: none; border-color: var(--purple); }
.backlog-controls {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
}
.backlog-control {
  display: flex;
  flex-direction: column;
  gap: 5px;
  flex: 1 1 140px;
}
.seg-btn {
  flex: 1;
  padding: 8px 12px;
  border-radius: 10px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  color: var(--text-dim);
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
}
.seg-btn.active {
  background: var(--gradient-accent);
  color: white;
  border-color: rgba(168, 85, 247, 0.5);
}
.backlog-select {
  padding: 8px 12px;
  border-radius: 10px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
}
.backlog-select:focus { outline: none; border-color: var(--purple); }
.backlog-hint {
  color: var(--text-quiet);
  font-size: 0.78rem;
  margin: 2px 0 0;
}
.backlog-hint.is-error { color: var(--red); }
.backlog-actions { display: flex; justify-content: flex-end; }
.backlog-submit {
  height: 40px;
  padding: 0 18px;
  border: none;
  border-radius: 12px;
  background: var(--gradient-accent);
  color: white;
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
}
.backlog-submit:disabled { opacity: 0.5; cursor: not-allowed; }

/* Pending-attachment tray — horizontally scrolling strip of 52px thumbs. */
.attach-tray {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  padding: 4px 0 0;
}
.attach-thumb {
  position: relative;
  width: 52px;
  height: 52px;
  border-radius: 6px;
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  overflow: hidden;
  flex: 0 0 auto;
  cursor: pointer;
}
.attach-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.attach-thumb .file-glyph {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 1.2rem;
  color: var(--text-dim);
}
.attach-thumb .file-glyph .ext {
  font-size: 0.5rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  max-width: 46px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
/* uploading / error overlays */
.attach-thumb .overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.6rem;
  text-align: center;
  padding: 2px;
}
.attach-thumb.is-uploading .overlay {
  background: rgba(7, 7, 12, 0.55);
  color: var(--cyan);
}
.attach-thumb.is-uploading .spinner {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(34, 211, 238, 0.3);
  border-top-color: var(--cyan);
  border-radius: 50%;
  animation: att-spin 0.8s linear infinite;
}
@keyframes att-spin { to { transform: rotate(360deg); } }
.attach-thumb.is-error { border-color: var(--red); }
.attach-thumb.is-error .overlay {
  background: rgba(239, 68, 68, 0.18);
  color: var(--red);
  flex-direction: column;
  gap: 1px;
  cursor: pointer;
}
.attach-thumb .remove {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: none;
  background: var(--red);
  color: white;
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
}
/* role badge (builder only — /play renders its own toggle; this is a
   shared affordance kept here for any surface reusing the tray) */
.attach-thumb .role-badge {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  font-size: 0.45rem;
  text-align: center;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 1px 0;
  background: rgba(7, 7, 12, 0.7);
}
.attach-thumb .role-badge.reference { color: var(--cyan); }
.attach-thumb .role-badge.asset { color: var(--purple); }

/* drag-over highlight on the thread */
.transcript.attach-dragover {
  outline: 2px dashed var(--purple);
  outline-offset: -8px;
  border-radius: 12px;
}

/* attachment bubble — thumbnails inside a sent message */
.bubble .att-bubble {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 6px;
}
.bubble .att-bubble .att-mini {
  width: 52px;
  height: 52px;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  cursor: pointer;
}
.bubble .att-bubble .att-mini img { width: 100%; height: 100%; object-fit: cover; }
.bubble .att-bubble .att-mini .file-glyph {
  width: 100%; height: 100%;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.1rem; color: var(--text-dim);
}

/* ---- attachment viewer (lightbox) ---- */
.att-viewer {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(7, 7, 12, 0.92);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  flex-direction: column;
}
.att-viewer-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(10px + env(safe-area-inset-top, 0px)) 14px 10px;
  border-bottom: 1px solid var(--border);
}
.att-viewer-title {
  flex: 1;
  color: var(--text);
  font-size: 0.9rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.att-viewer-body {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  overflow: auto;
}
.att-viewer-body img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 8px;
}
.att-viewer-file {
  text-align: center;
  color: var(--text-dim);
}
.att-viewer-file .file-icon { font-size: 3rem; }
.att-viewer-file .name { color: var(--text); margin: 10px 0 4px; word-break: break-all; }
.att-viewer-dl {
  display: inline-block;
  margin-top: 14px;
  padding: 10px 20px;
  border-radius: 12px;
  background: var(--gradient-accent);
  color: white;
  font-weight: 600;
  text-decoration: none;
}
.att-viewer-status { color: var(--text-dim); }
