/* Kilo Message Part overrides */

[data-component="text-part"] {
  margin-top: 8px;

  [data-slot="text-part-body"] {
    margin-top: 0;
  }

  [data-slot="text-part-copy-wrapper"] {
    display: none;
  }

  [data-slot="text-part-copy-wrapper"][data-is-turn-copy] {
    display: flex;

    [data-component="icon-button"] {
      width: 20px;
      height: 20px;
    }
  }

  [data-slot="assistant-copy-wrapper"] {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 2px;
    margin-top: 2px;

    [data-component="icon-button"] {
      width: 20px;
      height: 20px;
    }

    /* Thumbs up/down: fill the outline on hover to preview the rated state. */
    [data-component="icon-button"][data-icon="thumbs-up"]:hover [data-slot="icon-svg"] path,
    [data-component="icon-button"][data-icon="thumbs-down"]:hover [data-slot="icon-svg"] path {
      fill: currentColor;
    }
  }
}

/* Hover-revealed "Open in Diff Viewer" icon button in edit/write tool headers */
[data-component="tool-trigger"] [data-slot="basic-tool-tool-info"]:has([data-component="edit-trigger"]),
[data-component="tool-trigger"] [data-slot="basic-tool-tool-info"]:has([data-component="write-trigger"]) {
  flex: 1 1 auto;
}

[data-component="edit-trigger"],
[data-component="write-trigger"] {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-width: 0;

  [data-slot="message-part-title-area"] {
    flex: 0 1 auto;
    min-width: 0;
    overflow: hidden;
  }

  [data-slot="tool-trigger-actions"] {
    flex-shrink: 0;
    margin-left: auto;
    display: inline-flex;
    align-items: center;
    opacity: 0;
    transition: opacity 0.15s ease;
  }
}

[data-component="tool-trigger"]:hover [data-slot="tool-trigger-actions"],
[data-slot="tool-trigger-actions"]:focus-within {
  opacity: 1;
}

/* Prevent long title/path from hiding the collapsible expand arrow */
[data-component="edit-trigger"],
[data-component="write-trigger"] {
  [data-slot="message-part-title"] {
    flex-shrink: 1;
    min-width: 0;
    overflow: hidden;
  }

  [data-slot="message-part-title-filename"] {
    margin-right: 8px;
  }

  [data-slot="message-part-title-text"] {
    flex-shrink: 0;
  }

  [data-slot="message-part-meta-line"] {
    display: inline-flex;
    align-items: baseline;
    gap: 4px;
    overflow: hidden;
    white-space: nowrap;
    min-width: 0;
    flex-shrink: 1;

    &.clickable {
      cursor: pointer;
      transition: color 0.15s ease;

      &:hover {
        color: var(--text-base);
      }
    }
  }

  [data-slot="message-part-title-filename"] {
    flex-shrink: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    direction: rtl;
    text-align: left;
  }

  [data-slot="message-part-directory-inline"] {
    color: var(--text-weak);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    direction: rtl;
    text-align: left;
    flex-shrink: 1;
    min-width: 0;
  }
}

/* Prevent long filenames in apply-patch accordion from hiding diff changes */
[data-component="accordion"][data-scope="apply-patch"] {
  [data-slot="apply-patch-filename"] {
    flex-shrink: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    direction: rtl;
    text-align: left;
  }
}

/* Task tool child-session tool list (v1.0.25 style) */
[data-component="task-tools"] {
  padding: 8px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;

  [data-slot="task-tool-item"] {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text-weak);

    [data-slot="icon-svg"] {
      flex-shrink: 0;
      color: var(--icon-weak);
    }
  }

  [data-slot="task-tool-title"] {
    font-family: var(--font-family-sans);
    font-size: var(--font-size-small);
    font-weight: var(--font-weight-medium);
    line-height: var(--line-height-large);
    color: var(--text-weak);
    flex-shrink: 0;
  }

  [data-slot="task-tool-subtitle"] {
    font-family: var(--font-family-sans);
    font-size: var(--font-size-small);
    font-weight: var(--font-weight-regular);
    line-height: var(--line-height-large);
    color: var(--text-weaker);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
  }
}

/* File mention chips in sent user messages */
[data-slot="user-message-text"] [data-highlight="file"] {
  color: var(--vscode-textLink-foreground, var(--syntax-property));
  background-color: color-mix(in srgb, var(--vscode-textLink-foreground, var(--syntax-property)) 15%, transparent);
  border-radius: 3px;
  box-shadow: 0 0 0 0.5px color-mix(in srgb, var(--vscode-textLink-foreground, var(--syntax-property)) 25%, transparent);
}

[data-slot="user-message-text"] [data-highlight="file"][data-clickable] {
  cursor: pointer;
  transition:
    background-color 0.15s,
    box-shadow 0.15s;
}

[data-slot="user-message-text"] [data-highlight="file"][data-clickable]:hover {
  background-color: color-mix(in srgb, var(--vscode-textLink-foreground, var(--syntax-property)) 25%, transparent);
  box-shadow: 0 0 0 0.5px color-mix(in srgb, var(--vscode-textLink-foreground, var(--syntax-property)) 40%, transparent);
  text-decoration: underline;
}

html[data-theme="kilo-vscode"] [data-component="bash-output"] {
  border-radius: 0;
  border: 0;
  background: transparent;
  overflow: visible;

  [data-slot="bash-terminal"] {
    border: 0;
    border-radius: var(--radius-sm);
    background: var(--surface-tool-output-base);
  }

  [data-slot="bash-pre"] code,
  .shiki code {
    color: var(--text-weak);
  }
}

/* Bash tool: static terminal preview with separate command/output surfaces. */
[data-component="bash-output"] {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-inline: -6px;
  width: calc(100% + 12px);
  border: 0;
  border-radius: 0;
  background: transparent;
  overflow: visible;
}

[data-component="bash-output"] [data-slot="bash-terminal"] {
  border-radius: 0;
  border: 1px solid var(--border-weak-base);
  background: var(--surface-raised-base);
  overflow: hidden;
}

[data-component="bash-output"] [data-slot="bash-section"] {
  position: relative;
}

[data-component="bash-output"] [data-slot="bash-section"][data-kind="command"] {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  align-items: start;
  column-gap: 8px;
  padding: 8px 12px 7px;
}

[data-component="bash-output"] [data-slot="bash-section"][data-kind="output"] {
  padding: 8px 12px 10px;
}

[data-component="bash-output"] [data-slot="bash-prompt"] {
  color: var(--text-weak, var(--vscode-descriptionForeground));
  font-family: var(--font-family-mono);
  font-feature-settings: var(--font-family-mono--font-feature-settings);
  font-size: var(--kilo-font-size-12);
  line-height: var(--line-height-large);
  user-select: none;
}

[data-component="bash-output"] [data-slot="bash-section-code"] {
  min-width: 0;
  overflow-y: auto;
  overflow-x: hidden;
  max-height: 240px;
}

[data-component="bash-output"] [data-slot="bash-section-actions"] {
  position: absolute;
  top: 4px;
  right: 4px;
  display: flex;
  align-items: center;
  gap: 2px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease;
}

[data-component="bash-output"] [data-slot="bash-section"]:hover [data-slot="bash-section-actions"],
[data-component="bash-output"] [data-slot="bash-section"]:focus-within [data-slot="bash-section-actions"] {
  opacity: 1;
  pointer-events: auto;
}

[data-component="bash-output"] [data-slot="bash-pre"] {
  margin: 0;
  padding: 0;
}

[data-component="bash-output"] .shiki {
  margin: 0;
  padding: 0;
  background: transparent !important;
}

[data-component="shell-expanded-output"] .shiki {
  margin: 0;
  padding: 12px;
  background: transparent !important;
}

[data-component="bash-output"] [data-slot="bash-pre"] code,
[data-component="bash-output"] .shiki code,
[data-component="shell-expanded-output"] .shiki code {
  font-family: var(--font-family-mono);
  font-feature-settings: var(--font-family-mono--font-feature-settings);
  font-size: var(--kilo-font-size-12);
  line-height: var(--line-height-large);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  background: transparent;
}

/* Tool error inline card (upstream removed these styles in v1.2.25) */
[data-component="tool-error"] {
  display: flex;
  align-items: start;
  gap: 8px;

  [data-slot="icon-svg"] {
    color: var(--icon-critical-base);
    margin-top: 4px;
  }

  [data-slot="message-part-tool-error-content"] {
    display: flex;
    flex: 1;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 2px 8px;
    min-width: 0;
    font-family: var(--font-family-sans);
    font-size: var(--font-size-base);
    font-style: normal;
    line-height: var(--line-height-large);
    letter-spacing: var(--letter-spacing-normal);
  }

  [data-slot="message-part-tool-error-heading"] {
    display: inline-flex;
    flex: none;
    align-items: baseline;
    gap: 8px;
    white-space: nowrap;
  }

  [data-slot="message-part-tool-error-title"] {
    font-weight: var(--font-weight-medium);
    color: var(--text-on-critical-base);
    white-space: nowrap;
  }

  [data-slot="message-part-tool-error-code"] {
    color: var(--text-on-critical-weak);
  }

  [data-slot="message-part-tool-error-message"] {
    color: var(--text-on-critical-weak);
    flex: 1 0 auto;
    min-width: 0;
    max-width: 100%;
    max-height: 240px;
    overflow-y: auto;
    overflow-wrap: anywhere;
  }
}

@media (max-width: 240px) {
  [data-component="tool-error"] > [data-component="icon"] {
    display: none;
  }
}

/* Queued state (upstream removed in v1.2.25) */
[data-component="user-message"] {
  [data-slot="user-message-attachment"][data-queued] {
    opacity: 0.6;
  }

  [data-slot="user-message-text"] {
    transition: opacity 0.3s ease;

    &[data-queued] {
      opacity: 0.6;
    }
  }

  [data-slot="user-message-queued-indicator"] {
    margin-top: 6px;
    margin-right: 2px;
    font-size: var(--font-size-small);
    color: var(--text-weak);
    user-select: none;
  }
}

[data-component="tool-output"] {
  margin-bottom: 0px;
}

[data-component="todos"] {
  [data-slot="message-part-todo-hidden"] {
    padding: 2px 0 2px 28px;
    color: var(--text-weaker);
    font-size: var(--font-size-small);
    line-height: var(--line-height-normal);
  }

  [data-slot="message-part-todo-content"][data-changed="changed"] {
    color: var(--text-base);
    font-weight: var(--font-weight-medium);
  }
}

html[data-theme="kilo-vscode"] [data-component="todos"] {
  margin-inline: -6px;
  width: calc(100% + 12px);
  padding: 8px 12px 10px;
  border: 0;
  border-radius: var(--radius-sm);
  background: var(--surface-tool-output-base);
  color: var(--text-weak);

  [data-slot="checkbox-checkbox-label"] {
    color: var(--text-weak);
    font-size: var(--kilo-font-size-12);
    line-height: var(--kilo-font-size-16);
  }

  [data-slot="message-part-todo-hidden"] {
    color: var(--text-weaker);
    font-size: var(--kilo-font-size-12);
    line-height: var(--kilo-font-size-16);
  }

  [data-slot="message-part-todo-content"][data-changed="changed"] {
    color: var(--text-base);
  }
}

/* User message copy button: collapse wrapper when idle, show on hover.
 * The wrapper must be tall enough to fully contain the button (20px)
 * so that hovering the button keeps [data-component="user-message"]
 * hovered — otherwise :hover is lost and pointer-events/opacity revert. */
[data-component="user-message"] {
  [data-slot="user-message-copy-wrapper"] {
    min-height: 0;
    height: 20px;
    margin-top: 0;

    [data-slot="user-message-meta-wrap"] {
      display: none;
    }

    [data-component="icon-button"] {
      width: 20px;
      height: 20px;
    }
  }
}

[data-component="question-answers"] {
  padding: 8px;
}

/* Reasoning block: visually distinct from normal agent output.
   Reasoning stays open unless the user explicitly collapses it. */
[data-component="reasoning-part"] {
  width: 100%;
  border-left: 2px solid var(--border-weak-base);
  border-radius: var(--radius-sm);
  overflow: hidden;

  [data-component="collapsible"].tool-collapsible {
    gap: 0;
  }

  [data-slot="collapsible-trigger"] {
    height: 36px;
    padding: 0 8px;
    gap: 6px;
    background: var(--surface-inset-base);
    border-radius: 0;
    cursor: pointer;

    &:hover {
      background-color: var(--surface-inset-base-hover, var(--vscode-list-hoverBackground));
    }
  }

  [data-slot="reasoning-header"] {
    display: flex;
    flex: 1 1 auto;
    align-items: center;
    gap: 6px;
    color: var(--text-weaker);
    font-size: var(--font-size-small);
    font-weight: var(--font-weight-medium);
    min-width: 0;

    [data-component="icon"] {
      flex-shrink: 0;
      color: var(--icon-weak-base);
    }
  }

  [data-slot="reasoning-label"] {
    flex: 0 0 auto;
    white-space: nowrap;
  }

  [data-slot="reasoning-title"] {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--text-weak);
    font-weight: var(--font-weight-regular);
  }

  [data-slot="reasoning-content"] {
    padding: 8px 10px;
    background: var(--surface-inset-base);

    [data-component="markdown"] {
      margin-top: 0;
      font-style: italic;
      font-size: var(--font-size-small);
      color: var(--text-weak);
      opacity: 0.9;

      strong,
      b {
        color: var(--text-weak);
      }
    }
  }

  /* Collapse/expand animation via Kobalte's CSS variable.
     Uses grid trick: the outer wrapper transitions grid-template-rows
     between 0fr (collapsed) and 1fr (expanded) so the content smoothly
     collapses without needing to know the pixel height up front. */
  [data-slot="collapsible-content"] {
    display: grid;
    grid-template-rows: 0fr;
    transition: grid-template-rows 250ms ease-out;
    overflow: hidden;

    > * {
      overflow: hidden;
    }

    &[data-expanded] {
      grid-template-rows: 1fr;
    }
  }

  /* Streaming state: keep the block open while content grows. */
  &[data-streaming] {
    &[data-auto-collapse] [data-slot="reasoning-content"] {
      max-height: 120px;
      overflow-y: auto;
      scroll-behavior: smooth;
      mask-image: linear-gradient(to bottom, transparent 0%, black 12px, black 85%, transparent 100%);
      -webkit-mask-image: linear-gradient(to bottom, transparent 0%, black 12px, black 85%, transparent 100%);
    }

    /* Pulse the brain icon while streaming */
    [data-slot="reasoning-header"] [data-component="icon"] {
      animation: reasoning-pulse 2s ease-in-out infinite;
    }
  }
}

html[data-theme="kilo-vscode"] [data-component="text-part"] {
  margin-top: 0;
}

html[data-theme="kilo-vscode"] [data-component="reasoning-part"] {
  border-left: 0;
  border-radius: 0;
  overflow: visible;

  [data-component="collapsible"].tool-collapsible {
    gap: 0;
    border-radius: 0;

    &:has([data-slot="collapsible-trigger"][aria-expanded="true"]) {
      gap: 6px;
    }
  }

  [data-slot="collapsible-trigger"] {
    margin-inline: -6px;
    width: calc(100% + 12px);
    min-height: 24px;
    height: auto;
    padding: 2px 6px;
    background: transparent;
    border-radius: 4px;
    transition:
      background-color 0.15s ease,
      color 0.15s ease;

    &:hover {
      background-color: var(--vscode-list-hoverBackground, var(--surface-raised-base-hover));
    }
  }

  [data-slot="collapsible-arrow"] {
    opacity: 1;
  }

  [data-slot="reasoning-header"] {
    gap: 6px;
    color: var(--text-weak);
    font-size: var(--kilo-font-size-12);
    font-weight: var(--font-weight-regular);
    line-height: var(--kilo-font-size-16);

    [data-component="icon"] {
      color: var(--text-weak);
    }
  }

  [data-slot="reasoning-label"],
  [data-slot="reasoning-title"] {
    color: var(--text-weak);
    font-weight: var(--font-weight-regular);
    line-height: var(--kilo-font-size-16);
  }

  [data-slot="reasoning-label"] + [data-slot="reasoning-title"]::before {
    content: "·";
    margin-right: 6px;
    color: var(--text-weak);
  }

  [data-slot="collapsible-trigger"]:hover {
    [data-slot="reasoning-label"],
    [data-slot="reasoning-title"] {
      color: var(--vscode-list-hoverForeground, var(--vscode-foreground, var(--text-strong)));
    }

    [data-slot="reasoning-header"] [data-component="icon"],
    [data-slot="collapsible-arrow-icon"] {
      color: var(--vscode-list-hoverForeground, var(--vscode-foreground, var(--icon-base)));
    }
  }

  [data-slot="collapsible-content"] {
    margin-inline: -6px;
    width: calc(100% + 12px);
  }

  [data-slot="reasoning-content"] {
    padding: 8px 12px 10px;
    border: 0;
    border-radius: var(--radius-sm);
    background: var(--surface-tool-output-base);

    [data-component="markdown"] {
      font-size: var(--kilo-font-size-12);
      line-height: 160%;
    }
  }
}

@keyframes reasoning-pulse {
  0%,
  100% {
    opacity: 0.5;
  }
  50% {
    opacity: 1;
  }
}

[data-component="tool-hint"] {
  display: flex;
  align-items: start;
  gap: 6px;
  padding: 4px 8px;
  border-left: 2px solid var(--border-weak-base);

  [data-component="icon"] {
    flex-shrink: 0;
    color: var(--icon-weak-base);
    margin-top: 1px;
  }

  [data-slot="tool-hint-message"] {
    font-family: var(--font-family-sans);
    font-size: var(--font-size-small);
    font-style: italic;
    color: var(--text-weak);
    opacity: 0.9;
    line-height: var(--line-height-large);
  }
}
