:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --primary: #3b82f6;
  --primary-dark: #2563eb;
  --success: #16a34a;
  --danger: #dc2626;
  --warn: #f59e0b;
  --text: #1f2937;
  --muted: #6b7280;
  --border: #e5e7eb;
  --radius: 14px;
}

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

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 16px;
}

.hidden { display: none !important; }

/* ---------- 登录界面 ---------- */
.auth-screen {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  background: linear-gradient(160deg, #2563eb, #7c3aed);
}
.auth-card {
  width: 100%; max-width: 380px;
  background: #fff; border-radius: 20px;
  padding: 32px 24px;
  box-shadow: 0 20px 50px rgba(0,0,0,.2);
}
.app-title { margin: 0; font-size: 26px; text-align: center; }
.app-sub { margin: 4px 0 24px; text-align: center; color: var(--muted); font-size: 14px; }

.form-group { margin-bottom: 16px; }
.form-group label { display: block; margin-bottom: 6px; font-size: 14px; color: var(--muted); }
.form-group input, .form-group select {
  width: 100%; padding: 12px 14px;
  border: 1px solid var(--border); border-radius: 10px;
  font-size: 16px; background: #fff; color: var(--text);
}
.form-group input:focus, .form-group select:focus { outline: none; border-color: var(--primary); }
.form-group input[type="number"] { font-size: 20px; font-weight: 700; }

.btn {
  display: block; width: 100%;
  padding: 13px; border: none; border-radius: 10px;
  font-size: 16px; font-weight: 600; cursor: pointer;
  background: var(--primary); color: #fff;
}
.btn:active { opacity: .85; }
.btn.secondary { background: #eef2ff; color: var(--primary); }
.btn.danger { background: #fee2e2; color: var(--danger); }
.btn.success { background: var(--success); color: #fff; }
.btn.small { width: auto; display: inline-block; padding: 9px 16px; font-size: 14px; }

.link-btn { background: none; border: none; color: var(--primary); font-size: 14px; cursor: pointer; }

/* ---------- 顶栏 ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px;
  background: linear-gradient(160deg, #2563eb, #7c3aed);
  color: #fff;
}
.topbar-name { font-size: 18px; font-weight: 700; }
.topbar-role { font-size: 12px; opacity: .85; }
.topbar-balance { text-align: right; margin-left: auto; margin-right: 14px; }
.balance-label { display: block; font-size: 11px; opacity: .85; }
.balance-value { font-size: 20px; font-weight: 700; }
.btn-logout {
  background: rgba(255,255,255,.18); color: #fff;
  border: none; border-radius: 8px; padding: 8px 12px; font-size: 13px; cursor: pointer;
}

/* ---------- 内容区 ---------- */
.content {
  max-width: 560px; margin: 0 auto;
  padding: 16px 16px 88px;
}

.card {
  background: var(--card); border-radius: var(--radius);
  padding: 16px; margin-bottom: 14px;
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
}
.card-title { font-size: 16px; font-weight: 700; margin: 0 0 12px; }

/* 余额大卡 */
.balance-card { text-align: center; padding: 28px 16px; }
.balance-card .amount { font-size: 40px; font-weight: 800; color: var(--primary); }
.balance-card .hint { color: var(--muted); font-size: 13px; margin-top: 4px; }

.stats-row { display: flex; gap: 10px; }
.stat { flex: 1; text-align: center; padding: 14px 8px; }
.stat .num { font-size: 20px; font-weight: 700; }
.stat .lbl { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* 列表 */
.item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 0; border-bottom: 1px solid var(--border);
}
.item:last-child { border-bottom: none; }
.item-main { flex: 1; min-width: 0; }
.item-title { font-size: 15px; font-weight: 600; word-break: break-word; }
.item-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.item-right { text-align: right; margin-left: 10px; }

/* 家长项目列表：一行的按钮太多（执行/编辑/停用/删除），窄屏会把标题挤得只剩一两个字。
   这里让「金额 + 操作」整体换到标题下面一行，按钮不够放时再自动换行。
   注意用 display:block 而不是 flex + width:100%：item-main 是 flex:1（flex-basis:0），
   右侧宽度 100% 正好和它凑满一行，反而不会换行，标题会被压成 0 宽。 */
.task-item { display: block; }
.task-item .task-right {
  width: 100%; margin: 10px 0 0;
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; flex-wrap: wrap; text-align: left;
}
.task-item .task-actions {
  margin: 0 0 0 auto;
  display: flex; flex-wrap: wrap; gap: 6px;
}
.task-item .task-actions .btn { flex: 0 0 auto; }

.badge {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  font-size: 12px; font-weight: 600;
}
.badge.labor { background: #e0f2fe; color: #0369a1; }
.badge.study { background: #fae8ff; color: #a21caf; }
.badge.pending { background: #fef3c7; color: #b45309; }
.badge.approved { background: #dcfce7; color: #15803d; }
.badge.rejected { background: #fee2e2; color: #b91c1c; }
.badge.init { background: #e0e7ff; color: #4338ca; }
.badge.reward { background: #dcfce7; color: #15803d; }
.badge.punish { background: #fee2e2; color: #b91c1c; }
.badge.withdraw { background: #ede9fe; color: #6d28d9; }
.badge.muted { background: #f3f4f6; color: #6b7280; }

.amount.pos { color: var(--success); font-weight: 700; }
.amount.neg { color: var(--danger); font-weight: 700; }

/* 空状态 */
.empty { text-align: center; color: var(--muted); padding: 32px 12px; font-size: 14px; }
.empty .big { font-size: 40px; display: block; margin-bottom: 8px; }

/* 底部导航 */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0;
  max-width: 560px; margin: 0 auto;
  display: flex; background: #fff;
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.tab {
  flex: 1; text-align: center; padding: 10px 0 8px;
  font-size: 12px; color: var(--muted); cursor: pointer;
  border: none; background: none;
}
.tab .icon { display: block; font-size: 20px; line-height: 1.2; }
.tab.active { color: var(--primary); font-weight: 600; }

/* 弹窗/表单卡片 */
.inline-actions { display: flex; gap: 8px; margin-top: 12px; }
.inline-actions .btn { flex: 1; }

/* 弹窗 */
.modal-overlay {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(0,0,0,.45);
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.modal {
  width: 100%; max-width: 360px;
  background: #fff; border-radius: 16px; padding: 20px;
}
.modal-title { font-size: 16px; font-weight: 700; margin-bottom: 12px; }
.modal textarea {
  width: 100%; border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 12px; font-size: 15px; resize: vertical; font-family: inherit;
}

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%);
  background: rgba(17,24,39,.92); color: #fff;
  padding: 10px 18px; border-radius: 10px; font-size: 14px;
  z-index: 100; max-width: 80vw; text-align: center;
}

/* 任务照片 */
.photo-strip { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.photo-thumb {
  position: relative; width: 76px; height: 76px;
  border-radius: 8px; overflow: hidden; border: 1px solid var(--border);
  background: #f3f4f6;
}
.photo-thumb img {
  width: 100%; height: 100%; object-fit: cover;
  display: block; cursor: zoom-in;
}
.photo-del {
  position: absolute; top: 2px; right: 2px;
  width: 20px; height: 20px; padding: 0; line-height: 1;
  border: none; border-radius: 50%; cursor: pointer;
  background: rgba(0,0,0,.6); color: #fff; font-size: 14px;
}
.modal input[type="file"] {
  width: 100%; font-size: 14px; color: var(--muted);
}
.modal input[type="file"]::file-selector-button {
  margin-right: 10px; padding: 8px 14px;
  border: 1px solid var(--border); border-radius: 8px;
  background: #fff; color: inherit; font: inherit; cursor: pointer;
}

/* ---------- 账本日历 ---------- */
.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.cal-title { font-size: 16px; font-weight: 700; }
.cal-nav {
  width: 34px; height: 34px; border: none; border-radius: 9px;
  background: #eef2ff; color: var(--primary); font-size: 17px; line-height: 1; cursor: pointer;
}
.cal-nav:active { opacity: .7; }
.cal-foot { text-align: center; margin-top: 12px; }

.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.cal-wd { text-align: center; font-size: 12px; color: var(--muted); padding: 4px 0; }
.cal-cell {
  position: relative; aspect-ratio: 1 / 1;
  display: flex; align-items: center; justify-content: center;
  border-radius: 9px; font-size: 15px; cursor: pointer;
}
.cal-cell.blank { cursor: default; }
.cal-cell.has { background: #f1f5ff; font-weight: 700; }
.cal-num { display: flex; align-items: center; justify-content: center; width: 26px; height: 26px; border-radius: 50%; }
.cal-cell.today .cal-num { background: var(--primary); color: #fff; font-weight: 700; }
.cal-cell.sel { background: var(--primary); color: #fff; }
.cal-cell.sel .cal-num { background: none; color: #fff; }

.cal-dot {
  position: absolute; bottom: 5px; width: 5px; height: 5px;
  border-radius: 50%; background: var(--success);
}
.cal-dot.neg { background: var(--danger); }
.cal-cell.sel .cal-dot { background: #fff; }

/* 当天明细 */
.day-sec {
  display: flex; justify-content: space-between; align-items: baseline;
  font-size: 13px; font-weight: 700; color: var(--muted);
  margin: 16px 0 2px; padding-bottom: 4px; border-bottom: 1px solid var(--border);
}
.item-last { border-bottom: none; }
.item-subtotal { color: var(--muted); font-weight: 600; }
.day-sum {
  display: flex; justify-content: space-between; align-items: baseline;
  margin-top: 14px; padding-top: 12px; border-top: 2px solid var(--border);
  font-weight: 700;
}
.day-sum .v { font-size: 20px; }

/* 指派选择器 */
.chip-row { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  padding: 7px 14px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--border); background: #fff;
  color: var(--muted); font-size: 14px; font-family: inherit;
}
.chip.on {
  background: var(--primary); border-color: var(--primary);
  color: #fff; font-weight: 600;
}

/* 点开看大图 */
.modal-overlay.photo-viewer { background: rgba(0,0,0,.9); padding: 12px; }
.modal-overlay.photo-viewer img {
  max-width: 100%; max-height: 100%;
  border-radius: 8px; cursor: zoom-out;
}

/* 存钱目标 */
.goal-item { padding: 10px 0; }
.goal-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.goal-title { font-weight: 600; font-size: 15px; }
.goal-bar {
  height: 10px; background: var(--border); border-radius: 999px;
  overflow: hidden; margin: 8px 0 6px;
}
.goal-fill { height: 100%; background: var(--primary); border-radius: 999px; }
.goal-done { color: var(--success); font-weight: 600; font-size: 15px; margin: 8px 0 6px; }
.goal-meta {
  display: flex; justify-content: space-between;
  font-size: 12px; color: var(--muted);
}
