/**
 * ChefSuite Pro - Mobile-First Enhancements
 * Enhanced responsive design and PWA optimisations
 */

/* Mobile-First Base Styles */
:root {
  --mobile-header-height: 60px;
  --mobile-nav-height: 70px;
  --mobile-padding: 16px;
  --mobile-margin: 12px;
  --touch-target-size: 44px;
  --mobile-font-size: 16px;
  --mobile-line-height: 1.5;
}

/* Touch-friendly interactions */
* {
  -\webkit-tap-highlight-color: rgba(0, 0, 0, 0.1);
  -webkit-touch-callout: none;
}

/* Improved touch targets */
button, .btn, a, input, select, textarea {
  min-height: var(--touch-target-size);
  min-width: var(--touch-target-size);
  touch-action: manipulation;
}

/* Mobile-optimised typography */
@media (max-width: 768px) {
  body {
    font-size: var(--mobile-font-size);
    line-height: var(--mobile-line-height);
    -webkit-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
  }

  h1 { font-size: 1.75rem; }
  h2 { font-size: 1.5rem; }
  h3 { font-size: 1.25rem; }
  h4 { font-size: 1.125rem; }
  h5 { font-size: 1rem; }
  h6 { font-size: 0.875rem; }
}

/* Enhanced mobile navigation */
.mobile-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--mobile-nav-height);
  background: white;
  border-top: 1px solid #e9ecef;
  z-index: 1000;
  display: flex;
  justify-content: space-around;
  align-items: center;
  box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
}

.mobile-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
    justify-content: center;
  padding: 8px;
  text-decoration: none;
  color: #6c757d;
    transition: color 0.2s ease;
  min-width: var(--touch-target-size);
  min-height: var(--touch-target-size);
}

.mobile-nav-item.active,
.mobile-nav-item:hover {
  color: #007bff;
}

.mobile-nav-item i {
  font-size: 1.2rem;
  margin-bottom: 2px;
}

.mobile-nav-item span {
  font-size: 0.75rem;
  font-weight: 500;
}

/* Mobile-optimized cards */
@media (max-width: 768px) {
  .card {
    margin-bottom: var(--mobile-margin);
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  }

  .card-body {
    padding: var(--mobile-padding);
  }

  .card-header {
    padding: 12px var(--mobile-padding);
    border-bottom: 1px solid #e9ecef;
  }
}

/* Enhanced mobile forms */
@media (max-width: 768px) {
  .form-control {
    font-size: var(--mobile-font-size);
    padding: 12px 16px;
    border-radius: 8px;
    border: 2px solid #e9ecef;
    transition: border-color 0.2s ease;
  }

  .form-control:focus {
    border-color: #007bff;
    box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, 0.25);
  }

  .form-label {
    font-weight: 600;
    margin-bottom: 8px;
    color: #495057;
  }

  .form-group {
    margin-bottom: 20px;
  }

  .btn {
    padding: 12px 24px;
    font-size: var(--mobile-font-size);
    font-weight: 600;
    border-radius: 8px;
    border: none;
    transition: all 0.2s ease;
  }

  .btn-primary {
    background: linear-gradient(135deg, #007bff 0%, #0056b3 100%);
    color: white;
  }

  .btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 123, 255, 0.3);
  }
}

/* Mobile-optimized tables */
@media (max-width: 768px) {
  .table-responsive {
    border: none;
    border-radius: 8px;
    overflow: hidden;
  }

  .table {
    font-size: 0.875rem;
    margin-bottom: 0;
  }

  .table th,
  .table td {
    padding: 12px 8px;
    border-top: 1px solid #e9ecef;
  }

  .table thead th {
    background: #f8f9fa;
    font-weight: 600;
    color: #495057;
    border-bottom: 2px solid #dee2e6;
  }

  /* Stack table on very small screens */
  @media (max-width: 576px) {
    .table-stack {
      display: block;
    }

    .table-stack thead {
      display: none;
    }

    .table-stack tbody,
    .table-stack tr,
    .table-stack td {
      display: block;
    }

    .table-stack tr {
      border: 1px solid #dee2e6;
      border-radius: 8px;
      margin-bottom: 12px;
      padding: 12px;
      background: white;
    }

    .table-stack td {
      border: none;
      padding: 6px 0;
      position: relative;
      padding-left: 50%;
    }

    .table-stack td:before {
      content: attr(data-label) ": ";
      position: absolute;
      left: 0;
      width: 45%;
      font-weight: 600;
      color: #495057;
    }
  }
}

/* Mobile-optimized modals */
@media (max-width: 768px) {
  .modal-dialog {
    margin: 20px;
    max-width: calc(100vw - 40px);
  }

  .modal-content {
    border-radius: 12px;
    border: none;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
  }

  .modal-header {
    padding: 20px;
    border-bottom: 1px solid #e9ecef;
  }

  .modal-body {
    padding: 20px;
  }

  .modal-footer {
    padding: 20px;
    border-top: 1px solid #e9ecef;
  }

  .modal-title {
    font-size: 1.25rem;
    font-weight: 600;
  }
}

/* PWA-specific styles */
.pwa-mode {
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}

.pwa-mode .mobile-nav {
  padding-bottom: env(safe-area-inset-bottom);
}

/* Install prompt styles */
.install-prompt {
  position: fixed;
  bottom: 80px;
  left: 20px;
  right: 20px;
  background: white;
  border-radius: 12px;
  padding: 16px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
  z-index: 1001;
  display: none;
  animation: slideUp 0.3s ease;
}

.install-prompt.show {
  display: block;
}

@keyframes slideUp {
  from {
    transform: translateY(100%);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.install-prompt-content {
  display: flex;
  align-items: center;
  gap: 12px;
}

.install-prompt-icon {
  width: 48px;
  height: 48px;
  background: linear-gradient(135deg, #007bff 0%, #0056b3 100%);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 1.5rem;
}

.install-prompt-text {
  flex: 1;
}

.install-prompt-title {
  font-weight: 600;
  margin-bottom: 4px;
  color: #212529;
}

.install-prompt-subtitle {
  font-size: 0.875rem;
  color: #6c757d;
  margin-bottom: 0;
}

.install-prompt-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.install-prompt-btn {
  padding: 8px 16px;
  border-radius: 6px;
  border: none;
  font-weight: 600;
  font-size: 0.875rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

.install-prompt-btn.primary {
  background: #007bff;
  color: white;
}

.install-prompt-btn.secondary {
  background: #f8f9fa;
  color: #6c757d;
}

/* Offline indicator */
.offline-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  background: #dc3545;
  color: white;
  padding: 8px 16px;
  text-align: center;
  font-size: 0.875rem;
  font-weight: 600;
  z-index: 1002;
  transform: translateY(-100%);
  transition: transform 0.3s ease;
}

.offline-banner.show {
  transform: translateY(0);
}

/* Loading states for mobile */
.mobile-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  text-align: center;
}

.mobile-loading-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid #e9ecef;
  border-top: 3px solid #007bff;
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin-bottom: 16px;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

.mobile-loading-text {
  color: #6c757d;
  font-size: 0.875rem;
}

/* Swipe gestures */
.swipe-container {
  overflow-x: hidden;
  position: relative;
}

.swipe-item {
  transition: transform 0.3s ease;
}

.swipe-item.swiping {
  transition: none;
}

/* Pull-to-refresh */
.pull-to-refresh {
  position: relative;
  overflow: hidden;
}

.pull-to-refresh-indicator {
  position: absolute;
  top: -60px;
  left: 50%;
  transform: translateX(-50%);
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: white;
  border-radius: 50%;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  transition: top 0.3s ease;
}

.pull-to-refresh.pulling .pull-to-refresh-indicator {
  top: 20px;
}

/* Accessibility improvements for mobile */
@media (max-width: 768px) {
  .sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
  }

  /* Focus styles for keyboard navigation */
  button:focus,
  .btn:focus,
  a:focus,
  input:focus,
  select:focus,
  textarea:focus {
    outline: 2px solid #007bff;
    outline-offset: 2px;
  }

  /* High contrast mode support */
  @media (prefers-contrast: high) {
    .card {
      border: 2px solid #000;
    }

    .btn {
      border: 2px solid currentColor;
    }
  }

  /* Reduced motion support */
  @media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
      animation-duration: 0.01ms !important;
      animation-iteration-count: 1 !important;
      transition-duration: 0.01ms !important;
    }
  }
}

/* Dark mode mobile optimizations */
@media (prefers-color-scheme: dark) {
  .mobile-nav {
    background: #1a1a1a;
    border-top-color: #333;
  }

  .mobile-nav-item {
    color: #adb5bd;
  }

  .mobile-nav-item.active,
  .mobile-nav-item:hover {
    color: #007bff;
  }

  .install-prompt {
    background: #1a1a1a;
    color: white;
  }

  .install-prompt-title {
    color: white;
  }

  .install-prompt-subtitle {
    color: #adb5bd;
  }

  .offline-banner {
    background: #dc3545;
  }
}