/* TriHard loading states — skeletons, inline trace spinner, full-screen loader.
   Ported from the trihard-ui design kit; uses only --th-* tokens already
   loaded by brand-tokens.css. Classes
   are namespaced th-* so they never collide with the app's own .card/.hint/
   .btn etc. */

:root {
    --th-skel-base: color-mix(in srgb, var(--th-text) 7%, transparent);
    --th-skel-hi: color-mix(in srgb, var(--th-text) 9%, transparent);
    --th-ghost: color-mix(in srgb, var(--th-text) 10%, transparent);
    --th-ghost-hi: color-mix(in srgb, var(--th-text) 38%, transparent);
    --th-pop-ease: cubic-bezier(.3, 1.6, .5, 1);
}

@keyframes th-fade-in { from { opacity: 0; } }
@keyframes th-sweep { from { background-position: -40vw 0; } to { background-position: 100vw 0; } }
@keyframes th-scan { from { stroke-dashoffset: .16; } to { stroke-dashoffset: -1.2; } }
@keyframes th-run { from { stroke-dashoffset: 0; } to { stroke-dashoffset: -1; } }
@keyframes th-run-head { from { stroke-dashoffset: -.27; } to { stroke-dashoffset: -1.27; } }
@keyframes th-grow-x { to { transform: scaleX(1); } }

.th-fade { animation: th-fade-in 280ms var(--th-ease) both; }
.th-grow-x { transform-origin: 0 50%; transform: scaleX(0); animation: th-grow-x 700ms var(--th-ease) forwards; }
.th-sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
@media (prefers-reduced-motion: reduce) { .th-grow-x { animation: none; transform: none; } }

/* ---------- chart-card states (loading / empty / error) ---------- */
.th-card__state { display: grid; place-content: center; justify-items: center; gap: 12px; text-align: center; padding: 24px 0; }
.th-card__state p { margin: 0; max-width: 32ch; font: 400 14px/1.45 var(--th-font-ui); color: var(--th-text-muted); }

/* ---------- skeletons ---------- */
.th-skel { display: block; position: relative; overflow: hidden; background: var(--th-skel-base); border-radius: var(--th-radius-sm); }
.th-skel::after {
    content: ""; position: absolute; inset: 0;
    background-image: linear-gradient(90deg, transparent, var(--th-skel-hi), transparent);
    background-size: 40vw 100%; background-repeat: no-repeat;
    background-attachment: fixed; /* every skeleton on screen sweeps in sync */
    animation: th-sweep 1.8s var(--th-ease) infinite;
}
.th-skel-stack { display: flex; flex-direction: column; width: 100%; gap: 10px; }
.th-skel-row { display: flex; align-items: center; gap: 10px; }
.th-skel-metric { display: flex; flex-direction: column; gap: 8px; }
.th-skel-metric__row { display: flex; align-items: flex-end; gap: 6px; }

.th-chart-skel { width: 100%; }
.th-chart-skel__svg { display: block; overflow: visible; width: 100%; }
.th-chart-skel__bars { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; align-items: end; padding-top: 36px; box-sizing: border-box; height: 100%; }
.th-chart-skel__race { display: flex; gap: 3px; }
.th-chart-skel__legend { display: flex; flex-wrap: wrap; gap: 12px 24px; }
.th-chart-skel__zone { display: grid; grid-template-columns: 24px 1fr 44px; gap: 12px; align-items: center; }
.th-grid-skel { stroke: var(--th-line); stroke-width: 1; shape-rendering: crispEdges; opacity: .75; }
.th-ghost { stroke: var(--th-ghost); stroke-width: 2.25; stroke-linecap: round; fill: none; }
.th-ghost-scan { stroke: var(--th-ghost-hi); stroke-width: 2.25; stroke-linecap: round; stroke-dasharray: .16 1.2; fill: none; animation: th-scan 1.8s var(--th-ease) infinite; }

/* ---------- inline trace spinner (buttons, sync status) ---------- */
.th-spinner { display: inline-flex; align-items: center; vertical-align: middle; color: inherit; }
.th-spinner svg { display: block; overflow: visible; }
.th-spinner__base, .th-spinner__run { fill: none; stroke: currentColor; stroke-width: 11; stroke-linecap: round; stroke-linejoin: round; }
.th-spinner__base { opacity: .22; }
.th-spinner__head { fill: none; stroke: #FF6B1F; stroke-width: 13; stroke-linecap: round; stroke-linejoin: round; stroke-dasharray: .05 .95; animation: th-run-head 1.1s linear infinite; }
.th-spinner__run { stroke-dasharray: .32 .68; animation: th-run 1.1s linear infinite; }

/* ---------- full-screen loader (always ink) ---------- */
.th-fsl {
    position: fixed; inset: 0; z-index: 1000; display: grid; place-items: center;
    padding: env(safe-area-inset-top, 0px) 24px env(safe-area-inset-bottom, 0px);
    background: radial-gradient(60% 55% at 62% 50%, rgb(255 107 31 / .09), transparent 70%), #101820; color: #F4F2EC;
    animation: th-fade-in 240ms ease both; transition: opacity 460ms var(--th-ease);
}
.th-fsl--exit { opacity: 0; pointer-events: none; }
.th-fsl__inner { display: flex; flex-direction: column; align-items: center; gap: 40px; width: min(440px, 76vw); transition: transform 460ms var(--th-ease); }
.th-fsl--exit .th-fsl__inner { transform: translateY(-8px) scale(.985); }
.th-loader { width: 100%; height: auto; overflow: visible; display: block; }
.th-loader__course, .th-loader__line, .th-loader__hot { fill: none; stroke-width: 13; stroke-linecap: round; stroke-linejoin: round; }
.th-loader__course { stroke: rgb(244 242 236 / .12); }
.th-loader__line { stroke: #F4F2EC; stroke-dasharray: 1 1; stroke-dashoffset: 1; }
.th-loader__hot { stroke: #FF6B1F; stroke-width: 17; opacity: 0; }
.th-loader__dot { fill: #FF6B1F; fill-opacity: .14; stroke: #FF6B1F; stroke-opacity: .55; stroke-width: 2; transform-box: fill-box; transform-origin: center; transition: fill-opacity 120ms ease, stroke-opacity 120ms ease; }
.th-loader__dot.is-lit { fill-opacity: 1; stroke-opacity: 0; }
.th-loader__ring { fill: none; stroke: #FF6B1F; stroke-width: 2.5; opacity: 0; transform-box: fill-box; transform-origin: center; }
.th-fsl__mark { width: 100%; }
.th-fsl__status { display: flex; align-items: baseline; gap: 12px; min-height: 22px; }
.th-fsl__msg { font: 500 15px/1.4 var(--th-font-ui); color: rgb(244 242 236 / .7); text-align: center; }
.th-fsl__pct { font: 600 13px/1 var(--th-font-data); font-variant-numeric: tabular-nums; color: #F4F2EC; }

/* Ink panel the TraceLoader races inside, used everywhere a chart is
   loading (both the innerHTML case and the canvas-overlay case). */
.th-chart-loader {
    display: flex; align-items: center; justify-content: center;
    width: 100%; height: 100%;
    background: #101820;
    border-radius: 16px;
    overflow: hidden;
}
.th-chart-loader__mount { width: 100%; max-width: 260px; padding: 0 20px; }

/* ---------- reduced motion: show end states, keep only gentle changes ---------- */
@media (prefers-reduced-motion: reduce) {
    .th-fade, .th-fsl { animation: none; }
    .th-skel::after { animation: none; background: none; }
    .th-ghost-scan { display: none; }
    .th-spinner__run { animation-duration: 3s; }
    .th-spinner__head { animation: none; opacity: 0; }
    .th-fsl__inner { transition: none; }
}
