/* polish.css — shared UI/UX design-system layer (Phase 1 of the polish spec)
 * ───────────────────────────────────────────────────────────────────────
 * Opt-in only. Linking this file on a page changes NOTHING visually until
 * that page's markup adopts the .ca-* classes below (Phase 2+, page by
 * page, reviewed individually). The two exceptions are called out inline:
 * the global :focus-visible reset and prefers-reduced-motion handling are
 * safe-by-construction (they can only ever change keyboard-focus outlines
 * or reduce/skip animation — neither can break existing click-driven UI),
 * so those apply automatically the moment this file is linked.
 *
 * Tokens deliberately do NOT redefine any page's existing --text/--muted/
 * --border/--blue3/etc. variables — every page already has its own tuned
 * palette. New tokens here cover only what doesn't already exist
 * (radii/shadows/easing/durations/focus-ring). Anywhere this file needs a
 * page colour it reads the existing variable with a safe fallback, e.g.
 * var(--text, #fff), so it degrades gracefully even before a page defines
 * its own tokens.
 *
 * Mobile breakpoint matches the codebase's existing convention
 * (max-width:900px, per athlete-dashboard.html/coach-dashboard.html).
 * ───────────────────────────────────────────────────────────────────────
 */

:root{
  /* Radii */
  --ca-radius-sm: 8px;
  --ca-radius-md: 12px;
  --ca-radius-lg: 16px;
  --ca-radius-pill: 999px;

  /* Shadows — subtle, dark-UI-appropriate (this codebase is dark-themed
     throughout); each step adds elevation without a harsh drop shadow. */
  --ca-shadow-sm: 0 1px 2px rgba(0,0,0,.24), 0 1px 1px rgba(0,0,0,.16);
  --ca-shadow-md: 0 4px 12px rgba(0,0,0,.28), 0 2px 4px rgba(0,0,0,.18);
  --ca-shadow-lg: 0 12px 32px rgba(0,0,0,.36), 0 4px 10px rgba(0,0,0,.22);

  /* Motion */
  --ca-ease: cubic-bezier(.2,.8,.2,1);
  --ca-duration-fast: 120ms;
  --ca-duration-base: 200ms;
  --ca-duration-slow: 320ms;

  /* Focus ring — one consistent treatment for every interactive element,
     regardless of each page's own accent colour, so keyboard users get a
     predictable outline everywhere. */
  --ca-focus-ring-color: #60a5fa;
  --ca-focus-ring-width: 2px;
  --ca-focus-ring-offset: 2px;
}

/* ═══════════════════════════════════════════════════════════════════════
   GLOBAL, SAFE-BY-CONSTRUCTION RULES — apply the moment this file is
   linked, no opt-in class needed.
   ═══════════════════════════════════════════════════════════════════════ */

/* :focus-visible everywhere. Only ever shows for keyboard/programmatic
   focus (never for a mouse click), so this cannot visually interfere with
   any existing click-driven interaction on any page. */
:focus-visible{
  outline: var(--ca-focus-ring-width) solid var(--ca-focus-ring-color);
  outline-offset: var(--ca-focus-ring-offset);
  border-radius: var(--ca-radius-sm);
}
/* Remove the default mouse-click focus ring some browsers still draw,
   without removing it for keyboard users (that's the whole point of
   :focus-visible over a blanket :focus reset). */
:focus:not(:focus-visible){ outline: none; }

/* prefers-reduced-motion — scoped to the .ca-* utilities this file
   introduces (not a blanket `*`, which would reach into per-page
   animations this layer has no visibility into and no business touching). */
@media (prefers-reduced-motion: reduce){
  .ca-btn, .ca-card--clickable, .ca-reveal, .ca-toast, .skeleton{
    transition: none !important;
    animation: none !important;
  }
  html.ca-js .ca-reveal:not(.ca-revealed){ opacity: 1; transform: none; }
}

/* ═══════════════════════════════════════════════════════════════════════
   BUTTON STANDARDS (.ca-btn) — opt-in class, added alongside a page's
   existing button class (e.g. class="btn-primary ca-btn") so colour and
   hierarchy are 100% preserved; this only adds structural/behavioural
   consistency (sizing, motion, states).
   ═══════════════════════════════════════════════════════════════════════ */
.ca-btn{
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: var(--ca-radius-sm);
  transition: transform var(--ca-duration-fast) var(--ca-ease),
              box-shadow var(--ca-duration-fast) var(--ca-ease),
              opacity var(--ca-duration-fast) var(--ca-ease);
  -webkit-tap-highlight-color: transparent;
}
.ca-btn:hover{
  transform: translateY(-2px);
  box-shadow: var(--ca-shadow-sm);
}
.ca-btn:active{
  transform: translateY(0) scale(.98);
  box-shadow: none;
}
.ca-btn:disabled,
.ca-btn[aria-disabled="true"]{
  opacity: .5;
  cursor: not-allowed;
  pointer-events: none;
  transform: none;
  box-shadow: none;
}
/* 44px minimum touch target on mobile, per WCAG 2.5.5 — desktop keeps
   each page's existing (usually smaller) padding-driven size. */
@media (max-width: 900px){
  .ca-btn{ min-height: 44px; min-width: 44px; padding-left: 16px; padding-right: 16px; }
}
/* Marks a button as in-flight while its guarded handler is running — see
   CAPolish.guardClick() in polish.js. Purely visual; the actual
   double-submit prevention is the JS guard itself. */
.ca-btn.ca-btn-busy{ opacity: .7; cursor: progress; pointer-events: none; }

/* ═══════════════════════════════════════════════════════════════════════
   CARD STANDARDS (.ca-card) — hover elevation ONLY on .ca-card--clickable,
   never on a static display card (hover motion on a non-interactive card
   is a well-known anti-pattern — it invites a click that does nothing).
   ═══════════════════════════════════════════════════════════════════════ */
.ca-card{
  border-radius: var(--ca-radius-md);
  border: 1px solid var(--border, rgba(148,163,184,.18));
  box-shadow: var(--ca-shadow-sm);
}
.ca-card--clickable{
  cursor: pointer;
  transition: transform var(--ca-duration-base) var(--ca-ease),
              box-shadow var(--ca-duration-base) var(--ca-ease),
              border-color var(--ca-duration-base) var(--ca-ease);
}
.ca-card--clickable:hover{
  transform: translateY(-2px);
  box-shadow: var(--ca-shadow-md);
  border-color: var(--ca-focus-ring-color);
}

/* ═══════════════════════════════════════════════════════════════════════
   FORM FIELD STANDARDS (.ca-field) — wraps a label + input/select/
   textarea + inline error slot. Consistent height/radius/spacing/focus;
   error state driven by [aria-invalid="true"] on the control itself, not
   a separate error-only class, so screen readers and styling read off the
   same source of truth.
   ═══════════════════════════════════════════════════════════════════════ */
.ca-field{ display: flex; flex-direction: column; gap: 6px; }
.ca-field-label{
  font-size: 12.5px;
  font-weight: 700;
  color: var(--muted, #94a3b8);
}
.ca-field-control{
  height: 44px;
  padding: 0 14px;
  border-radius: var(--ca-radius-sm);
  border: 1px solid var(--border2, rgba(148,163,184,.28));
  background: var(--card2, rgba(255,255,255,.04));
  color: var(--text, #fff);
  font: inherit;
  font-size: 14px;
  transition: border-color var(--ca-duration-fast) var(--ca-ease),
              box-shadow var(--ca-duration-fast) var(--ca-ease);
}
textarea.ca-field-control{ height: auto; min-height: 96px; padding-top: 10px; padding-bottom: 10px; }
.ca-field-control:focus-visible{
  border-color: var(--ca-focus-ring-color);
  box-shadow: 0 0 0 3px rgba(96,165,250,.18);
}
/* Error state — keyed off aria-invalid, so setting the attribute in JS is
   the ONLY step needed to both style the field and announce it correctly. */
.ca-field-control[aria-invalid="true"]{
  border-color: #ef4444;
}
.ca-field-control[aria-invalid="true"]:focus-visible{
  box-shadow: 0 0 0 3px rgba(239,68,68,.18);
}
.ca-field-error{
  display: none;
  font-size: 12px;
  line-height: 1.4;
  color: #fca5a5;
}
.ca-field-control[aria-invalid="true"] ~ .ca-field-error,
.ca-field-error.ca-field-error--show{
  display: block;
}

/* ═══════════════════════════════════════════════════════════════════════
   MOTION — .ca-reveal (scroll-in animation, wired by CAPolish.initReveal()
   in polish.js via IntersectionObserver).
   Progressive enhancement, load-bearing: the hidden pre-reveal state only
   ever applies under html.ca-js, a class polish.js sets synchronously the
   moment it starts executing. If polish.js fails to load or throws before
   that line, html never gets .ca-js, so .ca-reveal elements are NEVER
   hidden — they render at their natural opacity:1 from the very first
   paint. JS can only ever reveal content sooner via animation, never hide
   content the CSS-only fallback would have shown.
   ═══════════════════════════════════════════════════════════════════════ */
html.ca-js .ca-reveal:not(.ca-revealed){
  opacity: 0;
  transform: translateY(12px);
}
html.ca-js .ca-reveal.ca-revealed{
  opacity: 1;
  transform: translateY(0);
  transition: opacity var(--ca-duration-slow) var(--ca-ease),
              transform var(--ca-duration-slow) var(--ca-ease);
}

/* ═══════════════════════════════════════════════════════════════════════
   TOAST SYSTEM — complementary to, NOT a replacement for, each page's
   existing appAlert()/appConfirm() modal pattern. Toasts are for
   lightweight, non-blocking notifications only; destructive-action
   confirmation must keep using a modal (appConfirm or equivalent) so the
   user has to make an explicit choice, not watch a toast time out.
   Two live regions so success/info/warning (polite — announced without
   interrupting) and error (assertive — announced immediately) get correct
   screen-reader urgency; both share the same visual stacking position.
   ═══════════════════════════════════════════════════════════════════════ */
#ca-toast-polite, #ca-toast-assertive{
  position: fixed;
  z-index: 10000;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none; /* individual toasts re-enable it */
  top: 18px;
  right: 18px;
  width: min(360px, calc(100vw - 36px));
}
@media (max-width: 900px){
  #ca-toast-polite, #ca-toast-assertive{
    top: auto;
    bottom: 18px;
    right: 18px;
    left: 18px;
    width: auto;
    align-items: center;
  }
}
.ca-toast{
  pointer-events: auto;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  border-radius: var(--ca-radius-md);
  box-shadow: var(--ca-shadow-lg);
  background: #0f172a;
  border: 1px solid rgba(148,163,184,.22);
  color: #fff;
  font-size: 13px;
  line-height: 1.45;
  animation: ca-toast-in var(--ca-duration-base) var(--ca-ease);
}
.ca-toast.ca-toast-leaving{
  animation: ca-toast-out var(--ca-duration-fast) var(--ca-ease) forwards;
}
@keyframes ca-toast-in{
  from{ opacity: 0; transform: translateY(-8px) scale(.98); }
  to{ opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes ca-toast-out{
  from{ opacity: 1; transform: translateY(0) scale(1); }
  to{ opacity: 0; transform: translateY(-8px) scale(.98); }
}
.ca-toast-icon{ flex-shrink: 0; width: 18px; height: 18px; margin-top: 1px; }
.ca-toast-body{ flex: 1; min-width: 0; }
.ca-toast-close{
  flex-shrink: 0;
  background: transparent;
  border: none;
  color: rgba(255,255,255,.5);
  cursor: pointer;
  padding: 2px;
  border-radius: var(--ca-radius-sm);
  line-height: 0;
}
.ca-toast-close:hover{ color: #fff; }
.ca-toast--success{ border-color: rgba(34,197,94,.4); }
.ca-toast--success .ca-toast-icon{ color: #4ade80; }
.ca-toast--info{ border-color: rgba(59,130,246,.4); }
.ca-toast--info .ca-toast-icon{ color: #60a5fa; }
.ca-toast--warning{ border-color: rgba(245,158,11,.4); }
.ca-toast--warning .ca-toast-icon{ color: #fbbf24; }
.ca-toast--error{ border-color: rgba(239,68,68,.4); }
.ca-toast--error .ca-toast-icon{ color: #f87171; }

/* ═══════════════════════════════════════════════════════════════════════
   SKELETON LOADERS
   ═══════════════════════════════════════════════════════════════════════ */
.skeleton{
  position: relative;
  overflow: hidden;
  background: rgba(148,163,184,.12);
  border-radius: var(--ca-radius-sm);
}
.skeleton::after{
  content: "";
  position: absolute;
  inset: 0;
  transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, rgba(255,255,255,.06), transparent);
  animation: ca-skeleton-shimmer 1.6s ease-in-out infinite;
}
@media (prefers-reduced-motion: reduce){
  .skeleton::after{ animation: none; }
}
@keyframes ca-skeleton-shimmer{
  100%{ transform: translateX(100%); }
}
.skeleton-line{ height: 12px; border-radius: var(--ca-radius-pill); margin-bottom: 8px; }
.skeleton-line:last-child{ margin-bottom: 0; width: 70%; }
.skeleton-avatar{ width: 44px; height: 44px; border-radius: 50%; flex-shrink: 0; }
.skeleton-card{ height: 120px; border-radius: var(--ca-radius-md); }

/* ═══════════════════════════════════════════════════════════════════════
   EMPTY-STATE PATTERN — icon + heading + one sentence + one primary
   action. See CAPolish.emptyStateHTML() in polish.js for a generator that
   enforces this shape rather than hand-rolling it per page.
   ═══════════════════════════════════════════════════════════════════════ */
.ca-empty-state{
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 6px;
  padding: 40px 20px;
}
.ca-empty-state-icon{
  width: 40px;
  height: 40px;
  margin-bottom: 6px;
  color: var(--muted, #94a3b8);
  opacity: .7;
}
.ca-empty-state-heading{
  font-size: 15px;
  font-weight: 800;
  color: var(--text, #fff);
}
.ca-empty-state-text{
  font-size: 13px;
  color: var(--muted, #94a3b8);
  max-width: 320px;
  line-height: 1.5;
}
.ca-empty-state-action{ margin-top: 10px; }
