/**
 * SGLE Theme - Accessibility Styles (WCAG 2.1 AA Compliant)
 * 
 * Comprehensive accessibility enhancements including:
 * - Skip links for keyboard navigation
 * - Focus-visible styles for all interactive elements
 * - High contrast mode support
 * - Screen reader only content
 * - Reduced motion support
 * - Keyboard navigation indicators
 * 
 * @package SGLE_Theme
 * @version 1.0.0
 */

/* ==========================================
   SKIP LINKS
   ========================================== */

.skip-link {
  position: absolute;
  top: -100px;
  left: 0;
  z-index: 9999;
  padding: 1rem 1.5rem;
  background-color: #1e40af;
  color: #ffffff;
  font-weight: 600;
  font-size: 0.875rem;
  text-decoration: none;
  border-radius: 0 0 0.5rem 0;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
  transition: top 0.3s ease-in-out;
}

.skip-link:focus {
  top: 0;
  outline: 3px solid #fbbf24;
  outline-offset: 2px;
}

.skip-link:hover {
  background-color: #1e3a8a;
  text-decoration: underline;
}

/* ==========================================
   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;
}

.sr-only-focusable:focus,
.sr-only-focusable:active {
  position: static;
  width: auto;
  height: auto;
  overflow: visible;
  clip: auto;
  white-space: normal;
}

/* ==========================================
   FOCUS STYLES (WCAG 2.1 AA)
   ========================================== */

/* Remove default outline and add custom focus-visible styles */
*:focus {
  outline: none;
}

/* Focus-visible polyfill for better keyboard navigation */
*:focus-visible {
  outline: 3px solid #3b82f6;
  outline-offset: 2px;
  transition: outline-offset 0.15s ease-in-out;
}

/* Enhanced focus for interactive elements */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[role="button"]:focus-visible,
[tabindex]:not([tabindex="-1"]):focus-visible {
  outline: 3px solid #3b82f6;
  outline-offset: 2px;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

/* Focus for navigation items */
nav a:focus-visible {
  outline: 3px solid #3b82f6;
  outline-offset: 2px;
  background-color: rgba(59, 130, 246, 0.1);
}

/* Focus for form inputs */
input[type="text"]:focus-visible,
input[type="email"]:focus-visible,
input[type="password"]:focus-visible,
input[type="tel"]:focus-visible,
input[type="url"]:focus-visible,
input[type="search"]:focus-visible,
input[type="number"]:focus-visible,
input[type="date"]:focus-visible,
input[type="datetime-local"]:focus-visible,
input[type="time"]:focus-visible,
textarea:focus-visible,
select:focus-visible {
  outline: 3px solid #3b82f6;
  outline-offset: 0;
  border-color: #3b82f6;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

/* Focus for checkboxes and radios */
input[type="checkbox"]:focus-visible,
input[type="radio"]:focus-visible {
  outline: 3px solid #3b82f6;
  outline-offset: 2px;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

/* Focus for buttons */
button:focus-visible,
[role="button"]:focus-visible {
  outline: 3px solid #3b82f6;
  outline-offset: 2px;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}

/* Focus within modals */
[role="dialog"] *:focus-visible,
[role="alertdialog"] *:focus-visible {
  outline: 3px solid #3b82f6;
  outline-offset: 2px;
}

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

@media (prefers-contrast: high) {
  /* Increase border widths */
  *[class*="border"] {
    border-width: 2px !important;
  }

  /* Enhance focus indicators */
  *:focus-visible {
    outline-width: 4px;
    outline-offset: 3px;
  }

  /* Increase text contrast */
  body {
    color: #000000;
    background-color: #ffffff;
  }

  /* Button contrast */
  button,
  [role="button"] {
    border: 2px solid currentColor;
  }

  /* Link contrast */
  a {
    text-decoration: underline;
    text-decoration-thickness: 2px;
  }
}

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

@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;
  }

  /* Keep essential animations visible but shorter */
  .sgle-toast,
  [role="alert"],
  [role="status"] {
    animation-duration: 0.2s !important;
    transition-duration: 0.2s !important;
  }
}

/* ==========================================
   KEYBOARD NAVIGATION INDICATORS
   ========================================== */

/* Show visual indicator when navigating by keyboard */
body.using-keyboard *:focus {
  outline: 3px solid #3b82f6;
  outline-offset: 2px;
}

/* Hide indicators when using mouse */
body:not(.using-keyboard) *:focus {
  outline: none;
}

/* Table keyboard navigation */
table tbody tr:focus-within {
  outline: 2px solid #3b82f6;
  outline-offset: -2px;
  background-color: rgba(59, 130, 246, 0.05);
}

/* Card keyboard navigation */
.card:focus-within,
[class*="card"]:focus-within {
  outline: 2px solid #3b82f6;
  outline-offset: 2px;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

/* ==========================================
   ARIA LIVE REGIONS
   ========================================== */

[role="alert"],
[role="status"],
[aria-live] {
  position: relative;
}

/* Toast/notification positioning for screen readers */
#sgle-toast-container {
  position: fixed;
  z-index: 9999;
}

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

/* Modal backdrop should not be focusable */
[role="dialog"]::backdrop,
.modal-backdrop {
  -webkit-tap-highlight-color: transparent;
}

/* Modal focus management */
[role="dialog"],
[role="alertdialog"] {
  position: fixed;
  z-index: 1000;
}

/* Ensure modals are announced to screen readers */
[role="dialog"][aria-modal="true"],
[role="alertdialog"][aria-modal="true"] {
  /* Content will be announced */
}

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

/* Required field indicator */
[required]::after,
[aria-required="true"]::after {
  content: " *";
  color: #ef4444;
  font-weight: 600;
}

/* Error messages */
[role="alert"].error-message,
.error-message[aria-live="assertive"] {
  padding: 0.75rem 1rem;
  background-color: #fef2f2;
  border: 2px solid #ef4444;
  border-radius: 0.5rem;
  color: #991b1b;
  font-weight: 500;
  margin-top: 0.5rem;
}

/* Invalid field styling */
input:invalid:not(:placeholder-shown),
select:invalid:not(:placeholder-shown),
textarea:invalid:not(:placeholder-shown),
[aria-invalid="true"] {
  border-color: #ef4444;
  border-width: 2px;
  background-color: #fef2f2;
}

input:invalid:focus,
select:invalid:focus,
textarea:invalid:focus,
[aria-invalid="true"]:focus {
  outline: 3px solid #ef4444;
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.1);
}

/* Valid field styling */
input:valid:not(:placeholder-shown).validated,
select:valid:not(:placeholder-shown).validated,
textarea:valid:not(:placeholder-shown).validated,
[aria-invalid="false"].validated {
  border-color: #10b981;
  border-width: 2px;
}

/* Field descriptions */
[aria-describedby]::before {
  /* Associated description will be announced */
}

/* ==========================================
   NAVIGATION ACCESSIBILITY
   ========================================== */

/* Current page indicator */
[aria-current="page"] {
  position: relative;
  font-weight: 600;
}

[aria-current="page"]::before {
  content: "";
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 4px;
  height: 80%;
  background-color: #3b82f6;
  border-radius: 0 4px 4px 0;
  display: none;
}

/* Breadcrumb navigation */
nav[aria-label="Breadcrumb"] ol {
  display: flex;
  flex-wrap: wrap;
  list-style: none;
  padding: 0;
  margin: 0;
}

nav[aria-label="Breadcrumb"] li:not(:last-child)::after {
  content: "/";
  padding: 0 0.5rem;
  color: #94a3b8;
}

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

/* Table captions */
table caption {
  padding: 0.75rem 1rem;
  font-weight: 600;
  text-align: left;
  caption-side: top;
  background-color: #f8fafc;
  border-bottom: 2px solid #e2e8f0;
}

/* Table headers must be properly associated */
th[scope="col"] {
  text-align: left;
}

th[scope="row"] {
  font-weight: 600;
}

/* Sortable column headers */
th[aria-sort] {
  cursor: pointer;
  user-select: none;
  position: relative;
  padding-right: 2rem;
}

th[aria-sort]::after {
  content: "⇅";
  position: absolute;
  right: 0.5rem;
  opacity: 0.5;
}

th[aria-sort="ascending"]::after {
  content: "↑";
  opacity: 1;
}

th[aria-sort="descending"]::after {
  content: "↓";
  opacity: 1;
}

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

/* Disabled buttons */
button:disabled,
[role="button"][aria-disabled="true"] {
  cursor: not-allowed;
  opacity: 0.6;
  pointer-events: none;
}

/* Loading state */
button[aria-busy="true"],
[role="button"][aria-busy="true"] {
  cursor: wait;
  opacity: 0.8;
  position: relative;
}

button[aria-busy="true"]::after,
[role="button"][aria-busy="true"]::after {
  content: "";
  position: absolute;
  inset: 0;
  background-color: rgba(255, 255, 255, 0.5);
  border-radius: inherit;
}

/* Toggle buttons */
[role="switch"] {
  position: relative;
  cursor: pointer;
}

[role="switch"][aria-checked="true"] {
  /* Checked state styling */
}

[role="switch"][aria-checked="false"] {
  /* Unchecked state styling */
}

/* ==========================================
   DROPDOWN/COMBOBOX ACCESSIBILITY
   ========================================== */

/* Dropdown indicators */
[role="combobox"] {
  position: relative;
}

[role="combobox"][aria-expanded="true"] {
  /* Expanded state */
}

[role="combobox"][aria-expanded="false"] {
  /* Collapsed state */
}

/* Listbox options */
[role="listbox"] {
  max-height: 300px;
  overflow-y: auto;
  border: 2px solid #e2e8f0;
  border-radius: 0.5rem;
  background-color: #ffffff;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

[role="option"] {
  padding: 0.5rem 1rem;
  cursor: pointer;
}

[role="option"][aria-selected="true"] {
  background-color: #eff6ff;
  color: #1e40af;
  font-weight: 600;
}

[role="option"]:hover,
[role="option"]:focus {
  background-color: #f1f5f9;
}

/* ==========================================
   TOOLTIP ACCESSIBILITY
   ========================================== */

[role="tooltip"] {
  position: absolute;
  z-index: 1000;
  padding: 0.5rem 0.75rem;
  background-color: #1e293b;
  color: #ffffff;
  font-size: 0.875rem;
  border-radius: 0.375rem;
  pointer-events: none;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

[role="tooltip"][aria-hidden="true"] {
  display: none;
}

/* ==========================================
   TAB PANEL ACCESSIBILITY
   ========================================== */

[role="tablist"] {
  display: flex;
  gap: 0.25rem;
  border-bottom: 2px solid #e2e8f0;
}

[role="tab"] {
  padding: 0.75rem 1.5rem;
  cursor: pointer;
  border: none;
  background: transparent;
  color: #64748b;
  font-weight: 500;
  position: relative;
  transition: color 0.2s ease;
}

[role="tab"]:hover {
  color: #334155;
}

[role="tab"][aria-selected="true"] {
  color: #3b82f6;
  font-weight: 600;
}

[role="tab"][aria-selected="true"]::after {
  content: "";
  position: absolute;
  bottom: -2px;
  left: 0;
  right: 0;
  height: 2px;
  background-color: #3b82f6;
}

[role="tabpanel"] {
  padding: 1.5rem;
  outline: none;
}

[role="tabpanel"][hidden] {
  display: none;
}

/* ==========================================
   ALERT/STATUS MESSAGES
   ========================================== */

[role="alert"] {
  padding: 1rem 1.25rem;
  border-radius: 0.5rem;
  border-left: 4px solid;
  margin-bottom: 1rem;
}

[role="alert"].info {
  background-color: #eff6ff;
  border-color: #3b82f6;
  color: #1e40af;
}

[role="alert"].success {
  background-color: #f0fdf4;
  border-color: #10b981;
  color: #065f46;
}

[role="alert"].warning {
  background-color: #fef3c7;
  border-color: #f59e0b;
  color: #92400e;
}

[role="alert"].error {
  background-color: #fef2f2;
  border-color: #ef4444;
  color: #991b1b;
}

[role="status"] {
  /* Status messages for less important updates */
  padding: 0.75rem 1rem;
  border-radius: 0.375rem;
  font-size: 0.875rem;
}

/* ==========================================
   PROGRESS/LOADING INDICATORS
   ========================================== */

[role="progressbar"] {
  position: relative;
  height: 0.5rem;
  background-color: #e2e8f0;
  border-radius: 9999px;
  overflow: hidden;
}

[role="progressbar"]::after {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  background-color: #3b82f6;
  border-radius: inherit;
  transition: width 0.3s ease;
}

/* Indeterminate progress */
[role="progressbar"][aria-valuenow="indeterminate"]::after {
  animation: progress-indeterminate 1.5s infinite;
  width: 30%;
}

@keyframes progress-indeterminate {
  0% {
    left: -30%;
  }
  100% {
    left: 100%;
  }
}

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

/* Ensure minimum contrast ratios (WCAG AA) */
.text-contrast-low {
  color: #64748b; /* 4.5:1 on white background */
}

.text-contrast-medium {
  color: #475569; /* 7:1 on white background */
}

.text-contrast-high {
  color: #1e293b; /* 12:1 on white background */
}

/* Background colors with sufficient contrast */
.bg-accessible-light {
  background-color: #f8fafc;
  color: #1e293b;
}

.bg-accessible-dark {
  background-color: #1e293b;
  color: #f8fafc;
}

/* ==========================================
   TOUCH TARGET SIZES (WCAG 2.5.5)
   ========================================== */

/* Ensure minimum touch target size of 44x44px */
button,
[role="button"],
a,
input[type="checkbox"],
input[type="radio"],
select {
  min-height: 100%;
  min-width: auto;
}

/* Exception for inline elements */
p a,
span a,
li a {
  min-height: auto;
  min-width: auto;
  display: inline;
}

/* Icon buttons */
.icon-button,
button.icon-only,
[role="button"].icon-only {
  width: 44px;
  height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

/* ==========================================
   LANGUAGE ATTRIBUTES
   ========================================== */

/* Ensure proper language announcements */
[lang]:not([lang=""]) {
  /* Content in different language will be announced correctly */
}

/* ==========================================
   PRINT STYLES (ACCESSIBILITY)
   ========================================== */

@media print {
  /* Ensure good contrast for printing */
  body {
    color: #000000;
    background: #ffffff;
  }

  /* Show links in print */
  a[href]::after {
    content: " (" attr(href) ")";
    font-size: 0.875em;
    color: #64748b;
  }

  /* Hide non-essential elements */
  nav,
  .no-print,
  [aria-hidden="true"] {
    display: none;
  }

  /* Ensure page breaks don't break content */
  h1, h2, h3, h4, h5, h6 {
    page-break-after: avoid;
  }

  table, figure {
    page-break-inside: avoid;
  }
}

/* ==========================================
   RESPONSIVE TEXT SIZING
   ========================================== */

/* Support browser text zoom (WCAG 1.4.4) */

/* Use relative units for better scaling */
.text-xs { font-size: 0.75rem; }
.text-sm { font-size: 0.875rem; }
.text-base { font-size: 1rem; }
.text-lg { font-size: 1.125rem; }
.text-xl { font-size: 1.25rem; }
.text-2xl { font-size: 1.5rem; }
.text-3xl { font-size: 1.875rem; }
.text-4xl { font-size: 2.25rem; }

/* ==========================================
   FOCUS TRAP FOR MODALS
   ========================================== */

/* Prevent focus on elements outside modal */
body.modal-open > *:not(#modal-container):not(#sgle-toast-container) {
  /* Screen readers will skip these */
  visibility: hidden;
}

body.modal-open #modal-container {
  visibility: visible;
}

/* ==========================================
   UTILITY CLASSES
   ========================================== */

/* Keyboard-only visible elements */
.keyboard-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;
}

.keyboard-only:focus {
  position: static;
  width: auto;
  height: auto;
  overflow: visible;
  clip: auto;
  white-space: normal;
}

/* Accessible hiding */
.accessible-hide {
  position: absolute;
  left: -10000px;
  width: 1px;
  height: 1px;
  overflow: hidden;
}

/* Focus management */
.focus-trap {
  /* Focus will be trapped within this element */
}

.no-focus-outline:focus {
  outline: none;
}

/* High contrast text */
.high-contrast-text {
  color: #000000;
  background-color: #ffffff;
  font-weight: 600;
  padding: 0.125rem 0.25rem;
}

@media (prefers-contrast: high) {
  .high-contrast-text {
    border: 2px solid #000000;
  }
}
