/*
   Omni237 Portal — circuit reconnect surface.

   Pairs with Pages/Shared/_ReconnectModal.cshtml and js/omni237-reconnect.js.

   PLATFORM DEBT, deliberately taken and recorded: a reconnect modal is
   data-agnostic shared UI. Under the Platform Reuse Rule in AGENTS.md it
   belongs in the SM360.UI package, with Omni237 consuming it. SM360's
   implementation today lives in the SM360 Portal application rather than in the
   shared package, and moving it needs an SDK release. Until that release lands
   this is a product-local build kept behind one partial, one stylesheet and one
   script that Omni237 owns, so the swap is a substitution rather than a
   refactor. Tracked as marvinamiranda/omni237#637.

   Class names and element ids are the framework's contract. Blazor's
   UserSpecifiedDisplay adds exactly one of components-reconnect-{show, hide,
   retrying, failed, paused, resume-failed, rejected} to the container, and
   writes the attempt countdown into #components-seconds-to-next-attempt.
   `retrying` is added ON TOP of `show` rather than replacing it, which is why
   the retrying rule below has to hide the first-attempt line explicitly.

   An external stylesheet on purpose. The framework's own default display writes
   its CSS into an inline <style>, which is precisely what a Content-Security-
   Policy without 'unsafe-inline' strips; this file is served from 'self' and
   keeps working under a nonce-based policy.
*/

/* Hidden until Blazor says otherwise. No state class means no circuit trouble. */
#components-reconnect-modal {
    display: none;
}

/* Every state that must interrupt the user. `components-reconnect-hide` and
   `components-reconnect-rejected` are absent by design: hide means the circuit
   is back, and rejected reloads the page from script. */
#components-reconnect-modal.components-reconnect-show,
#components-reconnect-modal.components-reconnect-retrying,
#components-reconnect-modal.components-reconnect-failed,
#components-reconnect-modal.components-reconnect-paused,
#components-reconnect-modal.components-reconnect-resume-failed {
    display: flex;
    position: fixed;
    inset: 0;
    z-index: 2147483000; /* above the SM360 layout's sidebar (1000) and any modal */
    align-items: center;
    justify-content: center;
    padding: 16px;
    background: rgba(15, 23, 42, 0.55);
    -webkit-backdrop-filter: blur(2px);
    backdrop-filter: blur(2px);
}

.omni-reconnect-panel {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    width: 20rem;
    max-width: 100%;
    padding: 32px;
    border-radius: 8px;
    background: #ffffff;
    color: #0f172a;
    font-family: Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
    font-size: 0.9375rem;
    line-height: 1.45;
    text-align: center;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
}

#components-reconnect-modal p {
    margin: 0;
}

/* ---- Per-state visibility ---------------------------------------------- */

.components-reconnect-first-attempt-visible,
.components-reconnect-repeated-attempt-visible,
.components-reconnect-failed-visible,
.components-pause-visible,
.components-resume-failed-visible,
.omni-reconnect-spinner {
    display: none;
}

#components-reconnect-modal.components-reconnect-show .components-reconnect-first-attempt-visible,
#components-reconnect-modal.components-reconnect-show .omni-reconnect-spinner,
#components-reconnect-modal.components-reconnect-retrying .components-reconnect-repeated-attempt-visible,
#components-reconnect-modal.components-reconnect-retrying .omni-reconnect-spinner,
#components-reconnect-modal.components-reconnect-failed .components-reconnect-failed-visible,
#components-reconnect-modal.components-reconnect-paused .components-pause-visible,
#components-reconnect-modal.components-reconnect-resume-failed .components-resume-failed-visible {
    display: block;
}

/* The framework adds `retrying` without removing `show`, so both lines would
   otherwise render at once and the panel would say two different things. */
#components-reconnect-modal.components-reconnect-retrying .components-reconnect-first-attempt-visible {
    display: none;
}

/* ---- Controls ----------------------------------------------------------- */

.omni-reconnect-btn {
    padding: 8px 24px;
    border: 0;
    border-radius: 4px;
    background: #00a99d;
    color: #ffffff;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
}

.omni-reconnect-btn:hover {
    background: #00766c;
}

.omni-reconnect-btn:focus-visible {
    outline: 2px solid #0f172a;
    outline-offset: 2px;
}

.omni-reconnect-reload {
    color: #475569;
    font-size: 0.8125rem;
    text-decoration: underline;
}

/* ---- Rejoining animation ------------------------------------------------ */

.omni-reconnect-spinner {
    position: relative;
    width: 64px;
    height: 64px;
}

.omni-reconnect-spinner div {
    position: absolute;
    border: 3px solid #00a99d;
    border-radius: 50%;
    opacity: 1;
    animation: omni-reconnect-ripple 1.5s cubic-bezier(0, 0.2, 0.8, 1) infinite;
}

.omni-reconnect-spinner div:nth-child(2) {
    animation-delay: -0.5s;
}

@keyframes omni-reconnect-ripple {
    0% {
        top: 32px;
        left: 32px;
        width: 0;
        height: 0;
        opacity: 1;
    }

    100% {
        top: 0;
        left: 0;
        width: 64px;
        height: 64px;
        opacity: 0;
    }
}

/* A user who has asked for less motion still needs to know the app is trying,
   so the panel keeps its text and loses only the ripple. */
@media (prefers-reduced-motion: reduce) {
    .omni-reconnect-spinner div {
        animation: none;
        top: 0;
        left: 0;
        width: 64px;
        height: 64px;
        opacity: 0.35;
    }
}

/* ---- Dark theme --------------------------------------------------------- */

[data-theme="dark"] .omni-reconnect-panel {
    background: #1e293b;
    color: #e2e8f0;
}

[data-theme="dark"] .omni-reconnect-reload {
    color: #94a3b8;
}

[data-theme="dark"] .omni-reconnect-btn:focus-visible {
    outline-color: #e2e8f0;
}
