/* FAST Ordering - Custom Styles */

/* Color Variables */
:root {
  /* FUSE Primary Colors */
  --primary-charcoal: #374151;
  --primary-charcoal-dark: #1f2937;
  --primary-teal: #14b8a6;
  --primary-teal-dark: #0d9488;
  --primary-green: #10b981;
  --primary-green-dark: #059669;
  
  /* Background Colors */
  --bg-primary: #f8fafc;
  --bg-secondary: #ffffff;
  --bg-charcoal: #374151;
  --bg-charcoal-dark: #1f2937;
  
  /* Text Colors */
  --text-primary: #1f2937;
  --text-secondary: #6b7280;
  --text-light: #9ca3af;
  --text-white: #ffffff;
  
  /* Accent Colors */
  --accent-blue: #3b82f6;
  --accent-teal: #14b8a6;
  --accent-green: #10b981;
  --accent-red: #ef4444;
  --accent-orange: #f59e0b;
  
  /* Border Colors */
  --border-light: #e5e7eb;
  --border-medium: #d1d5db;
  
  /* Shadow Colors */
  --shadow-light: rgba(0, 0, 0, 0.1);
  --shadow-medium: rgba(0, 0, 0, 0.15);
  --shadow-teal: rgba(20, 184, 166, 0.3);
}

/* Animations */
@keyframes slideIn {
  from { transform: translateX(-100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}

/* Utility Classes */
.animate-slide-in { animation: slideIn 0.3s ease-out; }
.animate-fade-in { animation: fadeIn 0.2s ease-out; }
.animate-pulse-hover:hover { animation: pulse 0.3s ease-in-out; }

/* Background Classes */
.gradient-bg { 
  background: var(--primary-charcoal); 
}

.gradient-bg-green { 
  background: var(--primary-green); 
}

.gradient-bg-teal { 
  background: var(--primary-teal); 
}

/* Glass Effect */
.glass-effect { 
  backdrop-filter: blur(10px); 
  background: rgba(255, 255, 255, 0.1); 
}

/* Shadow Effects */
.shadow-glow { 
  box-shadow: 0 0 20px var(--shadow-teal); 
}

.shadow-card {
  box-shadow: 0 4px 6px -1px var(--shadow-light), 0 2px 4px -1px var(--shadow-light);
}

.shadow-card-hover {
  box-shadow: 0 10px 15px -3px var(--shadow-light), 0 4px 6px -2px var(--shadow-light);
}

/* Button Styles */
.btn-primary,
.btn-secondary,
.btn-success,
.btn-warning,
.btn-danger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.65rem 1.4rem;
  border-radius: 9999px !important;
  font-weight: 600;
  line-height: 1.25;
  font-size: 1rem;
  text-decoration: none;
  border: none;
  cursor: pointer;
  color: var(--text-white);
  background: var(--primary-teal);
  transition: transform 0.18s ease, box-shadow 0.18s ease, background 0.18s ease, opacity 0.18s ease;
  box-shadow: 0 10px 18px -12px rgba(17, 24, 39, 0.45);
}

.btn-primary {
  background: var(--primary-teal);
  color: var(--text-white);
}

.btn-primary:hover {
  background: var(--primary-teal-dark);
  transform: translateY(-1px);
  box-shadow: 0 14px 26px -14px rgba(17, 24, 39, 0.55);
}

.btn-secondary {
  background: var(--primary-charcoal);
  color: var(--text-white);
}

.btn-secondary:hover {
  background: var(--primary-charcoal-dark);
  transform: translateY(-1px);
  box-shadow: 0 14px 26px -14px rgba(17, 24, 39, 0.55);
}

.btn-success {
  background: var(--primary-teal);
  color: var(--text-white);
}

.btn-success:hover {
  background: var(--primary-teal-dark);
  transform: translateY(-1px);
  box-shadow: 0 14px 26px -14px rgba(17, 24, 39, 0.55);
}

.btn-warning {
  background: var(--accent-orange);
}

.btn-warning:hover {
  background: #d97706;
  transform: translateY(-1px);
  box-shadow: 0 14px 26px -14px rgba(17, 24, 39, 0.45);
}

.btn-danger {
  background: var(--accent-red);
}

.btn-danger:hover {
  background: #dc2626;
  transform: translateY(-1px);
  box-shadow: 0 14px 26px -14px rgba(17, 24, 39, 0.45);
}

.btn-primary:focus,
.btn-secondary:focus,
.btn-success:focus,
.btn-warning:focus,
.btn-danger:focus {
  outline: none;
  box-shadow: 0 0 0 4px rgba(20, 184, 166, 0.16);
}

.customer-nav {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.75rem;
}

.customer-nav-link {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.55rem 1.25rem;
  border-radius: 9999px;
  font-weight: 600;
  font-size: 1rem;
  line-height: 1.2;
  transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease, color 0.2s ease;
  white-space: nowrap;
}

.customer-nav-link:hover {
  transform: translateY(-1px);
}

.customer-nav-link i {
  font-size: 0.95em;
}

.btn-small {
  padding: 0.4rem 0.85rem;
  font-size: 0.875rem;
  border-radius: 9999px !important;
}

.btn-disabled {
  opacity: 0.6;
  cursor: not-allowed;
  pointer-events: none;
  transform: none !important;
  box-shadow: none !important;
}

/* Form Styles */
.form-input {
  @apply w-full border-2 border-gray-200 rounded-lg px-3 py-2 transition-all duration-200;
  border-color: var(--border-light);
}

.form-input:focus {
  border-color: var(--primary-teal);
  box-shadow: 0 0 0 3px rgba(20, 184, 166, 0.1);
  outline: none;
}

/* Card Styles */
.card {
  @apply bg-white rounded-2xl shadow-card overflow-hidden;
  background: var(--bg-secondary);
}

.card-hover {
  @apply transition-all duration-200;
}

.card-hover:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-card-hover);
}

/* Icon Colors */
.icon-primary { color: var(--primary-teal); }
.icon-success { color: var(--primary-green); }
.icon-info { color: var(--accent-blue); }
.icon-warning { color: var(--accent-orange); }
.icon-danger { color: var(--accent-red); }

/* Text Colors */
.text-primary { color: var(--text-primary); }
.text-secondary { color: var(--text-secondary); }
.text-light { color: var(--text-light); }
.text-white { color: var(--text-white); }

/* Device-Specific Styles */

/* Mobile Devices (phones) */
@media (max-width: 768px) {
  /* Mobile-specific variables */
  :root {
    --mobile-font-size: 14px;
    --mobile-padding: 12px;
    --mobile-margin: 8px;
    --mobile-safe-bottom: env(safe-area-inset-bottom, 20px);
  }
  
  /* Ensure body has proper mobile padding */
  body {
    padding-bottom: var(--mobile-safe-bottom);
  }
  
  /* Mobile navigation - vertical stack */
  .mobile-nav {
    @apply flex flex-col space-y-2;
  }
  
  /* Mobile buttons - larger touch targets */
  .btn-mobile {
    @apply py-4 px-6 text-lg;
    min-height: 48px; /* iOS recommended touch target */
  }
  
  /* Mobile forms - larger inputs */
  .form-input-mobile {
    @apply py-4 px-4 text-lg;
    min-height: 48px;
  }
  
  /* Mobile cards - full width */
  .card-mobile {
    @apply w-full mx-2;
  }
  
  /* Hide original cart on mobile */
  #cart {
    display: none !important;
  }
  
  /* Mobile cart - always visible sidebar */
  .cart-mobile {
    position: fixed;
    right: 0;
    top: 0;
    height: 100dvh;
    max-height: 100vh;
    width: 320px;
    z-index: 50;
    background: white;
    border-left: 1px solid #e5e7eb;
    transform: translateX(100%);
    transition: transform 0.3s ease-in-out;
    box-shadow: -4px 0 6px -1px rgba(0, 0, 0, 0.1);
    /* Prevent iOS from treating this as a modal */
    -webkit-overflow-scrolling: touch;
    /* Remove default iOS modal styling */
    webkit-appearance: none;
    display: flex;
    flex-direction: column;
  }
  
  /* Ensure mobile cart content has enough bottom padding */
  .cart-mobile .px-4.pt-4.pb-8 {
    padding-bottom: calc(2rem + var(--mobile-safe-bottom)); /* 32px + safe area bottom padding for submit button */
  }

  /* Make cart content scrollable while keeping submit button visible */
  .cart-mobile .flex.flex-col {
    height: 100%;
  }
  
  .cart-mobile .overflow-y-auto {
    flex: 1;
    overflow-y: auto;
    padding-bottom: 0px; /* Extra padding so users can scroll past submit button and click it reliably */
  }

  /* Invisible spacer to prevent rubberbanding - users can scroll past submit button */
  .cart-mobile #invisible-spacer {
    height: calc(160px + env(safe-area-inset-bottom, 0px));
    width: 100%;
    pointer-events: none;
    flex-shrink: 0;
    background: transparent;
  }

  /* Ensure submit order form is sticky at bottom of cart */
  .cart-mobile form[method="post"][action*="/submit"] {
    position: sticky;
    bottom: calc(env(safe-area-inset-bottom, 0px) + 0px); /* Position above iOS safe area */
    background: white;
    border-top: 2px solid #e5e7eb;
    padding-top: 1rem;
    padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 1.5rem);
    margin-top: auto;
    z-index: 10;
    box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.1);
  }

  /* Parent div containing the submit form should also be sticky */
  .cart-mobile .flex.flex-col > div > .mt-6:last-child {
    position: sticky;
    bottom: 0;
    background: white;
    margin-bottom: 0;
    z-index: 10;
  }
  
  .cart-mobile.show {
    transform: translateX(0);
  }
  
  /* Mobile cart toggle button - respects safe areas for iPhone notch */
  .cart-toggle-mobile {
    position: fixed;
    bottom: calc(var(--mobile-safe-bottom) + env(safe-area-inset-bottom, 0px) + 20px);
    right: calc(20px + env(safe-area-inset-right, 0px));
    z-index: 50;
    width: 64px;
    height: 64px;
    background: #14b8a6;
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    transition: all 0.2s ease-in-out;
    border: none;
    cursor: pointer;
  }
  
  .cart-toggle-mobile:hover {
    background: #0d9488;
    transform: scale(1.05);
  }
  
  .cart-toggle-mobile:active {
    transform: scale(0.95);
  }
  
  /* Mobile cart overlay */
  .cart-overlay-mobile {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 40;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease-in-out, visibility 0.3s ease-in-out;
  }
  
  .cart-overlay-mobile.show {
    opacity: 1;
    visibility: visible;
  }
  
  /* Mobile-specific grid - single column */
  .mobile-grid {
    @apply grid grid-cols-1 gap-4;
  }
  
  /* Mobile search - full width */
  .search-mobile {
    @apply w-full;
  }
  
  /* Mobile product cards - stacked */
  .product-card-mobile {
    @apply w-full mb-4;
  }
  
  /* Mobile order buttons - more compact */
  .btn-success {
    padding: 12px 16px !important;
    font-size: 16px !important;
    min-height: 44px;
  }
  
  /* Mobile modal and form improvements */
  .modal-mobile {
    padding-bottom: calc(var(--mobile-safe-bottom) + 1rem);
  }
  
  .modal-mobile .modal-content {
    max-height: calc(100vh - var(--mobile-safe-bottom) - 2rem);
    margin-bottom: var(--mobile-safe-bottom);
  }
  
  .form-mobile {
    padding-bottom: calc(var(--mobile-safe-bottom) + 2rem);
  }
  
  .form-mobile .form-actions {
    position: sticky;
    bottom: 0;
    background: white;
    padding: 1rem;
    border-top: 1px solid #e5e7eb;
    margin: 0 -1rem -1rem -1rem;
    padding-bottom: calc(1rem + var(--mobile-safe-bottom));
  }
  
  /* Mobile button improvements */
  .btn-mobile-improved {
    min-height: 48px;
    padding: 14px 20px;
    font-size: 16px;
    border-radius: 9999px !important;
    font-weight: 600;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    transition: all 0.2s ease;
  }
  
  .btn-mobile-improved:active {
    transform: translateY(1px);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
  }
}

/* Tablet Devices */
@media (min-width: 769px) and (max-width: 1024px) {
  /* Tablet-specific variables */
  :root {
    --tablet-font-size: 16px;
    --tablet-padding: 16px;
    --tablet-margin: 12px;
  }
  
  /* Tablet grid - 2 columns */
  .tablet-grid {
    @apply grid grid-cols-2 gap-6;
  }
  
  /* Tablet navigation - horizontal */
  .tablet-nav {
    @apply flex flex-row space-x-4;
  }
}

/* Desktop Devices */
@media (min-width: 1025px) {
  /* Desktop-specific variables */
  :root {
    --desktop-font-size: 16px;
    --desktop-padding: 24px;
    --desktop-margin: 16px;
  }
  
  /* Desktop grid - 3+ columns */
  .desktop-grid {
    @apply grid grid-cols-3 gap-8;
  }
  
  /* Desktop sidebar */
  .desktop-sidebar {
    @apply w-64 fixed left-0 top-0 h-full;
  }
  
  /* Desktop hover effects */
  .desktop-hover:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-card-hover);
  }
}

/* Touch Device Detection */
@media (hover: none) and (pointer: coarse) {
  /* Touch-specific styles */
  .touch-target {
    min-height: 44px;
    min-width: 44px;
  }
  
  /* Remove hover effects on touch devices */
  .no-hover:hover {
    transform: none;
    box-shadow: none;
  }
}

/* High DPI Displays */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
  /* Retina/high DPI optimizations */
  .retina-image {
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;
  }
}

/* Dark Mode Support */
@media (prefers-color-scheme: dark) {
  :root {
    --bg-primary: #1a1a1a;
    --bg-secondary: #2d2d2d;
    --text-primary: #ffffff;
    --text-secondary: #d1d5db;
    --border-light: #374151;
  }
  
  .dark-mode {
    background: var(--bg-primary);
    color: var(--text-primary);
  }
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* iOS-Specific Optimizations */
.os-ios {
  /* iOS Safari specific fixes */
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.os-ios .btn-mobile {
  /* iOS button styling */
  -webkit-appearance: none;
  border-radius: 8px;
}

.os-ios .form-input-mobile {
  /* iOS input styling */
  -webkit-appearance: none;
  border-radius: 8px;
}

/* Android-Specific Optimizations */
.os-android {
  /* Android Chrome specific fixes */
  -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1);
}

.os-android .btn-mobile {
  /* Android button styling */
  border-radius: 4px;
}

.os-android .form-input-mobile {
  /* Android input styling */
  border-radius: 4px;
}

/* iPhone Specific (smaller screens) */
@media (max-width: 480px) {
  .device-mobile {
    /* iPhone-specific optimizations */
    --mobile-font-size: 13px;
    --mobile-padding: 8px;
  }
  
  .cart-mobile {
    width: 100vw; /* Full width on small phones */
  }
  
  .btn-mobile {
    @apply py-3 px-4 text-base;
    min-height: 44px; /* Smaller touch target for small phones */
  }
}

/* iPhone Pro Max and larger Android phones */
@media (min-width: 481px) and (max-width: 768px) {
  .device-mobile {
    /* Larger phone optimizations */
    --mobile-font-size: 15px;
    --mobile-padding: 16px;
  }
  
  .cart-mobile {
    width: 320px; /* Fixed width for larger phones */
  }
}

/* Fix for Backorder Filter Checkboxes on Mobile */
@media (max-width: 768px) {
  /* Ensure checkboxes don't get hidden or distorted by mobile form styles */
  input[type="checkbox"].form-input-mobile {
    min-height: unset !important;
    padding: 0 !important;
    -webkit-appearance: checkbox !important;
    appearance: checkbox !important;
  }

  /* Explicitly target the backorder filter checkboxes */
  #hide-backordered, #only-backordered {
    -webkit-appearance: checkbox !important;
    appearance: checkbox !important;
    width: 20px !important;
    height: 20px !important;
    min-width: 20px !important;
    min-height: 20px !important;
    display: inline-block !important;
    margin-top: 4px !important;
    padding: 0 !important;
    border: 1px solid #d1d5db !important;
    border-radius: 4px !important;
    visibility: visible !important;
    opacity: 1 !important;
    /* Ensure background doesn't hide the checkmark */
    background-color: white !important; 
  }
}
