/**
 * iOS-Style Enhancements for Pool Buddy
 * Optimized for App Store quality mobile experience
 */

/* ===== iOS-Style Animations ===== */
@keyframes slideInUp {
  from {
    transform: translateY(100%);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

@keyframes slideInRight {
  from {
    transform: translateX(100%);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes scaleIn {
  from {
    transform: scale(0.95);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

@keyframes buttonPress {
  0% { transform: scale(1); }
  50% { transform: scale(0.95); }
  100% { transform: scale(1); }
}

/* Page transition animations */
.page-enter {
  animation: slideInRight 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.modal-enter {
  animation: slideInUp 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.fade-enter {
  animation: fadeIn 0.2s ease-in;
}

.scale-enter {
  animation: scaleIn 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ===== iOS-Style Touch Feedback ===== */
.ios-button,
button:not(.no-press-effect),
.nav-item,
.card:has(button),
.clickable {
  -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
  transition: transform 0.1s, opacity 0.1s;
}

.ios-button:active,
button:not(.no-press-effect):active,
.nav-item:active,
.clickable:active {
  transform: scale(0.97);
  opacity: 0.8;
}

/* ===== Enhanced Bottom Navigation ===== */
nav[role="navigation"] {
  backdrop-filter: blur(10px);
  background: rgba(255, 255, 255, 0.95);
  box-shadow: 0 -1px 3px rgba(0, 0, 0, 0.1);
}

/* Modern iOS-Style Bottom Navigation */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 50;
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border-top: 0.5px solid rgba(0, 0, 0, 0.1);
  box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.05);
}

.bottom-nav-container {
  display: flex;
  justify-content: space-around;
  align-items: stretch;
  max-width: 600px;
  margin: 0 auto;
  padding: 0;
}

.nav-item {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.nav-item-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 8px 12px;
  min-height: 56px;
  position: relative;
}

.nav-icon-wrapper {
  position: relative;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 4px;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.nav-icon {
  width: 24px;
  height: 24px;
  stroke-width: 2;
  color: #6b7280;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.nav-label {
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.01em;
  color: #6b7280;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  text-align: center;
}

/* Active State */
.nav-item.active .nav-icon-wrapper {
  transform: translateY(-2px);
}

.nav-item.active .nav-icon-wrapper::before {
  content: '';
  position: absolute;
  inset: -6px;
  background: linear-gradient(135deg, rgba(14, 165, 233, 0.1) 0%, rgba(14, 165, 233, 0.15) 100%);
  border-radius: 12px;
  animation: fadeIn 0.2s ease;
}

.nav-item.active .nav-icon {
  color: #0ea5e9;
  stroke-width: 2.5;
  transform: scale(1.1);
}

.nav-item.active .nav-label {
  color: #0ea5e9;
  font-weight: 600;
}

/* Hover State (for desktop) */
@media (hover: hover) {
  .nav-item:hover .nav-icon-wrapper {
    transform: translateY(-1px);
  }
  
  .nav-item:hover .nav-icon {
    color: #0284c7;
  }
  
  .nav-item:hover .nav-label {
    color: #0284c7;
  }
}

/* Active Press State */
.nav-item:active .nav-item-content {
  transform: scale(0.95);
  opacity: 0.7;
}

/* Active Indicator Line (Top) */
.nav-item.active::before {
  content: '';
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 32px;
  height: 3px;
  background: linear-gradient(90deg, #0ea5e9 0%, #06b6d4 100%);
  border-radius: 0 0 3px 3px;
  box-shadow: 0 2px 8px rgba(14, 165, 233, 0.3);
  animation: slideDown 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes slideDown {
  from {
    opacity: 0;
    transform: translateX(-50%) translateY(-3px);
  }
  to {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
}

/* Safe Area Padding */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  .bottom-nav {
    padding-bottom: env(safe-area-inset-bottom);
  }
  
  .nav-item-content {
    padding-bottom: calc(8px + env(safe-area-inset-bottom));
  }
}

/* Badge Support (for notifications) */
.nav-icon-wrapper .badge {
  position: absolute;
  top: -2px;
  right: -2px;
  width: 8px;
  height: 8px;
  background: #ef4444;
  border: 2px solid white;
  border-radius: 50%;
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.5;
  }
}

/* ===== Floating Action Button ===== */
.fab {
  position: fixed;
  bottom: 80px;
  right: 20px;
  width: 56px;
  height: 56px;
  border-radius: 28px;
  background: linear-gradient(135deg, #0ea5e9 0%, #0284c7 100%);
  box-shadow: 0 4px 16px rgba(14, 165, 233, 0.4), 0 8px 32px rgba(14, 165, 233, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 40;
  border: none;
}

.fab:hover {
  transform: scale(1.08) translateY(-2px);
  box-shadow: 0 6px 20px rgba(14, 165, 233, 0.5), 0 12px 40px rgba(14, 165, 233, 0.25);
}

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

.fab svg {
  width: 28px;
  height: 28px;
  color: white;
}

@media (min-width: 768px) {
  .fab {
    display: none;
  }
}

/* ===== iOS-Style Cards ===== */
.ios-card {
  background: #ffffff;
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  transition: all 0.2s ease;
}

.ios-card:active {
  transform: scale(0.99);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

/* Quick Action Cards */
.quick-action-card {
  background: white;
  border: 1px solid #e5e7eb;
  border-radius: 16px;
  padding: 16px;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  cursor: pointer;
  display: block;
  text-decoration: none;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.quick-action-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  border-color: #d1d5db;
}

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

/* Gradient Status Colors */
.from-green-50 { background: linear-gradient(135deg, #f0fdf4 0%, #dcfce7 100%); }
.from-amber-50 { background: linear-gradient(135deg, #fffbeb 0%, #fef3c7 100%); }
.from-red-50 { background: linear-gradient(135deg, #fef2f2 0%, #fee2e2 100%); }

.border-green-200 { border-color: #bbf7d0; }
.border-amber-200 { border-color: #fde68a; }
.border-red-200 { border-color: #fecaca; }

.text-green-700 { color: #15803d; }
.text-green-900 { color: #14532d; }
.text-amber-700 { color: #b45309; }
.text-amber-800 { color: #92400e; }
.text-amber-900 { color: #78350f; }
.text-red-700 { color: #b91c1c; }
.text-red-900 { color: #7f1d1d; }

.bg-green-200 { background-color: #bbf7d0; }
.bg-amber-200 { background-color: #fde68a; }
.bg-red-200 { background-color: #fecaca; }

.bg-green-500 { background-color: #22c55e; }
.bg-amber-500 { background-color: #f59e0b; }
.bg-red-500 { background-color: #ef4444; }

/* ===== Pull-to-Refresh Indicator ===== */
.pull-to-refresh {
  position: absolute;
  top: -60px;
  left: 0;
  right: 0;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s ease;
  pointer-events: none;
}

.pull-to-refresh.visible {
  transform: translateY(60px);
}

.ptr-spinner {
  width: 24px;
  height: 24px;
  border: 3px solid #e5e7eb;
  border-top-color: #0ea5e9;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ===== Enhanced Form Inputs ===== */
.ios-input-group {
  position: relative;
  margin-bottom: 20px;
}

.ios-input {
  width: 100%;
  padding: 16px 12px 8px;
  border: 1px solid #d1d5db;
  border-radius: 10px;
  font-size: 16px;
  transition: all 0.2s ease;
  background: #ffffff;
}

.ios-input:focus {
  outline: none;
  border-color: #0ea5e9;
  box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.1);
}

.ios-input-label {
  position: absolute;
  left: 12px;
  top: 16px;
  color: #6b7280;
  font-size: 16px;
  pointer-events: none;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.ios-input:focus + .ios-input-label,
.ios-input:not(:placeholder-shown) + .ios-input-label {
  top: 6px;
  font-size: 12px;
  color: #0ea5e9;
}

/* ===== Bottom Sheet Modal ===== */
.bottom-sheet-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  z-index: 60;
  animation: fadeIn 0.3s ease;
}

.bottom-sheet {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  max-height: 90vh;
  background: #ffffff;
  border-radius: 20px 20px 0 0;
  z-index: 61;
  animation: slideInUp 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.bottom-sheet-handle {
  width: 36px;
  height: 5px;
  background: #d1d5db;
  border-radius: 3px;
  margin: 12px auto;
}

.bottom-sheet-header {
  padding: 0 20px 16px;
  border-bottom: 1px solid #e5e7eb;
}

.bottom-sheet-content {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
}

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

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

.skeleton-text {
  height: 16px;
  margin-bottom: 8px;
  border-radius: 4px;
}

.skeleton-title {
  height: 24px;
  width: 60%;
  margin-bottom: 12px;
  border-radius: 6px;
}

.skeleton-card {
  height: 120px;
  margin-bottom: 12px;
  border-radius: 12px;
}

/* ===== Swipe Actions ===== */
.swipe-container {
  position: relative;
  overflow: hidden;
}

.swipe-actions {
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  display: flex;
  align-items: stretch;
  transform: translateX(100%);
  transition: transform 0.3s ease;
}

.swipe-container.swiped .swipe-actions {
  transform: translateX(0);
}

.swipe-action {
  min-width: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.swipe-action.delete {
  background: #ef4444;
}

.swipe-action:active {
  opacity: 0.8;
}

/* ===== iOS-Style Switches ===== */
.ios-switch {
  position: relative;
  display: inline-block;
  width: 51px;
  height: 31px;
}

.ios-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.ios-switch-slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #d1d5db;
  transition: 0.3s;
  border-radius: 34px;
}

.ios-switch-slider:before {
  position: absolute;
  content: "";
  height: 27px;
  width: 27px;
  left: 2px;
  bottom: 2px;
  background-color: white;
  transition: 0.3s;
  border-radius: 50%;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.ios-switch input:checked + .ios-switch-slider {
  background-color: #0ea5e9;
}

.ios-switch input:checked + .ios-switch-slider:before {
  transform: translateX(20px);
}

/* ===== Smooth Scrolling ===== */
html {
  scroll-behavior: smooth;
}

main {
  -webkit-overflow-scrolling: touch;
}

/* ===== Status Bar Safe Area ===== */
@supports (padding-top: env(safe-area-inset-top)) {
  header.safe-top {
    padding-top: calc(env(safe-area-inset-top) + 8px);
    padding-bottom: 8px;
  }
  
  nav.safe-bottom {
    padding-bottom: calc(env(safe-area-inset-bottom) + 8px);
  }
  
  .fab {
    bottom: calc(env(safe-area-inset-bottom) + 92px);
  }
  
  .bottom-nav {
    padding-bottom: env(safe-area-inset-bottom);
  }
}

/* ===== 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 Support (Future Enhancement) ===== */
@media (prefers-color-scheme: dark) {
  /* Placeholder for dark mode styles */
}

/* ===== iOS-Style List Items ===== */
.ios-list-item {
  background: white;
  padding: 16px;
  border-bottom: 1px solid #f3f4f6;
  transition: background-color 0.15s;
}

.ios-list-item:active {
  background: #f9fafb;
}

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

/* ===== Enhanced Buttons ===== */
.btn-primary {
  background: linear-gradient(135deg, #0ea5e9 0%, #0284c7 100%);
  color: white;
  padding: 14px 24px;
  border-radius: 12px;
  font-weight: 600;
  font-size: 16px;
  border: none;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 2px 8px rgba(14, 165, 233, 0.3);
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(14, 165, 233, 0.4);
}

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

.btn-secondary {
  background: white;
  color: #0ea5e9;
  padding: 14px 24px;
  border-radius: 12px;
  font-weight: 600;
  font-size: 16px;
  border: 2px solid #0ea5e9;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.btn-secondary:active {
  background: #f0f9ff;
  transform: scale(0.98);
}

/* ===== Success Checkmark Animation ===== */
@keyframes checkmark {
  0% {
    stroke-dashoffset: 100;
  }
  100% {
    stroke-dashoffset: 0;
  }
}

.success-checkmark {
  stroke-dasharray: 100;
  stroke-dashoffset: 100;
  animation: checkmark 0.5s ease-out forwards;
}
