/**
 * OFFICIAL-F7-APPROVED-CHAT-BUBBLES
 * Shared literal bubble component CSS — single source with bubble-reference-proof v23.
 * Bubble rules only: no proof page background, layout, DM, tables, or typing activation.
 */

@import url("https://fonts.googleapis.com/css2?family=Barlow:wght@300;400;500;600&display=swap");

:root {
  --font-body: "Barlow", sans-serif;

  /* ── sizing formula tokens (single source) ── */
  --bubble-font-size: 16px;
  --bubble-line-height: 1.2;
  --bubble-line-unit: calc(var(--bubble-font-size) * var(--bubble-line-height));
  --bubble-py: 6px;
  --bubble-px: 12px;
  --bubble-text-inset-x: 3px;

  /* optical vertical center: Barlow glyphs sit low in line box (bbox was symmetric) */
  --bubble-text-optical-y: -1px;

  /* one-line floor: py + line-unit + py (31.2px; rounds to ~32px rendered) */
  --bubble-one-line-min-height: calc(
    var(--bubble-py) + var(--bubble-line-unit) + var(--bubble-py)
  );
  --bubble-multiline-min-height: var(--bubble-one-line-min-height);

  --bubble-author-line-h: var(--bubble-line-unit);
  --bubble-with-author-body-h: calc(var(--bubble-author-line-h) + var(--bubble-line-unit));
  --bubble-with-author-min-height: calc(
    2 * var(--bubble-py) + var(--bubble-with-author-body-h)
  );

  /* ── time pocket (height-independent, horizontal reserve only) ── */
  --bubble-time-font-size: 11px;
  --bubble-time-color: rgba(255, 255, 255, 0.28);
  --bubble-time-pocket-width: 38px;
  --bubble-time-pocket-w: var(--bubble-time-pocket-width);
  --bubble-text-safe-right: var(--bubble-time-pocket-width);
  --bubble-time-right: 10px;
  --bubble-time-bottom: 5px;

  /* outgoing compact */
  --bubble-outgoing-pocket-width: 34px;
  --bubble-outgoing-pocket-w: var(--bubble-outgoing-pocket-width);
  --bubble-outgoing-px: 11px;
  --bubble-outgoing-text-inset-x: 2px;
  --bubble-short-min-width: 56px;

  --bubble-min-width: 68px;
  --bubble-max-width: 75%;
  --bubble-gap: 9px;
  --bubble-border-radius: 16px;
  --bubble-tail-radius: 4px;

  /* legacy aliases */
  --bubble-py-compact: var(--bubble-py);

  /* typing token (proof parity; typing not activated in Common gate) */
  --typing-indicator-py: calc(((var(--bubble-py) * 2 + 5px) * 1.44 - 5px) / 2);

  /* ── v20 emoji badge +5% overlap (DOM intersection ~44%) ── */
  --emoji-badge-size: 18px;
  --emoji-badge-overlap-x: 12px;
  --emoji-badge-overlap-y: 10px;
  --emoji-badge-overlap-x-out: 10px;
  --emoji-badge-overlap-y-out: 12px;
  --emoji-badge-rotate-in: -5deg;
  --emoji-badge-rotate-out: 5deg;
  --bubble-proof-author-sample-min-width: 236px;
  --bubble-emoji-badge-size: var(--emoji-badge-size);
}

/* ── bubble shell (padding on .bubble-inner only — formula-driven heights) ── */
.bubble {
  max-width: var(--bubble-max-width);
  min-width: var(--bubble-min-width);
  width: fit-content;
  padding: 0;
  font-size: var(--bubble-font-size);
  line-height: var(--bubble-line-height);
  font-weight: 300;
  font-family: var(--font-body);
  color: #ffffff;
  position: relative;
  background: rgba(255, 255, 255, 0.03);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow:
    0 2px 8px rgba(0, 0, 0, 0.2),
    inset 0 1px 1px rgba(255, 255, 255, 0.1),
    inset 0 0 20px rgba(0, 0, 0, 0.1);
  border: none;
  overflow: hidden;
  animation: bubbleIn 0.4s cubic-bezier(0.25, 0.8, 0.25, 1.2) forwards;
  opacity: 0;
  transform: translateY(20px) scale(0.95);
  filter: blur(4px);
  cursor: default;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  caret-color: transparent;
  --bl-x: 50%;
  --bl-y: 50%;
  --bl-opacity: 0;
  display: block;
}

.bubble::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  padding: 1px;
  background: linear-gradient(
    180deg,
    rgba(255, 255, 255, 0.35) 0%,
    rgba(255, 255, 255, 0.15) 20%,
    rgba(255, 255, 255, 0.03) 40%,
    rgba(255, 255, 255, 0.03) 60%,
    rgba(255, 255, 255, 0.15) 80%,
    rgba(255, 255, 255, 0.35) 100%
  );
  -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  pointer-events: none;
  z-index: 2;
}

.bubble::after {
  content: "";
  position: absolute;
  width: 180px;
  height: 180px;
  border-radius: 50%;
  background: radial-gradient(
    circle,
    rgba(255, 255, 255, 0.15) 0%,
    rgba(255, 255, 255, 0.06) 30%,
    rgba(255, 255, 255, 0.01) 60%,
    transparent 100%
  );
  left: var(--bl-x);
  top: var(--bl-y);
  transform: translate(-50%, -50%);
  opacity: var(--bl-opacity);
  pointer-events: none;
  z-index: 1;
}

.bubble.incoming {
  align-self: flex-start;
  border-radius:
    var(--bubble-border-radius)
    var(--bubble-border-radius)
    var(--bubble-border-radius)
    var(--bubble-tail-radius);
  margin-right: auto;
}

.bubble.outgoing {
  align-self: flex-end;
  --bubble-text-safe-right: var(--bubble-outgoing-pocket-width);
  --bubble-time-pocket-w: var(--bubble-outgoing-pocket-width);
  --bubble-time-right: 9px;
  border-radius:
    var(--bubble-border-radius)
    var(--bubble-border-radius)
    var(--bubble-tail-radius)
    var(--bubble-border-radius);
  margin-left: auto;
  background: rgba(255, 255, 255, 0.05);
  box-shadow:
    0 2px 8px rgba(0, 0, 0, 0.2),
    inset 0 1px 1px rgba(255, 255, 255, 0.15),
    inset 0 0 20px rgba(0, 0, 0, 0.1);
}

.bubble.outgoing .bubble-inner {
  padding-left: calc(var(--bubble-outgoing-px) + var(--bubble-outgoing-text-inset-x));
  padding-right: calc(var(--bubble-outgoing-px) + var(--bubble-outgoing-pocket-width));
}

/* ── sizing tiers (formula: py + line-unit × lines + py) ── */
.bubble.bubble--one-line {
  height: auto;
  min-height: var(--bubble-one-line-min-height);
  max-height: none;
}

.bubble.bubble--one-line .bubble-inner {
  min-height: var(--bubble-one-line-min-height);
  height: auto;
  max-height: none;
  align-items: center;
  padding:
    var(--bubble-py)
    calc(var(--bubble-px) + var(--bubble-time-pocket-w))
    var(--bubble-py)
    calc(var(--bubble-px) + var(--bubble-text-inset-x));
}

.bubble.bubble--one-line .bubble-text-body {
  justify-content: center;
  align-self: stretch;
  min-height: var(--bubble-line-unit);
}

.bubble.bubble--two-line,
.bubble.bubble--multi-line {
  height: auto;
  min-height: var(--bubble-multiline-min-height);
  max-height: none;
}

.bubble.bubble--two-line .bubble-inner,
.bubble.bubble--multi-line .bubble-inner {
  height: auto;
  min-height: auto;
  max-height: none;
  align-items: center;
  padding:
    var(--bubble-py)
    calc(var(--bubble-px) + var(--bubble-text-safe-right))
    var(--bubble-py)
    calc(var(--bubble-px) + var(--bubble-text-inset-x));
}

.bubble.bubble--two-line .bubble-text-body,
.bubble.bubble--multi-line .bubble-text-body {
  justify-content: center;
  align-self: stretch;
}

.bubble.bubble--with-author {
  height: auto;
  min-height: var(--bubble-with-author-min-height);
  max-height: none;
}

.bubble.bubble--with-author .bubble-inner {
  height: auto;
  min-height: auto;
  max-height: none;
  align-items: center;
}

.bubble.bubble--short {
  min-width: var(--bubble-short-min-width);
  width: fit-content;
}

/* ── inner layout: time out of flow; shared vertical center ── */
.bubble-inner {
  position: relative;
  box-sizing: border-box;
  width: 100%;
  min-width: 0;
  display: flex;
  align-items: center;
  padding:
    var(--bubble-py)
    calc(var(--bubble-px) + var(--bubble-text-safe-right))
    var(--bubble-py)
    calc(var(--bubble-px) + var(--bubble-text-inset-x));
  z-index: 3;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.bubble-text-body {
  flex: 1 1 auto;
  min-width: 0;
  width: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-self: stretch;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.bubble .msg-text {
  display: block;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  line-height: var(--bubble-line-unit);
  transform: translateY(var(--bubble-text-optical-y));
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  caret-color: transparent;
}

.bubble .time {
  position: absolute;
  right: var(--bubble-time-right);
  bottom: var(--bubble-time-bottom);
  font-size: var(--bubble-time-font-size);
  font-weight: 400;
  color: var(--bubble-time-color);
  line-height: 1;
  white-space: nowrap;
  z-index: 4;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  pointer-events: none;
  height: var(--bubble-time-font-size);
  margin: 0;
  padding: 0;
}

@keyframes bubbleIn {
  0% { opacity: 0; transform: translateY(20px) scale(0.95); filter: blur(4px); }
  60% { opacity: 1; filter: blur(0px); }
  100% { opacity: 1; transform: translateY(0) scale(1); filter: blur(0px); }
}

/* ── typing indicator (proof v23 visual — single source for proof route + live Common) ── */
.typing-indicator {
  align-self: flex-start;
  display: flex;
  gap: 3px;
  padding: var(--typing-indicator-py) var(--bubble-px);
  border-radius:
    var(--bubble-border-radius)
    var(--bubble-border-radius)
    var(--bubble-border-radius)
    var(--bubble-tail-radius);
  background: rgba(255, 255, 255, 0.03);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow: inset 0 1px 1px rgba(255, 255, 255, 0.1), 0 2px 8px rgba(0, 0, 0, 0.2);
  position: relative;
  overflow: hidden;
  animation: bubbleIn 0.3s ease forwards;
  cursor: default;
  --bl-x: 50%;
  --bl-y: 50%;
  --bl-opacity: 0;
}
.typing-indicator::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  padding: 1px;
  background: linear-gradient(
    180deg,
    rgba(255, 255, 255, 0.35) 0%,
    rgba(255, 255, 255, 0.15) 20%,
    rgba(255, 255, 255, 0.03) 40%,
    rgba(255, 255, 255, 0.03) 60%,
    rgba(255, 255, 255, 0.15) 80%,
    rgba(255, 255, 255, 0.35) 100%
  );
  -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  pointer-events: none;
  z-index: 2;
}
.typing-indicator::after {
  content: "";
  position: absolute;
  width: 180px;
  height: 180px;
  border-radius: 50%;
  background: radial-gradient(
    circle,
    rgba(255, 255, 255, 0.15) 0%,
    rgba(255, 255, 255, 0.06) 30%,
    rgba(255, 255, 255, 0.01) 60%,
    transparent 100%
  );
  left: var(--bl-x);
  top: var(--bl-y);
  transform: translate(-50%, -50%);
  opacity: var(--bl-opacity);
  pointer-events: none;
  z-index: 1;
  transition: opacity 0.15s ease;
}
.typing-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.5);
  animation: typingBounce 1.4s infinite ease-in-out;
  position: relative;
  z-index: 3;
}
.typing-dot:nth-child(2) {
  animation-delay: 0.2s;
}
.typing-dot:nth-child(3) {
  animation-delay: 0.4s;
}
@keyframes typingBounce {
  0%,
  60%,
  100% {
    transform: translateY(0);
    opacity: 0.4;
  }
  30% {
    transform: translateY(-4px);
    opacity: 1;
  }
}

.bubble-proof-row .typing-indicator {
  flex: 0 0 auto;
}

#f7-app-root .clean-chat-page.clean-common-page .common-proof-messages-area .bubble-proof-row.common-typing-exit {
  animation: commonTypingFadeOut 0.3s ease forwards;
  pointer-events: none;
}

@keyframes commonTypingFadeOut {
  from {
    opacity: 1;
    transform: translateY(0);
  }
  to {
    opacity: 0;
    transform: translateY(8px);
  }
}

.f7-bubble-reference-proof-page.bubble-proof-static .bubble,
#f7-app-root .clean-chat-page.clean-common-page .clean-chat-messages .bubble,
#f7-app-root .clean-chat-page.clean-common-page .common-proof-messages-area .bubble {
  animation: none;
  opacity: 1;
  transform: none;
  filter: none;
}

#f7-app-root .clean-chat-page.clean-common-page .common-proof-messages-area .bubble.bubble--appear {
  animation: bubbleIn 0.4s cubic-bezier(0.25, 0.8, 0.25, 1.2) forwards;
  opacity: 0;
  transform: translateY(20px) scale(0.95);
  filter: blur(4px);
}

.bubble-proof-common-author {
  display: block;
  font-size: var(--bubble-font-size);
  font-weight: 600;
  color: rgba(255, 160, 80, 0.85);
  margin-bottom: 2px;
  line-height: var(--bubble-line-unit);
  min-height: var(--bubble-author-line-h);
  flex-shrink: 0;
  white-space: nowrap;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.bubble-proof-common-author-zone {
  font-size: calc(var(--bubble-font-size) - 2px);
  font-weight: 400;
}

/* Badge on .bubble corner — overlap via calc(overlap - size), not full outside translate */
.bubble.bubble--emoji-badge {
  overflow: visible;
}

.bubble.bubble--emoji-badge .bubble-proof-emoji-badge {
  position: absolute;
  z-index: 6;
  font-size: var(--emoji-badge-size);
  line-height: 1;
  filter: drop-shadow(0 0.5px 1px rgba(0, 0, 0, 0.5));
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  pointer-events: none;
}

.bubble.incoming.bubble--emoji-badge .bubble-proof-emoji-badge {
  top: calc(var(--emoji-badge-overlap-y) - var(--emoji-badge-size));
  right: calc(var(--emoji-badge-overlap-x) - var(--emoji-badge-size));
  left: auto;
  transform-origin: 100% 100%;
  transform: rotate(var(--emoji-badge-rotate-in));
}

.bubble.outgoing.bubble--emoji-badge .bubble-proof-emoji-badge {
  top: calc(var(--emoji-badge-overlap-y-out) - var(--emoji-badge-size));
  left: calc(var(--emoji-badge-overlap-x-out) - var(--emoji-badge-size));
  right: auto;
  transform-origin: 0% 100%;
  transform: rotate(var(--emoji-badge-rotate-out));
}
