:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --ink: #1c1c1e;
  --sub: #8a8a8e;
  --line: #ececef;
  --accent: #3b6fe0;
  --holiday: #e23b3b;
  --makeup: #e08a1e;
  --west: #6741d9;
  --rest: #9aa0a6;
  --radius: 18px;
  --shadow: 0 1px 3px rgba(0,0,0,.04), 0 8px 24px rgba(0,0,0,.05);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.app {
  max-width: 460px;
  margin: 0 auto;
  padding: 14px 14px 28px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* ============ 天气卡（可点击展开 7 天） ============ */
.weather {
  background: linear-gradient(135deg, #eaf1ff 0%, #f6f9ff 100%);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  user-select: none;
  transition: box-shadow .18s ease;
}
.weather:active { box-shadow: 0 1px 3px rgba(0,0,0,.06); }
.wx-emoji { font-size: 40px; line-height: 1; }
.wx-main { flex: 1; min-width: 0; }
.wx-temp { font-size: 28px; font-weight: 700; line-height: 1.1; }
.wx-desc { font-size: 13px; color: var(--sub); margin-top: 2px; }
.wx-meta { text-align: right; font-size: 12px; color: var(--sub); }
.wx-hilo { font-weight: 600; color: var(--ink); }
.wx-hum { margin-top: 4px; }
.wx-city {
  flex: none;
  border-left: 1px solid rgba(59,111,224,.15);
  padding-left: 12px;
}
.wx-city select {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--accent);
  font-size: 14px;
  font-weight: 600;
  padding: 4px 18px 4px 0;
  cursor: pointer;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'><path d='M0 0l5 6 5-6z' fill='%233b6fe0'/></svg>");
  background-repeat: no-repeat;
  background-position: right 0 center;
}

/* 7 天预报 */
.forecast {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px 8px;
  margin-top: -4px;
  animation: fcIn .18s ease;
}
.forecast[hidden] { display: none; }
@keyframes fcIn { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }
.fc-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
}
.fc-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  padding: 4px 0;
}
.fc-day { font-size: 12px; color: var(--sub); white-space: nowrap; }
.fc-item.fc-today .fc-day { color: var(--accent); font-weight: 700; }
.fc-emoji { font-size: 20px; line-height: 1; }
.fc-temp { font-size: 12px; font-weight: 600; white-space: nowrap; }
.fc-temp .lo { color: var(--sub); font-weight: 400; }

/* ============ 月历 ============ */
.cal {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 10px 16px;
}
.cal-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 2px 4px 12px;
}
.nav {
  width: 32px; height: 32px;
  border: none; border-radius: 50%;
  background: var(--bg); color: var(--ink);
  font-size: 20px; line-height: 1; cursor: pointer;
}
.nav:active { background: #e7e8ec; }
.cal-title { flex: 1; text-align: center; font-size: 17px; font-weight: 700; }
.today-btn {
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--accent);
  font-size: 13px;
  padding: 5px 12px;
  border-radius: 999px;
  cursor: pointer;
}
.weekdays, .grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr)); /* minmax(0,1fr)：防止长文本把列撑宽导致网格超出屏幕 */
}
.weekdays span {
  text-align: center;
  font-size: 12px;
  color: var(--sub);
  padding: 6px 0;
}
.weekdays span.we { color: var(--holiday); }

.cell {
  position: relative;
  aspect-ratio: 1 / 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  cursor: pointer;
  user-select: none;
}
.cell .g { font-size: 16px; font-weight: 600; line-height: 1.1; }
.cell .l {
  font-size: 11px; color: var(--sub); margin-top: 3px; line-height: 1;
  transform: scale(.95); transform-origin: center;
  max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* 相邻月份：文字变淡，但背景色同样按状态着色 */
.cell.other .g, .cell.other .l { color: #c7c9ce; }
.cell.other.cn-fest .l, .cell.other.west-fest .l { color: inherit; }

/* 节日分色 */
.cell.cn-fest .l { color: var(--holiday); font-weight: 600; }
.cell.west-fest .l { color: var(--west); font-weight: 600; }

/* 周末红字（调休上班除外） */
.cell.we .g { color: var(--holiday); }
.cell.other.we .g { color: #c7c9ce; }

/* 休息日日期红字 */
.cell.rest .g { color: var(--holiday); }
.cell.other.rest .g { color: #c7c9ce; }

/* 调休上班 */
.cell.makeup .g { color: var(--makeup); }
.cell.makeup .l { color: var(--makeup); }

/* 今天 */
.cell.today { background: rgba(59,111,224,.10); }
.cell.today .g { color: var(--accent); }
.cell.today .l { color: var(--accent); }

/* 选中 */
.cell.sel { outline: 2px solid var(--accent); outline-offset: -2px; }

/* 右上角角标：休 / 班 / 今 */
.cell .tag-top {
  position: absolute;
  top: 2px;
  right: 2px;
  font-size: 9px;
  line-height: 1;
  font-weight: 700;
  color: #fff;
  padding: 2px 3px;
  border-radius: 5px;
  transform: scale(.92);
  transform-origin: top right;
}
.tag-top.hui { background: var(--holiday); }
.tag-top.ban { background: #6b7280; }
.tag-top.jin { background: var(--accent); }

/* 有待办的日期：右下角小蓝点 */
.cell.has-todo::before {
  content: '';
  position: absolute;
  bottom: 5px;
  right: 6px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--accent);
  opacity: .85;
}

/* ============ 农历 + 宜忌 ============ */
.almanac {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 16px 12px;
}
.al-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}
.al-left { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.al-lunar { font-size: 22px; font-weight: 700; letter-spacing: .5px; }
.al-ganzhi { font-size: 12px; color: var(--sub); }
.al-status {
  flex: none;
  font-size: 12px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 999px;
  color: var(--accent);
  background: rgba(59,111,224,.08);
}
.al-status.holiday { color: #fff; background: var(--holiday); }
.al-status.makeup { color: #fff; background: var(--makeup); }
.al-status.rest { color: var(--rest); background: rgba(154,160,166,.14); }

.al-yiji { display: flex; flex-direction: column; gap: 7px; }
.al-row { display: flex; align-items: flex-start; gap: 8px; }
.al-badge {
  flex: none;
  width: 20px; height: 20px;
  border-radius: 6px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; color: #fff;
  margin-top: 1px;
}
.al-badge.yi { background: var(--holiday); }
.al-badge.ji { background: #6b7280; }
.al-list { font-size: 13px; line-height: 1.5; color: var(--ink); }

/* ============ 待办区 ============ */
.todos {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 14px 16px;
}
.todo-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 2px 2px 10px;
}
.todo-head-left { display: flex; align-items: baseline; gap: 6px; }
.todo-title { font-size: 17px; font-weight: 700; }
.todo-count { font-size: 13px; color: var(--sub); }
.add-btn {
  width: 34px; height: 34px;
  border: none; border-radius: 50%;
  background: var(--accent); color: #fff;
  font-size: 22px; line-height: 1;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(59,111,224,.30);
}
.add-btn:active { transform: scale(.94); }
.todo-list { display: flex; flex-direction: column; gap: 8px; }
.todo-empty {
  text-align: center;
  color: var(--sub);
  font-size: 14px;
  padding: 20px 0 16px;
}
.todo-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 12px;
  background: #fafbfc;
  border: 1px solid var(--line);
}
.todo-item.cat-work { border-left: 3px solid #3b6fe0; }
.todo-item.cat-life { border-left: 3px solid #2e9e6b; }
.todo-item.cat-important { border-left: 3px solid #e23b3b; }
.todo-item.cat-note { background: #fffaf0; border-color: #f3e6c8; }
.todo-item.is-note { cursor: pointer; }
.check {
  width: 22px; height: 22px;
  flex: none;
  border-radius: 50%;
  border: 1.5px solid #c7cbd1;
  background: #fff;
  color: #fff;
  font-size: 14px;
  line-height: 1;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  padding: 0;
}
.check.on { background: var(--accent); border-color: var(--accent); }
.note-icon { width: 22px; height: 22px; flex: none; display: flex; align-items: center; justify-content: center; font-size: 15px; }
.todo-body { flex: 1; min-width: 0; }
.todo-text { font-size: 15px; line-height: 1.4; word-break: break-word; white-space: pre-wrap; }
.todo-item.done .todo-text { text-decoration: line-through; color: #b5b8bd; }
.todo-meta { display: flex; gap: 8px; margin-top: 4px; font-size: 12px; color: var(--sub); align-items: center; }
.todo-meta .rep { color: #a0a4aa; }
.del {
  border: none; background: transparent;
  color: #c4c8ce; font-size: 20px; line-height: 1;
  cursor: pointer; padding: 0 2px; flex: none;
}
.del:active { color: #e23b3b; }
.edit {
  border: none; background: transparent;
  color: #c4c8ce; font-size: 15px; line-height: 1;
  cursor: pointer; padding: 0 2px; flex: none;
}
.edit:active { color: var(--accent); }

/* ============ 同步 ============ */
.sync {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 2px 0 4px;
}
.sync-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--accent);
  font-size: 15px;
  font-weight: 600;
  padding: 11px 28px;
  border-radius: 999px;
  box-shadow: var(--shadow);
  cursor: pointer;
}
.sync-btn:active { transform: scale(.97); }
.sync-btn .sync-ic { font-size: 16px; display: inline-block; }
.sync-btn.spinning .sync-ic { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.sync-status { font-size: 12px; color: var(--sub); min-height: 16px; text-align: center; }
.sync-status.err { color: var(--holiday); }
.sync-status.ok { color: #2e9e6b; }

/* ============ 弹层 ============ */
.mask {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.35);
  display: flex; align-items: flex-end; justify-content: center;
  z-index: 50;
}
.mask[hidden] { display: none; }
.sheet {
  width: 100%; max-width: 460px;
  background: var(--card);
  border-radius: 20px 20px 0 0;
  padding: 16px 18px calc(18px + env(safe-area-inset-bottom));
  box-shadow: 0 -8px 30px rgba(0,0,0,.15);
  animation: slideUp .22s ease;
  /* 键盘弹出时视口变矮：限制高度并内部滚动，避免输入框被顶出屏幕 */
  max-height: 86vh;
  max-height: 86dvh;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}
@keyframes slideUp { from { transform: translateY(30px); opacity: .6; } to { transform: none; opacity: 1; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; font-size: 17px; font-weight: 700; margin-bottom: 12px; }
.sheet-close { border: none; background: transparent; font-size: 24px; color: var(--sub); cursor: pointer; line-height: 1; }
.todo-input {
  width: 100%;
  border: 1px solid var(--line);
  background: #fafbfc;
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 15px;
  line-height: 1.5;
  outline: none;
  color: var(--ink);
  font-family: inherit;
  resize: none;
  min-height: 96px;
  max-height: 240px;
}
.todo-input:focus { border-color: var(--accent); background: #fff; }
.shake { animation: shake .35s; }
@keyframes shake { 0%,100% { transform: none; } 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }
.sheet-field { margin-top: 14px; }
.sheet-label { font-size: 13px; color: var(--sub); margin-bottom: 8px; }
.sheet-hint { font-size: 12px; color: var(--sub); margin-top: 6px; text-align: right; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 999px;
  padding: 7px 12px;
  font-size: 13px;
  cursor: pointer;
}
.chip.active { border-color: var(--accent); color: var(--accent); background: rgba(59,111,224,.08); font-weight: 600; }
.sheet-actions { display: flex; gap: 10px; margin-top: 18px; }
.btn-ghost { flex: 1; padding: 12px; border-radius: 12px; border: 1px solid var(--line); background: #fff; color: var(--ink); font-size: 15px; cursor: pointer; }
.btn-primary { flex: 1; padding: 12px; border-radius: 12px; border: none; background: var(--accent); color: #fff; font-size: 15px; font-weight: 600; cursor: pointer; }
.btn-danger { flex: 1; padding: 12px; border-radius: 12px; border: none; background: var(--holiday); color: #fff; font-size: 15px; font-weight: 600; cursor: pointer; }
.del-actions { flex-direction: column; gap: 8px; margin-top: 4px; }
.del-actions .btn-danger, .del-actions .btn-ghost { width: 100%; }
.key-tip { font-size: 13px; color: var(--sub); line-height: 1.5; margin-bottom: 12px; }

/* ============ Toast ============ */
.toast {
  position: fixed;
  left: 50%;
  bottom: 54px;
  transform: translateX(-50%);
  background: rgba(28,28,30,.92);
  color: #fff;
  font-size: 13px;
  line-height: 1.4;
  padding: 10px 16px;
  border-radius: 12px;
  max-width: 82%;
  text-align: center;
  z-index: 80;
  box-shadow: 0 8px 24px rgba(0,0,0,.25);
}
.toast[hidden] { display: none; }

/* ============ 小屏适配（≤360px，如 iPhone SE / 小安卓机） ============ */
@media (max-width: 360px) {
  .app { padding: 10px 10px 24px; gap: 10px; }
  .cal { padding: 12px 6px 14px; }
  .cell .g { font-size: 15px; }
  .cell .l { font-size: 10px; }
  .al-lunar { font-size: 20px; }
  .wx-emoji { font-size: 34px; }
  .wx-temp { font-size: 24px; }
  .todo-input { min-height: 84px; }
}

/* ============ 视图切换 ============ */
.view-switch { display: flex; gap: 6px; padding: 2px 4px 12px; justify-content: flex-end; }
.view-switch button {
  border: 1px solid var(--line); background: #fff; color: var(--sub);
  font-size: 13px; font-weight: 600; padding: 5px 14px; border-radius: 999px; cursor: pointer;
}
.view-switch button.active { border-color: var(--accent); color: var(--accent); background: rgba(59,111,224,.08); }

/* ============ 周视图 ============ */
.week-view { margin-top: 2px; }
.wk-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.wk-col { display: flex; flex-direction: column; min-height: 120px; background: #fafbfc; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.wk-col.today { border-color: var(--accent); }
.wk-col.sel { outline: 2px solid var(--accent); outline-offset: -2px; }
.wk-col.drop-target { background: rgba(59,111,224,.10); border-color: var(--accent); }
.wk-head { padding: 5px 2px 4px; text-align: center; border-bottom: 1px solid var(--line); cursor: pointer; user-select: none; }
.wk-head.holiday { background: rgba(226,59,59,.08); }
.wk-head.makeup { background: rgba(224,138,30,.10); }
.wk-head.rest { background: rgba(154,160,166,.10); }
.wk-d { font-size: 14px; font-weight: 700; }
.wk-w { font-size: 10px; color: var(--sub); }
.wk-l { font-size: 9px; color: var(--sub); transform: scale(.92); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wk-col.today .wk-d { color: var(--accent); }
.wk-list { flex: 1; padding: 4px 3px; display: flex; flex-direction: column; gap: 3px; overflow-y: auto; }
.wk-empty { text-align: center; color: #cfd2d6; font-size: 12px; padding: 6px 0; }
.wk-chip {
  font-size: 10px; line-height: 1.2; padding: 3px 4px; border-radius: 6px; background: #fff;
  border: 1px solid var(--line); cursor: pointer; touch-action: none; user-select: none;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.wk-chip.cat-work { border-left: 3px solid #3b6fe0; }
.wk-chip.cat-life { border-left: 3px solid #2e9e6b; }
.wk-chip.cat-important { border-left: 3px solid #e23b3b; }
.wk-chip.cat-note { background: #fffaf0; border-color: #f3e6c8; }
.wk-chip.done { opacity: .5; text-decoration: line-through; }
.wk-chip.dragging-clone { box-shadow: 0 6px 18px rgba(0,0,0,.18); }

/* ============ 日视图 ============ */
.day-view { margin-top: 2px; }
.day-banner {
  background: linear-gradient(135deg, #eaf1ff 0%, #f6f9ff 100%); border-radius: 14px; padding: 16px;
  display: flex; align-items: center; gap: 14px;
}
.day-banner.holiday { background: linear-gradient(135deg, #fdeaea, #fff); }
.day-banner.makeup { background: linear-gradient(135deg, #fdf2e3, #fff); }
.day-banner.rest { background: linear-gradient(135deg, #eef0f2, #fff); }
.day-big { font-size: 46px; font-weight: 800; line-height: 1; color: var(--accent); }
.day-banner.holiday .day-big { color: var(--holiday); }
.day-sub { font-size: 13px; color: var(--sub); line-height: 1.5; }

/* ============ 今天/逾期聚合 ============ */
.aggr { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px 14px 14px; }
.aggr-head { display: flex; align-items: center; justify-content: space-between; padding: 2px 2px 8px; }
.aggr-title { font-size: 15px; font-weight: 700; }
.aggr-count { font-size: 12px; color: var(--sub); }
.aggr-body { display: flex; flex-direction: column; gap: 6px; max-height: 240px; overflow-y: auto; }
.aggr-empty { text-align: center; color: var(--sub); font-size: 13px; padding: 10px 0; }
.aggr-h { font-size: 12px; color: var(--sub); margin-top: 4px; font-weight: 600; }
.aggr-item { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 10px; background: #fafbfc; border: 1px solid var(--line); cursor: pointer; }
.aggr-item.overdue { background: #fdeaea; border-color: #f3c9c9; }
.aggr-dot { width: 18px; height: 18px; flex: none; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 700; color: #fff; background: var(--accent); }
.aggr-item.overdue .aggr-dot { background: var(--holiday); }
.aggr-tx { flex: 1; min-width: 0; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.aggr-date { flex: none; font-size: 12px; color: var(--sub); }

/* ============ 待办时间标签 ============ */
.todo-time { display: inline-block; font-size: 11px; font-weight: 700; color: var(--accent); background: rgba(59,111,224,.10); border-radius: 6px; padding: 1px 6px; margin-right: 6px; }

/* ============ 语音按钮 + 解析预览 ============ */
.sheet-tools { display: flex; align-items: center; gap: 10px; margin-top: 10px; }
.mic-btn {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--accent); background: rgba(59,111,224,.08); color: var(--accent);
  font-size: 13px; font-weight: 600; padding: 7px 12px; border-radius: 999px; cursor: pointer;
}
.mic-btn:active { transform: scale(.96); }
.mic-btn.recording { background: var(--holiday); border-color: var(--holiday); color: #fff; animation: pulse 1.1s infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .6; } }
.parse-hint { font-size: 12px; color: var(--accent); margin-top: 8px; background: rgba(59,111,224,.07); border-radius: 8px; padding: 6px 10px; }

/* 360 适配：新增组件 */
@media (max-width: 360px) {
  .wk-d { font-size: 13px; }
  .wk-l { font-size: 8px; }
  .wk-chip { font-size: 9px; padding: 2px 3px; }
  .view-switch button { padding: 4px 11px; }
  .day-big { font-size: 38px; }
}
