/* ============================================================================
   Reconnect overlay — what a member of staff sees when the circuit drops.

   WHY THIS FILE EXISTS
   --------------------
   Blazor Server ships two reconnect displays and picks between them at the
   moment of the FIRST disconnect (blazor.web.js, onConnectionDown):

     • an element with id="components-reconnect-modal" is in the DOM
         -> UserSpecifiedDisplay: Blazor only toggles the classes
            .components-reconnect-show / -hide / -failed / -rejected
            on that element. The markup and the look are entirely ours.

     • no such element
         -> DefaultReconnectDisplay: Blazor injects its own <div>, with
            INLINE styles, and never sets any of those classes.

   Until this file (and <ReconnectOverlay/>) existed every Maple head fell into
   the second branch, which caused two separate faults:

     1. INVISIBLE BLOCKER. The injected div is
        `position:fixed; inset:0; z-index:1050; background:#fff; opacity:.8`,
        but MudBlazor.min.css overrides it with
        `#components-reconnect-modal{background-color:var(--mud-palette-background)!important}`.
        On the touch shells (/touch, /pos/kiosk, /kds, /tv) there is no
        <MudThemeProvider> above them — TouchLayout is deliberately provider-free
        — so --mud-palette-background is UNDEFINED, the var() substitution is
        invalid, and background-color computes to `transparent`. The result is a
        full-screen, perfectly invisible sheet over the whole page. Staff see a
        normal, inviting home screen, tap a tile, and nothing happens, because
        every tap lands on that sheet. Only a small line of text at the very top
        hints at what is wrong. That is the support call this file closes.

     2. DEAD SELF-HEALING. wallDisplayReconnect.js decides when to take over by
        reading the .components-reconnect-* CLASSES. The default display never
        sets them, so the watcher always concluded "no reconnect UI = healthy"
        and never once took over. Supplying our own element is what switches
        Blazor to the class-toggling display, so that whole recovery layer
        starts working as designed.

   COLOURS
   -------
   The overlay is a direct child of <body>, OUTSIDE .touch-shell / .app-theme,
   so the night-roast overrides in cafe-touch.css (declared on `.theme-dark`)
   cannot reach it by inheritance. <ReconnectOverlay/> therefore stamps the
   shop's own theme class onto the overlay root itself, which puts the root
   inside that block's scope. Every colour below is still a --cafe-* token, per
   the café rule that a literal is a colour that cannot go dark — but each one
   carries a day-value fallback so this sheet is also correct in a head that
   never loads cafe-touch.css at all (the same pattern crm.css uses).
   ============================================================================ */

/* ── Root: the tap blocker ───────────────────────────────────────────────────
   Hidden until Blazor adds a state class. Both the background and the z-index
   are !important at a higher specificity than MudBlazor's own !important rule
   on the bare id, so the transparent-sheet bug above cannot come back through
   whichever stylesheet happens to load last. The root paints NOTHING; the
   scrim child does, which keeps that fight to one declaration. */
#components-reconnect-modal.mk-rc {
    position: fixed;
    inset: 0;
    z-index: 100000 !important;
    background: transparent !important;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 24px;
    box-sizing: border-box;
    font-family: Roboto, "Segoe UI", system-ui, sans-serif;

    /* Day roast. Re-pointed by .theme-dark below (cafe-touch.css) when loaded;
       the fallbacks keep a bare head on the day palette. */
    --mkrc-ink:        var(--cafe-ink, #2b211a);
    --mkrc-muted:      var(--cafe-muted, #6b5d52);
    --mkrc-card:       var(--cafe-cream-1, #f7f2e9);
    --mkrc-card-edge:  var(--cafe-line, #e3d8c6);
    --mkrc-fill:       var(--cafe-espresso, #5e3c28);
    --mkrc-fill-2:     var(--cafe-espresso-2, #8a5a3c);
    --mkrc-on-fill:    var(--cafe-on-accent, #fffaf2);
    --mkrc-scrim:      rgba(24, 16, 11, 0.55);
    --mkrc-shadow:     0 24px 64px rgba(56, 38, 22, 0.32);
    --mkrc-ghost-edge: var(--cafe-line, #e3d8c6);
}

/* Night roast. cafe-touch.css re-declares the --cafe-* tokens on .theme-dark,
   and ReconnectOverlay stamps that class here, so the tokens above already
   resolve to night values. Only what is NOT a --cafe-* token needs restating. */
#components-reconnect-modal.mk-rc.theme-dark {
    --mkrc-card:       var(--cafe-cream-1, #241a14);
    --mkrc-ink:        var(--cafe-ink, #f4ece1);
    --mkrc-muted:      var(--cafe-muted, #bcaa99);
    --mkrc-card-edge:  var(--cafe-line, rgba(255, 255, 255, 0.10));
    --mkrc-scrim:      rgba(8, 5, 3, 0.68);
    --mkrc-shadow:     0 24px 64px rgba(0, 0, 0, 0.55);
    --mkrc-ghost-edge: var(--cafe-line, rgba(255, 255, 255, 0.18));
}

/* Blazor's four states. -hide is set once a reconnect succeeds. */
#components-reconnect-modal.mk-rc.components-reconnect-show,
#components-reconnect-modal.mk-rc.components-reconnect-failed,
#components-reconnect-modal.mk-rc.components-reconnect-rejected {
    display: flex;
}

#components-reconnect-modal.mk-rc.components-reconnect-hide {
    display: none;
}

/* ── Scrim ───────────────────────────────────────────────────────────────────
   A flat wash rather than a backdrop-filter: this can appear on the kiosk
   ordering screen, whose paint budget is the reason no blur/large-shadow effect
   is allowed there (v1.16 made the shop kiosks unusable). Fading it in over
   ~400ms means a sub-second blip never flashes a full modal at the operator,
   while the blocker itself is live from the first frame — because from the
   first frame the taps really are going nowhere. */
.mk-rc__scrim {
    position: absolute;
    inset: 0;
    background: var(--mkrc-scrim);
    animation: mk-rc-fade 400ms ease-out both;
}

/* ── Card ────────────────────────────────────────────────────────────────────
   Sized for a tablet at arm's length on the counter, and still sane on a phone
   (the delivery-app / guest screens) and a wall TV. */
.mk-rc__card {
    position: relative;
    width: min(34rem, 100%);
    max-height: calc(100vh - 48px);
    overflow-y: auto;
    box-sizing: border-box;
    padding: 40px 36px 34px;
    border-radius: 26px;
    background: var(--mkrc-card);
    border: 1px solid var(--mkrc-card-edge);
    box-shadow: var(--mkrc-shadow);
    color: var(--mkrc-ink);
    text-align: center;
    animation: mk-rc-rise 320ms cubic-bezier(0.2, 0.8, 0.3, 1) both;
}

/* One block per state; only the live one is displayed. Duplicated markup rather
   than one block with swapped strings, so each state reads as a whole piece of
   copy in the .razor instead of a pile of conditional spans. */
.mk-rc__state { display: none; }
.components-reconnect-show     .mk-rc__state--show     { display: block; }
.components-reconnect-failed   .mk-rc__state--failed   { display: block; }
.components-reconnect-rejected .mk-rc__state--rejected { display: block; }

/* ── Marks ───────────────────────────────────────────────────────────────────
   A spinner while there is still something to wait for; a static glyph once the
   only way forward is the button, because a spinner there would promise motion
   that is not coming. */
.mk-rc__spinner {
    width: 46px;
    height: 46px;
    margin: 0 auto 22px;
    border-radius: 50%;
    border: 4px solid var(--mkrc-card-edge);
    border-top-color: var(--mkrc-fill);
    animation: mk-rc-spin 1.1s linear infinite;
}

.mk-rc__glyph {
    width: 62px;
    height: 62px;
    margin: 0 auto 22px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 30px;
    line-height: 1;
    background: linear-gradient(135deg, var(--mkrc-fill) 0%, var(--mkrc-fill-2) 100%);
    color: var(--mkrc-on-fill);
}

.mk-rc__title {
    margin: 0 0 10px;
    font-size: 1.65rem;
    font-weight: 700;
    line-height: 1.2;
    color: var(--mkrc-ink);
}

.mk-rc__body {
    margin: 0 0 26px;
    font-size: 1.05rem;
    line-height: 1.5;
    color: var(--mkrc-muted);
}

/* ── Actions ─────────────────────────────────────────────────────────────────
   Plain <button>s, not MudButton: app.css forces dark text onto MudButtons,
   which is unreadable on an espresso fill. They are also wired in plain JS
   (reconnect-ui.js) rather than @onclick — an @onclick needs the very circuit
   that is down, so a Blazor-wired button here would be another dead control on
   a screen whose whole complaint is dead controls. */
.mk-rc__actions {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

#components-reconnect-modal.mk-rc .mk-rc__btn {
    display: block;
    width: 100%;
    min-height: 60px;
    padding: 16px 24px;
    border: 0;
    border-radius: 16px;
    font-size: 1.1rem;
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    transition: transform 120ms ease, filter 120ms ease;
}

#components-reconnect-modal.mk-rc .mk-rc__btn:active { transform: scale(0.97); }

#components-reconnect-modal.mk-rc .mk-rc__btn--primary {
    background: linear-gradient(135deg, var(--mkrc-fill) 0%, var(--mkrc-fill-2) 100%);
    color: var(--mkrc-on-fill);
}

#components-reconnect-modal.mk-rc .mk-rc__btn--ghost {
    background: transparent;
    color: var(--mkrc-ink);
    border: 1px solid var(--mkrc-ghost-edge);
    font-weight: 600;
}

/* While Blazor is still retrying on its own, the manual escape hatch is held
   back for 8s. Offering "Refresh" instantly would train staff to refresh on
   every blip and throw away a cart the automatic retry was about to restore
   intact — the retained circuit comes back WITH its state, a refresh does not. */
.mk-rc__state--show .mk-rc__actions {
    /* mk-rc-reveal, not a plain fade: `both` holds the from-frame through the
       8s delay, and that frame must be `visibility: hidden`, not merely
       opacity 0. An invisible-but-tappable button is the same fault this whole
       overlay exists to fix, just eight seconds wide. visibility flips at the
       instant the animation starts, so the button becomes real and visible
       together. */
    animation: mk-rc-reveal 500ms ease-out 8s both;
}

/* ── Attempt counter ─────────────────────────────────────────────────────────
   Blazor writes the numbers into these two ids itself. Kept as a symbol-and-
   digits badge rather than a sentence: it stays honest in every language, and
   it gives whoever does phone support something exact to ask for. */
.mk-rc__attempt {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin: 20px 0 0;
    font-size: 0.85rem;
    font-variant-numeric: tabular-nums;
    color: var(--mkrc-muted);
    opacity: 0.75;
}

.mk-rc__note {
    margin: 18px 0 0;
    font-size: 0.9rem;
    color: var(--mkrc-muted);
}

@keyframes mk-rc-spin { to { transform: rotate(360deg); } }
@keyframes mk-rc-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes mk-rc-reveal {
    from { opacity: 0; visibility: hidden; }
    to   { opacity: 1; visibility: visible; }
}
@keyframes mk-rc-rise {
    from { opacity: 0; transform: translateY(14px) scale(0.97); }
    to   { opacity: 1; transform: none; }
}

/* Staff terminals that have motion reduced at the OS level: keep the spinner
   (it is the only signal that anything is still happening) but drop the rest. */
@media (prefers-reduced-motion: reduce) {
    .mk-rc__scrim,
    .mk-rc__card {
        animation-duration: 1ms;
        animation-delay: 0ms;
    }
    /* Duration only — the 8s delay is a deliberate UX hold, not decoration, and
       zeroing it here would quietly offer the refresh straight away on any
       terminal with motion reduced at the OS level. */
    .mk-rc__state--show .mk-rc__actions { animation-duration: 1ms; }
}

/* Phones: the guest receipt and delivery-app screens. */
@media (max-width: 480px) {
    .mk-rc__card { padding: 30px 22px 26px; border-radius: 20px; }
    .mk-rc__title { font-size: 1.4rem; }
}

/* Wall TVs and the kitchen boards, read from across the room. */
@media (min-width: 1600px) {
    .mk-rc__card { width: min(44rem, 100%); padding: 52px 46px 44px; }
    .mk-rc__title { font-size: 2.1rem; }
    .mk-rc__body { font-size: 1.25rem; }
}
