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

html {
    scroll-behavior: smooth;
    overflow-x: auto;
    overflow-y: auto;
}

:root {
    --primary-color: #2563eb;
    --primary-dark: #1e40af;
    --success-color: #10b981;
    --error-color: #ef4444;
    --bg-color: #f8fafc;
    --card-bg: #ffffff;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --border-color: #e2e8f0;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    padding: 20px;
    color: var(--text-primary);
    overflow-x: auto;
    overflow-y: auto;
    /* 确保滚动条始终可见 */
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.3) rgba(255, 255, 255, 0.1);
}

.container {
    max-width: 1000px;
    margin: 0 auto;
    min-height: 100vh; /* 确保容器有最小高度 */
    display: flex;
    flex-direction: column; /* 垂直布局 */
    position: relative; /* 确保定位正确 */
    padding-bottom: 100px; /* 大幅增加底部内边距，为页脚留出足够空间 */
}

header {
    text-align: center;
    color: white;
    margin-bottom: 30px;
    padding: 20px;
}

header h1 {
    font-size: 2.5rem;
    margin-bottom: 10px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.2);
}

.subtitle {
    font-size: 1.1rem;
    opacity: 0.9;
}

/* 主布局 - 左右结构 */
.main-layout {
    display: flex;
    gap: 20px;
    align-items: flex-start; /* 改为flex-start，避免强制拉伸 */
    flex: 1; /* 填充剩余空间 */
    flex-direction: row-reverse; /* 将历史记录面板移到右侧 */
    flex-wrap: wrap; /* 允许换行 */
    margin-bottom: 50px; /* 增加底部间距，为页脚留出更多空间 */
}

.left-panel {
    flex: 1; /* 占据剩余空间 */
}

.right-panel {
    flex: 0 0 450px; /* 进一步增加宽度 */
    position: sticky;
    top: 20px;
    height: fit-content;
    min-height: 600px; /* 增加20%：500px * 1.2 = 600px */
    max-height: 90vh; /* 进一步增加最大高度以显示5条记录 */
}

.history-panel {
    background: var(--card-bg);
    border-radius: 16px;
    box-shadow: var(--shadow-lg);
    padding: 20px;
    height: 100%; /* 填满整个右侧面板 */
    min-height: 600px; /* 增加20%：500px * 1.2 = 600px */
    max-height: 90vh; /* 进一步增加高度以显示5条记录 */
    overflow-y: auto; /* 确保有滑动条 */
    display: flex;
    flex-direction: column;
    /* Firefox滚动条支持 */
    scrollbar-width: thin;
    scrollbar-color: #cbd5e1 #f1f1f1;
}

.history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 2px solid var(--border-color);
}

.history-header h2 {
    color: var(--primary-color);
    font-size: 1.5rem;
    margin: 0;
}

/* 收起按钮样式已移除 */

.calculator-wrapper {
    background: var(--card-bg);
    border-radius: 16px;
    box-shadow: var(--shadow-lg);
    padding: 25px; /* 减少内边距 */
    margin-bottom: 15px; /* 减少底部间距 */
}

/* 方法选择器样式已移除 */

.calc-section {
    animation: fadeIn 0.3s ease;
}

.calc-section.hidden {
    display: none;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.calc-section h2 {
    color: var(--primary-color);
    margin-bottom: 15px; /* 增加底部间距 */
    margin-top: 0; /* 移除顶部间距 */
    font-size: 1.8rem;
}

.info {
    color: var(--text-secondary);
    margin-bottom: 20px; /* 减少底部间距 */
    font-size: 0.95rem;
}

.input-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr); /* 改为三列布局 */
    gap: 15px; /* 统一间距 */
    margin-bottom: 15px; /* 统一底部间距 */
    margin-top: 15px; /* 统一顶部间距 */
}

.input-group {
    display: flex;
    flex-direction: column;
    min-width: 0; /* 防止内容溢出 */
}

.input-group.full-width {
    grid-column: 1 / -1;
    margin-bottom: 15px; /* 统一底部间距 */
}

.input-group label {
    font-weight: 600;
    margin-bottom: 12px; /* 增加标签底部间距 */
    color: var(--text-primary);
    font-size: 0.9rem;
    line-height: 1.2; /* 优化行高 */
    word-break: break-word; /* 允许标签换行 */
    hyphens: auto; /* 自动断词 */
}

.input-group input {
    padding: 14px; /* 增加内边距 */
    border: 2px solid var(--border-color);
    border-radius: 8px;
    font-size: 1rem;
    transition: all 0.3s ease;
    width: 100%; /* 确保填满容器 */
    box-sizing: border-box;
}

.input-group input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.input-group input::placeholder {
    color: #cbd5e1;
}

.input-group select {
    padding: 14px; /* 增加内边距 */
    border: 2px solid var(--border-color);
    border-radius: 8px;
    font-size: 1rem;
    background: white;
    transition: all 0.3s ease;
    cursor: pointer;
    width: 100%; /* 确保填满容器 */
    box-sizing: border-box;
}

.input-group select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.input-group select[readonly] {
    background-color: #f8fafc;
    color: #64748b;
    cursor: not-allowed;
}

/* 隐藏字段样式 */
.hidden-field {
    display: none !important;
}

.calc-btn {
    width: 100%;
    padding: 16px 28px; /* 增加内边距 */
    background: linear-gradient(135deg, var(--primary-color), var(--primary-dark));
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: var(--shadow);
    margin-top: 15px; /* 统一顶部间距 */
}

.calc-btn:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

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

.result-section {
    margin-top: 15px; /* 减少顶部间距 */
    padding: 20px;
    background: linear-gradient(135deg, #f0f9ff 0%, #e0f2fe 100%);
    border-radius: 8px;
    border-left: 4px solid var(--primary-color);
}

.result-section.show {
    animation: slideIn 0.4s ease;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(-20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.result-section h3 {
    color: var(--primary-color);
    margin-bottom: 15px;
    font-size: 1.3rem;
}

.result-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px;
    margin-bottom: 10px;
    background: white;
    border-radius: 6px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.result-label {
    font-weight: 600;
    color: var(--text-primary);
}

.result-value {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--success-color);
}

.error-message {
    background: #fee2e2;
    border-left-color: var(--error-color);
    color: var(--error-color);
    padding: 15px;
    border-radius: 8px;
    font-weight: 600;
}

.info-message {
    background: #eff6ff;
    border-left: 4px solid var(--primary-color);
    color: var(--primary-color);
    padding: 15px;
    border-radius: 8px;
    font-weight: 600;
}

.formula-info {
    margin-top: 15px; /* 统一顶部间距 */
    padding: 15px; /* 减少内边距 */
    background: #f8fafc;
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

.formula-info h3 {
    color: var(--text-primary);
    margin-bottom: 10px;
    font-size: 1.1rem;
}

.formula-info p {
    font-family: 'Courier New', monospace;
    color: var(--text-secondary);
    font-size: 0.95rem;
    line-height: 1.6;
}

/* 历史记录样式 */
.history-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    margin-top: 10px;
}

.history-section h3 {
    color: var(--primary-color);
    margin-bottom: 20px;
    font-size: 1.3rem;
    text-align: center;
}

.history-list {
    display: flex;
    flex-direction: column;
    gap: 8px; /* 减少间距 */
    flex: 1;
    overflow-y: auto; /* 确保有滑动条 */
    padding-right: 5px;
    min-height: 480px; /* 增加20%：400px * 1.2 = 480px */
    max-height: 70vh; /* 进一步增加高度以显示5条记录 */
}

.history-item {
    background: #f8fafc;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 10px; /* 减少内边距 */
    transition: all 0.3s ease;
    flex-shrink: 0;
    margin-bottom: 6px; /* 进一步减少底部间距 */
    min-height: 60px; /* 进一步减少最小高度，确保5条记录能显示 */
}

.history-item:hover {
    box-shadow: var(--shadow);
    transform: translateX(5px);
}

.history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border-color);
}

.history-number {
    font-weight: 700;
    color: var(--primary-color);
    font-size: 1.1rem;
}

.history-sample-id {
    font-weight: 600;
    color: var(--success-color);
    background: rgba(16, 185, 129, 0.1);
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.9rem;
}

.history-time {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.history-content {
    display: flex;
    flex-direction: column;
    gap: 2px; /* 进一步减少间距，确保5条记录能显示 */
}

.history-inputs,
.history-results {
    font-size: 0.75rem; /* 进一步减小字体 */
    color: var(--text-primary);
    line-height: 1.1; /* 进一步减少行高 */
}

.history-inputs strong,
.history-results strong {
    color: var(--primary-color);
    margin-right: 5px;
}

.history-empty,
.history-error {
    text-align: center;
    padding: 40px;
    color: var(--text-secondary);
}

.history-error {
    color: var(--error-color);
}

.error-hint {
    font-size: 0.85rem;
    margin-top: 10px;
    opacity: 0.8;
}

/* 滚动条样式 */
/* 整个页面滚动条 */
body::-webkit-scrollbar {
    width: 12px;
}

body::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 6px;
}

body::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.3);
    border-radius: 6px;
    border: 2px solid transparent;
    background-clip: content-box;
}

body::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.5);
}

/* 历史记录区域滚动条 */
.history-panel::-webkit-scrollbar,
.history-section::-webkit-scrollbar,
.history-list::-webkit-scrollbar {
    width: 8px;
}

.history-panel::-webkit-scrollbar-track,
.history-section::-webkit-scrollbar-track,
.history-list::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

.history-panel::-webkit-scrollbar-thumb,
.history-section::-webkit-scrollbar-thumb,
.history-list::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 4px;
}

.history-panel::-webkit-scrollbar-thumb:hover,
.history-section::-webkit-scrollbar-thumb:hover,
.history-list::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

footer {
    text-align: center;
    color: white;
    padding: 20px;
    opacity: 0.9;
    margin-top: 50px; /* 增加顶部间距，避免被遮挡 */
    position: relative; /* 确保页脚位置正确 */
    z-index: 100; /* 提高层级，确保页脚在最上层 */
    background: transparent; /* 透明背景 */
    width: 100%; /* 确保宽度 */
    clear: both; /* 清除浮动 */
}

/* 响应式设计 */
@media (max-width: 1024px) {
    /* 平板和小屏幕：改为上下布局 */
    .main-layout {
        flex-direction: column; /* 小屏幕使用正常顺序 */
        align-items: stretch;
        flex-wrap: nowrap;
    }
    
    .left-panel {
        flex: none;
        position: static;
    }
    
    .right-panel {
        flex: none;
        position: static;
    }
    
    .history-panel {
        min-height: 300px;
        max-height: 50vh;
    }
    
    .input-grid {
        grid-template-columns: repeat(2, 1fr); /* 平板保持两列 */
    }
    
    body {
        overflow-x: hidden; /* 小屏幕隐藏水平滚动 */
    }
}

@media (max-width: 768px) {
    header h1 {
        font-size: 2rem;
    }
    
    .calculator-wrapper {
        padding: 20px;
    }
    
    .history-panel {
        padding: 15px;
    }
    
    /* 方法选择器样式已移除 */
    
    .input-grid {
        grid-template-columns: 1fr; /* 小屏幕时改为单列 */
    }
    
    .result-item {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }
}

/* 打印样式 */
@media print {
    body {
        background: white;
    }
    
    .method-selector,
    .calc-btn {
        display: none;
    }
    
    .calculator-wrapper {
        box-shadow: none;
    }
}

