/* 全局样式 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #f5f5f5;
    color: #333;
    line-height: 1.6;
    overflow-x: hidden; /* 防止水平滚动 */
}

#app {
    width: 100%;
    max-width: 1200px; /* 电脑版最大宽度 */
    margin: 0 auto;
    background: white;
    min-height: 100vh;
    position: relative;
    padding-bottom: 80px; /* 为底部导航留空间 */
}

/* 电脑版适配 */
@media (min-width: 768px) {
    #app {
        max-width: 800px;
        margin: 20px auto;
        border-radius: 16px;
        box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
        padding-bottom: 20px; /* 电脑版不需要底部导航空间 */
    }
}

/* 导航栏 */
.navbar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    background: white;
    border-top: 1px solid #eee;
    display: flex;
    z-index: 1000;
    max-width: 100vw; /* 防止溢出 */
}

.nav-item {
    flex: 1;
    padding: 12px 8px;
    text-align: center;
    font-size: 14px;
    color: #666;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.nav-item.active {
    color: #4ECDC4;
    font-weight: 500;
}

.nav-item:hover {
    background: #f8f9fa;
}

/* 电脑版导航 */
@media (min-width: 768px) {
    .navbar {
        position: static;
        border-top: none;
        border-bottom: 1px solid #eee;
        border-radius: 16px 16px 0 0;
        margin: 0;
    }
    
    .nav-item {
        padding: 16px 20px;
        font-size: 16px;
    }
}

/* 页面容器 */
.page {
    display: none;
    padding: 16px;
    width: 100%;
    max-width: 100%;
    overflow-x: hidden; /* 防止水平溢出 */
}

.page.active {
    display: block;
}

/* 电脑版页面 */
@media (min-width: 768px) {
    .page {
        padding: 24px 32px;
    }
}

/* 卡片样式 */
.card {
    background: white;
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 16px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    width: 100%;
    max-width: 100%;
    overflow: hidden; /* 防止内容溢出 */
}

/* 电脑版卡片 */
@media (min-width: 768px) {
    .card {
        padding: 24px;
        margin-bottom: 20px;
    }
}

.title {
    font-size: 18px;
    font-weight: bold;
    color: #333;
    margin-bottom: 8px;
}

.subtitle {
    font-size: 14px;
    color: #666;
    margin-bottom: 16px;
}

/* 个人资料 */
.profile-section {
    display: flex;
    align-items: center;
    gap: 16px;
}

.avatar-container {
    position: relative;
    cursor: pointer;
}

.avatar {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: #f0f0f0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 32px;
    border: 3px solid transparent;
    transition: all 0.2s ease;
}

.avatar-container:hover .avatar {
    border-color: #4ECDC4;
}

.edit-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.2s;
}

.avatar-container:hover .edit-overlay {
    opacity: 1;
}

.edit-icon {
    font-size: 16px;
}

.profile-info {
    flex: 1;
}

.profile-name {
    font-size: 16px;
    font-weight: bold;
    color: #333;
    margin-bottom: 4px;
}

.profile-birth {
    font-size: 14px;
    color: #666;
}

/* 图表控制 */
.chart-controls {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    width: 100%;
}

.control-item {
    flex: 1;
    min-width: 140px;
    max-width: 100%;
}

/* 电脑版图表控制 */
@media (min-width: 768px) {
    .chart-controls {
        gap: 20px;
    }
    
    .control-item {
        min-width: 200px;
    }
}

.control-label {
    display: block;
    font-size: 14px;
    color: #333;
    margin-bottom: 8px;
    font-weight: 500;
}

.picker-small {
    width: 100%;
    padding: 10px 12px;
    border: 2px solid #ddd;
    border-radius: 8px;
    font-size: 14px;
    color: #333;
    background: white;
    cursor: pointer;
}

.picker-small:focus {
    outline: none;
    border-color: #4ECDC4;
}

/* 图表容器 */
.chart-container {
    width: 100%;
    height: 350px;
    position: relative;
    background: #fafafa;
    border-radius: 10px;
    overflow: hidden;
    margin-bottom: 16px;
}

.chart-canvas {
    width: 100%;
    height: 100%;
    cursor: crosshair;
    display: block; /* 确保Canvas正确显示 */
}

/* 电脑版图表 */
@media (min-width: 768px) {
    .chart-container {
        height: 450px;
    }
}

/* 大屏幕图表 */
@media (min-width: 1024px) {
    .chart-container {
        height: 500px;
    }
}

/* 选中数据显示 */
.selected-data {
    background: #f8f9fa;
    border-radius: 10px;
    padding: 12px;
    margin-bottom: 16px;
    border-left: 4px solid #4ECDC4;
    width: 100%;
    overflow: hidden;
}

.selected-date {
    font-size: 16px;
    font-weight: bold;
    color: #333;
    text-align: center;
    margin-bottom: 12px;
}

.selected-values-compact {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    width: 100%;
}

.value-item-compact {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: white;
    border-radius: 6px;
    padding: 6px 8px;
    flex: 1;
    min-width: 90px;
    max-width: 100%;
    border: 1px solid rgba(0, 0, 0, 0.1);
    overflow: hidden;
}

/* 电脑版选中数据 */
@media (min-width: 768px) {
    .selected-data {
        padding: 16px;
    }
    
    .selected-values-compact {
        gap: 10px;
    }
    
    .value-item-compact {
        min-width: 120px;
        padding: 8px 12px;
    }
}

.value-color-small {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    margin-right: 6px;
    flex-shrink: 0;
}

.value-name-compact {
    font-size: 12px;
    color: #666;
    margin-right: 6px;
}

.value-number-compact {
    font-size: 12px;
    font-weight: bold;
    color: #333;
    margin-left: auto;
}

/* 成员管理 */
.members-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    flex-wrap: wrap;
    gap: 12px;
}

.btn-add {
    background: #4ECDC4;
    color: white;
    border: none;
    border-radius: 16px;
    padding: 8px 16px;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.btn-add:hover {
    background: #3bb5b8;
}

.members-row {
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: 100%;
}

.member-item {
    display: flex;
    align-items: center;
    padding: 12px;
    background: #f8f9fa;
    border-radius: 12px;
    position: relative;
    width: 100%;
    border: 2px solid #ddd;
    overflow: hidden;
}

/* 电脑版成员管理 */
@media (min-width: 768px) {
    .members-row {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
        gap: 16px;
    }
    
    .member-item {
        min-width: 300px;
    }
}

.me-item {
    border-color: #4ECDC4;
    background: #e8f8f7;
}

.person-info-compact {
    flex: 1;
    margin-left: 12px;
    min-width: 0;
}

.person-name {
    font-size: 14px;
    font-weight: bold;
    color: #333;
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.person-birth-compact {
    font-size: 12px;
    color: #666;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.member-tag {
    position: absolute;
    top: 8px;
    right: 12px;
    font-size: 10px;
    padding: 4px 8px;
    border-radius: 8px;
    background: #4ECDC4;
    color: white;
}

.member-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.delete-btn-small {
    width: 32px;
    height: 32px;
    border-radius: 6px;
    background: #FF6B6B;
    color: white;
    border: none;
    font-size: 16px;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(255, 107, 107, 0.3);
    transition: all 0.2s ease;
}

.delete-btn-small:hover {
    transform: scale(0.95);
}

/* 对比控制 */
.control-row-compact {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
    flex-wrap: wrap;
    width: 100%;
}

.control-item-half {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 10px;
    background: #f8f9fa;
    border-radius: 8px;
    min-width: 140px;
    overflow: hidden;
}

.control-label-compact {
    font-size: 13px;
    color: #333;
    margin-right: 6px;
    font-weight: 500;
    white-space: nowrap;
}

.picker-compact {
    padding: 6px 10px;
    background: white;
    border-radius: 6px;
    font-size: 13px;
    color: #333;
    border: 1px solid #ddd;
    min-width: 100px;
    text-align: center;
    max-width: 100%;
}

.compare-selector-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 0;
    padding: 0;
    width: 100%;
    overflow: hidden;
}

.person-selector-clean {
    flex: 1;
    min-width: 0; /* 允许收缩 */
}

.selector-box-clean {
    width: 100%;
    padding: 10px;
    background: white;
    border: 2px solid #ddd;
    border-radius: 8px;
    text-align: center;
    font-size: 14px;
    color: #333;
    min-height: 40px;
    cursor: pointer;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.selector-box-clean:focus {
    outline: none;
    border-color: #4ECDC4;
}

.vs-divider {
    font-size: 12px;
    font-weight: bold;
    color: #666;
    padding: 0 8px;
    min-width: 32px;
    text-align: center;
    background: #f0f0f0;
    border-radius: 12px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

/* 电脑版对比控制 */
@media (min-width: 768px) {
    .control-row-compact {
        gap: 16px;
    }
    
    .control-item-half {
        padding: 12px;
        min-width: 180px;
    }
    
    .control-label-compact {
        font-size: 14px;
        margin-right: 8px;
    }
    
    .picker-compact {
        padding: 8px 12px;
        font-size: 14px;
        min-width: 120px;
    }
    
    .compare-selector-row {
        gap: 12px;
    }
    
    .selector-box-clean {
        padding: 12px;
    }
    
    .vs-divider {
        font-size: 14px;
        padding: 0 12px;
        min-width: 40px;
        height: 32px;
    }
}

/* 对比图例 */
.compare-legend {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin-bottom: 16px;
    padding: 12px;
    background: #f8f9fa;
    border-radius: 8px;
    flex-wrap: wrap;
    width: 100%;
}

.legend-line-item {
    display: flex;
    align-items: center;
    font-size: 13px;
    color: #333;
    font-weight: 500;
    white-space: nowrap;
}

.line-sample {
    width: 24px;
    height: 3px;
    margin-right: 6px;
    background: #666;
    flex-shrink: 0;
}

.line-sample.solid {
    background: #333;
}

.line-sample.dashed {
    background: linear-gradient(to right, #333 50%, transparent 50%);
    background-size: 6px 3px;
}

.compare-chart {
    width: 100%;
    height: 380px;
    position: relative;
    background: #fafafa;
    border-radius: 10px;
    overflow: hidden;
    margin-bottom: 16px;
}

/* 电脑版对比图例和图表 */
@media (min-width: 768px) {
    .compare-legend {
        gap: 32px;
    }
    
    .legend-line-item {
        font-size: 14px;
    }
    
    .line-sample {
        width: 32px;
        margin-right: 8px;
    }
    
    .compare-chart {
        height: 450px;
    }
}

/* 大屏幕对比图表 */
@media (min-width: 1024px) {
    .compare-chart {
        height: 500px;
    }
}

/* 对比数据显示 */
.selected-data-compare {
    background: #f8f9fa;
    border-radius: 10px;
    padding: 12px;
    margin-bottom: 16px;
    border-left: 4px solid #4ECDC4;
    width: 100%;
    overflow: hidden;
}

.compare-values {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    width: 100%;
}

.person-values {
    flex: 1;
    background: white;
    border-radius: 8px;
    padding: 10px;
    min-width: 0; /* 允许收缩 */
    overflow: hidden;
}

.values-row {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    width: 100%;
}

.value-item-small {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #f8f9fa;
    border-radius: 4px;
    padding: 3px 6px;
    flex: 1;
    min-width: 50px;
    max-width: 100%;
    border: 1px solid rgba(0, 0, 0, 0.1);
    overflow: hidden;
}

/* 电脑版对比数据 */
@media (min-width: 768px) {
    .selected-data-compare {
        padding: 16px;
    }
    
    .compare-values {
        gap: 16px;
        flex-wrap: nowrap;
    }
    
    .person-values {
        padding: 12px;
    }
    
    .values-row {
        gap: 6px;
    }
    
    .value-item-small {
        padding: 4px 8px;
        min-width: 60px;
    }
}

.value-name-small {
    font-size: 10px;
    color: #666;
}

.value-number-small {
    font-size: 10px;
    font-weight: bold;
    color: #333;
}

/* 设置页面 */
.rhythm-details {
    space-y: 16px;
}

.rhythm-detail-item {
    padding: 16px;
    background: #f8f9fa;
    border-radius: 8px;
    margin-bottom: 12px;
}

.rhythm-detail-title {
    font-size: 16px;
    font-weight: bold;
    color: #333;
    margin-bottom: 8px;
}

.rhythm-detail-desc {
    font-size: 14px;
    color: #666;
    line-height: 1.5;
}

.data-actions {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.btn-secondary {
    background: #6c757d;
    color: white;
    border: none;
    border-radius: 8px;
    padding: 10px 16px;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-secondary:hover {
    background: #5a6268;
}

.btn-danger {
    background: #dc3545;
    color: white;
    border: none;
    border-radius: 8px;
    padding: 10px 16px;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-danger:hover {
    background: #c82333;
}

/* 弹窗样式 */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    padding: 16px;
    box-sizing: border-box;
}

.modal.show {
    display: flex;
}

.modal-content {
    background: white;
    border-radius: 16px;
    padding: 20px;
    width: 100%;
    max-width: 400px;
    max-height: 90vh;
    overflow-y: auto;
    box-sizing: border-box;
}

/* 电脑版弹窗 */
@media (min-width: 768px) {
    .modal {
        padding: 40px;
    }
    
    .modal-content {
        padding: 32px;
        max-width: 500px;
        max-height: 80vh;
    }
}

.modal-title {
    font-size: 18px;
    font-weight: bold;
    color: #333;
    text-align: center;
    margin-bottom: 24px;
}

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

.form-label {
    display: block;
    font-size: 14px;
    color: #333;
    margin-bottom: 8px;
    font-weight: 500;
}

.form-input {
    width: 100%;
    padding: 12px;
    border: 2px solid #eee;
    border-radius: 8px;
    font-size: 14px;
    color: #333;
}

.form-input:focus {
    outline: none;
    border-color: #4ECDC4;
}

.avatar-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
}

.avatar-option {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: #f0f0f0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    border: 3px solid transparent;
    cursor: pointer;
    transition: all 0.2s ease;
}

.avatar-option.selected {
    border-color: #4ECDC4;
    background: #e8f8f7;
}

.avatar-option:hover {
    transform: scale(1.05);
}

.modal-actions {
    display: flex;
    gap: 12px;
    margin-top: 24px;
}

.btn-primary {
    background: #4ECDC4;
    color: white;
    border: none;
    border-radius: 8px;
    padding: 12px 24px;
    font-size: 14px;
    cursor: pointer;
    flex: 1;
    transition: all 0.2s ease;
}

.btn-primary:hover {
    background: #3bb5b8;
}

.modal-actions .btn-secondary {
    flex: 1;
}

/* 小屏幕优化 */
@media (max-width: 480px) {
    .page {
        padding: 12px;
    }
    
    .card {
        padding: 12px;
        margin-bottom: 12px;
    }
    
    .chart-controls {
        flex-direction: column;
        gap: 8px;
    }
    
    .control-item {
        min-width: 100%;
    }
    
    .control-row-compact {
        flex-direction: column;
        gap: 8px;
    }
    
    .control-item-half {
        min-width: 100%;
    }
    
    .compare-selector-row {
        flex-direction: column;
        gap: 8px;
    }
    
    .vs-divider {
        width: 100%;
        min-width: auto;
    }
    
    .compare-values {
        flex-direction: column;
        gap: 8px;
    }
    
    .data-actions {
        flex-direction: column;
        gap: 8px;
    }
    
    .selected-values-compact {
        flex-direction: column;
        gap: 4px;
    }
    
    .value-item-compact {
        min-width: 100%;
    }
    
    .chart-container {
        height: 300px;
    }
    
    .compare-chart {
        height: 320px;
    }
}

/* 超小屏幕优化 */
@media (max-width: 360px) {
    .page {
        padding: 8px;
    }
    
    .card {
        padding: 10px;
    }
    
    .nav-item {
        padding: 10px 4px;
        font-size: 12px;
    }
    
    .chart-container {
        height: 280px;
    }
    
    .compare-chart {
        height: 300px;
    }
}

/* 防止溢出的全局样式 */
html {
    overflow-x: hidden;
}

body {
    width: 100%;
    max-width: 100vw;
    overflow-x: hidden;
}

/* 确保所有容器不会溢出 */
* {
    max-width: 100%;
}

/* 文本溢出处理 */
.text-ellipsis {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* 响应式图片 */
img {
    max-width: 100%;
    height: auto;
}

/* 确保表单元素不会溢出 */
input, select, textarea {
    max-width: 100%;
    box-sizing: border-box;
}

/* 隐藏类 */
.hidden {
    display: none !important;
}

/* 调试用边框（开发时可启用） */
.debug * {
    border: 1px solid red !important;
}