/* ========================================
   CALCULATOR WIDGET STYLES
   ======================================== */

/* Main Container */
.calculator-container {
  display: flex;
  padding: 32px;
  flex-direction: column;
  align-items: center;
  gap: 32px;
  border-radius: 12px;
  background: var(--mystic-brand-yellow);
  position: relative;
  font-family: var(--mystic-font-family);
  max-width: 800px;
  margin: 0 auto;
  overflow: visible;
  box-sizing: border-box;
  word-wrap: break-word;
}

/* No Background State */
.calculator-container.no-background {
  background: transparent;
  border: 2px dashed var(--mystic-gray-300);
}

/* Ensure no background override works in Elementor editor */
.elementor-editor-active .calculator-container.no-background {
  background: transparent !important;
  border: none !important;
}

/* Auto-Flex Container */
.calculator-container.auto-flex {
  width: 100%;
  height: 100%;
  max-width: none;
  margin: 0;
  flex: 1;
  padding: clamp(12px, 3vw, 20px);
  gap: clamp(6px, 1.5vw, 12px);
  box-sizing: border-box;
  justify-content: space-between;
  min-height: 100%;
}

/* Auto-flex overrides for child elements */
.calculator-container.auto-flex .calculator-header {
  padding: 0;
  flex-shrink: 0;
}

.calculator-container.auto-flex .calculator-form {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-evenly;
  gap: clamp(6px, 1.5vw, 12px);
  min-height: 0;
}

.calculator-container.auto-flex .form-controls-wrapper {
  padding: 0;
}

.calculator-container.auto-flex .result-card {
  margin: 0;
}

.calculator-container.auto-flex .cta-buttons-grid {
  padding: 6px 0 0;
  flex-shrink: 0;
}

/* Background Toggle Button */
.background-toggle-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 50%;
  background: color-mix(in srgb, var(--mystic-bg-white) 90%, transparent);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  transition: all 0.2s ease;
  z-index: 50;
  box-shadow: 0 2px 4px var(--mystic-shadow-medium);
}

.background-toggle-btn:hover {
  background: var(--mystic-bg-white);
  transform: scale(1.1);
}

.background-toggle-btn:focus {
  outline: 2px solid var(--mystic-warning);
  outline-offset: 2px;
}

/* Header Section */
.calculator-header {
  display: flex;
  padding: 0 16px;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  align-self: stretch;
  text-align: center;
}

.calculator-title {
  color: var(--mystic-btn-primary-text);
  font-family: var(--mystic-font-family);
  font-size: 22px;
  font-style: normal;
  font-weight: 600;
  line-height: 120%;
  letter-spacing: -0.44px;
  margin: 0;
}

.calculator-subtitle {
  align-self: stretch;
  color: var(--mystic-yellow-800);
  text-align: center;
  font-family: var(--mystic-font-family);
  font-size: 16px;
  font-style: normal;
  font-weight: 400;
  line-height: 160%;
  margin: 0;
}

/* Form Section */
.calculator-form {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  align-self: stretch;
}

.form-controls-wrapper {
  display: flex;
  padding: 0 16px;
  flex-direction: column;
  align-items: flex-start;
  gap: 16px;
  align-self: stretch;
}

.form-group {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  align-self: stretch;
}

.form-label {
  align-self: stretch;
  color: var(--mystic-btn-primary-text);
  font-family: var(--mystic-font-family);
  font-size: 16px;
  font-style: normal;
  font-weight: 600;
  line-height: 160%;
  margin: 0;
}

.form-select-wrapper {
  position: relative;
  display: flex;
  align-self: stretch;
  z-index: 10;
}

.form-select {
  display: flex;
  min-height: 52px;
  padding: 12px 44px 12px 20px;
  justify-content: space-between;
  align-items: center;
  align-self: stretch;
  border-radius: 8px;
  border: 1px solid var(--mystic-yellow-200);
  background: var(--mystic-yellow-200);
  color: var(--mystic-btn-primary-text);
  font-family: var(--mystic-font-family);
  font-size: 16px;
  font-style: normal;
  font-weight: 400;
  line-height: 150%;
  letter-spacing: 0.16px;
  width: 100%;
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  cursor: pointer;
  box-sizing: border-box;
  position: relative;
  z-index: 1;
}

.form-select:focus {
  outline: 2px solid var(--mystic-warning);
  outline-offset: 2px;
}

.select-arrow {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
  width: 24px;
  height: 24px;
  z-index: 2;
}

/* Result Card */
.result-card {
  display: flex;
  padding: 24px;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 16px;
  align-self: stretch;
  border-radius: 8px;
  border: 1px solid var(--mystic-yellow-200);
  background: var(--mystic-yellow-200);
  margin: 0 16px;
  text-align: center;
}

.result-title {
  color: var(--mystic-btn-primary-text);
  font-family: var(--mystic-font-family);
  font-size: 12px;
  font-style: normal;
  font-weight: 600;
  line-height: 120%;
  letter-spacing: 0.24px;
  text-transform: uppercase;
  opacity: 0.7;
  margin: 0;
}

.result-amount {
  color: var(--mystic-btn-primary-text);
  font-family: var(--mystic-font-family);
  font-size: 28px;
  font-style: normal;
  font-weight: 500;
  line-height: 120%;
  letter-spacing: -0.84px;
  margin: 0;
  transition: opacity 0.15s ease;
}

.result-disclaimer {
  align-self: stretch;
  color: var(--mystic-btn-primary-text);
  text-align: center;
  font-family: var(--mystic-font-family);
  font-size: 14px;
  font-style: normal;
  font-weight: 400;
  line-height: 150%;
  margin: 0;
}

/* CTA Buttons Grid */
.cta-buttons-grid {
  display: flex;
  padding: 0 16px 32px 16px;
  flex-direction: column;
  align-items: flex-start;
  gap: 12px;
  align-self: stretch;
}

.cta-button {
  display: flex;
  min-height: 52px;
  padding: 12px 20px;
  justify-content: center;
  align-items: center;
  gap: 8px;
  align-self: stretch;
  border-radius: 8px;
  background: var(--mystic-brand-yellow-alt);
  text-decoration: none;
  transition:
    background-color 0.2s ease,
    transform 0.1s ease;
  box-sizing: border-box;

  color: var(--mystic-warning);
  font-family: var(--mystic-font-family);
  font-size: 16px;
  font-style: normal;
  font-weight: 600;
  line-height: 150%;
}

.cta-button:hover {
  background: var(--mystic-yellow-100);
  transform: translateY(-1px);
  text-decoration: none;
  color: var(--mystic-warning);
}

.cta-button:focus {
  outline: 2px solid var(--mystic-warning);
  outline-offset: 2px;
}

.cta-button:active {
  transform: translateY(0);
}

.cta-button span {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 1;
  line-clamp: 1;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ========================================
   RESPONSIVE STYLES
   ======================================== */

/* Mobile Styles */
@media (max-width: 767px) {
  .form-select {
    font-size: 16px; /* Prevents zoom on iOS */
    -webkit-appearance: menulist;
    -moz-appearance: menulist;
    appearance: menulist;
    position: relative;
    z-index: 1000;
  }

  .form-select:focus {
    z-index: 1001;
  }

  .form-select-wrapper {
    position: relative;
    z-index: 100;
    isolation: isolate;
  }

  .calculator-container {
    overflow: visible;
    position: relative;
    z-index: 1;
    isolation: isolate;
  }

  .form-controls-wrapper {
    position: relative;
    z-index: 10;
    overflow: visible;
  }

  .calculator-form {
    overflow: visible;
    position: relative;
    z-index: 5;
  }

  .result-card {
    position: relative;
    z-index: 1;
  }

  /* Ensure dropdown options appear above other elements */
  .form-select option {
    background: var(--mystic-yellow-200);
    color: var(--mystic-btn-primary-text);
  }

  /* Adjust arrow position for mobile */
  .select-arrow {
    z-index: 2;
    pointer-events: none;
  }

  /* Ensure proper stacking context */
  .background-toggle-btn {
    z-index: 50;
  }
}

/* Desktop Styles */
@media (min-width: 768px) {
  .calculator-container {
    padding-top: 32px;
  }

  .calculator-header {
    padding: 0 24px;
  }

  .calculator-title {
    font-size: 24px;
    letter-spacing: -0.48px;
    color: var(--mystic-yellow-950);
  }

  .calculator-subtitle {
    color: var(--mystic-yellow-700);
  }

  .form-controls-wrapper {
    display: flex;
    padding: 0 24px;
    flex-direction: row;
    align-items: flex-start;
    gap: 12px;
    align-self: stretch;
  }

  .form-group {
    flex: 1 0 0;
  }

  .result-card {
    margin: 0 24px;
  }

  .result-amount {
    color: var(--mystic-yellow-950);
    font-size: 40px;
    letter-spacing: -1.2px;
  }

  .cta-buttons-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr;
    gap: 12px;
    padding: 0 24px 24px 24px;
    align-self: stretch;
  }

  .cta-button {
    height: 48px;
    flex: 1 0 0;
    align-self: auto;
  }

  /* Auto-flex desktop overrides */
  .calculator-container.auto-flex {
    padding: clamp(16px, 4vw, 32px);
  }

  .calculator-container.auto-flex .calculator-header {
    padding: 0;
  }

  .calculator-container.auto-flex .form-controls-wrapper {
    padding: 0;
  }

  .calculator-container.auto-flex .result-card {
    margin: 0;
  }

  .calculator-container.auto-flex .cta-buttons-grid {
    padding: 0;
  }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  .cta-button {
    transition: none;
  }

  .cta-button:hover {
    transform: none;
  }

  .cta-button:active {
    transform: none;
  }

  .result-amount {
    transition: none;
  }
}

/* ========================================
   ACCESSIBILITY ENHANCEMENTS
   ======================================== */

.form-select:focus-visible {
  outline: 2px solid var(--mystic-warning);
  outline-offset: 2px;
}

.cta-button:focus-visible {
  outline: 2px solid var(--mystic-warning);
  outline-offset: 2px;
}

/* ========================================
   HIGH CONTRAST MODE SUPPORT
   ======================================== */

@media (prefers-contrast: high) {
  .form-select {
    border-width: 2px;
  }

  .cta-button {
    border: 2px solid var(--mystic-warning);
  }

  .result-card {
    border-width: 2px;
  }
}

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

@media print {
  .calculator-container {
    background: var(--mystic-bg-white) !important;
    box-shadow: none !important;
  }

  .background-toggle-btn {
    display: none;
  }

  .cta-button {
    background: var(--mystic-bg-white) !important;
    border: 1px solid var(--mystic-text-dark) !important;
    color: var(--mystic-text-dark) !important;
  }

  .cta-button svg {
    display: none;
  }
}

/* ========================================
   ELEMENTOR EDITOR SPECIFIC FIXES
   ======================================== */

.elementor-editor-active .calculator-container {
  min-height: 400px;
}

.elementor-editor-active .form-select {
  pointer-events: none;
}

.elementor-editor-active .cta-button {
  pointer-events: none;
}

.elementor-editor-active .background-toggle-btn {
  pointer-events: none;
}

/* ========================================
   LOADING STATES
   ======================================== */

.calculator-container.loading .result-amount::after {
  content: "...";
  animation: dots 1.5s infinite;
}

@keyframes dots {
  0%,
  20% {
    color: color-mix(in srgb, var(--mystic-brand-brown) 40%, transparent);
    text-shadow:
      0.25em 0 0 color-mix(in srgb, var(--mystic-brand-brown) 40%, transparent),
      0.5em 0 0 color-mix(in srgb, var(--mystic-brand-brown) 40%, transparent);
  }
  40% {
    color: var(--mystic-brand-brown);
    text-shadow:
      0.25em 0 0 color-mix(in srgb, var(--mystic-brand-brown) 40%, transparent),
      0.5em 0 0 color-mix(in srgb, var(--mystic-brand-brown) 40%, transparent);
  }
  60% {
    text-shadow:
      0.25em 0 0 var(--mystic-brand-brown),
      0.5em 0 0 color-mix(in srgb, var(--mystic-brand-brown) 40%, transparent);
  }
  80%,
  100% {
    text-shadow:
      0.25em 0 0 var(--mystic-brand-brown),
      0.5em 0 0 var(--mystic-brand-brown);
  }
}

/* ========================================
   RTL SUPPORT
   ======================================== */

[dir="rtl"] .form-select {
  padding: 12px 20px 12px 44px;
}

[dir="rtl"] .select-arrow {
  right: auto;
  left: 12px;
}

[dir="rtl"] .cta-button {
  flex-direction: row-reverse;
}

[dir="rtl"] .background-toggle-btn {
  right: auto;
  left: 8px;
}

/* ========================================
   RESPONSIVE IMPROVEMENTS (small screens)
   ======================================== */

@media (max-width: 480px) {
  .calculator-container {
    padding: 16px;
    gap: 16px;
  }

  .calculator-title {
    font-size: 18px !important;
    line-height: 1.3 !important;
  }

  .calculator-subtitle {
    font-size: 14px !important;
  }

  .form-controls-wrapper {
    gap: 12px;
  }

  .cta-buttons-grid {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .result-amount {
    font-size: 24px !important;
  }
}

/* ========================================
   ACCESSIBILITY IMPROVEMENTS
   ======================================== */

.calculator-container:focus-within {
  outline: 2px solid var(--mystic-warning);
  outline-offset: 2px;
}

/* ========================================
   ERROR STATES
   ======================================== */

.calculator-container.error {
  border: 2px solid var(--mystic-error);
  background: var(--mystic-error-light);
}

.calculator-container.error .result-amount {
  color: var(--mystic-error);
}

.calculator-container.error .result-amount::after {
  content: " (Error loading rates)";
  font-size: 14px;
  font-weight: normal;
}

/* ========================================
   RATE SOURCE LINKS
   ======================================== */

.rate-source-links {
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid color-mix(in srgb, var(--mystic-warning) 20%, transparent);
}

.rate-links-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--mystic-btn-primary-text);
  margin-bottom: 8px;
  text-align: center;
}

.rate-links-container {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: center;
}

.rate-source-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  background: color-mix(in srgb, var(--mystic-brand-yellow-alt) 80%, transparent);
  border: 1px solid color-mix(in srgb, var(--mystic-warning) 30%, transparent);
  border-radius: 6px;
  color: var(--mystic-warning);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  transition: all 0.2s ease;
}

.rate-source-link:hover {
  background: var(--mystic-brand-yellow-alt);
  border-color: color-mix(in srgb, var(--mystic-warning) 50%, transparent);
  color: var(--mystic-warning);
  transform: translateY(-1px);
  box-shadow: 0 2px 4px color-mix(in srgb, var(--mystic-warning) 10%, transparent);
}

.rate-source-link svg {
  flex-shrink: 0;
}

/* Mobile responsive for rate source links */
@media (max-width: 480px) {
  .rate-links-container {
    flex-direction: column;
    align-items: center;
  }

  .rate-source-link {
    width: 100%;
    max-width: 280px;
    justify-content: center;
  }
}
