/* POSQR PWA shared styles — install button, toasts, view transitions, touch polish */

/* ── View Transitions API (smooth cross-page fades) ───────────────────── */
@view-transition { navigation: auto; }

::view-transition-old(root),
::view-transition-new(root) {
    animation-duration: 260ms;
    animation-timing-function: cubic-bezier(0.32, 0.72, 0.16, 1);
}

::view-transition-old(root) {
    animation-name: pwa-fade-out;
}
::view-transition-new(root) {
    animation-name: pwa-fade-in;
}

@keyframes pwa-fade-out {
    to { opacity: 0; transform: translateY(-6px); }
}
@keyframes pwa-fade-in {
    from { opacity: 0; transform: translateY(8px); }
}

/* Skip animation if user prefers reduced motion */
@media (prefers-reduced-motion: reduce) {
    ::view-transition-old(root),
    ::view-transition-new(root) {
        animation: none !important;
    }
}

/* ── Touch polish ─────────────────────────────────────────────────────── */
html {
    -webkit-tap-highlight-color: transparent;
    overscroll-behavior-y: contain;
}
button, [role="button"], a, input[type="checkbox"], input[type="radio"] {
    -webkit-touch-callout: none;
}
body {
    -webkit-user-select: text;
    user-select: text;
}
input, textarea, select {
    font-size: 16px; /* prevents iOS zoom on focus */
}

/* Install FAB (floating action button) */
.pwa-install-fab {
    position: fixed;
    bottom: calc(env(safe-area-inset-bottom, 0px) + 18px);
    right: 18px;
    z-index: 9999;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 12px 18px;
    border: none;
    border-radius: 999px;
    background: linear-gradient(135deg, #1a73e8, #0b4ea2);
    color: #fff;
    font-family: inherit;
    font-size: 13px;
    font-weight: 700;
    box-shadow: 0 12px 30px rgba(26, 115, 232, .35), 0 4px 8px rgba(0, 0, 0, .12);
    cursor: pointer;
    backdrop-filter: blur(8px);
    transition: transform .18s cubic-bezier(0.32, 0.72, 0.16, 1), box-shadow .18s;
    animation: pwa-install-pop .5s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}
.pwa-install-fab:hover  { transform: translateY(-2px); }
.pwa-install-fab:active { transform: scale(0.96); }

@keyframes pwa-install-pop {
    from { opacity: 0; transform: translateY(20px) scale(.85); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* Hide install button when already running standalone */
.pwa-standalone .pwa-install-fab { display: none !important; }

/* ── Update available toast ───────────────────────────────────────────── */
.pwa-update-toast {
    position: fixed;
    bottom: calc(env(safe-area-inset-bottom, 0px) + 18px);
    left: 50%;
    transform: translateX(-50%);
    z-index: 10000;
    display: inline-flex;
    align-items: center;
    gap: 14px;
    padding: 12px 18px;
    background: #0f172a;
    color: #fff;
    border-radius: 16px;
    font-size: 13px;
    font-weight: 600;
    box-shadow: 0 14px 40px rgba(0, 0, 0, .35);
    animation: pwa-toast-slide-up .35s cubic-bezier(0.32, 0.72, 0.16, 1) both;
}
.pwa-update-toast-btn {
    background: #34a853;
    color: #fff;
    border: none;
    padding: 6px 14px;
    border-radius: 10px;
    font-family: inherit;
    font-weight: 700;
    font-size: 12px;
    cursor: pointer;
    transition: background .15s;
}
.pwa-update-toast-btn:hover { background: #2c8f47; }

/* ── Generic toast ────────────────────────────────────────────────────── */
.pwa-toast {
    position: fixed;
    top: calc(env(safe-area-inset-top, 0px) + 18px);
    left: 50%;
    transform: translateX(-50%) translateY(-10px);
    z-index: 10001;
    padding: 12px 22px;
    background: #0f172a;
    color: #fff;
    border-radius: 14px;
    font-size: 13px;
    font-weight: 700;
    box-shadow: 0 10px 30px rgba(0, 0, 0, .25);
    opacity: 0;
    transition: opacity .25s, transform .25s cubic-bezier(0.32, 0.72, 0.16, 1);
    pointer-events: none;
    max-width: 90vw;
    text-align: center;
}
.pwa-toast.show     { opacity: 1; transform: translateX(-50%) translateY(0); }
.pwa-toast-success  { background: #047857; }
.pwa-toast-error    { background: #b91c1c; }
.pwa-toast-info     { background: #1a73e8; }

@keyframes pwa-toast-slide-up {
    from { transform: translateX(-50%) translateY(40px); opacity: 0; }
    to   { transform: translateX(-50%) translateY(0); opacity: 1; }
}

/* ── Undo toast (with countdown ring + undo button) ──────────────────── */
.pwa-undo-toast {
    position: fixed;
    bottom: calc(env(safe-area-inset-bottom, 0px) + 18px);
    left: 50%;
    transform: translate(-50%, 20px);
    z-index: 10001;
    display: inline-flex;
    align-items: center;
    gap: 14px;
    padding: 10px 12px 10px 18px;
    background: linear-gradient(135deg, #1e293b, #0f172a);
    color: #fff;
    border-radius: 999px;
    box-shadow: 0 14px 40px rgba(0, 0, 0, .35), 0 0 0 1px rgba(255, 255, 255, .06);
    opacity: 0;
    transition: opacity .25s, transform .3s cubic-bezier(0.32, 0.72, 0.16, 1);
    max-width: 92vw;
}
.pwa-undo-toast.show { opacity: 1; transform: translate(-50%, 0); }
.pwa-undo-msg {
    font-size: 13px;
    font-weight: 700;
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
    max-width: 50vw;
}
.pwa-undo-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: rgba(255, 255, 255, .12);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, .15);
    padding: 6px 14px 6px 6px;
    border-radius: 999px;
    font-family: inherit;
    font-size: 12px;
    font-weight: 800;
    cursor: pointer;
    transition: background .15s, transform .12s;
}
.pwa-undo-btn:hover  { background: rgba(255, 255, 255, .2); }
.pwa-undo-btn:active { transform: scale(.96); }
.pwa-undo-btn:disabled { opacity: .6; cursor: wait; }
.pwa-undo-ring {
    display: inline-block;
    flex-shrink: 0;
}

/* ── Offline Sync Badge + Panel ───────────────────────────────────────── */
.pwa-sync-badge {
    position: fixed;
    bottom: calc(env(safe-area-inset-bottom, 0px) + 18px);
    left: 18px;
    z-index: 9998;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    border: none;
    border-radius: 999px;
    background: linear-gradient(135deg, #f59e0b, #d97706);
    color: #fff;
    font-family: inherit;
    font-size: 13px;
    font-weight: 800;
    box-shadow: 0 10px 28px rgba(245, 158, 11, .38), 0 2px 6px rgba(0,0,0,.1);
    cursor: pointer;
    transition: transform .15s ease, box-shadow .15s ease;
    animation: pwa-sync-pop .4s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}
.pwa-sync-badge:hover  { transform: translateY(-2px); }
.pwa-sync-badge:active { transform: scale(0.96); }
.pwa-sync-badge.hidden { display: none; }
.pwa-sync-badge[data-state="offline"] {
    background: linear-gradient(135deg, #dc2626, #991b1b);
    box-shadow: 0 10px 28px rgba(220, 38, 38, .38);
    animation: pwa-sync-pulse 2s ease-in-out infinite;
}
.pwa-sync-badge[data-state="syncing"] {
    background: linear-gradient(135deg, #2563eb, #1d4ed8);
}
.pwa-sync-badge[data-state="syncing"] .pwa-sync-icon {
    animation: pwa-spin 1s linear infinite;
}
.pwa-sync-icon { font-size: 16px; line-height: 1; }
.pwa-sync-count {
    background: rgba(255,255,255,.25);
    padding: 2px 8px;
    border-radius: 999px;
    font-variant-numeric: tabular-nums;
    font-weight: 900;
}
.pwa-sync-text { font-weight: 700; letter-spacing: .3px; }

@keyframes pwa-sync-pop {
    from { opacity: 0; transform: translateY(20px) scale(.85); }
    to   { opacity: 1; transform: translateY(0)    scale(1);   }
}
@keyframes pwa-sync-pulse {
    0%, 100% { box-shadow: 0 10px 28px rgba(220, 38, 38, .38); }
    50%      { box-shadow: 0 10px 28px rgba(220, 38, 38, .65), 0 0 0 6px rgba(220, 38, 38, .15); }
}
@keyframes pwa-spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }

/* Offline panel modal */
.pwa-offline-panel {
    position: fixed;
    inset: 0;
    z-index: 10005;
    background: rgba(15, 23, 42, .5);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding: 0;
    animation: pwa-fade-in 0.2s ease-out;
}
@media (min-width: 640px) {
    .pwa-offline-panel { align-items: center; padding: 20px; }
}
@keyframes pwa-fade-in { from { opacity: 0; } to { opacity: 1; } }

.pwa-offline-panel-card {
    background: #fff;
    color: #0f172a;
    border-radius: 24px 24px 0 0;
    max-width: 480px;
    width: 100%;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 -20px 60px rgba(0, 0, 0, .25);
    animation: pwa-panel-up 0.3s cubic-bezier(0.32, 0.72, 0.16, 1);
}
@media (min-width: 640px) {
    .pwa-offline-panel-card { border-radius: 24px; }
}
@media (prefers-color-scheme: dark) {
    .pwa-offline-panel-card { background: #1e293b; color: #f1f5f9; }
}
.dark .pwa-offline-panel-card { background: #1e293b; color: #f1f5f9; }
@keyframes pwa-panel-up {
    from { transform: translateY(30px); opacity: 0; }
    to   { transform: translateY(0); opacity: 1; }
}

.pwa-offline-panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 18px 22px 14px;
    border-bottom: 1px solid rgba(0,0,0,.08);
}
.dark .pwa-offline-panel-header { border-color: rgba(255,255,255,.08); }
.pwa-offline-panel-header h3 { margin: 0; font-size: 17px; font-weight: 800; }
.pwa-offline-panel-header p  { margin: 2px 0 0; font-size: 11px; font-weight: 700; }
.text-emerald-600 { color: #059669 !important; }
.text-amber-600   { color: #d97706 !important; }
.pwa-offline-close, .pwa-offline-close-2 {
    background: rgba(0,0,0,.05);
    border: none;
    border-radius: 999px;
    width: 32px; height: 32px;
    cursor: pointer;
    font-size: 16px;
    color: inherit;
}
.dark .pwa-offline-close { background: rgba(255,255,255,.08); }

.pwa-offline-panel-body {
    flex: 1;
    overflow-y: auto;
    padding: 8px 22px;
    min-height: 80px;
}
.pwa-offline-empty {
    text-align: center;
    padding: 40px 20px;
    color: #94a3b8;
    font-size: 13px;
    font-weight: 600;
}
.pwa-offline-row {
    padding: 12px 0;
    border-bottom: 1px dashed rgba(0,0,0,.08);
}
.dark .pwa-offline-row { border-color: rgba(255,255,255,.08); }
.pwa-offline-row:last-child { border-bottom: none; }
.pwa-offline-row-label {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 8px;
    font-size: 13px;
}
.pwa-offline-row-when {
    font-size: 10px;
    font-weight: 700;
    color: #94a3b8;
    white-space: nowrap;
}
.pwa-offline-row-meta {
    font-size: 10px;
    font-family: ui-monospace, monospace;
    color: #94a3b8;
    margin-top: 3px;
    word-break: break-all;
}

.pwa-offline-panel-footer {
    padding: 14px 22px;
    border-top: 1px solid rgba(0,0,0,.08);
    display: flex;
    gap: 10px;
}
.dark .pwa-offline-panel-footer { border-color: rgba(255,255,255,.08); }
.pwa-offline-clear {
    flex: 1;
    background: rgba(239, 68, 68, .1);
    color: #dc2626;
    border: 1px solid rgba(239, 68, 68, .3);
    border-radius: 12px;
    padding: 10px 14px;
    font-family: inherit;
    font-size: 13px;
    font-weight: 800;
    cursor: pointer;
}
.pwa-offline-sync {
    flex: 2;
    background: linear-gradient(135deg, #2563eb, #1d4ed8);
    color: #fff;
    border: none;
    border-radius: 12px;
    padding: 10px 14px;
    font-family: inherit;
    font-size: 13px;
    font-weight: 900;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(37, 99, 235, .3);
}
.pwa-offline-sync:disabled {
    background: #94a3b8;
    box-shadow: none;
    cursor: not-allowed;
}

/* ── Network status bar ───────────────────────────────────────────────── */
.pwa-net-bar {
    position: fixed;
    top: 0; left: 0; right: 0;
    z-index: 10002;
    padding: 8px 14px;
    text-align: center;
    font-size: 12px;
    font-weight: 700;
    color: #fff;
    animation: pwa-bar-slide-down .3s cubic-bezier(0.32, 0.72, 0.16, 1) both;
}
.pwa-net-bar[data-state="offline"] { background: #b45309; }
.pwa-net-bar[data-state="online"]  { background: #047857; }

@keyframes pwa-bar-slide-down {
    from { transform: translateY(-100%); }
    to   { transform: translateY(0); }
}

/* ── Standalone-mode polish ───────────────────────────────────────────── */
.pwa-standalone body {
    /* Respect safe-area on notched devices */
    padding-top:    env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
    padding-left:   env(safe-area-inset-left);
    padding-right:  env(safe-area-inset-right);
}

/* Smoother scroll on iOS PWA */
.pwa-standalone * {
    -webkit-overflow-scrolling: touch;
}

/* ── Tap ripple effect (luxurious feedback) ───────────────────────────── */
@keyframes pwa-ripple {
    to { transform: scale(2.4); opacity: 0; }
}
.pwa-ripple {
    position: absolute;
    border-radius: 50%;
    pointer-events: none;
    background: currentColor;
    opacity: .28;
    transform: scale(0);
    animation: pwa-ripple .55s cubic-bezier(0.32, 0.72, 0.16, 1);
}
