/* ═══════════════════════════════════════════════════════════
   Mano App — Unified Styles
   Requires: tokens.css + theme.css loaded first.
   Covers: shell, chat, canvas, input bar, profile, overlays.
   ═══════════════════════════════════════════════════════════ */

/* ── Segment Tabs (design system component) ───────────────── */
/* Glass pill container with equal-width tabs.                 */
/* Usage: .segment-tabs > .segment-tab (.active for selected)  */

.segment-tabs {
  display: flex;
  gap: var(--space-2);
  padding: var(--space-2);
  background: var(--glass-bg);
  -webkit-backdrop-filter: var(--glass-filter);
  backdrop-filter: var(--glass-filter);
  border: 1px solid var(--glass-border);
  box-shadow: var(--glass-shadow);
  border-radius: var(--radius-full);
}

.segment-tab {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  text-align: center;
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-md);
  font-weight: var(--font-medium);
  color: var(--theme-text-muted);
  border-radius: var(--radius-full);
  border: none;
  background: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition:
    color var(--duration-fast),
    background var(--duration-fast);
}

.segment-tab.active {
  color: var(--theme-text);
  font-weight: var(--font-semibold);
  background: rgba(0, 0, 0, 0.1);
}

.segment-tab:not(.active):active {
  opacity: 0.6;
}

.segment-tab svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

/* ── Reset ─────────────────────────────────────────────────── */

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

[hidden] {
  display: none !important;
}
.hidden {
  display: none !important;
}

html,
body {
  height: 100%;
  overflow: hidden;
  background: var(--theme-bg);
}

body {
  font-family: var(--theme-font-body);
  font-size: var(--theme-font-size);
  line-height: var(--theme-line-height);
  color: var(--theme-text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

button {
  font: inherit;
  font-family: var(--theme-font-body);
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  color: inherit;
  -webkit-font-smoothing: antialiased;
}

input,
textarea {
  font: inherit;
  font-size: var(--text-xl);
  font-family: var(--theme-font-body);
  -webkit-font-smoothing: antialiased;
}

::-webkit-scrollbar {
  display: none;
}
* {
  scrollbar-width: none;
}

/* ══════════════════════════════════════════════════════════
   APP SHELL
   ══════════════════════════════════════════════════════════ */

#app {
  position: fixed;
  top: var(--safe-top);
  left: 0;
  right: 0;
  bottom: 0;
  overflow: hidden;
  background: var(--theme-bg);
}

#swipe-container {
  width: 100%;
  height: 100%;
  position: relative;
}

.panel {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background: var(--theme-bg);
}

/* Chat stays put — canvas slides over it */
#panel-chat {
  z-index: 1;
}

#panel-canvas {
  z-index: 2;
  transform: translateX(100%);
  transition:
    transform 320ms cubic-bezier(0.25, 0.46, 0.45, 0.94),
    box-shadow 320ms ease;
  box-shadow: none;
  border-radius: 0;
}

#panel-canvas.overlay-visible {
  transform: translateX(0);
  box-shadow: var(--canvas-panel-shadow);
  border-radius: 20px 0 0 20px;
}

/* ── Swipe Indicator ─────────────────────────────────────── */

/* ══════════════════════════════════════════════════════════
   CHAT PANEL
   ══════════════════════════════════════════════════════════ */

#panel-chat {
  background: var(--theme-bg);
}

#panel-chat .chat-window {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  background: var(--theme-surface);
  position: relative;
  overflow: hidden;
}

/* ── Chat Header ─────────────────────────────────────────── */

/* ── Chat Header — transparent row, children float independently ── */
.chat-header {
  position: fixed;
  top: calc(var(--safe-top) + var(--space-6));
  left: var(--space-3);
  width: calc(100vw - var(--space-3) * 2);
  z-index: var(--z-header);
  background: transparent;
  border: none;
  box-shadow: none;
  height: var(--touch-target);
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 0;
}

/* Glass pill mixin */
.header-avatar-btn,
.header-name-pill,
.header-search-btn {
  background: var(--glass-bg);
  -webkit-backdrop-filter: var(--glass-filter);
  backdrop-filter: var(--glass-filter);
  border: 1px solid var(--glass-border);
  box-shadow: var(--glass-shadow);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}

/* Avatar circle */
.header-avatar-btn {
  width: var(--touch-target);
  height: var(--touch-target);
  border-radius: var(--radius-full);
  padding: 0;
  cursor: pointer;
}

/* Name + status pill — shrinks to content, centered in remaining space */
.header-name-pill {
  flex: 1;
  height: var(--touch-target);
  border-radius: var(--radius-full);
  padding: 0 var(--space-10);
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  width: fit-content;
  min-width: 0;
  max-width: fit-content;
  margin: 0 auto;
}

/* Search button circle */
.header-search-btn {
  width: var(--touch-target);
  height: var(--touch-target);
  border-radius: var(--radius-full);
  color: var(--theme-text-muted);
}

/* Avatar image inside the button */
.header-avatar-inline {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  object-fit: cover;
  display: block;
}

.header-name {
  font-size: var(--text-md);
  font-weight: var(--font-semibold);
  color: var(--theme-text);
  line-height: var(--leading-tight);
}

.header-status {
  font-size: var(--text-xs);
  color: var(--palette-blue);
  line-height: var(--leading-tight);
  display: flex;
  align-items: center;
  gap: 3px;
}

.header-typing-dots {
  letter-spacing: 1px;
  font-size: var(--text-xs);
}

.header-avatar-btn:active,
.header-name-pill:active,
.header-search-btn:active {
  opacity: 0.5;
}

.avatar-btn,
.avatar-circle {
  display: none;
}

/* ── Search Overlay ──────────────────────────────────────── */

/* Glass pill: floats below the header row, same style as header pills */
.chat-search-overlay {
  position: fixed;
  top: calc(var(--safe-top) + var(--space-6));
  left: var(--space-3);
  right: var(--space-3);
  z-index: calc(var(--z-header) + 10);
  background: var(--glass-bg);
  -webkit-backdrop-filter: var(--glass-filter);
  backdrop-filter: var(--glass-filter);
  border: 1px solid var(--glass-border);
  box-shadow: var(--glass-shadow);
  border-radius: var(--radius-full);
  height: var(--touch-target);
  display: flex;
  align-items: center;
  padding: 0 var(--space-5);
  gap: var(--space-3);
  opacity: 0;
  transform: translateY(-8px) scale(0.97);
  pointer-events: none;
  transition:
    opacity var(--duration-normal) var(--ease-default),
    transform var(--duration-normal) var(--ease-default);
}

.chat-search-overlay.visible {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

.chat-search-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  font-size: var(--text-lg);
  font-family: inherit;
  color: var(--theme-text);
  padding: 0;
  min-width: 0;
  -webkit-appearance: none;
}

.chat-search-input::placeholder {
  color: var(--theme-text-muted);
}

/* Hide the native clear button on type=search */
.chat-search-input::-webkit-search-cancel-button {
  display: none;
}

.chat-search-count {
  font-size: var(--text-sm);
  color: var(--theme-text-muted);
  white-space: nowrap;
  flex-shrink: 0;
  letter-spacing: 0.01em;
}

.chat-search-close {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--overlay-reaction-in);
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--theme-text-muted);
  flex-shrink: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: opacity var(--duration-fast);
}

.chat-search-close:active {
  opacity: 0.5;
}

/* Floating chevron buttons — each an independent glass pill */
.search-chevron-btn {
  position: fixed;
  bottom: calc(var(--safe-bottom) + var(--space-9));
  z-index: calc(var(--z-header) + 10);
  width: var(--touch-target);
  height: var(--touch-target);
  border-radius: var(--radius-full);
  background: var(--glass-bg);
  -webkit-backdrop-filter: var(--glass-filter);
  backdrop-filter: var(--glass-filter);
  border: 1px solid var(--glass-border);
  box-shadow: var(--glass-shadow);
  color: var(--theme-text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition:
    opacity var(--duration-normal) var(--ease-default),
    transform var(--duration-normal) var(--ease-default);
  -webkit-tap-highlight-color: transparent;
}

#search-prev {
  right: calc(var(--space-3) + var(--touch-target) + var(--space-2));
}
#search-next {
  right: var(--space-3);
}

.search-chevron-btn.visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

/* Dim when no results, brighten when active */
.search-chevron-btn:not(.active) {
  color: var(--theme-text-muted);
  opacity: 0;
  pointer-events: none;
}
.search-chevron-btn.visible:not(.active) {
  opacity: 0.35;
  pointer-events: none;
}
.search-chevron-btn.visible.active {
  opacity: 1;
  color: var(--theme-text);
  pointer-events: auto;
}
.search-chevron-btn.visible.active:active {
  opacity: 0.4;
}

.msg-highlight {
  background: var(--palette-blue-soft);
  border-radius: var(--radius-xs);
}

.finder-flash {
  animation: finderFlash 2s ease-out;
}
@keyframes finderFlash {
  0%, 15% { background: rgba(0, 122, 255, 0.2); }
  100% { background: transparent; }
}

/* ── Messages Area ───────────────────────────────────────── */

.messages-scroll {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--theme-bg);
  position: relative;
  /* Offset for floating glass header: safe-top + margin + pill height + gap */
  padding-top: calc(
    var(--safe-top) + var(--space-6) + var(--touch-target) + var(--space-4)
  );
}

.messages-inner {
  padding: var(--space-6) var(--space-4);
  /* Bottom clearance: input row height + gap + safe-bottom */
  padding-bottom: calc(
    var(--touch-target) + var(--space-3) + var(--safe-bottom) + var(--space-6)
  );
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

/* ── Scroll-to-bottom Chip ───────────────────────────────── */

.scroll-down-chip {
  position: absolute;
  bottom: calc(
    var(--safe-bottom) + var(--space-3) + var(--touch-target) + var(--space-4)
  );
  right: var(--space-6);
  z-index: var(--z-overlay);
  display: flex;
  align-items: center;
  gap: var(--space-2);
  background: var(--theme-surface);
  border-radius: var(--radius-full);
  padding: var(--space-3) var(--space-6) var(--space-3) var(--space-5);
  box-shadow: var(--theme-shadow-raise);
  cursor: pointer;
  opacity: 0;
  transform: translateY(var(--space-4));
  transition:
    opacity var(--duration-normal) var(--ease-default),
    transform var(--duration-normal) var(--ease-default);
  color: var(--theme-text-muted);
  font-size: var(--text-base);
  font-weight: var(--font-semibold);
  border: none;
  pointer-events: none;
}

.scroll-down-chip:not([hidden]) {
  pointer-events: auto;
}
.scroll-down-chip.visible {
  opacity: 1;
  transform: translateY(0);
}
.scroll-down-count:empty {
  display: none;
}

/* ── Date Divider ────────────────────────────────────────── */

.date-divider {
  text-align: center;
  margin: var(--space-5) 0 var(--space-4);
}

.date-divider span {
  display: inline-block;
  background: var(--overlay-panel);
  color: var(--palette-white);
  font-size: var(--text-sm);
  padding: 3px var(--space-6);
  border-radius: var(--radius-xl);
}

/* ── Date Chip (floating scroll indicator) ───────────────── */

.date-chip {
  position: fixed;
  top: calc(var(--safe-top) + 64px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--overlay-panel);
  color: var(--palette-white);
  font-size: var(--text-sm);
  padding: var(--space-2) var(--space-7);
  border-radius: var(--radius-xl);
  z-index: 50;
  pointer-events: none;
  opacity: 0;
  transition: opacity var(--duration-normal);
}

.date-chip.visible {
  opacity: 1;
}

/* ── Message Row ─────────────────────────────────────────── */

.msg-row {
  display: flex;
  align-items: flex-end;
  gap: var(--space-3);
  padding: var(--space-1) var(--space-2);
  position: relative;
}

.msg-row.msg-animate-in {
  animation: msgSlideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1) both;
}

.msg-row.dir-in {
  flex-direction: row-reverse;
}
.msg-row.dir-out {
  flex-direction: row;
}

.msg-content {
  display: flex;
  flex-direction: column;
  max-width: 75%;
}

.dir-in .msg-content {
  align-items: flex-end;
}
.dir-out .msg-content {
  align-items: flex-start;
}

.msg-avatar {
  display: none;
}

/* ── Bubbles ─────────────────────────────────────────────── */

.msg-bubble {
  max-width: 100%;
  padding: var(--space-4) var(--space-6);
  font-size: var(--text-lg);
  line-height: var(--leading-normal);
  position: relative;
  word-break: break-word;
  user-select: none;
  display: flex;
  flex-direction: column;
  transition: opacity var(--duration-fast);
}

.msg-bubble:active {
  opacity: 0.85;
}

.dir-out .msg-bubble {
  background: var(--theme-bubble-incoming);
  color: var(--theme-text);
  border-radius: var(--theme-radius-bubble-in);
}

/* Continuation bubbles: tighten the corner on the tail side */
.dir-out:not(.first-in-group) .msg-bubble {
  border-radius: 4px 18px 18px 4px;
}

.dir-in .msg-bubble {
  background: var(--theme-bubble-outgoing);
  color: var(--theme-bubble-text-out);
  border-radius: var(--theme-radius-bubble-out);
}

.dir-in:not(.first-in-group) .msg-bubble {
  border-radius: 18px 4px 4px 18px;
}

.bubble-text {
  font-size: var(--text-lg);
  line-height: var(--leading-normal);
}

/* Markdown inside assistant bubbles */
.bubble-text--markdown p { margin: 0 0 0.4em; }
.bubble-text--markdown p:last-child { margin-bottom: 0; }
.bubble-text--markdown ul,
.bubble-text--markdown ol { margin: 0.3em 0; padding-left: 1.4em; }
.bubble-text--markdown li { margin-bottom: 0.15em; }
.bubble-text--markdown code {
  background: rgba(0,0,0,0.06);
  padding: 0.1em 0.35em;
  border-radius: 4px;
  font-size: 0.9em;
}
.bubble-text--markdown pre {
  background: rgba(0,0,0,0.06);
  padding: 0.6em 0.8em;
  border-radius: 6px;
  overflow-x: auto;
  margin: 0.3em 0;
}
.bubble-text--markdown pre code {
  background: none;
  padding: 0;
}
.bubble-text--markdown a {
  color: inherit;
  text-decoration: underline;
}

.bubble-link {
  color: var(--palette-blue);
  text-decoration: none;
}
.bubble-link:active {
  text-decoration: underline;
}
.dir-in .bubble-link {
  color: #5ba8ff;
}

/* ── Bubble Footer ───────────────────────────────────────── */

.bubble-footer {
  display: flex;
  align-items: flex-end;
  gap: var(--space-3);
  margin-top: var(--space-2);
}

.bubble-time {
  font-size: var(--text-xs);
  color: var(--theme-text-muted);
  white-space: nowrap;
  flex-shrink: 0;
  margin-left: auto;
  line-height: 1;
}

.dir-in .bubble-time {
  color: var(--theme-bubble-text-out);
  opacity: 0.7;
}

.msg-read {
  font-size: var(--text-xs);
  color: var(--palette-blue);
}

/* ── Reply Quote ─────────────────────────────────────────── */

.reply-quote {
  border-left: 3px solid var(--bubble-glass-border);
  padding: 3px var(--space-4);
  margin-bottom: var(--space-3);
  font-size: var(--text-base);
  line-height: var(--leading-snug);
  opacity: 0.9;
  background: var(--bubble-glass-bg);
  border-radius: var(--radius-xs);
}

.dir-out .reply-quote {
  border-left-color: var(--palette-blue);
  background: var(--palette-blue-soft);
  color: var(--theme-text-muted);
}

.reply-author {
  font-weight: var(--font-semibold);
  font-size: var(--text-sm);
  margin-bottom: 1px;
  opacity: 1;
}

.reply-text {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  display: block;
}

/* ── Voice Bubble ────────────────────────────────────────── */

.voice-bubble {
  display: flex;
  flex-direction: column;
  padding: var(--space-3) var(--space-5);
  min-width: 220px;
  max-width: 270px;
  gap: 0;
}

/* Top row: play btn + waveform + meta */
.voice-top-row {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: var(--space-4);
}

.voice-play {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--palette-green-sage-dark);
  color: var(--palette-white);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  cursor: pointer;
  transition:
    opacity var(--duration-fast),
    transform var(--duration-fast);
}
.voice-play:active {
  opacity: 0.7;
  transform: scale(0.92);
}
.voice-play[data-playing="true"] {
  background: var(--palette-green-sage-dark);
}

.voice-waveform-wrap {
  flex: 1;
  overflow: hidden;
}

.voice-waveform {
  height: 24px;
  display: flex;
  align-items: center;
  gap: 2px;
}

.voice-waveform .bar {
  width: 3px;
  flex-shrink: 0;
  border-radius: 2px;
  transition:
    background var(--duration-fast),
    opacity var(--duration-fast);
}

.dir-in .voice-waveform .bar {
  background: var(--palette-green-sage-dark);
  opacity: 0.75;
}
.dir-in .voice-waveform .bar.played {
  opacity: 1;
  background: var(--palette-green-sage-dark);
}

.dir-out .voice-waveform .bar {
  background: var(--palette-green-sage-dark);
  opacity: 0.4;
}
.dir-out .voice-waveform .bar.played {
  opacity: 0.85;
  background: var(--palette-green-sage-dark);
}

/* Meta row: speed pill + duration, side by side */
.voice-meta {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: var(--space-2);
  flex-shrink: 0;
}

.voice-duration {
  font-size: var(--text-xs);
  color: var(--bubble-glass-text);
  min-width: 28px;
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.dir-out .voice-duration {
  color: var(--palette-green-sage-dark);
  opacity: 0.7;
}
.dir-in .voice-duration {
  color: var(--palette-green-sage-dark);
  opacity: 0.7;
}

/* Speed pill — hidden until playing */
.voice-speed-pill {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--palette-green-sage-dark);
  background: transparent;
  border: 1.5px solid currentColor;
  border-radius: 20px;
  padding: 2px 0;
  cursor: pointer;
  line-height: 1.4;
  width: 30px;
  text-align: center;
  white-space: nowrap;
  /* Hidden by default */
  opacity: 0;
  pointer-events: none;
  transform: scale(0.85);
  transition:
    opacity 0.2s ease,
    transform 0.2s ease,
    background 0.15s ease,
    color 0.15s ease;
}

/* Visible when bubble is playing */
.voice-bubble.playing .voice-speed-pill {
  opacity: 0.65;
  pointer-events: auto;
  transform: scale(1);
}

.voice-speed-pill:active {
  opacity: 0.9 !important;
}

.voice-speed-pill.active {
  opacity: 1 !important;
  background: var(--palette-green-sage-dark);
  color: var(--palette-white);
  border-color: transparent;
}

/* Waveform shrinks slightly when playing to keep layout tidy */
.voice-bubble.playing .voice-waveform .bar {
  transform: scaleY(0.78);
  transform-origin: center;
  transition:
    transform 0.25s ease,
    opacity var(--duration-fast);
}

/* Transcript */
.voice-transcript {
  font-size: var(--text-sm);
  color: var(--theme-text);
  line-height: 1.5;
  margin-top: var(--space-3);
  padding-top: var(--space-3);
  border-top: 0.5px solid var(--theme-border);
  opacity: 0;
  transform: translateY(4px);
  transition:
    opacity 0.3s var(--ease-default),
    transform 0.3s var(--ease-default);
}
.voice-transcript.reveal {
  opacity: 0;
  transform: translateY(4px);
}
.voice-transcript.in {
  opacity: 1;
  transform: translateY(0);
}

/* Pre-existing transcript (rendered on load, show immediately) */
.voice-bubble .voice-transcript:not(.reveal) {
  opacity: 1;
  transform: none;
}

/* Transcribing shimmer */
.voice-transcript-loading {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: var(--space-3);
  padding-top: var(--space-3);
  border-top: 0.5px solid var(--theme-border);
}

.transcript-shimmer-line {
  height: 10px;
  border-radius: 6px;
  background: linear-gradient(
    90deg,
    var(--theme-border) 0%,
    var(--theme-surface-soft) 40%,
    var(--theme-border) 100%
  );
  background-size: 200% 100%;
  animation: shimmer 1.4s ease-in-out infinite;
}

@keyframes shimmer {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

/* ── System Message ──────────────────────────────────────── */

.msg-system {
  text-align: center;
  font-size: var(--text-sm);
  color: var(--theme-text-muted);
  margin: var(--space-3) 0;
  padding: 0 var(--space-9);
}

/* ── Reactions ───────────────────────────────────────────── */

.reactions-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.reaction-chip {
  background: var(--overlay-reaction-out);
  border: none;
  border-radius: var(--radius-full);
  padding: 2px 7px;
  font-size: var(--text-md);
  display: flex;
  align-items: center;
  cursor: pointer;
  transition: transform var(--duration-fast);
}

.dir-out .reaction-chip {
  background: var(--overlay-reaction-in);
}
.reaction-chip:active {
  transform: scale(0.9);
}

@keyframes reaction-pop {
  0% {
    transform: scale(0);
    opacity: 0;
  }
  60% {
    transform: scale(1.35);
    opacity: 1;
  }
  80% {
    transform: scale(0.9);
  }
  100% {
    transform: scale(1);
  }
}

.reaction-chip.pop {
  animation: reaction-pop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

/* ── File/Document Bubble ───────────────────────────────── */

.file-bubble {
  padding: var(--space-4) var(--space-5) var(--space-2);
}

.file-bubble-row {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  margin-bottom: var(--space-2);
}

/* When the row is an anchor (agent-sent files with a URL) it should look
 * identical to the div variant — inherit color, no underline, cursor. */
a.file-bubble-link {
  color: inherit;
  text-decoration: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  /* Suppress iOS's native long-press link preview so our message menu wins. */
  -webkit-touch-callout: none;
}

.file-bubble-icon {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.file-bubble-ext {
  font-size: 11px;
  font-weight: 700;
  color: #fff;
  letter-spacing: 0.03em;
}

.file-bubble-info {
  flex: 1;
  min-width: 0;
}

.file-bubble-name {
  font-size: var(--text-md);
  font-weight: var(--font-medium);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.file-bubble-meta {
  font-size: var(--text-sm);
  color: var(--theme-text-muted);
  margin-top: 1px;
}

/* ── Link Preview ──────────────────────────────────────── */

/* ── Typing Indicator ────────────────────────────────────── */

.typing-row {
  display: flex;
  align-items: flex-end;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-2);
}

.typing-bubble {
  background: var(--theme-bubble-incoming);
  border-radius: var(--theme-radius-bubble-in);
  box-shadow: var(--theme-shadow);
  padding: var(--space-5) var(--space-7);
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.typing-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--theme-text-muted);
  animation: typingBounce 1.2s infinite;
}

.typing-dot:nth-child(2) {
  animation-delay: 0.2s;
}
.typing-dot:nth-child(3) {
  animation-delay: 0.4s;
}

/* ── Bubble Highlight ────────────────────────────────────── */

.msg-bubble.highlighted {
  animation: highlight 0.5s ease;
}

@keyframes highlight {
  0%,
  100% {
    filter: brightness(1);
  }
  40% {
    filter: brightness(0.9);
  }
}

/* ══════════════════════════════════════════════════════════
   CONTEXT MENU OVERLAY
   ══════════════════════════════════════════════════════════ */

.msg-overlay {
  position: fixed;
  inset: 0;
  background: var(--overlay-dim);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  z-index: 500;
}

.msg-menu-target {
  opacity: 0;
}

/* Reaction strip pill */
.reaction-strip {
  position: fixed;
  z-index: 502;
  background: var(--theme-surface);
  border-radius: var(--radius-full);
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  padding: var(--space-4) var(--space-6);
  gap: var(--space-2);
}

.reaction-strip-emoji {
  font-size: 28px;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border-radius: 50%;
  transition: transform var(--duration-fast);
}

.reaction-strip-emoji:active {
  transform: scale(1.3);
}

.reaction-strip-plus {
  font-size: var(--text-xl);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--theme-surface-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--theme-text-muted);
  font-weight: 300;
}

/* Context menu card */
.ctx-menu {
  position: fixed;
  z-index: 501;
  background: var(--ctx-menu-bg);
  backdrop-filter: var(--ctx-menu-filter);
  -webkit-backdrop-filter: var(--ctx-menu-filter);
  border-radius: var(--radius-2xl);
  overflow: hidden;
  min-width: 200px;
  box-shadow: var(--shadow-lg), var(--shadow-xs);
  opacity: 0;
  transform: scale(0.92);
  transition:
    opacity var(--duration-normal) var(--ease-default),
    transform var(--duration-normal) var(--ease-default);
}

.ctx-menu.open {
  opacity: 1;
  transform: scale(1);
}

.ctx-menu-item {
  display: flex;
  align-items: center;
  gap: var(--space-6);
  padding: 0 var(--space-8);
  height: var(--touch-target);
  font-size: var(--text-xl);
  color: var(--theme-text);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  border-bottom: 0.5px solid var(--theme-border);
  width: 100%;
  background: none;
  text-align: left;
  border-left: none;
  border-right: none;
  border-top: none;
}

.ctx-menu-item:last-child {
  border-bottom: none;
}
.ctx-menu-item:active {
  background: var(--theme-surface-soft);
}
.ctx-menu-item.destructive {
  color: var(--theme-danger);
}

.ctx-menu-label {
  font-weight: var(--font-regular);
}

.ctx-menu-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  color: var(--theme-text-faint);
  flex-shrink: 0;
}

.ctx-menu-item.destructive .ctx-menu-icon {
  color: var(--theme-danger);
}

/* Legacy msg-menu (kept for JS compatibility) */
.msg-menu {
  position: fixed;
  z-index: 100;
  background: var(--theme-surface);
  border-radius: var(--radius-2xl);
  box-shadow: var(--shadow-lg);
  min-width: 200px;
  overflow: hidden;
  animation: scaleIn var(--duration-fast) var(--ease-default);
}

.msg-menu-reactions {
  display: flex;
  padding: var(--space-5) var(--space-6);
  border-bottom: 1px solid var(--theme-border);
  justify-content: space-around;
}

.react-btn {
  font-size: 22px;
  padding: var(--space-2) var(--space-3);
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: background var(--duration-fast);
}

.react-btn:active {
  background: var(--theme-surface-soft);
}

.msg-menu-actions {
  display: flex;
  flex-direction: column;
}

.msg-action {
  padding: var(--space-6) var(--space-8);
  text-align: left;
  font-size: var(--text-lg);
  color: var(--theme-text);
  display: flex;
  align-items: center;
  gap: var(--space-5);
  cursor: pointer;
  border: none;
  background: none;
  border-bottom: 1px solid var(--theme-border);
  width: 100%;
  transition: background var(--duration-fast);
}

.msg-action:last-child {
  border-bottom: none;
}
.msg-action:active {
  background: var(--theme-surface-soft);
}
.msg-action.separator {
  border-top: 1px solid var(--theme-border);
}
.msg-action.danger {
  color: var(--theme-danger);
}
.action-icon {
  font-size: var(--text-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  line-height: 0;
}
.action-icon svg {
  width: 20px;
  height: 20px;
}

/* ══════════════════════════════════════════════════════════
   REPLY BAR
   ══════════════════════════════════════════════════════════ */

/* Reply bar — lives inside .input-field-wrap above the text input */
.reply-bar {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4) var(--space-3) var(--space-3);
  border-bottom: 1px solid var(--overlay-separator);
  animation: slideDown 0.15s ease;
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
  overflow: hidden;
}

@keyframes slideDown {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.reply-bar-left-accent {
  width: 3px;
  min-height: 32px;
  align-self: stretch;
  border-radius: 99px;
  background: var(--palette-blue);
  flex-shrink: 0;
}

.reply-bar-content {
  flex: 1;
  min-width: 0;
}

.reply-bar-author {
  font-size: var(--text-sm);
  font-weight: var(--font-semibold);
  color: var(--palette-blue);
  line-height: 1.3;
}

.reply-bar-text {
  font-size: var(--text-sm);
  color: var(--theme-text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.3;
}

.reply-bar-close {
  color: var(--theme-text-muted);
  font-size: 15px;
  padding: var(--space-1) var(--space-2);
  line-height: 1;
  opacity: 0.6;
  flex-shrink: 0;
}

/* When replying: square off the top of the input pill */
.input-field-wrap.has-reply {
  border-radius: 18px;
  flex-direction: column;
  align-items: stretch;
  padding: 0;
}

.input-field-wrap.has-reply #input-field {
  padding: var(--space-2) var(--space-5) var(--space-3);
}

/* ══════════════════════════════════════════════════════════
   FLOATING INPUT BAR
   ══════════════════════════════════════════════════════════ */

/* ── Input bar: transparent row, children float independently ── */
.floating-input-bar {
  position: fixed;
  bottom: calc(var(--safe-bottom) + var(--space-3));
  left: var(--space-3);
  width: calc(100vw - var(--space-3) * 2);
  z-index: var(--z-input);
  background: transparent;
  border: none;
  box-shadow: none;
  padding: 0;
  display: flex;
  align-items: flex-end;
  gap: var(--space-2);
}

/* In standalone PWA mode, sit just above the home indicator */
@media all and (display-mode: standalone) {
  .floating-input-bar {
    bottom: env(safe-area-inset-bottom, 0px);
  }
}

/* Glass pill mixin — shared by all three floating children */
.attachment-btn,
.home-btn,
.tab-switcher-btn {
  width: var(--touch-target);
  height: var(--touch-target);
  flex-shrink: 0;
  background: var(--glass-bg);
  -webkit-backdrop-filter: var(--glass-filter);
  backdrop-filter: var(--glass-filter);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-full);
  box-shadow: var(--glass-shadow);
  color: var(--theme-text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity var(--duration-fast);
  -webkit-tap-highlight-color: transparent;
}

.attachment-btn:active,
.home-btn:active,
.tab-switcher-btn:active {
  opacity: 0.6;
}

.input-field-wrap {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  background: var(--glass-bg);
  -webkit-backdrop-filter: var(--glass-filter);
  backdrop-filter: var(--glass-filter);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-full);
  box-shadow: var(--glass-shadow);
  display: flex;
  align-items: center;
  padding: 0 0 0 var(--space-5);
  min-height: var(--touch-target);
  transition: border-radius 0.15s ease;
}

#input-field {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  font-size: var(--text-lg);
  color: var(--theme-text);
  padding: var(--space-3) var(--space-5) var(--space-3) 0;
  -webkit-appearance: none;
  resize: none;
  overflow-y: auto;
  min-height: 28px;
  max-height: 180px;
  line-height: 1.25;
  display: block;
  width: 100%;
  font-family: inherit;
  overflow-wrap: break-word;
  word-break: break-word;
  scrollbar-width: thin;
  scrollbar-color: rgba(0, 0, 0, 0.2) transparent;
}

/* Hide iOS keyboard accessory bar (prev/next/done) */
#input-field:focus {
  transform: translateZ(0);
  -webkit-touch-callout: none;
}
@supports (-webkit-touch-callout: none) {
  #input-field {
    -webkit-user-modify: read-write-plaintext-only;
    -webkit-touch-callout: none;
    touch-action: manipulation;
  }
}

#input-field::-webkit-scrollbar {
  width: 3px;
}

#input-field::-webkit-scrollbar-track {
  background: transparent;
  margin-top: 8px;
  margin-bottom: 8px;
  border-radius: 99px;
}

#input-field::-webkit-scrollbar-thumb {
  background: var(--overlay-scrollbar);
  border-radius: 99px;
  min-height: 20px;
}

#input-field:empty::before {
  content: attr(data-placeholder);
  color: var(--theme-text-muted);
  pointer-events: none;
}

#input-field br:only-child {
  display: none;
}

/* Mic — glass pill, matches attachment btn */
.mic-btn {
  position: relative;
  overflow: visible;
  width: var(--touch-target);
  height: var(--touch-target);
  border-radius: var(--radius-full);
  background: var(--glass-bg);
  -webkit-backdrop-filter: var(--glass-filter);
  backdrop-filter: var(--glass-filter);
  border: 1px solid var(--glass-border);
  box-shadow: var(--glass-shadow);
  color: var(--theme-text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition:
    opacity var(--duration-fast),
    transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1),
    background var(--duration-fast);
  -webkit-tap-highlight-color: transparent;
}

/* Send — black */
.send-btn {
  width: var(--touch-target);
  height: var(--touch-target);
  border-radius: var(--radius-full);
  background: var(--pill-dark-bg);
  border: 1px solid var(--pill-dark-border);
  box-shadow: var(--pill-dark-shadow);
  color: var(--palette-white);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: opacity var(--duration-fast);
  -webkit-tap-highlight-color: transparent;
}

.mic-btn:active,
.send-btn:active {
  opacity: 0.7;
}

.mic-btn .mic-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 0;
}
.mic-btn .send-icon {
  display: none;
  align-items: center;
  justify-content: center;
  line-height: 0;
}
.mic-btn.locked .mic-icon {
  display: none;
}
.mic-btn.locked .send-icon {
  display: flex;
}

/* ── Voice Recording Bar (inline in input) ───────────────── */

.voice-recording-bar {
  display: none;
  flex: 1;
  align-items: center;
  gap: var(--space-4);
  padding: 0 var(--space-2) 0 var(--space-1);
  min-height: 36px;
}

.voice-recording-bar.visible {
  display: flex;
}

.voice-rec-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--theme-danger);
  flex-shrink: 0;
  animation: voicePulse 1s ease-in-out infinite;
}

@keyframes voicePulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.2;
  }
}

/* Recording sonar rings */
.mic-btn.recording::before,
.mic-btn.recording::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: rgba(255, 59, 48, 0.25);
  animation: sonarRing 1.8s cubic-bezier(0.2, 0.6, 0.4, 1) infinite;
  pointer-events: none;
}

.mic-btn.recording::after {
  animation-delay: 0.6s;
}

@keyframes sonarRing {
  0% {
    transform: scale(1);
    opacity: 0.6;
  }
  100% {
    transform: scale(2.4);
    opacity: 0;
  }
}

.voice-rec-timer {
  font-size: var(--text-lg);
  font-weight: var(--font-medium);
  color: var(--theme-text);
  font-variant-numeric: tabular-nums;
  min-width: 36px;
  flex-shrink: 0;
}

.voice-rec-slide-hint {
  flex: 1;
  font-size: var(--text-base);
  color: var(--theme-text-muted);
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  transition: opacity var(--duration-normal);
}

.voice-rec-cancel {
  font-size: var(--text-lg);
  font-weight: var(--font-medium);
  color: var(--theme-danger);
  padding: var(--space-4) var(--space-4) var(--space-4) var(--space-4);
  white-space: nowrap;
  flex-shrink: 0;
}

/* Floating draggable mic bubble */
.vrec-float-bubble {
  position: fixed;
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: var(--theme-danger);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: calc(var(--z-modal) + 10);
  pointer-events: none;
  box-shadow: 0 4px 20px rgba(185, 28, 28, 0.4);
  opacity: 0;
  transform: scale(0.4);
  transition:
    opacity var(--duration-fast) var(--ease-default),
    transform var(--duration-fast) var(--ease-default);
}

.vrec-float-bubble.in {
  opacity: 1;
  transform: scale(1);
}

.vrec-lock-pill {
  position: fixed;
  width: 36px;
  background: var(--glass-bg);
  -webkit-backdrop-filter: var(--glass-filter);
  backdrop-filter: var(--glass-filter);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-full);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: var(--space-5) 0 var(--space-4);
  gap: var(--space-3);
  z-index: calc(var(--z-modal) + 11);
  pointer-events: none;
  box-shadow: var(--glass-shadow);
  opacity: 0;
  transform: translateY(var(--space-3));
  transition:
    opacity var(--duration-fast) var(--ease-default),
    transform var(--duration-fast) var(--ease-default);
}

.vrec-lock-pill.in {
  opacity: 1;
  transform: translateY(0);
}

.vrec-lock-icon,
.vrec-lock-chevron {
  color: var(--theme-text-muted);
  display: flex;
}

.vrec-lock-chevron {
  opacity: 0.5;
}

/* Voice recording overlay states */
.voice-recording-overlay {
  position: absolute;
  /* Leave the right side open for the mic bubble to float above */
  top: 0;
  bottom: 0;
  left: 0;
  right: 54px;
  background: var(--glass-bg);
  -webkit-backdrop-filter: var(--glass-filter);
  backdrop-filter: var(--glass-filter);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-full);
  box-shadow: var(--glass-shadow);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-8);
  z-index: 100;
  transition: opacity var(--duration-fast);
}

.voice-recording-locked {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 54px;
  background: var(--glass-bg);
  -webkit-backdrop-filter: var(--glass-filter);
  backdrop-filter: var(--glass-filter);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-full);
  box-shadow: var(--glass-shadow);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-6) 0 var(--space-8);
  z-index: 100;
  transition: opacity var(--duration-fast);
}

.voice-rec-left {
  display: flex;
  align-items: center;
  gap: var(--space-4);
}

.voice-rec-lock-hint {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  color: var(--theme-text-muted);
  transition: color var(--duration-fast);
}

.voice-rec-send {
  width: var(--touch-target);
  height: var(--touch-target);
  border-radius: 50%;
  background: var(--pill-dark-bg);
  border: 1px solid var(--pill-dark-border);
  box-shadow: var(--pill-dark-shadow);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}

.voice-rec-send:active {
  opacity: 0.7;
}

/* ── Attachment Drawer ────────────────────────────────────── */

/* Attachment drawer — full-cover sheet above input bar */
.attach-drawer {
  position: fixed;
  inset: 0;
  z-index: 1000;
  pointer-events: none;
  background: rgba(0, 0, 0, 0);
  transition: background var(--duration-slow);
}

.attach-drawer.open {
  pointer-events: auto;
  background: rgba(0, 0, 0, 0.3);
}

.attach-drawer-sheet {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--theme-surface);
  border-radius: var(--radius-2xl) var(--radius-2xl) 0 0;
  transform: translateY(100%);
  transition: transform var(--duration-slow) var(--ease-spring);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding-bottom: env(safe-area-inset-bottom, 16px);
}

.attach-drawer.open .attach-drawer-sheet {
  transform: translateY(0);
}

/* Drag handle */
.attach-handle {
  width: 36px;
  height: 4px;
  border-radius: 2px;
  background: var(--palette-warm-400);
  margin: 10px auto 4px;
  flex-shrink: 0;
}

/* Section header: "Photos & Videos" + "View Library" */
.attach-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4) var(--space-6) var(--space-3);
  flex-shrink: 0;
}

.attach-section-title {
  font-size: var(--text-lg);
  font-weight: var(--font-semibold);
  color: var(--theme-text);
}

.attach-view-library {
  font-size: var(--text-base);
  font-weight: var(--font-medium);
  color: var(--palette-blue);
  -webkit-tap-highlight-color: transparent;
}
.attach-view-library:active {
  opacity: 0.6;
}

/* Horizontal photo row */
.attach-photo-row {
  display: flex;
  gap: 2px;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  padding: 0 var(--space-6) var(--space-4);
  flex-shrink: 0;
  scrollbar-width: none;
}
.attach-photo-row::-webkit-scrollbar {
  display: none;
}

.att-photo-cell {
  width: 88px;
  height: 88px;
  min-width: 88px;
  border-radius: var(--radius-xl);
  cursor: pointer;
  position: relative;
  overflow: hidden;
  transition: opacity var(--duration-fast);
}

.att-photo-cell:active {
  opacity: 0.85;
}

/* Camera cell */
.att-camera-cell {
  background: #1c1c1e;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Multi-select UI */
.att-photo-select-ring {
  position: absolute;
  top: 5px;
  right: 5px;
  width: 20px;
  height: 20px;
  border-radius: var(--radius-full);
  border: 2px solid rgba(255, 255, 255, 0.8);
  background: transparent;
  pointer-events: none;
  transition:
    background var(--duration-fast),
    border-color var(--duration-fast);
}

.att-photo-select-num {
  position: absolute;
  top: 5px;
  right: 5px;
  width: 20px;
  height: 20px;
  border-radius: var(--radius-full);
  background: var(--palette-blue);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 700;
  color: #fff;
  pointer-events: none;
  opacity: 0;
  transition: opacity var(--duration-fast);
}

.att-photo-cell.selected .att-photo-select-ring {
  border-color: var(--palette-blue);
  background: transparent;
}

.att-photo-cell.selected .att-photo-select-num {
  opacity: 1;
}

.att-photo-cell.selected::after {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(42, 171, 238, 0.18);
  pointer-events: none;
  border-radius: var(--radius-xl);
}

/* Action list */
.attach-actions {
  border-top: 0.5px solid var(--theme-border);
  padding: var(--space-2) 0;
}

.attach-action-row {
  display: flex;
  align-items: center;
  gap: var(--space-5);
  padding: var(--space-5) var(--space-7);
  width: 100%;
  font-size: var(--text-lg);
  color: var(--theme-text);
  -webkit-tap-highlight-color: transparent;
}
.attach-action-row:active {
  background: var(--theme-surface-soft);
}
.attach-action-row svg {
  color: var(--theme-text-muted);
  flex-shrink: 0;
}

/* Caption bar — slides in above tab bar when photos selected */
.attach-caption-bar {
  flex-shrink: 0;
  padding: var(--space-3) var(--space-4);
  border-top: 0.5px solid var(--theme-border);
  background: var(--theme-surface);
}

.attach-caption-row {
  display: flex;
  align-items: flex-end;
  gap: var(--space-2);
}

.attach-caption-input-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  background: var(--glass-bg);
  -webkit-backdrop-filter: var(--glass-filter);
  backdrop-filter: var(--glass-filter);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-full);
  box-shadow: var(--glass-shadow);
  padding: 0 var(--space-5);
  min-height: var(--touch-target);
}

.attach-caption-field {
  flex: 1;
  min-height: 20px;
  max-height: 80px;
  overflow-y: auto;
  outline: none;
  font-size: var(--text-lg);
  color: var(--theme-text);
  -webkit-overflow-scrolling: touch;
  padding: var(--space-3) 0;
}

.attach-caption-field:empty::before {
  content: attr(data-placeholder);
  color: var(--theme-text-muted);
  pointer-events: none;
}

.attach-send-btn {
  width: var(--touch-target);
  height: var(--touch-target);
  border-radius: var(--radius-full);
  background: var(--pill-dark-bg);
  border: 1px solid var(--pill-dark-border);
  box-shadow: var(--pill-dark-shadow);
  color: var(--palette-white);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: opacity var(--duration-fast);
  -webkit-tap-highlight-color: transparent;
}

.attach-send-btn:active {
  opacity: 0.7;
}

/* (tab bar removed — replaced by action list) */

.emoji-btn {
  color: var(--theme-text-muted);
  padding: 3px;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 18px;
  transition: opacity var(--duration-fast);
}

.emoji-btn:active {
  opacity: 0.5;
}

/* ══════════════════════════════════════════════════════════
   CANVAS PANEL
   ══════════════════════════════════════════════════════════ */

#panel-canvas {
  background: var(--theme-bg);
  display: flex;
  flex-direction: column;
}

.canvas-inner {
  width: 100%;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
  background: var(--theme-bg);
}

.canvas-window {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
}

.canvas-content {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  position: relative;
  background: var(--theme-bg);
}

.canvas-pane {
  display: none;
  width: 100%;
  height: 100%;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0;
  background: var(--theme-bg);
}

.canvas-pane.active {
  display: block;
}

.canvas-pane:has(.app-iframe-wrap) {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.canvas-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-around;
  padding: var(--space-4) var(--space-8) var(--space-2);
  background: var(--theme-surface);
  border-top: 0.5px solid var(--theme-border);
  flex-shrink: 0;
}

.canvas-toolbar-btn {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--theme-text-muted);
  -webkit-tap-highlight-color: transparent;
}

.canvas-toolbar-btn:active {
  opacity: 0.5;
}

.tab-count-btn {
  border: 1.5px solid var(--theme-text-muted);
  border-radius: var(--radius-sm);
  width: 26px;
  height: 26px;
  font-size: var(--text-base);
  font-weight: var(--font-semibold);
}

/* Pane header */
.pane-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-5) var(--space-2) var(--space-4) 0;
  margin-bottom: var(--space-2);
}

.pane-header-title {
  font-size: var(--text-xl);
  font-weight: var(--font-semibold);
  color: var(--theme-text);
}

.pane-close-btn {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--theme-surface-soft);
  border: none;
  font-size: var(--text-xl);
  line-height: 1;
  color: var(--theme-text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background var(--duration-fast);
}

.pane-close-btn:active {
  background: var(--theme-border);
}

.pane-nav-back {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--theme-surface-soft);
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--theme-text-muted);
  -webkit-tap-highlight-color: transparent;
  transition: background var(--duration-fast);
}

.pane-nav-back:active {
  background: var(--theme-border);
}

/* App iframe */
.app-iframe-wrap {
  flex: 1;
  width: 100%;
  height: calc(100% - var(--touch-target));
  overflow: hidden;
  border-radius: 0 0 var(--radius-md) var(--radius-md);
}

.app-iframe {
  width: 100%;
  height: 100%;
  border: none;
  background: var(--theme-bg);
}

/* Tab switcher overlay */
.tab-switcher-overlay {
  position: fixed;
  inset: 0;
  z-index: var(--z-nav);
  background: rgba(var(--theme-surface-rgb), 0.82);
  backdrop-filter: blur(28px) saturate(1.5);
  -webkit-backdrop-filter: blur(28px) saturate(1.5);
  display: flex;
  flex-direction: column;
  transform: translateY(100%);
  transition: transform var(--duration-slow) var(--ease-spring);
}

.tab-switcher-overlay.open {
  transform: translateY(0);
}

.tab-switcher-header {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-6) var(--space-8);
  padding-top: calc(var(--space-6) + env(safe-area-inset-top, 44px));
}

.tab-switcher-title {
  font-size: var(--text-lg);
  font-weight: var(--font-semibold);
  color: var(--theme-text);
}

.tab-switcher-grid {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: var(--space-4) var(--space-6);
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-6);
  align-content: start;
}

.tab-card {
  background: var(--theme-surface);
  border-radius: var(--radius-2xl);
  overflow: hidden;
  cursor: pointer;
  width: 100%;
  display: flex;
  flex-direction: column;
  position: relative;
  box-shadow: var(--theme-shadow);
  transition: transform var(--duration-fast) var(--ease-default);
}

.tab-card:active {
  transform: scale(0.97);
}

.tab-card.active {
  box-shadow:
    0 0 0 2px rgba(0, 0, 0, 0.18),
    var(--shadow-sm);
}

.tab-card-header {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-3) var(--space-3) var(--space-5);
  background: var(--theme-surface);
  border-bottom: 0.5px solid rgba(0, 0, 0, 0.06);
}

.tab-card-favicon {
  width: 16px;
  height: 16px;
  border-radius: 4px;
  background: var(--theme-text);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 9px;
  font-weight: var(--font-semibold);
  color: var(--palette-white);
}

.tab-card-name {
  flex: 1;
  font-size: var(--text-base);
  font-weight: var(--font-medium);
  color: var(--theme-text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tab-card-close {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--theme-text-muted);
  font-size: var(--text-xl);
  flex-shrink: 0;
  border-radius: 50%;
}

.tab-card-close:active {
  background: var(--theme-surface-soft);
}

.tab-card-preview {
  width: 100%;
  height: 200px;
  overflow: hidden;
  position: relative;
  background: var(--theme-surface-code);
}

.tab-card-preview-inner {
  transform-origin: top left;
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none;
}

.tab-card-app-label {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  font-size: var(--text-md);
  font-weight: var(--font-medium);
  color: var(--theme-text-muted);
  background: var(--theme-surface-code);
}

.tab-switcher-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: var(--space-5) var(--space-8);
  padding-bottom: calc(var(--space-5) + env(safe-area-inset-bottom, 20px));
  background: rgba(var(--theme-surface-rgb), 0.72);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-top: 0.5px solid rgba(0, 0, 0, 0.06);
}

.tab-switcher-done {
  font-size: var(--text-xl);
  font-weight: var(--font-semibold);
  color: var(--theme-text);
}

/* ── Dashboard Widgets ───────────────────────────────────── */

.home-dashboard {
  padding: var(--space-10) var(--space-9) 80px;
  background: var(--theme-bg);
  min-height: 100%;
}

.dash-greeting {
  font-family: var(--theme-font-display);
  font-size: var(--text-4xl);
  font-weight: var(--font-regular);
  color: var(--theme-text);
  line-height: var(--leading-tight);
}

.dash-date {
  font-family: var(--theme-font-body);
  font-size: var(--text-base);
  color: var(--theme-text-muted);
  margin-top: var(--space-2);
  margin-bottom: var(--space-10);
}

/* Widget card */
.dash-widget {
  background: var(--theme-surface);
  border-radius: var(--theme-radius-card);
  border: 1px solid var(--theme-border);
  overflow: hidden;
  margin-bottom: var(--space-6);
  box-shadow: var(--theme-shadow);
}

/* Widget header: label bar — recessed, uppercase, tracked */
.widget-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4) var(--space-7);
  background: var(--theme-surface-soft);
  border-bottom: 1px solid var(--theme-border);
}

.widget-title {
  font-family: var(--theme-font-body);
  font-size: var(--text-xs);
  font-weight: var(--font-semibold);
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  color: var(--theme-text-muted);
}

.widget-count,
.widget-meta {
  font-family: var(--theme-font-body);
  font-size: var(--text-xs);
  font-weight: var(--font-medium);
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  color: var(--theme-text-faint);
}

/* Widget body padding — applied to direct content containers */
.weather-widget .widget-row,
.dash-widget .apps-grid,
.dash-widget .cal-row,
.dash-widget .cal-meals {
  padding: var(--space-6) var(--space-7);
}

.dash-widget .cal-row {
  padding-bottom: 0;
}
.dash-widget .cal-meals {
  padding-top: 0;
}

/* Weather */
.weather-widget .widget-row {
  display: flex;
  align-items: center;
  gap: var(--space-8);
}

.weather-temp {
  font-family: var(--theme-font-display);
  font-size: var(--text-5xl);
  font-weight: var(--font-regular);
  color: var(--theme-text);
  line-height: 1;
}

.weather-info {
  flex: 1;
}

.weather-condition {
  font-size: var(--text-base);
  font-weight: var(--font-medium);
  color: var(--theme-text);
}

.weather-location,
.weather-range {
  font-size: var(--text-sm);
  color: var(--theme-text-muted);
  margin-top: var(--space-1);
}

.weather-icon {
  flex-shrink: 0;
}

/* To-do */
.todo-item {
  display: flex;
  align-items: center;
  gap: var(--space-5);
  padding: var(--space-4) var(--space-7);
  border-bottom: 1px solid var(--theme-border);
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.todo-item:last-child {
  border-bottom: none;
}

.todo-check {
  font-size: var(--text-lg);
  color: var(--theme-text-sep);
  flex-shrink: 0;
  line-height: 1;
}

.todo-item.checked .todo-check {
  color: var(--theme-success);
}
.todo-item.checked .todo-text {
  color: var(--theme-text-muted);
  text-decoration: line-through;
}

.todo-text {
  font-size: var(--text-base);
  color: var(--theme-text);
  line-height: var(--leading-normal);
}

/* Apps grid */
.apps-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-5);
  align-items: center;
}

.app-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.app-tile:active .app-tile-icon {
  opacity: 0.7;
  transform: scale(0.93);
}

.app-tile-icon {
  width: 52px;
  height: 52px;
  border-radius: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--palette-white);
  box-shadow: var(--shadow-sm);
  transition:
    opacity var(--duration-fast),
    transform var(--duration-fast);
}

/* App icon colors — all from the design system palette */
.app-tile-icon--library {
  background: var(--palette-warm-900);
}
.app-tile-icon--people {
  background: var(--palette-warm-600);
}
.app-tile-icon--finder {
  background: var(--palette-green);
}
.app-tile-icon--tasks {
  background: var(--palette-amber);
}
.app-tile-icon--swim {
  background: var(--palette-green-sage-dark);
}
.app-tile-icon--routines {
  background: var(--palette-red);
}
.app-tile-icon--settings {
  background: var(--palette-warm-700);
}
.app-tile-icon--trick {
  background: var(--palette-blue);
}

.apps-grid-loading,
.apps-grid-empty {
  grid-column: 1 / -1;
  font-size: var(--text-sm);
  color: var(--theme-text-muted);
  padding: var(--space-6) 0;
  text-align: center;
}

.app-tile-label {
  font-size: var(--text-xs);
  font-weight: var(--font-medium);
  color: var(--theme-text-muted);
  text-align: center;
  line-height: var(--leading-snug);
}

/* Scores */
.score-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4) var(--space-7);
  border-bottom: 1px solid var(--theme-border);
}

.score-row:last-of-type {
  border-bottom: none;
}

.score-team {
  display: flex;
  align-items: center;
  gap: var(--space-4);
}

.team-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.team-name {
  font-size: var(--text-base);
  font-weight: var(--font-medium);
  color: var(--theme-text);
}

.score-num {
  font-family: var(--theme-font-display);
  font-size: var(--text-2xl);
  font-weight: var(--font-regular);
  color: var(--theme-text);
}

.score-status {
  font-size: var(--text-xs);
  font-weight: var(--font-medium);
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  color: var(--theme-text-muted);
  text-align: center;
  padding: var(--space-4) var(--space-7);
  border-top: 1px solid var(--theme-border);
}

/* Calorie tracker */
.cal-row {
  display: flex;
  align-items: center;
  gap: var(--space-8);
  margin-bottom: var(--space-6);
}

.cal-ring-wrap {
  width: 60px;
  height: 60px;
  position: relative;
  flex-shrink: 0;
}

.cal-ring {
  width: 100%;
  height: 100%;
}

.cal-ring-label {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-sm);
  font-weight: var(--font-semibold);
  color: var(--theme-text);
}

.cal-stats {
  display: flex;
  gap: var(--space-6);
}

.cal-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
}

.cal-stat-num {
  font-family: var(--theme-font-display);
  font-size: var(--text-lg);
  font-weight: var(--font-regular);
  color: var(--theme-text);
}

.cal-stat-label {
  font-size: var(--text-xs);
  color: var(--theme-text-muted);
  letter-spacing: 0.03em;
}

.cal-meals {
  display: flex;
  flex-direction: column;
}

.cal-meal {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-3) 0;
  border-bottom: 1px solid var(--theme-border);
}

.cal-meal:last-child {
  border-bottom: none;
  padding-bottom: 0;
}
.cal-meal-name {
  font-size: var(--text-base);
  color: var(--theme-text);
}
.cal-meal-val {
  font-size: var(--text-sm);
  color: var(--theme-text-muted);
  font-variant-numeric: tabular-nums;
}

/* Upcoming events */
.event-item {
  display: flex;
  align-items: center;
  gap: var(--space-6);
  padding: var(--space-4) var(--space-7);
  border-bottom: 1px solid var(--theme-border);
}

.event-item:last-child {
  border-bottom: none;
}

.event-time {
  font-size: var(--text-base);
  color: var(--theme-text-muted);
  min-width: 56px;
  flex-shrink: 0;
}

.event-info {
  flex: 1;
}

.event-name {
  font-size: var(--text-base);
  font-weight: var(--font-medium);
  color: var(--theme-text);
}

.event-detail {
  font-size: var(--text-sm);
  color: var(--theme-text-muted);
}

.event-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* ── Full-window app browser ─────────────────────────────── */

.app-fullwindow {
  position: fixed;
  inset: 0;
  z-index: calc(var(--z-nav) + 10);
  background: var(--theme-bg);
  display: none;
  flex-direction: column;
}

.app-fullwindow.visible {
  display: flex;
}

.app-fullwindow-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
}

.app-fullwindow-iframe {
  flex: 1;
  width: 100%;
  height: 100%;
  border: none;
  background: var(--theme-bg);
}

.app-fullwindow-swipe-edge {
  position: absolute;
  top: 0;
  left: 0;
  width: 20px;
  height: 100%;
  z-index: 10;
}

/* ══════════════════════════════════════════════════════════
   PROFILE PAGE
   ══════════════════════════════════════════════════════════ */

.profile-page {
  position: fixed;
  inset: 0;
  z-index: var(--z-overlay);
  background: var(--theme-bg);
  transform: translateY(100%);
  transition: transform 320ms var(--ease-spring);
  display: flex;
  flex-direction: column;
  font-family: var(--theme-font-body);
  overflow: hidden;
}

.profile-page.visible {
  transform: translateY(0);
}

/* Persistent floating close button — always top-right */
.profile-close-btn {
  position: absolute;
  top: calc(var(--safe-top) + var(--space-5));
  right: var(--space-5);
  z-index: 20;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-full);
  background: rgba(0, 0, 0, 0.3);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: opacity var(--duration-fast);
}

.profile-close-btn:active {
  opacity: 0.6;
}

/* ── Sticky header (visible after scroll) ── */
.profile-sticky-header {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 10;
  height: calc(var(--safe-top) + 56px);
  padding-top: var(--safe-top);
  display: flex;
  align-items: center;
  gap: var(--space-6);
  padding-left: var(--space-8);
  background: var(--theme-bg);
  border-bottom: 1px solid var(--theme-border);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--duration-normal);
}

.profile-sticky-header.visible {
  opacity: 1;
  pointer-events: auto;
}

.profile-sticky-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  display: block;
  flex-shrink: 0;
}

.profile-sticky-name {
  font-size: var(--text-md);
  font-weight: var(--font-semibold);
  color: var(--theme-text);
}

/* ── Hero (full-bleed → circle on scroll) ── */
.profile-page-scroll {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.profile-hero-section {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 260px;
  max-height: 80vw;
  overflow: hidden;
  background: transparent;
}

.profile-hero-image {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border-radius: 0;
  overflow: hidden;
  will-change: width, height, border-radius, left, top;
}

.profile-hero-avatar-fill {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  opacity: 1;
}

/* gradient fade at bottom so name reads cleanly */
.profile-hero-overlay {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: var(--space-14) var(--space-8) var(--space-8);
  background: linear-gradient(
    to bottom,
    transparent 0%,
    rgba(0, 0, 0, 0.55) 100%
  );
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  pointer-events: none;
}

.profile-back-btn {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-full);
  background: var(--glass-bg);
  -webkit-backdrop-filter: var(--glass-filter);
  backdrop-filter: var(--glass-filter);
  border: 1px solid var(--glass-border);
  box-shadow: var(--glass-shadow);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--theme-text);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  flex-shrink: 0;
}

.profile-back-btn:active {
  opacity: 0.6;
}

/* back btn floating over the hero image */
.profile-back-btn--hero {
  position: absolute;
  top: calc(var(--safe-top) + var(--space-6));
  left: var(--space-8);
  color: var(--palette-white);
  background: rgba(0, 0, 0, 0.28);
  border-color: rgba(255, 255, 255, 0.25);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  box-shadow: none;
}

.profile-name-lg {
  font-size: var(--text-2xl);
  font-weight: var(--font-semibold);
  color: var(--palette-white);
  letter-spacing: -0.01em;
}

.profile-status {
  font-size: var(--text-sm);
  color: var(--theme-success);
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

/* ── Action row (3 cards) ── */
.profile-actions-row {
  display: flex;
  justify-content: center;
  padding: var(--space-10) var(--space-8) var(--space-8);
  gap: var(--space-6);
}

.profile-action {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.profile-action:active .profile-action-icon {
  opacity: 0.55;
  transform: scale(0.95);
}

.profile-action-icon {
  width: 52px;
  height: 52px;
  border-radius: var(--theme-radius-item);
  background: var(--glass-bg);
  -webkit-backdrop-filter: var(--glass-filter);
  backdrop-filter: var(--glass-filter);
  border: 1px solid var(--glass-border);
  box-shadow: var(--glass-shadow);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--theme-text);
  transition:
    opacity var(--duration-fast),
    transform var(--duration-fast);
}

.profile-action-label {
  font-size: var(--text-sm);
  color: var(--theme-text-muted);
  font-weight: var(--font-medium);
}

/* ── Finder tabs — liquid glass pill ── */
.profile-finder-section {
  background: var(--theme-bg);
  padding: var(--space-8) var(--space-8) 0;
}

/* Profile finder section uses shared .segment-tabs */
.profile-finder-section .segment-tabs {
  margin-bottom: var(--space-4);
}

.profile-finder-content {
  min-height: 220px;
  background: var(--theme-surface);
  border-radius: var(--theme-radius-card) var(--theme-radius-card) 0 0;
  overflow: hidden;
}

.finder-photo-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 2px;
  padding: 2px;
}

.finder-photo-cell {
  aspect-ratio: 1;
  border-radius: var(--radius-xs);
  cursor: pointer;
  transition: opacity var(--duration-fast);
}

.finder-photo-cell:active {
  opacity: 0.75;
}

/* ── Finder file list ── */
.finder-file-list {
  display: flex;
  flex-direction: column;
}

.finder-file-row {
  display: flex;
  align-items: center;
  gap: var(--space-6);
  padding: var(--space-6) var(--space-8);
  border-bottom: 1px solid var(--theme-border);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background var(--duration-fast);
}

.finder-file-row:last-child {
  border-bottom: none;
}
.finder-file-row:active {
  background: var(--theme-surface-soft);
}

.finder-file-icon {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  background: var(--theme-surface-soft);
  border: 1px solid var(--theme-border);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--theme-text-muted);
}

.finder-file-info {
  flex: 1;
  min-width: 0;
}

.finder-file-name {
  font-size: var(--text-md);
  font-weight: var(--font-medium);
  color: var(--theme-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.finder-file-meta {
  font-size: var(--text-sm);
  color: var(--theme-text-muted);
  margin-top: var(--space-1);
}

.finder-empty {
  padding: var(--space-14) var(--space-8);
  text-align: center;
  font-size: var(--text-md);
  color: var(--theme-text-muted);
}

/* ══════════════════════════════════════════════════════════
   ANIMATIONS
   ══════════════════════════════════════════════════════════ */

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

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

@keyframes scaleIn {
  from {
    transform: scale(0.92);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes typingBounce {
  0%,
  60%,
  100% {
    transform: translateY(0);
  }
  30% {
    transform: translateY(-5px);
  }
}

/* ── Canvas send preview ────────────────────────────────── */
#canvas-send-preview {
  position: fixed;
  bottom: calc(var(--safe-bottom) + 70px);
  left: 0;
  right: 0;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 0 var(--space-4);
  pointer-events: none;
}

.canvas-preview-row {
  animation: canvas-bubble-in 220ms cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
  will-change: transform, opacity;
  filter: drop-shadow(0 4px 16px rgba(0, 0, 0, 0.18))
    drop-shadow(0 1px 4px rgba(0, 0, 0, 0.1));
}

.canvas-preview-row.canvas-preview-leaving {
  animation: canvas-bubble-out 280ms ease-in forwards;
}

.canvas-preview-row.dir-out .msg-bubble {
  cursor: pointer;
}

.canvas-preview-row.dir-out .msg-bubble:active {
  opacity: 0.75;
}

@keyframes canvas-bubble-in {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.92);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes canvas-bubble-out {
  from {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
  to {
    opacity: 0;
    transform: translateY(-8px) scale(0.92);
  }
}

/* ═══════════════════════════════════════════════════════════
   NEW BUBBLE TYPES + MISSING CASES
   ═══════════════════════════════════════════════════════════ */

/* ── Message status ticks ────────────────────────────────── */
.msg-status {
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
  margin-left: 2px;
  line-height: 1;
}

.msg-status--pending {
  color: var(--theme-bubble-text-out);
  opacity: 0.55;
}
.msg-status--sent {
  color: var(--theme-bubble-text-out);
  opacity: 0.65;
}
.msg-status--delivered {
  color: var(--theme-bubble-text-out);
  opacity: 0.65;
}
.msg-status--read {
  color: #4fc3f7;
  opacity: 1;
}
.msg-status--failed {
  color: #ff3b30;
  opacity: 1;
  cursor: pointer;
}
.msg-status--failed:active {
  opacity: 0.6;
}

/* ── Bubble "edited" label ────────────────────────────────── */
.bubble-edited {
  font-size: var(--text-xs);
  opacity: 0.55;
  margin-right: 2px;
  white-space: nowrap;
  font-style: italic;
}
.dir-in .bubble-edited {
  color: var(--theme-bubble-text-out);
}

/* ── Reaction count badge ────────────────────────────────── */
.reaction-count {
  font-size: 11px;
  font-weight: 600;
  margin-left: 2px;
  line-height: 1;
}

.reaction-chip.reacted-by-me {
  outline: 1.5px solid var(--palette-blue);
}

/* ── Media bubbles (image + video) ───────────────────────── */
.media-bubble {
  padding: 0 !important;
  overflow: hidden;
  gap: 0;
}

.media-thumb {
  width: 220px;
  height: 165px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  flex-shrink: 0;
  overflow: hidden;
}

/* Media thumb corners must track the outer bubble minus 3px padding */
.dir-out .media-thumb {
  border-radius: 18px 18px 18px 4px;
}
.dir-out:not(.first-in-group) .media-thumb {
  border-radius: 4px 18px 18px 4px;
}
.dir-in .media-thumb {
  border-radius: 18px 18px 4px 18px;
}
.dir-in:not(.first-in-group) .media-thumb {
  border-radius: 18px 4px 4px 18px;
}

.media-thumb-icon {
  opacity: 0.7;
}

.media-caption {
  font-size: var(--text-lg);
  color: var(--theme-text);
  padding: var(--space-2) var(--space-4) 0;
  line-height: var(--leading-snug);
}

.dir-in .media-caption {
  color: var(--theme-bubble-text-out);
}

.bubble-time--media {
  /* time overlays on bottom-right of media */
}

.media-bubble .bubble-footer {
  padding: var(--space-1) var(--space-3) var(--space-2) var(--space-3);
}

/* ── Video bubble extras ─────────────────────────────────── */
.video-thumb {
  position: relative;
}

.video-play-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.42);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.video-duration-badge {
  position: absolute;
  bottom: 8px;
  right: 8px;
  background: rgba(0, 0, 0, 0.52);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 8px;
  line-height: 1.4;
}

/* ── Forwarded label ─────────────────────────────────────── */
.forwarded-label {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: var(--text-sm);
  opacity: 0.55;
  font-style: italic;
  margin-bottom: var(--space-2);
}

/* ── Link preview card ────────────────────────────────────── */
a.link-preview,
.link-preview {
  display: flex;
  gap: var(--space-3);
  margin-top: var(--space-3);
  padding: var(--space-3);
  border-radius: var(--radius-md);
  background: rgba(0, 0, 0, 0.06);
  border-left: 3px solid var(--palette-blue);
  align-items: flex-start;
  cursor: pointer;
  text-decoration: none;
  color: inherit;
}

.dir-in .link-preview {
  background: rgba(255, 255, 255, 0.15);
  border-left-color: rgba(255, 255, 255, 0.6);
}

.link-preview-favicon {
  font-size: 18px;
  flex-shrink: 0;
  line-height: 1.2;
}

.link-preview-body {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.link-preview-title {
  font-size: var(--text-sm);
  font-weight: var(--font-semibold);
  line-height: var(--leading-snug);
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.link-preview-desc {
  font-size: var(--text-xs);
  opacity: 0.7;
  line-height: var(--leading-snug);
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.link-preview-url {
  font-size: 10px;
  opacity: 0.45;
  margin-top: 2px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

/* ── Forward sheet ────────────────────────────────────────── */
.forward-overlay {
  position: fixed;
  inset: 0;
  z-index: 700;
  background: rgba(0, 0, 0, 0);
  transition: background 0.25s ease;
  pointer-events: none;
}

.forward-overlay.open {
  background: rgba(0, 0, 0, 0.4);
  pointer-events: auto;
}

.forward-sheet {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--theme-surface);
  border-radius: 20px 20px 0 0;
  padding: 12px 0 calc(var(--safe-bottom) + 16px);
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.34, 1.2, 0.64, 1);
  display: flex;
  flex-direction: column;
  gap: 0;
}

.forward-sheet.open {
  transform: translateY(0);
}

.forward-sheet-handle {
  width: 36px;
  height: 4px;
  border-radius: 2px;
  background: var(--theme-border);
  margin: 0 auto 14px;
}

.forward-sheet-title {
  font-size: var(--text-lg);
  font-weight: var(--font-semibold);
  color: var(--theme-text);
  padding: 0 20px 12px;
  border-bottom: 0.5px solid var(--theme-border);
}

.forward-contacts {
  display: flex;
  gap: var(--space-5);
  padding: 16px 20px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.forward-contacts::-webkit-scrollbar {
  display: none;
}

.forward-contact {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  background: none;
  border: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  flex-shrink: 0;
}

.forward-contact:active .forward-avatar {
  transform: scale(0.9);
}

.forward-avatar {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--palette-blue);
  color: #fff;
  font-size: var(--text-xl);
  font-weight: var(--font-semibold);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform var(--duration-fast);
}

.forward-name {
  font-size: var(--text-sm);
  color: var(--theme-text);
  white-space: nowrap;
}

/* ── Edit bar ─────────────────────────────────────────────── */
.edit-bar {
  display: flex;
  align-items: stretch;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-4);
  background: var(--theme-surface-soft);
  border-radius: var(--radius-md);
  margin: 0 0 var(--space-2);
  position: relative;
}

.edit-bar-left-accent {
  width: 3px;
  background: var(--palette-blue);
  border-radius: 2px;
  flex-shrink: 0;
}

.edit-bar-content {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.edit-bar-label {
  font-size: var(--text-sm);
  font-weight: var(--font-semibold);
  color: var(--palette-blue);
}

.edit-bar-text {
  font-size: var(--text-base);
  color: var(--theme-text-muted);
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.edit-bar-close {
  background: none;
  border: none;
  color: var(--theme-text-muted);
  font-size: 16px;
  cursor: pointer;
  padding: 4px;
  display: flex;
  align-items: center;
  -webkit-tap-highlight-color: transparent;
}

/* ── Empty state ──────────────────────────────────────────── */
.chat-empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 80px 32px;
  gap: var(--space-4);
  text-align: center;
}

.chat-empty-avatar {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: var(--palette-blue);
  color: #fff;
  font-size: 32px;
  font-weight: var(--font-semibold);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: var(--space-2);
}

.chat-empty-avatar-img {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  object-fit: cover;
  margin-bottom: var(--space-2);
}

.chat-empty-title {
  font-size: var(--text-xl);
  font-weight: var(--font-semibold);
  color: var(--theme-text);
}

.chat-empty-sub {
  font-size: var(--text-base);
  color: var(--theme-text-muted);
}

/* ── Profile avatar fallback ─────────────────────────────── */
.header-avatar-inline,
.profile-hero-avatar-fill,
.profile-sticky-avatar {
  /* If image fails, show a colored background with initial */
  background: var(--palette-blue);
  color: #fff;
}

.header-avatar-inline {
  object-fit: cover;
}

/* ── Typing indicator (animated) ─────────────────────────── */
#typing-row {
  animation: fadeIn 0.2s ease forwards;
}

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