/* ==========================================================================
   清账 Debt Ledger —— 全局样式
   设计原则：简洁、现代、手机优先；避免复杂后台风格与过度动画。
   ========================================================================== */

:root {
  --danger: var(--debt);
  --success: var(--repay);
  --nav-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  overflow-x: hidden;
}

button, input, select, textarea {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

button { cursor: pointer; }
button:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

a { color: var(--brand); }

/* ---------- 通用容器 ---------- */

.wrap {
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  padding: 0 16px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  margin-bottom: 14px;
}

.card-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 15px;
  font-weight: 650;
  margin: 0 0 14px;
}

.card-title .sub {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-3);
}

/* ---------- 欢迎页 ---------- */

.welcome {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px 20px calc(32px + var(--safe-b));
  background:
    radial-gradient(1000px 520px at 50% -10%, var(--brand-glow), transparent 62%),
    var(--bg);
}

.brand {
  text-align: center;
  margin-bottom: 34px;
}

.brand h1 {
  font-size: 40px;
  font-weight: 760;
  letter-spacing: 6px;
  margin: 0 0 6px;
  text-indent: 6px;
}

.brand .en {
  font-size: 11px;
  letter-spacing: 5px;
  color: var(--text-3);
  font-weight: 600;
  text-indent: 5px;
}

.brand .tagline {
  margin-top: 16px;
  font-size: 13px;
  color: var(--text-2);
}

.role-actions {
  width: 100%;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.role-btn {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  padding: 20px 22px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--surface);
  box-shadow: var(--shadow);
  color: var(--text);
  text-align: left;
  transition: transform .15s ease, border-color .15s ease, box-shadow .15s ease;
}

.role-btn:hover { transform: translateY(-2px); border-color: var(--brand); box-shadow: var(--shadow-lg); }
.role-btn:active { transform: translateY(0); }

.role-btn .icon {
  width: 46px;
  height: 46px;
  flex: 0 0 46px;
  border-radius: 13px;
  display: grid;
  place-items: center;
  font-size: 21px;
  background: var(--brand-soft);
  color: var(--brand);
}

.role-btn.alt .icon { background: rgba(139, 92, 246, .12); color: var(--offset); }

.role-btn .txt { min-width: 0; }
.role-btn .txt b { display: block; font-size: 16px; font-weight: 640; }
.role-btn .txt small { display: block; color: var(--text-3); font-size: 12px; margin-top: 2px; }

.welcome-foot {
  margin-top: 28px;
  display: flex;
  gap: 18px;
  font-size: 13px;
  color: var(--text-3);
}

.link-btn {
  background: none;
  border: none;
  color: var(--text-3);
  padding: 4px;
  font-size: 13px;
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* ---------- 表单 ---------- */

.field { margin-bottom: 15px; }

.field label {
  display: block;
  font-size: 13px;
  color: var(--text-2);
  margin-bottom: 6px;
  font-weight: 550;
}

.field .hint {
  font-size: 12px;
  color: var(--text-3);
  margin-top: 5px;
}

.input, .select, .textarea {
  width: 100%;
  padding: 11px 13px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  outline: none;
  transition: border-color .15s ease, box-shadow .15s ease;
}

.input:focus, .select:focus, .textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-soft);
}

.textarea { resize: none; min-height: 90px; }

.amount-input {
  position: relative;
}

.amount-input .prefix {
  position: absolute;
  left: 13px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-3);
  font-size: 15px;
  pointer-events: none;
}

.amount-input .input { padding-left: 30px; font-size: 17px; font-weight: 600; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 11px 18px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: var(--brand-fill);
  color: #fff;
  font-weight: 600;
  font-size: 14px;
  transition: filter .15s ease, opacity .15s ease;
  white-space: nowrap;
}

.btn:hover { filter: brightness(1.06); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn.ghost {
  background: var(--surface);
  color: var(--text);
  border-color: var(--line-strong);
}

.btn.ghost:hover { border-color: var(--brand); color: var(--brand); }

.btn.soft { background: var(--brand-soft); color: var(--brand); }

.btn.danger { background: #a62433; }
.btn.success { background: #126734; }
.btn.block { width: 100%; }
.btn.sm { padding: 7px 12px; font-size: 13px; }

.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }
.btn-row > .btn { flex: 1 1 120px; }

/* 卡片内的操作按钮不撑满宽度，按内容大小排列。 */
.item-actions { justify-content: flex-end; }
.item-actions > .btn { flex: 0 0 auto; }

/* ---------- 应用外壳 ---------- */

.app-header {
  position: sticky;
  top: 0;
  z-index: 30;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--line);
}

.app-header .bar {
  height: 56px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.app-header .title {
  font-weight: 680;
  font-size: 16px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
  flex: 1;
}

.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  background: var(--brand-soft);
  color: var(--brand);
  white-space: nowrap;
}

.badge.creditor { background: rgba(139, 92, 246, .13); color: var(--offset); }
.badge.settled { background: rgba(22, 163, 74, .13); color: var(--success); }
.badge.pending { background: rgba(245, 158, 11, .14); color: var(--warn); }

.icon-btn {
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface);
  display: grid;
  place-items: center;
  font-size: 17px;
  color: var(--text-2);
  padding: 0;
}

.app-main {
  padding: 16px 0 calc(var(--nav-h) + var(--safe-b) + 84px);
}

.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: saturate(180%) blur(14px);
  border-top: 1px solid var(--line);
  padding-bottom: var(--safe-b);
}

.bottom-nav .inner {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  height: var(--nav-h);
  max-width: 720px;
  margin: 0 auto;
}

.nav-item {
  border: none;
  background: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--text-3);
  font-size: 11px;
  padding: 0;
  position: relative;
}

.nav-item .ico { font-size: 19px; line-height: 1; }
.nav-item.active { color: var(--brand); font-weight: 640; }

.nav-item .dot {
  position: absolute;
  top: 9px;
  right: calc(50% - 18px);
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 999px;
  background: var(--debt);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  display: grid;
  place-items: center;
}



/* ---------- 首页仪表盘 ---------- */

.hero {
  background: linear-gradient(135deg, var(--brand-fill) 0%, #5544c3 100%);
  color: #fff;
  border-radius: var(--radius);
  padding: 22px 20px;
  margin-bottom: 14px;
  box-shadow: 0 10px 30px var(--brand-glow);
}

.hero .label {
  font-size: 13px;
  opacity: .95;
  display: flex;
  align-items: center;
  gap: 8px;
}

.hero .amount {
  font-size: 38px;
  font-weight: 760;
  letter-spacing: -0.5px;
  margin: 6px 0 2px;
  word-break: break-all;
}

.hero .meta {
  font-size: 13px;
  opacity: .95;
}

.progress {
  height: 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .26);
  overflow: hidden;
  margin-top: 16px;
}

.progress > i {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: #fff;
  transition: width .4s ease;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 13px 14px;
  min-width: 0;
}

.stat .k {
  font-size: 12px;
  color: var(--text-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stat .v {
  font-size: 19px;
  font-weight: 700;
  margin-top: 3px;
  word-break: break-all;
}

.stat .v.pos { color: var(--debt); }
.stat .v.neg { color: var(--success); }

.alert {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 13px 15px;
  border-radius: var(--radius-sm);
  background: rgba(245, 158, 11, .12);
  border: 1px solid rgba(245, 158, 11, .3);
  color: var(--text);
  margin-bottom: 14px;
  width: 100%;
  text-align: left;
}

.alert .txt { flex: 1; min-width: 0; font-size: 14px; }
.alert .txt b { display: block; }

/* ---------- 图表 ---------- */

.chart-box {
  position: relative;
  width: 100%;
  height: 220px;
}

.chart-box.tall { height: 240px; }

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  margin-top: 12px;
  font-size: 12px;
  color: var(--text-2);
}

.chart-legend span { display: inline-flex; align-items: center; gap: 6px; }

.chart-legend i {
  width: 9px;
  height: 9px;
  border-radius: 3px;
  display: inline-block;
}

/* ---------- 列表 ---------- */

.list { display: flex; flex-direction: column; gap: 10px; }

.item {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 13px 14px;
  min-width: 0;
}

.item .row1 {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.item .row1 .t {
  font-weight: 620;
  font-size: 14px;
  min-width: 0;
  overflow-wrap: anywhere;
}

.item .row1 .m {
  font-size: 15px;
  font-weight: 700;
  white-space: nowrap;
  flex-shrink: 0;
}

.item .row2 {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 7px;
  font-size: 12px;
  color: var(--text-3);
}

.item .note {
  margin-top: 7px;
  font-size: 13px;
  color: var(--text-2);
  overflow-wrap: anywhere;
}

.m-pos { color: var(--debt); }
.m-neg { color: var(--success); }
.m-off { color: var(--offset); }

.tag {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 6px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--text-2);
  white-space: nowrap;
}

.tag.up { background: rgba(229, 72, 77, .1); color: var(--debt); border-color: transparent; }
.tag.down { background: rgba(22, 163, 74, .1); color: var(--success); border-color: transparent; }
.tag.off { background: rgba(139, 92, 246, .1); color: var(--offset); border-color: transparent; }
.tag.wait { background: rgba(245, 158, 11, .12); color: var(--warn); border-color: transparent; }
.tag.ok { background: rgba(22, 163, 74, .1); color: var(--success); border-color: transparent; }
.tag.no { background: rgba(229, 72, 77, .1); color: var(--debt); border-color: transparent; }

/* ---------- 分段控件 / 标签页 ---------- */

.segmented {
  display: flex;
  gap: 4px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 4px;
  margin-bottom: 14px;
  overflow-x: auto;
}

.segmented button {
  flex: 1 1 auto;
  min-width: max-content;
  border: none;
  background: none;
  padding: 8px 13px;
  border-radius: 9px;
  font-size: 13px;
  font-weight: 560;
  color: var(--text-2);
  white-space: nowrap;
}

.segmented button.active {
  background: var(--surface);
  color: var(--brand);
  font-weight: 660;
  box-shadow: var(--shadow);
}

/* ---------- 日历 ---------- */

.cal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.cal-head .m {
  font-weight: 700;
  font-size: 16px;
  min-width: 0;
}

.cal-week {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 4px;
  margin-bottom: 6px;
}

.cal-week span {
  text-align: center;
  font-size: 11px;
  color: var(--text-3);
  padding: 4px 0;
}

.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 4px;
}

.cal-day {
  aspect-ratio: 1 / 1;
  min-height: 54px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: var(--surface-2);
  padding: 4px 3px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 2px;
  overflow: hidden;
  min-width: 0;
}

.cal-day.out { color: var(--text-3); background: transparent; }
.cal-day.today { border-color: var(--brand); }
.cal-day.sel { background: var(--brand-fill); color: #fff; }
.cal-day.sel .d, .cal-day.sel .amt { color: #fff; }
.cal-day.sel .amt { opacity: .92; }

.cal-day .d {
  font-size: 12px;
  font-weight: 620;
  line-height: 1.1;
}

.cal-day .amt {
  font-size: 9px;
  line-height: 1.1;
  color: var(--text-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.cal-day .amt.up { color: var(--debt); }
.cal-day .amt.down { color: var(--success); }

.cal-day .dots { display: flex; gap: 2px; margin-top: 1px; }
.cal-day .dots i { width: 4px; height: 4px; border-radius: 50%; background: var(--brand); }
.cal-day .dots i.up { background: var(--debt); }
.cal-day .dots i.down { background: var(--success); }
.cal-day .dots i.off { background: var(--offset); }

/* ---------- 底部弹层（记账面板等） ---------- */

.sheet {
  position: fixed;
  left: 0;
  right: 0;
  top: auto;
  bottom: var(--keyboard-offset, 0px);
  width: 100%;
  max-width: none;
  margin: 0;
  border: 0;
  background: var(--surface);
  color: var(--text);
  border-radius: 20px 20px 0 0;
  box-shadow: var(--shadow-lg);
  max-height: calc(92dvh - var(--keyboard-offset, 0px));
  display: flex;
  flex-direction: column;
  padding: 0 0 var(--safe-b);
}

.sheet:not([open]) { display: none; }
.sheet::backdrop, .modal::backdrop { background: rgba(10, 12, 18, .5); }

.sheet .handle {
  width: 38px;
  height: 4px;
  border-radius: 999px;
  background: var(--line-strong);
  margin: 10px auto 4px;
  flex-shrink: 0;
}

.sheet .shead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 18px 12px;
  flex-shrink: 0;
}

.sheet .shead h3 { margin: 0; font-size: 17px; font-weight: 680; }

.sheet .sbody {
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0 18px 18px;
}

.type-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 9px;
  margin-bottom: 16px;
}

.type-btn {
  border: 1px solid var(--line-strong);
  background: var(--surface-2);
  border-radius: 12px;
  padding: 12px 10px;
  font-size: 13px;
  font-weight: 580;
  color: var(--text-2);
  text-align: center;
}

.type-btn.active {
  border-color: var(--brand);
  background: var(--brand-soft);
  color: var(--brand);
  font-weight: 660;
}

.preview {
  background: var(--surface-2);
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 13px 14px;
  font-size: 13px;
  color: var(--text-2);
  margin-bottom: 16px;
}

.preview .big {
  font-size: 19px;
  font-weight: 700;
  color: var(--text);
  margin-top: 3px;
}

/* ---------- 弹窗提示 ---------- */

.toast-wrap {
  position: fixed;
  left: 0;
  right: 0;
  top: 14px;
  z-index: 90;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
  padding: 0 16px;
}

.toast {
  max-width: 420px;
  width: 100%;
  padding: 11px 15px;
  border-radius: 11px;
  background: rgba(22, 25, 32, .94);
  color: #fff;
  font-size: 13.5px;
  box-shadow: var(--shadow-lg);
  animation: toast-in .22s ease;
}

.toast.err { background: rgba(190, 42, 47, .96); }
.toast.ok { background: rgba(21, 128, 61, .96); }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------- 空状态 / 加载 ---------- */

.empty {
  text-align: center;
  padding: 34px 18px;
  color: var(--text-3);
}

.empty .ico { font-size: 34px; margin-bottom: 10px; opacity: .55; }
.empty .t { font-size: 14px; font-weight: 560; color: var(--text-2); margin-bottom: 4px; }
.empty .s { font-size: 12.5px; }

.skeleton {
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--line) 37%, var(--surface-2) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.3s infinite;
  border-radius: 10px;
  height: 74px;
  margin-bottom: 10px;
}

@keyframes shimmer {
  from { background-position: 100% 0; }
  to { background-position: 0 0; }
}

/* ---------- 键值表 ---------- */

.kv {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}

.kv:last-child { border-bottom: none; }
.kv .k { color: var(--text-2); flex-shrink: 0; }
.kv .v { text-align: right; overflow-wrap: anywhere; min-width: 0; }

.code-box {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 8px;
  text-align: center;
  padding: 16px;
  background: var(--surface-2);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  margin: 4px 0 12px;
}

.key-box {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
  line-height: 1.8;
  word-break: break-all;
  background: var(--surface-2);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 13px;
  margin: 4px 0 12px;
  user-select: all;
}

.notice {
  font-size: 13px;
  line-height: 1.6;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: rgba(245, 158, 11, .1);
  border: 1px solid rgba(245, 158, 11, .28);
  color: var(--text-2);
  margin-bottom: 14px;
}

.notice.info { background: var(--brand-soft); border-color: var(--brand-glow); }
.notice.danger { background: rgba(229, 72, 77, .09); border-color: rgba(229, 72, 77, .26); }

/* ---------- 详情弹窗 ---------- */

.modal {
  width: calc(100% - 32px);
  max-width: 420px;
  bottom: var(--keyboard-offset, 0px);
  max-height: calc(84dvh - var(--keyboard-offset, 0px));
  overflow-y: auto;
  background: var(--surface);
  color: var(--text);
  border: 0;
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-lg);
}

.modal h3 { margin: 0 0 14px; font-size: 17px; font-weight: 680; }

/* ---------- 工具类 ---------- */

.row { display: flex; align-items: center; gap: 10px; }
.row.between { justify-content: space-between; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.mt8 { margin-top: 8px; }
.mt12 { margin-top: 12px; }
.mt16 { margin-top: 16px; }
.mb0 { margin-bottom: 0; }
.text-2 { color: var(--text-2); }
.text-3 { color: var(--text-3); }
.small { font-size: 12.5px; }
.center { text-align: center; }
.hidden { display: none !important; }
.nowrap { white-space: nowrap; }
.divider { height: 1px; background: var(--line); margin: 14px 0; }

@media (max-width: 380px) {
  .hero .amount { font-size: 32px; }
  .stat .v { font-size: 17px; }
  .wrap { padding: 0 12px; }
}

@media (min-width: 721px) {
  .stat-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .bottom-nav .inner { max-width: 720px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

