/**
 * Accessibility Widget - IS 5568 / WCAG 2.0 AA Compliant
 * Standalone widget for any website
 *
 * Usage:
 *   <link rel="stylesheet" href="accessibility-widget.css">
 *   <script src="accessibility-widget.js" defer></script>
 *
 * Version: 1.0.0
 * License: MIT
 */

/* ============================================
   CSS VARIABLES (auto-populated by JS)
   ============================================ */
:root {
  --a11y-brand: #2563EB;
  --a11y-brand-dark: #1e40af;
  --a11y-bg: #ffffff;
  --a11y-text: #1f2937;
  --a11y-border: #e5e7eb;
  --a11y-radius: 12px;
  --a11y-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
}

/* ============================================
   TRIGGER BUTTON (Floating Action Button)
   ============================================ */
#a11y-trigger {
  position: fixed !important;
  bottom: 24px !important;
  right: 24px !important;
  width: 52px !important;
  height: 52px !important;
  min-width: 52px !important;
  min-height: 52px !important;
  border-radius: 50% !important;
  background: color-mix(in srgb, var(--a11y-brand) 50%, transparent) !important;
  border: 2px solid var(--a11y-brand) !important;
  cursor: pointer !important;
  z-index: 99998 !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  transition: all 0.3s ease !important;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15) !important;
}

/* Pulse animation for trigger button */
@keyframes a11y-pulse {
  0%, 100% {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15), 0 0 0 0 var(--a11y-brand);
  }
  50% {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15), 0 0 0 8px color-mix(in srgb, var(--a11y-brand) 30%, transparent);
  }
}

#a11y-trigger:not(:hover):not(:focus) {
  animation: a11y-pulse 2.5s ease-in-out infinite;
}

#a11y-trigger:hover,
#a11y-trigger:focus {
  background: var(--a11y-brand) !important;
  transform: scale(1.1) !important;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25) !important;
}

#a11y-trigger:focus {
  outline: 3px solid var(--a11y-brand) !important;
  outline-offset: 2px !important;
}

/* Trigger SVG icon */
#a11y-trigger svg {
  width: 28px !important;
  height: 28px !important;
  transition: transform 0.3s ease !important;
}

#a11y-trigger:hover svg,
#a11y-trigger:focus svg {
  transform: scale(1.1) !important;
}

/* ============================================
   ACCESSIBILITY PANEL
   ============================================ */
#a11y-panel {
  position: fixed !important;
  bottom: 88px !important;
  right: 24px !important;
  width: 360px !important;
  max-width: calc(100vw - 48px) !important;
  max-height: calc(100vh - 120px) !important;
  background: var(--a11y-bg) !important;
  border: 2px solid var(--a11y-brand) !important;
  border-radius: var(--a11y-radius) !important;
  box-shadow: var(--a11y-shadow) !important;
  z-index: 99999 !important;
  display: none !important;
  flex-direction: column !important;
  overflow: hidden !important;
}

/* Panel open state */
#a11y-panel[aria-hidden="false"] {
  display: flex !important;
}

/* Mobile responsive */
@media (max-width: 400px) {
  #a11y-panel {
    width: calc(100vw - 32px) !important;
    right: 16px !important;
    bottom: 80px !important;
  }

  #a11y-trigger {
    right: 16px !important;
    bottom: 16px !important;
  }
}

/* ============================================
   PANEL HEADER
   ============================================ */
#a11y-panel-header {
  display: flex !important;
  align-items: center !important;
  justify-content: space-between !important;
  padding: 20px 24px !important;
  background: var(--a11y-brand) !important;
  color: white !important;
  border-bottom: 2px solid var(--a11y-brand-dark) !important;
}

#a11y-panel-title {
  margin: 0 !important;
  font-size: 18px !important;
  font-weight: 700 !important;
  font-family: system-ui, -apple-system, sans-serif !important;
  display: flex !important;
  align-items: center !important;
  gap: 8px !important;
}

#a11y-close-btn {
  width: 36px !important;
  height: 36px !important;
  min-width: 36px !important;
  min-height: 36px !important;
  border-radius: 50% !important;
  background: rgba(255, 255, 255, 0.2) !important;
  border: none !important;
  color: white !important;
  font-size: 24px !important;
  font-weight: 300 !important;
  cursor: pointer !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  transition: all 0.2s ease !important;
  line-height: 1 !important;
}

#a11y-close-btn:hover,
#a11y-close-btn:focus {
  background: rgba(255, 255, 255, 0.3) !important;
  transform: scale(1.1) !important;
}

#a11y-close-btn:focus {
  outline: 3px solid white !important;
  outline-offset: 2px !important;
}

/* ============================================
   PANEL CONTENT (scrollable)
   ============================================ */
#a11y-panel-content {
  padding: 20px 24px !important;
  overflow-y: auto !important;
  overflow-x: hidden !important;
  flex: 1 !important;
}

/* Scrollbar styling */
#a11y-panel-content::-webkit-scrollbar {
  width: 8px !important;
}

#a11y-panel-content::-webkit-scrollbar-track {
  background: var(--a11y-border) !important;
  border-radius: 4px !important;
}

#a11y-panel-content::-webkit-scrollbar-thumb {
  background: var(--a11y-brand) !important;
  border-radius: 4px !important;
}

#a11y-panel-content::-webkit-scrollbar-thumb:hover {
  background: var(--a11y-brand-dark) !important;
}

/* ============================================
   FEATURE ROWS
   ============================================ */
.a11y-feature-row {
  display: flex !important;
  align-items: center !important;
  justify-content: space-between !important;
  padding: 14px 0 !important;
  border-bottom: 1px solid var(--a11y-border) !important;
  gap: 16px !important;
}

.a11y-feature-row:last-of-type {
  border-bottom: none !important;
}

.a11y-feature-label {
  display: flex !important;
  align-items: center !important;
  gap: 10px !important;
  flex: 1 !important;
}

.a11y-feature-label svg {
  width: 24px !important;
  height: 24px !important;
  flex-shrink: 0 !important;
  color: var(--a11y-brand) !important;
}

.a11y-feature-label span {
  font-size: 14px !important;
  font-weight: 500 !important;
  color: var(--a11y-text) !important;
  font-family: system-ui, -apple-system, sans-serif !important;
  line-height: 1.4 !important;
}

/* ============================================
   TOGGLE BUTTONS
   ============================================ */
.a11y-toggle-btn {
  min-width: 56px !important;
  min-height: 32px !important;
  width: 56px !important;
  height: 32px !important;
  border-radius: 16px !important;
  background: var(--a11y-border) !important;
  border: none !important;
  cursor: pointer !important;
  position: relative !important;
  transition: all 0.3s ease !important;
  padding: 0 !important;
}

.a11y-toggle-btn::after {
  content: '' !important;
  position: absolute !important;
  width: 24px !important;
  height: 24px !important;
  border-radius: 50% !important;
  background: white !important;
  top: 4px !important;
  left: 4px !important;
  transition: all 0.3s ease !important;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2) !important;
}

.a11y-toggle-btn[aria-pressed="true"] {
  background: var(--a11y-brand) !important;
}

.a11y-toggle-btn[aria-pressed="true"]::after {
  left: 28px !important;
}

.a11y-toggle-btn:hover,
.a11y-toggle-btn:focus {
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--a11y-brand) 40%, transparent) !important;
}

.a11y-toggle-btn:focus {
  outline: none !important;
}

.a11y-toggle-btn:disabled {
  opacity: 0.5 !important;
  cursor: not-allowed !important;
}

/* ============================================
   BUTTON GROUPS (for font size)
   ============================================ */
.a11y-btn-group {
  display: flex !important;
  align-items: center !important;
  gap: 8px !important;
}

.a11y-action-btn {
  min-width: 40px !important;
  min-height: 40px !important;
  width: 40px !important;
  height: 40px !important;
  border-radius: 8px !important;
  background: var(--a11y-border) !important;
  border: none !important;
  color: var(--a11y-text) !important;
  font-size: 18px !important;
  font-weight: 700 !important;
  cursor: pointer !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  transition: all 0.2s ease !important;
  font-family: system-ui, -apple-system, sans-serif !important;
}

.a11y-action-btn:hover:not(:disabled),
.a11y-action-btn:focus:not(:disabled) {
  background: var(--a11y-brand) !important;
  color: white !important;
}

.a11y-action-btn:focus:not(:disabled) {
  outline: none !important;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--a11y-brand) 40%, transparent) !important;
}

.a11y-action-btn:disabled {
  opacity: 0.4 !important;
  cursor: not-allowed !important;
}

.a11y-font-size-display {
  min-width: 48px !important;
  text-align: center !important;
  font-size: 14px !important;
  font-weight: 600 !important;
  color: var(--a11y-brand) !important;
  font-family: system-ui, -apple-system, sans-serif !important;
}

/* ============================================
   RESET BUTTON (Feature 10)
   ============================================ */
.a11y-reset-btn {
  width: 100% !important;
  padding: 14px 20px !important;
  margin-top: 16px !important;
  border-radius: 8px !important;
  background: #dc2626 !important;
  color: white !important;
  border: none !important;
  font-size: 14px !important;
  font-weight: 600 !important;
  cursor: pointer !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  gap: 8px !important;
  transition: all 0.2s ease !important;
  font-family: system-ui, -apple-system, sans-serif !important;
}

.a11y-reset-btn:hover,
.a11y-reset-btn:focus {
  background: #b91c1c !important;
  transform: translateY(-1px) !important;
}

.a11y-reset-btn:focus {
  outline: none !important;
  box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.4) !important;
}

/* ============================================
   PANEL FOOTER
   ============================================ */
#a11y-panel-footer {
  padding: 16px 24px !important;
  border-top: 1px solid var(--a11y-border) !important;
  display: flex !important;
  flex-direction: column !important;
  gap: 12px !important;
}

.a11y-footer-link {
  font-size: 13px !important;
  color: var(--a11y-brand) !important;
  text-decoration: none !important;
  display: inline-flex !important;
  align-items: center !important;
  gap: 4px !important;
  font-family: system-ui, -apple-system, sans-serif !important;
  transition: color 0.2s ease !important;
}

.a11y-footer-link:hover,
.a11y-footer-link:focus {
  color: var(--a11y-brand-dark) !important;
  text-decoration: underline !important;
}

.a11y-footer-link:focus {
  outline: none !important;
  box-shadow: 0 0 0 2px var(--a11y-brand) !important;
  border-radius: 2px !important;
}

.a11y-dismiss-link {
  font-size: 12px !important;
  color: #9ca3af !important;
  text-decoration: none !important;
  cursor: pointer !important;
  transition: color 0.2s ease !important;
  font-family: system-ui, -apple-system, sans-serif !important;
  border: none !important;
  background: none !important;
  padding: 0 !important;
  text-align: left !important;
}

.a11y-dismiss-link:hover,
.a11y-dismiss-link:focus {
  color: #6b7280 !important;
  text-decoration: underline !important;
}

/* ============================================
   ARIA LIVE REGION (visually hidden)
   ============================================ */
#a11y-live {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

/* ============================================
   ACCESSIBILITY FEATURES (applied to body)
   ============================================ */

/* Feature 2: High Contrast Mode */
body.a11y-contrast {
  background: #000 !important;
  color: #FFFF00 !important;
}

body.a11y-contrast a,
body.a11y-contrast a *,
body.a11y-contrast button,
body.a11y-contrast button *,
body.a11y-contrast [role="button"] {
  color: #00FFFF !important;
}

body.a11y-contrast input,
body.a11y-contrast textarea,
body.a11y-contrast select {
  background: #000 !important;
  color: #FFFF00 !important;
  border-color: #FFFF00 !important;
}

body.a11y-contrast * {
  border-color: #FFFF00 !important;
}

/* Feature 3: Grayscale Mode */
html.a11y-gray {
  filter: grayscale(100%) !important;
}

/* Feature 4: Underline Links */
body.a11y-links a {
  text-decoration: underline !important;
}

/* Feature 5: Readable Font */
body.a11y-font,
body.a11y-font *,
body.a11y-font input,
body.a11y-font button,
body.a11y-font textarea {
  font-family: Arial, Helvetica, sans-serif !important;
}

/* Feature 6: Letter Spacing */
body.a11y-spacing,
body.a11y-spacing * {
  letter-spacing: 0.15em !important;
}

/* Feature 7: Line Height */
body.a11y-lh p,
body.a11y-lh li,
body.a11y-lh span,
body.a11y-lh div,
body.a11y-lh td,
body.a11y-lh th,
body.a11y-lh label {
  line-height: 2.0 !important;
}

/* Feature 9: Highlight on Hover/Focus */
body.a11y-highlight *:hover,
body.a11y-highlight *:focus {
  outline: 3px solid var(--a11y-brand) !important;
  outline-offset: 2px !important;
}

/* Exclude widget itself from highlight */
body.a11y-highlight #a11y-panel *:hover,
body.a11y-highlight #a11y-panel *:focus,
body.a11y-highlight #a11y-trigger:hover,
body.a11y-highlight #a11y-trigger:focus {
  outline: none !important;
}

/* ============================================
   HIGH CONTRAST MODE FOR WIDGET ITSELF
   ============================================ */
body.a11y-contrast #a11y-panel {
  background: #000 !important;
  border-color: #00FFFF !important;
  color: #FFFF00 !important;
}

body.a11y-contrast #a11y-panel-header {
  background: #FFFF00 !important;
  color: #000 !important;
  border-color: #00FFFF !important;
}

body.a11y-contrast #a11y-panel-title {
  color: #000 !important;
}

body.a11y-contrast #a11y-close-btn {
  color: #000 !important;
  border: 2px solid #00FFFF !important;
}

body.a11y-contrast .a11y-feature-label span {
  color: #FFFF00 !important;
}

body.a11y-contrast .a11y-feature-label svg {
  color: #FFFF00 !important;
}

body.a11y-contrast .a11y-font-size-display {
  color: #FFFF00 !important;
}

body.a11y-contrast .a11y-toggle-btn {
  background: #333 !important;
  border: 2px solid #FFFF00 !important;
}

body.a11y-contrast .a11y-toggle-btn::after {
  background: #FFFF00 !important;
}

body.a11y-contrast .a11y-toggle-btn[aria-pressed="true"] {
  background: #FFFF00 !important;
}

body.a11y-contrast .a11y-toggle-btn[aria-pressed="true"]::after {
  background: #000 !important;
}

body.a11y-contrast .a11y-action-btn {
  background: #333 !important;
  color: #FFFF00 !important;
  border: 2px solid #FFFF00 !important;
}

body.a11y-contrast .a11y-action-btn:hover:not(:disabled),
body.a11y-contrast .a11y-action-btn:focus:not(:disabled) {
  background: #FFFF00 !important;
  color: #000 !important;
}

body.a11y-contrast .a11y-reset-btn {
  background: #00FFFF !important;
  color: #000 !important;
}

body.a11y-contrast .a11y-reset-btn:hover,
body.a11y-contrast .a11y-reset-btn:focus {
  background: #FFFF00 !important;
}

body.a11y-contrast .a11y-footer-link {
  color: #00FFFF !important;
}

body.a11y-contrast #a11y-trigger {
  border-color: #FFFF00 !important;
  background: rgba(255, 255, 0, 0.3) !important;
}

body.a11y-contrast #a11y-trigger:hover,
body.a11y-contrast #a11y-trigger:focus {
  background: #FFFF00 !important;
}

body.a11y-contrast #a11y-trigger:hover svg,
body.a11y-contrast #a11y-trigger:focus svg {
  color: #000 !important;
}

/* ============================================
   REDUCED MOTION SUPPORT
   ============================================ */
@media (prefers-reduced-motion: reduce) {
  #a11y-trigger,
  #a11y-trigger svg,
  #a11y-trigger:hover,
  #a11y-trigger:focus,
  .a11y-toggle-btn,
  .a11y-toggle-btn::after,
  .a11y-action-btn,
  .a11y-reset-btn,
  #a11y-panel,
  #a11y-close-btn {
    animation: none !important;
    transition: none !important;
  }
}
