/* Mobile-First Optimizations for Côte d'Ivoire Development Showcase */
/* Phase 3: Enhanced Touch Interface and Mobile UX */

/* ===== MOBILE FOUNDATION ===== */

/* Safe area support for modern mobile devices */
:root {
  --safe-area-inset-top: env(safe-area-inset-top);
  --safe-area-inset-right: env(safe-area-inset-right);
  --safe-area-inset-bottom: env(safe-area-inset-bottom);
  --safe-area-inset-left: env(safe-area-inset-left);
  
  /* Touch target minimum sizes */
  --touch-target-min: 44px;
  --touch-target-comfortable: 48px;
  
  /* Mobile-specific timing */
  --mobile-transition-fast: 150ms;
  --mobile-transition-normal: 250ms;
  --mobile-transition-slow: 350ms;
}

/* Enhanced viewport handling */
@viewport {
  width: device-width;
  initial-scale: 1;
  maximum-scale: 5;
  user-scalable: yes;
}

/* ===== TOUCH INTERFACE OPTIMIZATIONS ===== */

/* Enhanced touch targets for all interactive elements */
.touch-target {
  min-height: var(--touch-target-min);
  min-width: var(--touch-target-min);
  touch-action: manipulation;
  -webkit-tap-highlight-color: rgba(14, 165, 233, 0.2);
  position: relative;
}

.touch-target-comfortable {
  min-height: var(--touch-target-comfortable);
  min-width: var(--touch-target-comfortable);
}

/* Touch feedback overlay */
.touch-feedback::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0;
  height: 0;
  background: rgba(14, 165, 233, 0.3);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  transition: all var(--mobile-transition-fast) ease-out;
  pointer-events: none;
  z-index: 1;
}

.touch-feedback:active::before {
  width: 100%;
  height: 100%;
  transition: all var(--mobile-transition-fast) ease-out;
}

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

@media (max-width: 768px) {
  #navigation-controls {
    position: fixed;
    bottom: calc(20px + var(--safe-area-inset-bottom));
    left: 50%;
    transform: translateX(-50%);
    flex-direction: row;
    padding: 12px 20px;
    border-radius: 28px;
    backdrop-filter: blur(20px);
    background: rgba(255, 255, 255, 0.95);
    border: 1px solid rgba(255, 255, 255, 0.3);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
    z-index: 1000;
    max-width: calc(100vw - 40px);
    transition: all var(--mobile-transition-normal) ease;
  }
  
  #navigation-controls.nav-hidden {
    transform: translateX(-50%) translateY(100px);
    opacity: 0;
  }
  
  #navigation-controls button {
    min-height: var(--touch-target-comfortable);
    min-width: var(--touch-target-comfortable);
    padding: 12px 16px;
    font-size: 0.875rem;
    font-weight: 600;
    border-radius: 20px;
    transition: all var(--mobile-transition-fast) ease;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
  }
  
  #navigation-controls button:active {
    transform: scale(0.95);
    transition: transform 100ms ease;
  }
  
  #step-indicator {
    order: 2;
    margin: 0 16px;
    text-align: center;
    font-size: 0.875rem;
    font-weight: 600;
    color: #475569;
  }
  
  .progress-dots {
    margin: 8px 0 0 0;
    display: flex;
    justify-content: center;
    gap: 6px;
  }
  
  .progress-dots div {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    transition: all var(--mobile-transition-normal) ease;
  }
}

/* ===== MOBILE SIDEBAR PANEL ===== */

@media (max-width: 768px) {
  #sidebar-info-panel {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    height: 70vh;
    max-height: 70vh;
    border-radius: 20px 20px 0 0;
    transform: translateY(100%);
    transition: transform var(--mobile-transition-slow) cubic-bezier(0.4, 0, 0.2, 1);
    backdrop-filter: blur(20px);
    background: rgba(255, 255, 255, 0.98);
    border: 1px solid rgba(255, 255, 255, 0.3);
    box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.12);
    z-index: 999;
    padding-bottom: var(--safe-area-inset-bottom);
  }
  
  #sidebar-info-panel.panel-visible {
    transform: translateY(0);
  }
  
  #sidebar-info-panel.panel-peek {
    transform: translateY(calc(100% - 80px));
  }
  
  /* Mobile sidebar header with drag handle */
  .sidebar-mobile-header {
    position: sticky;
    top: 0;
    background: rgba(255, 255, 255, 0.98);
    backdrop-filter: blur(20px);
    padding: 16px 20px 12px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
    cursor: grab;
    touch-action: pan-y;
  }
  
  .sidebar-mobile-header:active {
    cursor: grabbing;
  }
  
  .sidebar-drag-handle {
    width: 40px;
    height: 4px;
    background: #cbd5e1;
    border-radius: 2px;
    margin: 0 auto 12px;
    transition: background var(--mobile-transition-fast) ease;
  }
  
  .sidebar-mobile-header:active .sidebar-drag-handle {
    background: #94a3b8;
  }
  
  /* Mobile sidebar content */
  .sidebar-mobile-content {
    padding: 0 20px 20px;
    height: calc(100% - 80px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
}

/* ===== MOBILE POI MARKERS ===== */

@media (max-width: 768px) {
  .poi-marker {
    transform: scale(1.1);
    transition: all var(--mobile-transition-normal) ease;
  }
  
  .poi-marker:active {
    transform: scale(1.05);
    transition: transform 100ms ease;
  }
  
  .poi-marker-container {
    min-width: var(--touch-target-comfortable);
    min-height: var(--touch-target-comfortable);
    display: flex;
    align-items: center;
    justify-content: center;
  }
  
  .poi-marker-main {
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
    border: 3px solid rgba(255, 255, 255, 0.9);
  }
  
  /* Enhanced pulse animation for mobile */
  .poi-marker-pulse > div {
    animation: mobilePing 2.5s cubic-bezier(0, 0, 0.2, 1) infinite;
  }
  
  .poi-marker-pulse > div:nth-child(2) {
    animation-delay: 0.8s;
  }
}

@keyframes mobilePing {
  0% {
    transform: scale(1);
    opacity: 1;
  }
  75%, 100% {
    transform: scale(2.2);
    opacity: 0;
  }
}

/* ===== MOBILE MEDIA VIEWER ===== */

@media (max-width: 768px) {
  #media-viewer {
    padding: var(--safe-area-inset-top) 20px calc(20px + var(--safe-area-inset-bottom)) 20px;
    backdrop-filter: blur(20px);
    background: rgba(0, 0, 0, 0.95);
  }
  
  #media-viewer img,
  #media-viewer video {
    max-height: calc(100vh - 120px - var(--safe-area-inset-top) - var(--safe-area-inset-bottom));
    max-width: calc(100vw - 40px);
    border-radius: 12px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.5);
  }
  
  .media-viewer-controls {
    position: fixed;
    bottom: calc(20px + var(--safe-area-inset-bottom));
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 16px;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(20px);
    padding: 12px 20px;
    border-radius: 24px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
  }
  
  .media-viewer-controls button {
    min-width: var(--touch-target-comfortable);
    min-height: var(--touch-target-comfortable);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--mobile-transition-fast) ease;
  }
  
  .media-viewer-controls button:active {
    transform: scale(0.9);
  }
}

/* ===== MOBILE STORYTELLING OVERLAY ===== */

@media (max-width: 768px) {
  #storytelling-overlay {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 24px 20px calc(24px + var(--safe-area-inset-bottom));
    background: linear-gradient(0deg, 
      rgba(0,0,0,0.95) 0%, 
      rgba(0,0,0,0.8) 50%, 
      rgba(0,0,0,0.4) 80%, 
      transparent 100%);
    backdrop-filter: blur(8px);
    border-radius: 20px 20px 0 0;
    transform: translateY(0);
    transition: transform var(--mobile-transition-slow) ease;
  }
  
  #storytelling-overlay.overlay-hidden {
    transform: translateY(100%);
  }
  
  #storytelling-overlay h3 {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 8px;
    line-height: 1.3;
    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.6);
  }
  
  #storytelling-overlay p {
    font-size: 1rem;
    line-height: 1.6;
    margin-bottom: 0;
    text-shadow: 0 1px 4px rgba(0, 0, 0, 0.5);
  }
  
  .narrative-progress-indicator {
    margin-top: 16px;
    padding: 8px 16px;
    background: rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(10px);
    border-radius: 20px;
    font-size: 0.875rem;
    font-weight: 600;
    text-align: center;
  }
}

/* ===== GESTURE SUPPORT ===== */

/* Swipe gesture indicators */
.swipe-indicator {
  position: fixed;
  top: 50%;
  transform: translateY(-50%);
  width: 40px;
  height: 80px;
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(10px);
  border-radius: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity var(--mobile-transition-normal) ease;
  z-index: 1001;
  pointer-events: none;
}

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

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

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

.swipe-indicator::after {
  content: '';
  width: 12px;
  height: 12px;
  border: 2px solid #475569;
  border-left: none;
  border-bottom: none;
  transform: rotate(-45deg);
}

.swipe-indicator-left::after {
  transform: rotate(135deg);
}

/* Pull-to-refresh indicator */
.pull-refresh-indicator {
  position: fixed;
  top: calc(20px + var(--safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%) translateY(-100%);
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(20px);
  padding: 12px 20px;
  border-radius: 20px;
  font-size: 0.875rem;
  font-weight: 600;
  color: #475569;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
  transition: transform var(--mobile-transition-normal) ease;
  z-index: 1002;
}

.pull-refresh-indicator.show {
  transform: translateX(-50%) translateY(0);
}

/* ===== HAPTIC FEEDBACK SUPPORT ===== */

.haptic-light {
  /* Visual feedback for light haptic */
  animation: hapticPulse 200ms ease-out;
}

.haptic-medium {
  /* Visual feedback for medium haptic */
  animation: hapticPulse 300ms ease-out;
}

.haptic-heavy {
  /* Visual feedback for heavy haptic */
  animation: hapticPulse 400ms ease-out;
}

@keyframes hapticPulse {
  0% {
    box-shadow: 0 0 0 0 rgba(14, 165, 233, 0.4);
  }
  70% {
    box-shadow: 0 0 0 10px rgba(14, 165, 233, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(14, 165, 233, 0);
  }
}

/* ===== ORIENTATION HANDLING ===== */

@media (orientation: landscape) and (max-height: 500px) {
  #navigation-controls {
    bottom: 10px;
    padding: 8px 16px;
    border-radius: 20px;
  }
  
  #navigation-controls button {
    min-height: 36px;
    min-width: 36px;
    padding: 8px 12px;
    font-size: 0.8rem;
  }
  
  #storytelling-overlay {
    padding: 16px 20px;
    background: linear-gradient(0deg, 
      rgba(0,0,0,0.9) 0%, 
      rgba(0,0,0,0.6) 70%, 
      transparent 100%);
  }
  
  #storytelling-overlay h3 {
    font-size: 1.25rem;
    margin-bottom: 4px;
  }
  
  #storytelling-overlay p {
    font-size: 0.9rem;
    line-height: 1.5;
  }
  
  #sidebar-info-panel {
    height: 60vh;
    max-height: 60vh;
  }
}

/* ===== ENHANCED SCROLLING ===== */

/* Smooth scrolling for mobile */
.mobile-scroll {
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
  overscroll-behavior: contain;
}

/* Custom scrollbar for mobile */
@media (max-width: 768px) {
  ::-webkit-scrollbar {
    width: 4px;
    height: 4px;
  }
  
  ::-webkit-scrollbar-track {
    background: transparent;
  }
  
  ::-webkit-scrollbar-thumb {
    background: rgba(148, 163, 184, 0.5);
    border-radius: 2px;
  }
  
  ::-webkit-scrollbar-thumb:hover {
    background: rgba(148, 163, 184, 0.8);
  }
}

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

/* GPU acceleration for mobile animations */
.mobile-gpu-accelerated {
  transform: translateZ(0);
  will-change: transform, opacity;
  backface-visibility: hidden;
  perspective: 1000px;
}

/* Reduce motion for mobile battery saving */
@media (prefers-reduced-motion: reduce) {
  .mobile-gpu-accelerated {
    will-change: auto;
    transform: none;
  }
  
  * {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

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

/* Enhanced focus indicators for touch */
@media (max-width: 768px) {
  button:focus,
  .poi-marker:focus,
  [tabindex]:focus {
    outline: 3px solid #0ea5e9;
    outline-offset: 3px;
    box-shadow: 0 0 0 6px rgba(14, 165, 233, 0.2);
  }
  
  /* Larger touch targets for accessibility */
  .a11y-touch-target {
    min-height: 48px;
    min-width: 48px;
    padding: 12px;
  }
}

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

.mobile-skeleton {
  background: linear-gradient(90deg, 
    #f0f0f0 25%, 
    #e0e0e0 50%, 
    #f0f0f0 75%);
  background-size: 200% 100%;
  animation: mobileLoading 1.5s infinite;
  border-radius: 8px;
}

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

/* ===== MOBILE ERROR STATES ===== */

.mobile-error-toast {
  position: fixed;
  top: calc(20px + var(--safe-area-inset-top));
  left: 20px;
  right: 20px;
  background: rgba(239, 68, 68, 0.95);
  backdrop-filter: blur(20px);
  color: white;
  padding: 16px 20px;
  border-radius: 12px;
  font-weight: 600;
  text-align: center;
  transform: translateY(-100px);
  transition: transform var(--mobile-transition-normal) ease;
  z-index: 1003;
  box-shadow: 0 8px 32px rgba(239, 68, 68, 0.3);
}

.mobile-error-toast.show {
  transform: translateY(0);
}

/* ===== MOBILE UTILITY CLASSES ===== */

.mobile-only {
  display: none;
}

.desktop-only {
  display: block;
}

@media (max-width: 768px) {
  .mobile-only {
    display: block;
  }
  
  .desktop-only {
    display: none;
  }
  
  .mobile-hidden {
    display: none !important;
  }
  
  .mobile-full-width {
    width: 100% !important;
  }
  
  .mobile-center {
    text-align: center !important;
  }
}

/* ===== MOBILE DARK MODE SUPPORT ===== */

@media (prefers-color-scheme: dark) and (max-width: 768px) {
  #navigation-controls {
    background: rgba(30, 41, 59, 0.95);
    border: 1px solid rgba(255, 255, 255, 0.1);
  }
  
  #sidebar-info-panel {
    background: rgba(30, 41, 59, 0.98);
    border: 1px solid rgba(255, 255, 255, 0.1);
  }
  
  .sidebar-mobile-header {
    background: rgba(30, 41, 59, 0.98);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  }
  
  .sidebar-drag-handle {
    background: #64748b;
  }
  
  .media-viewer-controls {
    background: rgba(30, 41, 59, 0.95);
    border: 1px solid rgba(255, 255, 255, 0.1);
  }
}