/*
 * ACCESSIBILITY CSS - APPLE-LEVEL STANDARDS
 * Full WCAG 2.1 AA compliance with Apple HIG guidelines
 */

/* Screen reader only content */
.sr-only {
  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;
}

/* Screen reader only when not focused */
.sr-only-focusable:focus {
  position: static !important;
  width: auto !important;
  height: auto !important;
  padding: inherit !important;
  margin: inherit !important;
  overflow: visible !important;
  clip: auto !important;
  white-space: normal !important;
}

/* Skip links */
.skip-link {
  position: absolute;
  top: -40px;
  left: 6px;
  background: #000;
  color: #fff;
  padding: 8px 16px;
  text-decoration: none;
  border-radius: 8px;
  z-index: 10000;
  transition: top 0.3s ease;
  font-weight: 600;
  font-size: 14px;
}

.skip-link:focus {
  top: 6px !important;
  outline: 3px solid #0066ff;
  outline-offset: 2px;
}

/* Enhanced focus indicators */
[data-task-id]:focus,
.kanban-column:focus,
button:focus,
input:focus,
textarea:focus,
select:focus,
a:focus {
  outline: 3px solid rgba(0, 102, 255, 0.6) !important;
  outline-offset: 2px !important;
  box-shadow: 0 0 0 1px rgba(0, 102, 255, 0.3) !important;
  border-radius: 8px;
}

/* Keyboard navigation focus */
.keyboard-focused {
  background: rgba(0, 102, 255, 0.1) !important;
  border: 2px solid rgba(0, 102, 255, 0.4) !important;
  transform: translateY(-2px) !important;
  box-shadow: 0 8px 25px rgba(0, 102, 255, 0.2) !important;
  transition: all 0.2s ease !important;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  [data-task-id]:focus,
  .kanban-column:focus,
  button:focus {
    outline: 4px solid #000 !important;
    outline-offset: 2px !important;
    background: #fff !important;
    color: #000 !important;
  }

  .keyboard-focused {
    background: #fff !important;
    border: 3px solid #000 !important;
    color: #000 !important;
  }

  .skip-link {
    background: #fff !important;
    color: #000 !important;
    border: 2px solid #000 !important;
  }
}

/* Enhanced focus for dark mode */
@media (prefers-color-scheme: dark) {
  [data-task-id]:focus,
  .kanban-column:focus,
  button:focus,
  input:focus,
  textarea:focus,
  select:focus,
  a:focus {
    outline: 3px solid rgba(96, 165, 250, 0.8) !important;
    box-shadow: 0 0 0 1px rgba(96, 165, 250, 0.4) !important;
  }

  .keyboard-focused {
    background: rgba(96, 165, 250, 0.15) !important;
    border: 2px solid rgba(96, 165, 250, 0.6) !important;
    box-shadow: 0 8px 25px rgba(96, 165, 250, 0.3) !important;
  }

  .skip-link {
    background: #1a1a1a !important;
    color: #fff !important;
    border: 1px solid rgba(96, 165, 250, 0.5) !important;
  }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
  .keyboard-focused,
  .skip-link,
  [data-task-id]:focus,
  .kanban-column:focus {
    transition: none !important;
    animation: none !important;
    transform: none !important;
  }
}

/* Focus indicators for task items */
[data-task-id][role="option"] {
  position: relative;
  cursor: pointer;
}

[data-task-id][aria-selected="true"] {
  background: rgba(0, 102, 255, 0.08) !important;
  border-left: 4px solid #0066ff !important;
}

/* Enhanced button focus */
button:focus {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0, 102, 255, 0.3) !important;
}

button:focus:active {
  transform: translateY(0);
  box-shadow: 0 2px 6px rgba(0, 102, 255, 0.3) !important;
}

/* Form validation errors */
.error-message {
  color: #dc2626;
  font-size: 14px;
  margin-top: 4px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.error-message::before {
  content: "⚠️";
  flex-shrink: 0;
}

input[aria-invalid="true"],
textarea[aria-invalid="true"],
select[aria-invalid="true"] {
  border-color: #dc2626 !important;
  box-shadow: 0 0 0 1px rgba(220, 38, 38, 0.3) !important;
}

/* Loading states accessibility */
[aria-busy="true"] {
  position: relative;
  pointer-events: none;
  opacity: 0.7;
}

[aria-busy="true"]::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 20px;
  height: 20px;
  margin: -10px 0 0 -10px;
  border: 2px solid #e5e7eb;
  border-top: 2px solid #0066ff;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* Touch target sizes (minimum 44px) */
@media (hover: none) and (pointer: coarse) {
  button,
  [role="button"],
  a,
  input[type="checkbox"],
  input[type="radio"],
  [data-task-id] {
    min-height: 44px !important;
    min-width: 44px !important;
    padding: 12px !important;
  }

  /* Larger focus indicators for touch */
  [data-task-id]:focus,
  button:focus {
    outline-width: 4px !important;
    outline-offset: 3px !important;
  }
}

/* Live region styling */
[aria-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;
}

/* Status indicators */
[aria-expanded="true"]::after {
  content: " (expandido)";
  position: absolute;
  left: -10000px;
  width: 1px;
  height: 1px;
  overflow: hidden;
}

[aria-expanded="false"]::after {
  content: " (recolhido)";
  position: absolute;
  left: -10000px;
  width: 1px;
  height: 1px;
  overflow: hidden;
}

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

/* Focus trap styling */
.focus-trap {
  position: relative;
}

.focus-trap::before,
.focus-trap::after {
  content: "";
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

/* Modal accessibility */
.modal[aria-modal="true"] {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1000;
  background: rgba(0, 0, 0, 0.5);
}

/* Ensure visible focus on modal close button */
.modal [data-action="close-modal"]:focus {
  outline: 3px solid #fff !important;
  outline-offset: 2px !important;
  background: rgba(255, 255, 255, 0.2) !important;
}

/* Keyboard shortcuts indicator */
.keyboard-shortcuts {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: rgba(0, 0, 0, 0.9);
  color: #fff;
  padding: 16px;
  border-radius: 12px;
  font-size: 14px;
  z-index: 9999;
  max-width: 300px;
  opacity: 0;
  transform: translateY(20px);
  transition: all 0.3s ease;
  pointer-events: none;
}

.keyboard-shortcuts.visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.keyboard-shortcuts h4 {
  margin: 0 0 12px 0;
  font-size: 16px;
  font-weight: 600;
}

.keyboard-shortcuts ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.keyboard-shortcuts li {
  display: flex;
  justify-content: space-between;
  margin-bottom: 8px;
  font-size: 13px;
}

.keyboard-shortcuts kbd {
  background: rgba(255, 255, 255, 0.2);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: monospace;
  font-size: 12px;
}

/* Windows High Contrast Mode */
@media (-ms-high-contrast: active) {
  [data-task-id]:focus,
  .kanban-column:focus,
  button:focus {
    outline: 3px solid WindowText !important;
    outline-offset: 2px !important;
  }

  .keyboard-focused {
    background: Highlight !important;
    color: HighlightText !important;
    border: 2px solid WindowText !important;
  }
}

/* Print accessibility */
@media print {
  .skip-link,
  .keyboard-shortcuts,
  [aria-live] {
    display: none !important;
  }

  [data-task-id] {
    break-inside: avoid;
    margin-bottom: 1em;
  }
}