/* ========================================
   Enterprise V9 - Accessibility System
   מערכת נגישות מתקדמת WCAG 2.1 AA
   ======================================== */

@layer utilities {
/* ========================================
   Focus Management - ניהול פוקוס
   ======================================== */

/* Focus indicators for all interactive elements - רק אלמנטים אינטראקטיביים */
a:focus,
button:focus,
input:focus,
select:focus,
textarea:focus,
[tabindex]:focus,
[role="button"]:focus,
[role="link"]:focus,
[role="menuitem"]:focus {
  outline: 2px solid var(--primary-600);
  outline-offset: 2px;
  border-radius: 2px;
}

/* מניעת outline על body, main, divs וכו' */
body:focus,
main:focus,
div:focus,
section:focus,
header:focus,
footer:focus,
article:focus,
aside:focus,
nav:focus,
[class*="container"]:focus,
[class*="wrapper"]:focus,
[class*="-page"]:focus {
  outline: none;
}

/* Enhanced focus for buttons */
.btn:focus,
button:focus,
input:focus,
select:focus,
textarea:focus,
a:focus {
  outline: 2px solid var(--primary-600);
  outline-offset: 2px;
  box-shadow: 0 0 0 4px var(--primary-soft-strong);
}

/* Focus for custom elements */
.card:focus,
.document-card:focus,
.modal:focus {
  outline: 2px solid var(--primary-600);
  outline-offset: 2px;
}

/* Skip links for keyboard navigation */
.skip-link {
  position: absolute;
  top: -40px;
  left: 6px;
  background: var(--primary-600);
  color: var(--text-inverse);
  padding: 8px;
  text-decoration: none;
  border-radius: 4px;
  z-index: 10000;
  font-weight: 600;
}

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

/* ========================================
   Color Contrast - ניגודיות צבעים
   ======================================== */

/* Ensure minimum contrast ratio of 4.5:1 */
.text-primary { color: var(--text-main); } /* 16.7:1 ratio */
.text-secondary { color: var(--text-secondary); } /* 7.1:1 ratio */
.text-muted { color: var(--text-muted); } /* 4.6:1 ratio */

/* High contrast mode support */
@media (prefers-contrast: high) {
  .btn-primary {
    background: var(--bg-elevated);
    color: var(--text-inverse);
    border: 2px solid var(--border-strong);
  }
  
  .btn-secondary {
    background: var(--bg-surface);
    color: var(--text-main);
    border: 2px solid var(--border-strong);
  }
  
  .card {
    border: 2px solid var(--border-strong);
  }
}

/* ========================================
   Screen Reader Support - תמיכה בקוראי מסך
   ======================================== */

/* Hide decorative elements from screen readers */
.decorative,
.icon-decorative {
  aria-hidden: true;
}

/* Ensure proper heading hierarchy */
h1, h2, h3, h4, h5, h6 {
  font-weight: 600;
  line-height: 1.4;
  margin-bottom: 0.5rem;
}

/* Proper form labels */
.form-label {
  font-weight: 500;
  margin-bottom: 0.5rem;
  display: block;
}

.form-label.required::after {
  content: " *";
  color: var(--error-600);
  font-weight: 700;
}

/* Error messages with proper roles */
.form-error {
  color: var(--error-600);
  font-size: 0.875rem;
  margin-top: 0.25rem;
  display: block;
}

.form-error[role="alert"] {
  font-weight: 500;
}

/* Success messages */
.form-success {
  color: var(--success-600);
  font-size: 0.875rem;
  margin-top: 0.25rem;
  display: block;
}

/* ========================================
   Keyboard Navigation - ניווט מקלדת
   ======================================== */

/* Tab order management */
.tab-order-1 { order: 1; }
.tab-order-2 { order: 2; }
.tab-order-3 { order: 3; }
.tab-order-4 { order: 4; }

/* Keyboard accessible dropdowns */
.dropdown-menu {
  visibility: hidden;
  opacity: 0;
  transition: all 0.2s ease;
}

.dropdown-menu.show {
  visibility: visible;
  opacity: 1;
}

/* Keyboard accessible modals */
.modal {
  visibility: hidden;
  opacity: 0;
  transition: all 0.3s ease;
}

.modal.show {
  visibility: visible;
  opacity: 1;
}

/* Focus trap for modals */
.modal-content {
  position: relative;
}

/* ========================================
   ARIA Labels and Roles - תוויות ARIA
   ======================================== */

/* Button accessibility */
/* הוסר - .btn[aria-label]::before גרם לאפקט לא רצוי */
.btn[aria-label] {
  position: relative;
}

/* .btn[aria-label]::before {
  content: attr(aria-label);
  position: absolute;
  left: -9999px;
  width: 1px;
  height: 1px;
  overflow: hidden;
} */

/* Table accessibility */
.table[role="table"] {
  border-collapse: separate;
  border-spacing: 0;
}

.table th[role="columnheader"] {
  font-weight: 600;
  text-align: right;
}

.table td[role="cell"] {
  vertical-align: middle;
}

/* Form accessibility */
.form-group {
  margin-bottom: 1rem;
}

.form-input[aria-invalid="true"] {
  border-color: var(--error-600);
  box-shadow: 0 0 0 3px var(--error-soft);
}

.form-input[aria-invalid="true"]:focus {
  border-color: var(--error-600);
  box-shadow: 0 0 0 3px var(--danger-soft);
}

/* ========================================
   Motion and Animation - תנועה ואנימציה
   ======================================== */

/* Respect user's motion preferences */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms;
    animation-iteration-count: 1;
    transition-duration: 0.01ms;
    scroll-behavior: auto;
  }
}

/* Reduced motion for loading spinners */
@media (prefers-reduced-motion: reduce) {
  .loading-spinner {
    animation: none;
  }
}

/* ========================================
   Touch and Mobile Accessibility - נגישות מובייל
   ======================================== */

/* Minimum touch target size (44x44px) */
.btn,
button,
input[type="button"],
input[type="submit"],
input[type="reset"],
a {
  min-height: 44px;
  min-width: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  /* וידוא שקישורים יורשים צבע מה-parent (לא מדריסים) */
  color: inherit;
}

/* תיקון: וידוא שקישורי mega-link מקבלים צבע - גם אם יש CSS אחר שמדריס */
.premium-navbar .mega-link,
.premium-navbar .dropdown-menu.mega-menu a.mega-link,
/* הוסר !important - משתמש ב-specificity גבוה יותר */
.premium-navbar .dropdown-menu.mega-menu .mega-content a.mega-link,
.premium-navbar .dropdown-menu.mega-menu .mega-section a.mega-link,
.premium-navbar .dropdown-menu.mega-menu a,
.premium-navbar .dropdown-menu.mega-menu .mega-content a,
.premium-navbar .dropdown-menu.mega-menu .mega-section a,
.premium-navbar .mega-content a,
.premium-navbar .mega-section a {
  color: var(--text-secondary);
}

/* Touch-friendly form controls */
.form-input,
.form-select,
.form-textarea {
  min-height: 44px;
  padding: 0.75rem;
  font-size: 16px; /* Prevents zoom on iOS */
}

/* ========================================
   RTL Accessibility - נגישות RTL
   ======================================== */

/* RTL focus indicators */
[dir="rtl"] *:focus {
  outline-offset: -2px;
}

/* RTL skip links */
[dir="rtl"] .skip-link {
  left: auto;
  right: 6px;
}

/* RTL form layouts */
[dir="rtl"] .form-group {
  text-align: right;
}

[dir="rtl"] .form-label {
  text-align: right;
}

/* ========================================
   High Contrast and Dark Mode - מצב כהה
   ======================================== */

@media (prefers-color-scheme: dark) {
  :root {
    --primary-50: #1e3a8a;
    --primary-100: #1e40af;
    --primary-500: #3b82f6;
    --primary-600: #60a5fa;
    --primary-700: #93c5fd;
    --primary-900: #dbeafe;
    
    --secondary-50: #0f172a;
    --secondary-100: #1e293b;
    --secondary-500: #64748b;
    --secondary-600: #94a3b8;
    --secondary-700: #cbd5e1;
    --secondary-900: #f1f5f9;
  }
  
  .card {
    background: var(--secondary-100);
    border-color: var(--secondary-600);
    color: var(--secondary-900);
  }
  
  .form-input,
  .form-select,
  .form-textarea {
    background: var(--secondary-100);
    border-color: var(--secondary-600);
    color: var(--secondary-900);
  }
}

/* ========================================
   Print Accessibility - נגישות הדפסה
   ======================================== */

@media print {
  /* Hide interactive elements */
  .btn,
  button,
  .dropdown,
  .modal {
    display: none;
  }
  
  /* Ensure good contrast for print */
  /* הוסר: קוד כפיה גלובלי - צבעים ורקעים יוגדרו על אלמנטים ספציפיים */
  body, .card, .table, .card-body, .card-header, .card-footer,
  .container, .content-wrapper, main, section, article, div, p, span, h1, h2, h3, h4, h5, h6 {
    color: var(--text-main);
    background: var(--bg-surface);
  }
  
  /* Show URLs for links */
  a[href]:after {
    content: " (" attr(href) ")";
    font-size: 0.8em;
    color: var(--text-muted);
  }
  
  /* Page breaks */
  .page-break {
    page-break-before: always;
  }
  
  .no-break {
    page-break-inside: avoid;
  }
}

/* ========================================
   Utility Classes - מחלקות עזר
   ======================================== */

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

/* Focus visible only */
.focus-visible-only:focus:not(:focus-visible) {
  outline: none;
}

/* High contrast mode indicator */
@media (prefers-contrast: high) {
  .high-contrast-indicator::before {
    content: "🔍 High Contrast Mode";
    position: fixed;
    top: 10px;
    right: 10px;
    background: var(--text-main);
    color: var(--text-inverse);
    padding: 4px 8px;
    font-size: 12px;
    z-index: 9999;
    border-radius: 4px;
  }
}

/* ========================================
   Error Handling - טיפול בשגיאות
   ======================================== */

/* Error states */
.error-state {
  border: 2px solid var(--error-600);
  background: var(--error-50);
}

.error-message {
  color: var(--error-600);
  font-weight: 500;
  margin-top: 0.5rem;
}

/* Warning states */
.warning-state {
  border: 2px solid var(--warning-600);
  background: var(--warning-50);
}

.warning-message {
  color: var(--warning-600);
  font-weight: 500;
  margin-top: 0.5rem;
}

/* Success states */
.success-state {
  border: 2px solid var(--success-600);
  background: var(--success-50);
}

.success-message {
  color: var(--success-600);
  font-weight: 500;
  margin-top: 0.5rem;
}

/* ========================================
   Screen Reader Only Content - תוכן לקוראי מסך בלבד
   ======================================== */

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

/* ========================================
   Focus Management Enhanced - ניהול פוקוס משופר
   ======================================== */

.focus-visible:focus {
  outline: 2px solid var(--primary-500);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

.focus-visible:focus:not(:focus-visible) {
  outline: none;
}

/* High Contrast Focus Indicators */
@media (prefers-contrast: high) {
  .focus-visible:focus {
    outline: 3px solid var(--primary-700);
    outline-offset: 3px;
    background-color: var(--primary-50);
  }
}

/* Keyboard Navigation */
.keyboard-navigation *:focus {
  outline: 2px solid var(--primary-500);
  outline-offset: 2px;
}

/* Remove focus outline for mouse users */
.mouse-navigation *:focus {
  outline: none;
}

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

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

/* ========================================
   Reduced Motion Support Enhanced - תמיכה בתנועה מופחתת משופרת
   ======================================== */

@media (prefers-reduced-motion: reduce) {
  .sidebar {
    transition: none;
  }
  
  .nav-submenu {
    transition: none;
  }
  
  .card:hover {
    transform: none;
  }
  
  .btn:hover {
    transform: none;
  }
}

/* ========================================
   High Contrast Mode Enhanced - מצב ניגודיות גבוהה משופר
   ======================================== */

@media (prefers-contrast: high) {
  :root {
    --border-primary: var(--text-main);
    --border-secondary: var(--text-main);
    --text-primary: var(--text-main);
    --text-secondary: var(--text-main);
    --bg-primary: var(--bg-surface);
    --bg-secondary: var(--bg-surface);
  }
  
  .card {
    border: 2px solid var(--text-main);
  }
  
  .btn {
    border: 2px solid var(--text-main);
  }
  
  .form-input,
  .form-select,
  .form-textarea {
    border: 2px solid var(--text-main);
  }
}

/* ========================================
   Color Blind Friendly - ידידותי לעיוורי צבעים
   ======================================== */

.colorblind-friendly {
  --success-500: #0066cc;
  --warning-500: #ff6600;
  --error-500: #cc0000;
}

/* ========================================
   Text Scaling Support - תמיכה בהגדלת טקסט
   ======================================== */

@media (min-resolution: 1.5dppx) {
  body {
    font-size: calc(var(--text-base) * 1.1);
  }
}

/* ========================================
   Large Text Support - תמיכה בטקסט גדול
   ======================================== */

.large-text {
  font-size: 1.25em;
  line-height: 1.6;
}

.large-text .btn {
  padding: var(--space-4) var(--space-6);
  font-size: 1.1em;
}

.large-text .form-input,
.large-text .form-select,
.large-text .form-textarea {
  padding: var(--space-4) var(--space-5);
  font-size: 1.1em;
}

/* ========================================
   ARIA Live Regions - אזורי ARIA חיים
   ======================================== */

.live-region {
  position: absolute;
  left: -10000px;
  width: 1px;
  height: 1px;
  overflow: hidden;
}

.live-region[aria-live="polite"] {
  /* Polite announcements */
}

.live-region[aria-live="assertive"] {
  /* Urgent announcements */
}

/* ========================================
   Form Accessibility Enhanced - נגישות טפסים משופרת
   ======================================== */

.form-group {
  position: relative;
}

.form-error[role="alert"] {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  margin-top: var(--space-1);
}

.form-error[role="alert"]::before {
  content: '⚠';
  font-size: var(--text-sm);
  color: var(--error-600);
}

.form-success[role="status"] {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  margin-top: var(--space-1);
}

.form-success[role="status"]::before {
  content: '✓';
  font-size: var(--text-sm);
  color: var(--success-600);
}

/* Required Field Indicators */
.required-indicator {
  color: var(--error-500);
  font-weight: var(--font-bold);
  margin-left: var(--space-1);
}

[dir="rtl"] .required-indicator {
  margin-left: 0;
  margin-right: var(--space-1);
}

/* ========================================
   Button Accessibility Enhanced - נגישות כפתורים משופרת
   ======================================== */

.btn[aria-pressed="true"] {
  background-color: var(--primary-700);
  border-color: var(--primary-700);
}

.btn[aria-expanded="true"] .btn-icon {
  transform: rotate(180deg);
}

/* ========================================
   Loading States - מצבי טעינה
   ======================================== */

.loading[aria-busy="true"] {
  position: relative;
  pointer-events: none;
}

.loading[aria-busy="true"]::after {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--bg-overlay);
  display: flex;
  align-items: center;
  justify-content: center;
}

.loading[aria-busy="true"]::before {
  content: 'טוען...';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 1;
  font-weight: var(--font-medium);
  color: var(--text-primary);
}

/* ========================================
   Modal Accessibility Enhanced - נגישות מודלים משופרת
   ======================================== */

.modal[role="dialog"] {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal);
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-overlay);
}

.modal-content {
  background: var(--bg-primary);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-2xl);
  max-width: 90vw;
  max-height: 90vh;
  overflow-y: auto;
  position: relative;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-6);
  border-bottom: 1px solid var(--border-primary);
}

.modal-close {
  background: none;
  border: none;
  font-size: var(--text-xl);
  color: var(--text-secondary);
  cursor: pointer;
  padding: var(--space-2);
  border-radius: var(--radius-md);
  transition: all var(--transition-fast);
}

.modal-close:hover {
  background-color: var(--secondary-100);
  color: var(--text-primary);
}

/* ========================================
   Table Accessibility Enhanced - נגישות טבלאות משופרת
   ======================================== */

.table-responsive {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.table th[scope="col"] {
  background-color: var(--secondary-50);
  font-weight: var(--font-semibold);
  position: sticky;
  top: 0;
  z-index: 10;
}

.table th[aria-sort] {
  cursor: pointer;
  user-select: none;
}

.table th[aria-sort]::after {
  content: '';
  display: inline-block;
  width: 0;
  height: 0;
  margin-left: var(--space-2);
  vertical-align: middle;
}

[dir="rtl"] .table th[aria-sort]::after {
  margin-left: 0;
  margin-right: var(--space-2);
}

.table th[aria-sort="ascending"]::after {
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-bottom: 4px solid var(--text-primary);
}

.table th[aria-sort="descending"]::after {
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 4px solid var(--text-primary);
}

/* ========================================
   Navigation Accessibility Enhanced - נגישות ניווט משופרת
   ======================================== */

.nav-link[aria-current="page"] {
  background-color: var(--primary-50);
  color: var(--primary-700);
  font-weight: var(--font-semibold);
}

.nav-link[aria-expanded="true"] .nav-group-arrow {
  transform: rotate(90deg);
}

[dir="rtl"] .nav-link[aria-expanded="true"] .nav-group-arrow {
  transform: rotate(-90deg);
}

/* ========================================
   Breadcrumb Accessibility Enhanced - נגישות נתיבי ניווט משופרת
   ======================================== */

.breadcrumb[role="navigation"] {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.breadcrumb-item[aria-current="page"] {
  color: var(--text-primary);
  font-weight: var(--font-medium);
}

/* ========================================
   Alert Accessibility Enhanced - נגישות התראות משופרת
   ======================================== */

.alert[role="alert"],
.alert[role="status"] {
  padding: var(--space-4);
  border-radius: var(--radius-lg);
  border: 1px solid;
  margin-bottom: var(--space-4);
}

.alert-success {
  background-color: var(--success-50);
  border-color: var(--success-200);
  color: var(--success-800);
}

.alert-warning {
  background-color: var(--warning-50);
  border-color: var(--warning-200);
  color: var(--warning-800);
}

.alert-error {
  background-color: var(--error-50);
  border-color: var(--error-200);
  color: var(--error-800);
}

.alert-info {
  background-color: var(--info-50);
  border-color: var(--info-200);
  color: var(--info-800);
}

/* ========================================
   Progress Accessibility - נגישות פסי התקדמות
   ======================================== */

.progress[role="progressbar"] {
  width: 100%;
  height: 8px;
  background-color: var(--secondary-200);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  background-color: var(--primary-500);
  transition: width var(--transition-normal);
  border-radius: var(--radius-full);
}

/* ========================================
   Tooltip Accessibility - נגישות טולטיפים
   ======================================== */

.tooltip[role="tooltip"] {
  position: absolute;
  z-index: var(--z-tooltip);
  background: var(--text-primary);
  color: var(--text-inverse);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  max-width: 200px;
  word-wrap: break-word;
}

/* ========================================
   Mobile Accessibility Enhanced - נגישות מובייל משופרת
   ======================================== */

@media (max-width: 768px) {
  .topbar-notification,
  .topbar-toggle {
    min-height: 44px;
    min-width: 44px;
  }
}

/* ========================================
   Print Accessibility Enhanced - נגישות הדפסה משופרת
   ======================================== */

@media print {
  .nav-link[aria-current="page"]::after {
    content: ' (עמוד נוכחי)';
  }
  
  .btn::after {
    content: ' [כפתור]';
  }
  
  .form-input::after {
    content: ' [שדה קלט]';
  }
}

/* ========================================
   Voice Control Support - תמיכה בפקודות קוליות
   ======================================== */

.voice-command {
  position: relative;
}

.voice-command::after {
  content: attr(data-voice-command);
  position: absolute;
  top: -20px;
  left: 0;
  font-size: var(--text-xs);
  color: var(--text-tertiary);
  background: var(--bg-primary);
  padding: 2px 4px;
  border-radius: var(--radius-sm);
  opacity: 0;
  transition: opacity var(--transition-fast);
}

.voice-command:focus::after {
  opacity: 1;
}

/* ========================================
   Error Prevention - מניעת שגיאות
   ======================================== */

.destructive-action {
  position: relative;
}

.destructive-action::before {
  content: '⚠ פעולה מסוכנת';
  position: absolute;
  top: -30px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--error-600);
  color: var(--text-inverse);
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-sm);
  font-size: var(--text-xs);
  white-space: nowrap;
  opacity: 0;
  transition: opacity var(--transition-fast);
  z-index: var(--z-tooltip);
}

.destructive-action:focus::before,
.destructive-action:hover::before {
  opacity: 1;
}

/* ========================================
   Cognitive Load Reduction - הפחתת עומס קוגניטיבי
   ======================================== */

.complex-form .form-group {
  margin-bottom: var(--space-6);
}

.complex-form .form-section {
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  margin-bottom: var(--space-8);
}

.complex-form .form-section-title {
  font-size: var(--text-lg);
  font-weight: var(--font-semibold);
  margin-bottom: var(--space-4);
  color: var(--primary-700);
}

.form-step-indicator {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-4);
  margin-bottom: var(--space-8);
}

.form-step {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-full);
  background: var(--secondary-100);
  color: var(--text-secondary);
  font-size: var(--text-sm);
}

.form-step.active {
  background: var(--primary-500);
  color: var(--text-inverse);
}

.form-step.completed {
  background: var(--success-500);
  color: var(--text-inverse);
}
} /* סיום @layer utilities */