/* ========== 基础变量与重置 ========== */
:root {
    --primary: #4A90D9;
    --primary-light: #6BA8E8;
    --primary-dark: #357ABD;
    --secondary: #5ECFB1;
    --accent: #F5A623;
    --danger: #E85D5D;
    --success: #5ECFB1;
    --bg: #F0F4F8;
    --card-bg: #FFFFFF;
    --text: #2D3748;
    --text-secondary: #718096;
    --text-light: #A0AEC0;
    --border: #E2E8F0;
    --shadow: 0 4px 20px rgba(0,0,0,0.06);
    --shadow-lg: 0 10px 40px rgba(0,0,0,0.1);
    --radius: 16px;
    --radius-sm: 10px;
    --sidebar-w: 220px;
    --header-h: 60px;
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "PingFang SC", "Microsoft YaHei", sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    overflow-x: hidden;
}

#app {
    display: flex;
    min-height: 100vh;
}

/* ========== 侧边栏 / 导航 ========== */
.sidebar {
    width: var(--sidebar-w);
    background: var(--card-bg);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 24px 16px;
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    z-index: 100;
    transition: var(--transition);
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 32px;
    padding: 0 8px;
}

.brand-icon {
    font-size: 28px;
    animation: float 3s ease-in-out infinite;
}

.brand-text {
    font-size: 18px;
    font-weight: 700;
    color: var(--primary);
    letter-spacing: 1px;
}

.nav-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition);
    color: var(--text-secondary);
    font-weight: 500;
}

.nav-item:hover {
    background: rgba(74, 144, 217, 0.08);
    color: var(--primary);
}

.nav-item.active {
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    color: #fff;
    box-shadow: 0 4px 12px rgba(74, 144, 217, 0.3);
}

.nav-icon {
    font-size: 20px;
    width: 24px;
    text-align: center;
}

/* ========== 主内容区 ========== */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-w);
    padding: 24px 32px 32px;
    max-width: 800px;
    width: 100%;
}

.page {
    display: none;
    animation: fadeIn 0.4s ease;
}

.page.active {
    display: block;
}

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

.page-header {
    margin-bottom: 24px;
}

.page-header h1 {
    font-size: 26px;
    font-weight: 700;
    margin-bottom: 4px;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 14px;
}

/* ========== 机器人动画 ========== */
.robot-section {
    display: flex;
    justify-content: center;
    margin-bottom: 24px;
}

.robot-container {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.robot-body {
    position: relative;
    width: 140px;
    height: 180px;
    animation: robotFloat 3s ease-in-out infinite;
}

@keyframes robotFloat {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}

.robot-head {
    width: 90px;
    height: 70px;
    background: linear-gradient(145deg, #E8F0FE, #D4E4F7);
    border-radius: 24px;
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    border: 2px solid #C5D9ED;
    box-shadow: inset 0 2px 8px rgba(255,255,255,0.6), 0 4px 12px rgba(74,144,217,0.15);
    z-index: 2;
}

.antenna {
    position: absolute;
    top: -18px;
    left: 50%;
    transform: translateX(-50%);
    width: 4px;
    height: 18px;
    background: #A0BCD9;
    border-radius: 2px;
}

.antenna-ball {
    position: absolute;
    top: -8px;
    left: 50%;
    transform: translateX(-50%);
    width: 12px;
    height: 12px;
    background: var(--accent);
    border-radius: 50%;
    box-shadow: 0 0 8px var(--accent);
    animation: pulse 1.5s ease-in-out infinite;
}

.signal {
    position: absolute;
    top: -16px;
    left: 50%;
    transform: translateX(-50%);
    width: 20px;
    height: 20px;
    border: 2px solid var(--accent);
    border-radius: 50%;
    opacity: 0;
}

.signal-1 { animation: signalWave 2s infinite 0s; }
.signal-2 { animation: signalWave 2s infinite 0.5s; }
.signal-3 { animation: signalWave 2s infinite 1s; }

@keyframes signalWave {
    0% { width: 12px; height: 12px; opacity: 0.6; top: -10px; }
    100% { width: 40px; height: 40px; opacity: 0; top: -24px; }
}

@keyframes pulse {
    0%, 100% { transform: translateX(-50%) scale(1); opacity: 1; }
    50% { transform: translateX(-50%) scale(1.2); opacity: 0.7; }
}

.face {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 70px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.eye {
    width: 18px;
    height: 22px;
    background: #2D3748;
    border-radius: 50%;
    position: relative;
    overflow: hidden;
}

.pupil {
    width: 8px;
    height: 8px;
    background: #fff;
    border-radius: 50%;
    position: absolute;
    top: 5px;
    left: 5px;
    animation: pupilMove 4s ease-in-out infinite;
}

.eyelid {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 0;
    background: #D4E4F7;
    animation: blink 4s infinite;
    z-index: 1;
}

@keyframes blink {
    0%, 48%, 52%, 100% { height: 0; }
    50% { height: 100%; }
}

@keyframes pupilMove {
    0%, 100% { transform: translate(0, 0); }
    25% { transform: translate(3px, -2px); }
    50% { transform: translate(-2px, 1px); }
    75% { transform: translate(2px, 2px); }
}

.mouth {
    width: 20px;
    height: 8px;
    border-bottom: 3px solid #2D3748;
    border-radius: 0 0 12px 12px;
    position: absolute;
    bottom: 8px;
    left: 50%;
    transform: translateX(-50%);
}

.robot-torso {
    width: 70px;
    height: 70px;
    background: linear-gradient(145deg, #fff, #EDF2F7);
    border-radius: 20px;
    position: absolute;
    top: 68px;
    left: 50%;
    transform: translateX(-50%);
    border: 2px solid var(--border);
    box-shadow: 0 4px 12px rgba(0,0,0,0.06);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 6px;
}

.heart-beat {
    font-size: 14px;
    animation: heartBeat 1.2s ease-in-out infinite;
}

@keyframes heartBeat {
    0%, 100% { transform: scale(1); }
    15% { transform: scale(1.25); }
    30% { transform: scale(1); }
    45% { transform: scale(1.15); }
}

.chest-light {
    width: 30px;
    height: 8px;
    background: linear-gradient(90deg, var(--secondary), var(--primary));
    border-radius: 4px;
    animation: breathe 3s ease-in-out infinite;
}

@keyframes breathe {
    0%, 100% { opacity: 0.5; transform: scaleX(0.8); }
    50% { opacity: 1; transform: scaleX(1); }
}

.robot-arm {
    width: 16px;
    height: 40px;
    background: linear-gradient(145deg, #E8F0FE, #D4E4F7);
    border-radius: 10px;
    position: absolute;
    top: 78px;
    border: 1px solid #C5D9ED;
}

.robot-arm.left {
    left: 14px;
    transform: rotate(15deg);
    animation: armWaveL 3s ease-in-out infinite;
}

.robot-arm.right {
    right: 14px;
    transform: rotate(-15deg);
    animation: armWaveR 3s ease-in-out infinite;
}

@keyframes armWaveL {
    0%, 100% { transform: rotate(15deg); }
    50% { transform: rotate(25deg); }
}

@keyframes armWaveR {
    0%, 100% { transform: rotate(-15deg); }
    50% { transform: rotate(-25deg); }
}

.robot-shadow {
    width: 80px;
    height: 10px;
    background: rgba(0,0,0,0.08);
    border-radius: 50%;
    margin-top: 4px;
    animation: shadowScale 3s ease-in-out infinite;
}

@keyframes shadowScale {
    0%, 100% { transform: scaleX(1); opacity: 0.8; }
    50% { transform: scaleX(0.85); opacity: 0.5; }
}

.status-bubble {
    margin-top: 16px;
    padding: 10px 18px;
    background: var(--card-bg);
    border-radius: 20px;
    font-size: 13px;
    color: var(--text-secondary);
    box-shadow: var(--shadow);
    position: relative;
    animation: fadeIn 0.6s ease;
}

.status-bubble::before {
    content: '';
    position: absolute;
    top: -6px;
    left: 50%;
    transform: translateX(-50%);
    border-left: 6px solid transparent;
    border-right: 6px solid transparent;
    border-bottom: 6px solid var(--card-bg);
}

/* ========== 卡片通用 ========== */
.card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
    margin-bottom: 16px;
    transition: var(--transition);
}

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

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 14px;
}

.card-header h3 {
    font-size: 16px;
    font-weight: 600;
}

.tag {
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    background: rgba(94, 207, 177, 0.15);
    color: #2D9C7E;
}

.tag.warning {
    background: rgba(245, 166, 35, 0.15);
    color: #C6820F;
}

.tag.danger {
    background: rgba(232, 93, 93, 0.15);
    color: #C53B3B;
}

/* ========== 健康评分 ========== */
.health-score-card {
    text-align: center;
    padding: 24px 20px;
}

.score-circle {
    position: relative;
    width: 140px;
    height: 140px;
    margin: 0 auto 12px;
}

.score-circle svg {
    transform: rotate(-90deg);
    width: 100%;
    height: 100%;
}

.score-bg {
    fill: none;
    stroke: #EDF2F7;
    stroke-width: 10;
}

.score-bar {
    fill: none;
    stroke: url(#scoreGradient);
    stroke-width: 10;
    stroke-linecap: round;
    transition: stroke-dashoffset 1.5s ease;
}

.score-text {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    align-items: baseline;
    gap: 2px;
}

.score-number {
    font-size: 36px;
    font-weight: 700;
    color: var(--primary);
}

.score-unit {
    font-size: 14px;
    color: var(--text-secondary);
}

.score-desc {
    font-size: 13px;
    color: var(--text-secondary);
}

/* ========== 概述卡片 ========== */
.overview-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.overview-card .card-header {
    margin-bottom: 12px;
}

.overview-card .date {
    font-size: 12px;
    color: var(--text-light);
}

.overview-body {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 14px;
}

.overview-icon {
    width: 48px;
    height: 48px;
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    flex-shrink: 0;
}

.tongue-icon {
    background: linear-gradient(135deg, #FDE8E8, #FAD1D1);
}

.sleep-icon {
    background: linear-gradient(135deg, #E8F0FE, #D4E4F7);
}

.overview-info {
    flex: 1;
    min-width: 0;
}

.overview-title {
    font-weight: 600;
    font-size: 14px;
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.overview-detail {
    font-size: 12px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.btn-text {
    background: none;
    border: none;
    color: var(--primary);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    padding: 0;
    display: flex;
    align-items: center;
    gap: 4px;
}

.btn-text:hover {
    color: var(--primary-dark);
}

/* ========== 统计栏 ========== */
.stats-bar {
    display: flex;
    gap: 12px;
    margin-bottom: 20px;
}

.stat-item {
    flex: 1;
    background: var(--card-bg);
    border-radius: var(--radius-sm);
    padding: 16px 12px;
    text-align: center;
    box-shadow: var(--shadow);
}

.stat-value {
    display: block;
    font-size: 22px;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 2px;
}

.stat-label {
    font-size: 12px;
    color: var(--text-secondary);
}

/* ========== 筛选栏 ========== */
.filter-bar {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
}

.filter-btn {
    padding: 8px 16px;
    border-radius: 20px;
    border: 1px solid var(--border);
    background: var(--card-bg);
    color: var(--text-secondary);
    font-size: 13px;
    cursor: pointer;
    transition: var(--transition);
}

.filter-btn.active {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
    box-shadow: 0 4px 12px rgba(74, 144, 217, 0.25);
}

/* ========== 记录列表 ========== */
.record-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.record-item {
    background: var(--card-bg);
    border-radius: var(--radius-sm);
    padding: 16px;
    box-shadow: var(--shadow);
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    gap: 14px;
}

.record-item:hover {
    transform: translateX(4px);
    box-shadow: var(--shadow-lg);
}

.record-date {
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 56px;
}

.record-date .day {
    font-size: 22px;
    font-weight: 700;
    color: var(--primary);
    line-height: 1;
}

.record-date .month {
    font-size: 11px;
    color: var(--text-light);
    margin-top: 2px;
}

.record-info {
    flex: 1;
    min-width: 0;
}

.record-title {
    font-weight: 600;
    font-size: 14px;
    margin-bottom: 4px;
}

.record-meta {
    font-size: 12px;
    color: var(--text-secondary);
}

.record-score {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
}

.score-badge {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 14px;
    color: #fff;
}

.score-badge.good { background: linear-gradient(135deg, #5ECFB1, #4A90D9); }
.score-badge.normal { background: linear-gradient(135deg, #F5A623, #F7C948); }
.score-badge.poor { background: linear-gradient(135deg, #E85D5D, #F5A623); }

.score-label {
    font-size: 11px;
    color: var(--text-light);
}

/* ========== 弹窗 ========== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.45);
    backdrop-filter: blur(4px);
    z-index: 200;
    display: none;
    align-items: flex-end;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.modal-overlay.show {
    display: flex;
    opacity: 1;
}

.modal {
    background: var(--card-bg);
    width: 100%;
    max-width: 560px;
    max-height: 85vh;
    border-radius: var(--radius) var(--radius) 0 0;
    display: flex;
    flex-direction: column;
    transform: translateY(100%);
    transition: transform 0.35s cubic-bezier(0.32, 0.72, 0, 1);
}

.modal-overlay.show .modal {
    transform: translateY(0);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 18px 20px;
    border-bottom: 1px solid var(--border);
}

.modal-header h3 {
    font-size: 17px;
    font-weight: 600;
}

.modal-close {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: none;
    background: var(--bg);
    color: var(--text-secondary);
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-close:hover {
    background: var(--border);
}

.modal-body {
    padding: 20px;
    overflow-y: auto;
    flex: 1;
}

/* 弹窗内详情样式 */
.detail-section {
    margin-bottom: 20px;
}

.detail-section h4 {
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 10px;
    font-weight: 600;
}

.detail-image {
    width: 100%;
    height: 180px;
    background: linear-gradient(135deg, #F0F4F8, #E2E8F0);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-light);
    font-size: 14px;
    margin-bottom: 12px;
    border: 2px dashed var(--border);
}

.detail-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 12px;
}

.detail-tag {
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 12px;
    background: rgba(74, 144, 217, 0.1);
    color: var(--primary);
    font-weight: 500;
}

.detail-text {
    font-size: 14px;
    line-height: 1.7;
    color: var(--text);
    background: var(--bg);
    padding: 14px;
    border-radius: var(--radius-sm);
}

.detail-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}

.detail-metric {
    background: var(--bg);
    border-radius: var(--radius-sm);
    padding: 14px 10px;
    text-align: center;
}

.detail-metric .value {
    font-size: 18px;
    font-weight: 700;
    color: var(--primary);
    display: block;
}

.detail-metric .label {
    font-size: 11px;
    color: var(--text-secondary);
    margin-top: 4px;
}

.sleep-chart {
    height: 120px;
    background: var(--bg);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: flex-end;
    justify-content: space-around;
    padding: 16px 12px 12px;
    gap: 6px;
}

.chart-bar {
    flex: 1;
    border-radius: 6px 6px 0 0;
    min-height: 8px;
    position: relative;
    transition: height 0.8s ease;
}

.chart-bar.deep { background: linear-gradient(to top, #357ABD, #4A90D9); }
.chart-bar.light { background: linear-gradient(to top, #6BA8E8, #8CC4F0); }
.chart-bar.rem { background: linear-gradient(to top, #5ECFB1, #8AE0C8); }
.chart-bar.awake { background: linear-gradient(to top, #F5A623, #F7C948); }

.chart-legend {
    display: flex;
    justify-content: center;
    gap: 16px;
    margin-top: 10px;
    font-size: 12px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
}

.legend-dot {
    width: 10px;
    height: 10px;
    border-radius: 3px;
}

/* ========== 响应式：移动端 ========== */
@media (max-width: 768px) {
    :root {
        --sidebar-w: 0;
    }

    .sidebar {
        width: 100%;
        height: 64px;
        top: auto;
        bottom: 0;
        left: 0;
        right: 0;
        flex-direction: row;
        padding: 0;
        border-right: none;
        border-top: 1px solid var(--border);
        justify-content: center;
    }

    .brand {
        display: none;
    }

    .nav-list {
        flex-direction: row;
        width: 100%;
        justify-content: space-around;
        padding: 0 8px;
    }

    .nav-item {
        flex-direction: column;
        gap: 2px;
        padding: 8px 4px;
        font-size: 11px;
    }

    .nav-icon {
        font-size: 22px;
    }

    .nav-label {
        font-size: 11px;
    }

    .main-content {
        margin-left: 0;
        padding: 16px 16px 80px;
        max-width: 100%;
    }

    .page-header h1 {
        font-size: 22px;
    }

    .overview-grid {
        grid-template-columns: 1fr;
    }

    .stats-bar {
        gap: 8px;
    }

    .stat-item {
        padding: 12px 8px;
    }

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

    .robot-body {
        transform: scale(0.9);
    }

    .detail-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .modal {
        max-height: 90vh;
    }
}

/* 移动端横屏小优化 */
@media (max-width: 768px) and (min-height: 700px) {
    .robot-body {
        transform: scale(1);
    }
}

/* 桌面端额外优化 */
@media (min-width: 1024px) {
    .main-content {
        max-width: 900px;
        margin-left: var(--sidebar-w);
        padding: 32px 40px;
    }

    .overview-grid {
        gap: 20px;
    }

    .record-item {
        padding: 18px 20px;
    }
}

/* 桌面端弹窗居中卡片 */
@media (min-width: 769px) {
    .modal-overlay {
        align-items: center;
        padding: 40px 20px;
    }

    .modal {
        border-radius: var(--radius);
        max-height: 85vh;
        transform: translateY(20px);
        opacity: 0;
        transition: transform 0.35s ease, opacity 0.3s ease;
    }

    .modal-overlay.show .modal {
        transform: translateY(0);
        opacity: 1;
    }
}

/* ========== SVG渐变定义占位 ========== */
.score-circle svg defs {
    /* defs 不需要显示，但不可设为 none，否则部分浏览器渐变失效 */
}
