:root {
  --bg: #f2f4f9;
  --card: #ffffff;
  --line: #e4e8f0;
  --text: #1f2733;
  --muted: #8a93a6;
  --accent: #4f6ef7;
  --accent-soft: #eef1fe;
  --danger: #e5484d;
  --teal: #0f766e;
  --teal-soft: #e6faf5;
  --r-sm: 10px;
  --r-md: 14px;
  --r-lg: 16px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 4px 16px rgba(16, 24, 40, .06);
  --shadow-tab: 0 1px 3px rgba(16, 24, 40, .08);
  --ring: 0 0 0 3px var(--accent-soft);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
}

/* ---------- 顶栏 ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 20px;
  background: rgba(255, 255, 255, .88);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 4px 16px rgba(16, 24, 40, .04);
}

.brand { font-size: 18px; font-weight: 700; white-space: nowrap; }

.date-wrap { display: flex; align-items: center; gap: 8px; }

.day-nav { display: flex; align-items: center; gap: 2px; }

.day-nav input[type="date"] {
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  padding: 5px 8px;
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  background: #fff;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}

.day-nav input[type="date"]:focus { border-color: var(--accent); box-shadow: var(--ring); }

.weekday {
  font-size: 13px;
  color: var(--muted);
  background: var(--bg);
  padding: 3px 10px;
  border-radius: 999px;
  white-space: nowrap;
}

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

/* ---------- 布局 ---------- */

.layout {
  display: grid;
  grid-template-columns: 3fr 2fr;
  gap: 22px;
  padding: 22px 24px;
  max-width: 1280px;
  margin: 0 auto;
  align-items: start;
}

.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow);
  padding: 18px;
}

.opt-panel { position: sticky; top: 70px; max-height: calc(100vh - 96px); overflow-y: auto; }

.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; gap: 8px; }

.panel-head h2 { font-size: 15px; font-weight: 700; }

.panel-actions { display: flex; gap: 6px; }

/* ---------- 按钮 ---------- */

.btn {
  border: none;
  border-radius: var(--r-sm);
  padding: 6px 12px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  color: var(--text);
  background: #f1f3f8;
  transition: background .15s, box-shadow .15s;
}

.btn:hover { background: #e7eaf2; }
.btn-primary { background: var(--accent); color: #fff; box-shadow: 0 1px 2px rgba(79, 110, 247, .35); }
.btn-primary:hover { background: #3d5ce6; }
.danger { color: var(--danger); }

.icon-btn {
  width: 26px;
  height: 26px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
  font-family: inherit;
  transition: background .15s, color .15s;
}

.icon-btn:hover { background: #eceff5; color: var(--text); }

.drag-handle {
  color: #c3c9d6;
  cursor: grab;
  font-size: 14px;
  user-select: none;
  padding: 0 2px;
}

.drag-handle:hover { color: var(--muted); }

/* ---------- 查看/编辑模式（左右独立） ---------- */

#btnAddBlock,
#btnClear,
#btnAddGroup,
#btnAddDestGroup,
.group-head .group-up,
.group-head .group-down,
.group-head .add-opt,
.group-head .del-group,
.opt .opt-up,
.opt .opt-down,
.opt .opt-edit-btn { display: none; }

.plan-panel .block-ops,
.plan-panel .block-addbtns,
.plan-panel .drag-handle,
.plan-panel .task .task-up,
.plan-panel .task .task-down,
.plan-panel .task .add-sub,
.plan-panel .task .del,
.plan-panel .sub .del { display: none; }

body.edit-plan #btnAddBlock,
body.edit-plan #btnClear { display: inline-block; }

body.edit-plan .plan-panel .block-ops,
body.edit-plan .plan-panel .block-addbtns { display: flex; }

body.edit-plan .plan-panel .drag-handle { display: inline; }

body.edit-plan .plan-panel .task .task-up,
body.edit-plan .plan-panel .task .task-down,
body.edit-plan .plan-panel .task .add-sub,
body.edit-plan .plan-panel .task .del,
body.edit-plan .plan-panel .sub .del { display: inline-block; }

body.edit-opt #btnAddGroup,
body.edit-opt #btnAddDestGroup,
body.edit-opt .group-head .group-up,
body.edit-opt .group-head .group-down,
body.edit-opt .group-head .add-opt,
body.edit-opt .group-head .del-group,
body.edit-opt .opt .opt-up,
body.edit-opt .opt .opt-down,
body.edit-opt .opt .opt-edit-btn { display: inline-block; }

/* ---------- 左侧：时间块（时间 = 文件夹式标签） ---------- */

.block-list { display: flex; flex-direction: column; }

.block {
  position: relative;
  border: 1px solid var(--line);
  border-left: 4px solid #c9d2ea;
  border-radius: var(--r-md);
  padding: 36px 14px 10px;
  margin-bottom: 22px;
  background: #fff;
  transition: border-color .15s, box-shadow .15s;
}

.block.active {
  border-left-color: var(--accent);
  box-shadow: var(--ring);
}

.block-bar {
  position: absolute;
  top: -14px;
  left: 18px;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 3px 12px 3px 8px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 999px;
  box-shadow: var(--shadow-tab);
  transition: background .15s, border-color .15s;
}

.block.active .block-bar {
  background: var(--accent-soft);
  border-color: #b9c6fb;
}

.block.active .block-time { color: var(--accent); }

.block-time {
  flex: 1;
  font-size: 13.5px;
  font-weight: 600;
  border: none;
  background: transparent;
  outline: none;
  padding: 2px 8px;
  border-radius: 999px;
  font-family: inherit;
  color: var(--text);
  min-width: 60px;
}

.block-time:focus { background: var(--bg); }

.block-ops { display: flex; gap: 2px; }

.task {
  padding: 3px 4px;
  border-radius: var(--r-sm);
  margin: 2px 0;
}

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

.task.dest-task { background: var(--teal-soft); }

.task.dest-task:hover { background: #d9f7f0; }

.task.dest-task .task-text { color: var(--teal); font-weight: 500; }

.check-placeholder {
  width: 16px;
  flex-shrink: 0;
}

.task-pin { font-size: 13px; line-height: 1; }

.task-transit {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  font-size: 12px;
  font-family: inherit;
  color: var(--text);
  padding: 3px 2px;
  max-width: 84px;
  flex-shrink: 0;
  outline: none;
}

.task-transit:focus { border-color: var(--accent); box-shadow: var(--ring); }

.task-row { display: flex; align-items: center; gap: 6px; }

.subs {
  margin: 2px 0 2px 28px;
  padding-left: 8px;
  border-left: 2px dashed #dde2ee;
}

.sub {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 2px 4px;
  border-radius: 8px;
}

.sub:hover { background: var(--bg); }

.sub-check {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
  flex-shrink: 0;
}

.sub-text {
  flex: 1;
  font-size: 14px;
  border: none;
  background: transparent;
  outline: none;
  padding: 4px 6px;
  border-radius: 8px;
  border-bottom: 1px dashed transparent;
  font-family: inherit;
  color: var(--text);
}

.sub-text:focus { border-bottom-color: #c9d2ea; }

.sub.done .sub-text {
  text-decoration: line-through;
  color: var(--muted);
}

.task-check {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
  flex-shrink: 0;
}

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

.task-text {
  flex: 1;
  font-size: 14px;
  border: none;
  background: transparent;
  outline: none;
  padding: 5px 8px;
  border-radius: 8px;
  border-bottom: 1px dashed transparent;
  font-family: inherit;
  color: var(--text);
}

.task-text:focus { border-bottom-color: #c9d2ea; }

.block-addbtns {
  display: flex;
  gap: 6px;
  margin: 4px 0 2px;
}

.btn-addtask,
.btn-adddest {
  flex: 1;
  padding: 6px;
  color: var(--muted);
  background: transparent;
}

.btn-addtask:hover,
.btn-adddest:hover { background: var(--bg); color: var(--text); }

.btn-adddest { color: var(--teal); }

.btn-adddest:hover { background: var(--teal-soft); color: var(--teal); }

.empty-hint {
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  padding: 32px 10px;
  border: 1.5px dashed var(--line);
  border-radius: var(--r-md);
  background: #fbfcfe;
}

/* ---------- 右侧：分组与选项 ---------- */

.search-wrap { margin-bottom: 14px; }

.search-wrap input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}

.search-wrap input:focus { border-color: var(--accent); box-shadow: var(--ring); }

.group {
  margin-bottom: 16px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  overflow: hidden;
  background: #fff;
  box-shadow: 0 1px 2px rgba(16, 24, 40, .03);
  transition: box-shadow .15s;
}

.group:hover { box-shadow: var(--shadow-tab); }

.group-head {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  background: #f8f9fc;
}

.group.destination-group .group-head { background: #eefaf8; }

.group-icon { font-size: 13px; line-height: 1; }

.group-name {
  flex: 1;
  font-size: 14px;
  font-weight: 600;
  border: none;
  background: transparent;
  outline: none;
  border-radius: 8px;
  padding: 3px 6px;
  font-family: inherit;
  color: var(--text);
}

.group-name:focus { background: #fff; box-shadow: 0 0 0 2px var(--accent-soft); }

.group-count {
  font-size: 12px;
  color: var(--muted);
  background: var(--bg);
  padding: 1px 8px;
  border-radius: 999px;
  white-space: nowrap;
}

.group-items { padding: 6px; display: flex; flex-direction: column; gap: 2px; }

.group.collapsed .group-items { display: none; }

.opt {
  padding: 7px 8px;
  border-radius: var(--r-sm);
}

.opt-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.opt:hover { background: var(--bg); }

.opt-preview {
  font-size: 12px;
  color: var(--muted);
  padding: 0 8px 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.opt-time {
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 2px 8px;
  border-radius: 999px;
  white-space: nowrap;
}

.opt-text { flex: 1; font-size: 14px; word-break: break-all; }

.opt-pin { font-size: 13px; line-height: 1; }

.opt.dest .opt-time {
  background: #ccfbf1;
  color: var(--teal);
}

.opt.dest .opt-text { color: var(--teal); }

.opt-subcount {
  font-size: 11px;
  color: var(--muted);
  background: var(--bg);
  padding: 1px 7px;
  border-radius: 999px;
  white-space: nowrap;
}

.opt-add {
  width: 26px;
  height: 26px;
  border-radius: 8px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 16px;
  font-weight: 700;
  flex-shrink: 0;
}

.opt-add:hover { background: var(--accent); color: #fff; }

.opt.editing { background: var(--bg); }

.opt-fields { display: flex; align-items: center; gap: 6px; width: 100%; }

.opt.editing input {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 8px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}

.opt.editing input:focus { border-color: var(--accent); box-shadow: var(--ring); }

.opt.editing .edit-time { flex: 0 0 110px; }

.edit-subs-label {
  margin-top: 8px;
  font-size: 12px;
  color: var(--muted);
}

.edit-subs {
  width: 100%;
  min-height: 96px;
  margin-top: 4px;
  border: 1px solid #c9d2ea;
  border-radius: var(--r-sm);
  padding: 8px 10px;
  font-size: 15px;
  font-family: inherit;
  line-height: 1.7;
  color: var(--text);
  background: #fff;
  resize: vertical;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}

.edit-subs:focus {
  border-color: var(--accent);
  box-shadow: var(--ring);
}

.edit-subs::placeholder { color: #b0b8c8; }

.opt-save { color: #16a34a; }
.opt-del { color: var(--danger); }

.search-empty { text-align: center; color: var(--muted); font-size: 13px; padding: 20px 0; }

/* ---------- 弹窗 ---------- */

.modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(16, 24, 40, .45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 16px;
}

.modal-mask[hidden] { display: none; }

.modal {
  background: #fff;
  border-radius: var(--r-lg);
  box-shadow: 0 12px 40px rgba(16, 24, 40, .25);
  width: 100%;
  max-width: 420px;
  padding: 18px;
  max-height: 85vh;
  overflow-y: auto;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.modal-head h3 { font-size: 15px; font-weight: 700; }

.modal-body { display: flex; flex-direction: column; gap: 10px; }

.modal-hint { font-size: 12px; color: var(--muted); }

.sync-pass {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  padding: 8px 10px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}

.sync-pass:focus { border-color: var(--accent); box-shadow: var(--ring); }

.modal-actions { display: flex; gap: 8px; justify-content: flex-end; }

/* ---------- 反馈 ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 36px;
  transform: translateX(-50%) translateY(20px);
  background: #1f2733;
  color: #fff;
  padding: 10px 18px;
  border-radius: var(--r-sm);
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s, transform .25s;
  z-index: 99;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .18);
  max-width: 80vw;
}

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

@keyframes flashBg {
  0% { background: #fff3c4; }
  100% { background: transparent; }
}

.flash { animation: flashBg 1.2s ease-out; }

.dragging { opacity: .45; }

/* ---------- 移动端 ---------- */

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; padding: 12px; }
  .topbar { flex-wrap: wrap; padding: 10px 12px; gap: 10px; }
  .top-actions { margin-left: 0; }
  .opt-panel { position: static; max-height: none; }
  .block-bar { left: 14px; }
}
