/* ============================================================
   日历页
   ============================================================ */
[data-page="calendar"] { display: flex; flex-direction: column; overflow: hidden; }

.cal-header {
  flex-shrink: 0;
  padding: 8px 4px;
  display: flex;
  align-items: center;
}
.cal-nav { display: flex; align-items: center; flex: 1; }
.cal-title { font-size: 15px; font-weight: 720; flex: 1; text-align: center; letter-spacing: -.02em; }
.cal-arrow { width: 30px; height: 30px; display: flex; align-items: center; justify-content: center; border-radius: 50%; color: var(--text2); transition: background var(--tr), color var(--tr); flex-shrink: 0; }
.cal-arrow[hidden] { display: none; }
.cal-arrow:active { background: var(--material-field); color: var(--text); }
.cal-arrow:focus-visible { outline: var(--focus-ring); outline-offset: 2px; }
.cal-arrow svg { width: 17px; height: 17px; }

/* 第二行：全天左 + 日周月右 */
.cal-subheader {
  flex-shrink: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 112px;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  padding: 0 12px 6px;
  border-bottom: 1px solid var(--separator-soft);
}
.cal-view-tabs {
  grid-column: 2;
  position: relative;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  width: 100%;
  min-width: 0;
  background: transparent;
  border-radius: 999px;
  padding: 0;
  gap: 0;
  justify-self: end;
}

.cal-view-tab-indicator {
  position: absolute;
  left: 0;
  top: 0;
  height: 100%;
  border-radius: 999px;
  background: var(--accent);
  z-index: 0;
  pointer-events: none;
  width: 0;
  transition: width 0.34s var(--ease-nav);
  will-change: transform, width;
}

@media (prefers-reduced-motion: reduce) {
  .cal-view-tab-indicator {
    transition: none;
  }
}

.cal-view-tab {
  position: relative;
  z-index: 1;
  min-width: 0;
  min-height: 24px;
  padding: 0;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 620;
  color: var(--text3);
  background: transparent;
  transition: background var(--tr), color var(--tr);
}
.cal-view-tab.active { color: #fff; }
.cal-view-tab:focus-visible { outline: var(--focus-ring); outline-offset: 2px; }

.cal-view { display: none; flex: 1; flex-direction: column; overflow: hidden; }
.cal-view.active { display: flex; }

/* 全天行（日/周共用） */
.day-allday-row, .tl-allday-row {
  grid-column: 1;
  flex: 0 1 auto;
  display: flex;
  align-items: center;
  min-height: 24px;
  min-width: 0;
  max-width: 100%;
  width: 100%;
}
.day-allday-row[hidden], .tl-allday-row[hidden] { display: none; }
[data-page="calendar"]:not([data-cal-view="day"]) .day-allday-row {
  visibility: hidden;
  display: flex;
  pointer-events: none;
}
.day-allday-label, .tl-allday-label {
  width: 48px;
  flex-shrink: 0;
  font-size: 10px;
  color: var(--text3);
  text-align: right;
  padding-right: 8px;
  padding-top: 4px;
}
.day-allday-events, .tl-allday-events { flex: 0 1 auto; display: flex; flex-wrap: wrap; gap: 3px; padding: 2px 0; min-width: 0; }
.allday-chip { font-size: 11px; font-weight: 500; padding: 2px 8px; border-radius: 99px; background: var(--accent-light); color: var(--accent); white-space: nowrap; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.allday-chip.done { opacity: .34; text-decoration: line-through; filter: grayscale(45%); }
.allday-chip.missed { opacity: .48; border: 1px dashed color-mix(in srgb, var(--danger) 42%, transparent); color: color-mix(in srgb, var(--danger) 62%, var(--text2)); }

/* ── 日视图（时间轴） ── */
.tl-scroll { flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; position: relative; padding-bottom: 40px; }
/* Day/week surface enter — same language as month-cell slideUp in components.css */
@keyframes cal-calendar-enter {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
#viewDay.active .tl-scroll.cal-calendar-enter,
#viewWeek.active .week-scroll.cal-calendar-enter {
  animation: cal-calendar-enter 0.22s cubic-bezier(0.22, 1, 0.36, 1) both;
}
@media (prefers-reduced-motion: reduce) {
  #viewDay.active .tl-scroll.cal-calendar-enter,
  #viewWeek.active .week-scroll.cal-calendar-enter {
    animation: none !important;
  }
}
.tl-grid { position: relative; min-height: 1536px; }
.tl-row { position: absolute; left: 0; right: 0; height: 64px; display: flex; align-items: flex-start; }
.tl-row-label { width: 44px; flex-shrink: 0; font-size: 10px; font-weight: 600; color: var(--text3); text-align: right; padding-right: 10px; padding-top: 2px; letter-spacing: .04em; }
/* Timeline background hits (parity with .month-cell): tasks stay above (z-index 5). */
.tl-row-line {
  flex: 1;
  align-self: stretch;
  border-top: 1px solid var(--border);
  cursor: pointer;
  transition: background var(--tr-fast);
  -webkit-tap-highlight-color: transparent;
}
@media (hover: hover) {
  .tl-row:hover .tl-row-line {
    background: color-mix(in srgb, var(--accent-light) 22%, transparent);
  }
}
.tl-row:active .tl-row-line {
  background: color-mix(in srgb, var(--accent-light) 30%, transparent);
}
.tl-row.half .tl-row-line { border-top: 1px dashed var(--border); opacity: .5; }
.tl-row.half:active .tl-row-line { opacity: 0.85; }
.tl-now-line { position: absolute; left: 44px; right: 0; height: 2px; background: var(--accent); z-index: 10; pointer-events: none; box-shadow: 0 0 6px var(--accent-glow); }
.tl-now-dot { position: absolute; left: -5px; top: -4px; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 3px var(--accent-light); }

/* 时间轴任务色块 */
.tl-block {
  position: absolute;
  border-radius: 8px;
  padding: 4px 8px;
  cursor: pointer;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  transition: filter var(--tr), transform var(--tr), top .0s, box-shadow var(--tr);
  box-shadow: 0 2px 10px rgba(8, 9, 16, 0.14);
  z-index: 5;
  min-height: 24px;
}
/* 事件（日程块）：无描边，仅靠色块与阴影层次 */
.tl-block-event {
  border: none;
  outline: none;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.22);
}
.tl-block-event.tl-block-overdue {
  outline: none;
  outline-offset: 0;
}
.tl-block:active { transform: scale(.97); filter: brightness(1.1); }
.tl-block.draggable { cursor: grab; touch-action: none; }
.tl-block.draggable:active { cursor: grabbing; }
.tl-block.dragging-float {
  pointer-events: none;
  transition: none;
  filter: brightness(1.08) saturate(1.1);
  box-shadow: 0 18px 42px rgba(5,6,12,.42), 0 0 0 1px rgba(255,255,255,.18);
  z-index: 40 !important;
}
.tl-block.dragging-float.invalid-drop {
  filter: grayscale(.45) brightness(.86);
  box-shadow: 0 14px 34px rgba(120,24,24,.32), 0 0 0 1px color-mix(in srgb, var(--danger) 48%, transparent);
}
.tl-block.resizing { box-shadow: 0 0 0 2px var(--accent), 0 12px 28px rgba(0,0,0,.34); }

/* resize handle（双击后出现）*/
.tl-resize-handle {
  position: absolute;
  left: 0; right: 0;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: ns-resize;
  touch-action: none;
  z-index: 10;
}
.tl-resize-handle-top { top: 0; }
.tl-resize-handle-bot { bottom: 0; }
.tl-resize-line {
  width: 36px; height: 4px;
  border-radius: 99px;
  background: rgba(255,255,255,0.8);
}

/* 拖拽时间提示标签 */
.tl-drag-label {
  position: absolute;
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 99px;
  z-index: 30;
  pointer-events: none;
  white-space: nowrap;
  box-shadow: 0 2px 8px rgba(0,0,0,.3);
  transform: translateY(0);
}
.tl-block-title { display: flex; align-items: center; gap: 4px; min-width: 0; font-size: 11px; font-weight: 600; color: #fff; line-height: 1.3; }
.tl-block-title-text { min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.tl-block-alarm { width: 12px; height: 12px; flex: 0 0 auto; stroke-width: 2; }
.tl-block-time { font-size: 10px; color: rgba(255,255,255,.7); margin-top: 1px; }
.tl-block.done { opacity: .4; }
.tl-block.done .tl-block-title { text-decoration: line-through; }
.tl-block.tl-block-overdue {
  filter: grayscale(22%) saturate(.85);
  outline: 1px dashed rgba(255,255,255,.42);
  outline-offset: -2px;
}
.tl-block.tl-block-overdue .tl-block-title { opacity: .92; }
.tl-block.done { filter: grayscale(72%); }
.tl-block-reminder {
  border: 1px solid rgba(255,255,255,.18);
  box-shadow: 0 2px 10px rgba(0,0,0,.18);
}

/* 日历底部操作栏 */
.cal-bottom-bar {
  flex-shrink: 0;
  position: fixed;
  left: 0;
  right: 0;
  bottom: calc(var(--nav-h) + var(--safe-bottom));
  z-index: 9;
  padding: 10px 18px 12px;
  background: transparent;
  border-top: 0;
  pointer-events: none;
}
.cal-bottom-actions {
  position: relative;
  z-index: 1;
  display: flex;
  gap: 10px;
  align-items: stretch;
  pointer-events: auto;
}
.cal-bottom-actions .cal-bottom-btn {
  flex: 1;
  min-width: 0;
}
.cal-bottom-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 11px 12px;
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--accent-light) 76%, var(--material-raised));
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
  transition: background var(--tr), transform var(--tr), color var(--tr);
  border: 1px solid color-mix(in srgb, var(--accent) 58%, transparent);
  box-shadow: 0 1px 0 rgba(255,255,255,.62) inset, 0 4px 12px rgba(22,25,45,.045);
}
.cal-bottom-btn-secondary {
  background: var(--material-raised);
  color: var(--text);
  border-color: var(--separator);
  font-weight: 600;
}
.cal-bottom-btn:active:not(.cal-bottom-btn-secondary) {
  transform: scale(.97);
  background: var(--accent);
  color: #fff;
}
.cal-bottom-btn-secondary:active {
  transform: scale(.97);
  background: var(--bg4);
  color: var(--text);
}

/* ── 周视图 ── */
.week-header { display: grid; grid-template-columns: 44px repeat(var(--week-day-count, 7),1fr); flex-shrink: 0; border-bottom: 1px solid var(--separator-soft); }
.week-header-cell { text-align: center; padding: 6px 2px; font-size: 11px; color: var(--text3); }
.week-header-cell .wh-date { font-size: 15px; font-weight: 700; width: 27px; height: 27px; display: flex; align-items: center; justify-content: center; border-radius: 50%; margin: 2px auto 0; }
.week-header-cell.today .wh-date { background: var(--accent); color: #fff; }
.week-allday { display: grid; grid-template-columns: 44px repeat(var(--week-day-count, 7),1fr); grid-auto-rows: minmax(26px, auto); border-bottom: 1px solid var(--separator-soft); min-height: 0; align-items: stretch; }
.week-allday[hidden] { display: none; }
.week-allday-label { grid-column: 1; border-left: none; font-size: 10px; color: var(--text3); display: flex; align-items: flex-start; justify-content: flex-end; padding: 6px 6px 0 0; }
.week-allday-col { border-left: 1px solid var(--separator-soft); min-height: 100%; padding: 2px 3px; }
.week-allday-chip { align-self: center; margin: 2px 3px; min-width: 0; cursor: grab; touch-action: none; z-index: 2; }
.week-allday-chip.spanning { border-radius: 8px; }
.week-allday-chip.dragging { opacity: .72; cursor: grabbing; z-index: 8; }
.week-allday-chip.invalid { background: var(--danger-light); color: var(--danger); }
.week-scroll { flex: 1; overflow-y: auto; display: grid; grid-template-columns: 44px 1fr; }
#viewWeek { overscroll-behavior-x: contain; }
.week-time-col { display: flex; flex-direction: column; }
.week-time-slot { height: 32px; display: flex; align-items: flex-start; justify-content: flex-end; padding-right: 8px; font-size: 10px; color: var(--text3); padding-top: 2px; flex-shrink: 0; }
.week-days { display: grid; grid-template-columns: repeat(var(--week-day-count, 7),1fr); position: relative; }
.week-day-col { border-left: 1px solid var(--separator-soft); position: relative; height: 1536px; }
.week-day-col.today { background: color-mix(in srgb, var(--accent-light) 36%, transparent); }
.week-day-col.drag-target {
  background: color-mix(in srgb, var(--accent-light) 62%, transparent);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 34%, transparent);
}
.week-day-col.invalid-target {
  background: color-mix(in srgb, var(--danger-light) 78%, transparent);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--danger) 34%, transparent);
}
/* Full-hour tap targets under task blocks (same role as month cells). */
.week-hour-hit {
  position: absolute;
  left: 0;
  right: 0;
  height: 64px;
  z-index: 1;
  cursor: pointer;
  transition: background var(--tr-fast);
  -webkit-tap-highlight-color: transparent;
}
@media (hover: hover) {
  .week-hour-hit:hover {
    background: color-mix(in srgb, var(--accent-light) 20%, transparent);
  }
}
.week-hour-hit:active {
  background: color-mix(in srgb, var(--accent-light) 30%, transparent);
}
.week-hour-line {
  position: absolute;
  left: 0;
  right: 0;
  border-top: 1px solid var(--separator-soft);
  pointer-events: none;
  z-index: 2;
}
.week-block { position: absolute; left: 3px; right: 3px; border-radius: 7px; padding: 3px 5px; font-size: 10px; font-weight: 600; color: #fff; overflow: hidden; cursor: pointer; z-index: 3; box-shadow: 0 1px 0 rgba(255,255,255,.16) inset, 0 6px 14px rgba(8,9,16,.10); }
/* 周视图时间线 */
.week-now-line { position: absolute; left: 0; right: 0; height: 1.5px; background: var(--accent); z-index: 10; pointer-events: none; box-shadow: none; }
.week-now-dot { position: absolute; left: -4px; top: -4px; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 3px var(--accent-light); }
/* 过去时间遮罩 */
.week-past-mask { display: none; }
/* 可放置区域虚线框 */
.week-drop-zone { position: absolute; left: 1px; right: 1px; border: 1.5px dashed var(--accent); border-radius: 4px; opacity: .2; pointer-events: none; z-index: 2; transition: opacity .2s; }
.week-drop-zone.active { opacity: .6; }
/* 当前时间锚点（拖拽时高亮） */
.week-now-anchor { position: absolute; left: 0; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); opacity: 0; pointer-events: none; z-index: 12; transition: opacity .2s; transform: translateX(-4px); }
.week-now-anchor.active { opacity: 1; }

/* ── 月视图 ── */
.month-weekdays { display: grid; grid-template-columns: repeat(7,1fr); flex-shrink: 0; border-bottom: 1px solid var(--separator-soft); padding: 4px 0; }
.month-weekdays span { text-align: center; font-size: 11px; font-weight: 600; color: var(--text3); padding: 4px 0; }
.month-board {
  flex: 1;
  display: grid;
  overflow-y: auto;
  background: color-mix(in srgb, var(--bg) 82%, var(--bg2) 18%);
}
.month-grid,
.month-span-layer {
  grid-area: 1 / 1;
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  grid-template-rows: repeat(var(--month-week-count, 6), minmax(72px, 1fr));
  min-height: 100%;
}
.month-grid {
  z-index: 1;
}
.month-span-layer {
  z-index: 2;
  pointer-events: none;
}
.month-cell { border-right: 1px solid var(--separator-soft); border-bottom: 1px solid var(--separator-soft); padding: 6px 5px; cursor: pointer; min-height: 72px; position: relative; overflow: hidden; transition: background var(--tr), border-color var(--tr), opacity var(--tr); }
.month-cell:nth-child(7n) { border-right: none; }
.month-cell:hover { background: color-mix(in srgb, var(--accent-light) 24%, var(--bg3)); }
.month-cell.other-month {
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  border-color: color-mix(in srgb, var(--border) 42%, transparent);
}
.month-cell.other-month .mc-num {
  color: color-mix(in srgb, var(--text3) 45%, transparent);
  font-weight: 520;
}
.month-cell.other-month .mc-chip,
.month-cell.other-month .mc-span-bar,
.month-cell.other-month .mc-more {
  opacity: .34;
  filter: saturate(.55);
}
.month-cell.today .mc-num { background: var(--accent); color: #fff; border-radius: 50%; }
.mc-num { font-size: 12px; font-weight: 650; width: 22px; height: 22px; display: flex; align-items: center; justify-content: center; margin-bottom: 1px; color: var(--text); }
.mc-span-bar {
  align-self: start;
  justify-self: stretch;
  min-width: 0;
  height: 16px;
  margin: calc(30px + var(--mc-lane, 0) * 18px) 5px 0;
  padding: 1px 6px;
  border-radius: 6px;
  color: #fff;
  font-size: 10px;
  font-weight: 650;
  line-height: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-align: left;
  text-overflow: ellipsis;
  z-index: 4;
  pointer-events: auto;
}
.mc-span-bar.done { opacity: .32; text-decoration: line-through; filter: grayscale(60%); }
.mc-span-bar.missed { opacity: .48; filter: saturate(.55); }
.mc-chip {
  position: absolute;
  left: 5px;
  right: 5px;
  top: calc(30px + var(--mc-lane, 0) * 18px);
  min-width: 0;
  height: 16px;
  display: block;
  padding: 1px 5px;
  border-radius: 6px;
  color: #fff;
  font-size: 10px;
  font-weight: 650;
  line-height: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-align: left;
  text-overflow: ellipsis;
  z-index: 2;
}
.mc-chip.done { opacity: .32; text-decoration: line-through; filter: grayscale(60%); }
.mc-chip.missed { opacity: .48; filter: saturate(.55); }
.mc-chip.span-start {
  right: -1px;
  border-radius: 6px 0 0 6px;
}
.mc-chip.span-mid {
  left: -1px;
  right: -1px;
  border-radius: 0;
  color: transparent;
  text-shadow: none;
}
.mc-chip.span-end {
  left: -1px;
  border-radius: 0 6px 6px 0;
  color: transparent;
  text-shadow: none;
}
.mc-more {
  position: absolute;
  left: 6px;
  bottom: 4px;
  font-size: 10px;
  color: var(--text3);
  padding-left: 0;
}

/* ============================================================
   时间轴页（右 Tab，独立）
   ============================================================ */
[data-page="timeline"] {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
  --diary-body-x: 14px;
  --diary-body-top: 12px;
  --diary-time-col: 58px;
  --diary-axis-col: 18px;
  --diary-axis-half: 9px;
  --diary-col-gap: 8px;
  --diary-axis-x: calc(var(--diary-body-x) + var(--diary-time-col) + var(--diary-col-gap) + var(--diary-axis-half));
  --diary-left-hit-w: 112px;
  --diary-line-top: calc(var(--page-header-h, 52px) + var(--diary-body-top));
  background-image: linear-gradient(
    to bottom,
    color-mix(in srgb, var(--border) 72%, transparent),
    color-mix(in srgb, var(--border) 72%, transparent)
  );
  background-repeat: no-repeat;
  background-size: 1px calc(100% - var(--diary-line-top));
  background-position: var(--diary-axis-x) var(--diary-line-top);
}

/* 顶部浮动日期（随滚动更新） */
.tl-floating-date {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 20;
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 99px;
  padding: 4px 14px;
  pointer-events: none;
  white-space: nowrap;
  box-shadow: 0 2px 8px rgba(0,0,0,.3);
}

/* 日期分隔标题 */
.tl-day-header {
  position: absolute;
  left: 0; right: 0;
  height: 32px;
  display: flex;
  align-items: center;
  padding-left: 8px;
  background: rgba(23,24,35,.88);
  border-bottom: 1px solid var(--border);
  z-index: 8;
}
.tl-day-header.today { border-bottom-color: var(--accent); }
.tl-day-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--text3);
  letter-spacing: .04em;
}
.tl-day-header.today .tl-day-label { color: var(--accent); }
