/* ============================================================
   FinOS Base Styles
   ============================================================ */

@font-face {
  font-family: "IBM Plex Sans";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("../fonts/ibm-plex-sans-400.woff2") format("woff2");
}

@font-face {
  font-family: "IBM Plex Sans";
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url("../fonts/ibm-plex-sans-500.woff2") format("woff2");
}

@font-face {
  font-family: "IBM Plex Sans";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("../fonts/ibm-plex-sans-600.woff2") format("woff2");
}

@font-face {
  font-family: "IBM Plex Sans";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("../fonts/ibm-plex-sans-700.woff2") format("woff2");
}

/* Be Vietnam Pro — self-hosted (OFL), applied only for html[lang="vi"].
   Two subsets per weight: latin (Basic Latin) + vietnamese (VN diacritics). */
@font-face {
  font-family: "Be Vietnam Pro";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("../fonts/be-vietnam-pro/be-vietnam-pro-latin-400.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
  font-family: "Be Vietnam Pro";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("../fonts/be-vietnam-pro/be-vietnam-pro-vietnamese-400.woff2") format("woff2");
  unicode-range: U+0102-0103, U+0110-0111, U+0128-0129, U+0168-0169, U+01A0-01A1, U+01AF-01B0, U+0300-0301, U+0303-0304, U+0308-0309, U+0323, U+0329, U+1EA0-1EF9, U+20AB;
}

@font-face {
  font-family: "Be Vietnam Pro";
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url("../fonts/be-vietnam-pro/be-vietnam-pro-latin-500.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
  font-family: "Be Vietnam Pro";
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url("../fonts/be-vietnam-pro/be-vietnam-pro-vietnamese-500.woff2") format("woff2");
  unicode-range: U+0102-0103, U+0110-0111, U+0128-0129, U+0168-0169, U+01A0-01A1, U+01AF-01B0, U+0300-0301, U+0303-0304, U+0308-0309, U+0323, U+0329, U+1EA0-1EF9, U+20AB;
}

@font-face {
  font-family: "Be Vietnam Pro";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("../fonts/be-vietnam-pro/be-vietnam-pro-latin-600.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
  font-family: "Be Vietnam Pro";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("../fonts/be-vietnam-pro/be-vietnam-pro-vietnamese-600.woff2") format("woff2");
  unicode-range: U+0102-0103, U+0110-0111, U+0128-0129, U+0168-0169, U+01A0-01A1, U+01AF-01B0, U+0300-0301, U+0303-0304, U+0308-0309, U+0323, U+0329, U+1EA0-1EF9, U+20AB;
}

@font-face {
  font-family: "Be Vietnam Pro";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("../fonts/be-vietnam-pro/be-vietnam-pro-latin-700.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
  font-family: "Be Vietnam Pro";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("../fonts/be-vietnam-pro/be-vietnam-pro-vietnamese-700.woff2") format("woff2");
  unicode-range: U+0102-0103, U+0110-0111, U+0128-0129, U+0168-0169, U+01A0-01A1, U+01AF-01B0, U+0300-0301, U+0303-0304, U+0308-0309, U+0323, U+0329, U+1EA0-1EF9, U+20AB;
}

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

* {
  margin: 0;
  padding: 0;
}

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

/* --- Base --------------------------------------------------- */
body {
  height: 100%;
  background-color: hsl(var(--background));
  color: hsl(var(--foreground));
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.5;
}

/* Themed text selection. */
::selection {
  background-color: hsl(var(--primary) / 0.28);
  color: hsl(var(--foreground));
}

/* Themed custom scrollbars (WebKit + Firefox). */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb {
  background-color: var(--border-strong);
  border: 2px solid transparent;
  background-clip: padding-box;
  border-radius: 999px;
}
*::-webkit-scrollbar-thumb:hover { background-color: hsl(var(--muted-foreground)); }

/* Sane default focus ring for interactive elements without a component-specific one. */
:where(a, button, input, select, textarea, summary, [role="button"], [tabindex]:not([tabindex="-1"])):focus-visible {
  outline: 2px solid hsl(var(--ui-ring));
  outline-offset: 2px;
}

/* [exec/2474] FocusOnNavigate (App.razor:25) stamps tabindex="-1" on the page's first <h1> and focuses
   it by script, so the UA default ring (outline: auto) was painted around the heading on load. The
   focus move itself must stay (screen readers announce the new page); only the browser's default ring
   is removed. The selector cannot match a control: it needs an <h1> that script has made programmatically
   focusable, and real controls are never h1. */
h1[tabindex="-1"]:focus { outline: none; }

img,
picture,
video,
canvas,
svg {
  display: block;
  max-width: 100%;
}

input,
button,
textarea,
select {
  font: inherit;
}

p,
h1,
h2,
h3,
h4,
h5,
h6 {
  overflow-wrap: break-word;
}

#app {
  height: 100%;
}

/* --- Loading splash ----------------------------------------- */
.loading-splash {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100vh;
  gap: 1rem;
  color: hsl(var(--muted-foreground));
  font-size: 0.875rem;
}

/* Large title makes the splash the LCP element so LCP paints at first paint
   (~FCP) instead of jumping to the dashboard after the ~4s runtime boot (#646). */
.loading-splash__title {
  /* [exec/1534] T4 diagnosed this for the Family app's copy of this rule; [exec/2056] ports the
     same fix here — a long white-label name wrapped left-aligned and ragged under the centered
     logo, so it needs the same capped width + centered, balanced two-line wrap. */
  margin: 0;
  max-width: 20rem;
  text-align: center;
  text-wrap: balance;
  line-height: 1.25;
  font-size: clamp(1.25rem, 4vw, 1.75rem);
  font-weight: 700;
  color: hsl(var(--foreground));
}

.loading-splash img {
  animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.5; }
}

/* --- "Taking longer than usual" panel (exec/2560) -------------------------------------------
   Static markup lives inside .loading-splash in index.html with the `hidden` attribute;
   wwwroot/js/finos-client-log.js removes `hidden` at 15 s and fills the support code. Blazor replaces
   #app's children on first render, so the panel disappears with the splash and needs no teardown.
   Colours come from tokens only. Fallback-first: no container-query units, no :has(), no `inset`
   shorthand (the TV baseline rules in AGENTS.md apply to every new rule even on non-TV surfaces). */
.finos-slow-anchor {
  /* Zero height and a margin that cancels the splash `gap`: the card is OUT of the flow, so the logo,
     title and "loading" line stay exactly where they were when the panel appears. The `hidden`
     attribute is on this element so that, until the reporter reveals it, it takes no space at all. */
  align-self: stretch;
  position: relative;
  height: 0;
  margin-top: -1rem;
}

.finos-slow-anchor[hidden] {
  display: none;
}

.finos-slow-card {
  position: absolute;
  top: 0.5rem;
  left: 0;
  right: 0;
  margin: 0 auto;
  box-sizing: border-box;
  width: calc(100% - 2rem);
  max-width: 22rem;
  padding: 0.875rem 1rem;
  background-color: hsl(var(--card));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  box-shadow: 0 1px 3px hsl(var(--foreground) / 0.1);
  color: hsl(var(--foreground));
  text-align: center;
  font-size: 0.875rem;
  line-height: 1.45;
  animation: finos-slow-in 200ms ease-out both;
}

@keyframes finos-slow-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .finos-slow-card {
    animation: none;
  }
}

/* Language: both languages are in the markup (there is no resx before Blazor starts); <html lang>
   decides, exactly like the rest of the pre-Blazor text. Vietnamese is the default. */
.finos-slow-card .finos-en,
.finos-support-code .finos-en {
  display: none;
}

html[lang^="en"] .finos-slow-card .finos-en,
html[lang^="en"] .finos-support-code .finos-en {
  display: inline;
}

html[lang^="en"] .finos-slow-card .finos-vi,
html[lang^="en"] .finos-support-code .finos-vi {
  display: none;
}

.finos-slow-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.3;
  color: hsl(var(--foreground));
}

.finos-slow-body {
  margin: 0.375rem 0 0;
  color: hsl(var(--muted-foreground));
}

.finos-slow-code {
  margin-top: 0.75rem;
}

.finos-slow-label {
  display: block;
  font-size: 0.75rem;
  color: hsl(var(--muted-foreground));
}

.finos-slow-value {
  display: block;
  margin-top: 0.25rem;
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius);
  background-color: hsl(var(--primary) / 0.1);
  color: hsl(var(--foreground));
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 1.25rem;
  font-weight: 600;
  line-height: 1.4;
  letter-spacing: 0.08em;
  font-variant-numeric: tabular-nums;
  -webkit-user-select: all;
  user-select: all;
}

.finos-slow-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.finos-slow-btn {
  flex: 1 1 8rem;
  box-sizing: border-box;
  min-height: 44px;
  padding: 0 1rem;
  border-radius: var(--radius);
  font: inherit;
  font-weight: 600;
  line-height: 1.2;
  cursor: pointer;
}

.finos-slow-btn--primary {
  border: 1px solid hsl(var(--primary));
  background-color: hsl(var(--primary));
  color: hsl(var(--primary-foreground));
}

.finos-slow-btn--secondary {
  border: 1px solid hsl(var(--border));
  background-color: transparent;
  color: hsl(var(--foreground));
}

.finos-slow-btn:hover {
  filter: brightness(1.08);
}

.finos-slow-btn:focus-visible {
  outline: 2px solid hsl(var(--ui-ring, var(--ring)));
  outline-offset: 2px;
}

.finos-slow-done,
.finos-slow-btn[data-copied] .finos-slow-idle {
  display: none;
}

.finos-slow-btn[data-copied] .finos-slow-done {
  display: inline;
}

.finos-slow-note {
  margin: 0.5rem 0 0;
  font-size: 0.75rem;
  color: hsl(var(--muted-foreground));
}

.finos-slow-sr {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* A short viewport cannot hold the group AND the card (the card would run off the bottom edge and the
   buttons would need a scroll). There the card joins the flow and the splash re-centres as one group:
   the logo moves up, which is better than a Reload button below the fold. Placed after the card rule so
   it wins. */
@media (max-height: 47.75rem) {
  .finos-slow-anchor {
    height: auto;
    margin-top: 0;
  }

  .finos-slow-card {
    position: relative;
    top: auto;
  }
}

/* --- Blazor error UI --------------------------------------- */
#blazor-error-ui {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 1000;
  padding: 12px 16px;
  background-color: hsl(var(--destructive));
  color: hsl(var(--destructive-foreground));
  font-size: 14px;
  text-align: center;
}

#blazor-error-ui .reload {
  color: inherit;
  font-weight: 600;
  margin-left: 8px;
  text-decoration: underline;
}

#blazor-error-ui .dismiss {
  position: absolute;
  top: 50%;
  right: 12px;
  transform: translateY(-50%);
  width: 28px;
  height: 28px;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: inherit;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
}

#blazor-error-ui .dismiss:hover {
  background-color: hsl(var(--destructive-foreground) / 0.18);
}

/* Support code inside the bar (exec/2560): revealed by finos-client-log.js only when a code exists.
   The symmetric side padding keeps wrapped text clear of the dismiss button (which is centred
   vertically at the right edge) while the text stays centred. */
#blazor-error-ui {
  padding-left: 44px;
  padding-right: 44px;
}

#blazor-error-ui .finos-support-code {
  margin-left: 8px;
  white-space: nowrap;
}

#blazor-error-ui .reload {
  white-space: nowrap;
}

#blazor-error-ui .finos-support-code[hidden] {
  display: none;
}

#blazor-error-ui .finos-support-code .finos-en {
  display: none;
}

html[lang^="en"] #blazor-error-ui .finos-support-code .finos-en {
  display: inline;
}

html[lang^="en"] #blazor-error-ui .finos-support-code .finos-vi {
  display: none;
}

#blazor-error-ui .finos-support-code b {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-weight: 600;
  letter-spacing: 0.04em;
  -webkit-user-select: all;
  user-select: all;
}

/* --- Utilities --------------------------------------------- */

/* Screen-reader only */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

/* A hidden chart table is still a table box, which `overflow: hidden` does not clip: its cells would
   stretch the page sideways. A block box clips. */
table.sr-only {
  display: block;
  width: 1px !important;
  height: 1px !important;
  max-width: 1px !important;
}

/* Layout */
.container {
  width: 100%;
  max-width: 1280px;
  margin-inline: auto;
  padding-inline: 1rem;
}

.flex {
  display: flex;
}

.flex-col {
  flex-direction: column;
}

.items-center {
  align-items: center;
}

.justify-between {
  justify-content: space-between;
}

.gap-2 {
  gap: 0.5rem;
}

.gap-4 {
  gap: 1rem;
}

.grid {
  display: grid;
}

/* Visual */
.rounded {
  border-radius: var(--radius);
}

.shadow {
  box-shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
}

.shadow-md {
  box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
}

.border {
  border: 1px solid hsl(var(--border));
}

/* Typography */
.text-sm {
  font-size: 0.875rem;
  line-height: 1.25rem;
}

.text-xs {
  font-size: 0.75rem;
  line-height: 1rem;
}

.text-lg {
  font-size: 1.125rem;
  line-height: 1.75rem;
}

.text-xl {
  font-size: 1.25rem;
  line-height: 1.75rem;
}

.text-2xl {
  font-size: 1.5rem;
  line-height: 2rem;
}

.text-muted {
  color: hsl(var(--muted-foreground));
}

.font-medium {
  font-weight: 500;
}

.font-semibold {
  font-weight: 600;
}

.font-bold {
  font-weight: 700;
}

.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Spacing helpers */
.p-4 {
  padding: 1rem;
}

.p-6 {
  padding: 1.5rem;
}

.px-4 {
  padding-inline: 1rem;
}

.py-2 {
  padding-block: 0.5rem;
}

.mt-1 {
  margin-top: 0.25rem;
}

.mt-4 {
  margin-top: 1rem;
}

.w-full {
  width: 100%;
}

.h-full {
  height: 100%;
}

/* --- Admin shared ------------------------------------------ */
.admin-page-title {
  font-size: 1.5rem;
  font-weight: 600;
  color: hsl(var(--foreground));
  margin-bottom: .5rem;
}

.admin-page-hint {
  font-size: .875rem;
  color: hsl(var(--muted-foreground));
  margin-bottom: 1.5rem;
}

/* ============================================================
   TV D-pad focus ring (#426) — shared across TV pages.
   Strong remote-focus ring, distinct from selected/playing/today
   states. Uses transform (not box size) so focus never shifts layout.
   ============================================================ */
.tv-focusable {
  outline: none;
  transition: transform 120ms ease, box-shadow 120ms ease;
}

.tv-focusable:focus-visible,
.tv-focusable.tv-focus {
  /* 4px accent ring + white halo + glow; scale is purely visual (no reflow). */
  outline: 4px solid #2563eb;
  outline-offset: 2px;
  box-shadow: 0 0 0 2px #fff, 0 0 0 8px rgba(37, 99, 235, 0.35), 0 8px 28px rgba(37, 99, 235, 0.30);
  transform: scale(1.02);
  z-index: 5;
  position: relative;
  border-radius: 12px;
}

@media (prefers-reduced-motion: reduce) {
  .tv-focusable { transition: none; }
  .tv-focusable:focus-visible,
  .tv-focusable.tv-focus { transform: none; }
}

/* The anchored-popover `@position-try` fallbacks used to live here ([exec/1157]).
   [exec/1201] moved them to `_content/FinOS.Wasm.Controls/css/popover.css`: a
   `@position-try` name is document-global, and this sheet is not loaded by the Family
   app, so `UiSelect` there had no flip behaviour at all. They now ship with the assembly
   that defines the components using them. Do not re-add a copy here. */

/* Boot splash in index.html, shown until Blazor renders into #app. */
.boot-splash {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: var(--surface-page);
  color: var(--text-secondary);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
.boot-splash__logo { width: 56px; height: 56px; }
.boot-splash__name { font-size: 20px; font-weight: 600; color: var(--text-primary); }
.boot-splash__bar {
  width: 160px;
  height: 4px;
  border-radius: 2px;
  overflow: hidden;
  background: var(--border-subtle);
}
.boot-splash__bar span {
  display: block;
  width: 40%;
  height: 100%;
  border-radius: 2px;
  background: hsl(var(--primary-fill));
  animation: boot-splash-slide 1.2s ease-in-out infinite;
}
.boot-splash__text { font-size: 13px; }
@keyframes boot-splash-slide {
  from { transform: translateX(-100%); }
  to { transform: translateX(250%); }
}
@media (prefers-reduced-motion: reduce) {
  .boot-splash__bar span { animation: none; width: 100%; }
}
