* { box-sizing: border-box; margin: 0; padding: 0; }

.hidden { display: none !important; }


:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --text: #1c1e21;
  --text-dim: #8a8f99;
  --accent: #4f8cff;
  --accent-soft: #e8f0ff;
  --danger: #e5573f;
  --border: #eceef1;
  --cell-selected-bg: #dcebff;
  --tabbar-bg: #ffffff;
  --shadow: 0 1px 4px rgba(0, 0, 0, .06);
  --row-bg: #f2f4f7;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #22262e;
    --card: #2d333d;
    --text: #e7eaf0;
    --text-dim: #8a94a3;
    --accent: #5c96ff;
    --accent-soft: #23344f;
    --danger: #ff6b52;
    --border: #2a3038;
    --cell-selected-bg: #223652;
    --tabbar-bg: #1c2128;
    --shadow: 0 1px 4px rgba(0, 0, 0, .4);
    --row-bg: #161a20;
  }
}

html, body { height: 100%; }
body {
  font-family: system-ui, -apple-system, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}

#app {
  display: flex; flex-direction: column; height: 100%; max-width: 520px; margin: 0 auto;
  padding-top: env(safe-area-inset-top, 0px); /* 避开手机状态栏（edge-to-edge 时生效） */
}

.appbar {
  flex: 0 0 auto;
  padding: 14px 16px 8px;
  display: flex; align-items: center; justify-content: center; position: relative;
}
.appbar-title { font-size: 19px; font-weight: 700; }
.app-date { position: absolute; right: 16px; font-size: 12px; color: var(--text-dim); font-weight: 400; }
/* 顶栏云同步角标（与日期对称，贴左） */
.sync-badge {
  position: absolute; left: 14px; width: 20px; height: 20px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; -webkit-tap-highlight-color: transparent;
}
.sync-badge svg { width: 17px; height: 17px; }
.sync-badge.ok { color: #59a14f; }
.sync-badge.syncing { color: var(--accent); animation: sync-pulse 1.1s ease-in-out infinite; }
.sync-badge.error { color: var(--danger); }
@keyframes sync-pulse { 0%, 100% { opacity: .3; } 50% { opacity: 1; } }

.content {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 8px 12px 14px;
  -webkit-overflow-scrolling: touch;
}
.tab-panel { display: block; }
.tab-panel.hidden { display: none; }

/* ---------- 日历 ---------- */
.calendar-wrap {
  background: var(--card);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 10px 8px 6px;
}
.cal-nav { display: flex; align-items: center; gap: 4px; justify-content: space-between; margin-bottom: 4px; }
.cal-nav button {
  min-width: 36px; height: 36px; border: none; background: transparent;
  color: var(--text); font-size: 18px; border-radius: 8px; cursor: pointer;
}
.cal-nav button:active { background: var(--accent-soft); }
.cal-title { display: flex; gap: 6px; align-items: center; }
.cal-title select {
  appearance: none; -webkit-appearance: none; border: none; background: transparent;
  color: var(--text); font-size: 16px; font-weight: 600; padding: 4px 2px; outline: none;
}
.cal-today-btn {
  width: 100%; border: none; background: transparent; color: var(--accent);
  font-size: 13px; padding: 2px 0 6px; text-align: center; cursor: pointer;
}
.cal-weekdays { display: grid; grid-template-columns: repeat(7, 1fr); }
.cal-weekday { text-align: center; font-size: 12px; color: var(--text-dim); padding: 4px 0; }
.cal-cells { display: grid; grid-template-columns: repeat(7, 1fr); }
.cal-cell {
  min-height: 56px; padding: 3px 2px; display: flex; flex-direction: column;
  align-items: center; gap: 2px; cursor: pointer; border-radius: 8px; position: relative;
}
.cal-cell .cell-num {
  width: 22px; height: 22px; display: flex; align-items: center; justify-content: center;
  font-size: 13px; border-radius: 50%;
}
.cal-cell.today .cell-num { outline: 2px solid var(--accent); outline-offset: -2px; color: var(--accent); font-weight: 600; }
.cal-cell.selected { background: var(--cell-selected-bg); }
.cal-cell.selected .cell-num { background: var(--accent); color: #fff; font-weight: 600; outline: none; }
.cal-cell.selected.today .cell-num { background: var(--accent); color: #fff; outline: none; }
.cal-cell.other-month { opacity: .35; }
.cell-icons {
  display: flex; flex-wrap: wrap; justify-content: center; gap: 2px;
  width: 100%; align-items: flex-start;
}
.cell-ico { position: relative; font-size: 14px; line-height: 1; padding: 1px; }
.ico-count {
  position: absolute; top: -3px; right: -4px; font-size: 9px; font-weight: 700; color: #fff;
  background: var(--danger); border-radius: 7px; padding: 0 3px; min-width: 12px; height: 13px;
  line-height: 13px; text-align: center; font-style: normal;
}
.cell-more { font-size: 10px; color: var(--text-dim); }

/* ---------- 面板 ---------- */
.panel {
  background: var(--card);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 14px;
  margin-top: 12px;
}
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.panel-title { font-size: 15px; font-weight: 600; }
.link-btn { border: none; background: transparent; color: var(--text-dim); font-size: 12px; cursor: pointer; }
.checkin-list { display: flex; flex-direction: column; gap: 8px; }
.checkin-row { display: flex; align-items: center; gap: 10px; background: var(--row-bg); border-radius: 10px; padding: 8px 10px; }
.row-ico {
  width: 36px; height: 36px; border-radius: 9px; display: flex; align-items: center;
  justify-content: center; font-size: 20px; flex: 0 0 auto;
}
.row-name { flex: 1 1 auto; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-edit { border: none; background: transparent; color: var(--text-dim); font-size: 15px; padding: 6px; flex: 0 0 auto; cursor: pointer; }
.row-ctrl { display: flex; align-items: center; gap: 6px; flex: 0 0 auto; }
.num-btn {
  width: 38px; height: 38px; border-radius: 50%; border: none; font-size: 21px; font-weight: 700;
  background: var(--accent-soft); color: var(--accent); line-height: 1; cursor: pointer;
}
.num-btn:active { transform: scale(.92); }
.num-btn.minus { background: var(--row-bg); color: var(--text-dim); }
.num-btn:disabled { opacity: .35; pointer-events: none; }
.row-count { min-width: 34px; text-align: center; font-size: 18px; font-weight: 700; }
.empty-tip { text-align: center; color: var(--text-dim); font-size: 13px; padding: 18px 0; }
.add-btn {
  width: 100%; margin-top: 12px; padding: 12px; border: 1.5px dashed var(--border);
  border-radius: 10px; background: transparent; color: var(--accent); font-size: 14px; font-weight: 600; cursor: pointer;
}
/* 无按下效果 */

/* ---------- 统计 ---------- */
.stats-wrap { background: var(--card); border-radius: 14px; box-shadow: var(--shadow); padding: 14px; }
.stat-mode-tabs { display: flex; background: var(--bg); border-radius: 10px; padding: 3px; gap: 3px; margin-bottom: 10px; }
.stat-mode-tabs button {
  flex: 1; border: none; background: transparent; color: var(--text-dim); padding: 9px 0;
  font-size: 14px; border-radius: 8px; font-weight: 500; cursor: pointer;
}
.stat-mode-tabs button.active { background: var(--card); color: var(--accent); font-weight: 600; box-shadow: var(--shadow); }
.stat-nav { display: flex; align-items: center; justify-content: space-between; margin-bottom: 2px; }
.stat-nav button { border: none; background: transparent; color: var(--text); font-size: 18px; padding: 6px 10px; border-radius: 8px; cursor: pointer; }
.stat-title { font-size: 15px; font-weight: 600; text-align: center; }
.stat-today-btn {
  width: 100%; border: none; background: transparent; color: var(--accent);
  font-size: 13px; padding: 2px 0 10px; text-align: center; cursor: pointer;
}
.chart-box { position: relative; height: 270px; margin-bottom: 8px; }
.chart-box.hidden { display: none; }
.stat-empty { text-align: center; color: var(--text-dim); font-size: 13px; padding: 50px 0; }
.stat-empty.hidden { display: none; }
.stat-items { display: flex; flex-wrap: wrap; gap: 8px; border-top: 1px solid var(--border); padding-top: 12px; }
.stat-item { display: flex; align-items: center; gap: 6px; padding: 6px 10px; background: var(--row-bg); border-radius: 8px; font-size: 13px; cursor: pointer; }
.stat-item input { width: 16px; height: 16px; accent-color: var(--accent); }
.stat-item-ico { font-size: 16px; }
.stat-item-total {
  margin-left: auto; /* 靠右 */
  font-size: 12px; font-weight: 700; color: var(--accent);
  background: var(--accent-soft); border-radius: 8px; padding: 1px 8px;
  white-space: nowrap;
}

/* ---------- 设置 ---------- */
.settings-list { display: flex; flex-direction: column; gap: 8px; }
.setting-row {
  display: flex; align-items: center; gap: 12px; width: 100%; border: none;
  background: var(--row-bg); border-radius: 10px; padding: 14px; font-size: 15px;
  color: var(--text); text-align: left; cursor: pointer;
}
.setting-row:active { opacity: .7; }
.setting-row .setting-icon { font-size: 18px; }
.setting-row.danger { color: var(--danger); }
.data-stats { margin-top: 12px; font-size: 13px; color: var(--text-dim); text-align: center; }

/* ---------- 数据同步 ---------- */
.sync-status-text { font-size: 14px; margin-bottom: 4px; }
.sync-hint { font-size: 12px; color: var(--text-dim); line-height: 1.5; margin-bottom: 12px; }
.sync-form { display: flex; flex-direction: column; gap: 10px; }
.sync-form input {
  width: 100%; border: 1px solid var(--border); background: var(--bg); color: var(--text);
  border-radius: 10px; padding: 11px; font-size: 15px; outline: none;
}
.sync-form input:focus { border-color: var(--accent); }
.sync-enable-btn { padding: 11px 0; border: none; border-radius: 10px; font-size: 14px; font-weight: 600; cursor: pointer; }

/* ---------- 底部导航 ---------- */
.tabbar {
  flex: 0 0 auto; display: flex; background: var(--tabbar-bg);
  border-top: 1px solid var(--border); padding: 6px 0 calc(6px + env(safe-area-inset-bottom));
}
.tab-btn {
  position: relative;
  flex: 1; border: none; background: transparent; color: var(--text-dim);
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: 11px; padding: 4px 0; cursor: pointer;
}
.tab-btn .tab-ico { font-size: 20px; }
.tab-btn.active { color: var(--accent); font-weight: 600; }
/* 有新版本时设置页右上角红点 */
.tab-btn.has-update::after {
  content: ''; position: absolute; top: 1px; right: calc(50% - 15px);
  width: 8px; height: 8px; border-radius: 50%; background: var(--danger);
}

/* ---------- 弹窗 ---------- */
.modal-mask {
  position: fixed; inset: 0; background: rgba(0, 0, 0, .45); z-index: 50;
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal-mask.hidden { display: none; }
.modal {
  background: var(--card); border-radius: 14px; width: 100%; max-width: 380px;
  padding: 18px; box-shadow: 0 8px 30px rgba(0, 0, 0, .25); max-height: 84vh; overflow-y: auto;
}
.modal h3 { font-size: 16px; margin-bottom: 14px; }
.import-msg, .confirm-msg { font-size: 14px; color: var(--text-dim); line-height: 1.6; margin-bottom: 4px; white-space: pre-line; }
.field-label { display: block; font-size: 12px; color: var(--text-dim); margin: 12px 0 6px; }
input[type="text"] {
  width: 100%; border: 1px solid var(--border); background: var(--bg); color: var(--text);
  border-radius: 8px; padding: 10px; font-size: 15px; outline: none;
}
input[type="text"]:focus { border-color: var(--accent); }
.icon-grid { display: grid; grid-template-columns: repeat(8, 1fr); gap: 4px; max-height: 160px; overflow-y: auto; }
.icon-grid button { font-size: 20px; padding: 6px 0; border: 2px solid transparent; background: var(--row-bg); border-radius: 8px; cursor: pointer; }
.icon-grid button.active { background: var(--accent-soft); border-color: var(--accent); }
.color-grid { display: flex; gap: 8px; flex-wrap: wrap; }
.color-grid button { width: 28px; height: 28px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; }
.color-grid button.active { border-color: var(--text); transform: scale(1.1); }
.modal-actions { display: flex; gap: 10px; margin-top: 18px; }
.modal-actions .btn { flex: 1; padding: 11px 0; border: none; border-radius: 10px; font-size: 14px; font-weight: 600; cursor: pointer; }
.btn { background: var(--row-bg); color: var(--text); }
.btn.primary { background: var(--accent); color: #fff; }
.btn.danger { background: #fce8e5; color: var(--danger); }
.modal-actions #item-delete { flex: 0 0 auto; padding: 11px 16px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 110px; transform: translateX(-50%);
  background: rgba(0, 0, 0, .8); color: #fff; padding: 10px 18px; border-radius: 20px;
  font-size: 13px; z-index: 60; max-width: 80%; text-align: center;
}
.toast.hidden { display: none; }
