/* =============================================
   ROOF SELECTION MOBILE UX ENHANCEMENTS
   Mobile-first approach with thumb-friendly design
   ============================================= */

:root {
  --touch-min: 56px;
  --safe-area-bottom: env(safe-area-inset-bottom, 20px);
  --primary-green: #10b981;
  --primary-blue: #3b82f6;
}

/* =============================================
   1. FULLSCREEN MAP MODE
   ============================================= */
@media (max-width: 768px) {
  .roof-selection-compact {
    transition: all 0.3s ease-out;
  }

  .roof-selection-compact.fullscreen-mode {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    z-index: 9999 !important;
    background: white !important;
    display: flex !important;
    flex-direction: column !important;
    margin: 0 !important;
    padding: 0 !important;
    border-radius: 0 !important;
  }

  /* Hide desktop sections in fullscreen */
  .fullscreen-mode .controls-section,
  .fullscreen-mode .roof-selection-layout > .controls-section {
    display: none !important;
  }

  .fullscreen-mode .map-section {
    display: block !important;
    flex: 1 !important;
    height: 100% !important;
    width: 100% !important;
  }

  .fullscreen-mode .compact-map-container {
    height: 100% !important;
    min-height: 100vh !important;
    position: relative !important;
  }

  .fullscreen-mode #roof-map {
    height: 100% !important;
    min-height: 100% !important;
    width: 100% !important;
  }

  /* Fixed header in fullscreen */
  .fullscreen-mode .roof-selection-header {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    background: linear-gradient(to bottom,
      rgba(255,255,255,1) 0%,
      rgba(255,255,255,0.9) 80%,
      rgba(255,255,255,0) 100%);
    padding: 16px;
    z-index: 10;
    pointer-events: none;
  }

  .fullscreen-mode .roof-selection-header > * {
    pointer-events: all;
  }

  /* Exit fullscreen button */
  .fullscreen-exit-btn {
    position: fixed;
    top: 16px;
    left: 16px;
    z-index: 10001;
    width: 48px;
    height: 48px;
    background: rgba(255,255,255,0.98);
    border-radius: 24px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid var(--primary-blue);
    cursor: pointer;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
  }

  .fullscreen-exit-btn i {
    color: var(--primary-blue);
    font-size: 20px;
  }

  .fullscreen-exit-btn:active {
    transform: scale(0.95);
    background: rgba(243,244,246,0.98);
  }
}

/* =============================================
   2. ENHANCED TOUCH CONTROLS
   ============================================= */
@media (max-width: 768px) {
  .compact-map-controls {
    position: fixed !important;
    bottom: calc(100px + var(--safe-area-bottom)) !important;
    right: 16px !important;
    top: auto !important;
    left: auto !important;
    flex-direction: column !important;
    gap: 12px !important;
    background: transparent !important;
    padding: 0 !important;
    border: none !important;
    box-shadow: none !important;
  }

  .compact-map-controls .btn {
    width: var(--touch-min) !important;
    height: var(--touch-min) !important;
    min-width: var(--touch-min) !important;
    min-height: var(--touch-min) !important;
    background: rgba(255,255,255,0.98) !important;
    backdrop-filter: blur(10px) !important;
    -webkit-backdrop-filter: blur(10px) !important;
    box-shadow: 0 4px 16px rgba(0,0,0,0.15),
                0 0 0 1px rgba(0,0,0,0.05) !important;
    border: none !important;
    border-radius: 28px !important;
    font-size: 20px !important;
    color: #374151 !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    padding: 0 !important;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1) !important;
    cursor: pointer !important;
  }

  .compact-map-controls .btn:active {
    transform: scale(0.92) !important;
    background: rgba(243,244,246,0.98) !important;
  }

  .compact-map-controls .btn i {
    font-size: 20px !important;
    margin: 0 !important;
  }
}

/* =============================================
   3. VISUAL TARGETING SYSTEM - CROSSHAIR
   ============================================= */
.map-crosshair {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
  z-index: 1000;
  display: none;
}

@media (max-width: 768px) {
  .map-crosshair {
    display: block;
  }

  .compact-map-container {
    position: relative;
  }
}

/* Crosshair center with animated rings */
.crosshair-center {
  position: relative;
  width: 60px;
  height: 60px;
}

.crosshair-dot {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 12px;
  height: 12px;
  background: var(--primary-blue);
  border-radius: 50%;
  box-shadow: 0 0 0 3px white,
              0 0 8px rgba(59,130,246,0.6);
  z-index: 3;
}

.crosshair-ring {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 40px;
  height: 40px;
  border: 3px solid var(--primary-blue);
  border-radius: 50%;
  box-shadow: 0 0 0 2px white;
  z-index: 2;
}

.crosshair-pulse {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 60px;
  height: 60px;
  border: 2px solid var(--primary-blue);
  border-radius: 50%;
  opacity: 0.6;
  animation: crosshair-pulse 2s ease-in-out infinite;
  z-index: 1;
}

.crosshair-lines {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 200px;
  height: 200px;
}

.crosshair-line {
  position: absolute;
  background: var(--primary-blue);
  box-shadow: 0 0 4px rgba(59,130,246,0.4);
}

.crosshair-line-h {
  width: 200px;
  height: 3px;
  top: 50%;
  left: 0;
  transform: translateY(-50%);
}

.crosshair-line-v {
  width: 3px;
  height: 200px;
  left: 50%;
  top: 0;
  transform: translateX(-50%);
}

@keyframes crosshair-pulse {
  0%, 100% {
    transform: translate(-50%, -50%) scale(1);
    opacity: 0.6;
  }
  50% {
    transform: translate(-50%, -50%) scale(1.2);
    opacity: 1;
  }
}

/* Hide crosshair when roof is selected */
.compact-map-container.roof-selected .map-crosshair {
  display: none;
}

/* =============================================
   4. TUTORIAL ONBOARDING OVERLAY
   ============================================= */
.roof-tutorial-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.85);
  z-index: 10000;
  display: none;
  animation: fadeIn 0.3s ease-out;
  pointer-events: all;
}

.roof-tutorial-overlay.active {
  display: flex !important;
  align-items: center;
  justify-content: center;
  padding: 20px;
  pointer-events: all;
}

.tutorial-content {
  position: relative;
  background: white;
  border-radius: 20px;
  padding: 32px 24px;
  max-width: 360px;
  width: 100%;
  box-shadow: 0 20px 60px rgba(0,0,0,0.4);
  animation: slideUp 0.4s ease-out;
  z-index: 10001;
  pointer-events: all;
}

.tutorial-step {
  display: none;
  text-align: center;
  pointer-events: all;
}

.tutorial-step.active {
  display: block !important;
  animation: fadeIn 0.3s ease-out;
  pointer-events: all;
}

.tutorial-icon {
  width: 80px;
  height: 80px;
  margin: 0 auto 20px;
  background: linear-gradient(135deg, rgba(59,130,246,0.1), rgba(59,130,246,0.05));
  border-radius: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.tutorial-icon i {
  font-size: 36px;
  color: var(--primary-blue);
}

.tutorial-step h3 {
  font-size: 22px;
  font-weight: 700;
  color: #1f2937;
  margin: 0 0 12px 0;
  line-height: 1.3;
}

.tutorial-step p {
  font-size: 16px;
  color: #6b7280;
  margin: 0 0 24px 0;
  line-height: 1.6;
}

.tutorial-next-btn,
.tutorial-start-btn {
  width: 100%;
  padding: 16px 24px;
  background: linear-gradient(135deg, var(--primary-blue), #2563eb);
  border: none;
  border-radius: 12px;
  color: white;
  font-weight: 700;
  font-size: 16px;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(59,130,246,0.3);
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  position: relative;
  z-index: 10002;
  pointer-events: all;
  -webkit-tap-highlight-color: transparent;
}

.tutorial-next-btn:active,
.tutorial-start-btn:active {
  transform: scale(0.98);
  box-shadow: 0 2px 8px rgba(59,130,246,0.3);
}

.tutorial-progress {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin-top: 24px;
}

.progress-dot {
  width: 8px;
  height: 8px;
  border-radius: 4px;
  background: #d1d5db;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.progress-dot.active {
  width: 24px;
  background: var(--primary-blue);
}


/* =============================================
   5. MOBILE ANALYSIS PROGRESS OVERLAY
   ============================================= */
@media (max-width: 768px) {
  .mobile-analysis-overlay {
    position: fixed;
    inset: 0;
    background: linear-gradient(135deg, #1e3a8a 0%, #3b82f6 50%, #60a5fa 100%);
    z-index: 10000;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    animation: fadeIn 0.3s ease-out;
  }

  .mobile-analysis-overlay.active {
    display: flex !important;
  }

  .analysis-content {
    text-align: center;
    color: white;
  }

  .analysis-spinner {
    width: 80px;
    height: 80px;
    margin: 0 auto 32px;
    position: relative;
  }

  .spinner-ring {
    position: absolute;
    width: 100%;
    height: 100%;
    border: 4px solid rgba(255,255,255,0.2);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 1s linear infinite;
  }

  .spinner-ring:nth-child(2) {
    width: 60px;
    height: 60px;
    top: 10px;
    left: 10px;
    border-width: 3px;
    animation-duration: 1.5s;
    animation-direction: reverse;
  }

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

  .analysis-content h2 {
    font-size: 28px;
    font-weight: 700;
    margin: 0 0 16px 0;
    line-height: 1.2;
    color: white;
  }

  .analysis-steps-list {
    max-width: 320px;
    margin: 0 auto;
  }

  .analysis-step-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px;
    background: rgba(255,255,255,0.1);
    border-radius: 12px;
    margin-bottom: 12px;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    opacity: 0.5;
    transition: all 0.3s ease;
    color: white;
  }

  .analysis-step-item.active {
    opacity: 1;
    background: rgba(255,255,255,0.2);
    transform: scale(1.02);
  }

  .analysis-step-item.completed {
    opacity: 0.7;
  }

  .step-icon-circle {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255,255,255,0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    color: white;
  }

  .analysis-step-item.active .step-icon-circle {
    background: white;
    color: #1e3a8a;
  }

  .analysis-step-item.completed .step-icon-circle {
    background: rgba(16,185,129,0.4);
    color: white;
  }

  .step-icon-circle i {
    font-size: 18px;
  }

  .step-text {
    flex: 1;
    text-align: left;
  }

  .step-text h6 {
    font-size: 15px;
    font-weight: 600;
    margin: 0 0 4px 0;
    color: white;
  }

  .step-text p {
    font-size: 13px;
    margin: 0;
    opacity: 0.9;
    color: white;
  }
}

/* =============================================
   6. SUCCESS FEEDBACK ANIMATION
   ============================================= */
.roof-success-overlay {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 9998;
  display: none;
}

.roof-success-overlay.active {
  display: block;
}

.success-ripple {
  position: absolute;
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: var(--primary-green);
  opacity: 0;
  transform: translate(-50%, -50%) scale(0);
  animation: success-ripple 0.6s ease-out;
}

.success-check {
  position: absolute;
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: var(--primary-green);
  transform: translate(-50%, -50%) scale(0);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 24px rgba(16,185,129,0.4);
  animation: success-pop 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55) 0.2s forwards;
}

.success-check svg {
  width: 40px;
  height: 40px;
  stroke: white;
  stroke-width: 4;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 60;
  stroke-dashoffset: 60;
  animation: check-draw 0.5s ease-out 0.5s forwards;
}

@keyframes success-ripple {
  to {
    transform: translate(-50%, -50%) scale(4);
    opacity: 0;
  }
}

@keyframes success-pop {
  to {
    transform: translate(-50%, -50%) scale(1);
  }
}

@keyframes check-draw {
  to {
    stroke-dashoffset: 0;
  }
}

/* =============================================
   6. CONFIRMATION FAB BUTTON
   ============================================= */
@media (max-width: 768px) {
  .roof-confirm-fab {
    position: fixed;
    bottom: calc(24px + var(--safe-area-bottom));
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    min-width: 220px;
    height: var(--touch-min);
    background: linear-gradient(135deg, var(--primary-green), #059669);
    color: white;
    border: none;
    border-radius: 28px;
    font-size: 17px;
    font-weight: 700;
    box-shadow: 0 8px 24px rgba(16,185,129,0.4),
                0 0 0 4px rgba(16,185,129,0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    cursor: pointer;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    opacity: 0;
    pointer-events: none;
    z-index: 9997;
  }

  .roof-confirm-fab.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
    pointer-events: all;
  }

  .roof-confirm-fab:active {
    transform: translateX(-50%) translateY(0) scale(0.96);
  }

  .roof-confirm-fab i {
    font-size: 20px;
    animation: check-bounce 0.6s ease-out;
  }

  @keyframes check-bounce {
    0%, 100% { transform: scale(1); }
    40% { transform: scale(1.3); }
    60% { transform: scale(0.9); }
  }
}

/* =============================================
   7. QUICK SKIP & FRUSTRATION DETECTION
   ============================================= */
@media (max-width: 768px) {
  .mobile-quick-actions {
    position: fixed;
    top: 70px;
    left: 0;
    right: 0;
    padding: 12px 16px;
    background: linear-gradient(to bottom,
      rgba(255,255,255,0.98),
      rgba(255,255,255,0.92));
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    z-index: 999;
    transform: translateY(-120%);
    transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 2px 12px rgba(0,0,0,0.08);
  }

  .mobile-quick-actions.show {
    transform: translateY(0);
  }

  .help-prompt {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 16px;
    background: linear-gradient(135deg, rgba(59,130,246,0.08), rgba(59,130,246,0.05));
    border: 1.5px solid rgba(59,130,246,0.25);
    border-radius: 12px;
  }

  .help-prompt-text {
    flex: 1;
    min-width: 0;
  }

  .help-prompt-text p {
    margin: 0;
    font-size: 14px;
    color: #4b5563;
    line-height: 1.4;
  }

  .help-prompt-text strong {
    color: #1f2937;
    font-weight: 600;
  }

  .manual-entry-quick {
    padding: 10px 16px;
    background: white;
    border: 2px solid var(--primary-blue);
    border-radius: 10px;
    color: var(--primary-blue);
    font-weight: 600;
    font-size: 14px;
    white-space: nowrap;
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
  }

  .manual-entry-quick:active {
    transform: scale(0.96);
    background: rgba(59,130,246,0.05);
  }
}

/* =============================================
   UTILITY ANIMATIONS
   ============================================= */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(30px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes slideDown {
  from {
    opacity: 0;
    transform: translateY(-30px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Haptic feedback class */
.haptic-feedback {
  animation: haptic-pulse 0.15s ease-out;
}

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

/* =============================================
   ACCESSIBILITY & POLISH
   ============================================= */

/* Reduce motion for accessibility */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* Focus states for keyboard navigation */
.tutorial-next-btn:focus-visible,
.tutorial-start-btn:focus-visible,
.fullscreen-exit-btn:focus-visible,
.manual-entry-quick:focus-visible,
.roof-confirm-fab:focus-visible {
  outline: 3px solid var(--primary-blue);
  outline-offset: 2px;
}

/* Dark mode support (future) */
@media (prefers-color-scheme: dark) {
  .tutorial-content {
    background: #1f2937;
    color: #f9fafb;
  }

  .tutorial-step h3 {
    color: #f9fafb;
  }

  .tutorial-step p {
    color: #d1d5db;
  }
}
