/*
 * Native-app feel for the dashboard, product, existing-bill and billing pages.
 * Linked from: login, index, view/add/edit_product, exist_billing,
 * offline_exist_billing, retail-billing, restaurant-billing.
 *
 * 1. Page-to-page transitions (all browsers that support them; others ignore it).
 * 2. Touch behaviour on phones/tablets: html.wider-touch is set by
 *    fragments/shell.html when the main pointer is coarse (a finger), so a
 *    desktop with a mouse never gets any of this.
 * 3. Touch-sized controls on the ADMIN layout only (body.layout-top-nav). The
 *    billing screens have their own sizing in billing-css/touch-pos.css.
 */

/* ---------- 1. Page transitions ----------
   Same-origin navigations between two pages that both opt in cross-fade
   instead of flashing white. The old <meta name="view-transition"> on the
   billing pages was Chrome's early syntax and no longer does anything. */
@view-transition {
    navigation: auto;
}
::view-transition-old(root),
::view-transition-new(root) {
    animation-duration: 160ms;
    animation-timing-function: ease-out;
}
@media (prefers-reduced-motion: reduce) {
    @view-transition {
        navigation: none;
    }
}

/* ---------- 2. Touch behaviour (any page that links this file) ---------- */
html.wider-touch {
    -webkit-tap-highlight-color: transparent;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}
/* No 300ms double-tap-zoom wait before a tap counts */
html.wider-touch a,
html.wider-touch button,
html.wider-touch input,
html.wider-touch select,
html.wider-touch textarea,
html.wider-touch label,
html.wider-touch [role="button"],
html.wider-touch .btn {
    touch-action: manipulation;
}
/* Visible press state - a tap should feel like it landed */
html.wider-touch .btn:active:not(:disabled),
html.wider-touch button:active:not(:disabled),
html.wider-touch [role="button"]:active {
    filter: brightness(0.92);
}
/* Momentum scrolling in every scroll box */
html.wider-touch .table-responsive,
html.wider-touch .modal-body,
html.wider-touch .dropdown-menu {
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

/* ---------- Phones: list tables as cards ----------
   Opt-in tables (data-mobile-cards) are labelled by js/common/responsive-tables.js. */
@media (max-width: 640px) {
    table[data-mobile-cards] thead {
        display: none !important;
    }
    table[data-mobile-cards],
    table[data-mobile-cards] tbody {
        display: block !important;
        width: 100% !important;
        border: 0 !important;
        background: transparent !important;
    }
    table[data-mobile-cards] tbody tr {
        display: block;
        margin: 0 0 10px;
        padding: 10px 12px;
        background: #fff !important;
        border: 1px solid #e5e7eb;
        border-radius: 12px;
        box-shadow: 0 1px 3px rgba(17, 24, 39, 0.06);
    }
    table[data-mobile-cards] tbody td {
        display: flex !important;
        justify-content: space-between;
        align-items: center;
        gap: 12px;
        padding: 6px 0 !important;
        border: 0 !important;
        border-bottom: 1px dashed #f1f5f9 !important;
        text-align: right !important;
        white-space: normal !important;
        word-break: break-word;
        background: transparent !important;
    }
    table[data-mobile-cards] tbody td:last-child {
        border-bottom: 0 !important;
    }
    table[data-mobile-cards] tbody td[data-label]::before {
        content: attr(data-label);
        flex: 0 0 42%;
        text-align: left;
        font-weight: 600;
        font-size: 0.8rem;
        color: #6b7280;
    }
    table[data-mobile-cards] tbody td[data-label=""]::before {
        content: none;
    }
    /* "No data" / loading rows span the whole table: keep them centred */
    table[data-mobile-cards] tbody td:only-child {
        display: block !important;
        text-align: center !important;
    }
    table[data-mobile-cards] tbody td.d-none,
    table[data-mobile-cards] tbody td[hidden] {
        display: none !important;
    }
    /* Cards scroll with the page, like an app list - not inside a fixed-height
       box (view_product's frozen-header wrapper; its header is hidden here). */
    .product-table-scroll-wrapper:has(table[data-mobile-cards]),
    .table-responsive:has(table[data-mobile-cards]) {
        max-height: none !important;
        overflow: visible !important;
    }
}

/* 7"-10" tablets: a page's title row (title + search + selectors) was squeezed
   into one line, wrapping the title word by word. Title gets its own line. */
@media (min-width: 576px) and (max-width: 991.98px) {
    body.layout-top-nav .content-header > .d-sm-flex {
        flex-wrap: wrap;
    }
    body.layout-top-nav .content-header > .d-sm-flex > .me-auto {
        flex: 0 0 100%;
    }
}

/* Large monitors: the restaurant item grid stopped at 4 columns of very wide
   cards; show as many ~170px+ cards per row as fit, like a POS app. */
@media (min-width: 1600px) {
    .restaurant-mode #productContainer {
        grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)) !important;
    }
}

/* Short screens (phone sideways): the dashboard's floating "Server" chip
   covered the module tiles. */
@media (max-height: 560px) {
    .backend-url-overlay {
        display: none !important;
    }
}

/* ---------- 3. Admin layout: finger-sized controls ----------
   44px is the minimum comfortable touch target (Apple HIG / Material: 44-48).
   16px text in fields stops iPhone/Safari zooming the page on every focus.
   !important is needed: own.css and style.css already size these for touch
   screens with !important (14px text, 40px fields); these selectors are more
   specific, so they win among the !important rules. */
html.wider-touch body.layout-top-nav .btn:not(.btn-close) {
    min-height: 44px !important;
    min-width: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
}
/* Small buttons and table-row controls: 40px (own.css's touch size) so dense
   rows stay readable - the rule only ever raises a size, never lowers it. */
html.wider-touch body.layout-top-nav table .btn:not(.btn-close),
html.wider-touch body.layout-top-nav .btn-sm:not(.btn-close),
html.wider-touch body.layout-top-nav .btn-xs:not(.btn-close) {
    min-height: 40px !important; /* never below own.css's touch size */
    min-width: 40px;
}
html.wider-touch body.layout-top-nav .form-control,
html.wider-touch body.layout-top-nav .form-select,
html.wider-touch body.layout-top-nav select,
html.wider-touch body.layout-top-nav textarea,
html.wider-touch body.layout-top-nav input[type="text"],
html.wider-touch body.layout-top-nav input[type="number"],
html.wider-touch body.layout-top-nav input[type="email"],
html.wider-touch body.layout-top-nav input[type="tel"],
html.wider-touch body.layout-top-nav input[type="search"],
html.wider-touch body.layout-top-nav input[type="password"],
html.wider-touch body.layout-top-nav input[type="date"] {
    font-size: 16px !important; /* own.css/style.css force 14px with !important on touch screens */
}
html.wider-touch body.layout-top-nav .form-control:not(textarea),
html.wider-touch body.layout-top-nav .form-select,
html.wider-touch body.layout-top-nav select:not([multiple]) {
    min-height: 44px !important;
}
html.wider-touch body.layout-top-nav table .form-control:not(textarea),
html.wider-touch body.layout-top-nav table select:not([multiple]) {
    min-height: 40px !important; /* never below own.css's touch size */
}
html.wider-touch body.layout-top-nav .select2-container .select2-selection--single {
    min-height: 44px !important;
    display: flex;
    align-items: center;
}
/* Checkboxes and radios: bigger to hit */
html.wider-touch body.layout-top-nav input[type="checkbox"],
html.wider-touch body.layout-top-nav input[type="radio"] {
    min-width: 20px;
    min-height: 20px;
}
/* Pagination, dropdown items, menu links */
html.wider-touch body.layout-top-nav .page-link {
    min-width: 44px;
    min-height: 44px !important;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
html.wider-touch body.layout-top-nav .dropdown-item {
    padding-top: 0.7rem;
    padding-bottom: 0.7rem;
}
html.wider-touch body.layout-top-nav .main-nav .sm a,
html.wider-touch body.layout-top-nav .main-nav .nav-link {
    min-height: 44px !important;
    display: flex;
    align-items: center;
}
