/* PantryPrep — small screens.

   Loaded after every other stylesheet, so these rules override the desktop
   ones without editing them. Two breakpoints:

   70rem (about 1120px) the navigation folds behind a Menu button, and
                        tables become cards, laid out in a grid of columns
   40rem (about 640px)  phone layout: one card per row, rows stack,
                        buttons widen to thumb size

   Nothing here applies on a desktop-width window. */

/* ---------------------------------------------------------------- menu button */

/* Hidden on desktop, where every link fits across the header. */
.topnav__toggle { display: none; }

@media (max-width: 70rem) {
    .topnav__inner {
        padding: 0.7rem 1rem;
        gap: 0.5rem 1rem;
    }

    .topnav__toggle {
        display: inline-flex;
        align-items: center;
        gap: 0.5rem;
        margin-left: auto;
        min-height: 2.75rem;
        padding: 0 0.9rem;
        font: inherit;
        font-size: 0.95rem;
        color: var(--ink);
        background: transparent;
        border: 1px solid var(--rule);
        border-radius: var(--radius);
        cursor: pointer;
    }

    /* Three bars drawn with borders, so no icon font or image is needed. */
    .topnav__toggle-icon {
        width: 1.1rem;
        height: 0.8rem;
        border-top: 2px solid currentColor;
        border-bottom: 2px solid currentColor;
        position: relative;
    }

    .topnav__toggle-icon::after {
        content: "";
        position: absolute;
        left: 0;
        right: 0;
        top: 50%;
        border-top: 2px solid currentColor;
        transform: translateY(-50%);
    }

    .topnav__toggle[aria-expanded="true"] {
        border-color: var(--herb);
        color: var(--herb-deep);
    }

    /* Closed: only the wordmark and the Menu button show. A signed-out
       visitor has no Menu button, so their Sign in link stays visible. */
    .topnav:not([data-nav-open]) .topnav__links,
    .topnav:not([data-nav-open]) .topnav__user,
    .topnav:not([data-nav-open]) .topnav__account .inline-form {
        display: none;
    }

    /* Closed and signed in, the account row would still leave its padding
       behind under the header, so it goes entirely. */
    .topnav:not([data-nav-open]) .topnav__account:has(.inline-form) {
        display: none;
    }

    /* Open: the links drop below as a panel of large tap rows. */
    .topnav__links {
        width: 100%;
        flex-direction: column;
        gap: 0.15rem;
        margin-top: 0.25rem;
        padding: 0.4rem;
        background: var(--paper);
        border: 1px solid var(--rule);
        border-radius: var(--radius-lg);
        font-size: 1rem;
    }

    .topnav__links a {
        display: flex;
        align-items: center;
        justify-content: space-between;
        min-height: 2.9rem;
        padding: 0 0.85rem;
        border-radius: var(--radius);
        color: var(--ink);
    }

    /* A small chevron says each row goes somewhere. */
    .topnav__links a::after {
        content: "";
        width: 0.45rem;
        height: 0.45rem;
        border-top: 1.5px solid var(--rule-strong);
        border-right: 1.5px solid var(--rule-strong);
        transform: rotate(45deg);
    }

    .topnav__links a:hover,
    .topnav__links a:active {
        background: var(--surface);
    }

    .topnav__links a.is-active {
        background: var(--herb-wash);
        color: var(--herb-deep);
    }

    .topnav__links a.is-active::after { border-color: var(--herb); }

    /* In the phone menu the admin dropdown is one more row, which opens in
       place to show its pages, indented beneath it. */
    .navmenu__button {
        display: flex;
        justify-content: space-between;
        min-height: 2.9rem;
        padding: 0 0.85rem;
        border-radius: var(--radius);
        color: var(--ink);
    }

    .navmenu__button::after {
        width: 0.45rem;
        height: 0.45rem;
        border-color: var(--rule-strong);
    }

    .navmenu__panel {
        position: static;
        min-width: 0;
        padding: 0.1rem 0 0.25rem 1rem;
        background: transparent;
        border: 0;
        box-shadow: none;
    }

    .topnav__links .navmenu__panel a {
        min-height: 2.6rem;
        padding: 0 0.85rem;
    }

    .topnav__account {
        width: 100%;
        justify-content: space-between;
        margin-left: 0;
        padding: 0.15rem 0 0.1rem;
    }

    /* Signed out, the account area holds only Sign in, which belongs on the
       right of the wordmark rather than on a row of its own. */
    .topnav__account:not(:has(.inline-form)) {
        width: auto;
        margin-left: auto;
        padding: 0;
    }
}

/* ---------------------------------------------------------------- cards

   Tables turn into cards at the same width the navigation folds away, so a
   window is either fully wide or fully compact, never half of each. */

@media (max-width: 70rem) {
    /* ----- tables become cards ----- */

    /* Below the wide layout the table panel dissolves and each row becomes
       its own card, in a grid that is one column wide on a phone. Values sit two to a row, each with its column name above it, so a
       card is about half the height it would be with one value per line.
       Cells with nothing in them are hidden (app.js marks them is-blank). */
    .table {
        display: block;
        background: transparent;
        border: 0;
        border-radius: 0;
        box-shadow: none;
        overflow: visible;
    }

    .table tbody {
        display: grid;
        grid-template-columns: repeat(auto-fill, minmax(min(100%, 19rem), 1fr));
        gap: 0.75rem;
    }

    /* The header row is hidden, except for a select-all checkbox, which would
       otherwise have nowhere to live. */
    .table thead { display: block; }
    .table thead tr { display: block; }
    .table thead th { display: none; }

    .table thead th.table__check {
        display: flex;
        align-items: center;
        gap: 0.6rem;
        width: auto;
        padding: 0 0 0.75rem;
        border: 0;
        background: transparent;
        font-size: 0.9rem;
        color: var(--ink);
    }

    .table thead th.table__check::after { content: "Select all"; }

    .table tbody tr {
        position: relative;
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        column-gap: 1rem;
        margin: 0;
        padding: 0.8rem 0.95rem 0.55rem;
        background: var(--surface);
        border: 1px solid var(--rule);
        border-radius: var(--radius-lg);
        box-shadow: var(--shadow);
    }

    .table tbody tr:hover { background: var(--surface); }

    .table tbody td {
        display: block;
        min-width: 0;
        padding: 0.3rem 0;
        border: 0;
        text-align: left;
        overflow-wrap: anywhere;
    }

    .table tbody td.is-blank { display: none; }

    /* Columns a template marks as minor (servings, purchase dates, weights)
       stay on the desktop table and the item's own page, but are left off the
       phone card so a list stays scannable. */
    .table tbody td.table__minor { display: none; }

    /* Long single values, such as an email address, take the card's full
       width instead of breaking mid-word in half of it. */
    .table tbody td.table__wide { grid-column: 1 / -1; }

    .table tbody td[data-label]::before {
        content: attr(data-label);
        display: block;
        margin-bottom: 0.05rem;
        font-size: 0.74rem;
        font-weight: 600;
        color: var(--ink-soft);
    }

    /* The first real column is the card's title: larger, across the full
       width, with no label. When a row starts with a checkbox, the title is
       the cell after it. */
    .table tbody td:first-child:not(.table__check),
    .table tbody td.table__check + td {
        grid-column: 1 / -1;
        margin-bottom: 0.25rem;
        padding: 0 2.75rem 0.5rem 0;
        border-bottom: 1px solid var(--rule);
        font-size: 1.02rem;
        font-weight: 600;
    }

    .table tbody td:first-child:not(.table__check)::before,
    .table tbody td.table__check + td::before {
        display: none;
    }

    /* The row checkbox moves to the card's top right corner, enlarged for a
       thumb. */
    .table tbody td.table__check {
        position: absolute;
        top: 0.55rem;
        right: 0.55rem;
        width: auto;
        padding: 0.2rem;
    }

    .table tbody td.table__check::before { display: none; }

    .table__check input { font-size: 1.35rem; }

    /* Row actions get their own strip along the bottom of the card. */
    .table tbody td.table__actions {
        grid-column: 1 / -1;
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        gap: 0.25rem 1.5rem;
        margin-top: 0.35rem;
        padding-top: 0.35rem;
        border-top: 1px solid var(--rule);
        white-space: normal;
        text-align: left;
    }

    .table tbody td.table__actions::before { display: none; }

    /* A row with no actions for this person, such as your own line in a
       group's people list, drops the empty strip. */
    .table tbody td.table__actions.is-blank { display: none; }

    .table__actions a,
    .table__actions .linkbutton,
    .table__actions form {
        margin: 0;
    }

    .table__actions a,
    .table__actions .linkbutton {
        display: inline-block;
        padding: 0.45rem 0;
        font-size: 0.95rem;
    }

    /* On a card the everyday action reads as a link; deleting stays grey
       until touched. */
    .table__actions a:not(.danger),
    .table__actions .linkbutton:not(.linkbutton--danger) {
        color: var(--herb-deep);
        font-weight: 500;
    }
}

/* ---------------------------------------------------------------- phone layout */

@media (max-width: 40rem) {

    /* ----- page shell ----- */

    .page {
        padding: 1.5rem 1rem 3rem;
    }

    h1 { font-size: 1.6rem; }

    .pagehead {
        flex-direction: column;
        gap: 1rem;
    }

    .pagehead__note { max-width: none; }

    .notice { max-width: none; }

    /* Page actions fill the width in an even grid of buttons. */
    .actions {
        width: 100%;
        gap: 0.5rem;
    }

    .actions > .button,
    .actions > form {
        flex: 1 1 calc(50% - 0.5rem);
    }

    .actions .button {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 100%;
        min-height: 2.75rem;
        text-align: center;
    }

    /* ----- inputs ----- */

    /* iOS Safari zooms the whole page into any field under 16px when it is
       tapped, and does not zoom back out. 16px stops that. */
    .field input,
    .field select,
    .field textarea,
    .form textarea,
    .searchbar input[type="search"],
    .searchbar__select,
    .filters__field input,
    .filters__field select,
    .filters--inline input,
    .filters--inline select,
    .lineitem__cell input,
    .lineitem__cell select {
        font-size: 16px;
    }

    .form,
    .form--wide {
        max-width: none;
    }

    .fieldrow {
        flex-direction: column;
        gap: 0;
    }

    .fieldrow .field { flex: 1 1 auto; }

    /* Short number fields, such as serves, prep and cook, stay on one row. */
    .fieldrow:not(:has(select, textarea)) {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(5.5rem, 1fr));
        gap: 0 0.75rem;
    }

    /* ----- toolbars, search, and filters ----- */

    .toolbar {
        flex-wrap: wrap;
        gap: 0.75rem;
    }

    .toolbar > .button,
    .toolbar > form,
    .toolbar__actions {
        width: 100%;
    }

    .toolbar__actions { flex-wrap: wrap; }

    .toolbar .button {
        flex: 1 1 auto;
        min-height: 2.75rem;
        text-align: center;
    }

    .toolbar > form .button { width: 100%; }

    .searchbar {
        width: 100%;
        flex-wrap: wrap;
    }

    .searchbar input[type="search"] {
        flex: 1 1 100%;
        min-height: 2.75rem;
    }

    /* With no place picker beside it, the search box and its button share
       one row. */
    .searchbar:not(:has(select)) { flex-wrap: nowrap; }

    .searchbar:not(:has(select)) input[type="search"] { flex: 1 1 auto; min-width: 0; }

    .searchbar:not(:has(select)) .button { flex: none; width: auto; }

    .searchbar__select {
        flex: 1 1 auto;
        min-height: 2.75rem;
    }

    /* Two short filters sit side by side rather than stacking. */
    .filters {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        align-items: end;
        gap: 0.75rem;
    }

    .filters > :only-child,
    .filters__buttons { grid-column: 1 / -1; }

    .filters__field input,
    .filters__field select,
    .filters--inline input,
    .filters--inline select {
        width: 100%;
        min-width: 0;
        height: 2.75rem;
    }

    .filters__buttons { width: 100%; }

    .filters__buttons .button,
    .filters--inline .button {
        flex: 1 1 0;
        height: 2.75rem;
    }

    /* ----- panels ----- */

    .aisle { padding: 0.75rem 0.9rem 0.2rem; }

    .factgrid { padding: 0.85rem 1rem; }

    /* ----- selection bar ----- */

    /* While something is ticked, the bar floats at the bottom of the screen,
       where a thumb can reach it however far down the list you are. */
    .bulkbar {
        position: fixed;
        left: 0.5rem;
        right: 0.5rem;
        bottom: 0.5rem;
        z-index: 20;
        margin: 0;
        gap: 0.5rem 1rem;
        box-shadow: 0 8px 28px rgba(60, 40, 15, 0.25);
    }

    .bulkbar .button { min-height: 2.5rem; }

    .page:has(.bulkbar:not([hidden])) { padding-bottom: 8rem; }

    /* ----- dialogs ----- */

    .dialog,
    .dialog--narrow {
        width: calc(100vw - 1rem);
        max-height: calc(100dvh - 1rem);
        overflow-y: auto;
    }

    .dialog__head { padding: 0.9rem 1rem 0.75rem; }
    .dialog__body { padding: 1rem 1rem 0.25rem; }
    .dialog__foot { padding: 0.85rem 1rem 1rem; }

    .dialog__foot .button {
        flex: 1 1 auto;
        min-height: 2.75rem;
    }

    .dialog__close {
        min-width: 2.75rem;
        min-height: 2.75rem;
    }

    /* ----- recipes ----- */

    /* Recipe facts line up in three even columns. */
    .factgrid {
        display: grid;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 0.85rem 1rem;
    }

    .factgrid dd { font-size: 1.05rem; }

    .lines { padding: 0.9rem 0.85rem 1rem; }

    /* ----- meal plans ----- */

    .week { gap: 0.75rem; }

    .day__add {
        align-self: stretch;
        min-height: 2.75rem;
    }

    .meal__actions .linkbutton { font-size: 0.88rem; }

    .meal__cook .linkbutton { padding: 0.45rem 0.95rem; }

    .meal__remove .linkbutton { padding: 0.45rem 0.25rem; }

    .meal__check { margin-top: 0.05rem; }

    .meal__check,
    .meal-select-all input { font-size: 1.3rem; }

    /* ----- grocery lists ----- */

    .tick {
        width: 2rem;
        height: 2rem;
        font-size: 1.1rem;
    }

    .shoplist__item { padding: 0.75rem 0; }

    .shoplist__amount {
        display: block;
        margin-left: 0;
    }

    /* ----- logs pager ----- */

    .pager .button {
        min-width: 2.75rem;
        height: 2.75rem;
    }

    .pager__total {
        width: 100%;
        margin-left: 0;
    }

    /* ----- viewing-as banner ----- */

    .impersonation {
        justify-content: flex-start;
        padding: 0.6rem 1rem;
        font-size: 0.88rem;
    }

    .impersonation .button { width: 100%; }

    /* ----- account page ----- */

    .section .button { width: 100%; min-height: 2.75rem; }
}

/* Touch screens have no hover, and a tapped row can stay "hovered" until the
   next tap. Keep row backgrounds steady there. */
@media (hover: none) {
    .table tbody tr:hover { background: inherit; }
}
