/* Flow chat. Every value derives from the Keiro tokens in tokens.css. */

:root {
  --flow-column: 760px;
  --flow-bar-height: 56px;
  --flow-icon: 16px;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  display: grid;
  grid-template-rows: var(--flow-bar-height) minmax(0, 1fr) auto;
  background: var(--page);
  color: var(--ink-body);
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: var(--text-base-line);
}

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

:focus-visible {
  outline: var(--focus-ring-width) solid var(--focus-ring-color);
  outline-offset: var(--focus-ring-offset);
}

/* Header */

.bar {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  padding: 0 var(--space-6);
  border-bottom: var(--hairline) solid var(--line);
  background: var(--surface);
}

.wordmark {
  color: var(--ink);
  font-size: var(--text-lg);
  line-height: var(--text-lg-line);
  font-weight: var(--weight-semibold);
}

.status {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--muted);
  font-size: var(--text-sm);
  line-height: var(--text-sm-line);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: var(--radius-pill);
  background: var(--muted);
}

.status[data-state="ready"] .status-dot {
  background: var(--ok);
}

.status[data-state="busy"] .status-dot {
  background: var(--accent);
  animation: pulse 1.4s ease-in-out infinite;
}

.status[data-state="offline"] .status-dot {
  background: var(--warn);
}

@keyframes pulse {
  50% {
    opacity: 0.35;
  }
}

.spend {
  position: relative;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-left: auto;
  color: var(--muted-strong);
  font-size: var(--text-sm);
  line-height: var(--text-sm-line);
  font-variant-numeric: tabular-nums;
}

.ghost,
.primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: var(--control-height-compact);
  padding: 0 var(--space-3);
  border-radius: var(--control-radius);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  cursor: pointer;
}

.ghost {
  border: var(--hairline) solid var(--control-border);
  background: var(--surface);
}

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

.primary {
  border: 0;
  background: var(--ink);
  color: var(--on-ink);
}

.primary:hover {
  opacity: 0.88;
}

.popover {
  position: absolute;
  top: calc(100% + var(--space-2));
  right: 0;
  z-index: 10;
  display: grid;
  gap: var(--space-2);
  width: 240px;
  padding: var(--space-4);
  border-radius: var(--menu-radius, var(--radius-lg));
  background: var(--surface-raised);
  box-shadow: var(--shadow-popover);
}

.popover[hidden] {
  display: none;
}

.popover label {
  color: var(--ink);
  font-weight: var(--weight-medium);
}

.popover input {
  height: var(--control-height-compact);
  padding: 0 var(--space-3);
  border: var(--hairline) solid var(--control-border);
  border-radius: var(--control-radius);
  background: var(--surface);
}

.hint {
  margin: 0;
  color: var(--muted);
  font-size: var(--text-xs);
  line-height: var(--text-xs-line);
}

#spend-short {
  display: none;
}

/* Transcript */

.transcript {
  overflow-y: auto;
  padding: var(--space-8) max(var(--space-6), calc((100% - var(--flow-column)) / 2));
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.empty {
  margin: auto 0;
  text-align: center;
}

.empty h1 {
  margin: 0 0 var(--space-2);
  color: var(--ink);
  font-size: var(--text-2xl);
  line-height: var(--text-2xl-line);
  font-weight: var(--weight-semibold);
}

.empty p {
  margin: 0 0 var(--space-6);
  color: var(--muted);
}

.suggestions {
  display: grid;
  gap: var(--space-2);
}

.suggestion {
  padding: var(--space-3) var(--space-4);
  border: var(--hairline) solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
  color: var(--ink-body);
  text-align: left;
  cursor: pointer;
}

.suggestion:hover {
  background: var(--surface-hover);
  border-color: var(--line-strong);
}

.message {
  overflow-wrap: anywhere;
}

.message.user {
  align-self: flex-end;
  max-width: 80%;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-xl);
  background: var(--surface-active);
  color: var(--ink);
  white-space: pre-wrap;
}

.message.assistant > :first-child {
  margin-top: 0;
}

.message.assistant > :last-child {
  margin-bottom: 0;
}

.message.commentary {
  color: var(--muted-strong);
}

.message h3 {
  margin: var(--space-5) 0 var(--space-2);
  color: var(--ink);
  font-size: var(--text-base);
  font-weight: var(--weight-semibold);
}

.message p,
.message ul,
.message ol {
  margin: var(--space-3) 0;
}

.message a {
  color: var(--accent);
}

.message code,
.command-text {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
}

.message :not(pre) > code {
  padding: 0 var(--space-1);
  border-radius: var(--radius-xs);
  background: var(--surface-muted);
}

.message pre,
.command-output {
  overflow-x: auto;
  margin: 0;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  background: var(--surface-muted);
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  line-height: var(--text-sm-line);
}

.table-wrap {
  overflow-x: auto;
}

.message table {
  border-collapse: collapse;
  font-size: var(--text-sm);
  font-variant-numeric: tabular-nums;
}

.message th,
.message td {
  padding: var(--space-2) var(--space-3);
  border-bottom: var(--hairline) solid var(--line);
  text-align: left;
}

.message th {
  color: var(--ink);
  font-weight: var(--weight-medium);
}

.command,
.thought {
  border: var(--hairline) solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface);
}

.command summary,
.thought summary {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: var(--control-height-compact);
  padding: 0 var(--space-3);
  cursor: pointer;
  list-style: none;
}

.command summary::-webkit-details-marker,
.thought summary::-webkit-details-marker {
  display: none;
}

.command summary:hover,
.thought summary:hover {
  background: var(--surface-hover);
}

.command-text {
  overflow: hidden;
  color: var(--ink-body);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.command-state {
  flex: none;
  margin-left: auto;
  color: var(--muted);
  font-size: var(--text-xs);
  line-height: var(--text-xs-line);
  font-variant-numeric: tabular-nums;
}

.command-state.running::before {
  content: "";
  display: inline-block;
  width: 10px;
  height: 10px;
  border: 1.5px solid var(--line-stronger);
  border-top-color: var(--accent);
  border-radius: var(--radius-pill);
  animation: spin 0.8s linear infinite;
}

.command-state.ok {
  color: var(--ok-ink);
}

.command-state.failed {
  color: var(--danger);
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.command-output {
  max-height: 320px;
  border-radius: 0 0 var(--radius-md) var(--radius-md);
  white-space: pre-wrap;
}

.command-output:empty {
  display: none;
}

.thought summary {
  color: var(--muted);
  font-size: var(--text-sm);
}

.thought p {
  margin: 0;
  padding: 0 var(--space-3) var(--space-3);
  color: var(--muted-strong);
  font-size: var(--text-sm);
  white-space: pre-wrap;
}

.activity {
  color: var(--muted);
  font-size: var(--text-sm);
  line-height: var(--text-sm-line);
}

.artifact {
  margin: 0;
}

.artifact img {
  display: block;
  max-width: 100%;
  border: var(--hairline) solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface);
}

.artifact figcaption {
  margin-top: var(--space-2);
  color: var(--muted);
  font-size: var(--text-xs);
  line-height: var(--text-xs-line);
}

.notice {
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  line-height: var(--text-sm-line);
}

.notice.danger {
  border: var(--hairline) solid var(--danger-line);
  background: var(--danger-surface);
  color: var(--danger);
}

.notice.muted {
  padding: 0;
  color: var(--muted);
}

/* Composer */

.composer {
  display: flex;
  align-items: flex-end;
  gap: var(--space-2);
  width: min(var(--flow-column), calc(100% - 2 * var(--space-4)));
  margin: 0 auto var(--space-5);
  padding: var(--space-2) var(--space-2) var(--space-2) var(--space-4);
  border-radius: var(--radius-xl);
  background: var(--surface);
  box-shadow: var(--shadow-composer);
}

.composer textarea {
  flex: 1;
  min-height: var(--control-height-compact);
  max-height: 240px;
  padding: var(--space-2) 0;
  border: 0;
  outline: 0;
  background: transparent;
  resize: none;
}

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

.icon-button {
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  width: var(--control-height-compact);
  height: var(--control-height-compact);
  border: 0;
  border-radius: var(--radius-pill);
  background: var(--ink);
  color: var(--on-ink);
  cursor: pointer;
}

.icon-button:hover:not(:disabled) {
  opacity: 0.88;
}

.icon-button:disabled {
  background: var(--surface-active);
  color: var(--muted);
  cursor: default;
}

.icon {
  width: var(--flow-icon);
  height: var(--flow-icon);
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.stop-icon {
  fill: currentColor;
  display: none;
}

.icon-button.stop .send-icon {
  display: none;
}

.icon-button.stop .stop-icon {
  display: block;
}

/* Sign-in notice */

body.signin {
  display: grid;
  place-items: center;
  grid-template-rows: none;
}

body.signin main {
  display: grid;
  gap: var(--space-2);
  justify-items: center;
  color: var(--muted);
}

@media (max-width: 640px) {
  .bar {
    padding: 0 var(--space-4);
  }

  #spend-text {
    display: none;
  }

  #spend-short {
    display: inline;
  }

  .message.user {
    max-width: 90%;
  }
}

@media (prefers-reduced-motion: reduce) {
  .status-dot,
  .command-state.running::before {
    animation: none;
  }
}
