/* 待办任务计时器 —— 网站版样式（移动端优先） */
:root {
  --bg: #f4f6f8;
  --card: #ffffff;
  --ink: #2c3e50;
  --ink2: #7f8c8d;
  --line: #e5e9ee;
  --primary: #1a5276;
  --primary2: #2980b9;
  --accent: #c0392b;
  --green: #27ae60;
  --orange: #e67e22;
  --plan-bg: #fcf3cf;
  --radius: 12px;
  --shadow: 0 1px 4px rgba(30, 50, 70, .08);
  --tabbar-h: 58px;
  --topbar-h: 48px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #10161d;
    --card: #1a232c;
    --ink: #dde5ec;
    --ink2: #8a99a8;
    --line: #27333e;
    --primary: #7fb3d5;
    --primary2: #5dade2;
    --plan-bg: #3a3418;
    --shadow: 0 1px 4px rgba(0,0,0,.4);
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  background: var(--bg); color: var(--ink);
  font-size: 15px; line-height: 1.5;
}
button { font-family: inherit; }
input, textarea, select {
  font-family: inherit; font-size: 16px; color: var(--ink);
  background: var(--card); border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 10px; width: 100%; outline: none;
}
input:focus, textarea:focus, select:focus { border-color: var(--primary2); }
textarea { resize: vertical; min-height: 64px; }
.hidden { display: none !important; }

/* ---------- 登录 ---------- */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(160deg, #1a5276, #2980b9); padding: 20px;
}
.login-card {
  background: var(--card); border-radius: 16px; padding: 32px 26px;
  width: 100%; max-width: 360px; box-shadow: 0 10px 40px rgba(0,0,0,.25); text-align: center;
}
.login-logo { font-size: 44px; }
.login-card h1 { font-size: 20px; margin: 8px 0 2px; color: var(--ink); }
.login-sub { color: var(--ink2); font-size: 13px; margin: 0 0 18px; }
.login-err { color: var(--accent); font-size: 13px; min-height: 18px; margin: 10px 0 0; }

/* ---------- 布局 ---------- */
#app { display: flex; flex-direction: column; min-height: 100vh; }
#topbar {
  position: sticky; top: 0; z-index: 50;
  box-sizing: border-box;
  display: flex; align-items: center; justify-content: space-between;
  padding: env(safe-area-inset-top, 0px) 14px 6px;
  min-height: calc(var(--topbar-h) + env(safe-area-inset-top, 0px));
  background: var(--primary); color: #fff;
}
.top-actions { display: flex; align-items: center; gap: 4px; }
.top-title { font-weight: 700; font-size: 16px; }
.icon-btn { background: transparent; border: none; font-size: 20px; color: #fff; cursor: pointer; padding: 4px 8px; }
#view { flex: 1; padding: 12px 12px calc(var(--tabbar-h) + var(--safe-b) + 16px); max-width: 860px; width: 100%; margin: 0 auto; }
#tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 50;
  height: calc(var(--tabbar-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  display: flex; background: var(--card); border-top: 1px solid var(--line);
}
.tab-btn {
  flex: 1; border: none; background: none; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 1px; cursor: pointer; color: var(--ink2);
}
.tab-btn .t-ico { font-size: 19px; line-height: 1.1; }
.tab-btn .t-txt { font-size: 11px; }
.tab-btn.active { color: var(--primary2); font-weight: 700; }

/* ---------- 卡片与通用 ---------- */
.card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 14px; margin-bottom: 12px;
}
.card h3 { margin: 0 0 10px; font-size: 15px; color: var(--ink); display:flex; align-items:center; gap:6px; }
.card h3 .right { margin-left: auto; font-weight: 400; font-size: 12px; color: var(--ink2); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; }
.muted { color: var(--ink2); font-size: 12.5px; }
.big-num { font-size: 34px; font-weight: 800; letter-spacing: 1px; color: var(--accent); font-variant-numeric: tabular-nums; }
.btn {
  border: none; border-radius: 9px; padding: 9px 14px; font-size: 14px; cursor: pointer;
  background: var(--line); color: var(--ink); font-weight: 600;
}
.btn.primary { background: var(--primary2); color: #fff; }
.btn.green { background: var(--green); color: #fff; }
.btn.warn { background: var(--orange); color: #fff; }
.btn.danger { background: var(--accent); color: #fff; }
.btn.block { display: block; width: 100%; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.sm { padding: 5px 9px; font-size: 12.5px; border-radius: 7px; }
.chip {
  display: inline-block; border: 1px solid var(--primary2); color: var(--primary2);
  border-radius: 999px; padding: 3px 11px; font-size: 12.5px; margin: 0 6px 6px 0; cursor: pointer; background: transparent;
}
.badge { font-size: 11px; border-radius: 5px; padding: 1px 6px; background: var(--line); color: var(--ink2); white-space: nowrap; }
.badge.overdue { background: #fdecea; color: #c0392b; }
.badge.done { background: #e8f8f0; color: #1e8449; }
.progress-bar { height: 8px; border-radius: 5px; background: var(--line); overflow: hidden; }
.progress-bar > i { display: block; height: 100%; background: var(--primary2); border-radius: 5px; transition: width .4s; }

/* ---------- Toast / 弹层 ---------- */
#toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + 24px); transform: translateX(-50%);
  background: rgba(30,40,50,.92); color: #fff; padding: 9px 18px; border-radius: 999px;
  font-size: 13.5px; z-index: 300; max-width: 86vw; text-align: center;
}
#toast.err { background: rgba(192,57,43,.95); }
#modalRoot .overlay {
  position: fixed; inset: 0; background: rgba(10,16,22,.5); z-index: 200;
  display: flex; align-items: flex-end; justify-content: center;
}
#modalRoot .sheet {
  background: var(--card); width: 100%; max-width: 560px; max-height: 88vh; overflow-y: auto;
  border-radius: 16px 16px 0 0; padding: 18px 16px calc(16px + var(--safe-b));
}
@media (min-width: 640px) {
  #modalRoot .overlay { align-items: center; }
  #modalRoot .sheet { border-radius: 14px; }
}
.sheet h3 { margin: 0 0 14px; font-size: 16px; }
.sheet .field { margin-bottom: 12px; }
.sheet .field label { display: block; font-size: 13px; color: var(--ink2); margin-bottom: 4px; }
.sheet-actions { display: flex; gap: 10px; margin-top: 16px; }
.sheet-actions .btn { flex: 1; padding: 11px; }
.action-item {
  display: block; width: 100%; text-align: left; border: none; background: none;
  padding: 13px 6px; font-size: 15px; color: var(--ink); border-bottom: 1px solid var(--line); cursor: pointer;
}
.action-item:last-child { border-bottom: none; }
.action-item.danger { color: var(--accent); }

/* ---------- 工作台 ---------- */
.cd-progress { margin-bottom: 10px; }
.cd-progress .cd-name { font-weight: 700; }
.cd-progress .cd-pct { color: var(--accent); font-weight: 800; }
.timer-btns { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 10px; }
.timer-btns .btn { padding: 11px 2px; font-size: 13px; white-space: nowrap; }
.meta-line { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 4px; }
.meta-line .lbl { color: var(--ink2); font-size: 12.5px; }
.quick-btns { display: flex; gap: 5px; flex-wrap: wrap; margin-top: 6px; }
.quick-btns .btn { padding: 4px 8px; font-size: 12px; }
.hist-row { padding: 8px 4px; border-bottom: 1px solid var(--line); cursor: pointer; }
.hist-row:last-child { border-bottom: none; }
.hist-row.plan { background: var(--plan-bg); border-radius: 6px; }
.hist-row .h-top { display: flex; gap: 8px; align-items: baseline; font-size: 12.5px; color: var(--ink2); }
.hist-row .h-text { margin-top: 3px; font-size: 13.5px; white-space: pre-wrap; word-break: break-word; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.hist-row.expanded .h-text { display: block; -webkit-line-clamp: unset; }
.preview-banner {
  background: #fdf2e9; color: var(--orange); border-radius: 8px; padding: 7px 10px;
  font-size: 13px; font-weight: 700; margin-bottom: 10px; display: flex; align-items: center; gap: 8px;
}

/* ---------- 任务列表 ---------- */
.toolbar { display: flex; gap: 6px; margin-bottom: 8px; flex-wrap: wrap; }
.toolbar select { width: auto; flex: 0 1 auto; padding: 6px 6px; font-size: 13px; }
.toolbar input { flex: 1 1 120px; padding: 6px 10px; font-size: 14px; }
.tree-row {
  display: flex; align-items: center; gap: 6px; padding: 9px 6px;
  border-bottom: 1px solid var(--line); cursor: pointer;
}
.tree-row:last-child { border-bottom: none; }
.tree-row.current { background: #eaf7ef; }
.tree-row.container { font-weight: 700; color: var(--ink2); background: var(--line); border-radius: 6px; }
.tree-row .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree-row .sub { color: var(--ink2); font-size: 12px; }
.tree-check { width: 20px; height: 20px; accent-color: var(--primary2); flex: none; }
.caret { border: none; background: none; font-size: 12px; width: 22px; color: var(--ink2); }
.cal-panel .cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 3px; }
.cal-panel .cal-grid .hd { text-align: center; font-size: 11px; color: var(--ink2); padding: 2px 0; }
.cal-day {
  border: none; background: none; aspect-ratio: 1; border-radius: 7px; font-size: 13px;
  cursor: pointer; color: var(--ink); position: relative;
}
.cal-day.in-range { background: var(--primary2); color: #fff; }
.cal-day.today { background: var(--accent); color: #fff; font-weight: 800; }
.cal-day.dl::after {
  content: ""; position: absolute; top: 3px; right: 3px; width: 5px; height: 5px;
  border-radius: 50%; background: var(--accent);
}
.cal-day.dl.in-range::after { background: #fff; }
.batchbar {
  position: sticky; bottom: calc(var(--tabbar-h) + var(--safe-b) + 6px);
  background: var(--primary); color: #fff; border-radius: 10px; padding: 8px 10px;
  display: flex; gap: 8px; align-items: center; z-index: 40; box-shadow: var(--shadow);
}
.fab {
  position: fixed; right: 16px; bottom: calc(var(--tabbar-h) + var(--safe-b) + 18px);
  width: 52px; height: 52px; border-radius: 50%; border: none; background: var(--orange);
  color: #fff; font-size: 26px; box-shadow: 0 4px 14px rgba(0,0,0,.25); z-index: 60; cursor: pointer;
}

/* ---------- 汇总 ---------- */
.pie-wrap { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.pie-legend { font-size: 12.5px; }
.pie-legend li { list-style: none; margin-bottom: 3px; }
.pie-legend ul { margin: 0; padding: 0; }
.rec-row { padding: 8px 4px; border-bottom: 1px solid var(--line); }
.rec-row:last-child { border-bottom: none; }
.rec-row .r-top { display: flex; gap: 8px; font-size: 13px; font-weight: 600; }
.rec-row .r-meta { color: var(--ink2); font-size: 12px; margin-top: 2px; }
.rec-row .r-text { color: var(--ink2); font-size: 12.5px; margin-top: 2px; display:-webkit-box; -webkit-line-clamp:1; -webkit-box-orient:vertical; overflow:hidden; }

/* ---------- AI ---------- */
.ai-box { display: flex; flex-direction: column; height: calc(100vh - var(--topbar-h) - var(--tabbar-h) - 60px); }
.ai-msgs { flex: 1; overflow-y: auto; padding: 4px 0; }
.ai-msg { margin-bottom: 12px; max-width: 92%; }
.ai-msg.user { margin-left: auto; background: #e3f0fa; border-radius: 12px 12px 2px 12px; padding: 9px 12px; white-space: pre-wrap; }
.ai-msg.assistant { background: var(--card); border-radius: 12px 12px 12px 2px; padding: 9px 12px; box-shadow: var(--shadow); }
.ai-msg.error { background: #fdecea; color: var(--accent); border-radius: 10px; padding: 9px 12px; }
.ai-msg .md p { margin: 4px 0; }
.ai-msg .md pre { background: var(--line); padding: 8px; border-radius: 8px; overflow-x: auto; font-size: 12.5px; }
.ai-msg .md code { background: var(--line); border-radius: 4px; padding: 0 4px; font-size: 12.5px; }
.ai-msg .md pre code { background: none; padding: 0; }
.ai-msg .md table { border-collapse: collapse; font-size: 12.5px; }
.ai-msg .md td, .ai-msg .md th { border: 1px solid var(--line); padding: 3px 7px; }
.ai-msg .md h1,.ai-msg .md h2,.ai-msg .md h3,.ai-msg .md h4 { font-size: 14.5px; margin: 8px 0 4px; }
.ai-usage { color: var(--ink2); font-size: 11px; margin-top: 4px; }
.ai-inputbar { display: flex; gap: 8px; padding-top: 8px; border-top: 1px solid var(--line); }
.ai-inputbar textarea { min-height: 44px; max-height: 120px; }
@media (prefers-color-scheme: dark) {
  .ai-msg.user { background: #1f3a52; }
  .tree-row.current { background: #1d3328; }
  .preview-banner { background: #3a2a17; }
  .badge.overdue { background: #3a1d1a; }
  .badge.done { background: #16321f; }
}

/* ---------- 工作台双栏（宽屏 = exe 布局） ---------- */
.wb-grid { display: block; }
.wb-right { display: none; }
@media (min-width: 900px) {
  .wb-grid {
    display: grid; grid-template-columns: minmax(0, 55fr) minmax(0, 45fr);
    gap: 14px; align-items: start;
  }
  .wb-right { display: block; position: sticky; top: calc(var(--topbar-h) + 10px); }
  .wb-right .card { margin-bottom: 10px; }
}

/* ---------- 桌面宽屏适配 ---------- */
@media (min-width: 900px) {
  :root { --tabbar-h: 0px; }
  #topbar { order: 0; }
  #tabbar {
    order: 1; position: static; height: auto; padding: 10px 10px 0;
    border-top: none; justify-content: center; gap: 6px; background: transparent;
  }
  .tab-btn { flex: 0 0 auto; flex-direction: row; gap: 6px; padding: 8px 16px; border-radius: 999px; background: var(--line); }
  .tab-btn.active { background: var(--primary2); color: #fff; }
  .tab-btn .t-txt { font-size: 13.5px; }
  #view { order: 2; padding-bottom: 30px; max-width: 1280px; }
  .fab { bottom: 30px; }
  #toast { bottom: 40px; }
  .batchbar { bottom: 16px; }
}
