/* ========================================
   RESPONSIVE DESIGN IMPROVEMENTS
   Comprehensive mobile and tablet optimizations
   ======================================== */

/* Base responsive utilities */
.touch-friendly {
  min-height: 44px;
  min-width: 44px;
  touch-action: manipulation;
}

.mobile-scroll {
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

/* Mobile-first breakpoints */
@media (max-width: 640px) {
  /* Typography adjustments */
  h1 { font-size: 2rem !important; }
  h2 { font-size: 1.75rem !important; }
  h3 { font-size: 1.5rem !important; }
  
  /* Container spacing */
  .container-mobile {
    padding-left: 1rem;
    padding-right: 1rem;
  }
  
  /* Navigation improvements */
  .mobile-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: white;
    border-top: 1px solid #e5e7eb;
    padding: 0.75rem 1rem;
    z-index: 50;
    box-shadow: 0 -4px 6px -1px rgba(0, 0, 0, 0.1);
  }
  
  .mobile-nav-items {
    display: flex;
    justify-content: space-around;
    align-items: center;
  }
  
  .mobile-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 0.5rem;
    border-radius: 0.5rem;
    transition: all 0.2s;
    min-width: 44px;
    min-height: 44px;
  }
  
  .mobile-nav-item:active {
    background: #f3f4f6;
    transform: scale(0.95);
  }
  
  .mobile-nav-item.active {
    background: #eff6ff;
    color: #3b82f6;
  }
  
  .mobile-nav-icon {
    font-size: 1.25rem;
    margin-bottom: 0.25rem;
  }
  
  .mobile-nav-label {
    font-size: 0.75rem;
    font-weight: 500;
  }
  
  /* Modal improvements */
  .mobile-modal {
    position: fixed;
    inset: 0;
    z-index: 100;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
  }
  
  .mobile-modal-content {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: white;
    border-radius: 1rem 1rem 0 0;
    padding: 1.5rem;
    max-height: 90vh;
    overflow-y: auto;
    transform: translateY(100%);
    transition: transform 0.3s ease-out;
  }
  
  .mobile-modal-content.show {
    transform: translateY(0);
  }
  
  .mobile-modal-handle {
    width: 3rem;
    height: 0.25rem;
    background: #d1d5db;
    border-radius: 9999px;
    margin: 0 auto 1rem auto;
  }
  
  /* Form improvements */
  .mobile-form input,
  .mobile-form select,
  .mobile-form textarea {
    font-size: 16px; /* Prevents zoom on iOS */
    padding: 0.875rem;
    border-radius: 0.5rem;
    border: 2px solid #e5e7eb;
    width: 100%;
    transition: border-color 0.2s;
  }
  
  .mobile-form input:focus,
  .mobile-form select:focus,
  .mobile-form textarea:focus {
    border-color: #3b82f6;
    outline: none;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
  }
  
  .mobile-form-group {
    margin-bottom: 1.5rem;
  }
  
  .mobile-form label {
    display: block;
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: #374151;
  }
  
  /* Button improvements */
  .mobile-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.875rem 1.5rem;
    font-size: 1rem;
    font-weight: 600;
    border-radius: 0.75rem;
    transition: all 0.2s;
    min-height: 44px;
    touch-action: manipulation;
    user-select: none;
  }
  
  .mobile-btn:active {
    transform: scale(0.98);
  }
  
  .mobile-btn-primary {
    background: linear-gradient(135deg, #3b82f6, #1d4ed8);
    color: white;
    border: none;
  }
  
  .mobile-btn-secondary {
    background: white;
    color: #374151;
    border: 2px solid #e5e7eb;
  }
  
  .mobile-btn-danger {
    background: linear-gradient(135deg, #ef4444, #dc2626);
    color: white;
    border: none;
  }
  
  /* Card improvements */
  .mobile-card {
    background: white;
    border-radius: 1rem;
    padding: 1.5rem;
    margin-bottom: 1rem;
    box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1);
    border: 1px solid #f3f4f6;
  }
  
  .mobile-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid #f3f4f6;
  }
  
  .mobile-card-title {
    font-size: 1.125rem;
    font-weight: 700;
    color: #111827;
  }
  
  /* Touch-friendly interactions */
  .mobile-touch-item {
    padding: 1rem;
    border-radius: 0.5rem;
    transition: background-color 0.2s;
    touch-action: manipulation;
  }
  
  .mobile-touch-item:active {
    background: #f9fafb;
  }
  
  /* Swipe gestures */
  .mobile-swipeable {
    position: relative;
    overflow: hidden;
  }
  
  .mobile-swipe-actions {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    display: flex;
    align-items: center;
    background: #ef4444;
    padding: 0 1rem;
    transform: translateX(100%);
    transition: transform 0.3s ease-out;
  }
  
  .mobile-swipe-actions.show {
    transform: translateX(0);
  }
  
  /* Loading states */
  .mobile-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    text-align: center;
  }
  
  .mobile-spinner {
    width: 2rem;
    height: 2rem;
    border: 3px solid #f3f4f6;
    border-top: 3px solid #3b82f6;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 1rem;
  }
  
  /* Skeleton loading */
  .mobile-skeleton {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: loading 1.5s infinite;
    border-radius: 0.5rem;
  }
  
  .mobile-skeleton-text {
    height: 1rem;
    margin-bottom: 0.5rem;
  }
  
  .mobile-skeleton-title {
    height: 1.5rem;
    width: 60%;
    margin-bottom: 1rem;
  }
  
  /* Pull to refresh */
  .mobile-pull-refresh {
    position: relative;
    overflow: hidden;
  }
  
  .mobile-pull-indicator {
    position: absolute;
    top: -4rem;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    justify-content: center;
    width: 3rem;
    height: 3rem;
    background: white;
    border-radius: 50%;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    transition: top 0.3s ease-out;
  }
  
  .mobile-pull-indicator.show {
    top: 1rem;
  }
  
  /* Floating action button */
  .mobile-fab {
    position: fixed;
    bottom: 5rem;
    right: 1rem;
    width: 3.5rem;
    height: 3.5rem;
    background: linear-gradient(135deg, #3b82f6, #1d4ed8);
    color: white;
    border: none;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.4);
    z-index: 40;
    transition: all 0.3s ease;
  }
  
  .mobile-fab:active {
    transform: scale(0.9);
  }
  
  /* Chat optimizations */
  .mobile-chat {
    padding-bottom: 5rem; /* Space for mobile nav */
  }
  
  .mobile-chat-input {
    position: fixed;
    bottom: 4rem;
    left: 0;
    right: 0;
    padding: 1rem;
    background: white;
    border-top: 1px solid #e5e7eb;
    z-index: 30;
  }
  
  .mobile-chat-input-group {
    display: flex;
    gap: 0.75rem;
    align-items: flex-end;
  }
  
  .mobile-chat-textarea {
    flex: 1;
    padding: 0.75rem;
    border: 2px solid #e5e7eb;
    border-radius: 1.5rem;
    font-size: 16px;
    resize: none;
    max-height: 6rem;
    overflow-y: auto;
  }
  
  .mobile-chat-send {
    width: 3rem;
    height: 3rem;
    background: #3b82f6;
    color: white;
    border: none;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
  }
  
  /* Dashboard grid improvements */
  .mobile-dashboard-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1rem;
    padding: 1rem;
  }
  
  .mobile-stat-card {
    background: white;
    padding: 1.5rem;
    border-radius: 1rem;
    text-align: center;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  }
  
  .mobile-stat-number {
    font-size: 2rem;
    font-weight: 800;
    color: #3b82f6;
    display: block;
  }
  
  .mobile-stat-label {
    font-size: 0.875rem;
    color: #6b7280;
    margin-top: 0.5rem;
  }
  
  /* List improvements */
  .mobile-list {
    background: white;
    border-radius: 1rem;
    overflow: hidden;
    margin-bottom: 1rem;
  }
  
  .mobile-list-item {
    padding: 1rem;
    border-bottom: 1px solid #f3f4f6;
    display: flex;
    align-items: center;
    touch-action: manipulation;
  }
  
  .mobile-list-item:last-child {
    border-bottom: none;
  }
  
  .mobile-list-item:active {
    background: #f9fafb;
  }
  
  .mobile-list-icon {
    width: 2.5rem;
    height: 2.5rem;
    border-radius: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 0.75rem;
    font-size: 1.25rem;
  }
  
  .mobile-list-content {
    flex: 1;
  }
  
  .mobile-list-title {
    font-weight: 600;
    color: #111827;
    margin-bottom: 0.25rem;
  }
  
  .mobile-list-subtitle {
    font-size: 0.875rem;
    color: #6b7280;
  }
  
  .mobile-list-action {
    color: #9ca3af;
    font-size: 1.25rem;
  }
}

/* Tablet optimizations */
@media (min-width: 641px) and (max-width: 1024px) {
  .tablet-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1.5rem;
  }
  
  .tablet-sidebar {
    position: fixed;
    left: -16rem;
    top: 0;
    bottom: 0;
    width: 16rem;
    background: white;
    z-index: 50;
    transition: left 0.3s ease-out;
    box-shadow: 2px 0 8px rgba(0, 0, 0, 0.1);
  }
  
  .tablet-sidebar.show {
    left: 0;
  }
  
  .tablet-main {
    transition: margin-left 0.3s ease-out;
  }
  
  .tablet-main.with-sidebar {
    margin-left: 16rem;
  }
  
  .tablet-modal {
    max-width: 28rem;
    margin: 2rem auto;
  }
}

/* Landscape phone optimizations */
@media (max-width: 896px) and (orientation: landscape) {
  .landscape-nav {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: 4rem;
    background: white;
    border-right: 1px solid #e5e7eb;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 1rem 0;
    z-index: 50;
  }
  
  .landscape-nav-item {
    width: 3rem;
    height: 3rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 0.75rem;
    margin-bottom: 0.5rem;
    transition: all 0.2s;
  }
  
  .landscape-nav-item:active {
    background: #f3f4f6;
    transform: scale(0.95);
  }
  
  .landscape-nav-item.active {
    background: #eff6ff;
    color: #3b82f6;
  }
  
  .landscape-content {
    margin-left: 4rem;
    padding: 1rem;
  }
}

/* Animations */
@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

@keyframes loading {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(2rem);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* Touch feedback */
.mobile-ripple {
  position: relative;
  overflow: hidden;
}

.mobile-ripple::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0;
  height: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.5);
  transform: translate(-50%, -50%);
  transition: width 0.6s, height 0.6s;
}

.mobile-ripple:active::before {
  width: 300px;
  height: 300px;
}

/* Accessibility improvements */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* High contrast mode */
@media (prefers-contrast: high) {
  .mobile-btn-primary {
    background: #000;
    border: 2px solid #000;
  }
  
  .mobile-btn-secondary {
    background: #fff;
    color: #000;
    border: 2px solid #000;
  }
  
  .mobile-card {
    border: 2px solid #000;
  }
}

/* Large text support */
@media (prefers-reduced-data: reduce) {
  .mobile-skeleton {
    background: #f0f0f0;
    animation: none;
  }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
  .mobile-card {
    background: #1f2937;
    border-color: #374151;
    color: #f9fafb;
  }
  
  .mobile-nav {
    background: #1f2937;
    border-color: #374151;
  }
  
  .mobile-form input,
  .mobile-form select,
  .mobile-form textarea {
    background: #374151;
    border-color: #4b5563;
    color: #f9fafb;
  }
  
  .mobile-btn-secondary {
    background: #374151;
    color: #f9fafb;
    border-color: #4b5563;
  }
}