:root {
  --bg: #f7f7f5;
  --panel: #ffffff;
  --ink: #1d2433;
  --ink2: #5b6475;
  --line: #d9dce3;
  --line2: #eceef2;
  --wk: rgba(214, 90, 70, 0.11);
  --stripe: rgba(60, 80, 130, 0.055);
  --dayline: #dde0e8;
  --halfline: #eef0f4;
  --wkline: #78829a;
  --range: color-mix(in srgb, var(--accent) 22%, var(--panel));
  --on-danger: #ffffff;
  --today: #e8f0ff;
  --accent: #2250d8;
  --accent-ink: #ffffff;
  --danger: #b42318;
  --shadow: 0 10px 30px rgba(20, 30, 60, 0.18);
  --label: 136px;
  --rowh: 58px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171d;
    --panel: #1c2028;
    --ink: #e8ebf1;
    --ink2: #a3abba;
    --line: #343a47;
    --line2: #272c37;
    --wk: rgba(255, 130, 110, 0.13);
    --stripe: rgba(255, 255, 255, 0.04);
    --dayline: #323846;
    --halfline: #232834;
    --wkline: #75819b;
    --on-danger: #1a0a08;
    --today: #1f2a45;
    --accent: #7ea2ff;
    --accent-ink: #0d1530;
    --danger: #ff9a92;
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  display: flex; flex-direction: column;
  background: var(--bg); color: var(--ink);
  font: 14px/1.45 system-ui, -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
}
button, input, select, textarea { font: inherit; color: inherit; }
button {
  background: var(--panel); border: 1px solid var(--line); border-radius: 7px;
  padding: 6px 12px; cursor: pointer; min-height: 32px;
}
button:hover { border-color: var(--ink2); }
button:focus-visible, input:focus-visible, textarea:focus-visible, summary:focus-visible, .bar:focus-visible, .dcell:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
button.danger { color: var(--danger); }
kbd {
  font: 11px/1 ui-monospace, Menlo, monospace; padding: 2px 5px; border-radius: 4px;
  border: 1px solid currentColor; opacity: 0.9; margin-left: 4px;
}
.keys kbd { opacity: 1; margin: 0 2px; }

/* 顶栏 */
.bar-top {
  display: flex; align-items: center; gap: 14px; padding: 10px 16px; flex-wrap: wrap;
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.bar-top h1 { margin-right: auto; font-size: 20px; font-weight: 700; margin: 0; letter-spacing: 0.02em; }
.filterrow { flex-basis: 100%; order: 3; display: flex; align-items: center; gap: 10px; padding-top: 8px; border-top: 1px solid var(--line2); }
.filterrow[hidden] { display: none; }
.filters { display: flex; gap: 6px; flex-wrap: wrap; flex: 0 1 auto; min-width: 0; }
.chip { display: inline-flex; align-items: center; gap: 6px; border-radius: 999px; padding: 3px 10px; min-height: 28px; }
.chip .dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.chip[aria-pressed="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.chip kbd { margin-left: 2px; font-size: 10px; }
.tools { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.seg { display: inline-flex; }
.seg button + button { margin-left: -1px; }
.seg button:first-child { border-radius: 7px 0 0 7px; }
.seg button:last-child { border-radius: 0 7px 7px 0; }

.menu { position: relative; }
.menu summary {
  list-style: none; cursor: pointer; padding: 6px 12px; min-height: 32px; display: inline-flex; align-items: center;
  border: 1px solid var(--line); border-radius: 7px; background: var(--panel);
}
.menu summary::-webkit-details-marker { display: none; }
.menu summary::after { content: "▾"; margin-left: 6px; font-size: 11px; }
.menu-pop {
  position: absolute; right: 0; top: calc(100% + 4px); z-index: 30; min-width: 210px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 9px; box-shadow: var(--shadow);
  padding: 6px; display: flex; flex-direction: column; gap: 2px;
}
.menu-pop.left { right: auto; left: 0; max-height: 60vh; overflow: auto; }
.menu.active summary { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.pi { display: flex; gap: 8px; align-items: center; padding: 6px 8px; border-radius: 6px; cursor: pointer; white-space: nowrap; }
.pi:hover { background: var(--line2); }
.menu-pop button { border: 0; text-align: left; background: none; }
.menu-pop button:hover { background: var(--line2); }

/* 甘特 */
.work { flex: 1; display: flex; min-height: 0; }
.scroll { flex: 1; min-width: 0; overflow: auto; position: relative; outline: none; touch-action: pan-x pan-y; }
.scroll.pan, .scroll.pan * { cursor: grab !important; }
.scroll.panning, .scroll.panning * { cursor: grabbing !important; user-select: none; }
.grid.collapsed { --label: 52px; }
.grid { position: relative; min-width: 100%; width: calc(var(--label) + var(--n) * var(--dw)); }
.hrow { display: flex; position: sticky; z-index: 4; background: var(--panel); }
.hrow.months { top: 0; height: 24px; border-bottom: 1px solid var(--line2); }
.hrow.days { top: 24px; height: 46px; border-bottom: 1px solid var(--line); }
.corner {
  position: sticky; left: 0; z-index: 6; flex: none; width: var(--label); background: var(--panel);
  border-right: 1px solid var(--line); font-size: 12px; color: var(--ink2); padding: 4px 12px;
}
.mcell { flex: none; font-size: 12px; font-weight: 600; padding: 3px 8px; color: var(--ink2); border-left: 1px solid var(--line2); white-space: nowrap; overflow: clip; }
.mcell .mt { position: sticky; left: calc(var(--label) + 8px); }
.dcell {
  flex: none; width: var(--dw); text-align: center; border-left: 1px solid var(--line2);
  display: flex; flex-direction: column; justify-content: center; line-height: 1.2; font-size: 13px;
}
.dcell i { font-style: normal; font-size: 11px; color: var(--ink2); }
.dcell.wk { color: var(--danger); background: var(--wk); }
.dcell.mon { border-left: 2px solid var(--wkline); }
.dcell.wk i { color: var(--danger); }
.dcell.today { background: var(--today); font-weight: 700; }
.dcell .halves { display: none; font-size: 10px; color: var(--ink2); }
.grid.wide .dcell .halves { display: flex; justify-content: space-around; }
.grid.narrow .dcell i { display: none; }

.row { display: flex; height: var(--rowh); border-bottom: 1px solid var(--line2); }
.rlabel {
  position: sticky; left: 0; z-index: 3; flex: none; width: var(--label); background: var(--panel);
  border-right: 1px solid var(--line); padding: 0 12px; display: flex; align-items: center; gap: 8px;
}
.rlabel .dot { width: 10px; height: 10px; border-radius: 50%; flex: none; font-size: 0; display: grid; place-items: center; font-weight: 700; }
.grid.collapsed .rlabel { padding: 0; justify-content: center; }
.grid.collapsed .rlabel .dot { width: 28px; height: 28px; font-size: 13px; }
.grid.collapsed .rlabel .nm, .grid.collapsed .corner .ct { display: none; }
.corner { display: flex; align-items: center; justify-content: space-between; }
.grid.collapsed .corner { padding: 0; justify-content: center; }
.fold { min-height: 24px; padding: 0 7px; line-height: 1; font-size: 15px; }
.rlabel .nm { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.track {
  position: relative; flex: none; width: calc(var(--n) * var(--dw));
  background-image:
    linear-gradient(to right, var(--dayline) 1px, transparent 1px),
    linear-gradient(to right, var(--halfline) 1px, transparent 1px);
  background-size: var(--dw) 100%, var(--hw) 100%;
  cursor: cell;
}
.track.drop { background-color: var(--today); }
.wkend { position: absolute; top: 0; bottom: 0; width: var(--dw); background: var(--wk); pointer-events: none; }
.todaycol { position: absolute; top: 0; bottom: 0; width: var(--dw); background: var(--today); pointer-events: none; }
.stripes {
  position: absolute; inset: 0; pointer-events: none;
  background-image:
    linear-gradient(to right, var(--wkline) 0 2px, transparent 2px),
    linear-gradient(to right, transparent 50%, var(--stripe) 50%);
  background-size: calc(var(--dw) * 7) 100%, calc(var(--dw) * 2) 100%;
  background-position: var(--mo) 0, var(--so) 0;
  background-repeat: repeat-x;
}

.task {
  position: absolute; top: 7px; height: calc(var(--rowh) - 14px); border-radius: 7px; padding: 3px 10px;
  display: flex; flex-direction: column; justify-content: center; overflow: hidden; cursor: grab; user-select: none;
  touch-action: pan-x pan-y; -webkit-touch-callout: none; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25); z-index: 2;
}
.task .t1 { font-weight: 600; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; line-height: 1.25; }
.task .t2 { font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; line-height: 1.2; }
.task.has-pj { padding-bottom: 8px; }
.task.drag { cursor: grabbing; }
.task.sel { outline: 3px solid var(--ink); outline-offset: 1px; z-index: 3; }
.task.bad { outline: 3px solid var(--danger); }
.task.drag { opacity: 0.85; z-index: 5; cursor: grabbing; box-shadow: var(--shadow); }
.task .h { position: absolute; top: 0; bottom: 0; width: 8px; cursor: ew-resize; }
.task .h.l { left: 0; } .task .h.r { right: 0; }
.task .h:hover { background: rgba(255, 255, 255, 0.35); }
body.dragging { cursor: grabbing; }
body.dragging { user-select: none; }
body.dragging .task { pointer-events: none; }

.empty { padding: 60px 20px; text-align: center; color: var(--ink2); }
.empty h2 { color: var(--ink); margin: 0 0 6px; }
.empty .btns { margin-top: 14px; display: inline-flex; gap: 8px; }

.foot { font-size: 12px; color: var(--ink2); padding: 6px 16px; border-top: 1px solid var(--line); background: var(--panel); }
.toast {
  position: fixed; left: 50%; bottom: 44px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--ink); color: var(--bg); padding: 9px 16px; border-radius: 9px; z-index: 100;
  transition: opacity 0.18s, transform 0.18s; max-width: min(92vw, 520px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { background: var(--danger); color: var(--on-danger); }
@media (prefers-reduced-motion: reduce) { .toast { transition: none; } }

/* 对话框 */
dialog {
  border: 1px solid var(--line); border-radius: 14px; padding: 20px 22px; background: var(--panel); color: var(--ink);
  box-shadow: var(--shadow); width: min(560px, 94vw); overflow: auto; max-height: calc(100vh - 32px);
}
dialog.wide { width: min(780px, 94vw); }
dialog::backdrop { background: rgba(10, 15, 30, 0.45); }
dialog h2 { margin: 0 0 14px; font-size: 20px; }
.f { display: block; margin-bottom: 12px; }
.f .lbl, label.f { font-size: 12px; color: var(--ink2); }
.f input, .f textarea {
  display: block; width: 100%; margin-top: 4px; padding: 7px 10px; border: 1px solid var(--line); border-radius: 7px;
  background: var(--bg); color: var(--ink);
}
.f2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.actions { display: flex; gap: 8px; align-items: center; margin-top: 8px; }
.grow { flex: 1; }
.msg { min-height: 20px; margin: 0 0 4px; color: var(--danger); font-size: 13px; }
.hint { color: var(--ink2); font-size: 12px; }
.keys { border-collapse: collapse; width: 100%; }
.keys td { padding: 5px 4px; border-bottom: 1px solid var(--line2); }
.keys td:first-child { white-space: nowrap; width: 46%; }

.datefield { position: relative; margin-top: 4px; }
.datebtn { width: 100%; text-align: left; padding: 8px 10px; font-weight: 600; background: var(--bg); }
.datebtn small { font-weight: 400; color: var(--ink2); margin-left: 6px; }

/* 日历弹层 */
.cal {
  position: absolute; z-index: 20; left: 0; top: calc(100% + 6px); background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; box-shadow: var(--shadow); padding: 12px; width: 296px; max-width: calc(100vw - 32px);
}
.cal-months { display: flex; gap: 18px; }
.cal-m { width: 224px; }
.cal-nav { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.cal-nav button { min-height: 28px; padding: 2px 12px; }
.cal-h { text-align: center; height: 26px; font-weight: 600; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 32px); gap: 2px 0; }
.cal-w { font-size: 11px; text-align: center; color: var(--ink2); padding: 2px 0; }
.cal-d {
  border: 0; background: none; border-radius: 0; padding: 0; min-height: 32px; width: 32px; position: relative; font-size: 13px;
}
.cal-d:hover { background: var(--line2); }
.cal-d.wk { color: var(--danger); }
.cal-d.today::after { content: ""; position: absolute; left: 50%; bottom: 3px; width: 4px; height: 4px; margin-left: -2px; border-radius: 50%; background: var(--accent); }
.cal-d.in, .cal-d.edge {
  background-image: linear-gradient(to right, transparent var(--a, 0%), var(--range) var(--a, 0%), var(--range) var(--b, 100%), transparent var(--b, 100%));
}
.cal-d.edge { font-weight: 700; }
.cal-d.edge::before {
  content: ""; position: absolute; left: var(--a); width: calc(var(--b) - var(--a)); bottom: 0; height: 3px; background: var(--accent);
}
.cal-foot { border-top: 1px solid var(--line2); margin-top: 10px; padding-top: 10px; display: flex; flex-direction: column; gap: 8px; }
.cal-row { display: flex; align-items: center; gap: 10px; }
.cal-k { width: 30px; color: var(--ink2); font-size: 12px; }
.cal-row b { min-width: 42px; }
.half { display: inline-flex; }
.half button { min-height: 28px; padding: 2px 12px; border-radius: 0; }
.half button:first-child { border-radius: 7px 0 0 7px; } .half button:last-child { border-radius: 0 7px 7px 0; margin-left: -1px; }
.half button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.cal-sum { color: var(--ink2); font-size: 12px; }

.plist { max-height: 50vh; overflow: auto; margin-bottom: 10px; }
.prow { display: flex; gap: 8px; align-items: center; padding: 5px 0; border-bottom: 1px solid var(--line2); }
.prow input[type="text"] { flex: 1; padding: 6px 8px; border: 1px solid var(--line); border-radius: 7px; background: var(--bg); }
.prow input[type="color"] { width: 34px; height: 30px; padding: 0; border: 1px solid var(--line); border-radius: 7px; background: none; }
.prow small { color: var(--ink2); width: 54px; text-align: right; }
.padd { display: flex; gap: 8px; }
.padd input { flex: 1; padding: 7px 10px; border: 1px solid var(--line); border-radius: 7px; background: var(--bg); }

@media (max-width: 640px) {
  :root { --label: 92px; }
  .f2 { grid-template-columns: 1fr; }
  .cal-months .cal-m + .cal-m { display: none; }
}

/* 右侧抽屉 */
.drawer {
  flex: none; width: min(440px, 100vw); overflow-y: auto; padding: 18px 20px 24px;
  background: var(--panel); border-left: 1px solid var(--line); box-shadow: -6px 0 18px rgba(20, 30, 60, 0.08);
}
.drawer[hidden] { display: none; }
.dhead { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.dhead h2 { margin: 0; font-size: 20px; }
.x { font-size: 20px; line-height: 1; padding: 2px 10px; border: 0; background: none; }
.x:hover { background: var(--line2); }
.drawer .cal { max-width: calc(100vw - 40px); }
@media (max-width: 640px) { .drawer { position: fixed; inset: 0; width: auto; z-index: 50; } }

.pad { padding: 6px 8px; margin: 0; }
.pi .dot { width: 10px; height: 10px; border-radius: 3px; flex: none; }

/* 列表视图 */
.gantt-only { }
body.list-mode .gantt-only { display: none; }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.list { max-width: 860px; margin: 0 auto; padding: 14px 16px 40px; }
.lgroup { margin-bottom: 18px; }
.lhead { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.lhead .dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.lhead h3 { margin: 0; font-size: 16px; }
.lhead small { color: var(--ink2); flex: 1; }
.lgroup ul { list-style: none; margin: 0; padding: 0; }
.litem {
  display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr) minmax(0, 2fr); gap: 4px 14px; width: 100%; text-align: left;
  border: 0; border-bottom: 1px solid var(--line2); border-radius: 0; background: none; padding: 9px 6px; min-height: 44px;
}
.litem:hover { background: var(--line2); }
.litem.sel { background: var(--today); }
.litem .lt { font-weight: 600; overflow-wrap: anywhere; }
.litem .lp { color: var(--ink2); display: flex; align-items: center; gap: 6px; }
.litem .lp i { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.litem .ld { color: var(--ink2); }
.keytoggle { display: block; margin: 10px 0 4px; font-size: 13px; }
.keytoggle small { color: var(--ink2); margin-left: 24px; }
@media (max-width: 640px) {
  .litem { grid-template-columns: 1fr; }
  .bar-top { padding: 8px 12px; gap: 8px; }
  .tools kbd { display: none; }
  .filters { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 2px; }
  .chip { flex: none; }
  .foot { display: none; }
}
/* 触屏:放大点击目标到 ≥44px */
@media (pointer: coarse) {
  button, .menu summary { min-height: 44px; }
  .chip { min-height: 40px; }
  .fold { min-height: 40px; min-width: 40px; }
  .x { min-width: 44px; }
  .half button { min-height: 40px; padding: 2px 16px; }
  .cal { width: 336px; }
  .cal-m { width: 280px; }
  .cal-grid { grid-template-columns: repeat(7, 40px); }
  .cal-d { width: 40px; min-height: 40px; }
  .task .h { width: 18px; }
  .pi { padding: 11px 8px; }
  .prow input[type="color"] { height: 40px; width: 44px; }
}
@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; } }

.task.tiny .t1, .task.tiny .t2 { display: none; }
.task.tiny { padding: 0; }
.keygrid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 32px; }
.keygrid h3 { margin: 4px 0 6px; font-size: 14px; color: var(--ink2); font-weight: 600; }
.keygrid .keys td:first-child { width: 48%; }
@media (max-width: 760px) { .keygrid { grid-template-columns: 1fr; } }
@media (max-width: 640px) {
  .tools { display: contents; }
  .tools > * { order: 2; }
  .tools > #btnNew { order: 1; }
  .bar-top h1 { order: 0; }
  #btnHelp, .tools > .seg.gantt-only { display: none; }
}
@media (max-width: 640px) { .menu-pop.left { left: auto; right: 0; } }
