/* Prevent tool-trigger content from pushing the collapsible arrow off-screen */
[data-component="tool-trigger"] {
  [data-slot="basic-tool-tool-trigger-content"] {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
  }

  [data-slot="basic-tool-tool-info"] {
    font-size: var(--kilo-font-size-12);
    text-align: start;
  }

  [data-slot="basic-tool-tool-info-structured"] {
    min-width: 0;
    overflow: hidden;
  }

  [data-slot="message-part-title"] {
    align-items: baseline;
  }

  [data-slot="message-part-title-area"] {
    align-items: baseline;
  }

  [data-slot="basic-tool-tool-info-main"] {
    align-items: baseline;
    overflow: hidden;
  }

  [data-slot="basic-tool-icon"] {
    display: none;
  }

  [data-slot="basic-tool-tool-subtitle"] {
    font-size: var(--kilo-font-size-12);
    color: var(--text-weak);
  }

  [data-slot="basic-tool-tool-title"] {
    font-size: var(--kilo-font-size-12);
    font-weight: var(--font-weight-regular);
    color: var(--text-weak);
  }

  [data-slot="message-part-title-text"] {
    font-size: var(--kilo-font-size-12);
    font-weight: var(--font-weight-regular);
    color: var(--text-weak);
  }

  [data-slot="basic-tool-tool-arg"] {
    font-size: var(--kilo-font-size-12);
    color: var(--text-weak);
  }

  [data-slot="message-part-title-filename"] {
    font-size: var(--kilo-font-size-12);
    color: var(--text-weak);
  }

  [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;
    font-size: var(--kilo-font-size-12);
    color: var(--text-weak);

    &.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;
    font-size: var(--kilo-font-size-12);
  }

  [data-slot="webfetch-meta"] {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    overflow: hidden;
    min-width: 0;
    flex-shrink: 1;
  }
}

/* Tool icon in trigger: visible in VS Code theme */
html[data-theme="kilo-vscode"] [data-component="tool-trigger"] {
  [data-slot="basic-tool-icon"] {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    color: var(--text-weak);

    [data-component="icon"] {
      display: flex;
      color: inherit;
    }
  }
}

/* Card styling for tool calls in the VS Code sidebar theme */
html[data-theme="kilo-vscode"] [data-component="tool-part-wrapper"][data-part-type="tool"] {
  border-radius: 0;
  border: 0;
  overflow: visible;

  /* Header trigger — add bottom border when the collapsible is open */
  [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);
      padding: 2px 6px;
      min-height: 24px;
      height: auto;
      background-color: transparent;

      &:hover {
        background-color: transparent;
      }
    }

    [data-slot="basic-tool-tool-trigger-content"] {
      align-self: center;
      gap: 6px;
    }

    [data-slot="basic-tool-tool-info-structured"],
    [data-slot="basic-tool-tool-info-main"] {
      gap: 6px;
    }

    [data-slot="basic-tool-tool-title"]
      + :is(
        [data-slot="basic-tool-tool-subtitle"],
        [data-slot="basic-tool-tool-arg"],
        [data-slot="message-part-meta-line"],
        [data-slot="webfetch-meta"],
        [data-component="shell-submessage"]
      )::before {
      content: "·";
      margin-right: 6px;
      color: var(--text-weak);
    }

    [data-slot="message-part-title-text"]
      + :is([data-slot="message-part-meta-line"], [data-slot="basic-tool-tool-subtitle"])::before {
      content: "·";
      margin-right: 6px;
      color: var(--text-weak);
    }

    [data-slot="basic-tool-tool-title"],
    [data-slot="basic-tool-tool-subtitle"],
    [data-slot="basic-tool-tool-arg"],
    [data-slot="message-part-title-text"],
    [data-slot="message-part-title-filename"],
    [data-slot="message-part-directory-inline"],
    [data-slot="message-part-meta-line"] {
      line-height: var(--kilo-font-size-16);
    }

    [data-slot="collapsible-trigger"][aria-expanded="true"] {
      border-bottom: 0;
    }

    [data-slot="collapsible-trigger"]:has([data-slot="collapsible-arrow"]) {
      border-radius: 4px;
      cursor: pointer;
      transition:
        background-color 0.15s ease,
        color 0.15s ease;
    }

    /* Arrow always visible (no fade-on-hover) */
    [data-slot="collapsible-arrow"] {
      opacity: 1;
    }

    /* Arrow: RIGHT when collapsed, DOWN when expanded. */
    [data-slot="collapsible-arrow-icon"] {
      transform: translateZ(0) rotate(-90deg);
    }

    [data-slot="collapsible-trigger"][aria-expanded="true"] [data-slot="collapsible-arrow-icon"] {
      transform: translateZ(0) rotate(0deg);
    }

    [data-slot="collapsible-trigger"]:has([data-slot="collapsible-arrow"]):hover {
      background-color: var(--vscode-list-hoverBackground, var(--surface-raised-base-hover));

      [data-slot="basic-tool-tool-title"],
      [data-slot="basic-tool-tool-subtitle"],
      [data-slot="basic-tool-tool-arg"],
      [data-slot="message-part-title-text"],
      [data-slot="message-part-title-filename"],
      [data-slot="message-part-directory-inline"],
      [data-slot="message-part-meta-line"] {
        color: var(--vscode-list-hoverForeground, var(--vscode-foreground, var(--text-strong)));
      }

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

  /* Reposition copy button tooltip to appear below (not above) to avoid clipping */
  [data-component="tool-output"] [data-slot="markdown-copy-button"]::after {
    bottom: auto;
    top: calc(100% + 4px);
  }

  [data-slot="mcp-section-label"] {
    padding: 6px 12px 0;
    font-size: var(--kilo-font-size-11);
    color: var(--text-weak, var(--vscode-descriptionForeground));
  }

  [data-slot="mcp-tool-divider"] {
    height: 1px;
    background: var(--border-weak-base, var(--vscode-panel-border));
    margin-top: 4px;
  }

  [data-slot="mcp-section-label"] + [data-component="tool-output"] {
    margin-inline: -6px;
    width: calc(100% + 12px);
    max-height: 240px;
    padding: 8px 12px 10px;
    border: 0;
    border-radius: var(--radius-sm);
    background: var(--surface-tool-output-base);
    color: var(--text-weak);
    font-size: var(--kilo-font-size-12);
    line-height: var(--kilo-font-size-16);
    scrollbar-width: none;

    &::-webkit-scrollbar {
      display: none;
    }

    [data-component="markdown"] {
      color: inherit;
      font-size: inherit;
      line-height: inherit;
    }

    [data-component="markdown"] :is(a, code, span, [data-highlight="file"]) {
      color: inherit;
    }
  }

  [data-component="context-tool-group-trigger"] {
    min-height: 20px;

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

    [data-slot="context-tool-group-summary"] {
      color: var(--text-weak);
    }

    [data-slot="context-tool-group-summary"]::before {
      content: "·";
      margin-right: 6px;
      color: var(--text-weak);
    }
  }

  [data-component="context-tool-expanded-list"] {
    max-height: 180px;
    overflow-y: auto;
    padding: 4px 0;
    border: 1px solid var(--border-weak-base);
    background: color-mix(in srgb, var(--vscode-terminal-background, var(--vscode-panel-background)) 92%, black 8%);
    scrollbar-width: none;

    &::-webkit-scrollbar {
      display: none;
    }
  }

  [data-component="context-tool-expanded-row"],
  [data-component="context-tool-rolling-row"] {
    display: grid;
    grid-template-columns: max-content minmax(0, 1fr);
    align-items: baseline;
    column-gap: 8px;
    min-height: 20px;
    font-size: var(--kilo-font-size-12);
    line-height: var(--kilo-font-size-16);
  }

  [data-component="context-tool-expanded-row"] {
    padding: 2px 12px;
  }

  [data-slot="context-tool-expanded-action"],
  [data-slot="context-tool-rolling-action"] {
    color: var(--text-weak);
  }

  [data-slot="context-tool-expanded-detail"],
  [data-slot="context-tool-rolling-detail"] {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--text-weak);
    font-family: var(--font-family-mono);
    font-feature-settings: var(--font-family-mono--font-feature-settings);
  }

  /* Expandable tool output content */
  [data-component="tool-output"] {
    padding: 8px 12px;
    white-space: pre-wrap;
    word-break: break-word;
    min-width: 0;
    overflow: hidden;

    &[data-scrollable] {
      overflow-y: auto;
    }
  }

  [data-component="tool-output"][data-variant="preview"] {
    margin-inline: -6px;
    width: calc(100% + 12px);
    max-height: 240px;
    padding: 8px 12px 10px;
    border: 0;
    border-radius: var(--radius-sm);
    background: var(--surface-tool-output-base);
    color: var(--text-weak);
    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;
    word-break: normal;
    scrollbar-width: none;

    &::-webkit-scrollbar {
      display: none;
    }

    [data-component="markdown"] {
      color: inherit;
      font: inherit;
      line-height: inherit;
      white-space: inherit;
      overflow-wrap: inherit;
    }

    [data-component="markdown"] :is(a, code, span, [data-highlight="file"]) {
      color: inherit;
    }

    [data-component="markdown"] > *,
    [data-component="markdown"] p,
    [data-component="markdown"] pre {
      margin: 0;
    }
  }
}
