/**
 * MSMC Currency Converter Responsive Enhancement
 * 
 * CSS to improve the currency converter's responsive behavior
 * - Makes fields uniform in size
 * - Rotates switch button to be vertical in stacked layout
 * - Ensures consistent spacing and alignment
 */

/* Base styles - removed background and border shadow */
.msmc-currency-converter {
    padding: 15px;
    max-width: 100%;
    margin: 0 auto 20px;
    font-size: 14px;
    box-sizing: border-box;
    width: 100%;
}

/* Container-based responsive layout (not just viewport-based) */
.msmc-converter-row {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 10px;
}

/* Responsive behavior based on container width */
.msmc-currency-converter {
    container-type: inline-size;
}

/* For very narrow containers (< 300px) */
@container (max-width: 300px) {
    .msmc-converter-row {
        flex-direction: column;
    }
    
    .msmc-currency-group {
        width: 100%;
    }
    
    .msmc-converter-switch {
        justify-content: center;
        margin: 10px 0;
    }
    
    #msmc_switch_currencies,
    .msmc_switch_currencies {
        transform: rotate(90deg);
    }
    
    .msmc-field-container label {
        font-size: 13px;
    }
    
    .msmc-currency-converter {
        padding: 10px;
    }
}

/* For narrow containers (300px-500px) */
@container (min-width: 300px) and (max-width: 500px) {
    .msmc-converter-row {
        flex-direction: column;
    }
    
    .msmc-currency-group {
        width: 100%;
    }
    
    .msmc-converter-switch {
        justify-content: center;
        margin: 10px 0;
    }
    
    #msmc_switch_currencies,
    .msmc_switch_currencies {
        transform: rotate(90deg);
    }
}

/* For medium containers (500px-768px) */
@container (min-width: 500px) and (max-width: 768px) {
    .msmc-converter-row {
        flex-direction: row;
        flex-wrap: wrap;
    }
    
    .msmc-currency-group {
        flex: 1;
        min-width: 200px;
    }
    
    .msmc-converter-switch {
        flex-basis: 100%;
        order: 3;
        justify-content: center;
        margin: 10px 0;
    }
    
    #msmc_switch_currencies,
    .msmc_switch_currencies {
        transform: rotate(90deg);
    }
}

/* For wide containers */
@container (min-width: 768px) {
    .msmc-converter-row {
        flex-direction: row;
        align-items: flex-start;
    }
    
    .msmc-currency-group {
        flex: 1;
    }
    
    .msmc-converter-switch {
        padding-top: 28px;
    }
    
    #msmc_switch_currencies,
    .msmc_switch_currencies {
        transform: none;
    }
}

/* Enhanced animations for different orientations */
#msmc_switch_currencies.rotating-vertical,
.msmc_switch_currencies.rotating-vertical {
    animation: rotate-vertical 0.5s ease;
}

#msmc_switch_currencies.rotating-horizontal,
.msmc_switch_currencies.rotating-horizontal {
    animation: rotate-horizontal 0.5s ease;
}

@keyframes rotate-vertical {
    from { transform: rotate(90deg); }
    to { transform: rotate(270deg); }
}

@keyframes rotate-horizontal {
    from { transform: rotate(0deg); }
    to { transform: rotate(180deg); }
}

/* Better viewport responsive fallback for older browsers */
@media (max-width: 300px) {
    .msmc-currency-converter {
        padding: 8px;
        font-size: 13px;
    }
    
    .msmc-converter-row {
        flex-direction: column;
    }
    
    .msmc-currency-group {
        width: 100%;
    }
}

@media (min-width: 301px) and (max-width: 500px) {
    .msmc-currency-converter {
        padding: 10px;
    }
}

/* Ensure proper field sizing at all widths */
.msmc-input-wrapper input,
.msmc-select-wrapper select,
.msmc-currency-converter .select2-container .select2-selection {
    width: 100%;
    min-height: 34px;
    box-sizing: border-box;
}

/* Improve touch targets for mobile */
@media (hover: none) and (pointer: coarse) {
    #msmc_switch_currencies,
    .msmc_switch_currencies {
        min-width: 44px;
        min-height: 44px;
    }
    
    .msmc-field-container {
        margin-bottom: 12px;
    }
}

/* Sidebar-specific optimization */
.widget .msmc-currency-converter,
.sidebar .msmc-currency-converter {
    max-width: none;
    margin-left: 0;
    margin-right: 0;
}

.widget .msmc-converter-row,
.sidebar .msmc-converter-row {
    flex-direction: column;
}

.widget .msmc-currency-group,
.sidebar .msmc-currency-group {
    width: 100%;
}

.widget .msmc-converter-switch,
.sidebar .msmc-converter-switch {
    justify-content: center;
    margin: 10px 0;
}

.widget #msmc_switch_currencies,
.sidebar #msmc_switch_currencies,
.widget .msmc_switch_currencies,
.sidebar .msmc_switch_currencies {
    transform: rotate(90deg);
}

/* Ensure uniform field sizes */
.msmc-currency-converter .msmc-field-container {
    width: 100%;
    margin-bottom: 15px;
}

.msmc-currency-converter .msmc-input-wrapper,
.msmc-currency-converter .msmc-select-wrapper {
    width: 100%;
}

.msmc-currency-converter .msmc-input-wrapper input,
.msmc-currency-converter .msmc-select-wrapper select,
.msmc-currency-converter .select2-container .select2-selection {
    width: 100%;
    height: 38px !important;
    box-sizing: border-box;
}

/* Create stacked layout with vertical switch button */
.msmc-converter-row.msmc-stacked {
    flex-direction: column;
}

.msmc-converter-row.msmc-stacked .msmc-currency-group {
    width: 100%;
}

/* Switch button container centering - Improved */
.msmc-converter-switch {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    margin: 0;
    padding: 0;
    text-align: center;
}

/* Make sure the button itself doesn't have conflicting styles */
#msmc_switch_currencies,
.msmc_switch_currencies {
    background-color: #6b7280;
    color: white;
    width: 40px;
    height: 40px;
    font-size: 20px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto; /* Ensure centering */
    padding: 0;
}

/* Narrow layout centering */
@container (max-width: 767px) {
    .msmc-converter-row {
        flex-direction: column;
    }
    
    .msmc-currency-group {
        width: 100%;
    }
    
    .msmc-converter-switch {
        width: 100%;
        display: flex !important; /* Force flex display */
        justify-content: center !important;
        align-items: center !important;
        margin: 15px 0;
        padding: 0;
        flex-direction: row;
    }
    
    #msmc_switch_currencies,
    .msmc_switch_currencies {
        transform: rotate(90deg);
        margin: 0 auto !important;
    }
}

/* Fallback media query for older browsers without container queries */
@media (max-width: 767px) {
    .msmc-converter-switch {
        width: 100% !important;
        display: flex !important;
        justify-content: center !important;
        align-items: center !important;
        margin: 15px 0 !important;
        text-align: center;
    }
    
    .msmc-converter-switch > * {
        margin: 0 auto;
    }
}

/* Ensure stacked layout also centers properly */
.msmc-stacked .msmc-converter-switch {
    width: 100%;
    display: flex !important;
    justify-content: center !important;
    align-items: center !important;
    margin: 15px 0;
    padding: 0;
}

.msmc-stacked #msmc_switch_currencies,
.msmc-stacked .msmc_switch_currencies {
    margin: 0 auto !important;
    transform: rotate(90deg);
}

/* Force centering in all cases */
.msmc-converter-switch button {
    display: inline-flex !important;
    margin: 0 auto !important;
}

/* Fix conversion rate display */
.msmc-conversion-rate {
    width: 100%;
    text-align: center;
    clear: both;
    margin-top: 15px;
}

/* Responsive behavior */
@media (max-width: 768px) {
    .msmc-converter-row {
        flex-direction: column;
    }
    
    .msmc-converter-row .msmc-currency-group {
        width: 100%;
    }
    
    .msmc-converter-switch {
        width: 100% !important;
        display: flex !important;
        justify-content: center !important;
        align-items: center !important;
        margin: 15px 0 !important;
        text-align: center;
    }
    
    .msmc-converter-switch > * {
        margin: 0 auto;
    }
    
    #msmc_switch_currencies,
    .msmc_switch_currencies {
        transform: rotate(90deg) !important;
    }
    
    #msmc_switch_currencies.rotating,
    .msmc_switch_currencies.rotating {
        animation: rotate-vertical 0.5s ease;
    }
}

/* Additional styling for uniform appearance - removed background and box-shadow */
.msmc-currency-converter {
    padding: 15px;
    max-width: 100%;
    margin: 0 auto 20px;
    font-size: 14px;
    box-sizing: border-box;
}

.msmc-converter-row {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 10px;
}

.msmc-side-by-side {
    justify-content: space-between;
    align-items: flex-start;
}

.msmc-currency-group {
    flex: 1;
    min-width: 140px;
}

/* Fields */
.msmc-field-container label {
    display: block;
    margin-bottom: 5px;
    font-weight: 500;
    color: #333;
}

/* Switch Button */
.msmc-converter-switch {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    margin: 0;
    padding: 0;
    text-align: center;
}

/* For side-by-side layout, add padding top to align with fields */
.msmc-side-by-side .msmc-converter-switch {
    padding-top: 28px;
    width: auto;
    flex: 0 0 auto;
}

/* For stacked layout, keep margin top/bottom */
.msmc-stacked .msmc-converter-switch {
    margin: 15px 0;
    width: 100%;
}

/* Ensure the button itself doesn't get too wide */
#msmc_switch_currencies,
.msmc_switch_currencies {
    background-color: #6b7280;
    color: white;
    width: 40px;
    height: 40px;
    font-size: 20px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto; /* Ensure centering */
    padding: 0;
}

/* Switch button hover effect */
#msmc_switch_currencies:hover,
.msmc_switch_currencies:hover {
    background-color: #5c7965;
}

/* Switch button animation for horizontal layout */
#msmc_switch_currencies.rotating,
.msmc_switch_currencies.rotating {
    animation: rotate 0.5s ease;
}

@keyframes rotate {
    from { transform: rotate(0deg); }
    to { transform: rotate(180deg); }
}

/* Improved focus states for accessibility */
.msmc-input-wrapper input:focus,
.msmc-select-wrapper select:focus,
.msmc_switch_currencies:focus {
    outline: 2px solid #9d47a5;
    outline-offset: 2px;
    box-shadow: none;
}

/* Dark mode support - removed background styles */
@media (prefers-color-scheme: dark) {
    .msmc-currency-converter {
        color: #eee;
    }
    
    .msmc-field-container label {
        color: #eee;
    }
    
    .msmc-input-wrapper input,
    .msmc-select-wrapper select {
        background-color: #444;
        color: #eee;
        border-color: #555;
    }
    
    #msmc_switch_currencies,
    .msmc_switch_currencies {
        background-color: #444;
        color: #eee;
    }
    
    #msmc_switch_currencies:hover,
    .msmc_switch_currencies:hover {
        background-color: #555;
    }
}

/* Title styling */
.msmc-converter-title {
    margin-top: 0;
    margin-bottom: 15px;
    font-size: 18px;
    color: #333;
}

/* Enhanced Select2 integration */
.msmc-currency-converter .select2-container {
    width: 100% !important;
}

/* Improved Select2 field styling */
.msmc-currency-converter .select2-container--default .select2-selection--single {
    height: 38px !important;
    border: 1px solid #ddd !important;
    border-radius: var(--msmc-border-radius, 3px) !important;
    background-color: #fff;
}

/* Selection text alignment */
.msmc-currency-converter .select2-container--default .select2-selection--single .select2-selection__rendered {
    line-height: 36px !important;
    padding-left: 12px !important;
    color: var(--msmc-text-color, #333333);
}

/* Selection arrow alignment */
.msmc-currency-converter .select2-container--default .select2-selection--single .select2-selection__arrow {
    height: 36px !important;
}

/* Dropdown styles */
.select2-dropdown {
    border-color: #ddd !important;
    border-radius: 3px !important;
    z-index: 1000000 !important; /* Higher than popup */
}

/* Search field styling */
.select2-container--default .select2-search--dropdown .select2-search__field {
    border: 1px solid #ddd;
    border-radius: 2px;
    padding: 8px;
    outline: none;
}

.select2-container--default .select2-search--dropdown .select2-search__field:focus {
    border-color: var(--msmc-primary-color, #9d47a5);
}

/* Highlighted option - THIS IS THE HOVER STATE */
.select2-container--default .select2-results__option--highlighted[aria-selected] {
    background-color: var(--msmc-primary-color, #9d47a5) !important;
    color: var(--msmc-primary-text-color, #ffffff) !important;
}

/* Selected option */
.select2-container--default .select2-results__option[aria-selected=true] {
    background-color: rgba(157, 71, 165, 0.2);
}

/* Make the dropdown wider for better readability */
.select2-container--open .select2-dropdown--below {
    min-width: 250px !important;
    border-top: none !important;
    margin-top: -1px;
}

/* Better padding for dropdown options */
.select2-results__option {
    padding: 8px 12px !important;
}

/* Ensure dropdown is above everything */
body > .select2-container--open {
    z-index: 1000000 !important;
}

/* Enhanced focus styling */
.select2-container--default.select2-container--focus .select2-selection--single {
    border-color: var(--msmc-primary-color, #9d47a5) !important;
    outline: none;
}

/* 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;
}

/* Fix for empty switcher containers */
.msmc-currency-group:empty {
    display: none;
}

/* Adjusted for the second image layout (extra wide) */
.msmc-converter-extra-wide .msmc-converter-row {
    gap: 20px;
}

.msmc-converter-extra-wide .msmc-currency-group {
    flex: 0 0 45%;
}

.msmc-converter-extra-wide .msmc-converter-switch {
    padding-top: 38px;
}

/* Fix for responsive behavior on extra small screens */
@media (max-width: 480px) {
    .msmc-currency-converter {
        padding: 10px;
    }
    
    .msmc-converter-row {
        gap: 5px;
    }
    
    .msmc-field-container {
        margin-bottom: 10px;
    }
}

/* Ensure Select2 search box is always visible */
.select2-container--open .select2-search--dropdown .select2-search__field {
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
    padding: 8px !important;
    margin: 5px !important;
    width: calc(100% - 10px) !important;
    min-height: 30px !important;
}

/* Fix search area padding */
.select2-container--default .select2-search--dropdown {
    padding: 4px !important;
    display: block !important;
}

/* Style the search box more visibly */
.select2-container--default .select2-search--dropdown .select2-search__field {
    border: 1px solid #aaa !important;
    border-radius: 4px !important;
    background-color: #fff !important;
    color: #333 !important;
}

/* Make the dropdown wider and taller */
.select2-container--open .select2-dropdown {
    min-width: 250px !important;
    max-height: 350px !important;
}

/* Highlight search matches */
.select2-results__option mark {
    background-color: rgba(157, 71, 165, 0.3) !important;
    padding: 0 !important;
}

/* Make sure Z-index is high enough to show above other elements */
.select2-container--open {
    z-index: 99999 !important;
}

/* Converted amount field with green background */
.msmc_amount_to {
    background-color: #5c7965 !important;
    color: #ffffff !important;
    font-weight: bold;
    border: none !important;
    text-align: center;
    padding: 10px;
    border-radius: 4px !important;
}

/* Make the converted amount field readonly but styled */
.msmc_amount_to[readonly] {
    background-color: #5c7965 !important;
    color: #ffffff !important;
    cursor: not-allowed;
}

/* Ensure the converted amount field maintains proper height */
.msmc-currency-converter .msmc-input-wrapper .msmc_amount_to {
    height: 38px !important;
    line-height: 18px;
}

/* Label text color adjustment for better contrast */
.msmc-field-container label {
    color: #6b7280;
    font-weight: 500;
}

/* Ensure the select dropdowns match the design */
.msmc-currency-converter .select2-container--default .select2-selection--single {
    border: 1px solid #d1d5db !important;
    border-radius: 6px !important;
    background-color: #fff !important;
    min-height: 38px !important;
}

/* Style improvements for the number inputs */
.msmc_amount_from {
    text-align: center;
    font-weight: 500;
}

/* Enhanced conversion rate styling */
.msmc-conversion-rate {
    color: #6b7280;
    font-weight: 500;
    text-align: center;
    padding: 10px 0;
}

/* Responsive adjustments - Wide layout */
@container (min-width: 768px) {
    .msmc-converter-row {
        display: flex;
        flex-direction: row;
        align-items: flex-start;
        gap: 15px;
    }
    
    .msmc-currency-group {
        flex: 0 0 45%;
        min-width: 200px;
    }
    
    .msmc-converter-switch {
        flex: 0 0 auto;
        padding-top: 32px;
    }
    
    .msmc-conversion-rate {
        width: 100%;
        margin-top: 15px;
    }
}

/* Responsive adjustments - Narrow layout */
@container (max-width: 767px) {
    .msmc-converter-row {
        flex-direction: column;
    }
    
    .msmc-currency-group {
        width: 100%;
    }
    
    .msmc-converter-switch {
        width: 100% !important;
        display: flex !important; /* Force flex display */
        justify-content: center !important;
        align-items: center !important;
        margin: 15px 0;
        padding: 0;
        flex-direction: row;
    }
    
    #msmc_switch_currencies,
    .msmc_switch_currencies {
        transform: rotate(90deg);
        margin: 0 auto !important;
    }
}

/* Dark mode adjustments */
@media (prefers-color-scheme: dark) {
    .msmc_amount_to {
        background-color: #4a6356 !important;
    }
    
    .msmc-currency-converter {
        background-color: transparent;
    }
    
    .msmc-field-container label {
        color: #9ca3af;
    }
}