/* 轻记账 — 移动优先响应式样式 */
:root {
  --primary: #4f6ef7;
  --primary-dark: #3b55d9;
  --primary-soft: #eef1fe;
  --danger: #e5484d;
  --danger-soft: #fdeced;
  --success: #2f9e63;
  --bg: #f6f7fb;
  --card: #ffffff;
  --text: #1c2333;
  --text-2: #5b6474;
  --text-3: #98a1b3;
  --border: #e6e9f2;
  --radius: 14px;
  --shadow: 0 2px 12px rgba(28, 35, 51, 0.07);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  /* 类别配色 */
  --c1: #4f6ef7; --c2: #f2994a; --c3: #27ae60; --c4: #9b51e0;
  --c5: #eb5757; --c6: #2d9cdb; --c7: #f2c94c; --c8: #8e8e93;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg); color: var(--text);
  font-size: 15px; line-height: 1.55;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; }
a { color: var(--primary); text-decoration: none; }
h1, h2, h3 { font-weight: 600; }

.loading-screen {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; color: var(--text-3);
}

/* ---------- 布局骨架 ---------- */
.shell { max-width: 960px; margin: 0 auto; padding: 0 16px calc(84px + var(--safe-bottom)); }
.topbar {
  position: sticky; top: 0; z-index: 30;
  background: rgba(246, 247, 251, 0.92); backdrop-filter: blur(10px);
  padding: 14px 16px 10px; display: flex; align-items: center; gap: 12px;
}
.topbar .brand { font-size: 18px; font-weight: 700; letter-spacing: 0.3px; }
.topbar .brand span { color: var(--primary); }
.topbar .spacer { flex: 1; }

.ledger-switch {
  appearance: none; background: var(--card); border: 1px solid var(--border);
  border-radius: 999px; padding: 7px 30px 7px 14px; font-size: 13px; font-weight: 500;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%235b6474' stroke-width='1.6' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center;
  max-width: 160px; text-overflow: ellipsis;
}

.avatar {
  width: 34px; height: 34px; border-radius: 50%; background: var(--primary);
  color: #fff; display: inline-flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 600; flex-shrink: 0;
}
.avatar.sm { width: 22px; height: 22px; font-size: 10px; }
.avatar.creator { background: var(--c6); }

/* ---------- 卡片 ---------- */
.card {
  background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px; margin-bottom: 14px;
}
.card-title { font-size: 13px; color: var(--text-3); font-weight: 500; margin-bottom: 10px; }

/* ---------- 底部导航（移动端） ---------- */
.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  background: var(--card); border-top: 1px solid var(--border);
  display: flex; padding-bottom: var(--safe-bottom);
}
.bottom-nav button {
  flex: 1; padding: 9px 4px 8px; display: flex; flex-direction: column;
  align-items: center; gap: 2px; color: var(--text-3); font-size: 11px;
}
.bottom-nav button.active { color: var(--primary); }
.bottom-nav .nav-icon { font-size: 20px; line-height: 1.2; }

/* 桌面端：底部导航 → 顶部水平标签 */
@media (min-width: 720px) {
  .bottom-nav {
    position: static; border-top: none; border-radius: var(--radius);
    box-shadow: var(--shadow); margin-bottom: 14px; background: var(--card);
  }
  .bottom-nav button {
    flex-direction: row; gap: 7px; padding: 12px 8px; font-size: 14px;
    border-bottom: 2px solid transparent; border-radius: var(--radius) var(--radius) 0 0;
  }
  .bottom-nav button.active { border-bottom-color: var(--primary); background: var(--primary-soft); }
  .bottom-nav .nav-icon { font-size: 16px; }
  .shell { padding-bottom: 32px; }
  .topbar { background: transparent; backdrop-filter: none; }
}

/* ---------- 表单 ---------- */
.form-grid { display: grid; gap: 10px; }
.field label { display: block; font-size: 12px; color: var(--text-2); margin-bottom: 5px; font-weight: 500; }
.input, select.input, textarea.input {
  width: 100%; background: var(--bg); border: 1px solid var(--border);
  border-radius: 10px; padding: 11px 12px; font-size: 15px; outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79, 110, 247, 0.15); }
.input.amount-input { font-size: 20px; font-weight: 600; }

/* 快速录入：桌面端一行四列，移动端两列 */
.quick-form .form-grid { grid-template-columns: 1fr 1fr; }
@media (min-width: 720px) {
  .quick-form .form-grid { grid-template-columns: 150px 1fr 1.6fr 1fr auto; align-items: end; }
  .quick-form .span-full { grid-column: auto; }
}
.quick-form .span-full { grid-column: 1 / -1; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 11px 18px; border-radius: 10px; font-size: 15px; font-weight: 600;
  transition: transform 0.06s, background 0.15s;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--primary); color: #fff; width: 100%; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-primary:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-ghost { background: var(--primary-soft); color: var(--primary); }
.btn-danger { background: var(--danger-soft); color: var(--danger); }
.btn-sm { padding: 7px 12px; font-size: 13px; border-radius: 8px; }
.btn-block { width: 100%; }

/* ---------- 记录列表 ---------- */
.day-group { margin-bottom: 4px; }
.day-head {
  display: flex; justify-content: space-between; align-items: baseline;
  padding: 12px 2px 6px; font-size: 13px; color: var(--text-2);
}
.day-head .day-sum { font-weight: 600; color: var(--text); }

.record-row {
  display: flex; align-items: center; gap: 12px;
  background: var(--card); border-radius: 12px; padding: 12px 14px;
  box-shadow: var(--shadow); margin-bottom: 8px;
}
.record-row .cat-dot {
  width: 38px; height: 38px; border-radius: 11px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; background: var(--primary-soft);
}
.record-row .r-main { flex: 1; min-width: 0; }
.record-row .r-name {
  font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.record-row .r-meta {
  font-size: 12px; color: var(--text-3); display: flex; align-items: center; gap: 6px;
  margin-top: 2px; flex-wrap: wrap;
}
.record-row .r-amount { font-size: 16px; font-weight: 700; white-space: nowrap; }
.record-row .r-actions { display: flex; gap: 4px; }
.icon-btn {
  width: 30px; height: 30px; border-radius: 8px; display: inline-flex;
  align-items: center; justify-content: center; font-size: 14px; color: var(--text-3);
}
.icon-btn:hover { background: var(--bg); color: var(--text); }
.icon-btn.danger:hover { background: var(--danger-soft); color: var(--danger); }

.cat-chip {
  display: inline-block; padding: 1px 8px; border-radius: 999px;
  font-size: 11px; background: var(--primary-soft); color: var(--primary); font-weight: 500;
}

/* ---------- 统计 ---------- */
.stat-cards { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 14px; }
@media (min-width: 720px) { .stat-cards { grid-template-columns: repeat(4, 1fr); } }
.stat-card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 14px;
}
.stat-card .s-label { font-size: 12px; color: var(--text-3); }
.stat-card .s-value { font-size: 22px; font-weight: 700; margin-top: 4px; letter-spacing: -0.3px; }
.stat-card .s-sub { font-size: 11px; color: var(--text-3); margin-top: 2px; }

.chart-box { width: 100%; overflow-x: auto; }
.chart-box svg { display: block; width: 100%; min-width: 320px; height: auto; }
.chart-legend {
  display: flex; flex-wrap: wrap; gap: 8px 14px; margin-top: 10px;
  font-size: 12px; color: var(--text-2);
}
.chart-legend .lg-item { display: inline-flex; align-items: center; gap: 5px; }
.chart-legend .lg-swatch { width: 10px; height: 10px; border-radius: 3px; }

.seg-control {
  display: inline-flex; background: var(--bg); border-radius: 10px; padding: 3px;
  border: 1px solid var(--border); margin-bottom: 12px;
}
.seg-control button {
  padding: 6px 16px; border-radius: 8px; font-size: 13px; color: var(--text-2); font-weight: 500;
}
.seg-control button.active { background: var(--card); color: var(--primary); box-shadow: var(--shadow); }

.cat-bar-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; font-size: 13px; }
.cat-bar-row .cb-name { width: 64px; flex-shrink: 0; text-align: right; color: var(--text-2); }
.cat-bar-row .cb-track { flex: 1; height: 10px; background: var(--bg); border-radius: 999px; overflow: hidden; }
.cat-bar-row .cb-fill { height: 100%; border-radius: 999px; }
.cat-bar-row .cb-val { width: 76px; flex-shrink: 0; text-align: right; font-weight: 600; }

/* ---------- 认证页 ---------- */
.auth-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 24px 16px;
}
.auth-card {
  width: 100%; max-width: 400px; background: var(--card); border-radius: 18px;
  box-shadow: var(--shadow); padding: 28px 22px;
}
.auth-card h1 { font-size: 22px; text-align: center; margin-bottom: 4px; }
.auth-card .sub { text-align: center; color: var(--text-3); font-size: 13px; margin-bottom: 22px; }
.auth-switch { text-align: center; margin-top: 16px; font-size: 13px; color: var(--text-2); }

/* ---------- 成员 / 邀请 ---------- */
.member-row {
  display: flex; align-items: center; gap: 10px; padding: 10px 2px;
  border-bottom: 1px solid var(--border);
}
.member-row:last-child { border-bottom: none; }
.member-row .m-name { font-weight: 500; }
.member-row .m-email { font-size: 12px; color: var(--text-3); }
.role-tag {
  font-size: 11px; padding: 2px 8px; border-radius: 999px; font-weight: 500;
}
.role-tag.owner { background: #fdf3d8; color: #a5770a; }
.role-tag.member { background: var(--primary-soft); color: var(--primary); }

.invite-box {
  background: var(--bg); border: 1px dashed var(--border); border-radius: 10px;
  padding: 12px; font-size: 13px; word-break: break-all; margin-top: 10px;
}

/* ---------- 弹窗 ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(15, 20, 32, 0.45);
  display: flex; align-items: flex-end; justify-content: center; z-index: 100;
  padding: 0;
}
@media (min-width: 720px) { .modal-backdrop { align-items: center; padding: 24px; } }
.modal {
  background: var(--card); width: 100%; max-width: 440px;
  border-radius: 18px 18px 0 0; padding: 20px 18px calc(20px + var(--safe-bottom));
  max-height: 88vh; overflow-y: auto;
}
@media (min-width: 720px) { .modal { border-radius: 18px; } }
.modal h3 { margin-bottom: 14px; font-size: 17px; }
.modal-actions { display: flex; gap: 10px; margin-top: 18px; }
.modal-actions .btn { flex: 1; }

/* ---------- Toast ---------- */
#toast-root {
  position: fixed; top: 14px; left: 50%; transform: translateX(-50%);
  z-index: 200; display: flex; flex-direction: column; gap: 8px;
  width: calc(100% - 32px); max-width: 380px; pointer-events: none;
}
.toast {
  background: #232b3d; color: #fff; border-radius: 10px; padding: 11px 16px;
  font-size: 14px; box-shadow: 0 6px 24px rgba(0, 0, 0, 0.25);
  animation: toast-in 0.22s ease; text-align: center;
}
.toast.error { background: var(--danger); }
.toast.success { background: var(--success); }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------- 空状态 / 其他 ---------- */
.empty {
  text-align: center; color: var(--text-3); padding: 36px 16px; font-size: 14px;
}
.empty .empty-icon { font-size: 38px; margin-bottom: 10px; }
.hint { font-size: 12px; color: var(--text-3); margin-top: 6px; }
.divider { height: 1px; background: var(--border); margin: 14px 0; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.section-title { font-size: 16px; font-weight: 600; margin: 18px 2px 10px; }
.fab {
  position: fixed; right: 18px; bottom: calc(72px + var(--safe-bottom)); z-index: 45;
  width: 54px; height: 54px; border-radius: 50%; background: var(--primary); color: #fff;
  font-size: 28px; line-height: 1; box-shadow: 0 6px 20px rgba(79, 110, 247, 0.4);
  display: flex; align-items: center; justify-content: center;
}
@media (min-width: 720px) { .fab { display: none; } }
