/* ==========================================================================
   Wetontine PWA: runtime UI, standalone tweaks and mobile responsiveness
   ========================================================================== */

:root {
    --pwa-brand: #2c3e50;
    --pwa-accent: #1abc9c;
    --pwa-danger: #e74c3c;
    --pwa-warning: #f39c12;
    --pwa-success: #27ae60;
    --pwa-safe-top: env(safe-area-inset-top, 0px);
    --pwa-safe-right: env(safe-area-inset-right, 0px);
    --pwa-safe-bottom: env(safe-area-inset-bottom, 0px);
    --pwa-safe-left: env(safe-area-inset-left, 0px);
    --pwa-bottom-nav-height: 60px;
}

/* ---------- Touch behaviour ---------- */
html {
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0.05);
    -webkit-text-size-adjust: 100%;
}

body {
    overscroll-behavior-y: none;
}

[hidden] {
    display: none !important;
}

/* iOS zooms into inputs smaller than 16px on focus */
@media (max-width: 767.98px) {
    input.form-control,
    select.form-control,
    textarea.form-control,
    .select2-container .select2-selection,
    .select2-search__field {
        font-size: 16px !important;
    }
}

/* ---------- Toasts ---------- */
.pwa-toast-stack {
    position: fixed;
    z-index: 100000;
    right: calc(16px + var(--pwa-safe-right));
    bottom: calc(16px + var(--pwa-safe-bottom));
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-width: min(420px, calc(100vw - 32px));
}

.pwa-standalone body.has-bottom-nav .pwa-toast-stack,
body.has-bottom-nav .pwa-toast-stack {
    bottom: calc(var(--pwa-bottom-nav-height) + 16px + var(--pwa-safe-bottom));
}

.pwa-toast {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 12px 12px 16px;
    border-radius: 10px;
    background: #fff;
    color: #333;
    font-size: 14px;
    line-height: 1.4;
    box-shadow: 0 8px 28px rgba(0, 0, 0, 0.18);
    border-left: 4px solid var(--pwa-brand);
    animation: pwa-slide-in 0.2s ease-out;
}

.pwa-toast-success { border-left-color: var(--pwa-success); }
.pwa-toast-warning { border-left-color: var(--pwa-warning); }
.pwa-toast-danger { border-left-color: var(--pwa-danger); }

.pwa-toast-text { flex: 1; word-break: break-word; }
.pwa-toast-actions { display: flex; align-items: center; gap: 4px; flex-shrink: 0; }

.pwa-toast-close {
    appearance: none;
    border: 0;
    background: transparent;
    font-size: 22px;
    line-height: 1;
    color: #888;
    cursor: pointer;
    padding: 0 4px;
    min-width: 32px;
    min-height: 32px;
}

.pwa-btn {
    appearance: none;
    border: 0;
    border-radius: 6px;
    padding: 7px 12px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
}

.pwa-btn-primary { background: var(--pwa-brand); color: #fff; }
.pwa-btn-link { background: transparent; color: var(--pwa-brand); }

@keyframes pwa-slide-in {
    from { transform: translateY(12px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

@media (max-width: 575.98px) {
    .pwa-toast-stack {
        left: calc(12px + var(--pwa-safe-left));
        right: calc(12px + var(--pwa-safe-right));
        max-width: none;
    }
}

/* ---------- Bottom sheet / dialog ---------- */
.pwa-sheet-backdrop {
    position: fixed;
    inset: 0;
    z-index: 100001;
    background: rgba(0, 0, 0, 0.45);
    display: flex;
    align-items: flex-end;
    justify-content: center;
}

.pwa-sheet {
    background: #fff;
    width: 100%;
    max-width: 520px;
    max-height: 80vh;
    overflow: auto;
    border-radius: 16px 16px 0 0;
    padding-bottom: var(--pwa-safe-bottom);
    animation: pwa-slide-in 0.2s ease-out;
}

@media (min-width: 576px) {
    .pwa-sheet-backdrop { align-items: center; }
    .pwa-sheet { border-radius: 16px; }
}

.pwa-sheet-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    border-bottom: 1px solid #eee;
}

.pwa-sheet-body { padding: 16px; }

.pwa-ios-steps p { margin-bottom: 12px; }
.pwa-ios-share {
    font-size: 28px;
    text-align: center;
    color: #007aff;
}

.pwa-outbox-list { list-style: none; margin: 0; padding: 0; }
.pwa-outbox-list li {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 10px 0;
    border-bottom: 1px solid #f0f0f0;
}
.pwa-outbox-list li small { display: block; color: #888; }
.pwa-outbox-list li.is-failed small { color: var(--pwa-danger); }
.pwa-outbox-actions { display: flex; gap: 4px; }

/* ---------- Offline banner and outbox badge ---------- */
.pwa-offline-banner {
    position: fixed;
    z-index: 99999;
    left: 0;
    right: 0;
    top: 0;
    padding: calc(6px + var(--pwa-safe-top)) 16px 6px;
    background: #5d4037;
    color: #fff;
    font-size: 13px;
    text-align: center;
}

.pwa-is-offline body { padding-top: 32px; }

.pwa-is-offline form:not([data-offline-queue="true"]) [type="submit"] {
    opacity: 0.55;
}

.pwa-outbox-item { list-style: none; }

.pwa-outbox-badge {
    appearance: none;
    border: 0;
    border-radius: 999px;
    padding: 4px 12px;
    font-size: 12px;
    font-weight: 600;
    background: var(--pwa-warning);
    color: #fff;
    cursor: pointer;
}

.pwa-outbox-badge.pwa-outbox-has-failed { background: var(--pwa-danger); }

.pwa-outbox-floating {
    position: fixed;
    z-index: 9999;
    left: calc(16px + var(--pwa-safe-left));
    bottom: calc(16px + var(--pwa-safe-bottom));
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.2);
}

body.has-bottom-nav .pwa-outbox-floating {
    bottom: calc(var(--pwa-bottom-nav-height) + 16px + var(--pwa-safe-bottom));
}

/* ---------- Standalone (installed app) ---------- */
@media (display-mode: standalone) {
    body {
        padding-left: var(--pwa-safe-left);
        padding-right: var(--pwa-safe-right);
        user-select: none;
        -webkit-user-select: none;
    }

    input,
    textarea,
    [contenteditable],
    .table,
    .card-body p {
        user-select: text;
        -webkit-user-select: text;
    }

    /* Browser oriented chrome is not useful inside the installed app */
    .footer .copyright .right,
    .cookie-consent {
        display: none !important;
    }

    .header-area {
        padding-top: calc(10px + var(--pwa-safe-top));
    }
}

/* ---------- Customer bottom navigation (phones) ---------- */
.pwa-bottom-nav {
    display: none;
}

@media (max-width: 767.98px) {
    body.has-bottom-nav {
        padding-bottom: calc(var(--pwa-bottom-nav-height) + var(--pwa-safe-bottom));
    }

    .pwa-bottom-nav {
        position: fixed;
        z-index: 1030;
        left: 0;
        right: 0;
        bottom: 0;
        display: flex;
        height: calc(var(--pwa-bottom-nav-height) + var(--pwa-safe-bottom));
        padding: 0 var(--pwa-safe-right) var(--pwa-safe-bottom) var(--pwa-safe-left);
        background: #fff;
        border-top: 1px solid #e6e9ee;
        box-shadow: 0 -4px 14px rgba(0, 0, 0, 0.06);
    }

    .pwa-bottom-nav a {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 3px;
        font-size: 11px;
        color: #7a8394;
        text-decoration: none;
        min-width: 0;
    }

    .pwa-bottom-nav a i { font-size: 18px; }
    .pwa-bottom-nav a span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
    .pwa-bottom-nav a.active { color: var(--pwa-brand); font-weight: 600; }
}

/* ---------- Modals: full screen on phones ---------- */
@media (max-width: 575.98px) {
    .modal-dialog,
    .modal-dialog.modal-lg,
    .modal-dialog.modal-dialog-centered {
        max-width: 100%;
        width: 100%;
        min-height: 100%;
        margin: 0;
        align-items: stretch;
    }

    .modal-content {
        min-height: 100vh;
        min-height: 100dvh;
        border: 0;
        border-radius: 0;
        padding-top: var(--pwa-safe-top);
        padding-bottom: var(--pwa-safe-bottom);
    }

    .modal-body {
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch;
    }

    .swal2-popup {
        width: calc(100% - 24px) !important;
    }
}

#main_modal .modal-body,
#secondary_modal .modal-body {
    max-height: calc(100vh - 140px);
    max-height: calc(100dvh - 140px);
    overflow-y: auto !important;
}

@media (max-width: 575.98px) {
    #main_modal .modal-body,
    #secondary_modal .modal-body {
        max-height: none;
    }
}
