/* ==========================================================================
   TENGRI FUNDING — SHARED UI FEEDBACK COMPONENTS
   Connection banner, toasts, back-to-top, navigation progress, submit state
   and the unsaved-changes hint. Loaded by both the public landing (static
   index.html) and every Worker-rendered page, so colours are declared here with
   their own tokens instead of relying on either page stylesheet.
   ========================================================================== */

:root {
  --tf-ui-surface: #0b2347;
  --tf-ui-surface-2: #102d57;
  --tf-ui-ink: #f4f8ff;
  --tf-ui-muted: #a8bed8;
  --tf-ui-line: rgba(88, 185, 255, 0.28);
  --tf-ui-accent: #58b9ff;
  --tf-ui-accent-ink: #071a35;
  --tf-ui-shadow: 0 18px 40px -18px rgba(0, 0, 0, 0.75);
  --tf-offline-h: 0px;
}

html[data-theme="light"] {
  --tf-ui-surface: #ffffff;
  --tf-ui-surface-2: #eaf2ff;
  --tf-ui-ink: #0b1a2c;
  --tf-ui-muted: #4a5b70;
  --tf-ui-line: #cfdff3;
  --tf-ui-accent: #1769e0;
  --tf-ui-accent-ink: #ffffff;
  --tf-ui-shadow: 0 18px 40px -22px rgba(15, 42, 80, 0.4);
}

/* ------------------------------------------------------------------ Offline */
.tf-offline {
  position: fixed;
  z-index: 140;
  inset: 0 0 auto;
  display: none;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 9px 18px;
  font: 600 13px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  text-align: center;
  background: #fbbf24;
  color: #201502;
  border-bottom: 1px solid rgba(0, 0, 0, 0.18);
}
.tf-offline.is-on { display: flex; }
.tf-offline.is-restored { background: #34d399; color: #04231a; }
.tf-offline__icon { flex: none; width: 16px; height: 16px; }
/* Reserve the banner height in the flow and pin the sticky header below it, so
   the header never slides underneath the banner or covers page content. */
html.tf-offline-on body { padding-top: var(--tf-offline-h); }
html.tf-offline-on .site-head,
html.tf-offline-on .site-header { top: var(--tf-offline-h); }
html.tf-offline-on { scroll-padding-top: var(--tf-offline-h); }

/* ------------------------------------------------------------------- Toasts */
.tf-toasts {
  position: fixed;
  z-index: 130;
  right: 20px;
  bottom: 84px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: min(360px, calc(100vw - 32px));
  pointer-events: none;
}
.tf-toast {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 12px 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--tf-ui-line);
  border-left: 3px solid var(--tf-ui-accent);
  background: var(--tf-ui-surface-2);
  color: var(--tf-ui-ink);
  box-shadow: var(--tf-ui-shadow);
  pointer-events: auto;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.18s ease, transform 0.18s ease;
}
.tf-toast.is-visible { opacity: 1; transform: none; }
.tf-toast.is-leaving { opacity: 0; transform: translateY(6px); }
.tf-toast--error { border-color: rgba(248, 113, 113, 0.55); }
.tf-toast__text {
  margin: 0;
  font: 500 13.5px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow-wrap: anywhere;
}
.tf-toast__close {
  flex: none;
  margin-left: auto;
  width: 24px;
  height: 24px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--tf-ui-muted);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}
.tf-toast__close:hover,
.tf-toast__close:focus-visible { color: var(--tf-ui-ink); background: var(--tf-ui-surface-2); }
.tf-toast__close:focus-visible { outline: 2px solid var(--tf-ui-accent); outline-offset: 1px; }

/* ------------------------------------------------------------- Back to top */
.tf-top {
  position: fixed;
  z-index: 120;
  right: 20px;
  bottom: 20px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  padding: 0 16px 0 12px;
  border-radius: 999px;
  border: 1px solid var(--tf-ui-line);
  background: var(--tf-ui-surface);
  color: var(--tf-ui-ink);
  font: 600 13px/1 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  box-shadow: var(--tf-ui-shadow);
  cursor: pointer;
  opacity: 0;
  transform: translateY(10px);
  visibility: hidden;
  transition: opacity 0.18s ease, transform 0.18s ease, visibility 0.18s;
}
.tf-top.is-visible { opacity: 1; transform: none; visibility: visible; }
.tf-top:hover { border-color: var(--tf-ui-accent); }
.tf-top:focus-visible { outline: 2px solid var(--tf-ui-accent); outline-offset: 3px; }
.tf-top svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
/* The consent banner owns the bottom edge; do not stack two floating controls. */
body:has(.cc-banner.is-open) .tf-top { opacity: 0; visibility: hidden; }

/* ------------------------------------------------------- Navigation progress */
.tf-progress {
  position: fixed;
  z-index: 200;
  inset: 0 auto auto 0;
  width: 0;
  height: 3px;
  background: var(--tf-ui-accent);
  box-shadow: 0 0 10px rgba(88, 185, 255, 0.6);
  opacity: 0;
  pointer-events: none;
  transition: width 0.25s ease, opacity 0.2s ease;
}
.tf-progress.is-on { opacity: 1; }

/* --------------------------------------------------------- Submit busy state */
.btn.is-loading,
button.is-loading,
input.is-loading {
  position: relative;
  cursor: progress;
  opacity: 0.85;
}
/* A busy button is not a dead button: keep the action colour while it waits,
   instead of the muted "disabled" palette the theme applies to :disabled. */
.btn.is-loading:disabled,
button.is-loading:disabled,
input.is-loading:disabled,
html[data-tf-theme] body :is(.btn, button).is-loading:disabled {
  background: var(--tf-action, var(--tf-ui-accent));
  color: var(--tf-action-ink, var(--tf-ui-accent-ink));
  border-color: transparent;
  opacity: 0.92;
  pointer-events: none;
  cursor: progress;
}
.tf-spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  vertical-align: -2px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: tf-spin 0.7s linear infinite;
}
@keyframes tf-spin { to { transform: rotate(360deg); } }
[aria-busy="true"] { cursor: progress; }

/* ------------------------------------------------------- Unsaved-change hint */
.tf-dirty {
  margin: 12px 0 0;
  font: 600 12.5px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: #fbbf24;
}
html[data-theme="light"] .tf-dirty { color: #8a5a00; }

/* --------------------------------------------------------------- Motion pref */
@media (prefers-reduced-motion: reduce) {
  .tf-toast,
  .tf-top,
  .tf-progress,
  .tf-offline { transition: none; }
  .tf-spinner { animation-duration: 1.6s; }
}

@media (max-width: 560px) {
  .tf-toasts { right: 12px; left: 12px; width: auto; bottom: 76px; }
  .tf-top { right: 12px; bottom: 12px; padding: 0 14px 0 11px; }
  .tf-offline { font-size: 12.5px; padding: 8px 14px; }
}

/* ------------------------------------------------------- Broken image fallback */
/* Подменённая картинка остаётся в своей рамке и не сдвигает макет. */
.tf-img-failed {
  object-fit: contain;
  background: #0b2347;
  outline: 1px solid rgba(88, 185, 255, 0.28);
  outline-offset: -1px;
}

/* ------------------------------------------------------------- Safe area */
:root {
  --tf-safe-top: 0px;
  --tf-safe-right: 0px;
  --tf-safe-bottom: 0px;
  --tf-safe-left: 0px;
}

@supports (padding: env(safe-area-inset-left)) {
  :root {
    --tf-safe-top: env(safe-area-inset-top);
    --tf-safe-right: env(safe-area-inset-right);
    --tf-safe-bottom: env(safe-area-inset-bottom);
    --tf-safe-left: env(safe-area-inset-left);
  }
}

.tf-offline {
  padding-top: calc(9px + var(--tf-safe-top));
  padding-left: calc(18px + var(--tf-safe-left));
  padding-right: calc(18px + var(--tf-safe-right));
}

.tf-toasts {
  right: calc(20px + var(--tf-safe-right));
  bottom: calc(84px + var(--tf-safe-bottom));
}

.tf-top {
  right: calc(20px + var(--tf-safe-right));
  bottom: calc(20px + var(--tf-safe-bottom));
  min-height: 44px;
}

.tf-toast__close {
  min-width: 32px;
  min-height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

@media (max-width: 560px) {
  .tf-toasts { right: calc(12px + var(--tf-safe-right)); left: calc(12px + var(--tf-safe-left)); bottom: calc(76px + var(--tf-safe-bottom)); }
  .tf-top { right: calc(12px + var(--tf-safe-right)); bottom: calc(12px + var(--tf-safe-bottom)); }
  .tf-toast__close { min-width: 40px; min-height: 40px; }
}
