/* =====================================================================
   a11y-base.css — Accessibility foundation for SEBI-regulated fund sites
   Targets: WCAG 2.1 / 2.2 Level AA, GIGW 3.0, IS 17802
   Load this BEFORE your theme/brand CSS. Brand CSS may override colours
   only with token pairs that pass `npm run check:contrast`.
   ===================================================================== */

/* ---------- 1. Design tokens (all text/background pairs ≥ 4.5:1) ---------- */
:root {
  /* Surfaces */
  --color-bg:            #ffffff;
  --color-surface:       #f5f6f8;
  /* Text */
  --color-text:          #1a1d23;   /* 16.9:1 on bg */
  --color-text-muted:    #4a5160;   /*  8.0:1 on bg — never go lighter than #6b7280 (4.8:1) */
  /* Brand / interactive */
  --color-primary:       #0b4f8a;   /*  8.4:1 on bg — links, buttons */
  --color-primary-hover: #083a66;
  --color-on-primary:    #ffffff;   /*  8.4:1 on primary */
  /* Feedback */
  --color-error:         #b3261e;   /*  6.5:1 on bg */
  --color-success:       #1e6b34;   /*  6.6:1 on bg */
  /* Focus indicator — must be ≥ 3:1 against adjacent colours (WCAG 1.4.11 / 2.4.11) */
  --color-focus:         #c2410c;
  --focus-ring:          3px solid var(--color-focus);
  --focus-offset:        2px;
  /* Borders for form controls — ≥ 3:1 against bg (WCAG 1.4.11) */
  --color-border:        #6b7280;

  /* Type — rem units so browser zoom & user font settings work (WCAG 1.4.4) */
  --font-body: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", Arial, sans-serif;
  --text-base: 1rem;        /* never below 16px for body copy */
  --text-small: 0.875rem;   /* minimum for any text */
  --line-height: 1.6;       /* WCAG 1.4.12 text spacing friendly */

  /* Touch / pointer target minimum (WCAG 2.5.8 = 24px; we use 44px) */
  --target-min: 44px;
}

/* ---------- 2. Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { font-size: 100%; -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font-body);
  font-size: var(--text-base);
  line-height: var(--line-height);
  color: var(--color-text);
  background: var(--color-bg);
  overflow-wrap: break-word;
}
img, svg, video { max-width: 100%; height: auto; }

/* Links: underline by default — colour alone must not convey meaning (WCAG 1.4.1) */
a { color: var(--color-primary); text-decoration: underline; text-underline-offset: 0.15em; }
a:hover { color: var(--color-primary-hover); text-decoration-thickness: 2px; }

/* ---------- 3. Focus visibility (WCAG 2.4.7, 2.4.11) ---------- */
:focus { outline: none; }
:focus-visible {
  outline: var(--focus-ring);
  outline-offset: var(--focus-offset);
  border-radius: 2px;
}
/* Never let sticky headers hide the focused element (WCAG 2.4.11) */
html { scroll-padding-top: 6rem; }

/* ---------- 4. Skip link (WCAG 2.4.1) ---------- */
.skip-link {
  position: absolute;
  left: 1rem;
  top: -100px;
  z-index: 10000;
  padding: 0.75rem 1rem;
  background: var(--color-primary);
  color: var(--color-on-primary);
  font-weight: 600;
  text-decoration: none;
  border-radius: 4px;
}
.skip-link:focus, .skip-link:focus-visible { top: 1rem; }

/* ---------- 5. Screen-reader-only utility ---------- */
.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;
}

/* ---------- 6. Layout & reflow (WCAG 1.4.10 — usable at 320px / 400% zoom) ---------- */
.container { width: min(100% - 2rem, 72rem); margin-inline: auto; }
@media (max-width: 40rem) { .container { width: calc(100% - 2rem); } }

/* ---------- 7. Header & navigation ---------- */
.site-header { border-bottom: 1px solid var(--color-surface); background: var(--color-bg); }
.site-header__inner { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding-block: 0.75rem; flex-wrap: wrap; }
.site-logo { display: inline-flex; align-items: center; min-height: var(--target-min); font-weight: 700; color: var(--color-text); text-decoration: none; }
.nav-toggle {
  display: none;
  min-width: var(--target-min); min-height: var(--target-min);
  padding: 0.5rem 0.875rem;
  font: inherit; font-weight: 600;
  color: var(--color-text); background: transparent;
  border: 2px solid var(--color-border); border-radius: 4px; cursor: pointer;
}
.site-nav ul { list-style: none; margin: 0; padding: 0; display: flex; gap: 0.25rem; flex-wrap: wrap; }
.site-nav a {
  display: inline-flex; align-items: center;
  min-height: var(--target-min); padding: 0 0.75rem;
  color: var(--color-text); text-decoration: none; border-radius: 4px;
}
.site-nav a:hover { text-decoration: underline; }
.site-nav a[aria-current="page"] { font-weight: 700; text-decoration: underline; text-decoration-thickness: 3px; }
@media (max-width: 48rem) {
  .js .nav-toggle { display: inline-flex; align-items: center; }
  .js .site-nav { flex-basis: 100%; }
  .js .site-nav[data-open="false"] { display: none; }
  .site-nav ul { flex-direction: column; }
}

/* ---------- 8. Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: var(--target-min); padding: 0.625rem 1.25rem;
  font: inherit; font-weight: 600;
  color: var(--color-on-primary); background: var(--color-primary);
  border: 2px solid var(--color-primary); border-radius: 4px;
  cursor: pointer; text-decoration: none;
}
.btn:hover { background: var(--color-primary-hover); border-color: var(--color-primary-hover); color: var(--color-on-primary); }
.btn[disabled], .btn[aria-disabled="true"] { opacity: 0.6; cursor: not-allowed; }

/* ---------- 9. Forms (WCAG 1.3.1, 1.4.11, 3.3.1–3.3.3) ---------- */
.form { display: grid; gap: 1.25rem; max-width: 40rem; }
.field { display: grid; gap: 0.375rem; }
.field label, .field legend { font-weight: 600; }
.field .hint { color: var(--color-text-muted); font-size: var(--text-small); }
.field input, .field select, .field textarea {
  font: inherit; color: var(--color-text); background: var(--color-bg);
  min-height: var(--target-min); padding: 0.5rem 0.75rem;
  border: 2px solid var(--color-border); border-radius: 4px;
  width: 100%; max-width: 100%;
}
.field textarea { min-height: 8rem; resize: vertical; }
.field [aria-invalid="true"] { border-color: var(--color-error); border-width: 3px; }
.field .error { color: var(--color-error); font-weight: 600; font-size: var(--text-small); }
.field .error:empty { display: none; }
.field .error::before { content: "Error: "; }           /* error isn't conveyed by colour alone */
.required-marker { color: var(--color-error); }
fieldset.field { border: 0; padding: 0; margin: 0; }
.choice { display: flex; align-items: center; gap: 0.5rem; min-height: var(--target-min); }
.choice input { width: 1.25rem; height: 1.25rem; min-height: 0; margin: 0; flex-shrink: 0; }
.choice label { min-width: 0; font-weight: 400; }

.error-summary {
  border: 3px solid var(--color-error); padding: 1rem 1.25rem; border-radius: 4px;
}
.error-summary h2 { margin-top: 0; font-size: 1.125rem; color: var(--color-error); }
.status-message { padding: 1rem 1.25rem; border-left: 6px solid var(--color-success); background: var(--color-surface); }

/* Honeypot — accessible anti-spam instead of CAPTCHA (CAPTCHAs fail WCAG 1.1.1 / 3.3.8) */
.hp-field { position: absolute; left: -10000px; width: 1px; height: 1px; overflow: hidden; }

/* ---------- 10. Tables ---------- */
table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: 0.625rem 0.75rem; border-bottom: 1px solid var(--color-border); vertical-align: top; }
caption { text-align: left; font-weight: 700; padding-bottom: 0.5rem; }
.table-scroll { overflow-x: auto; }
.table-scroll:focus-visible { outline: var(--focus-ring); }

/* ---------- 11. Portfolio logo grid ---------- */
.portfolio-grid { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(10rem, 1fr)); gap: 1rem; }
.portfolio-grid a { display: grid; gap: 0.5rem; padding: 1rem; border: 1px solid var(--color-border); border-radius: 6px; color: var(--color-text); text-decoration: none; min-height: var(--target-min); }
.portfolio-grid a:hover .portfolio-name { text-decoration: underline; }
.portfolio-grid img { max-height: 3rem; width: auto; object-fit: contain; }
.portfolio-name { font-weight: 600; }

/* ---------- 12. Footer ---------- */
.site-footer { margin-top: 4rem; padding-block: 2rem; background: var(--color-surface); font-size: var(--text-small); }
.site-footer h2 { font-size: 1rem; }
.site-footer ul { list-style: none; padding: 0; margin: 0; display: grid; gap: 0.25rem; }
.site-footer a { display: inline-flex; align-items: center; min-height: var(--target-min); }
.footer-grid { display: grid; gap: 2rem; grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr)); }

/* ---------- 13. Motion (WCAG 2.2.2, 2.3.3) ---------- */
@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;
  }
}

/* ---------- 14. Windows High Contrast / forced colours ---------- */
@media (forced-colors: active) {
  .btn, .nav-toggle, .field input, .field select, .field textarea { border: 2px solid ButtonText; }
  :focus-visible { outline: 3px solid Highlight; }
}

/* ---------- 15. Print ---------- */
@media print {
  .skip-link, .nav-toggle, .site-nav { display: none !important; }
  a[href^="http"]::after { content: " (" attr(href) ")"; font-size: 0.8em; }
}
