/* Shared design tokens + light/dark themes for the whole Rayton site. */

/* Brand palette: Rayton navy + teal (from the logo). */
:root,
:root[data-theme="dark"] {
  --bg: #0b1620;
  --bg-grad: radial-gradient(1200px 600px at 80% -10%, #14293a 0%, #0b1620 55%);
  --panel: #122130;
  --panel-2: #1a2c3d;
  --line: #26394b;
  --text: #e8eef4;
  --muted: #90a2b3;        /* raised for AA contrast on panels */
  --accent: #2f9d88;       /* matured brand teal - desaturated, deeper */
  --accent-2: #268a77;
  --accent-ink: #04231d;
  --accent-tint: color-mix(in srgb, var(--accent) 14%, transparent);
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.34);

  /* Gain / loss / unchanged - luminance-distinct, always paired with a glyph/sign
     (never colour alone) so colourblind readers rely on shape + brightness. */
  --up: #2fae74;
  --down: #e0555a;
  --flat: #5b8fd6;
  --up-bg: rgba(47, 174, 116, 0.14);
  --down-bg: rgba(224, 85, 90, 0.14);
  --flat-bg: rgba(91, 143, 214, 0.14);

  /* Unverified / manual-entry trust cue (amber, distinct from gain/loss). */
  --warn: #d9a441;
  --warn-bg: rgba(217, 164, 65, 0.14);

  /* ---- Type scale: √φ (1.272) anchored at 14px body ---- */
  --fs-cap: 11px;  --fs-sm: 12.5px; --fs-body: 14px; --fs-lg: 17px;
  --fs-xl: 22px;   --fs-2xl: 28px;  --fs-3xl: 36px;
  /* ---- Spacing: 4px micro-grid, sections step by ~φ ---- */
  --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px;
  --sp-5: 24px; --sp-6: 38px; --sp-7: 60px;
  /* ---- Radii ---- */
  --r-sm: 6px; --r-md: 10px; --r-lg: 14px; --r-pill: 999px;
  /* ---- Motion: fast, decelerating, institutional (no bounce/overshoot) ---- */
  --ease-out: cubic-bezier(0.22, 0.61, 0.36, 1);
  --dur-1: 120ms; --dur-2: 200ms; --dur-3: 320ms;
}

:root[data-theme="light"] {
  --bg: #eef2f5;
  --bg-grad: radial-gradient(1200px 600px at 80% -10%, #ffffff 0%, #eef2f5 55%);
  --panel: #ffffff;
  --panel-2: #f2f6f8;
  --line: #e0e7ec;
  --text: #0b1620;
  --muted: #556472;
  --accent: #10806c;       /* matured brand teal for light bg */
  --accent-2: #0c6c5a;
  --accent-ink: #ffffff;
  --accent-tint: color-mix(in srgb, var(--accent) 12%, transparent);
  --shadow: 0 8px 24px rgba(11, 30, 45, 0.10);

  --up: #0f9d58;
  --down: #cf3a34;
  --flat: #2563eb;
  --up-bg: rgba(15, 157, 88, 0.12);
  --down-bg: rgba(207, 58, 52, 0.12);
  --flat-bg: rgba(37, 99, 235, 0.12);

  --warn: #b7791f;
  --warn-bg: rgba(183, 121, 31, 0.13);
}

* { box-sizing: border-box; }

/* Accessibility: a single, visible keyboard-focus ring everywhere. Mouse users
   don't see it (:focus-visible), keyboard users always do. */
:where(a, button, input, select, textarea, [tabindex]):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}

/* Money/percentage figures read as a column: same-width digits everywhere. */
.num, .value, .chg, .chip, td.num, .tabnum { font-variant-numeric: tabular-nums; }

/* Screen-reader-only text: visually hidden, still read aloud + reachable by AT.
   Used for chart/table descriptions and off-screen data summaries. */
.sr-only {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

/* Loading skeletons: placeholder blocks at the real dimensions of what's coming,
   so the layout doesn't jump when data arrives (design-system edge states). */
@keyframes sk-shimmer { 0% { background-position: -320px 0; } 100% { background-position: 320px 0; } }
.skeleton {
  border-radius: var(--r-sm); color: transparent !important;
  background: linear-gradient(90deg,
    color-mix(in srgb, var(--muted) 12%, var(--panel)) 25%,
    color-mix(in srgb, var(--muted) 20%, var(--panel)) 50%,
    color-mix(in srgb, var(--muted) 12%, var(--panel)) 75%);
  background-size: 320px 100%; animation: sk-shimmer 1.15s linear infinite;
}
@media (prefers-reduced-motion: reduce) { .skeleton { animation: none; } }
.sk-line { height: 12px; margin: 7px 0; }
.sk-line.lg { height: 26px; } .sk-line.w60 { width: 60%; } .sk-line.w40 { width: 40%; } .sk-line.w80 { width: 80%; }

/* ---- Motion: subtle entrances + interaction feedback ----
   Restrained on purpose — a calm rise-and-settle, never a bounce. The page
   structure eases in once on load; interactive elements get a fast, consistent
   transition and a small press response. All of it is disabled below for anyone
   who prefers reduced motion. */
@keyframes rise-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

/* Page sections ease in on load with a short, capped stagger. */
main > section, main > .panel, main > .book-grid, main > .grid2 {
  animation: rise-in var(--dur-3) var(--ease-out) both;
}
main > *:nth-child(1) { animation-delay: 0ms; }
main > *:nth-child(2) { animation-delay: 40ms; }
main > *:nth-child(3) { animation-delay: 80ms; }
main > *:nth-child(4) { animation-delay: 120ms; }
main > *:nth-child(5) { animation-delay: 150ms; }
main > *:nth-child(n+6) { animation-delay: 170ms; }

/* Consistent, fast interaction feedback. */
.btn, .sb-link, .sb-ask, .icon-btn, .segmented button, .chip, .theme-toggle {
  transition: background-color var(--dur-1) var(--ease-out),
              border-color var(--dur-1) var(--ease-out),
              color var(--dur-1) var(--ease-out),
              transform var(--dur-1) var(--ease-out),
              filter var(--dur-1) var(--ease-out);
}
.btn:active, .icon-btn:active, .segmented button:active, .sb-ask:active { transform: translateY(1px); }

/* Skeleton → real content: content fades in when it replaces placeholders. */
.just-loaded { animation: fade-in var(--dur-2) var(--ease-out) both; }

/* Honour the OS "reduce motion" setting: kill all animation/transition. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-delay: 0ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}

/* Trust cue: manual, non-statement-backed figures are badged, never silently
   mixed with authoritative numbers (design-system golden thread #5). */
.badge-unverified {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: var(--fs-cap); font-weight: 700; letter-spacing: .3px;
  padding: 2px 8px; border-radius: var(--r-pill);
  color: var(--warn); background: var(--warn-bg);
  border: 1px solid color-mix(in srgb, var(--warn) 40%, transparent);
}
.badge-source {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: var(--fs-cap); font-weight: 700; letter-spacing: .3px;
  padding: 2px 8px; border-radius: var(--r-pill);
  color: var(--accent); background: var(--accent-tint);
}

html { color-scheme: dark; }
html[data-theme="light"] { color-scheme: light; }

body {
  margin: 0;
  background: var(--bg-grad);
  background-attachment: fixed;
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  min-height: 100vh;
  transition: background-color 0.25s ease, color 0.25s ease;
}

a { color: inherit; }

/* Brand logos - theme-aware (dark-on-light vs white-on-dark variants). */
.brand { display: flex; align-items: center; gap: 12px; text-decoration: none; }

/* Full Rayton Investments lockup (icon + wordmark). */
.brand-logo {
  display: block; height: 30px; aspect-ratio: 2560 / 927;
  background: url("/static/brand/ri-full-light.png") left center / contain no-repeat;
}
:root[data-theme="dark"] .brand-logo { background-image: url("/static/brand/ri-full-dark.png"); }
.brand-logo.lg { height: 46px; }

/* RaytonCorp lockup. */
.rc-logo {
  display: block; height: 44px; aspect-ratio: 1920 / 697;
  background: url("/static/brand/rc-full-light.png") left center / contain no-repeat;
}
:root[data-theme="dark"] .rc-logo { background-image: url("/static/brand/rc-full-dark.png"); }

/* Standalone icon mark. */
.brand-mark {
  width: 40px; height: 40px; flex: none;
  background: url("/static/brand/ri-icon-light.png") center / contain no-repeat;
}
:root[data-theme="dark"] .brand-mark { background-image: url("/static/brand/ri-icon-dark.png"); }

/* Small page-context label shown after the logo in app headers. */
.page-label {
  color: var(--muted); font-size: 12px; font-weight: 700; letter-spacing: 1.5px;
  text-transform: uppercase; padding-left: 12px; margin-left: 2px;
  border-left: 1px solid var(--line);
}

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: 8px; justify-content: center;
  background: var(--panel); color: var(--text); border: 1px solid var(--line);
  padding: 10px 16px; border-radius: 10px; cursor: pointer; font-size: 14px;
  font-weight: 600; text-decoration: none; transition: all 0.15s ease;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: var(--accent-2); border-color: var(--accent-2); }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Theme toggle */
.theme-toggle {
  width: 40px; height: 40px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--panel); color: var(--text); cursor: pointer; font-size: 17px;
  display: grid; place-items: center;
}
.theme-toggle:hover { border-color: var(--accent); }

/* ---- Canonical metric card (design-system component; one language everywhere) ----
   Replaces the per-page card variants (kpi / mv-card / stat / policy-card) so every
   headline figure on every page reads the same: lead with the value, label above,
   context below, tabular figures, 1px border, no shadow. */
.metric-row { display: grid; gap: var(--sp-4); grid-template-columns: repeat(4, 1fr); }
.metric-row.cols-3 { grid-template-columns: repeat(3, 1fr); }
.metric-row.cols-2 { grid-template-columns: repeat(2, 1fr); }
@media (max-width: 900px) { .metric-row, .metric-row.cols-3 { grid-template-columns: 1fr 1fr; } }
@media (max-width: 560px) { .metric-row, .metric-row.cols-3, .metric-row.cols-2 { grid-template-columns: 1fr; } }
.metric {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-lg);
  padding: var(--sp-5); min-width: 0;
}
.metric .m-label {
  color: var(--muted); font-size: var(--fs-cap); font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.5px;
  display: flex; align-items: center; gap: 6px;
}
.metric .m-value {
  font-size: var(--fs-xl); font-weight: 750; letter-spacing: -0.3px; line-height: 1.15;
  margin-top: 7px; font-variant-numeric: tabular-nums;
}
.metric .m-value.lg { font-size: var(--fs-2xl); }
.metric .m-sub { color: var(--muted); font-size: var(--fs-sm); margin-top: 5px; line-height: 1.45; }
/* Optional 3px status rail on the left — the ONLY place a metric card carries colour. */
.metric.accent { border-left: 3px solid var(--accent); }
.metric.up { border-left: 3px solid var(--up); }
.metric.down { border-left: 3px solid var(--down); }
.metric.warn { border-left: 3px solid var(--warn); }

/* Change chips (gain / loss / unchanged) */
.chg { font-variant-numeric: tabular-nums; font-weight: 600; }
.chg.up { color: var(--up); }
.chg.down { color: var(--down); }
.chg.flat { color: var(--flat); }
.chip {
  display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 999px;
  font-size: 13px; font-weight: 700; font-variant-numeric: tabular-nums;
}
.chip.up { color: var(--up); background: var(--up-bg); }
.chip.down { color: var(--down); background: var(--down-bg); }
.chip.flat { color: var(--flat); background: var(--flat-bg); }
