/* ============================================================
 * 待办事项跟进 — Styles (light theme, accessible, responsive)
 * ============================================================ */
:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e3e8ef;
  --text: #1f2937;
  --text-2: #64748b;
  --muted: #94a3b8;
  --accent: #4f46e5;
  --accent-soft: #eef2ff;
  --danger: #dc2626;
  --shadow: 0 1px 3px rgba(15, 23, 42, .08), 0 8px 24px rgba(15, 23, 42, .06);
  --radius: 12px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}
button { font-family: inherit; cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}

/* ---------- Top bar ---------- */
.topbar {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
.brand { font-weight: 700; font-size: 17px; display: flex; align-items: center; gap: 8px; }
.brand .logo {
  width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center;
  background: linear-gradient(135deg, #6366f1, #4f46e5); color: #fff; font-size: 16px;
}
.brand small { font-weight: 500; color: var(--text-2); font-size: 12px; }
.topbar .spacer { flex: 1; }

.period { display: flex; align-items: center; gap: 6px; }
.period #periodLabel { font-weight: 600; min-width: 150px; text-align: center; }

.view-tabs { display: flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 3px; }
.view-tabs button {
  border: none; background: transparent; padding: 6px 14px; border-radius: 8px;
  color: var(--text-2); font-weight: 600; font-size: 13px;
}
.view-tabs button.active { background: var(--surface); color: var(--accent); box-shadow: var(--shadow); }

.btn-primary {
  background: var(--accent); color: #fff; border: none; padding: 8px 16px; border-radius: 9px;
  font-weight: 600; font-size: 13px; display: inline-flex; align-items: center; gap: 6px;
}
.btn-primary:hover { filter: brightness(1.05); }
#btnNotify {
  width: 36px; height: 36px; border: 1px solid var(--border); background: var(--surface);
  border-radius: 9px; font-size: 16px;
}
#btnNotify.on { background: var(--accent-soft); border-color: var(--accent); }
#btnMenu {
  width: 36px; height: 36px; border: 1px solid var(--border); background: var(--surface);
  border-radius: 9px; font-size: 18px; position: relative;
}
.menu {
  position: absolute; top: 46px; right: 16px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; box-shadow: var(--shadow); padding: 6px; min-width: 170px; display: none; z-index: 30;
}
.menu button { display: block; width: 100%; text-align: left; padding: 9px 12px; border: none; background: none; border-radius: 7px; color: var(--text); font-size: 13px; }
.menu button:hover { background: var(--surface-2); }
.menu .danger { color: var(--danger); }

.history-badge {
  display: none; font-size: 11px; color: var(--muted); border: 1px solid var(--border);
  padding: 2px 8px; border-radius: 20px; background: var(--surface-2);
}

/* ---------- Layout ---------- */
.layout {
  display: flex;
  align-items: stretch;
  min-height: calc(100vh - 56px);
}

/* ---------- Sidebar ---------- */
.sidebar {
  background: var(--surface); border-right: 1px solid var(--border);
  padding: 16px; position: sticky; top: 56px; height: calc(100vh - 56px);
  overflow-x: hidden; overflow-y: auto;
  width: 248px;
  flex-shrink: 0;
  opacity: 1;
  transition: width .28s cubic-bezier(.4, 0, .2, 1), padding .28s ease, opacity .2s ease;
}
.layout.collapsed .sidebar {
  width: 0;
  padding-left: 0;
  padding-right: 0;
  border-right-color: transparent;
  opacity: 0;
}
.sidebar h4 { margin: 0 0 4px; font-size: 12px; letter-spacing: .04em; color: var(--text-2); text-transform: uppercase; }

/* Sidebar toggle button (topbar) — substantial, icon-style with hover lift */
.sidebar-toggle-btn {
  width: 40px; height: 40px; border: 1px solid var(--border); background: var(--surface);
  border-radius: 12px; color: var(--text-2); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background .18s, color .18s, border-color .18s, transform .15s, box-shadow .18s;
  box-shadow: 0 1px 3px rgba(15,23,42,.06);
  flex: none;
}
.sidebar-toggle-btn:hover {
  background: linear-gradient(135deg, #eef2ff, #e0e7ff);
  color: var(--accent); border-color: var(--accent);
  transform: translateY(-1px) scale(1.06);
  box-shadow: 0 4px 12px rgba(79,70,229,.28);
}
.sidebar-toggle-btn:active {
  transform: translateY(0) scale(0.95);
  background: var(--accent); color: white;
  box-shadow: 0 2px 4px rgba(79,70,229,.3) inset;
}
.sidebar-toggle-btn svg { transition: stroke-width .15s; }
.sidebar-toggle-btn:hover svg { stroke-width: 2.6; }
/* Chevron icon direction is swapped via JS path's "d" attribute (applySidebarState).
   CSS transform on <svg>/<path> is unreliable across browsers for SVG icon swap. */

/* Nav arrows (prev/next) — round, substantial */
.nav-arrow {
  width: 32px; height: 32px; border: 1px solid var(--border); background: var(--surface);
  border-radius: 50%; color: var(--text-2); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s, color .15s, border-color .15s;
  box-shadow: 0 1px 2px rgba(15,23,42,.04);
}
.nav-arrow:hover { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }
.nav-arrow:active { background: var(--accent); color: white; }

/* Today button — pill, accent */
.today-btn {
  padding: 6px 14px; border: 1px solid var(--accent); background: var(--accent-soft);
  color: var(--accent); border-radius: 999px; font-weight: 600; font-size: 13px;
  cursor: pointer; transition: background .15s, color .15s;
}
.today-btn:hover { background: var(--accent); color: white; }
.filter-block { margin-bottom: 14px; }
.filter-block > label { display: block; font-size: 12px; font-weight: 600; color: var(--text-2); margin-bottom: 5px; }
.filter-block input, .filter-block select {
  width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--text); font-size: 13px;
}
.custom-range { display: flex; align-items: center; gap: 6px; margin-top: 6px; }
.custom-range input { flex: 1; min-width: 0; }
.custom-range span { color: var(--muted); }
.reset {
  width: 100%; padding: 8px; border: 1px dashed var(--border); background: var(--surface-2);
  border-radius: 8px; color: var(--text-2); font-weight: 600; font-size: 13px;
}
.reset:hover { border-color: var(--accent); color: var(--accent); }

/* ---------- Content ---------- */
.content { padding: 16px 20px 40px; flex: 1; min-width: 0; }

/* Banner */
#banner {
  display: none; align-items: center; gap: 10px; margin-bottom: 14px;
  background: linear-gradient(135deg, #eef2ff, #faf5ff); border: 1px solid #e0e7ff;
  padding: 10px 16px; border-radius: 12px; font-size: 13px; color: #3730a3;
}
#banner .bell { font-size: 16px; }
#banner b { color: var(--accent); }
#banner .link { margin-left: auto; background: none; border: none; color: var(--accent); font-weight: 700; }
.banner-view-btn {
  margin-left: auto; flex: none;
  padding: 5px 12px; border-radius: 8px; border: none;
  background: #4c1d95; color: #fff; font-size: 12px; font-weight: 600;
  cursor: pointer; transition: background .15s;
}
.banner-view-btn:hover { background: #5b21b6; }

/* ---------- Month view ---------- */
.month-head, .month-grid { display: grid; grid-template-columns: repeat(7, 1fr); }
.month-head { background: var(--surface); border: 1px solid var(--border); border-bottom: none; border-radius: 12px 12px 0 0; }
.month-head .wd { text-align: center; padding: 8px 0; font-weight: 700; font-size: 12px; color: var(--text-2); }
.month-grid {
  background: var(--border); gap: 1px; border: 1px solid var(--border); border-radius: 0 0 12px 12px; overflow: hidden;
}
.month.historical { opacity: .55; filter: grayscale(.6); }
.day {
  background: var(--surface); min-height: 104px; padding: 6px; display: flex; flex-direction: column; gap: 4px;
  cursor: pointer; transition: background .15s;
}
.day:hover { background: var(--surface-2); }
.day.muted { background: var(--surface-2); }
.day.today { background: #fffbeb; box-shadow: inset 0 0 0 2px #fbbf24; }
.day-head { display: flex; justify-content: space-between; align-items: center; }
.day-num { font-weight: 700; font-size: 13px; }
.day-head.weekend .day-num { color: var(--danger); }
.day.today .day-num { color: #b45309; }
.day-list { display: flex; flex-direction: column; gap: 3px; }
.chip {
  display: flex; align-items: center; gap: 5px; text-align: left; border: none; background: var(--surface-2);
  border-left: 3px solid var(--muted); border-radius: 6px; padding: 3px 6px; font-size: 12px; color: var(--text);
  width: 100%; overflow: hidden;
}
.chip:hover { background: #eef2ff; }
.chip.done { opacity: .55; text-decoration: line-through; }
.chip-title {
  white-space: normal; overflow: hidden; text-overflow: ellipsis;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical;
  word-break: break-word;
}
.more { background: none; border: none; color: var(--accent); font-size: 11px; padding: 2px 4px; text-align: left; font-weight: 600; }

/* Week strip — wraps inside the calendar grid (month view) as its own row.
   `grid-column: 1/-1` lives on the wrapper so the strip itself never stretches
   to fill a day-cell row. The strip's negative margin-bottom covers the grid's
   1px gap so no gray seam shows between the strip and the day cells. */
.week-strip-wrap {
  grid-column: 1 / -1;
  display: block;
}
.week-strip {
  display: flex; align-items: center; gap: 8px; padding: 10px 14px; margin-bottom: -1px;
  background: linear-gradient(135deg, #dbeafe, #eef2ff);
  border: 1px solid #7dd3fc; border-radius: 10px; flex-wrap: wrap;
  box-shadow: none;
}
.ws-label { font-size: 13px; font-weight: 700; color: #0369a1; white-space: nowrap; }
.ws-item {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 12px; background: #fff; border-left: 3px solid var(--muted); border-radius: 6px;
  padding: 3px 10px; color: var(--text); cursor: pointer;
  max-width: 100%;
  white-space: nowrap;
}
.ws-item .ws-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.ws-item .ws-sep { color: var(--muted); flex: none; }
.ws-item .ws-details { color: var(--text-2); overflow: hidden; text-overflow: ellipsis; flex: 0 1 auto; min-width: 0; }
.ws-item:hover { background: #e0f2fe; }
.ws-item.done { opacity: .5; text-decoration: line-through; }

/* month-only strip (floats above current month) — light purple, no shadow */
.month-strip {
  display: flex; align-items: center; gap: 8px; padding: 10px 14px; margin-bottom: 10px;
  background: linear-gradient(135deg, #f3e8ff, #faf5ff);
  border: 1px solid #d8b4fe; border-radius: 10px; flex-wrap: wrap;
  box-shadow: none;
}
.ms-label { font-size: 13px; font-weight: 700; color: #7e22ce; white-space: nowrap; }
.ms-item {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 12px; background: #fff; border-left: 3px solid var(--muted); border-radius: 6px;
  padding: 3px 10px; color: var(--text); cursor: pointer;
  max-width: 100%;
  white-space: nowrap;
}
.ms-item .ms-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.ms-item .ms-sep { color: var(--muted); flex: none; }
.ms-item .ms-details { color: var(--text-2); overflow: hidden; text-overflow: ellipsis; flex: 0 1 auto; min-width: 0; }
.ms-item:hover { background: #f3e8ff; }
.ms-item.done { opacity: .5; text-decoration: line-through; }

/* ---------- Week view ---------- */
.week { background: var(--border); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; display: grid; grid-template-columns: repeat(7, 1fr); gap: 1px; }
.week-head { display: contents; }
.week-strip.wide { grid-column: 1 / -1; background: linear-gradient(135deg, #dbeafe, #eef2ff); display: flex; gap: 8px; padding: 6px 10px; align-items: center; flex-wrap: wrap; box-shadow: none; }
.wcol { background: var(--surface); min-height: 70vh; display: flex; flex-direction: column; cursor: pointer; }
.wcol:hover { background: var(--surface-2); }
.wcol.today { background: #fffbeb; }
.wcol-head { display: flex; flex-direction: column; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--border); font-weight: 700; }
.wcol-head .dn { font-size: 11px; color: var(--text-2); font-weight: 500; }
.wcol-list { padding: 6px; display: flex; flex-direction: column; gap: 4px; }

/* Week view compact one-line item */
.wk-item {
  display: flex; align-items: baseline; gap: 4px; flex-wrap: wrap;
  padding: 6px 8px; border-left: 3px solid var(--muted);
  background: var(--surface-2); border-radius: 6px;
  font-size: 12px; cursor: pointer; overflow: visible;
  word-break: break-word;
}
.wk-item:hover { background: var(--surface); border-color: var(--accent); }
.wk-item.done { opacity: .55; text-decoration: line-through; }
.wk-item .wk-title { font-weight: 600; color: var(--text); flex: 0 1 auto; min-width: 0; }
.wk-item .wk-details { color: var(--text-2); flex: 1 1 auto; min-width: 0; }
.wk-item .wk-owner { color: var(--text-2); flex: 0 1 auto; }
.wk-item .wk-time { color: var(--accent); font-weight: 600; flex: 0 0 auto; }
.wk-item .wk-sep { color: var(--muted); padding: 0 2px; flex: 0 0 auto; }

/* ---------- Day view ---------- */
.dayview { max-width: 720px; margin: 0 auto; }
.dv-title { font-size: 16px; font-weight: 700; margin-bottom: 12px; }
.dv-row { display: flex; align-items: center; gap: 8px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 10px 14px; margin-bottom: 8px; cursor: pointer; }
.dv-row:hover { border-color: var(--accent); }
.dv-row.done { opacity: .55; }
.dv-row.done b { text-decoration: line-through; }
.dv-row .muted { color: var(--text-2); font-size: 12px; }

/* Day view full info card */
.day-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 12px 14px; margin-bottom: 10px; cursor: pointer;
  border-left: 3px solid var(--muted);
  box-shadow: 0 1px 2px rgba(15,23,42,.04);
  transition: box-shadow .15s, border-color .15s;
}
.day-card:hover { border-color: var(--accent); box-shadow: 0 2px 8px rgba(15,23,42,.08); }
.day-card.done { opacity: .55; }
.day-card.done .dc-title { text-decoration: line-through; color: var(--muted); }
.dc-head { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.dc-status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); flex: none; }
.dc-title { font-size: 16px; font-weight: 700; color: var(--text); }
.dc-details {
  background: linear-gradient(135deg, #eef2ff, #faf5ff);
  border: 1px solid #e0e7ff; border-radius: 8px;
  padding: 8px 12px; margin: 8px 0;
  font-size: 14px; color: var(--accent); font-weight: 500; line-height: 1.5;
}
.dc-meta { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-2); flex-wrap: wrap; }
.dc-meta .pill, .dc-meta .cat, .dc-meta .dot { flex: none; }
.dc-sep { color: var(--muted); padding: 0 2px; }
.dc-owner, .dc-time { font-weight: 500; }
.dc-time { color: var(--accent); }
.dc-status-label { font-weight: 500; }
.dc-remark { font-size: 12px; color: var(--text-2); margin-top: 6px; padding-top: 6px; border-top: 1px dashed var(--border); }
.dc-cf-list { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 6px; }
.dc-cf { font-size: 11px; background: var(--surface-2); border-radius: 4px; padding: 2px 6px; }
.dc-cf-k { color: var(--text-2); margin-right: 4px; }
.dc-cf-v { color: var(--text); font-weight: 600; }

/* ---------- Hover tooltip (popover) ---------- */
.task-tip {
  position: fixed; z-index: 300;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 4px 16px rgba(15,23,42,.15), 0 2px 4px rgba(15,23,42,.08);
  padding: 10px 12px; max-width: 320px;
  font-size: 12px; color: var(--text); line-height: 1.5;
  pointer-events: none;
}
.task-tip .tt-title { font-size: 13px; font-weight: 700; margin-bottom: 4px; }
.task-tip .tt-details {
  background: #f5f7fb; border-radius: 6px; padding: 4px 8px; margin: 4px 0;
  font-size: 12px; color: var(--text);
}
.task-tip .tt-row { display: flex; align-items: center; gap: 5px; margin: 3px 0; flex-wrap: wrap; font-size: 11px; color: var(--text-2); }
.task-tip .tt-row .tt-key { color: var(--muted); margin-right: 3px; }
.task-tip .tt-row .tt-val { color: var(--text); }
.task-tip .tt-remark { font-size: 11px; color: var(--text-2); margin-top: 4px; padding-top: 4px; border-top: 1px dashed var(--border); }
.task-tip .tt-cf-list { margin-top: 4px; padding-top: 4px; border-top: 1px dashed var(--border); }
.task-tip .tt-cf { display: flex; gap: 4px; font-size: 11px; color: var(--text-2); }
.task-tip .tt-cf .tt-key { color: var(--muted); }
.task-tip .tt-cf .tt-val { color: var(--text); font-weight: 600; }

.add-day { width: 100%; padding: 10px; border: 1px dashed var(--border); background: var(--surface-2); border-radius: 10px; color: var(--accent); font-weight: 600; }
.empty { text-align: center; color: var(--muted); padding: 40px 0; }

/* ---------- List view ---------- */
.stats { display: flex; gap: 18px; margin-bottom: 12px; font-size: 13px; color: var(--text-2); }
.stats b { color: var(--text); }
.list-toolbar {
  display: flex; align-items: center; gap: 12px; margin-bottom: 10px;
  flex-wrap: wrap; position: relative;
}
.edit-toggle {
  padding: 7px 14px; border: 1px solid var(--border); background: var(--surface);
  border-radius: 8px; font-size: 13px; font-weight: 600; color: var(--text);
  cursor: pointer; display: inline-flex; align-items: center; gap: 6px;
  transition: all .15s;
}
.edit-toggle:hover { border-color: var(--accent); color: var(--accent); }
.edit-toggle.on { background: var(--accent); color: white; border-color: var(--accent); }
.edit-toggle.danger { color: var(--danger); border-color: #fecaca; }
.edit-toggle.danger:not(:disabled):hover { background: #fef2f2; border-color: var(--danger); }
.edit-toggle:disabled { opacity: .5; cursor: not-allowed; }
.edit-arrow { font-size: 14px; }

/* List view batch selection column */
.c-select { justify-content: center; }
.c-select input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; }

/* Visibility quick chips — always accessible in toolbar */
.vis-quick { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; flex: 1; }
.vis-quick .vq-label { font-size: 12px; color: var(--muted); margin-right: 2px; }
.vis-quick .vq-chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 10px; border: 1px solid var(--border); background: var(--surface);
  border-radius: 999px; font-size: 12px; color: var(--text-2); cursor: pointer;
  user-select: none;
}
.vis-quick .vq-chip:hover { border-color: var(--accent); color: var(--accent); }
.vis-quick .vq-chip.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.vis-quick .vq-chip input[type="checkbox"] { display: none; }

.table-wrap {
  overflow-x: auto; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  max-height: calc(100vh - 280px);
  min-height: 200px;
}
.table-wrap.edit-mode { outline: 2px dashed var(--accent); outline-offset: -2px; background: var(--accent-soft); }
.table { display: block; }
.th-cell {
  position: relative; user-select: none;
  display: inline-flex; align-items: center; gap: 4px;
  padding: 12px 14px; font-weight: 700; font-size: 12px; color: var(--text-2);
  background: var(--surface-2); border-bottom: 1px solid var(--border);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  border-right: 1px solid var(--border);
  flex-shrink: 0;
}
.th-cell .th-label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.th-cell.sortable { cursor: pointer; }
.th-cell.sortable:hover { background: #e0e7ff; color: var(--accent); }
.th-cell.sorted { color: var(--accent); background: #eef2ff; }
.th-cell.sorted .th-sort { color: var(--accent); }
.th-sort { flex: none; font-size: 10px; color: var(--muted); line-height: 1; }
.th-cell.draggable { cursor: grab; }
.th-cell.draggable:hover { background: var(--accent); color: white; }
.th-cell.dragging { opacity: .5; }
.th-cell.drop-target { box-shadow: inset -2px 0 0 var(--accent); }
.col-resize {
  position: absolute; right: -3px; top: 0; bottom: 0; width: 6px; cursor: col-resize;
  z-index: 2;
}
.col-resize:hover { background: var(--accent); opacity: .35; }

.td-cell {
  padding: 12px 14px; font-size: 13px; color: var(--text);
  border-bottom: 1px solid var(--border); border-right: 1px solid var(--border);
  display: inline-flex; align-items: center;
  flex-shrink: 0;
}
.td-cell .td-inner {
  display: block; width: 100%;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.tr.th { display: flex; position: sticky; top: 0; z-index: 5; background: var(--surface-2); border-bottom: 1px solid var(--border); }
.tr { display: flex; align-items: stretch; }
.tr:not(.th):hover { background: var(--surface-2); }
.tr.done .td-cell { opacity: .55; text-decoration: line-through; color: var(--muted); }
.tr { cursor: pointer; }
/* Lock list column widths so header row and data rows always stay in sync */
.th-cell, .td-cell { flex: 0 0 auto; box-sizing: border-box; }
.c-act { text-align: right; }
.mini { border: 1px solid var(--border); background: var(--surface); border-radius: 7px; padding: 4px 10px; font-size: 12px; color: var(--accent); font-weight: 600; }

/* ---------- Pills / dots / tags ---------- */
.pill { font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 20px; border: 1px solid; line-height: 1.6; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; flex: none; }
.cat { font-size: 11px; font-weight: 600; padding: 1px 8px; border-radius: 6px; }

/* ---------- Modal ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(15, 23, 42, .45); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { background: var(--surface); border-radius: 16px; box-shadow: var(--shadow); width: 100%; max-width: 780px; max-height: 90vh; overflow-y: auto; padding: 22px 26px; }
.modal.action-modal { max-width: 560px; overflow: visible; }
.action-dialog h2 { margin: 0 0 10px; text-align: center; font-size: 20px; color: var(--text); }
.action-dialog-message { margin: 0 0 20px; text-align: center; color: var(--text-2); line-height: 1.6; }
.action-dialog > label { display: block; margin: 0 0 7px; color: var(--text-2); font-size: 13px; font-weight: 700; }
.action-dialog textarea {
  display: block; width: 100%; min-height: 140px; resize: vertical; box-sizing: border-box;
  padding: 12px 14px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface); color: var(--text); font: inherit; font-size: 15px; line-height: 1.6;
}
.action-dialog textarea:focus { outline: 3px solid rgba(79, 70, 229, .15); border-color: var(--accent); }
.action-dialog-actions { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin-top: 22px; }
.action-dialog-actions.two-actions { grid-template-columns: repeat(2, minmax(0, 1fr)); max-width: 360px; margin-left: auto; margin-right: auto; }
.action-dialog-actions button {
  min-width: 0; min-height: 42px; padding: 9px 14px; border: 1px solid var(--border); border-radius: 9px;
  background: var(--surface); color: var(--text); font-size: 14px; font-weight: 700; cursor: pointer; white-space: nowrap;
}
.action-dialog-actions button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.action-dialog-actions button.danger { background: #fff5f5; border-color: #fecaca; color: var(--danger); }
.action-dialog-actions button:hover { border-color: var(--accent); }
.form h3, .detail h3 { margin: 0 0 16px; font-size: 18px; }
.field { margin-bottom: 14px; }
.field > label { display: block; font-size: 12px; font-weight: 700; color: var(--text-2); margin-bottom: 5px; }
.field input:not([type="checkbox"]):not([type="radio"]), .field textarea, .field select {
  width: 100%; padding: 9px 11px; border: 1px solid var(--border); border-radius: 9px; font-size: 13px; background: var(--surface); color: var(--text); font-family: inherit;
}
.field select {
  -webkit-appearance: none;
  appearance: none;
  padding-right: 36px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 11px center;
  background-size: 14px 14px;
}
.field textarea { resize: vertical; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.seg { display: flex; gap: 14px; margin-bottom: 8px; flex-wrap: wrap; }
.seg label { font-size: 13px; display: inline-flex; align-items: center; gap: 5px; cursor: pointer; white-space: nowrap; }
.seg input[type="radio"],
#recurrenceArea input[type="checkbox"] {
  -webkit-appearance: auto;
  appearance: auto;
  width: 20px;
  height: 20px;
  min-width: 20px;
  min-height: 20px;
  margin: 0;
  padding: 0;
  flex: 0 0 20px;
  accent-color: var(--accent);
}
.when-box { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.when-box input[type="date"], .when-box input[type="time"], .when-box input[type="week"], .when-box input[type="month"] { flex: 1; min-width: 140px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; font-size: 13px; }
.hint { font-size: 11px; color: var(--muted); }

/* Repeat / range sub-form (in task editor) */
.repeat-row {
  display: flex; gap: 10px; align-items: center;
  flex-wrap: wrap; row-gap: 8px;
  padding: 10px 12px; border: 1px solid var(--border);
  border-radius: 10px; background: var(--surface-2);
  width: 100%; box-sizing: border-box;
}
.repeat-row .repeat-label {
  font-size: 13px; font-weight: 700; color: var(--text-2);
  white-space: nowrap;
}
.repeat-row select#f_repeatRule,
.repeat-row input#f_repeatEnd {
  width: 140px; min-width: 140px; max-width: 160px;
  padding: 8px 10px; border: 1px solid var(--border);
  border-radius: 8px; font-size: 13px;
  background: var(--surface); color: var(--text);
}
.repeat-row #customIntervalBox {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 13px; color: var(--text-2);
}
.repeat-row #f_repeatInterval { width: 64px; padding: 6px 8px; }
.repeat-row .range-sep {
  font-size: 12px; color: var(--muted); padding: 0 4px;
}
.repeat-empty {
  width: 100%;
  margin-top: 4px;
  font-size: 12px;
  color: var(--danger);
  font-weight: 600;
}
.range-row {
  display: flex; gap: 10px; align-items: center; flex-wrap: wrap;
  padding: 10px 12px; border: 1px solid var(--border);
  border-radius: 10px; background: var(--surface-2);
  width: 100%; box-sizing: border-box;
}
.range-row .repeat-label { font-size: 13px; font-weight: 700; color: var(--text-2); white-space: nowrap; }
.range-row input[type="date"] {
  width: 160px; min-width: 140px;
  padding: 8px 10px; border: 1px solid var(--border);
  border-radius: 8px; font-size: 13px;
  background: var(--surface); color: var(--text);
}
.range-row .hint { font-size: 11px; color: var(--muted); width: 100%; }
.form-actions { display: flex; align-items: center; gap: 8px; margin-top: 18px; }
.form-actions .spacer { flex: 1; }
.form-actions button { padding: 9px 16px; border-radius: 9px; font-weight: 600; font-size: 13px; border: 1px solid var(--border); background: var(--surface); color: var(--text); }
.form-actions .primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.form-actions .danger { color: var(--danger); border-color: #fecaca; }

/* custom field entries in form */
.cf-row { display: flex; gap: 8px; align-items: center; margin-bottom: 6px; }
.cf-row input { flex: 1; padding: 7px 9px; border: 1px solid var(--border); border-radius: 8px; font-size: 13px; }
.cf-row .cf-del { flex: none; width: 32px; height: 32px; padding: 0; }

/* ---------- Multi-select dropdown ---------- */
.multiselect { position: relative; }
.ms-toggle {
  width: 100%; display: flex; align-items: center; justify-content: space-between;
  padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--text); font-size: 13px; cursor: pointer;
}
.ms-toggle:hover, .ms-toggle.open { border-color: var(--accent); }
.ms-toggle .ms-arrow { font-size: 10px; color: var(--text-2); transition: transform .2s; }
.ms-toggle.open .ms-arrow { transform: rotate(180deg); }
.ms-panel {
  position: absolute; top: 100%; left: 0; z-index: 100;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: var(--shadow); display: flex; flex-direction: column;
  margin-top: 2px;
  /* Width adapts to content; constrained by viewport */
  min-width: 100%;
  width: max-content;
  max-width: calc(100vw - 32px);
}
.ms-actions {
  display: flex; gap: 6px; padding: 8px 10px; border-bottom: 1px solid var(--border);
}
.ms-actions button {
  flex: 1; padding: 5px 8px; border: 1px solid var(--border); background: var(--surface-2);
  border-radius: 6px; font-size: 12px; font-weight: 600; color: var(--text-2); cursor: pointer;
}
.ms-actions button:hover { border-color: var(--accent); color: var(--accent); }
.ms-actions button:disabled { opacity: .4; cursor: default; pointer-events: none; }
.ms-options {
  overflow-y: auto; overflow-x: auto; padding: 6px 8px; flex: 1;
  max-height: 240px;
}
.ms-opt {
  display: flex; align-items: center; gap: 6px; padding: 5px 6px; border-radius: 6px;
  cursor: pointer; font-size: 13px;
  word-break: break-word; overflow-wrap: anywhere;
}
.ms-opt:hover { background: var(--surface-2); }
.ms-opt input[type="checkbox"] { width: 15px; height: 15px; accent-color: var(--accent); cursor: pointer; flex: none; }
.ms-opt > span:not(.ms-only-btn) { word-break: break-word; overflow-wrap: anywhere; flex: 1 1 auto; min-width: 0; }
.ms-opt .ms-only-btn {
  margin-left: auto; width: 22px; height: 22px; border: none; background: none;
  font-size: 14px; color: var(--muted); cursor: pointer; border-radius: 4px;
  display: flex; align-items: center; justify-content: center; flex: none;
}
.ms-opt .ms-only-btn:hover { background: var(--surface-2); color: var(--accent); }
.ms-empty { font-size: 12px; color: var(--muted); text-align: center; padding: 12px; }

/* Context menu for "仅筛选此选项" */
.ms-context {
  position: fixed; z-index: 200; background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; box-shadow: var(--shadow); padding: 4px; min-width: 130px;
}
.ms-context button {
  display: block; width: 100%; text-align: left; padding: 7px 12px; border: none;
  background: none; border-radius: 6px; font-size: 13px; color: var(--text); cursor: pointer;
}
.ms-context button:hover { background: var(--surface-2); color: var(--accent); }

/* detail */
.d-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.d-meta { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 0 0 14px; }
.d-meta div { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; min-width: 0; }
.d-meta .full { grid-column: 1 / -1; }
.d-meta dt { font-size: 11px; color: var(--text-2); margin-bottom: 4px; white-space: nowrap; }
.d-meta dd { margin: 0; font-weight: 600; display: flex; align-items: center; gap: 6px; word-break: break-word; }
.d-sec { margin-bottom: 12px; }
.d-sec h4 { margin: 0 0 4px; font-size: 12px; color: var(--text-2); white-space: nowrap; }
.d-sec p { margin: 0; white-space: pre-wrap; word-break: break-word; }
.d-sec-prominent { background: var(--accent-soft); border: 1px solid #e0e7ff; border-radius: 10px; padding: 10px 14px; margin-bottom: 14px; }
.d-sec-prominent h4 { color: var(--accent); font-size: 13px; }
.d-sec-prominent p { font-size: 14px; color: var(--text); }

/* ---------- DB Loading Overlay ---------- */
.db-loading-overlay {
  display: none; position: fixed; z-index: 999; inset: 0;
  background: rgba(15, 23, 42, .50);
  align-items: center; justify-content: center;
  flex-direction: column;
  backdrop-filter: blur(2px);
}
.db-loading-overlay.show { display: flex; }

.db-loading-card {
  background: var(--surface); border-radius: 18px; padding: 36px 40px;
  min-width: 320px; max-width: 440px; width: 90%;
  text-align: center;
  box-shadow: 0 12px 40px rgba(15, 23, 42, .25);
}

.db-loading-ring {
  width: 48px; height: 48px; margin: 0 auto 20px;
  border: 4px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: db-ring-spin .8s linear infinite;
}
@keyframes db-ring-spin { to { transform: rotate(360deg); } }

.db-loading-status-bar {
  width: 100%; height: 5px; background: var(--border); border-radius: 3px; overflow: hidden;
  margin-bottom: 16px;
}
.db-loading-status-fill {
  width: 100%; height: 100%; background: linear-gradient(90deg, var(--accent), #818cf8, var(--accent));
  background-size: 200% 100%;
  border-radius: 3px;
  animation: db-bar-slide 1.5s ease-in-out infinite;
}
@keyframes db-bar-slide {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}

.db-loading-text {
  margin: 0; font-size: 16px; font-weight: 700; color: var(--text);
}
.db-loading-hint {
  margin: 8px 0 0; font-size: 12px; color: var(--muted);
}

/* ---------- Responsive ---------- */
/* Default: mobile-only elements hidden on desktop */
.mobile-filter-btn { display: none; }
.overlay { display: none; }

/* ---- 1200px: Tablet landscape — auto-collapse sidebar ---- */
@media (max-width: 1200px) {
  .topbar { gap: 8px; padding: 8px 12px; }
  .brand div { font-size: 14px; }
  .brand small { display: none; }
  .sidebar-toggle-btn { width: 34px; height: 34px; }
  .view-tabs button { padding: 5px 10px; font-size: 12px; }
  #periodLabel { min-width: 120px; font-size: 12px; }
}

/* ---- 860px: Tablet portrait — sidebar vertical strip + list-view cards ---- */
@media (max-width: 860px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; position: static; height: auto; border-right: none; border-bottom: 2px solid var(--border); border-radius: 0; }
  .content { padding: 12px; }
  .topbar { gap: 6px; padding: 8px 10px; }
  .brand { font-size: 14px; gap: 4px; }
  .period #periodLabel { min-width: 100px; font-size: 12px; }
  .view-tabs button { padding: 4px 8px; font-size: 12px; }
  .btn-primary { padding: 6px 12px; font-size: 12px; }

  /* List view: rows become cards, header hidden */
  .tr { display: flex; flex-wrap: wrap; gap: 2px; padding: 10px 8px; }
  .tr.th { display: none; }
  .th-cell { display: none; }
  .td-cell { width: auto !important; flex: 1 1 auto; min-width: 0; border-right: none; padding: 2px 4px; font-size: 12px; }
  .td-cell .td-inner { white-space: normal; overflow: visible; text-overflow: unset; }
  /* Show field labels as inline prefixes on mobile card rows */
  .td-cell[data-l] { display: inline-flex; align-items: baseline; gap: 4px; }
  .td-cell[data-l] .td-inner::before { content: attr(data-l); color: var(--text-2); font-size: 10px; font-weight: 600; margin-right: 4px; flex: none; }
  .td-cell.c-status .td-inner::before { content: "状态"; }
  .td-cell.c-prio .td-inner::before { content: "优先级"; }
  .td-cell.c-title .td-inner::before { content: "名称"; }
  .td-cell.c-details .td-inner::before { content: "事项"; }
  .td-cell.c-owner .td-inner::before { content: "责任人"; }
  .td-cell.c-cat .td-inner::before { content: "分类"; }
  .td-cell.c-time .td-inner::before { content: "时间"; }
  .td-cell.c-remark .td-inner::before { content: "备注"; }

  .grid2 { grid-template-columns: 1fr; }
  .month-grid .day { min-height: 70px; }
  .d-meta { grid-template-columns: 1fr; }
}

/* ---- 640px: Phone — sidebar drawer + floating button + modal full ---- */
@media (max-width: 640px), (max-width: 900px) and (max-height: 500px) {
  .topbar { gap: 4px; padding: 8px; }
  .brand { font-size: 13px; }
  .brand .logo { font-size: 18px; }
  .brand div { font-size: 13px; line-height: 1.2; }
  #btnSidebar { width: 30px; height: 30px; border-radius: 8px; }
  .nav-arrow { width: 28px; height: 28px; }
  #periodLabel { min-width: 80px; font-size: 11px; }
  .view-tabs button { padding: 4px 6px; font-size: 11px; }
  #btnNew { font-size: 12px; padding: 6px 10px; }
  #btnMenu { font-size: 16px; padding: 2px 6px; }
  .user-badge { font-size: 10px; padding: 3px 6px; }
  .user-logout { font-size: 10px; }

  /* Sidebar drawer */
  .layout { position: relative; }
  .sidebar {
    position: fixed; z-index: 200; top: 0; left: 0; height: 100vh; width: 280px;
    transform: translateX(-100%); transition: transform .28s ease;
    box-shadow: 4px 0 16px rgba(0,0,0,.15); border-radius: 0;
    overflow-y: auto;
  }
  .sidebar.open { transform: translateX(0); }
  .content { padding: 10px; width: 100%; }

  /* Overlay */
  .overlay {
    display: none; position: fixed; z-index: 180; inset: 0;
    background: rgba(15,23,42,.40);
  }
  .overlay.show { display: block; }

  /* Mobile filter button — fixed bottom-right */
  .mobile-filter-btn {
    display: flex; align-items: center; gap: 6px;
    position: fixed; z-index: 190; bottom: 24px; right: 24px;
    padding: 12px 18px; border: none; border-radius: 28px;
    background: var(--accent); color: white; font-size: 13px; font-weight: 700;
    box-shadow: 0 4px 16px rgba(79,70,229,.40); cursor: pointer;
  }
  .mobile-filter-btn:active { transform: scale(.95); background: #4338ca; }

  /* Modal full-width */
  .modal-back { padding: 0; align-items: stretch; }
  .modal { max-width: 100%; width: 100%; border-radius: 0; min-height: 100vh; padding: 16px; }
  .form-actions { flex-direction: column; gap: 8px; }
  .form-actions button { width: 100%; }

  /* Stats bar wrap */
  .stats { flex-wrap: wrap; gap: 8px; font-size: 11px; }

  /* Disable hover tooltip on touch */
  .task-tip { display: none !important; }
}

/* ---- 480px: Small phone — mobile vertical lists for month/week ---- */
@media (max-width: 480px) {
  .brand { display: none; }
  .topbar { gap: 3px; }
  .period #periodLabel { min-width: 60px; font-size: 10px; }

  .modal { padding: 12px; }
  .detail { padding: 12px; }

  /* Month / week: hide grid, show vertical list */
  .month-grid, .week { display: none; }
  .mv-list, .wv-list { display: block; }
  /* Column header row — explicit labels for date/weekday/events */
  .mv-col-head, .wv-col-head {
    display: grid; grid-template-columns: 36px 60px 1fr;
    gap: 10px; padding: 8px 12px;
    font-size: 11px; font-weight: 700; color: var(--muted);
    border-bottom: 1px solid var(--border);
    background: var(--surface-2);
  }
  .mv-item, .wv-item {
    display: grid; grid-template-columns: 36px 60px 1fr;
    align-items: center; gap: 10px; padding: 10px 12px;
    border-bottom: 1px solid var(--border); cursor: pointer;
  }
  .mv-item:hover, .wv-item:hover { background: var(--surface-2); }
  .mv-day, .wv-day {
    width: 36px; height: 36px; border-radius: 10px;
    background: var(--surface-2); display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 14px; color: var(--text);
  }
  .mv-day.today, .wv-day.today { background: var(--accent); color: white; }
  .mv-weekday, .wv-weekday { font-size: 13px; color: var(--text-2); font-weight: 500; }
  .mv-weekday.today, .wv-weekday.today { color: var(--accent); font-weight: 700; }
  .mv-info, .wv-info { min-width: 0; }
  .mv-count, .wv-count { font-size: 12px; color: var(--text-2); font-weight: 600; }
  .mv-none, .wv-none { font-size: 11px; color: var(--muted); }

  /* List view compact */
  .td-cell { font-size: 11px; padding: 2px; }
  .list-toolbar { gap: 4px; }
  .edit-toggle { padding: 5px 8px; font-size: 11px; }
  .vis-quick .vq-chip { padding: 2px 6px; font-size: 10px; }
  .table-wrap { border-radius: 8px; }
  .user-info { display: none; }
}

/* ---- Touch optimization — larger hit areas, no hover stick ---- */
@media (hover: none) and (pointer: coarse) {
  button, .vq-chip, .tr:not(.th) { min-height: 44px; }
  .th-cell.draggable { min-height: 44px; }
  .nav-arrow, #btnSidebar { min-width: 44px; min-height: 44px; }
}

/* ---- Mobile experience rebuild ---- */
html, body { max-width: 100%; overflow-x: hidden; }

@media (max-width: 640px), (max-width: 900px) and (max-height: 500px) {
  body { min-height: 100dvh; background: #f5f7fc; }

  .topbar {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto 44px 44px;
    grid-template-areas:
      "period period period period"
      "tabs tabs tabs tabs"
      "user new notify menu";
    gap: 7px 6px;
    padding: max(7px, env(safe-area-inset-top)) 8px 8px;
    align-items: center;
    box-shadow: 0 2px 12px rgba(15, 23, 42, .06);
  }
  .topbar .spacer, .brand { display: none; }
  #btnSidebar { display: none; }
  .period { grid-area: period; width: 100%; min-width: 0; justify-content: space-between; gap: 5px; }
  .period #periodLabel {
    flex: 1; min-width: 0; padding: 0 3px; font-size: 12px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  }
  .period .nav-arrow { width: 38px; height: 38px; min-width: 38px; min-height: 38px; }
  .period .today-btn { min-height: 38px; padding: 5px 12px; }
  .view-tabs {
    grid-area: tabs; display: grid; grid-template-columns: repeat(4, 1fr);
    width: 100%; padding: 3px; border-radius: 12px;
  }
  .view-tabs button { min-height: 38px; padding: 6px 4px; font-size: 12px; }
  #userArea { grid-area: user; min-width: 0; overflow: hidden; }
  #userArea .user-info { width: 100%; min-width: 0; justify-content: flex-start; }
  #userArea .user-email { display: none; }
  #btnNew { grid-area: new; min-height: 40px; padding: 7px 12px; white-space: nowrap; }
  #btnNotify { grid-area: notify; width: 40px; height: 40px; min-width: 40px; min-height: 40px; }
  #btnMenu { grid-area: menu; width: 40px; height: 40px; min-width: 40px; min-height: 40px; padding: 0; }
  .menu {
    position: absolute; top: calc(100% + 6px); left: 8px; right: 8px;
    min-width: 0; max-height: min(70dvh, 520px); overflow-y: auto;
    padding: 8px; border-radius: 14px;
  }
  .menu button { min-height: 44px; padding: 11px 14px; }

  .layout { display: block; min-height: calc(100dvh - 140px); }
  .content { width: 100%; padding: 10px 8px calc(92px + env(safe-area-inset-bottom)); }
  #banner {
    gap: 8px; padding: 10px 12px; margin-bottom: 10px;
    line-height: 1.45; border-radius: 13px;
  }
  #banner .bell { align-self: flex-start; }
  #banner button { margin-left: auto; flex: none; min-height: 38px; padding: 6px 10px; }

  .sidebar {
    width: min(88vw, 330px); padding: max(18px, env(safe-area-inset-top)) 16px 28px;
    overscroll-behavior: contain;
  }
  .mobile-filter-btn {
    right: 16px; bottom: calc(16px + env(safe-area-inset-bottom));
    min-height: 52px; padding: 0 17px; border-radius: 26px;
  }
  body.modal-open .mobile-filter-btn { display: none; }

  /* Month and week become readable agenda lists on every phone width. */
  .month-grid, .week { display: none; }
  .mv-list, .wv-list { display: block; }
  .mobile-agenda {
    overflow: hidden; background: var(--surface); border: 1px solid var(--border);
    border-radius: 16px; box-shadow: 0 5px 18px rgba(15, 23, 42, .05);
  }
  .mobile-view-title {
    position: static;
    padding: 11px 14px; font-size: 15px; font-weight: 800;
    background: #fff; border-bottom: 1px solid var(--border);
  }
  .mv-col-head, .wv-col-head { display: none; }
  .mv-item, .wv-item {
    display: grid; grid-template-columns: 58px minmax(0, 1fr);
    align-items: start; gap: 10px; padding: 11px 12px;
    border-bottom: 1px solid #edf0f5; cursor: pointer;
    background: var(--surface); min-height: 68px;
  }
  .mv-item:last-child, .wv-item:last-child { border-bottom: 0; }
  .mv-item:active, .wv-item:active { background: var(--accent-soft); }
  .mobile-date-stack { display: flex; flex-direction: column; align-items: center; gap: 4px; }
  .mv-day, .wv-day {
    width: 38px; height: 38px; border-radius: 12px;
    background: var(--surface-2); display: flex; align-items: center; justify-content: center;
    font-weight: 800; font-size: 15px; color: var(--text);
  }
  .mv-day.today, .wv-day.today { color: #fff; background: linear-gradient(135deg, #6366f1, #4f46e5); box-shadow: 0 4px 10px rgba(79,70,229,.25); }
  .mv-weekday, .wv-weekday { font-size: 11px; color: var(--text-2); font-weight: 600; white-space: nowrap; }
  .mv-weekday.today, .wv-weekday.today { color: var(--accent); }
  .mv-info, .wv-info { display: flex; flex-direction: column; gap: 5px; min-width: 0; padding-top: 1px; }
  .mobile-task-preview {
    display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px;
    align-items: center; min-width: 0; padding-left: 8px;
    border-left: 3px solid var(--task-color, var(--accent));
  }
  .mobile-task-preview.done { opacity: .55; }
  .mobile-task-preview-title { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; font-weight: 700; }
  .mobile-task-preview-meta { max-width: 88px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 10px; color: var(--text-2); }
  .mobile-preview-empty { padding: 7px 0; font-size: 12px; color: var(--muted); }
  .mobile-preview-more { font-size: 11px; color: var(--accent); font-weight: 700; }

  .mobile-pending-panel { margin: 10px; border: 1px solid #ddd6fe; border-radius: 13px; overflow: hidden; background: #faf8ff; }
  .mobile-pending-head { display: flex; align-items: center; justify-content: space-between; padding: 9px 11px; color: #5b21b6; font-size: 12px; font-weight: 800; }
  .mobile-pending-head b { display: grid; place-items: center; min-width: 24px; height: 24px; padding: 0 6px; border-radius: 12px; background: #ede9fe; }
  .mobile-pending-items { display: grid; gap: 1px; background: #ede9fe; }
  .mobile-pending-item {
    display: grid; grid-template-columns: minmax(0,1fr); gap: 2px; text-align: left;
    padding: 9px 11px 9px 14px; border: 0; border-left: 3px solid var(--task-color, var(--accent));
    background: #fff; min-height: 0;
  }
  .mobile-pending-title { font-size: 12px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .mobile-pending-meta { font-size: 10px; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .mobile-pending-more { padding: 8px 11px; background: #faf8ff; color: #6d28d9; font-size: 11px; }

  /* Purpose-built card list instead of squeezing the desktop table. */
  .stats {
    display: grid; grid-template-columns: repeat(4, 1fr); gap: 5px;
    margin-bottom: 9px;
  }
  .stats span { padding: 7px 4px; text-align: center; background: var(--surface); border: 1px solid var(--border); border-radius: 9px; font-size: 10px; }
  .stats b { display: block; margin-top: 1px; font-size: 14px; }
  .list-toolbar { gap: 7px; margin-bottom: 8px; }
  .list-toolbar .edit-toggle { flex: 1; justify-content: center; min-height: 40px; padding: 7px 10px; font-size: 12px; }
  .mobile-list-sort { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; margin-bottom: 9px; }
  .mobile-list-sort select, .mobile-sort-direction {
    min-height: 42px; border: 1px solid var(--border); border-radius: 10px;
    background: var(--surface); color: var(--text); padding: 8px 11px; font-size: 13px;
  }
  .mobile-sort-direction { color: var(--accent); font-weight: 700; }
  .mobile-task-list { display: grid; gap: 9px; }
  .mobile-task-card {
    display: flex; gap: 10px; padding: 12px; background: var(--surface);
    border: 1px solid var(--border); border-left: 4px solid var(--task-color, var(--accent));
    border-radius: 13px; box-shadow: 0 2px 8px rgba(15,23,42,.04); cursor: pointer;
  }
  .mobile-task-card:active { transform: scale(.99); background: var(--surface-2); }
  .mobile-task-card.done { opacity: .62; }
  .mobile-card-select { width: 20px; height: 20px; flex: none; margin: 2px 0 0; accent-color: var(--accent); }
  .mobile-task-card-body { min-width: 0; flex: 1; }
  .mobile-task-card-head { display: flex; align-items: flex-start; gap: 8px; }
  .mobile-task-card-title { min-width: 0; flex: 1; font-size: 14px; line-height: 1.35; font-weight: 800; }
  .mobile-task-card-details, .mobile-task-card-remark {
    margin-top: 7px; padding: 7px 9px; border-radius: 8px; background: #f6f7fb;
    color: var(--text-2); font-size: 12px; line-height: 1.45;
    display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden;
  }
  .mobile-task-card-meta { display: flex; flex-wrap: wrap; gap: 5px 10px; margin-top: 8px; font-size: 11px; color: var(--text-2); }
  .mobile-task-card-meta span { display: inline-flex; align-items: center; gap: 4px; }
  .mobile-task-card-time { margin-top: 7px; font-size: 11px; font-weight: 700; color: var(--accent); }
  .mobile-task-card-remark { background: #fffaf0; color: #92400e; -webkit-line-clamp: 1; }

  .day-view { gap: 9px; }
  .day-card { padding: 12px; border-radius: 13px; }
  .dc-title { font-size: 15px; }

  /* Full-height sheet with reachable actions and no iOS form zoom. */
  .modal-back { height: 100dvh; padding: 0; align-items: stretch; }
  .modal {
    width: 100%; height: 100dvh; min-height: 0; max-height: 100dvh;
    border-radius: 0; padding: 16px 14px calc(100px + env(safe-area-inset-bottom));
    overscroll-behavior: contain;
  }
  .modal.detail-modal { padding-bottom: calc(184px + env(safe-area-inset-bottom)); }
  .modal.action-modal {
    width: calc(100% - 28px); height: auto; min-height: 0; max-height: calc(100dvh - 28px);
    margin: auto; padding: 22px 18px calc(22px + env(safe-area-inset-bottom)); border-radius: 16px;
  }
  .action-dialog h2 { font-size: 19px; }
  .action-dialog-message { margin-bottom: 16px; }
  .action-dialog textarea { min-height: 150px; font-size: 16px; }
  .action-dialog-actions { gap: 8px; margin-top: 18px; }
  .action-dialog-actions button { min-height: 44px; padding-left: 8px; padding-right: 8px; font-size: 13px; }
  .form h3, .detail h3 { font-size: 19px; margin-bottom: 14px; }
  .field { margin-bottom: 12px; }
  .field input:not([type="checkbox"]):not([type="radio"]), .field textarea, .field select,
  .when-box input[type="date"], .when-box input[type="time"],
  .when-box input[type="week"], .when-box input[type="month"] { font-size: 16px; min-height: 44px; }
  .seg {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
  }
  .seg label {
    justify-content: center;
    min-width: 0;
    min-height: 44px;
    padding: 7px 3px;
    border: 1px solid var(--border);
    border-radius: 9px;
    background: var(--surface-2);
    white-space: normal;
    text-align: center;
  }
  #recurrenceArea > label {
    min-height: 44px;
    padding: 7px 2px;
  }
  .when-box { align-items: stretch; }
  .when-box input[type="date"], .when-box input[type="time"], .when-box input[type="week"], .when-box input[type="month"] { min-width: 0; flex: 1 1 140px; }
  .repeat-row, .range-row { align-items: stretch; }
  .repeat-row select#f_repeatRule, .repeat-row input#f_repeatEnd,
  .range-row input { width: 100%; max-width: none; }
  .form-actions {
    position: fixed; left: 0; right: 0; bottom: 0;
    z-index: 5; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px; margin: 0; padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
    background: rgba(255,255,255,.96); border-top: 1px solid var(--border); box-shadow: 0 -8px 20px rgba(15,23,42,.07);
    backdrop-filter: blur(10px);
  }
  .form-actions .spacer { display: none; }
  .form-actions button { width: 100%; min-height: 44px; }
  .detail .form-actions { grid-template-columns: 1fr 1fr; }
  .detail .form-actions .primary { grid-column: 1 / -1; }
}

@media (max-width: 380px) {
  .topbar { grid-template-columns: minmax(0, 1fr) auto 40px 40px; padding-left: 6px; padding-right: 6px; }
  #btnNew { padding-left: 9px; padding-right: 9px; }
  .period #periodLabel { font-size: 11px; }
  .mobile-task-preview-meta { display: none; }
}

/* ========== 下面保持原 Auth / etc 规则 ========== */

/* ---------- Auth UI ---------- */
.auth-page {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; background: linear-gradient(135deg, #f0f4ff 0%, #faf5ff 100%);
  padding: 20px;
}
.auth-card {
  background: #fff; border-radius: 20px; box-shadow: 0 8px 32px rgba(15,23,42,.1);
  padding: 40px 36px; max-width: 420px; width: 100%;
}
.auth-brand { text-align: center; margin-bottom: 28px; }
.auth-brand .auth-logo { font-size: 48px; display: block; margin-bottom: 8px; }
.auth-brand h1 { margin: 0; font-size: 22px; color: var(--text); }
.auth-brand p { margin: 6px 0 0; color: var(--text-2); font-size: 14px; }
.auth-form { display: flex; flex-direction: column; gap: 16px; }
.auth-field { display: flex; flex-direction: column; gap: 6px; }
.auth-field label { font-size: 13px; font-weight: 600; color: var(--text-2); }
.auth-field input {
  padding: 12px 14px; border: 1px solid var(--border); border-radius: 10px;
  font-size: 15px; color: var(--text); background: var(--surface);
  transition: border-color .15s;
}
.auth-field input:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px rgba(79,70,229,.1); }
.auth-error { padding: 10px 14px; background: #fef2f2; border: 1px solid #fecaca; border-radius: 8px; color: #dc2626; font-size: 13px; }
.auth-btn.primary {
  width: 100%; padding: 14px; background: var(--accent); color: #fff;
  border: none; border-radius: 12px; font-size: 16px; font-weight: 700; cursor: pointer;
  transition: background .15s, transform .1s;
}
.auth-btn.primary:hover { background: #4338ca; }
.auth-btn.primary:active { transform: scale(.98); }
.auth-btn.primary:disabled { opacity: .65; cursor: not-allowed; }
.auth-toggle { text-align: center; margin-top: 18px; font-size: 13px; color: var(--text-2); }
.auth-link { border: none; background: none; color: var(--accent); font-weight: 600; cursor: pointer; font-size: 13px; }
.auth-link:hover { text-decoration: underline; }
.auth-offline-hint { text-align: center; margin-top: 16px; padding: 12px; background: #f5f7fb; border-radius: 8px; display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--text-2); }

/* User info in topbar */
.user-info { display: flex; align-items: center; gap: 10px; }
.user-badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 4px 10px; background: #ecfdf5; border: 1px solid #a7f3d0;
  border-radius: 999px; font-size: 12px; color: #065f46; font-weight: 500;
}
.user-badge .user-icon { font-size: 13px; }
.user-logout {
  padding: 4px 10px; border: 1px solid var(--border); background: var(--surface);
  border-radius: 8px; font-size: 12px; color: var(--text-2); cursor: pointer;
}
.user-logout:hover { border-color: var(--accent); color: var(--accent); }

/* ---------- Forced Update Overlay ---------- */
.update-overlay {
  display: none; position: fixed; z-index: 999; inset: 0;
  background: rgba(15,23,42,.60);
  align-items: center; justify-content: center;
}
.update-card {
  background: #fff; border-radius: 20px; padding: 36px 28px; max-width: 360px; width: 90%;
  text-align: center; box-shadow: 0 8px 32px rgba(15,23,42,.25);
}
.update-card .update-icon { font-size: 48px; display: block; margin-bottom: 12px; }
.update-card h3 { margin: 0 0 8px; font-size: 20px; color: var(--text); }
.update-card p { margin: 0 0 20px; font-size: 13px; color: var(--text-2); line-height: 1.5; }
.update-card .auth-btn.primary { width: 100%; }

/* ---------- Toast ---------- */
#toastHost {
  position: fixed; top: 70px; right: 20px; z-index: 100;
  display: flex; flex-direction: column; gap: 8px;
  pointer-events: none;
}
.toast {
  background: #1f2937; color: #fff;
  padding: 10px 16px; border-radius: 8px;
  font-size: 13px; max-width: 380px; min-width: 200px;
  box-shadow: 0 4px 16px rgba(0,0,0,.18);
  opacity: 0; transform: translateX(20px); transition: opacity .25s ease, transform .25s ease;
  pointer-events: auto;
  word-break: break-word;
}
.toast.show { opacity: 1; transform: translateX(0); }
.toast.error { background: #dc2626; }
.toast.success { background: #059669; }
.toast.info { background: #1f2937; }


/* ===== Backup reminder popup (from three-dots menu) ===== */
#btnMenu { position: relative; }
#btnMenu.backup-due::after {
  content: ''; position: absolute; top: 6px; right: 6px;
  width: 8px; height: 8px; border-radius: 50%; background: #ef4444;
  border: 2px solid var(--surface);
}
.menu button.warning {
  color: #b45309; background: #fffbeb; font-weight: 700;
}
.menu button.warning:hover { background: #fef3c7; }

/* Backup reminder popup anchored under the three-dots menu button */
.backup-reminder-popup {
  position: fixed; z-index: 60;
  width: max-content; min-width: 260px; max-width: 360px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 14px 18px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, .12);
}
.backup-reminder-popup h2 {
  margin: 0 0 10px; font-size: 15px; font-weight: 700;
  text-align: center; white-space: nowrap;
}
.backup-reminder-popup p {
  margin: 0 0 14px; font-size: 13px; color: var(--text-2); line-height: 1.5;
  text-align: center; white-space: nowrap;
}
.backup-reminder-popup .actions {
  display: flex; gap: 10px; justify-content: center; flex-wrap: nowrap;
}
.backup-reminder-popup .actions button {
  padding: 7px 14px; border-radius: 8px; font-weight: 600; font-size: 13px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer;
  white-space: nowrap;
}
.backup-reminder-popup .actions button.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.backup-reminder-popup .actions button:hover { border-color: var(--accent); color: var(--accent); }
.backup-reminder-popup .actions button.primary:hover { background: #4338ca; color: #fff; }

/* ===== Backup reminder banner (legacy, kept for safety) ===== */
#bannerBackup, #bannerDismiss {
  margin-left: 6px; background: none; border: none;
  font-weight: 700; cursor: pointer; font-size: 13px;
}
#bannerBackup { color: #d97706; }
#bannerDismiss { color: var(--muted); font-weight: 400; }
#bannerBackup:hover { text-decoration: underline; }
#bannerDismiss:hover { color: var(--text); }

/* ===== Backup settings modal ===== */
.backup-settings h2 { margin: 0 0 16px !important; font-size: 18px !important; }
.backup-settings code {
  background: #eef2ff; padding: 2px 6px; border-radius: 4px;
  font-size: 12px; color: var(--accent);
}
