:root {
  --bg: #f3f5f9;
  --card: #ffffff;
  --text: #1c2430;
  --muted: #6b7686;
  --line: #e3e8ef;
  --blue: #1f6feb;
  --blue-d: #165ac6;
  --blue-soft: #e8f1ff;
  --green: #18a058;
  --red: #d93025;
  --amber: #f0a020;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20, 30, 50, .05), 0 8px 24px rgba(20, 30, 50, .06);
}

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

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

.app {
  max-width: 720px;
  margin: 0 auto;
  padding: calc(12px + env(safe-area-inset-top)) 14px calc(24px + env(safe-area-inset-bottom));
}

/* ---------- 顶栏 ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 4px 2px 14px;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.logo { width: 38px; height: 38px; flex: none; }
.brand h1 { margin: 0; font-size: 19px; font-weight: 700; letter-spacing: .3px; }
.sub { margin: 1px 0 0; font-size: 12.5px; color: var(--muted); }
.status {
  font-size: 12px;
  color: var(--muted);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 10px;
  white-space: nowrap;
}
.status.ok { color: var(--green); border-color: #cdebd9; background: #f2fbf6; }
.status.err { color: var(--red); border-color: #f6d2cf; background: #fff5f4; }

/* ---------- 卡片 ---------- */
.card, .list-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 14px;
  margin-bottom: 14px;
}
.list-card { padding: 6px 0 4px; overflow: hidden; }
.card-head { display: flex; align-items: center; justify-content: space-between; margin: -4px 2px 10px; }
.card-head h2 { margin: 0; font-size: 15.5px; }
.link.small { font-size: 12.5px; padding: 4px 2px; }
.form-card.collapsed form { display: none; }

/* ---------- 表单 ---------- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; flex: 1 1 0; min-width: 0; }
.field > span { font-size: 13px; color: var(--muted); font-weight: 600; }
.field.wide { flex-basis: 100%; }
input[type=text], input[type=date], input[type=time], input[type=password], select, textarea {
  width: 100%;
  font: inherit;
  font-size: 16px; /* 避免 iOS 聚焦放大 */
  color: var(--text);
  background: #f7f9fc;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 11px 12px;
  outline: none;
  transition: border-color .15s, box-shadow .15s, background .15s;
  appearance: none;
  -webkit-appearance: none;
}
textarea { resize: vertical; min-height: 52px; }
input:focus, select:focus, textarea:focus {
  border-color: var(--blue);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(31, 111, 235, .12);
}
.row { display: flex; gap: 10px; align-items: flex-end; }
.date-row { flex-wrap: wrap; }
.date-row .field { flex: 0 0 46%; }
.quick-days { display: flex; gap: 6px; padding-bottom: 13px; flex: 1 1 auto; justify-content: flex-end; }
.chip {
  font: inherit; font-size: 13px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
  border-radius: 999px;
  padding: 6px 11px;
  cursor: pointer;
}
.chip:active { background: var(--blue-soft); }
.chip.on { color: #fff; background: var(--blue); border-color: var(--blue); }

.actions { display: flex; gap: 10px; margin-top: 4px; }
.btn {
  font: inherit;
  font-size: 16px;
  font-weight: 600;
  border-radius: 11px;
  padding: 12px 16px;
  border: 1px solid transparent;
  cursor: pointer;
  flex: 1;
  background: #eef1f6;
  color: var(--text);
  transition: transform .05s, background .15s;
}
.btn:active { transform: scale(.985); }
.btn.primary { background: var(--blue); color: #fff; }
.btn.primary:active { background: var(--blue-d); }
.btn.ghost { background: #fff; border-color: var(--line); color: var(--muted); flex: 0 0 auto; }
.btn.small { font-size: 14px; padding: 9px 13px; flex: 0 0 auto; }
.btn.danger-text { color: var(--red); }
.hint { font-size: 12.5px; color: var(--muted); margin: 10px 2px 0; }
.hint.warn { color: #b06a00; }

/* ---------- 列表 ---------- */
.list-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px 8px;
  gap: 10px;
}
.list-head h2 { margin: 0; font-size: 16px; }
.seg { display: flex; background: #f0f3f8; border-radius: 10px; padding: 3px; }
.seg button {
  font: inherit; font-size: 13px;
  border: 0; background: transparent; color: var(--muted);
  padding: 6px 11px; border-radius: 8px; cursor: pointer;
}
.seg button.on { background: #fff; color: var(--text); font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,.08); }

.event-list { padding: 0 8px 4px; }
.day-group { margin: 6px 0 4px; }
.day-label {
  position: sticky; top: 0; z-index: 1;
  display: flex; align-items: baseline; gap: 8px;
  font-size: 13px; font-weight: 700; color: var(--muted);
  padding: 8px 6px 6px;
  background: linear-gradient(#fff 70%, rgba(255,255,255,0));
}
.day-label .count { font-weight: 400; font-size: 12px; }
.day-label.today { color: var(--blue); }

.ev {
  display: grid;
  grid-template-columns: 62px 1fr 34px;
  gap: 10px;
  align-items: center;
  background: #fff;
  border: 1px solid var(--line);
  border-left: 3px solid var(--blue);
  border-radius: 11px;
  padding: 11px 8px 11px 10px;
  margin: 6px 0;
  cursor: pointer;
}
.ev.allday { border-left-color: var(--amber); }
.ev.memo { border-left-color: var(--green); }
.ev.past { opacity: .55; }
.ev-time { font-size: 13px; font-variant-numeric: tabular-nums; color: var(--muted); line-height: 1.35; }
.ev-time b { display: block; color: var(--text); font-size: 15px; }
.ev-main { min-width: 0; }
.ev-title { font-size: 15.5px; font-weight: 600; word-break: break-word; }
.ev-sub { font-size: 12.5px; color: var(--muted); margin-top: 2px; word-break: break-word; }
.ev-more {
  width: 34px; height: 34px; border-radius: 9px; border: 1px solid var(--line);
  background: #fff; color: var(--muted); font-size: 18px; line-height: 1;
  display: flex; align-items: center; justify-content: center; cursor: pointer;
}
.ev-more:active { background: #f0f3f8; }
.badge {
  display: inline-block; font-size: 11px; font-weight: 600;
  padding: 1px 6px; border-radius: 6px; margin-right: 5px;
  background: var(--blue-soft); color: var(--blue-d);
}
.badge.memo { background: #e7f7ee; color: #137a41; }
.badge.allday { background: #fff4e3; color: #9a6200; }

.empty { text-align: center; color: var(--muted); font-size: 14px; padding: 28px 10px; }

/* ---------- 底部动作面板 / 设置面板 ---------- */
.sheet-mask {
  position: fixed; inset: 0; background: rgba(15, 22, 35, .38);
  z-index: 40; backdrop-filter: blur(1px);
}
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
  background: #f7f9fc;
  border-radius: 18px 18px 0 0;
  padding: 10px 12px calc(12px + env(safe-area-inset-bottom));
  max-width: 720px; margin: 0 auto;
  box-shadow: 0 -8px 30px rgba(0,0,0,.18);
  animation: rise .18s ease-out;
  max-height: 88vh; overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.sheet-tall { max-height: 92vh; }
@keyframes rise { from { transform: translateY(24px); opacity: .6; } to { transform: none; opacity: 1; } }
.sheet-title {
  text-align: center; font-size: 13px; color: var(--muted);
  padding: 8px 10px 10px; word-break: break-word;
  font-weight: 600;
}
.sheet-btn {
  display: block; width: 100%;
  font: inherit; font-size: 16.5px; font-weight: 600;
  background: #fff; color: var(--blue);
  border: 0; border-radius: 12px;
  padding: 15px; margin-bottom: 8px;
  cursor: pointer;
}
.sheet-btn:active { background: #eef3fb; }
.sheet-btn.danger { color: var(--red); }
.sheet-btn.cancel { background: #fff; color: var(--text); }
.sheet-note { font-size: 12px; color: var(--muted); text-align: center; margin: 2px 8px 4px; }
.settings-body { padding: 0 2px; }
.settings-body h3 { font-size: 14.5px; margin: 18px 4px 6px; }
.settings-body h3:first-child { margin-top: 4px; }
.note { font-size: 12.5px; color: var(--muted); margin: 4px 4px 8px; line-height: 1.55; }
.copybox {
  background: #fff; border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; margin: 0 2px 8px;
}
.copybox code { font-size: 12.5px; word-break: break-all; color: var(--text); font-family: ui-monospace, Consolas, monospace; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin: 0 2px 6px; }
.grid2 { display: flex; gap: 10px; flex-wrap: wrap; }
.grid2 .field { flex: 1 1 40%; }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; margin: 2px 4px 10px; }
.check input { width: 18px; height: 18px; }
.result { font-size: 13px; margin: 4px 4px 0; min-height: 18px; word-break: break-word; }
.result.ok { color: var(--green); }
.result.err { color: var(--red); }
.howto { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; margin: 6px 2px 10px; font-size: 13.5px; }
.howto summary { cursor: pointer; color: var(--blue); font-weight: 600; }
.howto ol { margin: 8px 0 4px; padding-left: 20px; color: var(--text); line-height: 1.7; }

/* ---------- 页脚 ---------- */
.foot { text-align: center; font-size: 13px; color: var(--muted); padding: 4px 0 8px; }
.link { font: inherit; font-size: 13px; background: none; border: 0; color: var(--muted); text-decoration: underline; cursor: pointer; padding: 8px 4px; }
.dot { margin: 0 2px; }

/* ---------- 提示 ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(28px + env(safe-area-inset-bottom));
  transform: translate(-50%, 20px);
  background: rgba(24, 32, 45, .92); color: #fff;
  font-size: 14px; padding: 11px 18px; border-radius: 11px;
  max-width: min(86vw, 520px); text-align: center;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
  z-index: 80;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { background: rgba(190, 30, 25, .95); }

@media (max-width: 380px) {
  .date-row .field { flex-basis: 100%; }
  .quick-days { justify-content: flex-start; padding-bottom: 0; }
  .ev { grid-template-columns: 54px 1fr 32px; }
}
