/* =============================================================================
   accessibility.css - Accessibility & Focus Management Styles for Story Manager
   WCAG 2.2 AA Color Contrast Compliance
   ============================================================================= */

/* =============================================================================
   1. Focus Management
   ============================================================================= */
.sr-only-focusable:focus {
  position: static !important;
  width: auto !important;
  height: auto !important;
  margin: 0 !important;
  overflow: visible !important;
  clip: auto !important;
  background: var(--focus-outline) !important;
  color: white !important;
  padding: 0.5rem !important;
  border-radius: 4px !important;
  z-index: 9999 !important;
}

button:focus,
a:focus,
input:focus,
textarea:focus,
select:focus,
[tabindex]:focus {
  outline: var(--focus-outline-width) solid var(--focus-outline) !important;
  outline-offset: var(--focus-outline-offset) !important;
  border-radius: 4px !important;
}

button:focus:not(:focus-visible),
a:focus:not(:focus-visible),
input:focus:not(:focus-visible),
textarea:focus:not(:focus-visible),
select:focus:not(:focus-visible),
[tabindex]:focus:not(:focus-visible) {
  outline: none !important;
}

/* =============================================================================
   2. WCAG 2.2 Color Contrast Compliance
   ============================================================================= */

/* Base text colors for light theme */
body {
  color: var(--text-on-white);
}

/* Text-muted with proper contrast */
.text-muted {
  color: var(--text-muted) !important; /* 4.5:1+ contrast on white */
}

/* Text on light gray backgrounds */
.bg-light .text-muted,
.card-header .text-muted,
.panel-header .text-muted {
  color: var(--text-muted-dark) !important; /* 4.5:1+ contrast on #f8f9fa */
}

/* Modal text colors - ensure proper contrast */
.modal .form-label,
.modal label.form-label {
  color: var(--text-on-white) !important;
  font-weight: 500;
  font-size: var(--font-size-base);
}

.modal .modal-body {
  color: var(--text-on-white) !important;
}

/* Modal headers with white text on colored backgrounds */
.modal-header.bg-primary,
.modal-header.bg-secondary,
.modal-header.bg-success,
.modal-header.bg-danger,
.modal-header.bg-warning,
.modal-header.bg-info {
  color: var(--text-light) !important;
}

/* Empty states and loading messages */
.empty-state,
.loading-message,
.text-center.text-muted {
  color: var(--text-muted) !important;
}

/* Card content */
.card {
  color: var(--text-on-card);
}

.card-header {
  color: var(--text-on-card);
}

/* Form elements */
.form-label,
label {
  color: var(--text-on-white);
}

.form-control,
.form-select {
  color: var(--text-on-white);
}

/* Button text colors */
.btn-primary {
  color: var(--text-light) !important;
}

.btn-secondary {
  color: var(--text-light) !important;
}

.btn-outline-primary {
  color: var(--brand-blue) !important;
}

.btn-outline-secondary {
  color: var(--text-muted) !important;
}

/* Dropdown items */
.dropdown-item {
  color: var(--text-on-white);
}

.dropdown-item:hover {
  color: var(--brand-blue);
}

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

/* Navigation */
.navbar-nav .nav-link {
  color: var(--text-on-white) !important;
}

.navbar-nav .nav-link:hover {
  color: var(--brand-blue) !important;
}

.navbar-nav .nav-link.active {
  color: var(--brand-blue) !important;
}

.navbar-brand {
  color: var(--brand-blue) !important;
}

/* Breadcrumbs */
.breadcrumb-item {
  color: var(--text-muted);
}

.breadcrumb-item a {
  color: var(--brand-blue);
}

/* Status messages and alerts */
.alert-success {
  background-color: var(--success-bg);
  color: var(--success-text);
  border-color: #c3e6cb;
}

.alert-warning {
  background-color: var(--warning-bg);
  color: var(--warning-text);
  border-color: #ffeaa7;
}

.alert-danger {
  background-color: var(--danger-bg);
  color: var(--danger-text);
  border-color: #f5c6cb;
}

.alert-info {
  background-color: var(--info-bg);
  color: var(--info-text);
  border-color: #bee5eb;
}

/* =============================================================================
   3. Dark Theme Color Contrast Compliance
   ============================================================================= */

/* Dark theme base colors */
body.theme-dark {
  color: var(--text-on-dark);
}

body.theme-dark .text-muted {
  color: var(--text-muted-on-dark) !important;
}

body.theme-dark .card {
  color: var(--text-on-dark);
}

body.theme-dark .card-header {
  color: var(--text-on-dark);
}

body.theme-dark .modal .form-label,
body.theme-dark .modal label.form-label {
  color: var(--text-on-dark) !important;
}

body.theme-dark .modal .modal-body {
  color: var(--text-on-dark) !important;
}

body.theme-dark .form-label,
body.theme-dark label {
  color: var(--text-on-dark);
}

body.theme-dark .form-control,
body.theme-dark .form-select {
  color: var(--text-on-dark);
}

body.theme-dark .dropdown-item {
  color: var(--text-on-dark);
}

body.theme-dark .navbar-nav .nav-link {
  color: var(--text-on-dark) !important;
}

body.theme-dark .navbar-brand {
  color: var(--brand-blue) !important;
}

body.theme-dark .breadcrumb-item {
  color: var(--text-muted-on-dark);
}

body.theme-dark .breadcrumb-item a {
  color: var(--brand-blue);
}

/* Dark theme empty states */
body.theme-dark .empty-state,
body.theme-dark .loading-message,
body.theme-dark .text-center.text-muted {
  color: var(--text-muted-on-dark) !important;
}

/* =============================================================================
   4. High Contrast Mode Support
   
   ⚠️ NOTE: This :root block overrides variables from variables.css for users
   who prefer high contrast. This is intentional and should NOT be removed.
   ============================================================================= */
@media (prefers-contrast: high) {
  :root {
    --brand-blue: #000080;
    --brand-blue-hover: #000060;
    --text-dark: #000000;
    --text-muted: #000000;
    --text-muted-dark: #000000;
  }
  
  .btn-primary {
    background-color: #000080 !important;
    border-color: #000080 !important;
    color: #ffffff !important;
  }
  
  .btn-primary:hover {
    background-color: #000060 !important;
    border-color: #000060 !important;
  }
  
  .text-muted {
    color: #000000 !important;
  }
  
  .card {
    border: 2px solid #000000 !important;
  }
  
  .modal-content {
    border: 2px solid #000000 !important;
  }
}

/* =============================================================================
   5. 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;
  }
  
  .project-grid-item:hover,
  .chapter-grid-item:hover,
  .scene-grid-item:hover,
  .event-grid-item:hover {
    transform: none !important;
  }
}

/* =============================================================================
   6. Additional Accessibility Enhancements
   ============================================================================= */

/* Ensure minimum touch targets */
button,
.btn,
.nav-link,
.dropdown-item {
  min-height: var(--min-touch-target);
  min-width: var(--min-touch-target);
}

/* Ensure minimum font sizes */
body {
  font-size: var(--min-font-size);
}

/* Focus indicators for custom components */
.draggable-item:focus,
.grid-item:focus,
.panel-item:focus {
  outline: var(--focus-outline-width) solid var(--focus-outline);
  outline-offset: var(--focus-outline-offset);
}

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

/* Live regions for status updates */
[aria-live="polite"],
[aria-live="assertive"] {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  border: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

/* Skip links */
.skip-link {
  position: absolute;
  top: -40px;
  left: 6px;
  background: var(--focus-outline);
  color: white;
  padding: 8px;
  text-decoration: none;
  border-radius: 4px;
  z-index: 1000;
}

.skip-link:focus {
  top: 6px;
} 

/* Sidebar Tab Navigation - Details Page */
.card-header .nav-tabs .nav-link {
  color: #212529 !important; /* High-contrast dark text */
  background-color: #e9ecef !important; /* Light gray background for contrast */
  border: none !important;
  font-weight: 500;
  transition: background 0.2s, color 0.2s;
}

.card-header .nav-tabs .nav-link.active {
  color: #fff !important;
  background-color: var(--brand-blue) !important;
  border: none !important;
  font-weight: 700;
}

.card-header .nav-tabs .nav-link:focus,
.card-header .nav-tabs .nav-link:hover {
  color: var(--brand-blue) !important;
  background-color: #f8f9fa !important;
  text-decoration: underline;
  outline: var(--focus-outline-width) solid var(--focus-outline) !important;
  outline-offset: var(--focus-outline-offset) !important;
}

/* Dark theme support for sidebar tabs */
body.theme-dark .card-header .nav-tabs .nav-link {
  color: #f8f9fa !important;
  background-color: #495057 !important;
}

body.theme-dark .card-header .nav-tabs .nav-link.active {
  color: #fff !important;
  background-color: var(--brand-blue) !important;
}

body.theme-dark .card-header .nav-tabs .nav-link:focus,
body.theme-dark .card-header .nav-tabs .nav-link:hover {
  color: #fff !important;
  background-color: #6c757d !important;
}

/* =============================================================================
   3. Enhanced Focus Indicators
   ============================================================================= */
.btn:focus,
.form-control:focus,
.form-select:focus,
.nav-link:focus {
  outline: var(--focus-outline-width) solid var(--focus-outline) !important;
  outline-offset: var(--focus-outline-offset) !important;
  box-shadow: 0 0 0 var(--focus-outline-width) var(--focus-outline) !important;
}

/* =============================================================================
   4. High Contrast Mode Support
   ============================================================================= */
@media (prefers-contrast: high) {
  .card-header .nav-tabs .nav-link {
    border: 2px solid #000 !important;
  }
  
  .card-header .nav-tabs .nav-link.active {
    border: 3px solid #000 !important;
    background-color: #000 !important;
    color: #fff !important;
  }
}

/* =============================================================================
   5. Reduced Motion Support
   ============================================================================= */
@media (prefers-reduced-motion: reduce) {
  .card-header .nav-tabs .nav-link {
    transition: none !important;
  }
  
  .btn,
  .form-control,
  .form-select,
  .nav-link {
    transition: none !important;
  }
}

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

/* =============================================================================
   7. Skip Links
   ============================================================================= */
.sr-only-focusable:focus {
  position: static !important;
  width: auto !important;
  height: auto !important;
  margin: 0 !important;
  overflow: visible !important;
  clip: auto !important;
  background: var(--focus-outline) !important;
  color: white !important;
  padding: 0.5rem !important;
  border-radius: 4px !important;
  z-index: 9999 !important;
}

/* =============================================================================
   8. Form Accessibility
   ============================================================================= */
.form-label {
  font-weight: 500;
  color: var(--text-dark);
  margin-bottom: 0.5rem;
}

.form-text {
  color: var(--text-muted);
  font-size: 0.875rem;
}

.form-control:invalid,
.form-select:invalid {
  border-color: #dc3545;
}

.form-control:invalid:focus,
.form-select:invalid:focus {
  border-color: #dc3545;
  box-shadow: 0 0 0 0.2rem rgba(220, 53, 69, 0.25);
}

/* =============================================================================
   9. Button Accessibility
   ============================================================================= */
.btn {
  min-height: 44px;
  min-width: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.btn-sm {
  min-height: 32px;
  min-width: 32px;
}

.btn-lg {
  min-height: 48px;
  min-width: 48px;
}

/* =============================================================================
   10. Link Accessibility
   ============================================================================= */
a {
  color: var(--brand-blue);
  text-decoration: none;
  transition: color 0.2s ease;
}

a:hover {
  color: var(--brand-blue-hover);
  text-decoration: underline;
}

a:focus {
  outline: var(--focus-outline-width) solid var(--focus-outline);
  outline-offset: var(--focus-outline-offset);
  border-radius: 4px;
}

/* =============================================================================
   11. Image Accessibility
   ============================================================================= */
img {
  max-width: 100%;
  height: auto;
}

img[alt=""] {
  border: 2px dashed #ccc;
}

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

th,
td {
  padding: 0.75rem;
  text-align: left;
  border-bottom: 1px solid #dee2e6;
}

th {
  background-color: #f8f9fa;
  font-weight: 600;
  color: var(--text-dark);
}

/* =============================================================================
   13. Modal Accessibility
   ============================================================================= */
.modal {
  z-index: 1050;
}

.modal-backdrop {
  z-index: 1040;
}

.modal-header {
  border-bottom: 1px solid #dee2e6;
  padding: 1rem;
}

.modal-footer {
  border-top: 1px solid #dee2e6;
  padding: 1rem;
}

/* =============================================================================
   14. Alert Accessibility
   ============================================================================= */
.alert {
  border: 1px solid transparent;
  border-radius: 0.375rem;
  padding: 0.75rem 1rem;
  margin-bottom: 1rem;
}

.alert-success {
  color: #155724;
  background-color: #d4edda;
  border-color: #c3e6cb;
}

.alert-danger {
  color: #721c24;
  background-color: #f8d7da;
  border-color: #f5c6cb;
}

.alert-warning {
  color: #856404;
  background-color: #fff3cd;
  border-color: #ffeaa7;
}

.alert-info {
  color: #0c5460;
  background-color: #d1ecf1;
  border-color: #bee5eb;
}

/* =============================================================================
   15. Loading States
   ============================================================================= */
.loading {
  opacity: 0.6;
  pointer-events: none;
}

.loading::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 20px;
  height: 20px;
  margin: -10px 0 0 -10px;
  border: 2px solid #f3f3f3;
  border-top: 2px solid #3498db;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

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

/* =============================================================================
   16. Print Styles
   ============================================================================= */
@media print {
  .btn,
  .nav,
  .modal,
  .alert {
    display: none !important;
  }
  
  body {
    font-size: 12pt;
    line-height: 1.4;
    color: #000;
    background: #fff;
  }
  
  a {
    color: #000;
    text-decoration: underline;
  }
  
  h1, h2, h3, h4, h5, h6 {
    color: #000;
    page-break-after: avoid;
  }
  
  table {
    page-break-inside: avoid;
  }
} 