@use "../base/var";
@use "../base/color";
@use "../base/highlight";

[part~="wy-messages"] {
  padding: var.default(--wy-message-padding);
  flex: 1 1 100%;
  display: flex;
  flex-direction: column;
}

[part~="wy-message-placeholder"] {
  opacity: 0.5;
}

[part~="wy-message-date-separator"] {
  font-size: var.default(--wy-font-size-xs);
  pointer-events: none;
  position: sticky;
  display: block;
  top: calc(#{var.default(--wy-padding-lg)} + var(--wy-component-offset-top, 0px));
  z-index: 10;
  align-self: center;
  justify-self: center;
  margin: var.default(--wy-padding);
  background: color.token(--wy-surface-container-high);
  color: color.token(--wy-on-surface);
  padding: var.default(--wy-padding-sm);
  border-radius: var.default(--wy-border-radius-sm);
}

[part~="wy-message"] {
  --wy-component-background-color: #{color.token(--wy-surface-container)};
  --wy-component-color: #{color.token(--wy-on-surface)};

  display: flex;
  flex-direction: row;
  align-items: flex-start;
  margin-bottom: calc(var.default(--wy-padding) + 0.5 * var.default(--wy-button-size)); // Account for reaction button
  scroll-margin-block: 6rem;

  @include highlight.flash;
}

// centred rather than inline: the row mixes text with icons (the report flag, and the blocked marker in groups), and
// an icon renders as a flex box that will not sit on the text baseline on its own.
[part~="wy-message-meta"] {
  display: flex;
  align-items: center;
  gap: var.default(--wy-gap-sm);
  font-size: var.default(--wy-font-size-xs);
  margin: 0 0 calc(0.5 * var.default(--wy-gap)) calc(0.5 * var.default(--wy-gap));
  color: color.token(--wy-on-surface-variant);
}

// revealed by hovering the meta row rather than the whole message, so the flag appears with the name and timestamp it
// sits beside instead of whenever the pointer is anywhere over the text.
//
// NOTE: a plain span wrapping the icon, not the icon itself. wy-icon sets `display: contents` on its host, so the host
// generates no box and opacity on it is ignored entirely -- the flag would simply always show. The span also carries
// the colour and the title.
[part~="wy-message-report"] {
  display: inline-flex;
  flex: 0 0 auto;
  opacity: 0;
  cursor: pointer;
  color: color.token(--wy-on-surface-variant);
  transition: opacity var.default(--wy-transition-fast);

  // the icon is 14px, well under the 24px WCAG 2.5.8 asks for, and it sits right beside the timestamp. The padding
  // makes the target without moving anything: the negative margin takes the same space back out of the meta row's
  // flex layout, so the gap either side is unchanged.
  padding: var.wy-rem(0.3125);
  margin: var.wy-rem(-0.3125);

  [part~="wy-message-meta"]:hover &,
  &:focus-visible {
    opacity: 1;
  }

  // Touch devices have no hover, so there would be no way to reach the flag. `any-pointer`, not `hover`, because
  // `hover` describes only the *primary* input: on a touch laptop or a tablet with a trackpad the mouse is primary and
  // reports `hover: hover`, leaving the touchscreen with no way in. `any-hover: none` fails the same way, since the
  // mouse there can hover. `any-pointer: coarse` is true whenever any attached input is touch, which is the question.
  @media (any-pointer: coarse) {
    opacity: 1;
  }
}

[part~="wy-message-report-reported"] {
  // always visible rather than hover-only -- the filled icon carries the state, so the colour stays as it is.
  // Wins over the hover rule above by coming later with equal specificity.
  opacity: 1;
  cursor: default;
}

// a held-back message is dimmed whole -- avatar, name, time and the notice -- so it reads as set aside rather than as
// something to read. Dimmed piece by piece rather than on the message itself, since opacity on an ancestor cannot be
// undone further down, and the way out has to stay at full strength.
[part~="wy-message-blocked"] {
  [part~="wy-message-author"],
  [part~="wy-message-meta"],
  [part~="wy-message-bubble-section"] {
    opacity: var.default(--wy-opacity-disabled);
  }
}


[part~="wy-message-bubble"] {
  background-color: var(--wy-component-background-color);
  color: var(--wy-component-color);

  border-radius: #{var.default(--wy-border-radius)};
  display: flex; //inline-block;
  flex-direction: column;
  padding: var.default(--wy-message-padding);
  gap: var.default(--wy-gap);
  max-width: min(var.wy-rem(32), calc(100% - 2 * var.default(--wy-message-padding)));
}

[part~="wy-message-bubble-section"] {
  // message section (images, attachments, embeds etc.)
  flex: 1 1 100%;
  display: block;
  border-radius: var.default(--wy-border-radius-sm);
  clip-path: border-box;
}

[part~="wy-message-author"] {
  // Match .wy-message-meta positioning
  font-size: var.default(--wy-font-size-xs);
  margin: calc(1lh + 0.5 * var.default(--wy-gap)) var.wy-rem(0.5) 0 0;
}

[part~="wy-message-content"] {
  display: flex;
  flex-direction: column;
  width: 100%;
  align-items: flex-start;
  flex-wrap: wrap;
  min-width: 0;
  position: relative; // so that we can position reactions
}

// override some styles for message by ai agents
[part~="wy-message-agent"] {
  --wy-component-background-color: #{color.token(--wy-tertiary-container)};
  --wy-component-color: #{color.token(--wy-on-tertiary-container)};
}

// override some styles for message by current user
[part~="wy-message-me"] {
  margin-right: 0;
  margin-left: var.wy-rem(2.5);
  align-items: flex-end;
  --wy-component-background-color: #{color.token(--wy-secondary-container)};
  --wy-component-color: #{color.token(--wy-on-secondary-container)};

  [part~="wy-message-meta"] {
    margin: 0 calc(0.5 * var.default(--wy-gap)) calc(0.5 * var.default(--wy-gap)) 0;
  }

  [part~="wy-message-content"] {
    align-items: flex-end;
  }
}

// override some styles for message that contains only emoji
[part~="wy-message-bubble-emoji"] {
  background: none;
  padding: 0 0 var.default(--wy-message-padding);
}

// message status indicator (sending, sent, delivered, read)
[part~="wy-message-seenby"] {
  display: flex;
  gap: var.default(--wy-gap-sm);
  height: var.wy-rem(1.125); // same height as avatar (prevents layout change when readby indicators are updated)
  justify-content: flex-end;
  margin-top: var.wy-rem(-0.125);
}

// The one-to-one header avatar opens the other person's profile card, so it needs to read as clickable. Groups get no
// such treatment -- a group avatar is not one person, so the part is never set there.
[part~="wy-avatar-interactive"] {
  cursor: pointer;
  border-radius: 50%;

  &:focus-visible {
    outline: var.wy-rem(0.125) solid color.token(--wy-primary);
    outline-offset: var.wy-rem(0.125);
  }
}

// notice replacing the messages in a blocked private chat -- a state of the conversation, not something someone said.
[part~="wy-conversation-blocked"] {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var.default(--wy-gap-sm);
  padding: var.default(--wy-padding);
  text-align: center;
  max-width: var.wy-rem(30);
}

[part~="wy-conversation-blocked-title"] {
  font-weight: var.default(--wy-font-weight-bold);
  margin: var.default(--wy-gap-sm) 0;
}

[part~="wy-conversation-blocked-text"] {
  color: color.token(--wy-on-surface-variant);
  margin-top: 0;
}

