﻿:root {
  --ink: #f3f4f1;
  --muted: #a9b0a6;
  --line: #34423f;
  --panel: #111918;
  --panel-soft: #172321;
  --panel-strong: #1d2d29;
  --page: #07100f;
  --nav: #0b1514;
  --accent: #57d7b4;
  --accent-dark: #1b967d;
  --claw: #ee4b3e;
  --claw-dark: #9e2c24;
  --green: #72df9c;
  --amber: #f4c95d;
  --danger: #ff7a6d;
  --shadow: 0 18px 42px rgba(0, 0, 0, 0.38);
}

* { box-sizing: border-box; }

html { color-scheme: dark; }

body {
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(135deg, rgba(87, 215, 180, 0.08), transparent 38%),
    radial-gradient(circle at 82% 8%, rgba(238, 75, 62, 0.12), transparent 24%),
    var(--page);
  font-family: "Aptos", "Segoe UI", system-ui, sans-serif;
}

button, input, textarea, select { font: inherit; }

button, .file-button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  color: var(--ink);
  padding: 0 13px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  white-space: nowrap;
  transition: border-color 140ms ease, background 140ms ease, transform 140ms ease;
}

button:hover, .file-button:hover {
  border-color: var(--accent);
  background: #1b2a27;
}

button:active { transform: translateY(1px); }

.primary {
  border-color: var(--accent-dark);
  background: linear-gradient(135deg, #1b967d 0%, #116755 100%);
  color: #edfff9;
  font-weight: 700;
}

.primary:hover {
  border-color: var(--accent);
  background: linear-gradient(135deg, #22b898 0%, #1b967d 100%);
}

.danger { color: var(--danger); }
.file-button input { display: none; }

.app-shell {
  display: grid;
  grid-template-columns: 292px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: color-mix(in srgb, var(--nav) 94%, black);
  border-right: 1px solid var(--line);
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

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

.brand-mark {
  width: 46px;
  height: 46px;
  border-radius: 8px;
  background:
    radial-gradient(circle at 68% 28%, rgba(255, 255, 255, 0.35), transparent 16%),
    linear-gradient(145deg, var(--claw) 0%, var(--claw-dark) 100%);
  color: #fff8f5;
  display: grid;
  place-items: center;
  font-weight: 900;
  font-size: 18px;
  box-shadow: 0 10px 24px rgba(238, 75, 62, 0.18);
}

.brand h1 {
  margin: 0;
  font-size: 16px;
  line-height: 1.2;
}

.brand p {
  margin: 3px 0 0;
  font-size: 11px;
  color: var(--muted);
  line-height: 1.35;
}

.tabs {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.tab {
  justify-content: flex-start;
  width: 100%;
  text-align: left;
  background: transparent;
  border-radius: 7px;
}

.tab.is-active {
  border-color: var(--accent);
  background: rgba(87, 215, 180, 0.1);
  color: var(--accent);
}

.stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.stats div {
  background: var(--panel-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  text-align: center;
}

.stats .wide-stat { grid-column: 1 / -1; }

.stats span {
  display: block;
  font-size: 20px;
  font-weight: 800;
  color: var(--accent);
}

.stats small {
  color: var(--muted);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.stats-note, .source-note {
  font-size: 11px;
  color: var(--muted);
  line-height: 1.45;
  margin: 0;
}

.source-note code { color: var(--accent); }

.api-section {
  margin: 6px 0;
  font-size: 12px;
  color: var(--muted);
}
.api-section summary {
  cursor: pointer;
  font-weight: 600;
  padding: 4px 0;
  color: var(--ink);
}
.api-section label {
  margin-top: 8px;
}
.api-section input,
.api-section select {
  width: 100%;
  background: #0b1312;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  padding: 8px 10px;
  outline: none;
  margin-top: 3px;
}

.storage-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: auto;
}

.workspace {
  padding: 24px 28px 42px;
  overflow-y: auto;
}

.workspace-intro {
  display: grid;
  grid-template-columns: minmax(260px, 720px) minmax(220px, 440px);
  gap: 22px;
  align-items: end;
  margin-bottom: 20px;
}

.workspace-intro h2 {
  margin: 5px 0 0;
  font-size: clamp(25px, 3vw, 38px);
  line-height: 1.05;
  max-width: 720px;
}

.workspace-intro p:last-child {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

.eyebrow {
  margin: 0;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--claw);
  font-weight: 800;
}

.topbar {
  display: flex;
  gap: 12px;
  align-items: flex-end;
  margin-bottom: 18px;
  flex-wrap: wrap;
}

.search-box {
  flex: 1;
  min-width: 240px;
}

.search-box label {
  display: block;
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 4px;
}

.search-box input,
label input,
label textarea,
label select,
.panel select {
  width: 100%;
  background: #0b1312;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  padding: 10px 12px;
  outline: none;
}

.search-box input:focus,
label input:focus,
label textarea:focus,
label select:focus,
.panel select:focus {
  border-color: var(--accent);
}

.view { display: none; }
.view.is-visible { display: block; }

.view-desc {
  background: rgba(87, 215, 180, 0.07);
  border: 1px solid rgba(87, 215, 180, 0.22);
  border-radius: 8px;
  padding: 12px 14px;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 16px;
  line-height: 1.5;
}

.split {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 16px;
}

.panel, .wide-panel {
  background: rgba(17, 25, 24, 0.94);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  box-shadow: var(--shadow);
}

.wide-panel { margin-bottom: 16px; }

.generator-panel {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) minmax(280px, 420px);
  gap: 18px;
  align-items: end;
  background:
    linear-gradient(135deg, rgba(87, 215, 180, 0.12), rgba(238, 75, 62, 0.06)),
    var(--panel);
}

.generator-panel h2 {
  margin: 5px 0 0;
  font-size: 22px;
  line-height: 1.18;
}

.generator-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.recipe-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin: -6px 0 16px;
}

.recipe-card {
  min-height: 86px;
  align-items: flex-start;
  flex-direction: column;
  white-space: normal;
  text-align: left;
  background: rgba(23, 35, 33, 0.92);
}

.recipe-card strong {
  color: var(--ink);
  font-size: 13px;
}

.recipe-card span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.large-action {
  min-height: 46px;
  font-size: 15px;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.panel-header h2 {
  margin: 0;
  font-size: 16px;
}

.inline-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.version-chip {
  font-size: 11px;
  color: var(--muted);
  border: 1px solid var(--line);
  padding: 5px 8px;
  border-radius: 999px;
}

.form-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 12px;
}

label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 11px;
}

label textarea {
  min-height: 90px;
  resize: vertical;
  line-height: 1.45;
}

#single-turn-prompt { min-height: 170px; }

.guide-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 580px;
  overflow-y: auto;
}

.guide-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: var(--panel-soft);
  cursor: pointer;
}

.guide-card:hover { border-color: var(--accent); }

.guide-card h3 {
  margin: 0 0 4px;
  font-size: 14px;
}

.guide-card p {
  margin: 0;
  font-size: 11px;
  color: var(--muted);
}

.guide-card .guide-preview {
  margin-top: 6px;
  color: color-mix(in srgb, var(--muted) 82%, var(--ink));
  line-height: 1.45;
}

.gate-list, .coverage-list, .workflow-list {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.gate-row {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 9px 10px;
  border-radius: 7px;
  border: 1px solid var(--line);
  font-size: 13px;
}

.gate-row.pass { border-color: rgba(114, 223, 156, 0.38); background: rgba(114, 223, 156, 0.06); }
.gate-row.fail { border-color: rgba(255, 122, 109, 0.38); background: rgba(255, 122, 109, 0.06); }
.gate-row.warn { border-color: rgba(244, 201, 93, 0.38); background: rgba(244, 201, 93, 0.06); }

.gate-status {
  font-size: 10px;
  font-weight: 800;
  min-width: 42px;
  padding-top: 2px;
}

.gate-row.pass .gate-status { color: var(--green); }
.gate-row.fail .gate-status { color: var(--danger); }
.gate-row.warn .gate-status { color: var(--amber); }

.ref {
  font-size: 11px;
  color: var(--muted);
  margin-top: 2px;
}

.coverage-row, .workflow-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 10px;
  background: var(--panel-soft);
  font-size: 13px;
}

.coverage-row span, .workflow-row span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  margin-top: 2px;
}

.workflow-row select {
  width: 150px;
  min-width: 150px;
}

.evidence-group {
  margin-bottom: 16px;
}

.evidence-group-title {
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--accent);
  margin-bottom: 6px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--line);
}

.rule-hit {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  margin-bottom: 6px;
  background: var(--panel-soft);
}

.rule-hit .num {
  font-size: 10px;
  color: var(--accent);
  font-weight: 800;
  text-transform: uppercase;
}

.rule-hit p {
  margin: 0;
  font-size: 13px;
  line-height: 1.45;
}

.package-block {
  background: #07100f;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  font-family: Consolas, "Courier New", monospace;
  font-size: 12px;
  line-height: 1.55;
  white-space: pre-wrap;
  max-height: 460px;
  overflow-y: auto;
}

.package-block.compact { max-height: 220px; margin-top: 12px; }
.package-block.tall { min-height: 520px; }

.rubric-row {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px;
  margin-bottom: 9px;
  background: var(--panel-soft);
}

.row-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 7px;
}

.row-top span {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.rubric-row textarea {
  width: 100%;
  background: #0b1312;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  padding: 10px 12px;
  resize: vertical;
}

.rubric-subfield {
  margin-top: 8px;
  margin-bottom: 0;
}

.rubric-controls {
  display: grid;
  grid-template-columns: minmax(160px, 1fr) minmax(160px, 1fr);
  gap: 8px;
  margin-top: 8px;
}

.rubric-row .issues {
  margin-top: 7px;
  font-size: 11px;
  color: var(--danger);
  line-height: 1.45;
}

.rubric-row .clean {
  margin-top: 7px;
  font-size: 11px;
  color: var(--green);
}

.summary-pill {
  display: inline-block;
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 800;
}

.summary-pill.ready { background: rgba(114, 223, 156, 0.16); color: var(--green); }
.summary-pill.needs-work { background: rgba(244, 201, 93, 0.16); color: var(--amber); }
.summary-pill.blocked { background: rgba(255, 122, 109, 0.16); color: var(--danger); }
.summary-count { margin-left: 10px; font-size: 13px; color: var(--muted); }
.empty-note { color: var(--muted); font-size: 13px; }

/* ---------- Staged pipeline ---------- */
.stage-rail {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
  margin: 4px 0 18px;
}
.stage-chip {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  text-align: left;
  padding: 12px 14px;
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel-soft);
  position: relative;
}
.stage-chip-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  font-weight: 700;
  font-size: 13px;
  background: var(--panel-strong);
  border: 1px solid var(--line);
  color: var(--muted);
}
.stage-chip-label { font-weight: 600; font-size: 14px; color: var(--ink); }
.stage-chip-ref { font-size: 11px; color: var(--muted); }
.stage-chip.current {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px rgba(87, 215, 180, 0.35);
}
.stage-chip.current .stage-chip-num { background: var(--accent); color: var(--page); border-color: var(--accent); }
.stage-chip.done .stage-chip-num { background: rgba(114, 223, 156, 0.2); color: var(--green); border-color: rgba(114, 223, 156, 0.5); }
.stage-chip.locked { opacity: 0.55; cursor: not-allowed; }
.stage-chip.locked .stage-chip-num { color: var(--muted); }

.stage-panel { display: none; }
.stage-panel.is-active-stage { display: block; }

.stage-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  margin: 16px 0 8px;
  padding: 12px 16px;
  border: 1px dashed var(--line);
  border-radius: 12px;
  background: var(--panel-soft);
}
.stage-foot-note { margin: 0; color: var(--muted); font-size: 13px; flex: 1 1 240px; }
.stage-next:disabled { opacity: 0.5; cursor: not-allowed; }

.review-stack { display: grid; gap: 14px; }
.review-panel {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  padding: 6px 16px 14px;
}
.review-panel > summary {
  cursor: pointer;
  font-weight: 700;
  padding: 10px 0;
  list-style: none;
}
.review-panel > summary::-webkit-details-marker { display: none; }
.review-panel > summary::before { content: "\25B8  "; color: var(--accent); }
.review-panel[open] > summary::before { content: "\25BE  "; }
.rubric-actions { margin-bottom: 12px; }

@media (max-width: 1040px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: static;
    height: auto;
  }
  .tabs {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
  .stage-rail { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .workspace-intro,
  .split,
  .generator-panel {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .workspace { padding: 18px 14px 34px; }
  .tabs { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .stage-rail { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .form-grid { grid-template-columns: 1fr; }
  .recipe-grid { grid-template-columns: 1fr; }
  .panel-header {
    align-items: flex-start;
    flex-direction: column;
  }
  .rubric-controls { grid-template-columns: 1fr; }
  .workflow-row {
    align-items: flex-start;
    flex-direction: column;
  }
  .workflow-row select {
    width: 100%;
  }
}

/* ---------- Answer Helper chat ---------- */
.chat-log {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 420px;
  overflow-y: auto;
  padding: 4px;
  margin-bottom: 10px;
}

.chat-msg {
  display: flex;
  flex-direction: column;
}

.chat-msg.user { align-items: flex-end; }
.chat-msg.bot { align-items: flex-start; }

.chat-bubble {
  max-width: 88%;
  padding: 10px 13px;
  border-radius: 12px;
  font-size: 13px;
  line-height: 1.5;
  white-space: pre-wrap;
}

.chat-msg.bot .chat-bubble {
  background: var(--panel-strong);
  border: 1px solid var(--line);
  color: var(--ink);
  border-bottom-left-radius: 4px;
}

.chat-msg.user .chat-bubble {
  background: rgba(87, 215, 180, 0.12);
  border: 1px solid rgba(87, 215, 180, 0.25);
  color: var(--accent);
  border-bottom-right-radius: 4px;
}

.chat-input-row {
  display: flex;
  gap: 8px;
}

.chat-input-row input {
  flex: 1;
  background: #0b1312;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  padding: 10px 12px;
  outline: none;
}

.chat-input-row input:focus {
  border-color: var(--accent);
}

.chat-input-row button {
  min-height: 38px;
  min-width: 60px;
}


/* --- Annotate view: conversation in, Goal + rubric out --- */
.annotate-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
  align-items: start;
}
@media (max-width: 860px) {
  .annotate-grid { grid-template-columns: 1fr; }
}
.annotate-input-col textarea {
  width: 100%;
  resize: vertical;
  min-height: 320px;
  font-family: inherit;
}
.annotate-actions {
  display: flex;
  gap: 10px;
  margin-top: 10px;
  flex-wrap: wrap;
}
.annotate-output {
  border: 1px solid var(--border, #2a2a3a);
  border-radius: 10px;
  padding: 16px 18px;
  min-height: 320px;
  background: var(--panel, rgba(255,255,255,0.02));
  line-height: 1.5;
  overflow-wrap: anywhere;
}
.annotate-output h3 {
  margin: 14px 0 8px;
  font-size: 16px;
}
.annotate-output h3:first-child { margin-top: 0; }
.annotate-output h4 { margin: 12px 0 6px; font-size: 14px; }
