/* ==========================================================================
   MOBILE APP SHELL  (phones, <=760px)
   --------------------------------------------------------------------------
   The dashboards were built desktop-first: a left sidebar, a wide header with
   the language switch + "Currently Serving" select, and floating panels. On a
   phone that produced a header with four controls fighting for 375px — the
   area select collapsed to ~29px wide and clipped its own options, and the
   account menu rendered ~58px wide. Rather than shrink those further, mobile
   gets a real app shell: a compact top bar, a fixed bottom tab bar built from
   the SAME .sidebar-nav buttons (one source of truth — they already carry the
   icons, i18n labels, active state and unread dots), and bottom sheets for
   every menu/dropdown so nothing can be too narrow or run off-screen.
   ========================================================================== */

/* Nothing anywhere may scroll sideways. */
html, body{ max-width:100%; }
@media (max-width:760px){
  html, body{ overflow-x:hidden; }
  /* Flex/grid children default to min-width:auto, which lets long unbroken
     strings (addresses, emails, URLs) push a track wider than the screen.
     This is the single most common cause of left-right scroll. */
  .sidebar-layout > *, .dash-grid > *, .grid-2 > *, .grid-3 > *,
  .mini-card-row > *, .jobdetail-split > *, .post-job-columns > *{ min-width:0; }
  img, video, canvas, svg, iframe, table{ max-width:100%; }
  /* viewport-fit=cover puts the page under the notch in landscape, so the gutter is
     whichever is larger: the design's 16px or the device's own inset. */
  .container, .container-dash, .page{
    padding-left:max(16px, env(safe-area-inset-left));
    padding-right:max(16px, env(safe-area-inset-right));
  }
  .nav-inner{
    padding-left:max(14px, env(safe-area-inset-left));
    padding-right:max(14px, env(safe-area-inset-right));
  }
}

@media (max-width:760px){
  :root{
    --mtabbar-h:58px;
    --mtabbar-total:calc(58px + env(safe-area-inset-bottom, 0px));
    --mtopbar-h:56px;
  }

  /* ---------- top bar ---------- */
  .nav-inner{
    display:flex; flex-wrap:wrap; align-items:center;
    gap:8px; padding:6px 14px; min-height:var(--mtopbar-h);
  }
  .nav-logo-img{ height:42px; }
  .nav-right{ margin-left:auto; margin-right:0; gap:8px; align-items:center; }
  /* The EN/ES switch is a settings-grade control, not a per-screen one: it ate
     ~150px of a 375px bar. It moves into the More sheet (see buildMoreSheet). */
  .nav .lang-switch{ display:none; }
  /* The pre-existing <=720px rule pinned .account-wrap to the viewport so it wouldn't crowd
     the language switch. With the switch gone and the bar laid out properly it can sit in
     the bar again — pinned, it floated over page content while scrolling. */
  .account-wrap{ position:static !important; top:auto; right:auto; }
  .account-wrap.open{ width:auto !important; height:auto !important; }
  .account-panel{ position:relative; }

  /* "Currently Serving" gets its own full-width row under the logo rather than
     competing for horizontal space — this is what was collapsing to 29px. */
  .nav-area{
    order:3; flex:0 0 100%; width:100%;
    display:flex; align-items:center; gap:8px;
    padding:2px 0 6px; min-width:0;
  }
  .nav-area-label{ flex:0 0 auto; font-size:11.5px; }
  .nav-area-select{ flex:1 1 auto; min-width:0; }
  .nav-area-select .native-select-wrap{ width:100%; display:block; }

  /* ---------- bottom tab bar (from .sidebar-nav) ---------- */
  .mobile-nav-toggle{ display:none !important; }
  .sidebar-layout{ grid-template-columns:1fr; display:block; }
  .sidebar-col{ display:contents; }

  #company-mobile-nav, #crew-mobile-nav{
    display:flex !important; flex-direction:row; gap:0;
    position:fixed; left:0; right:0; bottom:0; top:auto; z-index:120;
    width:100%; max-width:100%;
    padding-left:max(4px, env(safe-area-inset-left));
    padding-right:max(4px, env(safe-area-inset-right));
    padding-bottom:env(safe-area-inset-bottom, 0px);
    height:var(--mtabbar-total);
    background:rgba(255,255,255,0.94);
    -webkit-backdrop-filter:saturate(180%) blur(18px);
    backdrop-filter:saturate(180%) blur(18px);
    border:none; border-top:1px solid var(--line); border-radius:0;
    box-shadow:0 -1px 0 rgba(17,20,24,0.04), 0 -8px 24px rgba(17,20,24,0.06);
    overflow:visible; max-height:none;
  }
  /* Only the 4 primary items + More ride the bar; the rest live in the sheet. */
  #company-mobile-nav .sidebar-nav-item,
  #crew-mobile-nav .sidebar-nav-item{ display:none; }
  #company-mobile-nav .sidebar-nav-item[data-mtab],
  #crew-mobile-nav .sidebar-nav-item[data-mtab]{
    display:flex; flex:1 1 0; min-width:0;
    flex-direction:column; align-items:center; justify-content:center;
    gap:3px; height:var(--mtabbar-h); padding:6px 2px 4px;
    background:none; border:none; border-radius:0;
    font-size:10.5px; font-weight:600; letter-spacing:.01em;
    color:var(--ink-soft); position:relative; text-align:center;
  }
  #company-mobile-nav .sidebar-nav-item[data-mtab] .icon,
  #crew-mobile-nav .sidebar-nav-item[data-mtab] .icon{ width:23px; height:23px; }
  #company-mobile-nav .sidebar-nav-item[data-mtab] span[data-i18n],
  #crew-mobile-nav .sidebar-nav-item[data-mtab] span[data-i18n]{
    display:block; width:100%; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; line-height:1.1;
  }
  /* "Matching Jobs" cannot fit a ~70px tab, and ellipsing it to "Matching J…" is worse than
     a shorter word. Each primary tab carries both labels; the bar shows the short one. */
  #company-mobile-nav .sidebar-nav-item[data-mtab] span.mtab-long,
  #crew-mobile-nav .sidebar-nav-item[data-mtab] span.mtab-long{ display:none; }
  #company-mobile-nav .sidebar-nav-item[data-mtab].active,
  #crew-mobile-nav .sidebar-nav-item[data-mtab].active{ color:#185fa5; background:none; }
  #company-mobile-nav .sidebar-nav-item[data-mtab].active .icon,
  #crew-mobile-nav .sidebar-nav-item[data-mtab].active .icon{ stroke-width:2.4; }
  #company-mobile-nav .sidebar-nav-item[data-mtab] .notif-dot,
  #crew-mobile-nav .sidebar-nav-item[data-mtab] .notif-dot{
    position:absolute; top:5px; left:50%; margin-left:7px;
  }

  /* Content must clear the fixed bar. */
  body.has-mobile-tabbar .page{ padding-bottom:calc(var(--mtabbar-total) + 20px); }

  /* Settings has 10 tabs — far too many for a tab bar, so it stays a list, but a
     full-width in-flow one rather than the old 220px floating panel. */
  #settings-mobile-nav{
    position:static !important; display:flex !important; flex-direction:column;
    width:100%; max-width:100%; top:auto; right:auto; gap:2px;
    max-height:none; overflow:visible; margin-bottom:18px;
    border:1px solid var(--line); border-radius:16px; padding:8px;
  }
  #settings-mobile-nav .sidebar-nav-item{ display:flex; min-height:48px; font-size:15px; }
  .dash-logout-btn{ display:none; }

  /* A fixed bottom bar with a top bar that scrolls away feels half-native; make it stick. */
  .nav{ position:sticky; top:0; z-index:110; background:var(--white); }

  /* The overview map is useful but it was claiming ~300px above the job list — on a phone
     that is the entire first screen before a single job is visible. */
  .jobs-map-wrap, .jobs-map{ height:170px; min-height:0; }
  #request-address-map, .jobdetail-map{ height:180px; min-height:0; }


  /* ---------- messaging: two screens, not two columns ----------
     The dashboard widget (.msg-layout-widget) is a preview and keeps its own
     compact form, so every rule here excludes it. */
  .msg-layout:not(.msg-layout-widget){
    display:block; border:none; border-radius:0; min-height:0; overflow:visible;
  }
  .msg-layout:not(.msg-layout-widget) .msg-threads{
    display:block; width:100%; max-height:none; overflow:visible;
    border-right:none; background:transparent;
  }
  .msg-layout:not(.msg-layout-widget) .msg-thread{
    border-bottom:1px solid var(--line); border-radius:0; padding:14px 4px;
  }
  .msg-layout:not(.msg-layout-widget) .msg-thread-title{ font-size:15.5px; }
  .msg-layout:not(.msg-layout-widget) .msg-thread-sub,
  .msg-layout:not(.msg-layout-widget) .msg-thread-preview{ font-size:13.5px; }
  /* List screen: conversation is off. */
  .msg-layout:not(.msg-layout-widget) .msg-pane{ display:none; }
  /* Conversation screen: list is off and the pane takes the window, with the
     composer pinned above the tab bar instead of scrolling away below the fold. */
  .msg-layout.mchat-open:not(.msg-layout-widget) .msg-threads{ display:none; }
  .msg-layout.mchat-open:not(.msg-layout-widget) .msg-pane{
    display:flex; position:fixed; left:0; right:0; top:0;
    bottom:var(--mtabbar-total); z-index:115;
    background:#fff; border:none;
  }
  .msg-layout:not(.msg-layout-widget) .msg-pane-head{
    display:flex; align-items:center; gap:10px; padding:10px 14px;
    flex:0 0 auto; background:#fff;
  }
  .msg-pane-headtext{ min-width:0; flex:1 1 auto; }
  .msg-layout:not(.msg-layout-widget) .msg-pane-title{ font-size:15.5px; }
  .msg-layout:not(.msg-layout-widget) .msg-pane-title,
  .msg-layout:not(.msg-layout-widget) .msg-pane-sub{
    overflow:hidden; text-overflow:ellipsis; white-space:nowrap;
  }
  .msg-back-btn{
    display:flex; align-items:center; justify-content:center;
    width:40px; height:40px; flex:0 0 auto; margin-left:-8px;
    background:none; border:none; border-radius:50%;
    color:var(--ink); cursor:pointer;
  }
  .msg-back-btn:active{ background:var(--paper-dim); }
  .msg-layout.mchat-open:not(.msg-layout-widget) .msg-scroll{
    flex:1 1 auto; max-height:none; min-height:0; overflow-y:auto;
    -webkit-overflow-scrolling:touch; padding:12px 14px;
  }
  .msg-layout.mchat-open:not(.msg-layout-widget) .msg-composer{
    flex:0 0 auto; margin:0; border-radius:0;
    border-left:none; border-right:none; border-bottom:none;
    padding:9px 12px calc(9px + env(safe-area-inset-bottom, 0px));
  }
  .msg-composer-input{ font-size:16px; }   /* <16px makes iOS zoom on focus */
  /* The page title and identity block are noise once a conversation is open. */
  body.msg-chat-open .dash-identity-text,
  body.msg-chat-open .nav{ display:none; }


  /* ---------- modals become bottom sheets ----------
     Centred boxes on a phone leave dead space top and bottom and put the primary
     action mid-screen, out of thumb reach. #confirm-changes-modal in particular
     had no max-height at all, so a long change list ran straight off the screen.
     All of them now dock to the bottom, cap their height and scroll inside. */
  #confirm-changes-modal, #payment-modal, .counter-modal{
    align-items:flex-end; padding:0;
  }
  #confirm-changes-modal .modal-box,
  #payment-modal .modal-box,
  .counter-modal .counter-box{
    max-width:100%; width:100%;
    border-radius:20px 20px 0 0;
    padding:24px 18px calc(22px + env(safe-area-inset-bottom, 0px));
    max-height:88vh; overflow-y:auto; -webkit-overflow-scrolling:touch;
    animation:msheetUp .26s cubic-bezier(.22,.9,.3,1.04);
  }
  /* Stacked, full-width actions — two buttons side by side at this width give
     each ~150px and wrap their labels. */
  .payment-modal-actions{ flex-direction:column; }
  .payment-modal-actions .btn{ width:100%; }

  /* The job-detail overlay is a full page on a phone, not a floating card. */
  #view-jobdetail.overlay-mode{ padding:0; display:block; background:#fff; }
  #view-jobdetail.overlay-mode .page.container{
    border-radius:0; max-width:100%; padding:16px 16px calc(24px + var(--mtabbar-total));
    box-shadow:none; animation:none;
  }

  /* Camera is already full-screen; just keep its controls clear of the home bar. */
  .camera-modal-controls{ padding-bottom:calc(22px + env(safe-area-inset-bottom, 0px)); }


  /* ---------- touch + input ergonomics ----------
     iOS Safari zooms the page whenever a focused field's font-size is under 16px, and the
     zoomed page then scrolls left-right — the one thing this redesign must never do. So
     every text-entry control is >=16px on phones regardless of its desktop size. The
     .native-select-wrap <select>s are invisible proxies behind the custom trigger, but
     they are still focusable, so they are included. */
  input, select, textarea,
  .native-select-trigger, .post-job-panel .native-select-trigger{
    font-size:16px !important;
  }
  /* Comfortable, thumb-sized hit targets. */
  .btn, .sidebar-nav-item, .msheet-item, .native-select-trigger,
  input[type="text"], input[type="email"], input[type="tel"],
  input[type="number"], input[type="password"], input[type="date"], select{
    min-height:46px;
  }
  .native-select-surface, .native-select-trigger{ height:46px; }
  .native-select-wrap{ height:46px; width:100%; display:block; }
  .field{ margin-bottom:18px; }
  /* Kill the grey flash on tap; the :active styles already give feedback. */
  a, button, .btn, .sidebar-nav-item, .msheet-item, .msg-thread, .job-card{
    -webkit-tap-highlight-color:transparent;
  }

  /* ---------- density ----------
     Empty states were sized for a desktop panel and cost most of a phone screen. */
  .empty-state, .dash-panel-body .empty-state{ padding:22px 14px; min-height:0; font-size:13.5px; }
  .dash-panel{ padding:16px 14px; }
  .dash-grid{ gap:14px; }
  .card{ padding:18px 16px; }
  .cal-cell{ min-height:46px; }
  .cal-cell .cal-daynum{ font-size:13px; }
  .section-title{ font-size:19px; }
  h1{ font-size:27px; }
  h2{ font-size:22px; }
  h3{ font-size:18px; }

  /* ---------- identity block ---------- */
  .dash-identity-text{
    padding:0; margin-bottom:14px;
    display:flex; flex-wrap:wrap; align-items:center; gap:8px;
  }
  /* The tab bar already says which dashboard you're in. */
  .dash-identity-text .section-label{ display:none; }
  .dash-identity-name{
    font-size:19px; line-height:1.2; margin:0;
    flex:1 1 100%; order:2; overflow-wrap:anywhere;
  }
  .account-status-badge{ order:1; }
  .dash-logo-slot{ order:1; }
  .dash-logo-slot:empty{ display:none; }
}

