/* ---------- Conversation ---------- */

.view-chat { position: relative; display: flex; flex-direction: column; min-height: 0; }

.thread {
  flex: 1;
  overflow-y: auto;
  padding: calc(var(--topbar-h) + 36px + env(safe-area-inset-top)) 16px
    calc(var(--composer-h) + var(--tabbar-h) + var(--tabbar-gap) + 36px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
}
.thread, .view-page { scrollbar-width: none; }
.thread::-webkit-scrollbar, .view-page::-webkit-scrollbar { display: none; }
.thread > * { width: 100%; max-width: var(--col); margin-left: auto; margin-right: auto; }

.stamp {
  text-align: center;
  margin: 28px auto 14px;
  font-size: 0.9375rem;
  font-weight: 500;
  color: var(--text-2);
}
.stamp:first-child { margin-top: 8px; }
.stamp .via { color: var(--text-3); font-weight: 400; }

.bubble {
  display: block;
  width: fit-content;
  max-width: min(var(--col), 92%);
  padding: 16px 20px;
  border-radius: 28px;
  font-size: 1.0625rem;
  line-height: 1.45;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.bubble + .bubble { margin-top: 6px; }
.bubble.out { background: var(--bubble); margin-right: auto; }
.bubble.in { background: var(--imessage-blue); color: #fff; margin-left: auto; margin-right: 0; }
.bubble.in + .bubble.out, .bubble.out + .bubble.in { margin-top: 14px; }

/* Put right-side bubbles on the right edge of the centered column. */
.thread > .bubble.in { margin-right: max(0px, calc((100% - var(--col)) / 2)); }
.thread > .bubble.out { margin-left: max(0px, calc((100% - var(--col)) / 2)); }

.typing {
  width: fit-content;
  margin-top: 14px;
  margin-left: max(0px, calc((100% - var(--col)) / 2)) !important;
  background: var(--bubble);
  border-radius: 28px;
  padding: 18px 20px;
  display: flex;
  gap: 5px;
}
.typing i { width: 8px; height: 8px; border-radius: 50%; background: var(--text-3); animation: blink 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: 0.15s; }
.typing i:nth-child(3) { animation-delay: 0.3s; }
@keyframes blink { 0%, 60%, 100% { opacity: 0.3; } 30% { opacity: 1; } }

.thread-empty { margin: auto; text-align: center; max-width: 320px; color: var(--text-2); line-height: 1.55; }
.thread-empty h2 { font-family: "Newsreader", Georgia, serif; font-size: 1.6rem; font-weight: 500; color: var(--text); margin-bottom: 8px; }

/* Composer floats over the thread so messages scroll behind it and the tab bar. */
.composer-wrap {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 4;
  padding: 0 16px calc(var(--tabbar-h) + var(--tabbar-gap) + 12px + env(safe-area-inset-bottom));
  pointer-events: none;
}
.composer-wrap > * { pointer-events: auto; }

.composer {
  max-width: var(--col);
  margin: 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 6px;
  min-height: 60px;
  padding: 8px 8px;
  border: 1px solid var(--border);
  border-radius: 30px;
  background: rgba(255, 255, 255, 0.82);
  -webkit-backdrop-filter: blur(20px) saturate(1.6);
  backdrop-filter: blur(20px) saturate(1.6);
  box-shadow: 0 4px 20px rgba(16, 17, 19, 0.08);
}
.composer:focus-within { border-color: #cfcfd4; }

.icon-btn {
  width: 42px;
  height: 42px;
  border: 0;
  border-radius: 50%;
  background: none;
  display: grid;
  place-items: center;
  color: var(--text);
  cursor: pointer;
  flex: none;
}
.icon-btn:hover { background: var(--muted); }
.icon-btn svg { width: 24px; height: 24px; }
#attach-btn svg { stroke-width: 2; }
#mic-btn { color: var(--text-2); }

.composer textarea {
  flex: 1;
  align-self: center;
  border: 0;
  outline: 0;
  resize: none;
  font: inherit;
  font-size: 1.0625rem;
  line-height: 1.4;
  min-height: 26px;
  max-height: 160px;
  padding: 2px 0;
  background: transparent;
}
.composer textarea::placeholder { color: var(--text-3); }

.send {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 0;
  background: var(--accent);
  color: #fff;
  display: grid;
  place-items: center;
  cursor: pointer;
  flex: none;
}
.send svg { width: 20px; height: 20px; stroke-width: 2.2; }

.composer-off { max-width: var(--col); margin: 0 auto; text-align: center; font-size: 0.9375rem; color: var(--text-2); padding: 12px 0; }

/* A link inside a bubble: a compact pill with the site name, never a long raw URL. */
.bubble-link {
  display: inline-flex; align-items: center; gap: 4px; max-width: 100%;
  padding: 2px 10px; border-radius: 999px; vertical-align: baseline;
  background: rgba(10, 132, 255, 0.10); color: var(--imessage-blue);
  font-weight: 500; text-decoration: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.bubble-link::after { content: "\203A"; font-weight: 600; }
.bubble.in .bubble-link { background: rgba(255, 255, 255, 0.22); color: #fff; }

/* ---------- Tapbacks and inline replies (iMessage-style) ---------- */

/* A round badge on the bubble's top corner: Christian's on your bubbles sits top-left (grey), yours
   on his sits top-right (blue), like Messages. A small dot is its tail. */
.bubble.has-tapback, .chart-msg.has-tapback { position: relative; }
.thread > .bubble.has-tapback { margin-top: 22px !important; }
.thread > .chart-msg.has-tapback { margin-top: 26px; }
.tapback {
  position: absolute;
  top: -20px;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  border: 2px solid var(--bg);
  pointer-events: none;
  animation: tapback-in 0.28s cubic-bezier(0.2, 1.4, 0.4, 1);
}
.tapback::after {
  content: "";
  position: absolute;
  bottom: -3px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: inherit;
  border: 2px solid var(--bg);
}
.bubble.in .tapback { left: -14px; }
.bubble.in .tapback::after { right: -1px; }
.bubble.out .tapback, .chart-msg .tapback { right: -14px; }
.bubble.out .tapback::after, .chart-msg .tapback::after { left: -1px; }
.chart-msg .tapback { top: -22px; right: 0; }
.tapback.theirs { background: var(--bubble); color: #8e8e93; }
.tapback.mine { background: var(--imessage-blue); color: #fff; }
@keyframes tapback-in { from { transform: scale(0.3); opacity: 0; } to { transform: scale(1); opacity: 1; } }

.tapback-glyph { display: grid; place-items: center; font-weight: 800; line-height: 0.9; letter-spacing: -0.02em; }
.tapback-glyph svg { width: 17px; height: 17px; fill: currentColor; display: block; }
.tapback-glyph.laugh { font-size: 0.5625rem; white-space: pre; text-align: center; }
.tapback-glyph.emphasize { font-size: 0.9375rem; letter-spacing: -0.12em; margin-left: -0.12em; }
.tapback-glyph.question { font-size: 1.0625rem; }
.tapback.theirs .tapback-glyph.love { color: #ff375f; }

/* The tapback row at the top of the long-press menu on Christian's replies. */
.menu-pop .tapback-row {
  display: flex;
  gap: 2px;
  padding: 2px 2px 6px;
  margin-bottom: 4px;
  border-bottom: 1px solid var(--border);
}
.menu-pop .tapback-row button {
  width: 38px;
  height: 38px;
  padding: 0;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: #8e8e93;
  text-align: center;
}
.menu-pop .tapback-row button.on { background: var(--imessage-blue); color: #fff; }
.menu-pop .tapback-row .tapback-glyph svg { width: 19px; height: 19px; }
.menu-pop .tapback-row .tapback-glyph.laugh { font-size: 0.625rem; }
.menu-pop .tapback-row .tapback-glyph.emphasize { font-size: 1.0625rem; }
.menu-pop .tapback-row .tapback-glyph.question { font-size: 1.1875rem; }

/* The quote above an inline reply: a grey bar and the first line of the message it answers. */
.reply-quote {
  display: flex;
  align-items: center;
  width: fit-content;
  max-width: min(var(--col), 78%);
  margin-top: 14px;
  padding: 2px 0 2px 10px;
  border: 0;
  border-left: 3px solid #d1d1d6;
  background: none;
  font: inherit;
  font-size: 0.875rem;
  line-height: 1.35;
  color: var(--text-2);
  text-align: left;
  cursor: pointer;
}
.reply-quote-text { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; min-width: 0; }
.reply-quote.from-in { border-left-color: rgba(10, 132, 255, 0.45); }
.thread > .reply-quote.out { margin-left: max(0px, calc((100% - var(--col)) / 2)); margin-right: auto; }
.thread > .reply-quote.in { margin-left: auto; margin-right: max(0px, calc((100% - var(--col)) / 2)); }
.thread > .reply-quote + .bubble, .thread > .reply-quote + .chart-msg, .thread > .reply-quote + .bubble-media { margin-top: 6px; }
.stamp + .reply-quote { margin-top: 2px; }

/* Jumped to from a quote. */
.bubble.flash, .chart-msg.flash { animation: bubble-flash 1.1s ease; }
@keyframes bubble-flash { 0%, 100% { filter: none; } 25% { filter: brightness(0.86); } }
