:root {
    --ily-pwa-accent: #4f46e5;
    --ily-pwa-bg: #f8fafc;
    --ily-pwa-text: #0f172a;
    --ily-pwa-muted: #64748b;
    --ily-safe-top: env(safe-area-inset-top, 0px);
    --ily-safe-right: env(safe-area-inset-right, 0px);
    --ily-safe-bottom: env(safe-area-inset-bottom, 0px);
    --ily-safe-left: env(safe-area-inset-left, 0px);
}

html.pwa-standalone,
html.pwa-standalone body {
    min-height: 100%;
    background: var(--ily-pwa-bg);
    overscroll-behavior-y: none;
}

html.pwa-standalone body {
    padding-left: var(--ily-safe-left);
    padding-right: var(--ily-safe-right);
}

html.pwa-standalone main {
    -webkit-overflow-scrolling: touch;
}

html.pwa-ios.pwa-standalone body {
    padding-top: var(--ily-safe-top);
}

html.pwa-standalone button,
html.pwa-standalone a,
html.pwa-standalone input,
html.pwa-standalone select,
html.pwa-standalone textarea {
    -webkit-tap-highlight-color: transparent;
}

#ily-pwa-sheet-backdrop,
#ily-pwa-update-backdrop {
    position: fixed;
    inset: 0;
    z-index: 9997;
    background: rgba(15, 23, 42, .42);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

.ily-pwa-sheet {
    position: fixed;
    left: 10px;
    right: 10px;
    bottom: calc(10px + var(--ily-safe-bottom));
    z-index: 9998;
    max-width: 560px;
    margin: 0 auto;
    overflow: hidden;
    border: 1px solid #e2e8f0;
    border-radius: 24px;
    background: rgba(255, 255, 255, .98);
    box-shadow: 0 24px 70px rgba(15, 23, 42, .25);
}

.ily-pwa-sheet__handle {
    width: 42px;
    height: 4px;
    margin: 9px auto 0;
    border-radius: 999px;
    background: #cbd5e1;
}

.ily-pwa-sheet__body {
    padding: 16px;
}

.ily-pwa-sheet__header {
    display: flex;
    gap: 12px;
    align-items: flex-start;
}

.ily-pwa-sheet__icon {
    width: 52px;
    height: 52px;
    flex: 0 0 auto;
    border-radius: 15px;
    box-shadow: 0 8px 24px rgba(79, 70, 229, .16);
}

.ily-pwa-sheet__title {
    margin: 1px 0 0;
    color: var(--ily-pwa-text);
    font: 800 15px/1.3 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.ily-pwa-sheet__text {
    margin-top: 5px;
    color: var(--ily-pwa-muted);
    font: 400 12px/1.5 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.ily-pwa-sheet__close {
    margin-left: auto;
    border: 0;
    border-radius: 10px;
    background: #f1f5f9;
    color: #64748b;
    width: 34px;
    height: 34px;
    cursor: pointer;
    font-size: 20px;
    line-height: 1;
}

.ily-pwa-steps {
    display: grid;
    gap: 8px;
    margin-top: 14px;
}

.ily-pwa-step {
    display: flex;
    gap: 10px;
    align-items: center;
    padding: 10px 12px;
    border: 1px solid #e2e8f0;
    border-radius: 14px;
    background: #f8fafc;
    color: #334155;
    font: 600 12px/1.35 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.ily-pwa-step__n {
    display: inline-flex;
    width: 24px;
    height: 24px;
    flex: 0 0 auto;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    background: #eef2ff;
    color: #4f46e5;
    font-weight: 800;
}

.ily-pwa-primary {
    width: 100%;
    margin-top: 13px;
    border: 0;
    border-radius: 14px;
    background: var(--ily-pwa-accent);
    color: #fff;
    padding: 12px 14px;
    cursor: pointer;
    font: 800 12px/1.2 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.ily-pwa-secondary {
    width: 100%;
    margin-top: 8px;
    border: 1px solid #e2e8f0;
    border-radius: 14px;
    background: #fff;
    color: #475569;
    padding: 11px 14px;
    cursor: pointer;
    font: 700 12px/1.2 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

#ily-pwa-update-toast {
    position: fixed;
    left: 12px;
    right: 12px;
    bottom: calc(12px + var(--ily-safe-bottom));
    z-index: 9999;
    max-width: 520px;
    margin: 0 auto;
    padding: 13px;
    border: 1px solid #c7d2fe;
    border-radius: 18px;
    background: #fff;
    box-shadow: 0 18px 50px rgba(15, 23, 42, .2);
}

#ily-pwa-update-toast strong {
    display: block;
    color: #1e293b;
    font: 800 13px/1.3 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

#ily-pwa-update-toast p {
    margin: 4px 0 0;
    color: #64748b;
    font: 400 11px/1.45 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

#ily-pwa-update-toast .actions {
    display: flex;
    gap: 8px;
    margin-top: 10px;
}

#ily-pwa-update-toast button {
    flex: 1;
    border-radius: 11px;
    padding: 9px 10px;
    cursor: pointer;
    font: 800 11px/1.2 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

#ily-pwa-update-toast [data-pwa-update] {
    border: 0;
    background: #4f46e5;
    color: #fff;
}

#ily-pwa-update-toast [data-pwa-update-later] {
    border: 1px solid #e2e8f0;
    background: #fff;
    color: #64748b;
}

@media (max-width: 767px) {
    html.pwa-standalone .ily-clean-page {
        padding-bottom: calc(18px + var(--ily-safe-bottom));
    }

    html.pwa-standalone main > div {
        padding-left: 12px;
        padding-right: 12px;
    }
}


/* PWA v3: top-right logout stays accessible on narrow screens */
@media (max-width: 767px) {
    header[role="banner"],
    body > div header {
        padding-right: max(10px, var(--ily-safe-right));
    }

    [data-logout-form] button {
        width: 42px;
        min-width: 42px;
        padding-left: 0;
        padding-right: 0;
    }
}
