/* Messaging Split View Layout */
.messaging-container {
  height: calc(100vh - 80px); /* Adjust based on your navbar height */
  overflow: hidden;
}

.messaging-split-view {
  display: flex;
  height: 100%;
  background: #f8f9fa;
}

/* Left Sidebar - Conversation List */
.conversation-sidebar {
  width: 380px;
  border-right: 1px solid #dee2e6;
  background: white;
  display: flex;
  flex-direction: column;
  height: 100%;
}

.conversation-list-header {
  flex-shrink: 0;
}

.conversation-list-items {
  overflow-y: auto;
  flex: 1;
}

.conversation-list-item {
  transition: background-color 0.2s ease;
  cursor: pointer;
  color: inherit;
}

.conversation-list-item:hover {
  background-color: #f8f9fa;
}

.conversation-list-item.active {
  background-color: #e7f3ff;
  border-left: 3px solid #0d6efd;
}

.conversation-list-item.unread {
  background-color: #f0f8ff;
}

.conversation-list-item.unread .conversation-title {
  font-weight: 600;
}

.conversation-list-item.unread .conversation-preview {
  font-weight: 500;
  color: #212529 !important;
}

/* Avatar Circle */
.avatar-circle {
  width: 45px;
  height: 45px;
  border-radius: 50%;
  font-size: 18px;
  font-weight: 600;
  flex-shrink: 0;
}

.conversation-list-item .avatar-circle {
  width: 50px;
  height: 50px;
  font-size: 20px;
}

/* Right Panel - Chat */
.chat-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: white;
  height: 100%;
}

.chat-header {
  flex-shrink: 0;
  box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  background: #f8f9fa;
}

.chat-input {
  flex-shrink: 0;
  box-shadow: 0 -1px 2px rgba(0,0,0,0.05);
}

/* Message Bubbles */
.message-item {
  animation: fadeIn 0.3s ease;
}

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

.message-item .bg-primary {
  background: linear-gradient(135deg, #0d6efd 0%, #0a58ca 100%) !important;
  border-radius: 18px 18px 4px 18px;
  box-shadow: 0 2px 8px rgba(13, 110, 253, 0.2);
}

.message-item .bg-light {
  background-color: white !important;
  border: 1px solid #e9ecef;
  border-radius: 18px 18px 18px 4px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.05);
}

.message-item .bg-primary p {
  color: white;
  margin: 0;
}

.message-item .bg-light p {
  color: #212529;
  margin: 0;
}

/* Scrollbar Styling */
.conversation-list-items::-webkit-scrollbar,
.chat-messages::-webkit-scrollbar {
  width: 6px;
}

.conversation-list-items::-webkit-scrollbar-track,
.chat-messages::-webkit-scrollbar-track {
  background: #f1f1f1;
}

.conversation-list-items::-webkit-scrollbar-thumb,
.chat-messages::-webkit-scrollbar-thumb {
  background: #888;
  border-radius: 3px;
}

.conversation-list-items::-webkit-scrollbar-thumb:hover,
.chat-messages::-webkit-scrollbar-thumb:hover {
  background: #555;
}

/* Responsive Design */
@media (max-width: 768px) {
  .messaging-container {
    height: calc(100vh - 60px); /* Adjust for mobile navbar */
  }
  
  .messaging-split-view {
    flex-direction: column;
  }
  
  .conversation-sidebar {
    width: 100%;
    height: 100%;
    display: none;
  }
  
  .conversation-sidebar.show {
    display: flex;
  }
  
  .chat-panel {
    width: 100%;
  }
  
  /* Show sidebar on index page, hide on show page */
  body[data-controller="conversations"][data-action="index"] .conversation-sidebar {
    display: flex;
  }
  
  body[data-controller="conversations"][data-action="index"] .chat-panel {
    display: none;
  }
  
  body[data-controller="conversations"][data-action="show"] .conversation-sidebar {
    display: none;
  }
  
  body[data-controller="conversations"][data-action="show"] .chat-panel {
    display: flex;
  }
  
  /* Mobile-specific improvements */
  .conversation-list-header {
    padding: 1rem;
    position: sticky;
    top: 0;
    z-index: 10;
    background: white;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
  }
  
  .conversation-list-header h5 {
    font-size: 1.25rem;
    font-weight: 600;
  }
  
  .conversation-list-item {
    padding: 1rem;
    border-bottom: 1px solid #f0f0f0;
    min-height: 80px;
    display: flex;
    align-items: center;
  }
  
  .conversation-list-item .avatar-circle {
    width: 56px;
    height: 56px;
    font-size: 22px;
    flex-shrink: 0;
  }
  
  .conversation-list-item .conversation-title {
    font-size: 1rem;
    font-weight: 600;
  }
  
  .conversation-list-item .conversation-preview {
    font-size: 0.9rem;
    line-height: 1.4;
  }
  
  .conversation-list-item .badge {
    font-size: 0.75rem;
    padding: 0.25rem 0.5rem;
  }
  
  /* Mobile chat header */
  .chat-header {
    padding: 0.75rem 1rem;
    position: sticky;
    top: 0;
    z-index: 10;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
  }
  
  .chat-header .avatar-circle {
    width: 42px;
    height: 42px;
    font-size: 18px;
  }
  
  .chat-header h5 {
    font-size: 1rem;
    font-weight: 600;
  }
  
  .chat-header small {
    font-size: 0.8rem;
  }
  
  /* Mobile messages */
  .chat-messages {
    padding: 1rem;
    background: #f5f5f5;
  }
  
  .message-item {
    margin-bottom: 1rem;
  }
  
  .message-item > div {
    max-width: 85%;
  }
  
  .message-item .bg-primary,
  .message-item .bg-light {
    padding: 0.75rem 1rem;
    font-size: 0.95rem;
    line-height: 1.5;
  }
  
  .message-item small {
    font-size: 0.75rem;
    margin-top: 0.25rem;
  }
  
  /* Mobile input */
  .chat-input {
    padding: 0.75rem 1rem;
    background: white;
    box-shadow: 0 -2px 8px rgba(0,0,0,0.08);
  }
  
  .chat-input textarea {
    font-size: 1rem;
    padding: 0.75rem;
    border-radius: 20px;
    border: 1px solid #e0e0e0;
    min-height: 44px;
  }
  
  .chat-input .btn-primary {
    min-width: 44px;
    min-height: 44px;
    border-radius: 50%;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  
  .chat-input .btn-primary i {
    font-size: 1.1rem;
  }
  
  .chat-input small {
    font-size: 0.75rem;
    margin-top: 0.5rem;
  }
  
  /* Mobile back button */
  .chat-header .btn-link {
    padding: 0.5rem;
    margin-left: -0.5rem;
    font-size: 1.25rem;
    color: #333;
  }
  
  /* Mobile dropdown menu */
  .chat-header .dropdown-menu {
    font-size: 0.95rem;
  }
  
  /* Improve touch targets */
  .conversation-list-item,
  .chat-input button,
  .chat-header button {
    -webkit-tap-highlight-color: rgba(0,0,0,0.1);
  }
  
  /* Active state for mobile */
  .conversation-list-item:active {
    background-color: #e8e8e8;
  }
  
  /* Empty state on mobile */
  .chat-panel .text-center i {
    font-size: 60px;
  }
  
  .chat-panel .text-center h3 {
    font-size: 1.25rem;
  }
  
  .chat-panel .text-center p {
    font-size: 0.9rem;
  }
  
  /* Prevent text selection on tap */
  .conversation-list-item * {
    user-select: none;
    -webkit-user-select: none;
  }
  
  /* Smooth scrolling */
  .conversation-list-items,
  .chat-messages {
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
  }
  
  /* Hide scrollbar on mobile for cleaner look */
  .conversation-list-items::-webkit-scrollbar,
  .chat-messages::-webkit-scrollbar {
    display: none;
  }
  
  /* Better visual hierarchy */
  .conversation-list-item.unread {
    background: linear-gradient(to right, #f0f8ff 0%, white 100%);
    border-left: 3px solid #0d6efd;
  }
  
  /* Improve badge visibility */
  .conversation-list-item .badge.bg-primary {
    background: linear-gradient(135deg, #0d6efd 0%, #0a58ca 100%) !important;
    box-shadow: 0 2px 4px rgba(13, 110, 253, 0.3);
  }
  
  /* Better spacing for message timestamps */
  .message-item small {
    display: block;
    opacity: 0.7;
  }
  
  /* Improve input focus state */
  .chat-input textarea:focus {
    border-color: #0d6efd;
    box-shadow: 0 0 0 3px rgba(13, 110, 253, 0.15);
    outline: none;
  }
  
  /* Add subtle animation to send button */
  .chat-input .btn-primary:active {
    transform: scale(0.95);
    transition: transform 0.1s ease;
  }
  
  /* Improve category badge on mobile */
  .badge.bg-secondary {
    background: linear-gradient(135deg, #6c757d 0%, #5a6268 100%) !important;
  }
  
  /* Better divider between conversations */
  .conversation-list-item:not(:last-child) {
    border-bottom: 1px solid #f0f0f0;
  }
  
  /* Add subtle hover effect even on mobile (for hybrid devices) */
  @media (hover: hover) {
    .conversation-list-item:hover {
      background-color: #f8f9fa;
    }
  }
}

@media (min-width: 769px) and (max-width: 1024px) {
  .conversation-sidebar {
    width: 320px;
  }
}

@media (min-width: 1400px) {
  .conversation-sidebar {
    width: 420px;
  }
}

/* Utilities */
.min-w-0 {
  min-width: 0;
}

.text-truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Safe area insets for notched devices */
@supports (padding: max(0px)) {
  .messaging-container {
    padding-left: max(0px, env(safe-area-inset-left));
    padding-right: max(0px, env(safe-area-inset-right));
  }
  
  .chat-input {
    padding-bottom: max(0.75rem, env(safe-area-inset-bottom));
  }
}

/* Badge Styling */
.conversation-list-item .badge {
  font-size: 0.7rem;
}

/* Empty State */
.chat-messages .text-center {
  margin-top: 100px;
}

/* Dropdown Menu */
.chat-header .dropdown-menu {
  min-width: 200px;
}

/* Focus States */
.chat-input textarea:focus {
  border-color: #0d6efd;
  box-shadow: 0 0 0 0.25rem rgba(13, 110, 253, 0.25);
}

/* Loading State */
.conversation-list-item.loading {
  opacity: 0.6;
  pointer-events: none;
}

/* Hover Effects */
.conversation-list-item:not(.active):hover {
  background-color: #f1f3f5;
}

/* Unread Badge Animation */
.badge.bg-primary {
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.7;
  }
}

/* Message Input Textarea */
.chat-input textarea {
  resize: none;
  border-radius: 8px;
}

/* Send Button */
.chat-input .btn-primary {
  border-radius: 8px;
  padding: 0.5rem 1rem;
  height: fit-content;
}

/* Conversation Preview Text */
.conversation-preview {
  line-height: 1.4;
}

/* Time Ago Text */
.conversation-list-item small {
  font-size: 0.75rem;
}

/* Category Badge */
.badge-sm {
  font-size: 0.7rem;
  padding: 0.2rem 0.5rem;
}
