/* US Bill — clear family-color system, Apple rhythm */

:root {
  --label: #1d1d1f;
  --secondary: #6e6e73;
  --tertiary: #86868b;
  --bg: #ffffff;
  --bg-alt: #f5f5f7;
  --separator: rgba(0, 0, 0, 0.08);
  --fill: rgba(0, 0, 0, 0.04);
  --blue: #0066cc;
  --blue-hover: #0077ed;
  --nav-h: 48px;
  --wide: 1080px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display",
    "Helvetica Neue", "PingFang SC", "Hiragino Sans GB", system-ui, sans-serif;
  --ease: cubic-bezier(0.28, 0.11, 0.32, 1);

  /* Family colors — distinct, Apple-soft */
  --f-me: #1d1d1f;
  --f-me-bg: #f5f5f7;
  --f-me-soft: rgba(29, 29, 31, 0.08);
  --f-henry: #0071e3;
  --f-henry-bg: #e8f2ff;
  --f-henry-soft: rgba(0, 113, 227, 0.12);
  --f-peter: #bf4800;
  --f-peter-bg: #fff1e6;
  --f-peter-soft: rgba(191, 72, 0, 0.12);
  --f-enzo: #7c3aed;
  --f-enzo-bg: #f3e8ff;
  --f-enzo-soft: rgba(124, 58, 237, 0.12);
  --ok: #1d8348;
  --warn: #b25000;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--label);
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.47;
  letter-spacing: -0.022em;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  /* 移动端：修复 iOS Safari 点击无响应 */
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }
input { font: inherit; }

/* 可点击元素移动端触控优化 */
.due-card, .chip {
  -webkit-user-select: none;
  user-select: none;
}

/* Nav */
.globalnav {
  position: sticky; top: 0; z-index: 100;
  height: var(--nav-h);
  background: rgba(22,22,23,.72);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
}
.wrap {
  width: min(var(--wide), calc(100vw - 40px));
  margin: 0 auto;
}
.globalnav .wrap {
  height: 100%;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
}
.brand { color: #f5f5f7; font-size: 12px; font-weight: 600; opacity: .92; }
.nav-links { display: flex; gap: 2px; overflow-x: auto; }
.nav-link {
  color: #f5f5f7; font-size: 12px; opacity: .8; padding: 0 11px;
  height: var(--nav-h); display: inline-flex; align-items: center; white-space: nowrap;
}
.nav-link:hover { opacity: 1; }

/* Hero — focus on money owed */
.hero {
  padding: 56px 0 28px;
  text-align: center;
}
.eyebrow {
  margin: 0 0 8px;
  color: var(--secondary);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: .04em;
  text-transform: uppercase;
}
.display {
  margin: 0;
  font-size: clamp(40px, 8vw, 64px);
  font-weight: 600;
  letter-spacing: -.02em;
  line-height: 1.05;
}
.hero-sub {
  margin: 12px auto 0;
  max-width: 28em;
  color: var(--secondary);
  font-size: 17px;
}

/* Legend */
.legend {
  display: flex; flex-wrap: wrap; justify-content: center; gap: 10px 18px;
  margin: 22px auto 0;
}
.legend-item {
  display: inline-flex; align-items: center; gap: 8px;
  font-size: 13px; color: var(--secondary);
}
.swatch {
  width: 10px; height: 10px; border-radius: 50%;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.06);
}
.family-swatch { background: var(--family-color); }

/* Due board */
.due-board {
  background: var(--bg-alt);
  border-top: 1px solid var(--separator);
  border-bottom: 1px solid var(--separator);
  padding: 36px 0 40px;
}
.due-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0,1fr));
  gap: 14px;
}
.due-card {
  position: relative;
  background: #fff;
  border-radius: 20px;
  padding: 22px 20px 18px;
  border: 1px solid var(--separator);
  overflow: hidden;
  min-height: 168px;
}
.due-card::before {
  content: "";
  position: absolute; left: 0; top: 0; bottom: 0; width: 5px;
}
.due-card.henry::before { background: var(--f-henry); }
.due-card.peter::before { background: var(--f-peter); }
.due-card.enzo::before { background: var(--f-enzo); }
.due-card.family-card::before { background: var(--family-color); }
.due-card.me,
.due-card.owner {
  grid-column: 1 / -1;
  background: var(--family-soft, var(--f-me-bg));
  border: 0;
  min-height: auto;
  padding: 18px 20px;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 12px;
}
.due-card.me::before,
.due-card.owner::before { display: none; }

.due-name {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  display: flex; align-items: center; gap: 8px;
}
.due-name .dot { width: 9px; height: 9px; border-radius: 50%; }
.due-name.henry .dot, .swatch.henry, .pill.henry { background: var(--f-henry); }
.due-name.peter .dot, .swatch.peter, .pill.peter { background: var(--f-peter); }
.due-name.enzo .dot, .swatch.enzo, .pill.enzo { background: var(--f-enzo); }
.due-name.me .dot, .swatch.me, .pill.me { background: var(--f-me); }
.due-card.family-card .due-name .dot { background: var(--family-color); }

.due-label {
  margin: 6px 0 0;
  color: var(--tertiary);
  font-size: 12px;
}
.due-amount {
  margin: 18px 0 4px;
  font-size: clamp(30px, 4vw, 40px);
  font-weight: 600;
  letter-spacing: -.03em;
  font-variant-numeric: tabular-nums;
  line-height: 1.05;
}
.due-card.henry .due-amount { color: var(--f-henry); }
.due-card.peter .due-amount { color: var(--f-peter); }
.due-card.enzo .due-amount { color: var(--f-enzo); }
.due-card.family-card .due-amount { color: var(--family-color); }
.due-card.me .due-amount,
.due-card.owner .due-amount {
  margin: 0;
  font-size: clamp(24px, 3vw, 32px);
  color: var(--family-color, var(--label));
  text-align: right;
}
.due-note {
  color: var(--tertiary);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
.due-bars {
  margin-top: 14px;
  display: flex; flex-direction: column; gap: 6px;
}
.bar-row {
  display: grid;
  grid-template-columns: 42px 1fr 64px;
  gap: 8px;
  align-items: center;
  font-size: 11px;
  color: var(--secondary);
  font-variant-numeric: tabular-nums;
}
.bar-track {
  height: 6px;
  border-radius: 99px;
  background: var(--fill);
  overflow: hidden;
}
.bar-fill {
  height: 100%;
  border-radius: 99px;
  background: currentColor;
  opacity: .85;
}
.due-card.henry .bar-fill { background: var(--f-henry); }
.due-card.peter .bar-fill { background: var(--f-peter); }
.due-card.enzo .bar-fill { background: var(--f-enzo); }
.due-card.family-card .bar-fill { background: var(--family-color); }

/* Totals strip */
.totals {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0;
  border-bottom: 1px solid var(--separator);
}
.totals > div {
  padding: 22px 12px;
  text-align: center;
  border-right: 1px solid var(--separator);
}
.totals > div:last-child { border-right: 0; }
.totals .k {
  color: var(--tertiary);
  font-size: 12px;
  margin-bottom: 6px;
}
.totals .v {
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -.02em;
  font-variant-numeric: tabular-nums;
}

/* Section */
.section { padding: 56px 0 64px; }
.section.alt { background: var(--bg-alt); }
.section-head { margin-bottom: 22px; }
.section-head h2 {
  margin: 0;
  font-size: clamp(28px, 4vw, 36px);
  font-weight: 600;
  letter-spacing: -.015em;
}
.section-head p {
  margin: 8px 0 0;
  color: var(--secondary);
  font-size: 15px;
}

/* Filters — collapsible sticky bar */
.filter-panel {
  position: sticky;
  top: calc(var(--nav-h) + 8px);
  z-index: 40;
  margin: 0 0 14px;
  border-radius: 16px;
  background: #fff;
  border: 1px solid var(--separator);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.05);
  overflow: hidden;
}
.filter-panel-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 10px 10px 12px;
}
.filter-toggle {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 8px;
  border-radius: 12px;
  text-align: left;
}
.filter-toggle:hover { background: var(--bg-alt); }
.filter-toggle-main {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.filter-panel-title {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.filter-summary {
  font-size: 12px;
  font-weight: 500;
  color: var(--secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-variant-numeric: tabular-nums;
}
.filter-summary.has-filter {
  color: var(--blue);
  font-weight: 600;
}
.filter-toggle-action {
  flex-shrink: 0;
  font-size: 12px;
  font-weight: 600;
  color: var(--blue);
  padding: 4px 8px;
  border-radius: 980px;
  background: rgba(0, 102, 204, 0.08);
}
.filter-body {
  display: none;
  padding: 0 14px 14px;
  border-top: 1px solid var(--separator);
}
.filter-panel.is-open .filter-body {
  display: block;
  padding-top: 12px;
}
.filter-panel.is-open .filter-panel-head {
  padding-bottom: 8px;
}
.filter-block + .filter-block { margin-top: 12px; }
.filter-block-label {
  margin: 0 0 8px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--tertiary);
}
.toolbar {
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
}
.toolbar-search { flex: 1; min-width: 0; width: 100%; }
.chip {
  padding: 8px 13px;
  border-radius: 980px;
  background: #fff;
  border: 1px solid var(--separator);
  font-size: 13px;
  font-weight: 600;
  color: var(--secondary);
  transition: background .15s var(--ease), color .15s var(--ease), border-color .15s var(--ease), box-shadow .15s var(--ease);
}
.chip:hover { color: var(--label); border-color: rgba(0,0,0,.16); }
.chip.active {
  background: var(--label);
  border-color: var(--label);
  color: #fff;
  box-shadow: 0 1px 2px rgba(0,0,0,.12);
}
/* Family chips: soft tint when idle, solid family color when active */
.chip-family.henry { color: var(--f-henry); border-color: rgba(0, 113, 227, 0.28); background: var(--f-henry-bg); }
.chip-family.peter { color: var(--f-peter); border-color: rgba(191, 72, 0, 0.28); background: var(--f-peter-bg); }
.chip-family.enzo { color: var(--f-enzo); border-color: rgba(124, 58, 237, 0.28); background: var(--f-enzo-bg); }
.chip-family.me { color: var(--f-me); border-color: rgba(29, 29, 31, 0.18); background: var(--f-me-bg); }
.chip-family.dynamic { color: var(--family-color); border-color: var(--family-soft); background: var(--family-soft); }
.chip-family.henry.active { background: var(--f-henry); border-color: var(--f-henry); color: #fff; }
.chip-family.peter.active { background: var(--f-peter); border-color: var(--f-peter); color: #fff; }
.chip-family.enzo.active { background: var(--f-enzo); border-color: var(--f-enzo); color: #fff; }
.chip-family.me.active { background: var(--f-me); border-color: var(--f-me); color: #fff; }
.chip-family.dynamic.active { background: var(--family-color); border-color: var(--family-color); color: #fff; }
.chip-reset {
  flex-shrink: 0;
  background: var(--bg-alt);
  padding: 7px 12px;
  font-size: 12px;
}
.search {
  flex: 1; min-width: 140px; width: 100%;
  border: 1px solid var(--separator);
  background: var(--bg-alt);
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 14px;
  outline: none;
}
.search:focus { box-shadow: 0 0 0 3px rgba(0,102,204,.15); border-color: transparent; background: #fff; }

/* Due cards are clickable filters */
.due-card {
  cursor: pointer;
  transition: transform .15s var(--ease), box-shadow .15s var(--ease);
}
.due-card:hover {
  transform: translateY(-1px);
  box-shadow: 0 10px 24px rgba(0,0,0,.06);
}
.due-card:focus-visible {
  outline: 3px solid rgba(0, 102, 204, 0.35);
  outline-offset: 2px;
}
.due-card.is-filter-active {
  box-shadow: 0 0 0 2px currentColor, 0 10px 24px rgba(0,0,0,.06);
}
.due-card.henry.is-filter-active { color: var(--f-henry); }
.due-card.peter.is-filter-active { color: var(--f-peter); }
.due-card.enzo.is-filter-active { color: var(--f-enzo); }
.due-card.me.is-filter-active { color: var(--f-me); box-shadow: 0 0 0 2px var(--f-me); }
.due-card.family-card.is-filter-active { color: var(--family-color); box-shadow: 0 0 0 2px var(--family-color), 0 10px 24px rgba(0,0,0,.06); }
.due-hint {
  margin-top: 10px;
  font-size: 11px;
  color: var(--tertiary);
}

/* Ledger */
.ledger {
  background: #fff;
  border: 1px solid var(--separator);
  border-radius: 18px;
  overflow: hidden;
}
.ledger-day {
  padding: 10px 18px 8px;
  border-top: 1px solid var(--separator);
  background: var(--bg-alt);
  color: var(--secondary);
  font-size: 11px;
  font-weight: 600;
  line-height: 1.3;
  letter-spacing: 0;
}
.ledger-day:first-child { border-top: 0; }
.entry {
  display: grid;
  grid-template-columns: 76px minmax(0,1fr) auto;
  gap: 14px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--separator);
  align-items: start;
}
.entry:last-child { border-bottom: 0; }
.entry:hover { background: rgba(0,0,0,.015); }

/* Left rail follows each family's proportional share, top to bottom. */
.entry {
  position: relative;
  padding-left: 22px;
}
.entry::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 4px;
  background: var(--entry-rail, #c7c7cc);
}
.entry.tone-henry { border-left-color: var(--f-henry); background: linear-gradient(90deg, var(--f-henry-soft), transparent 42%); }
.entry.tone-peter { border-left-color: var(--f-peter); background: linear-gradient(90deg, var(--f-peter-soft), transparent 42%); }
.entry.tone-enzo { border-left-color: var(--f-enzo); background: linear-gradient(90deg, var(--f-enzo-soft), transparent 42%); }
.entry.tone-me { border-left-color: #c7c7cc; }
.entry.tone-multi { border-left-color: #a1a1a6; }
.entry.tone-family { border-left-color: var(--entry-color); background: linear-gradient(90deg, var(--entry-soft), transparent 42%); }

.date .d { font-size: 16px; font-weight: 600; letter-spacing: -.02em; }
.date .m { margin-top: 2px; font-size: 11px; color: var(--tertiary); }

.entry h3 {
  margin: 0 0 3px;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -.016em;
}
.entry .desc {
  margin: 0;
  color: var(--secondary);
  font-size: 13px;
  line-height: 1.4;
}

.pills {
  display: flex; flex-wrap: wrap; gap: 6px;
  margin-top: 10px;
}
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 9px;
  border-radius: 980px;
  font-size: 11px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--label);
  background: var(--fill);
}
.pill.henry { background: var(--f-henry-bg); color: #004a99; }
.pill.peter { background: var(--f-peter-bg); color: #8a3a00; }
.pill.enzo { background: var(--f-enzo-bg); color: #5b21b6; }
.pill.me { background: var(--f-me-soft); color: var(--label); }
.pill.cat { font-weight: 500; color: var(--secondary); background: var(--fill); }
.pill.cat.dynamic { background: var(--category-color); color: var(--label); }
.pill.status-ok { background: #e7f7ee; color: var(--ok); }
.pill.status-pending { background: #fff1e0; color: var(--warn); }

.amt {
  text-align: right;
  min-width: 110px;
  font-variant-numeric: tabular-nums;
}
.amt .total {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -.02em;
}
.entry.is-settled .amt .total { color: var(--ok); }
.amt-splits {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  margin-top: 5px;
}
.amt-split {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 5px;
  color: var(--secondary);
  font-size: 11px;
  font-weight: 600;
  line-height: 1.35;
  white-space: nowrap;
}
.amt-split-dot {
  width: 6px;
  height: 6px;
  flex: 0 0 6px;
  border-radius: 50%;
  background: var(--family-color);
}
.amt .who {
  margin-top: 5px;
  font-size: 11px;
  color: var(--tertiary);
  line-height: 1.35;
}

.empty {
  padding: 40px;
  text-align: center;
  color: var(--tertiary);
}

/* Rules compact */
.rules {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}
.rule {
  background: #fff;
  border: 1px solid var(--separator);
  border-radius: 16px;
  padding: 18px;
}
.rule h3 { margin: 0 0 6px; font-size: 14px; }
.rule p { margin: 0; color: var(--secondary); font-size: 13px; line-height: 1.45; }
.rule code {
  font-family: "SF Mono", ui-monospace, Menlo, monospace;
  font-size: 12px;
  background: var(--fill);
  padding: 1px 5px;
  border-radius: 5px;
}

.footer {
  border-top: 1px solid var(--separator);
  padding: 24px 0 40px;
  color: var(--tertiary);
  font-size: 12px;
  display: flex; justify-content: space-between; flex-wrap: wrap; gap: 10px;
}
.footer a { color: var(--blue); }
.footer a:hover { color: var(--blue-hover); }
#sync-status.is-stale { color: var(--warn); }

/* ========== 加载更多按钮 ========== */

.load-more-wrap {
  padding: 16px;
  text-align: center;
  border-top: 1px solid var(--separator);
}
.load-more-btn {
  padding: 10px 24px;
  border-radius: 980px;
  background: var(--bg-alt);
  border: 1px solid var(--separator);
  font-size: 14px;
  font-weight: 600;
  color: var(--blue);
  cursor: pointer;
  transition: background .15s var(--ease);
  -webkit-user-select: none;
  user-select: none;
}
.load-more-btn:hover { background: #ebebed; }
.load-more-btn:disabled {
  color: var(--tertiary);
  cursor: default;
  opacity: .6;
}

/* ========== 骨架屏加载动画 ========== */

.skeleton-entry {
  display: grid;
  grid-template-columns: 76px minmax(0,1fr) auto;
  gap: 14px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--separator);
  align-items: start;
}
.skeleton-entry:last-child { border-bottom: 0; }
.sk-block {
  border-radius: 6px;
  background: linear-gradient(90deg, #f0f0f0 25%, #e8e8e8 50%, #f0f0f0 75%);
  background-size: 200% 100%;
  animation: sk-shimmer 1.5s infinite;
}
.sk-date-day { width: 48px; height: 18px; }
.sk-date-meta { width: 36px; height: 12px; margin-top: 4px; }
.sk-title { width: 70%; height: 18px; }
.sk-desc { width: 90%; height: 14px; margin-top: 6px; }
.sk-pills { width: 50%; height: 22px; margin-top: 10px; border-radius: 980px; }
.sk-amount { width: 80px; height: 20px; margin-left: auto; }
.sk-who { width: 56px; height: 12px; margin-top: 6px; margin-left: auto; }
@keyframes sk-shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ========== 响应式 — 移动端增强 ========== */

@media (max-width: 820px) {
  .wrap { width: calc(100vw - 24px); }
  .due-grid { grid-template-columns: 1fr; }
  .due-card.me, .due-card.owner { grid-column: auto; }
  .totals { grid-template-columns: 1fr; }
  .totals > div { border-right: 0; border-bottom: 1px solid var(--separator); }
  .rules { grid-template-columns: 1fr; }
  .ledger-day { padding: 10px 12px 8px; }
  .entry { grid-template-columns: 60px minmax(0,1fr) auto; gap: 10px; padding: 14px 12px 14px 16px; }
  .amt { min-width: 116px; text-align: right; }
  .amt .total { font-size: 15px; white-space: nowrap; }
  .skeleton-entry { grid-template-columns: 60px minmax(0,1fr) auto; gap: 10px; padding: 14px 12px; }
  .hero { padding: 40px 0 20px; }
  .section { padding: 36px 0 44px; }
  .filter-panel { top: calc(var(--nav-h) + 4px); border-radius: 12px; }
  .footer { flex-direction: column; }
  .footer > * + * { margin-left: 0; margin-top: 4px; }
}

@media (max-width: 360px) {
  .entry { grid-template-columns: 52px minmax(0, 1fr); }
  .amt {
    grid-column: 2;
    min-width: 0;
    text-align: right;
  }
  .amt-splits { align-items: flex-end; }
  .skeleton-entry { grid-template-columns: 52px minmax(0, 1fr); }
  .skeleton-entry > :last-child { display: none; }
}
