/* ============================================================================
   FoundryAI — Foundry Design System · Base layer (FAI-P07-02)
   ----------------------------------------------------------------------------
   Reset + document defaults + Blazor host chrome (loading & error UI), all
   token-driven. Loaded after tokens.css. Components live in scoped .razor.css.
   ========================================================================== */

*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

body {
    margin: 0;
    min-height: 100dvh;
    background: var(--fai-canvas);
    color: var(--fai-ink-2);
    font-family: var(--fai-font-body);
    font-size: var(--fai-text-body);
    line-height: var(--fai-leading-normal);
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

/* Scores and tables read best with tabular numerals (Inter tnum). */
table,
.fai-numeric,
.fai-stat,
.fai-score {
    font-variant-numeric: tabular-nums;
}

h1, h2, h3, h4, h5, h6 {
    margin: 0 0 var(--fai-space-3);
    color: var(--fai-ink);
    font-family: var(--fai-font-display);
    font-weight: 700;
    line-height: var(--fai-leading-tight);
    text-wrap: balance;
}

h1 { font-size: var(--fai-text-2xl); }
h2 { font-size: var(--fai-text-xl); }
h3 { font-size: var(--fai-text-lg); }
h4, h5, h6 { font-size: var(--fai-text-body); }

h1:focus {
    outline: none; /* FocusOnNavigate moves focus to h1; the ring is for controls, not headings */
}

p {
    margin: 0 0 var(--fai-space-3);
}

p:last-child,
h1:last-child, h2:last-child, h3:last-child,
h4:last-child, h5:last-child, h6:last-child {
    margin-bottom: 0;
}

a {
    color: var(--fai-primary);
    text-decoration: none;
    text-underline-offset: 2px;
}

a:hover {
    color: var(--fai-primary-strong);
    text-decoration: underline;
}

code,
pre,
kbd {
    font-family: var(--fai-font-mono);
    font-size: 0.9em;
}

code {
    color: var(--fai-ink);
    background: var(--fai-surface-2);
    border-radius: var(--fai-radius-sm);
    padding: 0.1em 0.35em;
}

pre {
    background: var(--fai-surface-2);
    border: 1px solid var(--fai-border);
    border-radius: var(--fai-radius-sm);
    padding: var(--fai-space-3);
    overflow-x: auto;
}

hr {
    border: 0;
    border-top: 1px solid var(--fai-border);
    margin: var(--fai-space-4) 0;
}

img,
svg {
    max-width: 100%;
}

::selection {
    background: var(--fai-primary-soft);
    color: var(--fai-primary-strong);
}

/* -- Focus ----------------------------------------------------------------
   Never removed (UI_UX_PLAN §3.2): everything interactive gets the teal ring. */
:focus-visible {
    outline: 2px solid var(--fai-primary);
    outline-offset: 2px;
    box-shadow: var(--fai-focus-ring);
    border-radius: var(--fai-radius-sm);
}

button:focus:not(:focus-visible) {
    box-shadow: none;
}

/* -- Visually hidden but screen-reader available --------------------------- */
.fai-visually-hidden {
    position: absolute !important;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}

/* keep Bootstrap-era utility working on unmigrated pages */
.visually-hidden {
    position: absolute !important;
    width: 1px;
    height: 1px;
    margin: -1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}

/* -- Shared micro-layout helpers (used by shell + styleguide + new screens) - */
.fai-stack {
    display: flex;
    flex-direction: column;
    gap: var(--fai-gap, var(--fai-space-3));
}

.fai-cluster {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--fai-gap, var(--fai-space-2));
}

.fai-grid {
    display: grid;
    gap: var(--fai-gap, var(--fai-space-4));
    grid-template-columns: repeat(var(--fai-cols, auto-fill), minmax(var(--fai-min, 200px), 1fr));
}

/* -- WASM boot/loading chrome ------------------------------------------------ */
#app,
.loading-progress,
.loading-progress-text {
    color-scheme: light;
}

.loading-progress {
    position: absolute;
    display: block;
    width: 8rem;
    height: 8rem;
    inset: 20vh 0 auto 0;
    margin: 0 auto;
}

.loading-progress circle {
    fill: none;
    stroke: var(--fai-surface-3);
    stroke-width: 0.6rem;
    transform-origin: 50% 50%;
    transform: rotate(-90deg);
}

.loading-progress circle:last-child {
    stroke: var(--fai-primary);
    stroke-dasharray: calc(3.141 * var(--blazor-load-percentage, 0%) * 0.8), 500%;
    transition: stroke-dasharray 0.05s ease-in-out;
}

.loading-progress-text {
    position: absolute;
    text-align: center;
    font-family: var(--fai-font-display);
    font-weight: 600;
    color: var(--fai-ink-3);
    inset: calc(20vh + 3.25rem) 0 auto 0.2rem;
}

.loading-progress-text:after {
    content: var(--blazor-load-percentage-text, "Loading");
}

/* -- Blazor error UI ------------------------------------------------------------ */
#blazor-error-ui {
    color-scheme: light only;
    background: var(--fai-danger-soft);
    color: var(--fai-danger);
    border-top: 1px solid var(--fai-border);
    bottom: 0;
    box-shadow: var(--fai-shadow-sm);
    box-sizing: border-box;
    display: none;
    inset-inline: 0;
    padding: 0.6rem 1.25rem 0.7rem;
    position: fixed;
    z-index: 1000;
}

#blazor-error-ui .dismiss {
    cursor: pointer;
    position: absolute;
    inset-inline-end: 0.75rem;
    top: 0.5rem;
}

/* -- Motion preferences ---------------------------------------------------- */
@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;
    }
}

/* -- Forced colors (Windows High Contrast): ring survives without the box-shadow */
@media (forced-colors: active) {
    :focus-visible {
        outline: 2px solid Highlight;
        box-shadow: none;
    }
}

/* -- Link buttons (anchors styled as FaiButton; CSS-isolated button styles do not apply to <a>) -- */
a.fai-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--fai-space-2);
    font-family: var(--fai-font-body);
    font-weight: 600;
    line-height: 1;
    border: 1px solid transparent;
    border-radius: var(--fai-radius-md);
    cursor: pointer;
    text-decoration: none;
    white-space: nowrap;
    min-height: 40px;
    padding-inline: var(--fai-space-4);
    font-size: var(--fai-text-body);
    box-sizing: border-box;
}
a.fai-btn-sm { min-height: 32px; padding-inline: var(--fai-space-3); font-size: var(--fai-text-sm); }
a.fai-btn-lg { min-height: 48px; padding-inline: var(--fai-space-5); }
a.fai-btn-primary { background: var(--fai-primary); color: var(--fai-on-primary); }
a.fai-btn-primary:hover { background: var(--fai-primary-strong); color: var(--fai-on-primary); text-decoration: none; }
a.fai-btn-secondary { background: var(--fai-surface); color: var(--fai-ink-2); border-color: var(--fai-border-strong); }
a.fai-btn-secondary:hover { border-color: var(--fai-primary); color: var(--fai-primary-strong); text-decoration: none; }
a.fai-btn-block { display: flex; width: 100%; }
