/**
 * Styles
 *
 * All styles for the accessibility widget, panel, and applied accessibility modes.
 * Follows WCAG 2.1 AA standards for color contrast and spacing.
 */

/* ==========================================================================
   Widget & Toggle Button
   ========================================================================== */

.eawp-widget {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 999999;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

.eawp-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 64px;
  height: 64px;
  background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
  color: #ffffff;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(37, 99, 235, 0.4), 0 2px 8px rgba(0, 0, 0, 0.1);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.eawp-toggle:hover {
  background: linear-gradient(135deg, #1d4ed8 0%, #1e40af 100%);
  transform: scale(1.08) translateY(-2px);
  box-shadow: 0 12px 32px rgba(37, 99, 235, 0.5), 0 4px 12px rgba(0, 0, 0, 0.15);
}

.eawp-toggle:focus {
  outline: 3px solid #93c5fd;
  outline-offset: 3px;
}

.eawp-toggle svg {
  width: 34px;
  height: 34px;
  min-width: 34px;
  min-height: 34px;
  max-width: 34px;
  max-height: 34px;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.1));
  color: inherit;
}

/* ==========================================================================
   Accessibility Panel
   ========================================================================== */

.eawp-panel {
  position: fixed;
  z-index: 999998;
  bottom: 100px;
  right: 20px;
  width: 380px;
  max-width: calc(100vw - 40px);
  background: rgba(20, 20, 20, 0.98);
  border-radius: 16px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3), 0 0 1px rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.1);
  opacity: 0;
  visibility: hidden;
  transform: translateY(10px);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  backdrop-filter: blur(20px);
  filter: none;
}

.eawp-panel.eawp-light-mode {
  background: rgba(255, 255, 255, 0.98);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.08), 0 0 1px rgba(0, 0, 0, 0.1);
  border: 1px solid rgba(0, 0, 0, 0.05);
}

.eawp-panel.eawp-active {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.eawp-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  background: transparent;
  border-radius: 16px 16px 0 0;
}

.eawp-light-mode .eawp-panel-header {
  border-bottom: 1px solid rgba(0, 0, 0, 0.08);
}

.eawp-panel-header h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  color: #f9fafb !important;
  letter-spacing: -0.02em;
}

.eawp-light-mode .eawp-panel-header h2 {
  color: #111827 !important;
}

.eawp-header-buttons {
  display: flex;
  align-items: center;
  gap: 8px;
}

.eawp-close,
.eawp-theme-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  background: transparent !important;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  color: #f9fafb;
  transition: all 0.2s ease;
  padding: 0;
}

.eawp-close svg,
.eawp-theme-toggle svg {
  width: 20px;
  height: 20px;
  color: inherit;
  stroke: currentColor;
}

.eawp-close:hover,
.eawp-theme-toggle:hover {
  background: transparent;
  color: #ffffff;
  transform: scale(1.1);
}

.eawp-light-mode .eawp-close,
.eawp-light-mode .eawp-theme-toggle {
  color: #374151;
}

.eawp-light-mode .eawp-close:hover,
.eawp-light-mode .eawp-theme-toggle:hover {
  background: transparent;
  color: #111827;
}

.eawp-close:focus,
.eawp-theme-toggle:focus {
  outline: 2px solid #2563eb;
  outline-offset: 1px;
}

.eawp-panel-content {
  padding: 16px;
  max-height: 60vh;
  overflow-y: auto;
}

/* Two-column grid layout for tool buttons */
.eawp-tools-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0;
  margin-bottom: 12px;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.eawp-light-mode .eawp-tools-grid {
  border: 1px solid rgba(0, 0, 0, 0.08);
}

/* High contrast mode - ensure border remains visible */
html.eawp-contrast-high .eawp-panel,
html.eawp-contrast-high .eawp-tools-grid,
html.eawp-contrast-invert .eawp-tools-grid {
  border: 1px solid rgba(255, 255, 255, 0.3) !important;
}

html.eawp-contrast-high .eawp-light-mode.eawp-panel,
html.eawp-contrast-high .eawp-light-mode .eawp-tools-grid,
html.eawp-contrast-invert .eawp-light-mode .eawp-tools-grid {
  border: 1px solid rgba(0, 0, 0, 0.3) !important;
}

/* ==========================================================================
   Tool Buttons
   ========================================================================== */

.eawp-tool-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 20px 12px;
  margin-bottom: 0;
  background: transparent !important;
  border: none !important;
  border-right: 1px solid rgba(255, 255, 255, 0.08) !important;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08) !important;
  cursor: pointer;
  text-align: center;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  color: #d1d5db;
  font-size: 13px;
  font-weight: 600;
}

.eawp-tool-btn:nth-child(2n) {
  border-right: none;
}

.eawp-tool-btn:nth-last-child(-n+2) {
  border-bottom: none;
}

.eawp-tool-btn:hover {
  background: rgba(255, 255, 255, 0.03) !important;
}

.eawp-tool-btn:focus {
  background: rgba(37, 99, 235, 0.15) !important;
}

.eawp-tool-btn.eawp-active {
  background: rgba(37, 99, 235, 0.2) !important;
  color: #93c5fd !important;
}

.eawp-light-mode .eawp-tool-btn {
  color: #374151;
  background: transparent;
  border-right-color: rgba(0, 0, 0, 0.08) !important;
  border-bottom-color: rgba(0, 0, 0, 0.08) !important;
}

/* High contrast mode: increase border visibility for tool buttons */
html.eawp-contrast-high .eawp-tool-btn,
html.eawp-contrast-invert .eawp-tool-btn {
  border-right-color: rgba(255, 255, 255, 0.3) !important;
  border-bottom-color: rgba(255, 255, 255, 0.3) !important;
}

html.eawp-contrast-high .eawp-light-mode .eawp-tool-btn,
html.eawp-contrast-invert .eawp-light-mode .eawp-tool-btn {
  border-right-color: rgba(0, 0, 0, 0.3) !important;
  border-bottom-color: rgba(0, 0, 0, 0.3) !important;
}

.eawp-light-mode .eawp-tool-btn:hover {
  background: rgba(0, 0, 0, 0.03) !important;
}

.eawp-light-mode .eawp-tool-btn:focus {
  background: rgba(37, 99, 235, 0.08) !important;
}

.eawp-light-mode .eawp-tool-btn.eawp-active {
  background: rgba(37, 99, 235, 0.12) !important;
  color: #1d4ed8 !important;
}

.eawp-tool-btn svg {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  color: inherit;
}

.eawp-tool-label {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.eawp-mode-text {
  font-size: 11px;
  font-weight: 500;
  opacity: 0.7;
}

/* Reset Button - Higher specificity to override theme/WordPress styles */
.eawp-panel .eawp-panel-content .eawp-reset-btn,
.eawp-panel .eawp-panel-content button.eawp-reset-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 14px 16px;
  margin-top: 0;
  background: transparent;
  border: 1px solid rgba(239, 68, 68, 0.3);
  border-radius: 12px;
  cursor: pointer;
  color: #fca5a5;
  font-size: 14px;
  font-weight: 700;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.eawp-panel .eawp-panel-content .eawp-reset-btn:hover,
.eawp-panel .eawp-panel-content button.eawp-reset-btn:hover {
  background: rgba(127, 29, 29, 0.3);
  border-color: rgba(239, 68, 68, 0.4);
}

.eawp-panel .eawp-panel-content .eawp-reset-btn:focus,
.eawp-panel .eawp-panel-content button.eawp-reset-btn:focus {
  outline: none;
  background: rgba(127, 29, 29, 0.2);
  border-color: rgba(239, 68, 68, 0.5);
}

.eawp-light-mode .eawp-panel-content .eawp-reset-btn,
.eawp-light-mode .eawp-panel-content button.eawp-reset-btn {
  border: 1px solid rgba(239, 68, 68, 0.2);
  color: #991b1b;
}

.eawp-light-mode .eawp-panel-content .eawp-reset-btn:hover,
.eawp-light-mode .eawp-panel-content button.eawp-reset-btn:hover {
  background: rgba(254, 226, 226, 0.3);
  border-color: rgba(239, 68, 68, 0.3);
}

.eawp-light-mode .eawp-panel-content .eawp-reset-btn:focus,
.eawp-light-mode .eawp-panel-content button.eawp-reset-btn:focus {
  background: rgba(254, 226, 226, 0.2);
  border-color: rgba(239, 68, 68, 0.4);
}

/* ==========================================================================
   Accessibility Modes - Applied to <html> or <body>
   ========================================================================== */

/* --- Contrast Modes (applied to html) --- */

/* High Contrast Mode */
html.eawp-contrast-high {
  filter: contrast(150%);
}

/* Desaturate Mode */
html.eawp-contrast-desaturate {
  filter: saturate(0%);
}

/* Invert Colors Mode */
html.eawp-contrast-invert {
  filter: invert(100%) hue-rotate(180deg);
}

/* --- Color Shift Modes (applied to body to work with contrast) --- */

/* Protanopia (Red-Blind) - Yellow/Blue Scheme */
body.eawp-color-protanopia > *:not(.eawp-widget) {
  filter: sepia(0.4) saturate(1.2) hue-rotate(15deg);
}

/* Deuteranopia (Green-Blind) - Blue/Yellow Scheme */
body.eawp-color-deuteranopia > *:not(.eawp-widget) {
  filter: sepia(0.3) saturate(1.3) hue-rotate(340deg);
}

/* Tritanopia (Blue-Blind) - Red/Green Scheme */
body.eawp-color-tritanopia > *:not(.eawp-widget) {
  filter: sepia(0.3) saturate(1.4) hue-rotate(90deg);
}

/* Monochrome Mode */
body.eawp-color-monochrome > *:not(.eawp-widget) {
  filter: grayscale(100%);
}

/* --- Animation Control --- */

html.eawp-no-animation *,
html.eawp-no-animation *::before,
html.eawp-no-animation *::after {
  animation-duration: 0.01ms !important;
  animation-iteration-count: 1 !important;
  transition-duration: 0.01ms !important;
  scroll-behavior: auto !important;
}

/* --- Font Modes --- */
html.eawp-font-serif *:not(.eawp-widget):not(.eawp-widget *) {
  font-family: Georgia, "Times New Roman", Times, serif !important;
}

html.eawp-font-sans *:not(.eawp-widget):not(.eawp-widget *) {
  font-family: Arial, Helvetica, sans-serif !important;
}

html.eawp-font-dyslexic *:not(.eawp-widget):not(.eawp-widget *) {
  font-family: "OpenDyslexic", Arial, Helvetica, Verdana, sans-serif !important;
  font-weight: 500 !important;
  letter-spacing: 0.05em !important;
}

/* ==========================================================================
   Responsive Design
   ========================================================================== */

@media (max-width: 480px) {
  .eawp-widget {
    bottom: 16px;
    right: 16px;
  }

  .eawp-toggle {
    width: 56px;
    height: 56px;
  }

  .eawp-toggle svg {
    width: 28px;
    height: 28px;
  }

  .eawp-panel {
    bottom: 84px;
    right: 16px;
    width: calc(100vw - 32px);
  }

  .eawp-panel-header h2 {
    font-size: 17px;
  }

  .eawp-tool-btn {
    padding: 14px 10px;
    font-size: 12px;
  }

  .eawp-tool-btn svg {
    width: 20px;
    height: 20px;
  }
}

@media (max-height: 600px) {
  .eawp-panel-content {
    max-height: 50vh;
  }
}

/* ==========================================================================
   Print Styles
   ========================================================================== */

@media print {

  .eawp-widget,
  .eawp-panel {
    display: none !important;
  }
}

/* ==========================================================================
   Accessibility Enhancements
   ========================================================================== */

/* Ensure focus is visible for keyboard navigation */
*:focus-visible {
  outline: 2px solid #2563eb;
  outline-offset: 2px;
}

/* High contrast mode adjustments */
@media (prefers-contrast: high) {
  .eawp-toggle {
    border: 2px solid #ffffff;
  }

  .eawp-panel {
    border: 2px solid #000000;
  }
}

/* Reduced motion preference */
@media (prefers-reduced-motion: reduce) {

  .eawp-toggle,
  .eawp-panel,
  .eawp-tool-btn,
  .eawp-close,
  .eawp-reset-btn {
    transition: none;
  }
}

/* ==========================================================================
   Highlight Modes
   ========================================================================== */

/* Highlight Links */
html.eawp-highlight-links a:not(.eawp-panel *) {
  outline: 3px solid #f59e0b !important;
  outline-offset: 2px !important;
}

/* Highlight Headings */
html.eawp-highlight-headings h1:not(.eawp-panel *),
html.eawp-highlight-headings h2:not(.eawp-panel *),
html.eawp-highlight-headings h3:not(.eawp-panel *),
html.eawp-highlight-headings h4:not(.eawp-panel *),
html.eawp-highlight-headings h5:not(.eawp-panel *),
html.eawp-highlight-headings h6:not(.eawp-panel *) {
  outline: 3px solid #3b82f6 !important;
  outline-offset: 2px !important;
}

/* Highlight Buttons */
html.eawp-highlight-buttons button:not(.eawp-panel *),
html.eawp-highlight-buttons input[type="button"]:not(.eawp-panel *),
html.eawp-highlight-buttons input[type="submit"]:not(.eawp-panel *),
html.eawp-highlight-buttons input[type="reset"]:not(.eawp-panel *),
html.eawp-highlight-buttons .wp-block-button__link:not(.eawp-panel *),
html.eawp-highlight-buttons a.button:not(.eawp-panel *) {
  outline: 3px solid #10b981 !important;
  outline-offset: 2px !important;
}

/* Highlight All */
html.eawp-highlight-all a:not(.eawp-panel *) {
  outline: 3px solid #f59e0b !important;
  outline-offset: 2px !important;
}

html.eawp-highlight-all h1:not(.eawp-panel *),
html.eawp-highlight-all h2:not(.eawp-panel *),
html.eawp-highlight-all h3:not(.eawp-panel *),
html.eawp-highlight-all h4:not(.eawp-panel *),
html.eawp-highlight-all h5:not(.eawp-panel *),
html.eawp-highlight-all h6:not(.eawp-panel *) {
  outline: 3px solid #3b82f6 !important;
  outline-offset: 2px !important;
}

html.eawp-highlight-all button:not(.eawp-panel *),
html.eawp-highlight-all input[type="button"]:not(.eawp-panel *),
html.eawp-highlight-all input[type="submit"]:not(.eawp-panel *),
html.eawp-highlight-all input[type="reset"]:not(.eawp-panel *),
html.eawp-highlight-all .wp-block-button__link:not(.eawp-panel *),
html.eawp-highlight-all a.button:not(.eawp-panel *) {
  outline: 3px solid #10b981 !important;
  outline-offset: 2px !important;
}

/* ==========================================================================
   Text Width Limiting (WCAG Compliant)
   ========================================================================== */

/* Limit text width to ~65 characters per line for optimal readability */
body.eawp-text-width-limited p:not(.eawp-panel *),
body.eawp-text-width-limited h1:not(.eawp-panel *),
body.eawp-text-width-limited h2:not(.eawp-panel *),
body.eawp-text-width-limited h3:not(.eawp-panel *),
body.eawp-text-width-limited h4:not(.eawp-panel *),
body.eawp-text-width-limited h5:not(.eawp-panel *),
body.eawp-text-width-limited h6:not(.eawp-panel *),
body.eawp-text-width-limited li:not(.eawp-panel *) {
  max-width: 65ch !important;
}