/* ============================================================
   CRM Responsive Baseline (shared across CRM HTML pages)
   Version: 2.0.0 - Comprehensive Mobile Responsiveness Update
   Last Updated: January 6, 2026
   
   Goals:
   - Prevent horizontal cutoffs (overflow-x issues)
   - Make media (img/video/canvas) scale correctly
   - Improve text wrapping for long strings (emails, addresses)
   - Provide safe-area padding support on iOS
   - Keep tables usable on mobile via horizontal scroll
   - Full mobile-first responsive design
   ============================================================ */

:root {
  --crm-safe-left: env(safe-area-inset-left, 0px);
  --crm-safe-right: env(safe-area-inset-right, 0px);
  --crm-safe-top: env(safe-area-inset-top, 0px);
  --crm-safe-bottom: env(safe-area-inset-bottom, 0px);

  /* A sane default "content max width" for wide monitors */
  --crm-content-max: 1440px;
  
  /* Mobile breakpoints */
  --mobile-sm: 480px;
  --mobile-md: 600px;
  --tablet: 768px;
  --tablet-lg: 1024px;
  --desktop: 1200px;
}

/* Base reset / mobile text scaling */
html {
  box-sizing: border-box;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-behavior: smooth;
}

*, *::before, *::after {
  box-sizing: inherit;
}

/* Prevent unexpected horizontal scroll from any component */
body {
  margin: 0;
  max-width: 100%;
  overflow-x: hidden;
  padding-left: var(--crm-safe-left);
  padding-right: var(--crm-safe-right);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Prevent body scroll when modal/sidebar is open */
body.modal-open,
body.sidebar-open {
  overflow: hidden;
  position: fixed;
  width: 100%;
}

/* Media should never overflow */
img, svg, video, canvas {
  max-width: 100%;
  height: auto;
}

/* Long strings (emails/URLs/IDs) should wrap instead of stretching layout.
   IMPORTANT: avoid applying aggressive wrapping to all div/span/button because it can
   cause normal UI labels (e.g. "Dashboard", "Notification") to split mid-word. */
:where(td, a, code, pre) {
  overflow-wrap: anywhere;
  word-break: break-word;
}

/* Table headers should remain readable (avoid mid-word wraps like "Custo mer").
   If the table is wider than the viewport, rely on the table container's horizontal scroll. */
:where(th) {
  overflow-wrap: normal;
  word-break: normal;
  hyphens: none;
  white-space: nowrap;
}

/* Opt-in utilities for long, unbroken strings */
.crm-wrap-anywhere {
  overflow-wrap: anywhere;
  word-break: break-word;
}

.crm-break-all {
  word-break: break-all;
}

/* Headings should never break mid-word */
:where(h1, h2, h3, h4, h5, h6) {
  overflow-wrap: normal;
  word-break: normal;
  hyphens: none;
}

/* Buttons, badges, and navigation should never hyphenate */
:where(button, .btn, .badge, .tag, .pill, .status, .nav-link, .menu-item, .sidebar-link, label) {
  overflow-wrap: normal;
  word-break: keep-all;
  -webkit-hyphens: none;
  -moz-hyphens: none;
  -ms-hyphens: none;
  hyphens: none;
  white-space: nowrap;
}

/* Allow buttons with long text to wrap if needed but not hyphenate */
.btn-wrap {
  white-space: normal !important;
  word-break: keep-all;
}

/* Stats and metrics should never break */
:where(.stat-value, .stat-label, .metric, .count, .price) {
  white-space: nowrap;
  overflow-wrap: normal;
  word-break: normal;
  hyphens: none;
}

/* Icons should not affect text flow */
:where(i[class*="fa-"], .icon) {
  flex-shrink: 0;
}

/* Common container helpers (works with and without Bootstrap) */
.crm-container {
  width: 100%;
  max-width: var(--crm-content-max);
  margin-left: auto;
  margin-right: auto;
  padding-left: 16px;
  padding-right: 16px;
}

@media (max-width: 600px) {
  .crm-container {
    padding-left: 12px;
    padding-right: 12px;
  }
}

/* Make any "table container" scroll horizontally on mobile */
.table-responsive,
.table-container,
.data-table-container,
:where(div)[style*="overflow-x: auto"] {
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* If a table is wider than the viewport, allow it to be scrolled */
table {
  max-width: 100%;
}

/* Buttons and inputs: mobile tap targets + prevent iOS zoom-on-focus */
@media (max-width: 600px) {
  input, select, textarea {
    font-size: 16px !important;
  }

  button, .btn, a.btn {
    min-height: 44px;
  }
}

/* Modals: ensure content fits smaller viewports */
.modal,
.modal-overlay {
  padding-left: max(12px, var(--crm-safe-left));
  padding-right: max(12px, var(--crm-safe-right));
  padding-bottom: max(12px, var(--crm-safe-bottom));
}

/* If a page uses fixed headers, this helps avoid top cutoffs */
.crm-safe-top {
  padding-top: max(0px, var(--crm-safe-top));
}

/* Bootstrap navbar fixes (works even if the page forgot toggler/collapse markup):
   On small screens, allow wrapping instead of cutting off. */
@media (max-width: 991.98px) {
  .navbar .navbar-nav {
    flex-wrap: wrap;
    gap: 8px;
  }

  .navbar .navbar-nav .nav-link {
    padding-left: 0.5rem;
    padding-right: 0.5rem;
    white-space: nowrap;
  }
}

/* ============================================================
   MOBILE NAVIGATION ENHANCEMENT
   ============================================================ */

/* Mobile Menu Button - Improved styling */
.mobile-menu-btn {
  display: none;
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 10000;
  width: 48px;
  height: 48px;
  background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
  color: white;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  font-size: 20px;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.4);
  transition: all 0.3s ease;
  -webkit-tap-highlight-color: transparent;
}

.mobile-menu-btn:hover {
  transform: scale(1.05);
  box-shadow: 0 6px 16px rgba(37, 99, 235, 0.5);
}

.mobile-menu-btn:active {
  transform: scale(0.95);
}

/* Sidebar Overlay - Smooth fade */
.sidebar-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0);
  z-index: 9998;
  transition: background 0.3s ease;
  -webkit-tap-highlight-color: transparent;
}

.sidebar-overlay.active {
  display: block;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}

/* Mobile Sidebar - Off-canvas with smooth animation */
@media (max-width: 768px) {
  .mobile-menu-btn {
    display: flex !important;
    align-items: center;
    justify-content: center;
  }

  .sidebar {
    position: fixed !important;
    top: 0;
    left: 0;
    height: 100vh;
    height: 100dvh; /* Dynamic viewport height for mobile browsers */
    width: 300px !important;
    max-width: 85vw;
    transform: translateX(-100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 9999 !important;
    box-shadow: none;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .sidebar.mobile-open {
    transform: translateX(0);
    box-shadow: 4px 0 30px rgba(0, 0, 0, 0.2);
  }

  /* Main content - full width on mobile */
  .main-content {
    margin-left: 0 !important;
    width: 100% !important;
  }

  /* Header adjustments for mobile menu button */
  .header {
    padding-left: 70px !important;
  }
}

@media (max-width: 480px) {
  .mobile-menu-btn {
    top: 10px;
    left: 10px;
    width: 44px;
    height: 44px;
    font-size: 18px;
  }

  .sidebar {
    width: 280px !important;
  }

  .header {
    padding-left: 65px !important;
  }
}

/* ============================================================
   MODAL RESPONSIVENESS - Full Screen on Mobile
   ============================================================ */

@media (max-width: 600px) {
  .modal {
    padding: 0 !important;
    align-items: flex-end !important;
  }

  .modal-content {
    width: 100% !important;
    max-width: 100% !important;
    max-height: 95vh !important;
    max-height: 95dvh !important;
    margin: 0 !important;
    border-radius: 20px 20px 0 0 !important;
    animation: slideUpModal 0.3s ease forwards;
  }

  @keyframes slideUpModal {
    from {
      transform: translateY(100%);
      opacity: 0;
    }
    to {
      transform: translateY(0);
      opacity: 1;
    }
  }

  .modal-header {
    padding: 16px 20px !important;
    border-radius: 20px 20px 0 0;
    position: sticky;
    top: 0;
    z-index: 10;
  }

  .modal-header h2,
  .modal-header h3 {
    font-size: 1.1rem !important;
  }

  .modal-header .close-btn {
    width: 36px;
    height: 36px;
    font-size: 24px;
  }

  .modal-body {
    padding: 16px !important;
    overflow-y: auto;
    max-height: calc(95vh - 140px);
    max-height: calc(95dvh - 140px);
    -webkit-overflow-scrolling: touch;
  }

  .modal-footer {
    padding: 12px 16px !important;
    padding-bottom: calc(12px + var(--crm-safe-bottom)) !important;
    flex-direction: column-reverse !important;
    gap: 8px !important;
    position: sticky;
    bottom: 0;
    background: inherit;
    border-top: 1px solid var(--border-color, #e5e7eb);
  }

  .modal-footer button,
  .modal-footer .btn {
    width: 100% !important;
    justify-content: center;
  }
}

/* ============================================================
   AI CHAT PANEL - Mobile Full Screen
   ============================================================ */

@media (max-width: 768px) {
  .ai-chat-panel {
    width: 100% !important;
    right: -100% !important;
    border-radius: 0 !important;
  }

  .ai-chat-panel.open {
    right: 0 !important;
  }

  .ai-chat-header {
    padding: 16px !important;
    padding-top: calc(16px + var(--crm-safe-top)) !important;
  }

  .ai-chat-messages {
    padding: 12px !important;
    height: calc(100vh - 140px);
    height: calc(100dvh - 140px);
  }

  .ai-chat-input-area {
    padding: 12px !important;
    padding-bottom: calc(12px + var(--crm-safe-bottom)) !important;
    gap: 10px;
  }

  .ai-chat-input-area input {
    padding: 14px 18px !important;
    font-size: 16px !important;
  }

  .ai-chat-input-area button {
    width: 48px !important;
    height: 48px !important;
  }

  /* AI Action buttons - stack on mobile */
  .ai-action-buttons {
    flex-direction: column !important;
    gap: 8px !important;
  }

  .ai-action-btn {
    width: 100% !important;
    justify-content: center !important;
    min-height: 44px !important;
    padding: 12px 16px !important;
  }

  /* AI Message bubbles - wider on mobile */
  .ai-message {
    max-width: 90% !important;
  }

  .ai-message-bubble {
    padding: 14px 16px !important;
    font-size: 15px !important;
  }

  /* Quick actions in chat */
  .ai-quick-actions {
    flex-wrap: wrap !important;
    gap: 8px !important;
  }

  .ai-quick-action-btn {
    flex: 1 1 calc(50% - 4px) !important;
    min-width: 120px !important;
    font-size: 13px !important;
  }
}

/* ============================================================
   DASHBOARD CARDS - Mobile Layout
   ============================================================ */

@media (max-width: 768px) {
  .dashboard-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 12px !important;
  }

  .stat-card {
    padding: 14px !important;
  }

  .stat-card h3 {
    font-size: 0.75rem !important;
    margin-bottom: 6px !important;
  }

  .stat-value,
  .stat-number {
    font-size: 1.5rem !important;
  }

  .stat-change {
    font-size: 0.7rem !important;
  }
}

@media (max-width: 480px) {
  .dashboard-grid {
    grid-template-columns: 1fr !important;
    gap: 10px !important;
  }

  .stat-card {
    padding: 16px !important;
    display: flex;
    align-items: center;
    gap: 12px;
  }

  .stat-card .stat-icon {
    width: 50px;
    height: 50px;
    flex-shrink: 0;
  }

  .stat-card h3 {
    font-size: 0.8rem !important;
  }

  .stat-value,
  .stat-number {
    font-size: 1.75rem !important;
  }
}

/* ============================================================
   TABLES & DATA GRIDS - Mobile Card View
   ============================================================ */

@media (max-width: 768px) {
  .data-table-container,
  .table-container {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 0 -12px;
    padding: 0 12px;
  }

  table {
    min-width: 600px;
    font-size: 0.9rem;
  }

  th, td {
    padding: 10px 8px !important;
    white-space: nowrap;
  }

  /* Sticky first column */
  table th:first-child,
  table td:first-child {
    position: sticky;
    left: 0;
    background: inherit;
    z-index: 1;
  }

  /* Action buttons in table cells */
  td .action-buttons,
  td .btn-group {
    flex-wrap: nowrap;
    gap: 4px;
  }

  td .btn {
    padding: 6px 10px !important;
    font-size: 0.8rem !important;
    min-height: 36px !important;
  }

  td .btn .btn-text {
    display: none;
  }

  td .btn i {
    margin: 0 !important;
  }
}

/* Card view alternative for very small screens */
@media (max-width: 480px) {
  .mobile-card-view table {
    display: block;
    min-width: 0;
  }

  .mobile-card-view thead {
    display: none;
  }

  .mobile-card-view tbody {
    display: flex;
    flex-direction: column;
    gap: 12px;
  }

  .mobile-card-view tr {
    display: block;
    background: var(--bg-card, white);
    border: 1px solid var(--border-color, #e5e7eb);
    border-radius: 12px;
    padding: 16px;
  }

  .mobile-card-view td {
    display: flex;
    justify-content: space-between;
    padding: 8px 0 !important;
    border-bottom: 1px solid var(--border-color, #e5e7eb);
  }

  .mobile-card-view td:last-child {
    border-bottom: none;
    justify-content: center;
    padding-top: 12px !important;
  }

  .mobile-card-view td::before {
    content: attr(data-label);
    font-weight: 600;
    color: var(--text-secondary, #6b7280);
    flex-shrink: 0;
    margin-right: 12px;
  }
}

/* ============================================================
   FORMS & INPUTS - Mobile Optimization
   ============================================================ */

@media (max-width: 768px) {
  .form-grid {
    grid-template-columns: 1fr !important;
    gap: 16px !important;
  }

  /* Stack inline form elements */
  .form-row,
  .form-inline {
    flex-direction: column !important;
    align-items: stretch !important;
  }

  input,
  select,
  textarea {
    width: 100% !important;
    min-height: 48px !important;
    padding: 14px 16px !important;
    font-size: 16px !important;
    border-radius: 10px !important;
  }

  textarea {
    min-height: 120px !important;
  }

  label {
    font-size: 0.9rem !important;
    margin-bottom: 6px !important;
    display: block;
  }

  /* Form group spacing */
  .form-group {
    margin-bottom: 16px !important;
  }

  /* Search inputs */
  .search-input,
  input[type="search"] {
    padding-left: 44px !important;
  }

  /* Checkbox and radio - larger touch targets */
  input[type="checkbox"],
  input[type="radio"] {
    width: 22px !important;
    height: 22px !important;
    min-height: 22px !important;
  }

  /* Select dropdowns */
  select {
    background-position: right 14px center !important;
    padding-right: 44px !important;
  }
}

/* ============================================================
   TYPOGRAPHY & SPACING
   ============================================================ */

@media (max-width: 768px) {
  h1 {
    font-size: 1.75rem !important;
  }

  h2 {
    font-size: 1.5rem !important;
  }

  h3 {
    font-size: 1.25rem !important;
  }

  h4 {
    font-size: 1.1rem !important;
  }

  p, li {
    font-size: 0.95rem;
    line-height: 1.6;
  }

  /* Content area padding */
  .content-area {
    padding: 16px !important;
  }

  /* Card padding */
  .card {
    padding: 16px !important;
    margin-bottom: 12px !important;
    border-radius: 12px !important;
  }

  .card-header {
    padding: 12px 16px !important;
    flex-wrap: wrap !important;
    gap: 10px !important;
  }

  .card-body {
    padding: 16px !important;
  }

  /* Spacing utilities */
  .mb-4 { margin-bottom: 1rem !important; }
  .mb-5 { margin-bottom: 1.25rem !important; }
  .p-4 { padding: 1rem !important; }
  .p-5 { padding: 1.25rem !important; }
}

@media (max-width: 480px) {
  h1 {
    font-size: 1.5rem !important;
  }

  h2 {
    font-size: 1.3rem !important;
  }

  h3 {
    font-size: 1.15rem !important;
  }

  .content-area {
    padding: 12px !important;
  }

  .card {
    padding: 14px !important;
  }
}

/* ============================================================
   BUTTONS - Touch Friendly
   ============================================================ */

@media (max-width: 768px) {
  button,
  .btn,
  a.btn {
    min-height: 44px !important;
    padding: 12px 20px !important;
    font-size: 0.95rem !important;
    border-radius: 10px !important;
    -webkit-tap-highlight-color: transparent;
  }

  /* Small buttons */
  .btn-sm {
    min-height: 38px !important;
    padding: 8px 14px !important;
    font-size: 0.85rem !important;
  }

  /* Large buttons */
  .btn-lg {
    min-height: 52px !important;
    padding: 14px 28px !important;
    font-size: 1.05rem !important;
  }

  /* Icon-only buttons */
  .btn-icon {
    width: 44px !important;
    height: 44px !important;
    padding: 0 !important;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  /* Button groups */
  .btn-group {
    flex-wrap: wrap !important;
    gap: 8px !important;
  }

  /* Full-width button utility */
  .btn-mobile-full {
    width: 100% !important;
  }
}

/* ============================================================
   HEADER - Mobile Optimizations
   ============================================================ */

@media (max-width: 768px) {
  .header {
    min-height: 60px;
    padding: 10px 16px !important;
    flex-wrap: wrap;
    gap: 8px;
  }

  .header-title,
  #pageTitle {
    font-size: 1.1rem !important;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: calc(100% - 120px);
  }

  .header-actions {
    gap: 8px !important;
  }

  .header-actions .btn {
    padding: 8px 12px !important;
  }

  .header-actions .btn .btn-text {
    display: none;
  }

  .header-actions .user-info span {
    display: none;
  }

  #serverStatus span {
    display: none;
  }
}

@media (max-width: 480px) {
  .header {
    padding: 8px 12px !important;
    padding-left: 58px !important;
  }

  .header-title,
  #pageTitle {
    font-size: 1rem !important;
    max-width: calc(100% - 100px);
  }
}

/* ============================================================
   TABS & NAVIGATION - Scrollable on Mobile
   ============================================================ */

@media (max-width: 768px) {
  .tab-navigation,
  .tabs,
  .nav-tabs {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    flex-wrap: nowrap !important;
    gap: 4px !important;
    padding-bottom: 8px;
    scrollbar-width: none;
    -ms-overflow-style: none;
  }

  .tab-navigation::-webkit-scrollbar,
  .tabs::-webkit-scrollbar,
  .nav-tabs::-webkit-scrollbar {
    display: none;
  }

  .tab-btn,
  .tab-button,
  .nav-tab {
    flex-shrink: 0 !important;
    white-space: nowrap !important;
    padding: 10px 16px !important;
    font-size: 0.9rem !important;
    min-height: 44px !important;
  }

  .tab-btn i,
  .tab-button i {
    margin-right: 6px !important;
  }
}

@media (max-width: 480px) {
  .tab-btn,
  .tab-button,
  .nav-tab {
    padding: 8px 12px !important;
    font-size: 0.85rem !important;
  }

  .tab-btn i,
  .tab-button i {
    display: none;
  }
}

/* ============================================================
   FILTER BARS & SEARCH - Mobile Layout
   ============================================================ */

@media (max-width: 768px) {
  .filter-bar,
  .search-bar,
  .toolbar {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 12px !important;
  }

  .filter-bar > *,
  .search-bar > *,
  .toolbar > * {
    width: 100% !important;
  }

  .filter-bar .btn-group {
    width: 100%;
    display: flex;
  }

  .filter-bar .btn-group .btn {
    flex: 1;
  }
}

/* ============================================================
   BADGES & TAGS - Mobile Sizes
   ============================================================ */

@media (max-width: 768px) {
  .badge,
  .tag,
  .label {
    padding: 4px 10px !important;
    font-size: 0.75rem !important;
    border-radius: 6px !important;
  }

  .badge-lg {
    padding: 6px 14px !important;
    font-size: 0.85rem !important;
  }
}

/* ============================================================
   UTILITY CLASSES - Mobile Visibility
   ============================================================ */

@media (max-width: 768px) {
  .hide-mobile,
  .desktop-only {
    display: none !important;
  }
}

@media (min-width: 769px) {
  .show-mobile,
  .mobile-only {
    display: none !important;
  }
}

/* Stack on mobile */
@media (max-width: 768px) {
  .stack-mobile {
    flex-direction: column !important;
  }

  .full-width-mobile {
    width: 100% !important;
  }

  .text-center-mobile {
    text-align: center !important;
  }
}

/* ============================================================
   ANIMATIONS - Reduced Motion Support
   ============================================================ */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ============================================================
   PERFORMANCE - Optimize Touch
   ============================================================ */

@media (max-width: 768px) {
  /* Improve scroll performance */
  .content-area,
  .modal-body,
  .sidebar,
  .ai-chat-messages {
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
  }

  /* Disable hover effects on touch devices */
  @media (hover: none) {
    *:hover {
      transform: none !important;
    }
  }
}

/* ============================================================
   LANDSCAPE MOBILE - Horizontal Layout Fixes
   ============================================================ */

@media (max-height: 500px) and (orientation: landscape) {
  .modal-content {
    max-height: 90vh !important;
    max-height: 90dvh !important;
  }

  .ai-chat-panel {
    width: 50% !important;
    right: -50% !important;
  }

  .ai-chat-panel.open {
    right: 0 !important;
  }

  .ai-chat-messages {
    height: calc(100vh - 120px) !important;
    height: calc(100dvh - 120px) !important;
  }

  .sidebar {
    padding-top: 10px !important;
    padding-bottom: 10px !important;
  }

  .nav-item {
    padding: 10px 16px !important;
  }
}

/* ============================================================
   SPECIFIC PAGE FIXES - Route Optimization
   ============================================================ */

@media (max-width: 768px) {
  .route-panels {
    grid-template-columns: 1fr !important;
    gap: 16px !important;
  }

  .route-config-panel {
    max-height: none !important;
    overflow-y: visible !important;
  }

  #routeMap {
    min-height: 300px !important;
    height: 300px !important;
  }

  #routeCustomerSelectionList {
    max-height: 350px !important;
  }
}

/* ============================================================
   SPECIFIC PAGE FIXES - Lead Marketplace
   ============================================================ */

@media (max-width: 768px) {
  #marketplaceLeadsGrid {
    grid-template-columns: 1fr !important;
    gap: 12px !important;
  }

  .marketplace-subtab-bar {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    flex-wrap: nowrap !important;
  }

  .marketplace-subtab {
    flex-shrink: 0 !important;
    padding: 10px 14px !important;
    font-size: 13px !important;
  }
}

/* ============================================================
   SPECIFIC PAGE FIXES - Customers & Invoices
   ============================================================ */

@media (max-width: 768px) {
  /* Customer profile modal */
  #customerProfileModal .modal-content {
    height: 95vh !important;
    height: 95dvh !important;
  }

  #customerProfileModal .profile-tabs {
    overflow-x: auto !important;
    flex-wrap: nowrap !important;
  }

  #customerProfileModal .profile-tab {
    flex-shrink: 0 !important;
    padding: 10px 14px !important;
  }

  /* Invoice view modal */
  #viewInvoiceModal .invoice-header {
    flex-direction: column !important;
    gap: 12px !important;
  }

  #viewInvoiceModal .invoice-actions {
    width: 100% !important;
    flex-direction: column !important;
    gap: 8px !important;
  }

  #viewInvoiceModal .invoice-actions .btn {
    width: 100% !important;
  }
}

/* ============================================================
   SPECIFIC PAGE FIXES - Settings
   ============================================================ */

@media (max-width: 768px) {
  .settings-grid {
    grid-template-columns: 1fr !important;
    gap: 16px !important;
  }

  .settings-card {
    padding: 16px !important;
  }

  .settings-tabs {
    overflow-x: auto !important;
    flex-wrap: nowrap !important;
  }

  .settings-tab {
    flex-shrink: 0 !important;
    white-space: nowrap !important;
  }
}

/* ============================================================
   SWIPE GESTURE HINT - Visual indicator for swipeable areas
   ============================================================ */

@media (max-width: 768px) {
  .swipe-hint {
    position: relative;
  }

  .swipe-hint::after {
    content: '';
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 40px;
    background: linear-gradient(to right, transparent, rgba(0,0,0,0.05));
    pointer-events: none;
  }
}

/* ============================================================
   PULL TO REFRESH INDICATOR (if implemented)
   ============================================================ */

.pull-to-refresh {
  display: none;
  position: fixed;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  padding: 12px 24px;
  background: var(--primary-color, #2563eb);
  color: white;
  border-radius: 0 0 12px 12px;
  z-index: 10001;
  font-size: 14px;
}

.pull-to-refresh.active {
  display: block;
  animation: slideDown 0.3s ease;
}

@keyframes slideDown {
  from {
    transform: translateX(-50%) translateY(-100%);
  }
  to {
    transform: translateX(-50%) translateY(0);
  }
}

/* ============================================================
   FLOATING ACTION BUTTON - Mobile Quick Actions
   ============================================================ */

@media (max-width: 768px) {
  .fab {
    position: fixed;
    bottom: calc(20px + var(--crm-safe-bottom));
    right: 20px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
    color: white;
    border: none;
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.4);
    z-index: 9990;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    cursor: pointer;
    transition: all 0.3s ease;
  }

  .fab:active {
    transform: scale(0.95);
  }

  .fab-menu {
    position: fixed;
    bottom: calc(90px + var(--crm-safe-bottom));
    right: 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px);
    transition: all 0.3s ease;
    z-index: 9989;
  }

  .fab-menu.open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
  }

  .fab-menu-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    background: white;
    border-radius: 24px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    font-size: 14px;
    white-space: nowrap;
  }

  .fab-menu-item i {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--primary-color, #2563eb);
    color: white;
  }
}

/* ============================================================
   COMPREHENSIVE MOBILE FIXES - January 2026 Audit
   Addresses layout issues found in mobile responsiveness audit
   ============================================================ */

/* ---- JOBS PAGE STATUS TABS ---- */
@media (max-width: 768px) {
  /* Jobs status tabs - horizontal scroll container */
  #jobs [style*="display: flex"][style*="gap: 8px"][style*="margin-bottom: 24px"] {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    flex-wrap: nowrap !important;
    padding-bottom: 8px;
    scrollbar-width: thin;
  }

  .job-status-tab {
    flex-shrink: 0 !important;
    min-width: auto !important;
    flex: 0 0 auto !important;
    padding: 10px 14px !important;
    font-size: 13px !important;
  }
}

@media (max-width: 480px) {
  .job-status-tab {
    padding: 8px 10px !important;
    font-size: 12px !important;
  }

  .job-status-tab i {
    margin-right: 4px !important;
  }

  .job-status-tab span {
    font-size: 10px !important;
  }
}

/* ---- SETTINGS TABS - Scrollable Container ---- */
@media (max-width: 768px) {
  #settings [style*="border-bottom: 2px solid"] [style*="display: flex"][style*="gap: 4px"] {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    flex-wrap: nowrap !important;
    padding-bottom: 8px;
    scrollbar-width: thin;
  }

  .settings-tab {
    flex-shrink: 0 !important;
    white-space: nowrap !important;
    padding: 10px 12px !important;
    font-size: 13px !important;
  }

  .settings-tab i {
    margin-right: 6px !important;
  }
}

@media (max-width: 480px) {
  .settings-tab {
    padding: 8px 10px !important;
    font-size: 11px !important;
  }

  /* Hide text, show only icons on very small screens */
  .settings-tab {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    min-width: 60px;
  }

  .settings-tab i {
    margin-right: 0 !important;
    font-size: 16px !important;
  }
}

/* ---- AI SCHEDULING MODAL TABS ---- */
@media (max-width: 768px) {
  #aiSchedulingModal [style*="display: flex"][style*="gap: 4px"][style*="margin-bottom: 24px"] {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    flex-wrap: nowrap !important;
  }

  .ai-schedule-tab {
    flex-shrink: 0 !important;
    white-space: nowrap !important;
    padding: 10px 12px !important;
    font-size: 13px !important;
  }
}

@media (max-width: 480px) {
  .ai-schedule-tab {
    padding: 8px 10px !important;
    font-size: 11px !important;
  }

  .ai-schedule-tab i {
    display: block !important;
    margin-bottom: 4px;
  }
}

/* ---- FORM GRIDS - Stack on Mobile ---- */
@media (max-width: 600px) {
  /* All inline grid-template-columns with 1fr 1fr */
  [style*="grid-template-columns: 1fr 1fr"],
  [style*="grid-template-columns:1fr 1fr"],
  .form-grid[style*="1fr 1fr"] {
    grid-template-columns: 1fr !important;
    gap: 16px !important;
  }

  /* Complex grids like 2fr 1fr */
  [style*="grid-template-columns: 2fr 1fr"],
  [style*="grid-template-columns:2fr 1fr"],
  [style*="grid-template-columns: 1fr 2fr"],
  [style*="grid-template-columns:1fr 2fr"] {
    grid-template-columns: 1fr !important;
    gap: 16px !important;
  }

  /* Triple column grids like 1fr 1fr 2fr */
  [style*="grid-template-columns: 1fr 1fr 1fr"],
  [style*="grid-template-columns: 1fr 1fr 2fr"] {
    grid-template-columns: 1fr !important;
    gap: 12px !important;
  }

  /* Modal form grids */
  .modal-body .form-grid,
  .modal-body [style*="grid-template-columns"] {
    grid-template-columns: 1fr !important;
  }
}

/* ---- DASHBOARD STAT GRIDS - Better Mobile Layout ---- */
@media (max-width: 600px) {
  /* Override minmax(280px) which is too wide for small phones */
  [style*="minmax(280px"],
  [style*="minmax(300px"] {
    grid-template-columns: 1fr !important;
  }

  /* AI Center quick stats - stack or 2 columns */
  #aiCenterQuickStats,
  [style*="repeat(4, 1fr)"] {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 10px !important;
  }

  /* Dashboard grid compact */
  .dashboard-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 10px !important;
  }
}

@media (max-width: 380px) {
  /* Very small phones - single column */
  .dashboard-grid,
  #aiCenterQuickStats,
  [style*="repeat(4, 1fr)"],
  [style*="repeat(2, 1fr)"] {
    grid-template-columns: 1fr !important;
  }
}

/* ---- ROUTE HISTORY FILTER BAR ---- */
@media (max-width: 768px) {
  #routeHistoryStartDate,
  #routeHistoryEndDate,
  #routeHistoryTruckFilter {
    width: 100% !important;
    min-width: unset !important;
  }

  /* Route history controls wrapper - stack */
  #routes [style*="display: flex"][style*="gap: 8px"][style*="align-items: center"] {
    flex-wrap: wrap !important;
  }
}

/* ---- CUSTOMER ANALYTICS FILTERS ---- */
@media (max-width: 768px) {
  #customerAnalyticsSearch,
  #customerSortBy {
    width: 100% !important;
    min-width: unset !important;
    max-width: none !important;
  }

  /* Wrap filter containers */
  #analytics [style*="display: flex"][style*="gap: 12px"] {
    flex-wrap: wrap !important;
  }
}

/* ---- LEAD MARKETPLACE FILTERS ---- */
@media (max-width: 768px) {
  #marketplaceServiceFilter,
  #leads select[style*="min-width"] {
    width: 100% !important;
    min-width: unset !important;
  }

  /* Marketplace subtabs - horizontal scroll */
  .marketplace-subtab-bar,
  #lead-marketplace [style*="display: flex"][style*="gap"][style*="border-bottom"] {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    flex-wrap: nowrap !important;
    padding-bottom: 8px;
  }

  .marketplace-subtab {
    flex-shrink: 0 !important;
    white-space: nowrap !important;
  }
}

/* ---- CARD ACTIONS - Ensure Wrapping ---- */
@media (max-width: 768px) {
  .card-actions {
    flex-wrap: wrap !important;
    gap: 8px !important;
  }

  .card-actions > * {
    flex: 0 1 auto !important;
  }

  /* Card header wrapper */
  .card-header {
    flex-wrap: wrap !important;
    gap: 12px !important;
  }

  /* Card header title - full width */
  .card-header .card-title,
  .card-header h3 {
    width: 100% !important;
    flex: 1 1 100% !important;
  }

  /* Card actions below title */
  .card-header .card-actions {
    width: 100% !important;
  }
}

/* ---- MODAL MAX-WIDTH FIXES ---- */
@media (max-width: 600px) {
  /* Ensure all modals respect viewport */
  .modal-content {
    width: 95vw !important;
    max-width: 95vw !important;
    margin: 10px !important;
  }

  /* Large modals (700px+) */
  .modal-content[style*="max-width: 700px"],
  .modal-content[style*="max-width: 800px"],
  .modal-content[style*="max-width: 900px"],
  .modal-content[style*="max-width: 1000px"],
  .modal-content[style*="max-width: 1100px"] {
    max-width: 95vw !important;
    width: 95vw !important;
  }
}

/* ---- BUTTON TEXT OVERFLOW ---- */
@media (max-width: 480px) {
  /* Buttons with long text - truncate or wrap */
  .btn,
  button {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  /* Icon-only buttons on very small screens for action buttons */
  .card-actions .btn .btn-text,
  .action-buttons .btn span:not(.sr-only) {
    display: none;
  }

  .card-actions .btn i,
  .action-buttons .btn i {
    margin: 0 !important;
  }
}

/* ---- QUOTE GENERATION MODAL GRIDS ---- */
@media (max-width: 600px) {
  #generateQuoteFromLeadModal [style*="grid-template-columns: 2fr 1fr"],
  #generateQuoteFromLeadModal [style*="grid-template-columns: 1fr 1fr 2fr"] {
    grid-template-columns: 1fr !important;
    gap: 12px !important;
  }

  /* Address input with satellite button - stack */
  #generateQuoteFromLeadModal [style*="display: flex"][style*="gap: 8px"]:has(input) {
    flex-wrap: wrap !important;
  }

  #generateQuoteFromLeadModal [style*="display: flex"][style*="gap: 8px"] input {
    width: 100% !important;
    flex: 1 1 100% !important;
  }
}

/* ---- AI CENTER TABS ---- */
@media (max-width: 768px) {
  #ai-center .tab-navigation,
  #ai-center [style*="display: flex"][style*="border-bottom"] {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    flex-wrap: nowrap !important;
  }
}

/* ---- PLANNING TABS ---- */
@media (max-width: 768px) {
  .planning-tabs {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    flex-wrap: nowrap !important;
  }

  .planning-tabs button {
    flex-shrink: 0 !important;
    white-space: nowrap !important;
  }
}

/* ---- EQUIPMENT & INVENTORY GRIDS ---- */
@media (max-width: 600px) {
  #equipment .dashboard-grid,
  #inventory .dashboard-grid {
    grid-template-columns: 1fr !important;
  }

  #equipmentCostSummary {
    grid-template-columns: 1fr !important;
  }
}

/* ---- WEATHER FORECAST GRID ---- */
@media (max-width: 480px) {
  #weatherForecast,
  [style*="minmax(100px"] {
    grid-template-columns: repeat(3, 1fr) !important;
    gap: 8px !important;
  }
}

@media (max-width: 360px) {
  #weatherForecast,
  [style*="minmax(100px"] {
    grid-template-columns: repeat(2, 1fr) !important;
  }
}

/* ---- FLEX GAP CONTAINERS - Wrap on Mobile ---- */
@media (max-width: 600px) {
  /* Any flex container with large gaps should wrap */
  [style*="display: flex"][style*="gap: 24px"],
  [style*="display: flex"][style*="gap: 32px"],
  [style*="display: flex"][style*="gap: 20px"] {
    flex-wrap: wrap !important;
    gap: 12px !important;
  }

  /* Child elements should be full width when stacked */
  [style*="display: flex"][style*="gap: 24px"] > *,
  [style*="display: flex"][style*="gap: 32px"] > * {
    flex: 1 1 100% !important;
    min-width: 0 !important;
  }
}

/* ---- HEADER ACTIONS MOBILE ---- */
@media (max-width: 480px) {
  .header-actions {
    gap: 6px !important;
  }

  .header-actions .btn {
    padding: 8px 10px !important;
    font-size: 12px !important;
  }

  /* Hide button text on very small screens */
  .header-actions .btn span {
    display: none;
  }
}

/* ---- INLINE STYLE WIDTH OVERRIDES ---- */
@media (max-width: 600px) {
  /* Override any fixed widths in inline styles */
  input[style*="width: 140px"],
  input[style*="width: 160px"],
  input[style*="width: 200px"],
  input[style*="width: 250px"],
  input[style*="width: 300px"],
  select[style*="width: 140px"],
  select[style*="width: 160px"],
  select[style*="width: 200px"] {
    width: 100% !important;
    min-width: unset !important;
  }

  /* Max-width containers */
  [style*="max-width: 800px"],
  [style*="max-width: 1000px"],
  [style*="max-width: 1200px"] {
    max-width: 100% !important;
    padding-left: 12px !important;
    padding-right: 12px !important;
  }
}

/* ---- DATE/TIME INPUT PAIRS ---- */
@media (max-width: 600px) {
  /* Create Job Modal date/time grid */
  #createJobModal [style*="grid-template-columns: 1fr 1fr"] {
    grid-template-columns: 1fr !important;
  }
}

/* ---- SCROLL INDICATORS FOR HORIZONTAL SCROLL AREAS ---- */
@media (max-width: 768px) {
  /* Add fade hint for scrollable areas */
  .job-status-tab:last-child::after,
  .settings-tab:last-child::after,
  .ai-schedule-tab:last-child::after {
    content: '';
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 20px;
    background: linear-gradient(to right, transparent, var(--bg-primary, white));
    pointer-events: none;
  }
}

/* ---- ENSURE NO HORIZONTAL OVERFLOW ---- */
@media (max-width: 768px) {
  .page-section,
  .content-area,
  .card,
  .card-content,
  .modal-body {
    overflow-x: hidden;
    max-width: 100vw;
  }

  /* But allow scroll in designated areas */
  .table-container,
  .data-table-container,
  [style*="overflow-x: auto"] {
    overflow-x: auto !important;
    max-width: 100%;
  }
  
  /* AI Learning section responsive fixes */
  #ai-learning .card-header {
    flex-direction: column;
    align-items: flex-start !important;
  }
  
  #ai-learning .card-header > div {
    width: 100%;
    justify-content: flex-start !important;
  }
  
  /* Learning stats grid - 2 columns on mobile */
  #learningStatsGrid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 12px !important;
  }
  
  #learningStatsGrid > div {
    padding: 16px !important;
  }
  
  #learningStatsGrid > div > div:first-child {
    font-size: 24px !important;
  }
  
  /* Learning tabs - scrollable on mobile */
  .learning-tab-pane {
    max-width: 100%;
    overflow-x: hidden;
  }
  
  /* Timeline filter dropdown */
  #learningTimelineFilter {
    width: 150px !important;
  }
}

/* ---- TOUCH IMPROVEMENTS ---- */
@media (max-width: 768px) and (hover: none) {
  /* Remove hover effects that don't work on touch */
  .btn:hover,
  .card:hover,
  .nav-item:hover {
    transform: none !important;
  }

  /* Larger tap targets */
  .nav-item,
  .settings-tab,
  .job-status-tab,
  .tab-btn {
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
  }
}

/* ============================================================
   iPHONE PRO (393px) & SMALL MOBILE FIXES
   ============================================================ */

/* Fix for 1fr 400px grid layout (route map) */
@media (max-width: 600px) {
  [style*="grid-template-columns: 1fr 400px"],
  [style*="grid-template-columns:1fr 400px"] {
    grid-template-columns: 1fr !important;
    gap: 16px !important;
  }
  
  [style*="grid-template-columns: 400px 1fr"],
  [style*="grid-template-columns:400px 1fr"] {
    grid-template-columns: 1fr !important;
    gap: 16px !important;
  }
}

/* Fix for minmax(300px+) grids - force single column */
@media (max-width: 420px) {
  [style*="minmax(300px"],
  [style*="minmax(320px"],
  [style*="minmax(350px"],
  [style*="minmax(400px"] {
    grid-template-columns: 1fr !important;
  }
  
  /* Force all repeat grids to single column on very small screens */
  [style*="repeat(auto-fit"],
  [style*="repeat(auto-fill"] {
    grid-template-columns: 1fr !important;
  }
}

/* 4-column grids -> 2 columns on small mobile */
@media (max-width: 480px) {
  [style*="repeat(4, 1fr)"],
  [style*="repeat(4,1fr)"] {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 10px !important;
  }
  
  /* 3-column grids -> 2 columns */
  [style*="repeat(3, 1fr)"],
  [style*="repeat(3,1fr)"] {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 10px !important;
  }
}

/* Very small screens - single column for all grids */
@media (max-width: 380px) {
  [style*="repeat(4, 1fr)"],
  [style*="repeat(4,1fr)"],
  [style*="repeat(3, 1fr)"],
  [style*="repeat(3,1fr)"],
  [style*="repeat(2, 1fr)"],
  [style*="repeat(2,1fr)"] {
    grid-template-columns: 1fr !important;
  }
}

/* AI Command Bar - optimize for very small screens */
@media (max-width: 420px) {
  .ai-command-bar {
    min-width: 0 !important;
    max-width: calc(100% - 100px) !important;
  }
  
  .ai-command-input {
    font-size: 13px !important;
    padding: 8px 12px !important;
  }
  
  .ai-command-bar input::placeholder {
    font-size: 12px !important;
  }
}

/* Header adjustments for iPhone Pro */
@media (max-width: 420px) {
  .header {
    padding: 8px 10px !important;
    padding-left: 54px !important;
    gap: 6px !important;
  }
  
  .header-actions {
    gap: 4px !important;
  }
  
  .header-actions .btn {
    padding: 6px 8px !important;
    min-height: 36px !important;
  }
  
  #serverStatus {
    padding: 4px 6px !important;
    font-size: 10px !important;
  }
  
  #serverStatus span,
  #serverStatus .status-text {
    display: none !important;
  }
  
  .user-info {
    padding: 4px 8px !important;
  }
  
  .user-info span:not(.user-initials) {
    display: none !important;
  }
}

/* Fix stat cards on very small screens */
@media (max-width: 380px) {
  .stat-card {
    flex-direction: column !important;
    text-align: center !important;
    padding: 14px 12px !important;
  }
  
  .stat-card .stat-icon {
    margin: 0 auto 8px !important;
  }
  
  .stat-value,
  .stat-number {
    font-size: 1.5rem !important;
  }
  
  .stat-card h3,
  .stat-label {
    font-size: 0.7rem !important;
  }
}

/* Mobile menu button positioning for notch phones */
@media (max-width: 420px) {
  .mobile-menu-btn {
    top: 8px;
    left: 8px;
    width: 42px;
    height: 42px;
    font-size: 16px;
    border-radius: 10px;
  }
}

/* Fix filter dropdowns and inputs on small screens */
@media (max-width: 420px) {
  .filter-bar select,
  .toolbar select,
  [class*="filter"] select {
    font-size: 13px !important;
    padding: 8px 30px 8px 10px !important;
    min-width: 0 !important;
    width: auto !important;
    max-width: 100% !important;
  }
  
  .filter-bar input,
  .toolbar input {
    font-size: 14px !important;
    padding: 8px 12px !important;
  }
}

/* Ensure content doesn't overflow on small screens */
@media (max-width: 420px) {
  .content-area {
    padding: 10px !important;
    overflow-x: hidden !important;
  }
  
  .page-section {
    overflow-x: hidden !important;
  }
  
  .card {
    margin-left: 0 !important;
    margin-right: 0 !important;
    border-radius: 10px !important;
  }
}

/* Modal adjustments for iPhone Pro */
@media (max-width: 420px) {
  .modal-content {
    margin: 0 !important;
    border-radius: 16px 16px 0 0 !important;
    max-height: 90dvh !important;
  }
  
  .modal-header {
    padding: 12px 16px !important;
  }
  
  .modal-header h2,
  .modal-header h3,
  .modal-title {
    font-size: 1rem !important;
  }
  
  .modal-body {
    padding: 12px !important;
  }
  
  .modal-footer {
    padding: 10px 12px !important;
    gap: 6px !important;
  }
  
  .modal-footer .btn {
    padding: 10px 14px !important;
    font-size: 0.9rem !important;
  }
}

/* Form improvements for iPhone Pro */
@media (max-width: 420px) {
  .form-group {
    margin-bottom: 14px !important;
  }
  
  .form-group label {
    font-size: 0.85rem !important;
    margin-bottom: 4px !important;
  }
  
  input, select, textarea {
    padding: 12px 14px !important;
    font-size: 16px !important; /* Prevents iOS zoom */
  }
  
  /* Form action buttons - stack */
  .form-actions {
    flex-direction: column !important;
    gap: 8px !important;
  }
  
  .form-actions .btn {
    width: 100% !important;
  }
}

/* Fix specific problematic inline styles */
@media (max-width: 600px) {
  /* Route planning section */
  #routeMap {
    min-height: 300px !important;
    height: 50vh !important;
  }
  
  /* Customer list in route planning */
  #routeCustomerSelectionList {
    max-height: 40vh !important;
  }
  
  /* Settings sections */
  .settings-section,
  [id*="settings"] .card {
    width: 100% !important;
    max-width: 100% !important;
  }
}

/* AI quick actions - scrollable on small screens */
@media (max-width: 420px) {
  .ai-quick-actions {
    display: flex !important;
    flex-wrap: nowrap !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 8px !important;
    gap: 6px !important;
  }
  
  .ai-quick-actions::-webkit-scrollbar {
    display: none;
  }
  
  .ai-quick-action-btn {
    flex-shrink: 0 !important;
    min-width: auto !important;
    padding: 8px 12px !important;
    font-size: 12px !important;
  }
}

/* Notification toasts - better positioning on mobile */
@media (max-width: 420px) {
  .notification,
  .toast,
  [class*="notification"],
  [class*="toast"] {
    left: 10px !important;
    right: 10px !important;
    max-width: calc(100% - 20px) !important;
    width: auto !important;
    bottom: calc(20px + var(--crm-safe-bottom)) !important;
  }
}


/* ════════════════════════════════════════════════════════════════════════
   MOBILE AI-FIRST EXPERIENCE (v3.0)
   Bottom navigation, AI Command Center, business profile
   ════════════════════════════════════════════════════════════════════════ */

/* ── Mobile Bottom Navigation ──────────────────────────────────────────── */
.mobile-bottom-nav {
  display: none; /* Hidden on desktop */
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 9998;
  background: var(--bg-primary, #ffffff);
  border-top: 1px solid var(--border-color, #e2e8f0);
  padding: 4px 0 calc(4px + var(--crm-safe-bottom, 0px));
  justify-content: space-around;
  align-items: center;
  box-shadow: 0 -2px 10px rgba(0,0,0,0.08);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

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

  /* Adjust content area so nothing hides behind bottom nav */
  .content-area {
    padding-bottom: 80px !important;
  }

  /* Move the AI FAB above bottom nav */
  .floating-ai-btn,
  #aiAssistantFab {
    bottom: calc(72px + var(--crm-safe-bottom, 0px)) !important;
    display: none !important; /* Hide FAB on mobile — we have bottom nav now */
  }

  /* On mobile, AI Command Center is the default home */
  #ai-command-center.page-section.active ~ #dashboard.page-section.active {
    display: none;
  }
}

.mobile-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 6px 12px;
  border: none;
  background: transparent;
  color: var(--text-secondary, #64748b);
  font-size: 10px;
  font-weight: 500;
  cursor: pointer;
  transition: color 0.2s;
  min-width: 56px;
  -webkit-tap-highlight-color: transparent;
}

.mobile-nav-item i {
  font-size: 18px;
  transition: transform 0.2s, color 0.2s;
}

.mobile-nav-item.active {
  color: #667eea;
}

.mobile-nav-item.active i {
  transform: scale(1.1);
}

.mobile-nav-item:active {
  transform: scale(0.95);
}

/* ── AI Command Center ─────────────────────────────────────────────────── */
.ai-cc-metric-card {
  background: var(--bg-secondary, #f8fafc);
  border: 1px solid var(--border-color, #e2e8f0);
  border-radius: 12px;
  padding: 14px;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.ai-cc-metric-card:active {
  transform: scale(0.97);
}

.ai-cc-metric-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
}

.ai-cc-metric-value {
  font-size: 24px;
  font-weight: 700;
  color: var(--text-primary, #1e293b);
  line-height: 1;
}

.ai-cc-metric-label {
  font-size: 12px;
  color: var(--text-secondary, #64748b);
  font-weight: 500;
}

.ai-cc-action-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px;
  background: var(--bg-secondary, #f8fafc);
  border: 1px solid var(--border-color, #e2e8f0);
  border-radius: 12px;
  cursor: pointer;
  transition: transform 0.15s, background 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.ai-cc-action-btn i {
  font-size: 16px;
  width: 20px;
  text-align: center;
}

.ai-cc-action-btn span {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary, #1e293b);
}

.ai-cc-action-btn:active {
  transform: scale(0.97);
  background: var(--bg-tertiary, #f1f5f9);
}

/* AI CC Chat Bar */
.ai-cc-chat-bar {
  display: flex;
  gap: 8px;
  background: var(--bg-secondary, #f8fafc);
  border: 2px solid var(--border-color, #e2e8f0);
  border-radius: 16px;
  padding: 6px 6px 6px 16px;
  transition: border-color 0.2s;
}

.ai-cc-chat-bar:focus-within {
  border-color: #667eea;
  box-shadow: 0 0 0 3px rgba(102,126,234,0.15);
}

.ai-cc-chat-bar input {
  flex: 1;
  border: none;
  background: transparent;
  font-size: 14px;
  color: var(--text-primary, #1e293b);
  outline: none;
  min-width: 0;
}

.ai-cc-chat-bar input::placeholder {
  color: var(--text-secondary, #94a3b8);
}

.ai-cc-send-btn {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  border: none;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  transition: transform 0.15s;
  flex-shrink: 0;
}

.ai-cc-send-btn:active {
  transform: scale(0.92);
}

/* ── Business Profile Settings ─────────────────────────────────────────── */
.profile-field-group {
  margin-bottom: 20px;
}

.profile-field-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary, #1e293b);
  margin-bottom: 6px;
}

.profile-field-group select,
.profile-field-group input,
.profile-field-group textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border-color, #e2e8f0);
  border-radius: 8px;
  font-size: 14px;
  color: var(--text-primary, #1e293b);
  background: var(--bg-primary, #ffffff);
}

.profile-chip-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 4px;
}

.profile-chip {
  padding: 6px 14px;
  border-radius: 20px;
  border: 1px solid var(--border-color, #e2e8f0);
  background: var(--bg-secondary, #f8fafc);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
  color: var(--text-secondary, #64748b);
  -webkit-tap-highlight-color: transparent;
}

.profile-chip.selected {
  background: rgba(102,126,234,0.15);
  border-color: #667eea;
  color: #667eea;
  font-weight: 500;
}

.profile-chip:active {
  transform: scale(0.96);
}

/* ── Dark Mode for new components ──────────────────────────────────────── */
[data-theme="dark"] .mobile-bottom-nav {
  background: rgba(15, 23, 42, 0.95);
  border-top-color: rgba(255,255,255,0.08);
}

[data-theme="dark"] .ai-cc-metric-card {
  background: rgba(30, 41, 59, 0.8);
  border-color: rgba(255,255,255,0.08);
}

[data-theme="dark"] .ai-cc-action-btn {
  background: rgba(30, 41, 59, 0.8);
  border-color: rgba(255,255,255,0.08);
}

[data-theme="dark"] .ai-cc-chat-bar {
  background: rgba(30, 41, 59, 0.8);
  border-color: rgba(255,255,255,0.1);
}

[data-theme="dark"] .profile-chip {
  background: rgba(30, 41, 59, 0.6);
  border-color: rgba(255,255,255,0.1);
  color: #94a3b8;
}

[data-theme="dark"] .profile-chip.selected {
  background: rgba(102,126,234,0.2);
  border-color: #667eea;
  color: #818cf8;
}

/* ── Mobile-specific adjustments ───────────────────────────────────────── */
@media (max-width: 480px) {
  .ai-cc-metric-card {
    padding: 12px;
  }
  .ai-cc-metric-value {
    font-size: 20px;
  }
  .ai-cc-action-btn {
    padding: 12px;
  }
  .ai-cc-action-btn span {
    font-size: 12px;
  }
  /* Notifications above bottom nav */
  .notification,
  .toast,
  [class*="notification"],
  [class*="toast"] {
    bottom: calc(80px + var(--crm-safe-bottom, 0px)) !important;
  }
}


/* ═══════════════════════════════════════════════════════════════
   NOTIFICATION BELL & PANEL (v3.1)
   ═══════════════════════════════════════════════════════════════ */

.notification-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  background: #ef4444;
  color: white;
  font-size: 10px;
  font-weight: 700;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
  box-shadow: 0 1px 3px rgba(239,68,68,0.3);
  animation: badge-pop 0.3s ease;
}

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

.notification-panel {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 360px;
  max-height: 480px;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.2);
  z-index: 9999;
  overflow: hidden;
}

.notification-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-color);
  background: var(--bg-secondary);
}

.notification-list {
  max-height: 400px;
  overflow-y: auto;
}

.notification-item {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-color);
  transition: background 0.15s;
  cursor: default;
}

.notification-item:hover {
  background: var(--bg-secondary);
}

.notification-item.unread {
  background: rgba(102,126,234,0.04);
  border-left: 3px solid #667eea;
}

.notification-item-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}

.notification-icon {
  font-size: 16px;
  flex-shrink: 0;
}

.notification-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.notification-time {
  font-size: 11px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.notification-message {
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.4;
  margin-bottom: 6px;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.notification-actions {
  display: flex;
  gap: 6px;
}

.notif-action-btn {
  font-size: 11px;
  padding: 3px 8px;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  background: none;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s;
}

.notif-action-btn:hover {
  background: var(--bg-secondary);
}

.notif-action-btn.primary {
  background: #667eea;
  color: white;
  border-color: #667eea;
}

.notif-action-btn.primary:hover {
  background: #5a6fe0;
}

.notif-action-btn.dismiss {
  color: var(--text-muted);
}

.notif-action-btn.dismiss:hover {
  color: #ef4444;
  border-color: #ef4444;
}

@media (max-width: 768px) {
  .notification-panel {
    width: calc(100vw - 16px);
    right: -8px;
    max-height: 60vh;
  }
}


/* ═══════════════════════════════════════════════════════════════
   VOICE INPUT STYLES (v3.1)
   ═══════════════════════════════════════════════════════════════ */

.ai-cc-voice-btn,
.ai-voice-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 16px;
  padding: 8px;
  cursor: pointer;
  border-radius: 50%;
  transition: all 0.2s;
}

.ai-cc-voice-btn:hover,
.ai-voice-btn:hover {
  color: #667eea;
  background: rgba(102,126,234,0.1);
}

.voice-active {
  color: #ef4444 !important;
  animation: voice-pulse 1.5s ease infinite;
}

@keyframes voice-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239,68,68,0.3); }
  50% { box-shadow: 0 0 0 10px rgba(239,68,68,0); }
}

.voice-listening {
  border-color: #ef4444 !important;
  box-shadow: 0 0 0 2px rgba(239,68,68,0.2) !important;
}


/* ═══════════════════════════════════════════════════════════════
   AI AUTO-ACTIONS CARDS (v3.1)
   ═══════════════════════════════════════════════════════════════ */

.auto-action-card {
  background: var(--bg-secondary);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 10px;
  border: 1px solid var(--border-color);
  transition: all 0.15s;
}

.auto-action-card:hover {
  border-color: #667eea;
  box-shadow: 0 2px 8px rgba(102,126,234,0.1);
}

.auto-action-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}

.auto-action-icon {
  font-size: 18px;
  flex-shrink: 0;
}

.auto-action-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}

.auto-action-desc {
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.4;
  margin-bottom: 10px;
}

.auto-action-buttons {
  display: flex;
  gap: 8px;
}

.auto-action-btn {
  font-size: 12px;
  padding: 6px 14px;
  border-radius: 6px;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
  transition: all 0.15s;
}

.auto-action-btn.execute {
  background: linear-gradient(135deg, #667eea, #764ba2);
  color: white;
}

.auto-action-btn.execute:hover {
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(102,126,234,0.3);
}

.auto-action-btn.dismiss {
  background: var(--bg-primary);
  color: var(--text-muted);
  border: 1px solid var(--border-color);
}

.auto-action-btn.dismiss:hover {
  color: #ef4444;
  border-color: #ef4444;
}
