:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --text: #1f2430;
  --muted: #8a92a6;
  --line: #e6e8ee;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --danger: #e53935;
  --danger-bg: #fdecea;
  --warn: #ef7f1a;
  --warn-bg: #fff4e6;
  --ok: #2e9e5b;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(16, 24, 40, .06), 0 1px 2px rgba(16, 24, 40, .04);
}

* { box-sizing: border-box; }

/* 保证 hidden 属性始终生效（不被 display 覆盖） */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Segoe UI", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* 顶栏 */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--primary);
  color: #fff;
  padding: calc(env(safe-area-inset-top) + 14px) 16px 14px;
}
.topbar-inner {
  max-width: 640px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.topbar-actions .btn { padding: 8px 10px; white-space: nowrap; }
.title { margin: 0; font-size: 20px; font-weight: 700; }
.subtitle { margin: 4px 0 0; font-size: 13px; opacity: .9; }

/* 按钮 */
.btn {
  border: none;
  border-radius: 10px;
  padding: 9px 14px;
  font-size: 14px;
  cursor: pointer;
  font-family: inherit;
  transition: background .15s, opacity .15s;
}
.btn:active { opacity: .8; }
.btn-primary { background: #fff; color: var(--primary); font-weight: 600; }
.btn-ghost { background: rgba(255,255,255,.18); color: #fff; }
.btn-ghost.plain { background: #eef1f6; color: var(--text); }

/* 月历 */
.calendar {
  max-width: 640px;
  margin: 12px auto 2px;
  padding: 14px 16px 10px;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.calendar-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.calendar-nav, .calendar-title { border: 0; background: transparent; color: var(--text); font-family: inherit; cursor: pointer; }
.calendar-nav { width: 38px; height: 32px; border-radius: 8px; background: #f4f6fb; font-size: 25px; line-height: 1; }
.calendar-title { font-size: 16px; font-weight: 700; padding: 7px 16px; border-radius: 8px; }
.calendar-title:active, .calendar-nav:active { background: #e8eefc; }
.weekdays, .calendar-grid { display: grid; grid-template-columns: repeat(7, 1fr); }
.weekdays { color: var(--muted); font-size: 11px; text-align: center; margin-bottom: 4px; }
.calendar-grid { row-gap: 3px; }
.calendar-blank { min-height: 42px; }
.calendar-day { min-width: 0; min-height: 42px; border: 1px solid transparent; border-radius: 9px; background: transparent; color: var(--text); font-family: inherit; cursor: pointer; padding: 3px 0 2px; display: flex; flex-direction: column; align-items: center; gap: 3px; }
.calendar-day span { display: grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; font-size: 13px; }
.calendar-day.today span { background: #e8eefc; color: var(--primary); font-weight: 700; }
.calendar-day.selected { border-color: var(--primary); background: #f1f5ff; }
.calendar-day b { min-height: 4px; display: flex; gap: 2px; }
.calendar-day b i { display: block; width: 4px; height: 4px; border-radius: 50%; background: var(--ok); }
.calendar-day.soon b i { background: var(--warn); }
.calendar-day.overdue b i { background: var(--danger); }
.calendar-hint { margin: 8px 0 0; color: var(--muted); text-align: center; font-size: 12px; }

/* 筛选 */
.filters {
  max-width: 640px;
  margin: 0 auto;
  padding: 12px 16px 4px;
  display: flex;
  gap: 8px;
  overflow-x: auto;
  white-space: nowrap;
  -webkit-overflow-scrolling: touch;
}
.chip {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--muted);
  padding: 7px 13px;
  border-radius: 999px;
  font-size: 13px;
  cursor: pointer;
}
.chip.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  font-weight: 600;
}

/* 列表 */
.list {
  max-width: 640px;
  margin: 0 auto;
  padding: 10px 16px calc(90px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-left: 4px solid transparent;
}
.card.overdue { border-left-color: var(--danger); }
.card.soon { border-left-color: var(--warn); }
.card.ok { border-left-color: var(--ok); }

.card .icon {
  width: 42px; height: 42px;
  border-radius: 12px;
  background: #f0f3f9;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px;
  flex: 0 0 auto;
}
.card .body { flex: 1 1 auto; min-width: 0; }
.card .name { font-size: 16px; font-weight: 600; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.card .meta { font-size: 13px; color: var(--muted); margin-top: 3px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.card .amount { color: var(--text); font-weight: 600; }
.tag {
  font-size: 11px; padding: 2px 8px; border-radius: 6px;
  background: #eef1f6; color: #5b6472;
}

.badge {
  flex: 0 0 auto;
  font-size: 12px; font-weight: 600;
  padding: 5px 10px; border-radius: 8px;
  text-align: center;
  line-height: 1.2;
}
.badge.overdue { background: var(--danger-bg); color: var(--danger); }
.badge.soon { background: var(--warn-bg); color: var(--warn); }
.badge.ok { background: #e9f7ef; color: var(--ok); }

.card .actions { display: flex; flex-direction: column; gap: 6px; flex: 0 0 auto; }
.mini {
  border: none; border-radius: 8px; padding: 6px 10px;
  font-size: 12px; cursor: pointer; font-family: inherit;
}
.mini.done { background: #e9f7ef; color: var(--ok); }
.mini.edit { background: #eef1f6; color: #5b6472; }
.mini.sync { background: #e8eefc; color: var(--primary); }
.mini.del { background: var(--danger-bg); color: var(--danger); }

/* 空状态 */
.empty {
  max-width: 640px; margin: 60px auto 0; text-align: center;
  color: var(--muted); font-size: 15px; padding: 0 24px;
}
.empty-icon { font-size: 48px; margin-bottom: 10px; }

/* 悬浮按钮 */
.fab {
  position: fixed;
  right: 20px;
  bottom: calc(20px + env(safe-area-inset-bottom));
  width: 58px; height: 58px;
  border-radius: 50%;
  border: none;
  background: var(--primary);
  color: #fff;
  font-size: 30px;
  cursor: pointer;
  box-shadow: 0 6px 16px rgba(37, 99, 235, .4);
  z-index: 20;
}

/* 模态框 */
.modal-mask {
  position: fixed; inset: 0;
  background: rgba(15, 18, 25, .45);
  display: flex; align-items: flex-end; justify-content: center;
  z-index: 30;
}
@media (min-width: 560px) {
  .modal-mask { align-items: center; }
}
.modal {
  background: var(--card);
  width: 100%;
  max-width: 520px;
  border-radius: 18px 18px 0 0;
  padding: 18px 18px calc(18px + env(safe-area-inset-bottom));
  max-height: 90vh;
  overflow-y: auto;
}
@media (min-width: 560px) {
  .modal { border-radius: 18px; padding-bottom: 18px; }
}
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.modal-head h2 { margin: 0; font-size: 18px; }
.modal-head .btn-ghost { background: #eef1f6; color: var(--text); }

.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.field em { color: var(--danger); font-style: normal; }
.field input, .field select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 11px 12px;
  font-size: 15px;
  font-family: inherit;
  background: #fbfcfe;
  color: var(--text);
}
.field input:focus, .field select:focus { outline: 2px solid var(--primary); outline-offset: -1px; border-color: var(--primary); }
.field small { display: block; color: var(--muted); margin-top: 5px; font-size: 12px; line-height: 1.4; }
.row { display: flex; gap: 12px; }
.row .field { flex: 1 1 0; min-width: 0; }
.interval-row { display: flex; gap: 8px; }
.interval-row input { flex: 1.4; min-width: 0; }
.interval-row select { flex: 1; }

.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 6px; }
.modal-actions.start { justify-content: flex-start; flex-wrap: wrap; }
.modal-actions .btn-primary { background: var(--primary); color: #fff; }

/* 使用说明与反馈 */
.data-modal { padding-bottom: calc(22px + env(safe-area-inset-bottom)); }
.guide-section { border-top: 1px solid var(--line); padding: 15px 0 2px; }
.guide-section:first-of-type { border-top: 0; padding-top: 0; }
.guide-section h3 { margin: 0 0 7px; font-size: 15px; }
.guide-section p, .guide-section li { color: #5b6472; font-size: 13px; line-height: 1.6; }
.guide-section p { margin: 0 0 8px; }
.guide-section ol { margin: 0; padding-left: 20px; }
.guide-section code { background: #eef1f6; border-radius: 4px; padding: 1px 4px; }
.room-row { display: flex; gap: 8px; margin-top: 8px; }
.room-row input { flex: 1; min-width: 0; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; font-size: 13px; font-family: inherit; background: #fbfcfe; color: var(--text); }
.room-row input[readonly] { background: #f0f3f9; color: var(--muted); }
.toast { position: fixed; z-index: 50; left: 50%; bottom: calc(94px + env(safe-area-inset-bottom)); transform: translateX(-50%); max-width: calc(100% - 36px); border-radius: 10px; background: rgba(25, 32, 48, .92); color: #fff; padding: 10px 14px; font-size: 13px; text-align: center; box-shadow: 0 6px 18px rgba(0, 0, 0, .2); }

@media (max-width: 560px) {
  .calendar { margin: 10px 12px 0; padding: 13px 12px 9px; }
  .filters { padding-left: 12px; padding-right: 12px; }
  .list { padding-left: 12px; padding-right: 12px; }
  .card { align-items: flex-start; gap: 9px; padding: 12px; }
  .card .icon { width: 38px; height: 38px; font-size: 19px; }
  .card .actions { display: grid; grid-template-columns: repeat(2, auto); gap: 5px; }
  .card .actions .del { grid-column: span 2; }
  .badge { position: absolute; right: 12px; margin-top: 42px; }
  .card { position: relative; padding-right: 110px; }
  .card .actions { position: absolute; right: 12px; top: 12px; }
  .card .meta { padding-right: 2px; }
}
