/* CSS变量定义 */
:root {
    --primary-color: #4CAF50;
    --primary-hover: #45a049;
    --secondary-color: #2196F3;
    --secondary-hover: #1976D2;
    --accent-color: #FF9800;
    --danger-color: #f44336;
    --text-color: #333;
    --text-light: #666;
    --bg-color: #f5f5f5;
    --card-bg: #ffffff;
    --border-color: #e0e0e0;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    --shadow-hover: 0 4px 12px rgba(0, 0, 0, 0.15);
    --border-radius: 8px;
    --spacing: 16px;
    --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --transition: all 0.2s ease;
}

/* 基础重置和全局样式 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-family);
    background-color: var(--bg-color);
    color: var(--text-color);
    line-height: 1.6;
    min-height: 100vh;
    margin: 0;
    padding: 0;
    overflow-x: hidden;
}

/* 侧边栏样式 */
.sidebar {
    position: fixed;
    left: 0;
    top: 0;
    width: 280px;
    height: 100vh;
    background: linear-gradient(180deg, var(--card-bg) 0%, #f8f9fa 100%);
    box-shadow: 2px 0 15px rgba(0, 0, 0, 0.1);
    transform: translateX(-250px);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border-color);
}

.sidebar.expanded {
    transform: translateX(0);
}

.sidebar-toggle {
    position: absolute;
    right: -25px;
    top: 50%;
    transform: translateY(-50%);
    width: 25px;
    height: 50px;
    background: rgba(255, 255, 255, 0.95);
    border: 1px solid var(--border-color);
    border-left: none;
    border-radius: 0 8px 8px 0;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--transition);
    box-shadow: 1px 0 3px rgba(0, 0, 0, 0.05);
    backdrop-filter: blur(10px);
}

.sidebar-toggle::after {
    content: '展开';
    position: absolute;
    right: -50px;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(255, 255, 255, 0.95);
    color: var(--text-light);
    padding: 4px 8px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 11px;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.sidebar-toggle:hover::after {
    opacity: 1;
}

.sidebar.expanded .sidebar-toggle::after {
    content: '收起';
}

.sidebar-toggle:hover {
    background: rgba(255, 255, 255, 1);
    border-color: var(--primary-color);
    box-shadow: 1px 0 8px rgba(76, 175, 80, 0.2);
}

.toggle-icon {
    color: var(--text-light);
    font-size: 16px;
    transition: all 0.3s ease;
}

.sidebar.expanded .toggle-icon {
    transform: rotate(180deg);
    color: var(--primary-color);
}

.sidebar-toggle:hover .toggle-icon {
    color: var(--primary-color);
}

.sidebar-content {
    padding: 20px;
    flex: 1;
    display: flex;
    flex-direction: column;
    opacity: 0;
    transition: opacity 0.3s ease 0.1s;
}

.sidebar.expanded .sidebar-content {
    opacity: 1;
}

/* 用户资料区域 */
.user-profile {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px;
    background: var(--bg-color);
    border-radius: var(--border-radius);
    margin-bottom: 20px;
}

.user-avatar {
    width: 48px;
    height: 48px;
    background: var(--primary-color);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    color: white;
}

.user-details {
    flex: 1;
}

.username {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-color);
    margin-bottom: 4px;
}

.user-status {
    font-size: 12px;
    color: var(--primary-color);
    font-weight: 500;
}

/* 导航菜单 */
.sidebar-nav {
    flex: 1;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: var(--transition);
    margin-bottom: 8px;
}

.nav-item:hover {
    background: var(--bg-color);
}

.nav-item.active {
    background: var(--primary-color);
    color: white;
}

.nav-icon {
    font-size: 18px;
    width: 24px;
    text-align: center;
}

.nav-text {
    font-size: 14px;
    font-weight: 500;
}

/* 侧边栏底部 */
.sidebar-footer {
    margin-top: auto;
    padding-top: 20px;
    border-top: 1px solid var(--border-color);
}

.logout-btn {
    width: 100%;
    background: var(--danger-color);
    color: white;
    border: none;
    padding: 12px 16px;
    border-radius: var(--border-radius);
    font-size: 14px;
    cursor: pointer;
    transition: var(--transition);
    font-weight: 500;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.logout-btn:hover {
    background: #d32f2f;
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(244, 67, 54, 0.3);
}

.logout-icon {
    font-size: 16px;
}

.logout-text {
    font-size: 14px;
}

/* 主内容区域 */
.main-content {
    margin-left: 30px;
    padding: var(--spacing);
    transition: margin-left 0.3s ease;
    min-height: 100vh;
}

.main-content.sidebar-expanded {
    margin-left: 280px;
}

/* 主容器 - 三列网格布局 */
.container {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: var(--spacing);
    max-width: 1400px;
    margin: 0 auto;
    min-height: calc(100vh - 32px);
}

/* 通用区域样式 */
.todo-section,
.pomodoro-section,
.notes-section {
    background: var(--card-bg);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    padding: var(--spacing);
    display: flex;
    flex-direction: column;
}

/* 区域标题 */
.section-header {
    margin-bottom: var(--spacing);
    border-bottom: 2px solid var(--border-color);
    padding-bottom: 12px;
}

.section-header h2 {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-color);
}

/* 按钮通用样式 */
.btn {
    padding: 10px 16px;
    border: none;
    border-radius: var(--border-radius);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    outline: none;
    will-change: transform, box-shadow;
}

.btn:focus {
    box-shadow: 0 0 0 3px rgba(76, 175, 80, 0.3);
}

.btn-primary {
    background-color: var(--primary-color);
    color: white;
}

.btn-primary:hover:not(:disabled) {
    background-color: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: var(--shadow-hover);
}

.btn-secondary {
    background-color: var(--secondary-color);
    color: white;
}

.btn-secondary:hover:not(:disabled) {
    background-color: var(--secondary-hover);
    transform: translateY(-1px);
    box-shadow: var(--shadow-hover);
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

/* 待办清单样式 */
.todo-input-container {
    margin-bottom: var(--spacing);
}

#todo-input {
    width: 100%;
    padding: 12px;
    border: 2px solid var(--border-color);
    border-radius: var(--border-radius);
    font-size: 14px;
    transition: var(--transition);
    will-change: border-color, box-shadow;
}

#todo-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(76, 175, 80, 0.1);
}

.todo-list {
    list-style: none;
    flex: 1;
    overflow-y: auto;
    margin-bottom: var(--spacing);
}

.todo-item {
    display: flex;
    align-items: center;
    padding: 12px;
    margin-bottom: 8px;
    background: var(--bg-color);
    border-radius: var(--border-radius);
    transition: var(--transition);
    will-change: transform, box-shadow;
}

.todo-item:hover {
    transform: translateX(4px);
    box-shadow: var(--shadow-hover);
}

.todo-item.completed {
    opacity: 0.7;
}

.todo-item.completed .todo-text {
    text-decoration: line-through;
    color: var(--text-light);
}

.todo-checkbox {
    margin-right: 12px;
    width: 18px;
    height: 18px;
    cursor: pointer;
}

.todo-text {
    flex: 1;
    font-size: 14px;
}

.todo-delete {
    background: var(--danger-color);
    color: white;
    border: none;
    border-radius: 4px;
    padding: 4px 8px;
    font-size: 12px;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.todo-item:hover .todo-delete {
    opacity: 1;
}

.todo-stats {
    padding: 12px;
    background: var(--bg-color);
    border-radius: var(--border-radius);
    text-align: center;
    font-size: 14px;
    color: var(--text-light);
}

/* 番茄钟样式 */
.timer-display {
    text-align: center;
    margin-bottom: calc(var(--spacing) * 2);
}

.timer-time {
    font-size: 3rem;
    font-weight: 700;
    color: var(--primary-color);
    margin-bottom: 8px;
    font-family: 'Courier New', monospace;
}

.timer-mode {
    font-size: 1.1rem;
    color: var(--text-light);
    font-weight: 500;
}

.timer-controls {
    display: flex;
    gap: 12px;
    justify-content: center;
    margin-bottom: calc(var(--spacing) * 2);
}

.timer-controls .btn {
    flex: 1;
    max-width: 100px;
}

.timer-stats {
    margin-top: auto;
    padding: 16px;
    background: var(--bg-color);
    border-radius: var(--border-radius);
    text-align: center;
}

.stat-item {
    font-size: 14px;
    color: var(--text-light);
}

.stat-label {
    margin-right: 8px;
}

/* Markdown笔记样式 */
.notes-container {
    display: flex;
    flex-direction: column;
    flex: 1;
    gap: var(--spacing);
}

.notes-editor {
    flex: 1;
}

.markdown-input {
    width: 100%;
    height: 300px;
    padding: 12px;
    border: 2px solid var(--border-color);
    border-radius: var(--border-radius);
    font-family: 'Courier New', monospace;
    font-size: 14px;
    resize: vertical;
    transition: var(--transition);
    will-change: border-color, box-shadow;
}

.markdown-input:focus {
    outline: none;
    border-color: var(--secondary-color);
    box-shadow: 0 0 0 3px rgba(33, 150, 243, 0.1);
}

.notes-preview {
    flex: 1;
}

.markdown-preview {
    height: 300px;
    padding: 12px;
    border: 2px solid var(--border-color);
    border-radius: var(--border-radius);
    background: var(--card-bg);
    overflow-y: auto;
    font-size: 14px;
    line-height: 1.6;
}

.preview-placeholder {
    color: var(--text-light);
    font-style: italic;
}

/* Markdown预览内容样式 */
.markdown-preview h1,
.markdown-preview h2,
.markdown-preview h3 {
    margin: 16px 0 8px 0;
    color: var(--text-color);
}

.markdown-preview h1 {
    font-size: 1.5rem;
}

.markdown-preview h2 {
    font-size: 1.3rem;
}

.markdown-preview h3 {
    font-size: 1.1rem;
}

.markdown-preview p {
    margin: 8px 0;
}

.markdown-preview ul,
.markdown-preview ol {
    margin: 8px 0;
    padding-left: 24px;
}

.markdown-preview li {
    margin: 4px 0;
}

.markdown-preview strong {
    font-weight: 600;
}

.markdown-preview em {
    font-style: italic;
}

.markdown-preview a {
    color: var(--secondary-color);
    text-decoration: none;
}

.markdown-preview a:hover {
    text-decoration: underline;
}

.markdown-preview code {
    background: var(--bg-color);
    padding: 2px 4px;
    border-radius: 3px;
    font-family: 'Courier New', monospace;
    font-size: 0.9em;
}

.markdown-preview pre {
    background: var(--bg-color);
    padding: 12px;
    border-radius: var(--border-radius);
    overflow-x: auto;
    margin: 12px 0;
}

.markdown-preview pre code {
    background: none;
    padding: 0;
}

.markdown-preview del {
    color: var(--text-light);
}

/* 无障碍辅助类 */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* 响应式设计 */
/* 平板端 (768px - 1024px) */
@media (max-width: 1024px) {
    .container {
        grid-template-columns: 1fr 1fr;
        grid-template-rows: auto auto;
    }

    .notes-section {
        grid-column: 1 / -1;
    }

    .notes-container {
        flex-direction: row;
    }

    .notes-editor,
    .notes-preview {
        flex: 1;
    }
}

/* 移动端 (< 768px) */
@media (max-width: 768px) {
    .main-content {
        margin-left: 0;
        padding: 8px;
    }

    .main-content.sidebar-expanded {
        margin-left: 0;
    }

    .sidebar {
        width: 100%;
        transform: translateX(-100%);
    }

    .sidebar.expanded {
        transform: translateX(0);
    }

    .sidebar-toggle {
        right: -50px;
        width: 50px;
        height: 50px;
    }

    .toggle-icon {
        font-size: 20px;
    }

    .container {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .section-header h2 {
        font-size: 1.3rem;
    }

    .timer-time {
        font-size: 2.5rem;
    }

    .timer-controls {
        flex-direction: column;
        gap: 8px;
    }

    .timer-controls .btn {
        max-width: none;
    }

    .notes-container {
        flex-direction: column;
    }

    .markdown-input,
    .markdown-preview {
        height: 250px;
    }

    .btn {
        padding: 12px 16px;
        font-size: 16px;
        /* 防止iOS缩放 */
    }

    #todo-input {
        font-size: 16px;
        /* 防止iOS缩放 */
    }
}

/* 小屏幕移动端 (< 480px) */
@media (max-width: 480px) {
    .main-content {
        padding: 4px;
    }

    .container {
        gap: 8px;
    }

    .todo-section,
    .pomodoro-section,
    .notes-section {
        padding: 12px;
    }

    .timer-time {
        font-size: 2rem;
    }

    .markdown-input,
    .markdown-preview {
        height: 200px;
    }

    .sidebar-content {
        padding: 15px;
    }

    .user-profile {
        padding: 12px;
    }

    .nav-item {
        padding: 10px 12px;
    }
}

/* 番茄钟通知动画 */
@keyframes pulse {
    0% {
        transform: scale(1);
        opacity: 1;
    }

    50% {
        transform: scale(1.05);
        opacity: 0.8;
    }

    100% {
        transform: scale(1);
        opacity: 1;
    }
}

.timer-time.pulse {
    animation: pulse 0.5s ease-in-out 3;
}

/* 通知样式增强 */
.pomodoro-notification {
    font-family: var(--font-family);
}

.pomodoro-notification h3 {
    color: var(--text-color);
}

.pomodoro-notification .notification-close:hover {
    color: var(--text-color);
    background: var(--bg-color);
    border-radius: 50%;
}