/* Mobile compatibility layer - desktop styles remain untouched. */
@media (max-width: 768px) {
  html, body { width: 100%; max-width: 100%; overflow-x: hidden; }
  body { min-width: 0 !important; }
  img, video, canvas, svg { max-width: 100%; height: auto; }
  iframe { max-width: 100%; }
  input, select, textarea, button { max-width: 100%; }
  input, select, textarea { font-size: 16px; }

  .app-shell, .layout { display: block !important; width: 100% !important; }
  .sidebar {
    position: relative !important;
    inset: auto !important;
    width: 100% !important;
    height: auto !important;
    max-height: none !important;
    overflow: visible !important;
  }
  .sidebar.collapsed { width: 100% !important; }
  .sidebar.collapsed .sidebar-title,
  .sidebar.collapsed .nav-section-title,
  .sidebar.collapsed .nav-item span,
  .sidebar.collapsed .sidebar-footer { display: initial !important; }
  .sidebar.collapsed .sidebar-header { justify-content: initial !important; }
  .sidebar.collapsed .nav-item { justify-content: flex-start !important; padding-inline: 14px !important; }

  .main,
  .sidebar.collapsed + .main,
  .sidebar.collapsed ~ .main {
    margin-left: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
  }

  .topbar, header { position: relative !important; top: auto !important; }
  .topbar-inner, .topbar-right, .header-content, .toolbar {
    flex-wrap: wrap !important;
    width: 100% !important;
  }
  .topbar-inner { align-items: stretch !important; }
  .topbar-right { justify-content: flex-start !important; }
  .search-box, .search-box input { width: 100% !important; min-width: 0 !important; }

  .content, main { width: 100% !important; max-width: 100% !important; padding-left: 12px !important; padding-right: 12px !important; }
  .top-banner { width: 100% !important; max-width: 100% !important; }

  .table-shell, .table-wrap, .table-wrapper, .table-container, .responsive-table {
    width: 100% !important;
    max-width: 100% !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
  }
  table { max-width: none; }

  .incident-details, .details-grid, .form-grid, .settings-grid, .profile-grid {
    grid-template-columns: minmax(0, 1fr) !important;
  }

  .filter-tabs { flex-wrap: nowrap !important; overflow-x: auto !important; padding-bottom: 4px; -webkit-overflow-scrolling: touch; }
  .filter-tab { flex: 0 0 auto; }

  .modal-backdrop { padding: 10px !important; align-items: flex-start !important; overflow-y: auto !important; }
  .modal-dialog, .modal-dialog.wide {
    width: 100% !important;
    max-width: 100% !important;
    max-height: calc(100dvh - 20px) !important;
    padding: 20px 16px !important;
    border-radius: 18px !important;
  }
  .modal-title { padding-right: 42px !important; }
  .modal-actions, .wizard-actions { gap: 8px !important; }
  .modal-actions > *, .wizard-actions > * { min-height: 44px; }

  footer {
    position: relative !important;
    left: auto !important;
    right: auto !important;
    bottom: auto !important;
    width: 100% !important;
  }

  .action-card { height: auto !important; min-height: 300px; }
  .stats, .summary-grid, .cards-grid { grid-template-columns: minmax(0, 1fr) !important; }
}

@media (max-width: 480px) {
  .content, main { padding-left: 10px !important; padding-right: 10px !important; }
  .topbar-inner { margin-left: 8px !important; margin-right: 8px !important; }
  .user-chip { max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
  .btn-primary-sm, .btn-ghost, .modal-btn { min-height: 44px; }
  .page-title { font-size: 1.15rem !important; }
  .page-subtitle { line-height: 1.4; }
}

/* Mobile navigation drawer. Desktop is intentionally untouched. */
@media (max-width: 768px) {
  body { font-size: 13.5px !important; }
  p, li, td, th, label, .page-subtitle, .card, .stat-card, .info-card { font-size: 0.94em; }
  h1, .page-title { font-size: 1.18rem !important; }
  h2 { font-size: 1.05rem !important; }
  h3 { font-size: 0.98rem !important; }

  .sidebar {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    bottom: 0 !important;
    width: min(86vw, 320px) !important;
    height: 100dvh !important;
    max-height: 100dvh !important;
    overflow-y: auto !important;
    z-index: 10020 !important;
    transform: translateX(-105%) !important;
    transition: transform .22s ease !important;
    box-shadow: 10px 0 30px rgba(0,0,0,.18) !important;
  }
  .sidebar.mobile-open { transform: translateX(0) !important; }
  .sidebar.collapsed { width: min(86vw, 320px) !important; }
  .sidebar-nav .nav-item, .sidebar .nav-item {
    font-size: 13px !important;
    min-height: 40px !important;
  }
  .sidebar .nav-label, .sidebar .nav-section-label,
  .sidebar .nav-section-title, .sidebar-footer {
    font-size: 12.5px !important;
  }
  .sidebar-header img { max-height: 54px !important; }

  .mobile-menu-trigger {
    position: fixed;
    top: 10px;
    left: 10px;
    z-index: 10030;
    min-width: 44px;
    height: 42px;
    padding: 0 12px;
    border: 0;
    border-radius: 12px;
    background: #111827;
    color: #fff;
    font: inherit;
    font-size: 13px;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    box-shadow: 0 5px 18px rgba(0,0,0,.22);
    cursor: pointer;
  }
  .mobile-menu-trigger .bars { font-size: 18px; line-height: 1; }
  .mobile-menu-overlay {
    position: fixed;
    inset: 0;
    z-index: 10010;
    background: rgba(15,23,42,.44);
    opacity: 0;
    visibility: hidden;
    transition: opacity .2s ease, visibility .2s ease;
  }
  .mobile-menu-overlay.visible { opacity: 1; visibility: visible; }
  body.mobile-menu-open { overflow: hidden !important; }

  /* Make room for the mobile menu button without changing desktop layout. */
  .main { padding-top: 58px !important; }
  .topbar, header { padding-left: 54px !important; }

  /* Keep form controls legible and avoid iOS input zoom. */
  input, select, textarea { font-size: 16px !important; }
  button, .btn, a.nav-item { font-size: 13px; }
}

@media (max-width: 480px) {
  body { font-size: 13px !important; }
  .sidebar { width: min(90vw, 300px) !important; }
  .sidebar.collapsed { width: min(90vw, 300px) !important; }
  .mobile-menu-trigger { height: 40px; padding: 0 10px; font-size: 12.5px; }
  .sidebar-nav .nav-item, .sidebar .nav-item { font-size: 12.5px !important; }
}
