/* Import modular styles */
@import url('./chat/thinking.css');

/* ================= ROOT & GLOBALS ================= */
:root {
  /* expose iOS safe area to JS (used in fitStage) */
  --sa-top: env(safe-area-inset-top);
  --sa-right: env(safe-area-inset-right);
  --sa-bottom: env(safe-area-inset-bottom);
  --sa-left: env(safe-area-inset-left);
  --chat-floating-controls-offset: calc(var(--input-section-height, 96px) + 12px);
  --chat-realism-panel-top-clearance: calc(var(--app-header-height, var(--topbar-height, 60px)) + 24px);
  --chat-realism-panel-bottom-clearance: calc(var(--chat-bottom-pad, 110px) + 12px);
}

body.capsule-overlay-active {
  overflow: hidden;
}

/* ================= CHAT LAYOUT & CONTAINERS ================= */
.chat-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--primary-bg);
  overflow: hidden;
  position: relative;
}

.chat-messages {
  position: relative;
  flex: 1;
  --empty-cloud-react: 0;
  overflow-y: auto;
  overflow-x: hidden;
  overflow-anchor: none; /* Prevent browser scroll anchoring from shifting view when images load */
  touch-action: pan-y;
  padding: 20px 12px;
  padding-bottom: var(--chat-bottom-pad, 100px); /* Dynamically set by handleViewportChange() in mm_utils.js */
  display: flex;
  flex-direction: column-reverse;
  gap: 12px;
  background: #000000;
  transition: background-color 0.4s ease, filter 0.15s ease;
}

/* ================= FLOATING CHAT CONTROLS ================= */

.scroll-bottom-btn {
  --scroll-btn-x: -50%;
  --scroll-btn-y: 0px;
  --scroll-btn-scale: 1;
  position: fixed;
  left: 50%;
  right: auto;
  bottom: var(--chat-floating-controls-offset, calc(var(--input-section-height, 96px) + 12px));
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 999px;
  background: rgba(18, 18, 20, 0.84);
  color: rgba(255, 255, 255, 0.94);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0;
  line-height: 0;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  box-shadow:
    0 10px 28px rgba(0, 0, 0, 0.34),
    0 3px 10px rgba(0, 0, 0, 0.22),
    inset 0 1px 0 rgba(255, 255, 255, 0.1);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  z-index: 2100;
  transform: translate3d(var(--scroll-btn-x), var(--scroll-btn-y), 0) scale(var(--scroll-btn-scale));
  transform-origin: center;
  transition:
    opacity 0.2s ease,
    visibility 0.2s ease,
    background 0.2s ease,
    border-color 0.2s ease,
    box-shadow 0.2s ease,
    transform 0.2s ease;
}

.scroll-bottom-btn:not([style*="display: none"]) {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.scroll-bottom-btn.no-thumbnails {
  bottom: var(--chat-floating-controls-offset, calc(var(--input-section-height, 96px) + 12px));
}

.scroll-bottom-btn:hover {
  --scroll-btn-y: -2px;
  --scroll-btn-scale: 1.02;
  background: rgba(24, 24, 28, 0.92);
  border-color: rgba(255, 255, 255, 0.24);
  box-shadow:
    0 12px 30px rgba(0, 0, 0, 0.38),
    0 4px 12px rgba(0, 0, 0, 0.26),
    inset 0 1px 0 rgba(255, 255, 255, 0.13);
}

.scroll-bottom-btn:active {
  --scroll-btn-y: 0px;
  --scroll-btn-scale: 0.98;
}

.scroll-bottom-btn:focus-visible {
  outline: 2px solid rgba(245, 166, 35, 0.65);
  outline-offset: 2px;
}

.scroll-bottom-btn svg {
  width: 20px;
  height: 20px;
  display: block;
  margin: 0;
  pointer-events: none;
}

.scroll-bottom-btn.pulse {
  animation: scroll-bottom-btn-pulse 2s ease-in-out infinite;
}

@keyframes scroll-bottom-btn-pulse {
  0%, 100% {
    box-shadow:
      0 10px 28px rgba(0, 0, 0, 0.34),
      0 3px 10px rgba(0, 0, 0, 0.22),
      inset 0 1px 0 rgba(255, 255, 255, 0.1);
  }
  50% {
    box-shadow:
      0 12px 30px rgba(74, 158, 255, 0.24),
      0 4px 12px rgba(0, 0, 0, 0.24),
      inset 0 1px 0 rgba(255, 255, 255, 0.12);
  }
}

@media (min-width: 769px) {
  .main-content.sidebar-open .scroll-bottom-btn,
  .sidebar.open ~ .main-content .scroll-bottom-btn {
    --scroll-btn-x: calc(-50% + (var(--sidebar-width, 0px) / 2));
  }

  .main-content.generations-open .scroll-bottom-btn {
    --scroll-btn-x: calc(-50% - (var(--capsule-panel-width, 0px) / 2));
  }

  .main-content.sidebar-open.generations-open .scroll-bottom-btn,
  .sidebar.open ~ .main-content.generations-open .scroll-bottom-btn {
    --scroll-btn-x: calc(-50% + ((var(--sidebar-width, 0px) - var(--capsule-panel-width, 0px)) / 2));
  }
}

@media (max-width: 768px) {
  :root {
    --chat-floating-controls-offset: calc(var(--input-section-height, 88px) + 8px);
    --chat-realism-panel-top-clearance: calc(var(--topbar-height-mobile, 56px) + 18px);
  }

  .scroll-bottom-btn {
    width: 40px;
    height: 40px;
  }

  .scroll-bottom-btn svg {
    width: 18px;
    height: 18px;
  }
}

.chat-messages::before,
.chat-messages::after {
  content: '';
  position: absolute;
  inset: -24%;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.45s ease, transform 0.45s ease, filter 0.45s ease;
  will-change: transform, opacity;
}

/* DISABLED: orange glow animation was confusing users (looked like a bug)
body.tips-empty-cloud-ready .chat-messages.chat-empty-cloud-visible {
  background:
    radial-gradient(170% 120% at 50% -18%, rgba(43, 54, 76, 0.4) 0%, rgba(10, 12, 16, 0) 72%),
    linear-gradient(166deg, #06070c 0%, #0b0d13 44%, #090b11 100%);
}

body.tips-empty-cloud-ready .chat-messages.chat-empty-cloud-visible::before {
  inset: -34%;
  opacity: 0.78;
  background:
    radial-gradient(ellipse 78% 56% at 51% 58%, rgba(255, 138, 70, 0.33) 0%, rgba(255, 138, 70, 0) 82%),
    radial-gradient(ellipse 54% 40% at 62% 45%, rgba(255, 92, 64, 0.24) 0%, rgba(255, 92, 64, 0) 78%),
    radial-gradient(ellipse 52% 38% at 38% 53%, rgba(227, 66, 52, 0.22) 0%, rgba(227, 66, 52, 0) 78%),
    radial-gradient(ellipse 48% 34% at 66% 62%, rgba(80, 226, 255, 0.2) 0%, rgba(80, 226, 255, 0) 78%),
    radial-gradient(ellipse 42% 30% at 35% 67%, rgba(255, 210, 92, 0.18) 0%, rgba(255, 210, 92, 0) 76%),
    radial-gradient(ellipse 92% 68% at 52% 60%, rgba(156, 163, 175, 0.16) 0%, rgba(156, 163, 175, 0) 84%);
  mask-image: radial-gradient(ellipse 118% 92% at 50% 60%, rgba(0, 0, 0, 0.98) 0%, rgba(0, 0, 0, 0.86) 63%, rgba(0, 0, 0, 0) 100%);
  -webkit-mask-image: radial-gradient(ellipse 118% 92% at 50% 60%, rgba(0, 0, 0, 0.98) 0%, rgba(0, 0, 0, 0.86) 63%, rgba(0, 0, 0, 0) 100%);
  filter: blur(64px) saturate(110%);
  animation: chat-empty-plasma-drift calc(19s - (7s * var(--empty-cloud-react, 0))) cubic-bezier(0.4, 0, 0.2, 1) infinite alternate;
}

body.tips-empty-cloud-ready .chat-messages.chat-empty-cloud-visible::after {
  inset: -26%;
  opacity: 0.58;
  background:
    radial-gradient(ellipse 88% 62% at 50% 60%, rgba(255, 255, 255, 0.09) 0%, rgba(255, 255, 255, 0) 82%),
    radial-gradient(ellipse 98% 70% at 50% 60%, rgba(255, 166, 109, 0.1) 0%, rgba(255, 166, 109, 0) 84%),
    radial-gradient(ellipse 64% 44% at 44% 56%, rgba(240, 94, 72, 0.08) 0%, rgba(240, 94, 72, 0) 82%);
  mask-image: radial-gradient(ellipse 132% 104% at 50% 60%, rgba(0, 0, 0, 0.9) 0%, rgba(0, 0, 0, 0.68) 66%, rgba(0, 0, 0, 0) 100%);
  -webkit-mask-image: radial-gradient(ellipse 132% 104% at 50% 60%, rgba(0, 0, 0, 0.9) 0%, rgba(0, 0, 0, 0.68) 66%, rgba(0, 0, 0, 0) 100%);
  filter: blur(36px);
  animation: chat-empty-plasma-breathe calc(8.6s - (2.8s * var(--empty-cloud-react, 0))) ease-in-out infinite;
}

body.tips-empty-cloud-ready .chat-messages.chat-empty-cloud-visible.chat-empty-typing::before {
  opacity: calc(0.78 + (0.14 * var(--empty-cloud-react, 0)));
  filter: blur(calc(64px - (12px * var(--empty-cloud-react, 0)))) saturate(calc(110% + (18% * var(--empty-cloud-react, 0))));
}

body.tips-empty-cloud-ready .chat-messages.chat-empty-cloud-visible.chat-empty-typing::after {
  opacity: calc(0.58 + (0.16 * var(--empty-cloud-react, 0)));
  filter: blur(calc(36px - (8px * var(--empty-cloud-react, 0))));
}

body.tips-empty-cloud-ready .chat-messages.chat-empty-cloud-visible.chat-empty-fading-out::before,
body.tips-empty-cloud-ready .chat-messages.chat-empty-cloud-visible.chat-empty-fading-out::after {
  animation: none;
  opacity: 0 !important;
  transform: translate3d(0, -2.4%, 0) scale(1.08);
  transition: opacity 2.6s ease, transform 2.6s cubic-bezier(0.22, 1, 0.36, 1), filter 2.6s ease;
}

body.tips-empty-cloud-ready .chat-messages.chat-empty-cloud-visible.chat-empty-fading-out {
  background:
    radial-gradient(170% 120% at 50% -18%, rgba(43, 54, 76, 0.16) 0%, rgba(10, 12, 16, 0) 74%),
    linear-gradient(165deg, #06070c 0%, #07090d 46%, #06080c 100%);
  transition: background 2.6s ease, background-color 2.6s ease, filter 2.6s ease;
}

@keyframes chat-empty-plasma-drift {
  0% { transform: translate3d(-2.8%, -2.2%, 0) scale(0.96); }
  35% { transform: translate3d(2.2%, 1.2%, 0) scale(1.04); }
  70% { transform: translate3d(-1.9%, 2.7%, 0) scale(1.01); }
  100% { transform: translate3d(2.5%, -1.6%, 0) scale(1.05); }
}

@keyframes chat-empty-plasma-breathe {
  0%, 100% { opacity: 0.38; transform: scale(0.97); }
  50% { opacity: 0.76; transform: scale(1.07); }
}
*/

/* Viewer mode background - different styling when user is viewer */
.chat-messages.viewer-mode {
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.03) 0%, rgba(139, 92, 246, 0.02) 100%);
  position: relative;
}

.chat-messages.viewer-mode::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: 
    radial-gradient(circle at 20% 30%, rgba(99, 102, 241, 0.04) 0%, transparent 50%),
    radial-gradient(circle at 80% 70%, rgba(139, 92, 246, 0.03) 0%, transparent 50%);
  pointer-events: none;
  z-index: 0;
}

.chat-messages.viewer-mode > * {
  position: relative;
  z-index: 1;
}

.chat-messages.loading {
  filter: blur(20px);
  pointer-events: none;
}

#chatTopSentinel {
  height: 1px;
}

/* Drag & Drop State */
.chat-messages.drag-over {
  background: radial-gradient(circle at center, rgba(255, 255, 255, 0.05) 0%, transparent 70%);
}

.chat-messages.drag-over::before {
  content: var(--formas-i18n-drop-chat, "Drop here to add to chat");
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  padding: 12px 24px;
  background: rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  color: rgba(255, 255, 255, 0.9);
  font-size: 14px;
  font-weight: 500;
  border-radius: 24px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3), 
              0 0 0 1px rgba(255, 255, 255, 0.05) inset;
  z-index: 1200;
  pointer-events: none;
}


/* ================= LOADERS, OVERLAYS & SENTINELS ================= */

/* Project Loading Overlay */
.project-loading {
  position: fixed;
  top: 50px;
  left: 0;
  right: 0;
  bottom: 0;
  width: auto;
  height: auto;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
  color: rgba(255, 248, 240, 0.92);
  z-index: 100;
  background: transparent;
  overflow: hidden;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.8s ease, visibility 0s linear 0.8s;
  text-align: center;
}

.project-loading::before {
  content: none;
}

.project-loading.active {
  opacity: 1;
  visibility: visible;
  pointer-events: none; /* Allow clicks to pass through loading overlay */
  transition: opacity 0.8s ease;
}

.project-loading .spinner {
  display: none;
}

.project-loading > .project-loading-title {
  margin: 0 0 10px;
  color: rgba(255, 248, 240, 0.5);
  font-family: 'Times New Roman', Times, Georgia, serif;
  font-size: clamp(13px, 0.9vw, 16px);
  font-style: italic;
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: 0;
  text-shadow: none;
}

.project-loading .project-name-pill {
  position: relative;
  overflow: hidden;
  box-sizing: border-box;
  max-width: min(480px, 76vw);
  min-width: 0;
  margin: 0;
  padding: 0 3px 10px;
  background: transparent;
  border: 0;
  border-radius: 0;
  color: rgba(255, 248, 240, 0.92);
  font-family: 'Times New Roman', Times, Georgia, serif;
  font-size: clamp(22px, 1.75vw, 30px);
  font-style: italic;
  font-weight: 700;
  line-height: 1;
  letter-spacing: 0;
  text-align: center;
  white-space: nowrap;
  text-overflow: ellipsis;
  text-shadow: none;
  box-shadow: none;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}

.project-name-pill.loading-progress {
  isolation: isolate;
}

.project-loading .project-name-pill::after {
  content: '';
  position: absolute;
  left: 50%;
  bottom: 0;
  width: min(76px, 58%);
  height: 1px;
  background: rgba(255, 248, 240, 0.16);
  transform: translateX(-50%);
  pointer-events: none;
}

.project-name-pill.loading-progress::before,
.project-name-pill.progress-complete::before {
  content: '';
  position: absolute;
  left: 50%;
  right: auto;
  bottom: 0;
  height: 1px;
  width: max(24px, min(var(--progress, 0%), 76px));
  max-width: 58%;
  background: rgba(255, 248, 240, 0.82);
  box-shadow: none;
  transform: translateX(-50%);
  transition: width 0.45s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.35s ease;
  pointer-events: none;
}

.project-name-pill.progress-complete::before {
  width: min(76px, 58%);
  opacity: 0.64;
}

.main-header-title > .project-name-pill {
  position: relative;
  display: inline-block;
  max-width: min(220px, 30vw);
  margin-left: 8px;
  padding-bottom: 4px;
  overflow: hidden;
  color: rgba(255, 248, 240, 0.56);
  font-family: 'Times New Roman', Times, Georgia, serif;
  font-size: 12px;
  font-style: italic;
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: 0;
  white-space: nowrap;
  text-overflow: ellipsis;
}

/* Hide full-screen overlay on mobile - use mobile pill instead */
@media (max-width: 768px) {
  .project-loading {
    display: none !important;
  }
}

/* ================= MOBILE PROJECT LOADING PILL ================= */
/* A beautiful centered loading screen for mobile that shows project loading progress */
.mobile-project-loading-pill {
  display: none; /* Hidden by default, shown via JS on mobile */
}

@media (max-width: 768px) {
  .mobile-project-loading-pill {
    position: fixed;
    inset: 0;
    z-index: 1100;
    
    /* Center content */
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 24px;
    padding: 40px 24px;
    
    background: rgba(0, 0, 0, 0.82);
    
    /* Hidden state */
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: 
      opacity 0.4s cubic-bezier(0.4, 0, 0.2, 1),
      visibility 0s linear 0.4s;
  }
  
  .mobile-project-loading-pill.active {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transition: opacity 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  }
  
  /* Spinner - larger and more prominent for centered view */
  .mobile-loading-spinner {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: 3px solid rgba(255, 255, 255, 0.08);
    border-top-color: rgba(255, 255, 255, 0.9);
    animation: mobileLoadingSpin 1s cubic-bezier(0.4, 0.15, 0.6, 0.85) infinite;
    flex-shrink: 0;
    box-shadow: 
      0 0 20px rgba(255, 255, 255, 0.1),
      inset 0 0 12px rgba(255, 255, 255, 0.05);
  }
  
  @keyframes mobileLoadingSpin {
    to { transform: rotate(360deg); }
  }
  
  /* Content area - centered and elegant */
  .mobile-loading-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    width: 100%;
    max-width: 280px;
  }
  
  /* Loading text - larger and centered */
  .mobile-loading-text {
    color: rgba(255, 248, 240, 0.9);
    font-family: 'Times New Roman', Times, serif;
    font-size: 22px;
    font-weight: 700;
    font-style: italic;
    letter-spacing: 0.2px;
    text-align: center;
    line-height: 1.3;
  }
  
  /* Progress bar container - pill shaped */
  .mobile-loading-progress-track {
    width: 100%;
    height: 6px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 10px;
    overflow: hidden;
    position: relative;
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.3);
  }
  
  /* Progress bar fill - with glow */
  .mobile-loading-progress-bar {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, 
      rgba(200, 200, 200, 0.8) 0%,
      rgba(255, 255, 255, 1) 50%,
      rgba(200, 200, 200, 0.8) 100%
    );
    border-radius: 10px;
    transition: width 0.8s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    box-shadow: 0 0 12px rgba(255, 255, 255, 0.2);
  }
  
  /* Shimmer effect on progress bar */
  .mobile-loading-progress-bar::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(
      90deg,
      transparent 0%,
      rgba(255, 255, 255, 0.5) 50%,
      transparent 100%
    );
    animation: progressShimmer 1.5s ease-in-out infinite;
  }
  
  @keyframes progressShimmer {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(100%); }
  }
  
  /* Indeterminate state - smooth back and forth animation */
  .mobile-project-loading-pill.indeterminate .mobile-loading-progress-bar {
    width: 40%;
    animation: indeterminateProgress 1.6s ease-in-out infinite;
  }
  
  @keyframes indeterminateProgress {
    0% { 
      transform: translateX(-100%);
    }
    50% {
      transform: translateX(150%);
    }
    100% { 
      transform: translateX(-100%);
    }
  }
  
  /* Complete state - keep the same quiet FORMAS loading language */
  .mobile-project-loading-pill.complete .mobile-loading-progress-bar {
    width: 100%;
    background: linear-gradient(90deg, 
      rgba(255, 248, 240, 0.22) 0%,
      rgba(255, 248, 240, 0.72) 50%,
      rgba(255, 248, 240, 0.22) 100%
    );
    box-shadow: 0 0 16px rgba(255, 248, 240, 0.18);
  }
  
  .mobile-project-loading-pill.complete .mobile-loading-spinner {
    border-top-color: rgba(255, 248, 240, 0.9);
    box-shadow: 
      0 0 20px rgba(255, 248, 240, 0.12),
      inset 0 0 12px rgba(255, 248, 240, 0.06);
  }
  
  .mobile-project-loading-pill.complete .mobile-loading-text {
    color: rgba(255, 248, 240, 0.9);
  }
}

/* Ensure mobile pill doesn't show when boot overlay is active */
/* Uses :has() selector with fallback class-based approach */
body:has(.app-boot-overlay:not(.is-hiding)) .mobile-project-loading-pill {
  opacity: 0 !important;
  visibility: hidden !important;
}

/* Fallback for browsers that don't support :has() - uses body class set via JS */
body.boot-overlay-active .mobile-project-loading-pill {
  opacity: 0 !important;
  visibility: hidden !important;
}

/* Top Loader (Infinite Scroll) */
.chat-top-loader {
  position: sticky;
  top: 0;
  width: 100%;
  height: 60px;
  display: flex;
  justify-content: center;
  align-items: center;
  background: linear-gradient(
    to bottom, 
    rgba(10,10,10,0.95), 
    rgba(10,10,10,0.8),
    rgba(10,10,10,0)
  );
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 5;
  transition: all 0.3s ease;
}

/* Extend gradient upward to fully cover top area */
.chat-top-loader::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  /* Extend 80px above, plus safe-area if present */
  top: calc(-80px - var(--sa-top, 0px));
  height: calc(80px + var(--sa-top, 0px));
  background: linear-gradient(
    to bottom,
    rgba(10,10,10,0.95),
    rgba(10,10,10,0.8),
    rgba(10,10,10,0)
  );
  pointer-events: none;
}

.chat-top-loader.hidden {
  opacity: 0;
  transform: translateY(-20px);
  pointer-events: none;
}

.chat-top-loader .spinner {
  width: 28px;
  height: 28px;
  border: 2px solid rgba(255,255,255,0.2);
  border-top-color: rgba(74, 158, 255, 0.8);
  border-radius: 50%;
  animation: modernSpin 1.2s cubic-bezier(0.4, 0, 0.2, 1) infinite;
}

@keyframes modernSpin {
  to {
    transform: rotate(360deg);
  }
}

/* Image Viewer ("Capsule") Overlay */
#capsuleImageOverlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding:
    max(16px, env(safe-area-inset-top))
    max(16px, env(safe-area-inset-right))
    max(16px, env(safe-area-inset-bottom))
    max(16px, env(safe-area-inset-left));
  background: rgba(10, 10, 12, 0.86);
  backdrop-filter: blur(6px) saturate(110%);
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s ease;
  z-index: 9999;
}

#capsuleImageOverlay.active {
  opacity: 1;
  pointer-events: auto;
}

/* While media is loading, avoid showing blurred canvas behind the overlay */
#capsuleImageOverlay.media-loading {
  background: #000000 !important;
  background-image: none !important;
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
}

/* Keep stage dark and show explicit loading state while media decodes */
#capsuleImageOverlay.media-loading #capsuleOverlayMedia {
  visibility: visible;
  background: #000 !important;
  pointer-events: none;
}

#capsuleImageOverlay.media-loading #capsuleOverlayMedia img,
#capsuleImageOverlay.media-loading #capsuleOverlayMedia video,
#capsuleImageOverlay.media-loading #capsuleOverlaySlider {
  opacity: 0 !important;
}

#capsuleImageOverlay.media-loading #capsuleOverlayMedia::before {
  content: '';
  position: absolute;
  top: calc(50% - 14px);
  left: 50%;
  width: 22px;
  height: 22px;
  margin-left: -11px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.22);
  border-top-color: rgba(255, 255, 255, 0.92);
  animation: mmViewerLoadingSpin 0.9s linear infinite;
  pointer-events: none;
  z-index: 3;
}

#capsuleImageOverlay.media-loading #capsuleOverlayMedia::after {
  content: var(--formas-i18n-loading, 'Loading…');
  position: absolute;
  top: calc(50% + 14px);
  left: 50%;
  transform: translateX(-50%);
  color: rgba(255, 255, 255, 0.72);
  font-size: 12px;
  letter-spacing: 0.2px;
  pointer-events: none;
  z-index: 3;
}

@keyframes mmViewerLoadingSpin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

#capsuleOverlayMedia {
  position: relative;
  width: min(92vw, 1200px); /* fallback initial size before fitStage() */
  height: min(70dvh, 92vw); /* fallback initial size before fitStage() */
  border-radius: 0px;
  border: none;
  background: #000; /* Solid black — prevent grey flash before image loads */
  overflow: hidden;
  touch-action: none;
}

#capsuleOverlayMedia img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  user-select: none;
  -webkit-user-drag: none;
  pointer-events: none;
}

#capsuleOverlaySlider {
  position: absolute;
  top: 0; bottom: 0;
  left: 50%;
  width: 2px;
  background: rgba(255,255,255,.9);
  box-shadow: 0 0 0 1px rgba(0,0,0,.15), 2px 0 8px rgba(0,0,0,.2);
  display: none;
}

#capsuleOverlaySlider::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 19px; height: 19px;
  transform: translate(-50%, -50%);
  background: url('/static/formas/icons/gpt/ab.png') no-repeat center center;
  background-size: 70%;
  border-radius: 50%;
  box-shadow: 0 4px 12px rgba(0,0,0,.3), 0 6px 16px rgba(0,0,0,.15);
}

#capsuleImageOverlay .overlay-actions {
  position: absolute;
  top: calc(16px + var(--sa-top, 0px));
  right: calc(16px + var(--sa-right, 0px));
  display: flex;
  gap: 8px;
}

#capsuleOverlayClose, #capsuleOverlayDownload {
  appearance: none;
  border: 0;
  background: rgba(255,255,255,.08);
  color: #fff;
  border-radius: 10px;
  padding: 8px 12px;
  font: 500 13px/1.2 system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
}

.viewer-error-bubble {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  background: rgba(255,77,77,.92);
  color: #fff;
  padding: 10px 14px;
  border-radius: 10px;
  font: 600 13px/1 system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  box-shadow: 0 8px 24px rgba(0,0,0,.25);
}


/* ================= BASE MESSAGE STYLES ================= */

.chat-messages {
  --chat-surface-bg: rgba(22, 22, 24, 0.92);
  --chat-surface-bg-strong: rgba(16, 16, 18, 0.92);
  --chat-surface-user-bg: rgba(255, 255, 255, 0.045);
  --chat-surface-border: rgba(255, 255, 255, 0.1);
  --chat-surface-border-hover: rgba(255, 255, 255, 0.16);
  --chat-surface-radius: 14px;
  --chat-surface-radius-media: 12px;
  --chat-surface-radius-tight: 8px;
  --chat-surface-pad-y: 12px;
  --chat-surface-pad-x: 14px;
  --chat-surface-shadow: 0 4px 14px rgba(0, 0, 0, 0.18);
  --chat-surface-shadow-strong: 0 14px 38px rgba(0, 0, 0, 0.32);
  --chat-text-max: min(720px, 70%);
  --chat-media-max: min(720px, 70%);
  --chat-gap: 8px;
}

.message,
.message .message-content {
  box-sizing: border-box;
}

.message img, .message video {
  max-width: 100%;
  margin-top: 4px;
  border-radius: 6px;
  display: block;
}

.message img {
  cursor: pointer;
  transition: opacity 0.15s ease;
}

.message img:hover {
  opacity: 0.9;
}

.dropped-prompt {
  font-style: italic;
  font-size: 0.85em;
}

/* Desktop screen adjustments for all messages */
@media (min-width: 1024px) {
  .message {
    margin-left: 0;
    margin-right: 0;
    max-width: 900px;
  }
}


/* ================= ASSISTANT MESSAGE STYLES ================= */

.message.assistant {
  display: flex;
  justify-content: flex-start;
  align-items: flex-end;
  gap: var(--chat-gap);
}

.message.assistant .message-content {
  background: var(--chat-surface-bg);
  color: var(--text-primary);
  padding: var(--chat-surface-pad-y) var(--chat-surface-pad-x);
  border-radius: var(--chat-surface-radius) var(--chat-surface-radius) var(--chat-surface-radius) 6px;
  /* Balanced chat width for text-only replies */
  max-width: var(--chat-text-max);
  border: 1px solid var(--chat-surface-border);
  font-weight: 400;
  font-size: 14px;
  line-height: 1.5;
  position: relative;
  --message-bg: var(--chat-surface-bg);
  overflow: visible;
  box-shadow: var(--chat-surface-shadow);
}

.message.assistant .message-content:hover {
  border-color: var(--chat-surface-border-hover);
}

/* Media replies should feel "full-bleed" (no bubble chrome around the media). */
.message.assistant .message-content:has(
  .chat-img-wrapper,
  .chat-model-wrapper,
  .chat-model-wrapper-clean,
  model-viewer,
  .chat-pointcloud-container,
  .chat-pointcloud-wrapper,
  .media-container,
  .image-grid
) {
  /* Keep the balanced chat width (prevents oversized media) */
  max-width: var(--chat-media-max);
  padding: 0;
  background: transparent;
  border-color: transparent;
  box-shadow: none;
}

.message.assistant .message-content:has(
  .chat-img-wrapper,
  .chat-model-wrapper,
  .chat-model-wrapper-clean,
  model-viewer,
  .chat-pointcloud-container,
  .chat-pointcloud-wrapper,
  .media-container,
  .image-grid
)::before {
  content: none;
}

/* Frost highlight layer (very subtle) */
.message.assistant .message-content::before {
  content: none;
}

/* Pointcloud styles moved to pointcloud.css */

/* Assistant media wrappers (large, responsive width) */
.message.assistant .chat-img-wrapper,
.message.assistant .chat-model-wrapper,
.message.assistant .chat-pointcloud-wrapper {
  position: relative;
  display: block;
  max-width: 520px; /* Tighter maximum width for a balanced chat column */
  width: auto; /* Allow natural width up to max-width */
  height: auto;
  margin-bottom: 0;
  border-radius: 8px;
  overflow: hidden;
  transition: width 0.3s ease, height 0.3s ease;
}

.message.assistant .chat-model-wrapper {
  min-height: 307px;
  background: var(--secondary-bg);
  aspect-ratio: 1 / 1;
}

/* Assistant media content preserves aspect ratio */
.message.assistant .chat-img-wrapper img,
.message.assistant .chat-img-wrapper video {
  width: 100%;
  height: auto;
  object-fit: contain;
  position: relative;
  z-index: 1;
}

/* Desktop screen adjustments for assistant messages */
@media (min-width: 1024px) {
  .message.assistant {
    margin-right: auto;
    margin-left: 20px;
  }
  .message.assistant .chat-img-wrapper,
  .message.assistant .chat-model-wrapper,
  .message.assistant .chat-pointcloud-wrapper {
    max-width: 640px; /* Keep media from becoming too wide */
  }
  .message.assistant .chat-model-wrapper {
    min-height: 400px;
  }
}

@media (min-width: 1600px) {
  .message.assistant {
    /* Cap margin at 200px max to prevent excessive padding on ultra-wide screens */
    margin-left: min(calc((100vw - 1600px) / 2 + 20px), 200px);
  }
}

/* Keep chat transcript readable on wide screens.
   Module canvases remain full-width; only normal chat rows use this column. */
@media (min-width: 1024px) {
  .chat-messages {
    --chat-thread-max: 1180px;
    --chat-thread-gutter: clamp(48px, 6vw, 112px);
    --chat-thread-width: min(
      var(--chat-thread-max),
      calc(100% - var(--chat-thread-gutter) - var(--chat-thread-gutter))
    );
  }

  .chat-messages > .message:not(.module):not(.thinking) {
    width: min(100%, var(--chat-thread-width));
    max-width: var(--chat-thread-width);
    margin-left: auto !important;
    margin-right: auto !important;
  }

  .chat-messages > .message.assistant:not(.module):not(.thinking) {
    margin-left: auto !important;
    margin-right: auto !important;
  }

  .chat-messages > .message.user:not(.module) {
    width: min(100%, var(--chat-thread-width));
    max-width: var(--chat-thread-width);
  }

  .chat-messages > .message.assistant.thinking:not(.module) {
    width: min(100%, var(--chat-thread-width)) !important;
    max-width: var(--chat-thread-width) !important;
    margin-left: auto !important;
    margin-right: auto !important;
  }
}

@media (min-width: 1600px) {
  .chat-messages {
    --chat-thread-max: 1320px;
    --chat-thread-gutter: clamp(72px, 6vw, 180px);
  }
}

@media (min-width: 2200px) {
  .chat-messages {
    --chat-thread-max: 1520px;
  }
}

@media (min-width: 769px) and (max-width: 1023px) {
  .chat-messages {
    padding-left: clamp(24px, 5vw, 48px);
    padding-right: clamp(24px, 5vw, 48px);
  }
}

/* Mobile screen adjustments for assistant messages */
@media (max-width: 768px) {
  .message.assistant .chat-img-wrapper,
  .message.assistant .chat-model-wrapper,
  .message.assistant .chat-pointcloud-wrapper {
    max-width: 400px; /* SMALLER MAXIMUM WIDTH on mobile */
  }
  .message.assistant .chat-model-wrapper {
    min-height: 200px;
  }
}


/* ================= USER MESSAGE STYLES ================= */

.message.user {
  display: flex;
  justify-content: flex-end;
  align-items: flex-end;
  width: 100%;
  gap: 8px;
}

.message.user .message-content {
  /* Minimal pill bubble (modern, compact) */
  background: var(--chat-surface-user-bg);
  color: var(--text-primary);
  padding: 10px 12px;
  /* Avoid “stadium/egg” look on long messages */
  border-radius: calc(var(--chat-surface-radius) + 2px) calc(var(--chat-surface-radius) + 2px) var(--chat-surface-radius-tight) calc(var(--chat-surface-radius) + 2px);
  max-width: min(560px, 70%);
  font-weight: 400;
  font-size: 14px;
  line-height: 1.4;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  position: relative;
  margin-left: auto;
  order: 1;
  overflow: visible !important; /* Allow prompt pill to extend beyond container */
  /* Tighter, cleaner outline */
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.message.user .message-content:hover {
  border-color: rgba(255, 255, 255, 0.08);
}

.message.user .message-content span:not(.chat-img-wrapper) {
  align-self: flex-end;
  text-align: right;
}

.message.user video {
  width: 100%;
  height: auto;
  border-radius: 20px;
  object-fit: cover;
}

/* ================= WHATSAPP-STYLE AVATARS ================= */

/* Base avatar styles */
.message-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
  transition: opacity 0.2s ease, visibility 0s linear 0.2s;
  transform-origin: center center;
}

/* Smooth pop animation when avatar becomes visible */
.message-avatar[style*="opacity: 1"] {
  transition: opacity 0.2s ease, visibility 0s linear 0s;
  animation: avatarPop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

/* Ghost placeholder - transparent but maintains layout */
.message-avatar[style*="opacity: 0"] {
  pointer-events: none;
  transform: scale(0.8);
}

/* Avatar pop animation */
@keyframes avatarPop {
  0% {
    transform: scale(0.5);
    opacity: 0;
  }
  60% {
    transform: scale(1.1);
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

/* User avatar on the right */
.message.user .message-avatar {
  order: 2;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.message.user .avatar-initials {
  color: white;
  font-size: 13px;
  font-weight: 600;
  line-height: 1;
  text-transform: uppercase;
}

/* Assistant avatar on the left */
.message.assistant .message-avatar {
  order: 1;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.1);
  margin-bottom: 0; /* Align with message content bottom */
}

.message.assistant .message-content {
  order: 2;
  flex: 0 1 auto; /* Don't grow, but can shrink if needed */
}

.message.assistant .formas-icon {
  width: 20px;
  height: 20px;
  object-fit: contain;
  display: block;
  margin: 0;
}

/* Invisible avatar for thinking messages - maintains alignment */
.message.thinking .message-avatar,
.message.assistant.thinking .message-avatar {
  opacity: 0 !important;
  pointer-events: none !important;
  visibility: hidden !important;
  width: 32px !important; /* Ensure it maintains full width */
  flex-shrink: 0 !important;
}

/* Single user image (small, fixed square size) */
.message.user:not(.multi-image) .chat-img-wrapper {
  border-radius: 20px;
  margin-left: auto;
  margin-bottom: 8px; /* Add space between image and text */
  display: block;
  width: 160px;
  height: 160px;
  aspect-ratio: 1 / 1;
  align-self: flex-end;
  overflow: visible; /* Allow border to show on hover */
  position: relative;
}

/* Multi-image user message container */
.message.user.multi-image .message-content {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  max-width: min(560px, 70%);
}

.message.user.multi-image .image-grid {
  display: grid;
  gap: 8px;
  align-self: flex-end;
  width: auto;
  max-width: 100%;
  align-items: start; /* Ensure items align to top of each cell */
  justify-items: start; /* Ensure items align to left of each cell */
  order: 1; /* Images come first */
}

/* ================= SMOOTH IMAGE LOADING ================= */
/* Hide image until fully decoded; blur-up reveal for pro feel */
.smooth-image-loading {
  opacity: 0 !important;
  filter: blur(12px);
  transform: scale(1.04);
  visibility: visible !important;
  will-change: opacity, filter, transform;
  transition: opacity 0.35s cubic-bezier(0.4, 0, 0.2, 1),
              filter 0.45s cubic-bezier(0.4, 0, 0.2, 1),
              transform 0.45s cubic-bezier(0.4, 0, 0.2, 1);
}

.smooth-image-loaded {
  opacity: 1 !important;
  filter: blur(0);
  transform: scale(1);
  visibility: visible !important;
  will-change: auto;
  transition: opacity 0.35s cubic-bezier(0.4, 0, 0.2, 1),
              filter 0.45s cubic-bezier(0.4, 0, 0.2, 1),
              transform 0.45s cubic-bezier(0.4, 0, 0.2, 1);
}

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

/* Capsule tag used by pointcloud/model/style capsules */
.media-tag {
  position: absolute;
  top: 10px;
  left: 10px;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(10, 12, 18, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: rgba(255, 255, 255, 0.92);
  font: 700 10px/1 system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  pointer-events: none;
  z-index: 3;
}

/* ================= STYLE CLARIFICATION UI (base vs style) ================= */
.clarify-pill{
  padding:6px 10px;
  border:1px solid rgba(255,255,255,0.14);
  background:rgba(255,255,255,0.04);
  color:rgba(255,255,255,0.9);
  border-radius:9999px;
  font-size:12px;
  font-weight:600;
  cursor:pointer;
  transition:background .15s ease,border-color .15s ease,color .15s ease,transform .15s ease;
}
.clarify-pill:hover{
  background:rgba(255,255,255,0.06);
  border-color:rgba(255,255,255,0.22);
  transform: translateY(-1px);
}
.clarify-btn-base.selected{
  background:rgba(147,197,253,0.9);
  color:#111827;
  border-color:rgba(96,165,250,1);
}
.clarify-btn-style.selected{
  background:rgba(250,204,21,0.92);
  color:#111827;
  border-color:rgba(245,158,11,1);
}
input.clarify-slider{
  width:100%;
  appearance:none;
  height:6px;
  border-radius:9999px;
  background:rgba(255,255,255,0.12);
  outline:none
}
input.clarify-slider::-webkit-slider-thumb{
  -webkit-appearance:none;
  appearance:none;
  width:16px;height:16px;
  border-radius:50%;
  background:#ffffff;
  border:2px solid rgba(255,255,255,0.65);
  transition:transform .12s ease,box-shadow .12s ease
}
input.clarify-slider:hover::-webkit-slider-thumb{
  transform:scale(1.1);
  box-shadow:0 0 0 3px rgba(255,255,255,0.2)
}
input.clarify-slider::-moz-range-thumb{
  width:16px;height:16px;
  border-radius:50%;
  background:#ffffff;
  border:2px solid rgba(255,255,255,0.65);
  transition:transform .12s ease,box-shadow .12s ease
}
input.clarify-slider:hover::-moz-range-thumb{
  transform:scale(1.1);
  box-shadow:0 0 0 3px rgba(255,255,255,0.2)
}
.clarify-remove-btn{
  position:absolute;
  top:8px;right:8px;
  width:24px;height:24px;
  border-radius:50%;
  background:rgba(0,0,0,0.6);
  border:1px solid rgba(255,255,255,0.18);
  color:#fff;
  display:flex;
  align-items:center;
  justify-content:center;
  cursor:pointer;
  font-size:14px;
  font-weight:700;
  line-height:1;
  transition:all .15s ease;
  z-index:10
}
.clarify-remove-btn:hover{
  background:rgba(255,60,60,0.85);
  border-color:rgba(255,255,255,0.35);
  transform:scale(1.08)
}
.clarify-card-removed{
  opacity:0;
  pointer-events:none;
  transition:opacity .3s ease
}

/* Assistant media: skeleton shimmer while loading */
.message.assistant .chat-img-wrapper {
  width: 100%;
  /* Smooth height transitions when image loads */
  transition: height 0.35s cubic-bezier(0.2, 0.8, 0.2, 1), 
              opacity 0.25s ease-out,
              background 0.25s ease-out;
}

/* Smooth height transition for message content when images load */
.message.assistant .message-content {
  transition: height 0.35s cubic-bezier(0.2, 0.8, 0.2, 1);
}

/* Primary trigger: JS sets .loading on the wrapper (works even if :has() is unsupported) */
.message.assistant .chat-img-wrapper.loading {
  aspect-ratio: var(--media-ar, 1 / 1);
  background: rgba(255, 255, 255, 0.04);
}

/* When loading class is removed, fade out skeleton smoothly */
.message.assistant .chat-img-wrapper.loaded {
  background: transparent;
}

.message.assistant .chat-img-wrapper.loading::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(
    90deg,
    rgba(255, 255, 255, 0.04) 0%,
    rgba(255, 255, 255, 0.08) 50%,
    rgba(255, 255, 255, 0.04) 100%
  );
  background-size: 200% 100%;
  animation: chat-skeleton-shimmer 1.1s ease-in-out infinite;
  pointer-events: none;
  z-index: 0;
}

.message.assistant .chat-img-wrapper.loading .spinner-ring {
  opacity: 0;
}

/* 3D model + pointcloud capsules: use the same skeleton shimmer while .loading */
.message.assistant .chat-model-wrapper.loading,
.message.assistant .chat-model-wrapper-clean.loading,
.message.assistant .chat-pointcloud-wrapper.loading {
  background: rgba(255, 255, 255, 0.04);
}

.message.assistant .chat-model-wrapper.loading::before,
.message.assistant .chat-model-wrapper-clean.loading::before,
.message.assistant .chat-pointcloud-wrapper.loading::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(
    90deg,
    rgba(255, 255, 255, 0.04) 0%,
    rgba(255, 255, 255, 0.08) 50%,
    rgba(255, 255, 255, 0.04) 100%
  );
  background-size: 200% 100%;
  animation: chat-skeleton-shimmer 1.1s ease-in-out infinite;
  pointer-events: none;
  z-index: 0;
}

/* User messages: never show “spinner wheel” — decode is fast on small tiles */
.message.user .spinner-ring {
  display: none !important;
}

/* Skeleton shimmer for both user and assistant images while loading */
.chat-img-wrapper.loading {
  background: rgba(255, 255, 255, 0.04);
}

.chat-img-wrapper.loading::before {
  content: ‘’;
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(
    90deg,
    rgba(255, 255, 255, 0.04) 0%,
    rgba(255, 255, 255, 0.08) 50%,
    rgba(255, 255, 255, 0.04) 100%
  );
  background-size: 200% 100%;
  animation: chat-skeleton-shimmer 1.1s ease-in-out infinite;
  pointer-events: none;
  z-index: 0;
}

/* Reserve space on assistant wrappers to avoid layout jump */
.message.assistant .chat-img-wrapper.loading {
  aspect-ratio: var(--media-ar, 1 / 1);
}

/* Hide spinner when skeleton is showing */
.chat-img-wrapper.loading .spinner-ring {
  opacity: 0;
}

/* Ensure spinner is centered and visible during load */
.chat-img-wrapper .spinner-ring {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 1;
  pointer-events: none;
}

/* Hide spinner when loaded */
.chat-img-wrapper.loaded .spinner-ring {
  opacity: 0;
  transition: opacity 0.2s ease;
}

/* Fallback: ensure squares even if context classes are missing */
.image-grid {
  display: grid;
  gap: 8px;
}
.image-grid > .mediabubble-container { display: block; }

/* Allow prompt pill to extend beyond mediabubble container */
.message.user .mediabubble-container {
  overflow: visible !important;
}
.image-grid .chat-img-wrapper {
  display: block;
  width: 160px;
  height: 160px;
  aspect-ratio: 1 / 1;
  border-radius: 12px;
  overflow: visible; /* Allow border to show on hover */
  position: relative;
}
.image-grid .chat-img-wrapper img,
.image-grid .chat-img-wrapper video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Ensure grid direct children are block-level and have no stray spacing */
.message.user.multi-image .image-grid > .mediabubble-container {
  display: block;
  margin: 0;
  padding: 0;
  /* Override generic span rules that push user spans to the right/bottom */
  align-self: start !important;
  justify-self: start;
  text-align: left;
}

/* Multi-image grid item sizing */
.message.user.multi-image .chat-img-wrapper {
  margin: 0;
  width: 160px;
  height: 160px;
  aspect-ratio: 1 / 1;
  border-radius: 12px;
  overflow: visible; /* Allow border to show on hover */
  position: relative;
}

/* User image content is always cropped to fill the square */
.message.user .chat-img-wrapper img,
.message.user .chat-img-wrapper video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  position: absolute;
  top: 0;
  left: 0;
  z-index: 0; /* Below border and overlay */
  display: block;
  border-radius: inherit; /* Match parent border radius */
}

/* Layout for 2 images */
.message.user.multi-image.image-count-2 .image-grid {
  grid-template-columns: repeat(2, 1fr);
  width: 328px; /* 2 * 160px + 8px gap */
  height: 160px;
}

/* Layout for 3 images (L-shape from bottom-right) */
.message.user.multi-image.image-count-3 .image-grid {
  grid-template-columns: repeat(2, 1fr);
  grid-template-rows: repeat(2, 1fr);
  width: 328px;
  height: 328px;
}
.message.user.multi-image.image-count-3 .chat-img-wrapper:nth-child(1) { grid-column: 2; grid-row: 2; }
.message.user.multi-image.image-count-3 .chat-img-wrapper:nth-child(2) { grid-column: 1; grid-row: 2; }
.message.user.multi-image.image-count-3 .chat-img-wrapper:nth-child(3) { grid-column: 2; grid-row: 1; }

/* Layout for 4 images (2x2 grid) */
.message.user.multi-image.image-count-4 .image-grid {
  grid-template-columns: repeat(2, 1fr);
  grid-template-rows: repeat(2, 1fr);
  width: 328px;
  height: 328px;
}

/* Layout for 5+ images: switch to 3 columns while maintaining tile size */
.message.user.multi-image.image-count-5 .image-grid,
.message.user.multi-image.image-count-6 .image-grid,
.message.user.multi-image.image-count-7 .image-grid,
.message.user.multi-image.image-count-8 .image-grid {
  grid-template-columns: repeat(3, 1fr);
  width: calc(3 * 160px + 2 * 8px);
}

/* Text in a multi-image message */
.message.user.multi-image .mediabubble-container {
  order: 2; /* Container comes after images */
  align-self: flex-end;
  width: 100%;
}

.message.user.multi-image .message-text {
  order: 2; /* Text comes after images */
  align-self: flex-end;
  text-align: right;
  width: 100%;
  margin-top: 12px; /* Add space between images and text */
}

/* ================= PROMPT DRAGGABLE STYLES ================= */
.message .message-text.prompt-draggable {
  position: relative;
  display: inline-block;
  width: auto;
  max-width: 100%;
  min-width: 0;
  overflow-wrap: anywhere;
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
  box-sizing: border-box;
  border-radius: 14px;
  padding: 6px 10px;
  margin: 1px 0;
  border: 1px solid transparent;
  outline: 1px solid transparent;
  outline-offset: 1px;
  box-shadow: 0 0 0 0 transparent;
  cursor: grab;
  user-select: text;
  overflow: visible !important;
  transition: border-color 0.14s ease, outline-color 0.14s ease, box-shadow 0.14s ease, background-color 0.14s ease, transform 0.14s ease;
}

.message .message-text.prompt-draggable:hover {
  background: rgba(255, 255, 255, 0.045);
  border-color: rgba(255, 255, 255, 0.32);
  outline-color: rgba(255, 255, 255, 0.2);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.16), 0 4px 14px rgba(0, 0, 0, 0.24);
  transform: translateY(-1px);
  z-index: 10;
}

.message .message-text.prompt-draggable:active {
  cursor: grabbing;
  transform: translateY(0);
  background: rgba(255, 255, 255, 0.07);
  border-color: rgba(255, 255, 255, 0.48);
  outline-color: rgba(255, 255, 255, 0.28);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.22), 0 2px 8px rgba(0, 0, 0, 0.2);
}

.message .message-text.prompt-draggable.prompt-dragging {
  opacity: 0.55;
  transform: scale(0.98);
}

.message .message-text.prompt-draggable.prompt-clicked {
  background: rgba(56, 189, 248, 0.12);
  border-color: rgba(56, 189, 248, 0.4);
  box-shadow: 0 0 0 1px rgba(56, 189, 248, 0.22);
  animation: promptClickPulse 0.24s ease;
}

@keyframes promptClickPulse {
  0% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.05);
  }
  100% {
    transform: scale(1);
  }
}

/* Ensure text selection still works */
.message .message-text.prompt-draggable::selection {
  background: rgba(59, 130, 246, 0.3);
}

.message .message-text.prompt-draggable::-moz-selection {
  background: rgba(59, 130, 246, 0.3);
}

/* USER PROMPT COPY / EDIT  */
.message.user {
  flex-wrap: wrap;
}


.message.user .message-action-btn.action-pill .message-action-icon {
  display: block;
  width: 18px;
  height: 18px;
  background-repeat: no-repeat;
  background-position: center;
  background-size: contain;
  opacity: 0.92;
  filter: brightness(1.18);
  transition: filter 0.16s ease, opacity 0.16s ease;
}

.message.user .message-action-btn.action-pill:hover .message-action-icon,
.message.user .message-action-btn.action-pill:focus-visible .message-action-icon {
  opacity: 1;
}

.message.user > .message-actions.user-prompt-actions,
.message.user > .message-actions.user-prompt-edit-actions {
  flex: 0 0 100%;
  display: flex !important;
  flex-direction: row !important;
  justify-content: flex-end;
  align-items: center;
  gap: 4px;
  width: auto !important;
  max-width: 100%;
  margin: 4px 0 0 0 !important;
  padding: 0;
  background: transparent;
  border: 0;
  box-shadow: none;
  order: 5;
}

.message.user > .message-actions.user-prompt-actions {
  opacity: 0 !important;
  pointer-events: none;
  transform: translateY(-2px);
  transition: opacity 0.16s ease, transform 0.16s ease;
}

.message.user:hover > .message-actions.user-prompt-actions,
.message.user:focus-within > .message-actions.user-prompt-actions,
.message.user > .message-actions.user-prompt-actions:hover {
  opacity: 1 !important;
  pointer-events: auto;
  transform: translateY(0);
}

/* While editing, Copy/Edit are replaced by Cancel/Send — never both at once. */
.message.user > .message-actions.user-prompt-actions.editing-active {
  display: none !important;
}

.message.user > .message-actions.user-prompt-edit-actions {
  opacity: 1 !important;
  pointer-events: auto;
  transform: none;
}

@media (max-width: 768px) {
  .message.user > .message-actions.user-prompt-actions {
    opacity: 1 !important;
    pointer-events: auto;
    transform: none;
  }
}

.message-text.editing {
  display: block;
  width: 100%;
}

.user-prompt-edit-input {
  display: block;
  width: 100%;
  min-width: 220px;
  resize: none;
  overflow: hidden;
  box-sizing: border-box;
  font: inherit;
  color: inherit;
  line-height: inherit;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 14px;
  padding: 6px 10px;
  outline: none;
  transition: border-color 0.14s ease, background-color 0.14s ease;
}

.user-prompt-edit-input:focus {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(56, 189, 248, 0.5);
}

.user-prompt-edit-btn {
  font: 600 12px/1 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  padding: 6px 12px;
  border-radius: 20px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(255, 255, 255, 0.05);
  color: rgba(255, 255, 255, 0.85);
  cursor: pointer;
  transition: background-color 0.14s ease, border-color 0.14s ease, color 0.14s ease;
}

.user-prompt-edit-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.28);
}

.user-prompt-edit-btn.confirm {
  background: rgba(56, 189, 248, 0.16);
  border-color: rgba(56, 189, 248, 0.4);
  color: #fff;
}

.user-prompt-edit-btn.confirm:hover {
  background: rgba(56, 189, 248, 0.26);
  border-color: rgba(56, 189, 248, 0.6);
}

/* Desktop screen adjustments for user messages */
@media (min-width: 1024px) {
  .message.user {
    margin-left: auto;
    margin-right: 20px;
  }
}
@media (min-width: 1600px) {
  .message.user {
    /* Cap margin at 200px max to prevent excessive padding on ultra-wide screens */
    margin-right: min(calc((100vw - 1600px) / 2 + 20px), 200px);
  }
}

/* Mobile responsive adjustments for user multi-image */
@media (max-width: 768px) {
  .message.user.multi-image .message-content { max-width: 85%; }
  .message.user:not(.multi-image) .chat-img-wrapper { width: 120px; height: 120px; }
  .message.user.multi-image .chat-img-wrapper { width: 120px; height: 120px; border-radius: 10px; }
  .message.user.multi-image.image-count-2 .image-grid { width: 248px; height: 120px; }
  .message.user.multi-image.image-count-3 .image-grid,
  .message.user.multi-image.image-count-4 .image-grid { width: 248px; height: 248px; }
  .message.user.multi-image.image-count-5 .image-grid,
  .message.user.multi-image.image-count-6 .image-grid,
  .message.user.multi-image.image-count-7 .image-grid,
  .message.user.multi-image.image-count-8 .image-grid { width: calc(3 * 120px + 2 * 8px); }
  /* Fallback responsive sizes */
  .image-grid .chat-img-wrapper { width: 120px; height: 120px; border-radius: 10px; }
}

/* Very small screen adjustments */
@media (max-width: 480px) {
  .message.user:not(.multi-image) .chat-img-wrapper { width: 100px; height: 100px; }
  .message.user.multi-image .chat-img-wrapper { width: 100px; height: 100px; }
  .message.user.multi-image.image-count-2 .image-grid { width: 208px; height: 100px; }
  .message.user.multi-image.image-count-3 .image-grid,
  .message.user.multi-image.image-count-4 .image-grid { width: 208px; height: 208px; }
  .message.user.multi-image.image-count-5 .image-grid,
  .message.user.multi-image.image-count-6 .image-grid,
  .message.user.multi-image.image-count-7 .image-grid,
  .message.user.multi-image.image-count-8 .image-grid { width: calc(3 * 100px + 2 * 8px); }
  /* Fallback smallest sizes */
  .image-grid .chat-img-wrapper { width: 100px; height: 100px; }
}


/* ================= MODULE MESSAGE STYLES ================= */

.message.module {
  display: flex;
  justify-content: center;
  width: 100%;
  max-width: none;
  margin-bottom: 16px;
}

.message.module .message-content {
  background: var(--secondary-bg);
  border: 1px solid var(--border-subtle);
  border-radius: 26px;
  padding: 16px;
  width: 100%;
  max-width: 900px;
  position: relative;
  overflow: hidden;
}

.module-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border-subtle);
}

.module-icon {
  width: 36px;
  height: 36px;
  background: var(--tertiary-bg);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}

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

.module-title {
  font-size: 15px;
  font-weight: 500;
  color: var(--text-primary);
  margin-bottom: 2px;
}

.module-description {
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 400;
}

.module-badge {
  background: var(--button-secondary);
  color: var(--text-primary);
  padding: 3px 6px;
  border-radius: 10px;
  font-size: 10px;
  font-weight: 400;
  border: 1px solid var(--border-color);
  flex-shrink: 0;
}

.module-controls {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.module-control-btn,
.module-minimize {
  background: var(--tertiary-bg);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  width: 24px;
  height: 24px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  transition: all 0.15s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.module-control-btn:hover,
.module-minimize:hover {
  background: var(--hover-subtle);
  color: var(--text-primary);
  transform: scale(1.05);
}

.module-fullscreen:hover {
  background: var(--accent-color);
  color: white;
}

.module-fullscreen.active {
  background: var(--accent-color);
  color: white;
}

.module-interface {
  background: var(--primary-bg);
  border-radius: 8px;
  padding: 8px;
  border: 1px solid var(--border-subtle);
  min-height: 200px;
  max-height: 70vh;
  overflow-y: auto;
}

.module-interface.drag-over {
  background: var(--hover-subtle);
  border: 1px dashed var(--border-color);
  transition: background 0.15s, border 0.15s;
}

.module-fullscreen-active {
  opacity: 0.5;
  pointer-events: none;
}

.module-fullscreen-active .message-content {
  border-color: rgba(245, 166, 35, 0.5);
  box-shadow: 0 0 0 2px rgba(245, 166, 35, 0.15);
}

.canvas-interface,
.interior-interface {
  text-align: center;
  padding: 16px;
}

.canvas-interface h3 {
  color: var(--text-primary);
  margin-bottom: 12px;
  font-size: 14px;
  font-weight: 500;
}

.canvas-controls {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 12px;
}

.canvas-btn {
  background: var(--button-secondary);
  color: var(--button-secondary-text);
  border: 1px solid var(--border-color);
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 400;
  transition: all 0.15s ease;
}

.canvas-btn:hover {
  background: var(--hover-bg);
  transform: translateY(-1px);
}

.interior-interface {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  padding: 12px;
}

.interior-section h4 {
  color: var(--text-primary);
  margin-bottom: 8px;
  font-size: 13px;
  font-weight: 500;
}

.interior-option {
  background: var(--tertiary-bg);
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s ease;
  border: 1px solid var(--border-subtle);
  font-size: 12px;
  color: var(--text-primary);
  margin-bottom: 6px;
}

.interior-option:hover {
  background: var(--hover-subtle);
  border-color: var(--border-color);
  transform: translateY(-1px);
}



/* ================= MISC CHAT COMPONENTS ================= */

/* Date Bubble */
.chat-date-bubble {
  position: absolute;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 12px;
  opacity: 0;
  transition: opacity 0.2s ease;
  pointer-events: none;
  z-index: 10;
}

.chat-date-bubble.show {
  opacity: 1;
}

/* ── Markdown rendering in chat messages ── */
.message-text h1,
.message-text h2,
.message-text h3,
.message-text h4,
.message-text h5,
.message-text h6 {
  margin: 0.6em 0 0.3em;
  line-height: 1.3;
  font-weight: 600;
}
.message-text h1 { font-size: 1.4em; }
.message-text h2 { font-size: 1.25em; }
.message-text h3 { font-size: 1.1em; }
.message-text h4,
.message-text h5,
.message-text h6 { font-size: 1em; }

/* Code block wrapper with copy button */
.message-text .code-block-wrap {
  position: relative;
  margin: 8px 0;
  border-radius: 8px;
  overflow: hidden;
  background: rgba(0, 0, 0, 0.35);
}
.message-text .code-block-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 14px;
  background: rgba(255, 255, 255, 0.06);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}
.message-text .code-block-lang {
  font-size: 0.75em;
  color: rgba(255, 255, 255, 0.45);
  font-family: 'SF Mono', 'Fira Code', monospace;
  text-transform: lowercase;
}
.message-text .code-copy-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.4);
  cursor: pointer;
  font-size: 0.75em;
  padding: 3px 8px;
  border-radius: 4px;
  transition: all 0.15s ease;
  opacity: 0;
}
.message-text .code-block-wrap:hover .code-copy-btn {
  opacity: 1;
}
.message-text .code-copy-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: rgba(255, 255, 255, 0.8);
}
.message-text .code-copy-btn.copied {
  opacity: 1;
  color: #4ade80;
}

.message-text .code-block-wrap pre {
  margin: 0;
  border-radius: 0;
}
.message-text pre {
  background: rgba(0, 0, 0, 0.35);
  border-radius: 8px;
  padding: 12px 14px;
  margin: 8px 0;
  overflow-x: auto;
  font-size: 0.85em;
  line-height: 1.5;
}
.message-text pre code {
  background: none;
  padding: 0;
  border-radius: 0;
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
  color: #e0e0e0;
  white-space: pre;
}
.message-text code {
  background: rgba(255, 255, 255, 0.1);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
  font-size: 0.9em;
}

.message-text ul,
.message-text ol {
  margin: 6px 0;
  padding-left: 1.6em;
}
.message-text li {
  margin: 3px 0;
  line-height: 1.5;
}

.message-text blockquote {
  border-left: 3px solid rgba(255, 255, 255, 0.3);
  margin: 6px 0;
  padding: 4px 12px;
  color: rgba(255, 255, 255, 0.75);
}

.message-text hr {
  border: none;
  border-top: 1px solid rgba(255, 255, 255, 0.15);
  margin: 10px 0;
}

.message-text a {
  color: #7eb8ff;
  text-decoration: underline;
}

.message-text del {
  opacity: 0.6;
}

/* Typing cursor */
.message-text.cursor::after {
  content: '_';
  display: inline-block;
}

.message-text.typing::after {
  animation: blinkCursor 0.6s steps(2, start) infinite;
}

/* AI Thinking Indicator */
.ai-thinking {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  padding: 0;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 400;
  width: auto;
  max-width: 100%;
}

.thinking-dots {
  display: flex;
  gap: 4px;
}

.thinking-dot {
  width: 4px;
  height: 4px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: thinking 1.55s infinite cubic-bezier(0.4, 0, 0.2, 1);
}
.thinking-dot:nth-child(1) { 
  animation-delay: 0s; 
  animation-name: thinking-left; /* ✨ Left spreads left */
}
.thinking-dot:nth-child(2) { 
  animation-delay: 0.14s;
  animation-name: thinking; /* ✨ Center stays */
}
.thinking-dot:nth-child(3) { 
  animation-delay: 0.28s;
  animation-name: thinking-right; /* ✨ Right spreads right */
}

.thinking-dots.inline {
  display: inline-flex;
  margin-left: 4px;
}

/* Progressive Thinking Animation */
.ai-thinking.progressive {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 0;
  align-items: flex-start; /* Left-align the thinking sequence */
  width: auto;
  max-width: 100%;
}

.thinking-line {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 0;
  transition: all 0.3s ease;
  width: auto;
  max-width: 100%;
  justify-content: flex-start;
  position: relative;
}

.thinking-line.active {
  color: var(--text-primary);
}

.thinking-line.active .thinking-text {
  color: var(--text-primary);
  background: transparent;
  -webkit-text-fill-color: currentColor;
  animation: thinkingTextPulse 1.6s ease-in-out infinite;
  font-weight: 500;
}

.thinking-line .thinking-dots {
  flex-shrink: 0;
  min-width: var(--checkmark-container-width, 24px);
  width: var(--checkmark-container-width, 24px);
  display: flex;
  align-items: center;
  justify-content: center;
}

.message.assistant.thinking.search-thinking {
  --search-thinking-blue: #54b8ff;
  --search-thinking-blue-soft: rgba(84, 184, 255, 0.2);
  --search-thinking-blue-glow: rgba(58, 160, 255, 0.38);
}

.message.assistant.thinking.search-thinking .thinking-line .thinking-text {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  line-height: 24px;
  transition:
    color 0.7s cubic-bezier(0.22, 1, 0.36, 1),
    text-shadow 0.7s cubic-bezier(0.22, 1, 0.36, 1),
    opacity 0.35s ease;
}

.message.assistant.thinking.search-thinking .thinking-line.active .thinking-text,
.message.assistant.thinking.search-thinking .thinking-line.completed .thinking-text {
  color: var(--search-thinking-blue) !important;
  -webkit-text-fill-color: currentColor !important;
  text-shadow: 0 0 16px var(--search-thinking-blue-soft);
}

.message.assistant.thinking.search-thinking.search-thinking-complete .thinking-line .thinking-text,
.message.assistant.thinking.search-thinking.search-thinking-complete .thinking-line.completed .thinking-text {
  color: #999999 !important;
  text-shadow: 0 0 0 rgba(84, 184, 255, 0);
}

.message.assistant.thinking.search-thinking .search-thinking-icon {
  position: relative;
  width: 24px;
  height: 24px;
  display: inline-flex !important;
  align-items: center;
  justify-content: center;
  align-self: center;
  line-height: 0;
  transform: translateY(-1px);
  background: transparent !important;
  box-shadow: none !important;
  border: 0 !important;
}

.message.assistant.thinking.search-thinking .search-globe {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  color: rgba(101, 196, 255, 0.98);
  background: transparent;
  box-shadow: none;
  transition:
    color 0.7s cubic-bezier(0.22, 1, 0.36, 1),
    opacity 0.45s ease,
    filter 0.45s ease;
  animation: searchGlobeBreathe 2.4s ease-in-out infinite;
  filter:
    drop-shadow(0 0 6px rgba(84, 184, 255, 0.52))
    drop-shadow(0 0 14px rgba(84, 184, 255, 0.18));
}

.message.assistant.thinking.search-thinking .search-globe::after {
  content: none;
}

.message.assistant.thinking.search-thinking .search-globe svg {
  display: block;
  width: 18px;
  height: 18px;
  stroke: currentColor;
  stroke-width: 1.8;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  transform-box: fill-box;
  transform-origin: center;
  animation: searchGlobeSpin 1.65s infinite;
}

.message.assistant.thinking.search-thinking .search-thinking-sources {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 5px 0 0 32px;
  max-width: min(520px, calc(100vw - 128px));
  opacity: 1;
  transform: translateY(0);
  transition:
    opacity 0.22s ease,
    transform 0.22s ease;
}

.message.assistant.thinking.search-thinking .search-thinking-sources.is-removing {
  opacity: 0;
  transform: translateY(-4px);
  pointer-events: none;
}

.message.assistant.thinking.search-thinking .search-thinking-source {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 22px;
  max-width: 220px;
  padding: 2px 8px 2px 7px;
  border: 1px solid rgba(84, 184, 255, 0.28);
  border-radius: 999px;
  background: rgba(84, 184, 255, 0.09);
  color: var(--search-thinking-blue);
  text-decoration: none;
  font-size: 12px;
  font-weight: 500;
  line-height: 18px;
  box-shadow: 0 0 14px rgba(84, 184, 255, 0.08);
  animation: searchSourceChipIn 0.24s cubic-bezier(0.22, 1, 0.36, 1) both;
  transition:
    border-color 0.18s ease,
    background-color 0.18s ease,
    transform 0.18s ease;
}

.message.assistant.thinking.search-thinking a.search-thinking-source:hover {
  border-color: rgba(84, 184, 255, 0.58);
  background: rgba(84, 184, 255, 0.16);
  transform: translateY(-1px);
}

.message.assistant.thinking.search-thinking .search-source-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 14px;
  height: 14px;
  flex: 0 0 14px;
  color: currentColor;
  opacity: 0.88;
}

.message.assistant.thinking.search-thinking .search-source-icon svg {
  display: block;
  width: 14px;
  height: 14px;
  stroke: currentColor;
  stroke-width: 1.35;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.message.assistant.thinking.search-thinking .search-source-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@keyframes searchSourceChipIn {
  from {
    opacity: 0;
    transform: translateY(3px) scale(0.97);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes searchGlobeBreathe {
  0%, 100% {
    opacity: 0.78;
    transform: scale(0.98);
    filter:
      drop-shadow(0 0 5px rgba(84, 184, 255, 0.42))
      drop-shadow(0 0 12px rgba(84, 184, 255, 0.12))
      saturate(108%);
  }
  50% {
    opacity: 1;
    transform: scale(1.04);
    filter:
      drop-shadow(0 0 8px rgba(84, 184, 255, 0.72))
      drop-shadow(0 0 18px rgba(84, 184, 255, 0.22))
      saturate(132%);
  }
}

@keyframes searchGlobeSpin {
  0% {
    transform: rotate(0deg);
    animation-timing-function: cubic-bezier(0.12, 0.86, 0.2, 1);
  }
  24% {
    transform: rotate(300deg);
    animation-timing-function: cubic-bezier(0.3, 0, 0.2, 1);
  }
  46% {
    transform: rotate(390deg);
    animation-timing-function: cubic-bezier(0.08, 0.72, 0.2, 1);
  }
  70% {
    transform: rotate(690deg);
    animation-timing-function: cubic-bezier(0.34, 0, 0.22, 1);
  }
  100% {
    transform: rotate(720deg);
  }
}

/* Checkmark icon standardization */
.thinking-line .thinking-dots img {
  width: var(--checkmark-size, 16px);
  height: var(--checkmark-size, 16px);
  display: block;
}

.thinking-line .thinking-text {
  flex: 0 0 auto;
  font-size: 13px;
  line-height: 1.4;
  background: transparent;
  padding: 0;
  border-radius: 0;
}

/* Horizontal dots for generating state */
.thinking-dots.horizontal {
  gap: 4px;
  transform: translateY(-1px);
}

.thinking-dots.horizontal .thinking-dot {
  animation: thinkingPulseHorizontal 1.55s cubic-bezier(0.4, 0, 0.2, 1) infinite both;
}

.thinking-dots.horizontal .thinking-dot:nth-child(1) { 
  animation-delay: -0.24s; 
  animation-name: thinkingPulseHorizontal-left; /* ✨ Left spreads left */
}
.thinking-dots.horizontal .thinking-dot:nth-child(2) { 
  animation-delay: -0.12s;
  animation-name: thinkingPulseHorizontal; /* ✨ Center stays */
}
.thinking-dots.horizontal .thinking-dot:nth-child(3) { 
  animation-delay: 0s;
  animation-name: thinkingPulseHorizontal-right; /* ✨ Right spreads right */
}

/* Center dot - stays in place */
@keyframes thinkingPulseHorizontal {
  0%, 80%, 100% {
    transform: scale(0.78) translate(0, 0);
    opacity: 0.4;
  }
  40% {
    transform: scale(1.18) translate(0, 0);
    opacity: 0.92;
  }
}

/* Left dot - spreads left when pulsing */
@keyframes thinkingPulseHorizontal-left {
  0%, 80%, 100% {
    transform: scale(0.78) translate(0, 0);
    opacity: 0.4;
  }
  40% {
    transform: scale(1.18) translate(-1.25px, 0);
    opacity: 0.92;
  }
}

/* Right dot - spreads right when pulsing */
@keyframes thinkingPulseHorizontal-right {
  0%, 80%, 100% {
    transform: scale(0.78) translate(0, 0);
    opacity: 0.4;
  }
  40% {
    transform: scale(1.18) translate(1.25px, 0);
    opacity: 0.92;
  }
}

/* Ensure thinking messages maintain flex layout with avatar space */
.message.assistant.thinking {
  display: flex !important;
  justify-content: flex-start !important;
  align-items: flex-end !important;
  gap: var(--chat-gap, 8px) !important;
  width: auto !important;
  max-width: min(560px, calc(100vw - 150px)) !important;
  margin-top: 6px !important;
}

/* Compact, left-aligned thinking bubble (no background) */
.message.assistant.thinking .message-content {
  background: transparent !important;
  border: 0 !important;
  padding: 0 !important;
  width: auto !important;
  max-width: 100% !important;
  box-shadow: none !important;
}

.message.assistant.thinking .ai-thinking.progressive {
  padding: 0 !important;
  gap: 2px !important;
  align-items: flex-start;
  width: auto !important;
  max-width: 100% !important;
}

.message.assistant.thinking .thinking-line {
  gap: 12px !important;
  padding: 0 !important;
  min-height: 0 !important;
  width: auto !important;
  max-width: 100% !important;
}

.message.assistant.thinking .thinking-dots {
  min-width: var(--checkmark-container-width, 24px) !important;
  width: var(--checkmark-container-width, 24px) !important;
}

.message.assistant.thinking .thinking-dot {
  width: 4px;
  height: 4px;
}

.message.assistant.thinking .thinking-line .thinking-text {
  padding: 0 !important;
  margin: 0 !important;
  /* Keep gradient shine for active; just remove capsule background color */
  background-color: transparent !important;
}

.message.assistant.thinking .thinking-line.completed .thinking-text {
  background: none !important;
  padding: 0 !important;
  color: #999999 !important;
  -webkit-text-fill-color: currentColor !important;
}

@keyframes thinkingTextPulse {
  0%, 100% { opacity: 0.66; }
  50% { opacity: 1; }
}

/* Analysing text with plain pulse effect */
.analysing-text {
  position: relative;
  display: inline-block;
  color: var(--text-primary);
  -webkit-text-fill-color: currentColor;
  animation: thinkingTextPulse 1.6s ease-in-out infinite;
  font-weight: 500;
  letter-spacing: 0.02em;
}

/* Final override: keep assistant reply/thinking text free of gradient fills. */
.message.assistant .message-content,
.message.assistant .message-text,
.message.assistant .message-text *,
.message.assistant.thinking .thinking-text,
.thinking-text,
.analysing-text {
  background-image: none !important;
  -webkit-background-clip: border-box !important;
  background-clip: border-box !important;
}

/* Drag Preview */
.drag-preview {
  display: flex;
  align-items: center;
  transform-origin: center;
}
.drag-preview .sidebar-item-icon {
  width: 18px;
  height: 18px;
  margin-right: 10px;
  margin-left: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
}
.drag-preview .sidebar-item-text {
  flex: 1;
  font-size: 13px;
}
.drag-preview .sidebar-item-badge {
  background: var(--button-secondary);
  color: rgb(170, 170, 170);
  font-size: 9px;
  padding: 1px 4px;
  border-radius: 6px;
  font-weight: 400;
  margin-left: 14px;
  flex-shrink: 0;
}


/* ================= MEDIA STATES (LAZY LOAD, PLACEHOLDERS) ================= */

/* Universal Hover Effect */
.message.assistant .chat-img-wrapper:hover::before,
.message.user .chat-img-wrapper:hover::before,
.message.assistant .chat-model-wrapper:hover::before {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  border-radius: inherit;
  pointer-events: none;
}

/* ================= USER MESSAGE IMAGE HOVER EFFECTS ================= */
/* Make user images show they're clickable and draggable */
.message.user .chat-img-wrapper {
  transition: all 0.15s cubic-bezier(0.4, 0, 0.2, 1);
  cursor: grab;
  border: 1px solid transparent; /* Reserve space for border */
  transform-origin: center center; /* Ensure transforms happen from center */
  position: relative; /* Ensure pseudo-element positioning context */
}

.message.user .chat-img-wrapper::after {
  content: '';
  position: absolute;
  top: 4px; /* Offset border 4px lower */
  left: 0;
  right: 0;
  bottom: -4px; /* Adjust bottom to maintain height */
  border: 1px solid transparent;
  border-radius: inherit;
  pointer-events: none;
  z-index: 2; /* Above image, below overlay */
  transition: all 0.15s cubic-bezier(0.4, 0, 0.2, 1);
  transform-origin: center center;
}

.message.user .chat-img-wrapper:hover {
  transform: translateY(-2px) scale(1.012);
  cursor: grab;
  z-index: 10;
  transform-origin: center center; /* Ensure scaling happens from center */
}

.message.user .chat-img-wrapper:hover::after {
  border: 1px solid rgba(255, 255, 255, 0.9);
  box-shadow: 
    0 0 0 0.5px rgba(255, 255, 255, 0.5),
    0 4px 12px rgba(59, 130, 246, 0.3),
    0 0 20px rgba(255, 255, 255, 0.2);
}

.message.user .chat-img-wrapper:active {
  cursor: grabbing;
  transform: translateY(0) scale(1);
}

.message.user .chat-img-wrapper:active::after {
  border-color: rgba(255, 255, 255, 1);
  box-shadow: 
    0 0 0 1px rgba(255, 255, 255, 0.8),
    0 2px 8px rgba(59, 130, 246, 0.4);
}

.message.user .chat-img-wrapper:hover::before {
  background: rgba(59, 130, 246, 0.15);
  border-radius: inherit;
  z-index: 1; /* Below border, above image */
}

/* Ensure images are clipped properly even with overflow visible */
.message.user .chat-img-wrapper img,
.message.user .chat-img-wrapper video {
  border-radius: inherit;
  overflow: hidden;
}

/* Generation placeholders moved to placeholders.css */

/* Lazy Loading */
.message.assistant .chat-img-wrapper.lazy-load,
.message.user .chat-img-wrapper.lazy-load { 
  background: var(--secondary-bg); 
}
.message.assistant .chat-img-wrapper.lazy-load { background: #373737; }

/* CRITICAL: Plasma placeholders MUST be transparent to show canvas */
.message.assistant .chat-img-wrapper.plasma-placeholder,
.message.assistant .chat-img-wrapper.generation-placeholder.plasma-placeholder,
.message.assistant .chat-img-wrapper.generation-placeholder.image-placeholder,
.message.assistant .chat-img-wrapper.generation-placeholder.video-placeholder,
.message.assistant .chat-img-wrapper.generation-placeholder.model-placeholder {
  background: transparent !important;
}

.message.assistant .chat-img-wrapper.lazy-load img,
.message.assistant .chat-img-wrapper.lazy-load video,
.message.user .chat-img-wrapper.lazy-load img,
.message.user .chat-img-wrapper.lazy-load video {
  opacity: 0;
  transform: scale(0.98);
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.message.assistant .chat-img-wrapper.lazy-load.loaded,
.message.user .chat-img-wrapper.lazy-load.loaded { 
  background: transparent; 
}
.message.assistant .chat-img-wrapper.lazy-load.loaded {
  aspect-ratio: auto;
  min-height: 0;
  height: auto;
}

/* 📐 VIDEO FIX: Ensure videos have proper size before metadata loads */
.message.assistant .chat-img-wrapper[data-media-type="video"] {
  min-height: 200px; /* Minimum height until video loads */
  aspect-ratio: 16 / 9; /* Default aspect ratio for most videos */
}

.message.assistant .chat-img-wrapper[data-media-type="video"].loaded {
  min-height: 0; /* Remove min-height after video loads */
  aspect-ratio: auto; /* Let video determine aspect ratio */
}

.message.assistant .chat-img-wrapper.lazy-load.loaded img,
.message.assistant .chat-img-wrapper.lazy-load.loaded video,
.message.user .chat-img-wrapper.lazy-load.loaded img,
.message.user .chat-img-wrapper.lazy-load.loaded video {
  opacity: 1;
  transform: scale(1);
}

.message.assistant .chat-img-wrapper.lazy-load .spinner-ring,
.message.user .chat-img-wrapper.lazy-load .spinner-ring {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
  z-index: 2;
  opacity: 1;
  transition: opacity 0.3s ease;
}

.message.assistant .chat-img-wrapper.lazy-load.loaded .spinner-ring,
.message.user .chat-img-wrapper.lazy-load.loaded .spinner-ring {
  opacity: 0;
}

/* Image placeholders moved to placeholders.css */

.message.assistant .chat-img-wrapper.error,
.message.user .chat-img-wrapper.error {
  width: 96px;
  height: 96px;
}


/* ================= 3D MODEL STYLES ================= */
/* Pointcloud styles moved to pointcloud.css */

/* Hide failed/deleted images - capsules and chat messages */
.generation-item.hidden-error,
.message.hidden-error,
.chat-img-wrapper.hidden-error,
.media-content.hidden-error {
  display: none !important;
  visibility: hidden !important;
  opacity: 0 !important;
  height: 0 !important;
  overflow: hidden !important;
  margin: 0 !important;
  padding: 0 !important;
}

.chat-model-wrapper {
  position: relative;
  display: inline-block;
  margin-bottom: 0;
  border-radius: 6px;
  overflow: hidden;
  /* Ensure the wrapper respects the same sizing as images */
  max-width: 100%;
  height: auto;
}

/* ================= CLEAN 3D MODEL STYLES (Image-like appearance) ================= */

.chat-model-wrapper-clean {
  position: relative;
  display: inline-block;
  margin-bottom: 0;
  border-radius: 8px;
  overflow: hidden;
  /* Match image wrapper styling exactly */
  max-width: 100%;
  height: auto;
  background: transparent;
  /* Remove any special 3D model styling */
  min-height: unset;
  aspect-ratio: unset;
}

/* Clean 3D model container - matches image behavior */
.chat-model-container-clean {
  position: relative;
  width: 100%;
  height: 100%; /* Match wrapper height to maintain aspect ratio */
  max-width: 100%;
  /* Remove forced min-height for clean appearance */
  min-height: unset;
  background: transparent;
  border-radius: 8px;
  overflow: hidden;
}

/* Clean 3D model thumbnail - matches image styling */
.chat-model-thumb-clean {
  width: 100%;
  height: 100%; /* Fill container height to maintain aspect ratio */
  object-fit: contain;
  display: block;
  cursor: pointer;
  border-radius: 8px;
}

/* Clean 3D model canvas/viewer - matches image behavior */
.chat-model-container-clean canvas,
.chat-model-container-clean model-viewer {
  width: 100% !important;
  height: 100% !important; /* Fill container height to maintain aspect ratio */
  max-width: 100% !important;
  display: block;
  pointer-events: none;
  object-fit: contain;
  border-radius: 8px;
}

/* Assistant clean model wrappers - match image wrapper sizing exactly */
.message.assistant .chat-model-wrapper-clean {
  position: relative;
  display: block;
  max-width: 600px; /* Same as images */
  width: auto;
  height: auto;
  margin-bottom: 0;
  border-radius: 8px;
  overflow: hidden;
  transition: width 0.3s ease, height 0.3s ease;
  /* Maintain 1:1 aspect ratio for 3D models */
  background: transparent;
  min-height: unset;
  aspect-ratio: 1 / 1; /* Keep square aspect for 3D models */
}

/* Desktop adjustments for clean model wrappers */
@media (min-width: 1024px) {
  .message.assistant .chat-model-wrapper-clean {
    max-width: 800px; /* Same as images on desktop */
  }
}

/* Mobile adjustments for clean model wrappers */
@media (max-width: 768px) {
  .message.assistant .chat-model-wrapper-clean {
    max-width: 400px; /* Same as images on mobile */
  }
}

.chat-model-container {
  position: relative;
  width: 100%;
  height: auto;
  /* Ensure the container doesn't exceed the wrapper bounds */
  max-width: 100%;
  /* Ensure proper positioning context for retry button */
  min-height: 200px;
}

.chat-model-thumb {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  cursor: pointer;
}

.chat-model-container canvas,
.chat-model-container model-viewer {
  width: 100% !important;
  height: auto !important;
  max-width: 100% !important;
  display: block;
  pointer-events: none;
  /* Ensure the canvas respects the container bounds */
  object-fit: contain;
}

.chat-model-overlay {
  position: absolute;
  inset: 0;
  cursor: pointer;
}

/* Force canvas elements to respect container bounds */
.chat-model-container canvas[style*="width: 800px"],
.chat-model-container canvas[style*="height: 800px"] {
  width: 100% !important;
  height: auto !important;
  max-width: 100% !important;
}

/* 3D Model Retry Button Styling */
.chat-model-container .retry-button,
.chat-model-container [style*="RETRY DOWNLOAD"] {
  position: absolute !important;
  top: 50% !important;
  left: 50% !important;
  transform: translate(-50%, -50%) !important;
  color: #ffffff !important;
  font-size: 14px !important;
  font-weight: 600 !important;
  text-align: center !important;
  cursor: pointer !important;
  background: rgba(0, 0, 0, 0.7) !important;
  padding: 12px 20px !important;
  border-radius: 8px !important;
  border: 1px solid rgba(255, 255, 255, 0.2) !important;
  backdrop-filter: blur(10px) !important;
  transition: all 0.3s ease !important;
  z-index: 10 !important;
  width: auto !important;
  height: auto !important;
  max-width: calc(100% - 40px) !important;
  word-wrap: break-word !important;
  /* Ensure proper centering by setting explicit positioning context */
  margin: 0 !important;
  line-height: 1.2 !important;
}

.chat-model-container .retry-button:hover,
.chat-model-container [style*="RETRY DOWNLOAD"]:hover {
  background: rgba(0, 0, 0, 0.9) !important;
  border-color: rgba(255, 255, 255, 0.4) !important;
  transform: translate(-50%, -50%) scale(1.05) !important;
}


/* ================= KEYFRAMES & ANIMATIONS ================= */

/* Removed unused chat-spin animation */

/* Center dot - stays in place */
@keyframes thinking {
  0%, 80%, 100% { 
    transform: scale(0.78) translate(0, 0);
    opacity: 0.4;
  }
  40% { 
    transform: scale(1.18) translate(0, 0);
    opacity: 0.92;
  }
}

/* Left dot - spreads left when pulsing */
@keyframes thinking-left {
  0%, 80%, 100% { 
    transform: scale(0.78) translate(0, 0);
    opacity: 0.4;
  }
  40% { 
    transform: scale(1.18) translate(-1.25px, 0);
    opacity: 0.92;
  }
}

/* Right dot - spreads right when pulsing */
@keyframes thinking-right {
  0%, 80%, 100% { 
    transform: scale(0.78) translate(0, 0);
    opacity: 0.4;
  }
  40% { 
    transform: scale(1.18) translate(1.25px, 0);
    opacity: 0.92;
  }
}

@keyframes blinkCursor {
  from, to { opacity: 1; }
  50% { opacity: 0; }
}

/* ================= MEDIA FEEDBACK OVERLAY (Thumbs) ================= */

/* Overlay container positioned inside media wrapper */
.media-feedback-overlay {
  position: absolute;
  left: 10px;
  bottom: 10px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  opacity: 0;
  transform: translateY(10px) scale(0.95);
  transition: opacity 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94),
              transform 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
  z-index: 3;
  pointer-events: none;
}

/* Show overlay when hovering the media wrapper */
.chat-img-wrapper:hover .media-feedback-overlay,
.chat-model-wrapper:hover .media-feedback-overlay {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
  transition-delay: 0.1s;
}

/* Circular thumb buttons with frosted glass effect */
.thumb-btn {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.08);
  border: none;
  box-shadow: 
    0 2px 8px rgba(0, 0, 0, 0.12),
    0 1px 2px rgba(0, 0, 0, 0.08),
    inset 0 0 0 1px rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(12px) saturate(180%);
  -webkit-backdrop-filter: blur(12px) saturate(180%);
  cursor: pointer;
  opacity: 0;
  transform: translateY(6px) scale(0.9);
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  animation: buttonAppear 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94) forwards;
}

/* Staggered animation delays for buttons */
.media-feedback-overlay .thumb-ok {
  animation-delay: 0.15s;
}

.media-feedback-overlay .thumb-notok {
  animation-delay: 0.25s;
}

.media-feedback-overlay .thumb-download {
  animation-delay: 0.35s;
}

/* Entrance animation keyframes */
@keyframes buttonAppear {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.9);
  }
  to {
    opacity: 0.7;
    transform: translateY(0) scale(1);
  }
}

/* Hover state - refined and smooth */
.thumb-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  box-shadow: 
    0 4px 12px rgba(0, 0, 0, 0.16),
    0 2px 4px rgba(0, 0, 0, 0.12),
    inset 0 0 0 1px rgba(255, 255, 255, 0.15),
    0 0 0 4px rgba(255, 255, 255, 0.08);
  transform: scale(1.08);
  opacity: 1;
}

/* Active/Click state - bounce feedback */
.thumb-btn:active {
  transform: scale(0.95);
  transition: all 0.1s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Icon styling with smooth transitions */
.thumb-btn img {
  width: 8px;
  height: 8px;
  display: block;
  object-fit: contain;
  pointer-events: none;
  opacity: 0.6;
  filter: drop-shadow(0 0.5px 1px rgba(0, 0, 0, 0.2));
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.thumb-btn:hover img {
  opacity: 0.9;
  transform: scale(1.05);
}


.thumb-btn svg {
  width: 12px;
  height: 12px;
  display: block;
  color: #fff;
  pointer-events: none;
  opacity: 0.6;
  filter: drop-shadow(0 0.5px 1px rgba(0, 0, 0, 0.2));
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.thumb-btn:hover svg {
  opacity: 0.9;
  transform: scale(1.05);
}

/* Count label with refined typography */
.thumb-count {
  color: rgba(255, 255, 255, 0.85);
  font-size: 9px;
  line-height: 1;
  font-weight: 600;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
  opacity: 0;
  transform: scale(0.9);
  transition: all 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
  animation: buttonAppear 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94) 0.3s forwards;
}

/* Hide counts when project is not shared */
.media-feedback-overlay:not([data-shared="true"]) .thumb-count { 
  display: none; 
}

/* Selection behavior with subtle highlighting */
.media-feedback-overlay[data-selected="ok"] .thumb-ok {
  background: rgba(255, 255, 255, 0.15);
  box-shadow: 
    0 4px 16px rgba(0, 0, 0, 0.2),
    0 2px 4px rgba(0, 0, 0, 0.15),
    inset 0 0 0 1px rgba(255, 255, 255, 0.25),
    0 0 0 4px rgba(255, 255, 255, 0.12);
  opacity: 1;
  transform: scale(1.05);
  animation: selectedBounce 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.media-feedback-overlay[data-selected="notok"] .thumb-notok {
  background: rgba(255, 255, 255, 0.15);
  box-shadow: 
    0 4px 16px rgba(0, 0, 0, 0.2),
    0 2px 4px rgba(0, 0, 0, 0.15),
    inset 0 0 0 1px rgba(255, 255, 255, 0.25),
    0 0 0 4px rgba(255, 255, 255, 0.12);
  opacity: 1;
  transform: scale(1.05);
  animation: selectedBounce 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* Selected button icons become fully visible and colored */
.media-feedback-overlay[data-selected="ok"] .thumb-ok img,
.media-feedback-overlay[data-selected="notok"] .thumb-notok img {
  opacity: 1;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.3)) brightness(1.1);
}

/* Bounce animation for selection */
@keyframes selectedBounce {
  0% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.25);
  }
  100% {
    transform: scale(1.05);
  }
}

/* Fade the non-selected button significantly */
.media-feedback-overlay[data-selected="ok"] .thumb-notok,
.media-feedback-overlay[data-selected="notok"] .thumb-ok {
  opacity: 0.15;
  filter: grayscale(0.9);
  transform: scale(0.95);
}

/* When selected, keep selected button prominent */
.media-feedback-overlay[data-selected="ok"] .thumb-ok,
.media-feedback-overlay[data-selected="notok"] .thumb-notok {
  opacity: 1;
  transform: scale(1.05);
}

/* Immediate feedback animation */
.thumb-btn.just-voted {
  animation: bigBounce 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) !important;
  z-index: 10;
  filter: drop-shadow(0 4px 8px rgba(0,0,0,0.3));
}

@keyframes bigBounce {
  0% { transform: scale(1); }
  40% { transform: scale(1.4); }
  75% { transform: scale(0.9); }
  100% { transform: scale(1.05); }
}

/* Optimistic blast: immediately enlarge selected and fade the other */
.media-feedback-overlay.optimistic-blast[data-selected="ok"] .thumb-ok,
.media-feedback-overlay.optimistic-blast[data-selected="notok"] .thumb-notok {
  transform: scale(1.5) !important;
  opacity: 1 !important;
  transition: transform 0.5s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.2s ease;
}
.media-feedback-overlay.optimistic-blast[data-selected="ok"] .thumb-notok,
.media-feedback-overlay.optimistic-blast[data-selected="notok"] .thumb-ok {
  opacity: 0.1 !important;
  transform: scale(0.85) !important;
}

/* Ensure overlay itself is visible and interactive during optimistic blast */
.media-feedback-overlay.optimistic-blast {
  opacity: 1 !important;
  transform: translateY(0) scale(1) !important;
  pointer-events: auto !important;
  display: inline-flex !important;
}

/* On mobile, re-enable overlay during optimistic animation */
@media (max-width: 768px) {
  .media-feedback-overlay.optimistic-blast {
    display: inline-flex !important;
  }
}

/* Hide feedback overlay on mobile devices (phones and tablets) */
@media (max-width: 768px) {
  .media-feedback-overlay {
    display: none !important;
  }
}

/* iPad optimization - simplified interactions */
@media (min-width: 769px) and (max-width: 1024px) {
  .media-feedback-overlay {
    /* Always slightly visible on iPad for discoverability */
    opacity: 0.6;
    transform: translateY(0) scale(1);
    pointer-events: auto;
  }
  
  .chat-img-wrapper:hover .media-feedback-overlay,
  .chat-model-wrapper:hover .media-feedback-overlay {
    opacity: 1;
    transition-delay: 0s;
  }
  
  .thumb-btn {
    /* Slightly larger for touch */
    width: 28px;
    height: 28px;
    opacity: 0.8;
  }
  
  /* No hover effects on iPad - direct touch only */
  .thumb-btn:hover {
    transform: scale(1);
    box-shadow: 
      0 2px 8px rgba(0, 0, 0, 0.12),
      0 1px 2px rgba(0, 0, 0, 0.08),
      inset 0 0 0 1px rgba(255, 255, 255, 0.1);
  }
  
  /* Active state for touch feedback */
  .thumb-btn:active {
    transform: scale(0.92);
  }
}

/* Lock state: only selected PNG icon remains, no circle */
.media-feedback-overlay[data-locked="true"] {
  pointer-events: none;
}

/* Hide the unselected button completely */
.media-feedback-overlay[data-locked="true"][data-selected="ok"] .thumb-notok,
.media-feedback-overlay[data-locked="true"][data-selected="notok"] .thumb-ok {
  display: none;
}

/* Remove circle background from selected button, keep only PNG */
.media-feedback-overlay[data-locked="true"] .thumb-btn {
  background: transparent;
  border-color: transparent;
  box-shadow: none;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  /* Keep size at 48px - remove width/height auto */
  padding: 0;
}

.media-feedback-overlay[data-locked="true"] .thumb-btn img {
  opacity: 0.8; /* more visible when locked */
}


/* View-only pill notification - glass style */
.viewer-mode-pill {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 10000;
  padding: 12px 24px;
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 24px;
  color: rgba(255, 255, 255, 0.9);
  font-size: 14px;
  font-weight: 500;
  letter-spacing: 0.3px;
  box-shadow: 
    0 8px 32px rgba(0, 0, 0, 0.1),
    inset 0 1px 0 rgba(255, 255, 255, 0.2);
  display: flex;
  align-items: center;
  gap: 8px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.6s ease, transform 0.6s ease;
  white-space: nowrap;
}

.viewer-mode-pill.show {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

.viewer-mode-pill.hide {
  opacity: 0;
  transform: translate(-50%, -50%) scale(0.95);
}

.viewer-mode-pill-icon {
  width: 16px;
  height: 16px;
  opacity: 0.8;
  flex-shrink: 0;
}

/* Mobile adjustments */
@media (max-width: 768px) {
  .viewer-mode-pill {
    padding: 10px 20px;
    font-size: 13px;
  }
}

/* Folder deleted pill notification - inline message style */
.folder-deleted-pill-notification {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  background: rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(12px) saturate(150%);
  -webkit-backdrop-filter: blur(12px) saturate(150%);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 20px;
  color: rgba(255, 255, 255, 0.85);
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.2px;
  box-shadow: 
    0 4px 16px rgba(0, 0, 0, 0.15),
    inset 0 1px 0 rgba(255, 255, 255, 0.1);
  max-width: 100%;
  line-height: 1.4;
}

.folder-deleted-pill-notification .pill-icon {
  font-size: 16px;
  opacity: 0.9;
  flex-shrink: 0;
  line-height: 1;
}

.folder-deleted-pill-notification .pill-text {
  flex: 1;
  word-wrap: break-word;
}

/* Ensure pill notification messages don't show avatar */
.message.assistant:has(.folder-deleted-pill-notification) .message-avatar {
  opacity: 0 !important;
  visibility: hidden !important;
  width: 0 !important;
  margin: 0 !important;
}

/* Center pill notifications in chat */
.message.assistant:has(.folder-deleted-pill-notification) {
  justify-content: center;
  align-items: center;
}

.message.assistant:has(.folder-deleted-pill-notification) .message-content {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
}

/* Mobile adjustments for folder deleted pill */
@media (max-width: 768px) {
  .folder-deleted-pill-notification {
    padding: 8px 16px;
    font-size: 12px;
    gap: 6px;
  }
  
  .folder-deleted-pill-notification .pill-icon {
    font-size: 14px;
  }
}

/* ── Image-reference clarification bubble ─────────────────────────────── */
.message.assistant.clarify-bubble .message-content {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.10);
  border-radius: 16px;
  padding: 14px 16px 12px;
  max-width: 520px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.message.assistant.clarify-bubble .message-text {
  color: rgba(255, 255, 255, 0.92);
  font-size: 14px;
  line-height: 1.4;
  font-weight: 500;
  margin: 0;
}

.message.assistant.clarify-bubble .clarify-thumbs {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  gap: 8px;
  margin: 2px 0 0;
}

.message.assistant.clarify-bubble .clarify-thumb {
  position: relative;
  width: 96px;
  height: 96px;
  padding: 0;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.10);
  background: rgba(0, 0, 0, 0.30);
  cursor: pointer;
  transition: transform 140ms ease, border-color 140ms ease, box-shadow 140ms ease;
  flex: 0 0 auto;
}

.message.assistant.clarify-bubble .clarify-thumb:hover {
  transform: translateY(-2px) scale(1.03);
  border-color: rgba(255, 255, 255, 0.40);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.30);
}

.message.assistant.clarify-bubble .clarify-thumb:focus-visible {
  outline: 2px solid rgba(255, 255, 255, 0.55);
  outline-offset: 2px;
}

.message.assistant.clarify-bubble .clarify-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.message.assistant.clarify-bubble .clarify-thumb-num {
  position: absolute;
  top: 6px;
  left: 6px;
  background: rgba(0, 0, 0, 0.70);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  letter-spacing: 0;
  line-height: 1;
}

.message.assistant.clarify-bubble .clarify-hint {
  color: rgba(255, 255, 255, 0.48);
  font-size: 12px;
  line-height: 1.4;
  margin: 0;
}

/* ═══════════════════════════════════════════════════════════════════════
 * Memory card — rendered by /memory slash command.
 * Built by DOM APIs in SlashDispatch.js (textContent only, no innerHTML
 * on user data). Lives inside an assistant message bubble.
 * ═══════════════════════════════════════════════════════════════════════ */

/* Claude-style: no pills, no loud color, hairline dividers, generous
 * whitespace, refined typography. The card reads like a journal page,
 * not a settings panel. */
.memory-card {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 560px;
  padding: 28px 4px 18px;
  background: transparent;
  border: 0;
  box-shadow: none;
  color: rgba(255, 255, 255, 0.9);
  font: 400 14px/1.55 ui-serif, "Iowan Old Style", "Apple Garamond", Georgia, "Times New Roman", serif;
}

.memcard-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 18px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
  margin-bottom: 18px;
}
.memcard-title {
  font: 400 17px/1.2 ui-serif, "Iowan Old Style", "Apple Garamond", Georgia, "Times New Roman", serif;
  letter-spacing: 0.01em;
  color: rgba(255, 255, 255, 0.92);
  font-style: italic;
}
.memcard-count {
  font: 500 11px/1 ui-sans-serif, -apple-system, system-ui, sans-serif;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.35);
  background: transparent;
  padding: 0;
}

.memcard-id {
  display: flex;
  align-items: baseline;
  gap: 14px;
  padding: 0 0 18px;
  background: transparent;
  border: 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
  margin-bottom: 14px;
}
.memcard-id-label {
  font: 500 10px/1 ui-sans-serif, -apple-system, system-ui, sans-serif;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.35);
  flex-shrink: 0;
}
.memcard-id-value {
  font: 500 19px/1.1 ui-serif, "Iowan Old Style", "Apple Garamond", Georgia, "Times New Roman", serif;
  color: rgba(255, 255, 255, 0.98);
  letter-spacing: -0.005em;
}
.memcard-id-empty {
  color: rgba(255, 255, 255, 0.4);
  font-style: italic;
  font-size: 13px;
}

.memcard-entries {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  max-height: 380px;
  overflow-y: auto;
}
.memcard-entries::-webkit-scrollbar { width: 6px; }
.memcard-entries::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.08); border-radius: 3px; }
.memcard-entry {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: baseline;
  column-gap: 16px;
  row-gap: 2px;
  padding: 12px 0 14px;
  border: 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  background: transparent;
  transition: opacity 120ms ease;
}
.memcard-entry:last-child { border-bottom: 0; }
.memcard-entry-topic {
  grid-column: 1 / 2;
  font: 500 9px/1 ui-sans-serif, -apple-system, system-ui, sans-serif;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.32);
  padding: 0;
  background: transparent;
  border-radius: 0;
  margin-bottom: 4px;
}
.memcard-entry-text {
  grid-column: 1 / 2;
  font: 400 14px/1.5 ui-serif, "Iowan Old Style", "Apple Garamond", Georgia, "Times New Roman", serif;
  color: rgba(255, 255, 255, 0.92);
  word-break: break-word;
  letter-spacing: -0.002em;
}
.memcard-entry-remove {
  grid-column: 2 / 3;
  grid-row: 1 / 3;
  align-self: center;
  appearance: none;
  background: transparent;
  border: 0;
  color: rgba(255, 255, 255, 0.22);
  font: 400 14px/1 ui-sans-serif, -apple-system, system-ui, sans-serif;
  width: 20px;
  height: 20px;
  padding: 0;
  border-radius: 50%;
  cursor: pointer;
  opacity: 0;
  transition: opacity 160ms ease, color 160ms ease;
}
.memcard-entry:hover .memcard-entry-remove { opacity: 1; }
.memcard-entry-remove:hover { color: rgba(255, 255, 255, 0.85); }
.memcard-entry-remove:disabled { opacity: 0.3; cursor: not-allowed; }
.memcard-entry-remove:focus-visible { opacity: 1; outline: 1px solid rgba(255, 255, 255, 0.3); outline-offset: 2px; }

.memcard-empty {
  list-style: none;
  padding: 24px 0;
  text-align: left;
  font-style: italic;
  color: rgba(255, 255, 255, 0.4);
  background: transparent;
  border-radius: 0;
  font-size: 13px;
}

.memcard-topics {
  display: flex;
  flex-wrap: wrap;
  gap: 14px 18px;
  padding-top: 18px;
  margin-top: 6px;
  border-top: 1px solid rgba(255, 255, 255, 0.07);
}
.memcard-topic {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  padding: 0;
  border-radius: 0;
  background: transparent;
  border: 0;
  font: 400 13px/1 ui-serif, "Iowan Old Style", "Apple Garamond", Georgia, "Times New Roman", serif;
  color: rgba(255, 255, 255, 0.7);
}
.memcard-topic-count {
  font: 500 10px/1 ui-sans-serif, -apple-system, system-ui, sans-serif;
  color: rgba(255, 255, 255, 0.32);
  letter-spacing: 0.04em;
}

.memcard-footer {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  padding-top: 20px;
  margin-top: 8px;
  border-top: 1px solid rgba(255, 255, 255, 0.07);
}
.memcard-clear {
  appearance: none;
  background: transparent;
  border: 0;
  color: rgba(255, 255, 255, 0.4);
  font: 400 12px/1 ui-sans-serif, -apple-system, system-ui, sans-serif;
  letter-spacing: 0.02em;
  padding: 0;
  cursor: pointer;
  text-decoration: underline;
  text-decoration-color: rgba(255, 255, 255, 0.15);
  text-underline-offset: 3px;
  transition: color 160ms ease, text-decoration-color 160ms ease;
}
.memcard-clear:hover {
  color: rgba(255, 180, 180, 0.85);
  text-decoration-color: rgba(255, 180, 180, 0.4);
}
.memcard-clear:disabled { opacity: 0.4; cursor: not-allowed; }
.memcard-hint {
  font: 400 11px/1.4 ui-sans-serif, -apple-system, system-ui, sans-serif;
  color: rgba(255, 255, 255, 0.3);
  text-align: right;
  letter-spacing: 0.01em;
  font-style: italic;
}
.memcard-hint {
  font: 500 11px/1.35 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: rgba(255, 255, 255, 0.4);
  text-align: right;
}

/* ── Chat video sound toggle (speaker on/off) ─────────────────────── */
/* Videos autoplay muted (browser policy); this speaker button unmutes on click. */
.chat-img-wrapper.mediabubble[data-media-type="video"] {
  position: relative;
}
.chat-video-sound-toggle {
  position: absolute;
  bottom: 6px;
  right: 6px;
  z-index: 6;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  margin: 0;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 999px;
  background: rgba(18, 18, 20, 0.55);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  color: #fff;
  cursor: pointer;
  opacity: 0.85;
  transition: opacity 0.18s ease, background 0.18s ease, border-color 0.18s ease, transform 0.18s ease;
}
.chat-img-wrapper.mediabubble[data-media-type="video"]:hover .chat-video-sound-toggle {
  opacity: 1;
}
.chat-video-sound-toggle:hover {
  background: rgba(0, 0, 0, 0.72);
  border-color: rgba(255, 255, 255, 0.4);
  transform: scale(1.06);
}
.chat-video-sound-toggle.active {
  background: rgba(18, 18, 20, 0.78);
  border-color: rgba(255, 255, 255, 0.45);
}
.chat-video-sound-toggle svg {
  display: block;
  pointer-events: none;
}

/* ── Transparent dark-line media (e.g. Extract Edges results) ──
   These PNGs are transparent with dark lines; on the dark capsule panel and
   viewer they'd be invisible. Give them a light backdrop wherever displayed. */
.generation-item[data-job-type="edge_extract"] .capsule-image,
.generation-item[data-job-type="edge_extract"] .capsule-image img,
.capsule-image.edge-extract-img img
{
  background: #eef0f3 !important; 
}

#capsuleImageOverlay.media-transparent-dark-lines #capsuleOverlayImg {
  background: #eef0f3 !important;
  border-radius: 4px !important;
}

#capsuleImageOverlay.media-transparent-dark-lines #capsuleOverlayParentImagesGrid .is-loaded {
  background: #eef0f3 !important;
  border-radius: 4px !important;
}
