/* ---------------------------------------------------------------------------
   App shell (Views/Shared/_Layout.cshtml): the header, the nav and the
   phone/desktop switch.

   "Phone" is ONE media query, used verbatim here, in mobile.css and in
   app-shell.js (AbcShell.PHONE_QUERY); MobileLayoutContractTests keeps the
   three identical:
       (max-width: 767.98px), (pointer: coarse) and (max-height: 500px)
   = a narrow screen, or a touch screen held sideways. A tablet keeps the
   desktop look. Width, not the browser's name, decides: a narrow desktop
   window gets the phone layout too.

   Desktop keeps the photo background and the coloured header buttons and
   uses the full width of the window. The phone gets a native app look: a
   white top bar, a bottom tab bar, plain light background, big touch targets.
   --------------------------------------------------------------------------- */

:root {
    --app-ink: #1c1f2e;
    --app-muted: #6b7185;
    --app-bg: #f2f3f7;
    --app-surface: #ffffff;
    --app-line: #e3e5ec;
    --app-brand: #0b0b45;      /* navy square of the LBD/GO mark */
    --app-accent: #d10000;     /* red square of the LBD/GO mark */
    --app-primary: #1b6ec2;
    --app-topbar-h: 54px;
    --app-tabbar-h: 58px;
    --app-safe-top: env(safe-area-inset-top, 0px);
    --app-safe-bottom: env(safe-area-inset-bottom, 0px);
    --app-safe-left: env(safe-area-inset-left, 0px);
    --app-safe-right: env(safe-area-inset-right, 0px);
}

/* Show one or the other. .phone-only is hidden when NEITHER half of the phone
   query holds (the two conditions below, negated); .desktop-only is hidden
   inside the phone query further down. */
@media not all and (max-width: 767.98px) {
    @media not all and (pointer: coarse) and (max-height: 500px) {
        .phone-only {
            display: none !important;
        }
    }
}

/* ---- Desktop header ------------------------------------------------------ */

.app-header {
    background: #fff;
    border-bottom: 1px solid var(--app-line);
    box-shadow: 0 .25rem .75rem rgba(0, 0, 0, .05);
    margin-bottom: 1rem;
}

.app-header-inner {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: .5rem 1.5rem;
}

.app-brand {
    min-width: 0;
    margin-right: auto;
}

.app-company {
    color: darkred;
    font-family: 'Arial Black', Arial, sans-serif;
    font-size: 1.5rem;
    line-height: 1.2;
}

.app-outlet {
    color: var(--app-ink);
    font-weight: 600;
    font-size: 1rem;
}

.app-store-slot:empty {
    display: none;
}

.app-nav {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: .4rem;
}

/* The More group's links sit in the same row as the others on a desktop. */
.app-nav-more {
    display: contents;
}

.app-version {
    order: -1;
    color: var(--app-muted);
    font-size: 11px;
    margin-right: .75rem;
}

.app-nav-link {
    display: inline-flex;
    align-items: center;
    gap: .45rem;
    padding: .45rem .85rem;
    border: 0;
    border-radius: .375rem;
    color: #fff;
    font-weight: 600;
    text-decoration: none;
    white-space: nowrap;
    background-color: #2E86C1;
    transition: filter .15s ease;
}

.app-nav-link:hover,
.app-nav-link:focus-visible {
    color: #fff;
    filter: brightness(.92);
}

.app-nav-link.active {
    box-shadow: inset 0 -3px 0 rgba(0, 0, 0, .35);
}

/* The colours the buttons have always had. */
.nav-order    { background-color: #2E86C1; }
.nav-items    { background-color: #3498DB; }
.nav-history  { background-color: #5DADE2; }
.nav-reports  { background-color: #85C1E9; }
.nav-settings,
.nav-password { background-color: #2C5F2D; }
.nav-logout   { background-color: #DC3545; }
.nav-login    { background-color: #28A745; }

.app-badge {
    min-width: 1.35em;
    padding: 0 .35em;
    border-radius: 999px;
    background: var(--app-accent);
    color: #fff;
    font-size: .72rem;
    font-weight: 700;
    line-height: 1.35em;
    text-align: center;
}

.app-badge[hidden] {
    display: none;
}

.app-sheet-backdrop {
    display: none;
}

/* Use the whole window on a desktop. */
.app-container {
    padding-left: 1.5rem;
    padding-right: 1.5rem;
}

/* A smaller desktop or a tablet: keep the buttons on one line. */
@media (max-width: 1199.98px) {
    .app-company {
        font-size: 1.2rem;
    }

    .app-nav-link {
        padding: .4rem .6rem;
        font-size: .9rem;
    }

    .app-version {
        display: none;
    }
}

/* ---- Phone ----------------------------------------------------------------
   The same query as mobile.css and AbcShell.PHONE_QUERY.                     */

@media (max-width: 767.98px), (pointer: coarse) and (max-height: 500px) {
    .desktop-only {
        display: none !important;
    }

    /* Selectors a notch stronger than site.css's plain html/body/.card-body: the Password page
       loads site.css a second time, after this file. */
    :root {
        font-size: 16px;
        -webkit-text-size-adjust: 100%;
    }

    body[data-signed-in] {
        background: var(--app-bg);
        color: var(--app-ink);
        font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
        height: auto;
        min-height: 100vh;
        -webkit-tap-highlight-color: transparent;
    }

    /* No double-tap zoom delay on anything you can tap. */
    a, button, input, select, textarea, label {
        touch-action: manipulation;
    }

    /* iPhone zooms the page into any field with text smaller than 16px. */
    input, select, textarea, .form-control, .form-select {
        font-size: 16px !important;
    }

    /* Top bar. Sticky makes it a stacking context at 1030: the tab bar, More sheet and backdrop
       inside it all stack there. A page drawn over it (History's open order, 1035) would hide the
       More sheet, so while More is open the whole header lifts above that (app-shell.js). */
    .app-header {
        position: sticky;
        top: 0;
        z-index: 1030;
        margin-bottom: 0;
        padding-top: var(--app-safe-top);
        box-shadow: none;
    }

    .more-open .app-header {
        z-index: 1045;
    }

    .app-header-inner {
        min-height: var(--app-topbar-h);
        flex-wrap: wrap;
        gap: .25rem .75rem;
        padding: .4rem calc(1rem + var(--app-safe-right)) .4rem calc(1rem + var(--app-safe-left));
    }

    .app-company {
        order: 2;
        color: var(--app-muted);
        font-family: inherit;
        font-size: .75rem;
        font-weight: 600;
        letter-spacing: .02em;
        text-transform: uppercase;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .app-outlet {
        font-size: 1.05rem;
        font-weight: 700;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .app-brand {
        display: flex;
        flex-direction: column;
        flex: 1 1 0;
    }

    .is-signed-out .app-company {
        order: 0;
        color: darkred;
        font-size: 1rem;
        text-transform: none;
    }

    /* Signed out there is nothing to navigate to: the page is the sign-in form. */
    .app-nav-signed-out {
        display: none;
    }

    .app-store-slot {
        flex: 0 1 auto;
        max-width: 50%;
        font-size: .9rem;
    }

    /* Bottom tab bar. */
    .is-signed-in .app-nav {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 1030;
        flex-wrap: nowrap;
        gap: 0;
        height: calc(var(--app-tabbar-h) + var(--app-safe-bottom));
        padding: 0 var(--app-safe-right) var(--app-safe-bottom) var(--app-safe-left);
        background: var(--app-surface);
        border-top: 1px solid var(--app-line);
    }

    .is-signed-in .app-nav > .app-nav-link {
        position: relative;
        flex: 1 1 0;
        flex-direction: column;
        justify-content: center;
        gap: 3px;
        height: var(--app-tabbar-h);
        padding: 0;
        border-radius: 0;
        background: none;
        color: var(--app-muted);
        font-size: 11px;
        font-weight: 600;
        filter: none;
        box-shadow: none;
    }

    .is-signed-in .app-nav > .app-nav-link i {
        font-size: 20px;
    }

    .is-signed-in .app-nav > .app-nav-link.active,
    .is-signed-in .app-nav > .app-more-toggle[aria-expanded="true"] {
        color: var(--app-brand);
    }

    .is-signed-in .app-nav > .app-nav-link.active i {
        color: var(--app-accent);
    }

    /* The order count rides on the cart icon. */
    .is-signed-in .app-nav > .app-nav-link .app-badge {
        position: absolute;
        top: 5px;
        left: calc(50% + 6px);
    }

    /* More sheet: version, Password/Settings, Logout. */
    .app-nav-more {
        display: none;
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 1050;
        padding: .75rem calc(1rem + var(--app-safe-right)) calc(1rem + var(--app-safe-bottom)) calc(1rem + var(--app-safe-left));
        background: var(--app-surface);
        border-radius: 16px 16px 0 0;
        box-shadow: 0 -8px 30px rgba(0, 0, 0, .18);
    }

    .app-nav-more.is-open {
        display: flex;
        flex-direction: column;
        gap: .5rem;
    }

    .app-nav-more::before {
        content: "";
        align-self: center;
        width: 36px;
        height: 5px;
        margin-bottom: .25rem;
        border-radius: 3px;
        background: #c9ccd6;
    }

    .app-nav-more .app-version {
        display: block;
        order: 10;
        margin: .25rem 0 0;
        text-align: center;
    }

    .app-nav-more .app-nav-link {
        justify-content: flex-start;
        gap: .9rem;
        min-height: 52px;
        padding: 0 1rem;
        border-radius: 12px;
        font-size: 1.05rem;
    }

    .app-nav-more .app-nav-link i {
        width: 1.25rem;
        text-align: center;
    }

    .app-sheet-backdrop:not([hidden]) {
        display: block;
        position: fixed;
        inset: 0;
        z-index: 1040;
        background: rgba(15, 18, 35, .4);
    }

    /* Room for the tab bar under the last thing on every page. */
    .app-container {
        padding: .75rem calc(.75rem + var(--app-safe-right)) 0 calc(.75rem + var(--app-safe-left));
    }

    .is-signed-in .app-main {
        padding-bottom: calc(var(--app-tabbar-h) + var(--app-safe-bottom) + 1rem) !important;
    }

    /* Cards look like app panels: no photo behind them, rounded, no heavy shadow. */
    .card {
        border: 0;
        border-radius: 14px;
        box-shadow: 0 1px 2px rgba(20, 23, 40, .06);
    }

    .card-header {
        background: transparent !important;
        border-bottom: 1px solid var(--app-line);
    }

    /* site.css caps these for the desktop's full-height screens; a phone scrolls the page instead. */
    .app-main .card-body,
    .app-main .table-container {
        max-height: none;
        overflow: visible;
    }

    .btn {
        min-height: 44px;
    }

    .btn-sm {
        min-height: 38px;
    }

    #toastContainer {
        top: auto;
        bottom: calc(var(--app-tabbar-h) + var(--app-safe-bottom) + 1rem);
        transform: translateX(-50%);
        width: calc(100% - 2rem);
    }

    .toast {
        min-width: 0;
        width: 100%;
    }

    /* toastr (window.showToast) slides in from the top; keep it below the top bar. */
    #toast-container.toast-top-center {
        top: calc(var(--app-topbar-h) + var(--app-safe-top) + .5rem);
    }

    #toast-container > div {
        width: calc(100vw - 2rem);
    }
}

/* ---- Quantity stepper (both layouts) --------------------------------------
   <div class="qty-stepper"><button data-step="-1">..<input>..<button data-step="1"></div>
   app-shell.js handles the buttons.                                          */

.qty-stepper {
    display: inline-flex;
    align-items: stretch;
    border: 1px solid var(--app-line);
    border-radius: 10px;
    background: #fff;
    overflow: hidden;
}

.qty-stepper button {
    width: 40px;
    min-height: 40px;
    border: 0;
    background: #f5f6fa;
    color: var(--app-brand);
    font-size: 1rem;
}

.qty-stepper button:disabled {
    color: #b9bdca;
}

.qty-stepper input {
    width: 3.5rem;
    border: 0;
    border-left: 1px solid var(--app-line);
    border-right: 1px solid var(--app-line);
    text-align: center;
    font-weight: 700;
    color: var(--app-ink);
    -moz-appearance: textfield;
    appearance: textfield;
}

.qty-stepper input::-webkit-outer-spin-button,
.qty-stepper input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

@media (prefers-reduced-motion: reduce) {
    .app-nav-link {
        transition: none;
    }
}
