* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    transition: all 0.3s ease;
}

/* 基础样式 - 浅色主题 */
body {
    overflow: hidden;
    display: flex;
    min-height: 100vh;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    color: #333333;
    background-color: #FAFAFA;
    overflow-x: hidden;
}

/* 主容器：顶部导航+内容区 */
.main-container {
    flex: 1;
    /* 占满剩余宽度 */
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* 顶部导航栏样式 */
.top-nav {
    display: flex;
    align-items: center;
    height: 48px;
    padding: 0 15px;
    background-color: #FFFFFF;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
    border-bottom: 1px solid #EEEEEE;
    z-index: 5;
}

.card_h {
    display: flex;
    flex-direction: row;
    justify-content: space-between;
}

.top-nav button {
    padding: 0 15px;
    height: 100%;
    border: none;
    background-color: transparent;
    color: #666666;
    cursor: pointer;
    font-size: 14px;
    display: flex;
    align-items: center;
}

.top-nav button i {
    margin-right: 6px;
}

.top-nav button:hover {
    background-color: #F5F5F5;
}

.top-nav button.active {
    background-color: #F5F5F5;
    color: #222222;
    border-bottom: 2px solid #4A90E2;
}

/* 添加设备按钮 */
.add-device-btn {
    margin-left: 10px;
    color: #4A90E2;
}

/* 主题切换按钮位置 */
.theme-toggle {
    margin-left: auto;
}

/* 移动端菜单按钮 */
.menu-toggle {
    display: none;
    padding: 12px 15px;
    border: none;
    background-color: transparent;
    color: #666666;
    cursor: pointer;
}

/* 主内容区域样式 */
.main-content {
    flex: 1;
    padding: 15px;
    min-height: calc(100vh - 48px);
    /* 减去顶部导航高度 */
}

/* 右侧设备列表（单独容器） */
.sidebar {
    width: 200px;
    background-color: #FFFFFF;
    box-shadow: -2px 0 5px rgba(0, 0, 0, 0.03);
    z-index: 4;
    border-left: 1px solid #EEEEEE;
    min-height: 100vh;
    /* 全屏高度 */
    display: flex;
    flex-direction: column;
}

.sidebar h3 {
    display: flex;
    align-items: center;
    height: 48px;
    padding: 0 20px;
    background-color: #FFFFFF;
    color: #333333;
    font-size: 16px;
    font-weight: 600;
    border-bottom: 1px solid #EEEEEE;
    margin: 0;
}

.sidebar h3 i {
    margin-right: 10px;
    color: #4A90E2;
}

/* 设备列表容器 */
.device-list-container {
    flex: 1;
    overflow-y: auto;
    padding: 10px;
}

/* 设备列表项样式 */
.device-list-container>div {
    margin-bottom: 8px;
}

.device-active {
    border-color: #4A90E2 !important;
    background-color: #F0F7FF !important;
}

/* 内容区域切换样式 */
.content-section {
    display: none;
    min-height: 100%;
    height: 100%;
    animation: fadeIn 0.5s ease;
}

.content-section.active {
    display: block;
}

.content-section h2 {
    margin-bottom: 15px;
    color: #333333;
    font-weight: 600;
    padding-bottom: 10px;
    border-bottom: 1px solid #EEEEEE;
    font-size: 18px;
}

.content-section h3 {
    color: #333333;
    margin-bottom: 15px;
    font-size: 16px;
}

.content-section p {
    color: #666666;
    line-height: 1.6;
}

/* 卡片容器样式 */
.card {
    background-color: white;
    border-radius: 6px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.03);
    padding: 15px;
    margin-bottom: 15px;
}

.b_card {
    background-color: white;
    border-radius: 6px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.03);
    padding: 15px;
    margin-bottom: 0;
    /* 改为0，移除底部间距 */
    height: 66vh;
    /* 让卡片占满父容器高度 */
    display: flex;
    flex-direction: column;
    /* 使用flex布局 */
}

/* 统计数据网格 */
.stats-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    margin-bottom: 20px;
}

.stat-card {
    flex: 1;
    min-width: 180px;
    background-color: #F8F9FA;
    border-radius: 6px;
    padding: 15px;
}

.stat-card .stat-label {
    font-size: 13px;
    color: #666;
    margin-bottom: 5px;
}

.stat-card .stat-value {
    font-size: 20px;
    font-weight: 600;
    color: #333;
    display: flex;
    align-items: baseline;
}

.stat-card .stat-value .unit {
    font-size: 14px;
    color: #666;
    margin-left: 5px;
    font-weight: normal;
}

.stat-card .stat-trend {
    font-size: 12px;
    margin-top: 5px;
    display: flex;
    align-items: center;
}

.trend-up {
    color: #00B42A;
}

.trend-down {
    color: #F53F3F;
}

/* 图表容器 */
.chart-container {
    width: 100%;
    flex: 1;
    /* 占满剩余空间 */
    min-height: 0;
    /* 允许高度小于最小高度限制 */
    position: relative;
}

/* 时间筛选器 */
.time-filter {
    display: flex;
    gap: 10px;
    margin-bottom: 15px;
    flex-wrap: wrap;
}

.time-filter button {
    padding: 5px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    background-color: white;
    cursor: pointer;
    font-size: 13px;
}

.time-filter button.filter-active {
    background-color: #4A90E2;
    color: white;
    border-color: #4A90E2;
}

/* 加载状态 */
.loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 350px;
    color: #666;
}

.loading .spinner {
    width: 40px;
    height: 40px;
    border: 3px solid #ddd;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 10px;
}

/* 无数据状态 */
.no-data {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 350px;
    color: #999;
}

.no-data i {
    font-size: 40px;
    margin-bottom: 10px;
}

/* 数据更新指示器 */
.data-update-indicator {
    position: absolute;
    top: 10px;
    right: 10px;
    background-color: #4A90E2;
    color: white;
    padding: 3px 8px;
    border-radius: 4px;
    font-size: 12px;
    opacity: 0;
    transition: opacity 0.3s;
    pointer-events: none;
}

.data-update-indicator.active {
    opacity: 1;
}

/* 最后更新时间 */
.last-update {
    text-align: right;
    padding-right: 10px;
}

/* 添加设备模态框 */
.add-device-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s;
}

.add-device-modal.active {
    opacity: 1;
    visibility: visible;
}

.modal-content {
    background-color: white;
    border-radius: 6px;
    width: 90%;
    max-width: 500px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    transform: translateY(-20px);
    transition: transform 0.3s;
}

.add-device-modal.active .modal-content {
    transform: translateY(0);
}

.modal-header {
    padding: 15px 20px;
    border-bottom: 1px solid #eee;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h3 {
    margin: 0;
    font-size: 16px;
}

.modal-close {
    background: none;
    border: none;
    font-size: 18px;
    cursor: pointer;
    color: #999;
}

.modal-body {
    padding: 20px;
}

.device-json-input {
    width: 100%;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-family: monospace;
    resize: vertical;
}

.json-error {
    color: #F53F3F;
    font-size: 12px;
    margin-top: 5px;
    min-height: 18px;
}

.modal-footer {
    padding: 15px 20px;
    border-top: 1px solid #eee;
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

.modal-btn {
    padding: 6px 15px;
    border-radius: 4px;
    cursor: pointer;
    border: 1px solid #ddd;
    background-color: white;
}

.modal-btn.confirm {
    background-color: #4A90E2;
    color: white;
    border-color: #4A90E2;
}

/* 动画效果 */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

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

/* 移动端响应式调整 */
@media (max-width: 768px) {
    body {
        flex-direction: column;
    }

    .container {
        width: 100%;
    }

    .main-container {
        width: 100%;
    }

    .top-nav {
        height: 48px;
        padding-right: 0;
    }

    .menu-toggle {
        display: block;
    }

    .main-content {
        width: 100%;
        padding: 10px;
        min-height: calc(100vh - 48px);
    }

    /* 移动端侧边栏改为覆盖层 */
    .sidebar {
        width: 100%;
        height: 0;
        overflow: hidden;
        position: absolute;
        top: 48px;
        left: 0;
        right: 0;
        bottom: 0;
        transition: height 0.3s ease;
        z-index: 100;
        min-height: auto;
    }

    .sidebar.active {
        height: calc(100% - 48px);
    }

    .top-nav button {
        padding: 12px 10px;
        font-size: 13px;
    }

    .top-nav button i {
        margin-right: 5px;
    }

    .card {
        padding: 12px;
        margin-bottom: 12px;
    }

    .content-section h2 {
        font-size: 17px;
        margin-bottom: 12px;
    }

    .chart-container {
        height: 250px;
    }

    .stats-grid {
        gap: 10px;
    }

    .stat-card {
        min-width: 140px;
        padding: 12px;
    }
}

/* 深色主题样式 */
body.dark-theme {
    background-color: #1A1A1A;
    color: #E0E0E0;
}

body.dark-theme .main-container {
    background-color: #1A1A1A;
}

body.dark-theme .top-nav {
    background-color: #2D2D2D;
    border-bottom: 1px solid #3D3D3D;
    height: 48px;
}

body.dark-theme .top-nav button {
    color: #BBBBBB;
}

body.dark-theme .top-nav button:hover {
    background-color: #3D3D3D;
}

body.dark-theme .top-nav button.active {
    background-color: #3D3D3D;
    color: #FFFFFF;
    border-bottom: 2px solid #61A0FF;
}

body.dark-theme .sidebar {
    background-color: #2D2D2D;
    border-left: 1px solid #3D3D3D;
}

body.dark-theme .sidebar h3 {
    background-color: #2D2D2D;
    color: #E0E0E0;
    border-bottom: 1px solid #3D3D3D;
    height: 48px;
}

body.dark-theme .sidebar h3 i {
    color: #61A0FF;
}

body.dark-theme .sidebar .add-device {
    color: #61A0FF;
    border-bottom: 1px solid #3D3D3D;
}

body.dark-theme .sidebar .add-device:hover {
    background-color: #1E3A6E;
}

body.dark-theme .sidebar li {
    border-bottom: 1px solid #3D3D3D;
    color: #BBBBBB;
}

body.dark-theme .sidebar li i {
    color: #999999;
}

body.dark-theme .sidebar li:hover {
    background-color: #3D3D3D;
    color: #FFFFFF;
}

body.dark-theme .sidebar li:hover i {
    color: #61A0FF;
}

body.dark-theme .sidebar li.active {
    background-color: #1E3A6E;
    color: #61A0FF;
    border-left: 3px solid #61A0FF;
}

body.dark-theme .sidebar li.active i {
    color: #61A0FF;
}

body.dark-theme .content-section h2 {
    color: #E0E0E0;
    border-bottom: 1px solid #3D3D3D;
}

body.dark-theme .content-section h3 {
    color: #E0E0E0;
}

body.dark-theme .content-section p {
    color: #BBBBBB;
}

body.dark-theme .card {
    background-color: #2D2D2D;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
}

body.dark-theme .stat-card {
    background-color: #333842;
}

body.dark-theme .stat-card .stat-label,
body.dark-theme .stat-card .stat-value .unit {
    color: #BBBBBB;
}

body.dark-theme .stat-card .stat-value {
    color: #E0E0E0;
}

body.dark-theme .time-filter button {
    background-color: #333842;
    border-color: #444;
    color: #BBBBBB;
}

/* 深色主题下的模态框 */
body.dark-theme .modal-content {
    background-color: #2D2D2D;
    border-color: #3D3D3D;
}

body.dark-theme .modal-header {
    border-bottom-color: #3D3D3D;
}

body.dark-theme .modal-header h3 {
    color: #E0E0E0;
}

body.dark-theme .device-json-input {
    background-color: #333;
    border-color: #444;
    color: #E0E0E0;
}

body.dark-theme .modal-btn {
    background-color: #333;
    border-color: #444;
    color: #BBBBBB;
}

body.dark-theme .modal-btn.confirm {
    background-color: #61A0FF;
    border-color: #61A0FF;
}