/* ═══════════════════════════════════════════════════════════════
   Senshin Accessibility Layer
   WCAG 2.1 AA compliance: focus visible, contrast, targets, ARIA
   ═══════════════════════════════════════════════════════════════ */

/* ── Focus visible — keyboard-only focus ring ────────────── */

*:focus {
  outline: none;
}

*:focus-visible {
  outline: 2px solid var(--accent, #2563eb);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ── Skip to content link ────────────────────────────────── */

.skip-link {
  position: absolute;
  top: -100%;
  left: 16px;
  z-index: 10000;
  padding: 8px 16px;
  background: var(--accent, #2563eb);
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  border-radius: 0 0 8px 8px;
  text-decoration: none;
  transition: top 0.15s ease;
}

.skip-link:focus {
  top: 0;
}

/* ── Minimum touch/click target — 44×44px (WCAG 2.5.5) ─── */

button,
[role="button"],
a,
input[type="checkbox"],
input[type="radio"],
select,
summary {
  min-height: var(--comp-btn-h, 40px);
  min-width: 44px;
}

/* Exceptions for inline text links */
p a, li a, td a, span a, .inline-link {
  min-height: unset;
  min-width: unset;
}

/* Small BUTTONS get padding to meet 44px target.
   NOTE: .pill, .tag, .chip are display-only status labels, NOT interactive,
   so WCAG 2.5.5 (touch target) does not apply — excluding them keeps them slim. */
.btn-sm {
  min-height: var(--comp-btn-h, 40px);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* ── Contrast — WCAG AA minimum ratios ───────────────────── */
/* 4.5:1 for normal text, 3:1 for large text (18px+ or 14px bold) */

/* Ensure body text meets 4.5:1 on white (#fff) */
body {
  color: var(--t1, #1c1c1a); /* contrast ratio ~18:1 on white */
}

/* Secondary text must still meet 4.5:1 */
.text-secondary, .text-muted {
  color: var(--t3, #6b6b67); /* contrast ratio ~4.8:1 on white */
}

/* Tertiary/hint text — 3:1 minimum for non-essential */
.text-hint {
  color: var(--t4, #9a9a96); /* use only for non-essential, decorative text */
}

/* Placeholder text */
::placeholder {
  color: var(--t4, #9a9a96);
  opacity: 1;
}

/* ── ARIA landmark styling ───────────────────────────────── */

[role="main"],
[role="navigation"],
[role="banner"],
[role="complementary"],
[role="contentinfo"] {
  position: relative;
}

/* Visually hidden but accessible to screen readers */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Show on focus (for skip links and similar) */
.sr-only-focusable:focus,
.sr-only-focusable:active {
  position: static;
  width: auto;
  height: auto;
  padding: inherit;
  margin: inherit;
  overflow: visible;
  clip: auto;
  white-space: normal;
}

/* ── Live regions ────────────────────────────────────────── */

[aria-live="polite"],
[aria-live="assertive"] {
  position: relative;
}

/* Status messages (toast, inline alerts) */
[role="status"],
[role="alert"] {
  position: relative;
}

/* ── Form accessibility ──────────────────────────────────── */

/* Error state */
[aria-invalid="true"],
.field-error {
  border-color: #dc2626 !important;
  box-shadow: 0 0 0 1px #dc2626;
}

[aria-invalid="true"]:focus-visible,
.field-error:focus-visible {
  outline-color: #dc2626;
}

/* Required field indicator */
[aria-required="true"] + label::after,
label[data-required]::after {
  content: " *";
  color: #dc2626;
  font-weight: 700;
}

/* Disabled state */
[aria-disabled="true"],
[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

/* ── Selection / highlight contrast ──────────────────────── */

::selection {
  background: rgba(37, 99, 235, 0.25);
  color: inherit;
}

/* ── Table accessibility ─────────────────────────────────── */

table {
  border-collapse: collapse;
}

th {
  text-align: left;
}

th[aria-sort] {
  cursor: pointer;
}

th[aria-sort]::after {
  content: "";
  display: inline-block;
  width: 0;
  height: 0;
  margin-left: 6px;
  vertical-align: middle;
}

th[aria-sort="ascending"]::after {
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-bottom: 5px solid currentColor;
}

th[aria-sort="descending"]::after {
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 5px solid currentColor;
}

/* ── High contrast mode ──────────────────────────────────── */

@media (forced-colors: active) {
  * {
    forced-color-adjust: auto;
  }

  .pill, .tag, .chip, .badge {
    border: 1px solid ButtonText;
  }

  button, [role="button"] {
    border: 1px solid ButtonText;
  }

  *:focus-visible {
    outline: 2px solid Highlight;
    outline-offset: 2px;
  }
}

/* ── Print accessibility ─────────────────────────────────── */

@media print {
  .skip-link,
  [aria-hidden="true"] {
    display: none !important;
  }

  a[href]::after {
    content: " (" attr(href) ")";
    font-size: 0.85em;
    color: #666;
  }

  a[href^="#"]::after,
  a[href^="javascript"]::after {
    content: "";
  }
}

/* ── Scrollbar styling (non-essential, decorative) ───────── */

::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.15);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 0, 0, 0.25);
}

/* Firefox */
* {
  scrollbar-width: thin;
  scrollbar-color: rgba(0, 0, 0, 0.15) transparent;
}
