/* ─────────────────────────────────────────────────────────
   mobile.css — phone polish layer for the .studio-* shell.

   Loaded LAST in index.html so it wins the cascade over the base
   mobile rules in r2-tokens.css. Everything here targets the shell
   the app actually renders (.studio-shell / .studio-main /
   .studio-mobile-tabs / .modal-scrim). An earlier version of this file
   styled a previous prototype shell (.dirA-*) that no longer renders,
   so none of it applied — that's why mobile nav, modals, and overflow
   were unstyled. Breakpoint matches the shell flip at 860px.
   ───────────────────────────────────────────────────────── */

@media (max-width: 860px) {

  /* ── Hard stop on horizontal overflow ─────────────────────
     Belt-and-braces: the shell already clips, but pin every layout
     ancestor to the viewport so a wide table/row can't push content
     off the right edge (where it was being silently cut). */
  html, body, #root, .studio-shell, .studio-main {
    max-width: 100vw;
    overflow-x: hidden;
  }
  .studio-main > * { max-width: 100vw; }

  /* ── Bottom tab bar ───────────────────────────────────────
     Was a sticky TOP scroll-strip that hid Invoices + P&L off-screen
     (only 4 of 7 tabs fit). Now a fixed bottom bar with all 7 views
     one thumb-tap away — the native-app pattern, reachable one-handed. */
  .studio-mobile-tabs {
    position: fixed;
    top: auto;
    left: 0; right: 0; bottom: 0;
    z-index: 40;
    display: flex;
    gap: 0;
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom, 0px));
    background: var(--paper);
    border-top: 1px solid var(--rule);
    border-bottom: 0;
    overflow: visible;            /* no more horizontal scroll */
    box-shadow: 0 -2px 12px rgba(26, 26, 26, 0.05);
  }

  .studio-tab {
    flex: 1 1 0;
    min-width: 0;
    min-height: 44px;             /* WCAG 2.5.5 / Apple HIG touch target */
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    position: relative;
    padding: 4px 2px;
    background: transparent;
    border: 0;
    border-top: 2px solid transparent;
    cursor: pointer;
    color: var(--mid);
    font-family: var(--sans);
    font-size: 9px;
    letter-spacing: 0.01em;
    text-transform: uppercase;
    -webkit-tap-highlight-color: transparent;
  }
  .studio-tab-label {
    line-height: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
  }
  .studio-tab.active {
    color: var(--ink);
    border-top-color: var(--ink);
    font-weight: 600;
  }
  /* Count badge (open invoices / board items) — tiny pill top-right. */
  .studio-tab-badge {
    position: absolute;
    top: 3px;
    right: 50%;
    transform: translateX(18px);
    min-width: 15px;
    height: 15px;
    padding: 0 4px;
    border-radius: 999px;
    background: var(--accent, var(--red));
    color: #fff;
    font-family: var(--mono);
    font-size: 9px;
    line-height: 15px;
    text-align: center;
  }

  /* Clear the fixed bar so the last bit of every view stays reachable. */
  .studio-main {
    width: 100%;
    min-width: 0;
    padding-bottom: calc(60px + env(safe-area-inset-bottom, 0px));
  }

  /* ── Touch targets ────────────────────────────────────────
     Buttons were 32–36px tall; bump to the 44px minimum. */
  .btn, .btn-sm { min-height: 44px; }
  .iconbtn { min-width: 40px; min-height: 40px; }
  /* Avatar / save-indicator button carries inline 32px; enlarge the tap area. */
  .user-menu-trigger { width: 40px !important; height: 40px !important; font-size: 15px !important; }

  /* ── Data tables: scroll inside their own box, never push the page ──
     Invoices / P&L / Clients tables are wider than a phone; let them
     scroll horizontally within the card instead of clipping. */
  .invoices-table, .pnl-table, .expenses-table,
  .invoice-lines, .picker-list {
    display: block;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  /* Clients task tables sit inside a .table-scroll wrapper: the wrapper
     scrolls, the table keeps its natural width. min-width stops the
     columns crushing into one-word-per-line stacks on a phone. */
  .table-scroll {
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .table-scroll .clients-table { min-width: 700px; }
  /* Reset min-width on every list/detail grid AND its children. A CSS grid
     track defaults to min-width:auto, so a child with nowrap content (a long
     client email, an invoice row) expands the track past the viewport and
     gets clipped. min-width:0 lets the track shrink so tables scroll instead. */
  .invoices-body, .invoices-list, .invoices-detail,
  .clients-body, .clients-list, .clients-detail,
  .pnl-body, .pnl-grid,
  .notes-body, .notes-list, .notes-detail {
    min-width: 0;
    max-width: 100%;
  }
  .invoices-list-item, .clients-list-item { min-width: 0; max-width: 100%; }

  /* ── Modals → bottom sheets ───────────────────────────────
     The shared Modal (.modal-scrim > .modal) and the invoice pane were
     floating centre cards with side margins. As bottom sheets they're
     bigger, thumb-reachable, and clear the notch + home indicator. */
  .modal-scrim {
    align-items: flex-end;
    padding: 0;
    z-index: 100;                 /* above the bottom tab bar */
  }
  .modal-scrim .modal,
  .modal-scrim .invoice-pane {
    width: 100%;
    max-width: 100%;
    max-height: 92vh;
    margin: 0;
    border-radius: 16px 16px 0 0;
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  /* Keep the close (×) clear of the status bar / Dynamic Island. */
  .modal-scrim .modal > header,
  .modal-scrim .invoice-pane > header {
    padding-top: calc(18px + env(safe-area-inset-top, 0px));
  }

  /* Modal forms use inline multi-column grids (Client / Issue / Due, etc.)
     that overflow a phone. Collapse every grid inside a modal body to one
     column, and keep the body from escaping the sheet width. */
  .modal .body { overflow-x: hidden; }
  .modal .body [style*="grid"] {
    grid-template-columns: 1fr !important;
    gap: 12px !important;
  }
}
