/* =========================================================
   MOBILE.CSS - OPTIMIZED VERSION WITH IMPROVED PERFORMANCE
   - Better mobile responsiveness
   - Faster rendering
   - Smoother animations
   - Touch-optimized controls
========================================================= */

@media (max-width: 768px) {

  /* -----------------------------------------------------
     PERFORMANCE OPTIMIZATIONS
  ----------------------------------------------------- */
  
  * {
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
  }

  /* Use GPU acceleration for better performance */
  .glass-card,
  .btn,
  .modal,
  .sidebar {
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
    will-change: transform;
  }

  /* -----------------------------------------------------
     GLOBAL RESET - STOP HEIGHT COLLAPSE
  ----------------------------------------------------- */

  html, body {
    height: auto !important;
    min-height: 100% !important;
    overflow-x: hidden !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
  }

  * {
    box-sizing: border-box;
    max-height: none !important;
  }

  /* -----------------------------------------------------
     APP LAYOUT - OPTIMIZED FOR MOBILE
  ----------------------------------------------------- */

  .app-container {
    display: block !important;
    height: auto !important;
    min-height: 100vh !important;
    overflow: visible !important;
  }

  .main-content {
    display: block !important;
    width: 100% !important;
    height: auto !important;
    min-height: auto !important;
    overflow: visible !important;
    position: relative !important;
    padding: 60px 0 20px 0 !important;
  }

  /* -----------------------------------------------------
     CONTENT AREA - PREVENT BLANK PAGE
  ----------------------------------------------------- */

  .content-area,
  .content-area.page-transition {
    display: block !important;
    width: 100% !important;
    height: auto !important;
    min-height: auto !important;
    max-height: none !important;
    overflow: visible !important;
    position: relative !important;
    padding: 16px !important;
    transform: none !important;
    opacity: 1 !important;
  }

  .page-transition {
    animation: none !important;
    transition: none !important;
  }

  /* -----------------------------------------------------
     HEADER - STICKY & OPTIMIZED
  ----------------------------------------------------- */

  .header {
    position: fixed !important;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1001;
    background: #ffffff;
    padding: 12px 16px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    display: flex;
    justify-content: space-between;
    align-items: center;
  }

  .header-left {
    display: flex;
    align-items: center;
    gap: 12px;
  }

  .page-title {
    font-size: 1.125rem !important;
    margin: 0 !important;
  }

  .menu-toggle {
    display: block !important;
    background: none;
    border: none;
    padding: 8px;
    cursor: pointer;
    color: #374151;
  }

  .menu-toggle svg {
    width: 24px;
    height: 24px;
  }

  /* -----------------------------------------------------
     SIDEBAR - MOBILE DRAWER WITH SMOOTH ANIMATION
  ----------------------------------------------------- */

  .sidebar {
    position: fixed;
    top: 0;
    left: -280px;
    width: 280px;
    height: 100vh;
    background: linear-gradient(180deg, #7c3aed 0%, #6d28d9 100%);
    z-index: 2000;
    transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    box-shadow: 2px 0 10px rgba(0,0,0,0.2);
  }

  .sidebar.active {
    left: 0;
  }

  /* Sidebar overlay */
  .sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1999;
    display: none;
    opacity: 0;
    transition: opacity 0.3s ease;
  }

  .sidebar-overlay.active {
    display: block;
    opacity: 1;
  }

  /* -----------------------------------------------------
     BUTTONS - TOUCH OPTIMIZED
  ----------------------------------------------------- */

  .btn {
    min-height: 44px !important;
    padding: 12px 20px !important;
    font-size: 1rem !important;
    touch-action: manipulation;
  }

  .btn-sm {
    min-height: 36px !important;
    padding: 8px 16px !important;
    font-size: 0.875rem !important;
  }

  .btn-icon {
    min-width: 44px !important;
    min-height: 44px !important;
    padding: 10px !important;
  }

  /* -----------------------------------------------------
     FORMS - MOBILE FRIENDLY
  ----------------------------------------------------- */

  .form-input,
  .form-select,
  textarea {
    min-height: 44px !important;
    font-size: 16px !important; /* Prevents zoom on iOS */
    padding: 12px 16px !important;
    border-radius: 8px !important;
  }

  .form-label {
    font-size: 0.875rem !important;
    margin-bottom: 6px !important;
    font-weight: 500 !important;
  }

  .form-group {
    margin-bottom: 16px !important;
  }

  .form-row {
    display: block !important;
    gap: 0 !important;
  }

  .form-row .form-group {
    width: 100% !important;
  }

  /* -----------------------------------------------------
     TABLES - RESPONSIVE CARDS ON MOBILE
  ----------------------------------------------------- */

  .data-table,
  .service-table,
  .reminder-table {
    display: block !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch !important;
  }

  .data-table thead {
    display: none !important;
  }

  .data-table tbody,
  .data-table tr {
    display: block !important;
    width: 100% !important;
  }

  .data-table tr {
    margin-bottom: 16px !important;
    background: #ffffff !important;
    border-radius: 12px !important;
    padding: 16px !important;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08) !important;
  }

  .data-table td {
    display: flex !important;
    justify-content: space-between !important;
    align-items: center !important;
    padding: 10px 0 !important;
    border: none !important;
    border-bottom: 1px solid #f3f4f6 !important;
  }

  .data-table td:last-child {
    border-bottom: none !important;
  }

  .data-table td::before {
    content: attr(data-label);
    font-weight: 600;
    color: #6b7280;
    font-size: 0.75rem;
    text-transform: uppercase;
  }

  /* -----------------------------------------------------
     MODALS - FULL SCREEN ON MOBILE
  ----------------------------------------------------- */

  .modal {
    width: 100% !important;
    max-width: 100% !important;
    height: 100vh !important;
    max-height: 100vh !important;
    margin: 0 !important;
    border-radius: 0 !important;
    overflow-y: auto !important;
  }

  .modal-header {
    position: sticky !important;
    top: 0 !important;
    background: #ffffff !important;
    z-index: 10 !important;
    padding: 16px !important;
    border-bottom: 1px solid #e5e7eb !important;
  }

  .modal-body {
    padding: 20px 16px !important;
  }

  .modal-footer {
    position: sticky !important;
    bottom: 0 !important;
    background: #ffffff !important;
    padding: 16px !important;
    border-top: 1px solid #e5e7eb !important;
    display: flex !important;
    gap: 12px !important;
  }

  .modal-footer .btn {
    flex: 1 !important;
  }

  /* -----------------------------------------------------
     CARDS - OPTIMIZED SPACING
  ----------------------------------------------------- */

  .glass-card {
    padding: 16px !important;
    margin-bottom: 16px !important;
    border-radius: 12px !important;
  }

  .stat-card-new {
    padding: 16px !important;
    flex-direction: row !important;
    gap: 12px !important;
  }

  .stat-icon-circle {
    width: 48px !important;
    height: 48px !important;
    flex-shrink: 0 !important;
  }

  .stat-info h3 {
    font-size: 0.75rem !important;
  }

  .stat-info p {
    font-size: 1.5rem !important;
  }

  /* -----------------------------------------------------
     NAVIGATION - TOUCH FRIENDLY
  ----------------------------------------------------- */

  .nav-item {
    min-height: 48px !important;
    padding: 12px 16px !important;
    font-size: 1rem !important;
    display: flex !important;
    align-items: center !important;
    gap: 12px !important;
  }

  .nav-item svg {
    width: 20px !important;
    height: 20px !important;
    flex-shrink: 0 !important;
  }

  /* -----------------------------------------------------
     ACTION BUTTONS - LARGER TOUCH TARGETS
  ----------------------------------------------------- */

  .action-buttons {
    display: flex !important;
    gap: 8px !important;
    flex-wrap: wrap !important;
  }

  .action-buttons .btn {
    flex: 1 !important;
    min-width: 100px !important;
  }

  /* -----------------------------------------------------
     QUICK ACTIONS - STACKED ON MOBILE
  ----------------------------------------------------- */

  .quick-actions-grid {
    display: grid !important;
    grid-template-columns: 1fr !important;
    gap: 12px !important;
  }

  .quick-action-btn {
    width: 100% !important;
    justify-content: center !important;
  }

  /* -----------------------------------------------------
     CHARTS - RESPONSIVE
  ----------------------------------------------------- */

  .chart-card {
    padding: 16px !important;
    margin-bottom: 16px !important;
  }

  .chart-card canvas {
    max-height: 250px !important;
  }

  /* -----------------------------------------------------
     STATUS BADGES - READABLE SIZE
  ----------------------------------------------------- */

  .status-badge {
    font-size: 0.75rem !important;
    padding: 6px 12px !important;
    white-space: nowrap !important;
  }

  /* -----------------------------------------------------
     TYPOGRAPHY - MOBILE OPTIMIZED
  ----------------------------------------------------- */

  h1 { font-size: 1.5rem !important; }
  h2 { font-size: 1.25rem !important; }
  h3 { font-size: 1.125rem !important; }
  h4 { font-size: 1rem !important; }
  h5 { font-size: 0.875rem !important; }
  h6 { font-size: 0.75rem !important; }

  /* -----------------------------------------------------
     SPACING - CONSISTENT & CLEAN
  ----------------------------------------------------- */

  .content-area > * + * {
    margin-top: 16px !important;
  }

  /* -----------------------------------------------------
     FOOTER - STICKY ON MOBILE
  ----------------------------------------------------- */

  .sidebar-footer {
    position: sticky !important;
    bottom: 0 !important;
    background: rgba(109, 40, 217, 0.95) !important;
    padding: 16px !important;
    border-top: 1px solid rgba(255,255,255,0.1) !important;
  }

  /* -----------------------------------------------------
     ACCESSIBILITY - BETTER FOCUS STATES
  ----------------------------------------------------- */

  button:focus,
  input:focus,
  select:focus,
  textarea:focus {
    outline: 2px solid #7c3aed !important;
    outline-offset: 2px !important;
  }

  /* -----------------------------------------------------
     PERFORMANCE - REDUCE ANIMATIONS ON MOBILE
  ----------------------------------------------------- */

  @media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
      animation-duration: 0.01ms !important;
      animation-iteration-count: 1 !important;
      transition-duration: 0.01ms !important;
    }
  }

  /* -----------------------------------------------------
     UTILITIES - MOBILE HELPERS
  ----------------------------------------------------- */

  .mobile-hide {
    display: none !important;
  }

  .mobile-show {
    display: block !important;
  }

  .mobile-full-width {
    width: 100% !important;
  }

  /* -----------------------------------------------------
     LOADING STATES - BETTER UX
  ----------------------------------------------------- */

  .loading {
    pointer-events: none !important;
    opacity: 0.6 !important;
  }

  .loading::after {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    margin: -10px 0 0 -10px;
    border: 2px solid #7c3aed;
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
  }

  @keyframes spin {
    to { transform: rotate(360deg); }
  }
}

/* =====================================================
   TABLET (768px - 1024px)
===================================================== */

@media (min-width: 769px) and (max-width: 1024px) {
  .main-content {
    padding-left: 0 !important;
  }

  .sidebar {
    width: 240px;
  }

  .content-area {
    padding: 24px !important;
  }

  .form-row {
    grid-template-columns: 1fr 1fr !important;
  }
}
