/* Mobile-specific CSS enhancements for TaxVault */

/* Safe area support for notched devices */
@supports (padding: max(0px)) {
  body {
    padding-left: max(0px, env(safe-area-inset-left));
    padding-right: max(0px, env(safe-area-inset-right));
  }

  /* Adjust fixed elements for notches */
  header, aside {
    padding-left: max(1rem, env(safe-area-inset-left));
    padding-right: max(1rem, env(safe-area-inset-right));
  }
}

/* Mobile touch improvements */
@media (hover: none) and (pointer: coarse) {
  /* Increase tap target sizes on touch devices */
  button, a[href], [role="button"] {
    min-height: 44px;
    min-width: 44px;
    padding: max(0.5rem, calc((44px - 1em) / 2)) 1rem;
  }

  /* Add more spacing around interactive elements */
  input, textarea, select {
    min-height: 44px;
    padding: 0.75rem;
    font-size: 16px; /* Prevents zoom on iOS */
  }

  /* Remove focus ring on touch (it appears on tap) */
  *:focus-visible {
    outline-offset: 2px;
  }

  /* Improve scrolling performance on mobile */
  .scroll-smooth {
    -webkit-overflow-scrolling: touch;
  }

  /* Reduce animation on lower-end devices */
  @media (prefers-reduced-motion: reduce) {
    * {
      animation-duration: 0.01ms !important;
      animation-iteration-count: 1 !important;
      transition-duration: 0.01ms !important;
    }
  }
}

/* Improve text readability on mobile */
@media (max-width: 640px) {
  body {
    font-size: 16px;
    line-height: 1.6;
  }

  h1 {
    font-size: 24px;
  }

  h2 {
    font-size: 20px;
  }

  h3 {
    font-size: 18px;
  }

  /* Prevent text selection on long-press (improves UX) */
  button, [role="button"], label {
    user-select: none;
    -webkit-user-select: none;
  }
}

/* Keyboard appearance optimization */
@media (max-height: 500px) {
  /* Reduce header height when keyboard is open */
  header {
    min-height: auto;
    padding: 0.5rem;
  }

  /* Compact navigation when keyboard is visible */
  aside {
    font-size: 0.875rem;
  }
}

/* Landscape orientation optimizations */
@media (orientation: landscape) and (max-height: 500px) {
  header {
    min-height: auto;
  }

  /* Reduce vertical spacing in landscape mode */
  .card {
    padding: 0.75rem 1rem;
  }

  /* Stack form fields more compactly */
  input, select, textarea {
    margin-bottom: 0.5rem;
  }
}

/* High-DPI screen optimization */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
  /* Ensure crisp icons and images */
  img, svg {
    image-rendering: crisp-edges;
  }
}

/* Dark mode mobile optimization */
@media (prefers-color-scheme: dark) {
  /* Improve contrast on OLED screens */
  body {
    background-color: #000;
  }

  .card {
    background-color: #111;
  }

  /* Reduce brightness flicker */
  *::-webkit-scrollbar {
    background-color: rgba(255, 255, 255, 0.05);
  }
}

/* iOS-specific fixes */
@supports (-webkit-touch-callout: none) {
  /* Prevent callout menu on long-press */
  button, a, img {
    -webkit-touch-callout: none;
  }

  /* Fix font sizing issue on iOS */
  input, textarea, select {
    font-size: 16px;
  }

  /* Smooth momentum scrolling */
  main, [role="region"] {
    -webkit-overflow-scrolling: touch;
  }
}

/* Android-specific fixes */
@media (max-width: 600px) {
  /* Compensate for Android system UI */
  body {
    min-height: 100dvh; /* Use dynamic viewport height */
  }
}

/* Bottom safe area support for notched devices */
@supports (padding: max(0px)) {
  /* Floating buttons should respect bottom safe area */
  .floating-btn, .fab {
    padding-bottom: max(1rem, env(safe-area-inset-bottom));
  }

  /* Sticky footer support */
  footer {
    padding-bottom: max(1rem, env(safe-area-inset-bottom));
  }
}

/* Portrait mode optimization */
@media (orientation: portrait) and (max-width: 768px) {
  /* Full-width layout on small portrait screens */
  main {
    margin: 0;
  }

  .container {
    max-width: 100%;
    padding: 0;
  }
}

/* Tablet optimization */
@media (min-width: 600px) and (max-width: 960px) {
  /* Two-column layout on tablets */
  .grid-auto {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* Input field optimization for mobile */
input[type="text"],
input[type="email"],
input[type="tel"],
input[type="date"],
textarea {
  /* Prevent zoom on iOS when focused */
  font-size: 16px;

  /* Add padding for easier tapping */
  padding: 0.75rem;

  /* Full width on mobile */
  width: 100%;

  /* Add visual feedback */
  transition: border-color 0.2s;
}

/* Focus states for accessibility */
input:focus,
textarea:focus,
select:focus,
button:focus,
[role="button"]:focus {
  outline: 2px solid #4f46e5;
  outline-offset: 2px;
}

/* Improve button responsiveness on touch */
button:active,
[role="button"]:active {
  transform: scale(0.98);
  transition: transform 0.05s;
}

/* Form layout optimization */
@media (max-width: 640px) {
  form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
  }

  .form-row {
    flex-direction: column;
  }

  label {
    display: block;
    margin-bottom: 0.25rem;
    font-weight: 600;
  }
}

/* Modal/dialog optimization for mobile */
@media (max-width: 640px) {
  dialog, [role="dialog"] {
    width: 100%;
    max-width: 100%;
    margin: 0;
    border-radius: 1rem 1rem 0 0;
    max-height: 90vh;
    bottom: 0;
    position: fixed;
  }
}

/* Network status indicator */
.network-status {
  position: fixed;
  top: env(safe-area-inset-top);
  left: 0;
  right: 0;
  padding: 0.75rem 1rem;
  background: #fbbf24;
  color: #000;
  font-size: 0.875rem;
  text-align: center;
  z-index: 100;
  animation: slideDown 0.3s ease;
}

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

/* Loading state optimization */
.skeleton {
  animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

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

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

  button:active {
    transform: none;
  }
}

/* PWA-specific styling */
@media (display-mode: standalone) {
  /* Remove URL bar spacing compensation */
  body {
    padding-top: 0;
  }

  /* Adjust for fullscreen app */
  header {
    padding-top: max(0.5rem, env(safe-area-inset-top));
  }
}
