:root {
  --paper: #f6f1ea;
  --panel: #fffcf8;
  --ink: #241c16;
  --ink-2: #5b4f45;
  --ink-3: #8d8076;
  --rule: #e6ddd2;
  --rule-strong: #d2c5b6;
  --clay: #9a4b2f;
  --clay-ink: #fff6ee;
  --clay-wash: #f5e4da;
  --sage: #4f6b57;
  --sage-wash: #e5ece5;
  --ok: #2f7a4e;
  --warn: #9a5b00;
  --bad: #ad2f22;
  --bad-wash: #f9e9e6;
  --you: #2c241e;
  --you-ink: #fbf5ee;
  --shadow: 0 1px 2px rgb(60 35 15 / 6%), 0 10px 28px -14px rgb(60 35 15 / 18%);
  --radius: 16px;
  --serif: 'Iowan Old Style', 'Palatino Linotype', Palatino, Georgia, serif;
  --sans: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #16120f;
    --panel: #1e1915;
    --ink: #f3ece4;
    --ink-2: #c3b6a9;
    --ink-3: #908376;
    --rule: #332b25;
    --rule-strong: #4a4038;
    --clay: #e08d6c;
    --clay-ink: #2a140c;
    --clay-wash: #3a241b;
    --sage: #9cc2a6;
    --sage-wash: #233029;
    --ok: #74d39c;
    --warn: #f0b860;
    --bad: #ff9184;
    --bad-wash: #3b1f1b;
    --you: #efe4d8;
    --you-ink: #1f1813;
    --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 14px 30px -16px rgb(0 0 0 / 60%);
  }
}

* {
  box-sizing: border-box;
}
[hidden] {
  display: none !important;
}
html {
  -webkit-text-size-adjust: 100%;
}
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 16px/1.55 var(--sans);
  -webkit-font-smoothing: antialiased;
}
.wrap {
  width: min(1180px, 100% - 40px);
  margin-inline: auto;
}
a {
  color: var(--clay);
  text-underline-offset: 3px;
}
h1,
h2 {
  font-family: var(--serif);
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 0;
}
h1 {
  font-size: clamp(1.5rem, 3vw, 1.9rem);
  line-height: 1.2;
}
h2 {
  font-size: 1.1rem;
  margin-bottom: 6px;
}
p {
  margin: 0;
}
.muted {
  color: var(--ink-3);
}
.small {
  font-size: 0.86rem;
}
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}
:focus-visible {
  outline: 2px solid var(--clay);
  outline-offset: 2px;
  border-radius: 6px;
}
button {
  font: inherit;
  cursor: pointer;
}
button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

/* Header */
.bar {
  border-bottom: 1px solid var(--rule);
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 2;
}
.bar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 60px;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  text-decoration: none;
  font-family: var(--serif);
  font-size: 1.15rem;
  font-weight: 600;
  white-space: nowrap;
}
.brand-sub {
  color: var(--ink-3);
  font-weight: 400;
}
.brand-mark {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: var(--clay);
  stroke-width: 1.6;
  stroke-linejoin: round;
  stroke-linecap: round;
}
.badge {
  font-size: 0.8rem;
  color: var(--ink-2);
  text-decoration: none;
  border: 1px solid var(--rule-strong);
  border-radius: 999px;
  padding: 4px 12px;
  white-space: nowrap;
}
.badge:hover {
  color: var(--ink);
  border-color: var(--ink-3);
}
@media (max-width: 520px) {
  .badge .wide {
    display: none;
  }
}

/* Layout */
.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 20px;
  align-items: start;
  padding: 24px 0;
}
@media (max-width: 920px) {
  .layout {
    grid-template-columns: minmax(0, 1fr);
  }
}
.panel {
  background: var(--panel);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}
.side {
  display: grid;
  gap: 20px;
}
@media (min-width: 921px) {
  .side {
    position: sticky;
    top: 84px;
  }
}

/* Chat */
.chat {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-height: min(760px, calc(100vh - 140px));
}
.chat-head {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 16px;
}
.chat-head p {
  margin-top: 4px;
}
.notice {
  border: 1px solid var(--bad);
  background: var(--bad-wash);
  color: var(--bad);
  border-radius: 10px;
  padding: 10px 14px;
}
.messages {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
  flex: 1;
}
.message {
  max-width: 88%;
  display: grid;
  gap: 8px;
  animation: rise 200ms ease-out;
}
@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
}
.message.you {
  align-self: end;
}
.message.agent {
  align-self: start;
}
.bubble {
  border-radius: 16px;
  padding: 10px 14px;
  overflow-wrap: anywhere;
}
.you .bubble {
  background: var(--you);
  color: var(--you-ink);
  border-bottom-right-radius: 6px;
  white-space: pre-wrap;
}
.agent .bubble {
  background: var(--paper);
  border: 1px solid var(--rule);
  border-bottom-left-radius: 6px;
}
.agent .bubble p + p,
.agent .bubble p + ul,
.agent .bubble ul + p {
  margin-top: 8px;
}
.agent .bubble ul {
  margin: 0;
  padding-left: 20px;
}
.agent .bubble.error {
  background: var(--bad-wash);
  border-color: var(--bad);
  color: var(--bad);
}
.meta {
  font-size: 0.78rem;
  color: var(--ink-3);
  padding: 0 4px;
}

/* The agent's work, shown as it happens */
.trace {
  list-style: none;
  margin: 0;
  padding: 0 0 0 4px;
  display: grid;
  gap: 6px;
  font-size: 0.88rem;
  color: var(--ink-2);
}
.trace li {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr);
  gap: 8px;
  align-items: start;
}
.trace .dot {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--sage-wash);
  color: var(--sage);
  margin-top: 1px;
}
.trace .dot svg {
  width: 11px;
  height: 11px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.trace .failed .dot {
  background: var(--bad-wash);
  color: var(--bad);
}
.trace .live .dot {
  background: var(--clay-wash);
  color: var(--clay);
}
.trace .detail {
  color: var(--ink-3);
  font-size: 0.82rem;
}
.trace .label {
  color: var(--ink);
}
.trace .via {
  display: inline-block;
  margin-left: 6px;
  padding: 0 6px;
  border-radius: 999px;
  border: 1px solid var(--rule-strong);
  font-size: 0.7rem;
  color: var(--ink-3);
  vertical-align: 1px;
}
details.raw summary {
  cursor: pointer;
  font-size: 0.78rem;
  color: var(--ink-3);
  padding-left: 4px;
}
details.raw pre {
  font: 0.78rem/1.5 var(--mono);
  white-space: pre-wrap;
  word-break: break-word;
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 10px;
  padding: 10px 12px;
  margin: 6px 0 0;
  max-height: 280px;
  overflow: auto;
}
.thinking {
  display: inline-flex;
  gap: 4px;
  padding: 12px 14px;
  border-radius: 16px;
  border: 1px solid var(--rule);
  background: var(--paper);
  width: fit-content;
}
.thinking span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--ink-3);
  animation: blink 1.2s infinite ease-in-out;
}
.thinking span:nth-child(2) {
  animation-delay: 0.15s;
}
.thinking span:nth-child(3) {
  animation-delay: 0.3s;
}
@keyframes blink {
  0%,
  80%,
  100% {
    opacity: 0.25;
  }
  40% {
    opacity: 1;
  }
}

/* Approval */
.approval {
  border: 1px solid var(--clay);
  background: var(--clay-wash);
  border-radius: 14px;
  padding: 14px 16px;
  display: grid;
  gap: 10px;
}
.approval h3 {
  margin: 0;
  font-size: 0.95rem;
}
.approval ul {
  margin: 0;
  padding-left: 18px;
}
.approval .row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

/* Empty state */
.messages:empty {
  display: none;
}
.empty {
  display: grid;
  gap: 10px;
  flex: 1;
  align-content: end;
}
.empty-title {
  font-size: 0.86rem;
  color: var(--ink-3);
}
.suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.suggestion {
  border: 1px solid var(--rule-strong);
  background: transparent;
  color: var(--ink-2);
  border-radius: 12px;
  padding: 8px 12px;
  text-align: left;
  font-size: 0.92rem;
  max-width: 100%;
}
.suggestion:hover {
  border-color: var(--clay);
  color: var(--ink);
}

/* Composer */
.composer {
  border: 1px solid var(--rule-strong);
  border-radius: 14px;
  background: var(--paper);
  padding: 10px 12px;
  display: grid;
  gap: 8px;
}
.composer:focus-within {
  border-color: var(--clay);
  box-shadow: 0 0 0 3px var(--clay-wash);
}
.composer textarea {
  font: inherit;
  color: inherit;
  border: 0;
  background: transparent;
  resize: none;
  outline: none;
  width: 100%;
  max-height: 200px;
  line-height: 1.5;
}
.composer-row {
  display: flex;
  align-items: center;
  gap: 12px;
}
.composer-row .muted {
  flex: 1;
}
.count {
  color: var(--ink-3);
  font-variant-numeric: tabular-nums;
}
.count.over {
  color: var(--bad);
  font-weight: 600;
}
.primary {
  background: var(--clay);
  color: var(--clay-ink);
  border: 0;
  border-radius: 10px;
  padding: 8px 18px;
  font-weight: 600;
}
.primary:not(:disabled):hover {
  filter: brightness(1.06);
}
.ghost {
  background: transparent;
  color: var(--ink-2);
  border: 1px solid var(--rule-strong);
  border-radius: 10px;
  padding: 6px 12px;
  font-size: 0.9rem;
  white-space: nowrap;
}
.ghost:hover {
  color: var(--ink);
  border-color: var(--ink-3);
}

/* Side panels */
.samples {
  list-style: none;
  padding: 0;
  margin: 12px 0 0;
  display: grid;
  gap: 8px;
}
.samples button {
  width: 100%;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 10px;
  align-items: baseline;
  text-align: left;
  border: 1px solid var(--rule);
  background: var(--paper);
  border-radius: 10px;
  padding: 8px 10px;
  color: var(--ink);
}
.samples button:hover {
  border-color: var(--clay);
}
.samples .number {
  font: 600 0.85rem var(--mono);
}
.samples .email {
  color: var(--ink-2);
  font-size: 0.86rem;
  overflow: hidden;
  text-overflow: ellipsis;
}
.samples .status {
  font-size: 0.75rem;
  color: var(--ink-3);
}
.how {
  display: grid;
  gap: 12px;
}
.flow {
  list-style: none;
  counter-reset: flow;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 12px;
}
.flow li {
  counter-increment: flow;
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr);
  column-gap: 10px;
  font-size: 0.9rem;
  color: var(--ink-2);
}
.flow li::before {
  content: counter(flow);
  grid-row: span 2;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--clay-wash);
  color: var(--clay);
  font: 600 0.75rem var(--mono);
}
.flow strong {
  color: var(--ink);
  font-weight: 600;
}
.quota {
  display: grid;
  gap: 6px;
}
.quota-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 0.82rem;
}
#quota-text {
  font-variant-numeric: tabular-nums;
}
.meter {
  height: 6px;
  border-radius: 999px;
  background: var(--rule);
  overflow: hidden;
}
.meter span {
  display: block;
  height: 100%;
  width: 0;
  background: var(--ok);
  border-radius: inherit;
  transition: width 400ms ease;
}
.meter.high span {
  background: var(--warn);
}
.meter.full span {
  background: var(--bad);
}
.links {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  font-size: 0.9rem;
}
.foot {
  font-size: 0.84rem;
  padding: 8px 0 36px;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 1ms !important;
  }
}
