/* DayFlow — 个人日程 PWA */

:root {
  --bg: #f2f2f7;
  --card: #ffffff;
  --card-2: #ffffff;
  --text: #1c1c1e;
  --text-2: #8a8a8e;
  --text-3: #b0b0b5;
  --sep: rgba(60, 60, 67, 0.14);
  --sep-strong: rgba(60, 60, 67, 0.24);
  --fill: rgba(120, 120, 128, 0.12);
  --fill-2: rgba(120, 120, 128, 0.2);
  --accent: #0a84ff;
  --danger: #ff3b30;
  --tabbar: rgba(249, 249, 249, 0.84);
  --sheet: #ffffff;
  --nav: rgba(249, 249, 249, 0.82);
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.12);
  --hour-h: 64px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --card: #1c1c1e;
    --card-2: #2c2c2e;
    --text: #ffffff;
    --text-2: #98989f;
    --text-3: #6c6c72;
    --sep: rgba(84, 84, 88, 0.55);
    --sep-strong: rgba(120, 120, 128, 0.6);
    --fill: rgba(120, 120, 128, 0.22);
    --fill-2: rgba(120, 120, 128, 0.32);
    --accent: #0a84ff;
    --tabbar: rgba(22, 22, 24, 0.84);
    --sheet: #1c1c1e;
    --nav: rgba(18, 18, 20, 0.82);
    --shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC",
    "Helvetica Neue", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
  -webkit-text-size-adjust: 100%;
}

body { overflow: hidden; }

button, input, select, textarea {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}
button { border: 0; background: none; padding: 0; cursor: pointer; }
input, textarea, select { -webkit-appearance: none; appearance: none; }

#app {
  height: 100%;
  display: flex;
  flex-direction: column;
}

/* ---------- 顶部导航 ---------- */

.nav {
  flex: none;
  padding: calc(env(safe-area-inset-top, 0px) + 8px) 12px 0;
  background: var(--nav);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 0.5px solid var(--sep);
  z-index: 20;
}

.nav-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  height: 46px;
}

.nav-title {
  flex: 1;
  min-width: 0;
  text-align: center;
}
.nav-title h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: 0.2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.nav-title p {
  margin: 1px 0 0;
  font-size: 11px;
  color: var(--text-2);
  font-variant-numeric: tabular-nums;
}

.icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
  background: var(--fill);
  transition: transform 0.15s ease, opacity 0.15s ease;
}
.icon-btn:active { transform: scale(0.92); opacity: 0.7; }
.icon-btn svg { width: 18px; height: 18px; }

.today-btn {
  height: 34px;
  padding: 0 14px;
  border-radius: 17px;
  background: var(--fill);
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
}
.today-btn:active { opacity: 0.6; }

/* 分段控制 */
.seg {
  display: flex;
  gap: 2px;
  padding: 2px;
  margin: 6px auto 8px;
  width: 168px;
  background: var(--fill);
  border-radius: 9px;
}
.seg button {
  flex: 1;
  height: 28px;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  transition: background 0.2s ease, box-shadow 0.2s ease;
}
.seg button.on {
  background: var(--card);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.14);
  font-weight: 600;
}

/* ---------- 主体 ---------- */

main {
  flex: 1;
  min-height: 0;
  position: relative;
  overflow: hidden;
}

.view {
  position: absolute;
  inset: 0;
  display: none;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 96px);
}
.view.on { display: block; }
.view.pad { padding: 12px 12px calc(env(safe-area-inset-bottom, 0px) + 96px); }

/* ---------- 日视图 ---------- */

.day-scroll { padding-top: 6px; }

.time-grid {
  display: grid;
  grid-template-columns: 54px 1fr;
  padding-right: 10px;
}

.hours { position: relative; }
.hour-label {
  height: var(--hour-h);
  position: relative;
}
.hour-label span {
  position: absolute;
  top: -7px;
  right: 8px;
  font-size: 11px;
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.2px;
}
.hour-label:first-child span { top: 2px; }

.col {
  position: relative;
  border-left: 1px solid var(--sep);
  background-image: repeating-linear-gradient(
    to bottom,
    var(--sep) 0,
    var(--sep) 1px,
    transparent 1px,
    transparent var(--hour-h)
  );
}

.events { position: absolute; inset: 0 0 0 0; }

.ev {
  position: absolute;
  padding: 0 2px;
  overflow: hidden;
}
.ev-inner {
  height: 100%;
  border-radius: 9px;
  padding: 5px 7px 5px 8px;
  overflow: hidden;
  border-left: 3px solid var(--c);
  background: var(--c-bg);
  display: flex;
  flex-direction: column;
  gap: 1px;
  transition: transform 0.12s ease;
}
.ev:active .ev-inner { transform: scale(0.98); }
.ev-time {
  font-size: 10.5px;
  color: var(--text-2);
  font-variant-numeric: tabular-nums;
  height: 13px;
  flex: none;
}
.ev-title {
  font-size: 13px;
  font-weight: 600;
  line-height: 1.15;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
}
.ev.small .ev-inner { padding: 2px 6px; }
.ev.small .ev-title { font-size: 12px; -webkit-line-clamp: 1; }
.ev.small .ev-time { display: none; }
.ev-note {
  font-size: 11px;
  color: var(--text-2);
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.now-line {
  position: absolute;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--danger);
  z-index: 5;
  pointer-events: none;
  display: none;
}
.now-line::before {
  content: "";
  position: absolute;
  left: -4px;
  top: -3px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--danger);
}

/* ---------- 周视图 ---------- */

.week-day {
  background: var(--card);
  border-radius: 14px;
  margin: 0 12px 10px;
  padding: 10px 12px;
  border: 0.5px solid var(--sep);
}
.week-day.today {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(10, 132, 255, 0.14);
}
.week-day-head {
  display: flex;
  align-items: baseline;
  gap: 6px;
  margin-bottom: 6px;
}
.week-dow { font-size: 14px; font-weight: 600; }
.week-day.today .week-dow { color: var(--accent); }
.week-date { font-size: 12px; color: var(--text-2); font-variant-numeric: tabular-nums; }
.week-badge {
  margin-left: auto;
  font-size: 11px;
  color: var(--accent);
  font-weight: 600;
}
.week-empty { font-size: 13px; color: var(--text-3); padding: 2px 0 4px; }

.wrow {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 0;
  border-top: 0.5px solid var(--sep);
}
.wrow:first-of-type { border-top: 0; }
.wrow:active { opacity: 0.55; }
.wdot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex: none;
  background: var(--c);
}
.wtime {
  font-size: 12px;
  color: var(--text-2);
  font-variant-numeric: tabular-nums;
  width: 84px;
  flex: none;
}
.wtitle {
  flex: 1;
  font-size: 14px;
  font-weight: 500;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.wbell { color: var(--text-3); display: flex; }
.wbell svg { width: 12px; height: 12px; }

/* ---------- 空状态 ---------- */

.empty {
  text-align: center;
  padding: 46px 30px;
  color: var(--text-2);
}
.empty-icon {
  width: 54px;
  height: 54px;
  border-radius: 16px;
  background: var(--fill);
  color: var(--text-3);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 12px;
}
.empty-icon svg { width: 26px; height: 26px; }
.empty h3 { margin: 0 0 6px; font-size: 15px; color: var(--text); font-weight: 600; }
.empty p { margin: 0; font-size: 13px; line-height: 1.5; }
.empty .link {
  display: inline-block;
  margin-top: 14px;
  color: var(--accent);
  font-size: 14px;
  font-weight: 500;
}

/* ---------- 待办 ---------- */

.composer {
  display: flex;
  gap: 8px;
  align-items: center;
  background: var(--card);
  border-radius: 12px;
  padding: 6px 6px 6px 14px;
  margin-bottom: 16px;
  border: 0.5px solid var(--sep);
}
.composer input {
  flex: 1;
  border: 0;
  background: none;
  outline: none;
  height: 34px;
  font-size: 15px;
}
.composer input::placeholder { color: var(--text-3); }
.composer button {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: var(--accent);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
}
.composer button:active { opacity: 0.7; }
.composer button svg { width: 18px; height: 18px; }

.sec-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-2);
  letter-spacing: 0.4px;
  margin: 18px 4px 8px;
  text-transform: uppercase;
}
.sec-title:first-child { margin-top: 0; }

.todo-list {
  background: var(--card);
  border-radius: 12px;
  overflow: hidden;
  border: 0.5px solid var(--sep);
}
.todo {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-top: 0.5px solid var(--sep);
  min-height: 50px;
}
.todo:first-child { border-top: 0; }
.todo:active { background: var(--fill); }
.check {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1.5px solid var(--text-3);
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: transparent;
  transition: all 0.15s ease;
}
.check svg { width: 12px; height: 12px; }
.todo.done .check {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.todo-body { flex: 1; min-width: 0; }
.todo-title {
  font-size: 15px;
  line-height: 1.3;
  overflow: hidden;
  word-break: break-word;
}
.todo.done .todo-title { color: var(--text-3); text-decoration: line-through; }
.todo-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 3px;
  font-size: 11.5px;
  color: var(--text-2);
}
.todo-meta .tag {
  padding: 1px 6px;
  border-radius: 5px;
  color: #fff;
  font-size: 10.5px;
  font-weight: 600;
}
.todo-meta .due.overdue { color: var(--danger); }
.todo .chev { color: var(--text-3); display: flex; }
.todo .chev svg { width: 16px; height: 16px; }

/* ---------- 设置 ---------- */

.group {
  background: var(--card);
  border-radius: 12px;
  overflow: hidden;
  border: 0.5px solid var(--sep);
  margin-bottom: 18px;
}
.gtitle {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-2);
  letter-spacing: 0.4px;
  margin: 0 4px 8px;
}
.row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  min-height: 48px;
  border-top: 0.5px solid var(--sep);
  width: 100%;
  text-align: left;
  font-size: 15px;
}
.row:first-child { border-top: 0; }
.row:active { background: var(--fill); }
.row .rlabel { flex: 1; }
.row .rval { color: var(--text-2); font-size: 14px; }
.row .chev { color: var(--text-3); display: flex; }
.row .chev svg { width: 16px; height: 16px; }
.row.danger .rlabel { color: var(--danger); }

.color-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex: none;
  background: var(--c);
}

.swatches {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  padding: 4px 0;
}
.swatch {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--c);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  transition: transform 0.12s ease;
}
.swatch svg { width: 14px; height: 14px; opacity: 0; }
.swatch.on svg { opacity: 1; }
.swatch.on { transform: scale(1.06); }

/* ---------- 悬浮按钮 ---------- */

.fab {
  position: fixed;
  right: 18px;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 74px);
  width: 56px;
  height: 56px;
  border-radius: 28px;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 6px 20px rgba(10, 132, 255, 0.38);
  z-index: 30;
  transition: transform 0.15s ease, opacity 0.15s ease;
}
.fab:active { transform: scale(0.92); }
.fab svg { width: 26px; height: 26px; }
.fab.hide { opacity: 0; pointer-events: none; transform: scale(0.8); }

/* ---------- 标签栏 ---------- */

.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: var(--tabbar);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-top: 0.5px solid var(--sep);
  z-index: 25;
}
.tab {
  flex: 1;
  height: 50px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: var(--text-3);
  font-size: 10px;
  font-weight: 500;
  position: relative;
}
.tab svg { width: 22px; height: 22px; }
.tab.on { color: var(--accent); }
.tab .badge {
  position: absolute;
  top: 4px;
  left: 50%;
  margin-left: 6px;
  min-width: 15px;
  height: 15px;
  padding: 0 4px;
  border-radius: 8px;
  background: var(--danger);
  color: #fff;
  font-size: 10px;
  font-weight: 600;
  display: none;
  align-items: center;
  justify-content: center;
}
.tab .badge.on { display: inline-flex; }

/* ---------- 弹层 ---------- */

.backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.28s ease;
  z-index: 40;
}
.backdrop.on { opacity: 1; pointer-events: auto; }

.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  background: var(--sheet);
  border-radius: 16px 16px 0 0;
  transform: translateY(102%);
  transition: transform 0.34s cubic-bezier(0.32, 0.72, 0, 1);
  z-index: 41;
  box-shadow: var(--shadow);
}
.sheet.on { transform: translateY(0); }

.sheet-head {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 10px;
  border-bottom: 0.5px solid var(--sep);
}
.sheet-head h2 { margin: 0; font-size: 16px; font-weight: 600; }
.sheet-head button { font-size: 15px; color: var(--accent); font-weight: 500; }
.sheet-head button.plain { color: var(--text-2); }
.sheet-head button.del { color: var(--danger); }

.sheet-body {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 6px 16px calc(env(safe-area-inset-bottom, 0px) + 16px);
}

.field {
  padding: 10px 0;
  border-bottom: 0.5px solid var(--sep);
}
.field:last-child { border-bottom: 0; }
.field > label {
  display: block;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-2);
  letter-spacing: 0.3px;
  margin-bottom: 6px;
}
.field input[type="text"],
.field input[type="date"],
.field input[type="time"],
.field textarea,
.field select {
  width: 100%;
  border: 0;
  background: var(--fill);
  border-radius: 9px;
  padding: 10px 12px;
  font-size: 15px;
  outline: none;
}
.field textarea { resize: none; min-height: 62px; line-height: 1.4; }
.field input[type="date"],
.field input[type="time"] { min-height: 40px; display: block; }

.two { display: flex; gap: 10px; }
.two > div { flex: 1; min-width: 0; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  height: 32px;
  padding: 0 13px;
  border-radius: 16px;
  background: var(--fill);
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.chip.on { background: var(--accent); color: #fff; }
.chip .cd { width: 7px; height: 7px; border-radius: 50%; background: var(--c); }
.chip.on .cd { background: #fff; }

.chips.tight .chip { height: 30px; padding: 0 10px; font-size: 12.5px; }

.hint {
  font-size: 11.5px;
  color: var(--text-2);
  line-height: 1.45;
  margin: 8px 0 0;
}

/* 提醒横幅 */
.banner {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + 8px);
  left: 12px;
  right: 12px;
  padding: 12px 14px;
  border-radius: 14px;
  background: rgba(28, 28, 30, 0.94);
  color: #fff;
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.28);
  z-index: 60;
  transform: translateY(-140%);
  opacity: 0;
  transition: transform 0.36s cubic-bezier(0.32, 0.72, 0, 1), opacity 0.3s ease;
  display: flex;
  gap: 10px;
  align-items: flex-start;
}
.banner.on { transform: translateY(0); opacity: 1; }
.banner .b-icon {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.14);
  display: flex;
  align-items: center;
  justify-content: center;
  flex: none;
}
.banner .b-icon svg { width: 16px; height: 16px; }
.banner .b-body { flex: 1; min-width: 0; }
.banner .b-title { font-size: 14px; font-weight: 600; }
.banner .b-sub { font-size: 12px; opacity: 0.78; margin-top: 2px; }

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 140px);
  transform: translate(-50%, 12px);
  background: rgba(28, 28, 30, 0.92);
  color: #fff;
  font-size: 13px;
  padding: 9px 16px;
  border-radius: 20px;
  opacity: 0;
  pointer-events: none;
  transition: all 0.25s ease;
  z-index: 70;
  max-width: 86vw;
  text-align: center;
}
.toast.on { opacity: 1; transform: translate(-50%, 0); }

/* 首次引导 */
.guide {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 80;
  display: none;
  flex-direction: column;
  padding: calc(env(safe-area-inset-top, 0px) + 30px) 26px
    calc(env(safe-area-inset-bottom, 0px) + 26px);
}
.guide.on { display: flex; }
.guide h1 { font-size: 26px; margin: 0 0 8px; letter-spacing: -0.3px; }
.guide .lead { color: var(--text-2); font-size: 14px; line-height: 1.55; margin: 0 0 26px; }
.guide ul { list-style: none; padding: 0; margin: 0 0 auto; }
.guide li {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 12px 0;
  border-top: 0.5px solid var(--sep);
  font-size: 14px;
  line-height: 1.45;
}
.guide li .num {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: none;
  margin-top: 1px;
}
.guide .btn-primary {
  height: 48px;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  font-size: 16px;
  font-weight: 600;
}

.btn {
  height: 44px;
  border-radius: 11px;
  background: var(--fill);
  color: var(--text);
  font-size: 15px;
  font-weight: 500;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.btn:active { opacity: 0.65; }
.btn.primary { background: var(--accent); color: #fff; }
.btn.danger { color: var(--danger); }

/* 日视图空提示 */
.day-hint {
  position: sticky;
  top: 0;
  z-index: 6;
  margin: 6px 12px 0;
  padding: 7px 12px;
  border-radius: 10px;
  background: var(--fill);
  color: var(--text-2);
  font-size: 12.5px;
  text-align: center;
}

/* 表单里并排的时间字段 */
.field .two label {
  display: block;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-2);
  letter-spacing: 0.3px;
  margin-bottom: 6px;
}

/* 下拉箭头 */
.field select,
.row select {
  padding-right: 30px !important;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%),
    linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 16px) calc(50% - 2px), calc(100% - 11px) calc(50% - 2px);
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  opacity: 1;
}
.field select { color: var(--text); }

@media (min-width: 600px) {
  .sheet, .tabbar, .fab, .banner, .toast { max-width: 520px; }
  .sheet { left: 50%; right: auto; width: 520px; transform: translate(-50%, 102%); }
  .sheet.on { transform: translate(-50%, 0); }
  .tabbar { left: 50%; transform: translateX(-50%); border-radius: 16px 16px 0 0; }
  .fab { right: calc(50vw - 260px + 18px); }
  .banner, .toast { left: 50%; right: auto; transform: translateX(-50%); }
  .banner { transform: translate(-50%, -140%); }
  .banner.on { transform: translate(-50%, 0); }
}
