/* Collapsible Sidebar Styles */
.sidebar-col {
  transition: all 0.3s ease-in-out;
  position: relative;
  flex-shrink: 0;
}

.user-sidebar {
  position: relative;
  transition: all 0.3s ease-in-out;
  overflow: visible;
  min-height: 400px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.1);
  border: 1px solid #e9ecef;
}

/* Toggle Button */
.sidebar-toggle {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 1000;
}

#sidebarToggle {
  width: 35px;
  height: 35px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: all 0.3s ease;
}

#sidebarToggle:hover {
  background-color: #007bff;
  color: white;
  border-color: #007bff;
}

#sidebarToggle i {
  transition: transform 0.3s ease;
}

/* Sidebar States */
.user-sidebar.collapsed {
  width: 80px !important;
}

.sidebar-col.collapsed {
  flex: 0 0 80px !important;
  max-width: 80px !important;
  min-width: 80px !important;
  padding: 0px !important;
}

/* Menu Links */
.user-sidebar .links li a {
  display: flex;
  align-items: center;
  padding: 12px 20px;
  transition: all 0.3s ease;
  position: relative;
  white-space: nowrap;
}

.user-sidebar .links li a i {
  min-width: 20px;
  margin-right: 12px;
  text-align: center;
  font-size: 16px;
  transition: all 0.3s ease;
}

.user-sidebar .links li a .menu-text {
  opacity: 1;
  transition: opacity 0.3s ease;
  flex: 1;
}

/* Collapsed State */
.user-sidebar.collapsed .links li a {
  padding: 12px 15px;
  justify-content: center;
}

.user-sidebar.collapsed .links li a i {
  margin-right: 0;
  font-size: 18px;
}

.user-sidebar.collapsed .links li a .menu-text {
  opacity: 0;
  width: 0;
  overflow: hidden;
}

.user-sidebar.collapsed #sidebarToggle i {
  transform: rotate(180deg);
}

/* Tooltip for collapsed state */
.user-sidebar.collapsed .links li a {
  position: relative;
}

.user-sidebar.collapsed .links li a:hover::after {
  content: attr(title);
  position: absolute;
  left: 100%;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(0, 0, 0, 0.8);
  color: white;
  padding: 8px 12px;
  border-radius: 4px;
  white-space: nowrap;
  z-index: 1000;
  margin-left: 10px;
  font-size: 14px;
  opacity: 0;
  animation: fadeInTooltip 0.3s ease forwards;
}

.user-sidebar.collapsed .links li a:hover::before {
  content: '';
  position: absolute;
  left: 100%;
  top: 50%;
  transform: translateY(-50%);
  border: 6px solid transparent;
  border-right-color: rgba(0, 0, 0, 0.8);
  z-index: 1000;
  margin-left: 4px;
  opacity: 0;
  animation: fadeInTooltip 0.3s ease forwards;
}

@keyframes fadeInTooltip {
  to {
    opacity: 1;
  }
}

/* Hover Expansion (PC only) */
@media (min-width: 992px) {
  .user-sidebar.collapsed:hover {
    width: 250px !important;
    z-index: 100;
    box-shadow: 0 4px 20px rgba(0,0,0,0.15);
  }
  
  .sidebar-col.collapsed:hover {
    flex: 0 0 250px !important;
    max-width: 250px !important;
    z-index: 100;
  }
  
  .user-sidebar.collapsed:hover .links li a .menu-text {
    opacity: 1;
    width: auto;
    transition-delay: 0.1s;
  }
  
  .user-sidebar.collapsed:hover .links li a {
    padding: 12px 20px;
    justify-content: flex-start;
  }
  
  .user-sidebar.collapsed:hover .links li a i {
    margin-right: 12px;
  }
  
  /* Hide tooltips on hover expansion */
  .user-sidebar.collapsed:hover .links li a:hover::after,
  .user-sidebar.collapsed:hover .links li a:hover::before {
    display: none;
  }
  
  /* Smooth hover transition */
  .sidebar-col.collapsed {
    position: relative;
    overflow: visible;
  }
  
  .user-sidebar.collapsed:hover {
    position: relative;
    left: 0;
    top: 0;
    width: 250px !important;
    background: white;
    border: 1px solid #e9ecef;
    border-radius: 8px;
    z-index: 99;
  }
}

/* Active link styling */
.user-sidebar .links li a.active {
  background: linear-gradient(135deg, #007bff, #0056b3);
  color: white;
  border-radius: 8px;
  margin: 2px 8px;
  box-shadow: 0 2px 8px rgba(0, 123, 255, 0.3);
}

.user-sidebar .links li a:hover:not(.active) {
  background-color: #f8f9fa;
  border-radius: 8px;
  margin: 2px 8px;
  transform: translateX(2px);
}

.user-sidebar .links li a {
  border-radius: 8px;
  margin: 1px 8px;
}

/* Improved toggle button styling */
#sidebarToggle {
  background: linear-gradient(135deg, #f8f9fa, #e9ecef);
  border: 1px solid #dee2e6;
  color: #495057;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

#sidebarToggle:hover {
  background: linear-gradient(135deg, #007bff, #0056b3);
  color: white;
  border-color: #0056b3;
  box-shadow: 0 4px 8px rgba(0, 123, 255, 0.3);
  transform: scale(1.05);
}

/* Badge styling for collapsed state */
.user-sidebar.collapsed .badge {
  display: none;
}

.user-sidebar.collapsed:hover .badge {
  display: inline-block;
}

/* Mobile - Always show full sidebar */
@media (max-width: 991.98px) {
  .sidebar-toggle {
    display: none !important;
  }
  
  .user-sidebar.collapsed {
    width: 100% !important;
  }
  
  .sidebar-col.collapsed {
    flex: 0 0 100%;
    max-width: 100%;
  }
  
  .user-sidebar.collapsed .links li a .menu-text {
    opacity: 1 !important;
    width: auto !important;
  }
  
  .user-sidebar.collapsed .links li a {
    padding: 12px 20px !important;
    justify-content: flex-start !important;
  }
  
  .user-sidebar.collapsed .links li a i {
    margin-right: 12px !important;
  }
  
  .user-dashboard .row {
    flex-wrap: wrap !important;
  }
}

/* Additional improvements */
.user-sidebar .links {
  padding-top: 45px; /* Account for toggle button */
}

.user-sidebar .links li {
  margin-bottom: 2px;
}

/* Smooth icon animations */
.user-sidebar .links li a i {
  transition: all 0.3s ease;
}

.user-sidebar.collapsed .links li a:hover i {
  transform: scale(1.1);
  color: #007bff;
}

/* Loading state */
.sidebar-loading {
  opacity: 0.7;
  pointer-events: none;
}

/* Focus states for accessibility */
.user-sidebar .links li a:focus {
  outline: 2px solid #007bff;
  outline-offset: 2px;
}

#sidebarToggle:focus {
  outline: 2px solid #007bff;
  outline-offset: 2px;
}

/* Ensure sidebar doesn't interfere with header */
.user-sidebar {
  z-index: 10;
  position: relative;
}

.user-sidebar.collapsed {
  z-index: 10;
}

/* Prevent sidebar from covering header */
@media (min-width: 992px) {
  .user-dashboard {
    position: relative;
    z-index: 1;
  }
  
  .user-sidebar.collapsed:hover {
    z-index: 99 !important; /* Lower than typical header z-index */
  }
  
  .sidebar-col.collapsed:hover {
    z-index: 99 !important;
  }
}

/* Container and Row Adjustments */
.user-dashboard .row {
  display: flex !important;
  flex-wrap: nowrap !important;
  margin-left: -15px;
  margin-right: -15px;
  align-items: flex-start !important;
}

/* Ensure proper flex behavior */
.user-dashboard .row > * {
  flex-shrink: 0;
}

.user-dashboard .row > .w-100 {
  flex-shrink: 1 !important;
  flex-grow: 1 !important;
}

/* Main Content Area */
.user-dashboard .row > .col-lg-9 {
  transition: all 0.3s ease-in-out;
  flex: 1 1 auto !important;
  max-width: none !important;
  padding-left: 15px;
  padding-right: 15px;
}

/* Sidebar Column Default */
@media (min-width: 992px) {
  .sidebar-col {
    flex: 0 0 25% !important;
    max-width: 25% !important;
    padding-left: 15px;
    padding-right: 15px;
  }
  
  .sidebar-col.collapsed {
    flex: 0 0 80px !important;
    max-width: 80px !important;
    min-width: 80px !important;
  }
}

/* Message Wrapper Responsive Layout */
.message-wrapper {
  width: 100% !important;
  transition: all 0.3s ease-in-out;
  flex: 1 1 auto !important;
}

/* Main Content Area - Full Width */
.user-dashboard .row > .w-100 {
  flex: 1 1 auto !important;
  max-width: none !important;
  min-width: 0 !important;
  padding-left: 15px;
  padding-right: 15px;
  transition: all 0.3s ease-in-out;
}

/* Responsive adjustments for different screen sizes */
@media (min-width: 992px) {
  .user-dashboard .row > .w-100 {
    padding-left: 20px;
    padding-right: 20px;
  }
}

@media (max-width: 991px) {
  .user-dashboard .row > .w-100 {
    padding-left: 15px;
    padding-right: 15px;
  }
  
  .message-wrapper {
    margin-left: 0 !important;
    margin-right: 0 !important;
  }
}

/* Ensure smooth transitions when sidebar toggles */
.user-dashboard .row {
  transition: all 0.3s ease-in-out;
}

/* Optimize chat layout for full width */
.chat-wrapper-area {
  width: 100% !important;
  max-width: none !important;
}

.chat-wrapper {
  width: 100% !important;
}

/* Ensure form elements use full available width */
#msg-form {
  width: 100% !important;
}

.chat-input-group {
  width: 100% !important;
  max-width: none !important;
}

/* Additional responsive improvements */
@media (max-width: 767px) {
  .user-dashboard .container {
    padding-left: 10px !important;
    padding-right: 10px !important;
    margin-left: 10px !important;
    margin-right: 10px !important;
  }
  
  .user-dashboard .row > .w-100 {
    padding-left: 10px !important;
    padding-right: 10px !important;
  }
  
  .message-wrapper {
    margin-bottom: 20px !important;
  }
}

/* Ensure proper spacing and alignment */
.chat-header-grid {
  width: 100% !important;
  max-width: none !important;
}

.chat-card {
  width: 100% !important;
}

/* Optimize for very wide screens */
@media (min-width: 1400px) {
  .user-dashboard .row > .w-100 {
    padding-left: 30px !important;
    padding-right: 30px !important;
  }
}

/* Override conflicting styles from innerpages.css */
.user-dashboard .message-wrapper {
  padding: 20px 30px !important;
  border-radius: 5px !important;
  border: 1px solid var(--border-color) !important;
  width: 100% !important;
  max-width: none !important;
  box-sizing: border-box !important;
}

.user-dashboard .chat-wrapper {
  width: 100% !important;
  max-width: none !important;
  box-sizing: border-box !important;
}

.user-dashboard .chat-wrapper-area {
  width: 100% !important;
  max-width: none !important;
  box-sizing: border-box !important;
}

/* Ensure proper flex behavior for the entire layout */
.user-dashboard {
  overflow-x: hidden !important;
}

.user-dashboard .container {
  max-width: none !important;
  width: 100% !important;
}

/* Enhanced responsive behavior when sidebar is collapsed */
.user-dashboard.sidebar-collapsed .message-wrapper {
  margin-left: 0 !important;
  margin-right: 0 !important;
  width: 100% !important;
}

.user-dashboard.sidebar-collapsed .row > .w-100 {
  padding-left: 25px !important;
  padding-right: 25px !important;
}

/* Smooth transitions for all layout changes */
.user-dashboard * {
  transition: all 0.3s ease-in-out;
}

/* Ensure chat elements maintain proper spacing */
.chat-bottom {
  width: 100% !important;
  max-width: none !important;
}

.chat-input-group textarea {
  width: 100% !important;
  max-width: none !important;
}

/* Optimize for different sidebar states */
@media (min-width: 992px) {
  .user-dashboard:not(.sidebar-collapsed) .row > .w-100 {
    padding-left: 20px !important;
    padding-right: 20px !important;
  }
  
  .user-dashboard.sidebar-collapsed .row > .w-100 {
    padding-left: 30px !important;
    padding-right: 30px !important;
  }
}

/* Mobile Optimizations for Profile Pictures and Images */
@media (max-width: 767px) {
  /* Make profile pictures smaller on mobile */
  .chat-card .thumb {
    flex: 0 0 35px !important;
    max-width: 35px !important;
    height: 35px !important;
  }
  
  .chat-card .thumb img {
    width: 35px !important;
    height: 35px !important;
  }
  
  /* Make sent images smaller on mobile */
  .chat-image {
    max-width: 180px !important;
    height: auto !important;
  }
  
  /* Adjust chat header profile pictures */
  .chat-header-grid img.rounded-circle {
    width: 28px !important;
    height: 28px !important;
  }
  
  /* Reduce spacing on mobile */
  .chat-card {
    margin-bottom: 12px !important;
  }
  
  .chat-card .thumb {
    margin-inline-start: 8px !important;
  }
  
  .chat-card.reply-chat .thumb {
    margin-right: 12px !important;
    margin-left: 0px !important;
  }
  
  /* Optimize chat text content for mobile */
  .chat-card .chat-text .content {
    padding: 8px 12px !important;
    font-size: 13px !important;
  }
  
  .chat-card .chat-text .content p {
    font-size: 13px !important;
    line-height: 1.4 !important;
  }
}

/* Extra small mobile devices */
@media (max-width: 480px) {
  /* Even smaller profile pictures for very small screens */
  .chat-card .thumb {
    flex: 0 0 30px !important;
    max-width: 30px !important;
    height: 30px !important;
  }
  
  .chat-card .thumb img {
    width: 30px !important;
    height: 30px !important;
  }
  
  /* Smaller sent images for very small screens */
  .chat-image {
    max-width: 150px !important;
  }
  
  /* Smaller header profile pictures */
  .chat-header-grid img.rounded-circle {
    width: 24px !important;
    height: 24px !important;
  }
  
  /* Reduce margins and padding further */
  .chat-card .thumb {
    margin-inline-start: 6px !important;
  }
  
  .chat-card.reply-chat .thumb {
    margin-right: 8px !important;
  }
  
  .chat-card .chat-text .content {
    padding: 6px 10px !important;
    font-size: 12px !important;
  }
  
  .chat-card .chat-text .content p {
    font-size: 12px !important;
  }
  
  /* Optimize image actions for small screens */
  .image-actions small {
    font-size: 10px !important;
  }
  
  .image-actions .btn {
    font-size: 10px !important;
    padding: 2px 4px !important;
  }
  
  /* Optimize chat input area for very small screens */
  .chat-input-group {
    gap: 8px !important;
  }
  
  .chat-input-group textarea {
    font-size: 13px !important;
    padding: 10px 16px !important;
  }
  
  .chat-send-button button {
    width: 40px !important;
    height: 40px !important;
  }
  
  /* Optimize file attachment icon for small screens */
  .helper-form i {
    font-size: 16px !important;
    padding: 6px !important;
  }
}

/* Additional mobile optimizations for chat layout */
@media (max-width: 767px) {
  /* Optimize chat header for mobile */
  .chat-header-grid {
    gap: 16px !important;
    grid-template-columns: 1fr auto 1fr !important;
  }
  
  /* Ensure proper text truncation on mobile */
  .chat-header-grid .text-truncate {
    max-width: 80px !important;
  }
  
  /* Optimize queued files preview for mobile */
  .queued-files-container {
    padding: 8px !important;
  }
  
  .queued-file {
    padding: 6px !important;
    margin-bottom: 6px !important;
  }
  
  /* Optimize progress bar for mobile */
  .message-progress {
    height: 4px !important;
  }
  
  /* Ensure proper spacing for mobile chat */
  .chat-wrapper {
    padding-top: 15px !important;
  }
  
  .chat-bottom {
    padding-top: 15px !important;
  }
  
  /* Touch-friendly optimizations for mobile */
  .chat-image {
    cursor: pointer !important;
    -webkit-tap-highlight-color: rgba(0, 123, 255, 0.3) !important;
  }
  
  .chat-image:active {
    transform: scale(0.98) !important;
  }
  
  /* Ensure buttons are touch-friendly */
  .btn {
    min-height: 44px !important;
    min-width: 44px !important;
  }
  
  .btn-sm {
    min-height: 32px !important;
    min-width: 32px !important;
  }
  
  /* Optimize scrollbar for mobile */
  .chat-wrapper::-webkit-scrollbar {
    width: 4px !important;
  }
  
  .chat-wrapper::-webkit-scrollbar-thumb {
    border-radius: 10px !important;
  }
}

/* CRITICAL: Mobile Sidebar Visibility Fixes */
@media (max-width: 991px) {
  /* Force sidebar to be visible on mobile */
  .sidebar-col {
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
    position: relative !important;
    transform: none !important;
    width: 100% !important;
    max-width: 100% !important;
    flex: 0 0 100% !important;
    margin-bottom: 20px !important;
    order: -1 !important; /* Move sidebar to top on mobile */
  }
  
  /* Ensure sidebar content is visible */
  .user-sidebar {
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
    width: 100% !important;
    max-width: 100% !important;
    position: relative !important;
    transform: none !important;
    box-shadow: none !important;
    border-radius: 8px !important;
    border: 1px solid #e1e5e9 !important;
    background: #ffffff !important;
  }
  
  /* Remove collapsed state on mobile */
  .user-sidebar.collapsed {
    width: 100% !important;
    max-width: 100% !important;
  }
  
  .user-sidebar.collapsed .links li a .menu-text {
    opacity: 1 !important;
    width: auto !important;
    overflow: visible !important;
  }
  
  .user-sidebar.collapsed .links li a {
    padding: 12px 20px !important;
    justify-content: flex-start !important;
  }
  
  .user-sidebar.collapsed .links li a i {
    margin-right: 12px !important;
    font-size: 16px !important;
  }
  
  /* Hide sidebar toggle on mobile */
  .sidebar-toggle {
    display: none !important;
  }
  
  /* Ensure all menu items are visible */
  .user-sidebar .links {
    padding-top: 20px !important;
    padding-bottom: 20px !important;
  }
  
  .user-sidebar .links li {
    margin-bottom: 8px !important;
  }
  
  .user-sidebar .links li a {
    padding: 12px 20px !important;
    border-radius: 6px !important;
    transition: all 0.2s ease !important;
  }
  
  .user-sidebar .links li a:hover {
    background-color: #f8f9fa !important;
    transform: translateX(5px) !important;
  }
  
  /* Ensure main content takes full width on mobile */
  .user-dashboard .row > .w-100 {
    flex: 0 0 100% !important;
    max-width: 100% !important;
    width: 100% !important;
    padding-left: 15px !important;
    padding-right: 15px !important;
  }
  
  /* Mobile-specific layout adjustments */
  .user-dashboard .row {
    flex-direction: column !important;
    flex-wrap: wrap !important;
  }
  
  /* Ensure container doesn't interfere */
  .user-dashboard .container {
    padding-left: 15px !important;
    padding-right: 15px !important;
    margin-left: 0 !important;
    margin-right: 0 !important;
  }
}

/* Extra small mobile devices - additional sidebar fixes */
@media (max-width: 480px) {
  .sidebar-col {
    margin-bottom: 15px !important;
  }
  
  .user-sidebar .links li a {
    padding: 10px 16px !important;
    font-size: 14px !important;
  }
  
  .user-sidebar .links li a i {
    font-size: 14px !important;
    margin-right: 10px !important;
  }
  
  .user-sidebar .links {
    padding-top: 15px !important;
    padding-bottom: 15px !important;
  }
  
  /* Ensure menu text is always visible */
  .user-sidebar .links li a .menu-text {
    font-size: 14px !important;
    font-weight: 500 !important;
  }
  
  /* Optimize badge display on mobile */
  .badge {
    font-size: 10px !important;
    padding: 2px 6px !important;
  }
}

/* Override any conflicting styles that might hide the sidebar */
@media (max-width: 991px) {
  /* Force override any display: none rules */
  .sidebar-col,
  .user-sidebar,
  .user-sidebar * {
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
  }
  
  /* Override any transform or position rules that might hide elements */
  .sidebar-col,
  .user-sidebar {
    transform: none !important;
    position: relative !important;
    left: auto !important;
    right: auto !important;
    top: auto !important;
    bottom: auto !important;
    z-index: auto !important;
  }
  
  /* Ensure links are clickable */
  .user-sidebar .links li a {
    pointer-events: auto !important;
    cursor: pointer !important;
    user-select: auto !important;
  }
  
  /* Override any overflow hidden that might cut off content */
  .user-sidebar,
  .sidebar-col {
    overflow: visible !important;
    clip: auto !important;
    clip-path: none !important;
  }
}

/* Mobile-specific mobile menu toggle */
@media (max-width: 991px) {
  .mobile-menu-toggle {
    display: block !important;
    position: fixed !important;
    top: 20px !important;
    right: 20px !important;
    z-index: 9999 !important;
    background: #007bff !important;
    color: white !important;
    border: none !important;
    border-radius: 50% !important;
    width: 50px !important;
    height: 50px !important;
    font-size: 20px !important;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15) !important;
  }
  
  .mobile-menu-toggle:hover {
    background: #0056b3 !important;
    transform: scale(1.1) !important;
  }
  
  /* Ensure mobile menu is always accessible */
  .mobile-sidebar {
    display: block !important;
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: 100% !important;
    background: rgba(0,0,0,0.5) !important;
    z-index: 9998 !important;
    opacity: 1 !important;
    visibility: visible !important;
  }
}
