/* ============================================================
   MOBILE RESPONSIVE LAYER (Al Kayan CRM)
   Loaded on every dashboard page. Desktop is untouched —
   every rule below is inside a media query.
   Breakpoints: 1024px (tablet-landscape/small laptop),
                768px (tablet-portrait/large phone),
                480px (small phone)
   ============================================================ */

/* --- Global overflow guard (no horizontal scroll) ---------- */
html, body {
  overflow-x: hidden;
}

/* --- Touch target baseline --------------------------------- */
@media (max-width: 768px) {
  .nav-item,
  .btn,
  .btn-primary,
  .btn-secondary,
  .btn-ghost,
  .pm-action-btn,
  .header-btn,
  .toggle-btn,
  .theme-toggle,
  .hamburger,
  .period-btn,
  .task-action-btn,
  .filter-group select,
  .search-box input,
  input[type="text"],
  input[type="email"],
  input[type="tel"],
  input[type="date"],
  input[type="number"],
  input[type="search"],
  select,
  textarea,
  .form-group input,
  .form-group select,
  .form-group textarea {
    min-height: 44px;
  }

  .btn,
  .btn-primary,
  .btn-secondary,
  .btn-ghost {
    padding-top: 12px;
    padding-bottom: 12px;
  }
}

/* --- Header responsive ------------------------------------- */
@media (max-width: 768px) {
  .dashboard-header {
    flex-wrap: wrap;
    gap: 12px;
  }

  .header-right {
    flex-wrap: wrap;
    gap: 8px;
  }

  .header-right .toggle-btn,
  .header-right .theme-toggle {
    padding: 8px 12px;
  }
}

@media (max-width: 480px) {
  .header-left h1 {
    font-size: 18px;
    line-height: 1.3;
  }

  .header-left .welcome-text {
    font-size: 12px;
  }
}

/* --- Generic toolbar wrapping ------------------------------ */
@media (max-width: 768px) {
  .customers-toolbar,
  .tasks-toolbar,
  .goals-toolbar,
  .schedule-toolbar,
  .toolbar-left,
  .toolbar-right,
  .pm-toolbar {
    flex-wrap: wrap;
  }

  .toolbar-left,
  .toolbar-right {
    width: 100%;
    justify-content: flex-start;
  }

  .search-box {
    width: 100%;
    max-width: none;
  }

  .search-box input {
    width: 100%;
  }

  .filter-group {
    min-width: 0;
  }

  .filter-group select {
    width: 100%;
  }
}

/* --- Modals fit the viewport (bottom-sheet feel) ----------- */
@media (max-width: 768px) {
  .modal-overlay {
    padding: 10px;
    align-items: flex-end;
  }

  .modal-premium,
  .modal-container,
  .modal-box,
  .modal-content {
    max-width: 100% !important;
    width: 100%;
    max-height: 92vh;
    border-radius: 16px 16px 0 0;
    margin: 0;
  }

  .modal-premium,
  .modal-container,
  .modal-box,
  .modal-content {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
}

/* --- Tables scroll inside their card (no page h-scroll) ---- */
@media (max-width: 768px) {
  .pm-card,
  .employee-performance-table,
  .users-table-wrap,
  .report-card-body,
  .table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .pm-table,
  .users-table,
  .reports-table,
  .employee-performance-table {
    min-width: 560px;
  }
}

/* --- Bottom navigation (mobile only) ----------------------- */
.mobile-bottom-nav {
  display: none;
}

@media (max-width: 768px) {
  .mobile-bottom-nav {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 90;
    background: var(--bg-card);
    border-top: 1px solid var(--border-color);
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.12);
    padding: 4px 6px calc(4px + env(safe-area-inset-bottom, 0px));
    backdrop-filter: blur(12px);
  }

  .mobile-bottom-nav .mnav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    padding: 8px 4px;
    border-radius: 12px;
    color: var(--text-muted);
    font-size: 11px;
    font-weight: 500;
    cursor: pointer;
    background: transparent;
    border: none;
    min-height: 48px;
    transition: color 0.2s, background 0.2s;
  }

  .mobile-bottom-nav .mnav-item .mnav-icon {
    font-size: 20px;
    line-height: 1;
  }

  .mobile-bottom-nav .mnav-item.active {
    color: var(--gold);
    background: rgba(201, 168, 76, 0.12);
  }

  .mobile-bottom-nav .mnav-item:active {
    background: rgba(201, 168, 76, 0.2);
  }

  /* Keep content clear of the fixed bottom nav */
  .main-content {
    padding-bottom: calc(76px + env(safe-area-inset-bottom, 0px));
  }
}

/* --- Card / grid stacking ---------------------------------- */
@media (max-width: 768px) {
  .customers-grid {
    grid-template-columns: 1fr 1fr;
  }

  .goals-grid,
  .tasks-grid {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 480px) {
  .customers-grid,
  .goals-grid,
  .tasks-grid {
    grid-template-columns: 1fr;
  }

  .stat-card {
    padding: 14px 16px;
    gap: 12px;
  }

  .stat-number {
    font-size: 18px;
  }
}

/* --- Schedule grids: horizontal scroll on phones ----------- */
@media (max-width: 768px) {
  .weekly-schedule-grid,
  .weekly-schedule-grid-employee {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .schedule-header,
  .schedule-days,
  .schedule-header-employee,
  .schedule-days-employee {
    min-width: 840px;
  }
}

/* --- Performance dashboard grids --------------------------- */
@media (max-width: 1024px) {
  .statistics-grid {
    grid-template-columns: repeat(3, 1fr);
  }

  .charts-section {
    grid-template-columns: 1fr;
  }

  .goal-completion-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 768px) {
  .statistics-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 480px) {
  .statistics-grid {
    grid-template-columns: 1fr;
  }

  .goal-completion-grid {
    grid-template-columns: 1fr;
  }

  .table-header {
    min-width: 640px;
  }
}

/* --- Employee schedule overview cards ---------------------- */
@media (max-width: 1024px) {
  .weekly-overview,
  .stats-grid-employee {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 480px) {
  .weekly-overview,
  .stats-grid-employee {
    grid-template-columns: 1fr;
  }
}

/* --- Form rows -> stacked on phones ------------------------ */
@media (max-width: 480px) {
  .form-row,
  .pm-form-row {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }

  .form-actions {
    flex-direction: column-reverse;
    width: 100%;
  }

  .form-actions .btn-primary,
  .form-actions .btn-secondary,
  .form-actions button {
    width: 100%;
  }
}

/* --- Content padding tightening ---------------------------- */
@media (max-width: 480px) {
  .main-content {
    padding-left: 12px;
    padding-right: 12px;
  }

  .weekly-schedule-content,
  .admin-goals-content,
  .performance-dashboard-content,
  .employee-goals-dashboard,
  .employee-weekly-schedule-content,
  .employee-tasks-dashboard {
    padding: 12px;
  }
}

/* --- Touch target polish for secondary actions (audit L1-L4) */
@media (max-width: 768px) {
  .card-action-btn,
  .pay-row-btn,
  .program-action-btn,
  .campaign-detail-btn,
  .action-btn,
  .pm-action-btn {
    min-width: 40px;
    min-height: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px 12px;
  }

  .period-btn {
    min-height: 40px;
    padding: 10px 16px;
  }

  .modal-close,
  .modal-header .modal-close,
  .modal-close-btn,
  .modal-premium-close {
    min-width: 32px;
    min-height: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 4px;
  }
}

@media (max-width: 480px) {
  .toggle-btn,
  .theme-toggle,
  .header-btn {
    min-height: 40px;
    padding: 8px 12px;
  }
}