/* ========================================
   MOBILE UX ENHANCEMENTS
   Trail Intel Mobile-First Improvements
   ======================================== */

/* Ensure proper viewport behavior */
html {
  -webkit-text-size-adjust: 100%;
  -ms-text-size-adjust: 100%;
}

/* Improve touch targets and spacing */
* {
  -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1);
}

/* ===============================
   GENERAL MOBILE IMPROVEMENTS
   =============================== */


/* Improve button spacing on mobile */
@media (max-width: 768px) {
  .primary-btn, .secondary-btn {
    padding: 12px 16px;
    font-size: 16px; /* Prevents zoom on iOS */
    min-height: 44px;
  }
  
  /* Improve form elements */
  input, textarea, select {
    font-size: 16px; /* Prevents zoom on iOS */
    padding: 12px;
    border-radius: 6px;
  }
  
  /* Better spacing between UI elements */
  .tab + .tabcontent {
    margin-top: 15px;
  }
  
  /* Improve modal spacing */
  .modal-content {
    margin: 10px;
    padding: 20px;
    border-radius: 8px;
  }
}

/* ===============================
   NAVIGATION IMPROVEMENTS
   =============================== */

/* Hamburger menu for very small screens */
@media (max-width: 600px) {
  /* Consider adding a hamburger menu for tabs if needed */
  .tab {
    position: relative;
  }
  
  /* Improve tab button text wrapping */
  .tab button {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
  }
  
  /* Shorter button text on very small screens */
  .tab button {
    font-size: 14px;
  }
  
  /* Specific adjustments for long button text */
  .tab button[id="btn-ai"] {
    /* Intelligence Collection button might need shorter text */
    font-size: 13px;
  }
}

/* ===============================
   CREDIT SYSTEM MOBILE IMPROVEMENTS
   =============================== */

@media (max-width: 768px) {
  /* Credit Package Selection Improvements */
  .credit-purchase-modal .packages-container {
    gap: 12px;
  }
  
  .credit-purchase-modal .credit-package {
    min-height: auto;
    padding: 18px 15px;
  }
  
  .credit-package .package-price {
    margin: 10px 0;
  }
  
  .credit-package .credits-count {
    margin-bottom: 8px;
    font-weight: 600;
  }
  
  .credit-package .package-description {
    line-height: 1.4;
    margin: 8px 0;
  }
  
  /* Marketing Credit Packages */
  .marketing-pricing-card .credit-packages .package-option {
    border: 1px solid rgba(0,0,0,0.1);
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    margin-bottom: 12px;
  }
  
  .marketing-pricing-card .package-option.popular-package {
    border-color: #4CAF50;
    background: rgba(76, 175, 80, 0.05);
  }
  
  .marketing-pricing-card .package-option.value-package {
    border-color: #FF9800;
    background: rgba(255, 152, 0, 0.05);
  }
  
  /* Cost Confirmation Modal Improvements */
  .cost-modal .cost-breakdown {
    border-radius: 6px;
  }
  
  .cost-modal .cost-row {
    align-items: flex-start;
  }
  
  .cost-modal .cost-label {
    flex: 1;
    text-align: left;
  }
  
  .cost-modal .cost-value {
    flex-shrink: 0;
    margin-left: 10px;
  }
}

@media (max-width: 480px) {
  /* Full-screen credit modals on small mobile */
  .credit-purchase-modal,
  .cost-modal-content {
    width: 100vw;
    height: 100vh;
    margin: 0;
    border-radius: 0;
    max-height: none;
  }
  
  /* Stack package options vertically with better spacing */
  .marketing-pricing-card .package-option {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto;
    gap: 5px;
    padding: 12px;
    text-align: center;
  }
  
  .marketing-pricing-card .package-discount {
    grid-column: 1;
    justify-self: center;
    margin-top: 5px;
  }
  
  /* Improve button accessibility */
  .credit-purchase-modal .purchase-btn,
  .cost-modal .cost-modal-btn {
    font-size: 16px; /* Prevent zoom on iOS */
    border-radius: 8px;
    font-weight: 600;
  }
  
  /* Better touch feedback */
  .package-option:active,
  .credit-package:active {
    transform: scale(0.98);
    opacity: 0.9;
  }
}

/* ===============================
   CONTENT AREA IMPROVEMENTS
   =============================== */

@media (max-width: 768px) {
  /* Improve dashboard layout */
  .dashboard-grid {
    grid-template-columns: 1fr;
    gap: 15px;
  }
  
  /* Stack form elements */
  .form-row {
    flex-direction: column;
    gap: 10px;
  }
  
  .form-group {
    margin-bottom: 15px;
  }
  
  /* Improve image gallery on mobile */
  .gallery-grid {
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 10px;
  }
  
  /* Improve upload area */
  .upload-area {
    padding: 20px;
    margin: 10px 0;
  }
  
  /* Better spacing for tips and info sections */
  .upload-tips-section {
    margin: 15px 0;
  }
  
  .tips-table {
    flex-direction: column;
    gap: 15px;
  }
  
  .tips-column {
    width: 100%;
  }
}

/* ===============================
   TABLE IMPROVEMENTS
   =============================== */

@media (max-width: 768px) {
  /* Make tables scrollable horizontally */
  .table-container {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  
  table {
    min-width: 600px;
    font-size: 14px;
  }
  
  th, td {
    padding: 8px 6px;
    white-space: nowrap;
  }
  
  /* Stack table rows on very small screens */
  @media (max-width: 480px) {
    .mobile-stack-table {
      display: block;
    }
    
    .mobile-stack-table thead {
      display: none;
    }
    
    .mobile-stack-table tbody,
    .mobile-stack-table tr,
    .mobile-stack-table td {
      display: block;
      width: 100%;
    }
    
    .mobile-stack-table tr {
      border: 1px solid #ddd;
      margin-bottom: 10px;
      padding: 10px;
      border-radius: 6px;
    }
    
    .mobile-stack-table td {
      border: none;
      position: relative;
      padding-left: 30%;
    }
    
    .mobile-stack-table td:before {
      content: attr(data-label) ": ";
      position: absolute;
      left: 6px;
      width: 25%;
      font-weight: bold;
      text-align: left;
    }
  }
}

/* ===============================
   MODAL IMPROVEMENTS
   =============================== */

@media (max-width: 768px) {
  .modal {
    padding: 10px;
  }
  
  .modal-content {
    max-height: 90vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  
  .modal-header {
    padding: 15px 20px;
    flex-wrap: wrap;
    gap: 10px;
  }
  
  .modal-body {
    padding: 20px;
  }
  
  .modal-footer {
    padding: 15px 20px;
    flex-wrap: wrap;
    gap: 10px;
  }
  
  .modal-footer button {
    flex: 1;
    min-width: 120px;
  }
}

/* ===============================
   UTILITY CLASSES
   =============================== */

/* Hide on mobile */
@media (max-width: 768px) {
  .hide-mobile {
    display: none !important;
  }
}

/* Show only on mobile */
.show-mobile {
  display: none !important;
}

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

/* Text alignment utilities for mobile */
@media (max-width: 768px) {
  .mobile-text-center {
    text-align: center !important;
  }
  
  .mobile-text-left {
    text-align: left !important;
  }
}

/* Spacing utilities for mobile */
@media (max-width: 768px) {
  .mobile-mb-small {
    margin-bottom: 10px !important;
  }
  
  .mobile-mb-medium {
    margin-bottom: 20px !important;
  }
  
  .mobile-p-small {
    padding: 10px !important;
  }
}

/* ===============================
   ACCESSIBILITY IMPROVEMENTS
   =============================== */

/* Improve focus indicators for touch navigation */
@media (max-width: 768px) {
  button:focus,
  a:focus,
  input:focus,
  select:focus,
  textarea:focus {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
  }
  
  /* Larger click areas for small elements */
  .icon-button {
    padding: 12px;
    min-width: 44px;
    min-height: 44px;
  }
}

/* ===============================
   PERFORMANCE OPTIMIZATIONS
   =============================== */

/* Reduce animations on mobile for better performance */
@media (max-width: 768px) and (prefers-reduced-motion: no-preference) {
  * {
    animation-duration: 0.2s !important;
    transition-duration: 0.2s !important;
  }
}

/* Disable hover effects on touch devices */
@media (hover: none) and (pointer: coarse) {
  .tab button:hover {
    background-color: initial;
  }
  
  .primary-btn:hover {
    transform: none;
    background-color: var(--primary-color);
  }
  
  .secondary-btn:hover {
    background-color: white;
  }
}

/* ===============================
   DARK THEME MOBILE ADJUSTMENTS
   =============================== */

@media (max-width: 768px) {
  body.dark-theme .modal-content {
    background-color: var(--dark-bg-secondary);
    border: 1px solid var(--dark-border);
  }
  
  body.dark-theme .tab button {
    background-color: var(--dark-surface-1);
    border-bottom: 1px solid var(--dark-border);
  }
  
  body.dark-theme .tab button.active {
    background-color: var(--dark-surface-2);
    border-left: 4px solid var(--dark-primary);
  }
}
