/* ========== COMPREHENSIVE RESPONSIVE BREAKPOINTS ========== */
/* Smooth transitions between all breakpoints for seamless desktop-to-mobile experience */

/* Global transition rules for smooth responsive behavior */
* {
  transition: padding 0.3s ease, margin 0.3s ease, font-size 0.3s ease, width 0.3s ease, height 0.3s ease;
}

.container,
.app-container,
.sidebar,
.main-content,
.nav-item,
.logo,
.header,
.user-info,
.dashboard-tiles,
.metric-btn,
.btn {
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Large Desktop (1200px+) - Default desktop styles */
/* No media query needed - default styles */

/* Medium Desktop and Large Tablets (1024px - 1199px) - PROPER DESKTOP LAYOUT */
@media (max-width: 1199px) and (min-width: 1024px) {
  .container {
    padding: 15px;
  }

  .app-container {
    height: calc(100vh - 30px);
    border-radius: 12px;
  }

  /* Keep sidebar vertical but narrower */
  .sidebar {
    width: 240px; /* Narrower than 280px default */
    padding: 15px 12px;
    max-height: 100vh; /* Full height - NOT 80px */
  }

  .nav-item {
    padding: 10px 14px;
    font-size: 14px;
  }

  .desktop-logo {
    margin-bottom: 32px;
  }

  .pharmacy-name-container {
    padding: 15px 16px;
  }

  .pharmacy-name-display {
    font-size: 18px;
  }

  .main-content {
    padding: 15px;
  }

  .header {
    padding: 15px;
    margin-bottom: 20px;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
  }

  .user-info {
    margin-left: auto;
  }

  .dashboard-tiles {
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 15px;
  }

  /* Tables remain desktop-style */
  .table-container {
    overflow-x: auto;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  }

  .metric-btn {
    padding: 12px 14px;
    font-size: 14px;
  }

  .btn {
    padding: 8px 14px;
    font-size: 14px;
  }

  .modal-content {
    max-width: 90%;
    width: 90%;
  }
}

/* Small Tablets (769px - 1023px) - COMPACT DESKTOP OR SWITCH TO MOBILE */
@media (max-width: 1023px) and (min-width: 900px) {
  /* At this range, sidebar should be narrower but still vertical */
  .sidebar {
    width: 200px; /* Even narrower */
    padding: 12px 8px;
    max-height: 100vh; /* Keep full height */
  }

  .nav-item {
    padding: 8px 10px;
    font-size: 13px;
  }

  .desktop-logo {
    margin-bottom: 28px;
  }

  .pharmacy-name-container {
    padding: 14px 14px;
  }

  .pharmacy-name-display {
    font-size: 16px;
  }

  .main-content {
    padding: 12px;
  }

  /* Tables become scrollable */
  .table-container {
    overflow-x: auto;
    font-size: 13px;
  }
}

/* ========== CLEAN DESKTOP TO MOBILE TRANSITION ========== */
/* When sidebar can't fit properly (at ~1000px), switch to mobile dropdown menu */

/* Responsive inventory summary layout */
@media (max-width:768px){
  .inventory-summary > div[style*="display: flex"] {
    flex-direction: column !important;
    gap: 16px !important;
  }
  .inventory-summary > div[style*="display: flex"] > div {
    min-width: auto !important;
  }
}

/* Enhanced mobile navigation - collapsible sidebar */
@media (max-width: 900px) {
  .app-container {
    flex-direction: column;
    height: auto;
    border-radius: 10px;
  }

  .sidebar {
    width: 100%;
    flex-direction: row;
    overflow-x: auto;
    padding: 10px 15px;
    position: sticky;
    top: 0;
    z-index: 1000;
    max-height: 80px;
    scrollbar-width: thin;
  }

  .sidebar::-webkit-scrollbar {
    height: 4px;
  }

  .sidebar::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.3);
    border-radius: 2px;
  }

  .nav-item {
    white-space: nowrap;
    min-width: 120px;
    padding: 8px 12px;
    margin: 2px 4px;
    font-size: 14px;
    text-align: center;
    justify-content: center;
  }

  .nav-item:hover,
  .nav-item.active {
    transform: translateY(-2px);
  }

  .logo {
    font-size: 18px;
    margin-bottom: 8px;
    margin-right: 20px;
    flex-shrink: 0;
  }

  .user-profile-card {
    min-width: 200px;
    flex-shrink: 0;
    margin-left: auto;
    padding: 8px;
  }

  .user-avatar {
    width: 40px;
    height: 40px;
    font-size: 16px;
  }

  .user-name {
    font-size: 13px;
  }

  .user-role {
    font-size: 11px;
  }

  .main-content {
    padding: 15px;
  }

  .header {
    padding: 15px;
    margin-bottom: 20px;
  }

  .pos-grid {
    grid-template-columns: 1fr;
    height: auto;
    gap: 15px;
  }

  .pos-grid > div:last-child {
    max-height: 50vh;
  }

  #cartItems {
    max-height: 35vh;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    padding-right: 4px;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.3) transparent;
  }

  #cartItems::-webkit-scrollbar {
    width: 6px;
  }

  #cartItems::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
  }

  #cartItems::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.3);
    border-radius: 3px;
  }

  #cartItems::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.5);
  }

  /* Smooth scrolling and better visibility for cart items */
  #cartItems {
    scroll-behavior: smooth;
  }

  /* Enhanced cart item visibility on mobile */
  .cart-item {
    min-height: 60px;
    display: flex;
    align-items: center;
    word-wrap: break-word;
    overflow-wrap: break-word;
  }

  .cart-item-name {
    font-weight: 600;
    color: white;
    flex: 1;
    min-width: 0;
  }

  .cart-item-details {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
  }

  .pos-alert-tiles {
    flex-direction: column;
    height: auto;
    gap: 8px;
  }

  .pos-alert-tile {
    min-height: 50px;
  }

  .filter-controls {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  .filter-group {
    min-width: auto;
  }
}

/* Responsive KPI tiles - allow text wrapping to show all content */
.kpi-card, .inventory-tile {
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.kpi-card > div,
.inventory-tile > div {
  word-wrap: break-word;
  overflow-wrap: break-word;
}

/* Make tile text responsive to container size - progressively smaller fonts */
@media (max-width: 1200px) {
  .kpi-card div[style*="font-size: 32px"],
  .inventory-tile div[style*="font-size: 32px"] {
    font-size: 28px !important;
  }
  
  .kpi-card div[style*="font-size: 13px"],
  .inventory-tile div[style*="font-size: 13px"] {
    font-size: 12px !important;
  }
  
  .kpi-grid {
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)) !important;
  }
}

@media (max-width: 1000px) {
  .kpi-card div[style*="font-size: 32px"],
  .inventory-tile div[style*="font-size: 32px"] {
    font-size: 24px !important;
  }
  
  .kpi-card div[style*="font-size: 24px"],
  .inventory-tile div[style*="font-size: 24px"] {
    font-size: 20px !important;
  }
  
  .kpi-card div[style*="font-size: 13px"],
  .inventory-tile div[style*="font-size: 13px"] {
    font-size: 11px !important;
  }
  
  .kpi-grid {
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)) !important;
  }
}

@media (max-width: 800px) {
  .kpi-card div[style*="font-size: 32px"],
  .inventory-tile div[style*="font-size: 32px"] {
    font-size: 22px !important;
  }
  
  .kpi-card div[style*="font-size: 24px"],
  .inventory-tile div[style*="font-size: 24px"] {
    font-size: 18px !important;
  }
  
  .kpi-card div[style*="font-size: 13px"],
  .inventory-tile div[style*="font-size: 13px"] {
    font-size: 10px !important;
    letter-spacing: 0.3px !important;
  }
  
  .kpi-card div[style*="font-size: 12px"],
  .inventory-tile div[style*="font-size: 12px"] {
    font-size: 9px !important;
  }
  
  .kpi-grid {
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)) !important;
    gap: 12px !important;
  }
  
  .inventory-tile.compact,
  .inventory-tile-static.compact {
    padding: 8px 12px !important;
  }
}

@media (max-width: 600px) {
  .kpi-card div[style*="font-size: 32px"],
  .inventory-tile div[style*="font-size: 32px"] {
    font-size: 18px !important;
  }
  
  .kpi-card div[style*="font-size: 24px"],
  .inventory-tile div[style*="font-size: 24px"] {
    font-size: 16px !important;
  }
  
  .kpi-card div[style*="font-size: 13px"],
  .inventory-tile div[style*="font-size: 13px"] {
    font-size: 9px !important;
    letter-spacing: 0.2px !important;
  }
  
  .kpi-card div[style*="font-size: 12px"],
  .inventory-tile div[style*="font-size: 12px"] {
    font-size: 8px !important;
  }
  
  .kpi-grid {
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)) !important;
    gap: 8px !important;
  }
  
  .kpi-card,
  .inventory-tile {
    padding: 16px 10px !important;
  }
}

@media (max-width: 480px) {
  .kpi-card div[style*="font-size: 32px"],
  .inventory-tile div[style*="font-size: 32px"] {
    font-size: 16px !important;
  }
  
  .kpi-card div[style*="font-size: 24px"],
  .inventory-tile div[style*="font-size: 24px"] {
    font-size: 14px !important;
  }
  
  .kpi-card div[style*="font-size: 13px"],
  .inventory-tile div[style*="font-size: 13px"] {
    font-size: 8px !important;
    letter-spacing: 0.1px !important;
  }
  
  .kpi-card div[style*="font-size: 12px"],
  .inventory-tile div[style*="font-size: 12px"] {
    font-size: 7px !important;
  }
  
  .kpi-grid {
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)) !important;
    gap: 6px !important;
  }
  
  .kpi-card,
  .inventory-tile {
    padding: 12px 8px !important;
  }
}

/* Ensure all text content is visible by allowing wrapping and scaling */
.kpi-card div[style*="text-transform: uppercase"],
.inventory-tile div[style*="text-transform: uppercase"],
.kpi-card div[id*="Value"],
.kpi-card div[id*="Rate"],
.kpi-card div[id*="Count"],
.kpi-card div[id*="Alerts"],
.kpi-card div[id*="Warnings"] {
  overflow: visible;
  max-width: 100%;
  word-wrap: break-word;
  overflow-wrap: break-word;
  line-height: 1.2;
}

/* Additional responsiveness for very small screens */
@media (max-width: 400px) {
  .kpi-card div[style*="font-size: 32px"],
  .inventory-tile div[style*="font-size: 32px"] {
    font-size: 14px !important;
  }
  
  .kpi-card div[style*="font-size: 24px"],
  .inventory-tile div[style*="font-size: 24px"] {
    font-size: 12px !important;
  }
  
  .kpi-card div[style*="font-size: 13px"],
  .inventory-tile div[style*="font-size: 13px"] {
    font-size: 7px !important;
    letter-spacing: 0px !important;
  }
  
  .kpi-card div[style*="font-size: 12px"],
  .inventory-tile div[style*="font-size: 12px"] {
    font-size: 6px !important;
  }
  
  .kpi-grid {
    grid-template-columns: repeat(auto-fit, minmax(100px, 1fr)) !important;
    gap: 4px !important;
  }
  
  .kpi-card,
  .inventory-tile {
    padding: 8px 6px !important;
    min-height: 80px !important;
  }
}

/* Ensure currency and value text can wrap naturally on new lines if needed */
.kpi-card div[id*="Value"],
.kpi-card div[id*="Amount"],
.inventory-tile div[id*="Value"],
.inventory-tile div[id*="Amount"] {
  white-space: normal !important;
  word-break: break-word;
  hyphens: auto;
}

/* Compact Mobile Header Navigation - Completely Replace Sidebar */
.mobile-header {
  display: none; /* Hidden by default, shown on mobile */
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 9999;
  background: linear-gradient(135deg,
    rgba(0, 0, 0, 0.95) 0%,
    rgba(20, 30, 50, 0.9) 50%,
    rgba(0, 0, 0, 0.95) 100%);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.15);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
  padding: 16px 20px;
  min-height: 80px;
  /* Flexbox properties to arrange children in a horizontal row */
  flex-direction: row;
  align-items: center;
  gap: 16px;
}

.desktop-logo {
  display: block; /* Shown by default, hidden on mobile */
}

/* Hamburger Menu Button - Left Side */
.mobile-hamburger-menu {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.3s ease;
  flex-shrink: 0;
}

.mobile-hamburger-menu:hover {
  background: rgba(255, 255, 255, 0.15);
  transform: scale(1.05);
}

.mobile-hamburger-menu.active {
  background: rgba(255, 255, 255, 0.2);
  border-color: rgba(255, 255, 255, 0.3);
}

.hamburger-icon {
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: 20px;
  height: 16px;
}

.hamburger-line {
  width: 100%;
  height: 2px;
  background: white;
  border-radius: 1px;
  transition: all 0.3s ease;
}

.mobile-hamburger-menu.active .hamburger-line:nth-child(1) {
  transform: translateY(6px) rotate(45deg);
}

.mobile-hamburger-menu.active .hamburger-line:nth-child(2) {
  opacity: 0;
}

.mobile-hamburger-menu.active .hamburger-line:nth-child(3) {
  transform: translateY(-6px) rotate(-45deg);
}

/* Mobile Pharmacy Name - Inline with Hamburger Menu */
.mobile-pharmacy-name {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  margin-left: 16px; /* Add margin between hamburger and pharmacy name */
}

.pharmacy-name-text {
  color: white;
  font-size: 18px;
  font-weight: 700;
  text-align: center;
  padding: 12px 20px;
  background: linear-gradient(135deg,
    rgba(255, 255, 255, 0.12) 0%,
    rgba(255, 255, 255, 0.06) 50%,
    rgba(255, 255, 255, 0.10) 100%);
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  box-shadow:
    0 4px 16px rgba(0, 0, 0, 0.2),
    inset 0 1px 0 rgba(255, 255, 255, 0.15);
  backdrop-filter: blur(15px);
  -webkit-backdrop-filter: blur(15px);
  letter-spacing: 0.3px;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
  position: relative;
  overflow: hidden;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
  width: 100%; /* Allow full width utilization */
  max-width: none; /* Remove max-width restriction */
}

.pharmacy-name-text::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(
    90deg,
    transparent 0%,
    rgba(255, 255, 255, 0.1) 50%,
    transparent 100%
  );
  transition: left 3s ease;
  animation: shimmer 4s infinite;
}

@keyframes shimmer {
  0% { left: -100%; }
  50% { left: 100%; }
  100% { left: 100%; }
}

.pharmacy-name-text:hover {
  transform: translateY(-2px);
  box-shadow:
    0 12px 40px rgba(0, 0, 0, 0.4),
    inset 0 1px 0 rgba(255, 255, 255, 0.3);
}

/* Adjust main content for fixed header */
@media (max-width: 768px) {
  .main-content {
    margin-top: 80px;
    padding: 20px;
  }
}

/* Mobile Menu Dropdown - Full Screen Overlay */
.mobile-menu-dropdown {
  position: fixed;
  top: 80px;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(145deg,
    rgba(0, 0, 0, 0.98) 0%,
    rgba(20, 20, 30, 0.96) 50%,
    rgba(0, 0, 0, 0.98) 100%);
  backdrop-filter: blur(25px);
  -webkit-backdrop-filter: blur(25px);
  opacity: 0;
  visibility: hidden;
  transform: translateY(-20px);
  transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 9998;
  overflow-y: auto;
  overflow-x: hidden;
}

.menu-content {
  padding: 30px 20px;
  max-width: 600px;
  margin: 0 auto;
}

.menu-items {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-width: 500px;
  margin: 0 auto;
}

/* Professional mobile navigation enhancements */
.mobile-nav-item:first-child {
  border-top-left-radius: 16px;
  border-top-right-radius: 16px;
}

.mobile-nav-item:last-child {
  border-bottom-left-radius: 16px;
  border-bottom-right-radius: 16px;
}

/* Add subtle glow effect for active items */
.mobile-nav-item.active::after {
  content: '';
  position: absolute;
  right: 20px;
  top: 50%;
  transform: translateY(-50%);
  width: 8px;
  height: 8px;
  background: #667eea;
  border-radius: 50%;
  box-shadow: 0 0 12px rgba(102, 126, 234, 0.6);
}

/* Better touch feedback */
.mobile-hamburger-menu:active {
  transform: scale(0.95);
}

/* Smooth pharmacy name updates */
.pharmacy-name-text {
  transition: all 0.4s ease;
}

.pharmacy-name-text.updating {
  opacity: 0.7;
  transform: scale(0.98);
}

.mobile-menu-dropdown.show {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}

/* Menu Header - Enhanced */
.menu-header {
  padding: 20px 24px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.15);
  background: linear-gradient(135deg,
    rgba(255, 255, 255, 0.08) 0%,
    rgba(255, 255, 255, 0.04) 100%);
  border-top-left-radius: 20px;
  border-top-right-radius: 20px;
  position: relative;
}

.menu-header::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg,
    transparent 0%,
    rgba(255, 255, 255, 0.2) 50%,
    transparent 100%);
}

.current-page-display {
  display: flex;
  align-items: center;
  gap: 16px;
  color: white;
  font-weight: 700;
  position: relative;
  padding: 8px 0;
}

.current-page-display::before {
  content: 'Currently viewing:';
  position: absolute;
  top: -8px;
  left: 0;
  font-size: 11px;
  color: rgba(255, 255, 255, 0.6);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.current-page-icon {
  font-size: 24px;
  flex-shrink: 0;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.2), rgba(255, 255, 255, 0.1));
  padding: 8px;
  border-radius: 12px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.current-page-name {
  font-size: 18px;
  flex: 1;
  letter-spacing: 0.3px;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

.menu-separator {
  height: 2px;
  background: linear-gradient(90deg,
    transparent 0%,
    rgba(255, 255, 255, 0.2) 20%,
    rgba(255, 255, 255, 0.3) 50%,
    rgba(255, 255, 255, 0.2) 80%,
    transparent 100%);
  border-radius: 1px;
  margin: 4px 0;
}

/* Mobile Navigation Items - Enhanced */
.mobile-nav-item {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 18px 24px;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  min-height: 56px;
  color: rgba(255, 255, 255, 0.9);
  position: relative;
  background: transparent;
}

.mobile-nav-item:last-child {
  border-bottom: none;
  border-bottom-left-radius: 20px;
  border-bottom-right-radius: 20px;
}

.mobile-nav-item:hover {
  background: linear-gradient(90deg,
    rgba(255, 255, 255, 0.12) 0%,
    rgba(255, 255, 255, 0.08) 100%);
  color: white;
  transform: translateX(8px);
  border-left: 3px solid rgba(255, 255, 255, 0.4);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

.mobile-nav-item:active {
  background: linear-gradient(90deg,
    rgba(255, 255, 255, 0.2) 0%,
    rgba(255, 255, 255, 0.12) 100%);
  transform: translateX(4px);
}

.mobile-nav-item.active {
  background: linear-gradient(90deg,
    rgba(102, 126, 234, 0.2) 0%,
    rgba(118, 75, 162, 0.15) 50%,
    rgba(255, 255, 255, 0.1) 100%);
  color: white;
  font-weight: 700;
  border-left: 4px solid #667eea;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.2),
    0 0 20px rgba(102, 126, 234, 0.3);
  position: relative;
}

.mobile-nav-item.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 4px;
  background: linear-gradient(180deg, #667eea, #764ba2);
  border-radius: 0 2px 2px 0;
}

.mobile-nav-item .nav-icon {
  font-size: 20px;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  flex-shrink: 0;
  transition: all 0.3s ease;
}

.mobile-nav-item:hover .nav-icon {
  background: rgba(255, 255, 255, 0.15);
  transform: scale(1.1);
}

.mobile-nav-item.active .nav-icon {
  background: linear-gradient(135deg, #667eea, #764ba2);
  color: white;
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.mobile-nav-item .nav-text {
  font-size: 16px;
  font-weight: 600;
  flex: 1;
  letter-spacing: 0.2px;
}

/* Show/Hide Logic - Switch to Mobile View When Sidebar Can't Fit Properly */
@media (max-width: 1000px) {
  .sidebar {
    display: none !important;
  }

  .desktop-nav {
    display: none !important;
  }

  .desktop-logo {
    display: none !important;
  }

  .mobile-header {
    display: flex !important;
  }

  /* Adjust main content to fill full width when sidebar is hidden */
  .app-container {
    flex-direction: column;
  }

  .main-content {
    width: 100%;
    padding: 0;
  }
}

@media (min-width: 1001px) {
  .mobile-header {
    display: none !important;
  }

  .desktop-logo {
    display: block !important;
  }

  .desktop-nav {
    display: block !important;
  }
}

/* Responsive Adjustments for Different Screen Sizes */
@media (max-width: 480px) {
  .mobile-header {
    padding: 12px 16px;
    min-height: 70px;
  }

  .pharmacy-name-text {
    font-size: 16px;
    padding: 10px 16px;
    min-height: 46px;
    letter-spacing: 0.2px;
  }

  .mobile-hamburger-menu {
    width: 44px;
    height: 44px;
  }

  .hamburger-icon {
    width: 18px;
    height: 14px;
  }


  .mobile-menu-dropdown {
    left: -8px;
    right: -8px;
    border-radius: 18px;
    max-height: 75vh;
  }

  .menu-header {
    padding: 18px 20px;
  }

  .mobile-nav-item {
    padding: 16px 20px;
    min-height: 52px;
    gap: 14px;
  }

  .mobile-nav-item .nav-icon {
    font-size: 18px;
    width: 28px;
    height: 28px;
  }

  .mobile-nav-item .nav-text {
    font-size: 15px;
  }

  .current-page-icon {
    font-size: 22px;
    padding: 6px;
  }

  .current-page-name {
    font-size: 16px;
  }
}

@media (max-width: 360px) {
  .mobile-header {
    padding: 10px 14px;
    min-height: 66px;
  }

  .pharmacy-name-text {
    font-size: 15px;
    padding: 10px 14px;
    min-height: 44px;
    letter-spacing: 0.1px;
  }

  .mobile-hamburger-menu {
    width: 40px;
    height: 40px;
  }

  .hamburger-icon {
    width: 16px;
    height: 12px;
  }

  .mobile-menu-button {
    padding: 10px 14px;
    font-size: 13px;
    min-height: 44px;
    gap: 8px;
  }

  .menu-icon {
    font-size: 16px;
  }

  .mobile-menu-dropdown {
    left: -6px;
    right: -6px;
    border-radius: 16px;
    max-height: 70vh;
  }

  .menu-header {
    padding: 16px 18px;
  }

  .mobile-nav-item {
    padding: 14px 18px;
    min-height: 48px;
    gap: 12px;
  }

  .mobile-nav-item .nav-icon {
    font-size: 16px;
    width: 26px;
    height: 26px;
  }

  .mobile-nav-item .nav-text {
    font-size: 14px;
  }

  .current-page-icon {
    font-size: 20px;
    padding: 6px;
  }

  .current-page-name {
    font-size: 15px;
  }
}

/* Enhanced mobile responsiveness for overall app layout */

/* Mobile phones - small screens */
@media (max-width: 480px) {
  .container {
    padding: 5px;
  }

  .app-container {
    height: calc(100vh - 10px);
    border-radius: 5px;
  }

  .sidebar {
    padding: 5px 8px;
    max-height: 60px;
  }

  .nav-item {
    min-width: 80px;
    padding: 4px 8px;
    font-size: 11px;
    gap: 4px;
  }

  .nav-item span:not(.nav-icon) {
    display: none; /* Hide text labels on very small screens */
  }

  .logo {
    font-size: 14px;
    margin-right: 10px;
  }

  .user-profile-card {
    min-width: 150px;
    padding: 6px;
  }

  .user-avatar {
    width: 32px;
    height: 32px;
    font-size: 14px;
  }

  .user-name {
    font-size: 11px;
  }

  .user-role {
    font-size: 9px;
  }

  .main-content {
    padding: 8px;
  }

  .header {
    padding: 8px;
    margin-bottom: 10px;
  }

  .header h1 {
    font-size: 18px;
  }

  /* Form inputs */
  input, select, textarea {
    font-size: 16px !important; /* Prevent zoom on iOS */
    padding: 8px;
  }

  button {
    padding: 8px 12px;
    font-size: 14px;
    min-height: 36px;
  }

  /* Cards and tiles */
  .card {
    padding: 10px;
    margin-bottom: 8px;
  }

  .card h3 {
    font-size: 14px;
  }

  /* Modal adjustments */
  .modal {
    margin: 10px;
    max-height: calc(100vh - 20px);
  }

  .modal-body {
    padding: 15px;
  }

  /* Table responsive */
  table {
    font-size: 12px;
  }

  th, td {
    padding: 6px 4px;
  }

  /* POS specific - Mobile Optimized */
  .pos-grid {
    gap: 8px;
    height: calc(100vh - 200px); /* Ensure proper height on mobile */
  }

  .pos-grid > div:first-child {
    max-height: 40vh; /* Product list area */
    overflow-y: auto;
  }

  .pos-grid > div:last-child {
    max-height: 55vh; /* Cart and payment area */
    display: flex;
    flex-direction: column;
  }

  #cartItems {
    max-height: 40vh !important;
    overflow-y: auto !important;
    overflow-x: hidden;
    flex: 1;
    min-height: 150px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    padding: 8px;
    background: rgba(0, 0, 0, 0.3);
  }

  .payment-section {
    flex-shrink: 0;
    margin-top: 12px;
  }

  .pos-item {
    padding: 8px;
    font-size: 12px;
  }

  /* Cart item styling for mobile */
  .cart-item {
    padding: 8px 12px !important;
    margin-bottom: 8px !important;
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
  }

  .cart-item:last-child {
    margin-bottom: 0 !important;
  }

  /* Quick actions - already handled above, but ensuring consistency */
  .quick-actions {
    grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
    gap: 6px;
  }

  .action-card {
    padding: 8px;
    min-height: 60px;
    font-size: 11px;
  }
}

/* Very small phones - Enhanced POS Cart */
@media (max-width: 360px) {
  .sidebar {
    flex-direction: column;
    max-height: 100px;
    padding: 5px;
  }

  /* POS Cart Optimizations for Very Small Screens */
  .pos-grid {
    height: calc(100vh - 180px);
    gap: 6px;
  }

  .pos-grid > div:first-child {
    max-height: 35vh;
  }

  .pos-grid > div:last-child {
    max-height: 60vh;
  }

  #cartItems {
    max-height: 45vh !important;
    min-height: 120px;
    padding: 6px;
    font-size: 13px;
  }

  .cart-item {
    padding: 6px 10px !important;
    margin-bottom: 6px !important;
    font-size: 12px;
  }

  .payment-section {
    margin-top: 8px;
    padding: 8px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 6px;
  }

  .payment-row {
    font-size: 13px;
    padding: 4px 0;
  }

  .payment-total {
    font-size: 14px !important;
    font-weight: bold;
  }

  .nav-item {
    min-width: 60px;
    padding: 3px 6px;
    font-size: 10px;
    margin: 1px 2px;
  }

  .logo {
    font-size: 12px;
    margin-bottom: 4px;
    margin-right: 0;
  }

  .user-profile-card {
    min-width: 120px;
    padding: 4px;
    margin-top: 4px;
  }

  .user-avatar {
    width: 28px;
    height: 28px;
    font-size: 12px;
  }

  .main-content {
    padding: 5px;
  }

  .header {
    padding: 6px;
    margin-bottom: 8px;
  }

  .header h1 {
    font-size: 16px;
  }

  /* Ultra-compact cards */
  .card {
    padding: 8px;
    margin-bottom: 6px;
  }

  .card h3 {
    font-size: 13px;
  }

  /* Minimal buttons */
  button {
    padding: 6px 8px;
    font-size: 12px;
    min-height: 32px;
  }

  /* Compact inputs */
  input, select, textarea {
    padding: 6px;
    font-size: 14px !important;
  }

  /* Table ultra-compact */
  table {
    font-size: 10px;
  }

  th, td {
    padding: 4px 2px;
  }
}

/* =================================
   INVENTORY MOBILE OPTIMIZATIONS
   ================================= */

/* Mobile Inventory Optimizations - Base (768px and below) */
@media (max-width: 768px) {
  /* Inventory Filter Section - Make it stack vertically */
  #inventorySection .filter-section {
    padding: 16px !important;
    margin-bottom: 16px !important;
  }

  #inventorySection .filter-section > div:first-child {
    display: flex !important;
    flex-direction: column !important;
    gap: 16px !important;
    grid-template-columns: none !important;
  }

  #inventorySection .filter-section input,
  #inventorySection .filter-section select {
    font-size: 16px !important; /* Prevent zoom on iOS */
    padding: 12px 16px !important;
    min-height: 44px !important;
  }

  /* Inventory Table - Convert to Card Layout on Mobile */
  #inventoryHeaderContainer {
    display: none !important;
  }

  /* Hide the table within the container but keep the container for mobile cards */
  .table-container table {
    display: none !important;
  }

  .table-container {
    display: block !important;
    border: none !important;
    border-radius: 0 !important;
    padding: 0 !important;
    background: transparent !important;
    max-height: none !important;
    overflow: visible !important;
  }

  /* Style the table container for mobile card layout */
  .table-container {
    max-height: calc(100vh - 300px) !important;
    min-height: 400px !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    scrollbar-color: rgba(0, 0, 0, 0.3) transparent;
  }

  .table-container::-webkit-scrollbar {
    width: 6px;
  }

  .table-container::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.1);
    border-radius: 3px;
  }

  .table-container::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.3);
    border-radius: 3px;
  }

  .table-container::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.5);
  }

  /* Create Mobile Card Layout */
  #inventoryTableBody.mobile-cards {
    display: flex !important;
    flex-direction: column;
    gap: 12px;
    padding: 0;
    width: 100%;
    background: transparent;
  }

  /* Ensure mobile cards are always visible on mobile */
  @media (max-width: 768px) {
    #inventoryTableBody {
      display: flex !important;
      flex-direction: column;
      gap: 12px;
      padding: 0;
      width: 100%;
    }
  }

  .inventory-item-card {
    background: white;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    padding: 16px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    transition: all 0.2s ease;
    width: 100%;
    display: block !important;
    margin-bottom: 12px;
    box-sizing: border-box;
  }

  .inventory-item-card:hover {
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
    transform: translateY(-1px);
  }

  .inventory-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 12px;
  }

  .inventory-card-title {
    font-weight: 600;
    font-size: 16px;
    color: #1f2937;
    line-height: 1.2;
    flex: 1;
    margin-right: 12px;
  }

  .inventory-card-checkbox {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
  }

  .inventory-card-details {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 12px;
  }

  .inventory-detail-item {
    display: flex;
    flex-direction: column;
  }

  .inventory-detail-label {
    font-size: 12px;
    font-weight: 500;
    color: #6b7280;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
  }

  .inventory-detail-value {
    font-size: 14px;
    color: #1f2937;
    font-weight: 500;
  }

  .inventory-card-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    border-top: 1px solid #f3f4f6;
    padding-top: 12px;
    margin-top: 12px;
  }

  .inventory-action-btn {
    padding: 8px 16px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    border: 1px solid;
    cursor: pointer;
    transition: all 0.2s ease;
    min-width: 44px;
    min-height: 36px;
  }

  .inventory-action-edit {
    background: #f0f9ff;
    border-color: #0ea5e9;
    color: #0369a1;
  }

  .inventory-action-edit:hover {
    background: #e0f2fe;
  }

  .inventory-action-delete {
    background: #fef2f2;
    border-color: #f87171;
    color: #dc2626;
  }

  .inventory-action-delete:hover {
    background: #fee2e2;
  }

  /* Status Indicators */
  .inventory-status-badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
  }

  .inventory-status-ok {
    background: #dcfce7;
    color: #166534;
  }

  .inventory-status-low {
    background: #fef3c7;
    color: #92400e;
  }

  .inventory-status-out {
    background: #fee2e2;
    color: #991b1b;
  }

  /* Batch Operations on Mobile */
  #batchControls {
    padding: 12px 16px !important;
    background: #f0f9ff !important;
  }

  #batchControls > div {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 12px !important;
  }

  #batchControls > div > div {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-left: 0 !important;
  }

  #batchControls button {
    flex: 1;
    min-width: 120px;
    text-align: center;
    min-height: 36px;
  }
}

/* Desktop Table Scrolling Improvements */
@media (min-width: 769px) {
  /* Ensure proper desktop table scrolling */
  .table-container {
    max-height: calc(100vh - 400px) !important;
    overflow-x: auto !important;
    overflow-y: auto !important;
    border: 1px solid #e5e7eb;
    border-radius: 0 0 12px 12px;
    position: relative;
  }

  /* Improve table responsiveness even on desktop */
  #inventorySection .table {
    min-width: 950px; /* Ensure table doesn't get too compressed */
  }

  /* Add scrollbar styling for desktop */
  .table-container::-webkit-scrollbar {
    width: 8px;
    height: 8px;
  }

  .table-container::-webkit-scrollbar-track {
    background: #f1f5f9;
    border-radius: 4px;
  }

  .table-container::-webkit-scrollbar-thumb {
    background: #94a3b8;
    border-radius: 4px;
  }

  .table-container::-webkit-scrollbar-thumb:hover {
    background: #64748b;
  }
}

/* Intermediate Screen Sizes - Maintain Desktop Table with Better Scrolling */
@media (max-width: 900px) and (min-width: 769px) {
  .table-container {
    overflow-x: auto !important;
  }

  #inventorySection .table {
    min-width: 850px;
  }
}

/* Mobile Inventory Optimizations - Small Screens (480px and below) */
@media (max-width: 480px) {
  /* Make inventory cards more compact */
  .inventory-item-card {
    padding: 12px;
    margin-bottom: 8px;
  }

  .inventory-card-title {
    font-size: 15px;
  }

  .inventory-card-details {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .inventory-detail-label {
    font-size: 11px;
  }

  .inventory-detail-value {
    font-size: 13px;
  }

  .inventory-card-actions {
    flex-direction: column;
    gap: 6px;
  }

  .inventory-action-btn {
    width: 100%;
    padding: 10px 16px;
    font-size: 14px;
  }

  /* KPI Cards on Mobile */
  #inventorySection .kpi-grid {
    grid-template-columns: 1fr !important;
    gap: 10px !important;
  }

  #inventorySection .kpi-card {
    padding: 12px !important;
  }

  /* Filter buttons stack vertically on very small screens */
  #inventorySection .filter-section > div:last-child {
    flex-direction: column !important;
    align-items: stretch !important;
  }

  #inventorySection .filter-section > div:last-child button {
    width: 100%;
    margin-bottom: 6px;
  }
}

/* Mobile Inventory Optimizations - Very Small Screens (360px and below) */
@media (max-width: 360px) {
  .inventory-item-card {
    padding: 10px;
    border-radius: 8px;
  }

  .inventory-card-title {
    font-size: 14px;
    line-height: 1.3;
  }

  .inventory-detail-label {
    font-size: 10px;
  }

  .inventory-detail-value {
    font-size: 12px;
  }

  .inventory-action-btn {
    padding: 8px 12px;
    font-size: 13px;
    min-height: 32px;
  }

  /* Batch controls ultra compact */
  #batchControls {
    padding: 8px 12px !important;
  }

  #batchControls button {
    min-width: 100px;
    padding: 6px 12px;
    font-size: 12px;
    min-height: 32px;
  }

  /* Ultra-compact KPI adjustments */
  #inventorySection .kpi-card {
    padding: 8px !important;
  }

  #inventorySection .filter-section {
    padding: 12px !important;
  }
}

/* =================================
   INVENTORY COMPONENT PROPORTIONAL SIZING
   ================================= */

/* Ensure all inventory components are properly proportioned */
@media (max-width: 768px) {
  /* Tab buttons responsive */
  #inventorySection .tab-header {
    flex-direction: column !important;
    gap: 8px !important;
  }

  #inventorySection .tab-button {
    flex: 1;
    padding: 12px 16px !important;
    font-size: 14px !important;
    min-height: 44px;
    text-align: center;
    width: 100%;
  }

  /* Card headers responsive */
  #inventorySection .card {
    margin-bottom: 16px !important;
    padding: 16px !important;
  }

  /* Search and filter improvements */
  #inventorySection .filter-section label {
    font-size: 14px !important;
    margin-bottom: 6px !important;
  }

  /* KPI grid full responsive */
  #inventorySection .kpi-grid {
    grid-template-columns: 1fr 1fr !important;
    gap: 12px !important;
  }

  /* Results count and action buttons */
  #inventorySection .filter-section > div:last-child {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 8px !important;
  }

  #inventorySection .filter-section button {
    padding: 10px 16px !important;
    font-size: 14px !important;
    min-height: 44px !important;
    border-radius: 8px !important;
  }

  /* No results state */
  #inventoryNoResults {
    padding: 32px 16px !important;
  }

  #inventoryNoResults div:first-child {
    font-size: 32px !important;
  }
}

/* Very small screen proportional adjustments */
@media (max-width: 480px) {
  /* Single column KPI */
  #inventorySection .kpi-grid {
    grid-template-columns: 1fr !important;
  }

  /* Tab header compact */
  #inventorySection .tab-button {
    padding: 10px 14px !important;
    font-size: 13px !important;
    min-height: 40px;
  }

  /* Adjust container height for smaller screens */
  .table-container {
    max-height: calc(100vh - 250px) !important;
    min-height: 300px !important;
  }
}

/* Ultra-small screens (360px and below) */
@media (max-width: 360px) {
  .table-container {
    max-height: calc(100vh - 220px) !important;
    min-height: 250px !important;
  }

  /* Ensure inventory cards fit properly */
  .inventory-item-card {
    margin-bottom: 8px !important;
    padding: 8px !important;
  }
}

/* Prevent horizontal overflow on all screen sizes */
@media (max-width: 768px) {
  #inventorySection * {
    box-sizing: border-box;
  }

  #inventorySection {
    overflow-x: hidden;
    width: 100%;
  }

  /* Ensure no component exceeds viewport width */
  #inventorySection .card,
  #inventorySection .filter-section,
  #inventorySection .inventory-item-card,
  #inventorySection .kpi-card {
    max-width: 100%;
    word-wrap: break-word;
    overflow-wrap: break-word;
  }

  /* Input and select elements responsive */
  #inventorySection input[type="text"],
  #inventorySection input[type="number"],
  #inventorySection select {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
  }
}

/* =================================
   PURCHASES MOBILE OPTIMIZATIONS
   ================================= */

/* Mobile Purchases Optimizations - Base (768px and below) */
@media (max-width: 768px) {
  /* Purchases Tab Headers */
  #purchasesSection .tab-header {
    flex-direction: column !important;
    gap: 8px !important;
  }

  #purchasesSection .tab-button {
    flex: 1;
    padding: 12px 16px !important;
    font-size: 14px !important;
    min-height: 44px;
    text-align: center;
    width: 100%;
    border-radius: 8px !important;
  }

  /* Header Cards Responsive */
  #purchasesSection .card {
    margin-bottom: 16px !important;
    padding: 16px !important;
  }

  /* Purchases Header Section */
  #purchasesSection div[style*="background: linear-gradient(135deg, #6b7280"] {
    padding: 20px 16px !important;
    margin-bottom: 16px !important;
    border-radius: 12px !important;
  }

  #purchasesSection div[style*="background: linear-gradient(135deg, #6b7280"] h1 {
    font-size: 22px !important;
  }

  /* Order Management Section */
  #purchasesSection .card div[style*="display: flex; align-items: center; justify-content: space-between"] {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 16px !important;
  }

  #purchasesSection .card div[style*="display: flex; align-items: center; gap: 16px"] {
    text-align: center;
    justify-content: center !important;
  }

  #purchasesSection .btn.btn-primary {
    width: 100%;
    padding: 14px 20px !important;
    font-size: 16px !important;
    min-height: 48px;
  }

  /* Filter Section Mobile */
  #purchasesSection .filter-section {
    padding: 16px !important;
    margin-bottom: 16px !important;
  }

  #purchasesSection .filter-section > div:first-child {
    display: flex !important;
    flex-direction: column !important;
    gap: 16px !important;
    grid-template-columns: none !important;
  }

  #purchasesSection .filter-section input,
  #purchasesSection .filter-section select {
    font-size: 16px !important; /* Prevent iOS zoom */
    padding: 12px 16px !important;
    min-height: 44px !important;
    width: 100% !important;
    box-sizing: border-box;
  }

  #purchasesSection .filter-section button {
    width: 100%;
    padding: 12px 16px !important;
    font-size: 14px !important;
    min-height: 44px !important;
    margin-top: 8px;
  }

  /* Summary Stats Responsive */
  #purchasesSection .filter-section > div:last-child {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 12px !important;
    padding-top: 16px !important;
  }

  #purchasesSection .filter-section > div:last-child > div {
    flex-wrap: wrap !important;
    justify-content: center !important;
  }

  /* Tables - Hide desktop tables and prepare for mobile cards */
  #purchasesSection table {
    display: none !important;
  }

  #purchasesSection div[style*="overflow-x: auto"] {
    display: block !important;
    border: none !important;
    border-radius: 0 !important;
    padding: 0 !important;
    background: transparent !important;
    max-height: calc(100vh - 300px) !important;
    min-height: 400px !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    scrollbar-color: rgba(0, 0, 0, 0.3) transparent;
  }

  /* Ensure specific table containers are properly handled */
  #purchasesSection #ordersTable,
  #purchasesSection #processedOrdersTable,
  #purchasesSection #invTable {
    display: none !important;
  }

  /* Make sure mobile cards container is visible */
  #purchasesSection .mobile-cards {
    display: block !important;
    width: 100% !important;
    padding: 0 !important;
  }

  /* Mobile card base styling */
  #purchasesSection .mobile-card {
    background: white !important;
    border: 1px solid #e5e7eb !important;
    border-radius: 12px !important;
    padding: 16px !important;
    margin-bottom: 12px !important;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1) !important;
    transition: all 0.2s ease !important;
    width: 100% !important;
    box-sizing: border-box !important;
    display: block !important;
  }

  #purchasesSection .mobile-card:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15) !important;
    transform: translateY(-2px) !important;
  }

  /* Mobile cards container styling - CRITICAL for displaying mobile cards outside hidden tables */
  #purchasesSection .mobile-cards-container {
    display: block !important;
    width: 100% !important;
    padding: 0 !important;
    margin: 0 !important;
    visibility: visible !important;
    opacity: 1 !important;
  }

  /* Mobile group header styling */
  #purchasesSection .mobile-group-header {
    background: #f8fafc !important;
    padding: 12px 16px !important;
    margin: 16px 0 8px 0 !important;
    border-left: 4px solid #3b82f6 !important;
    border-radius: 4px !important;
    font-weight: 600 !important;
  }

  #purchasesSection .mobile-group-header .group-title {
    font-size: 14px !important;
    color: #1f2937 !important;
    margin-bottom: 4px !important;
  }

  #purchasesSection .mobile-group-header .group-summary {
    font-size: 12px !important;
    color: #6b7280 !important;
  }

  /* Mobile no-data state styling */
  #purchasesSection .mobile-no-data {
    text-align: center !important;
    padding: 32px 16px !important;
    color: #6b7280 !important;
    font-size: 14px !important;
    background: rgba(255, 255, 255, 0.9) !important;
    border-radius: 12px !important;
    margin: 10px !important;
    border: 1px solid #e5e7eb !important;
  }

  #purchasesSection div[style*="overflow-x: auto"]::-webkit-scrollbar {
    width: 6px;
  }

  #purchasesSection div[style*="overflow-x: auto"]::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.1);
    border-radius: 3px;
  }

  #purchasesSection div[style*="overflow-x: auto"]::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.3);
    border-radius: 3px;
  }

  #purchasesSection div[style*="overflow-x: auto"]::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.5);
  }
}

/* Purchase Order Card Layout */
@media (max-width: 768px) {
  .purchase-order-card {
    background: white;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 12px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    transition: all 0.2s ease;
    width: 100%;
    display: block !important;
    box-sizing: border-box;
  }

  .purchase-order-card:hover {
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
    transform: translateY(-1px);
  }

  .purchase-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 12px;
    flex-wrap: wrap;
    gap: 8px;
  }

  .purchase-card-id {
    font-weight: 700;
    font-size: 16px;
    color: #1f2937;
    background: #f3f4f6;
    padding: 4px 8px;
    border-radius: 6px;
  }

  .purchase-card-status {
    flex-shrink: 0;
  }

  .purchase-status-badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
  }

  .purchase-status-pending {
    background: #fef3c7;
    color: #92400e;
  }

  .purchase-status-ordered {
    background: #dbeafe;
    color: #1e40af;
  }

  .purchase-status-received {
    background: #dcfce7;
    color: #166534;
  }

  .purchase-card-details {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 12px;
  }

  .purchase-detail-item {
    display: flex;
    flex-direction: column;
  }

  .purchase-detail-label {
    font-size: 12px;
    font-weight: 500;
    color: #6b7280;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
  }

  .purchase-detail-value {
    font-size: 14px;
    color: #1f2937;
    font-weight: 500;
  }

  .purchase-card-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    border-top: 1px solid #f3f4f6;
    padding-top: 12px;
    margin-top: 12px;
    flex-wrap: wrap;
  }

  .purchase-action-btn {
    padding: 8px 16px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    border: 1px solid;
    cursor: pointer;
    transition: all 0.2s ease;
    min-width: 44px;
    min-height: 36px;
    flex: 1;
    text-align: center;
  }

  .purchase-action-view {
    background: #f0f9ff;
    border-color: #0ea5e9;
    color: #0369a1;
  }

  .purchase-action-view:hover {
    background: #e0f2fe;
  }

  .purchase-action-edit {
    background: #fef3c7;
    border-color: #d97706;
    color: #92400e;
  }

  .purchase-action-edit:hover {
    background: #fde68a;
  }

  .purchase-action-delete {
    background: #fef2f2;
    border-color: #f87171;
    color: #dc2626;
  }

  .purchase-action-delete:hover {
    background: #fee2e2;
  }
}

/* Mobile Purchases - Small Screens (480px and below) */
@media (max-width: 480px) {
  .purchase-order-card {
    padding: 12px;
    margin-bottom: 10px;
  }

  .purchase-card-details {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .purchase-card-actions {
    flex-direction: column;
    gap: 6px;
  }

  .purchase-action-btn {
    width: 100%;
    padding: 10px 16px;
    font-size: 14px;
    min-height: 40px;
  }

  /* Enhanced mobile card styling for small screens */
  #purchasesSection .mobile-card {
    padding: 14px !important;
    margin-bottom: 12px !important;
    border-radius: 12px !important;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.1) !important;
  }

  #purchasesSection .mobile-card .card-header {
    margin-bottom: 12px !important;
    flex-wrap: wrap !important;
    gap: 8px !important;
  }

  #purchasesSection .mobile-card .card-title {
    font-size: 15px !important;
    font-weight: 700 !important;
  }

  #purchasesSection .mobile-card .status-badge {
    padding: 6px 10px !important;
    font-size: 11px !important;
    border-radius: 12px !important;
  }

  #purchasesSection .mobile-card .card-content {
    margin-bottom: 12px !important;
  }

  #purchasesSection .mobile-card .info-row {
    display: flex !important;
    justify-content: space-between !important;
    margin-bottom: 8px !important;
    font-size: 13px !important;
  }

  #purchasesSection .mobile-card .info-label {
    color: #6b7280 !important;
    font-weight: 500 !important;
  }

  #purchasesSection .mobile-card .info-value {
    color: #1f2937 !important;
    font-weight: 600 !important;
  }

  #purchasesSection .mobile-card .card-actions {
    display: flex !important;
    flex-wrap: wrap !important;
    gap: 8px !important;
    justify-content: space-between !important;
  }

  #purchasesSection .mobile-card .action-btn {
    flex: 1 !important;
    min-width: calc(50% - 4px) !important;
    padding: 10px 12px !important;
    font-size: 12px !important;
    font-weight: 600 !important;
    border-radius: 8px !important;
    border: none !important;
    cursor: pointer !important;
    transition: all 0.2s ease !important;
  }

  /* Tab buttons stack better */
  #purchasesSection .tab-button {
    padding: 10px 14px !important;
    font-size: 13px !important;
    min-height: 40px;
  }

  /* Adjust container height for smaller screens */
  #purchasesSection div[style*="overflow-x: auto"] {
    max-height: calc(100vh - 250px) !important;
    min-height: 300px !important;
  }
}

/* Mobile Purchases - Very Small Screens (360px and below) */
@media (max-width: 360px) {
  .purchase-order-card {
    padding: 10px;
    border-radius: 8px;
  }

  .purchase-card-id {
    font-size: 14px;
  }

  .purchase-detail-label {
    font-size: 11px;
  }

  .purchase-detail-value {
    font-size: 13px;
  }

  .purchase-action-btn {
    padding: 8px 12px;
    font-size: 13px;
    min-height: 36px;
  }

  #purchasesSection div[style*="overflow-x: auto"] {
    max-height: calc(100vh - 220px) !important;
    min-height: 250px !important;
  }
}

/* Prevent horizontal overflow on purchases */
@media (max-width: 768px) {
  #purchasesSection * {
    box-sizing: border-box;
  }

  #purchasesSection {
    overflow-x: hidden;
    width: 100%;
  }

  /* Ensure no component exceeds viewport width */
  #purchasesSection .card,
  #purchasesSection .filter-section,
  #purchasesSection .purchase-order-card {
    max-width: 100%;
    word-wrap: break-word;
    overflow-wrap: break-word;
  }
}

/* Landscape orientation adjustments for mobile */
@media (max-width: 900px) and (orientation: landscape) {
  .sidebar {
    max-height: 50px;
    padding: 4px 10px;
  }

  .nav-item {
    padding: 4px 8px;
    font-size: 12px;
  }

  .user-profile-card {
    padding: 4px 8px;
  }

  .main-content {
    padding: 10px;
  }

  .app-container {
    height: calc(100vh - 10px);
  }
}

/* Touch-friendly improvements for all mobile devices */
@media (max-width: 900px) {
  /* Ensure touch targets are at least 44px */
  button, .nav-item, .action-card, input, select {
    min-height: 44px;
    min-width: 44px;
  }

  /* Improve tap highlighting */
  button, .nav-item, .action-card {
    -webkit-tap-highlight-color: rgba(0,0,0,0.1);
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
  }

  /* Better scrolling on mobile */
  .sidebar, .main-content {
    -webkit-overflow-scrolling: touch;
  }

  /* Hide scrollbars on mobile for cleaner look */
  .sidebar::-webkit-scrollbar,
  .main-content::-webkit-scrollbar {
    width: 2px;
    height: 2px;
  }

  .sidebar::-webkit-scrollbar-thumb,
  .main-content::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.2);
    border-radius: 1px;
  }

  /* Improve modal behavior on mobile */
  .modal-overlay {
    padding: 10px;
  }

  .modal {
    max-width: calc(100vw - 20px);
    max-height: calc(100vh - 20px);
    overflow-y: auto;
  }

  /* Purchases Page Mobile Form Optimization */

  /* Purchase Filter Section Mobile */
  .purchases-page .filter-section > div[style*="grid-template-columns"] {
    display: flex !important;
    flex-direction: column !important;
    gap: 16px !important;
  }

  .purchases-page .filter-section > div > div {
    width: 100% !important;
  }

  /* Create Order Modal Mobile Optimization */
  #orderModal .modal-content {
    width: 98% !important;
    max-width: 98% !important;
    height: 98vh !important;
    max-height: 98vh !important;
    margin: 1vh auto !important;
    padding: 16px !important;
  }

  #orderModal form {
    height: calc(98vh - 80px) !important;
  }

  /* Order form header section - Stack fields vertically */
  #orderModal div[style*="grid-template-columns: 1fr 1fr 1fr"] {
    display: flex !important;
    flex-direction: column !important;
    gap: 16px !important;
    padding: 20px !important;
  }

  /* Form inputs mobile optimization */
  #orderModal input.form-input,
  #orderModal select.form-input,
  #orderModal .form-input {
    min-height: 48px !important;
    padding: 12px 16px !important;
    font-size: 16px !important;
    border-radius: 8px !important;
    width: 100% !important;
    box-sizing: border-box !important;
  }

  #orderModal .form-label {
    font-size: 14px !important;
    margin-bottom: 8px !important;
    font-weight: 600 !important;
  }

  /* Product selection header controls mobile */
  #orderModal div[style*="justify-content: space-between"] {
    flex-direction: column !important;
    gap: 16px !important;
    align-items: stretch !important;
  }

  #orderModal div[style*="justify-content: space-between"] > div:last-child {
    display: flex !important;
    flex-direction: column !important;
    gap: 12px !important;
  }

  #orderModal div[style*="justify-content: space-between"] > div:last-child > div {
    display: flex !important;
    flex-wrap: wrap !important;
    gap: 8px !important;
    justify-content: center !important;
  }

  /* Search input mobile */
  #orderProductsSearch {
    width: 100% !important;
    min-height: 44px !important;
    padding: 12px 16px !important;
    font-size: 16px !important;
  }

  /* Product grid mobile - convert to card layout */
  #orderModal div[style*="grid-template-columns: 50px 2fr 1fr 100px 100px 120px 100px 120px 120px 120px"] {
    display: none !important;
  }

  #orderProductsList .product-row {
    display: block !important;
    background: white !important;
    border: 1px solid #e5e7eb !important;
    border-radius: 12px !important;
    margin-bottom: 16px !important;
    padding: 16px !important;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05) !important;
    position: relative !important;
  }

  #orderProductsList .product-row > div {
    display: block !important;
    width: 100% !important;
    margin-bottom: 12px !important;
    padding: 0 !important;
  }

  #orderProductsList .product-row > div:last-child {
    margin-bottom: 0 !important;
  }

  /* Product row restructure for mobile cards */
  #orderProductsList .product-row > div:first-child {
    position: absolute !important;
    top: 16px !important;
    right: 16px !important;
    width: auto !important;
    margin: 0 !important;
  }

  #orderProductsList .product-row > div:nth-child(2) {
    font-weight: bold !important;
    font-size: 16px !important;
    color: #111827 !important;
    margin-bottom: 8px !important;
    padding-right: 60px !important;
  }

  #orderProductsList .product-row > div:nth-child(3) {
    font-size: 14px !important;
    color: #6b7280 !important;
    margin-bottom: 12px !important;
  }

  /* Create mobile-friendly info layout */
  #orderProductsList .product-row > div:nth-child(n+4) {
    display: inline-block !important;
    width: calc(50% - 6px) !important;
    margin-bottom: 8px !important;
    font-size: 14px !important;
    vertical-align: top !important;
  }

  #orderProductsList .product-row > div:nth-child(odd) {
    margin-right: 12px !important;
  }

  /* Quantity and cost inputs mobile */
  #orderProductsList .product-row input[type="number"] {
    width: 100% !important;
    min-height: 40px !important;
    padding: 8px 12px !important;
    font-size: 16px !important;
    border-radius: 6px !important;
    border: 1px solid #d1d5db !important;
  }

  /* Order summary mobile */
  #orderModal div[style*="background: linear-gradient(135deg, #f0f9ff"] {
    padding: 24px !important;
    margin: 20px 0 !important;
  }

  #orderModal div[style*="justify-content: space-between"]:last-of-type {
    flex-direction: column !important;
    text-align: center !important;
    gap: 16px !important;
  }

  /* Action buttons mobile */
  #orderModal div[style*="justify-content: flex-end"]:last-child {
    flex-direction: column !important;
    gap: 12px !important;
    margin-top: 24px !important;
  }

  #orderModal button {
    min-height: 52px !important;
    font-size: 16px !important;
    font-weight: 600 !important;
    padding: 16px 24px !important;
    border-radius: 8px !important;
    width: 100% !important;
  }

  /* ========== ENHANCED MODAL MOBILE OPTIMIZATIONS ========== */

  /* General Modal Improvements for All Purchase Modals */
  .modal {
    animation: modalSlideUp 0.3s cubic-bezier(0.34, 1.56, 0.64, 1) !important;
  }

  @keyframes modalSlideUp {
    from {
      transform: translateY(100vh) scale(0.9);
      opacity: 0;
    }
    to {
      transform: translateY(0) scale(1);
      opacity: 1;
    }
  }

  /* Enhanced close button for touch interactions */
  .modal .btn:contains('✕'),
  .modal button[onclick*="close"],
  .modal-close {
    min-width: 44px !important;
    min-height: 44px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    border-radius: 12px !important;
    background: rgba(0, 0, 0, 0.05) !important;
    border: none !important;
    font-size: 18px !important;
    touch-action: manipulation !important;
  }

  /* View Order Modal Mobile - Enhanced */
  #viewOrderModal .modal-content {
    width: 98% !important;
    max-width: 98% !important;
    height: 98vh !important;
    max-height: 98vh !important;
    margin: 1vh auto !important;
    padding: 20px 16px !important;
    border-radius: 20px 20px 0 0 !important;
  }

  #viewOrderModal h3 {
    font-size: 18px !important;
    line-height: 1.3 !important;
    margin-bottom: 16px !important;
  }

  /* View Order Content Mobile Layout */
  #viewOrderModal div[style*="grid-template-columns: repeat(auto-fit, minmax(250px, 1fr))"] {
    display: flex !important;
    flex-direction: column !important;
    gap: 16px !important;
  }

  #viewOrderModal div[style*="grid-template-columns: repeat(auto-fit, minmax(250px, 1fr))"] > div {
    width: 100% !important;
  }

  /* Order info cards mobile */
  #viewOrderModal div[style*="background: #f9fafb"] {
    padding: 16px !important;
    border-radius: 12px !important;
    margin-bottom: 16px !important;
  }

  /* Action buttons mobile optimization */
  #viewOrderModal div[style*="display: flex; gap: 12px; flex-wrap: wrap"] {
    display: flex !important;
    flex-direction: column !important;
    gap: 12px !important;
    margin-top: 24px !important;
  }

  #viewOrderModal div[style*="display: flex; gap: 12px; flex-wrap: wrap"] button {
    width: 100% !important;
    min-height: 48px !important;
    font-size: 16px !important;
    border-radius: 12px !important;
    padding: 14px 20px !important;
    touch-action: manipulation !important;
  }

  /* Edit Received Order Modal Mobile - Enhanced */
  #editReceivedOrderModal .modal-content {
    width: 98% !important;
    max-width: 98% !important;
    height: 98vh !important;
    max-height: 98vh !important;
    margin: 1vh auto !important;
    padding: 20px 16px !important;
    border-radius: 20px 20px 0 0 !important;
  }

  #editReceivedOrderModal h3 {
    font-size: 18px !important;
    line-height: 1.3 !important;
  }

  /* Edit received order table mobile */
  #editReceivedOrderModal table {
    display: none !important;
  }

  #editReceivedOrderModal .editable-item {
    display: block !important;
    background: white !important;
    border: 1px solid #e5e7eb !important;
    border-radius: 12px !important;
    padding: 16px !important;
    margin-bottom: 12px !important;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1) !important;
  }

  /* Final action buttons for edit modal */
  #editReceivedOrderModal div[style*="justify-content: flex-end"] {
    position: fixed !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    background: white !important;
    padding: 16px !important;
    border-top: 1px solid #e5e7eb !important;
    box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.1) !important;
    z-index: 10 !important;
  }

  #editReceivedOrderModal div[style*="justify-content: flex-end"] > div {
    display: flex !important;
    flex-direction: column !important;
    gap: 12px !important;
    width: 100% !important;
  }

  #editReceivedOrderModal div[style*="justify-content: flex-end"] button {
    width: 100% !important;
    min-height: 48px !important;
    font-size: 16px !important;
    border-radius: 12px !important;
    padding: 14px 20px !important;
    touch-action: manipulation !important;
  }

  /* Add padding to modal content to account for fixed footer */
  #editReceivedOrderModal #editReceivedOrderContent {
    padding-bottom: 120px !important;
  }

  /* Add Product to Received Order Modal Mobile */
  #addNewProductToReceivedModal .modal-content {
    width: 98% !important;
    max-width: 98% !important;
    height: auto !important;
    max-height: 90vh !important;
    margin: 5vh auto !important;
    padding: 24px 16px !important;
    border-radius: 20px !important;
  }

  #addNewProductToReceivedModal h3 {
    font-size: 18px !important;
    text-align: center !important;
    margin-bottom: 24px !important;
  }

  #addNewProductToReceivedModal form {
    display: flex !important;
    flex-direction: column !important;
    gap: 20px !important;
  }

  #addNewProductToReceivedModal div[style*="grid-template-columns: 1fr 1fr"] {
    display: flex !important;
    flex-direction: column !important;
    gap: 16px !important;
  }

  #addNewProductToReceivedModal input,
  #addNewProductToReceivedModal select {
    min-height: 48px !important;
    padding: 12px 16px !important;
    font-size: 16px !important;
    border-radius: 12px !important;
    border: 2px solid #e5e7eb !important;
    width: 100% !important;
    box-sizing: border-box !important;
    touch-action: manipulation !important;
  }

  #addNewProductToReceivedModal input:focus,
  #addNewProductToReceivedModal select:focus {
    border-color: #3b82f6 !important;
    outline: none !important;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1) !important;
  }

  #addNewProductToReceivedModal label {
    font-size: 14px !important;
    font-weight: 600 !important;
    color: #374151 !important;
    margin-bottom: 8px !important;
    display: block !important;
  }

  /* Add Product Modal Mobile */
  #addProductModal .modal-content {
    width: 98% !important;
    max-width: 98% !important;
    height: 95vh !important;
    max-height: 95vh !important;
    margin: 2.5vh auto !important;
    padding: 20px 16px !important;
    border-radius: 20px 20px 0 0 !important;
  }

  #addProductModal h3 {
    font-size: 18px !important;
    text-align: center !important;
    margin-bottom: 20px !important;
  }

  /* Product search input */
  #addProductModal input[placeholder*="Search"] {
    width: 100% !important;
    min-height: 48px !important;
    padding: 12px 16px !important;
    font-size: 16px !important;
    border-radius: 12px !important;
    border: 2px solid #e5e7eb !important;
    margin-bottom: 20px !important;
    touch-action: manipulation !important;
  }

  /* Product list container mobile */
  #addProductModal div[style*="height: 400px"] {
    height: calc(95vh - 200px) !important;
    border-radius: 12px !important;
    border: 1px solid #e5e7eb !important;
    padding: 8px !important;
  }

  /* Product items mobile cards */
  #addProductModal .product-item {
    display: flex !important;
    flex-direction: column !important;
    background: white !important;
    border: 1px solid #e5e7eb !important;
    border-radius: 12px !important;
    padding: 16px !important;
    margin-bottom: 12px !important;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1) !important;
    touch-action: manipulation !important;
  }

  #addProductModal .product-item:active {
    transform: scale(0.98) !important;
    transition: transform 0.1s ease !important;
  }

  /* General Modal Button Optimizations */
  .modal button {
    min-height: 48px !important;
    padding: 12px 20px !important;
    font-size: 16px !important;
    border-radius: 12px !important;
    touch-action: manipulation !important;
    font-weight: 600 !important;
  }

  .modal button:active {
    transform: scale(0.98) !important;
    transition: transform 0.1s ease !important;
  }

  .modal .btn-primary {
    background: linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%) !important;
    border: none !important;
    color: white !important;
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3) !important;
  }

  .modal .btn-success {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%) !important;
    border: none !important;
    color: white !important;
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3) !important;
  }

  .modal .btn-secondary {
    background: #f3f4f6 !important;
    border: 2px solid #e5e7eb !important;
    color: #374151 !important;
  }

  /* Enhanced Touch Interactions for All Modals */
  .modal input,
  .modal select,
  .modal textarea {
    -webkit-tap-highlight-color: transparent !important;
    -webkit-touch-callout: none !important;
    -webkit-user-select: none !important;
    -moz-user-select: none !important;
    -ms-user-select: none !important;
    user-select: none !important;
  }

  .modal input:focus,
  .modal select:focus,
  .modal textarea:focus {
    -webkit-user-select: text !important;
    -moz-user-select: text !important;
    -ms-user-select: text !important;
    user-select: text !important;
  }

  /* Modal tables mobile - convert to card layout */
  .modal table.table {
    display: none !important;
  }

  .modal .mobile-table-card {
    background: white !important;
    border: 1px solid #e5e7eb !important;
    border-radius: 12px !important;
    padding: 16px !important;
    margin-bottom: 12px !important;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05) !important;
  }

  /* Enhanced scrolling for modal content */
  .modal-content {
    -webkit-overflow-scrolling: touch !important;
    scroll-behavior: smooth !important;
  }

  /* Prevent zoom on input focus (iOS) */
  .modal input,
  .modal select,
  .modal textarea {
    font-size: 16px !important; /* Prevents zoom on iOS */
  }

  /* Enhanced modal backdrop */
  .modal {
    backdrop-filter: blur(8px) !important;
    -webkit-backdrop-filter: blur(8px) !important;
  }

  /* Swipe indicator for modals */
  .modal-content::before {
    content: '' !important;
    position: absolute !important;
    top: 8px !important;
    left: 50% !important;
    transform: translateX(-50%) !important;
    width: 40px !important;
    height: 4px !important;
    background: rgba(0, 0, 0, 0.2) !important;
    border-radius: 2px !important;
    z-index: 1 !important;
  }

  /* Order items table mobile - convert to cards */
  #viewOrderModal table {
    display: none !important;
  }

  #viewOrderModal .order-item-card {
    background: #f8fafc !important;
    border: 1px solid #e2e8f0 !important;
    border-radius: 12px !important;
    padding: 16px !important;
    margin-bottom: 12px !important;
  }

  #viewOrderModal .order-item-card .item-header {
    display: flex !important;
    justify-content: space-between !important;
    align-items: center !important;
    margin-bottom: 12px !important;
    font-weight: 600 !important;
  }

  #viewOrderModal .order-item-card .item-details {
    display: grid !important;
    grid-template-columns: 1fr 1fr !important;
    gap: 8px !important;
    font-size: 14px !important;
    color: #64748b !important;
  }

  /* Any product selection tables in modals */
  .modal table {
    font-size: 14px !important;
  }

  .modal th,
  .modal td {
    padding: 8px 4px !important;
    font-size: 13px !important;
  }

  /* Improve checkbox and input visibility in forms */
  .modal input[type="checkbox"] {
    width: 20px !important;
    height: 20px !important;
    margin: 0 !important;
  }

  .modal select {
    min-height: 48px !important;
    padding: 12px 16px !important;
    font-size: 16px !important;
  }

  /* Accounting Page Mobile Optimization */

  /* Accounting filter section mobile */
  .accounting-page .filter-section > div[style*="grid-template-columns"] {
    display: flex !important;
    flex-direction: column !important;
    gap: 16px !important;
  }

  .accounting-page .filter-section > div > div {
    width: 100% !important;
  }

  /* Financial overview charts mobile */
  .accounting-page .chart-tile {
    grid-column: 1 / -1 !important;
    min-width: 100% !important;
  }

  .accounting-page div[style*="grid-template-columns: repeat(auto-fit, minmax(400px, 1fr))"] {
    display: flex !important;
    flex-direction: column !important;
    gap: 16px !important;
  }

  /* KPI cards mobile */
  .accounting-page .kpi-grid {
    display: flex !important;
    flex-direction: column !important;
    gap: 12px !important;
  }

  .accounting-page .kpi-card {
    width: 100% !important;
  }

  /* Invoices table mobile - convert to cards */
  .accounting-page #invTable {
    display: none !important;
  }

  .accounting-page #invTable.mobile-cards {
    display: block !important;
  }

  .accounting-page #invTable.mobile-cards thead {
    display: none !important;
  }

  .accounting-page #invTable.mobile-cards tbody {
    display: block !important;
  }

  .accounting-page #invTable.mobile-cards tbody .mobile-card {
    background: white !important;
    border: 1px solid #e5e7eb !important;
    border-radius: 12px !important;
    margin-bottom: 16px !important;
    padding: 16px !important;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05) !important;
    display: block !important;
  }

  .accounting-page #invTable.mobile-cards tbody .mobile-card .card-header {
    display: flex !important;
    justify-content: space-between !important;
    align-items: center !important;
    margin-bottom: 12px !important;
    padding-bottom: 12px !important;
    border-bottom: 1px solid #f3f4f6 !important;
  }

  .accounting-page #invTable.mobile-cards tbody .mobile-card .card-title {
    font-weight: bold !important;
    font-size: 16px !important;
    color: #111827 !important;
  }

  .accounting-page #invTable.mobile-cards tbody .mobile-card .status-badge {
    padding: 4px 12px !important;
    border-radius: 16px !important;
    font-size: 12px !important;
    font-weight: 600 !important;
    color: white !important;
  }

  .accounting-page #invTable.mobile-cards tbody .mobile-card .card-content {
    display: flex !important;
    flex-direction: column !important;
    gap: 8px !important;
  }

  .accounting-page #invTable.mobile-cards tbody .mobile-card .info-row {
    display: flex !important;
    justify-content: space-between !important;
    align-items: center !important;
    padding: 4px 0 !important;
  }

  .accounting-page #invTable.mobile-cards tbody .mobile-card .info-label {
    font-size: 14px !important;
    color: #6b7280 !important;
    font-weight: 500 !important;
  }

  .accounting-page #invTable.mobile-cards tbody .mobile-card .info-value {
    font-size: 14px !important;
    color: #111827 !important;
    font-weight: 600 !important;
    text-align: right !important;
  }

  .accounting-page #invTable.mobile-cards tbody .mobile-card .total-row {
    border-top: 1px solid #f3f4f6 !important;
    padding-top: 8px !important;
    margin-top: 8px !important;
  }

  .accounting-page #invTable.mobile-cards tbody .mobile-card .total-amount {
    font-size: 16px !important;
    font-weight: bold !important;
    color: #059669 !important;
  }

  /* Expense management mobile */
  .accounting-page .expense-form {
    padding: 16px !important;
  }

  .accounting-page .expense-form .form-grid {
    display: flex !important;
    flex-direction: column !important;
    gap: 16px !important;
  }

  /* Quick date filters mobile */
  .accounting-page div[style*="display: flex; gap: 8px; flex-wrap: wrap;"] {
    display: flex !important;
    flex-direction: column !important;
    gap: 8px !important;
  }

  .accounting-page div[style*="display: flex; gap: 8px; flex-wrap: wrap;"] button {
    width: 100% !important;
    justify-content: center !important;
    min-height: 44px !important;
  }

  /* Daily performance table mobile */
  .accounting-page #dailyPerformanceTable {
    font-size: 14px !important;
  }

  .accounting-page #dailyPerformanceTable th,
  .accounting-page #dailyPerformanceTable td {
    padding: 8px 4px !important;
    font-size: 12px !important;
  }

  /* Top products section mobile */
  .accounting-page #topProductsList {
    display: flex !important;
    flex-direction: column !important;
    gap: 12px !important;
  }

  /* Invoice Modal Mobile */
  #invoiceModal .modal-content {
    width: 98% !important;
    max-width: 98% !important;
    margin: 1vh auto !important;
    padding: 16px !important;
  }

  #invoiceModal .form-group {
    margin-bottom: 16px !important;
  }

  #invoiceModal .form-input,
  #invoiceModal .form-label {
    font-size: 16px !important;
    padding: 12px 16px !important;
    min-height: 48px !important;
    border-radius: 8px !important;
  }

  #invoiceModal .form-label {
    font-weight: 600 !important;
    margin-bottom: 8px !important;
    display: block !important;
  }

  /* Expense form mobile */
  .accounting-page .expense-form input,
  .accounting-page .expense-form select,
  .accounting-page .expense-form textarea {
    font-size: 16px !important;
    min-height: 48px !important;
    padding: 12px 16px !important;
    border-radius: 8px !important;
    width: 100% !important;
    box-sizing: border-box !important;
  }

  /* Accounting buttons mobile */
  .accounting-page button {
    min-height: 48px !important;
    font-size: 16px !important;
    padding: 12px 24px !important;
    border-radius: 8px !important;
  }

  .accounting-page .btn {
    width: 100% !important;
    margin-bottom: 8px !important;
  }

  /* Mobile action buttons in cards */
  .accounting-page .mobile-status-update {
    margin-bottom: 12px !important;
  }

  .accounting-page .mobile-due-date-update {
    margin-bottom: 12px !important;
  }

  .accounting-page .mobile-status-update select,
  .accounting-page .mobile-due-date-update input {
    font-size: 16px !important;
  }
}

/* Additional mobile optimization for very small screens */
@media screen and (max-width: 480px) {
  /* Extra small screens - optimize further */
  #orderModal .modal-content {
    width: 100% !important;
    height: 100vh !important;
    max-height: 100vh !important;
    margin: 0 !important;
    padding: 12px !important;
    border-radius: 0 !important;
  }

  #orderModal form {
    height: calc(100vh - 60px) !important;
  }

  #orderModal .form-input {
    font-size: 18px !important; /* Prevent zoom on iOS */
  }

  #orderProductsList .product-row > div:nth-child(n+4) {
    width: 100% !important;
    display: block !important;
    margin-right: 0 !important;
  }

  #orderModal button {
    min-height: 56px !important;
    font-size: 18px !important;
  }

  /* Purchases filter section very small screens */
  .purchases-page .filter-section {
    padding: 16px !important;
    margin-bottom: 16px !important;
  }

  /* Accounting page very small screens */
  .accounting-page .filter-section {
    padding: 16px !important;
    margin-bottom: 16px !important;
  }

  .accounting-page .chart-tile {
    padding: 16px !important;
    margin-bottom: 12px !important;
  }

  .accounting-page .chart-tile canvas {
    height: 200px !important;
  }

  .accounting-page .kpi-card {
    padding: 12px !important;
  }
}

/* Ultra small screens optimization */
@media screen and (max-width: 360px) {
  #orderModal .modal-content {
    padding: 8px !important;
  }

  #orderModal div[style*="grid-template-columns: 1fr 1fr 1fr"] {
    padding: 16px !important;
  }

  #orderProductsList .product-row {
    padding: 12px !important;
    margin-bottom: 12px !important;
  }

  #orderModal button {
    padding: 18px 16px !important;
  }

  /* Accounting page ultra small screens */
  .accounting-page .chart-tile {
    padding: 12px !important;
  }

  .accounting-page .kpi-card {
    padding: 8px !important;
  }

  .accounting-page .filter-section {
    padding: 12px !important;
  }
}

/* ===============================================
   STAFF PERFORMANCE PAGE MOBILE OPTIMIZATIONS
   =============================================== */

/* Staff Performance page base mobile styles */
@media screen and (max-width: 768px) {
  .staff-page {
    background: linear-gradient(135deg, #10b981 0%, #667eea 25%, #8b5cf6 50%, #f59e0b 75%, #10b981 100%);
    background-size: 400% 400%;
    animation: gradientShift 12s ease-in-out infinite;
    min-height: 100vh;
    position: relative;
  }

  .staff-page::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.12);
    backdrop-filter: blur(2px);
    pointer-events: none;
  }

  @keyframes gradientShift {
    0%, 100% {
      background-position: 0% 50%;
    }
    25% {
      background-position: 100% 50%;
    }
    50% {
      background-position: 0% 50%;
    }
    75% {
      background-position: 100% 50%;
    }
  }

  .staff-page > div {
    position: relative;
    z-index: 1;
  }
  .staff-page .date-range-container {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(15px);
    padding: 24px;
    margin-bottom: 28px;
    border-radius: 24px;
    border: 1px solid rgba(255, 255, 255, 0.3);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.1), 0 4px 16px rgba(0, 0, 0, 0.03);
  }

  .staff-page .date-range-buttons {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    margin-bottom: 20px;
  }

  .staff-page .date-range-buttons button {
    padding: 12px 10px;
    font-size: 12px;
    border-radius: 12px;
    white-space: nowrap;
    background: rgba(255, 255, 255, 0.8) !important;
    backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.3) !important;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    font-weight: 600;
    color: #374151 !important;
  }

  .staff-page .date-range-buttons button:hover,
  .staff-page .date-range-buttons button.btn-primary {
    transform: translateY(-2px);
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
    color: white !important;
    box-shadow: 0 8px 24px rgba(102, 126, 234, 0.3);
  }

  .staff-page .date-inputs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 12px;
  }

  .staff-page .date-inputs input {
    padding: 14px 16px;
    font-size: 16px;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.3);
    background: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(8px);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.05);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    color: #374151;
    font-weight: 500;
  }

  .staff-page .date-inputs input:focus {
    outline: none;
    border: 1px solid rgba(102, 126, 234, 0.5);
    background: rgba(255, 255, 255, 0.95);
    box-shadow: 0 8px 24px rgba(102, 126, 234, 0.15), 0 0 0 3px rgba(102, 126, 234, 0.1);
    transform: translateY(-2px);
  }

  .staff-page .overview-cards {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 28px;
  }

  .staff-page .overview-card {
    padding: 20px;
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(12px);
    border-radius: 20px;
    border: 1px solid rgba(255, 255, 255, 0.3);
    text-align: center;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.08), 0 2px 12px rgba(0, 0, 0, 0.03);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
  }

  .staff-page .overview-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, #667eea 0%, #764ba2 50%, #667eea 100%);
    background-size: 200% 100%;
    animation: shimmer 2s infinite;
  }

  .staff-page .overview-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.12), 0 4px 16px rgba(0, 0, 0, 0.05);
    background: rgba(255, 255, 255, 0.95);
  }

  .staff-page .overview-card h4 {
    font-size: 22px;
    margin: 8px 0 6px 0;
    font-weight: 700;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
  }

  .staff-page .overview-card p {
    font-size: 12px;
    color: #6b7280;
    margin: 0;
    font-weight: 500;
  }

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

  /* Staff rankings table to mobile cards */
  .staff-page .staff-rankings-wrapper {
    background: var(--bg-tertiary);
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 24px;
  }

  .staff-page .staff-rankings-table {
    display: none;
  }

  .staff-page .staff-rankings-cards {
    display: block;
  }

  .staff-page .staff-ranking-card {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 20px;
    padding: 20px;
    margin-bottom: 16px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.08), 0 2px 12px rgba(0, 0, 0, 0.03);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
  }

  .staff-page .staff-ranking-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: linear-gradient(90deg, #10b981 0%, #059669 100%);
    opacity: 0.8;
  }

  .staff-page .staff-ranking-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.12), 0 4px 16px rgba(0, 0, 0, 0.05);
    background: rgba(255, 255, 255, 0.98);
  }

  .staff-page .staff-ranking-card .rank-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
  }

  .staff-page .staff-ranking-card .rank-number {
    font-size: 16px;
    font-weight: 700;
    padding: 10px 14px;
    border-radius: 12px;
    background: rgba(16, 185, 129, 0.1);
    border: 1px solid rgba(16, 185, 129, 0.2);
    color: #059669;
    backdrop-filter: blur(8px);
  }

  .staff-page .staff-ranking-card .staff-name {
    font-size: 16px;
    font-weight: 600;
    margin: 0 0 6px 0;
    color: #1f2937;
  }

  .staff-page .staff-ranking-card .staff-role {
    font-size: 11px;
    color: #6b7280;
    background: rgba(107, 114, 128, 0.1);
    border: 1px solid rgba(107, 114, 128, 0.2);
    padding: 6px 10px;
    border-radius: 8px;
    display: inline-block;
    font-weight: 500;
    text-transform: capitalize;
  }

  .staff-page .staff-ranking-card .ranking-metrics {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin-top: 16px;
  }

  .staff-page .staff-ranking-card .metric {
    text-align: center;
    padding: 12px 8px;
    background: rgba(255, 255, 255, 0.6);
    backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.4);
    border-radius: 12px;
    transition: all 0.2s ease;
    position: relative;
    overflow: hidden;
  }

  .staff-page .staff-ranking-card .metric::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(90deg, rgba(102, 126, 234, 0.3) 0%, rgba(118, 75, 162, 0.3) 100%);
  }

  .staff-page .staff-ranking-card .metric:hover {
    transform: translateY(-2px);
    background: rgba(255, 255, 255, 0.8);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
  }

  .staff-page .staff-ranking-card .metric .metric-title {
    font-size: 9px;
    color: #6b7280;
    margin-bottom: 6px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
  }

  .staff-page .staff-ranking-card .metric .metric-value {
    font-size: 14px;
    font-weight: 700;
    color: #1f2937;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
  }

  /* Staff performance charts mobile optimization */
  .staff-page .charts-container {
    display: flex;
    flex-direction: column;
    gap: 24px;
  }

  .staff-page .chart-tile {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(12px);
    border-radius: 20px;
    padding: 24px;
    border: 1px solid rgba(255, 255, 255, 0.3);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.08), 0 2px 12px rgba(0, 0, 0, 0.03);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
  }

  .staff-page .chart-tile::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, #667eea 0%, #764ba2 50%, #10b981 100%);
    background-size: 200% 100%;
    animation: shimmer 3s infinite;
  }

  .staff-page .chart-tile:hover {
    transform: translateY(-4px);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.12), 0 4px 16px rgba(0, 0, 0, 0.05);
    background: rgba(255, 255, 255, 0.98);
  }

  .staff-page .chart-tile canvas {
    max-height: 280px !important;
    border-radius: 12px;
  }

  /* Staff selector mobile optimization */
  .staff-page .staff-selector-container {
    background: var(--bg-tertiary);
    padding: 16px;
    border-radius: 12px;
    margin-bottom: 20px;
    border: 1px solid var(--border-primary);
  }

  .staff-page .staff-selector-container select {
    width: 100%;
    padding: 12px;
    font-size: 16px;
    border-radius: 8px;
    border: 2px solid var(--border-primary);
    background: var(--bg-primary);
  }

  /* Staff detail tiles mobile optimization */
  .staff-page .staff-details-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
    margin-bottom: 24px;
  }

  .staff-page .staff-detail-tile {
    background: var(--bg-tertiary);
    border-radius: 12px;
    padding: 16px;
    border: 1px solid var(--border-primary);
    text-align: center;
  }

  .staff-page .staff-detail-tile .tile-title {
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 8px;
  }

  .staff-page .staff-detail-tile .tile-value {
    font-size: 18px;
    font-weight: 700;
    margin-bottom: 4px;
  }

  .staff-page .staff-detail-tile .tile-subtitle {
    font-size: 10px;
    color: var(--text-secondary);
  }

  /* Enhanced metrics comparison mobile optimization - matching User Portal style */
  .staff-page .metrics-buttons {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
    margin-bottom: 24px;
    padding: 0 16px;
  }

  .staff-page .metric-btn {
    padding: 20px 16px !important;
    border-radius: 20px !important;
    background: rgba(255, 255, 255, 0.9) !important;
    backdrop-filter: blur(15px) !important;
    border: 1px solid rgba(255, 255, 255, 0.25) !important;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.08), 0 4px 16px rgba(0, 0, 0, 0.03) !important;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
    min-height: 120px !important;
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 8px !important;
    text-align: center !important;
    position: relative !important;
    overflow: hidden !important;
  }

  .staff-page .metric-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, #10b981 0%, #667eea 50%, #8b5cf6 100%);
    background-size: 200% 100%;
    animation: shimmer 2.5s infinite;
  }

  .staff-page .metric-btn:hover {
    transform: translateY(-6px) !important;
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.12), 0 6px 20px rgba(0, 0, 0, 0.05) !important;
    background: rgba(255, 255, 255, 0.95) !important;
  }

  .staff-page .metric-btn div[style*="width: 40px"] {
    width: 36px !important;
    height: 36px !important;
    font-size: 18px !important;
    margin-bottom: 8px !important;
    border-radius: 12px !important;
  }

  .staff-page .metric-btn div[style*="font-weight: 700"] {
    font-size: 14px !important;
    font-weight: 700 !important;
    margin-bottom: 4px !important;
    background: linear-gradient(135deg, #10b981 0%, #667eea 50%, #8b5cf6 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
  }

  .staff-page .metric-btn div[style*="font-size: 11px"] {
    font-size: 11px !important;
    line-height: 1.2 !important;
    color: #6b7280 !important;
    font-weight: 500 !important;
  }

  .staff-page .metrics-comparison-chart {
    background: rgba(255, 255, 255, 0.95) !important;
    backdrop-filter: blur(15px) !important;
    border-radius: 24px !important;
    padding: 24px !important;
    border: 1px solid rgba(255, 255, 255, 0.3) !important;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.08), 0 4px 16px rgba(0, 0, 0, 0.03) !important;
    margin-bottom: 24px !important;
    position: relative !important;
    overflow: hidden !important;
  }

  .staff-page .metrics-comparison-chart::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, #10b981 0%, #667eea 50%, #8b5cf6 100%);
    background-size: 200% 100%;
    animation: shimmer 3s infinite;
  }

  .staff-page .metrics-comparison-chart canvas {
    max-height: 300px !important;
    border-radius: 16px !important;
  }
}

/* Staff page medium mobile screens */
@media screen and (max-width: 480px) {
  .staff-page .date-range-buttons {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }

  .staff-page .date-range-buttons button {
    padding: 10px 8px;
    font-size: 12px;
  }

  .staff-page .overview-cards {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .staff-page .overview-card {
    padding: 16px;
  }

  .staff-page .overview-card h4 {
    font-size: 18px;
  }

  .staff-page .staff-ranking-card .ranking-metrics {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .staff-page .chart-tile canvas {
    max-height: 250px !important;
  }

  .staff-page .metrics-buttons {
    grid-template-columns: 1fr !important;
    gap: 16px !important;
    padding: 0 8px !important;
  }

  .staff-page .metric-btn {
    min-height: 100px !important;
    padding: 18px 14px !important;
  }
}

/* Staff page very small screens */
@media screen and (max-width: 360px) {
  .staff-page .date-range-container {
    padding: 20px;
    margin-bottom: 20px;
  }

  .staff-page .date-range-buttons button {
    padding: 8px 4px;
    font-size: 10px;
  }

  .staff-page .overview-card {
    padding: 14px;
  }

  .staff-page .overview-card h4 {
    font-size: 18px;
  }

  .staff-page .staff-ranking-card {
    padding: 16px;
  }

  .staff-page .chart-tile {
    padding: 20px;
  }

  .staff-page .chart-tile canvas {
    max-height: 220px !important;
  }

  .staff-page .staff-detail-tile {
    padding: 16px;
  }

  .staff-page .metrics-comparison-chart {
    padding: 20px;
  }

  .staff-page .metrics-comparison-chart canvas {
    max-height: 220px !important;
  }

  .staff-page .metric-btn {
    min-height: 90px !important;
    padding: 16px 12px !important;
  }
}

/* ===============================================
   USER PORTAL PAGE MOBILE OPTIMIZATIONS
   =============================================== */

/* User Portal page base mobile styles */
@media screen and (max-width: 768px) {
  .user-portal-page {
    background: linear-gradient(135deg, #8b5cf6 0%, #667eea 30%, #10b981 70%, #f59e0b 100%);
    background-size: 400% 400%;
    animation: gradientShift 10s ease-in-out infinite;
    min-height: 100vh;
    position: relative;
  }

  .user-portal-page::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.12);
    backdrop-filter: blur(2px);
    pointer-events: none;
  }

  .user-portal-page > div {
    position: relative;
    z-index: 1;
  }

  /* Date range controls optimization */
  .user-portal-page .date-range-container {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(15px);
    padding: 24px;
    margin-bottom: 28px;
    border-radius: 24px;
    border: 1px solid rgba(255, 255, 255, 0.3);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.1), 0 4px 16px rgba(0, 0, 0, 0.03);
  }

  .user-portal-page .dropdown-btn {
    background: rgba(255, 255, 255, 0.8) !important;
    backdrop-filter: blur(8px) !important;
    border: 1px solid rgba(255, 255, 255, 0.3) !important;
    border-radius: 12px !important;
    padding: 12px 16px !important;
    font-size: 14px !important;
    font-weight: 600 !important;
    color: #374151 !important;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
    min-height: 44px !important;
  }

  .user-portal-page .dropdown-btn:hover {
    transform: translateY(-2px) !important;
    background: linear-gradient(135deg, #8b5cf6 0%, #667eea 100%) !important;
    color: white !important;
    box-shadow: 0 8px 24px rgba(139, 92, 246, 0.3) !important;
  }

  /* Metric buttons grid optimization */
  .user-portal-page div[style*="grid-template-columns: repeat(4, 1fr)"] {
    display: grid !important;
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 16px !important;
    max-width: none !important;
    margin: 0 !important;
    padding: 0 16px !important;
  }

  .user-portal-page .metric-btn {
    padding: 20px 16px !important;
    border-radius: 20px !important;
    background: rgba(255, 255, 255, 0.9) !important;
    backdrop-filter: blur(15px) !important;
    border: 1px solid rgba(255, 255, 255, 0.25) !important;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.08), 0 4px 16px rgba(0, 0, 0, 0.03) !important;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
    min-height: 120px !important;
    position: relative !important;
    overflow: hidden !important;
  }

  .user-portal-page .metric-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, #8b5cf6 0%, #667eea 50%, #10b981 100%);
    background-size: 200% 100%;
    animation: shimmer 2.5s infinite;
  }

  .user-portal-page .metric-btn:hover {
    transform: translateY(-6px) !important;
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.12), 0 6px 20px rgba(0, 0, 0, 0.05) !important;
    background: rgba(255, 255, 255, 0.95) !important;
  }

  .user-portal-page .metric-btn div[style*="width: 40px"],
  .user-portal-page .metric-btn div[style*="width: 46px"] {
    width: 36px !important;
    height: 36px !important;
    font-size: 18px !important;
    border-radius: 12px !important;
    margin-bottom: 8px !important;
  }

  .user-portal-page .metric-btn div[style*="font-weight: 700"] {
    font-size: 14px !important;
    font-weight: 700 !important;
    margin-bottom: 4px !important;
    background: linear-gradient(135deg, #8b5cf6 0%, #667eea 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
  }

  .user-portal-page .metric-btn div[style*="font-size: 11px"] {
    font-size: 11px !important;
    color: #6b7280 !important;
    font-weight: 500 !important;
  }

  /* Overall rank button special styling */
  .user-portal-page .metric-btn[style*="border-left: 4px solid #fbbf24"] {
    min-height: 140px !important;
    background: rgba(255, 255, 255, 0.95) !important;
  }

  .user-portal-page .metric-btn[style*="border-left: 4px solid #fbbf24"]::before {
    background: linear-gradient(90deg, #fbbf24 0%, #f59e0b 100%);
  }

  /* Individual rank badges in overall rank button */
  .user-portal-page .metric-btn div[style*="display: flex; justify-content: center; gap: 8px;"] {
    flex-wrap: wrap !important;
    gap: 6px !important;
  }

  .user-portal-page .metric-btn div[style*="background: #f3f4f6"] {
    background: rgba(255, 255, 255, 0.8) !important;
    backdrop-filter: blur(8px) !important;
    border: 1px solid rgba(255, 255, 255, 0.3) !important;
    padding: 6px 10px !important;
    border-radius: 8px !important;
    font-size: 10px !important;
  }

  /* Chart containers optimization */
  .user-portal-page div[style*="background: linear-gradient(135deg, var(--bg-secondary)"] {
    background: rgba(255, 255, 255, 0.95) !important;
    backdrop-filter: blur(15px) !important;
    border-radius: 24px !important;
    padding: 24px !important;
    margin-bottom: 24px !important;
    border: 1px solid rgba(255, 255, 255, 0.3) !important;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.08), 0 4px 16px rgba(0, 0, 0, 0.03) !important;
    position: relative !important;
    overflow: hidden !important;
  }

  .user-portal-page div[style*="background: linear-gradient(135deg, var(--bg-secondary)"]::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, #8b5cf6 0%, #667eea 50%, #10b981 100%);
    background-size: 200% 100%;
    animation: shimmer 3s infinite;
  }

  /* Chart canvas optimization */
  .user-portal-page canvas {
    max-height: 300px !important;
    border-radius: 16px !important;
  }

  /* Time period controls */
  .user-portal-page div[style*="padding: 8px 12px; border-radius: 10px"] {
    background: rgba(255, 255, 255, 0.9) !important;
    backdrop-filter: blur(10px) !important;
    border: 1px solid rgba(255, 255, 255, 0.3) !important;
    border-radius: 16px !important;
    padding: 12px 16px !important;
  }

  /* Buttons optimization */
  .user-portal-page button[style*="background: var(--primary)"],
  .user-portal-page button[style*="background: #10b981"] {
    padding: 12px 18px !important;
    border-radius: 16px !important;
    font-size: 14px !important;
    font-weight: 600 !important;
    min-height: 44px !important;
    backdrop-filter: blur(8px) !important;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
  }

  .user-portal-page button[style*="background: var(--primary)"]:hover,
  .user-portal-page button[style*="background: #10b981"]:hover {
    transform: translateY(-2px) !important;
    box-shadow: 0 8px 24px rgba(102, 126, 234, 0.3) !important;
  }

  /* Tab buttons optimization */
  .user-portal-page .tab-button {
    padding: 16px 20px !important;
    border-radius: 16px !important;
    font-size: 14px !important;
    font-weight: 600 !important;
    min-height: 44px !important;
    background: rgba(255, 255, 255, 0.8) !important;
    backdrop-filter: blur(10px) !important;
    border: 1px solid rgba(255, 255, 255, 0.3) !important;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
  }

  .user-portal-page .tab-button.active {
    background: linear-gradient(135deg, #8b5cf6 0%, #667eea 100%) !important;
    color: white !important;
    transform: translateY(-2px) !important;
    box-shadow: 0 8px 24px rgba(139, 92, 246, 0.3) !important;
  }
}

/* User Portal medium mobile screens */
@media screen and (max-width: 480px) {
  .user-portal-page div[style*="grid-template-columns: repeat(4, 1fr)"] {
    grid-template-columns: 1fr !important;
    gap: 16px !important;
    padding: 0 8px !important;
  }

  .user-portal-page .metric-btn {
    min-height: 100px !important;
    padding: 18px 14px !important;
  }

  .user-portal-page canvas {
    max-height: 250px !important;
  }

  .user-portal-page .tab-button {
    padding: 14px 16px !important;
    font-size: 13px !important;
  }
}

/* User Portal very small screens */
@media screen and (max-width: 360px) {
  .user-portal-page .date-range-container {
    padding: 20px;
    margin-bottom: 20px;
  }

  .user-portal-page .metric-btn {
    min-height: 90px !important;
    padding: 16px 12px !important;
  }

  .user-portal-page canvas {
    max-height: 220px !important;
  }
}

/* Print styles for mobile */
@media print {
  .sidebar {
    display: none;
  }

  .main-content {
    padding: 0;
  }

  .app-container {
    box-shadow: none;
    border: none;
  }
}

/* ========== RESPONSIVE TRANSITION MANAGEMENT ========== */
/* Comprehensive system to ensure smooth desktop-to-mobile transitions */

/* Enhanced viewport management for all screen sizes */
@media (max-width: 1400px) {
  body {
    font-size: 14px;
  }

  .app-container {
    margin: 10px auto;
    max-width: calc(100vw - 20px);
  }
}

/* Improved large tablet handling (1000px - 1199px) */
@media (max-width: 1199px) and (min-width: 1000px) {
  .table-container {
    overflow-x: auto;
    border-radius: 10px;
  }

  .table {
    min-width: 900px;
  }

  /* Slightly smaller buttons but maintain desktop feel */
  .btn {
    padding: 9px 18px;
    font-size: 14px;
  }

  .metric-btn {
    padding: 14px 18px;
    font-size: 15px;
  }
}

/* Mid-range tablet optimizations (900px - 999px) */
@media (max-width: 999px) and (min-width: 900px) {
  .sidebar .nav-item {
    padding: 8px 10px;
    font-size: 13px;
  }

  .table th,
  .table td {
    padding: 10px 8px;
    font-size: 13px;
  }

  .dashboard-tiles {
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  }
}

/* Small tablet range optimization (820px - 899px) */
@media (max-width: 899px) and (min-width: 820px) {
  .header {
    flex-direction: row;
    align-items: center;
    padding: 12px 15px;
  }

  .user-info {
    margin-left: auto;
  }

  /* Start making navigation more compact */
  .sidebar {
    padding: 10px;
  }

  .nav-item {
    min-width: 90px;
    padding: 6px 8px;
    font-size: 12px;
  }

  /* Tables remain functional but more compact */
  .table {
    font-size: 13px;
  }

  .table th,
  .table td {
    padding: 8px 6px;
  }
}

/* Critical transition zone (769px - 819px) - The intermediate fix */
@media (max-width: 819px) and (min-width: 769px) {
  .header {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    padding: 12px;
  }

  .user-info {
    align-self: flex-end;
    margin-left: 0;
  }

  /* Start mobile-like behavior for navigation */
  .sidebar {
    max-height: 70px;
    overflow-x: auto;
  }

  .nav-item {
    min-width: 85px;
    white-space: nowrap;
  }

  /* Tables become horizontally scrollable */
  .table-container {
    overflow-x: scroll;
    -webkit-overflow-scrolling: touch;
  }

  /* Buttons start transitioning to touch-friendly sizes */
  .btn {
    min-height: 38px;
    padding: 8px 14px;
  }

  .metric-btn {
    min-height: 42px;
    padding: 10px 16px;
  }

  /* Modal transitions */
  .modal-content {
    width: 95%;
    max-width: 95%;
  }
}

/* Ensure JavaScript breakpoint alignment remains consistent */
/* The 768px breakpoint in JS should trigger mobile card layouts */
@media (max-width: 768px) {
  /* Force mobile behavior for all components */
  .force-mobile-layout {
    display: block !important;
  }

  .hide-on-mobile {
    display: none !important;
  }

  /* Ensure all tables are properly hidden for mobile cards */
  .table-container table {
    display: none !important;
  }

  .mobile-cards-container {
    display: block !important;
  }
}

/* Performance optimizations for smooth transitions */
@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
    animation: none !important;
  }
}