/**
 * Horsify Reconnect Overlay
 *
 * Custom, branded reconnect experience for Blazor Server SignalR connection drops.
 * Replaces the default unstyled #components-reconnect-modal with a polished overlay.
 *
 * Design tokens (the @theme values in Styles/tailwind.css, written out so the overlay does not
 * depend on which of them Tailwind emits):
 *   Brand primary:  #2E4E3F  (--color-primary, deep sage green)
 *   Brand accent:   #8A6B14  (--color-accent; the old #D3A71A was 2.3:1 on the white card)
 *   Focus ring:     var(--color-focus-ring) — #8A6B14, and #D4AC5A in dark mode
 *   Overlay bg:     rgba(0,0,0,0.45) + backdrop-blur
 *   Card bg:        #FFFFFF  (dark: #1D2922)
 *   Success:        #2E4E3F on #DDE8E2  (--color-success / -light, the brand sage);
 *                   dark #A8CDB8  (--color-success-on-dark)
 *   Warn/failed:    #B45309  (--color-warning, amber — not alarming red);
 *                   dark title #FCD34D  (--color-warning-on-dark)
 *
 * States driven by JS class changes on #horsify-reconnect-overlay:
 *   .is-resuming      — the page has just come back from the background: the pill alone
 *   .is-reconnecting  — spinner + "Reconnecting…" text
 *   .is-connected     — brief success flash then auto-hidden
 *   .is-failed        — friendly message + Refresh button
 *
 * Load order: after Tailwind, Syncfusion, and all other CSS.
 * Build: none. App.razor links this file as written; minify-css.js does not minify it.
 *
 * ══════════════════════════════════════════════════════════════════
 *  TABLE OF CONTENTS
 * ──────────────────────────────────────────────────────────────────
 *  1.  Hide Blazor's default reconnect modal
 *  2.  Overlay base (backdrop)
 *  3.  Card (content panel)
 *  4.  Spinner
 *  5.  Success icon
 *  6.  Text elements
 *  7.  Refresh button
 *  8.  State modifiers (.is-reconnecting, .is-connected, .is-failed)
 *  9.  Mobile — bottom-anchored toast
 * 10.  Resume pill (.is-resuming)
 * 11.  Reduced motion
 * 12.  Dark mode
 * ══════════════════════════════════════════════════════════════════
 */

/* ─────────────────────────────────────────────────────────────────
   1.  Hide Blazor's default reconnect modal
       Blazor MUST still find this element in the DOM — we just
       keep it invisible so our custom overlay drives the UX.
   ───────────────────────────────────────────────────────────────── */
#components-reconnect-modal {
  display: none !important;
}

/* ─────────────────────────────────────────────────────────────────
   2.  Overlay base (backdrop)
   ───────────────────────────────────────────────────────────────── */
#horsify-reconnect-overlay {
  /* Layout */
  position: fixed;
  inset: 0;

  /* The connection layer of the stacking scale (Styles/tailwind.css): above every modal, popup
     and toast, because while the circuit is down nothing they show can be used. At 9999 it sat
     under any open SfDialog or modal, so a coach whose connection dropped with a lesson sheet or
     a booking dialog open saw no "reconnecting" and got no Retry. */
  z-index: var(--z-connection, 10080);
  display: flex;
  align-items: center;
  justify-content: center;

  /* Backdrop — solid colour is the fallback for browsers without backdrop-filter support */
  background: rgb(0 0 0 / 45%);

  /* Hidden by default — JS toggles visibility via opacity + pointer-events */
  opacity: 0;
  pointer-events: none;

  /* Entry / exit animation. The backdrop is put back only once the fade out is over: the resume
     pill (section 10) has none, and a backdrop restored as the pill left would dim and blur the
     page for the length of the fade. */
  transition:
    opacity          280ms cubic-bezier(0.4, 0, 0.2, 1),
    background-color 0s linear 280ms,
    backdrop-filter  0s linear 280ms;
}

/* Progressive enhancement: frosted-glass blur when the browser supports it */
@supports (backdrop-filter: blur(1px)) {
  #horsify-reconnect-overlay {
    backdrop-filter: blur(4px);
  }
}

#horsify-reconnect-overlay.is-visible {
  opacity: 1;
  pointer-events: all;
}

/* ─────────────────────────────────────────────────────────────────
   3.  Card (content panel)
   ───────────────────────────────────────────────────────────────── */
.hrc-card {
  /* Sizing */
  width: 100%;
  max-width: 360px;
  padding: 32px 28px 28px;

  /* Surface */
  background: #fff;
  border-radius: 20px;
  box-shadow:
    0 20px 60px rgb(0 0 0 / 18%),
    0 4px  16px rgb(0 0 0 / 8%);

  /* Content layout */
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  text-align: center;

  /* Slide-up entrance */
  transform: translateY(16px);
  transition:
    transform 280ms cubic-bezier(0.34, 1.56, 0.64, 1),
    opacity   280ms cubic-bezier(0.4, 0, 0.2, 1);
  opacity: 0;
}

#horsify-reconnect-overlay.is-visible .hrc-card {
  transform: translateY(0);
  opacity: 1;
}

/* Thin branded top accent bar */
.hrc-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  border-radius: 20px 20px 0 0;
  background: linear-gradient(90deg, #2E4E3F 0%, #4A6F5C 60%, #8A6B14 100%);
}

.hrc-card {
  position: relative; /* needed for ::before */
  overflow: hidden;
}

/* ─────────────────────────────────────────────────────────────────
   4.  Spinner  (pure-CSS ring)
   ───────────────────────────────────────────────────────────────── */
.hrc-spinner-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  margin-bottom: 4px;
}

.hrc-spinner {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 3.5px solid rgb(46 78 63 / 15%);
  border-top-color: #2E4E3F;
  animation: hrc-spin 0.9s linear infinite;
}

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

/* Subtle pulse on the spinner wrapper */
.hrc-spinner-wrap {
  animation: hrc-pulse 1.8s ease-in-out infinite;
}

@keyframes hrc-pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.7; }
}

/* ─────────────────────────────────────────────────────────────────
   5.  Success icon  (checkmark circle)
   ───────────────────────────────────────────────────────────────── */
.hrc-success-icon {
  display: none;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: #dde8e2;
  align-items: center;
  justify-content: center;
  margin-bottom: 4px;
}

/* SVG checkmark inside */
.hrc-success-icon::after {
  content: '';
  display: block;
  width: 26px;
  height: 14px;
  border-left: 3px solid #2e4e3f;
  border-bottom: 3px solid #2e4e3f;
  transform: rotate(-45deg) translate(1px, -3px);
  animation: hrc-check-draw 0.4s ease forwards;
}

@keyframes hrc-check-draw {
  from { opacity: 0; transform: rotate(-45deg) translate(1px, -3px) scale(0.6); }
  to   { opacity: 1; transform: rotate(-45deg) translate(1px, -3px) scale(1);   }
}

/* ─────────────────────────────────────────────────────────────────
   6.  Text elements
   ───────────────────────────────────────────────────────────────── */
.hrc-logo {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #2E4E3F;
  opacity: 0.55;
  margin-bottom: 2px;
}

.hrc-title {
  font-size: 17px;
  font-weight: 700;
  color: #212529;
  line-height: 1.25;
  margin: 0;
}

.hrc-subtitle {
  font-size: 14px;
  color: #6b7280;
  line-height: 1.5;
  margin: 0;
  max-width: 260px;
}

/* ─────────────────────────────────────────────────────────────────
   7.  Refresh button
   ───────────────────────────────────────────────────────────────── */
.hrc-refresh-btn {
  display: none; /* shown only in failed state */
  margin-top: 8px;
  padding: 11px 24px;
  border: none;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  background: #2E4E3F;
  color: #fff;
  transition:
    background 150ms ease,
    transform  100ms ease,
    box-shadow 150ms ease;

  /* Minimum touch target: WCAG 2.5.5 AAA requires 44×44 CSS px.
     Horizontal dimension is met by padding (11px × 2 = 22px) + content text
     width which always exceeds 22px. min-width is set explicitly to guarantee
     the horizontal target even for very short label translations. */
  min-height: 44px;
  min-width: 44px;
}

.hrc-refresh-btn:hover {
  background: #3d6b54;
  box-shadow: 0 4px 12px rgb(46 78 63 / 35%);
}

.hrc-refresh-btn:active {
  transform: scale(0.97);
  background: #1F3329;
}

/* The site's focus ring: 5.0:1 on the white card, 7.1:1 on the dark one. The old #D3A71A was 2.3:1
   on white, under the 3:1 a focus indicator needs. */
.hrc-refresh-btn:focus-visible {
  outline: 3px solid var(--color-focus-ring, #8a6b14);
  outline-offset: 3px;
}

/* ─────────────────────────────────────────────────────────────────
   8.  State modifiers
   ───────────────────────────────────────────────────────────────── */

/* — Reconnecting ————————————————————————————————————————————————— */
#horsify-reconnect-overlay.is-reconnecting .hrc-spinner-wrap  { display: flex; }
#horsify-reconnect-overlay.is-reconnecting .hrc-success-icon  { display: none;  }
#horsify-reconnect-overlay.is-reconnecting .hrc-refresh-btn   { display: none;  }

/* — Connected (briefly shown before auto-hide) ———————————————— */
#horsify-reconnect-overlay.is-connected .hrc-spinner-wrap     { display: none;  }
#horsify-reconnect-overlay.is-connected .hrc-success-icon     { display: flex;  }
#horsify-reconnect-overlay.is-connected .hrc-refresh-btn      { display: none;  }

/* The brand sage, not a Tailwind green: success is --color-success everywhere else on the site. */
#horsify-reconnect-overlay.is-connected .hrc-card::before     {
  background: linear-gradient(90deg, #2E4E3F 0%, #4A6F5C 60%, #A8CDB8 100%);
}

#horsify-reconnect-overlay.is-connected .hrc-title {
  color: #2e4e3f;
}

/* — Failed ——————————————————————————————————————————————————————— */
#horsify-reconnect-overlay.is-failed .hrc-spinner-wrap        { display: none;  }
#horsify-reconnect-overlay.is-failed .hrc-success-icon        { display: none;  }
#horsify-reconnect-overlay.is-failed .hrc-refresh-btn         { display: inline-flex; align-items: center; justify-content: center; }

#horsify-reconnect-overlay.is-failed .hrc-card::before        {
  background: linear-gradient(90deg, #b45309 0%, #d97706 100%);
}

#horsify-reconnect-overlay.is-failed .hrc-title {
  color: #92400e;
}

/* ─────────────────────────────────────────────────────────────────
   9.  Mobile  — bottom-anchored toast (≤ 640 px)
   ───────────────────────────────────────────────────────────────── */
@media (width <= 640px) {
  #horsify-reconnect-overlay {
    align-items: flex-end;
    padding: 0;
  }

  .hrc-card {
    max-width: 100%;
    border-radius: 20px 20px 0 0;

  /* Padding breakdown:
     - 28px top: slightly less than the desktop card's 32px top — appropriate
       for the compact bottom-sheet layout that spans full screen width.
     - 20px base bottom: comfortable clearance above the home indicator on
       devices without a safe area (standard Android / non-notch iPhones).
       This is less than the desktop's 28px bottom because the bottom-sheet
       sits flush at the screen edge and needs less visual breathing room.
     - env(safe-area-inset-bottom): additional dynamic inset on notched /
       Dynamic-Island iPhones so content never hides behind the home indicator. */
  padding: 28px 20px calc(20px + env(safe-area-inset-bottom, 0px));

    /* Slide up from bottom */
    transform: translateY(100%);
    transition:
      transform 320ms cubic-bezier(0.34, 1.22, 0.64, 1),
      opacity   280ms cubic-bezier(0.4, 0, 0.2, 1);
  }

  #horsify-reconnect-overlay.is-visible .hrc-card {
    transform: translateY(0);
  }

  .hrc-card::before {
    border-radius: 20px 20px 0 0;
  }
}

/* ─────────────────────────────────────────────────────────────────
   10. Resume pill (.is-resuming)
       A page that has just come back from the background is normally
       reconnected in two to four seconds, so it is left readable: no
       backdrop, no card, only this pill. The overlay is still the
       full-screen element and still takes pointer events (.is-visible),
       because a tap sent while the circuit is down is dropped by
       blazor.web.js; reconnect.js pulses the pill (.is-nudged) when it
       swallows one. The page behind still scrolls.
   ───────────────────────────────────────────────────────────────── */
.hrc-pill {
  /* Top centre, under the status bar or notch (the viewport is viewport-fit=cover). Not the
     bottom: on a phone that is the tab bar, the first thing a returning thumb goes for. */
  position: absolute;
  top: calc(env(safe-area-inset-top, 0px) + 12px);
  left: 50%;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px 8px 10px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: #2e4e3f;
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  line-height: 1;
  white-space: nowrap;
  box-shadow:
    0 6px 20px rgb(0 0 0 / 18%),
    0 1px 4px  rgb(0 0 0 / 10%);

  /* Hidden in every state but .is-resuming: the overlay's own opacity hides it at rest, but not
     under the card's states. */
  opacity: 0;
  visibility: hidden;
  transform: translate(-50%, -8px);
  transition:
    opacity    200ms ease,
    transform  200ms ease,
    visibility 0s linear 200ms;
}

.hrc-pill-spinner {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid rgb(255 255 255 / 35%);
  border-top-color: #fff;
  animation: hrc-spin 0.9s linear infinite;
}

/* Two classes, to outrank the dark theme's backdrop (section 12). The backdrop goes at once, while
   the overlay is still transparent, so the page is never dimmed on the way in. */
#horsify-reconnect-overlay.is-visible.is-resuming {
  background: transparent;
  backdrop-filter: none;
  transition:
    opacity          280ms cubic-bezier(0.4, 0, 0.2, 1),
    background-color 0s,
    backdrop-filter  0s;
}

/* The step up from the pill to a state with the card: the backdrop fades in under it. */
#horsify-reconnect-overlay.is-reconnecting,
#horsify-reconnect-overlay.is-connected,
#horsify-reconnect-overlay.is-failed {
  transition:
    opacity          280ms cubic-bezier(0.4, 0, 0.2, 1),
    background-color 280ms cubic-bezier(0.4, 0, 0.2, 1),
    backdrop-filter  0s;
}

#horsify-reconnect-overlay.is-resuming .hrc-pill {
  opacity: 1;
  visibility: visible;
  transform: translate(-50%, 0);
  transition:
    opacity    200ms ease,
    transform  200ms ease,
    visibility 0s;
}

/* The card waits where its entrance starts, so the step up to .is-reconnecting plays it. Not
   visible to assistive technology either: its words are the last state's. */
#horsify-reconnect-overlay.is-visible.is-resuming .hrc-card {
  opacity: 0;
  visibility: hidden;
  transform: translateY(16px);
}

@media (width <= 640px) {
  #horsify-reconnect-overlay.is-visible.is-resuming .hrc-card {
    transform: translateY(100%);
  }
}

.hrc-pill.is-nudged {
  animation: hrc-nudge 450ms ease;
}

@keyframes hrc-nudge {
  0%, 100% { transform: translate(-50%, 0) scale(1); }
  35%      { transform: translate(-50%, 0) scale(1.1); }
}

/* ─────────────────────────────────────────────────────────────────
   11. Reduced motion — respect user preference
   ───────────────────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  #horsify-reconnect-overlay,
  .hrc-card,
  .hrc-pill,
  .hrc-refresh-btn {
    transition: none !important;
    animation: none !important;
  }

  .hrc-spinner,
  .hrc-pill-spinner {
    animation: hrc-spin 1.5s linear infinite; /* keep rotating, just slower */
  }

  .hrc-spinner-wrap {
    animation: none;
  }

  .hrc-success-icon::after {
    animation: none;
    opacity: 1;
  }
}

/* ─────────────────────────────────────────────────────────────────
   12. Dark mode
   ───────────────────────────────────────────────────────────────── */
[data-theme="dark"] #horsify-reconnect-overlay {
  background: rgb(0 0 0 / 60%);
}

[data-theme="dark"] .hrc-card {
  background: #1d2922;
  box-shadow:
    0 20px 60px rgb(0 0 0 / 45%),
    0 4px  16px rgb(0 0 0 / 25%);
}

[data-theme="dark"] .hrc-title {
  color: #e8ede8;
}

[data-theme="dark"] .hrc-subtitle {
  color: #8a9e8a;
}

[data-theme="dark"] .hrc-logo {
  color: #6a9e7f;
}

/* The same sage, edged so it stands off a dark page. */
[data-theme="dark"] .hrc-pill {
  border-color: rgb(168 205 184 / 35%);
  box-shadow:
    0 6px 20px rgb(0 0 0 / 45%),
    0 1px 4px  rgb(0 0 0 / 25%);
}

[data-theme="dark"] .hrc-spinner {
  border-color: rgb(106 158 127 / 20%);
  border-top-color: #6a9e7f;
}

[data-theme="dark"] #horsify-reconnect-overlay.is-connected .hrc-success-icon {
  background: #2e4e3f;
}

[data-theme="dark"] .hrc-success-icon::after {
  border-color: #a8cdb8;
}

/* The light-mode state titles are dark inks: the green was 3.0:1 and the amber 2.1:1 on this card. */
[data-theme="dark"] #horsify-reconnect-overlay.is-connected .hrc-title {
  color: #a8cdb8;
}

[data-theme="dark"] #horsify-reconnect-overlay.is-failed .hrc-title {
  color: #fcd34d;
}
