/* ========================================
   周周待办 - 设计系统 & 样式
   ======================================== */

/* ---------- CSS Variables ---------- */
:root {
  /* Brand */
  --brand: #2d4636;
  --brand-ink: #fbfaf6;
  --brand-soft: #e3e8df;

  /* Background */
  --bg: #f9f7f0;
  --surface: #fffdf8;
  --surface-2: #f0ede4;
  --surface-3: #e8e4d8;

  /* Text */
  --ink-1: #1f1b14;
  --ink-2: #56524a;
  --ink-3: #8a8579;
  --ink-4: #b3ae9f;

  /* Lines */
  --line: #221e1814;
  --line-soft: #221e180d;
  --line-strong: #221e1824;

  /* Semantic */
  --danger: #a8463a;
  --danger-soft: #f1deda;
  --warn: #b07a2c;
  --warn-soft: #f4ecdd;
  --info: #4f6c82;
  --info-soft: #dfe6ec;
  --muted: #8a8579;
  --muted-soft: #ece9e0;

  /* Tag colors */
  --tag-slate: #4f6c82;
  --tag-sage: #5c7c5a;
  --tag-clay: #b07a2c;
  --tag-rust: #a8463a;
  --tag-plum: #7a5a7c;
  --tag-rose: #9e4f66;
  --tag-teal: #3f7375;
  --tag-ochre: #8a7438;

  /* Hover */
  --hover: #221e180a;

  /* Radius */
  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 14px;
  --r-xl: 18px;

  /* Font */
  --font-num: "Manrope", "PingFang SC", system-ui, sans-serif;
  --font-sans: "Manrope", -apple-system, BlinkMacSystemFont, "PingFang SC", "HarmonyOS Sans SC", "Noto Sans SC", "Microsoft YaHei", sans-serif;

  /* Transitions */
  --ease: cubic-bezier(.4, 0, .2, 1);
}

/* ---------- Dark Mode ---------- */
.dark {
  --bg: #141210;
  --surface: #1c1915;
  --surface-2: #24211c;
  --surface-3: #2d2923;

  --ink-1: #e8e4d8;
  --ink-2: #b3ae9f;
  --ink-3: #8a8579;
  --ink-4: #5c584e;

  --line: #ffffff0d;
  --line-soft: #ffffff08;
  --line-strong: #ffffff14;

  --hover: #ffffff0a;

  --brand: #4a7c5c;
  --brand-ink: #fbfaf6;
  --brand-soft: #243729;

  --danger: #d47266;
  --danger-soft: #3d1f1b;
  --warn: #d4a64c;
  --warn-soft: #3d301a;
  --info: #7a9bb5;
  --info-soft: #1f2a33;
  --muted-soft: #2d2923;
}

/* ---------- Reset & Base ---------- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body, #root {
  height: 100vh;
  min-height: 100%;
  min-height: 100dvh;
  overflow-x: hidden;
  overflow-y: hidden;
}

body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--ink-1);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

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

input, textarea, select {
  font-family: inherit;
  font-size: inherit;
}

a { color: inherit; text-decoration: none; }

svg { display: block; flex-shrink: 0; }

/* Scrollbar */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: #00000014;
  border: 2px solid transparent;
  background-clip: padding-box;
  border-radius: 8px;
}
::-webkit-scrollbar-thumb:hover {
  background: #00000029;
  border: 2px solid transparent;
  background-clip: padding-box;
}

/* ---------- App Layout ---------- */
.app {
  background: var(--bg);
  letter-spacing: .005em;
  grid-template-columns: 232px 1fr;
  width: 100%;
  height: 100%;
  min-height: 100dvh;
  display: grid;
  overflow: hidden;
}

/* ---------- Sidebar ---------- */
.side {
  background: var(--surface-2);
  border-right: 1px solid var(--line);
  flex-direction: column;
  gap: 18px;
  min-width: 0;
  padding: 18px 14px;
  display: flex;
  overflow-y: auto;
}

.side-brand {
  align-items: center;
  gap: 10px;
  padding: 4px 6px 2px;
  display: flex;
}

.side-brand .logo {
  background: var(--brand);
  width: 30px;
  height: 30px;
  color: var(--brand-ink);
  letter-spacing: -.02em;
  border-radius: 8px;
  place-items: center;
  font-size: 14px;
  font-weight: 700;
  display: grid;
  flex-shrink: 0;
}

.side-brand .wm {
  color: var(--ink-1);
  letter-spacing: -.01em;
  font-size: 14px;
  font-weight: 600;
}

.side-brand .wm small {
  color: var(--ink-3);
  letter-spacing: 0;
  margin-top: 1px;
  font-size: 11px;
  font-weight: 500;
  display: block;
}

.side-stats {
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 4px 2px 2px;
  display: grid;
}

.stat {
  border-radius: var(--r-md);
  background: var(--surface);
  border: 1px solid var(--line-soft);
  padding: 10px 12px;
}

.stat .v {
  font-family: var(--font-num);
  color: var(--ink-1);
  font-variant-numeric: tabular-nums;
  letter-spacing: -.02em;
  font-size: 22px;
  font-weight: 600;
  line-height: 1;
}

.stat .l {
  color: var(--ink-3);
  letter-spacing: .04em;
  margin-top: 6px;
  font-size: 11px;
}

.side-cta {
  background: var(--brand);
  width: 100%;
  color: var(--brand-ink);
  border-radius: var(--r-md);
  letter-spacing: .01em;
  justify-content: center;
  align-items: center;
  gap: 6px;
  padding: 10px 12px;
  font-size: 13px;
  font-weight: 600;
  transition: background .15s;
  display: flex;
}

.side-cta:hover { background: #243729; }
.dark .side-cta:hover { background: #3a5e48; }

.side-cta svg { width: 14px; height: 14px; }

.side-nav-label {
  color: var(--ink-4);
  text-transform: uppercase;
  letter-spacing: .14em;
  padding: 4px 8px;
  font-size: 10.5px;
  font-weight: 600;
}

.side-nav {
  flex-direction: column;
  gap: 1px;
  display: flex;
}

.nav-item {
  border-radius: var(--r-sm);
  color: var(--ink-2);
  text-align: left;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 7px 10px;
  font-size: 13px;
  transition: background .12s, color .12s;
  display: flex;
}

.nav-item:hover {
  background: var(--hover);
  color: var(--ink-1);
}

.nav-item.active {
  background: var(--ink-1);
  color: var(--bg);
}

.nav-item.active .badge {
  color: var(--bg);
  opacity: .7;
}

.nav-item svg {
  stroke-width: 1.8px;
  flex-shrink: 0;
  width: 15px;
  height: 15px;
}

.nav-item .badge {
  color: var(--ink-3);
  font-variant-numeric: tabular-nums;
  margin-left: auto;
  font-size: 11px;
}

.side-foot {
  color: var(--ink-4);
  border-top: 1px solid var(--line-soft);
  justify-content: space-between;
  margin-top: auto;
  padding: 12px 8px 6px;
  font-size: 11px;
  display: flex;
}

/* ---------- Main Area ---------- */
.main {
  grid-template-rows: auto auto 1fr;
  min-width: 0;
  height: 100%;
  min-height: 0;
  display: grid;
}

/* ---------- Topbar ---------- */
.topbar {
  border-bottom: 1px solid var(--line-soft);
  background: var(--surface);
  z-index: 40;
  align-items: center;
  gap: 16px;
  height: 56px;
  padding: 0 28px;
  display: flex;
}

.crumb {
  align-items: center;
  gap: 10px;
  display: flex;
}

.crumb h1 {
  letter-spacing: -.01em;
  color: var(--ink-1);
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  line-height: 1;
}

.crumb .sub {
  color: var(--ink-3);
  font-size: 12px;
}

.search {
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: var(--r-md);
  width: 260px;
  color: var(--ink-3);
  align-items: center;
  gap: 8px;
  margin-left: auto;
  padding: 7px 11px;
  display: flex;
}

.search svg {
  stroke-width: 1.8px;
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}

.search input {
  background: none;
  border: none;
  outline: none;
  color: var(--ink-1);
  flex: 1;
  min-width: 0;
  font-size: 13px;
}

.search input::placeholder { color: var(--ink-4); }

.search kbd {
  font-family: var(--font-num);
  background: var(--surface-2);
  border: 1px solid var(--line-soft);
  color: var(--ink-3);
  border-radius: 4px;
  margin-left: auto;
  padding: 1px 5px;
  font-size: 10.5px;
  flex-shrink: 0;
}

.icon-btn {
  border-radius: var(--r-sm);
  width: 32px;
  height: 32px;
  color: var(--ink-2);
  border: 1px solid var(--line-soft);
  background: var(--surface);
  place-items: center;
  transition: background .12s, color .12s;
  display: grid;
  flex-shrink: 0;
}

.icon-btn:hover {
  background: var(--hover);
  color: var(--ink-1);
}

.icon-btn svg { stroke-width: 1.8px; width: 15px; height: 15px; }

/* ---------- Content Area ---------- */
.content {
  grid-row: 3;
  padding: 24px 28px 32px;
  min-width: 0;
  overflow: auto;
}

.mobile-view-nav {
  display: none;
}

.mobile-add-btn {
  display: none;
}

.view-container {
  min-height: 100%;
}

/* ---------- Overview Bar ---------- */
.overview {
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  grid-template-columns: repeat(5, 1fr);
  gap: 1px;
  margin-bottom: 22px;
  display: grid;
  overflow: hidden;
  background: var(--line);
}

.ov-cell {
  background: var(--surface);
  flex-direction: column;
  gap: 6px;
  padding: 14px 16px;
  display: flex;
}

.ov-cell .lbl {
  color: var(--ink-3);
  letter-spacing: .06em;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  display: flex;
}

.ov-cell .num {
  font-family: var(--font-num);
  font-variant-numeric: tabular-nums;
  letter-spacing: -.02em;
  color: var(--ink-1);
  font-size: 26px;
  font-weight: 600;
  line-height: 1;
}

.ov-cell .num .total {
  color: var(--ink-4);
  margin-left: 2px;
  font-size: 14px;
  font-weight: 500;
}

.ov-cell .bar {
  background: var(--surface-2);
  border-radius: 2px;
  height: 3px;
  margin-top: 2px;
  overflow: hidden;
}

.ov-cell .bar i {
  background: var(--brand);
  border-radius: 2px;
  height: 100%;
  display: block;
  transition: width .3s var(--ease);
}

/* ---------- Daily View ---------- */
.day-block { margin-bottom: 28px; }

.day-head {
  border-bottom: 1px solid var(--line-soft);
  align-items: baseline;
  gap: 12px;
  margin-bottom: 8px;
  padding: 0 4px 10px;
  display: flex;
}

.day-head .wd {
  color: var(--ink-3);
  letter-spacing: .16em;
  text-transform: uppercase;
  font-size: 11px;
  font-weight: 600;
}

.day-head .dt {
  font-family: var(--font-num);
  letter-spacing: -.02em;
  color: var(--ink-1);
  font-variant-numeric: tabular-nums;
  font-size: 22px;
  font-weight: 600;
}

.day-head.today .dt { color: var(--brand); }

.day-head .meta {
  color: var(--ink-3);
  align-items: center;
  gap: 12px;
  margin-left: auto;
  font-size: 11.5px;
  display: flex;
}

.day-head .add {
  color: var(--ink-3);
  align-items: center;
  gap: 4px;
  font-size: 11.5px;
  display: flex;
  cursor: pointer;
}

.day-head .add:hover { color: var(--ink-1); }

.task-list {
  flex-direction: column;
  gap: 1px;
  display: flex;
}

.task {
  border-radius: var(--r-md);
  cursor: pointer;
  align-items: flex-start;
  gap: 12px;
  padding: 10px 12px 10px 8px;
  display: flex;
  position: relative;
  transition: background .1s;
}

.task:hover { background: var(--hover); }

.task .pri-mark {
  background: transparent;
  border-radius: 2px;
  width: 3px;
  height: 14px;
  position: absolute;
  top: 14px;
  left: 0;
}

.task.pri-h .pri-mark { background: var(--danger); }
.task.pri-m .pri-mark { background: var(--warn); }
.task.pri-l .pri-mark { background: var(--info); }

.task-main { flex: 1; min-width: 0; }

.task-title {
  color: var(--ink-1);
  letter-spacing: .005em;
  font-size: 14px;
  line-height: 1.4;
}

.task.done .task-title {
  color: var(--ink-3);
  text-decoration: line-through;
}

.task-meta {
  color: var(--ink-3);
  align-items: center;
  gap: 10px;
  margin-top: 5px;
  font-size: 11.5px;
  display: flex;
}

.task-meta .sep {
  background: var(--ink-4);
  border-radius: 999px;
  width: 2px;
  height: 2px;
}

.task-tail {
  color: var(--ink-3);
  font-variant-numeric: tabular-nums;
  align-self: center;
  font-size: 11px;
}

.empty-row {
  color: var(--ink-4);
  border: 1px dashed var(--line);
  border-radius: var(--r-md);
  text-align: center;
  background: none;
  margin-top: 4px;
  padding: 14px 12px;
  font-size: 12px;
  cursor: pointer;
}

.empty-row:hover {
  color: var(--ink-2);
  border-color: var(--line-strong);
}

/* ---------- Checkbox ---------- */
.check {
  border: 1.5px solid var(--line-strong);
  cursor: pointer;
  background: none;
  border-radius: 999px;
  flex-shrink: 0;
  place-items: center;
  width: 18px;
  height: 18px;
  transition: border-color .15s, background .15s;
  display: grid;
  margin-top: 1px;
}

.check:hover { border-color: var(--ink-2); }
.check.done {
  background: var(--line-strong);
  border-color: var(--line-strong);
}

.check.done::after {
  content: "";
  border-bottom: 2px solid var(--bg);
  border-left: 2px solid var(--bg);
  width: 8px;
  height: 5px;
  transform: rotate(-45deg) translate(1px, -1px);
}

/* ---------- Chip ---------- */
.chip {
  color: var(--ink-2);
  background: #221e180f;
  border-radius: 999px;
  align-items: center;
  gap: 5px;
  padding: 2px 7px;
  font-size: 11.5px;
  font-weight: 500;
  display: inline-flex;
}

.chip .dot {
  background: var(--ink-3);
  border-radius: 999px;
  width: 6px;
  height: 6px;
}

.chip.danger { color: var(--danger); background: #a8463a1f; }
.chip.danger .dot { background: var(--danger); }
.chip.warn { color: var(--warn); background: #b07a2c24; }
.chip.warn .dot { background: var(--warn); }
.chip.info { color: var(--info); background: #4f6c821f; }
.chip.info .dot { background: var(--info); }

/* ---------- Kanban ---------- */
.kanban {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
  height: calc(100vh - 160px);
  min-height: 0;
  display: grid;
}

.col {
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: var(--r-lg);
  flex-direction: column;
  min-height: 0;
  display: flex;
  overflow: hidden;
}

.col-head {
  align-items: center;
  gap: 8px;
  padding: 14px 14px 10px;
  display: flex;
}

.col-head .lab {
  color: var(--ink-1);
  letter-spacing: -.005em;
  font-size: 13px;
  font-weight: 600;
}

.col-head .cnt {
  color: var(--ink-3);
  font-variant-numeric: tabular-nums;
  font-size: 11.5px;
}

.col-head .add {
  border-radius: var(--r-sm);
  width: 22px;
  height: 22px;
  color: var(--ink-3);
  place-items: center;
  margin-left: auto;
  display: grid;
  cursor: pointer;
}

.col-head .add:hover { background: var(--hover); color: var(--ink-1); }
.col-head .add svg { width: 14px; height: 14px; }

.col-head .ind {
  background: var(--muted);
  border-radius: 999px;
  width: 6px;
  height: 6px;
}

.col[data-st="todo"] .ind { background: var(--ink-3); }
.col[data-st="doing"] .ind { background: var(--warn); }
.col[data-st="done"] .ind { background: var(--brand); }
.col[data-st="cancel"] .ind { background: var(--ink-4); }

.col-body {
  flex-direction: column;
  flex: 1;
  gap: 6px;
  min-height: 0;
  padding: 4px 10px 10px;
  display: flex;
  overflow-y: auto;
}

/* ---------- Card (Kanban/Quadrant) ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: var(--r-md);
  cursor: grab;
  flex-direction: column;
  gap: 8px;
  padding: 10px 12px;
  transition: border-color .12s, box-shadow .12s;
  display: flex;
  position: relative;
}

.card:hover {
  border-color: var(--line-strong);
  box-shadow: 0 1px 2px #00000005, 0 4px 12px #00000008;
}

.card:active { cursor: grabbing; }

.card .ttl {
  color: var(--ink-1);
  align-items: flex-start;
  gap: 10px;
  font-size: 13.5px;
  line-height: 1.4;
  display: flex;
}

.card .meta {
  color: var(--ink-3);
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  padding-left: 0;
  font-size: 11px;
  display: flex;
}

.card .meta .dt {
  font-variant-numeric: tabular-nums;
  align-items: center;
  gap: 4px;
  display: flex;
}

.card .meta svg {
  stroke-width: 1.8px;
  width: 11px;
  height: 11px;
}

.empty-col {
  border: 1px dashed var(--line);
  border-radius: var(--r-md);
  color: var(--ink-4);
  flex: 1;
  place-items: center;
  min-height: 80px;
  margin: 4px 0;
  font-size: 12px;
  display: grid;
}

/* ---------- Quadrant ---------- */
.matrix {
  grid-template-rows: 28px 1.18fr .82fr;
  grid-template-columns: 28px 1fr 1fr;
  gap: 14px;
  height: calc(100vh - 160px);
  min-height: 620px;
  display: grid;
}

.mx-axis-x, .mx-axis-y {
  color: var(--ink-4);
  letter-spacing: .18em;
  text-transform: uppercase;
  justify-content: center;
  align-items: center;
  font-size: 10.5px;
  font-weight: 600;
  display: flex;
}

.mx-axis-x { grid-area: 1/2/auto/span 2; gap: 18px; }
.mx-axis-x span { align-items: center; gap: 6px; display: inline-flex; }

.mx-axis-y { writing-mode: vertical-rl; grid-area: 2/1/span 2; gap: 18px; transform: rotate(180deg); }
.mx-axis-y span { align-items: center; gap: 6px; display: inline-flex; }

.quad {
  border: 1px solid var(--line-soft);
  border-radius: var(--r-lg);
  flex-direction: column;
  min-height: 0;
  padding: 18px 20px;
  display: flex;
  position: relative;
  overflow: hidden;
}

.quad.q1 { grid-area: 2/2; }
.quad.q2 { grid-area: 2/3; }
.quad.q3 { grid-area: 3/2; }
.quad.q4 { grid-area: 3/3; }

.quad.q1, .quad.q2 {
  box-shadow: 0 1px 2px #1f1b1405, 0 8px 24px #1f1b140a;
}

.quad.q1 { background: var(--danger-soft); border-color: #a8463a38; }
.quad.q2 { background: var(--brand-soft); border-color: #2d463638; }
.quad.q3 { background: var(--warn-soft); border-color: #b07a2c2e; padding: 14px 16px; }
.quad.q4 { background: var(--surface-2); border-color: var(--line); padding: 14px 16px; }

.quad::before {
  content: "";
  height: 4px;
  position: absolute;
  top: 0; left: 0; right: 0;
}

.quad.q1::before { background: var(--danger); }
.quad.q2::before { background: var(--brand); }
.quad.q3::before { background: var(--warn); opacity: .8; height: 3px; }
.quad.q4::before { background: none; border-top: 1.5px dashed #221e182e; height: 0; }

.quad-head {
  align-items: center;
  gap: 10px;
  margin-bottom: 4px;
  display: flex;
}

.q-num {
  font-family: var(--font-num);
  font-variant-numeric: tabular-nums;
  border-radius: 8px;
  flex-shrink: 0;
  place-items: center;
  font-weight: 600;
  display: inline-grid;
}

.quad.q1 .q-num { background: var(--danger); width: 32px; height: 32px; color: var(--brand-ink); font-size: 15px; box-shadow: 0 1px 2px #a8463a4d; }
.quad.q2 .q-num { background: var(--brand); width: 32px; height: 32px; color: var(--brand-ink); font-size: 15px; box-shadow: 0 1px 2px #2d46364d; }
.quad.q3 .q-num { background: var(--surface); width: 24px; height: 24px; color: var(--warn); font-size: 12px; }
.quad.q4 .q-num { background: var(--hover); width: 22px; height: 22px; color: var(--ink-3); font-size: 11px; }

.quad .title {
  color: var(--ink-1);
  letter-spacing: -.005em;
  font-weight: 600;
  line-height: 1.2;
}

.quad.q1 .title, .quad.q2 .title { font-size: 16px; }
.quad.q3 .title { color: var(--ink-2); font-size: 13.5px; font-weight: 600; }
.quad.q4 .title { color: var(--ink-3); font-size: 13px; font-weight: 500; }

.quad-head .cnt {
  color: var(--ink-3);
  font-variant-numeric: tabular-nums;
  margin-left: auto;
  font-size: 11.5px;
}

.quad.q4 .cnt { color: var(--ink-4); }

.quad-head .add {
  border-radius: var(--r-sm);
  width: 24px;
  height: 24px;
  color: var(--ink-3);
  place-items: center;
  display: grid;
  cursor: pointer;
}

.quad-head .add:hover { background: var(--hover); color: var(--ink-1); }
.quad-head .add svg { stroke-width: 1.8px; width: 14px; height: 14px; }

.q-action {
  letter-spacing: .02em;
  border-radius: 999px;
  align-items: center;
  gap: 5px;
  width: fit-content;
  margin-bottom: 12px;
  padding: 3px 9px;
  font-size: 11.5px;
  font-weight: 600;
  display: inline-flex;
}

.q-action::before {
  content: "";
  background: currentColor;
  border-radius: 999px;
  width: 5px;
  height: 5px;
}

.quad.q1 .q-action { background: var(--danger); color: var(--surface); }
.quad.q2 .q-action { background: var(--brand); color: var(--surface); }
.quad.q3 .q-action { background: var(--surface); color: var(--warn); border: 1px solid #b07a2c33; margin-bottom: 10px; padding: 2px 8px; font-size: 11px; }
.quad.q4 .q-action { color: var(--ink-4); letter-spacing: .06em; text-transform: uppercase; background: none; margin-bottom: 10px; padding: 0; font-size: 10.5px; font-weight: 500; }
.quad.q4 .q-action::before { display: none; }

.quad-list {
  flex-direction: column;
  flex: 1;
  gap: 6px;
  min-height: 0;
  display: flex;
  overflow-y: auto;
}

.quad.q4 .quad-list { gap: 0; }

.quad.q4 .card {
  border: 0;
  border-bottom: 1px solid var(--line);
  box-shadow: none;
  background: none;
  border-radius: 0;
  padding: 9px 4px;
  font-size: 12.5px;
}

.quad.q4 .card:last-child { border-bottom: 0; }
.quad.q4 .card:hover { background: var(--hover); border-radius: 6px; }
.quad.q4 .card .ttl { font-size: 12.5px; color: var(--ink-3); }
.quad.q4 .card .meta { display: none; }

.empty-quad {
  border: 1px dashed var(--line);
  border-radius: var(--r-md);
  color: var(--ink-4);
  flex: 1;
  place-items: center;
  font-size: 12px;
  display: grid;
}

/* ---------- Tag Filter ---------- */
.tagfilter-wrapper { position: relative; }

.tagfilter-trigger {
  border-radius: var(--r-sm);
  border: 1px solid var(--line-soft);
  background: var(--surface);
  height: 30px;
  color: var(--ink-2);
  align-items: center;
  gap: 6px;
  padding: 0 8px 0 10px;
  font-size: 12.5px;
  font-weight: 500;
  transition: background .12s, color .12s, border-color .12s;
  display: inline-flex;
}

.tagfilter-trigger:hover { background: var(--hover); color: var(--ink-1); border-color: var(--line); }
.tagfilter-trigger.is-active { background: var(--brand-soft); color: var(--brand); border-color: transparent; }
.tagfilter-trigger svg.lead { stroke-width: 1.8px; width: 13px; height: 13px; color: var(--ink-3); }
.tagfilter-trigger.is-active svg.lead { color: var(--brand); }
.tagfilter-trigger svg.caret { stroke-width: 2px; width: 12px; height: 12px; color: var(--ink-4); transition: transform .15s; }
.tagfilter-trigger.is-active svg.caret { transform: rotate(180deg); }

.tagfilter-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  z-index: 50;
  flex-direction: column;
  width: 304px;
  display: flex;
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  overflow: hidden;
  box-shadow: 0 1px 2px #1f1b140a, 0 8px 24px #1f1b1414, 0 24px 48px #1f1b140f;
}

.tfp-head {
  align-items: center;
  padding: 12px 14px 10px;
  display: flex;
}

.tfp-head .ttl {
  color: var(--ink-3);
  letter-spacing: .14em;
  text-transform: uppercase;
  font-size: 11px;
  font-weight: 600;
}

.tfp-head .actions { gap: 4px; margin-left: auto; display: flex; }
.tfp-head .actions button {
  color: var(--ink-3);
  border-radius: 4px;
  padding: 3px 7px;
  font-size: 11.5px;
}
.tfp-head .actions button:hover { background: var(--hover); color: var(--ink-1); }

.tfp-search {
  background: var(--surface-2);
  border-radius: var(--r-sm);
  color: var(--ink-3);
  align-items: center;
  gap: 8px;
  margin: 0 10px 6px;
  padding: 7px 10px;
  font-size: 12.5px;
  display: flex;
}

.tfp-search svg { stroke-width: 1.8px; width: 13px; height: 13px; }
.tfp-search input { color: var(--ink-1); background: none; border: 0; outline: none; flex: 1; font-size: 12.5px; }
.tfp-search input::placeholder { color: var(--ink-4); }

.tfp-list {
  flex-direction: column;
  max-height: 320px;
  padding: 4px 6px 6px;
  display: flex;
  overflow-y: auto;
}

.tfp-row {
  border-radius: var(--r-sm);
  color: var(--ink-1);
  text-align: left;
  cursor: pointer;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 7px 8px;
  font-size: 13px;
  transition: background .1s;
  display: flex;
}

.tfp-row:hover { background: var(--hover); }

.tfp-row .dot-tag {
  background: var(--ink-4);
  border-radius: 999px;
  flex-shrink: 0;
  width: 8px;
  height: 8px;
}

.tfp-row .name {
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
  overflow: hidden;
}

.tfp-row .cnt {
  color: var(--ink-4);
  font-variant-numeric: tabular-nums;
  font-size: 11.5px;
}

.tfp-row .tick {
  width: 14px; height: 14px;
  color: var(--brand);
  opacity: 0;
  place-items: center;
  display: grid;
}

.tfp-row .tick svg { stroke-width: 2.4px; width: 14px; height: 14px; }
.tfp-row.on { background: var(--brand-soft); }
.tfp-row.on .name { color: var(--brand); font-weight: 600; }
.tfp-row.on .tick { opacity: 1; }
.tfp-row.on .cnt { color: var(--brand); opacity: .65; }

.tfp-divider {
  background: var(--line-soft);
  height: 1px;
  margin: 4px 8px;
}

.tfp-foot {
  border-top: 1px solid var(--line-soft);
  background: var(--surface-2);
  color: var(--ink-3);
  align-items: center;
  padding: 10px 12px;
  font-size: 12px;
  display: flex;
}

/* ---------- Modal ---------- */
.modal-overlay {
  background: #00000040;
  z-index: 100;
  justify-content: center;
  align-items: center;
  display: flex;
  position: fixed;
  inset: 0;
}

.modal {
  background: var(--surface);
  border-radius: var(--r-xl);
  flex-direction: column;
  width: 520px;
  max-height: 90vh;
  display: flex;
  overflow: hidden;
  box-shadow: 0 1px 2px #0000000a, 0 8px 32px #00000014, 0 32px 64px #0000001a;
}

.modal-body {
  flex-direction: column;
  gap: 16px;
  padding: 22px;
  display: flex;
  overflow-y: auto;
}

.field {
  flex-direction: column;
  gap: 6px;
  display: flex;
}

.field label {
  color: var(--ink-3);
  letter-spacing: .04em;
  font-size: 11.5px;
  font-weight: 500;
}

.field input[type="text"],
.field input[type="date"],
.field textarea {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  color: var(--ink-1);
  padding: 8px 10px;
  font-size: 13px;
  outline: none;
  transition: border-color .15s;
  resize: vertical;
}

.field input:focus,
.field textarea:focus {
  border-color: var(--brand);
}

.field-row {
  gap: 14px;
  display: flex;
}

.field-row .field { flex: 1; min-width: 0; }

/* Segmented Control */
.seg {
  background: var(--surface-2);
  border-radius: var(--r-sm);
  gap: 2px;
  padding: 3px;
  display: flex;
}

.seg button {
  color: var(--ink-3);
  border-radius: 5px;
  padding: 4px 10px;
  font-size: 12px;
  white-space: nowrap;
}

.seg button.on {
  background: var(--surface);
  color: var(--ink-1);
  font-weight: 500;
  box-shadow: 0 1px 2px #0000000a;
}

/* Parent Pick */
.parent-pick {
  flex-wrap: wrap;
  gap: 6px;
  display: flex;
}

.parent-chip {
  border-radius: var(--r-sm);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink-2);
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  font-size: 12.5px;
  font-weight: 500;
  transition: border-color .1s, background .1s;
  display: inline-flex;
}

.parent-chip:hover { border-color: var(--line-strong); color: var(--ink-1); }
.parent-chip.on { border-color: var(--brand); background: var(--brand-soft); color: var(--brand); }

.modal-foot {
  border-top: 1px solid var(--line-soft);
  background: var(--surface-2);
  align-items: center;
  gap: 10px;
  padding: 14px 22px;
  display: flex;
}

.modal-foot .actions { gap: 8px; margin-left: auto; display: flex; }

/* Buttons */
.btn {
  border-radius: var(--r-sm);
  border: 1px solid var(--line);
  background: var(--surface);
  height: 32px;
  color: var(--ink-2);
  padding: 0 14px;
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  transition: background .12s, color .12s;
}

.btn:hover { background: var(--hover); color: var(--ink-1); }
.btn.primary {
  background: var(--brand);
  color: var(--brand-ink);
  border-color: transparent;
  font-weight: 600;
}
.btn.primary:hover { background: #243729; }
.btn.danger { color: var(--danger); }
.btn.danger:hover { background: var(--danger-soft); }
.btn:disabled { cursor: wait; opacity: .6; }

button:active { transform: translateY(1px); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}

/* ---------- Calendar ---------- */
.cal-head {
  align-items: center;
  gap: 14px;
  margin-bottom: 14px;
  display: flex;
}

.cal-head .y {
  font-family: var(--font-num);
  letter-spacing: -.02em;
  color: var(--ink-1);
  font-variant-numeric: tabular-nums;
  font-size: 22px;
  font-weight: 600;
}

.cal-head .y .m { color: var(--ink-3); margin-left: 6px; }

.cal-head .seg {
  background: var(--surface-2);
  border-radius: var(--r-sm);
  gap: 2px;
  padding: 3px;
  display: flex;
}

.cal-head .seg button {
  color: var(--ink-3);
  border-radius: 5px;
  padding: 4px 10px;
  font-size: 12px;
}

.cal-head .seg button.on {
  background: var(--surface);
  color: var(--ink-1);
  font-weight: 500;
  box-shadow: 0 1px 2px #0000000a;
}

.cal-head .nav { align-items: center; gap: 4px; margin-left: auto; display: flex; }
.cal-head .nav button {
  border-radius: var(--r-sm);
  width: 28px; height: 28px;
  color: var(--ink-2);
  place-items: center;
  display: grid;
}
.cal-head .nav button:hover { background: var(--hover); }
.cal-head .nav .today {
  border: 1px solid var(--line);
  width: auto; height: 28px;
  padding: 0 12px;
  font-size: 12px;
  font-weight: 500;
}

.cal {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  flex-direction: column;
  display: flex;
  overflow: hidden;
}

.cal-wkrow {
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
  grid-template-columns: repeat(7, 1fr);
  display: grid;
}

.cal-wkrow > div {
  color: var(--ink-3);
  letter-spacing: .16em;
  text-transform: uppercase;
  padding: 8px 12px;
  font-size: 11px;
  font-weight: 600;
}

.cal-wkrow > div.we { color: var(--ink-4); }

.cal-grid {
  grid-template-columns: repeat(7, 1fr);
  grid-auto-rows: minmax(120px, auto);
  align-content: start;
  display: grid;
}

.cal-cell {
  border-right: 1px solid var(--line-soft);
  border-bottom: 1px solid var(--line-soft);
  cursor: pointer;
  flex-direction: column;
  gap: 4px;
  padding: 8px 10px;
  display: flex;
  position: relative;
}

.cal-cell:nth-child(7n) { border-right: 0; }
.cal-cell:hover { background: var(--hover); }
.cal-cell.dim { background: var(--surface-2); }
.cal-cell.dim .d { color: var(--ink-4); }

.cal-cell .d {
  font-family: var(--font-num);
  color: var(--ink-2);
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 500;
  display: inline-flex;
}

.cal-cell.today .d {
  color: var(--brand-ink);
  background: var(--brand);
  border-radius: 999px;
  justify-content: center;
  width: 22px;
  height: 22px;
  font-weight: 600;
}

.cal-cell.we .d { color: var(--ink-3); }

.cal-evts {
  flex-direction: column;
  gap: 3px;
  margin-top: 2px;
  display: flex;
}

.cal-evt {
  color: var(--ink-2);
  background: var(--surface-2);
  border-left: 2px solid var(--muted);
  text-overflow: ellipsis;
  white-space: nowrap;
  border-radius: 4px;
  flex-shrink: 0;
  align-items: center;
  gap: 6px;
  padding: 4px 6px;
  font-size: 11.5px;
  line-height: 1.5;
  display: flex;
  overflow: hidden;
}

.cal-evt.danger { border-left-color: var(--danger); background: var(--danger-soft); color: var(--danger); }
.cal-evt.warn { border-left-color: var(--warn); background: var(--warn-soft); color: var(--warn); }
.cal-evt.brand { border-left-color: var(--brand); background: var(--brand-soft); color: var(--brand); }
.cal-evt.info { border-left-color: var(--info); background: var(--info-soft); color: var(--info); }

.cal-evt .name { text-overflow: ellipsis; overflow: hidden; }

.cal-more {
  color: var(--ink-3);
  margin-top: 1px;
  padding-left: 2px;
  font-size: 10.5px;
}

/* ---------- Month Plan View ---------- */
.month-plan-view {
  background: var(--bg);
  flex-direction: column;
  flex: 1;
  min-width: 0;
  height: 100%;
  padding-top: 24px;
  display: flex;
  overflow: auto;
}

.mp-projects {
  display: flex;
  gap: 16px;
  padding: 0 0 16px;
  overflow-x: auto;
}

.mp-calendar {
  margin-top: 16px;
}

/* ---------- Toast ---------- */
.toast {
  background: var(--ink-1);
  color: var(--bg);
  border-radius: var(--r-md);
  z-index: 200;
  padding: 10px 18px;
  font-size: 13px;
  font-weight: 500;
  position: fixed;
  bottom: 32px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  opacity: 0;
  transition: transform .3s var(--ease), opacity .3s var(--ease);
  pointer-events: none;
  box-shadow: 0 4px 16px #00000020;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

/* ---------- Utility ---------- */
.drag-over {
  outline: 2px dashed var(--brand);
  outline-offset: -2px;
  border-radius: var(--r-md);
}

/* ---------- Responsive ---------- */
@media (max-width: 1024px) {
  .app { grid-template-columns: 200px 1fr; }
  .kanban { grid-template-columns: repeat(2, 1fr); }
  .matrix { grid-template-columns: 20px 1fr 1fr; }
  .overview { grid-template-columns: repeat(3, 1fr); }
  .topbar { padding: 0 16px; }
  .content { padding: 16px; }
}

@media (max-width: 768px) {
  .app { grid-template-columns: 1fr; }
  .side { display: none; }
  .topbar {
    min-height: 56px;
    height: auto;
    flex-wrap: wrap;
    align-content: center;
    gap: 8px;
    padding: calc(8px + env(safe-area-inset-top)) 12px 8px;
  }
  .crumb {
    order: 1;
    flex: 1 1 auto;
    min-width: 0;
  }
  .crumb h1 {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 15px;
  }
  .icon-btn {
    order: 2;
    width: 44px;
    height: 44px;
  }
  .tagfilter-wrapper {
    order: 3;
    flex: 0 0 auto;
  }
  .tagfilter-trigger {
    min-height: 44px;
  }
  .search {
    order: 4;
    flex: 1 1 150px;
    width: auto;
    min-width: 0;
    margin-left: 0;
    min-height: 44px;
  }
  .mobile-view-nav {
    grid-row: 2;
    min-width: 0;
    align-items: center;
    gap: 6px;
    padding: 4px 12px;
    background: var(--surface);
    border-bottom: 1px solid var(--line-soft);
    display: flex;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .mobile-view-nav::-webkit-scrollbar { display: none; }
  .mobile-view-nav button {
    flex: 0 0 auto;
    min-height: 44px;
    padding: 0 14px;
    border-radius: var(--r-md);
    color: var(--ink-3);
    white-space: nowrap;
    font-size: 13px;
    font-weight: 600;
  }
  .mobile-view-nav button.active {
    background: var(--brand-soft);
    color: var(--brand);
  }
  .mobile-view-nav .mobile-add-btn {
    align-items: center;
    gap: 5px;
    background: var(--brand);
    color: var(--brand-ink);
    display: inline-flex;
    font-weight: 700;
  }
  .mobile-add-btn svg { width: 15px; height: 15px; }
  .content {
    grid-row: 3;
    padding: 12px 12px calc(20px + env(safe-area-inset-bottom));
  }
  .kanban { grid-template-columns: 1fr; }
  .matrix { grid-template-columns: 1fr; grid-template-rows: auto; gap: 8px; }
  .quad.q1, .quad.q2, .quad.q3, .quad.q4 { grid-area: auto; }
  .mx-axis-x, .mx-axis-y { display: none; }
  .overview { grid-template-columns: repeat(2, 1fr); }

  .modal-overlay { padding: 12px; }
  .modal {
    width: min(520px, calc(100vw - 24px));
    max-width: 100%;
    max-height: calc(100dvh - 24px);
  }
  .modal-body { padding: 16px; }
  .field-row { flex-direction: column; gap: 12px; }
  .seg { flex-wrap: wrap; }
  .seg button, .parent-chip { min-height: 40px; }
  .modal-foot {
    padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  }
  .modal-foot .actions .btn,
  #btnDeleteTodo { min-height: 44px; }
  .toast { bottom: calc(20px + env(safe-area-inset-bottom)); }
}

/* ---------- Auth Pages ---------- */
.auth-page {
  align-items: center;
  justify-content: center;
  height: 100vh;
  min-height: 100dvh;
  width: 100%;
  padding: env(safe-area-inset-top) 12px env(safe-area-inset-bottom);
  display: flex;
  background: var(--bg);
}

.auth-card {
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: var(--r-xl);
  width: 380px;
  max-width: 90vw;
  padding: 36px 32px;
  box-shadow: 0 1px 2px #0000000a, 0 8px 32px #0000000a;
}

.auth-brand {
  align-items: center;
  gap: 12px;
  margin-bottom: 28px;
  display: flex;
}

.auth-brand .logo {
  background: var(--brand);
  width: 40px;
  height: 40px;
  color: var(--brand-ink);
  border-radius: 10px;
  place-items: center;
  font-size: 18px;
  font-weight: 700;
  display: grid;
  flex-shrink: 0;
}

.auth-brand .wm {
  color: var(--ink-1);
  letter-spacing: -.01em;
  font-size: 18px;
  font-weight: 600;
}

.auth-brand .wm small {
  color: var(--ink-3);
  margin-top: 2px;
  font-size: 12px;
  font-weight: 500;
  display: block;
}

.auth-form {
  flex-direction: column;
  gap: 16px;
  display: flex;
}

.auth-field {
  flex-direction: column;
  gap: 6px;
  display: flex;
}

.auth-field label {
  color: var(--ink-3);
  letter-spacing: .04em;
  font-size: 12px;
  font-weight: 500;
}

.auth-field input {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  color: var(--ink-1);
  padding: 10px 12px;
  font-size: 14px;
  outline: none;
  transition: border-color .15s;
}

.auth-field input:focus {
  border-color: var(--brand);
}

.auth-error {
  color: var(--danger);
  font-size: 13px;
  min-height: 18px;
}

.auth-btn {
  background: var(--brand);
  color: var(--brand-ink);
  border-radius: var(--r-md);
  height: 40px;
  font-size: 14px;
  font-weight: 600;
  transition: background .15s;
  margin-top: 4px;
}

.auth-btn:hover { background: #243729; }
.dark .auth-btn:hover { background: #3a5e48; }

.auth-switch {
  color: var(--ink-3);
  text-align: center;
  font-size: 13px;
  margin-top: 4px;
}

.auth-switch a {
  color: var(--brand);
  font-weight: 500;
}

.dark .auth-switch a { color: #4a7c5c; }

/* ---------- Sidebar User Info ---------- */
.side-user {
  align-items: center;
  gap: 10px;
  padding: 8px 6px;
  display: flex;
}

.user-avatar {
  background: var(--brand);
  color: var(--brand-ink);
  border-radius: 999px;
  width: 30px;
  height: 30px;
  place-items: center;
  font-size: 12px;
  font-weight: 600;
  display: grid;
  flex-shrink: 0;
}

.user-meta {
  flex: 1;
  min-width: 0;
}

.user-name {
  color: var(--ink-1);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-phone {
  color: var(--ink-3);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.logout-btn {
  border-radius: var(--r-sm);
  width: 28px;
  height: 28px;
  color: var(--ink-3);
  place-items: center;
  transition: background .12s, color .12s;
  display: grid;
  flex-shrink: 0;
}

.logout-btn:hover {
  background: var(--danger-soft);
  color: var(--danger);
}

.logout-btn svg {
  stroke-width: 1.8px;
  width: 15px;
  height: 15px;
}

@media (max-width: 768px) {
  .auth-card {
    width: 100%;
    max-width: 380px;
    padding: 28px 22px;
  }
}
