/* ================================================================
   WCAG 2.2 Accessibility Improvements for Preview Page
   ================================================================ */

/* ===========================================
   Focus Indicators - WCAG 2.4.7 (Level AA)
   =========================================== */
*:focus-visible {
  outline: 3px solid #0066cc !important;
  outline-offset: 2px !important;
  z-index: 1;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[tabindex]:focus-visible {
  outline: 3px solid #0066cc !important;
  outline-offset: 2px !important;
}

/* Dark mode focus indicators */
@media (prefers-color-scheme: dark) {
  *:focus-visible {
    outline-color: #4da3ff !important;
  }
}

/* ===========================================
   Skip Navigation - WCAG 2.4.1 (Level A)
   =========================================== */
.skip-nav {
  position: absolute;
  left: -10000px;
  top: auto;
  width: 1px;
  height: 1px;
  overflow: hidden;
}

.skip-nav:focus {
  position: fixed;
  top: 10px;
  left: 10px;
  width: auto;
  height: auto;
  padding: 15px 20px;
  background: #000;
  color: #fff;
  z-index: 10000;
  text-decoration: none;
  border-radius: 4px;
  font-size: 16px;
  font-weight: 600;
}

/* ===========================================
   Touch Targets - WCAG 2.5.5 (Level AAA)
   =========================================== */
.action-link,
.share-option,
button:not(.btn-sm):not(.btn-xs),
a.btn:not(.btn-sm):not(.btn-xs),
input[type="checkbox"] + label,
input[type="radio"] + label {
  min-height: 44px;
  min-width: 44px;
  padding: 8px 12px;
}

/* Touch target spacing on mobile */
@media (max-width: 768px) {
  .action-link,
  .share-option {
    margin: 4px;
  }
}

/* ===========================================
   Screen Reader Only Content
   =========================================== */
.sr-only,
.visually-hidden:not(:focus):not(:active) {
  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;
}

/* ===========================================
   High Contrast Mode - WCAG 1.4.11 (Level AA)
   =========================================== */
@media (prefers-contrast: high) {
  .action-link,
  .share-option,
  .card,
  .border {
    border-width: 2px !important;
    border-color: currentColor !important;
  }

  button,
  .btn {
    border: 2px solid currentColor !important;
  }

  *:focus-visible {
    outline-width: 4px !important;
  }
}

/* ===========================================
   Reduced Motion - WCAG 2.3.3 (Level AAA)
   =========================================== */
@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;
  }

  .share-dropdown {
    animation: none !important;
  }
}

/* ===========================================
   Color Contrast Improvements
   =========================================== */
.text-muted {
  color: #595959 !important; /* Ensures 4.5:1 contrast ratio */
}

.badge.bg-secondary {
  background-color: #5a5a5a !important;
}

/* ===========================================
   Pure CSS Custom Radio Buttons
   =========================================== */
.custom-radio-icon {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2px solid #6c757d;
  border-radius: 50%;
  position: relative;
  background: white;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

/* Checked state - outer ring */
.size-option-header[aria-checked="true"] .custom-radio-icon,
.license-option-header[aria-checked="true"] .custom-radio-icon,
input[type="radio"]:checked + label .custom-radio-icon {
  border-color: #0066cc;
  background: white;
}

/* Checked state - inner dot */
.size-option-header[aria-checked="true"] .custom-radio-icon::after,
.license-option-header[aria-checked="true"] .custom-radio-icon::after,
input[type="radio"]:checked + label .custom-radio-icon::after {
  content: '';
  display: block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #0066cc;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  transition: all 0.2s ease;
}

/* Hover state */
.custom-radio-icon:hover,
.size-option-header:hover .custom-radio-icon,
.license-option-header:hover .custom-radio-icon {
  border-color: #0066cc;
  box-shadow: 0 0 0 2px rgba(0, 102, 204, 0.1);
}

/* Focus state */
.size-option-header:focus-visible .custom-radio-icon,
.license-option-header:focus-visible .custom-radio-icon {
  border-color: #0066cc;
  box-shadow: 0 0 0 3px rgba(0, 102, 204, 0.3);
}

/* Disabled state */
.custom-radio-icon:disabled,
.size-option-header[aria-disabled="true"] .custom-radio-icon,
.license-option-header[aria-disabled="true"] .custom-radio-icon {
  border-color: #555555;
  background: #f8f9fa;
  cursor: not-allowed;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  .custom-radio-icon {
    border-width: 3px;
  }

  .size-option-header[aria-checked="true"] .custom-radio-icon::after,
  .license-option-header[aria-checked="true"] .custom-radio-icon::after,
  input[type="radio"]:checked + label .custom-radio-icon::after {
    background: currentColor;
  }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
  .custom-radio-icon,
  .custom-radio-icon::after {
    transition: none;
  }
}

/* ===========================================
   Tooltip Button Accessibility
   =========================================== */
.license-tooltip-button.btn-link {
  border: none;
  background: none;
  color: inherit;
  text-decoration: none;
  min-height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: flex-start;
  border-radius: 6px;
  margin: -8px -8px -8px 0; /* Negative margins to offset the padding */
  padding: 8px;
  transition: background-color 0.15s ease;
}

.license-tooltip-button.btn-link:hover {
  background-color: rgba(0, 0, 0, 0.04);
  text-decoration: none;
}

.license-tooltip-button.btn-link:hover .fa-question-circle {
  color: #000000 !important;
}

.license-tooltip-button.btn-link:focus-visible {
  outline: 2px solid #0066cc;
  outline-offset: 2px;
  background-color: rgba(0, 102, 204, 0.08);
}

.license-tooltip-button.btn-link:active {
  background-color: rgba(0, 0, 0, 0.08);
}

/* Ensure the text styling is preserved */
.license-tooltip-button .fw-bold {
  font-weight: 600 !important;
}

.license-tooltip-button .text-muted {
  color: #6c757d !important;
}

.license-tooltip-button .text-dark {
  color: #343a40 !important;
}

/* ===========================================
   Form Control Accessibility
   =========================================== */
/* Radio group focus styling */
[role="radio"]:focus-visible {
  outline: 3px solid #0066cc !important;
  outline-offset: 2px !important;
  border-color: #0066cc !important;
}

[role="radio"][aria-checked="true"] {
  background-color: #f0f8ff;
  border-color: #0066cc !important;
}

[role="radio"][aria-checked="true"] .size-radio-icon,
[role="radio"][aria-checked="true"] .license-radio-icon {
  color: #0066cc !important;
}

/* ===========================================
   Form Control Accessibility
   =========================================== */
/* Make hidden radio buttons keyboard accessible */
input[type="radio"].visually-hidden-focusable {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

input[type="radio"].visually-hidden-focusable:focus + label {
  outline: 3px solid #0066cc;
  outline-offset: 2px;
}

/* Visual radio button indicators */
.size-radio-icon::before,
.license-radio-icon::before {
  content: "\f111"; /* Font Awesome circle */
  font-family: "Font Awesome 5 Free";
  font-weight: 400;
}

input[type="radio"]:checked + label .size-radio-icon::before,
input[type="radio"]:checked + label .license-radio-icon::before {
  content: "\f058"; /* Font Awesome check-circle */
  color: #0066cc;
}

/* ===========================================
   Mobile-First Responsive Improvements
   =========================================== */
/* Reorder content for mobile - Image first, then details */
@media (max-width: 991px) {
  #PreviewItemSpecsContainer {
    display: flex;
    flex-direction: column;
  }

  #PreviewItemContainer {
    order: 1;
  }

  #PreviewLicenseContainer {
    order: 2;
    padding-left: 0 !important;
    margin-top: 20px;
  }
}

/* Improve button stacking on mobile */
@media (max-width: 576px) {
  .cart-actions button,
  .quick-license-actions button,
  .custom-license button {
    width: 100%;
    margin-bottom: 10px;
  }

  /* Ensure proper spacing for touch targets */
  .image-actions-row {
    padding: 12px 0;
  }

  .image-actions-row .action-link {
    margin: 0 4px;
  }
}

/* ===========================================
   Landmark Regions - WCAG 2.4.1 (Level A)
   =========================================== */
main {
  display: block;
}

nav[role="navigation"],
header[role="banner"],
footer[role="contentinfo"] {
  display: block;
}

/* ===========================================
   Error State Indicators
   =========================================== */
.error,
.invalid {
  border-color: #A70606 !important;
  box-shadow: 0 0 0 0.2rem rgba(220, 53, 69, 0.25);
}

.error-message {
  color: #721c24;
  background-color: #f8d7da;
  border: 1px solid #f5c6cb;
  border-radius: 4px;
  padding: 8px 12px;
  margin-top: 4px;
  font-size: 14px;
}

/* ===========================================
   Loading States - WCAG 2.2.2 (Level A)
   =========================================== */
.loading {
  position: relative;
  pointer-events: none;
  opacity: 0.6;
}

.loading::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 20px;
  height: 20px;
  margin: -10px 0 0 -10px;
  border: 2px solid #0066cc;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spinner 0.6s linear infinite;
}

@keyframes spinner {
  to {
    transform: rotate(360deg);
  }
}

/* ===========================================
   Print Styles - Accessibility in Print
   =========================================== */
@media print {
  /* Ensure links are visible in print */
  a[href]:after {
    content: " (" attr(href) ")";
  }

  /* Hide non-essential elements */
  .share-button-wrapper,
  .action-link[title*="Download"],
  nav,
  footer {
    display: none !important;
  }

  /* Improve readability */
  body {
    font-size: 12pt;
    line-height: 1.5;
  }

  h1, h2, h3 {
    page-break-after: avoid;
  }
}

/* ===========================================
   RTL Support for International Users
   =========================================== */
[dir="rtl"] {
  .image-actions-row {
    direction: rtl;
  }

  .share-dropdown {
    left: auto;
    right: 0;
  }

  .action-link i,
  .share-option i {
    margin-left: 0.5rem;
    margin-right: 0;
  }
}

/* ===========================================
   Improved Mobile Navigation
   =========================================== */
@media (max-width: 768px) {
  /* Sticky action bar for mobile */
  .image-actions-row {
    position: sticky;
    bottom: 0;
    background: white;
    z-index: 100;
    padding: 12px;
    margin: 0;
    border-radius: 0;
  }

  /* Better mobile dropdown */
  .share-dropdown {
    bottom: 60px;
    top: auto;
  }
}

/* ===========================================
   Tablet Optimizations (768px - 991px)
   =========================================== */
@media (min-width: 768px) and (max-width: 991px) {
  #PreviewItemSpecsContainer {
    max-width: 100%;
    padding: 0 20px;
  }

  .preview-item-title {
    font-size: 1.5rem;
  }

  .license-options-card .card-body {
    padding: 1.25rem;
  }

  /* Two-column layout for action buttons */
  .image-actions-row {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }

  .share-button-wrapper {
    grid-column: span 2;
  }
}