/* ===== Installed-app page features (partials/pwa/standalone-scripts) =====
   The header refresh control, the pull-to-refresh / notice pill, and the
   "keep the screen on" toggle and chip (public/js/pwa-standalone.js).
   Colours come from the --bb-* tokens in modern-theme.css, which already
   switch under html.dark-theme, so there is no separate dark palette. */

/* ===== Header refresh control =====
   A <button> now, styled like the header's other round icon links. */
.top-header .navbar .pwa-refresh-trigger {
    background: none;
    border: 0;
    padding: 0;
    cursor: pointer;
}

.pwa-refresh-trigger[aria-busy="true"] {
    opacity: 0.65;
}

/* ===== Pull-to-refresh and notice pill =====
   Fixed just under the header (which grows by the status-bar inset in the
   installed app, mobile-polish.css section 5). --bb-ptr-pull is how far it
   has been pulled; at 0 it sits tucked away above its resting place. Above
   the header and page content, below the tab bar (1040), modals and
   SweetAlert, so a dialog always wins. Never takes taps. */
.bb-ptr {
    position: fixed;
    top: calc(60px + env(safe-area-inset-top, 0px));
    left: 50%;
    z-index: 1036;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    max-width: calc(100vw - 32px);
    padding: 0.4rem 0.9rem;
    border: 1px solid var(--bb-border, #e2e8f0);
    border-radius: var(--bb-radius-pill, 999px);
    background: var(--bb-surface, #fff);
    color: var(--bb-text, #0f172a);
    box-shadow: var(--bb-shadow-lg, 0 10px 24px -8px rgba(15, 23, 42, 0.14));
    font-size: var(--bb-fs-sm, 0.8125rem);
    font-weight: 600;
    line-height: 1.3;
    white-space: nowrap;
    direction: rtl;
    pointer-events: none;
    opacity: 0;
    transform: translate(-50%, calc(var(--bb-ptr-pull, 0px) - 100% - 12px));
    transition: transform 0.2s ease, opacity 0.2s ease;
}

.bb-ptr.is-visible {
    opacity: 1;
}

/* Follows the finger directly while pulling */
.bb-ptr.is-pulling {
    transition: opacity 0.2s ease;
}

.bb-ptr__icon {
    font-size: 1rem;
    line-height: 1;
    color: var(--bb-primary, #0f766e);
    transition: transform 0.2s ease;
}

.bb-ptr__label {
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Past the threshold the arrow turns: release refreshes */
.bb-ptr.is-armed .bb-ptr__icon {
    transform: rotate(180deg);
}

.bb-ptr.is-busy .bb-ptr__icon {
    animation: bb-ptr-spin 0.8s linear infinite;
}

.bb-ptr.is-notice .bb-ptr__icon {
    color: var(--bb-warning, #d97706);
}

@keyframes bb-ptr-spin {
    to {
        transform: rotate(360deg);
    }
}

/* ===== "Keep the screen on" toggle =====
   Sits in each board's own toolbar, with that toolbar's button classes. */
.bb-wake-toggle {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    white-space: nowrap;
}

.bb-wake-toggle.is-on {
    font-weight: 700;
    box-shadow: inset 0 0 0 2px currentColor;
}

/* Phones: icon only (the label stays for screen readers, the title explains) */
@media (max-width: 575.98px) {
    .bb-wake-toggle__label {
        position: absolute;
        width: 1px;
        height: 1px;
        margin: -1px;
        padding: 0;
        overflow: hidden;
        clip: rect(0, 0, 0, 0);
        white-space: nowrap;
        border: 0;
    }
}

/* ===== Chip shown while the screen is actually being kept on =====
   Bottom corner on the inline-start side (right in RTL), clear of the
   accessibility button on the left, and above the tab bar (--pwa-nav-h,
   0px when there is none) or the home indicator. */
.bb-wake-chip {
    position: fixed;
    inset-inline-start: 12px;
    bottom: calc(max(var(--pwa-nav-h, 0px), env(safe-area-inset-bottom, 0px)) + 12px);
    z-index: 1039;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding-block: 0.25rem;
    padding-inline: 0.8rem 0.25rem;
    border: 1px solid var(--bb-border, #e2e8f0);
    border-radius: var(--bb-radius-pill, 999px);
    background: var(--bb-surface, #fff);
    color: var(--bb-text, #0f172a);
    box-shadow: var(--bb-shadow-lg, 0 10px 24px -8px rgba(15, 23, 42, 0.14));
    font-size: var(--bb-fs-sm, 0.8125rem);
    font-weight: 600;
    direction: rtl;
}

.bb-wake-chip[hidden] {
    display: none;
}

.bb-wake-chip__icon {
    color: var(--bb-warning, #d97706);
}

.bb-wake-chip__off {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 36px;
    min-height: 36px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: var(--bb-surface-3, #f1f5f9);
    color: var(--bb-text-muted, #64748b);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.bb-wake-chip__off:focus-visible {
    outline: 2px solid var(--bb-primary, #0f766e);
    outline-offset: 2px;
}

@media print {
    .bb-ptr,
    .bb-wake-chip,
    .bb-wake-toggle {
        display: none !important;
    }
}

@media (prefers-reduced-motion: reduce) {
    .bb-ptr,
    .bb-ptr.is-pulling,
    .bb-ptr__icon {
        transition: none;
    }

    .bb-ptr.is-busy .bb-ptr__icon,
    .pwa-refresh-trigger .bx-spin,
    #pwa-refresh-btn .bx-spin {
        -webkit-animation: none;
        animation: none;
    }
}
