* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Microsoft YaHei', 'Segoe UI', sans-serif;
    background: #f8f9fa;
    height: 100vh;
    padding: 20px;
}

.dashboard {
    height: calc(100vh - 100px);
    width: 100%;
    max-width: 1600px;
    margin: 0 auto;
}

.header {
    text-align: center;
    margin-bottom: 30px;
}

.title {
    color: #2c3e50;
    font-size: 2.2em;
    font-weight: 600;
    letter-spacing: 1px;
    text-shadow: 1px 1px 3px rgba(0,0,0,0.1);
    transition: transform 0.3s ease;
}

.title:hover {
    transform: scale(1.01);
}

.tabs {
    margin-bottom: 25px;
    display: flex;
    gap: 15px;
    justify-content: center;
    flex-direction: row-reverse; /* 按钮顺序反转 */
}

.tab-button {
    background: linear-gradient(135deg, #4CAF50, #45a049);
    color: white;
    border: none;
    padding: 14px 28px;
    border-radius: 30px;
    cursor: pointer;
    font-size: 15px;
    transition: all 0.3s ease;
    box-shadow: 0 3px 6px rgba(0,0,0,0.1);
    position: relative;
    overflow: hidden;
}

.tab-button:after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255,255,255,0.1);
    opacity: 0;
    transition: all 0.3s;
}

.tab-button:hover:after {
    opacity: 1;
}

.tab-button.active {
    transform: translateY(-2px);
    box-shadow: 0 5px 8px rgba(0,0,0,0.2);
}

.chart-container {
    background: white;
    border-radius: 15px;
    padding: 25px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.08);
    height: calc(100% - 100px);
    position: relative;
    opacity: 0;
    transform: translateY(20px);
    animation: fadeIn 0.5s ease forwards;
    transition: box-shadow 0.3s ease;
}

.chart-container:hover {
    box-shadow: 0 8px 25px rgba(0,0,0,0.12);
}

@keyframes fadeIn {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.stats-box {
    position: absolute;
    top: -80px;  /* 调整到容器外，从-50px改为-80px使其更靠上 */
    right: 0;
    background: rgba(76, 175, 80, 0.1);
    padding: 15px 25px;
    border-radius: 10px;
    z-index: 20;
    transition: all 0.3s ease;
    backdrop-filter: blur(5px);
}

.stats-box:hover {
    background: rgba(76, 175, 80, 0.15);
    transform: translateY(-3px);
}

.stats-value {
    font-size: 24px;
    color: #2c3e50;
    font-weight: 600;
    transition: color 0.3s;
    border: none; /* 确保没有边框 */
}

.stats-label {
    color: #7f8c8d;
    font-size: 14px;
    font-weight: bold; /* 添加加粗效果 */
    border: none; /* 确保没有边框 */
}

.chart-row {
    display: flex;
    gap: 25px;
    height: 100%;
}

.chart-wrapper {
    flex: 2;
    min-width: 60%;
    height: 100%;
    position: relative;
    overflow: visible; /* 允许数据标签溢出 */
}

.pie-container {
    flex: 1;
    min-width: 35%;
    height: 100%;
}

.chartjs-plugin-datalabels {
    font-size: 14px !important;
    font-weight: 600 !important;
    color: white !important;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
}

.loading-indicator {
    display: none;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(255, 255, 255, 0.9);
    padding: 20px;
    border-radius: 10px;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
    z-index: 1000;
    transition: opacity 0.3s ease;
}

.loading-indicator.active {
    display: flex;
    align-items: center;
    gap: 15px;
    animation: pulse 1.5s infinite alternate;
}

@keyframes pulse {
    0% {
        box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
    }
    100% {
        box-shadow: 0 0 20px rgba(76, 175, 80, 0.3);
    }
}

.error-message {
    background-color: #f8d7da;
    color: #721c24;
    padding: 10px 15px;
    border-radius: 5px;
    margin-bottom: 15px;
    display: none;
    opacity: 0;
    transform: translateY(-10px);
    transition: all 0.3s ease;
}

.error-message.show {
    display: block;
    opacity: 1;
    transform: translateY(0);
    animation: shake 0.5s ease-in-out;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    10%, 30%, 50%, 70%, 90% { transform: translateX(-5px); }
    20%, 40%, 60%, 80% { transform: translateX(5px); }
}

.refresh-info {
    position: absolute;
    bottom: 5px;
    right: 15px;
    font-size: 12px;
    color: #6c757d;
    transition: opacity 0.3s;
    background-color: rgba(255, 255, 255, 0.9);  /* 添加半透明背景 */
    padding: 5px 8px;  /* 添加内边距 */
    border-radius: 4px;  /* 添加圆角 */
    z-index: 10;  /* 确保在日期标签上方 */
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);  /* 添加轻微阴影 */
}

.refresh-info:hover {
    opacity: 0.8;
}

.refresh-button {
    background: linear-gradient(135deg, #2196F3, #1976D2);
    color: white;
    border: none;
    padding: 6px 12px;
    border-radius: 20px;
    cursor: pointer;
    font-size: 12px;
    transition: all 0.3s ease;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    display: flex;
    align-items: center;
    gap: 4px;
    margin-left: 12px;
}

.refresh-button:hover {
    background: linear-gradient(135deg, #1E88E5, #1565C0);
    transform: translateY(-2px);
    box-shadow: 0 5px 8px rgba(0,0,0,0.2);
}

.refresh-button:active {
    transform: translateY(0);
}

.refresh-button svg {
    width: 11px;
    height: 11px;
    transition: transform 0.3s ease;
}

.refresh-button:hover svg {
    transform: rotate(180deg);
}

.db-status {
    margin-left: 8px;
    padding: 3px 6px;
    font-size: 10px;
    border-radius: 10px;
    display: inline-block;
}

.db-status.connected {
    background-color: rgba(76, 175, 80, 0.2);
    color: #2e7d32;
}

.db-status.disconnected {
    background-color: rgba(244, 67, 54, 0.2);
    color: #c62828;
}

/* 为图表数据标签设置样式，移除边框 */
.chartjs-datalabels {
    font-weight: bold;
    border: none !important;
    box-shadow: none !important;
    background: none !important;
}

/* 添加媒体查询以支持不同屏幕尺寸 */
@media (max-width: 768px) {
    .chart-row {
        flex-direction: column;
    }

    .chart-wrapper, .pie-container {
        width: 100%;
        min-width: 100%;
    }

    .pie-container {
        height: 300px;
        margin-top: 20px;
    }

    .chart-container {
        height: auto;
        padding: 15px;
        padding-top: 25px; /* 增加顶部内边距 */
        margin-top: 90px; /* 给顶部添加更多空间，从80px增加到90px */
    }

    .title {
        font-size: 1.8em;
    }

    .tabs {
        flex-direction: column;
        align-items: center;
        margin-bottom: 60px; /* 增加底部间距，避免与stats-box重叠 */
    }

    .tab-button {
        width: 100%;
        max-width: 250px;
        margin-bottom: 8px; /* 按钮之间添加间距 */
    }

    /* 调整小屏幕上的销售金额文字大小 - 应用到所有销售金额文字 */
    .stats-value, #dailyTotal, #monthlyTotal, #yearlyTotal {
        font-size: 18px !important; /* 从24px减小到18px，使用!important确保应用 */
    }

    .stats-label, #dailyTotalLabel, #monthlyTotalLabel, #yearlyTotalLabel {
        font-size: 12px !important; /* 从14px减小到12px，使用!important确保应用 */
    }

    /* 让stats-box在小屏幕上位置更合理 */
    .stats-box {
        top: -80px; /* 进一步向上调整位置，从-70px增加到-80px */
        padding: 10px 15px; /* 减小内边距 */
        right: 5px; /* 距离右侧更近 */
        z-index: 10; /* 确保正确的层叠顺序 */
        width: auto; /* 自动宽度，不要拉宽 */
        max-width: 200px; /* 限制最大宽度 */
        background: rgba(76, 175, 80, 0.15); /* 稍微增加背景不透明度以增强可见性 */
    }

    .horizontal-bar-container {
        height: 800px; /* 在移动设备上进一步增加高度 */
    }

    .chart-title {
        font-size: 16px;
        margin: 8px 0 12px 0;
    }

    /* 调整移动设备上的最后更新信息样式 */
    .refresh-info {
        bottom: 10px;
        right: 10px;
        font-size: 10px;
        padding: 3px 6px;
        width: auto;
        max-width: 200px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    /* 增加更多底部间距 */
    #dailyChart {
        padding-bottom: 45px;
    }

    /* 调整图表容器大小和溢出处理 */
    .chart-wrapper {
        width: 100%;
        min-width: 100%;
        height: auto !important; /* 使用auto高度适应内容 */
        min-height: 300px; /* 设置最小高度 */
        overflow: visible; /* 允许标签溢出 */
    }

    /* 调整小屏幕上的销售金额标签样式 */
    .chartjs-datalabels {
        font-size: 9px !important; /* 强制使用更小的字体 */
        background: rgba(255, 255, 255, 0.8) !important; /* 半透明背景提高可读性 */
        padding: 2px 3px !important; /* 减小内边距 */
        box-shadow: none !important; /* 移除阴影 */
        border-width: 0.5px !important; /* 更细的边框 */
    }

    /* 增加图表容器内边距，确保数据标签有足够空间 */
    #dailyChart .chart-wrapper {
        padding: 5px;
        margin-bottom: 10px;
    }
}

/* 添加更小屏幕设备的媒体查询 */
@media (max-width: 480px) {
    .stats-value, #dailyTotal, #monthlyTotal, #yearlyTotal {
        font-size: 16px !important; /* 在更小屏幕上进一步减小 */
    }

    .stats-label, #dailyTotalLabel, #monthlyTotalLabel, #yearlyTotalLabel {
        font-size: 11px !important;
    }

    .chart-container {
        padding: 10px;
        padding-top: 20px; /* 确保顶部有足够内边距 */
        margin-top: 70px; /* 给顶部stats-box留出更多空间 */
    }

    .stats-box {
        top: -70px; /* 进一步提高位置，确保在图表外部 */
        padding: 8px 12px;
        max-width: 180px; /* 更小屏幕上进一步限制宽度 */
        right: 5px; /* 放在右上角 */
    }

    /* 改善小屏幕上的间距和布局 */
    .dashboard {
        height: auto;
        padding-bottom: 20px;
    }

    .tabs {
        gap: 10px;
        margin-bottom: 40px; /* 减少底部间距 */
    }

    .tab-button {
        padding: 10px 20px;
        font-size: 14px;
    }

    /* 确保刷新按钮在小屏幕上正常显示 */
    .refresh-button {
        margin-bottom: 8px;
        align-self: center; /* 居中对齐 */
    }

    .horizontal-bar-container {
        height: 1000px; /* 在超小屏幕上更大的高度 */
    }

    .chart-title {
        font-size: 14px;
        margin: 5px 0 10px 0;
        line-height: 1.4;
    }

    /* 进一步调整超小屏幕上的最后更新信息样式 */
    .refresh-info {
        bottom: 15px;
        right: 5px;
        font-size: 9px;
        padding: 2px 4px;
        max-width: 150px;
    }

    /* 超小屏幕上给更多底部间距 */
    #dailyChart {
        padding-bottom: 55px;
    }

    /* 进一步调整超小屏幕的图表样式 */
    .chart-wrapper {
        min-height: 250px; /* 减小最小高度 */
    }

    /* 超小屏幕上的销售金额标签样式 */
    .chartjs-datalabels {
        font-size: 8px !important; /* 进一步减小字体 */
        padding: 1px 2px !important; /* 最小内边距 */
        border-radius: 2px !important; /* 减小圆角 */
        border-width: 0 !important; /* 移除边框 */
    }

    /* 调整图表在超小屏幕上的布局 */
    #dailyChart .chart-row {
        margin: 0 -5px; /* 负边距增加可用空间 */
    }

    #dailyChart .chart-wrapper {
        padding: 0;
    }

    /* 确保日期标签清晰显示 */
    #dailySalesChart {
        margin-bottom: 10px; /* 增加底部空间 */
    }
}

/* 横向柱形图容器样式 */
.horizontal-bar-container {
    margin-top: 20px;
    height: 600px; /* 增加高度以显示更多数据 */
}

/* 图表标题样式 */
.chart-title {
    text-align: center;
    font-size: 18px;
    font-weight: bold;
    margin: 10px 0 15px 0;
    color: #333;
    padding: 0 10px;
}

/* 对每日图表容器添加额外的底部间距 */
#dailyChart {
    padding-bottom: 35px;  /* 确保底部有足够空间 */
}

/* 为折线图数据标签增加智能布局样式 */
#dailySalesChart {
    height: 100%;
    min-height: 400px; /* 确保图表有足够高度显示所有标签 */
}

/* 增强数据标签的样式 */
.chartjs-datalabels {
    z-index: 5; /* 增加层级，确保标签显示在前面 */
    transition: opacity 0.2s; /* 添加过渡效果 */
}

/* 针对不同设备调整样式 */
@media (min-width: 769px) {
    /* 桌面设备样式优化 */
    #dailySalesChart {
        min-height: 450px; /* 增加图表高度 */
    }

    /* 优化桌面设备上的数据标签间距和样式 */
    .chart-wrapper {
        padding-top: 30px; /* 顶部增加空间 */
        padding-bottom: 30px; /* 底部增加空间 */
    }

    /* 确保桌面设备上标签有足够的间距 */
    .chartjs-datalabels {
        opacity: 0.9; /* 轻微透明效果 */
        padding: 3px 4px !important; /* 减小内边距，避免重叠 */
        font-size: 11px !important; /* 稍微减小字体大小 */
    }
}

/* 登录页面样式 */
.login-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, rgba(76, 175, 80, 0.9), rgba(33, 150, 243, 0.9));
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    opacity: 0;
    animation: fadeIn 0.5s ease forwards;
}

.login-container {
    background: white;
    border-radius: 15px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    width: 90%;
    max-width: 400px;
    padding: 30px;
    transform: translateY(20px);
    animation: slideUp 0.5s ease forwards 0.2s;
    opacity: 0;
}

@keyframes slideUp {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.login-header {
    text-align: center;
    margin-bottom: 25px;
}

.login-header h2 {
    color: #2c3e50;
    font-size: 1.8em;
    margin-bottom: 10px;
}

.login-header p {
    color: #7f8c8d;
    font-size: 0.9em;
}

.login-form {
    width: 100%;
}

.input-group {
    margin-bottom: 20px;
    position: relative;
}

.login-input {
    width: 100%;
    padding: 15px;
    border: 1px solid #ddd;
    border-radius: 30px;
    background: #f8f9fa;
    font-size: 16px;
    transition: all 0.3s;
    outline: none;
}

.login-input:focus {
    border-color: #4CAF50;
    box-shadow: 0 0 0 2px rgba(76, 175, 80, 0.2);
}

.remember-me {
    display: flex;
    align-items: center;
    margin-bottom: 20px;
    user-select: none;
}

.remember-me input {
    margin-right: 10px;
    cursor: pointer;
}

.remember-me label {
    color: #7f8c8d;
    font-size: 0.9em;
    cursor: pointer;
}

.login-button {
    width: 100%;
    padding: 15px;
    background: linear-gradient(135deg, #4CAF50, #45a049);
    color: white;
    border: none;
    border-radius: 30px;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    position: relative;
    overflow: hidden;
}

.login-button:after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.1);
    opacity: 0;
    transition: all 0.3s;
}

.login-button:hover:after {
    opacity: 1;
}

.login-button:active {
    transform: translateY(2px);
    box-shadow: 0 2px 3px rgba(0, 0, 0, 0.1);
}

.login-error {
    margin-top: 15px;
    color: #e74c3c;
    text-align: center;
    font-size: 0.9em;
    min-height: 20px;
    opacity: 0;
    transition: opacity 0.3s;
}

.login-error.show {
    opacity: 1;
    animation: shake 0.5s ease;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    20%, 60% { transform: translateX(-5px); }
    40%, 80% { transform: translateX(5px); }
}

/* 移动设备适配 */
@media (max-width: 480px) {
    .login-container {
        padding: 20px;
    }

    .login-header h2 {
        font-size: 1.5em;
    }

    .login-input, .login-button {
        padding: 12px;
    }
}
