:root {
    --primary: #4f8cff;
    --primary-dark: #3a6fd8;
    --bg: #f2f4f8;
    --card: #ffffff;
    --text: #1f2430;
    --text-sub: #8a93a6;
    --danger: #ff5c5c;
    --radius: 16px;
    --shadow: 0 2px 12px rgba(30, 40, 70, .08);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

body {
    font-family: -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    padding-bottom: calc(64px + env(safe-area-inset-bottom));
}

/* 顶栏 */
.app-header {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
    background: linear-gradient(135deg, var(--primary), #7aa9ff);
    color: #fff;
    border-radius: 0 0 20px 20px;
    box-shadow: var(--shadow);
}

.nav-btn {
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 12px;
    background: rgba(255, 255, 255, .18);
    color: #fff;
    font-size: 22px;
    cursor: pointer;
}

.nav-btn:active { background: rgba(255, 255, 255, .32); }

.date-box { text-align: center; cursor: pointer; user-select: none; }
.date-main { font-size: 18px; font-weight: 600; }
.date-sub { font-size: 12px; opacity: .85; margin-top: 2px; }

main { padding: 14px; max-width: 560px; margin: 0 auto; }

.card {
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 14px;
}

/* 登录 / 注册 */
.auth-title { text-align: center; font-size: 18px; margin: 6px 0 4px; }

.auth-form { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }

.auth-form input {
    padding: 12px 14px;
    border: 1.5px solid #e3e8f0;
    border-radius: 12px;
    font-size: 15px;
    outline: none;
    background: #f8f9fc;
}

.auth-form input:focus { border-color: var(--primary); background: #fff; }

.auth-btn { padding: 12px; }

.auth-switch { text-align: center; font-size: 13px; color: var(--text-sub); margin-top: 14px; }
.auth-switch a { color: var(--primary); text-decoration: none; font-weight: 600; }

/* 用户信息条 */
.user-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 10px 14px;
    margin-bottom: 12px;
    font-size: 14px;
}

.logout-btn {
    border: none;
    background: none;
    color: var(--danger);
    font-size: 13px;
    cursor: pointer;
    padding: 4px 6px;
}

/* 未登录时隐藏业务界面 */
body.logged-out #tab-tasks,
body.logged-out #tab-habits,
body.logged-out #tab-stats,
body.logged-out .tab-bar { display: none; }

/* 附件 */
.task-item { flex-wrap: wrap; }

.att-toggle {
    border: none;
    background: none;
    font-size: 15px;
    cursor: pointer;
    padding: 4px;
    color: var(--text-sub);
    position: relative;
}

.att-count {
    position: absolute;
    top: -4px;
    right: -6px;
    background: var(--primary);
    color: #fff;
    font-size: 10px;
    line-height: 1;
    padding: 2px 5px;
    border-radius: 8px;
}

.att-panel { flex-basis: 100%; padding: 4px 0 8px; }

.att-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.att-empty { font-size: 12px; color: var(--text-sub); }

.att-chip {
    position: relative;
    width: 108px;
    border: 1px solid #e7ebf3;
    border-radius: 10px;
    overflow: hidden;
    background: #f8f9fc;
}

.att-chip.img img {
    width: 100%;
    height: 72px;
    object-fit: cover;
    display: block;
}

.att-file {
    height: 72px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 6px;
}

.att-file-icon { font-size: 22px; }

.att-file-name {
    font-size: 10px;
    color: var(--text-sub);
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.att-meta {
    display: flex;
    flex-direction: column;
    padding: 4px 6px;
    gap: 1px;
}

.att-name {
    font-size: 11px;
    color: var(--text);
    text-decoration: none;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.att-size { font-size: 10px; color: var(--text-sub); }

.att-ops {
    position: absolute;
    top: 2px;
    right: 2px;
    display: flex;
    gap: 2px;
    opacity: 0;
    transition: opacity .15s;
}

.att-chip:hover .att-ops { opacity: 1; }

.att-ops button {
    border: none;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: rgba(31, 36, 48, .72);
    color: #fff;
    font-size: 11px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

.att-add {
    width: 60px;
    height: 72px;
    border: 1.5px dashed #c6cede;
    border-radius: 10px;
    background: none;
    color: var(--text-sub);
    font-size: 24px;
    cursor: pointer;
}

.att-add:active { border-color: var(--primary); color: var(--primary); }

/* 添加行 */
.add-row { display: flex; gap: 8px; margin: 10px 0; }

.add-row input[type="text"] {
    flex: 1;
    min-width: 0;
    padding: 11px 14px;
    border: 1.5px solid #e3e8f0;
    border-radius: 12px;
    font-size: 15px;
    outline: none;
    background: #f8f9fc;
}

.add-row input[type="text"]:focus { border-color: var(--primary); background: #fff; }

.add-row input[type="color"] {
    width: 44px;
    height: 44px;
    border: none;
    border-radius: 12px;
    background: none;
    cursor: pointer;
    padding: 2px;
}

.primary-btn {
    padding: 11px 18px;
    border: none;
    border-radius: 12px;
    background: var(--primary);
    color: #fff;
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
}

.primary-btn:active { background: var(--primary-dark); }

/* 进度 */
.progress-row { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--text-sub); }
.progress-bar { flex: 1; height: 8px; background: #edf0f6; border-radius: 4px; overflow: hidden; }
.progress-fill { height: 100%; width: 0; background: linear-gradient(90deg, var(--primary), #7aa9ff); border-radius: 4px; transition: width .3s; }

/* 任务列表 */
.task-list, .habit-list { list-style: none; margin-top: 6px; }

.task-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 4px;
    border-bottom: 1px solid #f0f2f7;
}

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

.check-circle {
    width: 24px;
    height: 24px;
    flex-shrink: 0;
    border: 2px solid #c6cede;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    color: transparent;
    transition: all .15s;
}

.task-item.done .check-circle { background: var(--primary); border-color: var(--primary); color: #fff; }

.task-title { flex: 1; font-size: 15px; word-break: break-all; }
.task-item.done .task-title { color: var(--text-sub); text-decoration: line-through; }

.del-btn {
    border: none;
    background: none;
    color: var(--text-sub);
    font-size: 17px;
    cursor: pointer;
    padding: 4px;
    visibility: hidden;
}

.task-item:hover .del-btn, .task-item:active .del-btn { visibility: visible; }

.empty-tip { text-align: center; color: var(--text-sub); font-size: 14px; padding: 26px 0; }

/* 习惯卡片 */
.habit-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 4px;
    border-bottom: 1px solid #f0f2f7;
}

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

.habit-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }

.habit-name { flex: 1; font-size: 15px; }
.habit-name small { display: block; color: var(--text-sub); font-size: 12px; margin-top: 2px; }

.checkin-btn {
    padding: 8px 16px;
    border: none;
    border-radius: 20px;
    background: #edf0f6;
    color: var(--text-sub);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all .15s;
}

.checkin-btn.checked { background: var(--primary); color: #fff; }

/* 概览图表 */
.stat-chart {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    height: 150px;
    padding: 10px 0 4px;
}

.stat-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; height: 100%; justify-content: flex-end; }

.stat-bar {
    width: 60%;
    max-width: 34px;
    background: linear-gradient(180deg, var(--primary), #7aa9ff);
    border-radius: 6px 6px 2px 2px;
    min-height: 3px;
    transition: height .4s;
}

.stat-col .dots { font-size: 10px; letter-spacing: 2px; }

.stat-label { font-size: 11px; color: var(--text-sub); }
.stat-tip { font-size: 11px; color: var(--text-sub); margin-top: 8px; text-align: center; }

/* 底部导航 */
.tab-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    background: rgba(255, 255, 255, .95);
    backdrop-filter: blur(10px);
    border-top: 1px solid #e8ebf2;
    padding-bottom: env(safe-area-inset-bottom);
}

.tab-btn {
    flex: 1;
    border: none;
    background: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 9px 0;
    font-size: 11px;
    color: var(--text-sub);
    cursor: pointer;
}

.tab-btn .tab-icon { font-size: 20px; line-height: 1; }
.tab-btn.active { color: var(--primary); font-weight: 600; }

/* toast */
#toast {
    position: fixed;
    bottom: 90px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(31, 36, 48, .9);
    color: #fff;
    padding: 9px 18px;
    border-radius: 20px;
    font-size: 13px;
    opacity: 0;
    pointer-events: none;
    transition: opacity .25s;
    z-index: 99;
}

#toast.show { opacity: 1; }

@media (min-width: 600px) {
    body { background: var(--bg); }
    .app-header { border-radius: 0; }
}
