/* Messaging Design System Styles - Mobile First */

/* Override global focus styles for message textarea */
textarea#message:focus {
  outline: none !important;
  box-shadow: none !important;
  transform: none !important;
}

/* Hide scrollbar for message textarea (it auto-resizes) */
textarea#message {
  scrollbar-width: none;
  /* Firefox */
  -ms-overflow-style: none;
  /* IE and Edge */
}

textarea#message::-webkit-scrollbar {
  display: none;
  /* Chrome, Safari, Opera */
}

/* Custom Animations */
@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes pulse-glow {

  0%,
  100% {
    opacity: 1;
  }

  50% {
    opacity: 0.5;
  }
}

.animate-fadeInUp {
  animation: fadeInUp 0.5s ease-out;
}

.animate-pulse-glow {
  animation: pulse-glow 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

/* Reduced Motion Support */
@media (prefers-reduced-motion: reduce) {

  .animate-fadeInUp,
  .animate-pulse-glow,
  .animate-pulse {
    animation: none;
  }

  * {
    transition-duration: 0.01ms !important;
  }
}

/* High Contrast Mode Support */
@media (prefers-contrast: high) {
  .bg-gradient-to-br {
    background: var(--bg-color, #ffffff) !important;
  }

  .text-transparent {
    color: var(--text-color, #000000) !important;
  }

  .border-gray-200 {
    border-color: #000000 !important;
  }
}

/* Mobile Optimizations */
@media (max-width: 640px) {

  /* Ensure touch targets are at least 44px (iOS) / 48px (Android) */
  button,
  a,
  input[type="submit"],
  input[type="button"],
  select {
    min-height: 44px;
    min-width: 44px;
  }

  /* Increase spacing between touch targets */
  .flex.gap-2>*+* {
    margin-left: 0.75rem;
  }

  /* Optimize form inputs for mobile */
  input[type="text"],
  input[type="email"],
  input[type="tel"],
  input[type="url"],
  input[type="password"],
  textarea,
  select {
    font-size: 16px;
    /* Prevents zoom on iOS */
  }
}

/* Glassmorphism Effects */
.glass-card {
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.glass-card:hover {
  background: rgba(255, 255, 255, 0.15);
}

/* Gradient Text */
.gradient-text {
  background: linear-gradient(to right, #2563eb, #4f46e5);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* Status Badge Animations */
.status-badge {
  position: relative;
}

.status-badge::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  padding: 1px;
  background: linear-gradient(135deg, currentColor, transparent);
  -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  opacity: 0.3;
}

/* Loading States */
.loading-skeleton {
  background: linear-gradient(90deg,
      #f0f0f0 25%,
      #e0e0e0 50%,
      #f0f0f0 75%);
  background-size: 200% 100%;
  animation: loading 1.5s ease-in-out infinite;
}

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

  100% {
    background-position: -200% 0;
  }
}

/* Message Status Indicators */
.message-status-sent {
  color: #3b82f6;
}

.message-status-delivered {
  color: #10b981;
}

.message-status-read {
  color: #059669;
}

.message-status-failed {
  color: #ef4444;
}

.message-status-pending {
  color: #6b7280;
}

/* Health Status Pulse */
.health-status-healthy {
  animation: pulse-glow 2s ease-in-out infinite;
}

.health-status-degraded {
  animation: pulse-glow 1s ease-in-out infinite;
}

.health-status-unhealthy {
  animation: pulse-glow 0.5s ease-in-out infinite;
}

/* Safe Area Padding for Notched Devices */
@supports (padding: max(0px)) {
  .pb-safe {
    padding-bottom: max(1rem, env(safe-area-inset-bottom));
  }

  .pt-safe {
    padding-top: max(1rem, env(safe-area-inset-top));
  }

  .px-safe {
    padding-left: max(1rem, env(safe-area-inset-left));
    padding-right: max(1rem, env(safe-area-inset-right));
  }
}

/* Bottom Sheet Modal (Mobile) */
@media (max-width: 640px) {
  .bottom-sheet {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    max-height: 90vh;
    border-radius: 1.5rem 1.5rem 0 0;
    transform: translateY(100%);
    transition: transform 0.3s ease-out;
  }

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

/* Focus States for Accessibility */
.focus-ring:focus {
  outline: 2px solid #3b82f6;
  outline-offset: 2px;
}

.focus-ring:focus:not(:focus-visible) {
  outline: none;
}

/* Print Styles */
@media print {
  .no-print {
    display: none !important;
  }

  .print-break {
    page-break-after: always;
  }
}

/* =====================================================
   WhatsApp-Style Message Sending UX
   ===================================================== */

/* Message Send Animation - Slide up and fade in */
.message-enter {
  animation: messageSlideIn 0.25s ease-out forwards;
}

@keyframes messageSlideIn {
  from {
    opacity: 0;
    transform: translateY(20px) scale(0.95);
  }

  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* Status Icon Base Styles */
.status-icon {
  transition: all 0.2s ease-out;
}

/* Status Icon Transition Animation */
.status-transitioning .status-icon {
  opacity: 0;
  transform: scale(0.8);
}

.message-status {
  min-width: 16px;
  display: inline-flex;
  align-items: center;
  transition: all 0.15s ease-out;
}

/* Double check slide-in animation for delivered status */
@keyframes secondCheckSlide {
  from {
    opacity: 0;
    transform: translateX(-4px);
  }

  to {
    opacity: 1;
    transform: translateX(0);
  }
}

/* Read status color transition (gray to blue) */
.status-icon.read-transition {
  animation: colorToBlue 0.3s ease-out forwards;
}

@keyframes colorToBlue {
  from {
    color: #9ca3af;
  }

  to {
    color: #3b82f6;
  }
}

/* Failed message subtle shake animation */
.message-failed {
  animation: subtleShake 0.4s ease-out;
}

@keyframes subtleShake {

  0%,
  100% {
    transform: translateX(0);
  }

  20% {
    transform: translateX(-4px);
  }

  40% {
    transform: translateX(4px);
  }

  60% {
    transform: translateX(-2px);
  }

  80% {
    transform: translateX(2px);
  }
}

/* Touch-friendly retry button */
.retry-btn {
  padding: 0.5rem 0.75rem;
  min-height: 44px;
  border-radius: 9999px;
  background: rgba(239, 68, 68, 0.1);
  touch-action: manipulation;
  transition: all 0.15s ease-out;
}

.retry-btn:hover {
  background: rgba(239, 68, 68, 0.2);
}

.retry-btn:active {
  background: rgba(239, 68, 68, 0.3);
  transform: scale(0.98);
}

/* Mobile-first message bubble styles */
.message-bubble {
  max-width: 85%;
  padding: 0.625rem 0.875rem;
  font-size: 0.9375rem;
  line-height: 1.4;
}

/* Tablet breakpoint */
@media (min-width: 640px) {
  .message-bubble {
    max-width: 70%;
    padding: 0.625rem 1rem;
  }

  .retry-btn {
    min-height: 36px;
  }
}

/* Desktop breakpoint */
@media (min-width: 1024px) {
  .message-bubble {
    max-width: 60%;
  }

  .retry-btn {
    min-height: 32px;
  }
}

/* Touch action for better mobile interaction */
.touch-action-manipulation {
  touch-action: manipulation;
}

/* Prevent double-tap zoom on interactive elements */
[data-action*="click"] {
  touch-action: manipulation;
}

/* Message input area - fixed at bottom, safe area aware */
.message-input-footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: white;
  border-top: 1px solid #e5e7eb;
  padding-bottom: max(0.5rem, env(safe-area-inset-bottom));
  z-index: 20;
}

@media (min-width: 1024px) {
  .message-input-footer {
    position: relative;
    padding-bottom: 0;
  }
}

/* Send button animations */
.send-button {
  transition: all 0.15s ease-out;
}

.send-button:active {
  transform: scale(0.95);
}

.send-button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* CSS Variables for theming */
:root {
  /* Message Colors - WhatsApp inspired but refined */
  --msg-sent-bg: linear-gradient(135deg, #7c3aed 0%, #6d28d9 100%);
  --msg-sent-text: #ffffff;
  --msg-received-bg: #ffffff;
  --msg-received-text: #1f2937;

  /* Status Colors */
  --status-pending: #9ca3af;
  --status-sent: #6b7280;
  --status-delivered: #6b7280;
  --status-read: #3b82f6;
  --status-failed: #ef4444;

  /* Shadows - Subtle depth */
  --shadow-message: 0 1px 2px rgba(0, 0, 0, 0.05), 0 1px 3px rgba(0, 0, 0, 0.1);
  --shadow-message-hover: 0 2px 4px rgba(0, 0, 0, 0.1);

  /* Timing - Snappy but smooth */
  --timing-fast: 150ms;
  --timing-normal: 250ms;
  --timing-slow: 400ms;
  --easing-smooth: cubic-bezier(0.4, 0, 0.2, 1);
}

/* Dark Mode Support (if needed in future) */
@media (prefers-color-scheme: dark) {
  /* Dark mode styles can be added here */
  /* Currently using light mode only as per design system */
}

/* =====================================================
   Extended Message Types Styles
   WhatsApp Interactive, Location, Contacts, Reactions
   ===================================================== */

/* Interactive Message Responses */
.interactive-response {
  display: inline-flex;
  align-items: flex-start;
  gap: 0.5rem;
  padding: 0.625rem;
  border-radius: 0.75rem;
  border-width: 1px;
  max-width: 100%;
}

.interactive-response p {
  margin: 0;
}

/* Interactive Button Pills (for sent messages with buttons) */
.interactive-button-pill {
  display: inline-flex;
  align-items: center;
  padding: 0.375rem 0.75rem;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 500;
  background: rgba(255, 255, 255, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.3);
  color: white;
  transition: all 0.15s ease;
}

.interactive-button-pill:hover {
  background: rgba(255, 255, 255, 0.3);
}

/* Reply Context Quote Bar */
.reply-context-quote {
  margin-bottom: 0.5rem;
}

.reply-context-quote .loading-placeholder {
  display: flex;
  align-items: center;
}

/* Reaction Badges */
.reaction-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 0.125rem;
  margin-top: 0.375rem;
}

.reaction-badges span {
  animation: reactionPop 0.25s ease-out;
}

@keyframes reactionPop {
  0% {
    transform: scale(0);
    opacity: 0;
  }

  50% {
    transform: scale(1.15);
  }

  100% {
    transform: scale(1);
    opacity: 1;
  }
}

/* Standalone Reaction Message */
.reaction-message {
  text-align: center;
  padding: 0.25rem 0;
}

@keyframes bounceOnce {

  0%,
  100% {
    transform: scale(1);
  }

  50% {
    transform: scale(1.2);
  }
}

.animate-bounce-once {
  animation: bounceOnce 0.3s ease-out;
}

/* Location Message */
.location-message {
  max-width: 280px;
}

.location-message img {
  width: 100%;
  height: auto;
}

/* Contact Card */
.contact-card {
  background: rgba(0, 0, 0, 0.02);
  border-radius: 0.75rem;
  padding: 0.75rem;
}

/* Line clamp utilities */
.line-clamp-2 {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Message Action Buttons (Reply, React) */
/* Note: display is controlled by Tailwind classes (hidden sm:flex) in the template */
.message-actions {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  gap: 0.25rem;
  opacity: 0;
  transition: opacity 0.15s ease;
  pointer-events: none;
}

.group:hover .message-actions,
.group:focus-within .message-actions {
  opacity: 1;
  pointer-events: auto;
}

.message-action-btn {
  padding: 0.5rem;
  background: white;
  border-radius: 9999px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1), 0 1px 2px rgba(0, 0, 0, 0.06);
  color: #6b7280;
  transition: all 0.15s ease;
  cursor: pointer;
  border: none;
}

.message-action-btn:hover {
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1), 0 2px 4px rgba(0, 0, 0, 0.06);
  color: #7c3aed;
}

.message-action-btn:active {
  transform: scale(0.95);
}

/* Touch-friendly mobile actions are now controlled via JS (tap to toggle)
   The .mobile-message-actions class handles mobile display */
/* Desktop message-actions hover behavior only */

/* Swipe to Reply Indicator */
.swipe-reply-indicator {
  position: absolute;
  left: -2.5rem;
  top: 50%;
  transform: translateY(-50%);
  opacity: 0;
  transition: opacity 0.15s ease;
}

.swipe-active .swipe-reply-indicator {
  opacity: 1;
}

/* Reply Context Bar (in message form) */
.reply-context-bar {
  /* Note: display is controlled by hidden class, don't set display here */
  border-radius: 0.5rem;
  overflow: hidden;
  background: #f5f3ff;
  border: 1px solid #e5e1ff;
  margin-bottom: 0.5rem;
}

.reply-context-bar .quote-bar {
  width: 0.25rem;
  background: #7c3aed;
  flex-shrink: 0;
}

.reply-context-bar .quote-content {
  flex: 1;
  padding: 0.5rem 0.75rem;
  min-width: 0;
}

.reply-context-bar .close-btn {
  padding: 0.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #9ca3af;
  transition: color 0.15s ease;
}

.reply-context-bar .close-btn:hover {
  color: #6b7280;
}

/* Emoji Picker Container */
.emoji-picker-container {
  position: fixed;
  z-index: 100;
  background: white;
  border-radius: 1rem;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
  overflow: hidden;
}

@media (max-width: 640px) {
  .emoji-picker-container {
    bottom: 0;
    left: 0;
    right: 0;
    top: auto;
    border-radius: 1rem 1rem 0 0;
    max-height: 50vh;
  }
}

/* Quick Reactions Bar */
.quick-reactions {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
  padding: 0.5rem;
  background: white;
  border-bottom: 1px solid #f3f4f6;
}

.quick-reaction {
  width: 2.5rem;
  height: 2.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  border-radius: 9999px;
  transition: all 0.15s ease;
  cursor: pointer;
  border: none;
  background: transparent;
}

.quick-reaction:hover {
  background: #f3f4f6;
  transform: scale(1.15);
}

.quick-reaction:active {
  transform: scale(0.95);
}

/* Emoji Grid */
.emoji-scroll {
  scrollbar-width: thin;
  scrollbar-color: #e5e7eb transparent;
}

.emoji-scroll::-webkit-scrollbar {
  width: 6px;
}

.emoji-scroll::-webkit-scrollbar-track {
  background: transparent;
}

.emoji-scroll::-webkit-scrollbar-thumb {
  background-color: #e5e7eb;
  border-radius: 3px;
}

.emoji-scroll::-webkit-scrollbar-thumb:hover {
  background-color: #d1d5db;
}

.emoji-btn {
  transition: all 0.1s ease;
  cursor: pointer;
  border: none;
  background: transparent;
}

.emoji-btn:hover {
  background: #f3f4f6;
  transform: scale(1.1);
}

.emoji-btn:active {
  transform: scale(0.9);
}

/* Emoji Category Headers */
.emoji-category h4 {
  position: sticky;
  top: 0;
  background: white;
  z-index: 1;
  padding-top: 0.5rem;
  padding-bottom: 0.25rem;
}

/* Fade in animation */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.animate-fadeIn {
  animation: fadeIn 0.15s ease-out;
}

/* Mobile bottom sheet backdrop */
@media (max-width: 640px) {
  .emoji-picker-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.3);
    z-index: 99;
  }

  .emoji-picker-container {
    z-index: 100;
  }
}

/* Optimistic reaction badge */
.optimistic-reaction {
  animation: reactionPop 0.2s ease-out;
}

/* Long press indicator */
.long-press-indicator {
  position: absolute;
  bottom: -4px;
  left: 50%;
  transform: translateX(-50%);
  width: 0;
  height: 2px;
  background: linear-gradient(90deg, #7c3aed, #a78bfa);
  border-radius: 1px;
  transition: width 0.5s linear;
}

.long-press-active .long-press-indicator {
  width: 80%;
}

/* Reaction tooltip */
.reaction-tooltip {
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%) translateY(-4px);
  background: #1f2937;
  color: white;
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 11px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease;
}

.reaction-badge:hover .reaction-tooltip {
  opacity: 1;
}

.reaction-tooltip::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 4px solid transparent;
  border-top-color: #1f2937;
}

/* Enhanced reaction badges */
.reaction-badge {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 3px 8px;
  background: white;
  border: 1px solid #e5e7eb;
  border-radius: 9999px;
  font-size: 0.75rem;
  cursor: pointer;
  transition: all 0.15s ease;
}

.reaction-badge:hover {
  border-color: #a78bfa;
  background: #f5f3ff;
  box-shadow: 0 2px 4px rgba(139, 92, 246, 0.1);
}

.reaction-badge.user-reacted {
  border-color: #7c3aed;
  background: #f5f3ff;
}

/* =====================================================
   Conversation Window Status Indicator
   ===================================================== */

.conversation-window-indicator {
  flex-shrink: 0;
}

/* Closing soon warning - subtle pulse glow */
@keyframes urgentPulse {

  0%,
  100% {
    box-shadow: 0 0 0 0 rgba(245, 158, 11, 0);
  }

  50% {
    box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.15);
  }
}

/* Closed window alert bar (above message input) */
.closed-window-alert {
  transition: all 0.2s ease-out;
}

/* =====================================================
   Interactive Message Composers
   ===================================================== */

.interactive-composer {
  position: fixed;
  inset: 0;
  z-index: 100;
}

/* Modal slide-up animation */
@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(100%);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes slideUpDesktop {
  from {
    opacity: 0;
    transform: translate(-50%, -48%);
  }

  to {
    opacity: 1;
    transform: translate(-50%, -50%);
  }
}

.interactive-composer>div:last-child {
  animation: slideUp 0.25s ease-out;
}

@media (min-width: 640px) {
  .interactive-composer>div:last-child {
    animation: slideUpDesktop 0.25s ease-out;
  }
}

/* Button items */
.button-item {
  transition: all 0.15s ease;
}

.button-item:hover {
  background: #f5f3ff;
}

/* Preview styling */
.interactive-composer [data-interactive-buttons-composer-target="previewButtons"] button,
.interactive-composer [data-interactive-list-composer-target="previewButtons"] button {
  pointer-events: none;
}

/* Character counter warning */
.char-count-warning {
  color: #ef4444;
}

/* Dropdown menu for interactive options */
.message-form-dropdown {
  transform-origin: bottom left;
  animation: dropdownOpen 0.15s ease-out;
}

@keyframes dropdownOpen {
  from {
    opacity: 0;
    transform: scale(0.95) translateY(8px);
  }

  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

/* List Composer Sections */
.section-item {
  transition: all 0.15s ease;
}

.section-item:hover {
  border-color: #c4b5fd;
}

.row-item {
  transition: all 0.15s ease;
}

.row-item:hover {
  background: #f5f3ff;
}

/* Section remove animation */
.section-item.removing {
  animation: sectionRemove 0.2s ease-out forwards;
}

@keyframes sectionRemove {
  to {
    opacity: 0;
    transform: translateX(-20px);
    height: 0;
    margin: 0;
    padding: 0;
  }
}

/* Row remove animation */
.row-item.removing {
  animation: rowRemove 0.15s ease-out forwards;
}

@keyframes rowRemove {
  to {
    opacity: 0;
    transform: scale(0.95);
    height: 0;
    margin: 0;
    padding: 0;
  }
}

/* Media Header Upload */
.media-upload-zone {
  transition: all 0.2s ease;
}

.media-upload-zone.dragover {
  border-color: #8b5cf6;
  background: rgba(139, 92, 246, 0.1);
}

.header-type-btn {
  transition: all 0.15s ease;
}

.header-type-btn:hover:not(.bg-violet-100) {
  transform: translateY(-1px);
}

/* Upload progress animation */
@keyframes progressPulse {

  0%,
  100% {
    opacity: 1;
  }

  50% {
    opacity: 0.7;
  }
}

.upload-progress-bar {
  animation: progressPulse 1.5s ease-in-out infinite;
}