/**
 * CSS cho public-facing functionality của Loan Calculator Plugin
 * Tối ưu hóa và dọn dẹp code - cải thiện structure và performance
 */

/* CSS Variables */
:root {
    --primary-color   : #667eea;
    --success-color   : #28a745;
    --danger-color    : #dc3545;
    --warning-color   : #ffc107;
    --info-color      : #17a2b8;
    --light-bg        : #f8f9fa;
    --border-color    : #e1e5e9;
    --border-light    : #f0f0f0;
    --text-color      : #333;
    --text-muted      : #666;
    --text-light      : #555;
    --border-radius   : 8px;
    --border-radius-sm: 4px;
    --border-radius-lg: 10px;
    --box-shadow      : 0 2px 10px rgba(0, 0, 0, 0.1);
    --box-shadow-lg   : 0 10px 30px rgba(0, 0, 0, 0.3);
    --transition      : all 0.3s ease;
    --font-size-sm    : 13px;
    --font-size-base  : 14px;
    --font-size-md    : 16px;
    --font-size-lg    : 18px;
    --font-size-xl    : 20px;
    --font-size-xxl   : 24px;
    --spacing-xs      : 5px;
    --spacing-sm      : 8px;
    --spacing-md      : 15px;
    --spacing-lg      : 20px;
    --spacing-xl      : 30px;
}

/* Base Container */
.loan-calculator-container {
    background   : #fff;
    border       : 1px solid var(--border-color);
    border-radius: var(--border-radius);
    box-shadow   : var(--box-shadow);
    padding      : var(--spacing-lg);
}

/* Header Styles */
.loan-calculator-header {
    text-align     : center;
    display        : flex;
    flex-direction : column;
    align-items    : center;
    justify-content: center;
}

.loan-calculator-title {
    font-size     : var(--font-size-xxl);
    font-weight   : 600;
    margin        : 0;
    color         : var(--text-color);
    text-transform: uppercase;
}

.loan-calculator-subtitle {
    color    : var(--text-color);
    margin   : 0;
    font-size: var(--font-size-md);
}

/* Form Sections */
.form-section {
    margin-bottom : var(--spacing-xl);
    padding-bottom: var(--spacing-lg);
    border-bottom : 1px solid var(--border-light);
}

.loan-form {
    margin-bottom: 0;
}

.loan-form .form-section:last-child {
    border-bottom: none;
}

.loan-form .form-section h4,
.consultation-popup-form .form-section h4 {
    color      : var(--text-color);
    font-size  : var(--font-size-lg);
    font-weight: 600;
}

.consultation-popup-form .form-section h4 {
    font-size: var(--font-size-md);
}

.consultation-popup-form .form-section {
    border-bottom: 1px solid var(--border-light);
}

/* Form Layout */
.loan-form .form-row,
.consultation-popup-form .form-row {
    display      : flex;
    gap          : var(--spacing-lg);
    margin-bottom: var(--spacing-lg);
}

.consultation-popup-form .form-row {
    gap          : var(--spacing-md);
    margin-bottom: var(--spacing-md);
}

.loan-form .form-row:last-child,
.consultation-popup-form .form-row:last-child {
    margin-bottom: 0;
}

.loan-form .form-group,
.consultation-popup-form .form-group {
    flex         : 1;
    margin-bottom: 0;
}

.loan-form .form-group label,
.consultation-popup-form .form-group label {
    display      : block;
    margin-bottom: var(--spacing-sm);
    font-weight  : 500;
    color        : var(--text-light);
}

.consultation-popup-form .form-group label {
    margin-bottom: 6px;
    font-size    : var(--font-size-base);
}

/* Form Controls */
.consultation-popup-form {
    margin-top: 20px;
}

.loan-form .form-control,
.consultation-popup-form .form-control {
    width        : 100%;
    padding      : 12px 16px;
    border       : 2px solid var(--border-color);
    border-radius: 6px;
    font-size    : var(--font-size-md);
    height       : auto;
    transition   : var(--transition);
    box-sizing   : border-box;
    margin       : 0;
}

.consultation-popup-form .form-control {
    padding      : 10px 12px;
    border       : 1px solid #ddd;
    border-radius: var(--border-radius-sm);
    font-size    : var(--font-size-base);
}

.loan-form .form-control:focus,
.consultation-popup-form .form-control:focus {
    outline     : none;
    border-color: var(--primary-color);
    box-shadow  : 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.consultation-popup-form .form-control:focus {
    box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.1);
}

.consultation-popup-form textarea.form-control {
    resize    : vertical;
    min-height: 80px;
}

.loan-form .form-help {
    display   : block;
    margin-top: var(--spacing-xs);
    font-size : var(--font-size-sm);
    color     : var(--text-muted);
}

.consultation-popup-form .form-description {
    margin     : 0;
    color      : var(--text-muted);
    font-size  : var(--font-size-base);
    line-height: 1.4;
}

.consultation-popup-form .required {
    color: var(--danger-color);
}

/* Form Actions & Buttons */
.loan-form .form-actions,
.consultation-form-content,
.consultation-popup-form .form-actions {
    text-align: center;
}

.loan-form .btn,
.consultation-form .btn,
.consultation-popup-form .btn-submit,
.email-form button {
    background     : var(--primary-color);
    color          : white;
    border         : none;
    font-size      : var(--font-size-md);
    font-weight    : 600;
    cursor         : pointer;
    transition     : var(--transition);
    text-decoration: none !important;
    display        : inline-block;
    margin         : 0;
}

.consultation-form .btn,
.consultation-popup-form .btn-submit {
    background: var(--success-color);
}

.loan-form .btn-loading .spinner {
    display         : inline-block;
    width           : 16px;
    height          : 16px;
    border          : 2px solid #ffffff;
    border-radius   : 50%;
    border-top-color: transparent;
    animation       : spin 1s ease-in-out infinite;
    margin-right    : var(--spacing-sm);
}

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

/* Results Section */
.loan-calculator-results {
    margin-top : var(--spacing-xl);
    padding-top: var(--spacing-xl);
    border-top : 2px solid var(--border-light);
}

.results-header h4 {
    margin     : 0 0 var(--spacing-lg) 0;
    color      : var(--text-color);
    font-size  : var(--font-size-xl);
    font-weight: 600;
}

/* Bank Comparison */
.bank-comparison {
    margin-bottom: var(--spacing-xl);
}

.bank-option {
    background   : var(--light-bg);
    border       : 2px solid #e9ecef;
    border-radius: var(--border-radius);
    padding      : var(--spacing-lg);
    margin-bottom: var(--spacing-md);
    cursor       : pointer;
    transition   : var(--transition);
}

.bank-option:hover,
.bank-option.selected {
    border-color: var(--primary-color);
    background  : #f0f4ff;
}

.bank-option.selected {
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.bank-info {
    display        : flex;
    justify-content: space-between;
    align-items    : center;
}

.bank-name {
    font-weight: 600;
    color      : var(--text-color);
    font-size  : var(--font-size-md);
}

.bank-rate {
    color      : var(--primary-color);
    font-weight: 600;
    font-size  : var(--font-size-lg);
}

.bank-payment {
    color      : var(--success-color);
    font-weight: 600;
    font-size  : var(--font-size-md);
}

/* Summary Components */
.details-summary {
    display      : flex;
    gap          : var(--spacing-lg);
    margin-bottom: var(--spacing-xl);
    background   : var(--light-bg);
    padding      : var(--spacing-lg);
    border-radius: var(--border-radius);
}

.summary-item {
    flex      : 1;
    text-align: center;
}

.summary-label {
    font-size    : var(--font-size-base);
    color        : var(--text-muted);
    margin-bottom: var(--spacing-sm);
}

.summary-value {
    font-size  : var(--font-size-xl);
    font-weight: 600;
    color      : var(--text-color);
}

.summary-row {
    display        : flex;
    justify-content: space-between;
    align-items    : center;
    padding        : 10px 0;
    border-bottom  : 1px solid var(--border-light);
}

.summary-row:last-child {
    border-bottom: none;
}

.summary-row.highlight {
    background   : var(--light-bg);
    padding      : 10px;
    border-radius: 6px;
    border       : 2px solid var(--success-color);
}

.summary-row .label {
    font-weight: 500;
    color      : var(--text-light);
}

.summary-row .value {
    font-weight: 600;
    color      : var(--text-color);
}

.summary-row.highlight .value {
    color    : var(--success-color);
    font-size: var(--font-size-lg);
}

.calculation-summary {
    margin: 0;
}

.summary-info h4 {
    color        : var(--text-color);
    font-size    : var(--font-size-lg);
    font-weight  : 600;
    border-bottom: 2px solid var(--primary-color);
}

/* Chart and Schedule */
.chart-container {
    margin    : var(--spacing-xl) 0;
    text-align: center;
}

.payment-schedule h5 {
    margin     : 0 0 var(--spacing-md) 0;
    color      : var(--text-color);
    font-size  : var(--font-size-md);
    font-weight: 600;
}

.schedule-table-container {
    max-height: 400px;
    overflow-y: auto;
}

.schedule-table {
    width          : 100%;
    border-collapse: collapse;
}

.schedule-table th,
.schedule-table td {
    padding   : 12px;
    text-align: center;
}

.schedule-table th {
    background : var(--light-bg);
    font-weight: 600;
    color      : var(--text-light);
    position   : sticky;
    top        : 0;
}

/* Email & Consultation Forms */
.email-form,
.consultation-form {
    margin-top   : var(--spacing-xl);
    padding      : var(--spacing-lg);
    background   : var(--light-bg);
    border-radius: var(--border-radius);
}

.email-form input {
    margin: 0;
}

.email-form-content {
    display    : flex;
    gap        : var(--spacing-md);
    align-items: flex-end;
}

.email-form .form-group {
    flex         : 1;
    margin-bottom: 0;
}

.consultation-form h5 {
    margin     : 0 0 var(--spacing-md) 0;
    color      : var(--text-color);
    font-size  : var(--font-size-lg);
    font-weight: 600;
}

.consultation-description {
    margin-bottom: var(--spacing-lg);
    color        : var(--text-muted);
    font-size    : var(--font-size-base);
    line-height  : 1.5;
}

/* Popup Styles */
.loan-calculator-popup {
    position: fixed;
    top     : 0;
    left    : 0;
    width   : 100%;
    height  : 100%;
    z-index : 9999;
}

.popup-overlay {
    position  : absolute;
    top       : 0;
    left      : 0;
    width     : 100%;
    height    : 100%;
    background: rgba(0, 0, 0, 0.5);
}

.popup-content {
    position     : absolute;
    top          : 50%;
    left         : 50%;
    transform    : translate(-50%, -50%);
    background   : #fff;
    border-radius: var(--border-radius-lg);
    box-shadow   : var(--box-shadow-lg);
    max-width    : 600px;
    width        : 90%;
    max-height   : 90vh;
    padding      : var(--spacing-lg);
    overflow-y   : auto;
}

.popup-header {
    display        : flex;
    justify-content: space-between;
    align-items    : center;
    color          : white;
    height         : 40px;
    margin-bottom  : 20px;
}

.popup-header h3 {
    margin     : 0;
    font-size  : var(--font-size-xl);
    font-weight: 600;
}

.popup-close {
    background     : none;
    border         : none;
    color          : var(--text-color);
    font-size      : 40px;
    cursor         : pointer;
    padding        : 0;
    margin         : 0;
    width          : 20px;
    height         : 20px !important;
    display        : flex;
    align-items    : center;
    justify-content: center;
    border-radius  : 50%;
    transition     : background-color 0.2s ease;
}

.popup-close:hover {
    background-color: rgba(255, 255, 255, 0.2);
}

/* Loading States */
select:disabled,
.form-control:disabled {
    background-color: #f5f5f5;
    color           : #999;
    cursor          : not-allowed;
    opacity         : 0.7;
}

select option[value=""]:first-child {
    font-style: italic;
    color     : var(--text-muted);
}

.form-control:disabled {
    background-image   : url('data:image/svg+xml;charset=US-ASCII,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 4 5"><path fill="%23666" d="M2 0L0 2h4zm0 5L0 3h4z"/></svg>');
    background-repeat  : no-repeat;
    background-position: right 8px center;
    background-size    : 12px;
}

/* Theme Variations */
.theme-modern .loan-calculator-header {
    background: linear-gradient(135deg, var(--primary-color) 0%, #764ba2 100%);
}

.theme-minimal .loan-calculator-container {
    border    : none;
    box-shadow: none;
}

.theme-minimal .loan-calculator-header {
    background: var(--text-color);
}

/* Body State */
body.popup-open {
    overflow: hidden;
}

/* Responsive Design */
@media (max-width: 768px) {
    .loan-calculator-container {
        margin       : 10px;
        border-radius: 0;
    }

    .loan-form .form-row,
    .consultation-popup-form .form-row,
    .details-summary,
    .email-form-content {
        flex-direction: column;
        gap           : var(--spacing-md);
    }

    .schedule-table-container {
        font-size: var(--font-size-base);
    }

    .schedule-table th,
    .schedule-table td {
        padding: var(--spacing-sm) 6px;
    }

    .popup-content {
        width     : 95%;
        max-height: 95vh;
        margin    : 0;
    }

    .popup-header {
        padding: var(--spacing-md) var(--spacing-lg);
    }

    .popup-header h3 {
        font-size: var(--font-size-lg);
    }

    .popup-body {
        padding: var(--spacing-lg);
    }

    .summary-row {
        flex-direction: column;
        align-items   : flex-start;
        gap           : var(--spacing-xs);
    }

    .summary-row.highlight {
        margin : 10px -10px;
        padding: 12px;
    }
}