/* Staff site, 10 of 13: the width switches and the phone base. After every file above on purpose: at equal
   specificity these override them on a phone. */

/* Width switches: one of two views of the same list, picked at the 800 px phone breakpoint. */
@media (min-width: 801px) { .narrow-only { display: none; } }
@media (max-width: 800px) { .wide-only { display: none; } }

/* ---- Phone base: type, targets, controls ----
   Last in the file on purpose: these override the desktop rules above at equal specificity.
   The crew app's scale: 17 px body, 52 px controls, 44 px for anything else you tap, 14 px text floor.
   Screen only: Letter paper lays out about 740 px wide, and the printed notice keeps its desktop type. */
@media screen and (max-width: 800px) {
    :root { --fs-small: 14px; --fs-smaller: 14px; --fs-fine: 14px; }
    /* Nothing anyone typed (a company name, an email, a token) may run off a phone: a word too long
       for its line breaks inside rather than widening or cutting the page. */
    body { font-size: 17px; line-height: 1.45; overflow-wrap: anywhere; }
    /* ...but our own short words are never squeezed into breaking mid-word. A pill wraps only at a
       space; in a heading row the pill, or the card's action button, keeps its width and the name or
       title beside it wraps instead. Rows that wrap (page actions, row actions) move a button to the
       next line before they would shrink it, so a button breaks a word only if that word alone is
       wider than the screen. */
    .badge { overflow-wrap: normal; }
    :is(.card-head, h1) > .badge { flex-shrink: 0; white-space: nowrap; }
    .section-head > :not(h2) { flex-shrink: 0; }
    h1 { font-size: 26px; font-weight: 700; line-height: 1.15; }
    /* Section labels: page h2s only, so a dialog's title and the job report's title keep their
       case. The crew map's list headings are the same labels (named too, to outrank their desktop size). */
    main h2:not(.modal-head h2, .job-report-title), .crew-map-list h2 { font-size: 14px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-3); }

    input:not([type=checkbox]):not([type=radio]), select, textarea { font-size: 17px; min-height: 52px; border-radius: 10px; }
    input[type=checkbox], input[type=radio] { width: 20px; height: 20px; accent-color: var(--primary); }
    .btn { min-height: 52px; display: inline-flex; align-items: center; justify-content: center; padding: .6rem 1rem; }
    /* Ghost actions are secondary, so they take the 44 px target rather than the 52 px button height. */
    .crumbs a, label.inline, .chip-toggle, .btn-ghost, .btn-danger-link { min-height: 44px; display: inline-flex; align-items: center; }
    /* A tick-box row's words are content, not a field caption: body size, like the client's add-ons on /q/. */
    label.inline { font-size: inherit; }
    /* A card's own action (Add visit, New quote) is secondary to the page's: the 44 px target, not 52. */
    .section-head .btn, .company-card .btn { min-height: 44px; padding: .4rem .9rem; }
    /* A heading's ghost action (Edit) keeps its 44 px target but not its height in the layout, so the
       heading row is as tall as the heading. */
    .section-head .btn-ghost { margin-block: -.6rem; }
    .company-card-name { display: inline-flex; align-items: center; min-height: 44px; }
    /* Stays a list-item so it keeps its disclosure triangle and its full-width tap area.
       MapLibre's attribution toggle is a summary too, sized by MapLibre: leave it alone. */
    summary:not(.maplibregl-map summary) { display: list-item; min-height: 44px; padding-block: .6rem; }
    /* A folded job card is one tappable row: tighter than a card with something in it. */
    .job-card { margin-bottom: .5rem; }
    .job-card:not([open]) { padding-block: 0; }

    /* Page actions fill the width in source order (reading order stays visual order), sharing a row
       while their words fit and wrapping onto the next when they do not. */
    .page-head .actions { width: 100%; align-items: stretch; gap: .4rem; }
    .page-head .actions > * { flex: 1 1 auto; margin: 0; }
    .page-head .actions > form { display: grid; }
    /* Slimmer sides than a lone button, so a status change, Report and Cancel project share one row
       at phone width; on a narrower screen the last one wraps at the normal gap. */
    .page-head .actions .btn { padding-inline: .8rem; }
    .page-head .actions .btn-danger-link { padding-inline: .35rem; }
    /* A quiet page action (Archive, Cancel project) keeps its own width beside the ones that fill. */
    .page-head .actions > :is(.btn-ghost, .btn-danger-link, form:has(> :is(.btn-ghost, .btn-danger-link))) { flex-grow: 0; }
    /* Ghost links leading the row (Team's "Company") line their text up with the title. */
    .page-head .actions > .btn-ghost:first-child { margin-left: -.8rem; }
    .grid-3 { gap: .75rem; }
    .segmented { display: flex; }
    .segmented a { flex: 1; min-height: 44px; }
    /* Stat tiles stay side by side: a figure needs far less width than a form field. */
    .grid-3.totals-row { grid-template-columns: repeat(auto-fill, minmax(8.5rem, 1fr)); }

    /* table.stack: a list table whose rows become cards, so nothing scrolls sideways.
       The contract: the header row is kept for screen readers only; each tr is a card; the first
       cell, when it has no data-label, is the card's title; every td[data-label] shows that label
       over its value, two to a line, and an empty one drops out; td.wide (a note) and td.actions
       (a wrapping row of buttons) take the full width. Links inside take the 44 px target.
       Inside a .card the rows are ruled list rows instead, so a card never holds cards. */
    table.stack thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
    table.stack, table.stack tbody { display: block; width: 100%; }
    table.stack.card-table { background: none; border: 0; }
    table.stack tr {
        --row-top: 14px; position: relative;
        display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .5rem 1rem; min-height: 64px; margin-bottom: 8px;
        padding: var(--row-top) 16px 14px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
    }
    table.stack td:first-child:not([data-label]), table.stack td.wide, table.stack td.actions, table.stack td[colspan] { grid-column: 1 / -1; }
    :is(.card, .public-card) table.stack tr { --row-top: 12px; min-height: 0; margin: 0; padding: var(--row-top) 0 12px; background: none; border: 0; border-top: 1px solid var(--line-soft); border-radius: 0; }
    :is(.card, .public-card) table.stack tbody tr:first-child { --row-top: 0px; border-top: 0; }
    /* A footer row (a report's total) is one more row, its empty cells dropped. */
    table.stack tfoot { display: block; }
    table.stack tfoot th { display: block; padding: 0; border: 0; text-align: left; color: var(--ink); font-size: inherit; }
    table.stack tfoot th:empty { display: none; }
    /* .num and :first-child are named so the desktop .line-table and .card-table cell rules give way. */
    /* A cell is a grid item: min-width 0 lets a long email wrap inside its column. */
    table.stack td, table.stack td.num, table.stack td:first-child { display: block; min-width: 0; padding: 0; border: 0; text-align: left; white-space: normal; }
    table.stack td[data-label]:empty { display: none; }
    table.stack td:first-child:not([data-label]) { font-size: 17px; font-weight: 600; }
    table.stack td:first-child:not([data-label]) a { text-decoration: none; color: var(--ink); }
    /* An archived or past row stays quiet, its title too. */
    table.stack tr:is(.archived, .past) td:first-child a { color: var(--muted); }
    table.stack td a:not(.btn) { display: inline-flex; align-items: center; min-height: 44px; }
    table.stack td[data-label]::before { content: attr(data-label); display: block; font-size: var(--fs-small); color: var(--muted); margin-bottom: .1rem; }
    table.stack td.actions { display: flex; flex-wrap: wrap; gap: 0 .25rem; justify-content: flex-start; }
    table.stack td.actions form { margin: 0; }
    /* Row actions are quiet and close together, and a ghost's text lines up with the text above it;
       its padding still widens the 44 px target. */
    table.stack td.actions .btn-ghost { padding-inline: .6rem; }
    table.stack td.actions > .btn-ghost:first-child, table.stack td.actions > form:first-child > .btn-ghost { margin-left: -.6rem; }
    /* A lone action (Edit) rides at the top right, level with the title, rather than taking a line of
       its own. Across, it is placed in the row's content box (its grid columns); down, in the padding
       box, from --row-top. A linked title is 44 px tall, a plain one a text line: two offsets. */
    table.stack td.actions:has(> :only-child) { position: absolute; top: calc(var(--row-top) - 10px); right: -.6rem; }
    table.stack tr:has(> td:first-child > a) > td.actions:has(> :only-child) { top: var(--row-top); }
    table.stack tr:has(> td.actions > :only-child) > td:first-child { padding-right: 6.5rem; }

    /* The signed-in-as strip stays one slim line under the app bar, its button at the 44 px target.
       A long name gives way (ellipsis), never the button. */
    .founder-banner { flex-wrap: nowrap; padding: .25rem .75rem; min-height: 44px; font-size: var(--fs-small); }
    .founder-banner > span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .founder-banner .btn { min-height: 44px; white-space: nowrap; }
    /* The phone strip has room for who, not where: the company shows on More, under the account. */
    .founder-banner-company { display: none; }

    /* LineTable's lines go to the client: on a phone each reads like a receipt, the description over
       "1 × $1,850.00" (muted) and the amount at the right, with no per-field captions. */
    table.stack.receipt-lines tr { grid-template-columns: max-content max-content 1fr; gap: .2rem .35rem; align-items: baseline; }
    table.stack.receipt-lines td[data-label]::before { content: none; }
    table.stack.receipt-lines td.num { color: var(--muted); }
    table.stack.receipt-lines td.unit::before { content: "× "; display: inline; margin: 0; }
    table.stack.receipt-lines td.amount { justify-self: end; color: var(--ink); font-weight: 600; }

    /* The line editor extends .stack (named in the selector to outrank it): lines are ruled rows
       in a two-column grid, description full width. */
    table.stack.line-editor tr {
        grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .5rem .75rem; padding: .75rem 0; margin-bottom: 0;
        background: none; border: 0; border-bottom: 1px solid var(--border); border-radius: 0;
    }
    .line-editor td.desc { grid-column: 1 / -1; }
    .line-editor td input:not([type=checkbox]), .line-editor td select { width: 100%; min-width: 0; text-align: left; box-sizing: border-box; }
    .line-editor td.remove { align-self: end; justify-self: end; }

    /* Job report: two photos a row, and each visit stacks its day over its times. */
    .job-report-photos { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .75rem; }
    .job-report-visits li { grid-template-columns: 1fr auto; }
    .job-report-visits li > :first-child, .job-report-visits li > :last-child { grid-column: 1 / -1; }
}
