/* ==========================================================================
   记账本 · 样式表
   --------------------------------------------------------------------------
   约定：
     - 收入用红、支出用绿（中文财务语境，与 A 股涨跌配色一致）；
     - 页面 CSP 不含 unsafe-inline，因此本文件里不出现任何内联样式依赖，
       所有需要动态取色的地方（分类色点、占比条）都用 SVG 呈现属性而非 style。
   ========================================================================== */

:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-soft: #fafbfc;
  --border: #e4e7ec;
  --border-strong: #d3d8e0;

  --text: #1d2129;
  --text-muted: #6b7280;
  --text-faint: #98a1ad;

  --primary: #4c6ef5;
  --primary-dark: #3b5bdb;
  --primary-soft: #edf1ff;

  --income: #e03131;
  --income-soft: #fff0f0;
  --income-bar: #f06565;

  --expense: #2f9e44;
  --expense-soft: #eefaf1;
  --expense-bar: #51b364;

  --warn-bg: #fff8e6;
  --warn-border: #f0d08a;

  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 4px 16px rgba(16, 24, 40, .05);
}

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

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.6;
}

h1, h2, h3 {
  margin: 0;
  font-weight: 600;
  line-height: 1.3;
}

h1 { font-size: 22px; }
h2 { font-size: 16px; }
h3 { font-size: 14px; }

p { margin: 0; }

a {
  color: var(--primary);
  text-decoration: none;
}

a:hover { text-decoration: underline; }

ul { margin: 0; padding: 0; list-style: none; }

code {
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--primary-soft);
  color: var(--primary-dark);
  font-size: 12px;
}

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.muted { color: var(--text-muted); font-size: 13px; }
.empty { padding: 28px 4px; color: var(--text-muted); text-align: center; }

/* ---------- 顶栏 ---------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 0 24px;
  height: 58px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  color: var(--text);
  font-size: 16px;
  font-weight: 600;
}

.brand:hover { text-decoration: none; }

.brand-mark {
  display: grid;
  place-items: center;
  width: 26px; height: 26px;
  border-radius: 8px;
  background: var(--primary);
  color: #fff;
  font-size: 15px;
  line-height: 1;
}

.mainnav {
  display: flex;
  gap: 4px;
}

.mainnav a {
  padding: 6px 13px;
  border-radius: 8px;
  color: var(--text-muted);
  font-weight: 500;
}

.mainnav a:hover {
  background: var(--surface-soft);
  color: var(--text);
  text-decoration: none;
}

.mainnav a.is-active {
  background: var(--primary-soft);
  color: var(--primary-dark);
}

/*
  顶栏右侧：环境标签 + 用户信息 + 退出。
  原先 env-tag 用 margin-left:auto 把自己顶到最右；现在它被包进 .topbar-right，
  这个"推到底"的职责上移给容器，否则容器内元素会各推各的、间距忽宽忽窄。
*/
.topbar-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 12px;
}

.env-tag {
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--warn-bg);
  border: 1px solid var(--warn-border);
  color: #8a6116;
  font-size: 12px;
}

.user-box {
  display: flex;
  align-items: center;
  gap: 9px;
  padding-left: 12px;
  border-left: 1px solid var(--border);
}

.user-avatar {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--primary-soft);
  color: var(--primary-dark);
  font-size: 13px;
  font-weight: 600;
  line-height: 1;
}

.user-meta {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1.3;
}

.user-name {
  max-width: 14ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 500;
}

.user-provider {
  color: var(--text-faint);
  font-size: 11px;
}

.logout-form { display: flex; }

/* ---------- 顶栏账本切换器 ---------- */

/*
  当前账本必须一直可见。共享账本里，"记错账本"和"记错金额"一样难发现，
  因此账本名直接摆在顶栏上，而不是藏进一个只有图标的下拉里。
*/
.ledger-switcher { position: relative; }

.ledger-trigger {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: 260px;
  padding: 4px 10px 4px 4px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  list-style: none;
}

/* 去掉 <summary> 默认的三角标记，自己画一个，跨浏览器外观才一致。 */
.ledger-trigger::-webkit-details-marker { display: none; }
.ledger-trigger::marker { content: ""; }

.ledger-trigger:hover,
.ledger-switcher[open] .ledger-trigger {
  background: var(--primary-soft);
  border-color: var(--primary);
}

.ledger-mark {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 22px;
  height: 22px;
  border-radius: 999px;
  background: var(--primary);
  color: #fff;
  font-size: 12px;
  line-height: 1;
}

.ledger-trigger-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ledger-tag {
  flex: 0 0 auto;
  padding: 1px 7px;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 400;
}

.ledger-caret { flex: 0 0 auto; color: var(--text-faint); font-size: 10px; }

.ledger-menu {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  z-index: 40;
  width: 286px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 8px 28px rgba(16, 24, 40, .14);
}

.ledger-menu-title {
  margin-bottom: 8px;
  padding: 0 4px;
  color: var(--text-faint);
  font-size: 12px;
}

.ledger-menu-list > li + li { margin-top: 2px; }

.ledger-menu-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  padding: 7px 10px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  text-align: left;
  cursor: pointer;
}

.ledger-menu-item:hover { background: var(--surface-soft); }

.ledger-menu-item.is-current {
  background: var(--primary-soft);
  color: var(--primary-dark);
  font-weight: 500;
  cursor: default;
}

.ledger-menu-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ledger-menu-meta { flex: 0 0 auto; color: var(--text-faint); font-size: 12px; font-weight: 400; }
.ledger-menu-item.is-current .ledger-menu-meta { color: var(--primary-dark); }

.ledger-menu-manage {
  display: block;
  margin-top: 8px;
  padding: 8px 10px 2px;
  border-top: 1px solid var(--border);
  font-size: 13px;
}

@media (max-width: 680px) {
  /* 窄屏保住账本图标与下拉箭头，名字让位给导航。 */
  .ledger-trigger-name,
  .ledger-tag { display: none; }
  .ledger-trigger { padding-right: 8px; }
}

/* 窄屏优先保住导航与退出按钮，昵称可以省略 —— 头像首字仍在。 */
@media (max-width: 680px) {
  .user-meta { display: none; }
  .user-box { padding-left: 9px; gap: 7px; }
}

/* ---------- 布局 ---------- */

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px;
}

.page > * + * { margin-top: 18px; }

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.page-head h1 + p { margin-top: 4px; max-width: 72ch; }

.range-chip {
  padding: 5px 12px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 12px;
  white-space: nowrap;
}

.panel-stack > * + * { margin-top: 18px; }

.two-col {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 336px;
  gap: 18px;
  align-items: start;
}

@media (max-width: 940px) {
  .two-col { grid-template-columns: minmax(0, 1fr); }
}

.col-side { position: sticky; top: 76px; }

@media (max-width: 940px) {
  .col-side { position: static; }
}

/* ---------- 卡片与面板 ---------- */

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

/* 标题可以带一行副标题，因此包一层容器，避免 h2 与副标题被 flex 拆成两端。 */
.panel-head-text { min-width: 0; }
.panel-head-text h2 { margin: 0; }

.panel-sub {
  margin-top: 2px;
  color: var(--text-faint);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.cards {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

@media (max-width: 720px) {
  .cards { grid-template-columns: minmax(0, 1fr); }
}

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

.card-label {
  color: var(--text-muted);
  font-size: 13px;
}

.card-value {
  margin-top: 6px;
  font-size: 26px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  letter-spacing: -.01em;
}

.card-value::before {
  content: "¥";
  margin-right: 2px;
  font-size: 16px;
  font-weight: 500;
  color: var(--text-faint);
}

.card-sub {
  margin-top: 4px;
  color: var(--text-faint);
  font-size: 12px;
}

.is-income { color: var(--income); }
.is-expense { color: var(--expense); }
.is-balance { color: var(--primary-dark); }
.is-negative { color: var(--income); }

.badge {
  padding: 3px 8px;
  border-radius: 6px;
  background: var(--primary-soft);
  color: var(--primary-dark);
  font-size: 12px;
}

.badge-muted {
  background: var(--surface-soft);
  border: 1px solid var(--border);
  color: var(--text-muted);
}

.badge-warn {
  background: var(--warn-bg);
  border: 1px solid var(--warn-border);
  color: #8a6116;
}

/* ---------- 表单 ---------- */

.field { margin-bottom: 14px; }

.field:last-child { margin-bottom: 0; }

.field label {
  display: block;
  margin-bottom: 6px;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
}

.label-optional {
  margin-left: 6px;
  color: var(--text-faint);
  font-size: 12px;
  font-weight: 400;
}

input[type="text"],
input[type="date"],
input[type="month"],
input[type="file"],
select,
.input {
  width: 100%;
  padding: 8px 11px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  line-height: 1.4;
}

input[type="text"]:focus,
input[type="date"]:focus,
input[type="month"]:focus,
select:focus,
.input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(76, 110, 245, .14);
}

input[type="file"] {
  padding: 7px 11px;
  background: var(--surface-soft);
}

input[type="color"] {
  width: 44px;
  height: 36px;
  padding: 2px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  cursor: pointer;
}

.input-money { position: relative; }

.input-prefix {
  position: absolute;
  left: 11px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-faint);
  pointer-events: none;
}

.input-money input { padding-left: 26px; }

.hint {
  margin-top: 6px;
  color: var(--text-faint);
  font-size: 12px;
  line-height: 1.55;
}

.field-row {
  display: flex;
  gap: 14px;
  align-items: flex-end;
  flex-wrap: wrap;
}

.field-row .field { flex: 1 1 180px; margin-bottom: 0; }
.field-row .field-color { flex: 0 0 auto; }

.form-actions {
  display: flex;
  gap: 10px;
  margin-top: 16px;
}

/* ---------- 按钮 ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  line-height: 1.4;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s ease, border-color .15s ease, color .15s ease;
}

.btn:hover { background: var(--surface-soft); }

.btn:disabled,
.btn[disabled] {
  opacity: .5;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  width: 100%;
}

.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-muted);
}

.btn-ghost:hover { background: var(--surface-soft); color: var(--text); }

.btn-danger { color: #c92a2a; }
.btn-danger:hover { background: var(--income-soft); color: #a61e1e; }

.btn-sm {
  padding: 5px 10px;
  font-size: 13px;
}

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

.toast-zone {
  position: fixed;
  top: 70px;
  right: 24px;
  z-index: 60;
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: min(420px, calc(100vw - 48px));
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 13px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 8px 28px rgba(16, 24, 40, .14);
  pointer-events: auto;
  animation: toast-in .18s ease-out;
  transition: opacity .2s ease, transform .2s ease;
}

.toast-hide {
  opacity: 0;
  transform: translateX(12px);
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: translateY(0); }
}

.toast-error { border-left: 3px solid var(--income); }

.toast-icon {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 20px; height: 20px;
  margin-top: 1px;
  border-radius: 50%;
  background: var(--income-soft);
  color: var(--income);
  font-size: 13px;
  font-weight: 700;
}

.toast-body { flex: 1 1 auto; min-width: 0; }

.toast-message { font-size: 14px; font-weight: 500; }

.toast-fields {
  margin-top: 6px;
  color: var(--text-muted);
  font-size: 13px;
}

.toast-fields li + li { margin-top: 2px; }

.toast-meta {
  margin-top: 6px;
  color: var(--text-faint);
  font-size: 11px;
}

.toast-req { margin-left: 8px; }

.toast-close {
  flex: 0 0 auto;
  width: 24px; height: 24px;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text-faint);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}

.toast-close:hover { background: var(--surface-soft); color: var(--text); }

/* ---------- 筛选栏 ---------- */

.filters {
  display: flex;
  gap: 14px;
  align-items: flex-end;
  flex-wrap: wrap;
}

.filters .field { margin-bottom: 0; flex: 0 1 200px; }
.filters-actions { margin-left: auto; }

/* ---------- 趋势图 ---------- */

.chart-panel { padding-bottom: 10px; }

.legend {
  display: flex;
  gap: 14px;
  color: var(--text-muted);
  font-size: 12px;
}

.legend li { display: inline-flex; align-items: center; gap: 6px; }

.legend-dot { width: 9px; height: 9px; border-radius: 2px; }
.legend-income { background: var(--income-bar); }
.legend-expense { background: var(--expense-bar); }

/* 折线的图例：一小段带圆点的线，形状要和图上真正画出来的一致。 */
.legend-line {
  position: relative;
  width: 16px;
  height: 2px;
  border-radius: 1px;
  background: var(--primary);
}

.legend-line::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 6px;
  height: 6px;
  margin: -3px 0 0 -3px;
  border: 2px solid var(--primary);
  border-radius: 50%;
  background: var(--surface);
}

.trend-chart {
  display: block;
  width: 100%;
  height: auto;
}

.grid-line {
  stroke: var(--border);
  stroke-width: 1;
  stroke-dasharray: 3 4;
}

/*
  零轴。有负结余时纵轴会向下扩展到负数区间，这条线就是正负分界，
  必须比普通参考线"实"一些，否则看不出柱子是从哪儿长出来的。
*/
.grid-zero {
  stroke: var(--border-strong);
  stroke-dasharray: none;
}

.axis-line { stroke: var(--border-strong); stroke-width: 1; }

.axis-text {
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.axis-y { fill: var(--text-faint); }
.axis-x { fill: var(--text-muted); }

/*
  关于"没有高亮"这件事：趋势图是固定区间（截至当月的最近 N 个月），
  它不表达"我正在筛哪个月"。因此这里既没有整列高亮底色，也没有柱子/折点的选中态 ——
  不是漏写，而是图与列表各管一件事：图看趋势，列表看明细。
  一旦加上高亮，点一下柱子整张图就要重画，用户刚看到的形状会被换掉。
*/
.bar { transition: opacity .15s ease; cursor: pointer; }
.bar:hover { opacity: .78; }

.bar-income { fill: var(--income-bar); }
.bar-expense { fill: var(--expense-bar); }

/*
  折线压在柱子之上，但鼠标事件必须放行 —— 否则这条横穿图区的线会把
  下方柱子的 hover 与点击全部吃掉。折点单独恢复事件（见 .balance-point）。
*/
.balance-line {
  fill: none;
  stroke: var(--primary);
  stroke-width: 2;
  stroke-linejoin: round;
  stroke-linecap: round;
  pointer-events: none;
}

.balance-point {
  fill: var(--surface);
  stroke: var(--primary);
  stroke-width: 2;
  cursor: pointer;
  transition: r .12s ease;
}

.balance-point:hover { r: 5; }

/* 结余为负的月份换个颜色提示，同时把图标稍微画大一点。 */
.balance-point.is-negative { stroke: var(--income); r: 4.5; }

.chart-hint {
  margin-top: 10px;
  color: var(--text-faint);
  font-size: 12px;
  line-height: 1.7;
}

/* 图表只支持鼠标点击，这里给键盘用户与读屏一条等价通路。 */
.chart-months {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.chart-months-label {
  margin-right: 2px;
  color: var(--text-faint);
  font-size: 12px;
}

.chart-month {
  padding: 3px 11px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text-muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.chart-month:hover {
  background: var(--surface-soft);
  color: var(--text);
  text-decoration: none;
}

.bar-empty {
  stroke: var(--text-faint);
  stroke-width: 2;
  stroke-linecap: round;
}

/* ---------- 表格 ---------- */

.table-wrap { overflow-x: auto; margin: 0 -4px; }

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.data-table th,
.data-table td {
  padding: 10px 8px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: middle;
}

.data-table thead th {
  padding-top: 2px;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
}

.data-table tbody tr:hover { background: var(--surface-soft); }

.data-table tbody tr:last-child td { border-bottom: 0; }

.num { text-align: right; font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }

.col-date { width: 92px; white-space: nowrap; }
.col-cat { width: 132px; }
.col-author { width: 118px; }
.col-source { width: 84px; }
.col-amount { width: 132px; white-space: nowrap; font-weight: 600; }
.col-actions { width: 132px; white-space: nowrap; text-align: right; }

.data-table .col-actions .btn + .btn { margin-left: 4px; }

.date-main { font-variant-numeric: tabular-nums; }
.date-sub { margin-left: 6px; color: var(--text-faint); font-size: 12px; }

.cat-name { display: inline-flex; align-items: center; gap: 7px; }
.cat-dot { flex: 0 0 auto; }

/*
  记账人。只在多人账本里出现，因此视觉上刻意比分类、金额都轻一档：
  它是"这笔是谁记的"的补充信息，不该抢主数据的位置。
*/
.author-chip { display: inline-flex; align-items: center; gap: 6px; max-width: 100%; }

.author-avatar {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 22px;
  height: 22px;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--surface-soft);
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
  line-height: 1;
}

.author-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-muted);
  font-size: 13px;
}

.col-note { max-width: 0; }
.ellipsis {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-muted);
}

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

.source-tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-soft);
  color: var(--text-muted);
  font-size: 12px;
}

.source-alipay { background: #eaf3ff; border-color: #c6dcff; color: #1b64c9; }
.source-wechat { background: #eafaf0; border-color: #bfe8cd; color: #1f8a4c; }

/* ---------- 分页 ---------- */

.pager {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.pager-status { color: var(--text-muted); font-size: 13px; }

/* ---------- 分类占比 ---------- */

.breakdown-list > li + li { margin-top: 16px; }

.breakdown-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 6px;
  font-size: 13px;
}

.breakdown-amount {
  color: var(--text);
  font-variant-numeric: tabular-nums;
  font-weight: 500;
}

.breakdown-percent {
  margin-left: 8px;
  color: var(--text-faint);
  font-size: 12px;
  font-weight: 400;
}

.share-bar {
  display: block;
  width: 100%;
  height: 6px;
  border-radius: 999px;
  overflow: hidden;
}

.share-track { fill: var(--border); }

.breakdown-count {
  display: block;
  margin-top: 5px;
  color: var(--text-faint);
  font-size: 12px;
}

/* ---------- 分类管理 ---------- */

.cat-create { margin-bottom: 18px; }

.cat-group + .cat-group { margin-top: 18px; }

.cat-list > li + li { border-top: 1px solid var(--border); }

.cat-row-form {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 0;
}

.cat-name-input { flex: 1 1 160px; min-width: 120px; }
.cat-type-input { flex: 0 0 96px; width: 96px; }
.cat-color-input { flex: 0 0 auto; }
.cat-usage {
  flex: 0 0 auto;
  min-width: 78px;
  color: var(--text-faint);
  font-size: 12px;
  text-align: right;
}
.cat-row-actions { flex: 0 0 auto; display: inline-flex; gap: 4px; }

@media (max-width: 640px) {
  .cat-row-form { flex-wrap: wrap; }
  .cat-name-input { flex: 1 1 100%; }
  .cat-usage { text-align: left; }
}

/* ---------- 导入页 ---------- */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin: 4px 0 16px;
}

@media (max-width: 720px) {
  .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

.stat-item {
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-soft);
}

.stat-value {
  display: block;
  font-size: 20px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.stat-label {
  display: block;
  margin-top: 2px;
  color: var(--text-muted);
  font-size: 12px;
}

.reasons {
  margin-bottom: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-soft);
  padding: 10px 14px;
}

.reasons summary {
  cursor: pointer;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
}

.reasons ul { margin-top: 8px; }

.reasons li {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 3px 0;
  font-size: 13px;
}

.reason-text { color: var(--text-muted); }
.reason-count { color: var(--text); font-variant-numeric: tabular-nums; }

.notice {
  padding: 12px 14px;
  border: 1px solid var(--warn-border);
  border-radius: var(--radius-sm);
  background: var(--warn-bg);
}

.notice h3 { margin-bottom: 6px; color: #8a6116; }

.notice li {
  position: relative;
  padding-left: 14px;
  color: #6f4f10;
  font-size: 13px;
}

.notice li::before {
  content: "·";
  position: absolute;
  left: 4px;
}

/* 认领历史数据：说明在左、动作在右，窄屏时自动折行堆叠。 */
.claim-notice {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.claim-text { flex: 1 1 320px; min-width: 0; }

.claim-notice h3 { margin-bottom: 4px; }

.claim-notice p { color: #6f4f10; font-size: 13px; }

.claim-notice .btn-primary { width: auto; }

.upload-panel .btn-primary { width: auto; }

/* ---------- 账本管理页 ---------- */

.ledger-forms {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

@media (max-width: 860px) {
  .ledger-forms { grid-template-columns: minmax(0, 1fr); }
}

/* .btn-primary 全局是 100% 宽（侧边表单用），这里要按内容收窄。 */
.ledger-form .btn-primary { width: auto; }

.ledger-cards > * + * { margin-top: 18px; }

/*
  当前账本用左侧色条标记，而不是整块换底色 ——
  卡片里已经有很多彩色徽标，整块染色反而看不出哪个才是重点。
*/
.ledger-card { border-left: 3px solid transparent; }
.ledger-card.is-current { border-left-color: var(--primary); }

.ledger-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.ledger-card-title { min-width: 0; }
.ledger-card-title h2 { margin-bottom: 7px; }
.ledger-card-meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.ledger-card-actions { flex: 0 0 auto; }
.ledger-card-actions .btn { width: auto; }

.ledger-current-tag {
  display: inline-block;
  padding: 5px 12px;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary-dark);
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
}

.ledger-section {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.ledger-section-title {
  margin-bottom: 10px;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
}

.member-list > li + li { margin-top: 2px; }

.member-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 0;
}

.member-avatar {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 26px;
  height: 26px;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--surface-soft);
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
  line-height: 1;
}

.member-name {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.member-self {
  margin-left: 6px;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary-dark);
  font-size: 11px;
}

.member-actions { flex: 0 0 auto; display: inline-flex; gap: 4px; }
.member-actions form { display: inline-flex; }

.invite-box {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.invite-label { flex: 0 0 auto; margin: 0; color: var(--text-muted); font-size: 13px; }

/*
  邀请码用等宽字体 + 拉开字距：12 位无分隔的字符串在比例字体里极易看错，
  而看错一位就等于"邀请码无效"，用户只能来回试。
*/
.invite-code {
  flex: 1 1 220px;
  min-width: 150px;
  padding: 8px 11px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-soft);
  color: var(--text);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 15px;
  letter-spacing: .16em;
}

.invite-box form { display: inline-flex; }
.invite-box .btn { width: auto; }

.ledger-rename {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.ledger-rename .field { flex: 1 1 220px; margin-bottom: 0; }
.ledger-rename .btn { width: auto; }

/*
  危险动作集中放在卡片底部并加上分隔线：
  「退出」只影响自己，「解散」会删掉全账本的流水，两者必须一眼可分。
*/
.ledger-card-foot {
  display: flex;
  gap: 10px;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.ledger-card-foot form { display: inline-flex; }
.ledger-card-foot .btn { width: auto; }

/* ---------- 登录页 ---------- */

/*
  登录页是唯一没有导航的页面，因此让它自己居中收窄，
  而不是撑满整个容器宽度 —— 一个孤零零的全宽按钮会显得很空。
*/
.login-page {
  display: flex;
  justify-content: center;
  padding: 44px 0 64px;
}

.login-card {
  width: 100%;
  max-width: 460px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px;
}

.login-head { margin-bottom: 20px; }
.login-head h1 { font-size: 20px; margin-bottom: 6px; }

.login-error {
  margin-bottom: 16px;
  padding: 10px 12px;
  border: 1px solid #f3c2c2;
  border-radius: var(--radius-sm);
  background: var(--income-soft);
  color: #a61e1e;
  font-size: 13px;
}

.login-cta { width: 100%; }

/* 按钮里的小方块图标：用半透明白底，在实心主色按钮上依然看得出轮廓。 */
.login-cta-icon {
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  border-radius: 6px;
  background: rgba(255, 255, 255, .24);
  font-size: 12px;
  line-height: 1;
}

.login-notice { margin-bottom: 0; }

.login-notice li + li { margin-top: 4px; }

.login-dev {
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px dashed var(--border);
}

.login-dev-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.login-dev-head h2 { font-size: 15px; }

.login-dev .field { margin-top: 14px; }

/* ---------- 页脚 ---------- */

.footer {
  max-width: 1200px;
  margin: 0 auto;
  padding: 8px 24px 40px;
  color: var(--text-faint);
  font-size: 12px;
}

.footer-sub { margin-top: 2px; }

/* ---------- HTMX 请求态 ---------- */

.htmx-request.btn { opacity: .65; }
.htmx-request #dashboard,
#dashboard.htmx-request { opacity: .6; transition: opacity .15s ease; }
