/**
 * Accessibility & UX Enhancements for Kapybar
 * WCAG 2.1 AA compliant styles and enhanced user experience
 */

/* ================================================
   COLOR CONTRAST IMPROVEMENTS (WCAG 2.1 AA)
   ================================================ */

:root {
  /* Enhanced contrast ratios (minimum 4.5:1 for normal text, 3:1 for large text) */
  --a11y-text-primary: #1f2937; /* 16.94:1 contrast on white */
  --a11y-text-secondary: #374151; /* 12.59:1 contrast on white */
  --a11y-text-muted: #4b5563; /* 9.73:1 contrast on white */
  --a11y-link: #047857; /* 8.59:1 contrast on white */
  --a11y-link-hover: #1f2937; /* 10.69:1 contrast on white */
  --a11y-success: #047857; /* 6.74:1 contrast on white */
  --a11y-warning: #b45309; /* 6.25:1 contrast on white */
  --a11y-danger: #b91c1c; /* 7.22:1 contrast on white */
  --a11y-focus: #1b5115; /* Focus indicator color */

  /* High contrast backgrounds */
  --a11y-bg-subtle: #f9fafb;
  --a11y-bg-muted: #f3f4f6;
  --a11y-border: #d1d5db;
  --a11y-border-focus: #047857;
}

/* Override existing colors for better contrast */
body {
  color: var(--a11y-text-primary);
}

h1,
h2,
h3,
h4,
h5,
h6,
.h1,
.h2,
.h3,
.h4,
.h5,
.h6 {
  color: var(--a11y-text-primary);
}

.text-muted {
  color: var(--a11y-text-muted) !important;
}

.color-link,
a:not(.btn) {
  color: var(--a11y-link);
}

.color-link:hover,
a:not(.btn):hover {
  color: var(--a11y-link-hover);
}

/* ================================================
   FOCUS MANAGEMENT & KEYBOARD NAVIGATION
   ================================================ */

/* Enhanced focus indicators for all interactive elements */
*:focus-visible {
  outline: 3px solid var(--a11y-focus);
  outline-offset: 2px;
  border-radius: 4px;
}

/* Custom focus styles for specific elements */
.btn:focus-visible {
  outline: 3px solid var(--a11y-focus);
  outline-offset: 2px;
  box-shadow: none;
}

.form-control:focus-visible,
.form-select:focus-visible {
  outline: 3px solid var(--a11y-focus);
  outline-offset: 2px;
  border-color: var(--a11y-border-focus);
  box-shadow: 0 0 0 0.125rem rgba(37, 99, 235, 0.25);
}

.card:focus-visible {
  outline: 3px solid var(--a11y-focus);
  outline-offset: 2px;
}

/* Navigation focus improvements */
.nav-link:focus-visible {
  outline: 3px solid var(--a11y-focus);
  outline-offset: 2px;
  background-color: var(--a11y-bg-subtle);
}

/* Table focus navigation */
.table:focus-within {
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.2);
}

.table tbody tr:focus-within {
  background-color: var(--a11y-bg-subtle);
  outline: 2px solid var(--a11y-focus);
  outline-offset: -2px;
}

/* Skip links for screen readers */
.skip-link {
  position: absolute;
  top: -40px;
  left: 6px;
  background: var(--a11y-text-primary);
  color: white;
  padding: 8px 16px;
  text-decoration: none;
  font-weight: 600;
  border-radius: 4px;
  z-index: 10000;
  opacity: 0;
  pointer-events: none;
  transition: top 0.2s ease, opacity 0.2s ease;
}

.skip-link:focus {
  top: 6px;
  opacity: 1;
  pointer-events: auto;
  outline: 3px solid var(--a11y-focus);
  outline-offset: 2px;
}

/* ================================================
   SCREEN READER ENHANCEMENTS
   ================================================ */

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

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

/* Enhanced form labels for screen readers */
.form-label-enhanced {
  font-weight: 600;
  color: var(--a11y-text-primary);
  margin-bottom: 0.5rem;
  display: block;
}

.form-label-enhanced.required::after {
  content: ' *';
  color: var(--a11y-danger);
  font-weight: bold;
  margin-left: 0.25rem;
}

/* ARIA live regions for dynamic content */
.live-region {
  position: absolute;
  left: -10000px;
  width: 1px;
  height: 1px;
  overflow: hidden;
}

/* ================================================
   LOADING STATES & SKELETON COMPONENTS
   ================================================ */

/* Dashboard skeleton loading */
.skeleton-dashboard {
  padding: 2rem;
  animation: pulse 1.5s ease-in-out infinite alternate;
}

.skeleton-card {
  background: linear-gradient(90deg, #f3f4f6 25%, #e5e7eb 50%, #f3f4f6 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: 0.75rem;
  margin-bottom: 1.5rem;
}

.skeleton-card-header {
  height: 3rem;
  margin-bottom: 1rem;
  border-radius: 0.75rem 0.75rem 0 0;
}

.skeleton-card-body {
  padding: 1.5rem;
}

.skeleton-line {
  height: 1rem;
  background: linear-gradient(90deg, #f3f4f6 25%, #e5e7eb 50%, #f3f4f6 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: 0.25rem;
  margin-bottom: 0.75rem;
}

.skeleton-line.short {
  width: 60%;
}

.skeleton-line.medium {
  width: 80%;
}

.skeleton-line.long {
  width: 100%;
}

.skeleton-stat {
  height: 5rem;
  background: linear-gradient(90deg, #f3f4f6 25%, #e5e7eb 50%, #f3f4f6 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: 0.5rem;
  margin-bottom: 1rem;
}

@keyframes shimmer {
  0% {
    background-position: -200% 0;
  }
  100% {
    background-position: 200% 0;
  }
}

@keyframes pulse {
  0% {
    opacity: 1;
  }
  50% {
    opacity: 0.7;
  }
  100% {
    opacity: 1;
  }
}

/* ================================================
   TOAST NOTIFICATIONS
   ================================================ */

.toast-container {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 1090;
  width: 320px;
  max-width: calc(100vw - 2rem);
}

.toast-modern {
  background: white;
  border: 1px solid var(--a11y-border);
  border-radius: 0.75rem;
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  margin-bottom: 0.75rem;
  overflow: hidden;
  transition: all 0.3s ease;
  transform: translateX(100%);
  opacity: 0;
}

.toast-modern.show {
  transform: translateX(0);
  opacity: 1;
}

.toast-modern.hide {
  transform: translateX(100%);
  opacity: 0;
}

.toast-header-modern {
  display: flex;
  align-items: center;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--a11y-border);
  background: var(--a11y-bg-subtle);
}

.toast-body-modern {
  padding: 1rem;
  color: var(--a11y-text-primary);
  font-size: 0.875rem;
  line-height: 1.5;
}

.toast-icon {
  width: 1.25rem;
  height: 1.25rem;
  margin-right: 0.5rem;
  flex-shrink: 0;
}

.toast-title {
  font-weight: 600;
  color: var(--a11y-text-primary);
  margin: 0;
  font-size: 0.875rem;
}

.toast-close {
  background: none;
  border: none;
  font-size: 1.25rem;
  color: var(--a11y-text-muted);
  cursor: pointer;
  margin-left: auto;
  padding: 0.25rem;
  border-radius: 0.25rem;
}

.toast-close:focus-visible {
  outline: 2px solid var(--a11y-focus);
  outline-offset: 2px;
}

.toast-close:hover {
  color: var(--a11y-text-primary);
  background-color: var(--a11y-bg-muted);
}

/* Toast variants */
.toast-success {
  border-left: 4px solid var(--a11y-success);
}

.toast-success .toast-icon {
  color: var(--a11y-success);
}

.toast-warning {
  border-left: 4px solid var(--a11y-warning);
}

.toast-warning .toast-icon {
  color: var(--a11y-warning);
}

.toast-error {
  border-left: 4px solid var(--a11y-danger);
}

.toast-error .toast-icon {
  color: var(--a11y-danger);
}

.toast-info {
  border-left: 4px solid var(--a11y-link);
}

.toast-info .toast-icon {
  color: var(--a11y-link);
}

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

.progress-form {
  width: 100%;
  height: 8px;
  background-color: var(--a11y-bg-muted);
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 1rem;
  position: relative;
}

.progress-form-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--a11y-link), #3b82f6);
  border-radius: 4px;
  transition: width 0.3s ease;
  min-width: 0;
}

.progress-form-text {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--a11y-text-primary);
  white-space: nowrap;
}

/* Multi-step form progress */
.steps-progress {
  display: flex;
  align-items: center;
  margin-bottom: 2rem;
  padding: 1rem;
  background: var(--a11y-bg-subtle);
  border-radius: 0.5rem;
}

.step-item {
  display: flex;
  align-items: center;
  flex: 1;
  position: relative;
}

.step-number {
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 600;
  margin-right: 0.5rem;
  border: 2px solid var(--a11y-border);
  background: white;
  color: var(--a11y-text-muted);
}

.step-item.active .step-number {
  background: var(--a11y-link);
  color: white;
  border-color: var(--a11y-link);
}

.step-item.completed .step-number {
  background: var(--a11y-success);
  color: white;
  border-color: var(--a11y-success);
}

.step-title {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--a11y-text-muted);
}

.step-item.active .step-title {
  color: var(--a11y-text-primary);
  font-weight: 600;
}

.step-item.completed .step-title {
  color: var(--a11y-text-primary);
}

.step-connector {
  height: 2px;
  background: var(--a11y-border);
  flex: 1;
  margin: 0 1rem;
}

.step-item.completed ~ .step-item .step-connector {
  background: var(--a11y-success);
}

/* ================================================
   EMPTY STATES
   ================================================ */

.empty-state {
  text-align: center;
  padding: 3rem 2rem;
  color: var(--a11y-text-muted);
}

.empty-state-icon {
  font-size: 3rem;
  color: var(--a11y-text-muted);
  margin-bottom: 1rem;
  opacity: 0.5;
}

.empty-state-title {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--a11y-text-primary);
  margin-bottom: 0.5rem;
}

.empty-state-description {
  font-size: 1rem;
  color: var(--a11y-text-muted);
  margin-bottom: 1.5rem;
  max-width: 400px;
  margin-left: auto;
  margin-right: auto;
  line-height: 1.5;
}

.empty-state-action {
  margin-top: 1rem;
}

/* Empty state variants */
.empty-state-table {
  padding: 2rem;
  border: 2px dashed var(--a11y-border);
  border-radius: 0.75rem;
  background: var(--a11y-bg-subtle);
}

.empty-state-search {
  padding: 2rem;
}

.empty-state-error {
  padding: 2rem;
  color: var(--a11y-danger);
}

.empty-state-error .empty-state-icon {
  color: var(--a11y-danger);
}

/* ================================================
   ENHANCED ERROR STATES
   ================================================ */

.error-summary {
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: 0.5rem;
  padding: 1rem;
  margin-bottom: 1.5rem;
}

.error-summary-title {
  font-weight: 600;
  color: var(--a11y-danger);
  margin-bottom: 0.5rem;
  font-size: 0.875rem;
}

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

.error-summary-item {
  margin-bottom: 0.25rem;
}

.error-summary-link {
  color: var(--a11y-danger);
  text-decoration: underline;
  font-size: 0.875rem;
}

.error-summary-link:hover {
  color: #991b1b;
}

/* Field-level error styling */
.form-group-error .form-control {
  border-color: var(--a11y-danger);
  background-color: #fef2f2;
}

.form-group-error .form-label {
  color: var(--a11y-danger);
}

.error-message {
  color: var(--a11y-danger);
  font-size: 0.875rem;
  margin-top: 0.25rem;
  font-weight: 500;
}

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

@media (prefers-contrast: high) {
  :root {
    --a11y-text-primary: #000000;
    --a11y-bg-subtle: #ffffff;
    --a11y-border: #000000;
    --a11y-focus: #0000ff;
  }

  .card,
  .btn,
  .form-control,
  .form-select {
    border: 2px solid #000000;
  }

  .toast-modern {
    border: 2px solid #000000;
  }
}

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

@media (prefers-reduced-motion: reduce) {
  .skeleton-card,
  .skeleton-line,
  .skeleton-stat {
    animation: none;
  }

  .toast-modern {
    transition: none;
  }

  .progress-form-bar {
    transition: none;
  }

  .shimmer,
  .pulse {
    animation: none;
  }
}

/* ================================================
   KEYBOARD NAVIGATION HELPERS
   ================================================ */

/* Focus trapping for modals and dropdowns */
.focus-trap {
  position: relative;
}

/* Enhanced table keyboard navigation */
.table-keyboard-nav tbody tr {
  cursor: pointer;
}

.table-keyboard-nav tbody tr:focus {
  background-color: var(--a11y-bg-subtle);
  outline: 2px solid var(--a11y-focus);
  outline-offset: -2px;
}

/* Keyboard shortcuts indicator */
.keyboard-shortcut {
  font-family: monospace;
  background: var(--a11y-bg-muted);
  border: 1px solid var(--a11y-border);
  border-radius: 0.25rem;
  padding: 0.125rem 0.375rem;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--a11y-text-primary);
}

/* ================================================
   PRINT STYLES
   ================================================ */

@media print {
  .skip-link,
  .toast-container,
  .skeleton-dashboard,
  .skeleton-card {
    display: none !important;
  }

  .card {
    box-shadow: none !important;
    border: 1px solid #000000 !important;
  }

  a::after {
    content: ' (' attr(href) ')';
    font-size: 0.8em;
    color: #666;
  }
}
