/* Custom styles beyond Tailwind - Modern Mobile-First Design */

/* Root Variables */
:root {
  --safe-area-inset-bottom: env(safe-area-inset-bottom, 0px);
  --header-height: 64px;
  --bottom-nav-height: 64px;
}

/* Smooth Scrolling */
html {
  scroll-behavior: smooth;
  -webkit-tap-highlight-color: transparent;
}

/* Safe Area for iOS Devices */
.safe-area-bottom {
  padding-bottom: calc(16px + var(--safe-area-inset-bottom));
}

/* Toast notifications - Modern Design */
.toast {
  transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.4s ease;
  transform: translateX(120%) scale(0.9);
  opacity: 0;
  width: 100%;
  max-width: 360px;
  backdrop-filter: blur(10px);
  border-radius: 12px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
}

.toast.show {
  transform: translateX(0) scale(1);
  opacity: 1;
}

/* Loading spinner */
@keyframes spinner {
  to { transform: rotate(360deg); }
}

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

/* Modern Card Styles */
.modern-card {
  background: white;
  border-radius: 16px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  overflow: hidden;
}

.modern-card:hover {
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
  transform: translateY(-2px);
}

.modern-card:active {
  transform: scale(0.98);
}

/* Glass Morphism Effect */
.glass-effect {
  background: rgba(255, 255, 255, 0.7);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.3);
}

.dark .glass-effect {
  background: rgba(31, 41, 55, 0.7);
  border: 1px solid rgba(75, 85, 99, 0.3);
}

/* Desktop layout with cart sidebar */
@media (min-width: 768px) {
  #main-content, .container {
    margin-right: 384px;
    width: auto;
    max-width: none;
  }
  
  #order-sidebar {
    border-left: 1px solid #e5e7eb;
    display: block !important;
  }
}

/* Mobile-specific fixes for cart */
@media (max-width: 767px) {
  /* Modern bottom navbar styling */
  #bottom-nav {
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.08);
  }
  
  /* Active state for bottom nav */
  .nav-btn.active {
    color: #6366f1 !important;
  }
  
  .nav-btn.active .nav-indicator {
    opacity: 1 !important;
    width: 20px;
  }
  
  .nav-btn.active[data-page="billing"] {
    color: white !important;
  }
  
  /* Improved touch feedback */
  .nav-btn:active {
    opacity: 0.7;
  }
  
  /* Cart button special styling */
  .nav-btn[data-page="billing"] {
    position: relative;
  }
  
  .nav-btn[data-page="billing"] .cart-count {
    position: absolute;
    top: 2px;
    right: 50%;
    margin-right: -20px;
    background: linear-gradient(135deg, #ef4444, #dc2626);
    color: white;
    border-radius: 9999px;
    height: 20px;
    min-width: 20px;
    padding: 0 6px;
    font-size: 10px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(239, 68, 68, 0.4);
    border: 2px solid white;
  }
}

/* Pull-to-refresh indicator */
.ptr-indicator {
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  padding: 8px 16px;
  background: rgba(99, 102, 241, 0.9);
  color: white;
  border-radius: 0 0 12px 12px;
  font-size: 12px;
  font-weight: 500;
  opacity: 0;
  transition: opacity 0.3s;
  z-index: 100;
}

/* Barcode scanner overlay - Modern Design */
.scanner-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.95);
  backdrop-filter: blur(10px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.scanner-viewport {
  width: 85%;
  max-width: 500px;
  aspect-ratio: 4/3;
  position: relative;
  overflow: hidden;
  border-radius: 20px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.scanner-target {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 70%;
  height: 40%;
  border: 3px solid #6366f1;
  border-radius: 12px;
  box-shadow: 0 0 0 4000px rgba(0, 0, 0, 0.6), 0 0 30px rgba(99, 102, 241, 0.5);
  animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

@keyframes pulse {
  0%, 100% {
    box-shadow: 0 0 0 0 rgba(99, 102, 241, 0.7), 0 0 0 4000px rgba(0, 0, 0, 0.6);
  }
  50% {
    box-shadow: 0 0 0 15px rgba(99, 102, 241, 0), 0 0 0 4000px rgba(0, 0, 0, 0.6);
  }
}

/* Form styles - Modern Input Design */
.form-group {
  margin-bottom: 1.25rem;
}

.form-label {
  display: block;
  margin-bottom: 0.5rem;
  font-weight: 600;
  font-size: 0.875rem;
  color: #374151;
  letter-spacing: 0.01em;
}

.dark .form-label {
  color: #e5e7eb;
}

.form-control {
  width: 100%;
  padding: 0.875rem 1rem;
  font-size: 1rem;
  line-height: 1.5;
  border: 2px solid #e5e7eb;
  border-radius: 12px;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  background: white;
}

.form-control:focus {
  border-color: #6366f1;
  outline: 0;
  box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.1);
  background: white;
}

.form-control::placeholder {
  color: #9ca3af;
}

/* Dark mode form control */
.dark .form-control {
  background-color: #1f2937;
  border-color: #374151;
  color: #e5e7eb;
}

.dark .form-control:focus {
  border-color: #6366f1;
  background-color: #1f2937;
  box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.2);
}

.dark .form-control::placeholder {
  color: #6b7280;
}

/* Responsive table - Modern Card-Based on Mobile */
.responsive-table {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 0 -1rem;
  padding: 0 1rem;
  width: calc(100% + 2rem);
  border-radius: 12px;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  background: white;
  border-radius: 12px;
  overflow: hidden;
}

.dark .data-table {
  background: #1f2937;
}

.data-table th, 
.data-table td {
  padding: 1rem;
  text-align: left;
  border-bottom: 1px solid #f3f4f6;
}

.dark .data-table th,
.dark .data-table td {
  border-bottom-color: #374151;
}

.data-table thead th {
  background: linear-gradient(to bottom, #f9fafb, #f3f4f6);
  font-weight: 700;
  color: #111827;
  font-size: 0.875rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom-width: 2px;
  position: sticky;
  top: 0;
  z-index: 10;
}

.dark .data-table thead th {
  background: linear-gradient(to bottom, #374151, #1f2937);
  color: #e5e7eb;
  border-bottom-color: #4b5563;
}

.data-table tbody tr {
  transition: all 0.2s ease;
}

.data-table tbody tr:hover {
  background-color: #f9fafb;
  transform: scale(1.005);
}

.dark .data-table tbody tr:hover {
  background-color: #374151;
}

/* Mobile optimizations - Enhanced Touch Experience */
@media (max-width: 640px) {
  .data-table th,
  .data-table td {
    padding: 0.75rem;
    font-size: 0.875rem;
  }

  /* Prevent zooming on inputs in iOS */
  input[type="text"],
  input[type="number"],
  input[type="email"],
  input[type="tel"],
  input[type="password"],
  select,
  textarea {
    font-size: 16px !important;
  }
  
  /* Mobile card layout for tables */
  .mobile-card-table {
    display: block;
  }
  
  .mobile-card-table tbody,
  .mobile-card-table tr {
    display: block;
    margin-bottom: 1rem;
  }
  
  .mobile-card-table tr {
    background: white;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    padding: 1rem;
  }
  
  .dark .mobile-card-table tr {
    background: #1f2937;
  }
}

/* Improved touch targets (44px min for accessibility) */
@media (max-width: 640px) {
  .form-control, 
  button,
  .btn,
  select,
  input[type="text"],
  input[type="number"],
  input[type="email"],
  input[type="tel"] {
    min-height: 48px;
  }
  
  .qty-btn {
    min-width: 48px;
    min-height: 48px;
  }
}

/* Active state for buttons on touch devices */
@media (hover: none) {
  button:active, .btn:active {
    opacity: 0.7;
    transform: scale(0.96);
    transition: all 0.1s ease;
  }
}

/* Card shadow effect - Enhanced Modern Design */
.card-hover {
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.card-hover:hover {
  transform: translateY(-4px);
  box-shadow: 0 20px 40px -10px rgba(0, 0, 0, 0.15);
}

.card-hover:active {
  transform: translateY(-2px) scale(0.98);
}

/* Active navigation button - Modern Indicator */
.nav-btn.active {
  color: #6366f1 !important;
}

.nav-item.active {
  background: linear-gradient(to right, rgba(99, 102, 241, 0.1), transparent);
  color: #6366f1 !important;
  border-left: 3px solid #6366f1;
  font-weight: 600;
}

/* Button Styles - Modern & Consistent */
.btn-primary {
  background: linear-gradient(135deg, #6366f1, #4f46e5);
  color: white;
  padding: 0.75rem 1.5rem;
  border-radius: 12px;
  font-weight: 600;
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  border: none;
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(99, 102, 241, 0.4);
}

.btn-primary:active {
  transform: translateY(0);
  box-shadow: 0 2px 8px rgba(99, 102, 241, 0.3);
}

.btn-secondary {
  background: white;
  color: #6366f1;
  padding: 0.75rem 1.5rem;
  border-radius: 12px;
  font-weight: 600;
  border: 2px solid #6366f1;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.btn-secondary:hover {
  background: #6366f1;
  color: white;
  transform: translateY(-2px);
}

/* Floating Action Button (FAB) */
.fab {
  position: fixed;
  bottom: calc(80px + var(--safe-area-inset-bottom));
  right: 1rem;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: linear-gradient(135deg, #6366f1, #4f46e5);
  color: white;
  box-shadow: 0 8px 24px rgba(99, 102, 241, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  z-index: 40;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  border: none;
}

.fab:hover {
  transform: scale(1.1) rotate(90deg);
  box-shadow: 0 12px 32px rgba(99, 102, 241, 0.5);
}

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

@media (min-width: 768px) {
  .fab {
    bottom: 2rem;
  }
}

/* Skeleton Loading Animation */
.skeleton {
  background: linear-gradient(90deg, #f3f4f6 25%, #e5e7eb 50%, #f3f4f6 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: 8px;
}

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

/* Ripple effect for touch feedback */
.ripple {
  position: relative;
  overflow: hidden;
}

.ripple::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0;
  height: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.5);
  transform: translate(-50%, -50%);
  transition: width 0.6s, height 0.6s;
}

.ripple:active::after {
  width: 300px;
  height: 300px;
}