/**
 * Global Accessibility Styles for WCAG 2.1 AA Compliance
 * - Focus indicators
 * - Screen reader utilities
 * - Color contrast compliance
 * - Keyboard navigation support
 */

/* ========================================
   WCAG AA Compliant Color Palette
   ======================================== */

:root {
  /* Text colors (on white #ffffff background) */
  --text-primary: #202124;      /* 14.1:1 contrast ✅ */
  --text-secondary: #5f6368;    /* 7.4:1 contrast ✅ */
  --text-disabled: #80868b;     /* 4.5:1 contrast ✅ */

  /* Interactive colors */
  --link-color: #1a73e8;        /* 4.6:1 contrast ✅ */
  --link-hover: #1557b0;        /* 6.2:1 contrast ✅ */
  --link-visited: #5e35b1;      /* 5.1:1 contrast ✅ */

  /* Status colors */
  --success-color: #1e8e3e;     /* 4.5:1 contrast ✅ */
  --success-bg: #e6f4ea;
  --error-color: #d93025;       /* 4.7:1 contrast ✅ */
  --error-bg: #fce8e6;
  --warning-color: #ea8600;     /* 4.5:1 contrast ✅ */
  --warning-bg: #fef7e0;
  --info-color: #1967d2;        /* 4.9:1 contrast ✅ */
  --info-bg: #e8f0fe;

  /* UI colors */
  --border-color: #dadce0;      /* 3.2:1 contrast ✅ */
  --focus-outline: #1a73e8;     /* 4.6:1 contrast ✅ */
  --focus-outline-width: 2px;
  --focus-outline-offset: 2px;

  /* Button colors */
  --btn-primary-bg: #1a73e8;
  --btn-primary-text: #ffffff;  /* 8.6:1 contrast ✅ */
  --btn-primary-hover: #1557b0;
  --btn-secondary-bg: #ffffff;
  --btn-secondary-text: #202124; /* 14.1:1 contrast ✅ */
  --btn-danger-bg: #d93025;
  --btn-danger-text: #ffffff;   /* 5.3:1 contrast ✅ */
}

/* ========================================
   Focus Indicators (Keyboard Navigation)
   ======================================== */

/* Clear, high-contrast focus indicators */
*:focus {
  outline: var(--focus-outline-width) solid var(--focus-outline);
  outline-offset: var(--focus-outline-offset);
  border-radius: 2px;
}

/* Hide focus for mouse users (only show for keyboard users) */
*:focus:not(:focus-visible) {
  outline: none;
}

/* Always show focus for keyboard users */
*:focus-visible {
  outline: var(--focus-outline-width) solid var(--focus-outline);
  outline-offset: var(--focus-outline-offset);
}

/* Enhanced focus for interactive elements */
button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[role="button"]:focus-visible,
[tabindex]:focus-visible {
  outline: var(--focus-outline-width) solid var(--focus-outline);
  outline-offset: var(--focus-outline-offset);
  box-shadow: 0 0 0 4px rgba(26, 115, 232, 0.1);
}

/* Special focus for buttons */
.btn:focus-visible {
  outline: var(--focus-outline-width) solid var(--focus-outline);
  outline-offset: var(--focus-outline-offset);
  box-shadow: 0 0 0 4px rgba(26, 115, 232, 0.2);
}

/* Keyboard navigation mode */
body.keyboard-nav *:focus {
  outline: var(--focus-outline-width) solid var(--focus-outline);
  outline-offset: var(--focus-outline-offset);
}

/* ========================================
   Screen Reader Utilities
   ======================================== */

/* Hide visually, but keep for screen readers */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

/* Show on focus (useful for skip links) */
.sr-only:focus,
.sr-only:active,
.sr-only-focusable:focus,
.sr-only-focusable:active {
  position: static;
  width: auto;
  height: auto;
  padding: 1rem;
  margin: 0;
  overflow: visible;
  clip: auto;
  white-space: normal;
}

/* Skip navigation link - completely hidden unless focused by keyboard */
.skip-link {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
  z-index: 10000;
}

.skip-link:focus,
.skip-link:active {
  position: absolute;
  top: 0;
  left: 0;
  width: auto;
  height: auto;
  padding: 8px 16px;
  margin: 0;
  overflow: visible;
  clip: auto;
  white-space: normal;
  background: var(--btn-primary-bg);
  color: var(--btn-primary-text);
  text-decoration: none;
  border-radius: 0 0 4px 0;
  outline: var(--focus-outline-width) solid var(--focus-outline);
}

/* ========================================
   Error Notifications
   ======================================== */

.error-notification {
  position: fixed;
  top: 20px;
  right: 20px;
  max-width: 400px;
  background: white;
  border-left: 4px solid;
  border-radius: 4px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  padding: 16px;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  z-index: 1000;
  opacity: 0;
  transform: translateX(100%);
  transition: all 0.3s ease;
}

.error-notification.show {
  opacity: 1;
  transform: translateX(0);
}

.error-notification.error-warning {
  border-left-color: var(--warning-color);
  background: var(--warning-bg);
}

.error-notification.error-error {
  border-left-color: var(--error-color);
  background: var(--error-bg);
}

.error-notification.error-critical {
  border-left-color: var(--error-color);
  background: var(--error-bg);
}

.error-notification.error-success {
  border-left-color: var(--success-color);
  background: var(--success-bg);
}

.error-icon {
  font-size: 20px;
  flex-shrink: 0;
}

.error-content {
  flex: 1;
}

.error-title {
  margin: 0 0 4px 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}

.error-message {
  margin: 0;
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.5;
}

.error-action-btn {
  margin-top: 12px;
  padding: 6px 12px;
  font-size: 13px;
}

.error-dismiss {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: var(--text-secondary);
  padding: 0;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: background-color 0.2s;
}

.error-dismiss:hover {
  background-color: rgba(0, 0, 0, 0.05);
}

/* ========================================
   Warning Banner
   ======================================== */

.warning-banner {
  background: var(--warning-bg);
  border-left: 4px solid var(--warning-color);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  border-radius: 4px;
}

.warning-icon {
  font-size: 20px;
  flex-shrink: 0;
}

.warning-banner p {
  margin: 0;
  flex: 1;
  font-size: 14px;
  color: var(--text-primary);
}

.warning-dismiss {
  background: none;
  border: none;
  font-size: 18px;
  cursor: pointer;
  color: var(--text-secondary);
  padding: 4px;
}

/* ========================================
   Accessible Buttons
   ======================================== */

/* Button appearance lives in styles/controls.css. It used to be redefined here
   too, and `.btn-primary:hover:not(:disabled)` (0,3,0) quietly beat the shared
   `.btn-primary:hover` on every page, so primary buttons turned blue on hover. */

/* ========================================
   Accessible Forms
   ======================================== */

/* Ensure labels are associated with inputs */
label {
  display: block;
  margin-bottom: 4px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
}

input,
select,
textarea {
  font-size: 14px;
  padding: 8px 12px;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  transition: border-color 0.2s;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--focus-outline);
  outline: var(--focus-outline-width) solid var(--focus-outline);
  outline-offset: 0;
}

/* Invalid input styling */
input:invalid,
select:invalid,
textarea:invalid,
input[aria-invalid="true"],
select[aria-invalid="true"],
textarea[aria-invalid="true"] {
  border-color: var(--error-color);
}

/* Required field indicator */
.required {
  color: var(--error-color);
  font-weight: 600;
}

/* Help text */
.help-text {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 4px;
}

/* Error text */
.error-text {
  font-size: 12px;
  color: var(--error-color);
  margin-top: 4px;
}

/* ========================================
   High Contrast Mode Support
   ======================================== */

@media (prefers-contrast: high) {
  :root {
    --text-primary: #000000;
    --text-secondary: #000000;
    --border-color: #000000;
    --focus-outline: #000000;
    --focus-outline-width: 3px;
  }

  button,
  input,
  select,
  textarea {
    border-width: 2px;
  }
}

/* ========================================
   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;
    scroll-behavior: auto !important;
  }
}

/* ========================================
   Loading States (Accessible)
   ======================================== */

.spinner {
  border: 3px solid rgba(0, 0, 0, 0.1);
  border-radius: 50%;
  border-top-color: var(--btn-primary-bg);
  width: 40px;
  height: 40px;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Spinner for reduced motion */
@media (prefers-reduced-motion: reduce) {
  .spinner {
    animation: none;
    border-top-color: var(--btn-primary-bg);
    opacity: 0.8;
  }
}

/* ========================================
   Keyboard-Accessible Draggable Elements
   ======================================== */

[draggable="true"],
.draggable {
  cursor: move;
}

[draggable="true"]:focus,
.draggable:focus {
  outline: var(--focus-outline-width) solid var(--focus-outline);
  outline-offset: var(--focus-outline-offset);
  box-shadow: 0 0 0 4px rgba(26, 115, 232, 0.1);
}

/* ========================================
   Accessible Links
   ======================================== */

a {
  color: var(--link-color);
  text-decoration: underline;
  transition: color 0.2s;
}

a:hover {
  color: var(--link-hover);
}

a:visited {
  color: var(--link-visited);
}

/* Don't rely on color alone for links */
a:not([class]) {
  text-decoration: underline;
}

/* ========================================
   Print Styles (Accessibility)
   ======================================== */

@media print {
  /* Ensure sufficient contrast in print */
  * {
    background: white !important;
    color: black !important;
  }

  /* Show URLs for links */
  a::after {
    content: " (" attr(href) ")";
  }
}
