/**
 * 💬 Chat Thread Styles - BESSER Spaceship Design
 * 1000000% Responsive & Beautiful
 */

.chat-thread {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh; /* Dynamic viewport for mobile */
  width: 100%;
  max-width: 100vw;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  overflow: hidden;
  background: var(--color-background);
  --chat-thread-header-height: 72px;
  --composer-height: 72px;
}

/* ========================================
   HEADER - Spaceship Command Center
   Fixed at top, no scroll
   ======================================== */

.chat-thread-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  min-height: 56px;
  background: rgba(255, 255, 255, 0.03);
  backdrop-filter: blur(40px) saturate(180%);
  -webkit-backdrop-filter: blur(40px) saturate(180%);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  position: fixed;
  top: var(--mobile-header-height);
  left: 0;
  right: 0;
  z-index: 1000;
  flex-shrink: 0;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.chat-thread-header .btn-icon {
  width: 36px;
  height: 36px;
  min-width: 36px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.05);
  backdrop-filter: blur(10px);
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.chat-thread-header .btn-icon:active {
  transform: scale(0.92);
  background: rgba(255, 255, 255, 0.08);
}

.chat-thread-partner {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
  cursor: pointer;
  padding: 4px;
  margin: -4px;
  border-radius: 12px;
  transition: background 0.2s ease;
}

.chat-thread-partner:active {
  background: rgba(255, 255, 255, 0.05);
}

.chat-thread-avatar {
  width: 40px;
  height: 40px;
  min-width: 40px;
  border-radius: 50%;
  flex-shrink: 0;
  position: relative;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.chat-thread-avatar .avatar-circle {
  width: 100%;
  height: 100%;
}

.chat-thread-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.chat-thread-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.chat-thread-info h3 {
  font-size: 15px;
  font-weight: 600;
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--color-text);
  letter-spacing: -0.01em;
}

.chat-thread-status {
  font-size: 11px;
  font-weight: 500;
  color: var(--color-text-secondary);
  margin: 0;
  display: flex;
  align-items: center;
  gap: 5px;
}

.status-indicator {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  display: inline-block;
}

.status-indicator.online {
  background: #10b981;
  box-shadow: 0 0 6px rgba(16, 185, 129, 0.8);
  animation: pulse-online 2s ease-in-out infinite;
}

@keyframes pulse-online {
  0%, 100% {
    opacity: 1;
    transform: scale(1);
  }
  50% {
    opacity: 0.8;
    transform: scale(0.95);
  }
}

.status-indicator.offline {
  background: #6b7280;
}

.chat-thread-actions {
  display: flex;
  gap: 6px;
  margin-left: auto;
}

/* ========================================
   MESSAGES CONTAINER - Spaceship Viewport
   Only scrollable area, fills space between header and composer
   ======================================== */

.chat-thread-messages {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 12px 16px;
  padding-top: calc(var(--mobile-header-height) + var(--chat-thread-header-height) + 12px);
  /* Reserve space for bottom nav (mobile) + composer + safe area + breathing room */
  padding-bottom: calc( var(--mobile-bottom-nav-height) + var(--composer-height, 72px) + var(--safe-area-inset-bottom) + 24px );
  display: flex;
  flex-direction: column;
  gap: 6px;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  position: relative;
  min-height: 100vh;
  min-height: 100dvh;
}

/* Desktop overrides: remove bottom nav spacing */
@media (min-width: 1024px) {
  .chat-thread-messages {
    padding-bottom: calc(var(--composer-height, 72px) + 24px);
  }
}

/* Custom scrollbar - subtle & beautiful */
.chat-thread-messages::-webkit-scrollbar {
  width: 4px;
}

.chat-thread-messages::-webkit-scrollbar-track {
  background: transparent;
}

.chat-thread-messages::-webkit-scrollbar-thumb {
  background: rgba(124, 58, 237, 0.3);
  border-radius: 2px;
  transition: background 0.2s ease;
}

.chat-thread-messages::-webkit-scrollbar-thumb:hover {
  background: rgba(124, 58, 237, 0.5);
}

/* Loading States - Premium feel */
.messages-loading,
.messages-empty,
.messages-error {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  text-align: center;
  color: var(--color-text-secondary);
  flex: 1;
}

.messages-loading .spinner {
  width: 36px;
  height: 36px;
  border: 2.5px solid rgba(124, 58, 237, 0.15);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.8s cubic-bezier(0.5, 0, 0.5, 1) infinite;
  margin-bottom: 16px;
}

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

.messages-empty .empty-icon,
.messages-error .error-icon {
  font-size: 56px;
  margin-bottom: 12px;
  opacity: 0.6;
  filter: grayscale(20%);
}

.messages-empty h3,
.messages-error h3 {
  font-size: 17px;
  font-weight: 600;
  margin: 0 0 6px 0;
  color: var(--color-text);
  letter-spacing: -0.02em;
}

.messages-empty p,
.messages-error p {
  font-size: 14px;
  margin: 0;
  max-width: 260px;
  line-height: 1.4;
}

/* Date Separator - Clean & minimal */
.message-date-separator {
  text-align: center;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--color-text-secondary);
  padding: 16px 0 8px;
  position: relative;
  margin: 4px 0;
  opacity: 0.7;
}


/* ========================================
   MESSAGE BUBBLES - Spaceship Precision
   ======================================== */

.message-bubble {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  margin: 1px 0;
  animation: messageSlideIn 0.35s cubic-bezier(0.16, 1, 0.3, 1);
  will-change: opacity, transform;
}

@keyframes messageSlideIn {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.message-bubble.received {
  margin-right: auto;
}

.message-bubble.sent {
  flex-direction: row-reverse;
  margin-left: auto;
}

.message-bubble.sent .message-content {
  align-items: flex-end;
  text-align: right;
}

.message-bubble.sent .message-meta {
  justify-content: flex-end;
}

.message-avatar {
  width: 28px;
  height: 28px;
  min-width: 28px;
  border-radius: 50%;
  flex-shrink: 0;
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
}

.message-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.message-content {
  max-width: 75%;
  display: flex;
  flex-direction: column;
  position: relative;
}

.message-text {
  padding: 10px 14px;
  border-radius: 20px;
  font-size: 15px;
  line-height: 1.42;
  word-wrap: break-word;
  overflow-wrap: break-word;
  white-space: pre-wrap;
  position: relative;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
  transition: transform 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.message-text:active {
  transform: scale(0.98);
}

/* Received Messages - Frosted Glass */
.message-bubble.received .message-text {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-bottom-left-radius: 6px;
  color: var(--color-text);
  backdrop-filter: blur(10px);
}

/* Sent Messages - BESSER Gradient */
.message-bubble.sent .message-text {
  background: linear-gradient(
    135deg, 
    rgba(124, 58, 237, 1) 0%,
    rgba(236, 72, 153, 0.95) 100%
  );
  border-bottom-right-radius: 6px;
  color: white;
  font-weight: 450;
  box-shadow: 0 2px 8px rgba(124, 58, 237, 0.25);
}

/* Links in messages */
.message-text a {
  color: inherit;
  text-decoration: underline;
  text-decoration-color: rgba(255, 255, 255, 0.5);
  text-underline-offset: 2px;
  transition: text-decoration-color 0.2s ease;
}

.message-text a:hover {
  text-decoration-color: rgba(255, 255, 255, 0.9);
}

.message-bubble.sent .message-text a {
  font-weight: 500;
}

/* Message Metadata - Subtle & Clean */
.message-meta {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 3px 6px 0;
  font-size: 10px;
  font-weight: 500;
  color: var(--color-text-secondary);
  opacity: 0.6;
}

.message-bubble.sent .message-meta {
  justify-content: flex-end;
}

.read-receipt {
  color: var(--color-text-secondary);
  font-size: 11px;
  line-height: 1;
}

.read-receipt.read {
  color: rgba(124, 58, 237, 0.8);
}

/* ========================================
   MESSAGE COMPOSER - Command Center Input
   Fixed at bottom, always visible above bottom nav
   ======================================== */

.chat-thread-composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.03);
  backdrop-filter: blur(40px) saturate(180%);
  -webkit-backdrop-filter: blur(40px) saturate(180%);
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  flex-shrink: 0;
  position: fixed;
  bottom: var(--mobile-bottom-nav-height); /* Above bottom navigation (already includes safe area) */
  left: 0;
  right: 0;
  z-index: 999;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

@supports (padding-bottom: env(safe-area-inset-bottom)) {
  .chat-thread-composer {
    padding-bottom: 10px; /* Bottom nav already provides primary safe-area padding */
  }
}

/* Ensure message bubbles never exceed container width and adapt to viewport */
.message-bubble {
  max-width: min(78%, 560px);
}

@media (max-width: 480px) {
  .message-bubble { max-width: 84%; }
}

@media (min-width: 1024px) {
  .message-bubble { max-width: min(60%, 640px); }
  .chat-thread-messages {
    padding-left: clamp(32px, 6vw, 96px);
    padding-right: clamp(32px, 6vw, 96px);
  }
}

/* Guarantee last message visibility: add after pseudo element spacer */
.chat-thread-messages::after {
  content: "";
  display: block;
  height: 8px; /* breathing room below last bubble */
}

/* Scrollbar styling for better desktop feel */
.chat-thread-messages::-webkit-scrollbar { width: 10px; }
.chat-thread-messages::-webkit-scrollbar-track { background: transparent; }
.chat-thread-messages::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.08); border-radius: 10px; border: 2px solid rgba(0,0,0,0.15); }
.chat-thread-messages::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.14); }

/* Prevent cut-off when virtual keyboard opens (mobile) */
@supports (height: 100svh) {
  .chat-thread { height: 100svh; }
  .chat-thread-messages { min-height: 100svh; }
}

/* Allow taller growing input without overlapping messages */
.composer-input { max-height: 180px; }

/* When input grows, push messages up (JS can toggle a class). Reserve variable driven space. */
.chat-thread.compose-expanded .chat-thread-messages { padding-bottom: calc(var(--composer-height,72px) + 48px); }

.composer-input-wrapper {
  flex: 1;
  min-width: 0;
  position: relative;
}

.composer-input {
  width: 100%;
  min-height: 38px;
  max-height: 120px;
  padding: 9px 14px;
  border: none;
  border-radius: 19px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: var(--color-text);
  font-size: 15px;
  line-height: 1.42;
  font-family: var(--font-sans);
  resize: none;
  outline: none;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.composer-input:focus {
  background: rgba(255, 255, 255, 0.09);
  border-color: rgba(124, 58, 237, 0.3);
  box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.08);
}

.composer-input::placeholder {
  color: var(--color-text-secondary);
  opacity: 0.5;
}

/* Composer Buttons - Spaceship Controls */
.chat-thread-composer .btn-icon {
  width: 38px;
  height: 38px;
  min-width: 38px;
  min-height: 38px;
  flex-shrink: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  align-items: center;
  justify-content: center;
}

.chat-thread-composer .btn-icon:active {
  transform: scale(0.90);
}

.chat-thread-composer .btn-primary {
  background: linear-gradient(
    135deg, 
    rgba(124, 58, 237, 1) 0%,
    rgba(236, 72, 153, 0.95) 100%
  );
  border: none;
  box-shadow: 0 2px 8px rgba(124, 58, 237, 0.3);
}

.chat-thread-composer .btn-primary:active {
  box-shadow: 0 1px 4px rgba(124, 58, 237, 0.4);
}

/* ========================================
   SCROLL TO BOTTOM BUTTON - Smart Auto-Scroll
   ======================================== */

.scroll-to-bottom {
  position: fixed;
  bottom: calc(var(--mobile-bottom-nav-height) + var(--composer-height, 72px) + 12px); /* Above composer */
  right: 16px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: linear-gradient(
    135deg, 
    rgba(124, 58, 237, 0.95) 0%,
    rgba(236, 72, 153, 0.95) 100%
  );
  border: none;
  box-shadow: 0 4px 16px rgba(124, 58, 237, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 1001;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  transform: translateY(0) scale(1);
  opacity: 0;
  pointer-events: none;
}

@media (min-width: 1024px) {
  .scroll-to-bottom {
    bottom: calc(var(--composer-height, 72px) + 12px);
  }
}

.scroll-to-bottom.visible {
  opacity: 1;
  pointer-events: all;
}

.scroll-to-bottom:hover {
  transform: translateY(-2px) scale(1.05);
  box-shadow: 0 6px 20px rgba(124, 58, 237, 0.5);
}

.scroll-to-bottom:active {
  transform: translateY(0) scale(0.95);
}

.scroll-to-bottom .arrow {
  font-size: 20px;
  line-height: 1;
  color: white;
}

/* Unread badge on scroll button */
.scroll-to-bottom .unread-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 10px;
  background: #ef4444;
  color: white;
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(239, 68, 68, 0.4);
  animation: badge-pop 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

@keyframes badge-pop {
  0% {
    transform: scale(0);
  }
  50% {
    transform: scale(1.2);
  }
  100% {
    transform: scale(1);
  }
}

/* Typing Indicator - Under last message */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  margin: 4px 0;
  animation: messageSlideIn 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}

.typing-indicator .message-avatar {
  width: 28px;
  height: 28px;
  min-width: 28px;
}

.typing-indicator-dots {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 10px 14px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 20px;
  border-bottom-left-radius: 6px;
}

.typing-indicator-dots span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--color-text-secondary);
  animation: typing-bounce 1.4s ease-in-out infinite;
}

.typing-indicator-dots span:nth-child(2) {
  animation-delay: 0.2s;
}

.typing-indicator-dots span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes typing-bounce {
  0%, 60%, 100% {
    transform: translateY(0);
    opacity: 0.5;
  }
  30% {
    transform: translateY(-8px);
    opacity: 1;
  }
}

/* Typing status in header */
.chat-thread-status.typing {
  color: var(--color-primary);
  font-weight: 600;
}

.chat-thread-status.typing .status-indicator {
  display: none;
}

/* ========================================
   MESSAGE IMAGES & ATTACHMENTS
   ======================================== */

.message-image {
  max-width: 280px;
  border-radius: 16px;
  overflow: hidden;
  margin-bottom: 4px;
  cursor: pointer;
  transition: transform 0.2s ease;
}

.message-image:active {
  transform: scale(0.98);
}

.message-image img {
  width: 100%;
  height: auto;
  display: block;
  object-fit: cover;
}

.message-bubble.sent .message-image {
  border-bottom-right-radius: 6px;
}

.message-bubble.received .message-image {
  border-bottom-left-radius: 6px;
}

/* Message with only image, no text */
.message-content:has(.message-image):not(:has(.message-text)) .message-image {
  margin-bottom: 0;
}

/* ========================================
   EMOJI PICKER OVERLAY
   ======================================== */

.emoji-picker {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  max-height: 60vh;
  background: rgba(20, 20, 40, 0.98);
  backdrop-filter: blur(40px) saturate(180%);
  -webkit-backdrop-filter: blur(40px) saturate(180%);
  border-top-left-radius: 24px;
  border-top-right-radius: 24px;
  box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.3);
  z-index: 10000;
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  flex-direction: column;
}

.emoji-picker.visible {
  transform: translateY(0);
}

.emoji-picker-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.emoji-picker-header h3 {
  font-size: 18px;
  font-weight: 600;
  margin: 0;
  color: var(--color-text);
}

.emoji-picker-grid {
  padding: 16px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(44px, 1fr));
  gap: 8px;
  overflow-y: auto;
  max-height: calc(60vh - 70px);
  -webkit-overflow-scrolling: touch;
}

.emoji-btn {
  width: 44px;
  height: 44px;
  border: none;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 12px;
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  align-items: center;
  justify-content: center;
}

.emoji-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  transform: scale(1.1);
}

.emoji-btn:active {
  transform: scale(0.95);
  background: rgba(124, 58, 237, 0.3);
}

/* ========================================
   FILE PREVIEW OVERLAY
   ======================================== */

.file-preview-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.9);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.3s ease;
  padding: 20px;
}

.file-preview-overlay.visible {
  opacity: 1;
}

.file-preview-container {
  background: rgba(20, 20, 40, 0.95);
  border-radius: 24px;
  max-width: 600px;
  width: 100%;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  overflow: hidden;
}

.file-preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.file-preview-header h3 {
  font-size: 18px;
  font-weight: 600;
  margin: 0;
  color: var(--color-text);
}

.file-preview-grid {
  padding: 24px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 16px;
  overflow-y: auto;
  max-height: calc(80vh - 180px);
  -webkit-overflow-scrolling: touch;
}

.file-preview-item {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.file-preview-content {
  aspect-ratio: 1;
  border-radius: 12px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.05);
  display: flex;
  align-items: center;
  justify-content: center;
}

.file-preview-content img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.file-icon {
  font-size: 48px;
}

.file-preview-name {
  font-size: 12px;
  color: var(--color-text);
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-preview-size {
  font-size: 11px;
  color: var(--color-text-secondary);
  margin: 0;
}

.file-preview-footer {
  display: flex;
  gap: 12px;
  padding: 20px 24px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.file-preview-footer .btn {
  flex: 1;
  justify-content: center;
  gap: 8px;
}

/* ========================================
   VOICE RECORDER OVERLAY
   ======================================== */

.voice-recorder-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.9);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.3s ease;
  padding: 20px;
}

.voice-recorder-overlay.visible {
  opacity: 1;
}

.voice-recorder-container {
  background: rgba(20, 20, 40, 0.95);
  border-radius: 24px;
  max-width: 400px;
  width: 100%;
  display: flex;
  flex-direction: column;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  overflow: hidden;
}

.voice-recorder-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.voice-recorder-header h3 {
  font-size: 18px;
  font-weight: 600;
  margin: 0;
  color: var(--color-text);
}

.voice-recorder-waveform {
  padding: 40px 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 180px;
}

.waveform-bars {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  height: 100px;
}

.waveform-bar {
  width: 4px;
  height: 20%;
  background: linear-gradient(
    to top,
    rgba(124, 58, 237, 0.8),
    rgba(236, 72, 153, 0.8)
  );
  border-radius: 2px;
  transition: height 0.1s ease;
}

.voice-recorder-time {
  text-align: center;
  padding: 0 24px 24px;
  font-size: 32px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--color-primary);
}

.voice-recorder-controls {
  display: flex;
  gap: 12px;
  padding: 20px 24px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  align-items: center;
}

.btn-record {
  width: 64px;
  height: 64px;
  min-width: 64px;
  min-height: 64px;
  border-radius: 50%;
  background: linear-gradient(
    135deg,
    rgba(239, 68, 68, 0.95) 0%,
    rgba(220, 38, 38, 0.95) 100%
  );
  box-shadow: 0 4px 16px rgba(239, 68, 68, 0.4);
}

.btn-record.pulsing {
  animation: record-pulse 2s ease-in-out infinite;
}

@keyframes record-pulse {
  0%, 100% {
    box-shadow: 0 4px 16px rgba(239, 68, 68, 0.4);
  }
  50% {
    box-shadow: 0 4px 24px rgba(239, 68, 68, 0.8);
  }
}

.voice-recorder-controls .btn-secondary,
.voice-recorder-controls .btn-primary {
  flex: 1;
}

/* ========================================
   SKELETON LOADER - Smooth Loading
   ======================================== */

.skeleton-loader {
  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: shimmer 1.8s ease-in-out infinite;
  border-radius: 10px;
}

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

/* ========================================
   RESPONSIVE - Tablet & Desktop
   ======================================== */

@media (min-width: 640px) {
  .chat-thread-header {
    padding: 10px 20px;
  }

  .chat-thread-messages {
    padding: 16px 24px;
  }

  .message-content {
    max-width: 70%;
  }

  .composer-input {
    font-size: 15px;
  }
}

@media (min-width: 768px) {
  .chat-thread-header {
    padding: 12px 24px;
    gap: 12px;
  }

  .chat-thread-header .btn-icon {
    width: 38px;
    height: 38px;
  }

  .chat-thread-avatar {
    width: 44px;
    height: 44px;
    min-width: 44px;
  }

  .chat-thread-info h3 {
    font-size: 16px;
  }

  .chat-thread-status {
    font-size: 12px;
  }

  .chat-thread-messages {
    padding: 20px 32px;
    gap: 8px;
  }

  .message-content {
    max-width: 65%;
  }

  .message-text {
    padding: 11px 16px;
    font-size: 15px;
  }

  .message-avatar {
    width: 32px;
    height: 32px;
    min-width: 32px;
  }

  .chat-thread-composer {
    padding: 12px 24px;
    gap: 10px;
  }

  .composer-input {
    min-height: 42px;
    padding: 11px 16px;
  }

  .chat-thread-composer .btn-icon {
    width: 42px;
    height: 42px;
    min-width: 42px;
  }
}

@media (min-width: 1024px) {
  .chat-thread-messages {
    padding: 24px 48px;
  }

  .message-content {
    max-width: 55%;
  }

  .message-text {
    font-size: 15px;
    padding: 12px 18px;
  }
}

/* ========================================
   ADAPTIVE HEIGHT - Better UX
   ======================================== */

@media (max-height: 667px) {
  /* iPhone SE, small screens */
  .chat-thread-header {
    min-height: 52px;
    padding: 6px 12px;
  }

  .chat-thread-avatar {
    width: 36px;
    height: 36px;
    min-width: 36px;
  }

  .chat-thread-info h3 {
    font-size: 14px;
  }

  .chat-thread-messages {
    padding: 10px 14px;
  }

  .message-text {
    padding: 9px 13px;
    font-size: 14px;
  }

  .composer-input {
    min-height: 36px;
    font-size: 14px;
  }
}

@media (min-height: 844px) {
  /* iPhone 14/15, modern phones */
  .chat-thread-messages {
    padding: 16px 18px;
  }
}

/* ========================================
   TOUCH OPTIMIZATIONS
   ======================================== */

@media (hover: none) and (pointer: coarse) {
  /* Touch devices only */
  .chat-thread-partner:active {
    background: rgba(255, 255, 255, 0.08);
  }

  .message-text {
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
  }

  .composer-input {
    font-size: 16px; /* Prevents zoom on iOS */
  }
}

/* ========================================
   DARK MODE ENHANCEMENTS
   ======================================== */

@media (prefers-color-scheme: dark) {
  .chat-thread-header,
  .chat-thread-composer {
    backdrop-filter: blur(60px) saturate(200%);
    -webkit-backdrop-filter: blur(60px) saturate(200%);
  }

  .message-bubble.received .message-text {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.1);
  }

  .composer-input {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.1);
  }

  .composer-input:focus {
    background: rgba(255, 255, 255, 0.11);
    border-color: rgba(124, 58, 237, 0.4);
    box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.12);
  }
}

/* ========================================
   LANDSCAPE MODE
   ======================================== */

@media (orientation: landscape) and (max-height: 500px) {
  .chat-thread-header {
    min-height: 48px;
    padding: 6px 12px;
  }

  .chat-thread-messages {
    padding: 8px 16px;
  }

  .chat-thread-composer {
    padding: 8px 12px;
  }

  .message-text {
    padding: 8px 12px;
  }
}

/* ========================================
   PRINT STYLES
   ======================================== */

@media print {
  .chat-thread-header,
  .chat-thread-composer {
    display: none;
  }

  .chat-thread-messages {
    overflow: visible;
    height: auto;
  }

  .message-bubble {
    page-break-inside: avoid;
  }
}
