/* ════════════════════════════════════════════════════════════════════
 * styles/mobile-fixes.css — BUNDLE #2 (2026-04-19)
 *
 * Emergency mobile UX fixes documented from Dr. David's screenshots.
 * Loaded AFTER styles/mobile.css → wins via cascade order + specificity.
 * Non-destructive: every rule scoped inside @media (max-width: 768px)
 * unless explicitly noted. Desktop UI completely untouched.
 *
 * Issues addressed (mapping to user-reported screenshots):
 *   #1  Tab labels stacking character-by-character (Media Buying / Settings)
 *   #2  Severe text truncation in dropdowns ("جميع" → "جم")
 *   #3  Calendar horizontal overflow (Saturday cut off)
 *   #4  Email char-stacking in user tables
 *   #5  Multi-word tab chaos (Finance / Sales)
 *   #6  Media Buying page unusable on mobile
 *   #7  Visible horizontal scrollbar on body
 *   #8  Settings → Users column misalignment
 *
 * Plus PWA install-prompt component styling.
 * ════════════════════════════════════════════════════════════════════ */

/* ───── PWA install prompt banner (visible on all viewports) ───── */
.install-prompt-banner {
  position: fixed;
  bottom: 16px;
  left: 16px;
  right: 16px;
  background: linear-gradient(135deg, #F59E0B, #D97706);
  color: #000;
  padding: 12px 16px;
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  z-index: 10000;
  animation: tdaInstallSlideUp 0.4s ease-out;
  max-width: 480px;
  margin-left: auto;
  margin-right: auto;
}

.install-prompt-content {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  direction: rtl;
}

.install-prompt-content > span {
  flex: 1 1 auto;
  font-weight: 600;
  font-size: 14px;
  line-height: 1.4;
  min-width: 180px;
}

.install-prompt-banner button {
  padding: 8px 16px;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 700;
  font-size: 13px;
  min-height: 36px;
  white-space: nowrap;
}

.install-prompt-banner .btn-install {
  background: #000;
  color: #F59E0B;
}

.install-prompt-banner .btn-install:hover {
  background: #1a1a1a;
}

.install-prompt-banner .btn-dismiss {
  background: rgba(0, 0, 0, 0.18);
  color: #000;
}

.install-prompt-banner .btn-dismiss:hover {
  background: rgba(0, 0, 0, 0.30);
}

@keyframes tdaInstallSlideUp {
  from { transform: translateY(120%); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

/* ════════════════════════════════════════════════════════════════════
 * ≤ 768 px — phones / phablets (BIG WIN ZONE)
 * ════════════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {

  /* ─── FIX #7 (foundational): kill body horizontal scroll ─── */
  html, body {
    overflow-x: hidden !important;
    max-width: 100vw !important;
  }

  /* Page-level wrappers stay within the viewport */
  .content-area,
  .page-container,
  main {
    max-width: 100% !important;
    overflow-x: hidden;
    box-sizing: border-box;
  }

  /* ─── FIX #1, #5, #6: tab labels never stack character-by-character ─── */
  .tab-btn,
  .tab-label,
  [role="tab"],
  .nav-tab,
  .module-tab,
  .dashboard-tab,
  .sales-tab-btn,
  .finance-tab-btn,
  .mb-tab-btn {
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    flex: 0 0 auto !important;
    min-width: 0 !important;
    max-width: 70vw !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    writing-mode: horizontal-tb !important;
    word-break: keep-all !important;
    line-break: strict !important;
  }

  /* Containers that hold the tabs → horizontal scroll, no wrap */
  .tabs-container,
  .nav-tabs,
  .tab-bar,
  [role="tablist"] {
    display: flex !important;
    flex-wrap: nowrap !important;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    -webkit-overflow-scrolling: touch !important;
    scrollbar-width: thin !important;
    gap: 8px !important;
    padding-bottom: 8px !important;
  }

  /* Specific to inline-styled flex tab rows used in pages */
  div[style*="display:flex"][style*="overflow-x"] > .tab-btn,
  div[style*="display: flex"][style*="overflow-x"] > .tab-btn {
    white-space: nowrap !important;
    flex: 0 0 auto !important;
  }

  /* ─── FIX #2: dropdowns / selects — full text, no truncation ─── */
  select,
  .select-input,
  .filter-dropdown,
  .form-input[id*="Filter"],
  .form-input[id*="filter"] {
    min-width: 110px !important;
    padding: 8px 12px !important;
    text-overflow: ellipsis !important;
    white-space: nowrap !important;
    font-size: 14px !important;
    height: auto !important;
  }

  /* The tiny filter selects in lists ("الكل", "جميع التخصصات", etc.) */
  select.form-input {
    min-width: 130px !important;
    max-width: 100% !important;
  }

  /* ─── FIX #4, #8: tables — emails + long text never char-stack ─── */
  table td,
  table th,
  .table-cell,
  .data-cell {
    word-break: normal !important;
    overflow-wrap: anywhere !important;
    white-space: normal !important;
    max-width: 220px;
  }

  /* Email-bearing cells — wrap at @ and . marks, never char-by-char */
  td.user-email,
  td.email,
  td[data-type="email"],
  td:has(> a[href^="mailto:"]) {
    word-break: break-word !important;
    overflow-wrap: break-word !important;
    font-size: 12px !important;
    line-height: 1.4 !important;
    min-width: 140px !important;
  }

  /* Generic protection: any cell that contains an @ in its text */
  table td a[href^="mailto:"] {
    word-break: break-word !important;
    overflow-wrap: anywhere !important;
    display: inline-block;
    max-width: 100%;
  }

  /* ─── FIX #3: Calendar — all 7 days fit, no Saturday cut-off ─── */
  .calendar-grid,
  .calendar-month-view,
  .month-grid,
  div[class*="calendar"][style*="grid-template-columns"] {
    display: grid !important;
    grid-template-columns: repeat(7, minmax(0, 1fr)) !important;
    gap: 2px !important;
    width: 100% !important;
    max-width: 100% !important;
    overflow-x: hidden !important;
    box-sizing: border-box;
  }

  .calendar-day-cell,
  .calendar-cell,
  .cal-day {
    min-width: 0 !important;
    width: 100% !important;
    padding: 4px !important;
    font-size: 11px !important;
    overflow: hidden;
    box-sizing: border-box;
  }

  .calendar-day-cell .day-number,
  .calendar-cell .day-number {
    font-size: 13px !important;
    font-weight: 600;
  }

  .calendar-day-cell .task-chip,
  .calendar-cell .task-chip,
  .calendar-day-cell .event-chip {
    font-size: 10px !important;
    padding: 2px 4px !important;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
  }

  /* Weekday headers (الأحد، الإثنين…) — short labels prevent overflow */
  .calendar-weekday,
  .month-header > * {
    font-size: 10px !important;
    text-align: center !important;
    padding: 4px 0 !important;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  /* ─── FIX #8 (reinforced): Settings Users table column alignment ─── */
  #usersTable table,
  table.users-table,
  .settings-users-table {
    width: 100% !important;
    table-layout: auto !important;
  }

  #usersTable td,
  table.users-table td,
  .settings-users-table td {
    padding: 8px 6px !important;
    font-size: 12px !important;
    vertical-align: middle;
  }

  /* ─── Modal responsiveness reinforcement (Task 4.7 baseline + extra) ─── */
  .modal-overlay {
    padding: 8px !important;
  }

  .modal-box,
  .modal-container {
    width: calc(100% - 16px) !important;
    max-width: calc(100% - 16px) !important;
    max-height: 92vh !important;
    overflow-y: auto !important;
    margin: 8px !important;
  }

  .modal-footer,
  .modal-actions {
    flex-direction: column-reverse !important;
    gap: 8px !important;
  }

  .modal-footer button,
  .modal-actions button,
  .modal-footer .btn,
  .modal-actions .btn {
    width: 100% !important;
    min-height: 44px !important;
  }

  /* ─── Touch targets — 44 × 44 minimum (iOS HIG) ─── */
  button:not(.tab-btn):not(.toast-close):not(.modal-close-btn),
  .btn,
  [role="button"],
  a.btn {
    min-height: 44px !important;
    padding: 10px 16px !important;
  }

  /* Tighter for tab chips so 5+ tabs fit a single row */
  .tab-btn,
  .sales-tab-btn,
  .finance-tab-btn,
  .mb-tab-btn {
    min-height: 38px !important;
    padding: 8px 14px !important;
    font-size: 13px !important;
  }

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

  /* Cards / widgets stack to single column ≤ 768 */
  .stats-grid,
  .grid-3,
  .grid-4,
  .grid-cols-3,
  .grid-cols-4,
  .dashboard-grid,
  .widgets-grid {
    grid-template-columns: 1fr !important;
    gap: 12px !important;
  }

  /* Header / top-bar wraps without crushing children */
  .header,
  .top-bar {
    flex-wrap: wrap !important;
    gap: 6px !important;
  }

  .header > *,
  .top-bar > * {
    min-width: 0 !important;
    flex-shrink: 1 !important;
  }
}

/* ════════════════════════════════════════════════════════════════════
 * ≤ 480 px — small phones (Galaxy S22 / iPhone SE / 13 mini)
 * ════════════════════════════════════════════════════════════════════ */
@media (max-width: 480px) {

  .tab-btn,
  .sales-tab-btn,
  .finance-tab-btn,
  .mb-tab-btn {
    font-size: 12px !important;
    padding: 6px 10px !important;
    max-width: 50vw !important;
  }

  .calendar-day-cell {
    font-size: 10px !important;
    padding: 3px !important;
  }

  /* Filter dropdowns can compress slightly more */
  select.form-input {
    min-width: 110px !important;
    font-size: 13px !important;
  }
}

/* ════════════════════════════════════════════════════════════════════
 * ≤ 380 px — extra-small (vintage Android)
 * ════════════════════════════════════════════════════════════════════ */
@media (max-width: 380px) {

  .tab-btn {
    font-size: 11px !important;
    padding: 6px 8px !important;
  }

  /* Keep emoji visible even when text shrinks */
  .tab-btn::first-letter {
    font-size: 14px;
  }

  .calendar-day-cell {
    font-size: 9px !important;
  }

  /* Modals get more aggressive trimming */
  .modal-box,
  .modal-container {
    padding: 12px !important;
  }
}

/* ════════════════════════════════════════════════════════════════════
 * Landscape mobile — keep modals usable
 * ════════════════════════════════════════════════════════════════════ */
@media (max-width: 900px) and (orientation: landscape) {

  .modal-box,
  .modal-container {
    max-height: 86vh !important;
  }
}

/* ════════════════════════════════════════════════════════════════════
 * Reduced-motion respect — disable our slide-up animation
 * ════════════════════════════════════════════════════════════════════ */
@media (prefers-reduced-motion: reduce) {

  .install-prompt-banner {
    animation: none !important;
  }
}

/* ════════════════════════════════════════════════════════════════════
 * BUNDLE #2.1 HOTFIX — 2026-04-19 (emergency, post-Bundle-#2 review)
 * Targeted selectors for ACTUAL classes + inline-style patterns found
 * in pages/. Bundle #2 used .mb-tab-btn (wrong); real class is
 * .media-tab-btn. Tables use no class at all — only inline styles.
 * ════════════════════════════════════════════════════════════════════ */

@media (max-width: 768px) {

  /* ─── HOTFIX #1 — Media Buying tabs (real class) ─── */
  .media-tab-btn {
    white-space: nowrap !important;
    flex: 0 0 auto !important;
    min-width: -moz-fit-content !important;
    min-width: fit-content !important;
    padding: 10px 16px !important;
    font-size: 13px !important;
    writing-mode: horizontal-tb !important;
    word-break: keep-all !important;
    overflow-wrap: normal !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
  }

  /* Force horizontal flex (override flex-wrap:wrap on tab containers) */
  div[style*="flex-wrap:wrap"]:has(.media-tab-btn),
  div[style*="flex-wrap: wrap"]:has(.media-tab-btn),
  div[style*="display:flex"]:has(.media-tab-btn),
  div[style*="display: flex"]:has(.media-tab-btn) {
    flex-wrap: nowrap !important;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    -webkit-overflow-scrolling: touch !important;
  }

  /* Catch-all for any switchMediaTab onclick — defensive */
  [onclick*="switchMediaTab"],
  [onclick*="switchMBTab"] {
    white-space: nowrap !important;
    flex: 0 0 auto !important;
  }

  /* ─── HOTFIX #2 — Tables (Call Center + others, no classes) ─── */
  table th,
  table td {
    white-space: nowrap !important;
    padding: 8px 6px !important;
    min-width: 80px !important;
    font-size: 12px !important;
  }

  /* Generic fallback: tables that aren't already in .table-responsive
     wrapper should become horizontally scrollable themselves */
  table:not(.table-responsive-wrapped) {
    display: block !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch !important;
    max-width: 100% !important;
  }

  table:not(.table-responsive-wrapped) thead,
  table:not(.table-responsive-wrapped) tbody {
    display: table !important;
    width: -moz-max-content !important;
    width: max-content !important;
    min-width: 100% !important;
  }

  /* Exception: tables ALREADY in a .table-responsive wrapper keep
     normal table layout — wrapper already provides scroll */
  .table-responsive table,
  .table-wrapper table {
    display: table !important;
    overflow: visible !important;
  }

  /* ─── HOTFIX #3 — Settings code labels (role/permission ids) ─── */
  code,
  code[style],
  .role-code,
  .permission-code {
    font-family: 'Monaco', 'Menlo', 'Courier New', monospace !important;
    font-size: 11px !important;
    word-break: break-all !important;
    display: inline-block !important;
    max-width: 100% !important;
    background: rgba(255, 255, 255, 0.05) !important;
    padding: 2px 6px !important;
    border-radius: 4px !important;
    line-height: 1.5 !important;
  }

  /* ─── HOTFIX #4 — Empty state messages (no class, inline style) ─── */
  div[style*="text-align:center"][style*="color:#6B7280"],
  div[style*="text-align: center"][style*="color: #6B7280"],
  div[style*="text-align:center"][style*="color:#9CA3AF"],
  div[style*="text-align: center"][style*="color: #9CA3AF"],
  .empty-state,
  .no-data,
  .no-results,
  [class*="empty-state"],
  [class*="no-data"] {
    text-align: center !important;
    padding: 24px 16px !important;
    font-size: 14px !important;
    line-height: 1.8 !important;
    word-break: keep-all !important;
    overflow-wrap: break-word !important;
    width: 100% !important;
    max-width: 100% !important;
  }

  /* ─── HOTFIX #5 — All buttons NEVER stack chars vertically ─── */
  button:not(.modal-close-btn):not(.toast-close):not(.tab-close),
  .btn,
  [role="button"],
  a.button,
  .action-btn {
    white-space: nowrap !important;
    min-width: -moz-fit-content !important;
    min-width: fit-content !important;
    min-height: 36px !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    padding: 8px 16px !important;
  }

  /* Compact action buttons (view/edit/delete in tables) */
  .view-btn, .edit-btn, .delete-btn,
  button[onclick*="view"],
  button[onclick*="show"],
  button[onclick*="open"] {
    min-width: 60px !important;
    padding: 6px 12px !important;
    font-size: 12px !important;
  }

  /* ─── HOTFIX #6 — Tab containers — slim scrollbar visual ─── */
  .tabs-container::-webkit-scrollbar,
  [role="tablist"]::-webkit-scrollbar,
  div[style*="overflow-x:auto"]::-webkit-scrollbar,
  div[style*="overflow-x: auto"]::-webkit-scrollbar {
    height: 3px !important;
  }

  .tabs-container::-webkit-scrollbar-thumb,
  [role="tablist"]::-webkit-scrollbar-thumb,
  div[style*="overflow-x:auto"]::-webkit-scrollbar-thumb,
  div[style*="overflow-x: auto"]::-webkit-scrollbar-thumb {
    background: rgba(245, 158, 11, 0.30) !important;
    border-radius: 2px !important;
  }

  /* ─── HOTFIX #7 — English mid-word breaking (e.g. "strategy") ─── */
  p, span, div, td, label, li {
    word-break: keep-all !important;
    overflow-wrap: break-word !important;
  }

  /* But code identifiers MAY break to prevent layout overflow */
  code,
  .identifier,
  [data-type="code"] {
    word-break: break-all !important;
  }

  /* ─── HOTFIX #8 — Aggressive overflow prevention ─── */
  html {
    overflow-x: hidden !important;
    max-width: 100vw !important;
  }

  body {
    overflow-x: hidden !important;
    max-width: 100vw !important;
    position: relative !important;
  }

  /* Hunt every fixed-width offender */
  body * {
    max-width: 100vw !important;
    box-sizing: border-box !important;
  }

  /* Exceptions — elements that LEGITIMATELY may exceed viewport */
  body table,
  body .modal,
  body .modal-container,
  body .modal-box,
  body [role="dialog"],
  body .tabs-container,
  body [role="tablist"],
  body .scroll-container,
  body .dropdown-menu,
  body [role="menu"],
  body .tooltip,
  body .toast-container,
  body .install-prompt-banner,
  body video,
  body iframe,
  body canvas,
  body img,
  body [style*="overflow-x: auto"],
  body [style*="overflow-x:auto"] {
    max-width: none !important;
  }

  /* ─── BONUS — Flex container intelligence ─── */
  div[style*="display: flex"] > *,
  div[style*="display:flex"] > * {
    min-width: 0 !important;
  }

  /* But buttons/tabs in flex must keep content-width */
  div[style*="display: flex"] > button,
  div[style*="display:flex"] > button,
  div[style*="display: flex"] > .tab-btn,
  div[style*="display:flex"] > .tab-btn,
  div[style*="display: flex"] > .media-tab-btn,
  div[style*="display:flex"] > .media-tab-btn {
    min-width: -moz-fit-content !important;
    min-width: fit-content !important;
    flex-shrink: 0 !important;
  }
}

/* ════════════════════════════════════════════════════════════════════
 * Bundle #2.1 — extra-small phones (≤ 380 px) refinements
 * ════════════════════════════════════════════════════════════════════ */
@media (max-width: 380px) {

  .media-tab-btn,
  .tab-btn {
    padding: 8px 12px !important;
    font-size: 12px !important;
  }

  table th,
  table td {
    font-size: 11px !important;
    padding: 6px 4px !important;
    min-width: 60px !important;
  }

  button:not(.modal-close-btn):not(.toast-close),
  .btn {
    font-size: 12px !important;
    padding: 6px 10px !important;
  }
}

/* ════════════════════════════════════════════════════════════════════
 * BUNDLE #2.2 PHASE A — 6 MOBILE QUICK WINS (2026-04-19)
 * Derived from docs/mobile-audit-2026-04-19.md recommendations.
 * NO blocker pages touched (sales.js / settings.js / call-center.js /
 * finance.js deferred to Phase B rebuilds).
 * ════════════════════════════════════════════════════════════════════ */

@media (max-width: 768px) {

  /* ─── Quick Win 1 — Sales pipeline table containment ─── */
  /* Root cause: pages/sales.js:279 — <table min-width:1600px> forces
     the WHOLE BODY to scroll horizontally (4× viewport). Solution:
     make the table itself the scroll container — body stays within
     100vw, user swipes horizontally inside the table only. */
  .pipelineTable,
  table#pipelineTable,
  table[class*="pipeline"],
  table[id*="pipeline"] {
    display: block !important;
    overflow-x: auto !important;
    overflow-y: visible !important;
    -webkit-overflow-scrolling: touch !important;
    max-width: 100% !important;
    width: 100% !important;
  }

  /* Force the table's parent to stay within viewport width */
  div:has(> table#pipelineTable),
  div:has(> .pipelineTable),
  div:has(> table[class*="pipeline"]) {
    max-width: 100vw !important;
    overflow-x: hidden !important;
    position: relative !important;
  }

  /* Also containment for the 1000px Renewals table (sales.js:702) */
  table[style*="min-width:1000px"],
  table[style*="min-width: 1000px"] {
    display: block !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch !important;
    max-width: 100% !important;
  }

  /* ─── Quick Win 2 — Settings Permission Matrix mobile notice ─── */
  /* Root cause: 8-column sticky-column matrix designed for 1200+
     screens. Hide it on mobile + show a clear message pointing users
     to the desktop. */
  .permission-matrix,
  table.permissions-matrix,
  #permissionMatrixTable,
  table[id*="permMatrix"],
  [data-component="permission-matrix"] {
    display: none !important;
  }

  /* Helper container that pages (or our JS) can inject */
  .permission-matrix-mobile-notice {
    display: block !important;
    padding: 24px 16px !important;
    margin: 16px 0 !important;
    background: rgba(245, 158, 11, 0.10) !important;
    border: 1px solid rgba(245, 158, 11, 0.35) !important;
    border-radius: 12px !important;
    text-align: center !important;
    color: #F59E0B !important;
    line-height: 1.8 !important;
  }

  /* Settings 16-tab horizontal bar → slim scroll + cramped padding */
  .settings-tabs,
  [data-tabs="settings"] {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch !important;
    white-space: nowrap !important;
    padding: 8px 0 !important;
    scrollbar-width: thin !important;
  }

  .settings-tabs > *,
  [data-tabs="settings"] > * {
    display: inline-block !important;
    flex: 0 0 auto !important;
    min-width: -moz-fit-content !important;
    min-width: fit-content !important;
    white-space: nowrap !important;
    padding: 8px 12px !important;
    font-size: 13px !important;
  }

  /* ─── Quick Win 3 — Team org chart hidden on mobile ─── */
  /* Root cause: absolute-positioned SVG nodes + drag-drop = impossible
     on touch devices. Hide chart + show list fallback where present. */
  .team-chart,
  .org-chart,
  .hierarchy-tree,
  [data-chart="org"],
  #orgChartContainer,
  #hierarchyTree {
    display: none !important;
  }

  .team-mobile-list {
    display: block !important;
  }

  /* Inform the user why the chart disappeared */
  .team-chart-mobile-notice,
  .org-chart-mobile-notice {
    display: block !important;
    padding: 20px 16px !important;
    margin: 12px 0 !important;
    text-align: center !important;
    color: #9CA3AF !important;
    font-size: 13px !important;
    background: rgba(156, 163, 175, 0.05) !important;
    border: 1px dashed rgba(156, 163, 175, 0.25) !important;
    border-radius: 8px !important;
  }

  /* ─── Quick Win 4 — Dashboard charts responsive ─── */
  /* Root cause: Chart.js canvas + some inline width:600px. Force all
     chart containers to the viewport width, stack legends below. */
  .chart-container,
  .dashboard-chart,
  canvas[id*="chart"],
  canvas[id*="Chart"],
  [data-chart]:not([data-chart="org"]) {
    max-width: 100% !important;
    width: 100% !important;
    height: auto !important;
    min-height: 200px !important;
  }

  canvas {
    max-width: 100% !important;
    height: auto !important;
  }

  .chartjs-size-monitor,
  .chartjs-render-monitor {
    max-width: 100% !important;
  }

  .chart-legend,
  [class*="chart-legend"],
  .dashboard-chart + div[class*="legend"] {
    display: block !important;
    text-align: center !important;
    margin-top: 12px !important;
    font-size: 11px !important;
  }

  /* ─── Quick Win 5 — Tasks mobile-card view ─── */
  /* Paired with components/mobile-task-cards.js which synthesizes
     .tasks-mobile-cards DOM from the existing #tasksTableBody rows. */
  .tasks-table,
  table.tasks-list,
  #tasksTable {
    display: none !important;
  }

  .tasks-mobile-cards {
    display: block !important;
  }

  .tasks-mobile-cards .task-card {
    background: rgba(255, 255, 255, 0.035);
    border: 1px solid rgba(245, 158, 11, 0.22);
    border-radius: 12px;
    padding: 14px 16px;
    margin-bottom: 12px;
  }

  .tasks-mobile-cards .task-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 8px;
    margin-bottom: 8px;
    padding-bottom: 8px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  }

  .tasks-mobile-cards .task-card-title {
    font-weight: 700;
    color: #F59E0B;
    font-size: 14px;
    line-height: 1.4;
    flex: 1;
  }

  .tasks-mobile-cards .task-card-status {
    padding: 4px 8px;
    border-radius: 6px;
    font-size: 11px;
    background: rgba(59, 130, 246, 0.15);
    color: #60A5FA;
    white-space: nowrap;
    flex-shrink: 0;
  }

  .tasks-mobile-cards .task-card-body {
    font-size: 13px;
    color: #D1D5DB;
    line-height: 1.6;
  }

  .tasks-mobile-cards .task-card-meta {
    display: flex;
    justify-content: space-between;
    margin-top: 10px;
    padding-top: 8px;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    font-size: 11px;
    color: #9CA3AF;
  }

  /* ─── Quick Win 6 — Audit Logs readability ─── */
  .audit-log-entry,
  [data-log-entry],
  tr[data-log] {
    display: block !important;
    background: rgba(255, 255, 255, 0.02) !important;
    border-left: 3px solid #F59E0B !important;
    padding: 12px 16px !important;
    margin-bottom: 8px !important;
    border-radius: 4px !important;
    font-size: 13px !important;
  }

  .log-timestamp {
    display: block !important;
    font-size: 11px !important;
    color: #9CA3AF !important;
    margin-bottom: 4px !important;
  }

  .log-user {
    color: #F59E0B !important;
    font-weight: 600 !important;
  }

  .log-action {
    color: #D1D5DB !important;
    margin-top: 4px !important;
  }

  .log-details {
    font-size: 11px !important;
    color: #6B7280 !important;
    margin-top: 8px !important;
    padding-top: 8px !important;
    border-top: 1px solid rgba(255, 255, 255, 0.05) !important;
  }
}

/* Desktop: hide mobile-only containers (prevents empty space) */
@media (min-width: 769px) {
  .tasks-mobile-cards,
  .team-mobile-list,
  .permission-matrix-mobile-notice,
  .team-chart-mobile-notice,
  .org-chart-mobile-notice,
  .sales-mobile-view,
  .sales-mobile-fab {
    display: none !important;
  }
}

/* ════════════════════════════════════════════════════════════════════
 * BUNDLE #1 — SALES MOBILE REBUILD (Week 1, 2026-04-19)
 * Dual-view: desktop pipelineTable preserved; mobile gets a stage-tabbed
 * card list + FAB + swipe gestures. Companion JS: components/sales-mobile-view.js
 * ════════════════════════════════════════════════════════════════════ */

@media (max-width: 768px) {

  /* Hide the desktop wide pipeline wrap on mobile — mobile view takes over */
  #pipelineTableWrap,
  #pipelineTable {
    display: none !important;
  }

  /* Also hide the footer stage-counts band (desktop uses its own) */
  #pipelineFooter {
    display: none !important;
  }

  /* Show mobile view */
  .sales-mobile-view {
    display: block !important;
    width: 100% !important;
    max-width: 100% !important;
    margin: 8px 0 !important;
  }

  .sales-mobile-wrapper {
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid rgba(245, 158, 11, 0.18);
    border-radius: 12px;
    padding: 0;
    overflow: hidden;
  }

  /* Summary bar */
  .sales-mobile-summary {
    padding: 10px 14px;
    font-size: 12px;
    color: #9CA3AF;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    text-align: center;
  }
  .sales-mobile-summary strong { color: #F59E0B; font-weight: 700; }

  /* Stage tabs (horizontal scroll) */
  .sales-mobile-stage-tabs {
    display: flex !important;
    flex-direction: row !important;
    flex-wrap: nowrap !important;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    -webkit-overflow-scrolling: touch !important;
    scrollbar-width: thin !important;
    gap: 6px !important;
    padding: 8px !important;
    background: rgba(0, 0, 0, 0.25);
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  }

  .sales-mobile-stage-tab {
    display: inline-flex !important;
    align-items: center !important;
    gap: 6px !important;
    flex: 0 0 auto !important;
    min-width: -moz-fit-content !important;
    min-width: fit-content !important;
    padding: 8px 12px !important;
    border: 1px solid rgba(245, 158, 11, 0.15) !important;
    background: rgba(245, 158, 11, 0.05) !important;
    color: #D1D5DB !important;
    border-radius: 20px !important;
    font-size: 12px !important;
    font-weight: 600 !important;
    cursor: pointer !important;
    white-space: nowrap !important;
    transition: all 0.15s !important;
  }

  .sales-mobile-stage-tab:active {
    transform: scale(0.97);
  }

  .sales-mobile-stage-tab.active {
    background: rgba(245, 158, 11, 0.22) !important;
    border-color: #F59E0B !important;
    color: #F59E0B !important;
  }

  .sales-mobile-stage-icon {
    font-size: 14px;
  }

  .sales-mobile-stage-label {
    font-size: 12px;
  }

  .sales-mobile-stage-count {
    display: inline-block;
    background: rgba(255, 255, 255, 0.08);
    color: inherit;
    padding: 1px 7px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 700;
    min-width: 18px;
    text-align: center;
  }

  /* Stage dots (swipe indicator) */
  .sales-mobile-stage-dots {
    display: flex !important;
    justify-content: center !important;
    gap: 6px !important;
    padding: 8px !important;
    background: rgba(0, 0, 0, 0.2);
  }

  .sales-mobile-stage-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.18);
    cursor: pointer;
    transition: all 0.2s;
  }

  .sales-mobile-stage-dot.active {
    width: 22px;
    border-radius: 4px;
    background: var(--dot-color, #F59E0B);
  }

  /* Deals list */
  .sales-mobile-deals-list {
    padding: 10px;
    min-height: 200px;
  }

  /* Deal card */
  .sales-deal-card {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(245, 158, 11, 0.22);
    border-radius: 12px;
    padding: 14px;
    margin-bottom: 10px;
    cursor: pointer;
    transition: transform 0.15s, background 0.15s;
    animation: salesDealCardIn 0.22s ease-out;
  }

  .sales-deal-card:active {
    transform: scale(0.985);
    background: rgba(245, 158, 11, 0.06);
  }

  .sales-deal-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 10px;
    padding-bottom: 8px;
    margin-bottom: 8px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  }

  .sales-deal-name {
    margin: 0;
    font-size: 15px;
    font-weight: 700;
    color: #F59E0B;
    flex: 1;
    line-height: 1.4;
    word-break: break-word;
  }

  .sales-deal-budget {
    flex-shrink: 0;
    background: rgba(16, 185, 129, 0.15);
    color: #10B981;
    padding: 3px 10px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 700;
    white-space: nowrap;
  }

  .sales-deal-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 10px;
  }

  .sales-deal-chip {
    background: rgba(255, 255, 255, 0.05);
    color: #D1D5DB;
    padding: 3px 8px;
    border-radius: 6px;
    font-size: 11px;
    white-space: nowrap;
    border: 1px solid rgba(255, 255, 255, 0.06);
  }

  .sales-deal-info {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-bottom: 10px;
    padding: 8px 10px;
    background: rgba(255, 255, 255, 0.02);
    border-radius: 8px;
    font-size: 12px;
    color: #D1D5DB;
  }

  .sales-deal-info-row {
    line-height: 1.5;
    word-break: break-word;
  }

  .sales-deal-followup {
    color: #F59E0B !important;
  }

  /* Card action buttons */
  .sales-deal-card-actions {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 6px;
    padding-top: 10px;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
  }

  .sales-deal-action {
    padding: 9px 6px !important;
    border-radius: 8px !important;
    font-size: 12px !important;
    font-weight: 600 !important;
    min-height: 40px !important;
    cursor: pointer !important;
    border: 1px solid transparent !important;
    transition: transform 0.12s !important;
    white-space: nowrap !important;
  }

  .sales-deal-action:active { transform: scale(0.95); }

  .sales-deal-whatsapp {
    background: rgba(37, 211, 102, 0.14) !important;
    color: #25D366 !important;
    border-color: rgba(37, 211, 102, 0.28) !important;
  }
  .sales-deal-edit {
    background: rgba(59, 130, 246, 0.14) !important;
    color: #3B82F6 !important;
    border-color: rgba(59, 130, 246, 0.28) !important;
  }
  .sales-deal-delete {
    background: rgba(239, 68, 68, 0.12) !important;
    color: #EF4444 !important;
    border-color: rgba(239, 68, 68, 0.28) !important;
  }

  /* Empty state */
  .sales-mobile-empty {
    text-align: center;
    padding: 40px 20px !important;
    color: #9CA3AF;
    line-height: 1.8;
  }
  .sales-mobile-empty strong { color: #F59E0B; }
  .sales-mobile-empty-cta {
    margin-top: 12px !important;
    padding: 10px 22px !important;
    background: linear-gradient(135deg, #F59E0B, #D97706) !important;
    color: #000 !important;
    border: none !important;
    border-radius: 8px !important;
    font-weight: 700 !important;
    font-size: 13px !important;
    cursor: pointer !important;
    min-height: 44px !important;
  }

  /* Floating action button */
  .sales-mobile-fab {
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    position: fixed !important;
    bottom: 20px !important;
    left: 20px !important;   /* RTL — appears on visual-left (start) */
    width: 56px !important;
    height: 56px !important;
    min-width: 56px !important;
    min-height: 56px !important;
    border-radius: 50% !important;
    background: linear-gradient(135deg, #F59E0B, #D97706) !important;
    color: #000 !important;
    border: none !important;
    font-size: 30px !important;
    font-weight: 700 !important;
    cursor: pointer !important;
    box-shadow: 0 6px 18px rgba(245, 158, 11, 0.45) !important;
    z-index: 900 !important;
    transition: transform 0.12s !important;
    padding: 0 !important;
  }

  .sales-mobile-fab:active {
    transform: scale(0.93);
  }

  @keyframes salesDealCardIn {
    from { opacity: 0; transform: translateY(12px); }
    to   { opacity: 1; transform: translateY(0); }
  }
}

/* Extra-small phones */
@media (max-width: 380px) {
  .sales-deal-card-actions {
    grid-template-columns: 1fr 1fr !important;
  }
  .sales-deal-delete { grid-column: span 2 !important; }
  .sales-mobile-stage-label { font-size: 11px !important; }
  .sales-deal-name          { font-size: 14px !important; }
}

/* ════════════════════════════════════════════════════════════════════════
   BUNDLE #2 (Week 2) — SETTINGS MOBILE REBUILD
   Dual-view pattern. pages/settings.js UNTOUCHED.
   Activated when body has .settings-mobile-active (toggled by
   components/settings-mobile-view.js on ≤768px + settings page).
   ════════════════════════════════════════════════════════════════════════ */

@media (max-width: 768px) {
  /* ─── Hide original horizontal tab bar when mobile view active ─────── */
  body.settings-mobile-active #mainContent button.tab-btn[data-tab] {
    display: none !important;
  }
  body.settings-mobile-active .settings-mobile-tabbar {
    display: none !important;
  }

  /* ─── Trigger button (bottom-sheet opener) ─────────────────────────── */
  .settings-mobile-trigger {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 14px 18px;
    margin: 0 0 16px 0;
    background: linear-gradient(180deg, #1a2332 0%, #131b27 100%);
    border: 1.5px solid #F59E0B;
    border-radius: 14px;
    color: #F59E0B;
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
    direction: rtl;
    box-shadow: 0 2px 8px rgba(245, 158, 11, 0.18);
    transition: transform 0.15s, box-shadow 0.15s;
    min-height: 52px;
    font-family: inherit;
  }
  .settings-mobile-trigger:active {
    transform: scale(0.98);
    box-shadow: 0 1px 4px rgba(245, 158, 11, 0.22);
  }
  .settings-mobile-trigger-emoji {
    font-size: 22px;
    line-height: 1;
  }
  .settings-mobile-trigger-label {
    flex: 1;
    text-align: right;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .settings-mobile-trigger-chev {
    font-size: 16px;
    color: #F59E0B;
    opacity: 0.8;
  }

  /* ─── Drawer overlay + bottom-sheet ─────────────────────────────────── */
  .settings-mobile-drawer-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0);
    z-index: 9998;
    pointer-events: none;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    transition: background 0.22s ease-out;
  }
  .settings-mobile-drawer-overlay.open {
    background: rgba(0, 0, 0, 0.62);
    pointer-events: auto;
  }
  .settings-mobile-drawer {
    width: 100%;
    max-width: 720px;
    max-height: 78vh;
    background: linear-gradient(180deg, #131b27 0%, #0a0a0a 100%);
    border-top-left-radius: 22px;
    border-top-right-radius: 22px;
    border-top: 1.5px solid #F59E0B;
    box-shadow: 0 -8px 36px rgba(0, 0, 0, 0.55);
    transform: translateY(100%);
    transition: transform 0.28s cubic-bezier(0.32, 0.72, 0.34, 1);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    direction: rtl;
  }
  .settings-mobile-drawer-overlay.open .settings-mobile-drawer {
    transform: translateY(0);
  }
  .settings-mobile-drawer-handle {
    width: 44px;
    height: 5px;
    background: #334155;
    border-radius: 999px;
    margin: 10px auto 8px;
    flex-shrink: 0;
  }
  .settings-mobile-drawer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 18px 12px;
    border-bottom: 1px solid rgba(245, 158, 11, 0.18);
    flex-shrink: 0;
  }
  .settings-mobile-drawer-title {
    color: #F59E0B;
    font-weight: 700;
    font-size: 15px;
  }
  .settings-mobile-drawer-close {
    background: transparent;
    border: none;
    color: #9CA3AF;
    font-size: 22px;
    cursor: pointer;
    padding: 4px 10px;
    border-radius: 8px;
    line-height: 1;
    min-width: 44px;
    min-height: 44px;
  }
  .settings-mobile-drawer-close:active {
    background: rgba(255, 255, 255, 0.06);
  }
  .settings-mobile-drawer-list {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 8px 12px 24px;
    -webkit-overflow-scrolling: touch;
  }
  .settings-mobile-section-item {
    display: flex;
    align-items: center;
    gap: 14px;
    width: 100%;
    padding: 14px 16px;
    margin-bottom: 6px;
    background: #0F1724;
    border: 1px solid #1e293b;
    border-radius: 12px;
    color: #E2E8F0;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    text-align: right;
    direction: rtl;
    transition: background 0.12s, border-color 0.12s;
    min-height: 54px;
    font-family: inherit;
  }
  .settings-mobile-section-item:active {
    background: #16213a;
  }
  .settings-mobile-section-item.active {
    background: rgba(245, 158, 11, 0.12);
    border-color: #F59E0B;
    color: #F59E0B;
  }
  .settings-mobile-section-emoji {
    font-size: 22px;
    width: 28px;
    text-align: center;
    line-height: 1;
  }
  .settings-mobile-section-label {
    flex: 1;
  }
  .settings-mobile-section-check {
    color: #F59E0B;
    font-weight: 800;
    opacity: 0;
    font-size: 16px;
    transition: opacity 0.12s;
  }
  .settings-mobile-section-item.active .settings-mobile-section-check {
    opacity: 1;
  }

  /* Lock body scroll behind open drawer */
  body.settings-mobile-drawer-open {
    overflow: hidden !important;
  }

  /* ─── Users section — cards view ───────────────────────────────────── */
  .settings-users-cards-container {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: 12px;
    direction: rtl;
  }
  .settings-user-card {
    background: linear-gradient(180deg, #131b27 0%, #0F1724 100%);
    border: 1px solid #1e293b;
    border-radius: 14px;
    padding: 14px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
    animation: settingsUserCardIn 0.22s ease-out;
  }
  @keyframes settingsUserCardIn {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
  }
  .settings-user-card-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    padding-bottom: 10px;
    margin-bottom: 10px;
    border-bottom: 1px dashed rgba(245, 158, 11, 0.15);
  }
  .settings-user-card-name {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
    flex: 1;
  }
  .settings-user-card-title {
    color: #E2E8F0;
    font-size: 15px;
    font-weight: 700;
    word-break: break-word;
  }
  .settings-user-card-email {
    color: #9CA3AF;
    font-size: 12px;
    word-break: break-all;
  }
  .settings-user-card-status {
    flex-shrink: 0;
    font-size: 12px;
    white-space: nowrap;
  }
  .settings-user-card-meta {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px 14px;
    margin-bottom: 12px;
  }
  .settings-user-card-meta-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    font-size: 12px;
    min-width: 0;
  }
  .settings-user-card-meta-item > span {
    color: #6B7280;
    flex-shrink: 0;
  }
  .settings-user-card-meta-item > strong {
    color: #CBD5E1;
    font-weight: 600;
    text-align: left;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
  }
  .settings-user-card-meta-item .role-badge {
    font-size: 11px !important;
    padding: 2px 8px !important;
  }
  .settings-user-card-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }
  .settings-user-action {
    min-height: 42px;
    border: none;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    padding: 8px 10px;
    transition: opacity 0.12s, transform 0.12s;
    font-family: inherit;
  }
  .settings-user-action:active {
    opacity: 0.78;
    transform: scale(0.97);
  }
  .settings-user-action-edit {
    background: rgba(59, 130, 246, 0.18);
    color: #3B82F6;
  }
  .settings-user-action-team {
    background: rgba(139, 92, 246, 0.18);
    color: #8B5CF6;
  }
  .settings-user-action-perm {
    background: rgba(245, 158, 11, 0.18);
    color: #F59E0B;
  }
  .settings-user-action-deactivate {
    background: rgba(239, 68, 68, 0.18);
    color: #EF4444;
  }
  .settings-users-empty {
    text-align: center;
    color: #6B7280;
    padding: 40px 16px;
    background: #0F1724;
    border: 1px dashed #1e293b;
    border-radius: 12px;
    font-size: 13px;
  }

  /* ─── Permission matrix — role browser ─────────────────────────────── */
  .settings-perm-browser {
    direction: rtl;
    margin-top: 8px;
  }
  .settings-perm-loading,
  .settings-perm-error {
    padding: 24px 16px;
    text-align: center;
    color: #9CA3AF;
    background: #0F1724;
    border: 1px dashed #1e293b;
    border-radius: 12px;
    font-size: 13px;
  }
  .settings-perm-error {
    color: #EF4444;
    border-color: rgba(239, 68, 68, 0.35);
  }
  .settings-perm-summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 14px;
    background: linear-gradient(180deg, #131b27 0%, #0F1724 100%);
    border: 1px solid rgba(245, 158, 11, 0.25);
    border-radius: 12px;
    margin-bottom: 10px;
  }
  .settings-perm-summary > strong {
    color: #F59E0B;
    font-size: 15px;
  }
  .settings-perm-summary > span {
    color: #9CA3AF;
    font-size: 13px;
    font-weight: 600;
  }
  .settings-perm-role-chips {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding: 4px 2px 12px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .settings-perm-role-chips::-webkit-scrollbar { display: none; }
  .settings-perm-role-chip {
    flex-shrink: 0;
    padding: 8px 14px;
    background: #0F1724;
    border: 1px solid #1e293b;
    border-radius: 999px;
    color: #9CA3AF;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    min-height: 36px;
    transition: transform 0.12s, border-color 0.12s;
    font-family: inherit;
  }
  .settings-perm-role-chip:active { transform: scale(0.96); }
  .settings-perm-role-chip.active {
    border-width: 1.5px;
    font-weight: 700;
  }
  .settings-perm-groups {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 6px;
  }
  .settings-perm-group {
    background: #0F1724;
    border: 1px solid #1e293b;
    border-radius: 12px;
    overflow: hidden;
  }
  .settings-perm-group-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    background: #131b27;
    border-bottom: 1px solid #1e293b;
  }
  .settings-perm-group-name {
    color: #F59E0B;
    font-weight: 700;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.4px;
  }
  .settings-perm-group-count {
    color: #6B7280;
    font-size: 12px;
    font-weight: 600;
  }
  .settings-perm-group-list {
    list-style: none;
    margin: 0;
    padding: 0;
  }
  .settings-perm-item {
    display: grid;
    grid-template-columns: 24px 1fr auto;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    border-bottom: 1px solid rgba(30, 41, 59, 0.5);
  }
  .settings-perm-item:last-child { border-bottom: none; }
  .settings-perm-item-icon {
    width: 22px;
    height: 22px;
    border-radius: 6px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 13px;
  }
  .settings-perm-item.on .settings-perm-item-icon {
    background: rgba(16, 185, 129, 0.16);
    color: #10B981;
  }
  .settings-perm-item.off .settings-perm-item-icon {
    background: rgba(100, 116, 139, 0.16);
    color: #475569;
  }
  .settings-perm-item-label {
    color: #CBD5E1;
    font-size: 13px;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .settings-perm-item.off .settings-perm-item-label {
    color: #6B7280;
  }
  .settings-perm-item-id {
    color: #475569;
    font-size: 10px;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    direction: ltr;
    text-align: left;
    flex-shrink: 0;
  }
  .settings-perm-hint {
    margin-top: 12px;
    padding: 10px 14px;
    text-align: center;
    color: #475569;
    font-size: 11px;
    background: rgba(245, 158, 11, 0.04);
    border: 1px dashed rgba(245, 158, 11, 0.2);
    border-radius: 10px;
  }

  /* ─── Generic sections (13 of 16) — CSS-only mobile adaptation ──────── */
  body.settings-mobile-active #tabContent form,
  body.settings-mobile-active #tabContent .form-group {
    width: 100% !important;
  }
  body.settings-mobile-active #tabContent input:not([type="checkbox"]):not([type="radio"]):not([type="color"]),
  body.settings-mobile-active #tabContent select,
  body.settings-mobile-active #tabContent textarea {
    width: 100% !important;
    font-size: 16px !important;
    box-sizing: border-box !important;
  }
  /* Horizontal scroll for any generic tab's table (users/permmatrix handled separately) */
  body.settings-mobile-active #tabContent table {
    display: block !important;
    overflow-x: auto !important;
    max-width: 100% !important;
    -webkit-overflow-scrolling: touch;
  }
  /* Touch-friendly buttons inside settings */
  body.settings-mobile-active #tabContent button {
    min-height: 44px;
  }
  /* Collapse 2-col grids to 1-col inside settings */
  body.settings-mobile-active #tabContent [style*="grid-template-columns: 1fr 1fr"],
  body.settings-mobile-active #tabContent [style*="grid-template-columns:1fr 1fr"] {
    grid-template-columns: 1fr !important;
  }
  /* Cards container should stay flex (not block from generic rule) */
  body.settings-mobile-active #settingsUsersCards {
    display: flex !important;
  }
  /* Main title spacing polish */
  body.settings-mobile-active #mainContent h2 {
    font-size: 20px !important;
    margin-bottom: 16px !important;
  }
}

/* ─── Desktop ≥769px — ensure mobile widgets are hidden ─────────────── */
@media (min-width: 769px) {
  .settings-mobile-trigger,
  #settingsUsersCards,
  #settingsPermBrowser {
    display: none !important;
  }
  .settings-mobile-drawer-overlay {
    display: none !important;
  }
}

/* ════════════════════════════════════════════════════════════════════════
   BUNDLE #3 (Week 3) — CALL CENTER MOBILE REBUILD
   Role-adaptive dual-view. pages/call-center.js UNTOUCHED.
   Activated when body has .callcenter-mobile-active (toggled by
   components/callcenter-mobile-view.js on ≤768px + CC page).
   ════════════════════════════════════════════════════════════════════════ */

@media (max-width: 768px) {
  /* ─── Hide original 9-tab horizontal scroll bar ───────────────────── */
  body.callcenter-mobile-active #ccNavTabs,
  body.callcenter-mobile-active .cc-mobile-desktop-tabs {
    display: none !important;
  }

  /* ─── Mobile header (role badge + 3-pill switcher) ────────────────── */
  .cc-mobile-header {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 12px 0 16px;
    margin-bottom: 12px;
    border-bottom: 1px solid rgba(245, 158, 11, 0.15);
    direction: rtl;
    position: sticky;
    top: 0;
    z-index: 40;
    background: linear-gradient(180deg, #0a0a0a 0%, rgba(10, 10, 10, 0.92) 100%);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
  }
  .cc-mobile-role {
    display: flex;
    align-items: center;
    justify-content: flex-start;
  }
  .cc-role-badge {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 14px;
    border-radius: 999px;
    font-size: 13px;
    font-weight: 700;
    border: 1px solid;
  }
  .cc-role-badge.is-manager {
    background: rgba(245, 158, 11, 0.14);
    border-color: rgba(245, 158, 11, 0.45);
    color: #F59E0B;
  }
  .cc-role-badge.is-agent {
    background: rgba(59, 130, 246, 0.14);
    border-color: rgba(59, 130, 246, 0.45);
    color: #3B82F6;
  }
  .cc-role-icon { font-size: 18px; line-height: 1; }
  .cc-role-text { line-height: 1; }

  .cc-mobile-pills {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
  }
  .cc-mobile-pill {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 10px 8px;
    min-height: 62px;
    background: #0F1724;
    border: 1px solid #1e293b;
    border-radius: 12px;
    color: #9CA3AF;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, transform 0.15s;
    font-family: inherit;
  }
  .cc-mobile-pill:active { transform: scale(0.97); }
  .cc-mobile-pill.active {
    background: rgba(245, 158, 11, 0.14);
    border-color: #F59E0B;
    color: #F59E0B;
  }
  .cc-pill-emoji { font-size: 20px; line-height: 1; }
  .cc-pill-label { font-size: 12px; font-weight: 700; }

  /* ─── Sections (common) ───────────────────────────────────────────── */
  .cc-section {
    direction: rtl;
    margin-bottom: 18px;
  }
  .cc-section-title {
    margin: 0 0 10px 0;
    font-size: 15px;
    color: #F59E0B;
    font-weight: 700;
  }
  .cc-empty {
    text-align: center;
    padding: 32px 16px;
    color: #6B7280;
    background: #0F1724;
    border: 1px dashed #1e293b;
    border-radius: 12px;
    font-size: 13px;
  }

  /* ─── KPI grid (4 variants) ───────────────────────────────────────── */
  .cc-kpi-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }
  .cc-kpi-grid.two-up {
    grid-template-columns: repeat(2, 1fr);
  }
  .cc-kpi-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 14px 10px;
    min-height: 96px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 12px;
    text-align: center;
  }
  .cc-kpi-card.primary { border-color: rgba(245, 158, 11, 0.35); }
  .cc-kpi-card.success { border-color: rgba(16, 185, 129, 0.35); }
  .cc-kpi-card.info    { border-color: rgba(59, 130, 246, 0.35); }
  .cc-kpi-card.warning { border-color: rgba(239, 68, 68, 0.35); }
  .cc-kpi-icon  { font-size: 22px; line-height: 1; }
  .cc-kpi-value {
    font-size: 22px;
    font-weight: 800;
    color: #F3F4F6;
    line-height: 1.1;
    word-break: break-word;
  }
  .cc-kpi-card.primary .cc-kpi-value { color: #F59E0B; }
  .cc-kpi-card.success .cc-kpi-value { color: #10B981; }
  .cc-kpi-card.info    .cc-kpi-value { color: #3B82F6; }
  .cc-kpi-card.warning .cc-kpi-value { color: #EF4444; }
  .cc-kpi-label { font-size: 11px; color: #9CA3AF; }

  /* ─── Today's Trend (replaces Chart.js for MVP) ───────────────────── */
  .cc-trend {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin-top: 10px;
    padding: 12px 14px;
    border-radius: 12px;
    font-size: 13px;
    border: 1px solid;
  }
  .cc-trend.trend-up   { background: rgba(16, 185, 129, 0.08); color: #10B981; border-color: rgba(16, 185, 129, 0.3); }
  .cc-trend.trend-flat { background: rgba(245, 158, 11, 0.08); color: #F59E0B; border-color: rgba(245, 158, 11, 0.3); }
  .cc-trend.trend-down { background: rgba(239, 68, 68, 0.08);  color: #EF4444; border-color: rgba(239, 68, 68, 0.3); }
  .cc-trend-icon { font-size: 22px; font-weight: 800; line-height: 1; }
  .cc-trend-text strong { font-weight: 800; }

  /* ─── Top agents leaderboard ──────────────────────────────────────── */
  .cc-top-agents {
    display: flex;
    flex-direction: column;
    gap: 8px;
  }
  .cc-top-agent {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(245, 158, 11, 0.12);
    border-radius: 12px;
  }
  .cc-top-rank {
    font-size: 15px;
    font-weight: 800;
    color: #F59E0B;
    min-width: 26px;
    text-align: center;
  }
  .cc-top-avatar {
    width: 36px; height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, #F59E0B, #D97706);
    color: #000;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 15px;
    flex-shrink: 0;
  }
  .cc-top-info { flex: 1; min-width: 0; }
  .cc-top-name {
    font-size: 14px;
    color: #F3F4F6;
    font-weight: 700;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .cc-top-stats {
    font-size: 11px;
    color: #9CA3AF;
    margin-top: 2px;
  }

  /* ─── Bonus calculator (agent) ────────────────────────────────────── */
  .cc-bonus-calc {
    padding: 16px;
    border-radius: 14px;
    background: linear-gradient(180deg, #131b27 0%, #0F1724 100%);
    border: 1px solid rgba(245, 158, 11, 0.2);
  }
  .cc-bonus-calc.tier-high { border-color: rgba(16, 185, 129, 0.45); }
  .cc-bonus-calc.tier-mid  { border-color: rgba(245, 158, 11, 0.55); }
  .cc-bonus-calc.tier-low  { border-color: rgba(59, 130, 246, 0.45); }
  .cc-bonus-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    margin-bottom: 10px;
  }
  .cc-bonus-amount {
    font-size: 26px;
    font-weight: 800;
    color: #F59E0B;
  }
  .cc-bonus-calc.tier-high .cc-bonus-amount { color: #10B981; }
  .cc-bonus-calc.tier-low .cc-bonus-amount { color: #3B82F6; }
  .cc-bonus-calc.tier-none .cc-bonus-amount { color: #6B7280; }
  .cc-bonus-tier { font-size: 12px; color: #9CA3AF; font-weight: 700; }
  .cc-bonus-progress {
    width: 100%;
    height: 6px;
    background: rgba(255, 255, 255, 0.06);
    border-radius: 999px;
    overflow: hidden;
    margin-bottom: 10px;
  }
  .cc-bonus-bar {
    height: 100%;
    background: linear-gradient(90deg, #F59E0B, #D97706);
    transition: width 0.4s ease-out;
  }
  .cc-bonus-calc.tier-high .cc-bonus-bar { background: linear-gradient(90deg, #10B981, #059669); }
  .cc-bonus-calc.tier-low .cc-bonus-bar  { background: linear-gradient(90deg, #3B82F6, #2563EB); }
  .cc-bonus-hint {
    font-size: 12px;
    color: #9CA3AF;
    line-height: 1.5;
  }

  /* ─── Agent cards (manager's 'agents' tab) ────────────────────────── */
  .cc-mobile-agents {
    display: flex;
    flex-direction: column;
    gap: 12px;
    direction: rtl;
  }
  .cc-agent-card {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(245, 158, 11, 0.15);
    border-radius: 14px;
    padding: 14px;
    animation: ccCardIn 0.22s ease-out;
  }
  @keyframes ccCardIn {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
  }
  .cc-agent-head {
    display: flex;
    align-items: center;
    gap: 12px;
    padding-bottom: 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  }
  .cc-agent-avatar {
    width: 48px; height: 48px;
    border-radius: 50%;
    background: linear-gradient(135deg, #F59E0B, #D97706);
    color: #000;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 18px;
    flex-shrink: 0;
  }
  .cc-agent-main { flex: 1; min-width: 0; }
  .cc-agent-name {
    font-size: 15px;
    color: #F3F4F6;
    font-weight: 700;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .cc-agent-sub {
    font-size: 12px;
    color: #9CA3AF;
    margin-top: 2px;
  }
  .cc-agent-kpis {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
    padding: 12px 0;
  }
  .cc-agent-kpi {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 8px 4px;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 8px;
    min-width: 0;
  }
  .cc-agent-kpi .k-icon { font-size: 14px; line-height: 1; }
  .cc-agent-kpi .k-val  {
    font-size: 14px;
    font-weight: 800;
    color: #F3F4F6;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100%;
  }
  .cc-agent-kpi .k-lbl  { font-size: 10px; color: #9CA3AF; }
  .cc-agent-actions {
    padding-top: 12px;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
  }
  .cc-agent-action {
    width: 100%;
    background: rgba(245, 158, 11, 0.14);
    color: #F59E0B;
    border: 1px solid rgba(245, 158, 11, 0.35);
    padding: 10px 12px;
    border-radius: 10px;
    font-size: 13px;
    font-weight: 700;
    min-height: 44px;
    cursor: pointer;
    font-family: inherit;
  }
  .cc-agent-action:active { opacity: 0.85; }
  .cc-agent-action.disabled,
  .cc-agent-action[disabled] {
    opacity: 0.5;
    cursor: not-allowed;
  }

  /* ─── Lead cards (agent CRM + manager master) ─────────────────────── */
  .cc-mobile-leads {
    display: flex;
    flex-direction: column;
    gap: 12px;
    direction: rtl;
  }
  .cc-lead-card {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(59, 130, 246, 0.22);
    border-radius: 14px;
    padding: 14px;
    animation: ccCardIn 0.22s ease-out;
  }
  .cc-lead-head { padding-bottom: 10px; border-bottom: 1px solid rgba(255, 255, 255, 0.05); }
  .cc-lead-name-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 4px;
  }
  .cc-lead-name {
    font-size: 15px;
    font-weight: 700;
    color: #F3F4F6;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .cc-lead-status {
    flex-shrink: 0;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 700;
  }
  .cc-lead-status.status-new        { background: rgba(59, 130, 246, 0.15);  color: #3B82F6; }
  .cc-lead-status.status-confirmed  { background: rgba(34, 197, 94, 0.15);   color: #22C55E; }
  .cc-lead-status.status-followup   { background: rgba(245, 158, 11, 0.15);  color: #F59E0B; }
  .cc-lead-status.status-noshow     { background: rgba(239, 68, 68, 0.15);   color: #EF4444; }
  .cc-lead-status.status-interested { background: rgba(139, 92, 246, 0.15);  color: #8B5CF6; }
  .cc-lead-status.status-cancelled  { background: rgba(107, 114, 128, 0.15); color: #9CA3AF; }
  .cc-lead-status.status-other      { background: rgba(255, 255, 255, 0.05); color: #D1D5DB; }
  .cc-lead-chip {
    display: inline-block;
    font-size: 11px;
    color: #9CA3AF;
    padding: 2px 8px;
    background: rgba(255, 255, 255, 0.04);
    border-radius: 6px;
  }
  .cc-lead-body {
    padding: 10px 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
  }
  .cc-lead-row {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: #D1D5DB;
  }
  .cc-lead-row > span:first-child { flex-shrink: 0; opacity: 0.75; }
  .cc-lead-row > span:last-child {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    direction: ltr;
    text-align: right;
    flex: 1;
  }
  .cc-lead-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    padding-top: 10px;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
  }
  .cc-lead-action {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    min-height: 44px;
    padding: 10px 8px;
    border-radius: 10px;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    border: 1px solid;
    text-decoration: none;
    font-family: inherit;
    transition: opacity 0.12s, transform 0.12s;
  }
  .cc-lead-action:active { transform: scale(0.97); opacity: 0.85; }
  .cc-lead-action.primary {
    background: rgba(245, 158, 11, 0.15);
    color: #F59E0B;
    border-color: rgba(245, 158, 11, 0.38);
  }
  .cc-lead-action.wa {
    background: rgba(37, 211, 102, 0.15);
    color: #25D366;
    border-color: rgba(37, 211, 102, 0.38);
  }
  .cc-lead-action.edit {
    background: rgba(59, 130, 246, 0.15);
    color: #3B82F6;
    border-color: rgba(59, 130, 246, 0.38);
  }
  .cc-lead-action.qc {
    background: rgba(139, 92, 246, 0.15);
    color: #8B5CF6;
    border-color: rgba(139, 92, 246, 0.38);
  }
  .cc-lead-action.disabled,
  .cc-lead-action[disabled] {
    opacity: 0.45;
    cursor: not-allowed;
  }

  /* ─── Generic adaptations for other CC tabs (bonus / followups / etc) ─ */
  body.callcenter-mobile-active #ccMainContent table {
    display: block !important;
    overflow-x: auto !important;
    max-width: 100% !important;
    -webkit-overflow-scrolling: touch;
  }
  body.callcenter-mobile-active #ccMainContent button {
    min-height: 44px;
  }
  body.callcenter-mobile-active #ccMainContent input:not([type="checkbox"]):not([type="radio"]),
  body.callcenter-mobile-active #ccMainContent select,
  body.callcenter-mobile-active #ccMainContent textarea {
    width: 100% !important;
    font-size: 16px !important;
    box-sizing: border-box !important;
  }
  /* Dashboard KPI cards auto-grid becomes 1-col */
  body.callcenter-mobile-active #ccMainContent [style*="grid-template-columns:repeat(auto-fill,minmax(220px"],
  body.callcenter-mobile-active #ccMainContent [style*="grid-template-columns:repeat(auto-fill,minmax(250px"],
  body.callcenter-mobile-active #ccMainContent [style*="grid-template-columns:repeat(auto-fit,minmax(180px"] {
    grid-template-columns: 1fr !important;
  }
  /* Ensure mobile overlays show as flex regardless of generic rules */
  body.callcenter-mobile-active #ccMobileAgents,
  body.callcenter-mobile-active #ccMobileAgentLeads,
  body.callcenter-mobile-active #ccMobileMasterLeads {
    display: flex !important;
  }
  /* Main heading polish */
  body.callcenter-mobile-active #mainContent h2 {
    font-size: 20px !important;
    margin-bottom: 10px !important;
  }
}

/* ─── Desktop ≥769px — ensure mobile widgets are hidden ─────────────── */
@media (min-width: 769px) {
  .cc-mobile-header,
  #ccMobileDashboardMgr,
  #ccMobileDashboardAgent,
  #ccMobileAgents,
  #ccMobileAgentLeads,
  #ccMobileMasterLeads {
    display: none !important;
  }
}
