* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

/* 防止 iOS 横屏时系统擅自放大文字 */
html { -webkit-text-size-adjust: 100%; }

:root {
  --bg: #f4f6fb;
  --card: #ffffff;
  --text: #1b1f2a;
  --text-2: #5a6275;
  --muted: #98a0b3;
  --line: #e9edf6;
  --line-2: #dfe4f0;
  --brand: #4f6ef7;
  --brand-2: #6b7cfa;
  --brand-soft: #eef1fe;
  --green: #22b573;
  --red: #ef4b5a;
  --shadow-1: 0 1px 2px rgba(27, 31, 42, .04), 0 4px 12px rgba(27, 31, 42, .05);
  --shadow-brand: 0 6px 20px rgba(79, 110, 247, .30);
  --radius: 14px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --content-max: 2080px;
  --content-half: 1040px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  /* 去掉双击缩放与点击延迟；禁止下拉回弹牵连整页 */
  touch-action: manipulation;
  overscroll-behavior-y: none;
}

.hidden { display: none !important; }
.err { color: var(--red); font-size: 13px; min-height: 20px; }

/* ---------- 通用按钮 ---------- */
.primary, .ghost, .block-btn {
  padding: 12px 18px; border-radius: 11px; font-size: 15px; font-weight: 600;
  cursor: pointer; border: 1px solid transparent; font-family: inherit;
  transition: transform .12s ease, box-shadow .2s ease, background .2s ease;
}
.primary { width: 100%; margin-top: 8px; background: linear-gradient(135deg, var(--brand-2), var(--brand)); color: #fff; box-shadow: var(--shadow-brand); }
.primary:active { transform: scale(.98); }
.ghost { background: var(--bg); color: var(--text-2); }
.ghost:active { background: #e9edf6; }
.block-btn { width: 100%; background: #fff; border-color: var(--line); }
.danger { color: var(--red); }

/* ---------- 登录页 ---------- */
#login-view {
  display: flex; align-items: center; justify-content: center; padding: 24px;
  min-height: 100vh; min-height: 100dvh;
}
.login-box {
  width: 100%; max-width: 344px; background: var(--card); border-radius: 18px;
  padding: 30px 22px 24px; box-shadow: var(--shadow-1);
}
.login-box h1 { font-size: 21px; font-weight: 700; letter-spacing: .5px; text-align: center; }
.login-box h1::after {
  content: ''; display: block; width: 34px; height: 3px; border-radius: 2px; margin: 12px auto 22px;
  background: linear-gradient(90deg, var(--brand-2), var(--brand));
}
/* 输入框字号不小于 16px：否则 iOS 聚焦时会把整页放大且不缩回 */
#token-input {
  width: 100%; padding: 13px 14px; border: 1.5px solid var(--line-2); border-radius: 11px;
  font-size: 16px; font-family: inherit; background: #fbfcfe; color: var(--text);
  transition: border-color .2s ease, box-shadow .2s ease, background .2s ease;
}
#token-input:focus { outline: none; border-color: var(--brand); background: #fff; box-shadow: 0 0 0 4px rgba(79, 110, 247, .12); }
#token-input::placeholder { color: #b3bacb; }

/* ---------- 页面骨架 ---------- */
#app-view {
  padding-bottom: calc(92px + var(--safe-bottom));
  min-height: 100vh; min-height: 100dvh;
}
#app-title {
  position: sticky; top: 0; z-index: 20; padding: 16px 18px 14px;
  font-size: 18px; font-weight: 700; letter-spacing: .3px;
  background: rgba(255, 255, 255, .93); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
#app-title::before {
  content: ''; display: inline-block; width: 4px; height: 16px; border-radius: 2px; margin-right: 9px;
  vertical-align: -2px; background: linear-gradient(180deg, var(--brand-2), var(--brand));
}

/* 切换页签时筛选区淡入，列表本身另有卡片动画 */
.page { animation: fade .22s ease both; }

/* ---------- 筛选 / 排序按钮 ---------- */
.filter-row {
  display: flex; gap: 8px; padding: 14px 16px 0;
  max-width: var(--content-max); margin-left: auto; margin-right: auto;
}
.filter-row + .filter-row { padding-top: 8px; }
/* min-width:0 是关键：否则 flex 项不会被压缩到小于文字宽度，窄屏会把整页撑宽 */
.chip {
  flex: 1 1 0; min-width: 0; padding: 9px 2px; border: 1.5px solid var(--line-2); border-radius: 12px;
  background: #fff; color: var(--text-2); font-size: 13px; font-weight: 500; font-family: inherit;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  cursor: pointer; transition: all .18s ease;
}
.chip:active { transform: scale(.97); }
.chip.active {
  background: linear-gradient(135deg, var(--brand-2), var(--brand));
  border-color: transparent; color: #fff; font-weight: 600;
  box-shadow: 0 4px 14px rgba(79, 110, 247, .28);
}

/* ---------- 任务列表：auto-fill 自适应列数，单列最窄 300px，容器封顶宽度锁死最多 6 列 ---------- */
.list {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 10px;
  padding: 14px 16px 24px; align-items: start;
  max-width: var(--content-max); margin-left: auto; margin-right: auto;
}
.card {
  position: relative; background: var(--card); border-radius: var(--radius);
  overflow: hidden; box-shadow: var(--shadow-1); animation: rise .26s ease both;
  transition: box-shadow .2s ease;
}
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.card:nth-child(2) { animation-delay: .03s; }
.card:nth-child(3) { animation-delay: .06s; }
.card::before {
  content: ''; position: absolute; left: 0; top: 16px; bottom: 16px; width: 3px; border-radius: 0 3px 3px 0;
  background: linear-gradient(180deg, var(--brand-2), var(--brand));
}
.card.done { box-shadow: 0 1px 2px rgba(27, 31, 42, .03); }
.card.done::before { background: var(--line-2); }
/* 重要任务：红色边框加粗，左侧装饰条一并变红 */
.card.important { border: 2px solid var(--red); }
.card.important::before { background: var(--red); }

.card-row { display: flex; align-items: flex-start; gap: 11px; padding: 13px 15px; }
.chk {
  position: relative; flex: none; width: 22px; height: 22px; margin-top: 1px;
  border: 2px solid #cfd6e4; border-radius: 50%;
  background: #fff; color: #fff; font-size: 13px; line-height: 18px; text-align: center;
  cursor: pointer; transition: all .18s ease;
}
/* 把点击热区扩到约 44px，手机上更好点 */
.chk::after { content: ''; position: absolute; inset: -11px; }
.chk:active { transform: scale(.9); }
.chk.on {
  background: linear-gradient(135deg, var(--green), #1aa066); border-color: transparent;
  box-shadow: 0 2px 8px rgba(34, 181, 115, .35);
}
.task-main { flex: 1; min-width: 0; cursor: pointer; }
.task-title { font-size: 15px; font-weight: 500; overflow-wrap: anywhere; }
.card.done .task-title { color: var(--muted); text-decoration: line-through; text-decoration-color: rgba(152, 160, 179, .55); }
.task-meta { margin-top: 3px; font-size: 12px; color: var(--muted); display: flex; justify-content: space-between; gap: 8px; }
/* 子任务进度标红，日期那种 meta 不受影响 */
.task-meta .sub-count { color: var(--red); }
/* 长期任务标识：加粗品牌蓝 */
.task-meta .long-tag { margin-left: 6px; font-weight: 700; color: var(--brand); }
/* 历史页距今天数：红色粗字，仅在历史页渲染 */
.task-meta .day-ago { margin-right: 6px; font-weight: 700; color: var(--red); }
.caret { flex: none; padding: 5px; background: none; border: none; color: var(--muted); font-size: 12px; cursor: pointer; }

/* ---------- 展开详情 ---------- */
.detail { padding: 12px 15px 13px; background: #fcfdff; border-top: 1px solid var(--line); }
/* pre-wrap：描述里用户手写的换行与连续空格原样保留，长行仍自动折行 */
.desc { margin-bottom: 10px; color: var(--text-2); font-size: 13.5px; overflow-wrap: anywhere; white-space: pre-wrap; }
.sub-row { display: flex; align-items: center; gap: 10px; padding: 6px 0; }
.sub-row .chk { width: 18px; height: 18px; border-width: 1.8px; font-size: 11px; line-height: 14px; }
.sub-title { flex: 1; min-width: 0; font-size: 14px; cursor: pointer; overflow-wrap: anywhere; }
.sub-row.done .sub-title { color: var(--muted); text-decoration: line-through; }
.sub-del {
  padding: 2px 6px; background: none; border: none; border-radius: 7px;
  color: #c3c9d8; font-size: 17px; line-height: 1; cursor: pointer; transition: background .2s ease;
}
.sub-del:active { background: var(--line); }
.sub-add {
  width: 100%; margin-top: 10px; padding: 10px 12px; border: 1.5px dashed var(--line-2); border-radius: 10px;
  background: #fff; color: var(--text); font-size: 16px; font-family: inherit;
  transition: border-color .2s ease, box-shadow .2s ease;
}
.sub-add:focus { outline: none; border-style: solid; border-color: var(--brand); box-shadow: 0 0 0 4px rgba(79, 110, 247, .10); }
.sub-add::placeholder { color: #b3bacb; }
/* 底部操作行：左侧改标题/改描述/长期勾选，删除靠最右；删除单独红色并带垃圾桶图标 */
.detail-actions { margin-top: 12px; display: flex; align-items: center; gap: 2px; }
.detail-actions button {
  padding: 6px 10px; background: none; border: none; border-radius: 8px;
  color: var(--text-2); font-size: 13px; font-weight: 500; font-family: inherit; cursor: pointer;
  transition: background .2s ease;
}
.detail-actions button:active { background: var(--line); }
.detail-actions .long-toggle {
  display: flex; align-items: center; gap: 6px; padding: 6px 8px;
  color: var(--text-2); font-size: 13px; cursor: pointer;
}
.detail-actions .long-toggle input { width: 17px; height: 17px; margin: 0; accent-color: var(--brand); cursor: pointer; }
/* 任务已完成时长期标记锁定：整块变灰、不可点 */
.detail-actions .long-toggle.off { color: var(--muted); cursor: default; }
.detail-actions .long-toggle input:disabled { cursor: default; opacity: .55; }
.detail-actions .del-btn { margin-left: auto; color: var(--red); }
.detail-actions .del-btn:active { background: #fdeef0; }
.detail-actions .del-btn::before {
  content: ''; display: inline-block; width: 14px; height: 14px; margin-right: 5px; vertical-align: -2px;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23ef4b5a' stroke-width='1.9' stroke-linecap='round'%3E%3Cpath d='M4 7h16M9.5 7V4.6h5V7M6.6 7l1 12.4h8.8L18.4 7M10.2 11v5M13.8 11v5'/%3E%3C/svg%3E") center / contain no-repeat;
}

/* ---------- 空状态 ---------- */
.empty { grid-column: 1 / -1; padding: 46px 0 56px; text-align: center; color: var(--muted); font-size: 14px; }
.empty::before {
  content: ''; display: block; width: 92px; height: 92px; margin: 0 auto 12px;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 96 96' fill='none'%3E%3Crect x='16' y='12' width='64' height='72' rx='14' stroke='%23ccd5e8' stroke-width='3'/%3E%3Cpath d='M30 38h36M30 52h26' stroke='%23dde4f2' stroke-width='3' stroke-linecap='round'/%3E%3Ccircle cx='66' cy='68' r='15' fill='%23eef1fe' stroke='%234f6ef7' stroke-width='3'/%3E%3Cpath d='M59.5 68.6l4.6 4.6L73 63.6' stroke='%234f6ef7' stroke-width='3.2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / contain no-repeat;
}

/* ---------- 悬浮新增按钮 ---------- */
.fab {
  position: fixed; bottom: calc(76px + var(--safe-bottom));
  right: max(18px, calc(50vw - var(--content-half) + 18px));
  width: 54px; height: 54px; border: none; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--brand-2), var(--brand)); color: #fff;
  box-shadow: var(--shadow-brand); cursor: pointer;
  transition: transform .15s ease, box-shadow .2s ease;
}
.fab svg { width: 24px; height: 24px; }
.fab:active { transform: scale(.9); box-shadow: 0 4px 12px rgba(79, 110, 247, .35); }

/* ---------- 底部导航 ---------- */
#tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: flex; justify-content: center;
  padding-bottom: var(--safe-bottom);
  background: rgba(255, 255, 255, .95); backdrop-filter: blur(10px);
  border-top: 1px solid var(--line); box-shadow: 0 -2px 14px rgba(27, 31, 42, .05);
}
.tab {
  flex: 1 1 0; max-width: 200px;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 9px 0 8px; background: none; border: none; font-family: inherit;
  font-size: 11px; color: var(--muted); cursor: pointer; transition: color .2s ease;
}
.tab svg { width: 21px; height: 21px; }
.tab:active { opacity: .65; }
.tab.active { color: var(--brand); font-weight: 600; }

/* ---------- 设置页 ---------- */
#page-settings { padding: 16px; max-width: var(--content-max); margin: 0 auto; }

/* ---------- 弹窗 ---------- */
.modal {
  position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-end; justify-content: center;
  background: rgba(23, 28, 45, .42); backdrop-filter: blur(2px);
  animation: fade .2s ease both;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { opacity: 0; transform: translateY(18px); } to { opacity: 1; transform: none; } }
.modal-box {
  width: 100%; max-width: 420px; padding: 20px 18px calc(20px + var(--safe-bottom));
  background: #fff; border-radius: 18px 18px 0 0;
  animation: slideUp .26s cubic-bezier(.2, .8, .2, 1) both;
}
.modal-box h2 { margin-bottom: 16px; font-size: 17px; font-weight: 700; }
/* 只针对文本输入框：长期任务复选框不套这套外观 */
.modal-box input[type="text"], .modal-box textarea {
  width: 100%; margin-bottom: 11px; padding: 12px 13px; border: 1.5px solid var(--line-2); border-radius: 11px;
  background: #fbfcfe; color: var(--text); font-size: 16px; font-family: inherit; resize: none;
  transition: border-color .2s ease, box-shadow .2s ease, background .2s ease;
}
.modal-box input[type="text"]:focus, .modal-box textarea:focus {
  outline: none; border-color: var(--brand); background: #fff; box-shadow: 0 0 0 4px rgba(79, 110, 247, .12);
}
.modal-box input[type="text"]::placeholder, .modal-box textarea::placeholder { color: #b3bacb; }
/* 长期任务勾选：用系统原生复选框，只定尺寸与选中色 */
.long-check { display: flex; align-items: center; gap: 8px; margin-bottom: 11px; color: var(--text-2); font-size: 14px; cursor: pointer; }
.long-check input { width: 17px; height: 17px; margin: 0; accent-color: var(--brand); cursor: pointer; }
.modal-actions { display: flex; gap: 10px; margin-top: 4px; }
.modal-actions .primary { flex: 1; margin-top: 0; }
.modal-actions .ghost { flex: none; padding: 12px 22px; }
/* 修改任务弹窗：不分屏宽一律居中，内容高时弹窗内部滚动 */
#edit-modal { align-items: center; padding: 16px; }
#edit-modal .modal-box { max-width: 560px; border-radius: 18px; max-height: 85vh; overflow-y: auto; }
#edit-desc { min-height: 170px; }

/* ---------- 断点 ---------- */
/* 小屏去掉竖排弹窗的内边距干扰，弹窗改为居中 */
@media (min-width: 520px) {
  .modal { align-items: center; padding: 20px; }
  .modal-box { border-radius: 18px; padding: 22px 20px; }
}

/* 平板起：筛选按钮不再被拉得过宽 */
@media (min-width: 640px) {
  .filter-row { justify-content: center; }
  .chip { flex: 0 1 170px; }
}

/* 桌面：标题居中（列数由 auto-fill 自动决定，无需断点） */
@media (min-width: 1024px) {
  #app-title { text-align: center; }
}

/* 系统开启“减少动态效果”时全部关掉 */
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
