@import url("https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,600;9..144,700&family=Source+Sans+3:wght@400;600&display=swap");

:root {
  --bg0: #0f1412;
  --bg1: #17201c;
  --ink: #e8f0ea;
  --muted: #9bb0a2;
  --accent: #c4a35a;
  --user: #24352c;
  --bot: #1a2620;
  --line: #2d3f36;
  --danger: #d9897a;
  --font-display: "Fraunces", "Palatino Linotype", Palatino, serif;
  --font-body: "Source Sans 3", "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

.app {
  display: grid;
  grid-template-columns: minmax(220px, 280px) 1fr;
  height: 100%;
  min-height: 100%;
}

.sidebar {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg0) 82%, #000);
  min-height: 0;
}

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 1rem 0.85rem 0.75rem;
  border-bottom: 1px solid var(--line);
}

.sidebar-brand {
  font-family: var(--font-display);
  font-weight: 700;
  color: var(--accent);
}

.sessions {
  overflow-y: auto;
  padding: 0.5rem 0.45rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.session {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.15rem;
  width: 100%;
  text-align: left;
  background: transparent;
  color: var(--ink);
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 0.55rem 0.65rem;
  font: inherit;
  cursor: pointer;
}

.session:hover {
  background: color-mix(in srgb, var(--user) 70%, transparent);
}

.session.active {
  border-color: var(--accent);
  background: var(--user);
}

.session-title {
  font-weight: 600;
  font-size: 0.92rem;
  line-height: 1.3;
  width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.session-id {
  font-size: 0.72rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.shell {
  max-width: none;
  margin: 0;
  min-height: 0;
  height: 100%;
  display: grid;
  grid-template-rows: auto 1fr auto;
  padding: 1.25rem 1rem 1rem;
  gap: 0.75rem;
  overflow: hidden;
}

.menu {
  display: none;
}

@media (max-width: 840px) {
  .app {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(84vw, 300px);
    z-index: 40;
    transform: translateX(-105%);
    transition: transform 160ms ease;
    box-shadow: 8px 0 24px rgba(0, 0, 0, 0.35);
  }

  .sidebar.open {
    transform: none;
  }

  .menu {
    display: inline-flex;
  }
}

body {
  font-family: var(--font-body);
  color: var(--ink);
  background:
    radial-gradient(1200px 600px at 10% -10%, #2a3d32 0%, transparent 55%),
    radial-gradient(900px 500px at 100% 0%, #3a3220 0%, transparent 50%),
    linear-gradient(165deg, var(--bg0), var(--bg1));
}

.header {
  padding: 0.5rem 0.25rem 0.75rem;
  border-bottom: 1px solid var(--line);
}

.header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.brand {
  font-family: var(--font-display);
  font-size: clamp(1.8rem, 4vw, 2.4rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--accent);
}

button.ghost {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--line);
  padding: 0.4rem 0.8rem;
  font-size: 0.9rem;
  white-space: nowrap;
}

button.ghost:hover {
  border-color: var(--accent);
}

.tagline {
  margin: 0.35rem 0 0;
  color: var(--muted);
  max-width: 40rem;
  line-height: 1.45;
}

.log {
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  padding: 0.75rem 0.15rem 1rem;
}

.bubble {
  max-width: min(100%, 820px);
  padding: 0.85rem 1rem;
  border-radius: 14px;
  line-height: 1.5;
  word-break: break-word;
  animation: rise 220ms ease-out;
}

.bubble .who {
  display: block;
  font-size: 0.75rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 0.35rem;
}

.bubble.user .body {
  white-space: pre-wrap;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.bubble.user {
  align-self: flex-end;
  background: var(--user);
  border: 1px solid #355043;
}

.bubble.assistant {
  align-self: flex-start;
  background: var(--bot);
  border: 1px solid var(--line);
}

.bubble.assistant .body {
  white-space: normal;
}

.bubble.assistant .body > *:first-child {
  margin-top: 0;
}

.bubble.assistant .body > *:last-child {
  margin-bottom: 0;
}

.bubble.assistant .body img {
  display: block;
  width: 100%;
  max-width: 100%;
  height: auto;
  object-fit: contain;
  background: #0c1210;
  cursor: zoom-in;
}

.export-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.85rem;
}

a.export-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.4rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #e8f0ea;
  color: #6b5420;
  text-decoration: none;
  font-size: 0.95rem;
}

a.export-chip:hover {
  border-color: #c4a35a;
}

.sd-fig {
  margin: 0.85rem 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  background: #121a17;
}

.sd-fig-link {
  display: block;
}

.sd-fig-error {
  outline: 1px dashed var(--danger);
}

.sd-fig-actions {
  display: flex;
  gap: 0.5rem;
  padding: 0.4rem 0.65rem;
  border-top: 1px solid var(--line);
  background: #15201b;
}

.sd-fig-actions a,
.sd-fig-actions button {
  background: transparent;
  color: var(--accent);
  border: 0;
  padding: 0.2rem 0.15rem;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
}

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(8, 12, 10, 0.94);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1rem 1rem 1.25rem;
  gap: 0.75rem;
}

.lightbox[hidden] {
  display: none;
}

.lightbox-bar {
  width: min(96vw, 1100px);
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.lightbox-caption {
  flex: 1;
  color: var(--muted);
  font-size: 0.9rem;
}

.lightbox-btn {
  background: var(--accent);
  color: #1a150a;
  border: 0;
  border-radius: 8px;
  padding: 0.4rem 0.75rem;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  font: inherit;
  font-size: 0.9rem;
}

.lightbox img {
  max-width: 96vw;
  max-height: 82vh;
  object-fit: contain;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #0c1210;
}

.bubble.assistant .body .mermaid-wrap {
  position: relative;
  overflow-x: auto;
  background: #121a17;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.75rem;
  margin: 0.75rem 0;
}

.bubble.assistant .body .mermaid-wrap svg {
  display: block;
  max-width: 100%;
  height: auto;
}

.mermaid-wrap {
  position: relative;
}

.mermaid-download {
  position: absolute;
  top: 0.45rem;
  right: 0.45rem;
  z-index: 2;
  font-size: 0.8rem !important;
  padding: 0.3rem 0.55rem !important;
  background: color-mix(in srgb, var(--bg0) 88%, transparent) !important;
}

.bubble.assistant .body p,
.bubble.assistant .body ul,
.bubble.assistant .body ol,
.bubble.assistant .body pre,
.bubble.assistant .body blockquote,
.bubble.assistant .body table {
  margin: 0.55em 0;
}

.bubble.assistant .body h1,
.bubble.assistant .body h2,
.bubble.assistant .body h3,
.bubble.assistant .body h4 {
  font-family: var(--font-display);
  font-weight: 600;
  line-height: 1.25;
  color: var(--accent);
  margin: 0.85em 0 0.35em;
}

.bubble.assistant .body h1 {
  font-size: 1.25rem;
}

.bubble.assistant .body h2 {
  font-size: 1.12rem;
}

.bubble.assistant .body h3,
.bubble.assistant .body h4 {
  font-size: 1.02rem;
}

.bubble.assistant .body ul,
.bubble.assistant .body ol {
  padding-left: 1.25rem;
}

.bubble.assistant .body li + li {
  margin-top: 0.2em;
}

.bubble.assistant .body a {
  color: var(--accent);
}

.bubble.assistant .body code {
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  font-size: 0.88em;
  background: #121a17;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 0.08em 0.32em;
}

.bubble.assistant .body pre {
  overflow-x: auto;
  background: #121a17;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.7rem 0.8rem;
}

.bubble.assistant .body pre code {
  background: none;
  border: 0;
  padding: 0;
}

.bubble.assistant .body blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 0.75rem;
  color: var(--muted);
}

.bubble.assistant .body table {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.92em;
}

.bubble.assistant .body th,
.bubble.assistant .body td {
  border: 1px solid var(--line);
  padding: 0.3rem 0.5rem;
  text-align: left;
}

.bubble.assistant .body th {
  background: #121a17;
}

.bubble .body.streaming::after {
  content: "▍";
  animation: blink 1s step-end infinite;
}

@keyframes blink {
  50% {
    opacity: 0;
  }
}

.composer form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.65rem;
  align-items: end;
}

.composer form#form {
  grid-template-columns: auto 1fr auto;
}

button.attach {
  font-size: 1.1rem;
  padding: 0.6rem 0.7rem;
  border-radius: 12px;
}

.attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-bottom: 0.55rem;
}

.attachment-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.3rem 0.35rem 0.3rem 0.65rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bot);
  color: var(--ink);
  font-size: 0.88rem;
}

.attachment-chip.uploading {
  opacity: 0.6;
}

.attachment-chip.failed {
  border-color: var(--danger);
  color: var(--danger);
}

.attachment-chip button {
  background: transparent;
  color: var(--muted);
  padding: 0 0.35rem;
  font-size: 1rem;
  line-height: 1;
  border-radius: 6px;
}

.attachment-chip button:hover {
  color: var(--ink);
}

textarea {
  width: 100%;
  resize: vertical;
  min-height: 3.2rem;
  max-height: 9rem;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #121a17;
  color: var(--ink);
  padding: 0.75rem 0.9rem;
  font: inherit;
}

textarea:focus {
  outline: 2px solid color-mix(in srgb, var(--accent) 55%, transparent);
  border-color: var(--accent);
}

button {
  border: 0;
  border-radius: 12px;
  background: var(--accent);
  color: #1a150a;
  font-weight: 600;
  padding: 0.75rem 1.1rem;
  cursor: pointer;
  font: inherit;
}

button:disabled {
  opacity: 0.55;
  cursor: wait;
}

.status {
  min-height: 1.2rem;
  margin: 0.45rem 0 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.status.error {
  color: var(--danger);
}

.hitl {
  margin: 0 0 0.75rem;
}

.hitl-card {
  border: 1px solid color-mix(in srgb, var(--accent) 45%, var(--border));
  border-radius: 14px;
  padding: 0.85rem 1rem;
  background: color-mix(in srgb, var(--accent) 8%, var(--panel));
}

.hitl-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 650;
}

.hitl-lead {
  margin: 0.35rem 0 0.75rem;
  color: var(--muted);
  font-size: 0.88rem;
}

.hitl-action {
  margin-bottom: 0.75rem;
}

.hitl-action-name {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.9rem;
  font-weight: 600;
}

.hitl-action-desc {
  margin: 0.25rem 0 0.45rem;
  color: var(--muted);
  font-size: 0.85rem;
}

.hitl-args-label {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
}

.hitl-args {
  display: block;
  width: 100%;
  margin-top: 0.35rem;
  box-sizing: border-box;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: inherit;
  font: 0.8rem/1.35 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  padding: 0.55rem 0.65rem;
  resize: vertical;
}

.hitl-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

/* Workflow form-only view */
.workflow-app {
  grid-template-columns: 1fr;
}

.workflow-shell {
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: 100%;
}

.form-panel-solo {
  flex: 1;
  min-height: 0;
  width: min(720px, 100%);
  margin: 0 auto;
  border-top: 1px solid var(--line);
}

.form-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: auto;
  padding: 1rem 1.1rem 1.25rem;
  background: color-mix(in srgb, var(--bg1) 88%, #000);
}

.step-form.is-busy {
  pointer-events: none;
}

.processing {
  margin: 0 0 1rem;
  padding: 0.75rem 1rem;
  border-radius: 10px;
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  color: var(--ink);
  font-size: 0.95rem;
}

.coach-note {
  margin: 0 0 1rem;
  padding: 0.85rem 1rem;
  border-left: 3px solid var(--accent);
  background: color-mix(in srgb, var(--accent) 7%, transparent);
  color: var(--ink);
  font-size: 0.95rem;
  line-height: 1.5;
}

.coach-note.streaming {
  opacity: 0.92;
}

.coach-note p {
  margin: 0.45rem 0;
}

.coach-note ul,
.coach-note ol {
  margin: 0.4rem 0 0.4rem 1.2rem;
}

.coach-note li {
  margin: 0.25rem 0;
}

.coach-note .mermaid,
.coach-note .mermaid-wrap {
  position: relative;
  margin-top: 0.75rem;
  overflow-x: auto;
  background: #121a17;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.75rem;
}

.coach-note .mermaid-wrap svg,
.coach-note .mermaid svg {
  display: block;
  max-width: 100%;
  height: auto;
}

.workflow-composer {
  grid-template-columns: 1fr;
}

.workflow-composer .status {
  margin-top: 0;
}

.form-panel-head h2 {
  margin: 0 0 0.35rem;
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: 600;
}

.form-desc {
  margin: 0 0 1rem;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.45;
}

.problem-statement {
  margin: 0 0 1rem;
  padding: 0.85rem 1rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: color-mix(in srgb, var(--accent) 10%, var(--bg0));
}

.problem-statement-label {
  font-size: 0.75rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 0.35rem;
  font-weight: 650;
}

.problem-statement p {
  margin: 0;
  color: var(--ink);
  font-size: 1rem;
  line-height: 1.45;
  white-space: pre-wrap;
}

.form-empty {
  color: var(--muted);
  font-size: 0.9rem;
}

.step-form .field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 0.85rem;
  color: var(--ink);
  font-size: 0.92rem;
}

.step-form .field.check,
.step-form label.radio {
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  gap: 0.55rem;
  width: 100%;
  margin: 0.15rem 0;
  cursor: pointer;
  line-height: 1.35;
}

.step-form fieldset.field label.check {
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  gap: 0.55rem;
  margin: 0.35rem 0;
  cursor: pointer;
}

.step-form label.radio .radio-copy {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.step-form label.radio .radio-detail {
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.4;
}

.step-form label.radio input[type="radio"],
.step-form .field.check input[type="checkbox"] {
  width: 1.05rem;
  height: 1.05rem;
  min-width: 1.05rem;
  margin: 0.15rem 0 0;
  flex-shrink: 0;
  accent-color: var(--accent);
  cursor: pointer;
}

.step-form input:not([type="radio"]):not([type="checkbox"]),
.step-form textarea,
.step-form select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg0);
  color: var(--ink);
  padding: 0.55rem 0.65rem;
  font: inherit;
  box-sizing: border-box;
}

.step-form fieldset.field {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.35rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  margin: 0 0 0.85rem;
  padding: 0.65rem 0.75rem;
}

.step-form fieldset.field legend {
  padding: 0 0.25rem;
  color: var(--ink);
  font-size: 0.92rem;
}

.step-form .other-wrap {
  margin-top: -0.35rem;
}

.step-form .other-wrap[hidden] {
  display: none;
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.form-action {
  flex: 1 1 auto;
}

.workflow-meta {
  margin: 0.35rem 0 0;
  color: var(--accent);
  font-size: 0.85rem;
}

.header-row a.ghost {
  text-decoration: none;
  color: var(--ink);
}

.header-row .brand {
  flex: 1;
  text-align: center;
}

.auth-page {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 2rem 1rem;
  background: var(--bg0);
  color: var(--ink);
}

.auth-card {
  width: min(420px, 100%);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 1.5rem;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--bg1);
}

.auth-card h1,
.auth-card h2 {
  font-family: var(--font-display);
  margin: 0;
  color: var(--accent);
}

.auth-card label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.9rem;
}

.auth-card input[type="email"],
.auth-card input[type="password"],
.auth-card input[type="text"] {
  font: inherit;
  color: var(--ink);
  background: var(--bg0);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.55rem 0.7rem;
}

.auth-card .check {
  flex-direction: row;
  align-items: center;
  gap: 0.5rem;
}

.admin-app {
  display: block;
  height: auto;
  min-height: 100%;
  background: var(--bg0);
  color: var(--ink);
}

.admin-main {
  padding: 1rem 1.25rem 2rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.admin-invite {
  width: min(520px, 100%);
}

.admin-table-wrap {
  overflow-x: auto;
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

.admin-table th,
.admin-table td {
  text-align: left;
  padding: 0.55rem 0.65rem;
  border-bottom: 1px solid var(--line);
}

.admin-langfuse a {
  color: var(--accent);
}

.status.error {
  color: var(--danger);
}

.ready-card {
  width: min(480px, 100%);
}

.ready-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.ready-list li {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.45rem 0;
  border-bottom: 1px solid var(--line);
}

.ready-actions {
  display: flex;
  gap: 0.5rem;
}

.ready-actions button {
  flex: 1;
}

.ready-actions button:disabled {
  cursor: not-allowed;
}
