/* Sage - built on Healf's real design tokens (docs/design/healf-design-tokens.md).
   Monochrome ladder, one deep-green accent, the tri-colour gradient reserved for the
   single moment the agent is working. */

:root {
  --bg: #ffffff;
  --surface: #f5f5f5;
  --surface-2: #e5e5e5;
  --ink: #000000;
  --ink-2: #525252;
  --ink-3: #737373;
  --ink-4: #a3a3a3;
  --line: #e5e5e5;
  --line-strong: #d4d4d4;
  --accent: #32755f;
  --accent-strong: #2a735d;
  --accent-soft: #dfece4;
  --warn: #804328;
  --warn-bg: #f1e5d0;
  --error: #b91c1c;
  --error-bg: #fee2e2;
  --thinking: linear-gradient(90deg, #32755f, #5377bb, #cb8f51, #5377bb, #32755f);
  --wash: linear-gradient(180deg, rgba(221, 207, 194, 0.22), rgba(255, 255, 255, 0));
  --shadow-pop: 0 4px 16px 0 rgba(0, 0, 0, 0.09);
  --shadow-sheet: 0 16px 40px -26px rgba(0, 0, 0, 0.85);
  --sans: "Figtree", "Avenir Next", Arial, sans-serif;
  --display: "Cormorant Garamond", Georgia, serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.55;
  color: var(--ink);
  background: var(--bg);
  display: flex;
  flex-direction: column;
}

button, input { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: none; }
:focus-visible { outline: 2px solid rgba(0, 0, 0, 0.5); outline-offset: 2px; }

/* ---- top bar ---- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px clamp(16px, 5vw, 48px);
  border-bottom: 1px solid var(--line);
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 5;
}

.brand { display: flex; align-items: baseline; gap: 12px; min-width: 0; }
.logo-dot {
  width: 12px; height: 12px;
  border-radius: 9999px;
  background: linear-gradient(130.85deg, #32755f 2.89%, #5377bb 43.91%, #cb8f51 77.91%);
  align-self: center;
  flex: none;
}
.wordmark { font-weight: 800; font-size: 20px; letter-spacing: -0.48px; }
.tagline { color: var(--ink-3); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.healf-link {
  color: inherit;
  text-decoration: underline;
  text-decoration-color: var(--ink-4);
  text-underline-offset: 3px;
}
.healf-link:hover { color: var(--accent); text-decoration-color: var(--accent); }

/* ---------- deploy gate ---------- */
/* Pre-paint lock: set by the inline head script, cleared on unlock. */
html.locked body > :not(#gate) { visibility: hidden; }
html.locked #gate { display: flex; }
.gate {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--bg);
  background-image: var(--wash);
  overflow: hidden;
  opacity: 1;
  transition: opacity 0.45s ease;
}
.gate.leaving { opacity: 0; pointer-events: none; }
.gate-art {
  position: absolute;
  right: -12vmin;
  bottom: -18vmin;
  width: 72vmin;
  height: 72vmin;
  color: var(--accent);
  opacity: 0.14;
  pointer-events: none;
}
.gate-card {
  position: relative;
  max-width: 620px;
  width: 100%;
  animation: gate-in 0.5s ease both;
}
@keyframes gate-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}
.gate-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 28px; }
.gate-eyebrow {
  color: var(--ink-3);
  font-size: 12px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  margin-bottom: 14px;
}
.gate-display {
  font-family: var(--display);
  font-weight: 300;
  font-size: clamp(32px, 5vw, 44px);
  line-height: 1.12;
  margin-bottom: 14px;
}
.gate-lede { color: var(--ink-2); font-size: 16px; line-height: 1.55; margin-bottom: 18px; }
.gate-points { list-style: none; margin: 0 0 26px; padding: 0; }
.gate-points li {
  position: relative;
  padding-left: 22px;
  color: var(--ink-2);
  font-size: 14.5px;
  line-height: 1.5;
  margin-bottom: 8px;
}
.gate-points li::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0.52em;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  opacity: 0.55;
}
.gate-form {
  border-top: 1px solid var(--line);
  padding-top: 22px;
}
.gate-ask { color: var(--ink); font-size: 14.5px; margin-bottom: 12px; }
.gate-row { display: flex; gap: 10px; }
.gate-input {
  flex: 1;
  padding: 12px 16px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  font: inherit;
  font-size: 15px;
  background: var(--bg);
  outline: none;
}
.gate-input:focus { border-color: var(--accent); }
.gate-btn {
  padding: 12px 26px;
  border: none;
  border-radius: 999px;
  background: var(--ink);
  color: var(--bg);
  font: inherit;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
}
.gate-btn:hover { background: var(--accent-strong); }
.gate-error { color: var(--error); font-size: 13.5px; margin-top: 10px; }
.gate-note { color: var(--ink-4); font-size: 12.5px; margin-top: 10px; }
.gate-credit { color: var(--ink-4); font-size: 12px; margin-top: 34px; letter-spacing: 0.02em; }
.gate-credit a { color: inherit; text-decoration: underline; text-decoration-color: var(--line-strong); text-underline-offset: 3px; }
.gate-credit a:hover { color: var(--accent); text-decoration-color: var(--accent); }

.topbar-right { display: flex; align-items: center; gap: 10px; min-width: 0; }
.dev-toggle {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink-4);
  border: 1px solid var(--line);
  border-radius: 9999px;
  padding: 4px 10px;
  transition: color 140ms ease, border-color 140ms ease, background 140ms ease;
  flex: none;
}
.dev-toggle:hover { color: var(--ink-2); border-color: var(--line-strong); }
.dev-toggle.on { color: var(--accent); border-color: var(--accent-soft); background: var(--accent-soft); }

.ghost-pill {
  font-size: 12px;
  color: var(--ink-3);
  border: 1px solid var(--line);
  border-radius: 9999px;
  padding: 4px 12px;
  transition: color 140ms ease, border-color 140ms ease;
  flex: none;
}
.ghost-pill:hover { color: var(--ink); border-color: var(--line-strong); }

/* Developer telemetry is hidden unless dev view is on. */
body:not(.dev) .activity, body:not(.dev) .run-summary { display: none; }

/* The working card: what the user sees while Sage works. */
.working { margin: 6px 0 14px; animation: rise 180ms ease; }
.working-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 12px 0 14px;
  min-height: 28px;
}
.working-product {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border-radius: 9999px;
  padding: 3px 12px 3px 3px;
  font-size: 13px;
  font-weight: 500;
  animation: rise 200ms ease;
}
.working-product img {
  width: 24px; height: 24px;
  border-radius: 9999px;
  object-fit: cover;
  background: var(--surface-2);
}
.status-text { color: var(--ink-3); font-size: 13.5px; transition: opacity 200ms ease; }

.skeleton { display: flex; flex-direction: column; gap: 9px; }
.skeleton-line {
  height: 13px;
  border-radius: 6px;
  background: linear-gradient(90deg, var(--surface) 25%, #efefef 45%, var(--surface) 65%);
  background-size: 220% 100%;
  animation: shimmer 1.6s ease-in-out infinite;
}
.skeleton-line.short { width: 62%; }
@keyframes shimmer { to { background-position: -220% 0; } }

.context-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 14px 6px 6px;
  border: 1px solid var(--line);
  border-radius: 9999px;
  text-decoration: none;
  color: var(--ink);
  transition: border-color 140ms ease;
  max-width: 46vw;
}
.context-card:hover { border-color: var(--line-strong); }
.context-card img {
  width: 36px; height: 36px;
  border-radius: 9999px;
  object-fit: cover;
  background: var(--surface);
}
.context-card .cc-text { min-width: 0; }
.context-card .cc-title {
  font-weight: 500;
  font-size: 13px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.context-card .cc-meta { color: var(--ink-3); font-size: 12px; }
.context-card .cc-meta .rating { color: var(--accent); font-weight: 500; }

/* ---- workspace: conversation + product rail ---- */
.workspace {
  flex: 1;
  display: flex;
  min-height: 0;
  background:
    linear-gradient(180deg, rgba(221, 207, 194, 0.16), rgba(255, 255, 255, 0) 220px);
}

.thread {
  flex: 1;
  min-width: 0;
  overflow-y: auto;
  padding: 32px clamp(16px, 5vw, 48px) 24px;
}
.thread > * { max-width: 720px; margin-left: auto; margin-right: auto; }

.product-rail {
  width: 300px;
  flex: none;
  border-left: 1px solid var(--line);
  background: var(--bg);
  padding: 24px 24px 32px;
  overflow-y: auto;
  animation: rise 220ms ease;
}
@media (max-width: 1100px) { .product-rail { display: none; } }

.pr-image {
  width: 100%;
  aspect-ratio: 1;
  object-fit: contain;
  border-radius: 16px;
  background: var(--surface);
  margin-bottom: 16px;
}
.pr-title {
  font-family: var(--display);
  font-weight: 300;
  font-size: 24px;
  line-height: 1.15;
  letter-spacing: -0.48px;
  margin-bottom: 6px;
}
.pr-meta { color: var(--ink-2); font-size: 13.5px; }
.pr-meta .rating { color: var(--accent); font-weight: 500; }
.pr-link {
  display: inline-block;
  margin-top: 10px;
  font-size: 12.5px;
  color: var(--ink-3);
  text-decoration: none;
  border-bottom: 1px solid var(--line-strong);
  padding-bottom: 1px;
  transition: color 140ms ease, border-color 140ms ease;
}
.pr-link:hover { color: var(--accent-strong); border-color: var(--accent-strong); }
.pr-divider { border: none; border-top: 1px solid var(--line); margin: 20px 0 16px; }
.pr-label {
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-4);
  margin-bottom: 10px;
}
.pr-actions { display: flex; flex-direction: column; gap: 8px; }
.pr-action {
  text-align: left;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 13.5px;
  color: var(--ink-2);
  background: var(--bg);
  transition: border-color 140ms ease, color 140ms ease, background 140ms ease;
}
.pr-action:hover { border-color: var(--line-strong); color: var(--ink); background: var(--surface); }

.sage-label {
  font-size: 10.5px;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-4);
  margin: 20px 0 2px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.sage-label::after { content: ""; flex: 1; border-top: 1px solid var(--line); }

.empty-state {
  background: var(--wash);
  border-radius: 24px;
  padding: 56px 32px 40px;
  text-align: center;
  margin-top: 6vh;
}
.empty-display {
  font-family: var(--display);
  font-weight: 300;
  font-size: clamp(32px, 5vw, 40px);
  letter-spacing: -0.72px;
  line-height: 1.1;
}
.empty-sub { color: var(--ink-2); margin-top: 12px; font-size: 15px; }
.starters { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 24px; }
.starter {
  border: 1px solid var(--line-strong);
  border-radius: 9999px;
  padding: 8px 16px;
  font-size: 14px;
  background: var(--bg);
  transition: border-color 140ms ease, background 140ms ease;
}
.starter:hover { border-color: var(--ink-2); background: var(--surface); }
.starter-tag {
  color: var(--ink-4);
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin-left: 4px;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.turn-user {
  background: var(--surface);
  border-radius: 16px;
  padding: 12px 16px;
  margin: 24px 0 20px auto;
  width: fit-content;
  max-width: 85%;
  animation: rise 180ms ease;
}

.turn-sage { margin: 0 0 8px; animation: rise 220ms ease; }
.turn-sage h1, .turn-sage h2, .turn-sage h3 {
  font-size: 18px;
  font-weight: 500;
  letter-spacing: -0.2px;
  margin: 20px 0 8px;
}
.turn-sage p { margin: 10px 0; }
.turn-sage ul, .turn-sage ol { margin: 10px 0 10px 22px; }
.turn-sage li { margin: 5px 0; }
.turn-sage strong {
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  background: rgba(223, 236, 228, 0.55);
  border-radius: 4px;
  padding: 0 3px;
  margin: 0 -1px;
}
.turn-sage code {
  font-family: var(--mono);
  font-size: 0.85em;
  background: var(--surface);
  border-radius: 6px;
  padding: 1px 6px;
}
.turn-sage hr { border: none; border-top: 1px solid var(--line); margin: 16px 0; }

.sources {
  border-top: 1px solid var(--line);
  margin-top: 14px;
  padding-top: 8px;
  color: var(--ink-3);
  font-size: 12px;
}
.sources .src-key { font-family: var(--mono); font-size: 11px; }
body:not(.dev) .src-raw { display: none; }
body.dev .src-human { display: none; }

/* ---- activity ---- */
.activity { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 12px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: var(--surface);
  border-radius: 9999px;
  padding: 5px 12px;
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--ink-2);
  animation: rise 160ms ease;
}
.chip .dot {
  width: 6px; height: 6px;
  border-radius: 9999px;
  background: var(--ink-4);
  animation: pulse 1.1s ease-in-out infinite;
}
.chip.ok .dot { background: var(--accent); animation: none; }
.chip.err .dot { background: var(--error); animation: none; }
@keyframes pulse { 50% { opacity: 0.35; } }

.thinking {
  height: 2px;
  border-radius: 2px;
  background: var(--thinking);
  background-size: 200% 100%;
  animation: drift 2.4s linear infinite;
  margin: 16px 0;
}
@keyframes drift { to { background-position: -200% 0; } }

.answer-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 2px 0 8px;
}
.run-summary {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--ink-3);
  font-size: 12px;
  border-radius: 9999px;
  padding: 3px 10px;
  transition: background 140ms ease;
}
.run-summary:hover { background: var(--surface); color: var(--ink-2); }

.feedback { display: inline-flex; gap: 2px; }
.fb {
  color: var(--ink-4);
  font-size: 13px;
  line-height: 1;
  padding: 4px 7px;
  border-radius: 9999px;
  transition: color 140ms ease, background 140ms ease;
}
.fb:hover:not(:disabled) { color: var(--ink-2); background: var(--surface); }
.fb.picked { color: var(--accent); background: var(--accent-soft); }
.fb:disabled:not(.picked) { opacity: 0.35; cursor: default; }

/* ---- composer ---- */
.composer-wrap {
  border-top: 1px solid var(--line);
  background: var(--bg);
  padding: 14px clamp(16px, 5vw, 48px) 12px;
}
.composer {
  display: flex;
  gap: 8px;
  max-width: 720px;
  margin: 0 auto;
}
.input {
  flex: 1;
  background: var(--surface);
  border: 1px solid transparent;
  border-radius: 9999px;
  padding: 12px 20px;
  font-size: 15px;
  transition: border-color 140ms ease, background 140ms ease;
}
.input::placeholder { color: var(--ink-3); }
.input:focus { outline: none; border-color: var(--ink-3); background: var(--bg); }
.send {
  background: var(--ink);
  color: #fff;
  border-radius: 9999px;
  padding: 12px 24px;
  font-weight: 500;
  transition: background 140ms ease;
}
.send:hover { background: #404040; }
.send:disabled { background: var(--ink-4); cursor: default; }
.footnote {
  max-width: 720px;
  margin: 8px auto 0;
  color: var(--ink-4);
  font-size: 11.5px;
  text-align: center;
}

/* ---- trace panel ---- */
.trace-panel {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: min(440px, 92vw);
  background: var(--bg);
  border-left: 1px solid var(--line);
  box-shadow: var(--shadow-sheet);
  z-index: 10;
  display: flex;
  flex-direction: column;
  transition: transform 200ms ease;
}
.trace-panel.hidden { transform: translateX(105%); }
.trace-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
  font-weight: 500;
}
.trace-close { font-size: 20px; color: var(--ink-3); padding: 2px 8px; border-radius: 9999px; }
.trace-close:hover { background: var(--surface); }
.trace-body { overflow-y: auto; padding: 12px 20px 24px; }
.trace-row {
  display: flex;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
  font-family: var(--mono);
  font-size: 12px;
  color: var(--ink-2);
}
.trace-row .t-kind { color: var(--accent); min-width: 52px; }
.trace-row .t-ms { color: var(--ink-4); margin-left: auto; white-space: nowrap; }

.hidden { display: none; }

/* On wide screens the product rail carries the product identity - the header pill would
   be a duplicate, so it steps back. */
@media (min-width: 1101px) {
  body.has-product .context-card { display: none; }
}

@media (max-width: 640px) {
  .tagline { display: none; }
  .context-card { max-width: 60vw; }
}
