/* The phone layout, from the supplied mobile concept.
 *
 * The shell card, the rail and the desktop density all go away. What is left
 * is the gradient, one job per screen, and a thumb-reachable tab bar. Loaded
 * last so these rules win without needing extra specificity. */

@media (max-width: 759px) {
  .app { padding: 0; }

  .shell {
    border-radius: 0; box-shadow: none; background: transparent;
    padding: 0; gap: 0; flex-direction: column;
  }

  .rail { display: none; }

  .main {
    gap: 8px;
    padding: calc(10px + env(safe-area-inset-top, 0px)) 16px 0;
  }

  /* --- Header ----------------------------------------------------------- */
  .mobilebar {
    flex: 0 0 auto; display: flex; align-items: center; gap: 10px; padding: 2px 0;
  }
  .mobilebar .mark { width: 28px; height: 28px; }
  .mobilebar .mtitle { flex: 1 1 auto; font-size: 19px; font-weight: 600; min-width: 0; }
  .mobilebar .back {
    flex: 0 0 auto; width: 34px; height: 34px;
    border: 0; border-radius: var(--r-btn); background: var(--panel); color: var(--ink-2);
    display: inline-flex; align-items: center; justify-content: center; cursor: pointer;
  }
  .mobilebar .mtitle-sm { display: flex; flex-direction: column; min-width: 0; flex: 1 1 auto; }
  .mobilebar .mtitle-sm .n { font-size: 17px; font-weight: 600; }
  .mobilebar .mtitle-sm .m { font-size: 11px; color: var(--muted); }

  /* --- Top bar ---------------------------------------------------------- */
  .topbar { background: transparent; padding: 0; gap: 8px; }
  .searchwrap { background: var(--panel); height: 44px; border-radius: var(--r-row); }
  /* 16px keeps iOS from zooming the page when the field takes focus. */
  .searchwrap input { font-size: 16px; }
  .refresh { height: 44px; width: 44px; padding: 0; justify-content: center; border-radius: var(--r-row); }
  .refresh .label { display: none; }
  /* The phone header already names the screen; the bar would only repeat it,
     so on screens with nothing to search the bar is just Refresh, right
     aligned under the title. */
  .bartitle { display: none; }
  .topbar { justify-content: flex-end; }

  /* Inside a submission the phone header already carries the back arrow, the
     name and the status. Repeating them in a title card below a search bar
     that the concept does not have would be three headers for one screen. */
  [data-screen="detail"] .topbar { display: none; }
  [data-screen="detail"] .detail-head > .btn:first-child,
  [data-screen="detail"] .detail-head > .who,
  [data-screen="detail"] .detail-head > .pill { display: none; }
  [data-screen="detail"] .detail-head { padding: 0; background: transparent; }
  [data-screen="detail"] .detail-head > .btn-quiet,
  [data-screen="detail"] .detail-head > .pill-warn {
    width: 100%; justify-content: flex-start;
    background: var(--panel); border-radius: var(--r-head);
    padding: 14px 12px; height: auto;
  }

  /* --- Surfaces --------------------------------------------------------- */
  .card, .detail-head, .health, .doclist, .doceditor { border-radius: var(--r-head); padding: 12px; }
  .listhead { padding-bottom: 8px; }

  .rows { gap: 8px; }
  .row {
    grid-template-columns: 42px minmax(0, 1fr) auto;
    background: var(--panel); border-radius: var(--r-head);
    padding: 11px 12px; min-height: 66px; gap: 12px;
  }
  /* The count and time move into the second line; the address steps aside. */
  .row .count, .row .when, .row .chev, .row .who .e { display: none; }
  .row .who .meta { display: block; }
  .row .who .n { font-size: 15px; }
  .row .who .e { font-size: 12px; }
  .thumb { width: 42px; height: 42px; border-radius: var(--r-nav); }

  /* Filter chips scroll rather than shrink, so labels stay readable. */
  .seg { overflow-x: auto; max-width: 100%; scrollbar-width: none; }
  .seg::-webkit-scrollbar { display: none; }

  /* --- One column everywhere -------------------------------------------- */
  .detail-grid, .exportgrid, .setgrid, .docsgrid, .tilegrid {
    grid-template-columns: minmax(0, 1fr);
  }
  .detail-grid, .exportgrid, .docsgrid {
    grid-template-rows: none; overflow-y: auto; overscroll-behavior: contain;
  }

  /* Analytics keeps its no-scroll promise on a phone too: the tabs are what
     make that possible, so each panel still fills the height rather than
     stacking into a column that runs off the bottom. */
  .a-head { gap: 8px; }
  .a-tabs { flex: 1 1 auto; }
  .a-tab { flex: 1 1 0; min-height: 36px; padding: 0 8px; }
  .a-head-right { width: 100%; justify-content: space-between; }

  .dl-wrap { grid-template-columns: minmax(0, 1fr); }
  .docsgrid { grid-template-rows: auto minmax(0, 1fr); overflow: hidden; }
  .tilegrid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .pgrid { grid-template-columns: repeat(3, 1fr); }
  .barrow { grid-template-columns: 88px minmax(0, 1fr) 44px; }
  .barrow .drop { display: none; }

  .doclist { flex-direction: row; overflow-x: auto; }
  .docrow { min-width: 210px; }
  .doc-header { padding: 12px 14px 0; }
  .doc-body:not(.is-email) { padding: 14px; }
  .doc-body.is-email { padding: 8px; }
  /* Split makes no sense at this width; the view control switches panes. */
  .email-panes[data-view="split"] { grid-template-columns: minmax(0, 1fr); }
  .email-panes[data-view="split"] .email-preview { display: none; }

  /* --- Touch targets ---------------------------------------------------- */
  .btn, .input, .pick, .tool { min-height: 44px; }
  .btn-sq, .recip > button, .mobilebar .back { width: 44px; height: 44px; }
  .seg > button { min-height: 36px; }
  .input { font-size: 16px; }
  /* 16px stops iOS zooming when the code field takes focus. */
  .code-hl, .code-input { font-size: 16px; }
  .code-gutter { font-size: 16px; }

  /* --- Tab bar ---------------------------------------------------------- */
  .tabbar {
    flex: 0 0 auto; display: flex; align-items: stretch; gap: 2px;
    margin: 8px 12px calc(12px + env(safe-area-inset-bottom, 0px));
    padding: 4px; background: var(--dark); border-radius: var(--r-rail);
  }
  .tabbtn {
    position: relative;
    display: flex; flex-direction: column; align-items: center; gap: 3px;
    flex: 1 1 0; padding: 8px 0 5px; min-height: 52px;
    border: 0; border-radius: var(--r-nav);
    background: transparent; color: #8d8996;
    font-size: 10px; cursor: pointer;
  }
  .tabbtn svg { color: #8d8996; }
  .tabbtn[aria-current="page"] { background: rgba(255, 255, 255, .1); color: #fff; font-weight: 500; }
  .tabbtn[aria-current="page"] svg { color: #fff; }
  .tabbtn .badge {
    position: absolute; top: 4px; right: calc(50% - 21px);
    min-width: 16px; height: 16px; padding: 0 4px;
    display: inline-flex; align-items: center; justify-content: center;
    border-radius: 999px; background: var(--accent); color: #fff;
    font-size: 9px; font-weight: 600;
  }

  /* Fixed bars must not sit over the last row of content or over focus. */
  .toasts {
    bottom: calc(78px + env(safe-area-inset-bottom, 0px));
    left: 12px; right: 12px; max-width: none;
  }
  .lightbox {
    padding: calc(10px + env(safe-area-inset-top, 0px)) 10px calc(10px + env(safe-area-inset-bottom, 0px));
  }
}

/* Landscape phones: a full-height card plus the tab bar leaves nothing for
 * content, so the chrome shrinks and the panels keep their own scroll. */
@media (max-height: 460px) and (max-width: 959px) {
  .main { gap: 6px; }
  .tabbar { margin-top: 4px; }
  .tabbtn { min-height: 42px; padding: 5px 0 3px; }
  .mobilebar { padding: 0; }
}
