/* ================================================================
 * style.css —— 页面的「长相」
 * ----------------------------------------------------------------
 * 手机优先设计：先按手机屏幕排版，宽屏（电脑）时自动限宽居中。
 * 颜色都写在最上面的变量里，想换配色只改这几行。
 * ================================================================ */

:root {
  /* 三色原则：米白 = 纸，生长绿 = 收入/主操作，暖橙 = 支出 */
  --bg: #f7f4ec;           /* 页底：米白，像纸 */
  --card: #fffdf8;         /* 卡片：比纸再白一点 */
  --text: #2b2a26;         /* 墨字，偏暖的黑 */
  --text-2: #6b6862;
  --text-3: #9c978e;
  --line: #e6e1d5;         /* 分隔线：纸的折痕 */

  --primary: #4e7b3c;      /* 主色：深一点的嫩芽绿（按钮/文字都要够深才看得清） */
  --primary-soft: #e9f1dd; /* 浅嫩芽绿：标签底、软提示 */
  --on-primary: #fffdf8;   /* 主色按钮上的文字 */
  --seg-active: #fffdf8;   /* 支出/收入 切换里选中的那一块 */
  --leaf: #8cc084;         /* 装饰用亮嫩芽绿：空状态插画、点缀 */
  --expense: #c2410c;      /* 支出：文字橙（白底 4.7:1，达标注） */
  --expense-soft: #fbe9dc; /* 支出的软底 */
  --income: #4e7b3c;       /* 收入：生长绿 */

  /* 数据安全提示条：出问题时用的「危险色」 */
  --danger-bg: #fff1f2;
  --danger-line: #fecdd3;
  --danger-text: #9f1239;

  --radius: 18px;
  --shadow: 0 1px 0 rgba(80, 60, 20, 0.04), 0 2px 8px rgba(80, 60, 20, 0.05);
  --shadow-sm: 0 1px 2px rgba(80, 60, 20, 0.06);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  /* 品牌字（启动页 / 空状态里的「芽记」「吾卷」）：书卷气，只用在品牌行，不用于正文 */
  --font-brand: Georgia, "Songti SC", "Noto Serif CJK SC", "Times New Roman", serif;
}

/* 系统是深色模式时，自动换一套暗色配色（墨褐纸 + 亮嫩芽绿） */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15140f;
    --card: #201e17;
    --text: #ede9df;
    --text-2: #a8a296;
    --text-3: #7e786c;
    --line: #2e2b23;
    --primary: #9cc98a;
    --primary-soft: #2a3320;
    --on-primary: #16200f;  /* 深色模式下按钮上必须用深色字，否则看不清 */
    --seg-active: #2c3324;
    --leaf: #7fb069;
    --expense: #f0a070;
    --expense-soft: #36241a;
    --income: #9cc98a;
    --danger-bg: #2b1419;
    --danger-line: #7f1d2d;
    --danger-text: #fecdd3;
    --shadow: 0 1px 0 rgba(0, 0, 0, 0.35), 0 2px 8px rgba(0, 0, 0, 0.25);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  }
}

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

html,
body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", sans-serif;
  font-size: 15px;
  line-height: 1.5;
  /* 给底部工具条 + 悬浮按钮留出空间，否则最后一条会被挡住 */
  padding-bottom: calc(130px + var(--safe-bottom));
}

button {
  font-family: inherit;
  font-size: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

/* 输入框字号 16px 是关键：小于 16px 时，iOS 会自动放大页面 */
input {
  font-family: inherit;
  font-size: 16px;
  color: var(--text);
}

/* ---------------- 顶部月份栏（吸顶） ---------------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  max-width: 560px;
  margin: 0 auto;
  padding: 8px 16px 10px;
  background: var(--bg);
}

/* 让吸顶区域和内容之间有分隔感 */
.topbar::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 1px;
  background: var(--line);
}

.monthbar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.navbtn {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  color: var(--text-2);
  font-size: 22px;
  line-height: 1;
  display: grid;
  place-items: center;
  transition: background 0.15s;
}

.navbtn:active {
  background: var(--line);
}

.monthlabel {
  font-size: 16px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 10px;
}

.monthlabel:active {
  background: var(--line);
}

/* 本月汇总：跟着内容一起滚，不再固定占着屏幕 */
.summary-block {
  padding: 14px 0 4px;
}

.summary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  background: var(--card);
  border: 1px solid var(--line);   /* 米白底上的浅卡片，靠描边分层，不靠重投影 */
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 15px 8px;
}

.sum {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.sum-k {
  font-size: 12px;
  color: var(--text-2);
}

.sum-v {
  font-size: 17px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.2px;
}

.expense {
  color: var(--expense);
}

.income {
  color: var(--income);
}

.sum-count {
  text-align: center;
  font-size: 12px;
  color: var(--text-3);
  padding-top: 8px;
}

/* ---------------- 数据安全提示条 ---------------- */
/* 平时 hidden，只有 app.js 判断「数据可能保不住」时才会露出来 */

.store-warn {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  max-width: 528px;
  margin: 12px auto 0;
  padding: 12px 14px;
  border-radius: 14px;
  background: var(--primary-soft);
  color: var(--text);
  font-size: 13px;
  line-height: 1.55;
  box-shadow: var(--shadow-sm);
}

/* 浏览器给的 [hidden] 会被上面的 display:flex 覆盖，所以要显式写一条 */
.store-warn[hidden] {
  display: none;
}

/* 真出问题（存不了 / 账没了）用红色；只是「很久没备份」保持青绿 */
.store-warn.is-danger {
  background: var(--danger-bg);
  color: var(--danger-text);
  box-shadow: inset 0 0 0 1px var(--danger-line);
}

.store-warn-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
  min-width: 0;
}

.store-warn-title {
  font-size: 13.5px;
}

.store-warn-body {
  color: var(--text-2);
}

.store-warn.is-danger .store-warn-body {
  color: inherit;
  opacity: 0.85;
}

.store-warn-close {
  flex: none;
  width: 24px;
  height: 24px;
  line-height: 1;
  border-radius: 8px;
  color: var(--text-3);
  font-size: 13px;
}

.store-warn.is-danger .store-warn-close {
  color: inherit;
  opacity: 0.7;
}

/* ---------------- 页面主体 ---------------- */

.page {
  max-width: 560px;
  margin: 0 auto;
  padding: 0 16px;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 16px;
}

/* 编辑状态给个边框提示，让用户知道正在改旧账 */
.card.is-editing {
  outline: 2px solid var(--primary);
  outline-offset: -2px;
}

/* 支出/收入 切换 */
.seg {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  background: var(--bg);
  border-radius: 12px;
  padding: 4px;
  margin-bottom: 12px;
}

.seg-btn {
  padding: 8px 0;
  border-radius: 9px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-2);
  transition: all 0.15s;
}

.seg-btn.is-active {
  background: var(--seg-active);
  color: var(--text);
  box-shadow: 0 1px 3px rgba(80, 60, 20, 0.12);
}

.seg-btn[data-type="expense"].is-active {
  color: var(--expense);
}

.seg-btn[data-type="income"].is-active {
  color: var(--income);
}

/* 金额输入 */
.amount-row {
  display: flex;
  align-items: baseline;
  gap: 6px;
  padding: 2px 4px 12px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 12px;
}

.currency {
  font-size: 22px;
  font-weight: 600;
  color: var(--text-2);
}

.amount-input {
  flex: 1;
  min-width: 0;
  border: none;
  outline: none;
  background: transparent;
  font-size: 32px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.5px;
  padding: 0;
}

.amount-input::placeholder {
  color: var(--text-3);
  font-weight: 500;
}

/* 分类按钮：5 列网格，10 个分类正好两行 */
.cats {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
  margin-bottom: 12px;
}

.cat {
  padding: 9px 2px;
  border-radius: 10px;
  background: var(--bg);
  color: var(--text-2);
  font-size: 13px;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: all 0.15s;
}

.cat.is-active {
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 650;
}

.cat:active {
  transform: scale(0.96);
}

/* 日期 + 备注 一行 */
.row2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 12px;
}

.input {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--bg);
  border-radius: 10px;
  padding: 10px 12px;
  outline: none;
  transition: border-color 0.15s;
}

.input:focus {
  border-color: var(--primary);
}

.input::placeholder {
  color: var(--text-3);
}

/* 主按钮 */
.primary {
  width: 100%;
  padding: 14px;
  border-radius: 14px;
  background: var(--primary);
  color: var(--on-primary);
  font-size: 16px;
  font-weight: 650;
  letter-spacing: 0.5px;
  transition: opacity 0.15s, transform 0.12s;
}

/* 按下去轻轻回弹：给「记完了」一点手感，但不做花哨动画 */
.primary:active {
  opacity: 0.88;
  transform: scale(0.98);
}

.ghost {
  width: 100%;
  padding: 10px;
  border-radius: 12px;
  color: var(--text-2);
  font-size: 14px;
  margin-top: 6px;
}

.form-msg {
  margin: 8px 0 0;
  min-height: 18px;
  font-size: 13px;
  color: var(--expense);
  text-align: center;
}

.is-hidden {
  display: none !important;
}

/* ---------------- 账目列表 ---------------- */

.list {
  padding-bottom: 8px;
}

.daygroup + .daygroup {
  margin-top: 14px;
}

.dayhead {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 0 6px 6px;
  font-size: 12px;
  color: var(--text-3);
}

.dayhead .day-sum {
  font-variant-numeric: tabular-nums;
}

.records {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.record {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  cursor: pointer;
  transition: background 0.12s;
}

.record + .record {
  border-top: 1px solid var(--line);
}

.record:active {
  background: var(--bg);
}

.rec-tag {
  flex: none;
  padding: 4px 9px;
  border-radius: 8px;
  background: var(--bg);
  color: var(--text-2);
  font-size: 12px;
  max-width: 88px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.rec-note {
  flex: 1;
  min-width: 0;
  color: var(--text-2);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.rec-amount {
  flex: none;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  font-size: 16px;
}

.rec-del {
  flex: none;
  width: 32px;
  height: 32px;
  border-radius: 9px;
  color: var(--text-3);
  font-size: 15px;
  display: grid;
  place-items: center;
}

.rec-del:active {
  background: rgba(194, 65, 12, 0.14);
  color: var(--expense);
}

/* 空状态：一根线描嫩芽 + 一句温和的话（不用 emoji，不制造压力） */
.empty {
  text-align: center;
  padding: 32px 24px 28px;
  color: var(--text-3);
  font-size: 13.5px;
  line-height: 1.7;
}

.empty-sprout {
  width: 54px;
  height: 54px;
  color: var(--leaf);
  margin-bottom: 8px;
}

.empty-title {
  margin: 0 0 4px;
  font-size: 15px;
  font-weight: 600;
  color: var(--text-2);
}

.empty-sub {
  margin: 0;
}

.empty-brand {
  margin: 18px 0 0;
  font-family: var(--font-brand);
  font-size: 12px;
  letter-spacing: 0.8px;
  color: var(--text-3);
  opacity: 0.85;
}

/* ---------------- 底部工具条 ---------------- */

.toolbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  display: flex;
  gap: 8px;
  max-width: 560px;
  margin: 0 auto;
  padding: 10px 16px calc(10px + var(--safe-bottom));
  background: var(--card);
  border-top: 1px solid var(--line);
}

.toolbtn {
  flex: 1;
  text-align: center;
  padding: 10px 0;
  border-radius: 11px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text-2);
  font-size: 13px;
  font-weight: 550;
  transition: background 0.12s;
}

.toolbtn:active {
  background: var(--line);
}

/* ---------------- 悬浮「记一笔」按钮 ---------------- */

.fab {
  position: fixed;
  right: 16px;
  bottom: calc(78px + var(--safe-bottom));
  z-index: 25;
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  padding: 0;
  border-radius: 50%;
  background: var(--primary);
  color: var(--on-primary);
  box-shadow: 0 8px 20px rgba(78, 123, 60, 0.32);
  transition: transform 0.12s, opacity 0.15s;
}

.fab svg {
  display: block;
}

.fab:active {
  transform: scale(0.96);
  opacity: 0.9;
}

/* ---------------- 记一笔抽屉 ---------------- */

.backdrop {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: rgba(20, 18, 14, 0.42);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.22s, visibility 0.22s;
}

.backdrop.is-open {
  opacity: 1;
  visibility: visible;
}

.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  max-width: 560px;
  margin: 0 auto;
  padding-bottom: var(--safe-bottom);
  background: var(--card);
  border: 1px solid var(--line);
  border-bottom: 0;
  border-radius: 22px 22px 0 0;
  box-shadow: 0 -10px 34px rgba(60, 45, 20, 0.18);
  transform: translateY(104%);
  visibility: hidden;
  transition: transform 0.26s cubic-bezier(0.2, 0.85, 0.3, 1), visibility 0.26s;
}

.sheet.is-open {
  transform: translateY(0);
  visibility: visible;
}

/* 抽屉开着时，后面的页面不许滚 */
body.sheet-open {
  overflow: hidden;
}

.sheet-grip {
  width: 40px;
  height: 4px;
  margin: 10px auto 0;
  border-radius: 2px;
  background: var(--line);
}

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 14px 0 18px;
}

.sheet-title {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  color: var(--text-2);
}

.sheet-close {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  color: var(--text-2);
  font-size: 15px;
  display: grid;
  place-items: center;
  transition: background 0.15s;
}

.sheet-close:active {
  background: var(--bg);
}

.sheet-body {
  max-height: 76vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 2px 18px 16px;
}

/* 抽屉里的表单不再是一张「卡片」，去掉边框和投影 */
.sheet .card.entry {
  background: transparent;
  border: 0;
  box-shadow: none;
  border-radius: 0;
  padding: 6px 0 0;
  margin: 0;
}

/* ---------------- 提示条 ---------------- */

.toast {
  position: fixed;
  left: 50%;
  top: 18px;
  z-index: 100;
  transform: translate(-50%, -20px);
  padding: 9px 16px;
  border-radius: 999px;
  background: rgba(43, 42, 38, 0.92);
  color: #fffdf8;
  font-size: 13px;
  font-weight: 500;
  max-width: 80vw;
  text-align: center;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.16);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}

.toast.is-show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* 电脑宽屏时，稍微收紧，别让页面拉得太长 */
@media (min-width: 600px) {
  body {
    font-size: 15px;
  }
}
