/* ========================================
   MOBILE OPTIMIZATION CSS
   Add this file to your GitHub repo
   ======================================== */

/* Mobile-first responsive design */
@media (max-width: 768px) {
  
  /* General layout improvements */
  body {
    font-size: 14px;
    -webkit-text-size-adjust: 100%;
  }
  
  .admin-container,
  .container {
    padding: 10px;
    max-width: 100%;
    margin: 0;
  }
  
  /* Header adjustments */
  .header,
  .admin-header {
    padding: 12px;
    flex-wrap: wrap;
    gap: 8px;
  }
  
  .header h1,
  .admin-header h1 {
    font-size: 18px;
  }
  
  /* Navigation tabs - Make them bigger and wrap */
  .tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 15px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  
  .tab {
    flex: 1 1 calc(50% - 8px);
    min-width: 100px;
    padding: 14px 12px;
    font-size: 13px;
    text-align: center;
    white-space: nowrap;
    border-radius: 8px;
  }
  
  /* Make scrollable table wrapper */
  .table-container,
  #usersTable,
  #permissionsTable,
  #dashboardsTable {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 0 -10px;
    padding: 0 10px;
  }
  
  /* Table improvements */
  table {
    min-width: 600px; /* Ensures horizontal scroll */
    font-size: 12px;
    border-collapse: collapse;
  }
  
  thead th {
    position: sticky;
    top: 0;
    background: white;
    z-index: 10;
    padding: 10px 8px;
    font-size: 11px;
  }
  
  tbody td {
    padding: 10px 8px;
    white-space: nowrap;
  }
  
  /* Make action buttons touch-friendly */
  .icon-btn {
    width: 42px;
    height: 42px;
    font-size: 20px;
    margin: 3px;
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
  
  /* Regular buttons - Bigger touch targets */
  button,
  .button,
  .btn {
    min-height: 44px; /* Apple's recommended */
    padding: 12px 20px;
    font-size: 15px;
    border-radius: 8px;
    cursor: pointer;
  }
  
  /* "+ Add User" type buttons */
  button[onclick*="Add"],
  button[onclick*="open"] {
    width: 100%;
    max-width: 200px;
    margin: 10px 0;
  }
  
  /* Modal improvements */
  .modal {
    padding: 10px;
  }
  
  .modal-content {
    width: 95%;
    max-width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    margin: auto;
    padding: 20px;
    border-radius: 12px;
  }
  
  .modal-content h2 {
    font-size: 20px;
    margin-bottom: 16px;
  }
  
  /* Form improvements */
  .form-group {
    margin-bottom: 16px;
  }
  
  .form-group label {
    display: block;
    margin-bottom: 6px;
    font-weight: 600;
    font-size: 14px;
  }
  
  input,
  select,
  textarea {
    width: 100%;
    min-height: 44px;
    padding: 12px;
    font-size: 16px; /* Prevents iOS zoom */
    border: 2px solid #e2e8f0;
    border-radius: 8px;
    box-sizing: border-box;
    -webkit-appearance: none;
  }
  
  input:focus,
  select:focus,
  textarea:focus {
    outline: none;
    border-color: #667eea;
  }
  
  /* Checkboxes - Make bigger */
  input[type="checkbox"] {
    width: 20px;
    height: 20px;
    min-height: 20px;
  }
  
  .checkbox-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px;
    margin-bottom: 8px;
  }
  
  .checkbox-item label {
    margin: 0;
    font-size: 14px;
  }
  
  /* Badge improvements */
  .badge {
    padding: 6px 10px;
    font-size: 11px;
    border-radius: 6px;
    display: inline-block;
  }
  
  /* Activity log improvements */
  .activity-item {
    font-size: 13px;
    padding: 14px;
    margin-bottom: 10px;
    border-radius: 8px;
    background: white;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
  }
  
  .activity-time {
    font-size: 11px;
    margin-bottom: 6px;
  }
  
  .activity-user {
    font-weight: 600;
  }
  
  .activity-details {
    font-size: 12px;
    color: #718096;
    margin-top: 6px;
  }
  
  /* Dashboard grid for mobile */
  .dashboard-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
    padding: 10px;
  }
  
  .dashboard-card {
    padding: 16px;
    border-radius: 12px;
    background: white;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  }
  
  /* Loading indicators */
  .loading {
    padding: 20px;
    text-align: center;
    font-size: 14px;
  }
  
  /* Message area */
  .message {
    padding: 14px;
    border-radius: 8px;
    margin: 10px 0;
    font-size: 14px;
  }
  
  /* Bottom navigation safe area (for iPhone notch) */
  .footer,
  .bottom-nav {
    padding-bottom: env(safe-area-inset-bottom);
  }
}

/* Very small phones (iPhone SE, etc.) */
@media (max-width: 480px) {
  
  /* Stack tabs vertically */
  .tab {
    flex: 1 1 100%;
  }
  
  /* Hide less critical table columns */
  table.hide-on-mobile td:nth-child(2),
  table.hide-on-mobile th:nth-child(2),
  table.hide-on-mobile td:nth-child(3),
  table.hide-on-mobile th:nth-child(3) {
    display: none;
  }
  
  /* Make modals full screen */
  .modal-content {
    width: 100%;
    height: 100%;
    max-height: 100%;
    border-radius: 0;
  }
  
  /* Reduce padding everywhere */
  .admin-container,
  .container {
    padding: 8px;
  }
}

/* Landscape mode on mobile */
@media (max-width: 768px) and (orientation: landscape) {
  .modal-content {
    max-height: 80vh;
  }
  
  .tabs {
    gap: 6px;
  }
  
  .tab {
    padding: 10px 8px;
    font-size: 12px;
  }
}

/* Touch improvements for all mobile devices */
@media (hover: none) and (pointer: coarse) {
  
  /* Remove hover effects, add active states */
  button:hover,
  .btn:hover {
    opacity: 1;
  }
  
  button:active,
  .btn:active {
    transform: scale(0.97);
    opacity: 0.8;
  }
  
  /* Better tap targets */
  a, button, input, select, textarea {
    -webkit-tap-highlight-color: rgba(102, 126, 234, 0.2);
  }
  
  /* Disable text selection on buttons */
  button, .btn {
    -webkit-user-select: none;
    user-select: none;
  }
}

/* iOS specific fixes */
@supports (-webkit-touch-callout: none) {
  /* Fix for iOS input zoom */
  input,
  select,
  textarea {
    font-size: 16px !important;
  }
  
  /* Fix for iOS safe areas */
  body {
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
  }
}

/* PWA specific styles */
@media (display-mode: standalone) {
  /* App is installed - hide browser chrome hints */
  .install-prompt {
    display: none;
  }
  
  /* Add extra padding for status bar */
  .header,
  .admin-header {
    padding-top: calc(12px + env(safe-area-inset-top));
  }
}

/* Dark mode support (optional) */
@media (prefers-color-scheme: dark) {
  /* Uncomment if you want dark mode support
  body {
    background: #1a202c;
    color: #e2e8f0;
  }
  
  .modal-content,
  .dashboard-card,
  .activity-item {
    background: #2d3748;
    color: #e2e8f0;
  }
  */
}
