/**
 * Centralized Payment Modal Styles
 * Production-ready, professional UI
 */

/* Modal Container */
#sp-payment-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 999999;
    /* Use flex centering so modal is centered even when parent transforms exist */
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    overflow-y: auto;
    /* -webkit-overflow-scrolling removed for compatibility */
}

/* Backdrop */
#sp-payment-modal .sp-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.65);
    -webkit-backdrop-filter: blur(4px);
    backdrop-filter: blur(4px);
    z-index: 1;
}

/* Modal Dialog */
#sp-payment-modal .sp-modal-content {
    position: relative;
    background: #ffffff;
    margin: 0 auto;
    max-width: 540px;
    width: 90%;
    border-radius: 16px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    animation: slideUp 0.3s ease-out;
    z-index: 2;
    max-height: calc(100vh - 80px);
    overflow-y: auto;
}

/* Ensure the dialog wrapper doesn't expand to full width for payment modal */
#sp-payment-modal .sp-modal {
    width: auto;
    max-width: none;
    display: inline-flex; /* let the modal content define width */
    align-items: stretch;
    justify-content: flex-start;
}

/* large size for modal when needed */
#sp-payment-modal .sp-modal.sp-modal-large { max-width: 1200px; }

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* Modal Header */
#sp-payment-modal .sp-modal-header {
    padding: 32px 32px 24px;
    text-align: center;
    border-bottom: 1px solid #e5e7eb;
}

#sp-payment-modal .sp-modal-icon {
    width: 72px;
    height: 72px;
    margin: 0 auto 20px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 10px 25px rgba(102, 126, 234, 0.3);
}

#sp-payment-modal .sp-modal-icon .dashicons {
    font-size: 36px;
    width: 36px;
    height: 36px;
    color: #ffffff;
}

#sp-payment-modal .sp-modal-title {
    margin: 0 0 8px;
    font-size: 26px;
    font-weight: 700;
    color: #111827;
    letter-spacing: -0.5px;
}

#sp-payment-modal .sp-modal-subtitle {
    margin: 0;
    font-size: 15px;
    color: #6b7280;
    line-height: 1.5;
}

/* Close Button */
#sp-payment-modal .sp-modal-close {
    position: absolute;
    top: 20px;
    right: 20px;
    width: 40px;
    height: 40px;
    padding: 0;
    background: #f3f4f6;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    z-index: 10;
}

#sp-payment-modal .sp-modal-close:hover {
    background: #e5e7eb;
    transform: rotate(90deg);
}

#sp-payment-modal .sp-modal-close .dashicons {
    font-size: 22px;
    width: 22px;
    height: 22px;
    color: #6b7280;
}

/* Modal Body */
#sp-payment-form-container,
#sp-payment-status-container {
    padding: 28px 32px 32px;
}

/* Payment Summary Card */
.sp-payment-summary-card {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 14px;
    padding: 24px;
    margin-bottom: 28px;
    color: #ffffff;
    box-shadow: 0 10px 25px rgba(102, 126, 234, 0.2);
}

.sp-payment-summary-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
}

.sp-payment-summary-row:not(:last-child) {
    border-bottom: 1px solid rgba(255, 255, 255, 0.2);
}

.sp-payment-summary-label {
    font-size: 14px;
    font-weight: 500;
    opacity: 0.9;
}

.sp-payment-summary-value {
    font-weight: 600;
    font-size: 15px;
}

.sp-payment-amount-row {
    padding-top: 14px;
}

.sp-payment-summary-amount {
    font-size: 32px;
    font-weight: 700;
    letter-spacing: -1px;
}

/* Form Elements */
.sp-form-group {
    margin-bottom: 22px;
}

.sp-form-label {
    display: block;
    margin-bottom: 10px;
    font-weight: 600;
    font-size: 14px;
    color: #374151;
}

.sp-form-label .dashicons {
    font-size: 16px;
    width: 16px;
    height: 16px;
    vertical-align: middle;
    margin-right: 6px;
    color: #667eea;
}

.sp-required {
    color: #ef4444;
    margin-left: 3px;
}

.sp-form-control {
    width: 100%;
    padding: 14px 16px;
    border: 2px solid #e5e7eb;
    border-radius: 10px;
    font-size: 16px;
    transition: all 0.2s;
    box-sizing: border-box;
    font-family: inherit;
}

.sp-form-control:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 4px rgba(102, 126, 234, 0.1);
}

.sp-form-control.sp-error {
    border-color: #ef4444;
    background: #fef2f2;
}

.sp-form-help {
    display: block;
    margin-top: 8px;
    font-size: 13px;
    color: #6b7280;
    line-height: 1.4;
}

.sp-form-error {
    margin-top: 8px;
    padding: 10px 14px;
    background: #fee2e2;
    border-left: 4px solid #ef4444;
    border-radius: 6px;
    font-size: 13px;
    color: #991b1b;
    line-height: 1.4;
}

/* Operators Section */
.sp-operators-section {
    margin-bottom: 26px;
}

.sp-operators-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 14px;
    margin-top: 14px;
}

.sp-operator-card {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px;
    background: #f9fafb;
    border: 2px solid #e5e7eb;
    border-radius: 10px;
    transition: all 0.2s;
}

.sp-operator-card:hover {
    border-color: #667eea;
    background: #f0f4ff;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.15);
}

.sp-operator-logo {
    width: 44px;
    height: 44px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.sp-operator-logo .dashicons {
    font-size: 22px;
    width: 22px;
    height: 22px;
    color: #ffffff;
}

.sp-operator-info {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.sp-operator-name {
    font-size: 14px;
    font-weight: 600;
    color: #111827;
}

.sp-operator-code {
    font-size: 12px;
    color: #6b7280;
    font-family: 'Courier New', monospace;
}

/* Alerts */
.sp-alert {
    padding: 14px 16px;
    border-radius: 10px;
    margin-bottom: 18px;
    display: flex;
    align-items: flex-start;
    gap: 12px;
    line-height: 1.5;
}

.sp-alert .dashicons {
    flex-shrink: 0;
    margin-top: 2px;
}

.sp-alert-error {
    background: #fee2e2;
    border-left: 4px solid #ef4444;
    color: #991b1b;
}

.sp-alert-success {
    background: #d1fae5;
    border-left: 4px solid #10b981;
    color: #065f46;
}

.sp-alert-info {
    background: #dbeafe;
    border-left: 4px solid #3b82f6;
    color: #1e40af;
}

/* Modal Actions */
.sp-modal-actions {
    display: flex;
    gap: 14px;
    justify-content: flex-end;
    margin-top: 28px;
}

/* Buttons */
.sp-btn {
    padding: 14px 28px;
    border: none;
    border-radius: 10px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-family: inherit;
}

.sp-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.sp-btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #ffffff;
    box-shadow: 0 4px 14px rgba(102, 126, 234, 0.4);
}

.sp-btn-primary:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.5);
}

.sp-btn-primary:active:not(:disabled) {
    transform: translateY(0);
}

.sp-btn-secondary {
    background: #f3f4f6;
    color: #374151;
}

.sp-btn-secondary:hover:not(:disabled) {
    background: #e5e7eb;
}

.sp-btn-spinner {
    display: none;
}

.sp-btn.sp-loading .sp-btn-text {
    display: none;
}

.sp-btn.sp-loading .sp-btn-spinner {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.sp-spin {
    animation: spin 1s linear infinite;
}

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

/* USSD Code Display */
.sp-ussd-code {
    padding: 24px;
    background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
    border: 2px solid #fbbf24;
    border-radius: 14px;
    margin: 22px 0;
    text-align: center;
    box-shadow: 0 4px 12px rgba(251, 191, 36, 0.2);
}

.sp-ussd-code-label {
    font-size: 14px;
    color: #92400e;
    margin-bottom: 10px;
    font-weight: 600;
}

.sp-ussd-code-value {
    font-size: 28px;
    font-weight: 700;
    color: #78350f;
    letter-spacing: 3px;
    font-family: 'Courier New', monospace;
}

/* Mobile Responsive */
@media (max-width: 640px) {
    #sp-payment-modal .sp-modal-content {
        margin: 20px auto;
        width: 95%;
        border-radius: 12px;
    }
    
    #sp-payment-modal .sp-modal-header {
        padding: 24px 20px 20px;
    }
    
    #sp-payment-form-container,
    #sp-payment-status-container {
        padding: 20px;
    }
    
    .sp-modal-actions {
        flex-direction: column-reverse;
    }
    
    .sp-btn {
        width: 100%;
    }
    
    .sp-operators-grid {
        grid-template-columns: 1fr;
    }
    
    .sp-payment-summary-amount {
        font-size: 26px;
    }
}

/* Prevent body scroll when modal is open */
body.sp-modal-open {
    overflow: hidden;
}
