/* Spinner animation */
.spinner {
  border: 4px solid rgba(0, 0, 0, 0.1);
  border-left-color: #3b82f6;
  border-radius: 50%;
  width: 48px;
  height: 48px;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Accessibility improvements */
.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;
}

:focus {
  outline: 1.5px solid #2563eb;
  outline-offset: 0;
  box-shadow: 0 0 0 2px #bfdbfe;
}

textarea:focus, input:focus {
  border-color: #2563eb;
  outline: none;
  box-shadow: 0 0 0 2px #bfdbfe;
}

.skip-link {
  position: absolute;
  top: 8px;
  left: -9999px;
  background-color: #000000;
  color: #ffffff;
  padding: 8px 12px;
  z-index: 100;
  transition: left 0.12s ease-in, box-shadow 0.12s ease;
  border-radius: 6px;
  font-weight: 600;
  box-shadow: 0 2px 6px rgba(0,0,0,0.15);
  border: 2px solid rgba(255,255,255,0.06);
  aria-hidden: true;
}

.skip-link:focus,
.skip-link:focus-visible {
  left: 8px;
  outline: none;
  box-shadow: 0 0 0 4px rgba(59,130,246,0.28);
  aria-hidden: false;
}

/* Adapt for dark theme: use bright background + dark text for best contrast */
[data-theme="dark"] .skip-link {
  background-color: #fbbf24; /* amber-400 */
  color: #0b1220; /* near-black text */
  border-color: rgba(0,0,0,0.12);
}

.dcforms-group-border {
    border: 2px solid #999ca1;
    border-radius: 0.5rem;
    padding: 1rem;
    margin-bottom: 1rem;
    background: #f8fafc;
}

[data-theme="dark"] .dcforms-group-border {
    border-color: #60a5fa;
    background: #23272f;
}

/* Submit button styles - consistent contrast for all modes */
button[type="submit"], .hover\:bg-blue-800:hover, .dark .hover\:bg-blue-700:hover {
  background-color: #1d4ed8 !important; /* blue-700 */
  color: #ffffff !important;
}

.dark button[type="submit"], [data-theme="dark"] button[type="submit"] {
  background-color: #1d4ed8 !important; /* blue-700 for dark mode */
  color: #ffffff !important;
}

/* High contrast mode support */
@media (forced-colors: active) {
  .border-red-500 {
    outline: 3px solid CanvasText;
  }
  button[type="submit"], .hover\:bg-blue-800:hover, .dark .hover\:bg-blue-700:hover {
    forced-color-adjust: none;
    /* Ensure minimum 4.5:1 contrast ratio for WCAG 2.2 AA */
    background-color: #1d4ed8 !important; /* blue-700 */
    color: #ffffff !important;
  }
  .dark button[type="submit"] {
    background-color: #1d4ed8 !important; /* blue-700 for dark mode */
  }
}

[data-theme="dark"] {
  --bg-main: #1a1a1a;
  --bg-surface: #2d2d2d;
  --color-text: #e0e0e0;
  --color-border: #555555;
  --bg-hover: #444444;
  --bg-selected: #2c3a54;
  --color-placeholder: #555555;
}

body[data-theme="dark"], [data-theme="dark"] body {
  background-color: var(--bg-main) !important;
  color: var(--color-text) !important;
}

[data-theme="dark"] .bg-white {
  background-color: #222 !important;
  color: #e0e0e0 !important;
}

[data-theme="dark"] .text-gray-700, [data-theme="dark"] .text-gray-600 {
  color: #c0c0c0 !important;
}

[data-theme="dark"] .border {
  border-color: #555 !important;
}

[data-theme="dark"] .bg-gray-100 {
  background-color: #181e24 !important;
}

[data-theme="dark"] .bg-gray-50 {
  background-color: #23272f !important;
}

[data-theme="dark"] .bg-blue-500 {
  background-color: #2563eb !important;
}

[data-theme="dark"] .bg-red-100 {
  background-color: #3b1e1e !important;
}

[data-theme="dark"] .text-red-700 {
  color: #ffb4b4 !important;
}

[data-theme="dark"] .text-green-500 {
  color: #6ee7b7 !important;
}

[data-theme="dark"] .bg-blue-500 {
  background-color: #3b82f6 !important;
}

[data-theme="dark"] .bg-blue-600:hover {
  background-color: #2563eb !important;
}

[data-theme="dark"] .bg-blue-600:hover {
  background-color: #1d4ed8 !important;
}

[data-theme="dark"] input,
[data-theme="dark"] textarea,
[data-theme="dark"] select {
  background-color: #23272f !important;
  color: #e0e0e0 !important;
  border-color: #555 !important;
}

[data-theme="dark"] input::placeholder,
[data-theme="dark"] textarea::placeholder {
  color: #888 !important;
}

.section-title {
  background-color: #DDDEDF;
  color: #111;
}

[data-theme="dark"] .section-title {
  background-color: #57595B !important;
  color: #fff !important;
}

/* Show placeholders by default, hide when help is active */
.dcforms-placeholder {
  font-size: 0.8em;
  margin-top: 0.0em;
  margin-bottom: 0.0em;
  padding-top: 0.0em;
  padding-left: 0.0em;
  color: #374151; /* WCAG AA compliant gray-700 for light mode */
  pointer-events: none;
  transition: opacity 0.2s;
  position: relative;
  z-index: 1;
  display: block;
  font-weight: 500; /* Slightly bolder for better readability */
}

/* Hide placeholders when help is active */
body.show-help .dcforms-placeholder {
  display: none !important;
}

/* Dark theme placeholder with WCAG AA compliance */
[data-theme="dark"] .dcforms-placeholder {
  color: #d1d5db !important; /* WCAG AA compliant gray-300 for dark mode */
}

[data-theme="dark"] body.show-help .dcforms-placeholder {
  color: #fbbf24 !important; /* Higher contrast yellow for dark mode */
}

input.dcforms-has-placeholder, textarea.dcforms-has-placeholder {
  padding-bottom: 4px !important;
}

.text-required-asterisk {
  color: #b91c1c; /* High contrast red for WCAG 2.2 AA compliance */
}

[data-theme="dark"] .text-required-asterisk {
  color: #fca5a5 !important; /* High contrast light red for dark mode */
}

/* Print button styles */
#print-btn2 {
  position: fixed;
  top: 4rem;
  right: 1rem;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  background-color: #e5e7eb; /* Tailwind bg-gray-200 */
  color: #1f2937;            /* Tailwind text-gray-800 */
  border-radius: 9999px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  transition: all 0.2s ease;
}

[data-theme="dark"] #print-btn2 {
  background-color: #374151; /* Tailwind dark:bg-gray-700 */
  color: #e5e7eb;            /* Tailwind dark:text-gray-200 */
}

#print-btn2:hover {
  background-color: #d1d5db; /* Tailwind hover:bg-gray-300 */
}

[data-theme="dark"] #print-btn2:hover {
  background-color: #4b5563; /* Tailwind dark:hover:bg-gray-600 */
}

/* Hide help text by default, show when .show-help is on body */
.dcforms-help {
  display: none;
  color: #92400e; /* WCAG AA compliant amber-800 for light mode */
  font-size: 0.9em;
  margin-top: 0.25rem;
  font-weight: 500; /* Slightly bolder for better readability */
}

body.show-help .dcforms-help {
  display: block;
}

/* Dark theme help text with WCAG AA compliance */
[data-theme="dark"] .dcforms-help {
  color: #fbbf24 !important; /* WCAG AA compliant yellow-400 for dark mode */
}

/* Dark theme dropdown styles */
[data-theme="dark"] #share-dropdown,
[data-theme="dark"] #language-dropdown {
  background-color: #374151 !important; /* gray-700 */
  border-color: #4b5563 !important; /* gray-600 */
}

[data-theme="dark"] #share-dropdown a,
[data-theme="dark"] #language-dropdown a {
  color: #e5e7eb !important; /* gray-200 */
}

[data-theme="dark"] #share-dropdown a:hover,
[data-theme="dark"] #language-dropdown a:hover {
  background-color: #4b5563 !important; /* gray-600 */
}

/* Footer catalog link - improved contrast in dark mode */
[data-theme="dark"] #catalog-link {
  color: #60a5fa !important; /* blue-400 for better contrast on dark backgrounds */
}

/* Submit Another button styling - match primary submit button contrast */
.bg-blue-500 {
  background-color: #1d4ed8 !important; /* blue-700 for WCAG compliance */
  color: #ffffff !important;
}

.hover\:bg-blue-600:hover {
  background-color: #1d4ed8 !important; /* blue-700 on hover */
}

[data-theme="dark"] .bg-blue-500,
[data-theme="dark"] .hover\:bg-blue-600:hover {
  background-color: #1d4ed8 !important; /* blue-700 in dark mode */
  color: #ffffff !important;
}

/* Print styles */
@media print {
  body {
    background-color: white !important;
    color: black !important;
  }

  /* Fix: Remove centering for print layout */
  .flex.justify-center.items-center.min-h-screen {
    justify-content: flex-start !important;
    align-items: flex-start !important;
    min-height: auto !important;
    padding-top: 0 !important;
    margin-top: 0 !important;
  }

  #theme-toggle, #print-btn, .skip-link, footer, button[type="submit"], 
  #language-selector, a[id^="lang-"], [class*="Version"] {
    display: none !important;
  }

  .form-print-view {
    padding: 0 !important;
    margin: 0 !important;
    width: 100% !important;
  }

  .form-print-header {
    margin-bottom: 1.5rem;
  }

  .print-logo-container {
    display: block !important;
    visibility: visible !important;
  }

  .print-logo-container img {
    display: block !important;
    visibility: visible !important;
    max-width: 100% !important;
    height: auto !important;
  }

  .print-header-logo-group {
    display: flex !important;
    visibility: visible !important;
  }

  /* Ensure all images in print header are visible */
  .form-print-header img {
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
    max-width: none !important;
    width: auto !important;
    height: auto !important;
  }

  /* Force logo images to be visible regardless of classes */
  img[src*="Dakota"], img[src*="logo"], img[alt*="logo"] {
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
  }

  /* Ensure h-20 class works properly on images in print */
  img.h-20 {
    height: 5rem !important;
    width: auto !important;
    display: block !important;
    max-width: none !important;
  }

  .form-print-field {
    margin-bottom: 1rem;
    page-break-inside: avoid;
  }

  .form-print-label {
    font-weight: 600;
    margin-bottom: 0.25rem;
  }

  .form-print-value {
    min-height: 1.5rem;
    margin-bottom: 0.2rem;
  }

  .form-print-line {
    display: block;
    height: 1px;
    width: 100%;
    background-color: #000;
    border-bottom: 1px solid #000;
    margin: 0;
  }

  .form-print-help {
    font-style: italic;
    font-size: 0.8em;
    color: #666;
    margin-top: 0.25rem;
  }

  .form-print-row {
    display: flex !important;
    flex-wrap: wrap !important;
    gap: 1.5rem !important;
    margin-bottom: 1rem !important; 
    width: 100% !important;
  }

  .form-print-column {
    min-width: 120px !important;
    flex: 1 1 calc(50% - 0.75rem) !important;
    display: block !important;
  }

  .form-print-group {
    margin-bottom: 1.5rem;
    page-break-inside: avoid;
  }

  .checkbox-container-horizontal,
  .radio-container-horizontal {
    display: flex !important;
    gap: 1rem !important;
    flex-wrap: wrap !important;
    margin-bottom: 0.5rem !important;
  }

  .checkbox-container-vertical,
  .radio-container-vertical {
    display: flex !important;
    flex-direction: column !important;
    gap: 0.5rem !important;
    margin-bottom: 0.5rem !important;
  }

  .form-print-checkbox-option,
  .form-print-radio-option {
    display: inline-flex !important;
    align-items: center !important;
    gap: 0.5rem !important;
  }

  .form-print-footer {
    margin-top: 2rem;
    text-align: right;
    font-size: 0.75rem;
    color: #666;
  }

  /* Print: preserve CSS Grid column layout */
  .dcforms-grid {
    display: grid !important;
    gap: 0.5rem 0.75rem !important;
    align-items: start !important;
  }
  .dcforms-grid[data-columns="1"] {
    grid-template-columns: 1fr !important;
  }
  .dcforms-grid[data-columns="2"] {
    grid-template-columns: repeat(2, 1fr) !important;
  }
  .dcforms-grid[data-columns="3"] {
    grid-template-columns: repeat(3, 1fr) !important;
  }
  .dcforms-grid[data-columns="4"] {
    grid-template-columns: repeat(4, 1fr) !important;
  }
  .dcforms-field-full {
    grid-column: 1 / -1 !important;
  }
}

/* Transition effects */
body,
.bg-white,
.bg-gray-50,
.bg-gray-100,
.bg-gray-800,
.text-gray-700,
.text-gray-600,
.text-gray-300,
.border {
    transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease;
}

/* Additional transitions for specific elements */
.design-component,
.toolbox-item,
.properties-panel,
#form-selection-modal > div {
    transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease;
}

/* Fade effect for the entire page during theme switching */
html {
    transition: opacity 0.2s ease;
}

/* Optional: Smooth transition for the theme toggle button itself */
#theme-toggle {
    transition: all 0.3s ease;
}

/* Icons-only on mobile for Share/Lang buttons */
@media (max-width: 639.98px) {
  #share-toggle .btn-label,
  #language-toggle .btn-label,
  #share-toggle #share-arrow,
  #language-toggle #language-arrow {
    display: none !important;
  }
  #share-toggle i:first-child,
  #language-toggle i:first-child {
    margin-right: 0 !important;
  }
  
  /* Also hide text on Dim and Help buttons on mobile */
  #theme-toggle-label,
  #help-toggle-label {
    display: none !important;
  }
  #theme-toggle-icon,
  #help-toggle-btn i:first-child {
    margin-right: 0 !important;
  }

  /* Mobile: revert CSS Grid to single-column stacked layout */
  .dcforms-grid {
    display: block !important;
  }
  .dcforms-grid > * {
    margin-bottom: 0.5rem;
  }
  .dcforms-field-full {
    grid-column: unset !important;
  }
}

/* Checkbox and radio button styling */
input[type="checkbox"],
input[type="radio"] {
    width: 20px !important;
    height: 20px !important;
    margin: 2px;
    margin-right: 6px;
    position: relative;
    cursor: pointer;
}

input[type="checkbox"]::before,
input[type="radio"]::before {
    content: '';
    position: absolute;
    top: -4px;
    left: -4px;
    right: -4px;
    bottom: -4px;
    z-index: -1;
}
