/* 家庭账本 H5 — 配色与 Android 端 res/values/colors.xml 保持一致
   brand #2F7D5B / dark #1F5C42 / income #2E9E5B / expense #E5533D / warn #F2994A
   page_bg #F5F7F6 / card #FFFFFF / text #222A26 / sub #7A8A82 / divider #ECEFED */

*, *::before, *::after { box-sizing: border-box; }

/* 必须放在最前面：只要组件写过 display（如 .overlay 的 flex），[hidden] 就会被覆盖，
   导致「已隐藏」的蒙层其实一直铺满全屏、把点击全吃掉。JS 全程用 el.hidden 控制显隐。 */
[hidden] { display: none !important; }

:root {
  --brand: #2F7D5B;
  --brand-dark: #1F5C42;
  --income: #2E9E5B;
  --expense: #E5533D;
  --warn: #F2994A;
  --page-bg: #F5F7F6;
  --card: #FFFFFF;
  --text: #222A26;
  --sub: #7A8A82;
  --divider: #ECEFED;
  --icon-bg: #E8F2EC;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --tab-h: 54px;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  /* iOS：禁用整页回弹，滚动交给 .view，避免键盘收起后页面停在半空 */
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
  /* 老 Safari 无 dvh：JS 会把实测高度写进 --app-h */
  --app-h: 100vh;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue",
               "Microsoft YaHei", sans-serif;
  font-size: 15px;
  color: var(--text);
  background: var(--page-bg);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

input, select, textarea, button { font: inherit; color: inherit; }

/* iOS Safari：字号 <16px 的输入框获得焦点会整页放大且无法缩回 */
input, textarea, select { font-size: 16px; }

button { -webkit-appearance: none; appearance: none; border: 0; background: none; cursor: pointer; }

.app {
  position: fixed;
  inset: 0;
  height: var(--app-h);
  display: flex;
  flex-direction: column;
  background: var(--page-bg);
}

/* ---------- 顶栏 ---------- */
.topbar {
  flex: 0 0 auto;
  padding: calc(var(--sat) + 6px) 12px 8px;
  background: var(--brand);
  color: #fff;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 46px;
}
.topbar--plain { background: var(--card); color: var(--text); border-bottom: 1px solid var(--divider); }
.topbar__title { font-size: 17px; font-weight: 600; flex: 1 1 auto; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar__btn { padding: 6px 10px; border-radius: 8px; font-size: 15px; color: inherit;
  background: rgba(255, 255, 255, .16); }
.topbar--plain .topbar__btn { background: var(--icon-bg); color: var(--brand); }
.topbar__btn:active { opacity: .6; }
.topbar__btn[hidden] { display: none; }

/* ---------- 主滚动区 ---------- */
.view {
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 12px 12px calc(16px + var(--sab));
}
.view--padded-nav { padding-bottom: calc(var(--tab-h) + var(--sab) + 16px); }

/* ---------- 底部标签栏 ---------- */
.tabbar {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: calc(var(--tab-h) + var(--sab));
  padding-bottom: var(--sab);
  background: var(--card);
  border-top: 1px solid var(--divider);
  display: flex;
  z-index: 20;
}
.tabbar[hidden] { display: none; }
.tabbar__item {
  flex: 1 1 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; font-size: 11px; color: var(--sub);
}
.tabbar__item.is-active { color: var(--brand); font-weight: 600; }
.tabbar__icon { font-size: 19px; line-height: 1; }

/* ---------- 卡片与通用块 ---------- */
.card {
  background: var(--card);
  border-radius: 14px;
  padding: 14px;
  margin-bottom: 12px;
  box-shadow: 0 1px 3px rgba(34, 42, 38, .05);
}
.card__title { font-size: 15px; font-weight: 600; margin: 0 0 10px; display: flex;
  align-items: center; justify-content: space-between; }
.card__hint { font-size: 12px; color: var(--sub); font-weight: 400; }
.section-title { font-size: 13px; color: var(--sub); margin: 4px 2px 8px; }
.empty { text-align: center; color: var(--sub); padding: 36px 12px; font-size: 14px; }
.empty__icon { font-size: 34px; display: block; margin-bottom: 8px; opacity: .5; }

.row { display: flex; align-items: center; gap: 10px; }
.row--between { justify-content: space-between; }
.grow { flex: 1 1 auto; min-width: 0; }
.muted { color: var(--sub); font-size: 13px; }
.money { font-variant-numeric: tabular-nums; }
.money--in { color: var(--income); }
.money--out { color: var(--expense); }

/* ---------- 汇总卡 ---------- */
.summary { display: flex; text-align: center; }
.summary > div { flex: 1 1 0; }
.summary__label { font-size: 12px; color: var(--sub); }
.summary__value { font-size: 19px; font-weight: 600; margin-top: 2px; }

/* ---------- 预算进度 ---------- */
.budget { margin-top: 12px; padding-top: 12px; border-top: 1px dashed var(--divider); }
.budget__bar { height: 8px; border-radius: 4px; background: var(--icon-bg); overflow: hidden; }
.budget__fill { height: 100%; border-radius: 4px; background: var(--brand); transition: width .3s; }
.budget__fill--near { background: var(--warn); }
.budget__fill--over { background: var(--expense); }
.alert {
  border-radius: 12px; padding: 10px 12px; font-size: 13px; margin-bottom: 12px;
  display: flex; align-items: flex-start; gap: 8px;
}
.alert--near { background: #FEF3E6; color: #A6620E; }
.alert--over { background: #FDECE9; color: #A03422; }
.alert--info { background: var(--icon-bg); color: var(--brand-dark); }
.alert__x { margin-left: auto; color: inherit; opacity: .6; padding: 0 4px; }

/* ---------- 列表 ---------- */
.list { background: var(--card); border-radius: 14px; overflow: hidden; }
.cell {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px; border-bottom: 1px solid var(--divider);
  position: relative; text-align: left; width: 100%;
}
.cell:last-child { border-bottom: 0; }
.cell:active { background: #F7F9F8; }
.cell__icon {
  width: 34px; height: 34px; border-radius: 10px; background: var(--icon-bg);
  display: flex; align-items: center; justify-content: center; font-size: 16px; flex: 0 0 auto;
}
.cell__main { flex: 1 1 auto; min-width: 0; }
.cell__name { font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cell__sub { font-size: 12px; color: var(--sub); margin-top: 1px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cell__value { font-size: 15px; font-weight: 600; flex: 0 0 auto; }
.cell__chev { color: var(--sub); font-size: 14px; flex: 0 0 auto; }
.day-head { display: flex; justify-content: space-between; font-size: 12px; color: var(--sub);
  padding: 10px 4px 6px; }

.badge { font-size: 10px; padding: 1px 5px; border-radius: 6px; vertical-align: middle; }
.badge--pending { background: #FEF3E6; color: #A6620E; }
.badge--failed { background: #FDECE9; color: #A03422; }
.badge--admin { background: var(--icon-bg); color: var(--brand-dark); }
.badge--mine { background: #EEF2F0; color: var(--sub); }

/* ---------- 按钮 ---------- */
.btn {
  display: block; width: 100%; padding: 13px; border-radius: 12px;
  background: var(--brand); color: #fff; font-size: 16px; font-weight: 600;
  text-align: center; margin-top: 8px;
}
.btn:active { background: var(--brand-dark); }
.btn[disabled] { opacity: .5; }
.btn--ghost { background: var(--card); color: var(--brand); border: 1px solid var(--brand); }
.btn--danger { background: var(--expense); }
.btn--sm { padding: 8px 12px; font-size: 14px; width: auto; display: inline-block; margin-top: 0; }
.btn--row { display: flex; gap: 10px; }
.btn--row > .btn { margin-top: 8px; }

.fab {
  position: absolute; right: 16px; bottom: calc(var(--tab-h) + var(--sab) + 16px);
  width: 52px; height: 52px; border-radius: 26px; background: var(--brand); color: #fff;
  font-size: 26px; line-height: 50px; text-align: center; z-index: 25;
  box-shadow: 0 4px 12px rgba(47, 125, 91, .35);
}
.fab:active { transform: scale(.94); }

/* ---------- 表单 ---------- */
.field { margin-bottom: 14px; }
.field__label { font-size: 13px; color: var(--sub); margin-bottom: 6px; }
.input, .textarea, .picker {
  width: 100%; padding: 11px 12px; border: 1px solid var(--divider); border-radius: 10px;
  background: #FBFCFC; -webkit-appearance: none; appearance: none;
}
.input:focus, .textarea:focus { outline: none; border-color: var(--brand); background: #fff; }
.textarea { min-height: 64px; resize: none; }
.picker {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='6'><path d='M0 0l5 6 5-6z' fill='%237A8A82'/></svg>");
  background-repeat: no-repeat; background-position: right 12px center; padding-right: 30px;
}
.amount-input { position: relative; }
.amount-input .input { font-size: 26px; font-weight: 600; padding-left: 30px; }
.amount-input::before {
  content: "¥"; position: absolute; left: 12px; top: 14px; font-size: 20px; color: var(--sub);
}

.seg { display: flex; background: var(--icon-bg); border-radius: 10px; padding: 3px; }
.seg__item { flex: 1 1 0; text-align: center; padding: 8px 0; border-radius: 8px;
  font-size: 15px; color: var(--sub); }
.seg__item.is-active { background: var(--card); color: var(--brand); font-weight: 600; }
.seg--expense .seg__item.is-active { color: var(--expense); }
.seg--income .seg__item.is-active { color: var(--income); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  padding: 7px 12px; border-radius: 16px; background: #F2F5F3; color: var(--text);
  font-size: 14px; border: 1px solid transparent;
}
.chip.is-active { background: var(--icon-bg); color: var(--brand); border-color: var(--brand);
  font-weight: 600; }

/* 月份切换条：iOS Safari 不支持 <input type="month">，必须走这个自定义控件 */
.monthbar { display: flex; align-items: center; justify-content: center; gap: 18px;
  padding: 2px 0 10px; }
.monthbar__btn { width: 34px; height: 34px; border-radius: 17px; background: var(--card);
  color: var(--brand); font-size: 18px; line-height: 32px; text-align: center;
  border: 1px solid var(--divider); }
.monthbar__label { font-size: 16px; font-weight: 600; min-width: 108px; text-align: center; }

/* ---------- 图片 ---------- */
.photo-add {
  width: 92px; height: 92px; border-radius: 12px; border: 1px dashed #C9D6CF;
  background: #FBFCFC; color: var(--sub); font-size: 12px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
}
.photo-add__plus { font-size: 24px; line-height: 1; }
.photo-grid { display: flex; flex-wrap: wrap; gap: 10px; }
.photo-thumb { position: relative; width: 92px; height: 92px; border-radius: 12px;
  overflow: hidden; background: var(--icon-bg); }
.photo-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-thumb__del { position: absolute; right: 0; top: 0; width: 22px; height: 22px;
  background: rgba(0, 0, 0, .55); color: #fff; border-radius: 0 12px 0 10px; font-size: 13px;
  line-height: 22px; text-align: center; }
.receipt-view { width: 100%; border-radius: 12px; background: #111; }

/* ---------- 图表 ---------- */
.chart { width: 100%; height: 230px; }
.chart--tall { height: 260px; }

/* ---------- 弹层 ---------- */
.toast {
  position: fixed; left: 50%; bottom: 15%; transform: translateX(-50%);
  background: rgba(34, 42, 38, .9); color: #fff; padding: 10px 16px; border-radius: 20px;
  font-size: 14px; z-index: 100; max-width: 80vw; text-align: center;
}
.overlay { position: fixed; inset: 0; background: rgba(0, 0, 0, .18); z-index: 90;
  display: flex; align-items: center; justify-content: center; }
.spinner { width: 30px; height: 30px; border: 3px solid rgba(255, 255, 255, .6);
  border-top-color: var(--brand); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.sheet-mask { position: fixed; inset: 0; background: rgba(0, 0, 0, .35); z-index: 80;
  display: flex; align-items: flex-end; }
.sheet { background: var(--card); width: 100%; border-radius: 16px 16px 0 0;
  padding: 14px 14px calc(14px + var(--sab)); max-height: 78vh; overflow-y: auto;
  -webkit-overflow-scrolling: touch; animation: up .22s ease-out; }
@keyframes up { from { transform: translateY(100%); } }
.sheet__head { display: flex; align-items: center; margin-bottom: 10px; }
.sheet__title { font-size: 16px; font-weight: 600; flex: 1 1 auto; }
.sheet__close { color: var(--sub); font-size: 20px; padding: 0 6px; }

/* ---------- 登录页 ---------- */
.auth { padding: 0 22px; max-width: 420px; margin: 0 auto; }
.auth__logo { width: 66px; height: 66px; border-radius: 18px; background: var(--brand);
  color: #fff; font-size: 30px; text-align: center; line-height: 66px; margin: 44px auto 12px; }
.auth__name { text-align: center; font-size: 21px; font-weight: 600; margin-bottom: 4px; }
.auth__slogan { text-align: center; font-size: 13px; color: var(--sub); margin-bottom: 26px; }
.auth__switch { text-align: center; font-size: 14px; color: var(--sub); margin-top: 16px; }
.auth__switch b { color: var(--brand); font-weight: 600; }

.detail-label { color: var(--sub); width: 76px; flex: 0 0 auto; font-size: 14px; }
.detail-value { font-size: 14px; }
.kv { display: flex; padding: 9px 0; border-bottom: 1px solid var(--divider); }
.kv:last-child { border-bottom: 0; }
.invite { font-size: 26px; font-weight: 700; letter-spacing: 4px; color: var(--brand);
  text-align: center; padding: 10px 0; }
.err { color: var(--expense); font-size: 13px; margin-top: -6px; margin-bottom: 10px; }
