/* ================================================================
   eCalendar — 移动端万年历样式表
   移动优先 (Mobile First)：默认样式面向手机小屏 (<768px)
   断点：
     ≥768px  —— 平板 (iPad / 大屏手机横屏)
     ≥768px + landscape —— 平板横屏，整页滚动 + 格子最小高度
     ≥768px + portrait  —— 平板纵屏，固定格子最小高度
     ≥1200px —— 桌面端
   ================================================================ */

/* ---------- 全局设计令牌 ---------- */
:root {
  --primary: #2f6bff;        /* 主色：品牌蓝（按钮、选中、时间） */
  --primary-dark: #1e4fd6;   /* 主色按下态 */
  --bg: #f4f6fb;             /* 页面背景：浅灰蓝 */
  --card: #ffffff;           /* 卡片背景（顶栏、月导航、日历容器） */
  --text: #26292f;           /* 主文字色 */
  --text-sub: #8a90a0;       /* 次级文字（农历、元信息、按钮） */
  --line: #eef0f5;           /* 边框/分割线 */
  --danger: #e5484d;         /* 警示色（红色提醒、周末、删除） */
  --today: #ff8a3d;          /* 今日高亮（预留） */
  --radius: 14px;            /* 统一圆角大小 */
}

/* ---------- 全局重置 ---------- */
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { font-size: 16px; }
/* 确保原生 hidden 属性始终生效（弹层组件会自定义 display 属性） */
[hidden] { display: none !important; }

/* ---------- 手机端默认布局（<768px） ---------- */
body {
  /* 优先使用苹方 / 微软雅黑等系统中文字体，避免加载 WebFont */
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue",
    "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  max-width: 520px;                     /* 手机端内容居中，最大宽度限制 */
  margin: 0 auto;
  padding: 0 12px calc(env(safe-area-inset-bottom) + 20px);  /* iPhone 底部安全区留白 */
  min-height: 100vh;
}

/* 顶栏 */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 2px 10px;
}
.app-title { font-size: 20px; font-weight: 700; letter-spacing: 1px; }
.today-info {
  font-size: 12.5px;
  color: var(--text-sub);
  background: var(--card);
  border-radius: 999px;
  padding: 6px 12px;
  box-shadow: 0 1px 4px rgba(30, 60, 120, 0.06);
  max-width: 68%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* 月份导航 */
.month-nav {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--card);
  border-radius: var(--radius);
  padding: 8px 10px;
  box-shadow: 0 2px 8px rgba(30, 60, 120, 0.05);
}
.nav-btn {
  width: 38px; height: 38px;
  border: none; background: var(--bg);
  border-radius: 10px;
  font-size: 22px; line-height: 1; color: var(--text);
  cursor: pointer;
}
.nav-btn:active { background: #e6eaf5; }
.month-label {
  flex: 1; text-align: center;
  font-size: 17px; font-weight: 700;
}
.today-btn {
  border: 1px solid var(--primary);
  color: var(--primary);
  background: #fff;
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 13px;
  cursor: pointer;
}
.today-btn:active { background: #eef3ff; }

/* 日历 */
.calendar-wrap {
  margin-top: 12px;
  background: var(--card);
  border-radius: var(--radius);
  padding: 10px;
  box-shadow: 0 2px 8px rgba(30, 60, 120, 0.05);
}
.week-row {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  text-align: center;
  font-size: 12px;
  color: var(--text-sub);
  padding: 4px 0 8px;
}
.week-row span:nth-child(1),
.week-row span:nth-child(7) { color: var(--danger); }

.day-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  border: 1px solid #d8d3c6;
  border-radius: 8px;
  overflow: hidden;
  background: #d8d3c6;   /* 作为分隔线底色 */
  gap: 1px;
}

/* 方格格子 */
.day-cell {
  position: relative;
  min-height: 58px;
  display: flex;
  flex-direction: column;
  padding: 3px 4px 2px;
  background: #faf9f5;   /* 暖灰白，仿样张 */
  cursor: pointer;
  overflow: hidden;
}
.day-cell:active { background: #efe9dc; }
.day-cell.other-month { opacity: 0.4; }

.cell-head {
  display: flex;
  align-items: baseline;
  gap: 3px;
}
.day-cell .sun {
  font-size: 14px;
  font-weight: 600;
  color: #2b2620;
  line-height: 1.15;
}
.day-cell .moon {
  font-size: 8.5px;
  color: #8a6f5c;        /* 红棕小字 */
  white-space: nowrap;
  overflow: hidden;
  max-width: 70%;
}
.day-cell .moon.fest { color: var(--danger); }
.day-cell .moon.jieqi { color: var(--primary); }

/* 周末/节日日期红色 */
.day-cell.weekend .sun,
.day-cell.festival .sun { color: #c0392b; }
/* 今天：蓝色加粗（仿样张），并带浅蓝底色 */
.day-cell.today { background: #e8f0ff; }
.day-cell.today .sun { color: var(--primary); font-weight: 700; }

/* 选中日期 */
.day-cell.selected { background: #cfe0ff; }
.day-cell.selected .sun { color: var(--primary); font-weight: 700; }

/* 格子内备忘标题：紧贴日期头部向下排列，空白在底部 */
.day-cell .evts {
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.day-cell .evt {
  font-size: 9px;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: #3d4657;
  background: #e8edf7;
  border-radius: 3px;
  padding: 0 3px;
  display: flex;
  align-items: center;
  gap: 3px;
}
.day-cell .evt .evt-time {
  color: var(--primary);
  font-weight: 600;
  flex: 0 0 auto;
  /* 手机端（<768px）不显示时间，只显示标题，节省格子空间 */
  display: none;
}
.day-cell .evt .evt-title {
  flex: 1 1 auto;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.day-cell .evt.remind { background: #fbe3e3; color: #c0392b; }
.day-cell .evt.remind .evt-time { color: #c0392b; }
.day-cell .evt.more { background: none; color: var(--text-sub); text-align: right; }

.required { color: var(--danger); font-weight: 700; }

.event-item {
  background: var(--card);
  border-radius: 12px;
  padding: 10px 12px;
  box-shadow: 0 1px 4px rgba(30, 60, 120, 0.05);
  cursor: pointer;
  border-left: 4px solid var(--primary);
}
.event-item.has-remind { border-left-color: var(--danger); }
.event-item .e-title { font-size: 14px; font-weight: 600; }
.event-item .e-meta { font-size: 12px; color: var(--text-sub); margin-top: 3px; }
.event-item .e-content {
  font-size: 12.5px; color: #5a6070;
  margin-top: 4px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.foot {
  text-align: center;
  color: #b6bac6;
  font-size: 11.5px;
  margin-top: 18px;
}

/* 弹层 */
.overlay {
  position: fixed; inset: 0;
  background: rgba(10, 16, 32, 0.45);
  z-index: 90;
}
.sheet {
  position: fixed;
  left: 50%; bottom: 0;
  transform: translateX(-50%);
  width: 100%;
  max-width: 520px;
  background: var(--card);
  border-radius: 20px 20px 0 0;
  padding: 10px 16px calc(env(safe-area-inset-bottom) + 18px);
  z-index: 100;
  max-height: 88vh;
  overflow-y: auto;
  box-shadow: 0 -6px 24px rgba(10, 20, 50, 0.15);
  animation: slideUp 0.22s ease;
}
@keyframes slideUp {
  from { transform: translate(-50%, 40px); opacity: 0; }
  to { transform: translate(-50%, 0); opacity: 1; }
}
.sheet-handle {
  width: 40px; height: 4px;
  background: #dde1ea;
  border-radius: 4px;
  margin: 4px auto 10px;
}
.sheet-head { display: flex; align-items: flex-end; gap: 10px; padding-bottom: 10px; }
.sheet-date { font-size: 22px; font-weight: 700; }
.sheet-lunar { font-size: 13px; color: var(--text-sub); padding-bottom: 3px; flex: 1; }
.close-btn {
  border: none; background: var(--bg);
  width: 32px; height: 32px; border-radius: 50%;
  font-size: 18px; color: var(--text-sub);
  cursor: pointer;
}

.day-events { list-style: none; display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.day-events .empty { color: var(--text-sub); font-size: 13px; padding: 4px 0 8px; }

/* 详情视图：添加备忘按钮 */
.add-btn {
  width: 100%;
  border: 1px dashed var(--primary);
  color: var(--primary);
  background: #f2f6ff;
  border-radius: 12px;
  padding: 13px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
.add-btn:active { background: #e4ecff; }

/* 表单视图：返回头 */
.form-head {
  display: flex;
  align-items: center;
  gap: 10px;
}
.form-title {
  flex: 1;
  text-align: center;
  font-size: 16px;
  font-weight: 700;
}
.back-btn {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text-sub);
  border-radius: 10px;
  padding: 8px 14px;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
}
.back-btn:active { background: var(--bg); }

/* 表单 */
.event-form { display: flex; flex-direction: column; gap: 10px; }
.field input[type="text"],
.field textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 15px;
  font-family: inherit;
  background: #fafbfe;
  outline: none;
}
.field input:focus, .field textarea:focus { border-color: var(--primary); background: #fff; }

/* 日期范围 */
.range-inputs { display: flex; gap: 10px; }
.range-item { flex: 1; }
.range-item label {
  display: block;
  font-size: 12px;
  color: var(--text-sub);
  margin-bottom: 4px;
}
.range-item input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 10px;
  font-size: 14px;
  background: #fafbfe;
  outline: none;
}
.range-item input:focus { border-color: var(--primary); background: #fff; }

/* 重复星期 chips */
.wd-label { font-size: 13px; color: var(--text-sub); margin-bottom: 6px; }
.chips { display: flex; gap: 6px; }
.chip {
  flex: 1;
  height: 34px;
  border: 1px solid var(--line);
  background: #fafbfe;
  border-radius: 8px;
  font-size: 14px;
  color: var(--text-sub);
  cursor: pointer;
}
.chip.on {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  font-weight: 600;
}
.chip:active { transform: scale(0.95); }
.hint {
  margin-top: 6px;
  font-size: 11.5px;
  color: #9aa0ae;
  line-height: 1.5;
}

.remind-field {
  display: flex; flex-direction: column; gap: 4px;
}
.remind-field label,
.time-field label { font-size: 13px; color: var(--text-sub); }
.time-field { display: flex; flex-direction: column; gap: 4px; }
.time-input-row {
  display: flex; align-items: center; gap: 8px;
}
.time-input-row input {
  flex: 1;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 10px;
  font-size: 14px;
  background: #fafbfe;
  outline: none;
}
.time-input-row input:focus { border-color: var(--primary); background: #fff; }

/* 标题行：标题 + 时间 chips */
.title-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.title-row input[type="text"] {
  flex: 1;
  min-width: 0;
}
.time-chips {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}
.time-chip {
  display: flex;
  align-items: center;
  gap: 3px;
  border: 1px solid var(--line);
  background: #fafbfe;
  border-radius: 8px;
  padding: 5px 7px;
  cursor: pointer;
  transition: all 0.15s;
}
.time-chip:active { background: #e4ecff; border-color: var(--primary); }
.time-chip .chip-label {
  font-size: 10px;
  color: var(--text-sub);
  font-weight: 600;
}
.time-chip .chip-value {
  font-size: 13px;
  font-weight: 700;
  color: var(--primary);
  letter-spacing: 0.5px;
}
.time-chip .chip-value.empty {
  color: #c0c6d4;
  font-weight: 500;
}

/* 提醒显示 */
.remind-display {
  width: 100%;
  border: 1px solid var(--line);
  background: #fafbfe;
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 15px;
  color: var(--primary);
  cursor: pointer;
  text-align: left;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.remind-display::after {
  content: "›";
  color: var(--text-sub);
  font-size: 18px;
}
.remind-display:active { background: #eef3ff; }
.remind-display.no-remind { color: var(--text-sub); }

/* 时间选择弹窗 */
.time-picker-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 16, 32, 0.45);
  z-index: 150;
  animation: fadeIn 0.2s ease;
}
.time-picker-sheet {
  position: fixed;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: 100%;
  max-width: 520px;
  background: var(--card);
  border-radius: 20px 20px 0 0;
  z-index: 160;
  padding: 12px 20px calc(env(safe-area-inset-bottom) + 20px);
  animation: slideUp 0.22s ease;
  box-shadow: 0 -6px 24px rgba(10, 20, 50, 0.15);
}
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.tp-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.tp-title {
  font-size: 16px;
  font-weight: 700;
}
.tp-btn {
  border: none;
  background: none;
  font-size: 15px;
  cursor: pointer;
  padding: 8px 12px;
  border-radius: 8px;
}
.tp-cancel { color: var(--text-sub); }
.tp-cancel:active { background: var(--bg); }
.tp-confirm { color: var(--primary); font-weight: 600; }
.tp-confirm:active { background: #eef3ff; }

.tp-wheel-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0;
  height: 180px;
  background: #f8f9fc;
  border-radius: 14px;
  position: relative;
}
.tp-wheel-wrap::before,
.tp-wheel-wrap::after {
  content: "";
  position: absolute;
  left: 12px;
  right: 12px;
  height: 36px;
  pointer-events: none;
}
.tp-wheel-wrap::before {
  top: 50%;
  transform: translateY(-50%);
  border-top: 1px solid #dde4f0;
  border-bottom: 1px solid #dde4f0;
  height: 34px;
  background: rgba(255,255,255,0.4);
}

.tp-wheel {
  flex: 1;
  height: 100%;
  overflow-y: scroll;
  scroll-snap-type: y mandatory;
  -webkit-overflow-scrolling: touch;
  max-height: 180px;
  position: relative;
}
.tp-wheel::-webkit-scrollbar { display: none; }

.tp-wheel .tp-item {
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  color: var(--text-sub);
  scroll-snap-align: center;
  cursor: pointer;
  transition: color 0.15s, font-weight 0.15s;
  user-select: none;
}
.tp-wheel .tp-item.active {
  color: var(--primary);
  font-weight: 700;
}
.tp-wheel .tp-item.empty-slot { visibility: hidden; }

.tp-sep {
  font-size: 24px;
  font-weight: 700;
  color: var(--text-sub);
  flex-shrink: 0;
}

.tp-quick-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}
.tp-quick {
  flex: 1;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 13px;
  cursor: pointer;
}
.tp-quick:active { background: var(--bg); }

/* 响应式 - 平板/桌面 */
@media (min-width: 768px) {
  .time-picker-sheet {
    left: 50%;
    top: 50%;
    bottom: auto;
    transform: translate(-50%, -50%);
    width: 360px;
    border-radius: 18px;
    padding: 18px 20px;
    animation: fadeScale 0.22s ease;
  }
}

.mini-btn {
  border: none; background: var(--bg);
  color: var(--text-sub);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 12.5px;
  cursor: pointer;
  white-space: nowrap;
}
.form-actions { display: flex; gap: 10px; }
.save-btn {
  flex: 1;
  border: none;
  background: var(--primary);
  color: #fff;
  border-radius: 12px;
  padding: 12px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
.save-btn:active { background: var(--primary-dark); }
.delete-btn {
  border: none; background: none;
  color: var(--danger);
  font-size: 13px;
  padding: 6px 8px;
  margin-left: auto;
  cursor: pointer;
  align-self: center;
}

/* 提示 */
.toast {
  position: fixed;
  left: 50%; bottom: 60px;
  transform: translateX(-50%);
  background: rgba(20, 26, 42, 0.92);
  color: #fff;
  font-size: 14px;
  border-radius: 999px;
  padding: 10px 18px;
  z-index: 200;
  max-width: 86%;
  text-align: center;
  animation: fadeInUp 0.25s ease;
}
@keyframes fadeInUp {
  from { transform: translate(-50%, 12px); opacity: 0; }
  to { transform: translate(-50%, 0); opacity: 1; }
}

/* ================= 响应式适配 ================= */
/* 平板及以上公共样式（字体大小、弹层等，不区分横纵屏） */
@media (min-width: 768px) {
  .app-title { font-size: 24px; }
  .today-info { font-size: 14px; }
  .month-label { font-size: 20px; }
  .week-row { font-size: 14px; }
  .calendar-wrap { padding: 14px; }
  .day-cell .sun { font-size: 19px; }
  .day-cell .moon { font-size: 11px; }
  .day-cell .evt { font-size: 11px; padding: 1px 4px; }
  /* 平板及以上：格子内显示起始时间 */
  .day-cell .evt .evt-time { display: inline; }

  /* 弹层改为居中对话框 */
  .sheet {
    left: 50%; top: 50%; bottom: auto;
    transform: translate(-50%, -50%);
    width: 500px;
    max-width: calc(100vw - 40px);
    border-radius: 18px;
    max-height: 84vh;
    animation: fadeScale 0.22s ease;
  }
  .sheet-handle { display: none; }
}

/* 平板横屏（768px ≤ 宽 < 1200px）：整页统一滚动 + 格子最小72px高度，内容一起滚动不置顶 */
@media (min-width: 768px) and (max-width: 1199px) and (orientation: landscape) {
  html { overflow-y: auto; scrollbar-width: none; }
  html::-webkit-scrollbar { display: none; }
  body {
    max-width: 760px;
    padding: 0 20px calc(env(safe-area-inset-bottom) + 20px);
    min-height: 100vh;
  }
  .topbar { padding: 10px 2px 6px; }
  .month-nav { padding: 6px 10px; }
  .calendar-wrap { margin-top: 8px; }
  .day-grid {
    overflow: visible;
    grid-auto-rows: minmax(72px, auto);  /* 每行 >= 72px（约4-5字符高），高度由内容决定 */
  }
  .day-cell {
    min-height: 72px;
    padding: 4px 6px 3px;
  }
  .foot { margin-top: 8px; }
}

/* 平板及以上 + 纵屏：原来的滚动模式，格子用固定最小高度 */
@media (min-width: 768px) and (orientation: portrait) {
  body { max-width: 760px; padding: 0 20px 40px; min-height: 100vh; }
  .day-cell { min-height: 92px; padding: 5px 6px 4px; }
}

/* 电脑（>=1200px）：放大字体和间距，适合大显示器 */
@media (min-width: 1200px) {
  body { max-width: 1180px; }
  .calendar-wrap { padding: 18px; }
  .day-cell { padding: 6px 8px 5px; }
  .day-cell .sun { font-size: 24px; }
  .day-cell .moon { font-size: 12px; }
  .day-cell .evt { font-size: 12px; padding: 2px 5px; }
}

/* 电脑（>=1200px）+ 横屏：恢复完整填满视口 + 格子等高均分，下面不留空白 */
@media (min-width: 1200px) and (orientation: landscape) {
  html { overflow-y: auto; scrollbar-width: none; }
  html::-webkit-scrollbar { display: none; }
  body {
    height: var(--vh, 100dvh);   /* 精确填满视口，用 JS --vh 修正 Firefox/Safari 偏差 */
    display: flex;
    flex-direction: column;
    overflow: hidden;            /* 整屏按比例缩放，不让滚动条出现 */
  }
  .topbar       { flex: 0 0 auto; padding: 10px 2px 6px; }
  .month-nav    { flex: 0 0 auto; padding: 6px 10px; }
  .calendar-wrap{
    flex: 1 1 0;                /* 占据剩余所有高度 */
    display: flex;
    flex-direction: column;
    overflow: hidden;
    margin-top: 8px;
    /* 保留 1200px 段的 padding:18px（本块未覆盖即继承） */
  }
  .day-grid {
    flex: 1 1 0;
    overflow: hidden;
    grid-auto-rows: 1fr;        /* 6 行完全均分剩余高度，每行等高 */
  }
  .day-cell {
    min-height: 0;              /* 允许 grid 严格按比例压缩，避免溢出 */
    /* 保留 1200px 段的 padding:6px 8px 5px */
  }
  .foot { flex: 0 0 auto; margin-top: 8px; }
}

@keyframes fadeScale {
  from { opacity: 0; transform: translate(-50%, -50%) scale(0.96); }
  to { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}
