/* ===== Mobile Optimization ===== */

/* Mobile-first compact progress bar */
@media (max-width: 768px) {
  /* Alternative: Horizontal progress line with current step only */
  .progress-container-compact {
    background: var(--bg-base);
    border-bottom: 1px solid var(--neutral-200);
    padding: var(--space-2) 0;
    margin-bottom: var(--space-4);
  }
  
  .progress-line {
    height: 4px;
    background: var(--neutral-200);
    border-radius: 2px;
    margin: 0 var(--space-4) var(--space-3);
    position: relative;
    overflow: hidden;
  }
  
  .progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), var(--primary-amber));
    border-radius: 2px;
    transition: width 0.3s ease;
    width: calc((var(--current-step, 1) - 1) / 7 * 100%);
  }
  
  .current-step-indicator {
    text-align: center;
    padding: 0 var(--space-4);
    font-size: var(--text-xs);
    color: var(--text-secondary);
    font-weight: 500;
  }
  
  .current-step-indicator .step-name {
    color: var(--primary);
    font-weight: 600;
  }

/* Base mobile styles for all screen sizes */
@media (max-width: 768px) {
  /* Typography adjustments */
  .hero h1 {
    font-size: 2rem;
    line-height: 1.2;
  }
  
  .hero p {
    font-size: var(--text-base);
    line-height: 1.5;
  }
  
  /* Container adjustments */
  .container {
    padding-left: var(--space-4);
    padding-right: var(--space-4);
  }
  
  /* Compact mobile progress bar */
  .progress-container {
    padding: var(--space-3) 0;
    margin-bottom: var(--space-4);
  }
  
  .progress-steps {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: var(--space-1);
    padding: 0 var(--space-3);
    max-width: 100%;
  }
  
  .progress-step {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-1);
  }
  
  .step-number {
    width: 28px;
    height: 28px;
    font-size: 11px;
    font-weight: 700;
  }
  
  .step-label {
    font-size: 8px;
    line-height: 1;
    text-align: center;
    max-width: 32px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  
  /* Form optimization */
  .form-control, .form-select {
    padding: var(--space-4);
    font-size: 16px; /* Prevents zoom on iOS */
    border-radius: var(--radius-lg);
  }
  
  .checkbox-grid {
    grid-template-columns: 1fr;
    gap: var(--space-3);
  }
  
  .form-check {
    padding: var(--space-4);
    margin-bottom: var(--space-2);
  }
  
  /* Button adjustments */
  .btn {
    padding: var(--space-4) var(--space-5);
    font-size: var(--text-base);
    min-height: 48px; /* Touch target size */
  }
  
  .btn-lg {
    padding: var(--space-5) var(--space-6);
    font-size: var(--text-lg);
    min-height: 52px;
  }
  
  /* Search page mobile */
  .search-container {
    grid-template-columns: 1fr;
    gap: 0;
  }
  
  .search-sidebar {
    position: static;
    max-height: none;
    border-right: none;
    border-bottom: 1px solid var(--neutral-200);
    padding: var(--space-4);
  }
  
  .search-content {
    padding: var(--space-4);
  }
  
  /* Analysis results mobile */
  .result-card {
    margin-bottom: var(--space-4);
    border-radius: var(--radius-lg);
  }
  
  .result-header {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--space-2);
  }
  
  .result-url {
    word-break: break-all;
    font-size: var(--text-sm);
  }
  
  .pros-cons-grid {
    grid-template-columns: 1fr;
    gap: var(--space-3);
  }
  
  /* Features grid mobile */
  .features {
    grid-template-columns: 1fr;
    gap: var(--space-4);
  }
  
  .feature {
    padding: var(--space-5);
  }
  
  /* Document upload mobile */
  .upload-area {
    padding: var(--space-6);
    min-height: 120px;
  }
  
  .upload-area h4 {
    font-size: var(--text-base);
  }
  
  /* Navigation adjustments */
  .step-nav {
    flex-direction: column;
    gap: var(--space-3);
  }
  
  .step-nav .btn {
    width: 100%;
  }
  
  /* Modal adjustments */
  .modal-content {
    margin: var(--space-4);
    max-height: 90vh;
    overflow-y: auto;
  }
  
  /* Markdown content mobile */
  .markdown-content {
    font-size: var(--text-sm);
    line-height: 1.6;
  }
  
  .markdown-content h1 {
    font-size: var(--text-xl);
  }
  
  .markdown-content h2 {
    font-size: var(--text-lg);
  }
  
  .markdown-content h3 {
    font-size: var(--text-base);
  }
  
  .markdown-content ul,
  .markdown-content ol {
    padding-left: var(--space-4);
  }
  
  /* Table responsiveness */
  .markdown-content table {
    font-size: var(--text-sm);
    overflow-x: auto;
    display: block;
    white-space: nowrap;
  }
  
  .markdown-content th,
  .markdown-content td {
    padding: var(--space-2);
  }
}

/* Extra small phones - Ultra compact progress */
@media (max-width: 480px) {
  .hero h1 {
    font-size: 1.75rem;
  }
  
  .progress-container {
    padding: var(--space-2) 0;
    margin-bottom: var(--space-3);
  }
  
  .progress-steps {
    gap: 2px;
    padding: 0 var(--space-2);
  }
  
  .step-number {
    width: 24px;
    height: 24px;
    font-size: 10px;
    font-weight: 700;
  }
  
  .step-label {
    display: none; /* Hide labels on very small screens */
  }
  
  /* Add current step indicator */
  .progress-step.active::after {
    content: attr(data-step-name);
    position: absolute;
    top: 30px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--primary);
    color: white;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 9px;
    white-space: nowrap;
    z-index: 10;
  }
}
  
  .container {
    padding-left: var(--space-3);
    padding-right: var(--space-3);
  }
  
  .form-check {
    padding: var(--space-3);
  }
  
  .feature {
    padding: var(--space-4);
  }
  
  .result-card {
    padding: var(--space-4);
  }
}

/* Touch-friendly improvements */
@media (hover: none) and (pointer: coarse) {
  /* Increase touch targets */
  .btn {
    min-height: 48px;
    padding: var(--space-4) var(--space-5);
  }
  
  .form-check {
    min-height: 48px;
    padding: var(--space-4);
  }
  
  .step-number {
    min-width: 44px;
    min-height: 44px;
  }
  
  /* Remove hover effects on touch devices */
  .btn:hover,
  .form-check:hover,
  .feature:hover {
    transform: none;
  }
  
  /* Improve input focus for touch */
  .form-control:focus,
  .form-select:focus {
    transform: scale(1.02);
    transition: transform 0.2s ease;
  }
}

/* Landscape orientation adjustments */
@media (max-width: 768px) and (orientation: landscape) {
  .progress-container {
    padding: var(--space-3) 0;
  }
  
  .hero {
    padding: var(--space-8) var(--space-4);
  }
  
  .step-label {
    display: none; /* Hide labels in landscape to save space */
  }
}

/* High DPI displays */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
  .hero-icon,
  .feature-icon,
  .step-number {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
  }
}

/* Dark mode support for mobile */
@media (prefers-color-scheme: dark) and (max-width: 768px) {
  .form-control,
  .form-select {
    background: #1f2937;
    border-color: #374151;
    color: #f9fafb;
  }
  
  .result-card {
    background: #1f2937;
    border-color: #374151;
  }
  
  .feature {
    background: #1f2937;
    border-color: #374151;
  }
}

/* Accessibility improvements for mobile */
@media (max-width: 768px) {
  /* Ensure sufficient color contrast */
  .btn-primary {
    background: var(--primary);
    border: 2px solid var(--primary);
  }
  
  .form-control:focus,
  .form-select:focus {
    border-width: 2px;
    border-color: var(--primary);
  }
  
  /* Improve focus indicators */
  .btn:focus,
  .form-control:focus,
  .form-select:focus,
  .form-check:focus-within {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
  }
  
  /* Improve text readability */
  .text-muted {
    color: #4b5563;
  }
  
  /* Ensure adequate spacing for readability */
  p, li {
    line-height: 1.6;
  }
}

/* Performance optimizations for mobile */
@media (max-width: 768px) {
  /* Reduce animations on slower devices */
  .form-check,
  .btn,
  .feature {
    transition-duration: 0.15s;
  }
  
  /* Optimize scroll performance */
  .search-content,
  .modal-content {
    -webkit-overflow-scrolling: touch;
    transform: translate3d(0, 0, 0);
  }
  
  /* Reduce shadow complexity */
  .feature:hover,
  .btn:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  }
}

/* Touch feedback styles */
.mobile-device .touch-active {
  background: rgba(249, 115, 22, 0.1) !important;
  transform: scale(0.98);
  transition: all 0.1s ease;
}

/* Mobile-specific utility classes */
.mobile-hidden {
  display: none !important;
}

@media (max-width: 768px) {
  .desktop-only {
    display: none !important;
  }
  
  .mobile-only {
    display: block !important;
  }
  
  .mobile-flex {
    display: flex !important;
  }
}

/* Improved mobile navigation */
@media (max-width: 768px) {
  .step-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: white;
    padding: var(--space-4);
    border-top: 1px solid var(--neutral-200);
    z-index: 1000;
    box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.1);
  }
  
  .main-content {
    padding-bottom: 100px; /* Account for fixed navigation */
  }
  
  .progress-container.scrolled {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
  }
}

/* Mobile property analysis enhancements */
@media (max-width: 768px) {
  .property-input-group {
    position: relative;
  }
  
  .property-input-group .form-control {
    padding-right: 60px;
  }
  
  .analyze-btn-mobile {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    padding: 8px 12px;
    font-size: var(--text-xs);
    border-radius: var(--radius-md);
  }
  
  .loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
  }
  
  .loading-spinner {
    background: white;
    padding: var(--space-6);
    border-radius: var(--radius-xl);
    text-align: center;
    min-width: 200px;
  }
  
  .loading-spinner .spinner {
    width: 40px;
    height: 40px;
    border: 4px solid var(--neutral-200);
    border-top: 4px solid var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto var(--space-4);
  }
  
  @keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
  }
  
  /* Mobile dashboard optimizations */
  .search-container {
    padding: 10px;
    gap: 20px;
  }
  
  .search-sidebar {
    padding: 16px;
    margin-bottom: 20px;
  }
  
  .search-content {
    padding: 16px;
  }
  
  .section-title {
    font-size: 20px;
  }
  
  .section-icon {
    width: 28px;
    height: 28px;
  }
  
  /* Dashboard mobile fixes */
  .dashboard-full-view {
    margin: 0;
    border-radius: 8px;
  }
  
  .dashboard-header-full {
    padding: 16px;
  }
  
  .dashboard-metrics-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    padding: 16px;
  }
  
  .metric-card {
    padding: 16px;
  }
  
  .metric-icon {
    width: 36px;
    height: 36px;
    font-size: 16px;
    margin-bottom: 8px;
  }
  
  .metric-value {
    font-size: 22px;
  }
  
  .metric-label {
    font-size: 12px;
  }
  
  .dashboard-map-section {
    margin: 0 10px 20px 10px;
  }
  
  .dashboard-map {
    height: 250px;
  }
  
  .dashboard-facilities-section {
    margin: 0 10px 20px 10px;
  }
  
  .facility-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }
  
  .facility-item {
    padding: 12px;
    font-size: 12px;
  }
  
  /* Mobile layout improvements */
  .search-container {
    display: block;
    padding: 8px;
  }
  
  .search-sidebar {
    order: 2;
    margin-top: 16px;
  }
  
  .search-content {
    order: 1;
  }
  
  /* Mini dashboard mobile */
  .dashboard-mini-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    padding: 12px;
  }
  
  .dashboard-mini-card {
    padding: 12px;
  }
  
  .dashboard-mini-card .metric-icon {
    width: 28px;
    height: 28px;
    font-size: 12px;
  }
  
  .dashboard-mini-card .metric-value {
    font-size: 18px;
  }
  
  .dashboard-mini-card .metric-label {
    font-size: 11px;
  }
  
  /* Platform grid mobile */
  .platform-grid {
    grid-template-columns: 1fr;
    gap: 8px;
  }
  
  .platform-btn {
    padding: 12px;
    gap: 10px;
  }
  
  .platform-icon {
    width: 28px;
    height: 28px;
    font-size: 12px;
  }
  
  .platform-name {
    font-size: 14px;
  }
  
  /* Analysis results mobile */
  .analysis-results {
    padding: 16px;
  }
  
  .result-card {
    margin-bottom: 16px;
    padding: 16px;
  }
  
  .result-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }
  
  .result-url {
    font-size: 12px;
    word-break: break-all;
  }
  
  .score-badge {
    font-size: 12px;
    padding: 4px 8px;
  }
  
  /* View toggles mobile */
  .view-toggle {
    flex-direction: column;
    gap: 8px;
    margin-bottom: 16px;
  }
  
  .view-toggle .btn {
    font-size: 14px;
    padding: 10px 16px;
  }
}

/* Enhanced accessibility for mobile */
@media (max-width: 768px) {
  /* Larger tap targets - Apple HIG compliance */
  .btn,
  .form-control,
  .form-select,
  .form-check,
  a {
    min-height: 44px;
    min-width: 44px;
  }
  
  /* Prevent double-tap zoom on buttons */
  .btn {
    touch-action: manipulation;
  }
  
  /* Better focus states */
  .btn:focus,
  .form-control:focus,
  .form-select:focus {
    outline: 3px solid var(--primary);
    outline-offset: 2px;
  }
  
  /* Improved error states */
  .form-control:invalid {
    border-color: #dc2626;
    box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.1);
  }
  
  /* Better spacing for readability */
  .form-group {
    margin-bottom: var(--space-8);
  }
  
  /* Improved text size */
  body {
    font-size: 16px;
    line-height: 1.6;
  }
  
  h1, h2, h3, h4, h5, h6 {
    line-height: 1.3;
  }
  
  /* Safe area support for modern phones */
  .container {
    padding-left: max(var(--space-4), env(safe-area-inset-left));
    padding-right: max(var(--space-4), env(safe-area-inset-right));
  }
  
  .step-nav {
    padding-bottom: max(var(--space-4), env(safe-area-inset-bottom));
  }
  
  /* Prevent content shift during loading */
  .search-content {
    min-height: 50vh;
  }
  
  /* Smooth momentum scrolling */
  .search-content,
  .modal-content,
  .results-container {
    -webkit-overflow-scrolling: touch;
    overflow-scrolling: touch;
  }
}