/* =============================================================================
   PWA CHROME
   =============================================================================
   Only the pieces that exist because the app can be installed: the topbar
   install button, the offline pill, the "new version" bar and the
   add-to-home-screen sheet. Everything reuses the design tokens in style.css.

   Contents
     1. Install button
     2. Offline pill
     3. Update bar
     4. Install sheet
   ============================================================================= */

/* -----------------------------------------------------------------------------
   1. Install button
   -------------------------------------------------------------------------- */
.pwa-install-btn[hidden] { display: none !important; }

/* A quiet cue that the button is an app action rather than another shortcut. */
.pwa-install-btn {
    position: relative;
}

.pwa-install-btn::after {
    content: "";
    position: absolute;
    top: 8px;
    right: 8px;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--brand-400);
    box-shadow: 0 0 0 2px var(--surface);
}

body.is-pwa .pwa-install-btn { display: none !important; }

/* -----------------------------------------------------------------------------
   2. Offline pill (injected into .topbar-actions)
   -------------------------------------------------------------------------- */
.pwa-offline-pill {
    display: none;
    align-items: center;
    gap: .35rem;
    height: 30px;
    padding: 0 .6rem;
    border-radius: var(--radius-pill);
    background: var(--red-50);
    color: var(--red-500);
    font-size: .72rem;
    font-weight: 700;
    letter-spacing: .01em;
    white-space: nowrap;
}

body.is-offline .pwa-offline-pill { display: inline-flex; }

.pwa-offline-pill::before {
    content: "";
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
}

@media screen and (max-width: 480px) {
    .pwa-offline-pill { display: none !important; }
}

/* -----------------------------------------------------------------------------
   3. Update bar
   -------------------------------------------------------------------------- */
.pwa-update {
    position: fixed;
    left: 1rem;
    right: 1rem;
    bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
    z-index: 1380;
    display: flex;
    align-items: center;
    gap: .65rem;
    max-width: 26rem;
    margin: 0 auto;
    padding: .6rem .6rem .6rem .85rem;
    border-radius: var(--radius);
    background: var(--sidebar-bg);
    color: #fff;
    box-shadow: var(--shadow-lg);
    animation: pwaRise .22s cubic-bezier(.4, 0, .2, 1);
}

.pwa-update__text {
    flex: 1 1 auto;
    min-width: 0;
    font-size: .82rem;
    line-height: 1.35;
}

.pwa-update__action {
    flex: 0 0 auto;
    min-height: 34px;
    padding: 0 .75rem;
    border: 0;
    border-radius: var(--radius-sm);
    background: #fff;
    color: var(--sidebar-bg);
    font-family: inherit;
    font-size: .8rem;
    font-weight: 700;
    cursor: pointer;
}

.pwa-update__action:hover { background: var(--brand-50); }

.pwa-update__close {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    padding: 0;
    border: 0;
    border-radius: var(--radius-sm);
    background: transparent;
    color: rgba(255, 255, 255, .65);
    font-size: 1.1rem;
    line-height: 1;
    cursor: pointer;
}

.pwa-update__close:hover { color: #fff; }

@media screen and (max-width: 992px) {
    .pwa-update {
        bottom: calc(var(--bottom-nav-height, 62px) + .75rem + env(safe-area-inset-bottom, 0px));
    }
}

/* The POS keeps the bottom edge for its checkout bar. */
body.pos-page .pwa-update {
    bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
}

@keyframes pwaRise {
    from { opacity: 0; transform: translateY(10px); }
    to   { opacity: 1; transform: none; }
}

/* -----------------------------------------------------------------------------
   4. Install sheet
   -------------------------------------------------------------------------- */
.pwa-sheet {
    position: fixed;
    inset: 0;
    z-index: 1400;
    display: flex;
    align-items: flex-end;
    justify-content: center;
}

.pwa-sheet__backdrop {
    position: absolute;
    inset: 0;
    background: rgba(6, 36, 90, .48);
    animation: pwaFade .18s ease;
}

.pwa-sheet__panel {
    position: relative;
    width: 100%;
    max-width: 27rem;
    max-height: 88vh;
    overflow-y: auto;
    padding: 1.1rem 1.15rem calc(1.15rem + env(safe-area-inset-bottom, 0px));
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    background: var(--surface);
    box-shadow: var(--shadow-lg);
    animation: pwaSheetIn .22s cubic-bezier(.4, 0, .2, 1);
}

.pwa-sheet__head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: .75rem;
    margin-bottom: .35rem;
}

.pwa-sheet__title {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 700;
    letter-spacing: -.01em;
    color: var(--text);
}

.pwa-sheet__close {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    margin: -.25rem -.25rem 0 0;
    padding: 0;
    border: 0;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--muted);
    font-size: 1.2rem;
    line-height: 1;
    cursor: pointer;
}

.pwa-sheet__close:hover { background: var(--surface-hover); color: var(--text); }

.pwa-sheet__body {
    margin: 0 0 1rem;
    color: var(--text-soft);
    font-size: .88rem;
    line-height: 1.6;
}

.pwa-sheet__steps {
    margin: 0 0 1.1rem;
    padding: 0;
    list-style: none;
    counter-reset: pwa-step;
}

.pwa-sheet__steps li {
    position: relative;
    counter-increment: pwa-step;
    padding: .55rem 0 .55rem 2.1rem;
    border-top: 1px solid var(--border);
    color: var(--text);
    font-size: .88rem;
    line-height: 1.5;
}

.pwa-sheet__steps li::before {
    content: counter(pwa-step);
    position: absolute;
    left: 0;
    top: .55rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.45rem;
    height: 1.45rem;
    border-radius: 50%;
    background: var(--brand-50);
    color: var(--brand-600);
    font-size: .74rem;
    font-weight: 700;
}

.pwa-sheet__steps kbd {
    display: inline-block;
    padding: .05rem .35rem;
    border: 1px solid var(--border-strong);
    border-bottom-width: 2px;
    border-radius: 5px;
    background: var(--surface-tint);
    color: var(--text);
    font-family: inherit;
    font-size: .8em;
    font-weight: 600;
}

.pwa-sheet__action {
    width: 100%;
    min-height: 46px;
}

@keyframes pwaFade {
    from { opacity: 0; }
    to   { opacity: 1; }
}

@keyframes pwaSheetIn {
    from { transform: translateY(100%); }
    to   { transform: none; }
}

@media screen and (min-width: 640px) {
    .pwa-sheet { align-items: center; }

    .pwa-sheet__panel {
        border-radius: var(--radius-lg);
        animation: pwaDialogIn .18s cubic-bezier(.4, 0, .2, 1);
    }

    @keyframes pwaDialogIn {
        from { opacity: 0; transform: translateY(8px) scale(.98); }
        to   { opacity: 1; transform: none; }
    }
}

@media (prefers-reduced-motion: reduce) {
    .pwa-update,
    .pwa-sheet__backdrop,
    .pwa-sheet__panel { animation: none; }
}
