/*!
 * Operaton DMN Frontend Styles - Fixed Button Styling
 *
 * Updated to match Gravity Forms Next button styling exactly
 *
 * @package OperatonDMN
 * @version 1.0.0-beta.10.1
 */

/* CSS Custom Properties that will inherit from Gravity Forms */
:root {
  --operaton-frontend-transition: 0.2s ease;
  --operaton-frontend-font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen-Sans, Ubuntu, Cantarell,
    'Helvetica Neue', sans-serif;
}

/* =============================================================================
   EVALUATION BUTTON - INHERIT FROM GRAVITY FORMS
   ============================================================================= */

.operaton-evaluate-btn {
  /* Reset any conflicting styles first */
  all: unset;

  /* Core display properties */
  display: inline-block !important;
  box-sizing: border-box !important;

  /* Let JavaScript copy styles from Next button */
  /* This ensures perfect matching with the current theme */

  /* Only set essential properties that shouldn't be overridden */
  cursor: pointer !important;
  text-decoration: none !important;
  text-align: center !important;
  vertical-align: middle !important;

  /* Minimal styling - let GF theme handle the rest */
  transition: all var(--operaton-frontend-transition) !important;

  /* Ensure it doesn't break layout */
  margin-left: 10px !important;

  /* Prevent text selection */
  user-select: none !important;
  -webkit-user-select: none !important;
  -moz-user-select: none !important;
  -ms-user-select: none !important;
}

/* Additional class when styled by JavaScript */
.operaton-evaluate-btn.operaton-styled {
  /* JavaScript will have copied all the relevant styles */
  /* Just ensure some base properties are maintained */
  font-family: inherit !important;
  outline: none !important;
  border-style: solid !important;
}

/* =============================================================================
   BUTTON STATES
   ============================================================================= */

/* Loading state */
.operaton-evaluate-btn.loading {
  position: relative !important;
  pointer-events: none !important;
  opacity: 0.8 !important;
}

.operaton-evaluate-btn.loading::after {
  content: '' !important;
  position: absolute !important;
  top: 50% !important;
  left: 50% !important;
  width: 16px !important;
  height: 16px !important;
  margin: -8px 0 0 -8px !important;
  border: 2px solid transparent !important;
  border-top: 2px solid currentColor !important;
  border-radius: 50% !important;
  animation: operaton-spin 1s linear infinite !important;
}

/* Success state */
.operaton-evaluate-btn.success {
  /* Maintain the same styling but with subtle success indication */
  box-shadow: 0 0 0 2px rgba(40, 167, 69, 0.3) !important;
}

/* Error state */
.operaton-evaluate-btn.error {
  /* Maintain the same styling but with subtle error indication */
  box-shadow: 0 0 0 2px rgba(220, 53, 69, 0.3) !important;
}

/* Disabled state */
.operaton-evaluate-btn.disabled,
.operaton-evaluate-btn:disabled {
  opacity: 0.6 !important;
  cursor: not-allowed !important;
  pointer-events: none !important;
}

/* =============================================================================
   GRAVITY FORMS INTEGRATION
   ============================================================================= */

/* Ensure the button container has proper flex layout */
.gform_footer .gform_button_wrapper {
  display: flex !important;
  align-items: center !important;
  gap: 10px !important;
  flex-wrap: wrap !important;
}

/* Make sure all buttons in the footer align properly */
.gform_wrapper .gform_footer input[type='submit'],
.gform_wrapper .gform_footer input[type='button'],
.gform_wrapper .gform_footer .operaton-evaluate-btn,
.gform_wrapper .gform_prev_button input,
.gform_wrapper .gform_next_button input {
  vertical-align: middle !important;
  margin: 0 !important;
  flex-shrink: 0 !important;
}

/* Specific adjustments for button containers */
.gform_wrapper .gform_footer .gform_prev_button,
.gform_wrapper .gform_footer .gform_next_button {
  display: inline-block !important;
  margin: 0 !important;
}

/* =============================================================================
   THEME COMPATIBILITY OVERRIDES
   ============================================================================= */

/* Ensure compatibility with all Gravity Forms themes */
.gform_wrapper .operaton-evaluate-btn,
.gform_wrapper.gravity-theme .operaton-evaluate-btn,
.gform_wrapper.gf_browser_chrome .operaton-evaluate-btn,
.gform_wrapper.gf_browser_safari .operaton-evaluate-btn {
  /* Let JavaScript handle the styling to match exactly */
  font-family: inherit !important;
  line-height: inherit !important;
}

/* Orbital theme specific adjustments */
.gform_wrapper.gf-orbital-theme .operaton-evaluate-btn {
  /* Orbital theme uses CSS custom properties */
  background: var(--gf-color-primary, #204ce5) !important;
  border-color: var(--gf-color-primary, #204ce5) !important;
  color: var(--gf-color-primary-contrast, #ffffff) !important;
}

.gform_wrapper.gf-orbital-theme .operaton-evaluate-btn:hover:not(.disabled) {
  background: var(--gf-color-primary-darker, #1a3bb8) !important;
  border-color: var(--gf-color-primary-darker, #1a3bb8) !important;
}

/* Legacy theme fallback */
.gform_wrapper.gform_legacy_markup .operaton-evaluate-btn {
  display: inline-block !important;
  background: #0073aa !important;
  border: 1px solid #0073aa !important;
  color: #ffffff !important;
  padding: 8px 16px !important;
  border-radius: 3px !important;
}

/* =============================================================================
   RESULT DISPLAY CONTAINERS
   ============================================================================= */

.operaton-result {
  display: block;
  margin: 20px 0;
  padding: 16px;
  background-color: #f8f9fa;
  border: 1px solid #dee2e6;
  border-radius: 6px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  font-family: var(--operaton-frontend-font);
  animation: fadeIn 0.3s ease-in;
}

.operaton-result h4 {
  margin: 0 0 8px 0 !important;
  font-size: 1.1em !important;
  color: #495057 !important;
  font-weight: 600 !important;
}

.operaton-result .result-content {
  margin: 0 !important;
  font-weight: 600 !important;
  color: #28a745 !important;
  font-size: 1.05em !important;
  word-wrap: break-word;
}

.operaton-result p {
  margin: 0 !important;
}

/* =============================================================================
   MESSAGE STYLING
   ============================================================================= */

.operaton-message {
  padding: 12px 16px;
  margin: 15px 0;
  border-radius: 6px;
  font-weight: 500;
  font-size: 14px;
  border-left: 4px solid;
  animation: slideInDown 0.3s ease;
}

.operaton-message-success {
  background-color: #d4edda;
  color: #155724;
  border-left-color: #28a745;
}

.operaton-message-error {
  background-color: #f8d7da;
  color: #721c24;
  border-left-color: #dc3545;
}

.operaton-message-warning {
  background-color: #fff3cd;
  color: #856404;
  border-left-color: #ffc107;
}

/* =============================================================================
   ANIMATIONS
   ============================================================================= */

@keyframes operaton-spin {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes slideInDown {
  from {
    opacity: 0;
    transform: translateY(-20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* =============================================================================
   RESPONSIVE DESIGN
   ============================================================================= */

@media (max-width: 768px) {
  /* Mobile button layout */
  .gform_footer .gform_button_wrapper {
    flex-direction: column !important;
    align-items: stretch !important;
  }

  .operaton-evaluate-btn {
    display: block !important;
    width: 100% !important;
    margin: 10px 0 !important;
    text-align: center !important;
  }

  /* Result containers on mobile */
  .operaton-result {
    margin: 10px 0;
    padding: 12px;
  }

  .operaton-message {
    font-size: 13px;
    padding: 10px 14px;
  }
}

/* =============================================================================
   ACCESSIBILITY FEATURES
   ============================================================================= */

/* Focus management for keyboard navigation */
.operaton-evaluate-btn:focus-visible {
  outline: 2px solid #0073aa !important;
  outline-offset: 2px !important;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  .operaton-evaluate-btn {
    border-width: 2px !important;
  }

  .operaton-result {
    border-width: 2px !important;
  }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
  .operaton-evaluate-btn,
  .operaton-result,
  .operaton-message {
    animation: none !important;
    transition: none !important;
  }

  .operaton-evaluate-btn.loading::after {
    animation: none !important;
  }
}

/* =============================================================================
   PRINT STYLES
   ============================================================================= */

@media print {
  .operaton-evaluate-btn {
    display: none !important;
  }

  .operaton-result {
    border: 1px solid #000 !important;
    background: white !important;
    color: black !important;
    box-shadow: none !important;
    break-inside: avoid;
  }

  .operaton-message {
    border: 1px solid #000 !important;
    background: white !important;
    color: black !important;
  }
}

/* Add this to your frontend.css file */

/* CRITICAL FIX: Ensure buttons are hidden by default and only shown when explicitly needed */
.operaton-evaluate-btn {
  display: none !important;
}

.operaton-evaluate-btn, .decision-flow-summary {
    transition: opacity 0.2s ease;
}

/* Only show the button when explicitly made visible by JavaScript */
.operaton-evaluate-btn.operaton-show-button {
  display: inline-block !important;
}

/* Decision flow summary hidden by default */
.decision-flow-summary {
  display: none !important;
}

/* Only show decision flow when explicitly made visible */
.decision-flow-summary.operaton-show-summary {
  display: block !important;
}

/* Page-specific hiding rules for extra safety */
.gform_wrapper .gform_page:nth-child(3) .operaton-evaluate-btn {
  display: none !important;
}

/* Ensure proper spacing when elements are hidden */
.gform_wrapper .operaton-evaluate-btn + .decision-flow-summary {
  margin-top: 20px;
}

/* Loading state for decision flow */
.decision-flow-summary.loading {
  opacity: 0.7;
  pointer-events: none;
}

.decision-flow-summary.loading::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(255, 255, 255, 0.8);
  z-index: 1;
}
