* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
}

.container {
    width: 100%;
    max-width: 1200px;
    background: white;
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    overflow: hidden;
}

h1 {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    text-align: center;
    padding: 40px;
    font-size: 32px;
    font-weight: 600;
}

.calculator-wrapper {
    padding: 50px;
    display: flex;
    gap: 40px;
    align-items: stretch;
    min-height: 600px; /* 固定最小高度，避免计算前后框架变化 */
}

.left-section,
.right-section {
    flex: 1;
    min-width: 0; /* 确保flex子元素不会溢出 */
    min-height: 500px; /* 固定最小高度 */
    display: flex;
    flex-direction: column;
    margin-bottom: 0;
}

/* 结果区域始终占据空间，即使没有结果 */
.right-section.result-section {
    display: flex !important;
    flex-direction: column;
}

.result-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    color: #999;
}

/* 没有结果时的提示 */
.result-section:not(.has-result) .result-content::before {
    content: '点击"开始计算"查看结果';
    font-size: 18px;
}

.result-section.has-result .result-content {
    justify-content: flex-start;
    align-items: stretch;
    text-align: left;
}

.result-section.has-result .result-content::before {
    display: none;
}

.input-section,
.result-section {
    margin-bottom: 30px;
}

h2 {
    color: #333;
    font-size: 24px;
    font-weight: 600;
    margin-bottom: 25px;
    padding-bottom: 12px;
    border-bottom: 2px solid #667eea;
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    color: #555;
    font-size: 16px;
    font-weight: 500;
    margin-bottom: 10px;
}

/* 月份输入框 */
.form-group-range {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.range-controls {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
}

.months-input {
    width: 15%;
    min-width: 50px;
    max-width: 90px;
    padding: 6px 10px;
    border: 2px solid #667eea;
    border-radius: 6px;
    color: #667eea;
    font-weight: 600;
    font-size: 16px;
    text-align: center;
    transition: all 0.3s;
    flex-shrink: 0;
}

.months-input:focus {
    outline: none;
    border-color: #764ba2;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.2);
}

.months-input:hover {
    border-color: #764ba2;
}

.months-unit {
    color: #667eea;
    font-weight: 500;
    font-size: 16px;
    flex-shrink: 0;
}

/* 范围滑块样式调整 */
.form-group-range .range-slider {
    flex: 1;
    min-width: 0;
    margin: 0;
}

/* 滑块样式 */
.range-slider {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 10px;
    background: linear-gradient(to right, #667eea, #764ba2);
    border-radius: 5px;
    outline: none;
    opacity: 0.9;
    transition: opacity 0.3s;
    cursor: pointer;
    margin: 15px 0;
}

.range-slider:hover {
    opacity: 1;
}

.range-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 24px;
    height: 24px;
    background: white;
    border: 4px solid #667eea;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.4);
    transition: all 0.3s;
}

.range-slider::-webkit-slider-thumb:hover {
    transform: scale(1.1);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.6);
}

.range-slider::-moz-range-thumb {
    width: 24px;
    height: 24px;
    background: white;
    border: 4px solid #667eea;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.4);
    transition: all 0.3s;
}

.range-slider::-moz-range-thumb:hover {
    transform: scale(1.1);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.6);
}

.range-slider::-moz-range-track {
    height: 10px;
    background: linear-gradient(to right, #667eea, #764ba2);
    border-radius: 5px;
}

/* 滑块标签 */
.range-labels {
    display: flex;
    justify-content: space-between;
    margin-top: -5px;
}

.range-labels span {
    color: #999;
    font-size: 14px;
    font-weight: 500;
}

/* 贷款类型平铺样式 */
.loan-type-options {
    display: flex;
    gap: 20px;
    margin-top: 12px;
}

.type-option {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 18px 24px;
    border: 2px solid #e0e0e0;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.3s;
    background: #f9f9f9;
    position: relative;
}

.type-option:hover {
    border-color: #667eea;
    background: #f0f4ff;
}

.type-option input[type="radio"] {
    display: none;
}

.type-option input[type="radio"]:checked + span {
    color: #667eea;
    font-weight: 600;
}

.type-option.selected {
    border-color: #667eea;
    background: #f0f4ff;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.type-option span {
    color: #555;
    font-size: 16px;
    transition: all 0.3s;
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 16px 20px;
    border: 2px solid #e0e0e0;
    border-radius: 10px;
    font-size: 18px;
    transition: all 0.3s;
    background: #f9f9f9;
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: #667eea;
    background: white;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.form-group select {
    cursor: pointer;
    background: white;
}

.calculate-btn {
    width: 100%;
    padding: 18px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 10px;
    font-size: 18px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    margin-top: 10px;
}

.calculate-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(102, 126, 234, 0.4);
}

.calculate-btn:active {
    transform: translateY(0);
}

/* 结果展示样式 */
.result-content {
    background: #f8f9ff;
    border-radius: 14px;
    padding: 28px;
}

/* 环形图样式 */
.donut-chart {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 20px;
    margin: 20px 0;
    padding: 20px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.donut-chart-svg {
    width: 160px;
    height: 160px;
    transform: rotate(-90deg);
    flex-shrink: 0;
}

.donut-chart-legend {
    display: flex;
    flex-direction: column;
    gap: 15px;
    flex: 1;
    min-width: 0; /* 防止内容溢出 */
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 0;
}

.legend-color {
    width: 24px;
    height: 24px;
    border-radius: 4px;
    flex-shrink: 0;
}

.legend-label {
    color: #666;
    font-size: 16px;
    white-space: nowrap;
    flex-shrink: 0;
}

.legend-value {
    color: #333;
    font-size: 16px;
    font-weight: 600;
    margin-left: 8px;
    white-space: nowrap;
}

.legend-percentage {
    color: #f59e0b; /* 黄色 */
    font-size: 16px;
    font-weight: 600;
    margin-left: 5px;
    white-space: nowrap;
}

.result-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 18px 0;
    border-bottom: 1px solid #e0e0e0;
}

.result-item:last-child {
    border-bottom: none;
}

.result-label {
    color: #666;
    font-size: 16px;
}

.result-value {
    color: #333;
    font-size: 24px;
    font-weight: 700;
    color: #667eea;
}

.highlight {
    color: #764ba2 !important;
}

/* 表格样式 */
.details-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 15px;
    background: white;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.details-table thead {
    display: table;
    width: 100%;
    table-layout: fixed;
}

.details-table tbody {
    display: block;
    max-height: 400px;
    overflow-y: auto;
    overflow-x: hidden;
    table-layout: fixed;
}

.details-table tr {
    display: table;
    width: 100%;
    table-layout: fixed;
}

.details-table th {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 12px;
    text-align: left;
    font-weight: 600;
    font-size: 14px;
    width: 20%; /* 每列20%宽度 */
}

.details-table td {
    padding: 12px;
    border-bottom: 1px solid #e0e0e0;
    font-size: 14px;
    color: #555;
    width: 20%; /* 每列20%宽度 */
}

.details-table tr:hover {
    background: #f8f9ff;
}

.details-table tr:last-child td {
    border-bottom: none;
}

.table-container {
    margin-top: 15px;
/*    max-height: 400px; */
    overflow-y: auto;
}

/* 错误提示 */
.error-message {
    background: #fee;
    color: #c33;
    padding: 12px;
    border-radius: 8px;
    border-left: 4px solid #c33;
    font-size: 14px;
}

/* 响应式 - 平板和手机 */
@media (max-width: 768px) {
    body {
        padding: 10px;
    }

    .container {
        border-radius: 12px;
    }

    h1 {
        font-size: 26px;
        padding: 25px;
    }

    .calculator-wrapper {
        padding: 25px;
        gap: 25px;
        min-height: auto; /* 移动端不需要固定高度 */
    }

    .left-section,
    .right-section {
        min-height: auto;
    }

    .calculator-wrapper {
        flex-direction: column;
    }
}

/* 响应式 - 小屏手机 */
@media (max-width: 480px) {
    body {
        padding: 5px;
    }

    .container {
        border-radius: 10px;
    }

    h1 {
        font-size: 22px;
        padding: 20px;
    }

    h2 {
        font-size: 18px;
        margin-bottom: 20px;
        padding-bottom: 10px;
    }

    .calculator-wrapper {
        padding: 20px;
        gap: 20px;
    }

    /* 表单元素 */
    .form-group label {
        font-size: 14px;
    }

    .form-group input,
    .form-group select {
        padding: 14px 16px;
        font-size: 16px;
    }

    /* 贷款期限 */
    .range-controls {
        gap: 8px;
        flex-wrap: wrap;
    }

    /* 月份输入框 */
    .months-input {
        width: 20%;
        min-width: 55px;
        max-width: 70px;
        font-size: 14px;
        padding: 4px 8px;
    }

    .months-unit {
        font-size: 14px;
    }

    /* 贷款类型选项 */
    .loan-type-options {
        gap: 12px;
    }

    .type-option {
        padding: 14px 16px;
    }

    .type-option span {
        font-size: 14px;
    }

    /* 滑块 */
    .range-slider {
        height: 8px;
    }

    .range-slider::-webkit-slider-thumb {
        width: 20px;
        height: 20px;
    }

    .range-slider::-moz-range-thumb {
        width: 20px;
        height: 20px;
    }

    .range-labels span {
        font-size: 12px;
    }

    /* 按钮 */
    .calculate-btn {
        padding: 16px;
        font-size: 16px;
    }

    /* 结果区域 */
    .result-content {
        padding: 20px;
    }

    .result-item {
        padding: 14px 0;
    }

    .result-label {
        font-size: 14px;
    }

    .result-value {
        font-size: 18px;
    }

    /* 环形图 */
    .donut-chart {
        flex-direction: column;
        gap: 20px;
        margin: 15px 0;
        padding: 20px;
    }

    .donut-chart-svg {
        width: 180px;
        height: 180px;
    }

    .donut-chart-legend {
        width: 100%;
    }

    .legend-item {
        padding: 8px 0;
    }

    .legend-color {
        width: 20px;
        height: 20px;
    }

    .legend-label {
        font-size: 14px;
    }

    .legend-value {
        font-size: 16px;
    }

    .legend-percentage {
        font-size: 14px;
    }

    /* 表格 */
    .details-table {
        font-size: 12px;
    }

    .details-table th,
    .details-table td {
        padding: 8px 6px;
        font-size: 12px;
    }

    .table-container {
        max-height: 300px;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* 滚动条美化（移动端） */
    .table-container::-webkit-scrollbar {
        width: 4px;
    }

    .table-container::-webkit-scrollbar-track {
        background: #f1f1f1;
    }

    .table-container::-webkit-scrollbar-thumb {
        background: #667eea;
        border-radius: 2px;
    }
}

/* 超小屏幕适配 */
@media (max-width: 360px) {
    h1 {
        font-size: 20px;
        padding: 15px;
    }

    h2 {
        font-size: 16px;
    }

    /* 贷款期限 */
    .range-controls {
        flex-wrap: nowrap;
    }

    .months-input {
        width: 25%;
        min-width: 50px;
        max-width: 60px;
    }

    .loan-type-options {
        flex-direction: column;
        gap: 10px;
    }

    .type-option {
        width: 100%;
    }

    .donut-chart-svg {
        width: 150px;
        height: 150px;
    }
}
