:root {
  --bg: #f2f5fa;
  --bg-2: #e9eef6;
  --panel: #ffffff;
  --panel-2: #f7f9fc;
  --text: #0f172a;
  --muted: #64748b;
  --faint: #94a3b8;
  --line: #e2e8f0;
  --line-2: #d3dbe6;
  --brand: #2563eb;
  --brand-2: #1d4ed8;
  --brand-soft: #eaf1ff;
  --ok: #059669;
  --warn: #d97706;
  --danger: #dc2626;
  --sh: 0 1px 2px rgba(16, 24, 40, .04), 0 8px 24px -12px rgba(16, 24, 40, .16);
  --sh-lg: 0 24px 60px -20px rgba(16, 24, 40, .32);
  --r: 12px;
}
[data-theme="dark"] {
  --bg: #0b1017;
  --bg-2: #0e141d;
  --panel: #131a24;
  --panel-2: #17202c;
  --text: #e6ecf5;
  --muted: #93a3b8;
  --faint: #6b7b90;
  --line: #223041;
  --line-2: #2b3a4d;
  --brand: #4f8bf7;
  --brand-2: #3b76e0;
  --brand-soft: #16233a;
  --sh: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px -12px rgba(0, 0, 0, .6);
  --sh-lg: 0 24px 60px -20px rgba(0, 0, 0, .8);
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.6 -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", "PingFang SC", "Hiragino Sans GB", sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--brand); }

/* ---------------------------------- 布局 ---------------------------------- */
.app { display: grid; grid-template-columns: 258px minmax(0, 1fr); height: 100vh; }
.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 14px;
  padding: 16px 14px; overflow-y: auto; min-width: 0;
}
.brand { display: flex; flex-direction: column; gap: 2px; }
.brand h1 { margin: 0; font-size: 16px; letter-spacing: .2px; display: flex; align-items: center; gap: 8px; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--brand); box-shadow: 0 0 0 4px var(--brand-soft); }
.brand p { margin: 2px 0 0; font-size: 12px; color: var(--muted); }

.stats { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 8px; }
.stat { background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; min-width: 0; }
.stat b { display: block; font-size: 19px; line-height: 1.2; font-variant-numeric: tabular-nums; }
.stat span { display: block; font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.side-h { margin: 4px 0 6px; font-size: 11px; letter-spacing: .08em; color: var(--faint); text-transform: uppercase; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; min-width: 0; }
.chip {
  border: 1px solid var(--line); background: var(--panel); color: var(--muted);
  border-radius: 999px; padding: 3px 10px; font-size: 12px; line-height: 1.6;
  display: inline-flex; align-items: center; gap: 6px; transition: .15s;
}
.chip i { font-style: normal; font-size: 11px; opacity: .75; font-variant-numeric: tabular-nums; }
.chip:hover { border-color: var(--line-2); color: var(--text); }
.chip.on { background: var(--brand); border-color: var(--brand); color: #fff; }
.chip.on i { opacity: .85; }
.side-foot { margin-top: auto; font-size: 11.5px; color: var(--faint); display: flex; flex-direction: column; gap: 8px; }
.side-foot .row { display: flex; gap: 6px; }

.main { display: flex; flex-direction: column; min-width: 0; overflow: hidden; }
.toolbar {
  display: flex; align-items: center; gap: 8px; padding: 10px 18px;
  border-bottom: 1px solid var(--line); background: var(--panel); flex-wrap: wrap;
}
.search { position: relative; flex: 1 1 260px; min-width: 180px; }
.search input {
  width: 100%; padding: 8px 12px 8px 34px; border-radius: 9px;
  border: 1px solid var(--line); background: var(--panel-2); outline: none;
}
.search input:focus { border-color: var(--brand); background: var(--panel); box-shadow: 0 0 0 3px var(--brand-soft); }
.search svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); width: 15px; height: 15px; color: var(--faint); }
.tb-spacer { flex: 1; }
.content { flex: 1; overflow-y: auto; padding: 16px 18px 40px; }
.wrap { max-width: 1120px; margin: 0 auto; display: flex; flex-direction: column; gap: 14px; }

/* ---------------------------------- 按钮 ---------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line); background: var(--panel); color: var(--text);
  border-radius: 9px; padding: 7px 13px; font-size: 13px; white-space: nowrap;
  transition: .15s; text-decoration: none;
}
.btn:hover { border-color: var(--line-2); background: var(--panel-2); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; box-shadow: 0 2px 8px -2px rgba(37, 99, 235, .5); }
.btn.primary:hover { background: var(--brand-2); border-color: var(--brand-2); }
.btn.ghost { background: transparent; }
.btn.icon { padding: 7px 9px; }
.btn.sm { padding: 4px 9px; font-size: 12px; border-radius: 8px; }
.btn.danger { color: var(--danger); border-color: #f3c9c9; background: #fff5f5; }
[data-theme="dark"] .btn.danger { background: #2a1518; border-color: #4a2026; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn svg { width: 15px; height: 15px; }

/* --------------------------------- 录入卡 --------------------------------- */
.entry {
  position: relative; background: var(--panel); border: 1px solid var(--line);
  border-radius: 16px; box-shadow: var(--sh); overflow: hidden;
}
.entry::before {
  content: ""; position: absolute; inset: 0 0 auto; height: 3px;
  background: linear-gradient(90deg, var(--brand), #7c3aed 55%, #0891b2);
}
.entry-head { display: flex; align-items: center; gap: 10px; padding: 13px 16px 0; }
.entry-head h2 { margin: 0; font-size: 15px; }
.entry-head .hint { font-size: 12px; color: var(--muted); }
.entry-body { padding: 12px 16px 14px; display: flex; flex-direction: column; gap: 11px; }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field > label { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.field .req { color: var(--danger); }
.row-date { display: grid; grid-template-columns: minmax(0, 170px) minmax(0, 170px) minmax(0, 1fr); gap: 10px; align-items: end; }
input[type="date"], input[type="text"], textarea, select {
  width: 100%; border: 1px solid var(--line); background: var(--panel-2); color: var(--text);
  border-radius: 9px; padding: 8px 10px; outline: none; transition: .15s; resize: vertical;
}
input[type="date"]:focus, input[type="text"]:focus, textarea:focus, select:focus {
  border-color: var(--brand); background: var(--panel); box-shadow: 0 0 0 3px var(--brand-soft);
}
textarea { min-height: 46px; line-height: 1.7; }
textarea#fTask { min-height: 44px; }
textarea#fDetail { min-height: 84px; }
.weekpill {
  align-self: end; margin-bottom: 1px; font-size: 12px; color: var(--brand);
  background: var(--brand-soft); border: 1px solid transparent; border-radius: 999px;
  padding: 4px 10px; justify-self: start; white-space: nowrap;
}
.entry-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.entry-actions .tip { font-size: 12px; color: var(--faint); }
kbd {
  font: 11px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--panel-2);
  border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 5px; padding: 1px 5px; color: var(--muted);
}

/* --------------------------------- 润色对比 -------------------------------- */
.compare { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: var(--panel-2); }
.compare-head {
  display: flex; align-items: center; gap: 8px; padding: 8px 12px;
  border-bottom: 1px solid var(--line); font-size: 12px; color: var(--muted);
}
.badge { font-size: 11px; padding: 2px 7px; border-radius: 999px; border: 1px solid transparent; }
.badge.ai { background: #ecfdf5; color: var(--ok); border-color: #bbf7d0; }
.badge.offline { background: #fffbeb; color: var(--warn); border-color: #fde68a; }
[data-theme="dark"] .badge.ai { background: #0f2a22; border-color: #1c4b3c; }
[data-theme="dark"] .badge.offline { background: #2a2010; border-color: #4a3617; }
.cmp-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.cmp-cell { padding: 10px 12px; min-width: 0; }
.cmp-cell + .cmp-cell { border-left: 1px solid var(--line); }
.cmp-cell h4 { margin: 0 0 4px; font-size: 11px; color: var(--faint); font-weight: 600; letter-spacing: .04em; }
.cmp-cell p { margin: 0; font-size: 13px; line-height: 1.75; white-space: pre-wrap; word-break: break-word; }
.cmp-cell.old p { color: var(--muted); }
.cmp-note { font-size: 12px; color: var(--muted); padding: 8px 12px; border-top: 1px solid var(--line); background: var(--panel); }
.cmp-acts { display: flex; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--line); background: var(--panel); flex-wrap: wrap; }

/* ---------------------------------- 列表 ---------------------------------- */
.list-bar { display: flex; align-items: center; gap: 8px; padding: 0 2px; }
.list-bar h3 { margin: 0; font-size: 14px; }
.list-bar .count { font-size: 12px; color: var(--muted); }
.week-head { display: flex; align-items: baseline; gap: 10px; padding: 6px 2px 8px; }
.week-head h2 { margin: 0; font-size: 14.5px; }
.week-head span { font-size: 12px; color: var(--muted); }
.week-head .spacer { flex: 1; }

.card {
  position: relative; background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; padding: 12px 14px 11px 17px; box-shadow: var(--sh);
  display: flex; flex-direction: column; gap: 7px; transition: .18s;
}
.card + .card { margin-top: 9px; }
.card::before { content: ""; position: absolute; left: 0; top: 10px; bottom: 10px; width: 3px; border-radius: 3px; background: var(--cat, var(--line-2)); }
.card:hover { border-color: var(--line-2); transform: translateY(-1px); }
.card.flash { animation: flash 1.6s ease-out; }
@keyframes flash { 0% { box-shadow: 0 0 0 3px var(--brand-soft), var(--sh); border-color: var(--brand); } 100% { box-shadow: var(--sh); } }
.card-top { display: flex; align-items: flex-start; gap: 9px; }
.card .date { font-size: 12px; color: var(--muted); background: var(--panel-2); border: 1px solid var(--line); border-radius: 7px; padding: 2px 8px; white-space: nowrap; }
.card .task { font-weight: 600; font-size: 14px; flex: 1; min-width: 0; }
.card .detail { margin: 0; font-size: 13px; color: var(--muted); line-height: 1.75; white-space: pre-wrap; word-break: break-word;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.card.open .detail { -webkit-line-clamp: unset; display: block; }
.card-foot { display: flex; align-items: center; gap: 8px; }
.tag { font-size: 11.5px; color: var(--cat); background: color-mix(in srgb, var(--cat) 11%, transparent);
  border: 1px solid color-mix(in srgb, var(--cat) 26%, transparent); border-radius: 999px; padding: 1px 8px; }
.card-acts { margin-left: auto; display: flex; gap: 4px; opacity: 0; transition: .15s; }
.card:hover .card-acts, .card:focus-within .card-acts { opacity: 1; }
.iconbtn { border: 1px solid transparent; background: transparent; color: var(--muted); border-radius: 7px; padding: 3px 7px; font-size: 12.5px; }
.iconbtn:hover { background: var(--panel-2); border-color: var(--line); color: var(--text); }
.iconbtn.danger:hover { color: var(--danger); border-color: #f3c9c9; background: #fff5f5; }
[data-theme="dark"] .iconbtn.danger:hover { background: #2a1518; border-color: #4a2026; }
mark { background: #fde68a; color: inherit; border-radius: 3px; padding: 0 1px; }
[data-theme="dark"] mark { background: #7c5306; color: #fde68a; }
.empty { text-align: center; color: var(--muted); padding: 46px 20px; }
.empty b { display: block; font-size: 15px; color: var(--text); margin-bottom: 6px; }

/* ---------------------------------- 表格 ---------------------------------- */
.tablewrap { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; overflow: auto; box-shadow: var(--sh); }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { position: sticky; top: 0; background: var(--panel-2); font-size: 12px; color: var(--muted); font-weight: 600; z-index: 2; }
tbody tr:hover { background: var(--panel-2); }
td.plan { min-width: 180px; font-weight: 500; }
td.detail { min-width: 280px; color: var(--muted); }
td.num { white-space: nowrap; color: var(--muted); }

/* ---------------------------------- 弹窗 ---------------------------------- */
.overlay {
  position: fixed; inset: 0; background: rgba(9, 14, 22, .45); backdrop-filter: blur(2px);
  display: none; align-items: center; justify-content: center; padding: 20px; z-index: 60;
}
.overlay.show { display: flex; }
.modal {
  background: var(--panel); border: 1px solid var(--line); border-radius: 16px;
  width: min(620px, 100%); max-height: 88vh; display: flex; flex-direction: column; box-shadow: var(--sh-lg);
}
.modal header { display: flex; align-items: center; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.modal header h3 { margin: 0; font-size: 15px; }
.modal header .x { margin-left: auto; }
.modal-body { padding: 16px 18px; overflow-y: auto; display: flex; flex-direction: column; gap: 13px; }
.modal footer { display: flex; align-items: center; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--line); background: var(--panel-2); border-radius: 0 0 16px 16px; }
.modal footer .spacer { flex: 1; }
.note { font-size: 12px; color: var(--muted); background: var(--panel-2); border: 1px solid var(--line); border-radius: 9px; padding: 9px 11px; }
.note b { color: var(--text); }
.steps { margin: 0; padding-left: 18px; font-size: 13px; color: var(--muted); display: flex; flex-direction: column; gap: 5px; }
.steps b { color: var(--text); }
.seg { display: inline-flex; background: var(--panel-2); border: 1px solid var(--line); border-radius: 9px; padding: 2px; gap: 2px; }
.seg button { border: 0; background: transparent; color: var(--muted); padding: 5px 11px; border-radius: 7px; font-size: 12.5px; }
.seg button.on { background: var(--panel); color: var(--text); box-shadow: var(--sh); }

/* ---------------------------------- toast --------------------------------- */
.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translate(-50%, 20px);
  background: #101827; color: #f8fafc; padding: 9px 16px; border-radius: 10px;
  font-size: 13px; box-shadow: var(--sh-lg); opacity: 0; pointer-events: none; transition: .22s; z-index: 90;
  max-width: 88vw;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { background: #7f1d1d; }
.toast.ok { background: #064e3b; }
[data-theme="dark"] .toast { background: #e6ecf5; color: #0d1117; }

.spin { width: 13px; height: 13px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; display: inline-block; animation: sp .7s linear infinite; }
@keyframes sp { to { transform: rotate(360deg); } }
.hidden { display: none !important; }

/* ---------------------------------- 打印 ---------------------------------- */
@media print {
  @page { size: A4 landscape; margin: 10mm; }
  :root { --bg: #fff; --panel: #fff; --panel-2: #fff; --text: #000; --muted: #333; --line: #bbb; }
  body { background: #fff; font-size: 10pt; }
  .sidebar, .toolbar, .entry, .list-bar, .card-acts, .overlay, .toast, .side-foot, [data-toggle] { display: none !important; }
  .app { display: block; height: auto; }
  .main, .content { height: auto; overflow: visible; padding: 0; }
  .wrap { max-width: none; gap: 6px; }
  .tablewrap { border: 1px solid #bbb; overflow: visible; box-shadow: none; }
  /* 覆盖窄窗口下的堆叠表格样式 */
  .tablewrap table { display: table; }
  .tablewrap tbody { display: table-row-group; }
  .tablewrap tr { display: table-row; background: none; border: 0; margin: 0; padding: 0; box-shadow: none; border-radius: 0; }
  .tablewrap thead { display: table-header-group; }
  .tablewrap td, .tablewrap th { display: table-cell; padding: 6px 8px; border-bottom: 1px solid #ccc; }
  .tablewrap td::before { content: none; }
  .tablewrap td.num:last-child { display: table-cell; }
  th { position: static; background: #f0f0f0 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  thead { display: table-header-group; }
  tr { break-inside: avoid; }
  .card { break-inside: avoid; box-shadow: none; }
  .card .detail { -webkit-line-clamp: unset; display: block; overflow: visible; }
  body.printing .card .card-acts { display: none !important; }
  a { color: #000; text-decoration: none; }
}

/* ---------------------------------- 响应式 -------------------------------- */
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; height: auto; min-height: 100vh; }
  .sidebar { border-right: 0; border-bottom: 1px solid var(--line); overflow: visible; padding: 12px 14px; }
  .brand p { display: none; }
  .stats { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .main { height: auto; }
  .content { overflow: visible; padding: 12px 12px 40px; }
  .row-date { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .row-date .weekpill { grid-column: 1 / -1; justify-self: start; }
  .cmp-grid { grid-template-columns: 1fr; }
  .cmp-cell + .cmp-cell { border-left: 0; border-top: 1px solid var(--line); }
  .toolbar { padding: 8px 12px; }
  .side-foot { flex-direction: row; flex-wrap: wrap; }
  .card-acts { opacity: 1; }
  /* 手机上筛选 chips 改成可横向滑动，省纵向空间 */
  .chips { flex-wrap: nowrap; overflow-x: auto; overflow-y: hidden; padding-bottom: 4px; scrollbar-width: none; }
  .chips::-webkit-scrollbar { display: none; }
  .chip { flex: 0 0 auto; }
  .side-scroll { overflow: visible; }
  .side-label { margin-top: 8px; }
  /* 手机上表格改成「标签 + 值」堆叠卡片，避免横向滚 */
  .tablewrap { border: 0; background: transparent; box-shadow: none; overflow: visible; }
  .tablewrap table, .tablewrap tbody, .tablewrap tr, .tablewrap td { display: block; width: 100%; }
  .tablewrap thead { display: none; }
  .tablewrap tr {
    background: var(--panel); border: 1px solid var(--line); border-left: 3px solid var(--brand);
    border-radius: 10px; margin-bottom: 10px; padding: 6px 10px; box-shadow: var(--sh);
  }
  .tablewrap td { border: 0; padding: 4px 0 4px 62px; position: relative; min-width: 0; }
  .tablewrap td::before {
    content: attr(data-label); position: absolute; left: 0; top: 4px; width: 54px;
    text-align: right; font-size: 12px; color: var(--faint);
  }
  .tablewrap td[data-label=""]::before, .tablewrap td.num:last-child::before { content: none; }
  .tablewrap td.num:last-child { padding-left: 0; display: flex; gap: 6px; justify-content: flex-end; }
  .tablewrap td.plan { font-weight: 600; min-width: 0; }
  .tablewrap td.detail { min-width: 0; }
}

/* ------------------------------- 仅打印显示 ------------------------------- */
.print-only { display: none; }
@media print {
  .print-only { display: block !important; margin-bottom: 10px; }
  .print-only h1 { margin: 0 0 4px; font-size: 14pt; }
  .print-only p { margin: 0; font-size: 9pt; color: #333; }
}

/* ---------------------------- 自动分类（录入卡） --------------------------- */
.cat-line { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 2px 0 12px; }
.cat-pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 12px; border-radius: 999px;
  border: 1px solid var(--line-2); background: var(--panel-2);
  font-size: 12.5px; font-weight: 600; color: var(--muted);
  transition: color .15s ease, border-color .15s ease;
}
.cat-pill.manual { border-style: dashed; }
.cat-select {
  padding: 5px 10px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--panel); color: var(--text); font-size: 12.5px;
  font-family: inherit; cursor: pointer;
}

/* 分类下拉不要被全局 select{width:100%} 拉满 */
.cat-line .cat-select { width: auto; flex: 0 0 auto; padding: 5px 12px; }
