@import "../../mixins/_tab-focus.less";
/**
 * C8Y AI Chat - AI chat widget component
 *
 * Note: Uses @size-* tokens for spacing and @font-size-* tokens for typography.
 *
 * Intentionally hardcoded values:
 * - Component-specific dimensions (400px): Minimum chat height
 * - Border radius (20px): Pill-shaped input and list items
 * - Border widths (1px): Standard borders
 * - Percentages (85%, 100%): Layout and width constraints
 * - Negative calc expressions: Complex computed heights
 * - Font-size em values (1.2em, 1.5em, 2em): Relative heading sizes
 * - Line-height values (1.7): Unitless ratio
 * - Z-index values: Stacking order
 */

c8y-widget-ai-chat-section {
  display: flex;
  max-height: calc(100vh - 400px);
  min-height: 400px;
  background-color: @component-background-default;
  border: 1px solid var(--c8y-root-component-border-color);
  border-radius: @size-base;
  padding: 0;

  .chat-input {
    border-bottom-left-radius: @size-base;
    border-bottom-right-radius: @size-base;
  }
}

c8y-agent-chat {
  width: 100%;
}

.chat-input {
  display: flex;
  width: 100%;
  flex-direction: column;
  gap: @size-8;
  padding: @size-16 @size-16 @size-4 @size-16;
  background-color: @component-background-default;
  border-top: 1px solid var(--c8y-root-component-border-color);
  margin-top: auto;
  position: sticky;
  bottom: 0;

  .chat-input-group {
    position: relative;
    width: 100%;

    textarea {
      border-radius: 20px !important;
      min-height: @size-40;
      padding-top: @size-10;
      padding-right: @size-40;
      padding-bottom: @size-10;
      padding-left: @size-16;

      &::-webkit-scrollbar {
        width: unset;
        /* for vertical scrollbars */
        height: unset;
        /* for horizontal scrollbars */
      }

      &::-webkit-scrollbar-track {
        background: unset;
      }

      &::-webkit-scrollbar-thumb {
        width: unset;
        border-radius: unset;
        background: unset;
      }

      &:hover {
        &::-webkit-scrollbar-thumb {
          background: unset;
        }
      }
    }

    .chat-input-group-btn {
      position: absolute;
      right: @size-4;
      bottom: @size-4;

      .btn-dot {
        margin: 0 !important;
        height: @form-control-height-base !important;
        border-radius: 50%;
      }
    }
  }
}

.chat-message {
  line-height: 1.7;

  .message-content {
    overflow-wrap: break-word;
    word-break: break-word;
    max-width: 100%;
    min-width: 0;

    p {
      margin-bottom: @size-8;

      &:last-child {
        margin-bottom: 0;
      }
    }
  }
}

.agent-message {
  align-self: flex-start;
  min-width: 0;
  width: 100%;
  margin-top: @size-16;
  padding: @size-16 @size-24 @size-16 @size-16;

  h1 {
    margin-top: @size-24;
    margin-bottom: @size-16;
    font-size: 2em;
    font-weight: 600;
  }

  h2 {
    margin-top: @size-24;
    margin-bottom: @size-16;
    font-size: 1.5em;
    font-weight: 600;
  }

  h3 {
    margin-top: @size-16;
    margin-bottom: @size-16;
    font-size: 1.2em;
    font-weight: 600;
  }
}

.user-message {
  background-color: var(--c8y-brand-70);
  color: var(--c8y-palette-low);
  align-self: flex-end;
  border-radius: @size-base;
  max-width: 85%;
  min-width: 0;
  padding: @size-base @size-16;
  order: 2;
}

.message-action {
  display: flex;
  align-items: center;
  gap: @size-base;
  padding: @size-base 0 @size-16 0;

  &:empty {
    display: none;
  }

  &.user-action {
    display: inline-block;
    align-self: flex-end;
    width: auto;
    padding: 0;
    margin-top: 0;
    margin-right: 0;
    order: 1;
  }

  &.agent-action {
    justify-content: flex-start;
    border-top: 1px dashed var(--c8y-root-component-border-color);
  }

  .btn-dot {
    margin: 0 !important;
    height: @form-control-height-base !important;
    border-radius: 50% !important;
  }
}

.message-timestamp {
  display: block;
  font-size: @font-size-xs;
  color: var(--c8y-text-muted);

  .user-message & {
    text-align: right;
  }
}


c8y-ai-chat {

  // Visually hidden label included when users copy-paste from the chat, e.g. to report issues.
  .hidden-copy-label {
    display: block;
    font-size: 0;
    line-height: 0;
    user-select: text;
  }

  .ai-tool-call {
    &__fieldset {
      display: inline-flex;
      max-inline-size: min-content;
      flex-direction: column;
      max-width: 100%;
      min-inline-size: 1rem;
      transition: all .35s ease;

      &:has([aria-expanded="true"]) {
        min-inline-size: 100%;
        transition: all .35s ease;
      }

      &:focus-within {
        .c8y-focus-inset();
        border-radius: var(--c8y-unit-base) !important;
      }
    }

    &__btn {
      display: inline-flex;
      align-items: center;
      gap: 4px;

      &:focus {
        outline: 0;
        box-shadow: none;
      }
    }
  }

  .reasoning-content {
    font-style: italic;
    font-size: @font-size-small;

    p {
      margin-bottom: @size-4;

      &:last-child {
        margin-bottom: 0;
      }
    }

  }


}
