/* ==========================================================================
   base.css — Kai-Signals: normalize, document base, typography foundation
   Loaded after tokens.css / light.css / dark.css.
   ========================================================================== */

/* ── Box model ───────────────────────────────────────────────────────────── */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* Ensure [hidden] always wins over component display values */
[hidden] { display: none !important; }

/* ── Document ────────────────────────────────────────────────────────────── */
html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  hanging-punctuation: first last;
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
}

body {
  font-family: var(--font-body);
  font-size: var(--text-body-md-size);
  line-height: var(--text-body-md-line);
  font-weight: var(--text-body-md-weight);
  color: var(--text-primary);
  background-color: var(--surface-page);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* ── Headings ────────────────────────────────────────────────────────────── */
h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-display);
  font-weight: 700;
  line-height: 1.2;
  color: var(--text-primary);
  text-wrap: balance;
}

h1 { font-size: var(--text-display-md-size); line-height: var(--text-display-md-line); font-weight: var(--text-display-md-weight); }
h2 { font-size: var(--text-display-sm-size); line-height: var(--text-display-sm-line); font-weight: var(--text-display-sm-weight); }
h3 { font-size: var(--text-heading-lg-size); line-height: var(--text-heading-lg-line); font-weight: var(--text-heading-lg-weight); font-family: var(--font-body); }
h4 { font-size: var(--text-heading-md-size); line-height: var(--text-heading-md-line); font-weight: var(--text-heading-md-weight); font-family: var(--font-body); }
h5, h6 { font-size: var(--text-body-lg-size); line-height: var(--text-body-lg-line); font-weight: 600; font-family: var(--font-body); }

/* ── Paragraphs ──────────────────────────────────────────────────────────── */
p {
  font-size: var(--text-body-md-size);
  line-height: var(--text-body-md-line);
  color: var(--text-secondary);
  text-wrap: pretty;
}

p + p { margin-top: var(--space-4); }

/* ── Links ───────────────────────────────────────────────────────────────── */
a {
  color: var(--text-link);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
  transition: color var(--duration-fast) var(--easing-default);
  /* Chromium/Firefox default anchors to a pointer cursor via their own UA
     stylesheet even after the anchor is blockified (e.g. a flex item) — Safari
     does not, and silently falls back to the arrow cursor on any link that
     isn't plain inline. Declaring it here covers every link site-wide. */
  cursor: pointer;
}

a:hover {
  color: var(--text-link-hover);
}

a:not([class]) {
  text-decoration-skip-ink: auto;
}

/* ── Focus visible — accessible focus ring ───────────────────────────────── */
:focus-visible {
  outline: 2px solid var(--color-brand-teal);
  outline-offset: 3px;
  border-radius: 3px;
}

/* Remove focus ring for mouse/touch users (progressive) */
:focus:not(:focus-visible) {
  outline: none;
}

/* ── Selection ───────────────────────────────────────────────────────────── */
/* Highlight pseudo-elements (::selection) inherit through a separate chain
   (CSS Pseudo-4) that WebKit does not resolve custom properties against —
   a var() here goes invalid at computed-value time in Safari and falls back
   to its default grey selection, while Chromium resolves it fine. Literal
   hex values only. Mirrors --color-brand-teal-muted/-strong (light) and
   --color-brand-teal-dim (tokens.css) + the --signal-tint-*-on-chip dark
   accent (dark.css) for the dark-mode pair.

   All four blocks below mirror the light.css/dark.css theming pattern
   exactly (default, OS-dark media query, explicit light, explicit dark) —
   the explicit :root[data-theme] blocks carry higher specificity (0,2,1 vs
   0,0,1) so a manual toggle always wins over the OS media query regardless
   of source order. Dropping the [data-theme="light"] block would leave a
   user whose OS is dark but who explicitly picked the light theme with the
   dark selection colours, since prefers-color-scheme tracks the OS setting
   independently of data-theme. */
::selection {
  background-color: #E0F2F1;
  color: #2D8B89;
}

@media (prefers-color-scheme: dark) {
  ::selection {
    background-color: #1B3A40;
    color: #4FC3C0;
  }
}

:root[data-theme="light"] ::selection {
  background-color: #E0F2F1;
  color: #2D8B89;
}

:root[data-theme="dark"] ::selection {
  background-color: #1B3A40;
  color: #4FC3C0;
}

/* ── Images & media ──────────────────────────────────────────────────────── */
img,
picture,
video,
canvas,
svg {
  display: block;
  max-width: 100%;
}

img { height: auto; }

/* ── Lists ───────────────────────────────────────────────────────────────── */
ul, ol {
  list-style: none;
}

/* Prose lists (inside .legal-page, .faq — apply styles via cascade) */
.prose ul, .prose ol,
.legal-page__body ul, .legal-page__body ol,
.risk-disclosure__body ul, .risk-disclosure__body ol,
.methodology__content ul, .methodology__content ol {
  list-style: disc;
  padding-left: var(--space-6);
}

.prose ol, .legal-page__body ol, .risk-disclosure__body ol, .methodology__content ol {
  list-style: decimal;
}

.prose li, .legal-page__body li, .risk-disclosure__body li, .methodology__content li {
  font-size: var(--text-body-md-size);
  line-height: var(--text-body-md-line);
  color: var(--text-secondary);
  margin-top: var(--space-2);
}

/* ── Tables ──────────────────────────────────────────────────────────────── */
table { border-collapse: collapse; width: 100%; }
th, td {
  text-align: left;
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--surface-border);
  font-size: var(--text-body-sm-size);
  line-height: var(--text-body-sm-line);
}
th {
  font-weight: 600;
  color: var(--text-primary);
  background-color: var(--surface-raised);
}
td { color: var(--text-secondary); }
tr:last-child td { border-bottom: none; }
tr:hover td { background-color: var(--surface-raised); }

/* ── Code / pre ──────────────────────────────────────────────────────────── */
code {
  font-family: var(--font-mono);
  font-size: 0.875em;
  background-color: var(--surface-raised);
  border: 1px solid var(--surface-border);
  border-radius: 4px;
  padding: 0.1em 0.4em;
  color: var(--text-primary);
}

pre {
  font-family: var(--font-mono);
  font-size: var(--text-mono-sm-size);
  background-color: var(--surface-raised);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-card);
  padding: var(--space-4);
  overflow-x: auto;
  color: var(--text-primary);
}

pre code {
  background: none;
  border: none;
  padding: 0;
  font-size: inherit;
}

/* ── Horizontal rule ─────────────────────────────────────────────────────── */
hr {
  border: none;
  border-top: 1px solid var(--surface-border);
  margin: var(--space-8) 0;
}

/* ── Blockquote ──────────────────────────────────────────────────────────── */
blockquote {
  border-left: 3px solid var(--color-brand-teal);
  padding-left: var(--space-5);
  margin: var(--space-6) 0;
  color: var(--text-secondary);
  font-style: italic;
}

/* ── Form base ───────────────────────────────────────────────────────────── */
input, textarea, select {
  font-family: var(--font-body);
  font-size: var(--text-body-md-size);
  color: var(--input-text);
  background-color: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: var(--radius-input);
  padding: var(--space-3) var(--space-4);
  width: 100%;
  -webkit-appearance: none;
  appearance: none;
  transition: border-color var(--duration-fast) var(--easing-default),
              box-shadow var(--duration-fast) var(--easing-default);
}

/* Safari paints its own yellow/blue background on autofilled fields,
   ignoring background-color, and the fill can't be un-set directly — the
   standard workaround is an inset box-shadow the size of the field, which
   paints over it. -webkit-text-fill-color re-applies the themed text colour,
   since `color` alone doesn't survive on an autofilled field either. The
   long transition delay defers Safari's own repaint so ours wins. */
input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus,
input:-webkit-autofill:active {
  -webkit-box-shadow: 0 0 0 1000px var(--input-bg) inset;
  -webkit-text-fill-color: var(--input-text);
  caret-color: var(--input-text);
  transition: background-color 600000s 0s, color 600000s 0s;
}

/* Bare <button>s (and unstyled [type=submit]/[type=button]/[type=reset])
   never had an appearance reset — Safari's native `push-button` chrome shows
   through any button whose class doesn't set its own opaque background
   (ghost/secondary/outline/link variants, disabled buttons, icon buttons).
   `button` itself is a plain element selector (0,0,1), so any class-level
   rule beats it — but the [type="..."] alternatives are attribute selectors
   with class-level specificity (0,1,0), which only lose to a one-class rule
   because this file loads before every other stylesheet (_SeoHead.cshtml).
   A future rule that styles a button via a bare [type="..."] selector (no
   class) would tie on specificity and the winner would depend on source
   order, not the class-always-wins guarantee this used to claim — don't
   add one without also giving it a class. */
button, [type="button"], [type="submit"], [type="reset"] {
  -webkit-appearance: none;
  appearance: none;
  background-color: transparent;
  border: none;
  font: inherit;
  color: inherit;
}

/* Safari honors `appearance: none` on <select> strictly (unlike its more
   lenient native-checkbox/radio behavior) and, unlike Chromium/Firefox, draws
   no fallback dropdown affordance at all once it's removed — so every select
   needs an explicit chevron. Drawn via `background-image` (not `mask-image`,
   which would clip the select's own text/value to the mask shape). Colour
   comes from the --select-chevron token (light.css/dark.css) since
   currentColor isn't honoured inside a background SVG's data URI. */
select {
  padding-right: calc(var(--space-4) * 2 + 12px);
  background-repeat: no-repeat;
  background-position: right var(--space-4) center;
  background-size: 12px 8px;
  background-image: var(--select-chevron);
}

/* Safari's native date/time control has its own fixed intrinsic layout
   (segmented value + calendar/clock icon) that the shared appearance:none +
   width:100% reset above clashes with — the icon can get pushed off-center
   and the value text renders centered instead of left-aligned once
   appearance is stripped. Chromium tolerates the same reset fine. */
input[type="date"], input[type="time"] {
  min-height: calc(var(--text-body-md-line) + var(--space-3) * 2);
}

input[type="date"]::-webkit-calendar-picker-indicator,
input[type="time"]::-webkit-calendar-picker-indicator {
  margin-inline-start: auto;
  cursor: pointer;
}

input[type="date"]::-webkit-date-and-time-value,
input[type="time"]::-webkit-date-and-time-value {
  text-align: left;
}

input::placeholder, textarea::placeholder {
  color: var(--input-placeholder);
}

input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--input-border-focus);
  box-shadow: 0 0 0 3px rgb(from var(--color-brand-teal) r g b / 0.2);
}

label {
  font-family: var(--font-body);
  font-size: var(--text-label-size);
  font-weight: var(--text-label-weight);
  line-height: var(--text-label-line);
  color: var(--text-primary);
  display: block;
  margin-bottom: var(--space-2);
}

/* ── Utility — typography shorthand ─────────────────────────────────────── */
.body-lg    { font-family: var(--font-body); font-size: var(--text-body-lg-size);    line-height: var(--text-body-lg-line);    font-weight: var(--text-body-lg-weight); }
.body-md    { font-family: var(--font-body); font-size: var(--text-body-md-size);    line-height: var(--text-body-md-line);    font-weight: var(--text-body-md-weight); }
.body-sm    { font-family: var(--font-body); font-size: var(--text-body-sm-size);    line-height: var(--text-body-sm-line);    font-weight: var(--text-body-sm-weight); }
.heading-lg { font-family: var(--font-body); font-size: var(--text-heading-lg-size); line-height: var(--text-heading-lg-line); font-weight: var(--text-heading-lg-weight); }
.heading-md { font-family: var(--font-body); font-size: var(--text-heading-md-size); line-height: var(--text-heading-md-line); font-weight: var(--text-heading-md-weight); }
.label      { font-family: var(--font-body); font-size: var(--text-label-size);      line-height: var(--text-label-line);      font-weight: var(--text-label-weight); }
.mono-md    { font-family: var(--font-mono); font-size: var(--text-mono-md-size);    line-height: var(--text-mono-md-line);    font-weight: var(--text-mono-md-weight); }
.mono-sm    { font-family: var(--font-mono); font-size: var(--text-mono-sm-size);    line-height: var(--text-mono-sm-line);    font-weight: var(--text-mono-sm-weight); }

/* ── Utility — accessibility ─────────────────────────────────────────────── */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ── Utility — semantic colour ───────────────────────────────────────────── */
.text-brand   { color: var(--text-brand); }
.text-muted   { color: var(--text-secondary); }
.text-danger  { color: var(--color-danger); font-size: var(--text-body-sm-size); }
.text-success { color: var(--color-success); }
