/*
 * Complete iOS Design System
 * Authentic Apple Store/iPhone app experience
 * Based on Apple's Human Interface Guidelines
 */

/* ===== iOS CSS CUSTOM PROPERTIES ===== */
:root {
  /* iOS Typography System - San Francisco Font Stack */
  --ios-font-stack: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'SF Pro Text', system-ui, sans-serif;
  
  /* iOS Typography Scale */
  --ios-large-title-size: 34px;
  --ios-title-1-size: 28px;
  --ios-title-2-size: 22px;
  --ios-headline-size: 17px;
  --ios-body-size: 17px;
  --ios-caption-size: 12px;
  
  /* iOS Letter Spacing */
  --ios-body-letter-spacing: -0.408px;
  --ios-headline-letter-spacing: -0.43px;
  
  /* iOS Spacing System (8px grid) */
  --ios-space-xs: 4px;
  --ios-space-sm: 8px;
  --ios-space-md: 12px;
  --ios-space-lg: 16px;
  --ios-space-xl: 24px;
  --ios-space-2xl: 32px;
  --ios-space-3xl: 48px;
  --ios-space-4xl: 64px;
  
  /* iOS Touch Targets */
  --ios-min-touch-target: 44px;
  
  /* iOS Border Radius */
  --ios-radius-sm: 6px;
  --ios-radius-md: 10px;
  --ios-radius-lg: 12px;
  --ios-radius-xl: 16px;
  
  /* iOS Light Mode Colors (RGB values) */
  --ios-blue: 0, 122, 255;
  --ios-blue-dark: 10, 132, 255;
  --ios-background-primary: 255, 255, 255;
  --ios-background-secondary: 242, 242, 247;
  --ios-background-tertiary: 255, 255, 255;
  --ios-background-grouped: 242, 242, 247;
  --ios-background-elevated: 255, 255, 255;
  --ios-label-primary: 0, 0, 0;
  --ios-label-secondary: 60, 60, 67;
  --ios-label-tertiary: 60, 60, 67;
  --ios-separator: 60, 60, 67;
  --ios-fill: 120, 120, 128;
  --ios-fill-secondary: 120, 120, 128;
  --ios-fill-tertiary: 118, 118, 128;
  
  /* iOS Gray Scale */
  --ios-gray: 142, 142, 147;
  --ios-gray2: 174, 174, 178;
  --ios-gray3: 199, 199, 204;
  --ios-gray4: 209, 209, 214;
  --ios-gray5: 229, 229, 234;
  --ios-gray6: 242, 242, 247;
  
  /* iOS System Colors */
  --ios-red: 255, 59, 48;
  --ios-orange: 255, 149, 0;
  --ios-yellow: 255, 204, 0;
  --ios-green: 52, 199, 89;
  --ios-mint: 0, 199, 190;
  --ios-teal: 48, 176, 199;
  --ios-cyan: 50, 173, 230;
  --ios-indigo: 88, 86, 214;
  --ios-purple: 175, 82, 222;
  --ios-pink: 255, 45, 85;
  --ios-brown: 162, 132, 94;
  
  /* iOS Animations */
  --ios-spring-easing: cubic-bezier(0.175, 0.885, 0.32, 1.275);
  --ios-ease-out: cubic-bezier(0.25, 0.46, 0.45, 0.94);
  --ios-transition-fast: 0.2s;
  --ios-transition-medium: 0.3s;
  --ios-transition-slow: 0.5s;
}

/* iOS Dark Mode Colors */
[data-theme="dark"], [data-bs-theme="dark"] {
  --ios-blue: 10, 132, 255;
  --ios-background-primary: 0, 0, 0;
  --ios-background-secondary: 28, 28, 30;
  --ios-background-tertiary: 44, 44, 46;
  --ios-background-grouped: 0, 0, 0;
  --ios-background-elevated: 28, 28, 30;
  --ios-label-primary: 255, 255, 255;
  --ios-label-secondary: 235, 235, 245;
  --ios-label-tertiary: 235, 235, 245;
  --ios-separator: 84, 84, 88;
  --ios-fill: 120, 120, 128;
  --ios-fill-secondary: 99, 99, 102;
  --ios-fill-tertiary: 72, 72, 74;
  
  /* Dark mode gray scale */
  --ios-gray: 142, 142, 147;
  --ios-gray2: 99, 99, 102;
  --ios-gray3: 72, 72, 74;
  --ios-gray4: 58, 58, 60;
  --ios-gray5: 44, 44, 46;
  --ios-gray6: 28, 28, 30;
}

/* ===== BASE TYPOGRAPHY SYSTEM ===== */
html {
  font-family: var(--ios-font-stack);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

body {
  font-family: var(--ios-font-stack);
  font-size: var(--ios-body-size);
  letter-spacing: var(--ios-body-letter-spacing);
  line-height: 1.4;
  background-color: rgb(var(--ios-background-grouped));
  color: rgb(var(--ios-label-primary));
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
}

/* iOS Typography Classes */
.ios-large-title {
  font-size: var(--ios-large-title-size);
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: -0.374px;
}

.ios-title-1 {
  font-size: var(--ios-title-1-size);
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: -0.374px;
}

.ios-title-2 {
  font-size: var(--ios-title-2-size);
  font-weight: 700;
  line-height: 1.3;
  letter-spacing: -0.26px;
}

.ios-headline {
  font-size: var(--ios-headline-size);
  font-weight: 600;
  line-height: 1.3;
  letter-spacing: var(--ios-headline-letter-spacing);
}

.ios-body {
  font-size: var(--ios-body-size);
  font-weight: 400;
  line-height: 1.4;
  letter-spacing: var(--ios-body-letter-spacing);
}

.ios-caption {
  font-size: var(--ios-caption-size);
  font-weight: 400;
  line-height: 1.3;
  letter-spacing: 0px;
}

/* ===== IOS COMPONENT SYSTEM ===== */

/* iOS Buttons */
.btn-ios-primary {
  background-color: rgb(var(--ios-blue));
  border: none;
  border-radius: var(--ios-radius-md);
  font-size: var(--ios-body-size);
  font-weight: 600;
  letter-spacing: var(--ios-body-letter-spacing);
  color: white;
  min-height: var(--ios-min-touch-target);
  padding: var(--ios-space-md) var(--ios-space-xl);
  transition: all var(--ios-transition-fast) var(--ios-ease-out);
  transform: translateZ(0);
  -webkit-tap-highlight-color: transparent;
}

.btn-ios-primary:hover {
  background-color: rgba(var(--ios-blue), 0.8);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(var(--ios-blue), 0.3);
}

.btn-ios-primary:active {
  transform: scale(0.98);
  transition: transform 0.1s ease-out;
}

.btn-ios-secondary {
  background-color: rgb(var(--ios-fill-tertiary));
  border: none;
  border-radius: var(--ios-radius-md);
  font-size: var(--ios-body-size);
  font-weight: 600;
  color: rgb(var(--ios-label-primary));
  min-height: var(--ios-min-touch-target);
  padding: var(--ios-space-md) var(--ios-space-xl);
  transition: all var(--ios-transition-fast) var(--ios-ease-out);
  transform: translateZ(0);
  -webkit-tap-highlight-color: transparent;
}

.btn-ios-secondary:hover {
  background-color: rgb(var(--ios-fill-secondary));
  transform: translateY(-1px);
}

.btn-ios-secondary:active {
  transform: scale(0.98);
  transition: transform 0.1s ease-out;
}

/* iOS Cards */
.card-ios {
  background-color: rgb(var(--ios-background-elevated));
  border: none;
  border-radius: var(--ios-radius-lg);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  transition: all var(--ios-transition-fast) var(--ios-ease-out);
  transform: translateZ(0);
  overflow: hidden;
}

.card-ios:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.card-ios-header {
  background-color: rgb(var(--ios-background-secondary));
  border-bottom: 1px solid rgba(var(--ios-separator), 0.3);
  padding: var(--ios-space-lg) var(--ios-space-xl);
  font-weight: 600;
  color: rgb(var(--ios-label-primary));
}

.card-ios-body {
  padding: var(--ios-space-xl);
}

/* iOS Form Controls */
.form-control-ios {
  background-color: rgb(var(--ios-fill-tertiary));
  border: none;
  border-radius: var(--ios-radius-md);
  padding: var(--ios-space-md) var(--ios-space-lg);
  font-size: var(--ios-body-size);
  color: rgb(var(--ios-label-primary));
  min-height: var(--ios-min-touch-target);
  transition: all var(--ios-transition-fast) var(--ios-ease-out);
}

.form-control-ios:focus {
  outline: 2px solid rgb(var(--ios-blue));
  outline-offset: -2px;
  background-color: rgb(var(--ios-background-elevated));
  box-shadow: 0 0 0 4px rgba(var(--ios-blue), 0.1);
}

.form-control-ios::placeholder {
  color: rgb(var(--ios-label-tertiary));
}

/* iOS Navigation */
.navbar-ios {
  background-color: rgba(28,28,30,0.98);
  border-bottom: 1px solid rgba(255,255,255,0.08);
  padding: var(--ios-space-sm) var(--ios-space-xl);
  min-height: var(--ios-min-touch-target);
}

.navbar-brand-ios {
  font-weight: 700;
  font-size: var(--ios-headline-size);
  color: rgb(var(--ios-label-primary));
  text-decoration: none;
}

/* iOS Navigation Links */
.nav-link-ios {
  font-size: var(--ios-body-size);
  font-weight: 500;
  color: rgb(var(--ios-label-secondary));
  padding: var(--ios-space-md) var(--ios-space-lg);
  border-radius: var(--ios-radius-md);
  transition: all var(--ios-transition-fast) var(--ios-ease-out);
  text-decoration: none;
  min-height: var(--ios-min-touch-target);
  display: flex;
  align-items: center;
  -webkit-tap-highlight-color: transparent;
}

.nav-link-ios:hover {
  background-color: rgba(var(--ios-fill), 0.1);
  color: rgb(var(--ios-label-primary));
}

.nav-link-ios.active {
  background-color: rgb(var(--ios-blue));
  color: white;
  font-weight: 600;
}

/* iOS Tables */
.table-ios {
  background-color: rgb(var(--ios-background-elevated));
  border-radius: var(--ios-radius-lg);
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.table-ios th {
  background-color: rgb(var(--ios-background-secondary));
  font-weight: 600;
  font-size: var(--ios-caption-size);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: rgb(var(--ios-label-secondary));
  padding: var(--ios-space-lg) var(--ios-space-xl);
  border: none;
}

.table-ios td {
  padding: var(--ios-space-lg) var(--ios-space-xl);
  border-bottom: 1px solid rgba(var(--ios-separator), 0.3);
  color: rgb(var(--ios-label-primary));
}

.table-ios tr:last-child td {
  border-bottom: none;
}

/* iOS List Groups */
.list-group-ios {
  background-color: rgb(var(--ios-background-elevated));
  border-radius: var(--ios-radius-lg);
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.list-group-item-ios {
  background-color: transparent;
  border: none;
  border-bottom: 1px solid rgba(var(--ios-separator), 0.3);
  padding: var(--ios-space-lg) var(--ios-space-xl);
  color: rgb(var(--ios-label-primary));
  transition: background-color var(--ios-transition-fast) var(--ios-ease-out);
}

.list-group-item-ios:last-child {
  border-bottom: none;
}

.list-group-item-ios:hover {
  background-color: rgba(var(--ios-fill), 0.05);
}

/* iOS Modals */
.modal-content-ios {
  background-color: rgb(var(--ios-background-elevated));
  border: none;
  border-radius: var(--ios-radius-xl);
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
  overflow: hidden;
}

.modal-header-ios {
  background-color: rgb(var(--ios-background-secondary));
  border-bottom: 1px solid rgba(var(--ios-separator), 0.3);
  padding: var(--ios-space-xl);
}

.modal-body-ios {
  padding: var(--ios-space-xl);
}

.modal-footer-ios {
  background-color: rgb(var(--ios-background-secondary));
  border-top: 1px solid rgba(var(--ios-separator), 0.3);
  padding: var(--ios-space-xl);
}

/* ===== IOS MOBILE OPTIMIZATIONS ===== */

/* iPhone Breakpoints */
@media (max-width: 428px) { /* iPhone Pro Max */
  :root {
    --ios-space-xl: 20px;
    --ios-space-2xl: 28px;
  }
  
  .ios-large-title {
    font-size: 28px;
  }
  
  .ios-title-1 {
    font-size: 24px;
  }
}

@media (max-width: 390px) { /* iPhone Pro */
  :root {
    --ios-space-xl: 18px;
    --ios-space-2xl: 24px;
  }
}

@media (max-width: 375px) { /* iPhone SE */
  :root {
    --ios-space-xl: 16px;
    --ios-space-2xl: 20px;
  }
  
  .ios-large-title {
    font-size: 24px;
  }
}

/* iOS Safe Area Support - Enhanced for Standalone Mode */
body {
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

/* Standalone mode detection and full-screen support */
@media all and (display-mode: standalone) {
  body {
    background-color: rgb(var(--ios-background-grouped)) !important;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
  }
  
  /* Hide scroll bars in standalone mode */
  ::-webkit-scrollbar {
    display: none;
  }
  
  /* Enhanced safe area for notch devices */
  .navbar-ios-mobile {
    padding-top: calc(env(safe-area-inset-top) + var(--ios-space-sm)) !important;
  }
  
  /* Adjust main content for safe areas */
  main {
    padding-bottom: calc(env(safe-area-inset-bottom) + var(--ios-space-lg)) !important;
  }
}

/* Full-screen app experience */
html, body {
  height: 100vh;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
}

/* Prevent Safari address bar from showing on scroll - only for public pages */
body.public-page {
  position: fixed;
  overflow: hidden;
  width: 100%;
  height: 100%;
}

/* Re-enable scrolling for standalone mode */
@media all and (display-mode: standalone) {
  body.public-page {
    position: static;
    overflow: auto;
    height: auto;
    min-height: 100vh;
  }
}

/* Ensure authenticated pages have normal scrolling */
body:not(.public-page) {
  position: static;
  overflow: auto;
  height: auto;
  min-height: 100vh;
}

/* iOS Safari specific fixes */
@supports (-webkit-touch-callout: none) {
  /* Hide address bar on iOS Safari */
  .main-content {
    padding-bottom: 100px;
    margin-bottom: -100px;
  }
  
  /* Prevent pull-to-refresh and bounce */
  body {
    overscroll-behavior: none;
    -webkit-overflow-scrolling: touch;
  }
  
  /* Fix for iOS Safari address bar */
  .container-fluid {
    min-height: calc(100vh + 1px);
  }
}

/* iPhone X and newer safe area adjustments */
@supports (padding-top: env(safe-area-inset-top)) {
  .navbar-ios-mobile {
    padding-top: calc(env(safe-area-inset-top) + 8px) !important;
  }
  
  .container-fluid {
    padding-bottom: calc(env(safe-area-inset-bottom) + 16px) !important;
  }
}

/* ===== IOS ACCESSIBILITY ===== */

/* Focus States */
*:focus {
  outline: 2px solid rgb(var(--ios-blue));
  outline-offset: 2px;
}

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

/* Dark Mode Auto-Detection */
@media (prefers-color-scheme: dark) {
  :root {
    --ios-blue: 10, 132, 255;
    --ios-background-primary: 0, 0, 0;
    --ios-background-secondary: 28, 28, 30;
    --ios-background-tertiary: 44, 44, 46;
    --ios-background-grouped: 0, 0, 0;
    --ios-background-elevated: 28, 28, 30;
    --ios-label-primary: 255, 255, 255;
    --ios-label-secondary: 235, 235, 245;
    --ios-label-tertiary: 235, 235, 245;
    --ios-separator: 84, 84, 88;
    --ios-fill: 120, 120, 128;
    --ios-fill-secondary: 99, 99, 102;
    --ios-fill-tertiary: 72, 72, 74;
  }
}

/* ===== IOS UTILITY CLASSES ===== */

/* Spacing Utilities */
.ios-p-xs { padding: var(--ios-space-xs); }
.ios-p-sm { padding: var(--ios-space-sm); }
.ios-p-md { padding: var(--ios-space-md); }
.ios-p-lg { padding: var(--ios-space-lg); }
.ios-p-xl { padding: var(--ios-space-xl); }
.ios-p-2xl { padding: var(--ios-space-2xl); }

.ios-m-xs { margin: var(--ios-space-xs); }
.ios-m-sm { margin: var(--ios-space-sm); }
.ios-m-md { margin: var(--ios-space-md); }
.ios-m-lg { margin: var(--ios-space-lg); }
.ios-m-xl { margin: var(--ios-space-xl); }
.ios-m-2xl { margin: var(--ios-space-2xl); }

/* Color Utilities */
.ios-text-primary { color: rgb(var(--ios-label-primary)); }
.ios-text-secondary { color: rgb(var(--ios-label-secondary)); }
.ios-text-tertiary { color: rgb(var(--ios-label-tertiary)); }
.ios-text-blue { color: rgb(var(--ios-blue)); }
.ios-text-red { color: rgb(var(--ios-red)); }
.ios-text-green { color: rgb(var(--ios-green)); }
.ios-text-orange { color: rgb(var(--ios-orange)); }
.ios-text-yellow { color: rgb(var(--ios-yellow)); }

.ios-bg-primary { background-color: rgb(var(--ios-background-primary)); }
.ios-bg-secondary { background-color: rgb(var(--ios-background-secondary)); }
.ios-bg-tertiary { background-color: rgb(var(--ios-background-tertiary)); }
.ios-bg-elevated { background-color: rgb(var(--ios-background-elevated)); }

/* Border Radius Utilities */
.ios-rounded-sm { border-radius: var(--ios-radius-sm); }
.ios-rounded-md { border-radius: var(--ios-radius-md); }
.ios-rounded-lg { border-radius: var(--ios-radius-lg); }
.ios-rounded-xl { border-radius: var(--ios-radius-xl); }

/* Animation Utilities */
.ios-transition { transition: all var(--ios-transition-fast) var(--ios-ease-out); }
.ios-spring { transition: all var(--ios-transition-medium) var(--ios-spring-easing); }

/* Touch Optimizations */
.ios-touch-target {
  min-height: var(--ios-min-touch-target);
  min-width: var(--ios-min-touch-target);
}

/* Backdrop Blur - disabled on iOS to prevent compositing bugs */
.ios-backdrop-blur {
  /* backdrop-filter intentionally omitted to prevent iOS Safari modal blur bug */
}

/* Remove tap highlights */
.ios-no-tap-highlight {
  -webkit-tap-highlight-color: transparent;
}

/* GPU Acceleration */
.ios-gpu-accelerated {
  transform: translateZ(0);
  will-change: transform;
}

/* ===== IOS SPECIFIC COMPONENT OVERRIDES ===== */

/* Override Bootstrap with iOS styling */
.btn-primary {
  background-color: rgb(var(--ios-blue)) !important;
  border: none !important;
  border-radius: var(--ios-radius-md) !important;
  font-weight: 600 !important;
  min-height: var(--ios-min-touch-target) !important;
  transition: all var(--ios-transition-fast) var(--ios-ease-out) !important;
}

.btn-primary:hover {
  background-color: rgba(var(--ios-blue), 0.8) !important;
  transform: translateY(-1px) !important;
}

.btn-primary:active {
  transform: scale(0.98) !important;
}

.card {
  background-color: rgb(var(--ios-background-elevated)) !important;
  border: none !important;
  border-radius: var(--ios-radius-lg) !important;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1) !important;
}

.form-control {
  background-color: rgb(var(--ios-fill-tertiary)) !important;
  border: none !important;
  border-radius: var(--ios-radius-md) !important;
  color: rgb(var(--ios-label-primary)) !important;
}

.form-control:focus {
  outline: 2px solid rgb(var(--ios-blue)) !important;
  box-shadow: 0 0 0 4px rgba(var(--ios-blue), 0.1) !important;
}

.navbar {
  background-color: #1c1c1e !important;
  border-bottom: 1px solid rgba(255,255,255,0.08) !important;
}

.table {
  background-color: rgb(var(--ios-background-elevated)) !important;
  border-radius: var(--ios-radius-lg) !important;
  overflow: hidden !important;
}

.table th {
  background-color: rgb(var(--ios-background-secondary)) !important;
  font-weight: 600 !important;
  text-transform: uppercase !important;
  font-size: var(--ios-caption-size) !important;
  letter-spacing: 0.5px !important;
}

/* Dark mode specific overrides */
[data-bs-theme="dark"] .form-control {
  background-color: rgb(var(--ios-fill-tertiary)) !important;
  color: rgb(var(--ios-label-primary)) !important;
}

[data-bs-theme="dark"] .btn-secondary {
  background-color: rgb(var(--ios-fill-tertiary)) !important;
  color: rgb(var(--ios-label-primary)) !important;
  border: none !important;
}