/* 定义全局变量，方便以后一键换肤 */
:root {
    --bg-color: #f8fafc;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --card-bg: #ffffff;
    --accent-color: #3b82f6;
    --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --sidebar-width: 160px;
    --sidebar-collapsed-width: 60px;
}

body {
    background-color: var(--bg-color);
    color: var(--text-primary);
    font-family: var(--font-family);
    margin: 0;
    padding: 0;
    min-height: 100vh;
    display: flex;
    overflow-x: hidden; /* 保留垂直滚动条，但隐藏水平滚动 */
}

/* 侧边栏样式 */
.sidebar {
    position: fixed;
    left: 0;
    top: 0;
    height: 100vh;
    width: var(--sidebar-width);
    background: linear-gradient(135deg, #f8fafc 0%, #e2e8f0 100%);
    color: #1e293b;
    z-index: 1000;
    transition: all 0.3s ease;
    display: flex;
    flex-direction: column;
    box-shadow: 2px 0 15px rgba(0, 0, 0, 0.1);
    border-right: 1px solid rgba(0, 0, 0, 0.1);
}

.sidebar-header {
    padding: 25px 20px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
    background: rgba(255, 255, 255, 0.5);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.sidebar-header h2 {
    margin: 0;
    font-size: 1.3rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    letter-spacing: 0.5px;
    flex: 1;
}

.toggle-btn {
    background: none;
    border: none;
    color: #1e293b;
    font-size: 1.2rem;
    cursor: pointer;
    padding: 5px;
    border-radius: 50%;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
}

.toggle-btn:hover {
    background: rgba(0, 0, 0, 0.1);
    transform: rotate(180deg);
}

.sidebar.collapsed {
    width: var(--sidebar-collapsed-width);
}

.sidebar.collapsed .sidebar-header h2 {
    display: none;
}

.sidebar.collapsed .menu-item span {
    display: none;
}

.sidebar.collapsed .menu-item i {
    margin-right: 0;
    font-size: 1.4rem;
}

.sidebar.collapsed .menu-item {
    justify-content: center;
    padding: 15px 0;
    margin: 8px 5px;
}

.sidebar-menu {
    padding: 20px 0;
    flex: 1;
}

.menu-item {
    display: flex;
    align-items: center;
    padding: 15px 20px;
    margin: 8px 12px;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.3s ease;
    white-space: nowrap;
    background: rgba(255, 255, 255, 0.7);
    border: 1px solid rgba(0, 0, 0, 0.1);
    color: #1e293b;
}

.menu-item:hover {
    background: rgba(255, 255, 255, 0.9);
    transform: translateX(8px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    border-color: rgba(0, 0, 0, 0.2);
}

.menu-item.active {
    background: rgba(255, 255, 255, 0.7);
    font-weight: bold;
    box-shadow: none;
    border-color: rgba(0, 0, 0, 0.1);
    color: #805ad5;
}

.menu-item.active i {
    color: #805ad5;
}

.menu-item i {
    font-size: 1.3rem;
    margin-right: 12px;
    width: 24px;
    text-align: center;
}

.sidebar.collapsed .menu-item span {
    display: none;
}

.sidebar.collapsed .menu-item i {
    margin-right: 0;
    font-size: 1.4rem;
}

/* 主内容区域 */
.main-content {
    margin-left: var(--sidebar-width);
    width: calc(100% - var(--sidebar-width));
    min-height: 100vh;
    padding: 15px;
    box-sizing: border-box;
    overflow-x: hidden;
    max-width: 100%;
}

.page {
    display: none;
}

.page.active {
    display: block;
}

/* 预算页面容器 */
.container {
    max-width: 1000px; /* 调整宽度 */
    margin: 0 auto;
    background: var(--card-bg);
    border-radius: 16px;
    padding: 20px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    min-height: 600px; /* 增加最小高度，确保所有页面高度一致 */
}



/* 适配小屏幕 */
@media (max-width: 768px) {
    /* 确保页面不会水平滚动 */
    body {
        overflow-x: hidden !important;
    }
    
    /* 调整主内容区域，确保不超出屏幕宽度 */
    .main-content {
        overflow-x: hidden !important;
        overflow-y: visible !important;
        margin-left: 0 !important;
        margin-bottom: 0 !important; /* 为底部栏留出空间 */
        width: 100% !important;
        padding: 0 !important;
        min-height: calc(100vh - 60px) !important;
        height: 100% !important;
        position: relative;
        z-index: 1;
        box-sizing: border-box !important;
        background-color: transparent !important;
        display: block !important;
    }
    
    /* 调整容器，确保不超出屏幕宽度 */
    .container {
        overflow-x: hidden !important;
        overflow-y: visible !important;
        max-width: 100%; /* 确保容器不超出屏幕宽度 */
        padding: 16px 16px 20px;
        box-sizing: border-box; /* 确保padding不增加宽度 */
        margin-top: 0 !important;
        margin-bottom: 0 !important;
        min-height: calc(100vh - 60px) !important;
        height: 100% !important;
        border-radius: 0 !important;
        box-shadow: none !important;
        background-color: rgba(255, 255, 255, 0.9) !important;
        width: 100% !important;
        display: block !important;
    }
    /* 将侧边栏改为底部栏 */
    .sidebar {
        position: fixed !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        height: 50px !important;
        width: 100vw !important;
        margin-bottom: 0 !important;
        border-radius: 16px 16px 0 0 !important;
        z-index: 1000 !important;
        box-shadow: 0 -2px 15px rgba(0, 0, 0, 0.1) !important;
        padding: 0 0 !important;
        display: flex !important;
        flex-direction: column !important;
        justify-content: center !important;
        top: auto !important;
        box-sizing: border-box !important;
        overflow: hidden !important;
        transform: none !important;
        flex-shrink: 0 !important;
    }
    

    
    /* 调整预算页面标题 */
    .container h1 {
        margin-top: 0;
        padding-top: 10px;
    }
    

    
    /* 隐藏小屏下的侧边栏头部 */
    .sidebar-header {
        display: none !important;
    }
    
    /* 调整菜单为横向排列 */
    .sidebar-menu {
        display: flex;
        flex-direction: row;
        justify-content: space-around;
        gap: 0;
        padding: 0;
        flex: 1;
        align-items: center;
        box-sizing: border-box;
        overflow: hidden !important;
        width: 100% !important;
    }
    
    .menu-item {
        flex-direction: column;
        text-align: center;
        padding: 5px 8px;
        margin: 0;
        flex: 1;
        max-width: none;
        min-height: 50px;
        display: flex;
        align-items: center;
        justify-content: center;
        box-sizing: border-box;
        font-size: 0.7rem;
        border-radius: 0;
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis;
        background-color: #f3f4f6;
        color: #4b5563;
    }
    
    /* 移除鼠标悬浮效果 */
    .menu-item:hover {
        background-color: #f3f4f6 !important;
        transform: none !important;
        cursor: pointer;
    }
    
    .menu-item i {
        margin-right: 0;
        margin-bottom: 3px;
        font-size: 1.1rem;
        /* transition: color 0.3s ease; */
    }
    
    .menu-item span {
        font-size: 0.75rem;
        line-height: 1.2;
        /* transition: color 0.3s ease; */
    }
    
    /* 调整激活菜单项 - 使用更具体的选择器覆盖全局样式 */
    .sidebar .sidebar-menu .menu-item.active {
        background-color: #f3f4f6 !important;
        background-image: none !important;
        color: #805ad5 !important;
        font-weight: normal !important;
        box-shadow: none !important;
        outline: none !important;
        border: none !important;
    }
    
    .sidebar .sidebar-menu .menu-item.active i {
        color: #805ad5 !important;
    }
    
    /* 移除菜单项按钮的轮廓 */
    .menu-item:focus {
        outline: none;
        border: none;
        background-color: #f3f4f6 !important;
    }
    
    .menu-item:active {
        outline: none;
        border: none;
        background-color: #f3f4f6 !important;
    }
    
    /* 确保菜单项在任何状态下都是灰色背景 */
    .menu-item:focus-within {
        background-color: #f3f4f6 !important;
    }
    
    .menu-item:visited {
        background-color: #f3f4f6 !important;
    }
    
    /* 移除所有状态下的边框和轮廓 */
    .menu-item {
        outline: none !important;
        border: none !important;
    }
    
    .menu-item * {
        outline: none !important;
        border: none !important;
    }
    
    /* 调整折叠按钮位置 */
    .toggle-btn {
        display: none;
    }
    
    /* 小屏幕下不显示折叠状态 */
    .sidebar.collapsed {
        height: 50px !important;
        width: 100vw !important;
        padding: 0 !important;
        box-sizing: border-box !important;
        overflow: hidden !important;
        transform: none !important;
        flex-shrink: 0 !important;
    }
    
    /* 小屏幕下隐藏原始的底部导航栏 */
    #bottom-nav {
        display: none !important;
    }
    
    .sidebar.collapsed .menu-item {
        flex-direction: column;
        padding: 5px 8px;
        margin: 0;
        flex: 1;
        max-width: none;
        min-height: 50px;
        box-sizing: border-box;
        border-radius: 0;
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis;
        font-size: 0.7rem;
        background-color: #f3f4f6;
        color: #4b5563;
    }
    
    .sidebar.collapsed .menu-item i {
        margin-right: 0;
        margin-bottom: 3px;
        font-size: 1rem;
    }
    
    .sidebar.collapsed .menu-item span {
        display: inline;
        font-size: 0.7rem;
        white-space: nowrap;
        text-overflow: ellipsis;
        overflow: hidden;
    }
    
    /* 调整折叠状态下的激活菜单项 - 使用更具体的选择器覆盖全局样式 */
    .sidebar.collapsed .sidebar-menu .menu-item.active {
        background-color: #f3f4f6 !important;
        background-image: none !important;
        color: #805ad5 !important;
        font-weight: normal !important;
        box-shadow: none !important;
        outline: none !important;
        border: none !important;
    }
    
    .sidebar.collapsed .sidebar-menu .menu-item.active i {
        color: #805ad5 !important;
    }
    
    /* 移除折叠状态下菜单项的轮廓和边框 */
    .sidebar.collapsed .menu-item:focus {
        outline: none;
        border: none;
        background-color: #f3f4f6 !important;
    }
    
    .sidebar.collapsed .menu-item:active {
        outline: none;
        border: none;
        background-color: #f3f4f6 !important;
    }
    
    /* 确保折叠状态下菜单项在任何状态下都是灰色背景 */
    .sidebar.collapsed .menu-item:focus-within {
        background-color: #f3f4f6 !important;
    }
    
    .sidebar.collapsed .menu-item:visited {
        background-color: #f3f4f6 !important;
    }
    
    .sidebar.collapsed .menu-item {
        outline: none !important;
        border: none !important;
    }
    
    .sidebar.collapsed .menu-item:hover {
        background-color: #f3f4f6 !important;
        transform: none !important;
        cursor: pointer;
    }
    
    .sidebar.collapsed .menu-item * {
        outline: none !important;
        border: none !important;
    }
    
    /* 小屏幕下的日期信息显示 */
    .date-info {
        padding: 12px 16px;
        margin-bottom: 1.5rem;
        gap: 8px;
        z-index: 1;
        position: relative;
    }
    
    .date-display {
        font-size: 0.85rem;
        min-width: 150px;
    }
    
    .week-display {
        font-size: 0.9rem;
        padding: 4px 12px;
    }
    
    .week-display span {
        font-size: 1.1rem;
        margin: 0 2px;
    }
    
    /* 调整小屏幕下的网格布局，确保不超出边界 */
    .container .grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 10px !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
        padding: 12px 0 !important;
        margin: 0 !important;
        overflow-x: hidden !important;
        overflow-y: visible !important;
        z-index: 2;
        position: relative;
    }
    
    /* 进一步调整小屏幕下的卡片样式，确保不超出边界 */
    .card {
        padding: 16px !important;
        box-sizing: border-box !important;
        max-width: 100% !important;
        overflow-x: hidden !important;
        overflow-y: visible !important;
        min-height: 120px !important;
        z-index: 3;
        position: relative;
    }
    
    /* 调整小屏幕下激活卡片的样式，确保不被遮挡 */
    .card.active {
        transform: translateY(-2px) !important;
        margin-bottom: 2px !important;
        z-index: 4;
        position: relative;
    }
    
    /* 调整卡片内的内容样式，确保不超出边界 */
    .card h3 {
        font-size: 1rem !important;
        white-space: nowrap !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
    }
    
    /* 调整时间显示样式，确保不超出边界 */
    .card .time {
        font-size: 1.8rem !important;
        white-space: nowrap !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
        max-width: 100% !important;
    }
    
    .card .time-display {
        font-size: 1.5rem !important;
    }
}

/* 统计分析页面 */
.analytics-container h1 {
    margin-top: 0;
    color: var(--text-primary);
}

/* 确保页面内容适合容器 */
#budget-page, #analytics-page {
    width: 100%;
}

/* 日历视图样式 */
.calendar-view {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 12px;
    margin-top: 20px;
    max-width: 100%;
}

/* 小屏幕日历视图 */
@media (max-width: 768px) {
    .calendar-view {
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
        gap: 8px;
    }
    
    .calendar-day {
        padding: 8px;
        min-height: 100px;
    }
}

.calendar-day {
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 12px;
    background: #f8fafc;
    min-height: 120px;
    position: relative;
    transition: transform 0.2s, box-shadow 0.2s;
}

.calendar-day:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.1);
}

.calendar-day-header {
    font-weight: 600;
    margin-bottom: 8px;
    font-size: 0.9rem;
    color: var(--text-secondary);
    text-align: center;
}

.calendar-day-content {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.domain-block {
    height: 8px;
    border-radius: 4px;
    margin-bottom: 2px;
    position: relative;
}

.domain-block.tooltip {
    cursor: pointer;
}

.tooltip {
    position: relative;
    display: inline-block;
}

.tooltip .tooltiptext {
    visibility: hidden;
    width: 200px;
    background-color: black;
    color: #fff;
    text-align: center;
    border-radius: 6px;
    padding: 8px;
    position: absolute;
    z-index: 1001;
    bottom: 125%;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.8rem;
    opacity: 0;
    transition: opacity 0.3s;
    pointer-events: none;
    white-space: nowrap;
}

/* 确保进度条内的tooltiptext不影响进度条显示 */
.progress-bar .tooltiptext {
    top: -40px;
    bottom: auto;
}

.tooltip:hover .tooltiptext {
    visibility: visible;
    opacity: 1;
}

/* 移除重复的.container定义 */

h1 {
    font-size: 1.5rem;
    margin-bottom: 1rem;
    text-align: center;
    font-weight: 700;
}

/* 日期信息显示 */
.date-info {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 12px;
    padding: 16px 20px;
    margin-bottom: 1.5rem;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    color: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
}

.date-display {
    font-size: 0.95rem;
    font-weight: 500;
    letter-spacing: 0.5px;
    flex: 1;
    min-width: 200px;
}

.week-display {
    font-size: 1.1rem;
    font-weight: 700;
    background: rgba(255, 255, 255, 0.2);
    padding: 6px 16px;
    border-radius: 20px;
    backdrop-filter: blur(10px);
    white-space: nowrap;
}

.week-display span {
    font-size: 1.3rem;
    font-weight: 800;
    margin: 0 4px;
}



/* 计时器网格布局 */
.grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    /* 默认两列布局，包括小屏幕 */
    gap: 16px;
    max-width: 100%;
}

/* 大屏幕网格布局 */
@media (min-width: 769px) {
    .grid {
        grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    }
}

/* 计时器卡片基础样式 */
.card {
    background: var(--card-bg);
    border-radius: 16px;
    padding: 20px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    transition: all 0.2s ease;
    cursor: pointer;
    position: relative;
    border: 2px solid transparent;
    user-select: none;
    /* 防止点击时选中文字 */
}

/* 激活状态的卡片：发光效果 */
.card.active {
    border-color: var(--accent-color);
    transform: translateY(-2px);
    box-shadow: 0 10px 15px -3px rgba(59, 130, 246, 0.2);
}

.card:hover {
    background: #fdfdfd;
}

.card h3 {
    margin: 0 0 8px 0;
    font-size: 1.1rem;
    color: var(--text-secondary);
}

/* 时间显示：等宽字体，防止数字跳动 */
.time {
    font-size: 2.5rem;
    font-weight: 700;
    font-family: "SF Mono", "Monaco", "Consolas", monospace;
    margin-bottom: 12px;
}

/* 进度条轨道 */
.progress-bar {
    height: 8px;
    background: #e2e8f0;
    border-radius: 4px;
    overflow: hidden;
}

/* 进度条填充 */
.progress {
    height: 100%;
    transition: width 0.3s ease;
}

/* 小圆点指示器 */
.dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    position: absolute;
    top: 20px;
    right: 20px;
}

.controls {
    display: flex;
    gap: 12px;
    flex-direction: column;
}

/* 底部按钮 */
.btn-secondary {
    width: 100%;
    margin-top: 24px;
    padding: 12px;
    background: #e2e8f0;
    border: none;
    border-radius: 8px;
    color: var(--text-secondary);
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-secondary:hover {
    background: #cbd5e1;
}

/* 模态框样式 */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
}

.modal-content {
    background-color: var(--card-bg);
    margin: 5% auto;
    padding: 0;
    border-radius: 16px;
    width: 90%;
    max-width: 600px;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
}

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

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

.close {
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    color: var(--text-secondary);
    line-height: 1;
}

.close:hover {
    color: #000;
}

.modal-body {
    padding: 24px;
}

.stats-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 16px;
}

.stats-table th,
.stats-table td {
    padding: 12px 8px;
    text-align: left;
    border-bottom: 1px solid #e2e8f0;
}

.stats-table th {
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.stats-table tr:last-child td {
    border-bottom: none;
}

.stats-section {
    margin-bottom: 24px;
}

.stats-section h3 {
    margin: 0 0 12px 0;
    font-size: 1.2rem;
    color: var(--text-primary);
    border-bottom: 1px solid #e2e8f0;
    padding-bottom: 8px;
}

.session-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.session-item {
    padding: 12px 0;
    border-bottom: 1px solid #f1f1f1;
}

.session-item:last-child {
    border-bottom: none;
}

.session-info {
    display: flex;
    justify-content: space-between;
    font-size: 0.9rem;
}

.session-time {
    font-weight: 500;
    color: var(--text-primary);
}

.session-duration {
    color: var(--text-secondary);
}

/* 适配大屏幕（电脑端） */
@media (min-width: 480px) {
    .grid {
        grid-template-columns: 1fr 1fr;
        /* 电脑端双列 */
    }
}

/* PWA模式下隐藏浏览器插件图标 */

@media all and (display-mode: standalone),
(display-mode: fullscreen),
(display-mode: minimal-ui) {

    /* 1. 锁定根容器，防止插件撑开页面或在 body 级别浮动 */
    /* body {
        position: fixed !important;
        top: 0;
        left: 0;
        width: 100vw;
        height: 100vh;
        overflow: hidden !important;
        padding: 0 !important;
        margin: 0 !important;
    } */

    /* 2. 让 .container 接管全局滚动 */
    /* .container {
        position: relative;
        z-index: 1;
        width: 100%;
        max-width: 500px;
        height: 100vh;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        padding: 20px;
        box-sizing: border-box;
        background-color: var(--bg-color);
    } */

    /* 3. 核心绝招：隐藏 body 下除应用容器外的一切直接子元素 */
    /* 屏蔽所有非 script/style/link 标签且不是 .container 的元素 */
    /* body> :not(.container):not(script):not(style):not(link) {
        display: none !important;
        visibility: hidden !important;
        opacity: 0 !important;
        pointer-events: none !important;
        position: absolute !important;
        top: -9999px !important;
    } */

    /* 精准打击：隐藏挂载在 html 下的所有非 body 和非 head 元素 */
    /* 注意：不能隐藏 head，否则会破坏页面 */
    html> :not(body):not(head) {
        display: none !important;
        visibility: hidden !important;
        width: 0 !important;
        height: 0 !important;
        opacity: 0 !important;
        pointer-events: none !important;
        z-index: -999999 !important;
    }
}

/* 4. 针对 Shadow DOM 注入的特殊补偿 (保留部分原有逻辑作为双重保险) */
/* body.pwa-mode [data-hidden-by-pwa="true"] {
    display: none !important;
} */

/* 强制隐藏翻译条等常见注入 ID */
/* #goog-gt-tt,
.goog-te-banner-frame,
#_chatgpt_ext_ {
    display: none !important;
} */

/* 严禁任何非容器元素响应点击 */
/* body *:not(.container):not(.container *) {
    pointer-events: none !important;
    user-select: none !important;
    max-width: 0 !important;
    max-height: 0 !important;
    overflow: hidden !important;
} */

