/* ════════════════════════════════════════════════════════════════════════════
   CHAT — the one-to-one conversation screen and its sheets.
   ════════════════════════════════════════════════════════════════════════════ */

:root {
  --chat-mine:        #105240;
  --chat-mine-text:   #f2fff9;
  --chat-mine-meta:   rgba(242, 255, 249, 0.62);
  --chat-theirs:      #18221d;
  --chat-theirs-text: rgba(255, 255, 255, 0.94);
  --chat-meta:        rgba(255, 255, 255, 0.5);
  --chat-read:        #53bdeb;
  --chat-quote-bg:    rgba(0, 0, 0, 0.22);
  --chat-sheet:       #141c18;
  --chat-chip:        rgba(24, 34, 29, 0.92);
  --chat-accent:      #7bf0b4;
  --chat-danger:      #ef4444;
}

.light {
  --chat-mine:        #d4f8e4;
  --chat-mine-text:   #0b1a13;
  --chat-mine-meta:   rgba(11, 26, 19, 0.5);
  --chat-theirs:      #ffffff;
  --chat-theirs-text: #0b1a13;
  --chat-meta:        rgba(11, 26, 19, 0.45);
  --chat-read:        #1d8fe0;
  --chat-quote-bg:    rgba(8, 30, 20, 0.06);
  --chat-sheet:       #ffffff;
  --chat-chip:        rgba(255, 255, 255, 0.95);
  --chat-accent:      #1969dd;
}

.chat-screen {
  position: relative;
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 512px;
  margin: 0 auto;
  background:
    radial-gradient(120% 60% at 100% 0%, rgba(123, 240, 180, 0.05), transparent 60%),
    radial-gradient(120% 60% at 0% 100%, rgba(25, 105, 221, 0.05), transparent 60%),
    var(--color-void);
  overflow: hidden;
}

/* ── Header ──────────────────────────────────────────────────────────────── */
.chat-header {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) 12px 10px;
  border-bottom: 1px solid var(--row-border);
  background: var(--color-void);
  z-index: 20;
}

.chat-round-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-secondary);
  border: none;
  cursor: pointer;
  list-style: none;
  text-decoration: none;
}
.light .chat-round-btn { background: rgba(8, 18, 14, 0.05); }
.chat-round-btn.is-small { width: 30px; height: 30px; }
.chat-round-btn::-webkit-details-marker { display: none; }

.chat-who {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  text-decoration: none;
}
.chat-who-avatar {
  position: relative;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 800;
}
.chat-who-avatar img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }
.chat-online-dot {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: #22c55e;
  border: 2px solid var(--color-void);
}
.chat-online-dot[hidden] { display: none; }
.chat-who-text { min-width: 0; display: flex; flex-direction: column; }
.chat-who-name {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-muted-icon { color: var(--text-tertiary); flex-shrink: 0; }
.chat-muted-icon[hidden] { display: none; }
.chat-who-status {
  font-size: 12px;
  color: var(--text-tertiary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-height: 15px;
}
.chat-who-status.is-live { color: var(--chat-accent); font-weight: 600; }

.chat-menu { position: relative; flex-shrink: 0; }
.chat-menu > summary { list-style: none; }
.chat-menu-panel {
  position: absolute;
  top: 42px;
  right: 0;
  z-index: 40;
  min-width: 220px;
  padding: 6px 0;
  border-radius: 14px;
  background: var(--color-card);
  border: 1px solid var(--row-border);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
}
.chat-menu-panel.is-scrollable {
  max-height: calc(100dvh - 120px - env(safe-area-inset-bottom));
  overflow-y: auto;
  overscroll-behavior: contain;
}
.chat-menu-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 11px 16px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
  background: none;
  border: none;
  cursor: pointer;
  text-decoration: none;
}
.chat-menu-item:hover { background: var(--row-hover); }
.chat-menu-item.is-divided { border-top: 1px solid var(--row-border); margin-top: 4px; padding-top: 13px; }
.chat-menu-item.is-danger { color: var(--chat-danger); }
.chat-menu-report { padding: 10px 16px 6px; border-top: 1px solid var(--row-border); }

/* ── Search bar ──────────────────────────────────────────────────────────── */
.chat-search {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--row-border);
  background: var(--color-void);
  z-index: 15;
}
.chat-search[hidden] { display: none; }
.chat-search-input {
  flex: 1;
  min-width: 0;
  height: 36px;
  padding: 0 14px;
  border-radius: 18px;
  border: 1px solid var(--row-border);
  background: var(--color-surface);
  color: var(--text-primary);
  font-size: 16px;
  outline: none;
}
.chat-search-count { font-size: 12px; color: var(--text-tertiary); min-width: 34px; text-align: center; }
.chat-search-done { background: none; border: none; color: var(--chat-accent); font-size: 14px; font-weight: 600; cursor: pointer; padding: 6px; }

/* ── Shared-history teaser ───────────────────────────────────────────────── */
.chat-teaser {
  flex-shrink: 0;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 9px 14px;
  text-decoration: none;
  border-bottom: 1px solid var(--row-border);
  background: rgba(123, 240, 180, 0.05);
}
.chat-teaser-badge {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #7bf0b4 0%, #4aadc8 50%, #1969dd 100%);
  margin-top: 1px;
}
.chat-teaser-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.chat-teaser-story { font-size: 12.5px; color: var(--text-secondary); font-style: italic; line-height: 1.4; }
.chat-teaser-count { font-size: 11px; color: var(--text-tertiary); margin-top: 3px; font-weight: 600; }
.chat-teaser-chevron { color: var(--text-tertiary); flex-shrink: 0; margin-top: 4px; }
.chat-screen.is-typing-focus .chat-teaser { display: none; }

/* ── Scroll area ─────────────────────────────────────────────────────────── */
.chat-scroll {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 10px 10px 14px;
}
.chat-loader { display: flex; justify-content: center; padding: 10px 0; }
.chat-loader[hidden] { display: none; }
.chat-spinner {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2.5px solid var(--row-border);
  border-top-color: var(--chat-accent);
  animation: chat-spin 0.8s linear infinite;
}
@keyframes chat-spin { to { transform: rotate(360deg); } }

.chat-intro {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 18px 16px 12px;
  gap: 6px;
}
.chat-intro[hidden] { display: none; }
.chat-intro-avatar {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  font-weight: 900;
  overflow: hidden;
}
.chat-intro-avatar img { width: 100%; height: 100%; object-fit: cover; }
.chat-intro-name { font-size: 15px; font-weight: 700; color: var(--text-primary); }
.chat-intro-note {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  max-width: 300px;
  font-size: 11.5px;
  line-height: 1.4;
  color: var(--text-tertiary);
  background: var(--chat-chip);
  border: 1px solid var(--row-border);
  padding: 5px 10px;
  border-radius: 8px;
}
.chat-intro-hint { font-size: 13px; color: var(--text-tertiary); margin-top: 8px; }
.chat-starter {
  margin-top: 6px;
  padding: 10px 16px;
  border-radius: 16px;
  max-width: 280px;
  background: rgba(123, 240, 180, 0.12);
  border: 1px solid rgba(123, 240, 180, 0.28);
  color: var(--chat-accent);
  font-size: 13px;
  font-style: italic;
  line-height: 1.45;
  text-align: left;
  cursor: pointer;
}

.chat-messages { display: flex; flex-direction: column; }

.chat-day,
.chat-system {
  align-self: center;
  margin: 10px 0 6px;
  max-width: 85%;
  text-align: center;
}
.chat-day span,
.chat-system span {
  display: inline-block;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-secondary);
  background: var(--chat-chip);
  border: 1px solid var(--row-border);
  padding: 4px 10px;
  border-radius: 8px;
  line-height: 1.4;
}
.chat-day.is-sticky { position: sticky; top: 0; z-index: 5; }

.chat-unread-line {
  align-self: stretch;
  text-align: center;
  margin: 10px -10px 8px;
  padding: 4px 0;
  background: rgba(123, 240, 180, 0.08);
}
.chat-unread-line span { font-size: 12px; font-weight: 700; color: var(--chat-accent); }

/* ── A message row ───────────────────────────────────────────────────────── */
.chat-row {
  position: relative;
  display: flex;
  flex-direction: column;
  margin-top: 2px;
  touch-action: pan-y;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
.chat-row.is-mine { align-items: flex-end; }
.chat-row.is-theirs { align-items: flex-start; }
.chat-row.is-group-start { margin-top: 8px; }
.chat-row.has-reactions { margin-bottom: 16px; }
.chat-row.is-flash .chat-bubble { animation: chat-flash 1.4s ease; }
@keyframes chat-flash {
  0%, 60% { box-shadow: 0 0 0 3px rgba(123, 240, 180, 0.55); }
  100% { box-shadow: 0 0 0 0 rgba(123, 240, 180, 0); }
}
.chat-row.is-selected .chat-bubble { filter: brightness(1.15); }
.chat-row.is-match .chat-bubble { box-shadow: 0 0 0 2px rgba(250, 204, 21, 0.75); }

.chat-swipe-hint {
  position: absolute;
  left: -34px;
  top: 50%;
  width: 28px;
  height: 28px;
  margin-top: -14px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--chat-chip);
  color: var(--text-secondary);
  opacity: 0;
}

.chat-bubble {
  position: relative;
  max-width: min(78%, 360px);
  padding: 6px 8px 6px 10px;
  border-radius: 14px;
  font-size: 15px;
  line-height: 1.38;
  overflow-wrap: anywhere;
  word-break: break-word;
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.12);
}
.is-mine .chat-bubble { background: var(--chat-mine); color: var(--chat-mine-text); }
.is-theirs .chat-bubble { background: var(--chat-theirs); color: var(--chat-theirs-text); }
.light .is-theirs .chat-bubble { box-shadow: 0 1px 1.5px rgba(8, 18, 14, 0.12); }
.is-mine.is-group-start .chat-bubble { border-top-right-radius: 4px; }
.is-theirs.is-group-start .chat-bubble { border-top-left-radius: 4px; }

.chat-bubble.is-emoji { background: transparent !important; box-shadow: none; padding: 0 2px; }
.chat-bubble.is-emoji .chat-text { font-size: 44px; line-height: 1.15; }
.chat-bubble.is-emoji .chat-meta {
  float: none;
  display: inline-flex;
  margin: 0;
  padding: 1px 6px;
  border-radius: 8px;
  background: var(--chat-chip);
  color: var(--chat-meta);
}
.chat-bubble.is-visual { padding: 3px; }
.chat-bubble.is-visual .chat-meta {
  position: absolute;
  right: 8px;
  bottom: 7px;
  margin: 0;
  padding: 1px 6px;
  border-radius: 9px;
  color: #fff;
  background: rgba(0, 0, 0, 0.45);
}
.chat-bubble.is-visual .chat-meta .chat-ticks { color: #fff; }
.chat-bubble.is-deleted { font-style: italic; }
.chat-deleted { display: inline-flex; align-items: center; gap: 6px; opacity: 0.6; font-size: 14px; }

.chat-text { white-space: pre-wrap; }
.chat-text a { color: inherit; text-decoration: underline; text-underline-offset: 2px; }
.is-theirs .chat-text a { color: var(--chat-read); }
.chat-text code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.88em;
  padding: 1px 4px;
  border-radius: 4px;
  background: var(--chat-quote-bg);
}
.chat-text mark { background: rgba(250, 204, 21, 0.55); color: inherit; border-radius: 3px; }

.chat-forwarded {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  font-style: italic;
  opacity: 0.65;
  margin-bottom: 2px;
}

.chat-quote {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  width: 100%;
  min-width: 160px;
  margin: 2px 0 5px;
  padding: 5px 9px;
  border: none;
  border-left: 3.5px solid var(--chat-accent);
  border-radius: 7px;
  background: var(--chat-quote-bg);
  color: inherit;
  text-align: left;
  cursor: pointer;
}
.chat-quote-name { font-size: 12.5px; font-weight: 700; color: var(--chat-accent); }
.chat-quote-text {
  font-size: 13px;
  opacity: 0.75;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Time, edited, star and ticks float into the last line of text, the way
   WhatsApp tucks them in when there's room. */
.chat-meta {
  float: right;
  position: relative;
  bottom: -5px;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  margin: 4px 0 0 10px;
  font-size: 11px;
  line-height: 1;
  white-space: nowrap;
  color: var(--chat-meta);
}
.is-mine .chat-meta { color: var(--chat-mine-meta); }
.chat-meta-icon { flex-shrink: 0; }
.chat-star { display: none; }
.chat-row[data-starred="true"] .chat-star { display: inline; }
.chat-edited { font-style: italic; }

.chat-ticks { display: inline-flex; align-items: center; margin-left: 1px; }
.chat-ticks svg { display: none; }
.chat-row[data-status="pending"] .tick-pending { display: block; }
.chat-row[data-status="failed"] .tick-failed { display: block; color: var(--chat-danger); }
.chat-row[data-status="sent"] .tick-one { display: block; }
.chat-row[data-status="delivered"] .tick-two { display: block; }
.chat-row[data-status="read"] .tick-two { display: block; color: var(--chat-read); }
.chat-row[data-status="failed"] .chat-bubble { opacity: 0.75; }
.chat-retry {
  margin-top: 3px;
  font-size: 12px;
  font-weight: 600;
  color: var(--chat-danger);
  background: none;
  border: none;
  cursor: pointer;
}

/* ── Media grid ──────────────────────────────────────────────────────────── */
.chat-media {
  display: grid;
  gap: 3px;
  width: min(68vw, 290px);
  border-radius: 11px;
  overflow: hidden;
  margin-bottom: 3px;
}
.chat-media.count-1 { grid-template-columns: 1fr; }
.chat-media.count-2 { grid-template-columns: 1fr 1fr; }
.chat-media.count-3 { grid-template-columns: 1fr 1fr; }
.chat-media.count-3 > :first-child { grid-column: span 2; }
.chat-media.count-4 { grid-template-columns: 1fr 1fr; }
.chat-media-item {
  position: relative;
  display: block;
  aspect-ratio: 1;
  overflow: hidden;
  padding: 0;
  border: none;
  background: rgba(0, 0, 0, 0.25);
  cursor: pointer;
}
.chat-media.count-1 .chat-media-item { aspect-ratio: auto; max-height: 360px; min-height: 120px; }
.chat-media.count-3 > :first-child { aspect-ratio: 2 / 1; }
.chat-media-item.is-hidden { display: none; }
.chat-media-item img,
.chat-media-item video {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  pointer-events: auto;
}
.chat-media.count-1 .chat-media-item img,
.chat-media.count-1 .chat-media-item video { max-height: 360px; }
.chat-media-item video { pointer-events: none; }
.chat-play {
  position: absolute;
  inset: 0;
  margin: auto;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.5);
  padding-left: 3px;
}
.chat-media { position: relative; }
.chat-media-more {
  position: absolute;
  right: 0;
  bottom: 0;
  width: calc(50% - 1.5px);
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.5);
  color: #fff;
  font-size: 26px;
  font-weight: 700;
  pointer-events: none;
}
.chat-media.is-uploading .chat-media-item::after {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
}
.chat-progress {
  position: absolute;
  inset: 0;
  margin: auto;
  width: 46px;
  height: 46px;
  z-index: 2;
}

/* ── Voice note ──────────────────────────────────────────────────────────── */
.chat-voice { display: flex; align-items: center; gap: 8px; width: min(64vw, 250px); padding: 2px 0 4px; }
.chat-voice-play {
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  border-radius: 50%;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.14);
  color: inherit;
  cursor: pointer;
}
.light .chat-voice-play { background: rgba(8, 30, 20, 0.08); }
.chat-voice-play .icon-pause { display: none; }
.chat-voice.is-playing .icon-pause { display: block; }
.chat-voice.is-playing .icon-play { display: none; }
.chat-wave { flex: 1; min-width: 0; height: 28px; display: flex; align-items: center; gap: 1.5px; overflow: hidden; cursor: pointer; }
.chat-wave span { flex: 1; min-width: 1px; border-radius: 2px; background: currentColor; opacity: 0.35; }
.chat-wave span.is-played { opacity: 0.95; }
.chat-voice-time { flex-shrink: 0; font-size: 11.5px; opacity: 0.7; min-width: 32px; font-variant-numeric: tabular-nums; }
.chat-voice-speed {
  flex-shrink: 0;
  white-space: nowrap;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 6px;
  border-radius: 10px;
  border: none;
  background: rgba(255, 255, 255, 0.14);
  color: inherit;
  cursor: pointer;
}
.light .chat-voice-speed { background: rgba(8, 30, 20, 0.08); }

/* ── Document ────────────────────────────────────────────────────────────── */
.chat-file {
  display: flex;
  align-items: center;
  gap: 10px;
  width: min(64vw, 260px);
  padding: 8px;
  margin-bottom: 3px;
  border-radius: 9px;
  background: var(--chat-quote-bg);
  color: inherit;
  text-decoration: none;
}
.chat-file-icon {
  width: 36px;
  height: 42px;
  flex-shrink: 0;
  border-radius: 5px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 6px;
  font-size: 9px;
  font-weight: 800;
  color: #fff;
  background: linear-gradient(160deg, #4aadc8, #1969dd);
}
.chat-file-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.chat-file-name { font-size: 13.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-file-size { font-size: 11.5px; opacity: 0.65; }
.chat-file-download { opacity: 0.7; flex-shrink: 0; }

/* ── Location ────────────────────────────────────────────────────────────── */
.chat-location { display: block; width: min(64vw, 260px); color: inherit; text-decoration: none; margin-bottom: 3px; }
.chat-location-map {
  position: relative;
  display: block;
  height: 140px;
  border-radius: 9px;
  overflow: hidden;
  background: linear-gradient(135deg, #1d3b30, #183048);
}
.chat-location-map img { width: 100%; height: 100%; object-fit: cover; }
.chat-location-pin { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -90%); }
.chat-location-label { display: block; font-size: 13.5px; font-weight: 600; padding: 6px 2px 0; }

/* ── Contact card ────────────────────────────────────────────────────────── */
.chat-contact { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; width: min(64vw, 250px); padding: 4px 0; }
.chat-contact-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  flex-shrink: 0;
}
.chat-contact-avatar img { width: 100%; height: 100%; object-fit: cover; }
.chat-contact-name { flex: 1; font-size: 14px; font-weight: 700; min-width: 0; }
.chat-contact-action {
  flex-basis: 100%;
  text-align: center;
  padding: 8px 0 2px;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
  color: var(--chat-accent);
  font-size: 13.5px;
  font-weight: 600;
  text-decoration: none;
}
.is-mine .chat-contact-action { color: inherit; }

/* ── Link preview ────────────────────────────────────────────────────────── */
.chat-link-card {
  display: block;
  margin: 2px 0 5px;
  border-radius: 8px;
  overflow: hidden;
  background: var(--chat-quote-bg);
  color: inherit;
  text-decoration: none;
  max-width: 300px;
}
.chat-link-card img { display: block; width: 100%; max-height: 160px; object-fit: cover; }
.chat-link-text { display: flex; flex-direction: column; gap: 2px; padding: 7px 9px; }
.chat-link-title { font-size: 13.5px; font-weight: 700; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.chat-link-desc { font-size: 12.5px; opacity: 0.72; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.chat-link-site { font-size: 11.5px; opacity: 0.55; }

/* ── Reactions under a bubble ────────────────────────────────────────────── */
.chat-reactions {
  position: absolute;
  bottom: -17px;
  display: inline-flex;
  align-items: center;
  gap: 1px;
  padding: 2px 6px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.2;
  background: var(--chat-theirs);
  border: 1.5px solid var(--color-void);
  color: var(--text-secondary);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
  cursor: pointer;
  z-index: 2;
}
.chat-reactions { left: 12px; }
.chat-bubble.is-emoji .chat-reactions,
.chat-bubble.is-visual .chat-reactions { bottom: -16px; }
.chat-reactions-count { font-size: 11.5px; font-weight: 600; margin-left: 2px; }

/* ── Typing, jump, drop ──────────────────────────────────────────────────── */
.chat-typing {
  position: absolute;
  left: 12px;
  bottom: calc(var(--chat-composer-h, 64px) + 6px);
  display: flex;
  gap: 4px;
  padding: 11px 14px;
  border-radius: 16px;
  border-top-left-radius: 4px;
  background: var(--chat-theirs);
  z-index: 6;
}
.chat-typing[hidden] { display: none; }
.chat-typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-tertiary);
  animation: chat-dot 1.2s infinite ease-in-out;
}
.chat-typing span:nth-child(2) { animation-delay: 0.15s; }
.chat-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes chat-dot {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-4px); opacity: 1; }
}

.chat-jump {
  position: absolute;
  right: 14px;
  bottom: calc(var(--chat-composer-h, 64px) + 12px);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--row-border);
  background: var(--chat-sheet);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.3);
  cursor: pointer;
  z-index: 7;
}
.chat-jump[hidden] { display: none; }
.chat-jump-count {
  position: absolute;
  top: -7px;
  right: -3px;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border-radius: 10px;
  background: var(--chat-accent);
  color: #04120b;
  font-size: 11px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
}
.light .chat-jump-count { color: #fff; }
.chat-jump-count[hidden] { display: none; }

.chat-drop {
  position: absolute;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(6, 10, 8, 0.82);
  border: 3px dashed var(--chat-accent);
  border-radius: 16px;
  color: var(--chat-accent);
  font-size: 18px;
  font-weight: 700;
  pointer-events: none;
}
.chat-drop[hidden] { display: none; }

/* ── Composer ────────────────────────────────────────────────────────────── */
.chat-composer {
  flex-shrink: 0;
  padding: 6px 8px calc(env(safe-area-inset-bottom, 0px) + 8px);
  background: var(--color-void);
  border-top: 1px solid var(--row-border);
  z-index: 10;
}
.chat-context {
  display: flex;
  align-items: stretch;
  gap: 8px;
  margin: 2px 4px 6px;
  padding: 6px 8px;
  border-radius: 10px;
  background: var(--color-surface);
}
.chat-context[hidden] { display: none; }
.chat-context-bar { width: 3.5px; border-radius: 2px; background: var(--chat-accent); flex-shrink: 0; }
.chat-context-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.chat-context-title { font-size: 12.5px; font-weight: 700; color: var(--chat-accent); }
.chat-context-body { font-size: 13px; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-context-close { background: none; border: none; color: var(--text-tertiary); cursor: pointer; padding: 4px; align-self: center; }

.chat-compose-row { display: flex; align-items: flex-end; gap: 6px; }
.chat-compose-row[hidden] { display: none; }
.chat-icon-btn {
  width: 40px;
  height: 42px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
}
.chat-icon-btn.is-inline { width: 36px; height: 40px; }
.chat-icon-btn.is-danger { color: var(--chat-danger); }
.chat-input-shell {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: flex-end;
  min-height: 42px;
  padding-left: 14px;
  border-radius: 22px;
  background: var(--color-surface);
  border: 1px solid var(--row-border);
}
.chat-input {
  flex: 1;
  min-width: 0;
  resize: none;
  font-size: 16px;
  line-height: 1.35;
  padding: 10px 0;
  max-height: 140px;
  overflow-y: auto;
  color: var(--text-primary);
  background: transparent;
}
.chat-primary {
  position: relative;
  width: 42px;
  height: 42px;
  flex-shrink: 0;
  border-radius: 50%;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  background: linear-gradient(135deg, #7bf0b4 0%, #4aadc8 50%, #1969dd 100%);
  box-shadow: 0 4px 14px rgba(25, 105, 221, 0.35);
  cursor: pointer;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}
.chat-primary svg { display: none; }
.chat-primary .icon-mic { display: block; }
.chat-composer.has-text .chat-primary .icon-mic { display: none; }
.chat-composer.has-text .chat-primary .icon-send { display: block; }
.chat-composer.is-editing .chat-primary .icon-mic,
.chat-composer.is-editing .chat-primary .icon-send { display: none; }
.chat-composer.is-editing .chat-primary .icon-check { display: block; }
.chat-primary.is-send svg { display: block; }
.chat-composer.has-text .chat-input-shell .is-inline { display: none; }

.chat-recorder { display: flex; align-items: center; gap: 8px; min-height: 42px; }
.chat-recorder[hidden] { display: none; }
.chat-rec-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--chat-danger); animation: chat-blink 1s infinite; flex-shrink: 0; }
.chat-recorder.is-paused .chat-rec-dot { animation: none; opacity: 0.4; }
@keyframes chat-blink { 50% { opacity: 0.25; } }
.chat-rec-time { font-size: 15px; font-variant-numeric: tabular-nums; color: var(--text-primary); min-width: 40px; }
.chat-rec-wave { flex: 1; height: 28px; display: flex; align-items: center; justify-content: flex-end; gap: 2px; overflow: hidden; }
.chat-rec-wave span { width: 3px; flex-shrink: 0; border-radius: 2px; background: var(--text-secondary); }
.chat-recorder .icon-mic { display: none; }
.chat-recorder.is-paused .icon-mic { display: block; }
.chat-recorder.is-paused .icon-pause { display: none; }

/* ── Overlays: sheets, message menu, viewer, toast ───────────────────────── */
.chat-layer {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  background: rgba(0, 0, 0, 0.45);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
  animation: chat-fade 0.15s ease;
}
.chat-layer[hidden] { display: none; }
@keyframes chat-fade { from { opacity: 0; } }
@keyframes chat-rise { from { transform: translateY(24px); opacity: 0; } }
@keyframes chat-pop { from { transform: scale(0.92); opacity: 0; } }

.chat-sheet {
  width: 100%;
  max-width: 512px;
  max-height: 82dvh;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  border-radius: 18px 18px 0 0;
  background: var(--chat-sheet);
  color: var(--text-primary);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.35);
  animation: chat-rise 0.2s ease;
}
.chat-sheet-grip { width: 38px; height: 4px; border-radius: 2px; background: var(--row-border); margin: 8px auto 2px; flex-shrink: 0; }
.chat-sheet-head { display: flex; align-items: center; gap: 8px; padding: 8px 16px 10px; flex-shrink: 0; }
.chat-sheet-title { flex: 1; font-size: 16px; font-weight: 700; }
.chat-sheet-body { overflow-y: auto; padding: 0 8px 12px; }
.chat-sheet-note { font-size: 13px; color: var(--text-tertiary); padding: 0 16px 10px; line-height: 1.45; }
.chat-sheet-foot { display: flex; gap: 8px; padding: 10px 16px 14px; border-top: 1px solid var(--row-border); flex-shrink: 0; }

.chat-option {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  padding: 12px 10px;
  border: none;
  border-radius: 12px;
  background: none;
  color: var(--text-primary);
  font-size: 15px;
  text-align: left;
  cursor: pointer;
}
.chat-option:hover,
.chat-option:focus-visible { background: var(--row-hover); outline: none; }
.chat-option.is-danger { color: var(--chat-danger); }
.chat-option.is-checked::after { content: "✓"; margin-left: auto; color: var(--chat-accent); font-weight: 800; }
.chat-option-icon {
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 15px;
  font-weight: 800;
  overflow: hidden;
}
.chat-option-icon img { width: 100%; height: 100%; object-fit: cover; }
.chat-option-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.chat-option-sub { font-size: 12.5px; color: var(--text-tertiary); }
.chat-option input[type="checkbox"] { width: 20px; height: 20px; accent-color: #3fc88a; margin-left: auto; }

.chat-attach-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; padding: 6px 8px 14px; }
.chat-attach-grid .chat-option { flex-direction: column; gap: 8px; font-size: 12.5px; text-align: center; padding: 12px 4px; }
.chat-attach-grid .chat-option-icon { width: 54px; height: 54px; }

.chat-btn {
  flex: 1;
  height: 44px;
  border-radius: 22px;
  border: 1px solid var(--row-border);
  background: var(--color-surface);
  color: var(--text-primary);
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
}
.chat-btn.is-primary { border: none; color: #fff; background: linear-gradient(135deg, #7bf0b4 0%, #4aadc8 50%, #1969dd 100%); }
.chat-btn.is-danger { color: var(--chat-danger); }
.chat-btn:disabled { opacity: 0.45; cursor: default; }

/* Preview before sending photos or videos */
.chat-preview { flex: 1; display: flex; flex-direction: column; background: #000; color: #fff; animation: chat-fade 0.15s; padding-top: env(safe-area-inset-top, 0px); }
.chat-preview-top { display: flex; align-items: center; justify-content: space-between; padding: 10px 12px; }
.chat-preview-stage { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; padding: 8px; }
.chat-preview-stage img,
.chat-preview-stage video { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 6px; }
.chat-preview-strip { display: flex; gap: 6px; padding: 6px 12px; overflow-x: auto; }
.chat-preview-thumb { position: relative; width: 54px; height: 54px; flex-shrink: 0; border-radius: 8px; overflow: hidden; border: 2px solid transparent; padding: 0; background: #222; cursor: pointer; }
.chat-preview-thumb.is-active { border-color: #7bf0b4; }
.chat-preview-thumb img,
.chat-preview-thumb video { width: 100%; height: 100%; object-fit: cover; pointer-events: none; }
.chat-preview-thumb .chat-preview-remove { position: absolute; top: 1px; right: 1px; width: 18px; height: 18px; border-radius: 50%; background: rgba(0,0,0,0.7); color: #fff; font-size: 12px; line-height: 18px; text-align: center; }
.chat-preview-add { width: 54px; height: 54px; flex-shrink: 0; border-radius: 8px; border: 1.5px dashed rgba(255,255,255,0.4); background: none; color: #fff; font-size: 24px; cursor: pointer; }
.chat-preview-bar { display: flex; align-items: flex-end; gap: 8px; padding: 8px 10px calc(env(safe-area-inset-bottom, 0px) + 10px); }
.chat-preview-bar .chat-input-shell { background: #1b1b1b; border-color: #2a2a2a; padding-right: 10px; }
.chat-preview-bar .chat-input { color: #fff; }
.chat-preview-close { background: rgba(255,255,255,0.12); border: none; color: #fff; width: 36px; height: 36px; border-radius: 50%; cursor: pointer; font-size: 18px; }
.chat-preview-count { font-size: 13px; opacity: 0.7; }

/* Long-press menu: the reaction bar above, actions below */
.chat-layer.is-menu { justify-content: flex-start; background: rgba(0, 0, 0, 0.5); }
.chat-pop { position: absolute; display: flex; flex-direction: column; align-items: flex-start; gap: 8px; max-width: calc(100vw - 20px); animation: chat-pop 0.14s ease; }
.chat-pop.is-mine { align-items: flex-end; }
.chat-pop > .chat-react-bar, .chat-pop > .chat-action-list { width: 250px; }
.chat-pop-bubble { margin: 0; pointer-events: none; max-height: 40dvh; overflow: hidden; border-radius: 14px; }
.chat-pop-bubble .chat-bubble { max-width: calc(100vw - 20px) !important; }
.chat-react-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 5px 8px;
  border-radius: 28px;
  background: var(--chat-sheet);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}
.chat-react-bar button {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: none;
  background: none;
  font-size: 25px;
  line-height: 1;
  cursor: pointer;
  transition: transform 0.12s;
}
.chat-react-bar button:hover { transform: scale(1.2); }
.chat-react-bar button.is-mine { background: var(--row-hover); box-shadow: inset 0 0 0 1.5px var(--row-border); }
.chat-react-bar .chat-react-more { font-size: 20px; color: var(--text-secondary); background: var(--row-hover); }
.chat-action-list {
  display: flex;
  flex-direction: column;
  border-radius: 14px;
  overflow: hidden;
  background: var(--chat-sheet);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}
.chat-action {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 11px 16px;
  border: none;
  background: none;
  color: var(--text-primary);
  font-size: 15px;
  text-align: left;
  cursor: pointer;
}
.chat-action + .chat-action { border-top: 1px solid var(--row-border); }
.chat-action:hover { background: var(--row-hover); }
.chat-action.is-danger { color: var(--chat-danger); }
.chat-action svg { flex-shrink: 0; opacity: 0.85; }

.chat-emoji-grid { display: grid; grid-template-columns: repeat(8, 1fr); gap: 2px; padding: 4px 10px 14px; }
.chat-emoji-grid button { aspect-ratio: 1; border: none; background: none; font-size: 26px; border-radius: 10px; cursor: pointer; }
.chat-emoji-grid button:hover { background: var(--row-hover); }

.chat-info-row { display: flex; justify-content: space-between; gap: 12px; padding: 12px 16px; border-top: 1px solid var(--row-border); font-size: 14px; }
.chat-info-row span:last-child { color: var(--text-tertiary); text-align: right; }
.chat-info-bubble { padding: 4px 16px 14px; display: flex; flex-direction: column; align-items: flex-end; pointer-events: none; }

.chat-result {
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: 100%;
  padding: 10px 12px;
  border: none;
  border-radius: 12px;
  background: none;
  color: var(--text-primary);
  text-align: left;
  cursor: pointer;
}
.chat-result:hover { background: var(--row-hover); }
.chat-result-head { display: flex; justify-content: space-between; font-size: 12.5px; color: var(--text-tertiary); }
.chat-result-head strong { color: var(--chat-accent); font-weight: 700; }
.chat-result-body { font-size: 14px; line-height: 1.4; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.chat-empty { text-align: center; padding: 28px 16px; font-size: 14px; color: var(--text-tertiary); }

.chat-video {
  position: fixed;
  inset: 0;
  z-index: 260;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
}
.chat-video video { max-width: 100%; max-height: 100%; }
.chat-video-close {
  position: absolute;
  top: calc(env(safe-area-inset-top, 0px) + 12px);
  right: 14px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
  font-size: 20px;
  cursor: pointer;
}

.chat-toast {
  position: absolute;
  left: 50%;
  bottom: calc(var(--chat-composer-h, 64px) + 16px);
  transform: translateX(-50%);
  z-index: 300;
  max-width: 85%;
  padding: 9px 16px;
  border-radius: 20px;
  background: rgba(20, 28, 24, 0.95);
  color: #fff;
  font-size: 13.5px;
  font-weight: 600;
  text-align: center;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
  animation: chat-rise 0.18s ease;
}
.chat-toast[hidden] { display: none; }

/* ── Chats list ──────────────────────────────────────────────────────────── */
.chat-list-ticks { display: inline-flex; vertical-align: -2px; margin-right: 3px; color: var(--text-tertiary); }
.chat-list-ticks.is-read { color: var(--chat-read); }
.chat-list-typing { color: var(--chat-accent) !important; font-weight: 600; font-style: normal !important; }
.chat-list-badge {
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 800;
  color: #04120b;
  background: #7bf0b4;
}
.light .chat-list-badge { background: #1969dd; color: #fff; }
.chat-list-badge.is-muted { background: var(--text-tertiary); color: var(--color-void); }
.chat-list-badge.is-dot { min-width: 12px; width: 12px; height: 12px; padding: 0; }
.chat-list-icons { display: inline-flex; align-items: center; gap: 4px; color: var(--text-tertiary); }

.nav-unread-badge {
  position: absolute;
  top: -4px;
  right: -8px;
  min-width: 17px;
  height: 17px;
  padding: 0 4px;
  border-radius: 9px;
  background: #7bf0b4;
  color: #04120b;
  font-size: 10px;
  font-weight: 800;
  line-height: 17px;
  text-align: center;
}
.light .nav-unread-badge { background: #1969dd; color: #fff; }
.nav-unread-badge[hidden] { display: none; }

/* ── Media, links and docs page ──────────────────────────────────────────── */
.media-tabs > input { position: absolute; opacity: 0; pointer-events: none; }
.media-tab-bar { display: flex; border-bottom: 1px solid var(--row-border); position: sticky; top: 0; background: var(--color-void); z-index: 5; }
.media-tab-bar label { flex: 1; text-align: center; padding: 12px 0; font-size: 14px; font-weight: 600; color: var(--text-tertiary); cursor: pointer; border-bottom: 2.5px solid transparent; }
#tab-media:checked ~ .media-tab-bar label[for="tab-media"],
#tab-docs:checked ~ .media-tab-bar label[for="tab-docs"],
#tab-links:checked ~ .media-tab-bar label[for="tab-links"] { color: var(--chat-accent); border-bottom-color: var(--chat-accent); }
.media-panel { display: none; padding: 2px 0 40px; }
#tab-media:checked ~ [data-panel="media"],
#tab-docs:checked ~ [data-panel="docs"],
#tab-links:checked ~ [data-panel="links"] { display: block; }
.media-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 2px; }
.media-cell { position: relative; display: block; aspect-ratio: 1; overflow: hidden; background: var(--color-surface); }
.media-cell img, .media-cell video { width: 100%; height: 100%; object-fit: cover; display: block; }
.media-doc { display: flex; align-items: center; gap: 12px; padding: 10px 16px; border-bottom: 1px solid var(--row-border); color: var(--text-primary); text-decoration: none; }

@media (prefers-reduced-motion: reduce) {
  .chat-layer, .chat-sheet, .chat-pop, .chat-toast, .chat-typing span, .chat-rec-dot { animation: none !important; }
}
