/* ===== 轻记账 PWA · 视觉对齐参考图：浅紫底 + 白色圆角卡片 + 深紫主色 ===== */
:root {
  --bg: #ECEAF6;
  --card: #FFFFFF;
  --ink: #2E2C5E;
  --ink-soft: #55538A;
  --muted: #8B89A8;
  --line: #EAE7F6;
  --primary: #4B48A8;
  --primary-grad: linear-gradient(135deg, #5B58C9, #403E92);
  --expense: #E2574C;
  --income: #2BB5A0;
  --chip-colors: #2BB5A0, #B04AC8, #FF9F43, #3D9DF2, #E257B4, #6C63FF;
  --radius-lg: 24px;
  --radius-md: 16px;
  --shadow-card: 0 6px 24px rgba(75, 72, 168, 0.08);
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "HarmonyOS Sans SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--ink);
  overscroll-behavior-y: none;
}
button { font-family: inherit; border: none; background: none; cursor: pointer; color: inherit; }
input { font-family: inherit; }
[hidden] { display: none !important; }

/* ===== 启动页 ===== */
.splash {
  position: fixed; inset: 0; z-index: 100;
  background: var(--bg);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px; padding-bottom: 10vh;
}
.splash-name { font-size: 20px; font-weight: 700; letter-spacing: 2px; }
.splash-progress { font-size: 13px; color: var(--muted); }

/* ===== 应用骨架 ===== */
.app { height: 100dvh; max-width: 600px; margin: 0 auto; position: relative; display: flex; flex-direction: column; }
.view { flex: 1; display: flex; flex-direction: column; min-height: 0; }

.offline-bar {
  background: #FFF3D6; color: #8A6A1F; font-size: 12px; text-align: center;
  padding: calc(4px + var(--sat)) 12px 4px;
}

.page-header {
  padding: calc(14px + var(--sat)) 20px 12px;
  display: flex; align-items: center; justify-content: space-between;
}
.page-header h1 { font-size: 22px; font-weight: 700; }
.btn-pill {
  display: inline-flex; align-items: center; gap: 5px;
  background: var(--card); color: var(--primary);
  font-size: 13px; font-weight: 600;
  padding: 9px 14px; border-radius: 999px;
  box-shadow: var(--shadow-card);
  min-height: 36px;
}
.btn-pill:disabled { color: var(--muted); box-shadow: none; }

/* ===== 明细列表 ===== */
.record-scroll { flex: 1; overflow-y: auto; padding: 4px 16px calc(120px + var(--sab)); -webkit-overflow-scrolling: touch; }

.date-group-title {
  display: flex; justify-content: space-between; align-items: baseline;
  font-size: 13px; color: var(--muted); font-weight: 600;
  margin: 18px 4px 8px;
}
.date-group-title em { font-style: normal; font-weight: 400; font-size: 12px; }

.record-card { background: var(--card); border-radius: var(--radius-lg); box-shadow: var(--shadow-card); overflow: hidden; }
.record-row {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px; min-height: 68px;
  border-bottom: 1px solid var(--line);
}
.record-row:last-child { border-bottom: none; }
.record-main { flex: 1; min-width: 0; }
.record-purpose { font-size: 15px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.record-sub { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); margin-top: 3px; }
.record-type-badge {
  font-size: 10px; padding: 1px 6px; border-radius: 6px; font-weight: 600;
}
.badge-expense { background: #FDEAEA; color: var(--expense); }
.badge-income { background: #E3F4F1; color: var(--income); }
.record-right { text-align: right; flex-shrink: 0; }
.record-amount { font-size: 16px; font-weight: 700; font-variant-numeric: tabular-nums; }
.amount-expense { color: var(--ink); }
.amount-income { color: var(--income); }
.record-thumb {
  width: 34px; height: 34px; border-radius: 10px; object-fit: cover;
  margin-top: 4px; border: 1px solid var(--line); cursor: pointer;
}
.thumb-flag { font-size: 11px; color: var(--muted); margin-top: 4px; display: inline-flex; align-items: center; gap: 2px; cursor: pointer; }

/* 骨架屏 */
.skeleton-wrap { padding-top: 8px; }
.sk-date { width: 120px; height: 14px; border-radius: 7px; background: #DDD9F0; margin: 16px 4px 10px; animation: pulse 1.2s ease-in-out infinite; }
.sk-row { height: 68px; border-radius: var(--radius-lg); background: #F4F2FB; margin-bottom: 10px; animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .45; } }

/* 空状态 */
.empty-state { text-align: center; padding: 15vh 20px 0; }
.empty-text { color: var(--muted); font-size: 14px; margin-top: 16px; }
.list-error { text-align: center; color: var(--muted); font-size: 13px; padding: 20px; }
.link-btn { color: var(--primary); font-weight: 600; text-decoration: underline; font-size: 13px; }

/* ===== 登录界面 ===== */
.login-view {
  position: fixed; inset: 0; z-index: 45;
  background: var(--bg);
  max-width: 600px; margin: 0 auto;
  display: flex; flex-direction: column; align-items: center;
  padding: calc(8vh + var(--sat)) 24px 24px;
  overflow-y: auto;
}
.login-name { font-size: 24px; font-weight: 700; letter-spacing: 2px; margin-top: 16px; }
.login-sub { font-size: 13px; color: var(--muted); margin: 8px 0 28px; }
.login-card {
  width: 100%;
  background: var(--card); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card); padding: 22px 18px;
}
.login-toggle {
  display: block; margin: 16px auto 0;
  color: var(--primary); font-size: 13px; font-weight: 600;
  min-height: 36px; padding: 4px 12px;
}
.login-note { font-size: 11px; color: var(--muted); margin-top: 24px; }

/* ===== 底部导航 ===== */
.tabbar {
  position: absolute; left: 0; right: 0; bottom: 0;
  background: var(--card);
  border-radius: 28px 28px 0 0;
  box-shadow: 0 -6px 24px rgba(75, 72, 168, 0.10);
  display: flex; align-items: flex-end; justify-content: space-around;
  padding: 10px 24px calc(10px + var(--sab));
  z-index: 20;
}
.tab-item {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  color: var(--muted); font-size: 11px; min-width: 64px; min-height: 44px; justify-content: center;
}
.tab-item.active { color: var(--primary); font-weight: 600; }
.tab-add {
  width: 60px; height: 60px; border-radius: 50%;
  background: var(--primary-grad);
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 8px 20px rgba(75, 72, 168, 0.40);
  margin-top: -34px; border: 5px solid var(--bg);
  flex-shrink: 0;
}
.tab-add:active { transform: scale(.93); }

/* ===== 记账页（全屏层） ===== */
.add-sheet {
  position: fixed; inset: 0; z-index: 50;
  background: var(--bg);
  display: flex; flex-direction: column;
  max-width: 600px; margin: 0 auto;
  animation: slideUp .25s ease-out;
}
@keyframes slideUp { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
.add-top {
  background: var(--primary-grad);
  padding: calc(16px + var(--sat)) 20px 0;
  border-radius: 0 0 28px 28px;
}
.add-tabs { display: flex; gap: 28px; padding-bottom: 0; }
.add-tab {
  color: rgba(255,255,255,.75); font-size: 16px; font-weight: 600;
  padding: 10px 2px 14px; position: relative; min-height: 44px;
}
.add-tab.active { color: #fff; }
.add-tab.active::after {
  content: ""; position: absolute; left: 50%; transform: translateX(-50%);
  bottom: 6px; width: 22px; height: 3.5px; border-radius: 2px; background: #1A1930;
}
.add-body { flex: 1; overflow-y: auto; padding: 16px 16px 0; display: flex; flex-direction: column; }
.form-card { background: var(--card); border-radius: var(--radius-lg); box-shadow: var(--shadow-card); padding: 20px 16px; }
.add-footer { padding: 16px 0 calc(16px + var(--sab)); }

.field-label { font-size: 13px; font-weight: 600; color: var(--ink-soft); margin: 18px 2px 8px; }
.field-label:first-child { margin-top: 0; }
.field-required { color: var(--expense); margin-left: 3px; }

.img-picker {
  border: 1.5px dashed #C9C4E8; border-radius: var(--radius-md);
  min-height: 96px; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 4px; color: var(--muted); font-size: 14px; cursor: pointer;
  padding: 14px;
}
.img-picker em { font-style: normal; font-size: 11px; color: #B0AEC9; }
.img-preview-wrap { position: relative; }
.img-preview-wrap img { width: 100%; max-height: 220px; object-fit: cover; border-radius: var(--radius-md); display: block; }
.img-actions { display: flex; gap: 10px; margin-top: 10px; }
.btn-mini {
  font-size: 12px; padding: 6px 16px; border-radius: 999px;
  background: #EFEDFA; color: var(--primary); font-weight: 600; min-height: 32px;
}
.btn-mini.danger { background: #FDEAEA; color: var(--expense); }
.img-progress { font-size: 12px; color: var(--muted); margin-top: 8px; }

.text-input, .amount-input {
  width: 100%; border: 1.5px solid var(--line); border-radius: var(--radius-md);
  font-size: 16px; padding: 13px 14px; color: var(--ink); background: #FBFAFE;
  outline: none;
}
.text-input:focus, .amount-input:focus { border-color: var(--primary); background: #fff; }
.amount-wrap { display: flex; align-items: center; gap: 8px; border: 1.5px solid var(--line); border-radius: var(--radius-md); background: #FBFAFE; padding: 4px 14px; }
.amount-wrap:focus-within { border-color: var(--primary); background: #fff; }
.amount-cny { font-size: 20px; font-weight: 700; color: var(--ink); }
.amount-input { border: none; background: transparent; font-size: 26px; font-weight: 700; padding: 10px 0; }
.field-error { color: var(--expense); font-size: 12px; margin: 6px 4px 0; }

/* ===== 按钮 ===== */
.btn {
  border-radius: 999px; font-size: 15px; font-weight: 700;
  padding: 13px 24px; min-height: 48px; flex: 1;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.btn-lg { width: 100%; font-size: 16px; min-height: 52px; }
.btn-primary { background: var(--primary-grad); color: #fff; box-shadow: 0 6px 16px rgba(75,72,168,.30); }
.btn-primary:disabled { opacity: .55; box-shadow: none; }
.btn-ghost { background: #EFEDFA; color: var(--ink-soft); }
.btn-danger { background: #FDEAEA; color: var(--expense); }
.btn:active { transform: scale(.97); }

/* ===== 底部弹层 ===== */
.mask { position: fixed; inset: 0; background: rgba(30,28,60,.45); z-index: 60; animation: fadeIn .2s; }
@keyframes fadeIn { from { opacity: 0; } }
.bottom-sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 61;
  background: var(--card); border-radius: 28px 28px 0 0;
  max-width: 600px; margin: 0 auto;
  padding: 10px 20px calc(20px + var(--sab));
  animation: sheetUp .28s cubic-bezier(.2,.9,.3,1);
  max-height: 86dvh; overflow-y: auto;
}
@keyframes sheetUp { from { transform: translateY(60%); } to { transform: none; } }
.sheet-handle { width: 40px; height: 4.5px; border-radius: 3px; background: #DDD9F0; margin: 4px auto 12px; }
.sheet-title { font-size: 18px; font-weight: 700; margin-bottom: 6px; }
.sheet-tip { font-size: 12px; color: var(--muted); line-height: 1.7; margin-top: 12px; }
.sheet-btns { display: flex; gap: 12px; margin-top: 20px; }
.sheet-divider { height: 1px; background: var(--line); margin: 24px 0 4px; }
.sheet-input { margin-bottom: 10px; }

/* 管理员与子账号 */
.menu-group-title { font-size: 12px; color: var(--muted); font-weight: 600; padding: 14px 16px 4px; }
.check-line {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; color: var(--ink-soft); margin-top: 12px;
  min-height: 32px; cursor: pointer;
}
.check-line input { width: 17px; height: 17px; accent-color: var(--primary); }
.cred-box {
  background: #F6F5FD; border-radius: var(--radius-md);
  padding: 14px 16px; margin-top: 14px;
}
.cred-line { display: flex; justify-content: space-between; align-items: center; padding: 6px 0; font-size: 15px; }
.cred-line span { color: var(--muted); font-size: 13px; }
.cred-line b { font-size: 20px; letter-spacing: 2px; color: var(--primary); font-variant-numeric: tabular-nums; }
.sub-row {
  display: flex; align-items: center; gap: 10px;
  border: 1.5px solid var(--line); border-radius: var(--radius-md);
  padding: 13px 14px; margin-bottom: 10px; min-height: 56px; cursor: pointer;
  background: #FBFAFE;
}
.sub-row .sub-acc { font-size: 16px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: 1px; }
.sub-row .sub-meta { font-size: 11px; color: var(--muted); margin-top: 2px; }
.sub-row .sub-info { flex: 1; min-width: 0; }
.status-badge { font-size: 11px; font-weight: 600; padding: 3px 10px; border-radius: 999px; flex-shrink: 0; }
.status-active { background: #E3F4F1; color: var(--income); }
.status-disabled { background: #FFF0E3; color: #D98A2B; }
.status-revoked { background: #FDEAEA; color: var(--expense); }
.perm-line {
  display: flex; justify-content: space-between; align-items: center;
  border: 1.5px solid var(--line); border-radius: var(--radius-md);
  padding: 13px 14px; margin-bottom: 10px; min-height: 48px;
  font-size: 14px; font-weight: 600; cursor: pointer;
}
.perm-line input { width: 20px; height: 20px; accent-color: var(--primary); }

.range-group { display: flex; flex-direction: column; gap: 10px; }
.range-item {
  display: flex; align-items: center; gap: 10px;
  border: 1.5px solid var(--line); border-radius: var(--radius-md);
  padding: 13px 14px; font-size: 15px; font-weight: 600; min-height: 48px; cursor: pointer;
}
.range-item:has(input:checked) { border-color: var(--primary); background: #F6F5FD; color: var(--primary); }
.range-item input { width: 18px; height: 18px; accent-color: var(--primary); }
.date-range { display: flex; align-items: center; gap: 10px; margin-top: 12px; }
.date-range input {
  flex: 1; border: 1.5px solid var(--line); border-radius: 12px;
  font-size: 15px; padding: 10px 12px; color: var(--ink); background: #FBFAFE; min-height: 44px;
}
.range-sep { color: var(--muted); font-size: 13px; }
.format-tag {
  display: inline-block; background: #EFEDFA; color: var(--primary);
  font-size: 13px; font-weight: 600; padding: 8px 16px; border-radius: 999px;
}

.export-state { text-align: center; padding: 24px 8px 8px; }
.export-state .btn { width: 100%; margin-top: 12px; }
.spinner {
  width: 36px; height: 36px; border-radius: 50%;
  border: 3.5px solid #E4E1F4; border-top-color: var(--primary);
  margin: 0 auto 14px; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.state-ic {
  width: 52px; height: 52px; border-radius: 50%; margin: 0 auto 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 24px; font-weight: 800;
}
.state-ic.ok { background: #E3F4F1; color: var(--income); }
.state-ic.fail { background: #FDEAEA; color: var(--expense); }
.state-title { font-size: 16px; font-weight: 700; }
.state-sub { font-size: 13px; color: var(--muted); margin-top: 6px; word-break: break-all; }

/* 安装引导 */
.install-steps { margin-top: 12px; display: flex; flex-direction: column; gap: 10px; }
.install-step {
  display: flex; gap: 12px; align-items: flex-start;
  background: #F8F7FD; border-radius: var(--radius-md); padding: 13px 14px;
  font-size: 14px; line-height: 1.6;
}
.install-step .num {
  width: 24px; height: 24px; border-radius: 50%; flex-shrink: 0;
  background: var(--primary); color: #fff; font-size: 13px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}

/* ===== 图片预览 ===== */
.img-viewer {
  position: fixed; inset: 0; z-index: 80; background: rgba(20,18,40,.92);
  display: flex; align-items: center; justify-content: center; padding: 24px;
}
.img-viewer img { max-width: 100%; max-height: 100%; border-radius: 12px; }
.viewer-close {
  position: absolute; top: calc(16px + var(--sat)); right: 20px;
  width: 44px; height: 44px; border-radius: 50%;
  background: rgba(255,255,255,.15); color: #fff; font-size: 18px;
}

/* ===== 确认对话框 ===== */
.confirm-dialog {
  position: fixed; z-index: 70; left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  width: min(320px, 84vw);
  background: var(--card); border-radius: var(--radius-lg); padding: 24px 20px 16px;
}
.confirm-text { font-size: 15px; line-height: 1.7; text-align: center; }
.confirm-btns { display: flex; gap: 12px; margin-top: 18px; }

/* ===== Toast ===== */
.toast {
  position: fixed; left: 50%; bottom: calc(110px + var(--sab)); transform: translateX(-50%);
  background: rgba(30,28,60,.9); color: #fff; font-size: 13px;
  padding: 10px 20px; border-radius: 999px; z-index: 90;
  animation: fadeIn .2s; white-space: nowrap;
}

/* ===== 我的页 ===== */
.profile-scroll { flex: 1; overflow-y: auto; padding: 4px 16px calc(120px + var(--sab)); }
.profile-card {
  background: var(--card); border-radius: var(--radius-lg); box-shadow: var(--shadow-card);
  padding: 18px 16px; display: flex; align-items: center; gap: 14px;
}
.profile-avatar {
  width: 56px; height: 56px; border-radius: 50%;
  background: var(--primary-grad); display: flex; align-items: center; justify-content: center;
}
.profile-name { font-size: 17px; font-weight: 700; }
.profile-sub { font-size: 12px; color: var(--muted); margin-top: 3px; }
.menu-group { background: var(--card); border-radius: var(--radius-lg); box-shadow: var(--shadow-card); margin-top: 14px; overflow: hidden; }
.menu-item {
  width: 100%; display: flex; align-items: center; gap: 12px;
  padding: 15px 16px; font-size: 15px; font-weight: 600; min-height: 52px;
  border-bottom: 1px solid var(--line); text-align: left;
}
.menu-item:last-child { border-bottom: none; }
.menu-ic {
  width: 34px; height: 34px; border-radius: 12px; font-size: 15px;
  display: flex; align-items: center; justify-content: center; font-weight: 700;
}
.profile-note { font-size: 12px; color: var(--muted); text-align: center; margin-top: 18px; line-height: 1.7; }

/* ===== 待同步条 ===== */
.outbox-bar {
  display: flex; align-items: center; justify-content: space-between;
  margin: 0 16px 4px; padding: 8px 14px;
  background: #FFF3D6; color: #8A6A1F; font-size: 12px; font-weight: 600;
  border-radius: 12px;
}

/* ===== 搜索与筛选 ===== */
.filter-bar { padding: 2px 16px 6px; }
.search-wrap {
  display: flex; align-items: center; gap: 8px;
  background: var(--card); border-radius: 999px; box-shadow: var(--shadow-card);
  padding: 9px 14px;
}
.search-wrap input {
  flex: 1; border: none; outline: none; background: transparent;
  font-size: 14px; color: var(--ink); min-height: 22px;
}
.search-wrap input::-webkit-search-cancel-button { -webkit-appearance: none; }
.chip-row { display: flex; gap: 8px; margin-top: 10px; }
.chip {
  font-size: 12px; font-weight: 600; color: var(--ink-soft);
  background: var(--card); border-radius: 999px; padding: 7px 15px;
  box-shadow: var(--shadow-card); min-height: 32px;
}
.chip.active { background: var(--primary); color: #fff; }
.filter-dates { display: flex; align-items: center; gap: 8px; margin-top: 10px; }
.filter-dates input {
  flex: 1; border: 1.5px solid var(--line); border-radius: 12px;
  font-size: 13px; padding: 8px 10px; color: var(--ink); background: var(--card); min-height: 38px;
}

/* 子账号密码行 */
.pwd-line { display: flex; align-items: center; gap: 12px; margin: 2px 0 4px; }
.pwd-line b { font-size: 20px; letter-spacing: 2px; color: var(--primary); font-variant-numeric: tabular-nums; }

/* ===== 明细详情面板 ===== */
.recd-amount { font-size: 30px; font-weight: 800; font-variant-numeric: tabular-nums; margin: 4px 0 12px; }
.recd-amount.expense { color: var(--ink); }
.recd-amount.income { color: var(--income); }
.recd-image {
  width: 100%; max-height: 240px; object-fit: cover;
  border-radius: var(--radius-md); display: block; margin-bottom: 12px; cursor: pointer;
}
.recd-meta { font-size: 13px; color: var(--muted); line-height: 2; }
.recd-edit-img { display: flex; align-items: center; gap: 12px; }
.recd-edit-img img { width: 64px; height: 64px; border-radius: 12px; object-fit: cover; border: 1px solid var(--line); }

@media (min-width: 600px) {
  .tabbar, .bottom-sheet, .add-sheet { border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
}
