/* Mobile-specific CSS enhancements */

/* Touch-friendly button sizes */
@media (max-width: 768px) {
  /* Ensure proper scrolling on mobile */
  html, body {
    height: auto;
    overflow-x: hidden;
  }
  
  body {
    position: relative;
  }
  
  #content {
    min-height: calc(100vh - 60px); /* Account for bottom nav */
    padding-bottom: 80px; /* Extra space for bottom nav */
  }
  
  .btn {
    min-height: 44px;
    padding: 0.5rem 1rem;
  }
  
  .btn-sm {
    min-height: 36px;
    padding: 0.375rem 0.75rem;
  }
  
  /* Form controls */
  .form-control,
  .form-select {
    min-height: 44px;
    font-size: 16px; /* Prevents zoom on iOS */
  }
  
  .form-check-input {
    width: 1.25rem;
    height: 1.25rem;
  }
  
  /* Tables - make them scrollable with fixed first column */
  .table-responsive {
    -webkit-overflow-scrolling: touch;
  }
  
  /* Card spacing on mobile */
  .card {
    margin-bottom: 1rem;
  }
  
  /* Navigation improvements */
  #sidebar {
    width: 280px; /* Wider on mobile for easier touch */
  }
  
  #sidebar .nav-link {
    padding: 0.75rem 1rem;
    font-size: 1rem;
  }
  
  /* Modal improvements */
  .modal-dialog {
    margin: 0.5rem;
  }
  
  .modal-content {
    border-radius: 1rem;
  }
  
  /* Toast positioning */
  .toast-container {
    bottom: 70px !important; /* Above potential bottom nav */
  }
  
  /* Ad spend table mobile view */
  .table td,
  .table th {
    white-space: nowrap;
  }
  
  /* Dashboard specific */
  .dashboard-controls-card {
    margin-left: -15px;
    margin-right: -15px;
    border-radius: 0;
  }
  
  /* Text size adjustments */
  h1 {
    font-size: 1.75rem;
  }
  
  h2 {
    font-size: 1.5rem;
  }
  
  h3 {
    font-size: 1.25rem;
  }
  
  .display-5 {
    font-size: 2rem;
  }
}

/* Small phones (below 576px) */
@media (max-width: 576px) {
  /* Full width buttons on small screens */
  .btn-group {
    display: flex;
    flex-direction: column;
    width: 100%;
  }
  
  .btn-group .btn {
    width: 100%;
    border-radius: 0.375rem !important;
    margin-bottom: 0.5rem;
  }
  
  /* Stack form elements */
  .row.g-3 > [class*="col-"] {
    padding-bottom: 0.5rem;
  }
  
  /* Reduce padding */
  .card-body {
    padding: 1rem;
  }
  
  .container-fluid {
    padding-left: 15px;
    padding-right: 15px;
  }
  
  /* Hide less important columns in tables */
  .table .d-none-mobile {
    display: none !important;
  }
  
  /* Full screen modals */
  .modal-fullscreen-sm-down .modal-dialog {
    margin: 0;
    max-width: 100%;
    height: 100%;
  }
  
  .modal-fullscreen-sm-down .modal-content {
    height: 100%;
    border-radius: 0;
  }
}

/* Touch-friendly hover states */
@media (hover: none) and (pointer: coarse) {
  /* Remove hover effects on touch devices */
  .btn:hover {
    transform: none !important;
    box-shadow: none !important;
  }
  
  .card:hover {
    box-shadow: 0 2px 4px rgba(0,0,0,0.1) !important;
  }
  
  /* Replace hover tooltips with click */
  [data-bs-toggle="tooltip"]:hover::after {
    display: none;
  }
}

/* Landscape orientation adjustments */
@media (max-width: 768px) and (orientation: landscape) {
  /* Reduce vertical spacing in landscape */
  .mobile-metric-card {
    padding: 0.5rem;
  }
  
  .mobile-daily-card .card-section {
    padding: 0.5rem;
  }
  
  /* Adjust dashboard header */
  .dashboard-controls-card .controls-header {
    padding: 0.75rem 1rem;
  }
}

/* iOS-specific fixes */
@supports (-webkit-touch-callout: none) {
  /* Improved iOS scrolling without position fixed */
  body {
    -webkit-overflow-scrolling: touch;
  }
  
  #content {
    -webkit-overflow-scrolling: touch;
  }
  
  /* Fix for iOS input zoom in product type costs */
  .mobile-product-costs input[type="number"],
  .mobile-product-costs input[type="date"],
  .mobile-product-costs select {
    font-size: 16px;
  }
}

/* Additional mobile styles for product type costs */
@media (max-width: 768px) {
  /* Ensure product type costs mobile view is properly contained */
  .mobile-product-costs {
    max-width: 100vw;
    overflow-x: hidden;
  }
  
  /* Mobile-specific form enhancements */
  .mobile-product-costs .form-control,
  .mobile-product-costs .form-select {
    min-height: 44px;
    font-size: 16px; /* Prevents zoom on iOS */
  }
  
  .mobile-product-costs .btn {
    min-height: 44px;
    padding: 0.75rem 1rem;
  }
  
  .mobile-product-costs .btn-lg {
    min-height: 50px;
    padding: 0.875rem 1.25rem;
  }
  
  /* Form check inputs for better touch */
  .mobile-product-costs .form-check-input {
    width: 1.25rem;
    height: 1.25rem;
    margin-top: 0.125rem;
  }
  
  .mobile-product-costs .form-check-label {
    margin-left: 0.5rem;
    font-size: 1rem;
  }
}

/* Improved focus states for accessibility */
.btn:focus,
.form-control:focus,
.form-select:focus {
  outline: 3px solid rgba(13, 110, 253, 0.25);
  outline-offset: 2px;
}

/* Touch interaction improvements */
.focused {
  background-color: rgba(13, 110, 253, 0.02);
  border-radius: 8px;
  transition: background-color 0.2s ease;
}

/* Button touch states */
.btn {
  transition: all 0.2s ease;
  -webkit-tap-highlight-color: transparent;
}

.btn:active {
  transform: scale(0.98);
}

/* Card touch feedback */
.card {
  transition: all 0.2s ease;
}

.card:active {
  transform: scale(0.99);
}

/* Navigation touch improvements */
.nav-link {
  -webkit-tap-highlight-color: transparent;
  transition: all 0.2s ease;
}

/* Pull to refresh indicator */
.pull-refresh-indicator {
  user-select: none;
  -webkit-user-select: none;
}

/* Prevent text selection on touch */
.mobile-bottom-nav,
.mobile-daily-card .card-header,
.mobile-ad-spend-card .card-header {
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

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

.spinner-border-sm {
  width: 1rem;
  height: 1rem;
  border-width: 0.2em;
}

/* Bottom navigation preparation */
.bottom-nav-spacing {
  padding-bottom: 70px;
}

/* Swipe indicators */
.swipe-hint {
  background: linear-gradient(90deg, transparent, rgba(0,0,0,0.05), transparent);
  animation: swipe-hint 2s ease-in-out infinite;
}

@keyframes swipe-hint {
  0%, 100% { transform: translateX(-100%); }
  50% { transform: translateX(100%); }
}

/* Mobile Ad Spend Cards */
.mobile-ad-spend-card {
  background: white;
  border: 1px solid #dee2e6;
  border-radius: 12px;
  margin-bottom: 1rem;
  overflow: hidden;
  box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

.mobile-ad-spend-card .card-header {
  background: #f8f9fa;
  border-bottom: 1px solid #dee2e6;
  padding: 0.75rem;
}

.mobile-ad-spend-card .date-amount .date {
  font-weight: 600;
  color: #495057;
}

.mobile-ad-spend-card .date-amount .amount {
  font-size: 1.1rem;
}

.mobile-ad-spend-card .badges {
  text-align: right;
}

.mobile-ad-spend-card .badges .badge {
  display: block;
  margin-bottom: 0.25rem;
  font-size: 0.75rem;
}

.mobile-ad-spend-card .card-body {
  padding: 0.75rem;
}

.mobile-ad-spend-card .btn-group .btn {
  font-size: 0.875rem;
  padding: 0.375rem 0.5rem;
}

/* Mobile table alternatives */
.mobile-data-card {
  background: white;
  border: 1px solid #dee2e6;
  border-radius: 8px;
  margin-bottom: 0.75rem;
  overflow: hidden;
}

.mobile-data-card .card-header {
  background: #f8f9fa;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid #dee2e6;
}

.mobile-data-card .card-body {
  padding: 0.75rem;
}

.mobile-data-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.25rem 0;
  border-bottom: 1px solid #f0f0f0;
}

.mobile-data-row:last-child {
  border-bottom: none;
}

.mobile-data-row .label {
  font-size: 0.875rem;
  color: #6c757d;
  font-weight: 500;
}

.mobile-data-row .value {
  font-size: 0.875rem;
  font-weight: 600;
  text-align: right;
}

/* Print styles */
@media print {
  .mobile-dashboard,
  .mobile-ad-spend-card,
  .d-print-none {
    display: none !important;
  }
  
  .d-none.d-md-block {
    display: block !important;
  }
}