/* ============ 设计变量 ============ */
:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #fafbfc;
  --line: #e8eaee;
  --line-strong: #dcdfe5;
  --text: #16181d;
  --text-2: #5c6370;
  --text-3: #9aa1ad;
  --accent: #2563eb;
  --accent-soft: #eaf1ff;
  --high: #e5484d;
  --normal: #2563eb;
  --idle: #9099a8;
  --danger: #e5484d;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 8px 24px -12px rgba(16, 24, 40, .12);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1014;
    --surface: #171a20;
    --surface-2: #1d2128;
    --line: #262a33;
    --line-strong: #31363f;
    --text: #e9ecf1;
    --text-2: #9ea6b4;
    --text-3: #6b7382;
    --accent: #5b8cff;
    --accent-soft: #1c2740;
    --high: #ff6369;
    --normal: #5b8cff;
    --idle: #7d8797;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 10px 30px -14px rgba(0, 0, 0, .6);
  }
}

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

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
               "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; cursor: pointer; border: 0; background: none; color: inherit; }

.app {
  max-width: 620px;
  margin: 0 auto;
  padding: 28px 16px calc(40px + var(--safe-b));
}

/* ============ 头部 ============ */
.head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: 8px; font-weight: 600; letter-spacing: .2px; }

.brand-mark {
  width: 22px; height: 22px; border-radius: 7px;
  background: var(--accent);
  position: relative; flex: none;
}
.brand-mark::after {
  content: "";
  position: absolute; left: 6px; top: 5px;
  width: 8px; height: 5px;
  border-left: 2px solid #fff; border-bottom: 2px solid #fff;
  transform: rotate(-45deg); border-radius: 1px;
}

.date-nav {
  display: flex; align-items: center; gap: 2px;
  margin-left: auto;
}

.date-info { text-align: center; min-width: 148px; padding: 0 4px; }
.date-info h1 { margin: 0; font-size: 15px; font-weight: 600; line-height: 1.3; }
.date-info p { margin: 0; font-size: 12px; color: var(--text-3); }

.icon-btn {
  width: 30px; height: 30px; border-radius: 8px;
  display: grid; place-items: center;
  color: var(--text-2);
  transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.icon-btn:active { transform: scale(.94); }

.head-actions { display: flex; align-items: center; gap: 8px; }

.ghost-btn {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 12px; color: var(--accent);
  background: var(--accent-soft);
  padding: 5px 10px; border-radius: 8px;
  transition: opacity .15s;
}
.ghost-btn:hover { opacity: .8; }
.ghost-btn em { font-style: normal; font-variant-numeric: tabular-nums; opacity: .7; }

/* ============ 提醒授权条 ============ */
.banner {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px 10px 14px;
  margin-bottom: 14px;
  font-size: 12.5px; color: var(--text-2);
  background: var(--accent-soft);
  border: 1px solid color-mix(in srgb, var(--accent) 22%, transparent);
  border-radius: var(--radius-sm);
}
.banner span { flex: 1; min-width: 0; }
.banner-btn {
  flex: none; padding: 5px 12px;
  font-size: 12.5px; color: #fff; background: var(--accent);
  border-radius: 7px;
}
.banner-btn:hover { opacity: .9; }
.banner-close {
  flex: none; width: 22px; height: 22px; border-radius: 6px;
  font-size: 16px; line-height: 1; color: var(--text-3);
}
.banner-close:hover { background: rgba(0, 0, 0, .06); color: var(--text); }

/* ============ 选项面板 ============ */
.icon-square {
  flex: none; width: 44px; height: 44px;
  display: grid; place-items: center;
  color: var(--text-2);
  background: var(--surface-2);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  transition: all .15s;
}
.icon-square:hover { color: var(--text); border-color: var(--accent); }
.icon-square[aria-expanded="true"] { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }

.plan-hint {
  margin-left: auto;
  padding: 3px 9px;
  font-size: 11.5px; color: var(--accent);
  background: var(--accent-soft);
  border-radius: 99px;
  white-space: nowrap;
}

.opt-panel {
  margin-top: 12px; padding-top: 12px;
  border-top: 1px dashed var(--line);
}
.opt-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px;
}
.opt-field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.opt-field > span { font-size: 11.5px; color: var(--text-3); }
.opt-field input, .opt-field select {
  height: 38px; padding: 0 10px;
  font-size: 14px; font-family: inherit; color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.opt-field input:focus, .opt-field select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.opt-hint { margin: 10px 0 0; font-size: 11.5px; color: var(--text-3); line-height: 1.7; }
.opt-hint code {
  padding: 1px 4px; font-family: ui-monospace, Menlo, Consolas, monospace;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 4px;
}

/* ============ 卡片 ============ */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  margin-bottom: 14px;
}

/* ============ 进度 ============ */
.progress-top {
  display: flex; align-items: baseline; justify-content: space-between;
  margin-bottom: 10px;
}
.progress-title { font-size: 13px; color: var(--text-2); }
.progress-num { font-variant-numeric: tabular-nums; line-height: 1; }
.progress-num b { font-size: 30px; font-weight: 650; letter-spacing: -1px; }
.progress-num i { font-size: 14px; font-style: normal; color: var(--text-3); margin-left: 2px; }

.progress-track {
  height: 8px; border-radius: 99px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  overflow: hidden;
}
.progress-fill {
  height: 100%; width: 0%;
  border-radius: 99px;
  background: linear-gradient(90deg, var(--accent), #38bdf8);
  transition: width .45s cubic-bezier(.22, 1, .36, 1);
}
.progress-fill.done { background: linear-gradient(90deg, #16a34a, #34d399); }

.progress-tip {
  margin-top: 8px; font-size: 12px; color: var(--text-3); min-height: 18px;
}

.stats {
  display: flex; align-items: center;
  margin-top: 14px; padding-top: 14px;
  border-top: 1px dashed var(--line);
}
.stat { flex: 1; text-align: center; }
.stat b { display: block; font-size: 18px; font-weight: 600; font-variant-numeric: tabular-nums; }
.stat span { font-size: 12px; color: var(--text-3); }
.stat-divider { width: 1px; height: 22px; background: var(--line); }

/* ============ 添加 ============ */
.add-row { display: flex; gap: 8px; }

#taskInput {
  flex: 1; min-width: 0;
  height: 44px; padding: 0 14px;
  font-size: 15px; font-family: inherit; color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
#taskInput::placeholder { color: var(--text-3); }
#taskInput:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.primary-btn {
  flex: none;
  height: 44px; padding: 0 16px;
  display: flex; align-items: center; gap: 5px;
  background: var(--accent); color: #fff;
  font-size: 14px; font-weight: 500;
  border-radius: var(--radius-sm);
  transition: opacity .15s, transform .1s;
}
.primary-btn:hover { opacity: .9; }
.primary-btn:active { transform: scale(.97); }

.prio-row {
  display: flex; align-items: center; gap: 10px;
  margin-top: 12px; flex-wrap: wrap;
}
.prio-label { font-size: 12px; color: var(--text-3); }

.seg {
  display: flex; gap: 2px; padding: 3px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 10px;
}
.seg-btn {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 12px;
  font-size: 13px; color: var(--text-2);
  border-radius: 8px;
  transition: background .15s, color .15s;
}
.seg-btn:hover { color: var(--text); }
.seg-btn.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); font-weight: 500; }

.dot { width: 7px; height: 7px; border-radius: 99px; flex: none; }
.dot-high { background: var(--high); }
.dot-normal { background: var(--normal); }
.dot-idle { background: var(--idle); }

/* ============ 筛选 ============ */
.filters { display: flex; gap: 6px; margin: 18px 0 10px; overflow-x: auto; padding-bottom: 2px; }
.filters::-webkit-scrollbar { display: none; }

.filter-btn {
  flex: none;
  padding: 7px 13px;
  font-size: 13px; color: var(--text-2);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 99px;
  transition: all .15s;
}
.filter-btn em { font-style: normal; color: var(--text-3); font-size: 12px; margin-left: 2px; }
.filter-btn:hover { border-color: var(--line-strong); }
.filter-btn.active { background: var(--text); color: var(--surface); border-color: var(--text); }
.filter-btn.active em { color: rgba(255, 255, 255, .6); }

/* ============ 列表 ============ */
.list { display: flex; flex-direction: column; gap: 8px; }

.item {
  display: flex; align-items: flex-start; gap: 11px;
  padding: 13px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  animation: pop .22s cubic-bezier(.22, 1, .36, 1);
  transition: border-color .15s, opacity .2s;
}
@keyframes pop { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.item:hover { border-color: var(--line-strong); }
.item.done { opacity: .5; background: var(--surface-2); box-shadow: none; }

.item-check {
  flex: none;
  width: 20px; height: 20px; margin-top: 1px;
  border-radius: 99px;
  border: 1.8px solid var(--line-strong);
  display: grid; place-items: center;
  transition: border-color .18s, background .18s, transform .12s;
}
.item-check:hover { border-color: var(--accent); transform: scale(1.08); }
.item-check svg { opacity: 0; transform: scale(.4); transition: all .2s cubic-bezier(.22, 1, .36, 1); }
.item.done .item-check { background: #16a34a; border-color: #16a34a; }
.item.done .item-check svg { opacity: 1; transform: scale(1); }

.item-body { flex: 1; min-width: 0; }

.item-title {
  font-size: 15px; line-height: 1.45; word-break: break-word;
  outline: none;
  border-radius: 4px;
  transition: color .2s;
}
.item.done .item-title { color: var(--text-3); text-decoration: line-through; text-decoration-thickness: 1px; }
.item-title[contenteditable="true"] {
  background: var(--surface-2);
  box-shadow: 0 0 0 3px var(--accent-soft);
  padding: 1px 4px; margin: -1px -4px;
  cursor: text;
}

.item-meta { display: flex; align-items: center; gap: 8px; margin-top: 4px; }

.tag {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 8px;
  font-size: 11px; line-height: 1.6;
  border-radius: 99px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--text-2);
  transition: border-color .15s;
}
.tag:hover { border-color: var(--line-strong); }
.tag-high { color: var(--high); }
.tag-normal { color: var(--normal); }
.tag-idle { color: var(--idle); }

.item-time { font-size: 11px; color: var(--text-3); font-variant-numeric: tabular-nums; }

.item-del {
  flex: none; width: 26px; height: 26px; margin-top: -2px;
  border-radius: 7px; display: grid; place-items: center;
  color: var(--text-3); opacity: 0;
  transition: opacity .15s, background .15s, color .15s;
}
.item:hover .item-del { opacity: 1; }

/* ============ 周期任务弹窗 ============ */
.modal-mask {
  position: fixed; inset: 0; z-index: 60;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  background: rgba(15, 18, 24, .38);
  animation: fade .18s ease;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.modal {
  width: 100%; max-width: 520px; max-height: 80vh;
  display: flex; flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 24px 60px -20px rgba(16, 24, 40, .45);
  animation: rise .22s cubic-bezier(.22, 1, .36, 1);
  overflow: hidden;
}
@keyframes rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }

.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 18px 12px;
  border-bottom: 1px solid var(--line);
}
.modal-head h2 { margin: 0; font-size: 15px; font-weight: 600; }
.modal-body { padding: 10px 14px; overflow-y: auto; }
.modal-foot { padding: 10px 18px 14px; border-top: 1px solid var(--line); }
.foot-hint { font-size: 11.5px; color: var(--text-3); }

.rec-row {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 8px;
  border-bottom: 1px solid var(--line);
}
.rec-row:last-child { border-bottom: 0; }
.rec-row.paused { opacity: .5; }
.rec-main { flex: 1; min-width: 0; }
.rec-title {
  font-size: 14px; line-height: 1.45; word-break: break-word;
  outline: none; border-radius: 4px; cursor: text;
}
.rec-title[contenteditable="true"] {
  background: var(--surface-2);
  box-shadow: 0 0 0 3px var(--accent-soft);
  padding: 1px 4px; margin: -1px -4px;
}
.rec-info { display: flex; align-items: center; gap: 8px; margin-top: 5px; flex-wrap: wrap; }
.rec-rule { font-size: 11.5px; color: var(--text-3); }
.rec-ops { flex: none; display: flex; gap: 6px; }
.rec-ops button {
  padding: 5px 10px; font-size: 12px; color: var(--text-2);
  border: 1px solid var(--line); border-radius: 7px;
  transition: all .15s;
}
.rec-ops button:hover { border-color: var(--line-strong); color: var(--text); }
.rec-ops button.danger:hover { color: var(--danger); border-color: var(--danger); }
.item-del:hover { background: rgba(229, 72, 77, .1); color: var(--danger); }

/* 空状态 */
.empty { text-align: center; padding: 46px 16px; color: var(--text-3); }
.empty-mark {
  width: 54px; height: 54px; margin: 0 auto 14px;
  border-radius: 50%;
  background: var(--surface);
  border: 1px dashed var(--line-strong);
  display: grid; place-items: center;
}
.empty h3 { margin: 0 0 4px; font-size: 15px; font-weight: 600; color: var(--text-2); }
.empty p { margin: 0; font-size: 13px; }

/* ============ 底部 ============ */
.foot { display: flex; align-items: center; justify-content: center; gap: 8px; margin-top: 18px; }
.link-btn { font-size: 12.5px; color: var(--text-3); transition: color .15s; }
.link-btn:hover { color: var(--danger); }
.foot-sep { color: var(--line-strong); }

.tip { text-align: center; font-size: 11.5px; color: var(--text-3); margin-top: 22px; line-height: 1.9; }
.tip code {
  padding: 1px 5px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 5px;
  color: var(--text-2);
}

/* ============ Toast ============ */
.toast {
  position: fixed; left: 50%; bottom: calc(28px + var(--safe-b));
  transform: translate(-50%, 12px);
  padding: 9px 16px;
  font-size: 13px; color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 99px;
  box-shadow: 0 8px 28px -8px rgba(16, 24, 40, .28);
  opacity: 0; pointer-events: none;
  transition: opacity .22s, transform .22s;
  z-index: 50;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ============ 移动端 ============ */
@media (max-width: 560px) {
  .head-actions { width: 100%; justify-content: space-between; margin-top: 2px; }
  .banner { flex-wrap: wrap; gap: 8px; }
  .opt-grid { grid-template-columns: 1fr; }
  .prio-row { gap: 8px; }
  .plan-hint { margin-left: 0; width: 100%; }
  .modal { max-height: 88vh; border-radius: 16px 16px 0 0; align-self: flex-end; width: 100%; max-width: none; }
  .modal-mask { align-items: flex-end; }
  .rec-row { flex-direction: column; align-items: stretch; gap: 10px; }
  .rec-ops { justify-content: flex-end; }
}
  .app { padding: 18px 12px calc(32px + var(--safe-b)); }
  .head { margin-bottom: 14px; }
  .date-info { min-width: 128px; }
  .card { padding: 15px; border-radius: 14px; margin-bottom: 12px; }
  .progress-num b { font-size: 26px; }
  .add-row { flex-direction: column; }
  #taskInput { height: 46px; }
  .primary-btn { height: 46px; justify-content: center; }
  .primary-btn span { display: inline; }
  .seg { flex: 1; }
  .seg-btn { flex: 1; justify-content: center; padding: 8px 6px; }
  .item { padding: 12px; }
  .item-del { opacity: 1; }
  .filters { margin: 14px -12px 10px; padding: 0 12px 2px; }
}

@media (max-width: 380px) {
  .brand-text { display: none; }
}

/* ============ 云同步弹窗 ============ */
.sync-body { padding: 18px 20px; }
.sync-desc { font-size: 13px; color: var(--text-2); line-height: 1.6; margin-bottom: 16px; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 12px; color: var(--text-2); }
.field input {
  height: 40px; padding: 0 12px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--bg); color: var(--text-1); font-size: 14px; outline: none;
  transition: border-color .15s; box-sizing: border-box;
}
.field input:focus { border-color: var(--accent); }
.sync-msg { font-size: 12.5px; color: #dc2626; min-height: 16px; margin-top: 2px; }
.sync-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.sync-foot .ghost-btn { font-size: 12.5px; color: var(--text-2); padding: 8px 4px; }
.sync-foot .ghost-btn:hover { opacity: .8; }
#syncBtn.syncing { opacity: .75; }
#syncBtn.syncing svg { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
