/* Mobile-Friendly CSS Improvements for ConnectCRM */

/* Prevent text scaling on orientation change */
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

/* Better touch targets - minimum 44x44px */
button, 
a,
input[type="button"],
input[type="submit"],
.touch-target {
  min-height: 44px;
  min-width: 44px;
  touch-action: manipulation;
}

/* Improve input fields on mobile */
input,
textarea,
select {
  font-size: 16px !important; /* Prevents iOS zoom */
  -webkit-appearance: none;
  appearance: none;
}

/* Better mobile scrolling */
body {
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
}

/* Improve tap highlighting */
* {
  -webkit-tap-highlight-color: rgba(37, 99, 235, 0.2);
}

/* Mobile-friendly spacing */
@media (max-width: 640px) {
  .container {
    padding-left: 16px;
    padding-right: 16px;
  }
  
  /* Larger touch targets */
  .btn,
  button {
    padding: 12px 16px;
    font-size: 16px;
  }
  
  /* Better modal sizing */
  .modal-content {
    max-height: 85vh;
    overflow-y: auto;
  }
  
  /* Stack tables vertically */
  table {
    font-size: 14px;
  }
  
  /* Hide less important columns on mobile */
  .hide-mobile {
    display: none !important;
  }
}

/* Better form elements */
input:focus,
textarea:focus,
select:focus {
  outline: none;
  ring: 2px solid #2563eb;
}

/* Prevent double-tap zoom */
a, button {
  touch-action: manipulation;
}

/* Better viewport height handling (especially on iOS) */
.min-h-screen {
  min-height: 100vh;
  min-height: -webkit-fill-available;
}

/* Smooth scrolling */
html {
  scroll-behavior: smooth;
}

/* Better loading states */
.loading {
  pointer-events: none;
  opacity: 0.6;
}

/* Mobile-friendly tables */
@media (max-width: 768px) {
  table {
    display: block;
    overflow-x: auto;
    white-space: nowrap;
    -webkit-overflow-scrolling: touch;
  }
  
  /* Responsive table cells */
  td, th {
    padding: 8px 12px;
  }
}

/* Better modals on mobile */
@media (max-width: 640px) {
  .fixed {
    position: fixed !important;
  }
  
  /* Full-width modals on mobile */
  .modal-container {
    width: calc(100% - 32px);
    max-width: 100%;
    margin: 16px;
  }
}

/* PWA Install button animation */
@keyframes slideUp {
  from {
    transform: translateY(100px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

#mobileInstallPrompt {
  animation: slideUp 0.3s ease-out;
}

/* Better safe area handling (notch, etc.) */
@supports (padding: max(0px)) {
  body {
    padding-left: max(0px, env(safe-area-inset-left));
    padding-right: max(0px, env(safe-area-inset-right));
  }
  
  .safe-top {
    padding-top: max(0px, env(safe-area-inset-top));
  }
  
  .safe-bottom {
    padding-bottom: max(0px, env(safe-area-inset-bottom));
  }
}

/* Improve select dropdowns on mobile */
select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3E%3Cpath stroke='%236B7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3E%3C/svg%3E");
  background-position: right 8px center;
  background-repeat: no-repeat;
  background-size: 20px;
  padding-right: 40px;
}

/* Better focus states for accessibility and mobile */
:focus-visible {
  outline: 2px solid #2563eb;
  outline-offset: 2px;
}

/* Loading spinner */
.spinner {
  border: 3px solid #f3f4f6;
  border-top: 3px solid #2563eb;
  border-radius: 50%;
  width: 24px;
  height: 24px;
  animation: spin 1s linear infinite;
}

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

/* Pull-to-refresh indicator (visual only) */
.ptr-indicator {
  text-align: center;
  padding: 10px;
  background: #f3f4f6;
  border-radius: 999px;
  margin: 10px auto;
  width: fit-content;
}

/* Better context menu handling */
img {
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

/* Improve horizontal scrolling */
.scroll-container {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}

.scroll-container::-webkit-scrollbar {
  height: 6px;
}

.scroll-container::-webkit-scrollbar-track {
  background: #f3f4f6;
  border-radius: 3px;
}

.scroll-container::-webkit-scrollbar-thumb {
  background: #9ca3af;
  border-radius: 3px;
}

/* Better mobile navigation */
@media (max-width: 768px) {
  .nav-item {
    padding: 12px 16px;
    font-size: 16px;
  }
  
  .nav-icon {
    font-size: 20px;
  }
}

/* Skeleton loading for better perceived performance */
.skeleton {
  animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
  background: linear-gradient(90deg, #f3f4f6 25%, #e5e7eb 50%, #f3f4f6 75%);
  background-size: 200% 100%;
}

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

/* Empty state improvements */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: #6b7280;
}

.empty-state-icon {
  font-size: 48px;
  margin-bottom: 16px;
  opacity: 0.5;
}

/* Better error states */
.error-message {
  padding: 12px 16px;
  background: #fef2f2;
  border-left: 4px solid #ef4444;
  color: #991b1b;
  border-radius: 4px;
  margin: 8px 0;
}

.success-message {
  padding: 12px 16px;
  background: #f0fdf4;
  border-left: 4px solid #10b981;
  color: #065f46;
  border-radius: 4px;
  margin: 8px 0;
}

/* Optimize for PWA display modes */
@media all and (display-mode: standalone) {
  /* Hide browser-specific UI elements */
  .hide-in-app {
    display: none !important;
  }
  
  /* Add extra padding for status bar */
  body {
    padding-top: env(safe-area-inset-top);
  }
}

/* Dark mode support (if needed in future) */
@media (prefers-color-scheme: dark) {
  /* Add dark mode styles here when ready */
}

/* 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;
  }
}
