/**
 * Cardstream Embedded Payment Form Styles
 */

.form-hostedfields {
    width: 100%;
    max-width: 500px;
    margin: 15px 0;
}

.form-group {
    margin: 4px 0 15px 0;
}

.form-group-fields {
    display: flex;
    flex-direction: row;
    gap: 20px;
}

.form-group label {
    display: inline-block;
    max-width: 100%;
    margin-bottom: 5px;
    font-weight: bold;
    color: #333 !important; /* Default black color for labels - force with !important */
}

/* Only show red label when form group has error class AND field is not focused */
.form-group.has-error label {
    color: #d00;
}

/* CRITICAL: Keep labels black when field is focused (even if has-error class exists) */
.form-group:has(.hostedfield.hf-focus) label,
.form-group:has(.form-control-hosted:focus) label {
    color: #333 !important;
}

/* Fallback for browsers that don't support :has() - use JavaScript to handle this */
.form-group label.label-normal {
    color: #333 !important;
}

.form-group label.error {
    color: #d00;
    margin: 5px 0 0 0;
    font-weight: normal;
    font-style: italic;
    font-size: 14px;
}

.form-control {
    display: block;
    box-sizing: border-box;
    width: 100%;
    padding: 6px 12px;
    font-size: 14px;
    color: #555;
    background-color: #fff;
    background-image: none;
    border: 1px solid #ddd;
    border-radius: 4px;
}

.box_loading {
    padding: 10px;
    text-align: center;
    display: block; /* Show loading initially */
}

.box_creditcard .fields {
    display: none; /* Hide fields initially until SDK is ready */
}

/* Show fields when SDK is ready */
.box_creditcard .fields.sdk-ready {
    display: block;
}

.box_creditcard.has_cards .fields {
    display: none;
}

.box_listcards > div {
    margin-bottom: 10px;
}

.box_listcards > div input {
    margin-right: 5px;
}

.box_creditcard.has_cards {
    display: none;
    padding-left: 23px;
}

.box_ccv {
    display: none;
    padding-left: 23px;
    width: 170px;
}

.box_ccv .form-group {
    margin-bottom: 15px;
}

/* HostedField specific styles */
.hostedfield:disabled {
    cursor: not-allowed;
    background-color: #eee;
    opacity: 1;
}

.hostedfield {
    padding: 8px 10px 10px 10px !important;
    height: auto !important;
}

.hostedfield:valid {
    border-color: #28a745 !important;
    color: #28a745 !important;
}

/* Default state - normal border color (black/grey) */
.hostedfield,
.hostedfield.hf-focus {
    border-color: #ddd !important;
    color: #555 !important;
}

/* Only show red border when field is invalid AND user has interacted (blur or change after typing) */
/* Don't show red on initial focus - only after user has typed something and blurred */
.hostedfield.hf-user-invalid.hf-invalid:not(.hf-focus) {
    border-color: #d00 !important;
    color: #d00 !important;
}

/* When field is focused, always show normal border (even if invalid) - prevents red on click */
.hostedfield.hf-focus,
.hostedfield.hf-focus.hf-invalid,
.hostedfield.hf-focus.hf-user-invalid {
    border-color: #ddd !important;
    color: #555 !important;
}

/* Valid field - green border */
.hostedfield:valid,
.hostedfield.hf-valid {
    border-color: #28a745 !important;
    color: #28a745 !important;
}

.hostedfield:readonly {
    color: lightgrey !important;
}

.hostedfield.hf-autofill {
    color: rgb(0, 0, 0) !important;
}

.hostedfield-frame {
    height: 25px !important;
}

/* Error display */
#cardstream-error-info {
    margin: 15px 0;
}

#cardstream-error-info .woocommerce-error {
    padding: 1em 2em 1em 3.5em;
    margin: 0 0 2em;
    position: relative;
    background-color: #f7f6f7;
    color: #515151;
    border-top: 3px solid var(--woocommerce-error, #b81c23);
    list-style: none outside;
    width: auto;
    word-wrap: break-word;
}

/* Form validation states */
.form-group.has-error .form-control {
    border-color: #d00;
}

.form-group.has-error label {
    color: #d00;
}

/* 3DS Modal styles - High z-index to ensure visibility on all themes */
.cardstream-3ds-modal {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    background-color: rgba(0, 0, 0, 0.5) !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    z-index: 999999 !important;
    width: 100% !important;
    height: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
}

.cardstream-3ds-modal-content {
    background-color: #fff;
    border-radius: 8px;
    padding: 20px;
    width: 90%;
    max-width: 600px;
    max-height: 90vh;
    position: relative;
}

/* 3DS Loader styles - Ensure loader is always visible */
.cardstream-3ds-loader {
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    justify-content: center !important;
    padding: 40px 20px !important;
    text-align: center !important;
    min-height: 300px !important;
    visibility: visible !important;
    opacity: 1 !important;
}

.cardstream-3ds-spinner {
    border: 4px solid #f3f3f3;
    border-top: 4px solid #3498db;
    border-radius: 50%;
    width: 50px;
    height: 50px;
    animation: cardstream-spin 1s linear infinite;
    -webkit-animation: cardstream-spin 1s linear infinite;
    -moz-animation: cardstream-spin 1s linear infinite;
    -o-animation: cardstream-spin 1s linear infinite;
    margin: 0 auto 20px;
}

/* 3DS Loader Spinner Animation - Browser Compatibility */
@keyframes cardstream-spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

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

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

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

.cardstream-3ds-loader p {
    margin: 0;
    color: #333;
    font-size: 16px;
    font-weight: 500;
}

.cardstream-3ds-loader p:last-child {
    margin-top: 10px;
    color: #666;
    font-size: 14px;
    font-weight: normal;
}

/* 3DS iframe styles */
.cardstream-3ds-iframe {
    width: 100%;
    height: 500px;
    border: none;
}

#cardstream-3ds-iframe {
    width: 100%;
    min-height: 500px;
    max-height: 80vh;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    background-color: #fff;
}

/* Powered by Cardstream */
.cardstream-powered-by {
    font-size: 12px;
    color: #666;
    margin-bottom: 15px;
}

.cardstream-powered-by a {
    color: #0073aa;
    text-decoration: none;
}

.cardstream-powered-by a:hover {
    text-decoration: underline;
}

/* Responsive */
@media (max-width: 768px) {
    .form-group-fields {
        flex-direction: column;
        gap: 0;
    }

    .form-hostedfields {
        max-width: 100%;
    }
}

