/* =============================================================================
   DINEHUB MOBILE OPTIMIZATIONS
   iOS & Android App Ready Enhancements
   ============================================================================= */

/* =============================================================================
   SAFE AREA INSETS - iPhone Notch/Dynamic Island Support
   ============================================================================= */

:root {
  /* Safe area fallbacks */
  --safe-area-top: env(safe-area-inset-top, 0px);
  --safe-area-bottom: env(safe-area-inset-bottom, 0px);
  --safe-area-left: env(safe-area-inset-left, 0px);
  --safe-area-right: env(safe-area-inset-right, 0px);
}

html {
  /* Prevent rubber-band scrolling on iOS */
  overscroll-behavior: none;

  /* Enable smooth scrolling */
  scroll-behavior: smooth;

  /* Base font size for rem calculations */
  font-size: 16px;
}

body {
  /* Apply safe area insets */
  padding-top: var(--safe-area-top);
  padding-bottom: var(--safe-area-bottom);
  padding-left: var(--safe-area-left);
  padding-right: var(--safe-area-right);

  /* Prevent horizontal overflow */
  max-width: 100vw;
  overflow-x: hidden;

  /* iOS smooth scrolling */
  -webkit-overflow-scrolling: touch;

  /* Prevent pull-to-refresh on body */
  overscroll-behavior-y: contain;
}

/* =============================================================================
   TOUCH OPTIMIZATIONS
   ============================================================================= */

/* Remove tap highlight on iOS */
* {
  -webkit-tap-highlight-color: rgba(0, 0, 0, 0.05);

  /* Prevent zoom on double-tap */
  touch-action: manipulation;
}

/* Re-enable specific touch actions where needed */
.scrollable {
  touch-action: pan-y;
  -webkit-overflow-scrolling: touch;
}

.zoomable {
  touch-action: pinch-zoom;
}

/* Smooth momentum scrolling on iOS */
.scrollable-container {
  -webkit-overflow-scrolling: touch;
  overflow-y: auto;
}

/* =============================================================================
   MINIMUM TOUCH TARGET SIZES
   ============================================================================= */

/* Buttons - 48px minimum (Android), 44px recommended (iOS) */
button,
.btn,
.button,
a.button,
[role="button"] {
  min-width: 48px;
  min-height: 48px;
  padding: 12px 20px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
}

/* Navigation items */
nav a,
.nav-link,
.nav-item {
  min-height: 48px;
  padding: 12px 16px;
  display: flex;
  align-items: center;
}

/* Icon buttons */
.icon-btn,
.nav-btn,
button[aria-label] {
  min-width: 48px;
  min-height: 48px;
  padding: 12px;
}

/* Checkbox and radio inputs */
input[type="checkbox"],
input[type="radio"] {
  min-width: 24px;
  min-height: 24px;
  margin: 12px;
}

/* Ensure labels are tappable */
label {
  min-height: 44px;
  display: flex;
  align-items: center;
  cursor: pointer;
  -webkit-tap-highlight-color: rgba(0, 0, 0, 0.05);
}

/* =============================================================================
   PREVENT iOS INPUT ZOOM
   ============================================================================= */

input,
select,
textarea {
  /* Prevent zoom on focus (iOS) */
  font-size: 16px !important;

  /* Better mobile UX */
  border-radius: 8px;
  padding: 14px 16px;

  /* Prevent horizontal overflow */
  max-width: 100%;
  box-sizing: border-box;
}

/* Better input types for mobile keyboards */
input[type="email"] {
  inputmode: email;
  autocomplete: email;
}

input[type="tel"] {
  inputmode: tel;
  autocomplete: tel;
}

input[type="number"] {
  inputmode: numeric;
  pattern: [0-9]*;
}

input[type="url"] {
  inputmode: url;
}

input[type="search"] {
  inputmode: search;
}

/* =============================================================================
   HORIZONTAL SCROLL PREVENTION
   ============================================================================= */

*,
*::before,
*::after {
  /* Prevent overflow */
  max-width: 100%;
  box-sizing: border-box;
}

/* Containers */
.container,
.modern-container,
.dashboard-container,
.auth-container,
main,
section {
  width: 100%;
  max-width: 100vw;
  overflow-x: hidden;
  padding-left: max(16px, var(--safe-area-left));
  padding-right: max(16px, var(--safe-area-right));
}

/* Images and media */
img,
video,
iframe,
embed,
object {
  max-width: 100%;
  height: auto;
}

/* Tables */
table {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  display: block;
}

/* =============================================================================
   RESPONSIVE BREAKPOINTS
   ============================================================================= */

/* Small phones - iPhone SE */
@media (max-width: 375px) {
  html {
    font-size: 14px;
  }

  .container {
    padding-left: 12px;
    padding-right: 12px;
  }

  h1 {
    font-size: 1.75rem;
  }

  h2 {
    font-size: 1.5rem;
  }

  button,
  .btn {
    font-size: 14px;
    padding: 10px 16px;
  }
}

/* Standard mobile phones */
@media (max-width: 480px) {
  .stats-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .form-row {
    grid-template-columns: 1fr;
  }

  /* Stack cards */
  .card-grid {
    grid-template-columns: 1fr;
  }
}

/* Large phones and small tablets */
@media (min-width: 481px) and (max-width: 768px) {
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .card-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* Tablets */
@media (min-width: 769px) and (max-width: 1024px) {
  html {
    font-size: 15px;
  }

  .stats-grid {
    grid-template-columns: repeat(3, 1fr);
  }

  .container {
    max-width: 960px;
  }
}

/* Desktop */
@media (min-width: 1025px) {
  .container {
    max-width: 1200px;
  }

  .mobile-only {
    display: none !important;
  }
}

/* Landscape mode - phones */
@media (max-height: 500px) and (orientation: landscape) {
  /* Reduce vertical padding */
  .section {
    padding-top: 20px;
    padding-bottom: 20px;
  }

  /* Smaller headers */
  h1 {
    font-size: 1.5rem;
    margin: 8px 0;
  }

  /* Compact nav */
  .nav-container {
    height: 50px;
  }

  /* Hide less important elements */
  .hero-subtitle,
  .feature-description {
    display: none;
  }
}

/* =============================================================================
   FIXED POSITIONING WITH SAFE AREAS
   ============================================================================= */

/* Fixed header/navbar */
.fixed-header,
.navbar,
.simple-nav {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  padding-top: var(--safe-area-top);
  padding-left: var(--safe-area-left);
  padding-right: var(--safe-area-right);
  z-index: 1000;
}

/* Fixed footer */
.fixed-footer,
.mobile-bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  padding-bottom: var(--safe-area-bottom);
  padding-left: var(--safe-area-left);
  padding-right: var(--safe-area-right);
  z-index: 1000;
}

/* Floating action button */
.fab {
  position: fixed;
  bottom: calc(24px + var(--safe-area-bottom));
  right: calc(24px + var(--safe-area-right));
  z-index: 999;
}

/* Modal dialogs */
.modal {
  padding-top: var(--safe-area-top);
  padding-bottom: var(--safe-area-bottom);
  padding-left: var(--safe-area-left);
  padding-right: var(--safe-area-right);
}

/* =============================================================================
   MOBILE NAVIGATION
   ============================================================================= */

@media (max-width: 768px) {
  /* Hide desktop navigation */
  .desktop-nav {
    display: none !important;
  }

  /* Show mobile navigation */
  .mobile-nav,
  .mobile-menu-btn {
    display: flex !important;
  }

  /* Hamburger menu button */
  .mobile-menu-btn {
    min-width: 48px;
    min-height: 48px;
    padding: 12px;
    background: transparent;
    border: none;
    cursor: pointer;
  }

  /* Mobile menu */
  .mobile-menu {
    position: fixed;
    top: 0;
    right: -100%;
    width: 85vw;
    max-width: 360px;
    height: 100vh;
    height: 100dvh; /* Dynamic viewport height */
    background: white;
    box-shadow: -2px 0 10px rgba(0, 0, 0, 0.1);
    transition: right 0.3s ease;
    z-index: 2000;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;

    /* Safe areas */
    padding-top: var(--safe-area-top);
    padding-bottom: var(--safe-area-bottom);
  }

  .mobile-menu.open {
    right: 0;
  }

  /* Mobile menu overlay */
  .mobile-menu-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    z-index: 1999;
  }

  .mobile-menu-overlay.open {
    opacity: 1;
    visibility: visible;
  }

  /* Bottom navigation bar */
  .mobile-bottom-nav {
    display: flex;
    justify-content: space-around;
    align-items: center;
    height: calc(56px + var(--safe-area-bottom));
    background: white;
    border-top: 1px solid #e5e7eb;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.05);
  }

  .mobile-bottom-nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 8px 4px;
    min-height: 48px;
    text-decoration: none;
    color: #6b7280;
    font-size: 11px;
    transition: color 0.2s ease;
  }

  .mobile-bottom-nav-item.active {
    color: #3b82f6;
  }

  .mobile-bottom-nav-icon {
    font-size: 20px;
  }

  /* Adjust main content for bottom nav */
  .dashboard-main {
    padding-bottom: calc(56px + var(--safe-area-bottom) + 20px);
  }
}

/* =============================================================================
   DARK MODE SUPPORT
   ============================================================================= */

@media (prefers-color-scheme: dark) {
  :root {
    --bg-primary: #111827;
    --bg-secondary: #1f2937;
    --bg-tertiary: #374151;
    --text-primary: #f9fafb;
    --text-secondary: #d1d5db;
    --text-tertiary: #9ca3af;
    --border-light: #374151;
    --border-medium: #4b5563;
    --border-dark: #6b7280;
  }

  body {
    background: var(--bg-primary);
    color: var(--text-primary);
  }

  .card,
  .modal,
  .dropdown {
    background: var(--bg-secondary);
    color: var(--text-primary);
  }

  input,
  select,
  textarea {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border-color: var(--border-medium);
  }

  input::placeholder {
    color: var(--text-tertiary);
  }
}

/* =============================================================================
   LOADING SKELETON SCREENS
   ============================================================================= */

.skeleton {
  background: linear-gradient(
    90deg,
    rgba(0, 0, 0, 0.06) 25%,
    rgba(0, 0, 0, 0.12) 50%,
    rgba(0, 0, 0, 0.06) 75%
  );
  background-size: 200% 100%;
  animation: skeleton-loading 1.5s infinite;
  border-radius: 8px;
}

@keyframes skeleton-loading {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

.skeleton-text {
  height: 1em;
  margin-bottom: 0.5em;
  border-radius: 4px;
}

.skeleton-heading {
  height: 2em;
  width: 60%;
  margin-bottom: 1em;
}

.skeleton-card {
  height: 200px;
  border-radius: 12px;
}

.skeleton-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
}

/* Dark mode skeleton */
@media (prefers-color-scheme: dark) {
  .skeleton {
    background: linear-gradient(
      90deg,
      rgba(255, 255, 255, 0.05) 25%,
      rgba(255, 255, 255, 0.10) 50%,
      rgba(255, 255, 255, 0.05) 75%
    );
    background-size: 200% 100%;
  }
}

/* =============================================================================
   ACCESSIBILITY - REDUCED MOTION
   ============================================================================= */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }

  .skeleton {
    animation: none;
  }
}

/* =============================================================================
   PERFORMANCE OPTIMIZATIONS
   ============================================================================= */

/* Use GPU acceleration for animations */
.animate,
.transition {
  will-change: transform;
  transform: translateZ(0);
  backface-visibility: hidden;
}

/* Lazy load images */
img[loading="lazy"] {
  opacity: 0;
  transition: opacity 0.3s ease;
}

img[loading="lazy"].loaded {
  opacity: 1;
}

/* =============================================================================
   UTILITY CLASSES
   ============================================================================= */

.mobile-only {
  display: none;
}

.desktop-only {
  display: block;
}

@media (max-width: 768px) {
  .mobile-only {
    display: block !important;
  }

  .desktop-only {
    display: none !important;
  }

  .mobile-flex {
    display: flex !important;
  }

  .mobile-grid {
    display: grid !important;
  }
}

/* Text truncation */
.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.truncate-2 {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Screen reader only */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

/* =============================================================================
   iOS SPECIFIC FIXES
   ============================================================================= */

/* Fix iOS Safari bottom bar issue */
@supports (-webkit-touch-callout: none) {
  .full-height {
    min-height: -webkit-fill-available;
  }

  html {
    height: -webkit-fill-available;
  }
}

/* Remove iOS input shadow */
input[type="text"],
input[type="email"],
input[type="tel"],
input[type="password"],
textarea {
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
}

/* Fix iOS button rendering */
button,
input[type="submit"],
input[type="button"] {
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
}

/* =============================================================================
   ANDROID SPECIFIC ENHANCEMENTS
   ============================================================================= */

/* Material Design ripple effect */
.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;
}

/* =============================================================================
   PWA INSTALL PROMPT
   ============================================================================= */

.install-prompt {
  position: fixed;
  bottom: calc(20px + var(--safe-area-bottom));
  left: 20px;
  right: 20px;
  background: white;
  border-radius: 12px;
  padding: 16px 20px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
  display: flex;
  align-items: center;
  gap: 16px;
  transform: translateY(200%);
  transition: transform 0.3s ease;
  z-index: 9999;
}

.install-prompt.show {
  transform: translateY(0);
}

.install-prompt-icon {
  font-size: 32px;
  flex-shrink: 0;
}

.install-prompt-content {
  flex: 1;
}

.install-prompt-title {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 4px;
}

.install-prompt-message {
  font-size: 14px;
  color: #6b7280;
}

.install-prompt-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.install-btn {
  background: #3b82f6;
  color: white;
  border: none;
  padding: 10px 20px;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  min-width: 80px;
}

.dismiss-btn {
  background: transparent;
  color: #6b7280;
  border: none;
  padding: 10px;
  cursor: pointer;
}
