/**
 * MeterSyncWeb Accessibility Styles
 * WCAG 2.1 Level AA Compliance
 */

/* Skip Navigation Links */
.skip-link {
  position: absolute;
  top: -40px;
  left: 0;
  background: var(--brand, #25d463);
  color: white;
  padding: 8px 16px;
  text-decoration: none;
  border-radius: 0 0 8px 0;
  z-index: 10000;
  font-weight: 600;
  transition: top 0.3s;
  font-size: 14px;
}

.skip-link:focus {
  top: 0;
  outline: 3px solid #ffbb00;
  outline-offset: 2px;
}

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

.sr-only-focusable:focus,
.sr-only-focusable:active {
  position: static !important;
  width: auto !important;
  height: auto !important;
  overflow: visible !important;
  clip: auto !important;
  white-space: normal !important;
}

/* Enhanced Focus Indicators */
*:focus-visible {
  outline: 3px solid var(--brand, #25d463);
  outline-offset: 2px;
  border-radius: 4px;
}

button:focus-visible,
a:focus-visible,
[role="button"]:focus-visible,
[role="tab"]:focus-visible {
  outline: 3px solid #ffbb00;
  outline-offset: 2px;
}

/* Remove default focus for mouse users */
*:focus:not(:focus-visible) {
  outline: none;
}

/* High Contrast Focus for Interactive Elements */
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 3px solid var(--brand, #25d463);
  outline-offset: 2px;
  box-shadow: 0 0 0 6px rgba(37, 212, 99, 0.1);
}

/* Accessible Form Elements */
label.required::after {
  content: " *";
  color: #ff6b6b;
  font-weight: bold;
  aria-label: "required";
}

.form-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 16px;
}

.form-field label {
  font-weight: 600;
  font-size: 14px;
  color: var(--text, #b5c4be);
}

.help-text {
  font-size: 12px;
  color: var(--muted, #a8b8ad);
  margin-top: 2px;
}

.error-text {
  font-size: 12px;
  color: #ff6b6b;
  margin-top: 4px;
  display: flex;
  align-items: center;
  gap: 4px;
}

.error-text::before {
  content: "⚠";
  font-weight: bold;
}

input[aria-invalid="true"],
select[aria-invalid="true"],
textarea[aria-invalid="true"] {
  border-color: #ff6b6b !important;
  background: rgba(255, 107, 107, 0.05);
}

/* Accessible Buttons */
button:disabled,
[role="button"][aria-disabled="true"] {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

button:not(:disabled):hover,
[role="button"]:not([aria-disabled="true"]):hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

button:not(:disabled):active,
[role="button"]:not([aria-disabled="true"]):active {
  transform: translateY(0);
}

/* Accessible Data Tables */
table {
  border-collapse: collapse;
  width: 100%;
}

table caption {
  text-align: left;
  font-weight: 600;
  margin-bottom: 8px;
  padding: 8px;
}

th[scope="col"],
th[scope="row"] {
  font-weight: 600;
  text-align: left;
  background: rgba(255, 255, 255, 0.05);
}

th[aria-sort="ascending"]::after {
  content: " ▲";
  font-size: 10px;
  margin-left: 4px;
}

th[aria-sort="descending"]::after {
  content: " ▼";
  font-size: 10px;
  margin-left: 4px;
}

th[aria-sort="none"] {
  cursor: pointer;
}

th[aria-sort="none"]:hover {
  background: rgba(255, 255, 255, 0.1);
}

/* Accessible Tab Navigation */
[role="tablist"] {
  display: flex;
  gap: 8px;
  border-bottom: 2px solid #1f2a32;
  padding-bottom: 0;
}

[role="tab"] {
  position: relative;
  padding: 12px 16px;
  border: none;
  background: transparent;
  color: var(--muted, #a8b8ad);
  cursor: pointer;
  transition: all 0.2s ease;
  font-weight: 500;
}

[role="tab"][aria-selected="true"] {
  color: var(--brand, #25d463);
  font-weight: 600;
}

[role="tab"][aria-selected="true"]::after {
  content: "";
  position: absolute;
  bottom: -2px;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--brand, #25d463);
  border-radius: 3px 3px 0 0;
}

[role="tab"]:hover:not([aria-selected="true"]) {
  color: var(--text, #b5c4be);
  background: rgba(255, 255, 255, 0.05);
}

[role="tabpanel"] {
  padding: 20px 0;
}

[role="tabpanel"][aria-hidden="true"] {
  display: none;
}

/* Accessible Modals */
[role="dialog"],
[role="alertdialog"] {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: var(--card, #131a20);
  border: 1px solid #1f2a32;
  border-radius: 12px;
  padding: 30px;
  max-width: 90vw;
  max-height: 90vh;
  overflow-y: auto;
  z-index: 1000;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.3);
}

.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  z-index: 999;
}

/* Accessible Loading States */
[aria-busy="true"] {
  position: relative;
  pointer-events: none;
  opacity: 0.6;
}

[aria-busy="true"]::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 24px;
  height: 24px;
  border: 3px solid rgba(255, 255, 255, 0.3);
  border-top-color: var(--brand, #25d463);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: translate(-50%, -50%) rotate(360deg); }
}

/* Status Indicators */
[role="status"],
[role="alert"] {
  padding: 12px;
  border-radius: 6px;
  margin: 8px 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

[role="status"] {
  background: rgba(29, 185, 84, 0.1);
  border-left: 3px solid var(--brand, #25d463);
  color: var(--brand, #25d463);
}

[role="alert"] {
  background: rgba(255, 107, 107, 0.1);
  border-left: 3px solid #ff6b6b;
  color: #ff6b6b;
}

/* Accessible Tooltips */
[aria-describedby][data-tooltip] {
  position: relative;
}

[aria-describedby][data-tooltip]:hover::after,
[aria-describedby][data-tooltip]:focus::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  background: #2a3942;
  color: white;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 12px;
  white-space: nowrap;
  margin-bottom: 8px;
  z-index: 1000;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

/* High Contrast Mode Support (Windows) */
@media (prefers-contrast: high) {
  * {
    border-color: currentColor !important;
  }

  button,
  [role="button"] {
    border: 2px solid currentColor !important;
  }

  *:focus-visible {
    outline: 3px solid currentColor !important;
    outline-offset: 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;
  }
}

/* Print Styles for Accessibility */
@media print {
  .skip-link,
  [role="navigation"],
  button,
  [role="button"] {
    display: none !important;
  }

  a[href]::after {
    content: " (" attr(href) ")";
    font-size: 12px;
    color: #666;
  }

  [aria-hidden="true"] {
    display: none !important;
  }
}

/* Touch Target Size (44x44px minimum) */
@media (pointer: coarse) {
  button,
  [role="button"],
  [role="tab"],
  a {
    min-height: 44px;
    min-width: 44px;
    padding: 12px 16px;
  }

  input[type="checkbox"],
  input[type="radio"] {
    width: 24px;
    height: 24px;
  }
}

/* Landmark Region Highlighting (for debugging) */
[role="banner"],
[role="navigation"],
[role="main"],
[role="complementary"],
[role="contentinfo"] {
  /* Uncomment below for visual debugging */
  /* border: 2px dashed rgba(29, 185, 84, 0.3); */
  /* outline: 1px solid rgba(29, 185, 84, 0.5); */
}

/* ARIA Live Region Styles (Screen Reader Announcements Only) */
.sr-only[aria-live],
#aria-live-announcer,
#aria-live-assertive {
  /* Ensure live regions are positioned correctly for screen readers only */
  position: absolute;
  left: -10000px;
  width: 1px;
  height: 1px;
  overflow: hidden;
}

/* Accessible Badge/Chip */
.badge[role="status"] {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
  background: rgba(255, 255, 255, 0.1);
}

/* Accessible Progress Indicators */
progress[role="progressbar"] {
  width: 100%;
  height: 8px;
  border: none;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.1);
}

progress[role="progressbar"]::-webkit-progress-bar {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 4px;
}

progress[role="progressbar"]::-webkit-progress-value {
  background: var(--brand, #25d463);
  border-radius: 4px;
}

progress[role="progressbar"]::-moz-progress-bar {
  background: var(--brand, #25d463);
  border-radius: 4px;
}

/* Custom Checkbox/Radio Accessibility */
input[type="checkbox"],
input[type="radio"] {
  position: relative;
  width: 20px;
  height: 20px;
  appearance: none;
  border: 2px solid var(--muted, #a8b8ad);
  border-radius: 4px;
  background: var(--card, #131a20);
  cursor: pointer;
  transition: all 0.2s ease;
}

input[type="radio"] {
  border-radius: 50%;
}

input[type="checkbox"]:checked,
input[type="radio"]:checked {
  background: var(--brand, #25d463);
  border-color: var(--brand, #25d463);
}

input[type="checkbox"]:checked::after {
  content: "✓";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: white;
  font-size: 14px;
  font-weight: bold;
}

input[type="radio"]:checked::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: white;
}

input[type="checkbox"]:focus-visible,
input[type="radio"]:focus-visible {
  outline: 3px solid var(--brand, #25d463);
  outline-offset: 2px;
}

/* Accessible Disclosure Widget (Accordion) */
[aria-expanded] {
  cursor: pointer;
  user-select: none;
}

[aria-expanded]::before {
  content: "▶";
  display: inline-block;
  margin-right: 8px;
  transition: transform 0.2s ease;
  font-size: 10px;
}

[aria-expanded="true"]::before {
  transform: rotate(90deg);
}

[aria-hidden="true"] {
  display: none;
}

/* Color Contrast Enhancements */
:root {
  /* Updated colors for WCAG AA compliance */
  --text-contrast: #b5c4be; /* 5.2:1 on #0f1418 */
  --muted-contrast: #a8b8ad; /* 4.6:1 on #131a20 */
  --brand-contrast: #25d463; /* 4.7:1 on #0f1418 */
  --warn-contrast: #d4a500; /* 5.1:1 on #0f1418 */
  --error-contrast: #ff6b6b; /* 5.8:1 on #0f1418 */
}
