/* Mobile-First Modern POS Design */

/* Cart item styling - Modern Card Design */
.cart-item-mobile {
  background: linear-gradient(135deg, #ffffff 0%, #f9fafb 100%);
  border-radius: 16px;
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
  border: 1px solid #f3f4f6;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.cart-item-mobile:active {
  transform: scale(0.98);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}

.dark .cart-item-mobile {
  background: linear-gradient(135deg, #1f2937 0%, #111827 100%);
  border-color: #374151;
}

/* Mobile cart overlay */
.mobile-cart-open {
  overflow: hidden !important;
}

/* Enhanced mobile cart */
#mobile-cart-overlay {
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  transition: opacity 0.3s ease;
}

#mobile-cart-panel {
  transform: translateY(100%);
  transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
  border-radius: 24px 24px 0 0;
  box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.3);
  will-change: transform;
}

#mobile-cart-panel.open {
  transform: translateY(0);
}

/* Swipe indicator for mobile cart */
#mobile-cart-panel::before {
  content: '';
  position: absolute;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  width: 40px;
  height: 4px;
  background: #d1d5db;
  border-radius: 2px;
  opacity: 0.5;
}

/* Bottom nav bar spacing for safe areas */
@media (max-width: 768px) {
  #bottom-nav {
    padding-bottom: max(16px, env(safe-area-inset-bottom));
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
  }
  
  .dark #bottom-nav {
    background: rgba(17, 24, 39, 0.9);
  }
  
  #mobile-cart-btn {
    bottom: calc(80px + max(0px, env(safe-area-inset-bottom)));
    box-shadow: 0 8px 24px rgba(99, 102, 241, 0.4);
  }
  
  /* Modern Page Headers */
  .page-header {
    padding: 1.5rem 1rem;
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.05), rgba(147, 51, 234, 0.05));
    border-radius: 16px;
    margin-bottom: 1.5rem;
  }
  
  /* Swipeable cards */
  .swipe-card {
    touch-action: pan-y;
    user-select: none;
  }
}

/* Improved mobile touch targets */
@media (max-width: 640px) {
  /* All interactive elements minimum 48x48px */
  .form-control, 
  button,
  .btn,
  select,
  input[type="text"],
  input[type="number"],
  input[type="email"],
  input[type="tel"],
  a.btn,
  .interactive-element {
    min-height: 48px;
  }
  
  /* Buttons should also have minimum width for better touch */
  button,
  .btn,
  a.btn {
    min-height: 48px;
    padding: 12px 20px;
  }
  
  .qty-btn {
    min-width: 48px;
    min-height: 48px;
    border-radius: 12px;
    font-size: 18px;
    font-weight: 600;
  }
  
  /* Icon-only buttons */
  button:has(i.fa):not(:has(span)),
  .btn:has(i.fa):not(:has(span)) {
    min-width: 48px;
    min-height: 48px;
    padding: 12px;
  }
  
  /* Increase spacing between interactive elements */
  button + button,
  .btn + .btn {
    margin-left: 8px;
  }
  
  /* Better spacing for form elements */
  .form-control {
    padding: 12px 16px;
    font-size: 16px; /* Prevents zoom on iOS */
  }
  
  select.form-control {
    padding: 12px 16px;
    background-position: right 12px center;
  }
  
  /* Product grid optimizations */
  .product-grid-mobile {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    padding: 8px;
  }
  
  .product-card-mobile {
    background: white;
    border-radius: 16px;
    padding: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border: 1px solid #f3f4f6;
    min-height: 120px;
  }
  
  .product-card-mobile:active {
    transform: scale(0.95);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
  }
  
  .dark .product-card-mobile {
    background: #1f2937;
    border-color: #374151;
  }
  
  /* Enhanced search bar */
  .search-bar-mobile {
    position: sticky;
    top: 64px;
    z-index: 15;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    padding: 12px 16px;
    margin: -12px -16px 16px;
  }
  
  .dark .search-bar-mobile {
    background: rgba(17, 24, 39, 0.95);
  }
  
  /* Modal close buttons */
  .modal button[aria-label*="close"],
  .modal button[aria-label*="Close"] {
    min-width: 48px;
    min-height: 48px;
  }
  
  /* Table action buttons in mobile card view */
  .data-table button,
  .data-table .btn {
    min-width: 48px;
    min-height: 48px;
    padding: 12px 16px;
  }
}

/* Active state for buttons on touch devices */
@media (hover: none) {
  button:active, 
  .btn:active,
  .card-hover:active {
    opacity: 0.8;
    transform: scale(0.97);
    transition: all 0.1s ease;
  }
  
  /* Prevent double-tap zoom */
  button,
  .btn,
  a {
    touch-action: manipulation;
  }
}

/* Mobile-Friendly Table Cards */
@media (max-width: 768px) {
  /* Hide table headers and restructure as cards on mobile */
  .data-table thead {
    display: none;
  }
  
  .data-table tbody {
    display: block;
  }
  
  .data-table tbody tr {
    display: block;
    background: white;
    border-radius: 12px;
    margin-bottom: 12px;
    padding: 16px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    border: 1px solid #f3f4f6;
  }
  
  .dark .data-table tbody tr {
    background: #1f2937;
    border-color: #374151;
  }
  
  .data-table tbody tr:hover {
    transform: none;
  }
  
  .data-table tbody td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
    border-bottom: 1px solid #f3f4f6;
    text-align: right;
  }
  
  .dark .data-table tbody td {
    border-bottom-color: #374151;
  }
  
  .data-table tbody td:last-child {
    border-bottom: none;
  }
  
  /* Add labels before data on mobile */
  .data-table tbody td::before {
    content: attr(data-label);
    font-weight: 600;
    color: #6b7280;
    text-align: left;
    margin-right: 12px;
    flex: 1;
  }

  /* Friendly display for full-width status rows (e.g., colspan) */
  .data-table tbody td[colspan] {
    display: block;
    text-align: center;
    border-bottom: none;
    padding: 12px 0;
  }
  .data-table tbody td[colspan]::before {
    content: none;
  }
  
  .dark .data-table tbody td::before {
    color: #9ca3af;
  }
  
  /* Special handling for action buttons */
  .data-table tbody td:has(button),
  .data-table tbody td:has(.btn) {
    justify-content: center;
    border-bottom: none;
    padding-top: 12px;
  }
  
  .data-table tbody td:has(button)::before,
  .data-table tbody td:has(.btn)::before {
    display: none;
  }
  
  /* Responsive table wrapper - allow scrolling as fallback */
  .responsive-table {
    width: 100%;
    margin: 0;
    padding: 0;
  }
}

/* Tablet optimizations */
@media (min-width: 641px) and (max-width: 1024px) {
  .product-grid-tablet {
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
  }
  
  .data-table th,
  .data-table td {
    padding: 1rem 0.75rem;
  }
}

/* Desktop and Tablet enhancements (without changing mobile) */
@media (min-width: 769px) {
  /* Make tables behave as regular tables again on >=769px */
  .data-table thead { display: table-header-group; }
  .data-table tbody { display: table-row-group; }
  .data-table tbody tr { display: table-row; background: transparent; box-shadow: none; border: none; padding: 0; margin: 0; }
  .data-table tbody td { display: table-cell; text-align: left; border-bottom: 1px solid rgba(243,244,246,1); padding: 0.75rem 1rem; }
  .dark .data-table tbody td { border-bottom-color: #374151; }
  .data-table tbody td::before { content: none; }
  .data-table tbody td[colspan] { display: table-cell; text-align: center; }

  /* Billing layout refinements on wider screens */
  .billing-container {
    max-width: 1280px;
    margin-left: auto;
    margin-right: auto;
    padding-left: 1rem;
    padding-right: 1rem;
  }
  /* Ensure order sidebar uses sticky layout rather than fixed when page scroll is needed */
  #order-sidebar {
    position: sticky;
    top: 1rem;
    height: auto;
    max-height: calc(100vh - 2rem);
  }

  /* Hide mobile bottom bar beyond mobile */
  .mobile-bottom-bar { display: none !important; }
}

/* Large desktop fine-tuning */
@media (min-width: 1280px) {
  #billing-product-grid {
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 1rem;
  }
}

/* Generic horizontal tab bar improvements (applies to pages using flex tab bars) */
.tab-container {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 6px;
  scrollbar-width: thin;
}
.tab-container::-webkit-scrollbar {
  height: 6px;
}
.tab-container::-webkit-scrollbar-thumb {
  background: rgba(107, 114, 128, 0.4);
  border-radius: 9999px;
}
.tab-button {
  white-space: nowrap;
  border-radius: 10px 10px 0 0;
  padding: 10px 14px;
  font-weight: 600;
  transition: all 0.2s ease;
}
.tab-button.active {
  background: linear-gradient(to right, #6366f1, #8b5cf6);
  color: white;
}


/* Pull to refresh indicator */
.pull-to-refresh {
  position: absolute;
  top: -50px;
  left: 50%;
  transform: translateX(-50%);
  transition: all 0.3s ease;
}

.pull-to-refresh.visible {
  top: 70px;
}

/* Smooth scroll snap for carousels */
.scroll-snap-x {
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.scroll-snap-x::-webkit-scrollbar {
  display: none;
}

.scroll-snap-item {
  scroll-snap-align: start;
  scroll-snap-stop: always;
}

/* Swipe indicators for mobile */
.swipe-indicator {
  position: absolute;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 6px;
  z-index: 10;
}

.swipe-indicator-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.5);
  transition: all 0.3s ease;
}

.swipe-indicator-dot.active {
  background: white;
  width: 24px;
  border-radius: 4px;
}

/* Mobile modal improvements */
@media (max-width: 768px) {
  /* Full-screen modals on mobile */
  .modal-content {
    max-height: 90vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  
  /* Better modal headers */
  .modal-header {
    position: sticky;
    top: 0;
    background: white;
    z-index: 10;
    border-bottom: 1px solid #e5e7eb;
    padding: 16px;
  }
  
  .dark .modal-header {
    background: #1f2937;
    border-bottom-color: #374151;
  }
  
  /* Improved modal footers */
  .modal-footer {
    position: sticky;
    bottom: 0;
    background: white;
    z-index: 10;
    border-top: 1px solid #e5e7eb;
    padding: 16px;
    padding-bottom: calc(16px + env(safe-area-inset-bottom));
  }
  
  .dark .modal-footer {
    background: #1f2937;
    border-top-color: #374151;
  }
}

/* Enhanced bottom navigation */
@media (max-width: 768px) {
  #bottom-nav {
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.1);
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
  }
  
  .dark #bottom-nav {
    background: rgba(17, 24, 39, 0.95);
  }
  
  /* Active tab indicator */
  .nav-item.active {
    position: relative;
  }
  
  .nav-item.active::before {
    content: '';
    position: absolute;
    top: -2px;
    left: 50%;
    transform: translateX(-50%);
    width: 32px;
    height: 3px;
    background: linear-gradient(to right, #6366f1, #8b5cf6);
    border-radius: 0 0 3px 3px;
  }
}

/* Floating action button improvements */
@media (max-width: 768px) {
  .fab {
    position: fixed;
    bottom: calc(80px + env(safe-area-inset-bottom));
    right: 16px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    box-shadow: 0 4px 16px rgba(99, 102, 241, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 40;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  }
  
  .fab:active {
    transform: scale(0.9);
  }
}

/* Status bar safe area for iOS */
@supports (padding: max(0px)) {
  body {
    padding-top: max(0px, env(safe-area-inset-top));
  }
  
  #app-header {
    padding-top: max(16px, env(safe-area-inset-top));
  }
  
  /* Ensure content doesn't go under notch */
  .page-content {
    padding-top: max(16px, env(safe-area-inset-top));
  }
}

/* Haptic feedback simulation */
@keyframes haptic-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(0.95); }
}

.haptic-feedback:active {
  animation: haptic-pulse 0.2s ease;
}

/* Skeleton loading improvements */
@keyframes skeleton-loading {
  0% {
    background-position: -200px 0;
  }
  100% {
    background-position: calc(200px + 100%) 0;
  }
}

.skeleton {
  background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
  background-size: 200px 100%;
  animation: skeleton-loading 1.5s ease-in-out infinite;
}

.dark .skeleton {
  background: linear-gradient(90deg, #374151 25%, #4b5563 50%, #374151 75%);
  background-size: 200px 100%;
}

/* Modern loader */
.modern-loader {
  width: 48px;
  height: 48px;
  border: 5px solid #f3f4f6;
  border-bottom-color: #6366f1;
  border-radius: 50%;
  display: inline-block;
  animation: rotation 1s linear infinite;
}

@keyframes rotation {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

.dark .modern-loader {
  border-color: #374151;
  border-bottom-color: #6366f1;
}

/* Notification badge */
.notification-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  background: linear-gradient(135deg, #ef4444, #dc2626);
  color: white;
  border-radius: 10px;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(239, 68, 68, 0.4);
  border: 2px solid white;
  animation: badge-pop 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.dark .notification-badge {
  border-color: #1f2937;
}

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

/* Empty state illustrations */
.empty-state {
  padding: 48px 24px;
  text-align: center;
}

.empty-state i {
  font-size: 64px;
  color: #d1d5db;
  margin-bottom: 16px;
  opacity: 0.5;
}

.dark .empty-state i {
  color: #4b5563;
}

/* Success/Error animations */
@keyframes success-scale {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.1); }
}

.success-animation {
  animation: success-scale 0.5s ease;
}

/* Improved focus states for accessibility */
@media (max-width: 768px) {
  button:focus-visible,
  a:focus-visible,
  input:focus-visible,
  select:focus-visible,
  textarea:focus-visible {
    outline: 3px solid #6366f1;
    outline-offset: 2px;
  }
}