/* ============================================
   ACCESSIBILITY - Focus States & A11y Features
   clearMetric LTD Website
   ============================================ */

/* ===== FOCUS INDICATORS ===== */

/* Ensure all interactive elements have visible focus */
a:focus-visible,
button:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible,
[role="button"]:focus-visible,
[role="link"]:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* Focus styles for keyboard navigation */
:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

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

/* ===== HIGH CONTRAST MODE ===== */

@media (prefers-contrast: more) {
  button,
  a,
  input,
  textarea,
  select {
    border-width: 2px;
  }
  
  .btn {
    border-width: 2px;
  }
}

/* ===== REDUCED MOTION ===== */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ===== COLOR CONTRAST ===== */

/* Ensure text has sufficient contrast */
body {
  color: var(--foreground);
  background-color: var(--background);
}

p,
li,
dd,
dt {
  color: var(--foreground);
}

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

/* Ensure link contrast */
a {
  color: var(--primary);
  text-decoration: underline;
  text-decoration-skip-ink: auto;
}

a:hover,
a:focus-visible {
  color: var(--primary-dark);
}

a:visited {
  color: var(--secondary);
}

/* ===== FORM ACCESSIBILITY ===== */

/* Ensure form labels are visible */
label {
  font-weight: var(--font-semibold);
  color: var(--foreground);
}

/* Required field indicator */
.required::after {
  content: " *";
  color: var(--danger);
  font-weight: var(--font-bold);
  margin-left: 0.25rem;
}

/* Form input accessibility */
input:required,
textarea:required,
select:required {
  border-color: var(--primary);
}

input:invalid,
textarea:invalid,
select:invalid {
  border-color: var(--danger);
}

input:valid,
textarea:valid,
select:valid {
  border-color: var(--success);
}

/* Error messages must be associated */
.form-error {
  color: var(--danger);
  font-weight: var(--font-semibold);
}

.form-success {
  color: var(--success);
  font-weight: var(--font-semibold);
}

/* ===== HEADING HIERARCHY ===== */

/* Ensure proper heading hierarchy for screen readers */
h1,
h2,
h3,
h4,
h5,
h6 {
  color: var(--foreground);
  font-weight: var(--font-bold);
  line-height: var(--leading-tight);
}

h1 {
  font-size: var(--text-4xl);
  margin-bottom: var(--space-4);
}

h2 {
  font-size: var(--text-3xl);
  margin-bottom: var(--space-3);
}

h3 {
  font-size: var(--text-2xl);
  margin-bottom: var(--space-3);
}

h4 {
  font-size: var(--text-xl);
  margin-bottom: var(--space-2);
}

h5 {
  font-size: var(--text-lg);
  margin-bottom: var(--space-2);
}

h6 {
  font-size: var(--text-base);
  margin-bottom: var(--space-2);
}

/* ===== IMAGE ACCESSIBILITY ===== */

/* Ensure images have meaningful alt text */
img {
  max-width: 100%;
  height: auto;
  display: block;
}

/* Decorative images should have empty alt */
img[alt=""],
img[alt] {
  display: block;
}

/* ===== BUTTON ACCESSIBILITY ===== */

/* Ensure buttons have sufficient size for touch (44x44px minimum) */
@media (hover: none) and (pointer: coarse) {
  button,
  a.btn,
  input[type="button"],
  input[type="submit"] {
    min-width: 2.75rem;
    min-height: 2.75rem;
  }
}

/* ===== SKIP LINK ===== */

#skip-to-content {
  position: absolute;
  top: -40px;
  left: 0;
  background: var(--primary);
  color: var(--primary-foreground);
  padding: var(--space-2) var(--space-3);
  text-decoration: none;
  z-index: var(--z-fixed);
  border-radius: 0 0 var(--radius-md) 0;
}

#skip-to-content:focus {
  top: 0;
}

/* ===== ICON ACCESSIBILITY ===== */

/* Ensure icon-only buttons have text labels */
.icon-only {
  color: inherit;
  text-decoration: none;
}

.icon-only[aria-label] {
  /* Has accessible label via aria-label */
}

/* ===== TABLE ACCESSIBILITY ===== */

table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: var(--space-6);
}

th {
  background-color: var(--neutral-100);
  color: var(--foreground);
  font-weight: var(--font-bold);
  text-align: left;
  padding: var(--space-3);
  border-bottom: 2px solid var(--border);
}

td {
  padding: var(--space-3);
  border-bottom: 1px solid var(--border);
}

tbody tr:hover {
  background-color: var(--neutral-50);
}

/* ===== LISTBOX ACCESSIBILITY ===== */

[role="listbox"],
[role="menu"] {
  outline: none;
}

[role="option"],
[role="menuitem"] {
  cursor: pointer;
  padding: var(--space-2) var(--space-3);
}

[role="option"]:hover,
[role="menuitem"]:hover {
  background-color: var(--neutral-100);
}

[aria-selected="true"],
[aria-checked="true"] {
  background-color: rgba(26, 31, 54, 0.1);
  font-weight: var(--font-semibold);
}

/* ===== LANDMARK ACCESSIBILITY ===== */

[role="main"],
[role="region"],
[role="navigation"],
[role="complementary"],
[role="contentinfo"] {
  /* Landmarks properly styled */
}

/* ===== LIVE REGION ===== */

[aria-live="polite"],
[aria-live="assertive"] {
  /* Live regions should be visible */
}

[aria-live="polite"][aria-hidden="true"],
[aria-live="assertive"][aria-hidden="true"] {
  display: none;
}

/* ===== DISABLED STATE ===== */

[disabled],
[aria-disabled="true"] {
  opacity: var(--opacity-50);
  cursor: not-allowed;
}

/* ===== TEXT VISIBILITY ===== */

/* Ensure text is not hidden behind other elements */
.text-hide,
.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;
}

/* ===== ANIMATION SAFETY ===== */

/* No auto-playing media that flashes */
@media (prefers-reduced-motion: reduce) {
  video,
  audio {
    pointer-events: none;
  }
}

/* ===== ZOOM & TEXT SCALING ===== */

html {
  /* Allow users to zoom to at least 200% */
}

/* Responsive font sizes for readability */
body {
  font-size: var(--text-base);
  line-height: var(--leading-normal);
}

@media (min-width: 1024px) {
  body {
    font-size: var(--text-base);
  }
}

/* ===== LANDMARK NAVIGATION ===== */

nav[aria-label] {
  /* Navigation landmarks with labels */
}

/* ===== BREADCRUMB ACCESSIBILITY ===== */

.breadcrumbs {
  list-style: none;
  padding: 0;
  margin: 0;
}

.breadcrumbs li::before {
  content: "/";
  margin: 0 var(--space-2);
  color: var(--muted-foreground);
}

.breadcrumbs li:first-child::before {
  content: "";
  margin: 0;
}

/* ===== CAROUSEL ACCESSIBILITY ===== */

[role="region"][aria-label*="carousel"],
[role="region"][aria-label*="slider"] {
  /* Carousel regions labeled for screen readers */
}

[aria-label*="carousel"] button,
[aria-label*="slider"] button {
  /* Ensure carousel controls are keyboard accessible */
}

/* ===== MODAL ACCESSIBILITY ===== */

[role="dialog"] {
  /* Modal dialogs */
}

[role="dialog"][aria-modal="true"] {
  /* Aria-modal indicates dialog is a modal */
}

/* Ensure focus returns to trigger element when modal closes */
