/* ================================================
   MESSAGES
   ================================================ */

.antimanual-msg {
  display: flex;
  align-items: start;
  margin-bottom: 8px;

  &.bot {
    margin-bottom: 4px;
  }
  &.system {
    position: relative;
    justify-content: center;
    width: 100%;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='20' viewBox='0 0 40 20'%3E%3Cpath d='M0 10 Q10 0 20 10 T40 10' stroke='%23aaadaf' stroke-width='3' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
    background-repeat: repeat-x;
    background-position: left bottom;
    background-size:8px 22px;

    .msg-content {
      color: var(--black_500) !important;
      padding: 0 4px;
      background-color: #fff;
    }
    &::after{
      content: '';
      position: absolute;
      left: 0;
      top: 0;
      bottom: 0;
      right: 0;
      background: linear-gradient(
        to right,
        #fff 0%,
        transparent 30%,
        transparent 70%,
        #fff 100%
      );
      opacity: 0.9;
    }
  }
  &.loading-message{
    .msg-content {
      background-color: transparent;
      padding: 0;
    }
  }
  .msg-content {
    padding: 8px 12px;
    margin: 0;
    font-size: var(--antimanual_font_size, 14px);
    overflow-x: auto;
    line-height: 1.5;

    &:has(.antimanual-escalation-card) {
      padding: 1px;
    }

    *:first-child {
      margin-top: 0;
    }

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

    pre{
      background-color: #fff;
      margin-bottom: 10px;
    }
  }

  /* Bot Messages */
  &.bot {
    justify-content: start;

    .msg-content {
      border-radius: 16px 16px 16px 4px;
    }
    .bot-profile-icon {
      border-radius: 50%;
      margin-right: 8px;
      width: 28px;
      height: 28px;
    }

    .antimanual-response {
      min-width: 0;
      overflow: hidden;

      /* Name of the agent who sent a live chat reply (distinguishes multiple
         agents replying on the same conversation). */
      .antimanual-agent-name {
        font-size: 12px;
        font-weight: 600;
        color: var(--black_500, #6b7280);
        margin-bottom: 4px;
        line-height: 1.2;
        overflow-wrap: anywhere;
      }

      .msg-content {
        color: var(--black_900);
        background-color: var(--black_25);
        max-width: unset;
        overflow-wrap: anywhere;
        word-break: break-word;
      }
    }

    &.no-avatar .bot-profile-icon {
      display: none;
    }
  }

  /* User Messages */
  &:last-child:not(.placeholder) {
     &.user {
      animation: antimanual-slide-in-right 0.3s ease-out;
     }
      &.bot {
      animation: antimanual-slide-in-left 0.3s ease-out;
     }
  }
  &.user {
    justify-content: flex-end;
    margin-bottom: 12px;
    .msg-content {
      color: var(--black_900);
      background-color:  color-mix(
        in srgb,
        var(--antimanual_primary_color) 30%,
        transparent
      );
      max-width: 100%;
      border-radius: 16px 4px 16px 16px;
    }

    .antimanual-msg-timestamp {
      display: block;
      margin-top: 4px;
      text-align: right;
      opacity: 0.7;
      line-height: 1;
    }
  }

  /* Placeholder Messages (hidden by default) */
  &.placeholder {
    display: none;
  }

  /* Timestamp (hover to reveal on bot messages) */
  .antimanual-msg-timestamp {
    font-size: 11px;
    color: var(--black_400, #9ca3af);
    opacity: 0;
    transition: opacity 0.2s ease;
    white-space: nowrap;
  }

  &:hover .antimanual-msg-timestamp {
    opacity: 1;
  }

  /* Actions (hover to reveal) */
  &:hover .antimanual-msg-actions {
    opacity: 1;
  }

  /* Chat-bubble friendly typography — compact, native chatbot feel.
   Sized in em so it inherits the message's base font-size. */
.atml-msg-html {
    line-height: 1.5;
    color: var(--black_800);
    word-wrap: break-word;
    overflow-wrap: anywhere;

    /* Trim outer whitespace so the bubble hugs the content */
    > *:first-child { margin-top: 0; }
    > *:last-child  { margin-bottom: 0; }

    p {
        margin: 0.45em 0;
    }

    h1, h2, h3, h4, h5, h6 {
        margin: 0.7em 0 0.25em;
        font-weight: 600;
        line-height: 1.3;
        color: var(--black_900);
        border: 0;
        padding: 0;

        &:first-child { margin-top: 0; }
    }

    h1 { font-size: 1.08em; }
    h2 { font-size: 1.05em; }
    h3 { font-size: 1em; color: var(--black_700); }
    h4, h5, h6 { font-size: 0.95em; color: var(--black_700); }

    strong { font-weight: 600; color: var(--black_900); }
    em     { font-style: italic; color: var(--black_700); }

    a {
        color: var(--antimanual_primary_color);
        text-decoration: underline;
        text-decoration-thickness: 1px;
        text-underline-offset: 2px;
        transition: opacity 0.15s ease;
        word-break: break-word;

        &:hover { opacity: 0.75; }
    }

    /* Inline code */
    code {
        background: var(--black_50);
        padding: 1px 5px;
        border-radius: 4px;
        font-family: ui-monospace, "SF Mono", "Fira Code", Menlo, Consolas, monospace;
        font-size: 0.87em;
        color: var(--black_900);
        word-break: break-word;
    }

    /* Block code */
    pre {
        background: var(--black_50);
        padding: 8px 10px;
        margin: 0.5em 0;
        border-radius: 6px;
        font-family: ui-monospace, "SF Mono", "Fira Code", Menlo, Consolas, monospace;
        font-size: 0.85em;
        line-height: 1.45;
        overflow-x: auto;

        code {
            background: transparent;
            padding: 0;
            border-radius: 0;
            font-size: 1em;
            color: inherit;
            white-space: pre;
        }
    }

    img {
        max-width: 100%;
        height: auto;
        border-radius: 6px;
        margin: 0.4em 0;
        display: block;
    }

    /* Lists — tight, no excess indent. padding-left holds bullets inside
       the bubble; margins are minimal. */
    ul, ol {
        margin: 0.35em 0;
        padding-left: 1.25em;
    }

    li {
        margin: 0.12em 0;
        line-height: 1.5;
        color: var(--black_800);

        > p { margin: 0; }

        ul, ol { margin: 0.15em 0; }
    }

    ul { list-style: disc; }
    ol { list-style: decimal; }

    /* Blockquote — soft accent rail, not a heavy quote */
    blockquote {
        margin: 0.5em 0;
        padding: 0.15em 0.75em;
        border-left: 2px solid var(--antimanual_primary_color);
        color: var(--black_600);
        background: transparent;
    }

    /* Horizontal rule — slim divider between thoughts */
    hr {
        border: 0;
        border-top: 1px solid var(--black_75);
        margin: 0.7em 0;
    }

    /* Tables — narrow bubbles can't hold wide tables, so let them scroll */
    table {
        display: block;
        max-width: 100%;
        overflow-x: auto;
        border-collapse: collapse;
        margin: 0.5em 0;
        font-size: 0.93em;

        th, td {
            padding: 4px 8px;
            border: 1px solid var(--black_75);
            text-align: left;
        }

        th {
            background: var(--black_25);
            font-weight: 600;
        }
    }
}
}

/* User Message Wrapper */
.antimanual-msg-user-wrapper {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  max-width: 85%;
}

.antimanual-live-chat-message-body {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.antimanual-live-chat-text {
  word-break: break-word;
}

.antimanual-live-chat-attachment {
  display: flex;
  flex-direction: column;
  gap: 6px;

  a {
    display: inline-flex;
    width: fit-content;
    max-width: min(240px, 100%);
    border-radius: 12px;
    overflow: hidden;
    border: 1px solid rgba(15, 23, 42, 0.08);
    background: var(--black_25);
  }

  img {
    display: block;
    max-width: 100%;
    max-height: 220px;
    object-fit: cover;
  }
}

.antimanual-live-chat-attachment-name {
  font-size: 11px;
  color: var(--black_600, #d6d9dc);
  word-break: break-all;
}

/* ================================================
   MESSAGE FOOTER (Sources, Actions, Timestamp)
   ================================================ */

.antimanual-msg-footer {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  margin-top: 2px;

  .sources {
    outline: none;
    border: none;
    background: transparent;
    color: var(--black_600, #4b5563);
    padding: 4px 10px;
    margin: 0;
    font-size: 12px;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 5px;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;

    &:hover {
      background: var(--black_100, #e5e7eb);
      color: var(--black_800, #1f2937);
    }

    .antimanual-icon.ea-arrow-down {
      width: 10px;
      transition: ease 0.3s transform;
    }

    &.expanded .antimanual-icon.ea-arrow-down {
      transform: rotate(180deg);
    }
  }
}

/* ================================================
   REFERENCES LIST
   ================================================ */

.antimanual-response .references {
  display: none;
  flex-direction: column;
  gap: 5px;
  margin-top: 5px;
  padding: 5px 10px;
  background: var(--black_50, #f9fafb);
  border-radius: 8px;
  border: 1px solid var(--black_100, #e5e7eb);
  width: 100%;

  a {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    text-decoration: none;
    font-size: 13px;
    color: var(--black_700, #374151);
    transition: all 0.2s ease;
    width: fit-content;

    &:hover {
      color: var(--antimanual_primary_color, #2563eb);
      text-decoration: underline;
      text-underline-offset: 2px;
    }

    .antimanual-icon {
      width: 14px;
      height: 22px;
      color: var(--black_400, #9ca3af);
      flex-shrink: 0;
    }

    .text {
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
      max-width: 240px;
    }
  }
}

/* ================================================
   MESSAGE ACTIONS (Copy, Feedback)
   ================================================ */

.antimanual-msg-actions {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.antimanual-msg-action-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  padding: 0;
  border: none;
  background: var(--black_50, #f9fafb);
  border-radius: 6px;
  color: var(--black_500, #6b7280);
  cursor: pointer;
  transition: all 0.2s ease;

  &:hover {
    background: var(--black_100, #e5e7eb);
    color: var(--black_700, #374151);
  }

  &.active {
    background: var(--antimanual_primary_color, #2563eb);
    color: #fff;
  }

  svg,
  .antimanual-icon {
    width: 12px;
    height: 12px;
  }
}

/* Copy Tooltip */
.antimanual-copy-tooltip {
  position: absolute;
  background: var(--black_800, #1f2937);
  color: #fff;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 11px;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transform: translateY(-4px);
  transition: all 0.2s ease;

  &.show {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Feedback Buttons */
.antimanual-feedback-btns {
  display: flex;
  gap: 4px;
}

.antimanual-feedback-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  padding: 0;
  border: none;
  background: transparent;
  border-radius: 4px;
  color: var(--black_400, #9ca3af);
  cursor: pointer;
  transition: all 0.2s ease;

  &:hover {
    background: var(--black_100, #e5e7eb);
  }

  &.liked {
    color: #10b981;
    background: rgba(16, 185, 129, 0.1);
  }

  &.disliked {
    color: #ef4444;
    background: rgba(239, 68, 68, 0.1);
  }

  svg {
    width: 12px;
    height: 12px;
  }
}
