/* Mobile Interface Optimization */

/* ==================== PWA - Full Screen App-like Experience ==================== */

/* iOS Safari - support for safe area insets (notch, home indicator) */
@media (max-width: 1024px) {
  /* Remove height restrictions to allow scrolling */
  html.h-100,
  body.h-100 {
    height: auto !important;
    min-height: 100vh;
  }

  body {
    overflow-y: auto !important;
    overflow-x: hidden;
    position: relative !important;
  }

  @supports (padding: max(0px)) {
    body {
      padding-left: env(safe-area-inset-left);
      padding-right: env(safe-area-inset-right);
    }
  }

  /* Prevent pull-to-refresh on mobile */
  body {
    overscroll-behavior-y: contain;
  }
}

/* ==================== Mobile-First Responsive Design ==================== */

/* Base Mobile/Tablet Styles - Apply to tablet and mobile */
@media (max-width: 1024px) {
  /* Add padding for fixed navbar + safe area */
  body {
    padding-top: calc(56px + env(safe-area-inset-top, 0)) !important;
  }

  /* Fixed header at top */
  .navbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1030;
    padding: 0.5rem 1rem;
    min-height: 56px;
    margin-top: env(safe-area-inset-top, 0);
    background-color: #212529 !important;
  }

  .navbar-brand {
    font-size: 1.1rem;
    font-weight: 600;
  }

  /* Mobile hamburger menu - logout item styling */
  .navbar-nav .nav-item.mobile-logout {
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    margin-top: 0.5rem;
    padding-top: 0.5rem;
  }

  .navbar-nav .nav-item.mobile-logout .nav-link {
    color: #dc3545 !important;
    font-weight: 500;
  }

  .navbar-nav .nav-item.mobile-logout .nav-link:hover {
    color: #bb2d3b !important;
  }

  /* Mobile header icons (notification, language, theme) - positioned between brand and hamburger */
  /* Note: Only displayed below 992px (lg breakpoint) via d-lg-none class in HTML */
  .mobile-header-icons {
    align-items: center;
    margin-left: auto;
    margin-right: 0.5rem;
    gap: 0.25rem;
  }

  .mobile-header-icons .btn-link,
  .mobile-header-icons .theme-toggle-btn {
    color: rgba(255, 255, 255, 0.85) !important;
    padding: 0.25rem !important;
    background: transparent !important;
    border: none !important;
  }

  .mobile-header-icons .btn-link:hover,
  .mobile-header-icons .theme-toggle-btn:hover,
  .mobile-header-icons .btn-link:focus,
  .mobile-header-icons .theme-toggle-btn:focus {
    color: rgba(255, 255, 255, 1) !important;
    background: rgba(255, 255, 255, 0.1) !important;
    border-radius: 0.25rem;
  }

  .mobile-header-icons .btn-link i,
  .mobile-header-icons .theme-toggle-btn i {
    color: inherit !important;
  }

  .mobile-header-icons .dropdown-menu {
    min-width: 200px;
  }

  /* Language switcher in mobile header */
  .mobile-header-icons .navbar-language-switcher .dropdown-toggle {
    color: rgba(255, 255, 255, 0.85) !important;
    padding: 0.25rem 0.5rem !important;
  }

  /* Navbar flex order for mobile - icons between brand and toggler */
  .navbar > .container-fluid {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
  }

  .navbar-brand {
    order: 0;
    flex-shrink: 0;
  }

  .mobile-header-icons {
    order: 1;
    flex-shrink: 0;
  }

  .navbar-toggler {
    order: 2;
    flex-shrink: 0;
    margin-left: 0 !important;
  }

  /* Collapse menu takes full width on new line below header */
  .navbar-collapse {
    order: 3;
    flex-basis: 100%;
    width: 100%;
  }

  /* Main content padding adjustment */
  .container,
  .container-fluid {
    padding-top: 0.5rem;
  }

  /* Main content with sidebar - reduce top padding */
  .container.main-content-with-sidebar {
    padding-top: 0.5rem !important;
  }

  /* Hide shortcuts sidebar on mobile/tablet */
  .shortcuts-sidebar {
    display: none !important;
  }

  /* Remove sidebar margin */
  .main-content-with-sidebar {
    margin-right: 0 !important;
  }

  /* Container adjustments */
  .container {
    padding-left: 0.75rem;
    padding-right: 0.75rem;
  }

  /* Hide footer on mobile/tablet */
  footer,
  .footer {
    display: none !important;
  }
}

/* Breadcrumb wrapper - prevent line break on tablet */
.breadcrumb-wrapper {
  display: flex !important;
  flex-direction: row !important;
  flex-wrap: nowrap !important;
  align-items: center !important;
  white-space: nowrap;
  margin-top: 10px;
}

.breadcrumb-wrapper .breadcrumb-content {
  display: block !important;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
}

.breadcrumb-wrapper .breadcrumb-content nav {
  display: block !important;
  width: 100%;
  white-space: nowrap;
}

.breadcrumb-wrapper .breadcrumb-content .breadcrumb {
  display: flex !important;
  flex-direction: row !important;
  flex-wrap: nowrap !important;
  white-space: nowrap;
  margin-bottom: 0;
  width: 100%;
}

.breadcrumb-wrapper .breadcrumb-content .breadcrumb .breadcrumb-item {
  white-space: nowrap;
  flex-shrink: 0;
}

/* Hide breadcrumbs only on mobile (phones) */
@media (max-width: 768px) {
  .breadcrumb {
    display: none;
  }

  .breadcrumb-wrapper {
    margin-bottom: 0.5rem;
  }
}

/* ==================== Bottom Navigation Bar ==================== */

.mobile-bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  border-top: 1px solid #e9ecef;
  box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
  z-index: 1000;
  display: none;
  background-color: #fff; /* Ensure background is opaque */
  padding: 0;
}

.mobile-nav-slider {
  display: flex;
  width: 300%;
  transition: transform 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.mobile-nav-page {
  width: 33.333%;
  display: flex;
  justify-content: space-around;
  padding: 0.5rem 0;
  padding-bottom: calc(0.1rem + env(safe-area-inset-bottom, 0));
}

[data-theme="dark"] .mobile-bottom-nav {
  background-color: #212529 !important;
  border-top-color: #373b3e;
}

@media (max-width: 1024px) {
  .mobile-bottom-nav {
    display: block;
  }

  /* Add bottom padding to body to account for fixed nav */
  body {
    padding-bottom: 70px;
  }
}

.mobile-nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0.5rem 0.25rem;
  text-decoration: none;
  color: #6c757d;
  transition: color 0.2s ease;
  min-height: 60px;
}

.mobile-nav-item:hover,
.mobile-nav-item:focus {
  text-decoration: none;
  color: #007bff;
}

.mobile-nav-item.active {
  color: #007bff;
}

.mobile-nav-icon {
  font-size: 1.5rem;
  margin-bottom: 0.25rem;
}

.mobile-nav-label {
  font-size: 0.75rem;
  font-weight: 500;
  text-align: center;
  line-height: 1.2;
}

.mobile-nav-badge {
  position: absolute;
  top: 0.25rem;
  right: 50%;
  transform: translateX(50%);
  background: #dc3545;
  color: white;
  border-radius: 50%;
  padding: 0.125rem 0.375rem;
  font-size: 0.625rem;
  font-weight: 600;
  min-width: 18px;
  text-align: center;
}

/* ==================== Messaging App Style Chat Interface ==================== */

@media (max-width: 1024px) {
  /* Chat Room List - Messaging App Style */
  .chat-room-index {
    padding: 0;
  }

  .chat-room-index .container {
    padding: 0;
  }

  .chat-room-index h1 {
    padding: 1rem;
    margin: 0;
  }

  /* Room cards as conversation list */
  .room-cards-container {
    grid-template-columns: 1fr;
    gap: 0;
    margin: 0;
  }

  .room-card {
    border-radius: 0;
    border-left: none;
    border-right: none;
    border-top: none;
    box-shadow: none;
    margin: 0;
  }

  .room-card:hover {
    transform: none;
    box-shadow: none;
  }

  .room-card-header,
  .room-card-body {
    padding: 1rem;
  }

  .room-card-header {
    padding-bottom: 0.5rem;
  }

  .room-card-body {
    padding-top: 0;
  }

  /* Chat Room View - Normal flow like desktop */
  .chat-room-view {
    display: block;
    padding: 0;
  }

  .chat-room-view .container {
    padding: 0;
    max-width: 100%;
  }

  .chat-room-view .row {
    margin: 0;
  }

  .chat-room-view .col-md-9 {
    padding: 0;
  }

  .chat-room-view .col-md-3 {
    display: none; /* Hide sidebar on mobile */
  }

  /* Card styling for mobile */
  .chat-room-view .card {
    border-radius: 0;
    border-left: none;
    border-right: none;
  }

  /* Chat header - inherits dark mode from dark-mode.css */
  .chat-header {
    padding: 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 56px; /* Account for navbar */
    z-index: 100;
  }

  .chat-header-title {
    font-size: 1.1rem;
    font-weight: 600;
    margin: 0;
    flex: 1;
  }

  .chat-header-actions {
    display: flex;
    gap: 0.5rem;
  }

  .chat-header-back {
    color: #007bff;
    text-decoration: none;
    font-size: 1.25rem;
    margin-right: 0.75rem;
  }

  /* Messages container - Use available height, inherits dark mode from dark-mode.css */
  #messages-container {
    height: calc(
      100vh - 70px - 120px - 120px
    ) !important; /* viewport - navbar - footer nav - input/header */
    max-height: calc(100vh - 70px - 120px - 140px) !important;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 0.5rem;
  }

  /* Message bubbles */
  .message {
    max-width: 85%;
    margin-bottom: 0.75rem;
    border-radius: 1rem;
    padding: 0.75rem 1rem;
    position: relative;
    word-wrap: break-word;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
    clear: both;
  }

  .message-own {
    float: right;
    border-bottom-right-radius: 0.25rem;
  }

  .message-other {
    float: left;
    border-bottom-left-radius: 0.25rem;
  }

  .message strong {
    display: block;
    font-size: 0.8rem;
    margin-bottom: 0.25rem;
    opacity: 0.8;
  }

  .message-own strong {
    /* Color inherits from dark-mode.css */
  }

  .message p {
    margin: 0;
    line-height: 1.4;
  }

  .message small {
    display: block;
    font-size: 0.7rem;
    margin-top: 0.25rem;
    opacity: 0.7;
  }

  /* Message input - Normal flow like desktop, inherits dark mode from dark-mode.css */
  .chat-input-container {
    padding: 0.75rem;
    position: relative;
    display: block !important;
  }

  /*
  .chat-input-form {
    display: flex;
    align-items: flex-end;
    gap: 0.5rem;
  }
*/
  /* Mobile File Upload Section - completely separate row above input */
  /* Initial state is hidden, JavaScript will show it when file is selected */
  #mobile-file-upload-section {
    display: none;
    width: 100%;
    margin-bottom: 0.75rem;
  }

  .mobile-file-preview-container {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 0.75rem;
    background-color: #e7f3ff;
    border: 1px solid #b6d4fe;
    border-radius: 0.5rem;
  }

  .mobile-file-thumbnail {
    flex-shrink: 0;
    width: 50px;
    height: 50px;
    border-radius: 0.375rem;
    overflow: hidden;
    background-color: #f8f9fa;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .mobile-file-thumbnail img {
    width: 100%;
    height: 100%;
    object-fit: cover;
  }

  .mobile-file-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 0.125rem;
  }

  .mobile-file-name {
    font-size: 0.875rem;
    font-weight: 500;
    color: #0d6efd;
    word-break: break-all;
    line-height: 1.3;
  }

  .mobile-file-size {
    font-size: 0.75rem;
    color: #6c757d;
  }

  .mobile-file-remove {
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    min-height: 32px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    background: none;
    border: none;
    color: #6c757d;
    font-size: 1.25rem;
    transition: color 0.15s ease;
  }

  .mobile-file-remove:hover {
    color: #dc3545;
  }

  .mobile-file-remove i,
  .mobile-file-remove .bi {
    pointer-events: none;
  }

  /* Dark mode for mobile file upload section */
  [data-theme="dark"] .mobile-file-preview-container {
    background-color: rgba(13, 110, 253, 0.15);
    border-color: rgba(13, 110, 253, 0.3);
  }

  [data-theme="dark"] .mobile-file-name {
    color: #4a9eff;
  }

  [data-theme="dark"] .mobile-file-size {
    color: #adb5bd;
  }

  [data-theme="dark"] .mobile-file-thumbnail {
    background-color: #2d2d2d;
  }

  [data-theme="dark"] .mobile-file-remove {
    color: #adb5bd;
  }

  [data-theme="dark"] .mobile-file-remove:hover {
    color: #f87171;
  }

  .chat-input-wrapper {
    flex: 1;
    min-width: 0; /* Allow shrinking */
    position: relative;
  }

  #comment-content,
  #mobile-comment-content {
    border-radius: 1.25rem;
    border: 1px solid #dee2e6;
    padding: 0.625rem 1rem;
    resize: none;
    min-height: 50px;
    max-height: 160px;
    font-size: 16px; /* Prevent zoom on iOS */
    line-height: 1.5;
    transition: height 0.1s ease;
  }

  #comment-content:focus,
  #mobile-comment-content:focus {
    border-color: #007bff;
    box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, 0.25);
  }

  /* Mobile attach file button */
  #mobile-attach-file-btn {
    border-radius: 50%;
    width: 44px;
    height: 44px;
    min-height: 44px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 1.1rem;
  }

  /* Mobile remove file button - borderless X icon */
  #mobile-remove-file-btn {
    width: 32px !important;
    height: 32px !important;
    min-width: 32px;
    min-height: 32px;
    padding: 0 !important;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 1.25rem;
    cursor: pointer;
    background: none !important;
    border: none !important;
    color: #6c757d;
    transition: color 0.15s ease;
  }

  #mobile-remove-file-btn:hover {
    color: #dc3545;
  }

  [data-theme="dark"] #mobile-remove-file-btn {
    color: #adb5bd;
  }

  [data-theme="dark"] #mobile-remove-file-btn:hover {
    color: #f87171;
  }

  #mobile-remove-file-btn i,
  #mobile-remove-file-btn .bi {
    pointer-events: none;
  }

  .chat-send-btn {
    background: #007bff;
    color: white;
    border: none;
    border-radius: 50%;
    width: 44px;
    height: 44px;
    min-height: 44px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    flex-shrink: 0;
  }

  .chat-send-btn:hover {
    background: #0056b3;
  }

  .chat-send-btn:disabled {
    background: #6c757d;
    opacity: 0.6;
  }
}

/* ==================== Progressive Message Loading ==================== */

.message-loader {
  text-align: center;
  padding: 1rem;
  color: #6c757d;
  display: none;
}

.message-loader.loading {
  display: block;
}

.message-loader-spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2px solid #f3f3f5;
  border-radius: 50%;
  border-top-color: #007bff;
  animation: spin 1s ease-in-out infinite;
}

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

/* Load more button */
.load-more-messages {
  width: 100%;
  margin-bottom: 1rem;
  background: transparent;
  border: 1px solid #dee2e6;
  color: #6c757d;
  padding: 0.75rem;
  border-radius: 0.5rem;
  font-size: 0.9rem;
}

.load-more-messages:hover {
  border-color: #adb5bd;
}

/* ==================== Touch-Friendly UI Elements ==================== */

@media (max-width: 1024px) {
  /* Larger touch targets */
  .btn {
    min-height: 32px;
    padding: 0.75rem 1rem;
    font-size: 1rem;
  }

  .btn-sm {
    min-height: 26px;
    padding: 0.5rem 0.75rem;
    font-size: 0.9rem;
  }

  /* Form controls */
  .form-control,
  .form-select {
    min-height: 32px;
    padding: 0.75rem;
    vertical-align: middle;
    font-size: 16px; /* Prevent zoom on iOS */
  }

  /* Links */
  a {
    display: inline-flex;
    align-items: center;
  }

  /* Exclude breadcrumb links and copy link button from touch-friendly sizing */
  .breadcrumb a,
  .breadcrumb-item a,
  .copy-page-link-btn {
    min-height: auto;
    display: inline;
  }

  .copy-page-link-btn {
    display: inline-flex;
  }

  /* Stat card wrapper links should stretch to full height */
  .site-index .row > [class*="col-"] > a.text-decoration-none {
    display: block;
    height: 100%;
    min-height: auto;
  }

  /* List items */
  .list-group-item {
    min-height: 60px;
    padding: 1rem;
    display: flex;
    align-items: center;
  }

  /* Cards */
  .card {
    border-radius: 0.75rem;
  }

  .card-header,
  .card-body,
  .card-footer {
    padding: 1rem;
  }

  /* Dropdowns */
  .dropdown-item {
    min-height: 44px;
    padding: 0.75rem 1rem;
    display: flex;
    align-items: center;
  }
}

/* ==================== Document Upload Mobile Optimization ==================== */

@media (max-width: 1024px) {
  /* Upload area */
  .upload-area {
    padding: 2rem 1rem;
    border-radius: 0.75rem;
  }

  .upload-icon {
    font-size: 2.5rem;
  }

  .upload-text {
    font-size: 1rem;
  }

  .upload-hint {
    font-size: 0.85rem;
  }

  /* File preview */
  .file-preview-item {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 1rem;
  }

  .file-preview-info {
    width: 100%;
  }

  .file-preview-actions {
    width: 100%;
    display: flex;
    gap: 0.5rem;
  }

  .file-preview-actions .btn {
    flex: 1;
  }

  /* Document grid */
  .document-grid {
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 0.75rem;
  }

  .document-card {
    border-radius: 0.75rem;
  }

  .document-thumbnail {
    height: 120px;
  }

  .document-info {
    padding: 0.75rem;
  }

  /* Document list */
  .document-list-item {
    padding: 1rem;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.75rem;
  }

  .document-list-info {
    width: 100%;
  }

  .document-list-actions {
    width: 100%;
    display: flex;
    gap: 0.5rem;
  }

  .document-list-actions .btn {
    flex: 1;
  }
}

/* ==================== Search Interface Mobile ==================== */

@media (max-width: 1024px) {
  .search-container {
    padding: 1rem;
  }

  .search-form {
    margin-bottom: 1.5rem;
  }

  .search-input {
    font-size: 16px; /* Prevent zoom on iOS */
    border-radius: 1.25rem;
    padding: 0.75rem 1rem;
    border: 2px solid #dee2e6;
  }

  .search-input:focus {
    border-color: #007bff;
    box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, 0.25);
  }

  .search-filters {
    display: none; /* Hide advanced filters by default */
  }

  .search-filters.show {
    display: block;
    margin-top: 1rem;
    padding: 1rem;
    border-radius: 0.75rem;
  }

  .search-toggle-filters {
    width: 100%;
    margin-bottom: 1rem;
    background: transparent;
    border: 1px solid #dee2e6;
    color: #6c757d;
    padding: 0.75rem;
    border-radius: 0.5rem;
  }

  .search-results {
    margin-top: 1rem;
  }

  .search-result-item {
    padding: 1rem;
    border-bottom: 1px solid #dee2e6;
    margin-bottom: 0.5rem;
    border-radius: 0.75rem;
  }

  .search-result-title {
    font-weight: 600;
    margin-bottom: 0.5rem;
  }

  .search-result-meta {
    font-size: 0.85rem;
    margin-bottom: 0.5rem;
  }

  .search-result-snippet {
    font-size: 0.9rem;
    line-height: 1.4;
  }
}

/* ==================== Notification Mobile Optimization ==================== */

@media (max-width: 1024px) {
  .notification-dropdown {
    position: fixed !important;
    top: 56px !important;
    left: 0 !important;
    right: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    border-radius: 0 !important;
    border: none !important;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1) !important;
    max-height: calc(100vh - 56px) !important;
  }

  .notification-dropdown .dropdown-item {
    padding: 1rem;
    border-bottom: 1px solid #f0f0f0;
  }

  .notification-dropdown .dropdown-header {
    padding: 1rem;
    border-bottom: 1px solid #dee2e6;
    position: sticky;
    top: 0;
    z-index: 10;
  }
}

/* ==================== Mention Management Mobile ==================== */

@media (max-width: 1024px) {
  .mention-list {
    padding: 0;
  }

  .mention-item {
    padding: 1rem;
    border-bottom: 1px solid #dee2e6;
    margin-bottom: 0.5rem;
    border-radius: 0.75rem;
  }

  .mention-content {
    margin-bottom: 0.75rem;
  }

  .mention-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
  }

  .mention-actions .btn {
    flex: 1;
    min-width: 120px;
  }

  .mention-meta {
    font-size: 0.85rem;
    color: #6c757d;
    margin-top: 0.5rem;
  }
}

/* ==================== Performance Optimizations ==================== */

/* Reduce animations on mobile for better performance */
@media (max-width: 1024px) {
  * {
    transition-duration: 0.15s !important;
  }

  /* Disable hover effects on touch devices */
  @media (hover: none) {
    .room-card:hover,
    .document-card:hover,
    .btn:hover {
      transform: none !important;
      box-shadow: inherit !important;
    }
  }
}

/* ==================== Accessibility Improvements ==================== */

@media (max-width: 1024px) {
  /* Focus indicators */
  *:focus {
    outline: 2px solid #007bff !important;
    outline-offset: 2px !important;
  }

  /* Skip to content link */
  .skip-to-content {
    position: absolute;
    top: -40px;
    left: 6px;
    background: #007bff;
    color: white;
    padding: 8px;
    text-decoration: none;
    border-radius: 4px;
    z-index: 10000;
  }

  .skip-to-content:focus {
    top: 6px;
  }

  /* Screen reader only content */
  .sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
  }
}

/* ==================== Dark Mode Support ==================== */
/* NOTE: Dark mode styles have been moved to dark-mode.css
   which supports all screen sizes and manual theme toggle.
   The styles below are kept for backward compatibility with
   system dark mode preference on mobile devices. */

/* Mobile-specific dark mode enhancements (works with dark-mode.css) */
@media (max-width: 1024px) {
  [data-theme="dark"] .delete-message-btn,
  html[data-theme="auto"] .delete-message-btn {
    width: 24px !important;
    height: 24px !important;
    min-height: 24px !important;
    padding: 0 !important;
  }

  [data-theme="dark"] .delete-message-btn svg,
  html[data-theme="auto"] .delete-message-btn svg {
    width: 16px !important;
    height: 16px !important;
  }
}

/* ==================== Print Styles ==================== */

@media print {
  .mobile-bottom-nav,
  .chat-input-container,
  .chat-header-actions,
  .mobile-nav-item {
    display: none !important;
  }

  .chat-room-view {
    height: auto !important;
  }

  #messages-container {
    height: auto !important;
    overflow: visible !important;
  }

  .message {
    break-inside: avoid;
    max-width: 100% !important;
    margin: 0.5rem 0 !important;
  }
}

/* ==================== Landscape Orientation ==================== */

@media (max-width: 1024px) and (orientation: landscape) {
  .chat-header {
    padding: 0.75rem 1rem;
  }

  .chat-input-container {
    padding: 0.5rem 0.75rem;
  }

  #messages-container {
    height: calc(
      100vh - 56px - 50px - 100px
    ) !important; /* Adjusted for landscape */
    max-height: calc(100vh - 56px - 50px - 100px) !important;
  }

  #comment-content,
  #mobile-comment-content {
    min-height: 36px;
    max-height: 80px;
  }

  .mobile-bottom-nav {
    padding: 0.25rem 0;
  }

  .mobile-nav-item {
    min-height: 50px;
    padding: 0.25rem;
  }

  .mobile-nav-icon {
    font-size: 1.25rem;
    margin-bottom: 0.125rem;
  }

  .mobile-nav-label {
    font-size: 0.7rem;
  }
}

/* ==================== Very Small Screens (< 375px) ==================== */

@media (max-width: 374px) {
  .container {
    padding-left: 0.5rem;
    padding-right: 0.5rem;
  }

  .mobile-nav-label {
    font-size: 0.65rem;
  }

  .mobile-nav-icon {
    font-size: 1.25rem;
  }

  .chat-header {
    padding: 0.75rem;
  }

  .chat-input-container {
    padding: 0.5rem;
  }

  #messages-container {
    height: calc(
      100vh - 56px - 70px - 110px
    ) !important; /* Adjusted for small screens */
    max-height: calc(100vh - 56px - 70px - 110px) !important;
  }

  .message {
    max-width: 90%;
    padding: 0.5rem 0.75rem;
  }

  .room-card-header,
  .room-card-body {
    padding: 0.75rem;
  }
}

/* ==================== Dashboard Stat Cards - Keep 4 Columns on Mobile ==================== */

@media (max-width: 1024px) {
  /* Override Bootstrap col-md-6 to keep 4 columns for stat-cards */
  .site-index .stat-card {
    padding: 0.75rem 0.5rem;
  }

  .site-index .row > [class*="col-lg-3"][class*="col-md-6"] {
    flex: 0 0 25%;
    max-width: 25%;
  }

  /* Smaller font sizes for stat numbers on mobile */
  .site-index .stat-number {
    font-size: 1.5rem;
  }

  .site-index .stat-label {
    font-size: 0.7rem;
  }

  .site-index .stat-icon {
    font-size: 1.25rem;
    margin-bottom: 0.5rem;
  }
}

/* Even smaller screens - still maintain 4 columns but with minimal padding */
@media (max-width: 576px) {
  .site-index .row > [class*="col-lg-3"][class*="col-md-6"] {
    flex: 0 0 25%;
    max-width: 25%;
    padding-left: 0.25rem;
    padding-right: 0.25rem;
  }

  .site-index .stat-card {
    padding: 0.5rem 0.25rem;
    border-radius: 0.5rem;
  }

  .site-index .stat-number {
    font-size: 1.25rem;
    margin-bottom: 0.25rem;
  }

  .site-index .stat-label {
    font-size: 0.6rem;
    line-height: 1.2;
  }

  .site-index .stat-icon {
    font-size: 1rem;
    margin-bottom: 0.25rem;
  }
}

/* ==================== Notification Page Mobile Optimization ==================== */

@media (max-width: 768px) {
  /* Notification page header - ensure proper mobile layout */
  .notification-index .page-header-box {
    flex-wrap: nowrap !important;
    align-items: flex-start !important;
  }

  .notification-index .header-content {
    flex: 1;
    min-width: 0; /* Allow text truncation */
  }

  .notification-index .page-header-title {
    font-size: 1.5rem !important;
    margin-bottom: 0.25rem !important;
    line-height: 1.2;
  }

  .notification-index .header-content small {
    display: block;
    margin-left: 0 !important;
    font-size: 0.8rem;
  }

  .notification-index .header-actions {
    flex-shrink: 0;
    margin-left: 0.5rem;
  }

  .notification-index .header-actions .btn {
    padding: 0.375rem 0.5rem;
    font-size: 1rem;
  }

  /* Show Read toggle - mobile styling */
  .notification-index .form-check-label {
    font-size: 0.9rem;
  }
}

@media (max-width: 576px) {
  /* Extra small screens - more compact */
  .notification-index .page-header-title {
    font-size: 1.3rem !important;
  }

  .notification-index .header-actions .btn {
    padding: 0.25rem 0.375rem;
    min-width: 36px;
  }
}

/* ==================== Inventory Pages Mobile Optimization ==================== */

@media (max-width: 768px) {
  /* Inventory page headers with proper padding and spacing */
  .inventory-my-items > .d-flex,
  .inventory-search > .d-flex,
  .inventory-photo-gallery > .d-flex {
    padding: 0.75rem 0;
    gap: 0.75rem;
  }

  .inventory-my-items h1,
  .inventory-search h1,
  .inventory-photo-gallery h1 {
    font-size: 1.25rem;
    margin-bottom: 0;
  }

  /* Inventory location pages - ensure proper header padding */
  .inventory-location-index .page-header-box,
  .inventory-location-view .page-header-box {
    padding: 1rem 1.25rem !important;
  }

  .inventory-location-index .page-header-title,
  .inventory-location-view .page-header-title {
    font-size: 1.1rem !important;
    margin-bottom: 0.25rem !important;
  }

  .inventory-location-index .page-header-subtitle,
  .inventory-location-view .page-header-subtitle {
    font-size: 0.8rem !important;
  }

  /* Photo gallery header */
  .inventory-photo-gallery > .d-flex.justify-content-between {
    flex-wrap: wrap;
  }

  .inventory-photo-gallery > .d-flex.justify-content-between > div:first-child {
    flex: 1;
    min-width: 0;
  }
}

@media (max-width: 576px) {
  /* Extra small screens for inventory pages */
  .inventory-location-index .page-header-box,
  .inventory-location-view .page-header-box {
    padding: 0.875rem 1rem !important;
    gap: 0.5rem !important;
  }

  .inventory-location-index .page-header-title,
  .inventory-location-view .page-header-title {
    font-size: 1rem !important;
  }

  .inventory-location-index .header-actions .btn,
  .inventory-location-view .header-actions .btn {
    padding: 0.35rem 0.5rem !important;
    font-size: 0.85rem !important;
  }

  .inventory-my-items h1,
  .inventory-search h1 {
    font-size: 1.1rem;
  }
}

/* ==================== Company Abbreviation Badge ==================== */
/* Displayed between back/forward navigation buttons on mobile */
.company-abbr-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 40px;
  padding: 4px 8px;
  font-size: 13px;
  font-weight: 700;
  color: #fff;
  background: rgba(255, 255, 255, 0.15);
  border-radius: 4px;
  letter-spacing: 0.5px;
}

/* Dark mode support */
[data-theme="dark"] .company-abbr-badge {
  background: rgba(255, 255, 255, 0.2);
}

/* Company Switch Dropdown for Mobile */
.company-abbr-badge.dropdown-toggle::after {
  display: none; /* Hide default dropdown arrow */
}

.company-switch-dropdown {
  min-width: 220px;
  max-height: 300px;
  overflow-y: auto;
}

.company-switch-dropdown .dropdown-item {
  padding: 10px 16px;
  font-size: 14px;
}

.company-switch-dropdown .dropdown-item.active {
  background-color: rgba(13, 110, 253, 0.15);
  color: #fff;
}

.company-switch-dropdown .dropdown-item .company-abbr {
  display: inline-block;
  min-width: 40px;
  font-weight: 700;
  margin-right: 4px;
}
