/*
 * The phone layer of the one theme (Metronic 8 or 9): the same pages, adjusted below the large breakpoint (992px, where the side menu
 * becomes a drawer) and when Ovule runs as an installed app. Loaded on every page by resources/app/Pwa.php.
 */

/* ---------------------------------------------------------------- toasts and the iPhone install sheet (every size) */
.app-pwa-toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(16px + env(safe-area-inset-bottom)); z-index: 1090;
    display: flex; align-items: center; gap: 12px; width: max-content; max-width: calc(100vw - 24px); padding: 12px 12px 12px 18px; border-radius: 12px;
    background: #181c32; color: #fff; font-size: 14px; box-shadow: 0 8px 30px rgba(0,0,0,.25); }
.app-pwa-toast button { background: transparent; border: 0; color: #ffd166; font-weight: 600; padding: 6px 8px; min-height: 36px; white-space: nowrap; }
.app-pwa-toast .app-pwa-x { color: #a1a5b7; font-size: 20px; line-height: 1; }
body.has-app-tabbar .app-pwa-toast { bottom: calc(76px + env(safe-area-inset-bottom)); }
.app-pwa-sheet { position: fixed; inset: 0; z-index: 1095; background: rgba(0,0,0,.45); display: flex; align-items: flex-end; justify-content: center; }
.app-pwa-sheet-card { background: var(--bs-body-bg, #fff); color: var(--bs-body-color, #181c32); width: 100%; max-width: 480px; border-radius: 16px 16px 0 0;
    padding: 24px 24px calc(24px + env(safe-area-inset-bottom)); font-size: 15px; }
.app-pwa-sheet-card h3 { font-size: 18px; margin-bottom: 12px; }
.app-pwa-sheet-card ol { padding-left: 20px; margin-bottom: 12px; } .app-pwa-sheet-card li { margin-bottom: 6px; }
.app-pwa-sheet-card p { color: #7e8299; font-size: 13px; }
.app-pwa-sheet-card button { width: 100%; min-height: 48px; border: 0; border-radius: 10px; background: #db1430; color: #fff; font-weight: 600; font-size: 16px; }

/* ---------------------------------------------------------------- the bottom navigation bar */
.app-tabbar { display: none; }
@media (max-width: 991.98px) {
    .app-tabbar { display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 1040; height: calc(60px + env(safe-area-inset-bottom));
        padding-bottom: env(safe-area-inset-bottom); background: var(--bs-body-bg, #fff); border-top: 1px solid var(--bs-border-color, #eff2f5);
        box-shadow: 0 -4px 16px rgba(0,0,0,.05); }
    .app-tab { flex: 1 1 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; position: relative;
        color: #7e8299; font-size: 11px; font-weight: 600; text-decoration: none; -webkit-tap-highlight-color: transparent; min-width: 0; }
    .app-tab i { font-size: 21px; line-height: 1; }
    .app-tab.active, .app-tab:active { color: var(--bs-primary, #009ef7); }
    .app-tab-badge { position: absolute; top: 6px; left: calc(50% + 6px); min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
        background: #f1416c; color: #fff; font-size: 10px; line-height: 18px; text-align: center; }
    body.has-app-tabbar { padding-bottom: calc(60px + env(safe-area-inset-bottom)) !important; }
    body.has-app-tabbar #kt_scrolltop { display: none !important; }
    /* the drawers (side menu, chat) and dropdowns sit above the bar */
    .drawer.drawer-on, .drawer-overlay { z-index: 1045 !important; }

    /* ------------------------------------------------------------ touch: bigger targets, no zoom when typing on iPhone */
    .form-control, .form-select, .input-group-text { font-size: 16px !important; min-height: 44px; }
    .form-control-sm, .form-select-sm { min-height: 40px; }
    .btn { min-height: 40px; } .btn.btn-icon { min-height: 0; }
    .btn-sm { min-height: 36px; }
    .menu-sub-dropdown .menu-link { padding-top: .75rem; padding-bottom: .75rem; }
    .table-responsive { -webkit-overflow-scrolling: touch; }
    .table td, .table th { white-space: nowrap; }
    .table td.text-wrap, .table td .text-wrap { white-space: normal; }

    /* ------------------------------------------------------------ page chrome: more room for the content */
    .toolbar .page-title h1 { font-size: 1.15rem !important; }
    #kt_footer { display: none !important; }
    .card > .card-header { min-height: 56px; }
    .card > .card-body { padding: 1.25rem; }
    .container-fluid, .container-xxl { padding-left: 12px !important; padding-right: 12px !important; }
}

/* ---------------------------------------------------------------- phones: dialogs fill the screen */
@media (max-width: 575.98px) {
    .modal-dialog:not(.modal-sm) { max-width: none !important; width: 100%; margin: 0; min-height: 100%; }
    .modal-dialog:not(.modal-sm) .modal-content { min-height: 100vh; min-height: 100dvh; border-radius: 0; border: 0; }
    .modal-dialog:not(.modal-sm) .modal-header { position: sticky; top: 0; z-index: 2; background: var(--bs-body-bg, #fff); padding-top: calc(1rem + env(safe-area-inset-top)); }
    .modal-body { padding: 1.25rem !important; }
    .modal-footer { position: sticky; bottom: 0; background: var(--bs-body-bg, #fff); padding-bottom: calc(.75rem + env(safe-area-inset-bottom)); }
}

/* ---------------------------------------------------------------- running as an installed app */
html.app-standalone body { -webkit-user-select: none; user-select: none; overscroll-behavior-y: none; }
html.app-standalone input, html.app-standalone textarea, html.app-standalone [contenteditable], html.app-standalone .table, html.app-standalone p { -webkit-user-select: text; user-select: text; }
html.app-standalone a, html.app-standalone button { -webkit-touch-callout: none; }
.app-pwa-toast > span { flex: 1 1 auto; }

/* ---------------------------------------------------------------- tables that become cards on phones (opt in: table.table-stack, td data-label) */
@media (max-width: 575.98px) {
    table.table-stack thead { display: none; }
    table.table-stack, table.table-stack tbody, table.table-stack tfoot { display: block; width: 100%; }
    table.table-stack tr { display: block; padding: .75rem 0; border-bottom: 1px dashed var(--bs-border-color, #e4e6ef); }
    table.table-stack td { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; text-align: right !important;
        padding: .2rem 0 !important; border: 0 !important; white-space: normal !important; }
    table.table-stack td::before { content: attr(data-label); color: #a1a5b7; font-weight: 600; font-size: .85rem; text-align: left; flex: 0 0 auto; }
    table.table-stack td:first-child { font-weight: 700; font-size: 1rem; text-align: left !important; justify-content: flex-start; }
    table.table-stack td:first-child::before { display: none; }
    table.table-stack td:not([data-label]):empty, table.table-stack td:not([data-label]) > .ts-v:empty { display: none; }
    table.table-stack td[colspan] { display: block; text-align: left !important; }
    table.table-stack td > .ts-v { min-width: 0; }
}

/* ---------------------------------------------------------------- customer portal */
.po-phone { display: none; }
@media (max-width: 575.98px) { .po-phone { display: block; } .po-desk { display: none; } }
@media (max-width: 767.98px) {
    #po_root .fin-tabs { flex-wrap: nowrap; overflow-x: auto; overflow-y: hidden; white-space: nowrap; scrollbar-width: none; margin-bottom: 1rem !important; }
    #po_root .fin-tabs::-webkit-scrollbar { display: none; }
    #po_root .fin-tabs .nav-link { padding-bottom: .75rem !important; }
    #po_root .po-products { max-height: none !important; overflow: visible !important; }
    #po_root .po-products input[data-qty] { min-width: 72px; font-size: 18px !important; text-align: center !important; }
    #po_root .po-sendbar { position: sticky; bottom: calc(60px + env(safe-area-inset-bottom)); z-index: 5; background: var(--bs-body-bg, #fff);
        margin: 0 -1.25rem !important; padding: 12px 1.25rem; border-top: 1px solid var(--bs-border-color, #eff2f5); box-shadow: 0 -6px 12px rgba(0,0,0,.04); }
    #po_root .po-sendbar .btn { min-height: 48px; padding-left: 1.5rem; padding-right: 1.5rem; }
}

/* ---------------------------------------------------------------- outbox: entries saved on the phone, waiting for a signal */
.app-outbox { position: fixed; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom)); z-index: 1041; border: 0; border-radius: 20px;
    padding: 8px 14px; background: #fff8dd; color: #7a5c00; font-size: 13px; font-weight: 600; box-shadow: 0 4px 14px rgba(0,0,0,.15); }
.app-outbox.app-outbox-bad { background: #fff5f8; color: #b5174a; }
.app-outbox i { margin-right: 4px; }
body.has-app-tabbar .app-outbox { bottom: calc(70px + env(safe-area-inset-bottom)); }
.app-outbox-list { list-style: none; padding: 0; margin: 0 0 12px; max-height: 40vh; overflow: auto; }
.app-outbox-list li { display: flex; flex-direction: column; padding: 8px 0; border-bottom: 1px solid #eff2f5; font-size: 14px; }
.app-outbox-list li span { font-size: 12px; color: #7e8299; }
.app-pwa-sheet-card button + button { margin-top: 8px; }
.app-pwa-sheet-card button.app-btn-light { background: #f1f1f4; color: #252f4a; }

/* ---------------------------------------------------------------- day-end capture on phones: each product a card with its numbers in a grid */
@media (max-width: 575.98px) {
    #de_products thead { display: none; }
    #de_products, #de_products tbody { display: block; width: 100%; }
    #de_products tr[data-pid] { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px 10px; padding: 12px 0; border-bottom: 1px dashed var(--bs-border-color, #e4e6ef); }
    #de_products tr[data-pid] > td { display: block; padding: 0 !important; border: 0 !important; text-align: left !important; }
    #de_products tr[data-pid] > td:first-child { grid-column: 1 / -1; white-space: normal !important; font-size: 1rem; }
    #de_products tr[data-pid] > td[data-label]::before { content: attr(data-label); display: block; font-size: .75rem; font-weight: 600; color: #a1a5b7; margin-bottom: 2px; }
    #de_products tr[data-pid] input { width: 100%; text-align: center; font-size: 18px !important; min-height: 44px; }
    #de_products tr.de-core-missing { display: block; padding: 12px 0; }
    #de_products tr.de-core-missing td { display: block; border: 0 !important; padding: 2px 0 !important; white-space: normal !important; }
    #de_cash_a input, #de_cash_b input, [data-inc] { font-size: 18px !important; text-align: center; }
}
