/* ══════════════════════════════════════════════════════════════
 * styles/mobile.css — PROMPT-07 Phase 5 (2026-04-17)
 * Mobile responsive overrides for The Doctor Agency ERP.
 *
 * Breakpoints:
 *   ≤ 768px  — sidebar collapses to off-canvas drawer
 *   ≤ 480px  — dense layouts, stack grids
 *   ≤ 375px  — small phone safe rules (text wrapping, min button size)
 *
 * Accessibility:
 *   - All interactive targets ≥ 44×44 px on touch devices
 *   - Form inputs ≥ 16px font-size so iOS does NOT auto-zoom
 *   - Focus outlines preserved
 *
 * Non-destructive: loaded AFTER luxury.css and inline <style> in index.html,
 * overrides via specificity + !important only where necessary to beat inline
 * styles produced by the SPA shell.
 * ══════════════════════════════════════════════════════════════ */

/* ───── Utility: body scroll lock while mobile menu open ───── */
body.is-mobile-menu-open {
  overflow: hidden;
  touch-action: none;
}

/* ───── Hamburger button (auto-injected into .header by keyboard-nav.js) ───── */
.mobile-menu-toggle {
  display: none; /* Hidden on desktop, shown at ≤768px via media query */
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  min-width: 44px;
  background: transparent;
  border: 1px solid rgba(245, 158, 11, 0.4);
  border-radius: 8px;
  color: #F59E0B;
  cursor: pointer;
  font-size: 20px;
  line-height: 1;
  padding: 0;
  margin-inline-end: 8px;
  transition: background 0.15s, color 0.15s, transform 0.15s;
}

.mobile-menu-toggle:hover,
.mobile-menu-toggle:focus-visible {
  background: rgba(245, 158, 11, 0.12);
  outline: none;
  color: #FBBF24;
}

.mobile-menu-toggle:active { transform: scale(0.97); }

/* ───── Overlay backdrop while sidebar is open on mobile ───── */
.mobile-sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(2px);
  z-index: 998;
  opacity: 0;
  transition: opacity 0.2s ease;
}

body.is-mobile-menu-open .mobile-sidebar-backdrop {
  display: block;
  opacity: 1;
}

/* ═══════════════ ≤ 768 px — phones/phablets ═══════════════ */
@media (max-width: 768px) {
  /* Show hamburger */
  .mobile-menu-toggle { display: inline-flex; }

  /* Sidebar → off-canvas drawer */
  .sidebar {
    position: fixed !important;
    top: 0;
    right: 0;       /* RTL app: drawer slides from right */
    height: 100vh;
    width: min(280px, 84vw) !important;
    z-index: 999;
    transform: translateX(100%);   /* hidden by default (off-screen to right) */
    transition: transform 0.25s ease;
    box-shadow: -4px 0 18px rgba(0, 0, 0, 0.45);
    overflow-y: auto;
    padding-bottom: 24px;
  }

  body.is-mobile-menu-open .sidebar {
    transform: translateX(0);
  }

  /* Main content takes full width — sidebar is overlay, not flow */
  .main-content {
    width: 100% !important;
    flex: 1 1 100% !important;
  }

  /* Header: tighter padding, wrap actions */
  .header {
    padding: 10px 12px !important;
    flex-wrap: wrap;
    gap: 6px;
  }

  .header-title {
    font-size: 15px !important;
    flex: 1 1 auto;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .header-actions {
    display: flex;
    align-items: center;
    gap: 4px;
  }

  /* Touch-friendly sizing */
  button,
  .btn,
  .btn-primary,
  .btn-secondary,
  .nav-item,
  .logout-btn,
  a[role="button"] {
    min-height: 44px;
  }

  /* Prevent iOS Safari auto-zoom on input focus */
  input,
  select,
  textarea {
    font-size: 16px !important;
  }

  /* Content area gets less padding */
  .content-area { padding: 12px !important; }

  /* Tables: horizontal scroll instead of clipping */
  .content-area table,
  .card table,
  .page-section table {
    display: block;
    overflow-x: auto;
    white-space: nowrap;
    -webkit-overflow-scrolling: touch;
    max-width: 100%;
  }

  /* Modal sizing */
  .modal-container,
  .modal-content {
    width: calc(100% - 24px) !important;
    max-width: calc(100% - 24px) !important;
    max-height: calc(100vh - 24px) !important;
    margin: 12px !important;
  }

  /* Breadcrumbs slim down */
  #breadcrumbsBar {
    padding: 6px 12px !important;
    font-size: 12px !important;
  }

  /* Stats grids: single column */
  .stats-grid,
  .grid-3,
  .grid-4,
  .grid-cols-3,
  .grid-cols-4 {
    grid-template-columns: 1fr !important;
    gap: 10px !important;
  }
}

/* ═══════════════ ≤ 480 px — small phones ═══════════════ */
@media (max-width: 480px) {
  .header-title { font-size: 14px !important; }
  .user-badge { display: none !important; }   /* reclaim space */

  /* Sidebar drawer takes more of screen on small phones */
  .sidebar { width: min(260px, 88vw) !important; }

  /* Card padding */
  .card,
  .widget,
  .dashboard-card { padding: 12px !important; }

  /* Font scaling for dense widgets */
  .stat-value   { font-size: 20px !important; }
  .stat-label   { font-size: 11px !important; }

  /* Form controls full-width */
  .form-row,
  .form-group {
    flex-direction: column !important;
    align-items: stretch !important;
  }
}

/* ═══════════════ ≤ 375 px — iPhone SE & smaller ═══════════════ */
@media (max-width: 375px) {
  .header { padding: 8px 10px !important; }
  .header-title { font-size: 13px !important; }

  /* Allow long Arabic labels to wrap */
  .nav-item,
  .breadcrumbs-item { white-space: normal !important; }

  /* Emoji buttons (bell, language toggle) stay compact but still ≥44px */
  #bellBtn,
  #langToggleBtn {
    padding: 4px 6px !important;
    min-width: 36px;
  }

  /* Error dialogs never exceed viewport */
  .modal-container,
  .modal-content { max-height: calc(100vh - 16px) !important; }
}

/* ═══════════════ Reduced motion respect ═══════════════ */
@media (prefers-reduced-motion: reduce) {
  .sidebar,
  .mobile-sidebar-backdrop,
  .mobile-menu-toggle { transition: none !important; }
}

/* ═══════════════ High-contrast focus rings for accessibility ═══════════════ */
@media (max-width: 768px) {
  button:focus-visible,
  a:focus-visible,
  input:focus-visible,
  select:focus-visible,
  textarea:focus-visible,
  [tabindex="0"]:focus-visible {
    outline: 2px solid #F59E0B !important;
    outline-offset: 2px !important;
  }
}
