/* ============================================
   Chat View Layout
   ============================================ */

.container {
  display: flex;
  flex-direction: column;
  height: 100%;
  font-size: var(--font-size-base);
  overflow: hidden;
  position: relative;
}

.chat-view {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  container: chat / inline-size;
  --chat-readable-width: 88ch;
  --chat-gutter: clamp(16px, 4cqi, 48px);
  --chat-scrollbar-width: 10px;
}

.chat-messages-wrapper {
  position: relative;
  flex: 1;
  overflow: hidden;
  min-height: 0;
}

.chat-messages {
  height: 100%;
  overflow: hidden;
  min-height: 0;
}

.chat-input {
  flex-shrink: 0;
}

/* ============================================
   Message List
   ============================================ */

.message-list-container {
  position: relative;
  height: 100%;
}

.message-list {
  height: 100%;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 12px var(--chat-gutter, 16px);
  scrollbar-gutter: stable;
}

.message-list-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--vscode-descriptionForeground);
  gap: 12px;
  font-size: var(--kilo-font-size-13);
}

.message-list-page-loader {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 0 12px;
  color: var(--vscode-descriptionForeground);
  font-size: var(--kilo-font-size-12);
}

.message-list-load-older {
  display: block;
  margin: 0 auto 12px;
  border: 1px solid var(--vscode-button-border, transparent);
  border-radius: 6px;
  background: var(--vscode-button-secondaryBackground);
  color: var(--vscode-button-secondaryForeground);
  cursor: pointer;
  padding: 5px 10px;
  font: inherit;
  font-size: var(--kilo-font-size-12);
}

.message-list-load-older:hover {
  background: var(--vscode-button-secondaryHoverBackground);
}

.message-list-content {
  display: flex;
  min-height: 100%;
  flex-direction: column;
  gap: 12px;
  margin-inline: calc(var(--chat-scrollbar-width, 10px) / 2) calc(var(--chat-scrollbar-width, 10px) / -2);
}

.message-list-content-empty {
  display: flex;
  min-height: 100%;
  align-items: center;
  justify-content: center;
}

.message-list-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--vscode-descriptionForeground);
  text-align: center;
  padding: 20px;
  gap: 20px;
}

.message-list-empty p {
  margin: 0;
}

.scroll-to-bottom-button {
  position: absolute;
  bottom: 12px;
  right: 12px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--vscode-button-background);
  color: var(--vscode-button-foreground);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--kilo-font-size-16);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
  transition: background-color 0.2s;
}

.scroll-to-bottom-button [data-component="icon"] {
  --icon-base: var(--vscode-button-foreground);
}

.scroll-to-bottom-button:hover {
  background: var(--vscode-button-hoverBackground);
}

/* ============================================
   Working Indicator
   ============================================ */

.working-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  font-size: var(--kilo-font-size-12);
  color: var(--vscode-descriptionForeground);
}

.working-indicator-slot {
  /* Offset the session actions appearing when work finishes. */
  min-height: 10px;
  flex-shrink: 0;
}

.working-text {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.working-elapsed {
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
  opacity: 0.7;
}

/* ============================================
   VscodeSessionTurn layout
   ============================================ */

/* Virtua positions turns absolutely based on measured box size, so flex `gap`
   on `.message-list-content` can't add spacing between turns. Bake the gap
   into the turn's own padding — it's included in the measured height and so
   shows up as spacing between turns (e.g. tool output to queued user message,
   including sub-agent task tools which expand inline). */
.vscode-session-turn {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  min-width: 0;
  padding: 0 4px 12px;
}

.vscode-session-turn[data-row="assistant"] {
  padding-bottom: 6px;
}

.vscode-session-turn[data-row="assistant"]:has(> .vscode-session-turn-assistant:empty) {
  padding-bottom: 0;
}

.vscode-session-turn-user {
  width: 100%;
}

.vscode-session-turn-user[data-revert-disabled] [data-component="icon-button"][data-icon="arrow-left"] {
  opacity: 0.4;
  cursor: not-allowed;
}

.vscode-session-turn-assistant {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
}

.vscode-session-turn-diffs {
  width: 100%;
}

/* Treat every chat host as a readable document. User messages, assistant
   prose, tool calls, diffs, and the composer all share one centered lane. */
.chat-view .vscode-session-turn-user,
.chat-view .vscode-session-turn-diffs,
.chat-view .error-card,
.chat-view [data-component="tool-part-wrapper"] {
  width: 100%;
  max-width: var(--chat-readable-width);
  margin-inline: auto;
}

.chat-view .message-list-content > .revert-banner,
.chat-view .message-list-content > [data-component="question-dock"],
.chat-view .message-list-content > .working-indicator-slot,
.chat-view .message-list-content > .vscode-session-turn[role="status"],
.chat-view .message-list-content > [data-component="suggest-bar"] {
  width: calc(100% - 8px);
  max-width: var(--chat-readable-width);
  margin-inline: auto;
}

.chat-view .prompt-input-container,
.chat-view .new-task-button-wrapper {
  box-sizing: border-box;
  width: min(
    calc(100% - var(--chat-gutter) - var(--chat-gutter) - var(--chat-scrollbar-width) - 8px),
    var(--chat-readable-width)
  );
  margin-inline: auto;
}

.chat-view .chat-input > .startup-error-banner,
.chat-view .chat-input > [data-component="permission-shortcuts"] {
  box-sizing: border-box;
  width: min(
    calc(100% - var(--chat-gutter) - var(--chat-gutter) - var(--chat-scrollbar-width) - 8px),
    var(--chat-readable-width)
  );
  margin-inline: auto;
}

.chat-view .chat-input > [data-component="permission-shortcuts"] > [data-component="dock-prompt"] {
  margin-inline: 0;
}

.vscode-session-turn-diffs-trigger {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0;
  margin: 0;
  background: transparent;
  border: none;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.vscode-session-turn-diffs-trigger [data-slot="session-turn-diffs-label"] {
  color: var(--text-strong);
  font-family: var(--font-family-sans);
  font-size: var(--font-size-base);
  font-weight: var(--font-weight-medium);
  line-height: var(--line-height-large);
}

.vscode-session-turn-diffs-trigger [data-slot="session-turn-diffs-chevron"] {
  display: inline-flex;
  align-items: center;
  color: var(--icon-weaker);
  opacity: 0;
  transition: opacity 0.15s ease;
}

.vscode-session-turn-diffs-trigger:hover [data-slot="session-turn-diffs-chevron"],
.vscode-session-turn-diffs-trigger:focus-visible [data-slot="session-turn-diffs-chevron"] {
  opacity: 1;
}

.vscode-session-turn-diffs-trigger [data-slot="session-turn-diffs-count"] {
  color: var(--text-weak);
  font-family: var(--font-family-sans);
  font-size: var(--font-size-small);
  line-height: var(--line-height-large);
  font-variant-numeric: tabular-nums;
}

.vscode-session-turn-diffs-trigger [data-slot="session-turn-diffs-meta"] {
  display: inline-flex;
  align-items: center;
}
