/* =========================================================
   COSMIC AGENTS — Workspace (/studio)
   Extends landing.css (tokens, nav, buttons) and demo.css
   (Markdown, message anatomy, chips, model picker, tabs).

   Layout: three columns filling the viewport, each scrolling
   on its own - saved conversations | the thread + composer |
   the crew's work. Below 1180px the crew panel becomes a
   drawer; below 820px the conversations do too.
   Colour roles as on /demo: gold = the answer, violet = the
   crew's own record, cyan = sources and deep research.
   ========================================================= */

body.studio {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---------- Navigation ---------- */
.studio-nav {
  flex-shrink: 0;
  padding: 12px clamp(14px, 2.4vw, 28px);
  gap: 12px;
}

.studio-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.studio-label {
  padding: 3px 10px;
  border-radius: 999px;
  border: 1px solid var(--border-bright);
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.74rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.drawer-toggle {
  display: none;
}

/* ---------- The three columns ---------- */
main.studio-main {
  flex: 1;
  min-height: 0;
  max-width: none;
  margin: 0;
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr) minmax(340px, 420px);
  gap: 18px;
  padding: 16px clamp(12px, 2vw, 24px);
}

/* ---------- Saved conversations ---------- */
.studio-threads {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
}

.thread-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.1) transparent;
}

.thread-item {
  display: flex;
  align-items: stretch;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  transition: background 0.15s ease;
}

.thread-item:hover {
  background: var(--surface);
}

.thread-item.active {
  background: var(--surface-hover);
  border-color: var(--border-bright);
}

.thread-open {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 9px 10px;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.thread-open:focus-visible,
.thread-delete:focus-visible {
  outline: 2px solid rgba(157, 141, 241, 0.6);
  outline-offset: -2px;
  border-radius: var(--radius-sm);
}

.thread-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
  font-size: 0.88rem;
}

.thread-item.active .thread-title {
  color: var(--ink);
}

.thread-time {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--dim);
  font-family: var(--mono);
  font-size: 0.7rem;
}

/* A conversation whose answer is being worked on right now. */
.thread-item.working .thread-time::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--emerald);
  animation: livepulse 2.4s ease-in-out infinite;
}

.thread-delete {
  padding: 0 10px;
  border: 0;
  background: none;
  color: var(--dim);
  font-size: 1.1rem;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s ease, color 0.15s ease;
}

.thread-item:hover .thread-delete,
.thread-delete:focus-visible {
  opacity: 1;
}

.thread-delete:hover {
  color: var(--rose);
}

.thread-empty {
  margin: 4px 2px;
  color: var(--dim);
  font-size: 0.84rem;
  line-height: 1.55;
}

/* ---------- The thread ---------- */
.studio-chat {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
  min-height: 0;
}

.studio-thread {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 30px;
  padding: 8px 6px 24px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.1) transparent;
}

.studio-thread > * {
  width: 100%;
  max-width: 860px;
  margin-left: auto;
  margin-right: auto;
}

.studio-intro {
  margin-top: auto;
  margin-bottom: auto;
  max-width: 560px;
  text-align: center;
}

.studio-intro h1 {
  margin: 0 0 14px;
  font-family: var(--display);
  font-size: clamp(1.5rem, 2.6vw, 2.1rem);
  line-height: 1.2;
  letter-spacing: -0.01em;
}

.studio-intro p {
  margin: 0;
  color: var(--muted);
  line-height: 1.65;
}

.turn {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* What was asked: right-aligned, in the crew's violet. */
.user-msg {
  align-self: flex-end;
  max-width: 80%;
  padding: 12px 16px;
  border: 1px solid rgba(157, 141, 241, 0.3);
  border-radius: var(--radius-lg) var(--radius-lg) 6px var(--radius-lg);
  background: linear-gradient(135deg, rgba(124, 58, 237, 0.18), rgba(34, 211, 238, 0.07));
}

.user-text {
  color: var(--ink);
  font-size: 0.95rem;
  line-height: 1.6;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.user-text.folded {
  max-height: 9.6em;
  overflow: hidden;
  -webkit-mask-image: linear-gradient(180deg, #000 55%, transparent);
  mask-image: linear-gradient(180deg, #000 55%, transparent);
}

.user-unfold,
.user-clarifications summary {
  margin-top: 8px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--cyan);
  font-family: var(--mono);
  font-size: 0.76rem;
  cursor: pointer;
}

.user-clarifications .user-text {
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.88rem;
}

/* The answer: the gold card. */
.answer-card {
  padding: 18px 22px;
  border: 1px solid var(--border);
  border-left: 3px solid rgba(245, 158, 11, 0.55);
  border-radius: var(--radius-lg);
  background: rgba(2, 3, 9, 0.62);
  box-shadow: var(--shadow-md);
}

.answer-card.is-live {
  border-left-color: var(--gold);
}

.answer-card.is-outcome {
  border-left-color: rgba(232, 121, 249, 0.5);
}

.answer-card.is-outcome .answer-body {
  color: var(--muted);
}

.answer-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 6px 12px;
  margin-bottom: 12px;
}

.answer-by {
  color: var(--gold);
  font-family: var(--mono);
  font-size: 0.84rem;
  font-weight: 600;
  letter-spacing: 0.04em;
}

.answer-meta {
  color: var(--dim);
  font-family: var(--mono);
  font-size: 0.74rem;
}

.answer-status {
  margin-bottom: 10px;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.8rem;
}

.answer-body {
  color: var(--ink);
  font-size: 0.97rem;
  line-height: 1.72;
  overflow-wrap: break-word;
}

.answer-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 18px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.answer-action {
  padding: 6px 12px;
  border: 1px solid var(--border-bright);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font: inherit;
  font-size: 0.8rem;
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease;
}

.answer-action:hover {
  color: var(--ink);
  border-color: rgba(56, 189, 248, 0.45);
}

.answer-action.is-next {
  color: var(--violet);
  border-color: rgba(157, 141, 241, 0.4);
}

/* Clarifying questions, asked inside the thread. */
.clarify-inline {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px 18px;
  border: 1px solid rgba(56, 189, 248, 0.35);
  border-radius: var(--radius-lg);
  background: rgba(56, 189, 248, 0.05);
}

.clarify-inline h3 {
  margin: 0;
  font-family: var(--display);
  font-size: 1rem;
}

.clarify-inline-note {
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.clarify-inline-q {
  display: flex;
  flex-direction: column;
  gap: 6px;
  color: var(--ink);
  font-size: 0.9rem;
  line-height: 1.5;
}

.clarify-inline textarea {
  padding: 8px 10px;
  border: 1px solid var(--border-bright);
  border-radius: var(--radius-sm);
  background: rgba(2, 3, 9, 0.6);
  color: var(--ink);
  font: inherit;
  font-size: 0.9rem;
  resize: vertical;
}

.clarify-inline textarea:focus {
  outline: none;
  border-color: rgba(56, 189, 248, 0.55);
}

.clarify-inline-actions {
  display: flex;
  gap: 8px;
}

/* ---------- Composer ---------- */
.studio-composer {
  flex-shrink: 0;
  width: 100%;
  max-width: 860px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px 14px;
  border: 1px solid var(--border-bright);
  border-radius: var(--radius-lg);
  background: rgba(4, 6, 15, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.studio-composer:focus-within {
  border-color: rgba(157, 141, 241, 0.5);
  box-shadow: 0 0 0 3px var(--violet-glow);
}

.studio-composer[data-mode="deep"] {
  border-color: rgba(56, 189, 248, 0.4);
}

.studio-composer textarea {
  width: 100%;
  min-height: 3.2em;
  max-height: 38vh;
  padding: 2px;
  border: 0;
  outline: none;
  resize: none;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 0.97rem;
  line-height: 1.55;
  field-sizing: content;
}

.studio-composer textarea::placeholder {
  color: var(--dim);
}

.composer-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 12px;
}

/* .mode-switch itself is shared (demo.css); Deep research is cyan. */
.mode-switch button[data-mode="deep"][aria-checked="true"] {
  background: var(--cyan-glow);
  color: var(--cyan);
}

.composer-note {
  flex: 1;
  min-width: 180px;
  margin: 0;
  color: var(--dim);
  font-size: 0.78rem;
  line-height: 1.45;
}

.composer-actions {
  display: flex;
  gap: 8px;
  margin-left: auto;
}

/* ---------- The crew panel ---------- */
.studio-crew {
  min-height: 0;
  padding: 16px;
  gap: 12px;
  border-radius: var(--radius-lg);
}

.studio-crew .panel-header {
  padding-bottom: 10px;
}

.studio-crew .mission-tabs {
  padding: 0;
}

.crew-body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

/* demo.css caps the feed outside mission mode; here it fills the panel. */
body.studio .chat-feed {
  flex: 1;
  max-height: none;
}

.crew-empty {
  margin: 8px 2px;
  color: var(--dim);
  font-size: 0.85rem;
  line-height: 1.6;
}

.crew-progress {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding-right: 4px;
}

.crew-scores {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.hb-fill-consistency {
  background: linear-gradient(90deg, var(--rose), var(--gold));
}

.crew-roster {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.crew-member {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 6px 10px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: rgba(2, 3, 9, 0.45);
}

.crew-member-name {
  color: var(--violet);
  font-family: var(--mono);
  font-size: 0.82rem;
}

.crew-member-role {
  color: var(--muted);
  font-size: 0.82rem;
}

.crew-tool {
  border-color: rgba(56, 189, 248, 0.35);
  color: var(--cyan);
  font-size: 0.7rem;
}

.drawer-backdrop {
  position: fixed;
  inset: 0;
  z-index: 140;
  background: rgba(0, 0, 0, 0.55);
}

/* ---------- Narrower screens: panels become drawers ---------- */
@media (max-width: 1180px) {
  main.studio-main {
    grid-template-columns: 230px minmax(0, 1fr);
  }

  #crew-toggle {
    display: inline-flex;
  }

  .studio-crew {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    z-index: 150;
    width: min(420px, 92vw);
    border-radius: 0;
    background: #05070f;
    transform: translateX(105%);
    transition: transform 0.25s ease;
  }

  body[data-drawer="crew"] .studio-crew {
    transform: none;
  }
}

@media (max-width: 820px) {
  main.studio-main {
    grid-template-columns: minmax(0, 1fr);
    padding: 10px;
  }

  #threads-toggle {
    display: inline-flex;
  }

  .studio-threads {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 150;
    width: min(300px, 86vw);
    padding: 16px;
    border-right: 1px solid var(--border);
    background: #05070f;
    transform: translateX(-105%);
    transition: transform 0.25s ease;
  }

  body[data-drawer="threads"] .studio-threads {
    transform: none;
  }

  .thread-delete {
    opacity: 1;
  }

  .studio-label,
  .status-pill,
  .account-runs,
  .account-name {
    display: none;
  }

  .user-msg {
    max-width: 92%;
  }

  .answer-card {
    padding: 14px 14px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .studio-crew,
  .studio-threads {
    transition: none;
  }
}

/* ---------- No access yet: the key screen ---------- */
body.needs-key .studio-main {
  display: none;
}

.studio-keyscreen {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: clamp(24px, 6vh, 64px) 16px;
}

.studio-keyscreen-card {
  display: flex;
  flex-direction: column;
  gap: 16px;
  width: min(620px, 100%);
  padding: 28px;
  border: 1px solid var(--border-bright);
  border-radius: var(--radius-xl);
  background: rgba(4, 6, 15, 0.85);
  box-shadow: var(--shadow-lg);
}

.studio-keyscreen-card h1 {
  margin: 0;
  font-family: var(--display);
  font-size: clamp(1.4rem, 2.4vw, 1.9rem);
  line-height: 1.25;
}

.studio-keyscreen-card > p {
  margin: 0;
  color: var(--muted);
  line-height: 1.65;
}

.studio-keyscreen-back {
  font-size: 0.86rem;
}

.studio-composer .model-control {
  background: rgba(2, 3, 9, 0.5);
}

.studio-composer.reviewing .model-roles {
  display: none;
}
