/* ChamberAI Design System - Accessibility & Utilities */
/* Version 1.0.0 */

/* Focus Visible Styles - for keyboard navigation */
:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
  border-radius: 2px;
}

/* Removes default outline and uses custom focus style */
:focus:not(:focus-visible) {
  outline: none;
}

/* High Contrast Mode Support */
@media (prefers-contrast: more) {
  :root {
    --color-border: #808080;
    --color-border-light: #999999;
    --color-text-secondary: #333333;
  }
}

/* Skip to Main Content Link */
.skip-to-main {
  position: absolute;
  top: -40px;
  left: 0;
  background: var(--color-primary);
  color: white;
  padding: 8px;
  text-decoration: none;
  z-index: 100;
}

.skip-to-main:focus {
  top: 0;
}

/* Screen Reader Only Content */
.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;
}

/* Visually Hidden but Available to Screen Readers */
.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;
}

/* Focus Visible on Interactive Elements */
button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

/* Remove outline for mouse users (when not in focus-visible) */
button:focus:not(:focus-visible),
a:focus:not(:focus-visible),
input:focus:not(:focus-visible),
select:focus:not(:focus-visible),
textarea:focus:not(:focus-visible) {
  outline: none;
}

/* Touch Target Sizing (minimum 44×44px) */
button, a[role="button"], [role="button"], input[type="checkbox"], input[type="radio"] {
  min-height: 44px;
  min-width: 44px;
  padding: max(8px, (44px - 1em) / 2);
}

/* Ensure touch targets have adequate spacing */
a, button, input, select, textarea, [role="button"] {
  margin: 8px 4px;
}

/* High Contrast Colors for Text */
@media (prefers-contrast: more) {
  body {
    color: #000000;
    background-color: #ffffff;
  }

  a {
    color: #0000ee;
    text-decoration: underline;
  }

  button {
    border: 2px solid;
  }

  input, textarea, select {
    border: 2px solid;
  }
}

/* Reduced Motion - Respect user preferences */
@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;
  }

  body {
    scroll-behavior: auto;
  }

  .transition-all,
  .transition-colors,
  .transition-shadow,
  .transition-transform,
  .transition-opacity {
    transition: none !important;
  }
}

/* Dark Mode with Sufficient Contrast */
@media (prefers-color-scheme: dark) {
  :root {
    --color-text-primary: #ffffff;
    --color-bg-primary: #000000;
    --color-border: #404854;
  }
}

/* Alert Role Styles */
[role="alert"],
.alert {
  position: relative;
  padding: 16px;
  border-radius: var(--radius-md);
  border: 1px solid;
}

[role="alert"]--error,
.alert--error {
  border-color: var(--color-error);
  background-color: var(--color-error-50);
  color: var(--color-error);
}

[role="alert"]--warning,
.alert--warning {
  border-color: var(--color-warning);
  background-color: var(--color-warning-50);
  color: var(--color-warning);
}

[role="alert"]--success,
.alert--success {
  border-color: var(--color-success);
  background-color: var(--color-success-50);
  color: var(--color-success);
}

[role="alert"]--info,
.alert--info {
  border-color: var(--color-info);
  background-color: var(--color-info-50);
  color: var(--color-info);
}

/* Status Messages (aria-live regions) */
[role="status"],
[role="log"],
[aria-live="polite"],
[aria-live="assertive"] {
  position: relative;
}

/* Aria-label for icons */
[aria-label] {
  /* Ensure icon has appropriate semantic meaning */
}

/* Tooltips - Accessible */
.tooltip {
  position: relative;
}

.tooltip[aria-describedby] {
  /* Screen readers will announce the tooltip content */
}

/* Form Error Association */
input.error,
textarea.error,
select.error {
  /* Red border indicates error visually */
  border-color: var(--color-error);
}

/* Error message should be associated with input */
input.error + .error-text,
textarea.error + .error-text,
select.error + .error-text {
  color: var(--color-error);
  display: block;
}

/* Disabled State Accessibility */
:disabled,
[aria-disabled="true"],
.disabled,
.is-disabled {
  opacity: 0.6;
  cursor: not-allowed;
  pointer-events: none;
}

/* Required Field Indicator */
.required {
  color: var(--color-error);
}

label.required::after {
  content: " *";
  color: var(--color-error);
  aria-label: "required";
}

/* Loading State Accessibility */
[aria-busy="true"],
.is-loading {
  position: relative;
  pointer-events: none;
}

[aria-busy="true"]::after,
.is-loading::after {
  content: "Loading...";
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

/* Empty State Accessibility */
.empty-state {
  padding: 48px 24px;
  text-align: center;
  color: var(--color-text-secondary);
}

/* List Items - Accessible */
ul li, ol li {
  margin-bottom: 8px;
}

/* Table Accessibility */
table {
  border-collapse: collapse;
  width: 100%;
}

table th {
  text-align: left;
  padding: 12px;
  border-bottom: 2px solid var(--color-border);
  background-color: var(--color-bg-secondary);
}

table td {
  padding: 12px;
  border-bottom: 1px solid var(--color-border);
}

table tbody tr:hover {
  background-color: var(--color-bg-secondary);
}

/* Link Accessibility */
a {
  color: var(--color-primary);
  text-decoration: underline;
}

a:visited {
  color: var(--color-ai-dark);
}

a:hover {
  text-decoration: underline;
}

a:active {
  color: var(--color-primary-darker);
}

/* Ensure color is not the only means of conveyance */
.text-success::before,
.text-error::before,
.text-warning::before {
  content: attr(data-icon);
  margin-right: 4px;
}

/* Heading Hierarchy - Utilities */
h1, .h1 { font-size: var(--font-size-4xl); }
h2, .h2 { font-size: var(--font-size-3xl); }
h3, .h3 { font-size: var(--font-size-2xl); }
h4, .h4 { font-size: var(--font-size-xl); }
h5, .h5 { font-size: var(--font-size-lg); }
h6, .h6 { font-size: var(--font-size-sm); }

/* Always maintain proper heading structure */
h1 + h3,
h2 + h4,
h3 + h5,
h4 + h6 {
  /* Invalid nesting - avoid */
}

/* Link Focus Indicator Enhancement */
a:focus-visible,
button:focus-visible {
  outline: 3px solid var(--color-primary);
  outline-offset: 2px;
}

/* Modal Accessibility - Trap focus */
.modal {
  overflow: hidden;
  position: fixed;
  z-index: var(--z-modal);
}

.modal[aria-modal="true"] {
  /* Focus trap active */
}

.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: var(--color-bg-overlay);
  z-index: var(--z-modal-backdrop);
}

/* Ensure modal is properly announced */
.modal[role="dialog"],
.modal[role="alertdialog"] {
  /* Screen reader will announce as dialog */
}

/* Badge/Tag Accessibility */
.badge {
  display: inline-block;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  font-size: var(--font-size-xs);
}

.badge[aria-label] {
  /* Screen reader will announce the meaning */
}

/* Color Contrast Checker */
.contrast-check {
  /* WCAG AA: 4.5:1 for normal text, 3:1 for large text */
}

.contrast-check--high {
  /* WCAG AAA: 7:1 for normal text, 4.5:1 for large text */
  color: var(--color-text-primary);
}

/* Utility classes for accessibility testing */
.wcag-aa { /* 4.5:1 contrast minimum */ }
.wcag-aaa { /* 7:1 contrast minimum */ }

/* Visible Focus Indicator for All Interactive Elements */
button:focus-visible,
a:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible,
[tabindex]:focus-visible,
[role="button"]:focus-visible,
[role="tab"]:focus-visible,
[role="menuitem"]:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
  border-radius: 2px;
}

/* Ensure minimum tap target size on touch devices */
@media (hover: none) and (pointer: coarse) {
  button, a, input[type="checkbox"], input[type="radio"] {
    min-height: 48px;
    min-width: 48px;
  }
}

/* Print Styles */
@media print {
  a[href]::after {
    content: " (" attr(href) ")";
  }

  .no-print {
    display: none !important;
  }

  body {
    background: white;
    color: black;
  }
}
