/**
 * 待办事项管理系统 - 竖版移动端样式
 * 基于原版PyQt5软件的界面设计
 */

/* 全局样式重置 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* 全局隐藏滚动条但保持滚动功能 */
* {
    scrollbar-width: none; /* Firefox */
    -ms-overflow-style: none; /* IE/Edge */
}

*::-webkit-scrollbar {
    display: none; /* WebKit浏览器 (Chrome, Safari, Edge) */
}

html {
    height: 100%;
    /* 移除html的padding，让header能够从屏幕顶部开始 */
    margin: 0;
    padding: 0;
    background: #ffffff; /* 纯色背景，避免顶部出现额外蓝色 */
    /* 隐藏滚动条但保持滚动功能 */
    scrollbar-width: none; /* Firefox */
    -ms-overflow-style: none; /* IE/Edge */
}

/* 隐藏WebKit浏览器的滚动条 */
html::-webkit-scrollbar {
    display: none;
}

:root {
    /* 标准root选择器，确保安全区变量生效 */
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-right: env(safe-area-inset-right, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-left: env(safe-area-inset-left, 0px);
    --header-base-height: 60px;
    --header-offset: calc(var(--header-base-height) + var(--safe-top) + 30px);
}

/* 移除伪元素覆盖层，解决蓝色背景问题 */

body {
    height: 100%;
    /* 移除body的padding，让header从顶部开始 */
    margin: 0;
    padding: 0;
}

:root {
    /* iOS安全区域变量 - 使用env()，旧版iOS会自动fallback到0px */
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-right: env(safe-area-inset-right, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-left: env(safe-area-inset-left, 0px);
    --header-base-height: 60px;
    /* 统一的头部占位高度，避免被遮挡 */
    --header-offset: calc(var(--header-base-height) + var(--safe-top) + 30px);
}

body {
    font-family: 'Microsoft YaHei', 'PingFang SC', 'Helvetica Neue', Arial, sans-serif;
    background: #ffffff; /* 与容器一致的纯白背景，消除延伸的蓝色 */
    color: #2c3e50;
    line-height: 1.6;
    min-height: 100vh;
    min-height: 100dvh; /* 动态视口高度，更准确的移动端支持 */
    overflow-x: hidden;
    /* 聚焦时滚动留出头部空间，防止输入框被遮住 */
    scroll-padding-top: var(--header-offset);
    /* 移除body的padding，让header从顶部开始 */
    /* 隐藏滚动条但保持滚动功能 */
    scrollbar-width: none; /* Firefox */
    -ms-overflow-style: none; /* IE/Edge */
}

/* 隐藏WebKit浏览器的滚动条 */
body::-webkit-scrollbar {
    display: none;
}

/* 表单控件在聚焦滚动时预留头部空间，避免被固定头遮挡 */
input,
textarea,
button,
select {
    scroll-margin-top: var(--header-offset);
}

/* 主容器 - 竖版设计 */
.app-container {
    max-width: 100%;
    min-height: 100dvh;
    background: #ffffff;
    position: relative;
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.1);
    /* 移除容器的padding，让header能够覆盖整个顶部 */
    margin: 0;
    padding: 0;
}

/* 头部样式 */
.header {
    background: linear-gradient(135deg, #4895ef 0%, #3f37c9 100%);
    color: white;
    min-height: calc(var(--header-base-height) + var(--safe-top));
    padding-top: calc(15px + var(--safe-top));
    padding-bottom: 15px;
    padding-left: calc(20px + var(--safe-left));
    padding-right: calc(20px + var(--safe-right));
    position: fixed;
    top: calc(-1 * var(--safe-top));
    left: 0;
    right: 0;
    z-index: 200;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    /* header向上延伸以覆盖安全区域，背景色会自动覆盖 */
    /* 确保header完全覆盖顶部，包括安全区域 */
    height: calc(var(--header-base-height) + var(--safe-top) + 15px + 15px);
}

.status-bar-bg {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: max(var(--safe-top), 20px); /* 为不支持env的设备提供可见高度 */
    background: linear-gradient(135deg, #4895ef 0%, #3f37c9 100%);
    z-index: 199; /* 低于header，覆盖灵动岛区域 */
    pointer-events: none;
}

.header::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: var(--safe-top);
    background: linear-gradient(135deg, #4895ef 0%, #3f37c9 100%);
    z-index: -1;
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.title-section {
    display: flex;
    align-items: baseline;
    gap: 8px;
}

.main-title {
    font-size: 18px;
    font-weight: 700;
    color: #ffffff;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

.version-label {
    background: #ff4757;
    color: white;
    font-size: 10px;
    font-weight: bold;
    padding: 2px 6px;
    border-radius: 3px;
    text-shadow: none;
}

.header-actions {
    display: flex;
    gap: 10px;
}

.refresh-btn {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 14px;
}

.refresh-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: rotate(180deg);
}

/* 主内容区域 */
.main-content {
    padding: 20px calc(15px + var(--safe-left)) calc(20px + var(--safe-bottom)) calc(15px + var(--safe-left));
    margin-top: var(--header-offset);
    min-height: calc(100dvh - var(--header-offset) - var(--safe-bottom) - 40px);
}

/* 消息提示 */
.message {
    position: fixed;
    top: calc(var(--safe-top) + var(--header-base-height) + 10px);
    left: calc(12px + var(--safe-left));
    right: calc(12px + var(--safe-right));
    padding: 12px 15px;
    margin: 0;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    animation: slideInDown 0.3s ease;
    z-index: 500;
}

.message.success {
    background: #d4edda;
    color: #155724;
    border-left: 4px solid #27ae60;
}

.message.error {
    background: #f8d7da;
    color: #721c24;
    border-left: 4px solid #e74c3c;
}

/* 添加待办事项区域 */
.add-todo-section {
    margin-bottom: 25px;
}

.add-form {
    width: 100%;
}

.input-group {
    display: flex;
    gap: 10px;
    align-items: center;
}

.todo-input {
    flex: 1;
    padding: 15px 18px;
    border: 2px solid #e1e8ed;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 400;
    background: #f8f9fa;
    transition: all 0.3s ease;
    outline: none;
}

.todo-input:focus {
    border-color: #4895ef;
    background: white;
    box-shadow: 0 0 0 4px rgba(72, 149, 239, 0.1);
}

.todo-input::placeholder {
    color: #8e9aaf;
}

.add-btn {
    background: linear-gradient(135deg, #4895ef 0%, #3f37c9 100%);
    border: none;
    color: white;
    width: 50px;
    height: 50px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 18px;
    box-shadow: 0 4px 15px rgba(72, 149, 239, 0.3);
}

.add-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(72, 149, 239, 0.4);
}

.add-btn:active {
    transform: translateY(0);
}

/* 待办事项列表 */
.todo-list-section {
    margin-top: 20px;
}

.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: #8e9aaf;
}

.empty-state i {
    font-size: 64px;
    margin-bottom: 20px;
    opacity: 0.5;
}

.empty-state p {
    font-size: 16px;
    margin-bottom: 8px;
}

.todo-group {
    margin-bottom: 30px;
}

.group-title {
    font-size: 16px;
    font-weight: 600;
    color: #2c3e50;
    margin-bottom: 15px;
    padding: 8px 12px;
    background: #f8f9fa;
    border-radius: 8px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.group-title i {
    color: #4895ef;
}

.count {
    background: #4895ef;
    color: white;
    font-size: 12px;
    padding: 2px 6px;
    border-radius: 10px;
    min-width: 18px;
    text-align: center;
}

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

.todo-item {
    background: white;
    border: 2px solid #e1e8ed;
    border-radius: 12px;
    padding: 6px 14px 14px;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
    transition: all 0.3s ease;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.todo-item:active,
.todo-item:focus-within {
    border-color: #4895ef;
    box-shadow: 0 0 0 3px rgba(72, 149, 239, 0.25);
}

.todo-item:hover {
    border-color: #4895ef;
    box-shadow: 0 4px 15px rgba(72, 149, 239, 0.15);
    transform: translateY(-2px);
}

.todo-item.important {
    border-color: #ff4757;
    background: linear-gradient(to right, rgba(255, 71, 87, 0.05), transparent);
}

/* 重要状态的待办卡片选中时的边框效果 - 增强版 */
.todo-item.important:active,
.todo-item.important:focus-within {
    border-color: #ff4757;
    border-width: 3px;
    box-shadow: 0 0 0 4px rgba(255, 71, 87, 0.4), 0 4px 20px rgba(255, 71, 87, 0.3);
    background: linear-gradient(to right, rgba(255, 71, 87, 0.1), transparent);
}

.todo-item.important:hover {
    border-color: #ff4757;
    box-shadow: 0 4px 15px rgba(255, 71, 87, 0.15);
    transform: translateY(-2px);
}

.todo-item.completed {
    opacity: 0.7;
    background: #f8f9fa;
}

.todo-item.completed .todo-text {
    text-decoration: line-through;
    color: #8e9aaf;
}

.todo-content {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.todo-header {
    width: 100%;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 10px;
    margin-top: 0;
}

.todo-text {
    font-size: 15px;
    font-weight: 400;
    color: #2c3e50;
    line-height: 1.5;
    word-break: break-word;
    margin-bottom: 8px;
}

.todo-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    font-size: 12px;
    color: #8e9aaf;
    margin-bottom: 6px;
    justify-content: flex-start;
    align-items: center;
    width: 100%;
    margin-top: 0;
}

.todo-date,
.todo-due {
    display: flex;
    align-items: center;
    gap: 4px;
}

.todo-actions {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}

.action-btn {
    background: #f8f9fa;
    border: 1px solid #e1e8ed;
    color: #6c757d;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 12px;
}

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

.action-btn.important-btn:hover {
    background: #fff3cd;
    border-color: #ffc107;
    color: #ffc107;
}

.action-btn.complete-btn:hover {
    background: #d4edda;
    border-color: #27ae60;
    color: #27ae60;
}

.action-btn.edit-btn:hover {
    background: #d9ecff;
    border-color: #3498db;
    color: #3498db;
}

.action-btn.delete-btn:hover {
    background: #f8d7da;
    border-color: #e74c3c;
    color: #e74c3c;
}

.action-btn.uncomplete-btn:hover {
    background: #fff3cd;
    border-color: #ffc107;
    color: #ffc107;
}

.action-btn.copy-btn:hover {
    background: #e7f1ff;
    border-color: #4895ef;
    color: #4895ef;
}

.action-btn .fa-star.active {
    color: #ff4757;
}

/* 底部统计信息 */
.footer {
    background: #f8f9fa;
    border-top: 1px solid #e1e8ed;
    padding: calc(10px + var(--safe-bottom)) calc(12px + var(--safe-left)) calc(10px + var(--safe-bottom)) calc(12px + var(--safe-right));
    position: sticky;
    bottom: 0;
    overscroll-behavior: contain; /* 只防止footer区域弹性滚动，不影响页面内容 */
    touch-action: pan-y; /* 允许垂直滚动，但限制其他手势 */
}

.stats {
    display: flex;
    justify-content: space-around;
    text-align: center;
    gap: 8px;
}

.stat-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.stat-number {
    font-size: 18px;
    font-weight: 700;
    color: #4895ef;
}

.stat-label {
    font-size: 12px;
    color: #8e9aaf;
    font-weight: 500;
}

/* 模态框样式 */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    animation: fadeIn 0.3s ease;
}

.modal-content {
    background: white;
    margin: 15% auto;
    padding: 0;
    border-radius: 12px;
    width: 90%;
    max-width: 500px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    animation: slideInUp 0.3s ease;
}

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

.modal-header h3 {
    font-size: 18px;
    font-weight: 600;
    color: #2c3e50;
}

.close-btn {
    background: none;
    border: none;
    font-size: 24px;
    color: #8e9aaf;
    cursor: pointer;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.3s ease;
}

.close-btn:hover {
    background: #f8f9fa;
    color: #2c3e50;
}

.edit-form {
    padding: 20px;
}

.edit-textarea {
    width: 100%;
    min-height: 120px;
    padding: 15px;
    border: 2px solid #e1e8ed;
    border-radius: 8px;
    font-size: 15px;
    font-family: inherit;
    resize: vertical;
    outline: none;
    transition: all 0.3s ease;
}

.edit-textarea:focus {
    border-color: #4895ef;
    box-shadow: 0 0 0 4px rgba(72, 149, 239, 0.1);
}

.modal-actions {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
    margin-top: 20px;
}

.cancel-btn,
.save-btn {
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
}

.cancel-btn {
    background: #f8f9fa;
    color: #6c757d;
    border: 1px solid #e1e8ed;
}

.cancel-btn:hover {
    background: #e9ecef;
}

.save-btn {
    background: linear-gradient(135deg, #4895ef 0%, #3f37c9 100%);
    color: white;
}

.save-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(72, 149, 239, 0.3);
}

/* 动画效果 */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

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

@keyframes slideInDown {
    from {
        transform: translateY(-20px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.05); }
    100% { transform: scale(1); }
}

/* 响应式设计 */
@media (max-width: 480px) {
    :root {
        --header-mobile-height: calc(var(--header-base-height) * 1.5 + var(--safe-top) + 40px);
        --header-mobile-visible-bottom: calc(var(--header-base-height) * 1.5 + 40px);
    }
    
    .header {
        padding-top: calc(20px + var(--safe-top));
        padding-bottom: 20px;
        padding-left: calc(15px + var(--safe-left));
        padding-right: calc(15px + var(--safe-right));
        min-height: calc(var(--header-base-height) * 1.5 + var(--safe-top));
        height: var(--header-mobile-height);
    }
    
    .header-content {
        margin-top: 50px;
    }
    
    .main-title {
        font-size: 16px;
    }
    
    .main-content {
        padding: 15px 12px;
        margin-top: var(--header-mobile-visible-bottom);
    }
    
    .message {
        top: calc(var(--safe-top) + var(--header-base-height) * 1.5 + 10px);
    }
    
    .todo-input {
        padding: 12px 15px;
        font-size: 15px;
    }
    
    .add-btn {
        width: 45px;
        height: 45px;
        font-size: 16px;
    }
    
    .todo-item {
        padding: 8px 12px 12px;
        gap: 10px;
        position: static;
        flex-direction: column;
        align-items: stretch;
    }

    .todo-actions {
        position: static;
        gap: 8px;
        justify-content: flex-end;
        width: auto;
    }
    
    .todo-content {
        width: 100%;
    }

    .todo-text {
        font-size: 14px;
    }

    .todo-meta {
        width: 100%;
        justify-content: flex-start; /* 底部靠左显示时间和提醒 */
    }
    
    .action-btn {
        width: 30px;
        height: 30px;
        font-size: 11px;
    }
    
    .modal-content {
        width: 95%;
        margin: 20% auto;
    }
}

@media (max-width: 360px) {
    .header-content {
        flex-direction: column;
        gap: 10px;
        text-align: center;
    }
    
    .stats {
        gap: 10px;
    }
    
    .stat-number {
        font-size: 16px;
    }
    
    .todo-meta {
        gap: 8px;
    }
}

/* 横屏模式优化 */
@media (max-height: 600px) and (orientation: landscape) {
    .modal-content {
        margin: 5% auto;
        max-height: 80vh;
        overflow-y: auto;
    }
    
    .edit-textarea {
        min-height: 80px;
    }
}

/* 触摸设备优化 */
@media (hover: none) {
    .action-btn:hover,
    .add-btn:hover,
    .refresh-btn:hover {
        transform: none;
    }
    
    .action-btn:active {
        transform: scale(0.95);
    }
    
    .add-btn:active {
        transform: scale(0.95);
    }
}

/* 高对比度模式支持 */
@media (prefers-contrast: high) {
    .todo-item {
        border-width: 3px;
    }
    
    .action-btn {
        border-width: 2px;
    }
}

/* 减少动画模式支持 */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* 暗色主题支持 */
@media (prefers-color-scheme: dark) {
    body {
        background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    }
    
    .app-container {
        background: #1a1a2e;
        color: #e4e4e7;
    }
    
    .header {
        background: linear-gradient(135deg, #3f37c9 0%, #4895ef 100%);
    }
    
    .todo-item {
        background: #0f3460;
        border-color: #16213e;
        color: #e4e4e7;
    }
    
    .todo-text {
        color: #e4e4e7;
    }
    
    .todo-input {
        background: #16213e;
        border-color: #0f3460;
        color: #e4e4e7;
    }
    
    .footer {
        background: #0f3460;
        border-color: #16213e;
    }
    
    .group-title {
        background: #0f3460;
        color: #e4e4e7;
    }
    
    .modal-content {
        background: #1a1a2e;
        color: #e4e4e7;
    }
    
    .edit-textarea {
        background: #16213e;
        border-color: #0f3460;
        color: #e4e4e7;
    }
}