/* 
 * CARE Notes Mobile Optimizations CSS
 * Mobile-first responsive design for health tracking applications
 * Optimized for touch interfaces, offline usage, and PWA experience
 */

/* ===== MOBILE-FIRST BASE STYLES ===== */

/* Reset and ensure proper touch behavior */
* {
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  -khtml-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

/* Allow text selection in input fields and content areas */
input, textarea, [contenteditable="true"], .selectable-text {
  -webkit-user-select: text;
  -moz-user-select: text;
  -ms-user-select: text;
  user-select: text;
}

/* Root variables for consistent mobile sizing */
:root {
  --touch-target-size: 44px;
  --touch-spacing: 8px;
  --mobile-padding: 16px;
  --mobile-gap: 12px;
  --swipe-threshold: 50px;
  --mobile-font-small: 14px;
  --mobile-font-normal: 16px;
  --mobile-font-large: 18px;
  --mobile-font-xl: 22px;
}

/* ===== TOUCH-FRIENDLY INTERFACE ===== */

/* Ensure all interactive elements meet touch target requirements */
button, .btn, .tracker-button, .back-button, 
input[type="submit"], input[type="button"],
.tracker-card, .anatomical-region {
  min-height: var(--touch-target-size);
  min-width: var(--touch-target-size);
  padding: 12px 20px;
  touch-action: manipulation;
  cursor: pointer;
}

/* Enhanced touch feedback for all buttons */
button:active, .btn:active, .tracker-button:active,
.back-button:active, .tracker-card:active {
  transform: scale(0.98);
  transition: transform 0.1s ease;
}

/* ===== SVG BODY DIAGRAM MOBILE OPTIMIZATIONS ===== */

/* Container optimizations for mobile body diagrams */
.body-svg-container {
  position: relative;
  width: 100%;
  max-width: 280px;
  margin: 0 auto;
  touch-action: pan-x pan-y;
}

.body-svg {
  width: 100%;
  height: auto;
  max-height: 70vh;
  touch-action: manipulation;
}

/* Enhanced anatomical region touch targets */
.anatomical-region {
  cursor: pointer !important;
  stroke-width: 2;
  transition: all 0.2s ease;
  min-width: var(--touch-target-size);
  min-height: var(--touch-target-size);
}

.anatomical-region:hover,
.anatomical-region:focus,
.anatomical-region.touch-active {
  stroke-width: 3;
  opacity: 0.8;
  filter: drop-shadow(0 0 4px rgba(26, 43, 92, 0.5));
}

/* Touch feedback for SVG regions */
.anatomical-region:active {
  transform: scale(1.05);
  stroke-width: 4;
}

/* ===== MOBILE FORM OPTIMIZATIONS ===== */

/* Mobile-optimized form controls */
input, select, textarea {
  font-size: 16px; /* Prevents zoom on iOS */
  padding: 12px;
  border-radius: 8px;
  border: 2px solid #d4c4a0;
  background: #faf8f3;
  -webkit-appearance: none;
  appearance: none;
}

/* Enhanced slider controls for mobile */
.intensity-slider {
  height: 8px;
  -webkit-appearance: none;
  appearance: none;
  background: linear-gradient(to right, #8b0000, #dc143c, #ff6b6b, #ffa500, #ffeb3b, #e8f5e8, #c8e6c9, #a5d6a7, #66bb6a, #4caf50);
  border-radius: 4px;
  outline: none;
  touch-action: manipulation;
}

.intensity-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: #1a2b5c;
  cursor: pointer;
  border: 3px solid white;
  box-shadow: 0 3px 6px rgba(0,0,0,0.3);
}

.intensity-slider::-moz-range-thumb {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: #1a2b5c;
  cursor: pointer;
  border: 3px solid white;
  box-shadow: 0 3px 6px rgba(0,0,0,0.3);
}

/* ===== MOBILE NAVIGATION ===== */

/* Premium enhanced back navigation */
.back-link, .back-button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  margin-bottom: 16px;
  font-size: var(--mobile-font-normal);
  touch-action: manipulation;
  transition: all var(--mobile-animation-smooth);
  border-radius: 25px;
  position: relative;
  overflow: hidden;
}

.back-link::before, .back-button::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.1), transparent);
  transition: left var(--mobile-animation-smooth);
}

.back-link:active::before, .back-button:active::before {
  left: 100%;
}

.back-link:active, .back-button:active {
  transform: scale(0.95);
  animation: premiumTapFeedback var(--mobile-animation-swift);
}

/* Mobile breadcrumb navigation */
.mobile-breadcrumb {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 0;
  font-size: var(--mobile-font-small);
  color: #666;
  overflow-x: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.mobile-breadcrumb::-webkit-scrollbar {
  display: none;
}

/* ===== FLOATING ACTION BUTTON (FAB) ===== */

.fab-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 1000;
}

.fab {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--clinical-success), #27ae60);
  color: white;
  border: none;
  font-size: 24px;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(46, 204, 113, 0.4);
  transition: all var(--mobile-animation-smooth);
  position: relative;
  overflow: hidden;
  will-change: transform, box-shadow;
}

.fab::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: radial-gradient(circle, rgba(255,255,255,0.2), transparent);
  opacity: 0;
  transition: opacity var(--mobile-animation-swift);
}

.fab:active::before {
  opacity: 1;
  animation: fabRipple var(--mobile-animation-bounce);
}

@keyframes fabRipple {
  0% { transform: scale(0); opacity: 1; }
  100% { transform: scale(2); opacity: 0; }
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: manipulation;
}

.fab:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 16px rgba(46, 204, 113, 0.5);
}

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

/* FAB menu */
.fab-menu {
  position: absolute;
  bottom: 70px;
  right: 0;
  background: white;
  border-radius: 12px;
  padding: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.2);
  min-width: 200px;
  transform: scale(0);
  opacity: 0;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  transform-origin: bottom right;
}

.fab-menu.open {
  transform: scale(1);
  opacity: 1;
}

.fab-menu-item {
  width: 100%;
  padding: 12px 16px;
  border: none;
  border-radius: 8px;
  margin-bottom: 4px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ===== SWIPE GESTURES ===== */

.swipeable {
  touch-action: pan-y;
  position: relative;
  overflow: hidden;
}

.swipe-indicator {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  opacity: 0;
  transition: opacity 0.3s ease;
  font-size: 24px;
  color: rgba(255,255,255,0.8);
  z-index: 10;
}

.swipe-indicator.left {
  left: 20px;
}

.swipe-indicator.right {
  right: 20px;
}

.swipe-active .swipe-indicator {
  opacity: 1;
}

/* ===== PULL-TO-REFRESH ===== */

.pull-to-refresh {
  position: relative;
  overflow: hidden;
}

.pull-refresh-indicator {
  position: absolute;
  top: -60px;
  left: 50%;
  transform: translateX(-50%);
  width: 40px;
  height: 40px;
  border: 3px solid #f3f3f3;
  border-top: 3px solid #2ecc71;
  border-radius: 50%;
  animation: spin 1s linear infinite;
  opacity: 0;
  transition: all 0.3s ease;
}

.pull-refresh-indicator.visible {
  opacity: 1;
  top: 20px;
}

@keyframes spin {
  0% { transform: translateX(-50%) rotate(0deg); }
  100% { transform: translateX(-50%) rotate(360deg); }
}

/* ===== OFFLINE INDICATORS ===== */

.offline-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  background: #ff6b6b;
  color: white;
  text-align: center;
  padding: 8px 16px;
  font-weight: 600;
  z-index: 9999;
  transform: translateY(-100%);
  transition: transform 0.3s ease;
}

.offline-banner.visible {
  transform: translateY(0);
}

.sync-indicator {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.8);
  color: white;
  padding: 8px 16px;
  border-radius: 20px;
  font-size: 14px;
  opacity: 0;
  transition: opacity 0.3s ease;
  z-index: 1000;
}

.sync-indicator.visible {
  opacity: 1;
}

/* ===== RESPONSIVE BREAKPOINTS ===== */

/* Mobile phones (portrait) */
@media (max-width: 480px) {
  .container {
    padding: 16px;
    margin: 8px;
  }
  
  h1 {
    font-size: 1.6em;
  }
  
  .body-diagrams {
    grid-template-columns: 1fr;
    gap: 16px;
  }
  
  .tracker-grid {
    grid-template-columns: 1fr;
    gap: 16px;
  }
  
  .fab-menu {
    right: -8px;
    min-width: calc(100vw - 32px);
    max-width: 300px;
  }
}

/* Mobile phones (landscape) */
@media (max-width: 768px) and (orientation: landscape) {
  .body-diagrams {
    grid-template-columns: 1fr 1fr;
    gap: 20px;
  }
  
  .body-svg-container {
    max-width: 240px;
  }
}

/* Tablets (portrait) */
@media (min-width: 481px) and (max-width: 768px) {
  .container {
    padding: 24px;
    margin: 12px;
  }
  
  .body-diagrams {
    grid-template-columns: 1fr 1fr;
    gap: 24px;
  }
  
  .tracker-grid {
    grid-template-columns: 1fr;
    gap: 20px;
  }
}

/* ===== ACCESSIBILITY ENHANCEMENTS ===== */

/* High contrast mode support */
@media (prefers-contrast: high) {
  .anatomical-region {
    stroke-width: 3;
  }
  
  .anatomical-region:hover,
  .anatomical-region:focus {
    stroke-width: 4;
  }
  
  button, .btn, .tracker-button {
    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;
  }
  
  .anatomical-region:active {
    transform: none;
  }
  
  button:active, .btn:active {
    transform: none;
  }
}

/* Focus visible for keyboard navigation */
.anatomical-region:focus-visible,
button:focus-visible,
.tracker-card:focus-visible {
  outline: 3px solid #2ecc71;
  outline-offset: 2px;
}

/* ===== PERFORMANCE OPTIMIZATIONS ===== */

/* GPU acceleration for smooth animations */
.anatomical-region,
.fab,
.tracker-card {
  will-change: transform;
}

/* Contain layout for better performance */
.body-svg-container,
.tracker-grid,
.dashboard-grid {
  contain: layout style;
}

/* ===== ANDROID-SPECIFIC OPTIMIZATIONS ===== */

/* Android Chrome address bar handling */
@supports (-webkit-touch-callout: none) {
  .container {
    min-height: calc(100vh - env(keyboard-inset-height, 0px));
    padding-bottom: calc(20px + env(keyboard-inset-height, 0px));
  }
}

/* Android safe areas */
.container {
  padding-left: max(16px, env(safe-area-inset-left));
  padding-right: max(16px, env(safe-area-inset-right));
  padding-bottom: max(20px, env(safe-area-inset-bottom));
}

.fab-container {
  bottom: max(20px, env(safe-area-inset-bottom, 20px));
  right: max(20px, env(safe-area-inset-right, 20px));
}

/* ===== LOADING STATES ===== */

.loading-skeleton {
  background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
  background-size: 200% 100%;
  animation: loading-shimmer 2s infinite;
}

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

.lazy-image {
  opacity: 0;
  transition: opacity 0.3s ease;
}

.lazy-image.loaded {
  opacity: 1;
}

/* ===== HAPTIC FEEDBACK SIMULATION ===== */

.haptic-light:active {
  animation: haptic-pulse-light 0.1s ease;
}

.haptic-medium:active {
  animation: haptic-pulse-medium 0.15s ease;
}

.haptic-heavy:active {
  animation: haptic-pulse-heavy 0.2s ease;
}

@keyframes haptic-pulse-light {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(0.98); }
}

@keyframes haptic-pulse-medium {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(0.96); }
}

@keyframes haptic-pulse-heavy {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(0.94); }
}