/* ─────────────────────────────────────────────
   NRFI Shared UI — cross-cutting accessibility,
   focus, motion, and component primitives.
   Loaded by every template after the page-level
   inline <style> so it can override base rules.
───────────────────────────────────────────── */

/* ── Design tokens ──────────────────────────────────────────────
   One source of truth for button/badge sizing. Page-level styles
   override colors only; geometry is unified here.
─────────────────────────────────────────────────────────────── */
:root {
  --btn-pad-y:     8px;
  --btn-pad-x:     16px;
  --btn-pad-y-sm:  5px;
  --btn-pad-x-sm:  12px;
  --btn-pad-y-lg:  12px;
  --btn-pad-x-lg:  22px;
  --btn-radius:    8px;
  --btn-font:      14px;
  --btn-font-sm:   13px;
  --btn-font-lg:   15px;
  --btn-fw:        600;
  --btn-gap:       6px;

  --badge-pad-y:   3px;
  --badge-pad-x:   9px;
  --badge-radius:  4px;
  --badge-font:    13px;

  --easing:        cubic-bezier(.2,.7,.2,1);
}

/* ── Standardized button geometry ──────────────────────────────
   ui.css loads after page <style> blocks, so plain `.btn` here
   wins on tied specificity. Page styles still control colors via
   variants (.btn-primary, .btn-accent, .btn-ghost, .btn-danger).
─────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--btn-gap);
  padding: var(--btn-pad-y) var(--btn-pad-x);
  border-radius: var(--btn-radius);
  font-size: var(--btn-font);
  font-weight: var(--btn-fw);
  line-height: 1.25;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: background .15s, border-color .15s, transform .08s, box-shadow .15s, opacity .15s;
  user-select: none;
}
.btn:active { transform: translateY(1px); }
.btn-sm { padding: var(--btn-pad-y-sm) var(--btn-pad-x-sm); font-size: var(--btn-font-sm); }
.btn-lg { padding: var(--btn-pad-y-lg) var(--btn-pad-x-lg); font-size: var(--btn-font-lg); }

/* Universal keyboard-focus ring. Mouse clicks suppressed via :focus-visible. */
:focus { outline: none; }
:focus-visible {
  outline: 2px solid var(--accent, #5b7cf7);
  outline-offset: 2px;
  border-radius: 4px;
}
/* Inputs/buttons: keep border-style + add ring around the box */
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
a:focus-visible,
[role="button"]:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid var(--accent, #5b7cf7);
  outline-offset: 2px;
  box-shadow: 0 0 0 4px rgba(91, 124, 247, 0.15);
}

/* Date inputs — hide native clear button + spin controls (cleaner look) */
input[type="date"]::-webkit-clear-button,
input[type="date"]::-webkit-inner-spin-button,
input[type="date"]::-ms-clear,
input[type="date"]::-ms-reveal {
  display: none !important;
  -webkit-appearance: none;
  appearance: none;
}
input[type="date"]::-webkit-calendar-picker-indicator {
  cursor: pointer;
  opacity: 0.7;
  filter: invert(1);
}
input[type="date"]::-webkit-calendar-picker-indicator:hover { opacity: 1; }

/* Honor reduced-motion preference globally */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* Stronger error state — readable on dark themes */
.error {
  background: rgba(244, 115, 106, 0.12) !important;
  border: 1px solid rgba(244, 115, 106, 0.55) !important;
  color: #ffb3ad !important;
  font-weight: 500;
}
.error::before {
  content: "⚠ ";
  font-weight: 700;
}

/* Stronger success state */
.success {
  background: rgba(61, 214, 140, 0.10) !important;
  border: 1px solid rgba(61, 214, 140, 0.45) !important;
  color: #aaf0cc !important;
  font-weight: 500;
}

/* Password input wrapper with reveal toggle */
.pw-wrap { position: relative; }
.pw-wrap input { padding-right: 38px !important; }
/* Hide native browser reveal-eye / autofill icons on password fields
   so they don't duplicate the custom toggle. Covers Edge/IE, Safari, Chrome. */
input[type="password"]::-ms-reveal,
input[type="password"]::-ms-clear,
input[type="password"]::-webkit-credentials-auto-fill-button,
input[type="password"]::-webkit-strong-password-auto-fill-button,
input[type="password"]::-webkit-contacts-auto-fill-button,
input[type="password"]::-webkit-caps-lock-indicator {
  display: none !important;
  visibility: hidden !important;
  width: 0 !important;
  height: 0 !important;
  pointer-events: none !important;
  position: absolute !important;
  right: 0 !important;
}
.pw-toggle {
  position: absolute; top: 50%; right: 8px;
  transform: translateY(-50%);
  background: transparent; border: none; padding: 6px;
  color: var(--muted); cursor: pointer; border-radius: 4px;
  display: flex; align-items: center; justify-content: center;
  transition: color .15s, background .15s;
}
.pw-toggle:hover { color: var(--text); background: rgba(255,255,255,0.05); }
.pw-toggle svg { width: 18px; height: 18px; }

/* Button loading state — adds spinner, disables clicks */
button[data-loading="true"],
.btn[data-loading="true"] {
  pointer-events: none;
  opacity: 0.75;
  position: relative;
  color: transparent !important;
}
button[data-loading="true"]::after,
.btn[data-loading="true"]::after {
  content: "";
  position: absolute;
  top: 50%; left: 50%;
  width: 16px; height: 16px;
  margin: -8px 0 0 -8px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: ui-spin 0.7s linear infinite;
  color: #fff;
}
@keyframes ui-spin {
  to { transform: rotate(360deg); }
}

/* Skeleton shimmer primitive */
.skeleton {
  background: linear-gradient(90deg,
    var(--surface, #1a1d27) 25%,
    var(--surface2, #22263a) 50%,
    var(--surface, #1a1d27) 75%);
  background-size: 200% 100%;
  animation: ui-shimmer 1.4s ease-in-out infinite;
  border-radius: 6px;
  color: transparent !important;
  user-select: none;
}
@keyframes ui-shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ── Micro-interactions ─────────────────────────────────────── */
/* Hover lift on stat cards / interactive surfaces */
.stat-card,
.stat-item {
  transition: background .18s, border-color .18s, transform .12s var(--easing), box-shadow .18s;
}
/* Each card carries its accent in --card-glow; hover + active states pull from
   it so colors stay in one place. Defaults to the blue accent; per-type and
   per-card rules below override it. */
.stat-card                  { --card-glow: var(--accent); }
.stat-card.gold             { --card-glow: var(--gold); }
.stat-card.nrfi             { --card-glow: var(--ml-away); }
.stat-card.yrfi             { --card-glow: var(--ml-home); }
.stat-card.splits           { --card-glow: var(--muted); }
.stat-card.splits-tab-no    { --card-glow: var(--ml-away); }
.stat-card.splits-tab-yes   { --card-glow: var(--ml-home); }
.stat-card.splits-tab-none  { --card-glow: var(--neutral); }
.stat-card.splits-tab-wager { --card-glow: var(--gold); }
.stat-card.k1-tab-over      { --card-glow: var(--k1-over); }
.stat-card.k1-tab-under     { --card-glow: var(--k1-under); }

/* "All Games" = white identity; "No Lean" = pale lilac (count number too). */
#fc-all, #sfc-all, #wfc-all, #kfc-all, #b-fc-all                  { --card-glow: #ffffff; }
#fc-neutral, #sfc-neutral, #wfc-neutral, #kfc-neutral             { --card-glow: #c9b6f5; }
#fc-all.active, #sfc-all.active, #wfc-all.active,
#kfc-all.active, #b-fc-all.active                                 { border-color: var(--card-glow); }
#fc-neutral.active, #sfc-neutral.active,
#wfc-neutral.active, #kfc-neutral.active                          { border-color: var(--card-glow); }
#fc-neutral .value, #sfc-neutral .value,
#wfc-neutral .value, #kfc-neutral .value                         { color: var(--card-glow); }
/* ML "Tie Lean" = violet, matching the ml-tie label/badge. Solid border (drop
   the dashed .splits styling). */
#wfc-tie          { --card-glow: var(--ml-tie); border-style: solid; }
#wfc-tie.active   { border-color: var(--card-glow); }
#wfc-tie .value   { color: var(--ml-tie); }

/* Hover: colored glow for every card (mirrors the Refresh button's hover). */
.stat-card:hover {
  transform: translateY(-1px);
  box-shadow: 0 0 20px color-mix(in srgb, var(--card-glow) 42%, transparent);
}
/* Active filter cards: crisp ring + colored halo glow. Defined after :hover so
   an active card keeps its ring even while hovered. */
.stat-card.active {
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--card-glow) 60%, transparent),
              0 0 22px color-mix(in srgb, var(--card-glow) 45%, transparent);
}
/* Label brightens from muted to full text color on hover and while selected —
   matches the section-tab (market page) behavior. Value keeps its accent color. */
.stat-card:hover .label,
.stat-card.active .label { color: var(--text); }

/* Smooth tab switch — fade panel content */
[data-fade-panel] {
  animation: ui-fade-in .25s var(--easing);
}
@keyframes ui-fade-in {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Gold zone badge — subtle pulse on first appearance.
   --row-i (set inline on table rows) staggers the cascade for a shimmer effect. */
.wager-badge,
.wager-badge-yrfi,
.wager-badge-scoreless,
.wager-badge-splits-score,
.wager-badge-ml-away,
.wager-badge-ml-home,
.wager-badge-ml-tie,
.wager-badge-k1-over,
.wager-badge-k1-under,
.splits-agree-badge,
.badge {
  animation: ui-pulse-in .55s var(--easing) both;
  animation-delay: calc(var(--row-i, 0) * 55ms);
}
@keyframes ui-pulse-in {
  0%   { transform: scale(.90); opacity: 0; }
  55%  { transform: scale(1.10); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

/* Section tab underline glides */
.section-tab {
  transition: color .18s, border-color .25s var(--easing);
}

/* Row hover lift (subtle) — applies on top of existing bg highlight */
tr.row-clickable {
  transition: background .15s;
}

/* Stagger fade-in primitive — opt-in via .stagger-in */
.stagger-in > * {
  opacity: 0;
  transform: translateY(6px);
  animation: ui-rise .45s cubic-bezier(.2,.7,.2,1) forwards;
}
.stagger-in > *:nth-child(1)  { animation-delay: 0.04s; }
.stagger-in > *:nth-child(2)  { animation-delay: 0.08s; }
.stagger-in > *:nth-child(3)  { animation-delay: 0.12s; }
.stagger-in > *:nth-child(4)  { animation-delay: 0.16s; }
.stagger-in > *:nth-child(5)  { animation-delay: 0.20s; }
.stagger-in > *:nth-child(6)  { animation-delay: 0.24s; }
.stagger-in > *:nth-child(7)  { animation-delay: 0.28s; }
.stagger-in > *:nth-child(8)  { animation-delay: 0.32s; }
.stagger-in > *:nth-child(n+9) { animation-delay: 0.36s; }
@keyframes ui-rise {
  to { opacity: 1; transform: translateY(0); }
}

/* Toast queue container — bottom-right stack */
#ui-toast-stack {
  position: fixed;
  bottom: 20px; right: 20px;
  z-index: 10000;
  display: flex; flex-direction: column-reverse; gap: 8px;
  pointer-events: none;
  max-width: 360px;
}
.ui-toast {
  pointer-events: auto;
  background: var(--surface2, #22263a);
  border: 1px solid var(--border, #2e3248);
  color: var(--text, #e8eaf0);
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 14px;
  box-shadow: 0 6px 24px rgba(0,0,0,.35);
  opacity: 0;
  transform: translateY(8px);
  animation: ui-toast-in .25s ease forwards;
}
.ui-toast.success { border-color: var(--nrfi, #3dd68c); }
.ui-toast.error   { border-color: var(--yrfi, #f4736a); }
.ui-toast.info    { border-color: var(--accent, #5b7cf7); }
.ui-toast.leaving { animation: ui-toast-out .2s ease forwards; }
@keyframes ui-toast-in {
  to { opacity: 1; transform: translateY(0); }
}
@keyframes ui-toast-out {
  to { opacity: 0; transform: translateY(8px); }
}

/* Form validation hints */
.field input[aria-invalid="true"] {
  border-color: var(--yrfi, #f4736a) !important;
}
.field-error {
  font-size: 12px; color: var(--yrfi, #f4736a);
  margin-top: 4px;
  display: none;
}
.field-error.show { display: block; }

/* Password strength meter */
.pw-strength {
  margin-top: 6px;
  height: 4px;
  background: var(--border, #2e3248);
  border-radius: 2px;
  overflow: hidden;
}
.pw-strength-fill {
  height: 100%;
  width: 0%;
  background: var(--yrfi, #f4736a);
  transition: width .2s, background .2s;
  border-radius: 2px;
}
.pw-strength-fill.s1 { width: 25%; background: var(--yrfi, #f4736a); }
.pw-strength-fill.s2 { width: 50%; background: #e0a040; }
.pw-strength-fill.s3 { width: 75%; background: var(--gold, #f5c542); }
.pw-strength-fill.s4 { width: 100%; background: var(--nrfi, #3dd68c); }
.pw-strength-label {
  font-size: 11px; color: var(--muted);
  margin-top: 4px; text-transform: uppercase; letter-spacing: .05em;
}

/* Row chevron — paired with .row-clickable on tables (CSS-only, no markup change) */
.row-clickable td:first-child {
  padding-left: 26px !important;
  position: relative;
}
.row-clickable td:first-child::before {
  content: '›';
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  font-size: 16px;
  font-weight: 700;
  line-height: 1;
  transition: transform .15s, color .15s;
  pointer-events: none;
}
.row-clickable:hover td:first-child::before { color: var(--text); }
.row-expanded td:first-child::before {
  transform: translateY(-50%) rotate(90deg);
  color: var(--accent);
}
/* Detail rows do not get a chevron */
.detail-row td:first-child::before { content: none !important; }
.detail-row td:first-child { padding-left: 16px !important; }

/* Sticky section tabs on mobile — keep in viewport while user scrolls long tables.
   Use id+class for higher specificity than the inline page styles that follow ui.css. */
@media (max-width: 900px) {
  #section-tabs.section-tabs,
  .section-tabs {
    position: -webkit-sticky !important;
    position: sticky !important;
    top: -1px;
    background: var(--bg);
    z-index: 50;
    margin-left: -12px;
    margin-right: -12px;
    padding-left: 12px;
    padding-right: 12px;
    border-bottom: 1px solid var(--border);
  }
}
