/**
 * Mob Smart Multi-Currency Frontend Styles
 * 
 * Contains all styles for the frontend currency switcher, 
 * popup, and related components.
 */

/* -------------------------------- 
   CSS Variables 
   -------------------------------- */
:root {
  /* Primary Accent Colors */
  --msmc-primary-color: #9d47a5;
  --msmc-primary-hover-color: #863270;
  --msmc-primary-text-color: #ffffff;

  /* Neutral Colors */
  --msmc-bg-color: #f5f5f5;
  --msmc-text-color: #333333;

  /* Popup Colors */
  --msmc-popup-bg-color: #ffffff;
  --msmc-popup-text-color: var(--msmc-text-color);

  /* Sizing */
  --msmc-button-size: 40px;
  --msmc-font-size: 12px;
  --msmc-border-radius: 3px;
  --msmc-z-index: 9999;
  --msmc-popup-z-index: 999999;

  /* Spacing */
  --msmc-spacing-xs: 4px;
  --msmc-spacing-sm: 8px;
  --msmc-spacing-md: 12px;
  --msmc-spacing-lg: 20px;
}

/* -------------------------------- 
     Core Containers 
     -------------------------------- */
.msmc-currency-switcher-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  z-index: var(--msmc-z-index);
  max-width: none; /* Allow wider container for currency code + symbol */
}

/* Main currency button with symbol display */
.msmc-currency-switcher-container .msmc-default-currency {
  width: auto !important;
  min-width: var(--msmc-button-size) !important;
  max-width: 120px !important;
  padding: 0 var(--msmc-spacing-sm) !important;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* -------------------------------- 
     DefaultCurrency Buttons 
     -------------------------------- */
#msmc-default-currency-button {
  background-color: var(--msmc-primary-color) !important;
  color: var(--msmc-primary-text-color) !important;
  border: none;
  font-size: var(--msmc-font-size) !important;
  width: var(--msmc-button-size) !important;
  height: var(--msmc-button-size) !important;
  border-radius: var(--msmc-border-radius) !important;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  cursor: pointer;
  transition: background-color 0.3s ease, transform 0.2s ease;
  margin-bottom: var(--msmc-spacing-sm);
  text-transform: uppercase;
  font-weight: 600;
  padding: 0;
}

/* -------------------------------- 
     Currency Buttons 
     -------------------------------- */

/* Base button styles - NON-ACTIVE state uses bg-color */
.msmc-currency-button,
.msmc-grid-currency-button {
  background-color: var(--msmc-bg-color) !important;
  color: var(--msmc-text-color) !important;
  border: none;
  font-size: var(--msmc-font-size) !important;
  width: var(--msmc-button-size) !important;
  height: var(--msmc-button-size) !important;
  border-radius: var(--msmc-border-radius) !important;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  cursor: pointer;
  transition: background-color 0.3s ease, transform 0.2s ease, opacity 0.2s ease;
  margin-bottom: var(--msmc-spacing-sm);
  text-transform: uppercase;
  font-weight: 600;
  padding: 0;
}

/* CRITICAL: Non-active buttons ALWAYS use bg-color (explicit override) */
.msmc-currency-button:not(.active):not(.selected):not([aria-pressed="true"]),
.msmc-grid-currency-button:not(.active):not(.selected):not(
    [aria-pressed="true"]
  ) {
  background-color: var(--msmc-bg-color) !important;
  color: var(--msmc-text-color) !important;
}

/* Hover state for non-active buttons - subtle effect, stays on bg-color */
.msmc-currency-button:not(.active):not(.selected):not(
    [aria-pressed="true"]
  ):hover,
.msmc-grid-currency-button:not(.active):not(.selected):not(
    [aria-pressed="true"]
  ):hover {
  background-color: var(--msmc-bg-color) !important;
  color: var(--msmc-text-color) !important;
  transform: translateY(-2px);
  opacity: 0.85;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}

/* ACTIVE button styles - uses primary color */
.msmc-currency-button.active,
.msmc-currency-button.selected,
.msmc-currency-button[aria-pressed="true"],
.msmc-grid-currency-button.active,
.msmc-grid-currency-button.selected,
.msmc-grid-currency-button[aria-pressed="true"] {
  background-color: var(--msmc-primary-color) !important;
  color: var(--msmc-primary-text-color) !important;
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

/* Hover on ACTIVE button - uses primary hover color */
.msmc-currency-button.active:hover,
.msmc-currency-button.selected:hover,
.msmc-currency-button[aria-pressed="true"]:hover,
.msmc-grid-currency-button.active:hover,
.msmc-grid-currency-button.selected:hover,
.msmc-grid-currency-button[aria-pressed="true"]:hover {
  background-color: var(--msmc-primary-hover-color) !important;
  color: var(--msmc-primary-text-color) !important;
}

.msmc-preferred-currencies {
  display: flex;
  flex-direction: column;
  width: 100%;
}

/* -------------------------------- 
     Switch Button (Plus Button) 
     -------------------------------- */
.msmc-switch-button {
  background-color: var(--msmc-primary-color) !important;
  color: var(--msmc-primary-text-color) !important;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  font-size: 18px;
  width: var(--msmc-button-size) !important;
  height: var(--msmc-button-size) !important;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  transition: background-color 0.3s, transform 0.3s;
  margin-top: var(--msmc-spacing-xs);
}

.msmc-switch-button:hover {
  background-color: var(--msmc-primary-hover-color) !important;
  transform: rotate(180deg);
}

/* -------------------------------- 
     Popup Container - Direct Child of Body 
     -------------------------------- */
body > .msmc-currency-popup {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5) !important;
  z-index: var(--msmc-popup-z-index) !important;
  display: none;
  align-items: center;
  justify-content: center;
}

/* Prevent scroll when popup is open */
body.msmc-popup-open {
  overflow: hidden;
}

/* -------------------------------- 
     Popup Content 
     -------------------------------- */
.msmc-popup-content {
  position: relative;
  background-color: var(--msmc-popup-bg-color) !important;
  border-radius: var(--msmc-border-radius) !important;
  padding: 20px;
  width: 90%;
  max-width: 350px;
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
  text-align: center;
  margin: auto;
  top: 40% !important;
}

.msmc-popup-content h2 {
  color: var(--msmc-primary-color) !important;
  margin-top: 0;
  margin-bottom: 15px;
  font-size: 18px;
  font-weight: 600;
}

/* Close Button */
.msmc-close-button {
  position: absolute;
  top: -10px;
  right: -10px;
  width: 25px;
  height: 25px;
  background-color: var(--msmc-primary-color) !important;
  color: var(--msmc-primary-text-color) !important;
  border: none;
  border-radius: 50%;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
  transition: background-color 0.2s;
  z-index: 1;
  padding: 0;
  line-height: 1;
}

.msmc-close-button:hover {
  background-color: var(--msmc-primary-hover-color) !important;
}

/* -------------------------------- 
     Currency Select Dropdown 
     -------------------------------- */
.msmc-currency-select {
  width: 100%;
  height: 40px;
  padding: 8px 12px;
  border: 1px solid #ddd;
  border-radius: var(--msmc-border-radius) !important;
  background-color: white;
  color: var(--msmc-text-color) !important;
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23333' d='M6 9L0 0h12'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 10px;
  outline: none;
}

.msmc-currency-select:focus {
  border-color: var(--msmc-primary-color);
}

/* -------------------------------- 
     Loading Spinner 
     -------------------------------- */
.msmc-loading-spinner {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(255, 255, 255, 0.8);
  display: none;
  align-items: center;
  justify-content: center;
  border-radius: var(--msmc-border-radius) !important;
  z-index: 1;
}

.msmc-spinner-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.msmc-spinner {
  border: 3px solid rgba(0, 0, 0, 0.1);
  border-top-color: var(--msmc-primary-color) !important;
  border-radius: 50%;
  width: 30px;
  height: 30px;
  animation: msmc-spinner-rotate 1s linear infinite;
}

.msmc-spinner-text {
  margin-top: var(--msmc-spacing-sm);
  font-size: 14px;
  color: var(--msmc-text-color) !important;
}

@keyframes msmc-spinner-rotate {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

/* -------------------------------- 
     Select2 Integration
     -------------------------------- */
.select2-container {
  width: 100% !important;
}

.select2-container--default .select2-selection--single {
  height: 40px;
  border: 1px solid #ddd !important;
}

.select2-container--default
  .select2-selection--single
  .select2-selection__rendered {
  line-height: 38px !important;
  padding-left: 12px !important;
  color: var(--msmc-text-color) !important;
  font-size: var(--msmc-font-size) !important;
}

.select2-container--default
  .select2-selection--single
  .select2-selection__arrow {
  height: 38px !important;
}

.select2-dropdown {
  border-color: var(--msmc-primary-color) !important;
  border-radius: 4px !important;
  z-index: 1000000 !important; /* Higher than popup */
}

.select2-container--default .select2-search--dropdown .select2-search__field {
  border: 1px solid var(--msmc-primary-color) !important;
  border-radius: 2px;
  outline: none;
}

.select2-container--default
  .select2-search--dropdown
  .select2-search__field:focus {
  border-color: var(--msmc-primary-hover-color) !important;
  box-shadow: 0 0 0 1px var(--msmc-primary-hover-color) !important;
}

.select2-container--default
  .select2-results__option--highlighted[aria-selected] {
  background-color: var(--msmc-primary-color) !important;
}

.select2-container--open .select2-dropdown--below {
  border-top: none !important;
  margin-top: -1px;
}

/* Ensure Select2 dropdown is above everything */
body > .select2-container--open {
  z-index: 1000000 !important;
}

/* -------------------------------- 
     Responsive Styles
     -------------------------------- */
@media (max-width: 767px) {
  .msmc-currency-switcher-container {
    bottom: var(--msmc-spacing-md);
    right: var(--msmc-spacing-md);
  }

  #msmc-default-currency-button,
  .msmc-currency-button,
  .msmc-switch-button {
    width: var(--msmc-button-size) !important;
    height: var(--msmc-button-size) !important;
    font-size: 11px;
  }

  .msmc-popup-content {
    width: 95%;
    padding: 15px;
    /* Position at top on mobile to avoid keyboard overlap */
    top: 20px !important;
    margin: 0 auto !important;
    position: absolute;
    left: 0;
    right: 0;
  }

  .msmc-popup-content h2 {
    font-size: 16px;
  }
}

@media (max-width: 480px) {
  .msmc-popup-content {
    width: 90%;
    max-width: 300px;
  }
}

/* -------------------------------- 
     Accessibility Styles
     -------------------------------- */
.msmc-screen-reader-text {
  border: 0;
  clip: rect(1px, 1px, 1px, 1px);
  clip-path: inset(50%);
  height: 1px;
  margin: -1px;
  overflow: hidden;
  padding: 0;
  position: absolute;
  width: 1px;
  word-wrap: normal !important;
}

/* High contrast mode support */
@media (forced-colors: active) {
  .msmc-currency-button,
  .msmc-switch-button,
  .msmc-close-button {
    border: 1px solid;
  }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
  .msmc-popup-content {
    background-color: #222;
    color: #eee;
  }

  .msmc-popup-content h2 {
    color: #eee;
  }

  .msmc-currency-select {
    background-color: #333;
    color: #eee;
    border-color: #555;
  }

  .select2-container--default .select2-selection--single {
    background-color: #333;
    border-color: #555 !important;
  }

  .select2-container--default
    .select2-selection--single
    .select2-selection__rendered {
    color: #eee;
  }

  .select2-dropdown {
    background-color: #333;
    border-color: #555 !important;
  }

  .select2-container--default .select2-results__option {
    color: #eee;
  }

  .select2-container--default .select2-search--dropdown .select2-search__field {
    background-color: #444;
    color: #eee;
    border-color: #555;
  }
}

/* Animation styles */
@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

/* Currency option styling */
.msmc-currency-option {
  display: flex;
  align-items: center;
}

.msmc-currency-code {
  font-weight: bold;
  margin-right: 8px;
}

.msmc-currency-name {
  font-size: 0.9em;
  color: #666;
}

/* -------------------------------- 
     Currency Grid in Popup 
     -------------------------------- */
.msmc-currency-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
  gap: var(--msmc-spacing-sm);
  margin-top: var(--msmc-spacing-md);
  padding-top: var(--msmc-spacing-md);
  border-top: 1px solid #eee;
}

/* Grid buttons - larger than sidebar buttons */
.msmc-grid-currency-button {
  width: auto !important;
  height: auto !important;
  min-height: 50px;
  padding: var(--msmc-spacing-sm) var(--msmc-spacing-md);
  flex-direction: column;
  gap: 2px;
}

.msmc-grid-currency-button .msmc-currency-code {
  font-size: var(--msmc-font-size);
  font-weight: 600;
}

.msmc-grid-currency-button .msmc-currency-symbol {
  font-size: calc(var(--msmc-font-size) - 2px);
  opacity: 0.8;
}

/* Fixed version of the popup display */
.msmc-currency-popup[style*="display: flex"] {
  display: flex !important;
}

/* Fix for empty switcher containers */
.msmc-currency-switcher-container:empty {
  display: none;
}

/* Container positions */
.msmc-currency-switcher-container.position-top-left {
  top: 20px;
  left: 20px;
  bottom: auto;
  right: auto;
}

.msmc-currency-switcher-container.position-top-right {
  top: 20px;
  right: 20px;
  bottom: auto;
  left: auto;
}

.msmc-currency-switcher-container.position-bottom-left {
  bottom: 20px;
  left: 20px;
  top: auto;
  right: auto;
}

.msmc-currency-switcher-container.position-bottom-right {
  bottom: 20px;
  right: 20px;
  top: auto;
  left: auto;
}

/* -------------------------------- 
     Currency Switcher Styles 
     -------------------------------- */
.msmc-currency-option {
  display: flex;
  align-items: center;
  padding: 5px 0;
}

.msmc-currency-symbol {
  font-weight: bold;
  margin-right: 5px;
  min-width: 25px;
}

.msmc-currency-code {
  font-weight: bold;
}

.msmc-currency-name {
  color: #666;
  margin-left: 5px;
}

/* -------------------------------- 
     Select2 Override Styles 
     -------------------------------- */
.select2-container--default .select2-results__option[aria-disabled="true"] {
  display: none !important;
}

.select2-container--default
  .select2-results__option--highlighted[aria-selected] {
  background-color: var(--msmc-primary-color, #9d47a5);
}

.select2-dropdown {
  border-color: var(--msmc-primary-color, #9d47a5);
}

.select2-container--default .select2-search--dropdown .select2-search__field {
  border: 1px solid var(--msmc-primary-color, #9d47a5);
  outline: none;
}

.select2-container--default
  .select2-search--dropdown
  .select2-search__field:focus {
  border-color: var(--msmc-primary-hover-color, #863270);
  box-shadow: 0 0 0 1px var(--msmc-primary-hover-color, #863270);
}

/* -------------------------------- 
   Instant Currency Conversion 
   -------------------------------- */

/* Base styles for convertible amounts */
.msmc-amount {
  display: inline;
  transition: opacity 0.15s ease-out, color 0.15s ease-out;
}

/* Converting state - fade effect */
.msmc-amount.msmc-converting {
  opacity: 0.5;
}

/* Highlight effect on conversion (optional - can be enabled via filter) */
.msmc-amount.msmc-just-converted {
  animation: msmc-pulse 0.5s ease-out;
}

@keyframes msmc-pulse {
  0% {
    background-color: rgba(157, 71, 165, 0.2);
  }
  100% {
    background-color: transparent;
  }
}

/* Success indicator for currency switch */
.msmc-currency-switcher-container.msmc-switch-success::after {
  content: "✓";
  position: absolute;
  top: -10px;
  right: -10px;
  background: #4caf50;
  color: white;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  animation: msmc-checkmark 0.6s ease-out forwards;
}

@keyframes msmc-checkmark {
  0% {
    transform: scale(0);
    opacity: 0;
  }
  50% {
    transform: scale(1.2);
    opacity: 1;
  }
  100% {
    transform: scale(1);
    opacity: 0;
  }
}
