/* PWA refresh button — visible only in standalone (html.pwa-standalone set in base.html head).
   Mobile: direct .header-main child, absolute center. Desktop: flex sibling before .header-right.
   Visibility/layout use html.pwa-standalone (iOS) and display-mode media (first PWA paint). */
html.pwa-standalone {
    --pwa-refresh-c1: #1a1a1a;
    --pwa-refresh-c2: #1B5E20;
    --pwa-refresh-c3: #0055A4;
    --pwa-refresh-c4: #FFD700;
}

@media (display-mode: standalone), (display-mode: fullscreen), (display-mode: minimal-ui), (display-mode: window-controls-overlay) {
    :root {
        --pwa-refresh-c1: #1a1a1a;
        --pwa-refresh-c2: #1B5E20;
        --pwa-refresh-c3: #0055A4;
        --pwa-refresh-c4: #FFD700;
    }
}

.header-pwa-refresh-slot,
.header-icon-slot.header-pwa-refresh-slot {
    display: none;
}

html.pwa-standalone .header-pwa-refresh-slot,
html.pwa-standalone .header-icon-slot.header-pwa-refresh-slot {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 0;
}

@media (display-mode: standalone), (display-mode: fullscreen), (display-mode: minimal-ui), (display-mode: window-controls-overlay) {
    .header-pwa-refresh-slot,
    .header-icon-slot.header-pwa-refresh-slot {
        display: flex;
        align-items: center;
        justify-content: center;
        min-width: 0;
    }
}

html.pwa-standalone .header-pwa-refresh-btn {
    touch-action: manipulation;
    color: var(--pwa-refresh-c1, #1a1a1a);
}

@media (display-mode: standalone), (display-mode: fullscreen), (display-mode: minimal-ui), (display-mode: window-controls-overlay) {
    .header-pwa-refresh-btn {
        touch-action: manipulation;
        color: var(--pwa-refresh-c1, #1a1a1a);
    }
}

html.pwa-standalone .header-pwa-refresh-btn svg {
    width: 24px;
    height: 24px;
    display: block;
}

@media (display-mode: standalone), (display-mode: fullscreen), (display-mode: minimal-ui), (display-mode: window-controls-overlay) {
    .header-pwa-refresh-btn svg {
        width: 24px;
        height: 24px;
        display: block;
    }
}

html.pwa-standalone .header-pwa-refresh-btn.is-refreshing svg {
    animation: pwa-refresh-spin 0.8s linear infinite, pwa-refresh-colors 1.6s linear infinite;
}

@media (display-mode: standalone), (display-mode: fullscreen), (display-mode: minimal-ui), (display-mode: window-controls-overlay) {
    .header-pwa-refresh-btn.is-refreshing svg {
        animation: pwa-refresh-spin 0.8s linear infinite, pwa-refresh-colors 1.6s linear infinite;
    }
}

@keyframes pwa-refresh-spin {
    to {
        transform: rotate(360deg);
    }
}

@keyframes pwa-refresh-colors {
    0%, 100% {
        color: var(--pwa-refresh-c1, #1a1a1a);
    }
    25% {
        color: var(--pwa-refresh-c2, #1B5E20);
    }
    50% {
        color: var(--pwa-refresh-c3, #0055A4);
    }
    75% {
        color: var(--pwa-refresh-c4, #FFD700);
    }
}

@media (prefers-reduced-motion: reduce) {
    html.pwa-standalone .header-pwa-refresh-btn.is-refreshing svg {
        animation: pwa-refresh-colors 1.6s linear infinite;
    }
}

@media (prefers-reduced-motion: reduce) and (display-mode: standalone),
       (prefers-reduced-motion: reduce) and (display-mode: fullscreen),
       (prefers-reduced-motion: reduce) and (display-mode: minimal-ui),
       (prefers-reduced-motion: reduce) and (display-mode: window-controls-overlay) {
    .header-pwa-refresh-btn.is-refreshing svg {
        animation: pwa-refresh-colors 1.6s linear infinite;
    }
}

@media (max-width: 768px) {
    /* Direct .header-main child: geometric center of the header row. */
    html.pwa-standalone .header-main {
        position: relative;
    }

    html.pwa-standalone .header-main > .header-pwa-refresh-slot,
    html.pwa-standalone .header-main > .header-icon-slot.header-pwa-refresh-slot {
        position: absolute;
        left: 50%;
        top: 50%;
        transform: translate(-50%, -50%);
        z-index: 2;
        pointer-events: none;
        flex: 0 0 40px;
        width: 40px;
        height: 40px;
    }

    html.pwa-standalone .header-pwa-refresh-btn {
        pointer-events: auto;
        width: 40px;
        height: 40px;
        min-width: 40px;
        min-height: 40px;
        padding: 0;
    }
}

@media (max-width: 768px) and (display-mode: standalone),
       (max-width: 768px) and (display-mode: fullscreen),
       (max-width: 768px) and (display-mode: minimal-ui),
       (max-width: 768px) and (display-mode: window-controls-overlay) {
    .header-main {
        position: relative;
    }

    .header-main > .header-pwa-refresh-slot,
    .header-main > .header-icon-slot.header-pwa-refresh-slot {
        position: absolute;
        left: 50%;
        top: 50%;
        transform: translate(-50%, -50%);
        z-index: 2;
        pointer-events: none;
        flex: 0 0 40px;
        width: 40px;
        height: 40px;
    }

    .header-pwa-refresh-btn {
        pointer-events: auto;
        width: 40px;
        height: 40px;
        min-width: 40px;
        min-height: 40px;
        padding: 0;
    }
}

@media (min-width: 769px) {
    /* In-flow: docked immediately left of .header-right (Quick Access block). */
    html.pwa-standalone .header-main > .header-pwa-refresh-slot,
    html.pwa-standalone .header-main > .header-icon-slot.header-pwa-refresh-slot {
        position: static;
        transform: none;
        pointer-events: auto;
        flex: 0 0 40px;
        width: 40px;
        height: 40px;
        margin-left: auto;
        margin-right: 8px;
    }

    html.pwa-standalone .header-pwa-refresh-btn {
        width: 40px;
        height: 40px;
        min-width: 40px;
        min-height: 40px;
        padding: 0;
    }
}

@media (min-width: 769px) and (display-mode: standalone),
       (min-width: 769px) and (display-mode: fullscreen),
       (min-width: 769px) and (display-mode: minimal-ui),
       (min-width: 769px) and (display-mode: window-controls-overlay) {
    .header-main > .header-pwa-refresh-slot,
    .header-main > .header-icon-slot.header-pwa-refresh-slot {
        position: static;
        transform: none;
        pointer-events: auto;
        flex: 0 0 40px;
        width: 40px;
        height: 40px;
        margin-left: auto;
        margin-right: 8px;
    }

    .header-pwa-refresh-btn {
        width: 40px;
        height: 40px;
        min-width: 40px;
        min-height: 40px;
        padding: 0;
    }
}
/* iOS Safari: auto-zoom on input focus when font-size < 16px. Standalone PWA only. */
@media screen and (max-width: 768px) {
    html.pwa-standalone .input,
    html.pwa-standalone .file-input,
    html.pwa-standalone .filter-input,
    html.pwa-standalone .filter-select,
    html.pwa-standalone .search-input-main,
    html.pwa-standalone .chat-form-area,
    html.pwa-standalone input:not([type="checkbox"]):not([type="radio"]):not([type="file"]):not([type="range"]):not([type="color"]):not([type="hidden"]),
    html.pwa-standalone textarea,
    html.pwa-standalone select {
        font-size: 16px !important;
    }
}

@media screen and (max-width: 768px) and (display-mode: standalone),
       screen and (max-width: 768px) and (display-mode: fullscreen),
       screen and (max-width: 768px) and (display-mode: minimal-ui) {
    .input,
    .file-input,
    .filter-input,
    .filter-select,
    .search-input-main,
    .chat-form-area,
    input:not([type="checkbox"]):not([type="radio"]):not([type="file"]):not([type="range"]):not([type="color"]):not([type="hidden"]),
    textarea,
    select {
        font-size: 16px !important;
    }
}
