/* ============================================================================================
   mobile.css — the phone and tablet layer for the whole app.

   Loaded after enhance.css (layout.ejs), so it settles the generic patterns every view shares —
   .content, .panel, .grid-2, table.tbl, .btn, form controls — and each module's own stylesheet,
   which loads later inside its view, can still refine its own pieces. The look it aims at is
   Apple's on a phone: large page titles, inset rounded cards on the grouped background, rows you
   can hit with a thumb, 16px form text (anything smaller makes iOS Safari zoom the page on
   focus), and nothing that ever pushes the page sideways.

   Breakpoints match the rest of the app: 900px (the rail becomes a drawer and the navigation bar
   appears — the shell itself is in app.css), 760px (MailVault single pane), 640px (phones).
   Colours come from tokens only (docs/THEMING.md).
   ============================================================================================ */

/* ---- 0. Shared pieces, any width ------------------------------------------------------------ */

/* Inset grouped list — the iOS Settings row: title and subtitle on the left, a value or a
   disclosure chevron on the right, hairlines inset from the left edge. Used by Attendance,
   Notifications and My HR; any view can use it. */
.ilist { list-style:none; margin:0; padding:0; }
.ilist > li, .ilist > .ilist-row { position:relative; display:flex; align-items:center; gap:12px; min-height:48px; padding:11px 16px; color:var(--ink); }
.ilist > li + li::before, .ilist > .ilist-row + .ilist-row::before {
  content:""; position:absolute; top:0; left:16px; right:0; height:1px; background:var(--line);
}
a.ilist-row { text-decoration:none; -webkit-tap-highlight-color:transparent; }
a.ilist-row:hover { background:var(--hover); text-decoration:none; }
a.ilist-row:active { background:var(--surface-2); }
.ilist-main { flex:1 1 auto; min-width:0; }
.ilist-title { font-weight:500; line-height:1.3; overflow-wrap:anywhere; }
.ilist-sub { margin-top:2px; font-size:.88em; line-height:1.4; color:var(--muted); overflow-wrap:anywhere; }
.ilist-value { flex:0 0 auto; color:var(--ink-2); font-variant-numeric:tabular-nums; text-align:right; white-space:nowrap; }
.ilist-chev { flex:0 0 auto; width:8px; height:8px; margin-left:2px; border-top:2px solid var(--line-2); border-right:2px solid var(--line-2); transform:rotate(45deg); border-radius:1px; }
.ilist-dot { flex:0 0 auto; width:9px; height:9px; border-radius:50%; background:var(--brand-2); }
.ilist-dot.off { background:transparent; }

/* Anything that sticks to the top of the page parks under the phone's navigation bar instead of
   sliding behind it (--app-topbar-h is 0 on desktop, so nothing moves there). The HR tab bar is
   the one sticky header in the shell today. */
.content .hrbar { top:var(--app-topbar-h, 0px); }


/* ---- 1. Tablets and phones (≤900px) ---------------------------------------------------------- */
@media (max-width: 900px) {
  /* tabs and segmented navs scroll as one row; the bar itself is the affordance */
  .admin-tabs, .inv-tabs, .subtabs { scrollbar-width:none; }
  .admin-tabs::-webkit-scrollbar, .inv-tabs::-webkit-scrollbar, .subtabs::-webkit-scrollbar { display:none; }

  /* popovers that live on <body> never run off the right edge */
  .sel-search-list, .mv-suggest, .hms-ctx { max-width:calc(100vw - 16px); }
  .hmstoast, .hrtoast { bottom:calc(18px + env(safe-area-inset-bottom, 0px)); max-width:calc(100vw - 32px); border-radius:14px; }
}


/* ---- 2. Phones (≤640px) --------------------------------------------------------------------- */
@media (max-width: 640px) {

  /* -- the page never scrolls sideways. `clip` (not `hidden`) cuts the overflow without turning
        html/body into scroll containers, so the sticky navigation bar keeps sticking; browsers
        without `clip` keep the old root-only `hidden`. Wide content scrolls inside its own box. */
  html { overflow-x:hidden; }
  @supports (overflow: clip) { html, body { overflow-x:clip; } }
  body { max-width:100%; }

  .content {
    padding:12px max(16px, env(safe-area-inset-right, 0px)) calc(28px + env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px));
    overflow-wrap:break-word;
  }
  /* break-word, not anywhere: both split an over-long word that would overflow, but `anywhere`
     also shrinks the element's min-content width to one character, so any text that is a flex or
     grid item (a header row, a numbered list) got squeezed into a letter-wide column ("Bo/ard/s",
     "Cloc/k in"). Only code — keys, URIs, tokens with no break points — keeps `anywhere`. */
  .content :is(p, li, dd, dt, summary, label, .help, .muted, .alert, .page-sub) { overflow-wrap:break-word; }
  .content code { overflow-wrap:anywhere; }

  /* -- large titles ---------------------------------------------------------------------------- */
  /* (:where keeps these at the weight of a plain class, so a module's own heading styles win) */
  :where(.content) :is(.page-title, h1) { font-size:28px; line-height:1.14; font-weight:700; letter-spacing:-.022em; overflow-wrap:break-word; }
  :where(.content) .page-sub { font-size:15px; line-height:1.45; margin-bottom:16px; }
  :where(.content) h2 { font-size:20px; letter-spacing:-.015em; }
  :where(.content) h3 { font-size:17px; }

  /* -- inset grouped cards: flat, rounder, a hairline instead of a lifted shadow ----------------- */
  :where(.content) .panel { border-radius:16px; border:1px solid var(--line); box-shadow:none; background:var(--panel); }
  :where(.content) .panel .panel { border-radius:12px; }
  :where(.content) .panel-head { min-height:48px; padding:12px 16px; font-size:16px; flex-wrap:wrap; row-gap:8px; }
  :where(.content) .panel-body { padding:14px 16px; }
  :where(.content) :is(.grid-2, .grid-3, .grid-4) { grid-template-columns:minmax(0, 1fr); gap:14px; }
  :where(.content) .grid-2 > .panel, :where(.content) .grid-3 > .panel { height:auto; }

  /* Multi-column grids written inline in a view (forms of 2–4 fields a row, mostly) stack into
     one column. A grid inside a deliberately wide scroller (min-width / overflow on an ancestor,
     e.g. the payroll setup sheet) keeps its columns — it is meant to be scrolled. */
  .content :is(form, div, section, fieldset)[style*="grid-template-columns"]:not([style*="min-width"] *):not([style*="overflow"] *) {
    grid-template-columns:minmax(0, 1fr) !important;
  }
  .content :is(form, div, section, fieldset)[style*="grid-template-columns"]:not([style*="min-width"] *):not([style*="overflow"] *) > * {
    grid-column:1 / -1 !important; min-width:0;
  }
  .detail-grid { grid-template-columns:1fr; }

  /* -- tables ------------------------------------------------------------------------------------
     A table with up to four columns stays a real table: it fills its card and its cells wrap.
     A wider one scrolls sideways inside itself rather than widening the page — unless it already
     sits in a scroller of its own (a sticky-header list, the roster grid, an overflow wrapper),
     where the wrapper does the scrolling and the table keeps its layout and sticky headers. */
  .content table.tbl { width:100%; }
  .content table.tbl th, .content table.tbl td { padding:10px 12px; }
  .content table.tbl td { font-size:14px; }
  @supports selector(:has(*)) {
    .content table.tbl:is(:has(> thead > tr > :nth-child(5)), :has(> tbody > tr:first-child > :nth-child(5))):not(:is(.tbl-scroll, .abs-pending, .rg-wrap, .map-scroll, .sp-scroll, .drive-list, [style*="overflow"]) > table):not(.tbl-cards) {
      display:block; overflow-x:auto; white-space:nowrap; -webkit-overflow-scrolling:touch; overscroll-behavior-x:contain;
    }
    /* …and a scrolled table with no header row still spans the full card */
    .content table.tbl:is(:has(> tbody > tr:first-child > :nth-child(5))):not(:has(> thead)):not(:is(.tbl-scroll, .abs-pending, .rg-wrap, .map-scroll, .sp-scroll, .drive-list, [style*="overflow"]) > table):not(.tbl-cards) > tbody {
      display:table; width:100%;
    }
    .content :is(.tbl-scroll, .abs-pending, [style*="overflow"]) > table.tbl:is(:has(> thead > tr > :nth-child(5)), :has(> tbody > tr:first-child > :nth-child(5))):not(.tbl-cards) { white-space:nowrap; }
  }
  @supports not selector(:has(*)) {
    .content table.tbl { display:block; overflow-x:auto; white-space:nowrap; -webkit-overflow-scrolling:touch; }
    .content :is(.tbl-scroll, .abs-pending, .rg-wrap, .map-scroll, .sp-scroll, [style*="overflow"]) > table.tbl { display:table; }
  }

  /* -- a table whose rows are records becomes one block per row -------------------------------
     For a list of things (a task, a request, a team) rather than figures to compare down a
     column: put .tbl-cards on the table.tbl and data-label on its cells. On a phone each row
     becomes a block inside the table's card — the first cell is its title, every other cell a line
     with the label on the left and the value on the right — and the hairlines are inset as in an
     iOS list. The sideways-scroll rule above leaves these tables alone. Wider screens keep the
     ordinary table. A row whose only cell spans the table (an empty message) stays one line. */
  .content table.tbl.tbl-cards, .content table.tbl.tbl-cards > tbody { display:block; width:100%; overflow:visible; white-space:normal; }
  .content table.tbl.tbl-cards > thead { display:none; }
  .content table.tbl.tbl-cards > tbody > tr { display:block; position:relative; padding:12px 16px; }
  .content table.tbl.tbl-cards > tbody > tr + tr::before { content:""; position:absolute; top:0; left:16px; right:0; height:1px; background:var(--line); }
  .content table.tbl.tbl-cards > tbody > tr > td {
    display:flex; flex-wrap:wrap; align-items:center; justify-content:flex-end; column-gap:8px; row-gap:4px;
    min-width:0; padding:5px 0; border:none; text-align:right; white-space:normal; font-size:15px; overflow-wrap:anywhere;
  }
  .content table.tbl.tbl-cards > tbody > tr > td[data-label]::before { content:attr(data-label); margin-right:auto; padding-right:8px; color:var(--muted); text-align:left; overflow-wrap:normal; }
  .content table.tbl.tbl-cards > tbody > tr > td:first-child, .content table.tbl.tbl-cards > tbody > tr > td[colspan] { display:block; padding:0 0 6px; text-align:left; font-size:16px; line-height:1.35; }
  .content table.tbl.tbl-cards > tbody > tr > td:first-child::before { content:none; }
  .content table.tbl.tbl-cards > tbody > tr > td[colspan] { padding:4px 0; text-align:center; font-size:15px; color:var(--muted); }

  /* -- media and code never widen their column ------------------------------------------------- */
  img, video { max-width:100%; height:auto; }
  iframe, canvas, svg, object, embed { max-width:100%; }
  pre { max-width:100%; overflow-x:auto; }

  /* -- form controls ----------------------------------------------------------------------------
     16px text stops iOS Safari zooming the page when a field takes focus. The selectors carry
     the same weight as enhance.css's 13.5px rule so this one wins, while a module's own, more
     specific field styling still wins over both. */
  input[type=text], input[type=email], input[type=password], input[type=search], input[type=number],
  input[type=date], input[type=time], input[type=tel], input[type=url], input[type=datetime-local],
  input[type=month], input[type=week], input:not([type]), select, textarea { font-size:16px; max-width:100%; }
  /* Fields in a card or a form fill the row and are a thumb tall. Zero specificity (:where), so
     any width a view or module chose on purpose still applies; fields inside tables, toolbars,
     card headers and inline forms keep their size. */
  :where(.content .panel-body, .content form) :where(input[type=text], input[type=email], input[type=password], input[type=search],
    input[type=number], input[type=date], input[type=time], input[type=tel], input[type=url], input[type=datetime-local],
    input[type=month], input:not([type]), select, textarea):where(:not(table *, .toolbar *, .panel-head *, form.inline *, .mv *, .sel-search-native)) {
    width:100%; min-height:44px;
  }
  :where(.content .panel-body, .content form) :where(.sel-search):where(:not(table *, .toolbar *, .panel-head *, .mv *)) { display:block; width:100%; }
  :where(.content) :where(input[type=checkbox], input[type=radio]) { width:18px; height:18px; accent-color:var(--brand-2); }

  /* -- buttons: thumb-sized, rounder, centred. Plain-class weight (:where), so a module that sizes
        its own toolbar buttons (MailVault's list bar, the roster selection bar) keeps them. ------ */
  :where(.content) .btn { min-height:44px; padding:10px 16px; border-radius:12px; font-size:15px; justify-content:center; }
  :where(.content) .btn.sm { min-height:44px; padding:8px 13px; border-radius:11px; font-size:14px; }
  /* A secondary button's fill (--surface-2) is all but the page colour on Native and Light, and
     enhance.css takes its shadow away, so one sitting on the page read as loose text. A hairline
     gives it an edge, as a bordered iOS button has. Left out: MailVault, which styles its own
     buttons (mailvault.css), and the roster's dark selection bar, where a light line would glare. */
  :where(.content) .btn.secondary:where(:not(.mail-shell *, .rg-bar *)) { box-shadow:inset 0 0 0 1px var(--line); }
  :where(.content) .btn.secondary:where(:not(.mail-shell *, .rg-bar *)):hover { box-shadow:inset 0 0 0 1px var(--line-2); }
  :where(.content) :is(.row-actions, .toolbar) { flex-wrap:wrap; }
  :where(.content) .toolbar > * { max-width:100%; }

  /* -- the appearance picker on Security & preferences: two previews a row -------------------- */
  .theme-grid { grid-template-columns:repeat(2, minmax(0, 1fr)); gap:10px; }
  .theme-card .tp { height:64px; }

  /* -- public pages with no app shell (sign-in) -------------------------------------------------- */
  .login-wrap { padding:16px; }
  .login-card { width:100%; max-width:400px; padding:20px; }
}
