/* ============================================
   Geniusy.ai CRM - the admin on phones (release admin-mobile, David, 11 Nov 2026)
   "Check the business from my phone". Same look, phone-sized.

   Desktop is unchanged: style.css is not touched, and every rule that changes the look is inside the
   ONE media query below, at the existing 768 px breakpoint (where style.css already slides the
   sidebar away). The only rule outside it hides the two new phone-only elements.
============================================ */

.topbar-menu, .sidebar-backdrop { display: none; }

@media (max-width: 768px) {
  /* -- the page never scrolls sideways; long words wrap -- */
  .main-content { min-width: 0; }
  .page-content { padding: 12px; overflow-wrap: anywhere; }
  .modal-body, .modal-title, .toast, .auth-card, .m-tip-pop { overflow-wrap: anywhere; }

  /* -- sign-in -- */
  #auth-screen { padding: 16px; }
  .auth-card { padding: 28px 20px; }
  .pw-toggle { min-width: 44px !important; min-height: 44px !important; right: 0 !important; }

  /* -- the top bar and the menu (the sidebar becomes a drawer) -- */
  .topbar { padding: 0 6px 0 4px; gap: 4px; }
  .topbar-menu {
    display: inline-flex; align-items: center; justify-content: center; flex: none;
    width: 44px; height: 44px; padding: 0; margin: 0;
    background: none; border: 0; border-radius: 8px;
    color: var(--text-primary); font-size: 22px; line-height: 1; cursor: pointer;
  }
  .topbar-title { min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .topbar-actions { gap: 0; }
  .topbar-badge { min-width: 44px; min-height: 44px; display: inline-flex; align-items: center; justify-content: center; }

  .sidebar { visibility: hidden; max-width: 85vw; transition: transform 0.3s, visibility 0.3s; }
  .sidebar.open { visibility: visible; box-shadow: 0 0 40px rgba(0, 0, 0, 0.6); }
  .sidebar-backdrop {
    display: block; position: fixed; inset: 0; z-index: 90;
    background: rgba(5, 13, 26, 0.6); opacity: 0; pointer-events: none; transition: opacity 0.2s;
  }
  .sidebar-backdrop.open { opacity: 1; pointer-events: auto; }
  body.nav-open { overflow: hidden; }
  .nav-item { min-height: 44px; font-size: 15px; }
  .btn-logout { min-width: 44px; min-height: 44px; }

  /* -- tap targets 44 px; form controls 16 px (no iPhone zoom) -- */
  .btn, .btn-sm { min-height: 44px; min-width: 44px; }
  .page-btn { width: 44px; height: 44px; }
  .modal-close { min-width: 44px; min-height: 44px; }
  .btn-play-recording { width: 44px; height: 44px; font-size: 14px; }
  .risk-flag-badge { min-height: 44px; min-width: 44px; justify-content: center; }
  input, select, textarea, .form-control { font-size: 16px !important; }
  .form-control { min-height: 44px; }
  .m-stack td input[type="checkbox"] { width: 44px; height: 44px; margin: 0; }

  /* -- headers and toolbars wrap instead of pushing the page wider -- */
  .page-header { flex-wrap: wrap; gap: 12px; margin-bottom: 16px; }
  .page-header h1 { font-size: 20px; }
  .card-header { flex-wrap: wrap; gap: 8px; padding: 12px 14px; }
  .m-wrap { flex-wrap: wrap !important; gap: 8px !important; }
  .toolbar { gap: 8px; }
  .toolbar > label, .filter-select, .search-box { flex: 1 1 100%; min-width: 0; }
  .toolbar input { min-width: 0; }
  .toolbar .btn { flex: 1 1 auto; justify-content: center; }
  .pagination { flex-wrap: wrap; padding: 12px 14px; }
  .ws-tabs { flex-wrap: wrap; }

  /* -- key figures: two across; numbers never split, they shrink on narrow phones -- */
  .stats-grid { gap: 10px; }
  .stats-grid[style*="repeat(4"] { grid-template-columns: repeat(2, 1fr) !important; }
  .stat-card { padding: 14px; min-width: 0; }
  .stat-value { font-size: clamp(18px, 5.6vw, 24px) !important; white-space: nowrap; }
  .ch-name { font-size: 22px; }
  .ch-kpi-strip { gap: 10px; }
  .ch-kpi-card { padding: 12px 10px; min-width: 0; }
  .ch-kpi-val { font-size: clamp(16px, 5vw, 22px); white-space: nowrap; }

  /* -- tables become stacked cards: one card per row, each value with its column name
        (labels come from the table's own header, set by mobile.js) -- */
  table.m-stack, .m-stack tbody, .m-stack tr, .m-stack td { display: block; width: 100%; }
  .m-stack thead { display: none; }
  .m-stack tr { padding: 10px 14px; border-bottom: 1px solid var(--border); }
  .m-stack tr:last-child { border-bottom: 0; }
  .m-stack tbody tr:hover td { background: none; }
  .m-stack tbody td {
    display: flow-root; padding: 4px 0; border: 0;
    text-align: right !important; white-space: normal !important; max-width: none !important;
  }
  .m-stack td::before {
    content: attr(data-label); float: left; margin-right: 12px; text-align: left;
    color: var(--text-secondary); font-size: 12px; font-weight: 600;
    text-transform: uppercase; letter-spacing: 0.4px; line-height: 20px;
  }
  .m-stack tbody td:first-child { text-align: left !important; font-size: 15px; font-weight: 600; padding-bottom: 6px; }
  .m-stack td:first-child::before { content: none; }
  .m-stack tbody td.m-full { text-align: left !important; }
  .m-stack td.m-full::before { float: none; display: block; margin-bottom: 2px; }
  .m-stack tbody td[colspan] { text-align: center !important; }
  .m-stack td[colspan]::before { content: none; }
  .m-stack td a { display: inline-flex; align-items: center; justify-content: center; min-height: 44px; min-width: 44px; padding: 0 6px; }
  .m-stack td .m-wrap { justify-content: flex-end; }

  /* -- fix round 4: Messages list rows. The row is a flex line whose text column had an automatic
        minimum width of its whole one-line preview (white-space: nowrap), about 2,300 px with the test
        data. Its flex children may now shrink (min-width: 0); the preview stays one line and ends in
        "..." (style.css already clips it, and it is the only element deliberately kept to one line);
        the sender / company line wraps and long names and emails break. Containers do not hide overflow. -- */
  .message-item > div, .message-item > div > div { min-width: 0; }
  .message-item > div > div:first-child > div:first-child { flex-wrap: wrap; }
  .message-item span, .message-subject { min-width: 0; overflow-wrap: anywhere; }

  /* -- the one table kept as a table (Monthly Costs): it scrolls inside its own box, Month pinned -- */
  [data-m-scroll] th, [data-m-scroll] td { padding: 10px; white-space: nowrap; }
  [data-m-scroll] th:first-child, [data-m-scroll] td:first-child { position: sticky; left: 0; z-index: 1; background: var(--navy-900); }

  /* -- tips: a tap opens what was only in a hover title (mobile.js) -- */
  .m-tip { cursor: pointer; }
  .m-tip::after { content: "\24D8"; margin-left: 4px; font-size: 12px; font-weight: 400; color: var(--cyan-400); }
  .stat-card.m-tip::after, .ch-kpi-card.m-tip::after { position: absolute; top: 6px; right: 8px; margin: 0; }
  /* fix round 4: the 10 px health dot (dashboard, Bottom 3) with a tip. Its box becomes a 44 x 44 tap
     area; the coloured dot is still drawn 10 px across in the middle (background clipped to the 10 px
     content box, whose corners are rounded by 22 - 17 = 5 px, so it stays a circle); the i sits inside
     the same box, to the right of the dot, so nothing spills out. Negative margins keep the row's height
     and line-up as before. */
  span.m-tip[style*="width:10px"][style*="border-radius:50%"] {
    position: relative; box-sizing: border-box !important; vertical-align: middle;
    width: 44px !important; height: 44px !important; padding: 17px !important;
    background-clip: content-box !important; margin: -17px 0 -17px -12px !important;
  }
  span.m-tip[style*="width:10px"][style*="border-radius:50%"]::after {
    position: absolute; right: 1px; top: 50%; transform: translateY(-50%); margin: 0; font-size: 11px; line-height: 1;
  }
  .m-tip-pop {
    position: fixed; z-index: 2000; max-width: calc(100vw - 24px);
    background: var(--navy-800); border: 1px solid var(--border-hover); border-radius: 10px;
    padding: 10px 12px; font-size: 13px; line-height: 1.5; color: var(--text-primary);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  }

  /* -- pop-ups: nearly the full screen, buttons share the footer -- */
  .modal-overlay { padding: 10px; }
  .modal { max-height: 92vh; max-height: 92dvh; overscroll-behavior: contain; }
  .modal-header { padding: 10px 6px 10px 16px; gap: 8px; }
  .modal-title { min-width: 0; }
  .modal-body { padding: 16px; }
  .modal-footer { padding: 12px 16px; flex-wrap: wrap; }
  .modal-footer .btn { flex: 1 1 auto; justify-content: center; }

  /* -- David's safeguards: actions that are not for a phone are hidden below 769 px (desktop keeps them):
        Sync Revenue, Trigger SM8 Sync, Sync SMS, Login as Client, Delete user -- */
  .m-hide-phone { display: none !important; }

  /* -- messages along the bottom, full width -- */
  .toast-container { left: 12px; right: 12px; bottom: 12px; }
  .toast { min-width: 0; max-width: none; }
}
