/* =========================================================
   贷款账簿 · 样式
   移动优先，桌面端自动收窄成居中卡片
   ========================================================= */

:root {
  --bg: #eff2f7;
  --bg-2: #e6ebf4;
  --card: #ffffff;
  --card-2: #f7f9fc;
  --text: #101828;
  --text-2: #475467;
  --muted: #7a8699;
  --line: #e4e8f0;
  --primary: #2f6bf6;
  --primary-2: #1e4fd0;
  --primary-soft: #eaf0ff;
  --accent: #0d9f6e;
  --accent-soft: #e6f7f0;
  --warn: #b7791f;
  --warn-soft: #fdf5e4;
  --danger: #d93a3f;
  --danger-soft: #fdeceb;
  --radius: 18px;
  --radius-sm: 12px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .05);
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 12px 28px -18px rgba(16, 24, 40, .35);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB",
          "Microsoft YaHei UI", "Microsoft YaHei", "Source Han Sans SC", "Noto Sans CJK SC", sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, "Roboto Mono", monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1218;
    --bg-2: #131a23;
    --card: #161d27;
    --card-2: #1b2430;
    --text: #e9eef6;
    --text-2: #a9b6c8;
    --muted: #7f8da1;
    --line: #26303d;
    --primary: #5b8dff;
    --primary-2: #3f74ea;
    --primary-soft: #18233a;
    --accent: #35c294;
    --accent-soft: #122c25;
    --warn: #e2b25a;
    --warn-soft: #2a2114;
    --danger: #ff6b6b;
    --danger-soft: #2c1618;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow: 0 1px 2px rgba(0, 0, 0, .35), 0 18px 40px -24px rgba(0, 0, 0, .8);
  }
}

/* 手动选的黑夜（不跟随系统时用它） */
:root[data-theme="dark"] {
  --bg: #0e1218;
  --bg-2: #131a23;
  --card: #161d27;
  --card-2: #1b2430;
  --text: #e9eef6;
  --text-2: #a9b6c8;
  --muted: #7f8da1;
  --line: #26303d;
  --primary: #5b8dff;
  --primary-2: #3f74ea;
  --primary-soft: #18233a;
  --accent: #35c294;
  --accent-soft: #122c25;
  --warn: #e2b25a;
  --warn-soft: #2a2114;
  --danger: #ff6b6b;
  --danger-soft: #2c1618;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow: 0 1px 2px rgba(0, 0, 0, .35), 0 18px 40px -24px rgba(0, 0, 0, .8);
}

* { box-sizing: border-box; }
/* 任何带 display 的元素都要能被 hidden 属性关掉 */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}

.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.is-hidden { display: none !important; }
svg { width: 20px; height: 20px; display: block; }

h1, h2, h3, p { margin: 0; }

button { font-family: inherit; }

/* ------------------------------- 启动页 ------------------------------- */
.boot {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: var(--bg);
  transition: opacity .35s ease;
}
.boot.done { opacity: 0; pointer-events: none; }
.boot-logo {
  width: 68px; height: 68px;
  border-radius: 20px;
  display: grid; place-items: center;
  font-size: 30px; font-weight: 700; color: #fff;
  background: linear-gradient(150deg, #4c86ff, #1c3fb8);
  box-shadow: 0 18px 40px -18px rgba(47, 107, 246, .9);
}
.boot-text { color: var(--muted); font-size: 14px; }

/* -------------------------------- 登录 -------------------------------- */
.auth {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(24px + env(safe-area-inset-top)) 20px calc(24px + env(safe-area-inset-bottom));
  background:
    radial-gradient(1100px 520px at 50% -12%, rgba(47, 107, 246, .20), transparent 62%),
    var(--bg);
}
.auth-inner { width: 100%; max-width: 400px; }

.brand {
  display: flex; align-items: center; gap: 14px;
  margin-bottom: 26px;
}
.brand-mark {
  width: 52px; height: 52px; flex: none;
  border-radius: 16px;
  display: grid; place-items: center;
  font-size: 24px; font-weight: 700; color: #fff;
  background: linear-gradient(150deg, #4c86ff, #1c3fb8);
  box-shadow: 0 14px 26px -14px rgba(47, 107, 246, .85);
}
.brand-mark-sm { width: 36px; height: 36px; border-radius: 11px; font-size: 17px; }
.brand h1 { font-size: 22px; letter-spacing: -.2px; }
.brand p { color: var(--muted); font-size: 13px; margin-top: 3px; }

.auth-card {
  background: var(--card);
  border-radius: 22px;
  padding: 22px;
  box-shadow: var(--shadow);
  border: 1px solid var(--line);
}

.tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  background: var(--card-2);
  border-radius: 12px;
  margin-bottom: 20px;
}
.tab {
  border: 0;
  background: transparent;
  color: var(--text-2);
  padding: 9px 0;
  border-radius: 9px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background .18s, color .18s, box-shadow .18s;
}
.tab.is-active {
  background: var(--card);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

.auth-hint {
  margin: 0 0 12px;
  font-size: 12px;
  line-height: 1.6;
  color: var(--muted);
  background: var(--primary-soft, rgba(79, 140, 255, 0.09));
  padding: 8px 12px;
  border-radius: 10px;
}
.auth-error {
  margin: 0 0 12px;
  font-size: 13px;
  color: var(--danger);
  background: var(--danger-soft);
  padding: 9px 12px;
  border-radius: 10px;
}
/* 出错的那个输入框描红 */
.input-invalid {
  border-color: var(--danger) !important;
  box-shadow: 0 0 0 3px rgba(217, 58, 63, 0.14) !important;
}

/* -------------------------------- 按钮 -------------------------------- */
.btn {
  border: 0;
  border-radius: 12px;
  padding: 12px 18px;
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: transform .12s ease, filter .18s ease, background .18s;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.btn:active { transform: scale(.985); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { filter: brightness(1.06); }
.btn-primary:disabled { opacity: .6; cursor: default; }
.btn-block { width: 100%; margin-top: 4px; }
.btn-ghost { background: var(--card-2); color: var(--text-2); }
.btn-danger { background: var(--danger-soft); color: var(--danger); }

.icon-btn {
  width: 36px; height: 36px;
  flex: none;
  display: grid; place-items: center;
  border: 0; border-radius: 11px;
  background: transparent;
  color: var(--text-2);
  cursor: pointer;
  transition: background .18s, color .18s;
}
.icon-btn:hover { background: var(--card-2); color: var(--text); }
.icon-btn.danger:hover { background: var(--danger-soft); color: var(--danger); }
.text-btn {
  border: 0; background: transparent;
  color: var(--primary); font-weight: 700; font-size: 15px;
  padding: 8px 4px; cursor: pointer;
}

/* -------------------------------- 主界面 ------------------------------ */
.app {
  min-height: 100dvh;
  padding: 0 16px calc(120px + env(safe-area-inset-bottom));
  max-width: 720px;
  margin: 0 auto;
}

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
  padding: calc(14px + env(safe-area-inset-top)) 0 12px;
}
.topbar-title { display: flex; align-items: center; gap: 10px; min-width: 0; }
.topbar-title strong { display: block; font-size: 16px; letter-spacing: -.2px; }
.topbar-user {
  display: block; font-size: 12px; color: var(--muted);
  margin-top: 2px;
  max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.topbar-actions { display: flex; gap: 4px; }

/* -------------------------------- 还款提醒 ------------------------------ */

.reminder {
  display: flex;
  align-items: center;
  gap: 13px;
  margin-bottom: 14px;
  padding: 13px 15px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.reminder-icon {
  flex: 0 0 auto;
  width: 40px; height: 40px;
  display: grid; place-items: center;
  border-radius: 13px;
  background: var(--primary-soft);
  color: var(--primary);
}
.reminder-icon svg { width: 21px; height: 21px; }

.reminder-main { flex: 1 1 auto; min-width: 0; }
.reminder-label { margin: 0; font-size: 11.5px; color: var(--muted); }

.reminder-line {
  margin: 3px 0 0;
  display: flex; align-items: baseline; gap: 8px;
  flex-wrap: nowrap;
}
.reminder-line strong { font-size: 16px; letter-spacing: -.2px; flex: 0 0 auto; }
.reminder-line strong[data-state="today"] { color: var(--danger); }
.reminder-line strong[data-state="soon"] { color: var(--warn); }
.reminder-name {
  font-size: 12.5px; color: var(--muted);
  max-width: 6.5em; min-width: 0; flex: 1 1 auto;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.reminder-amount { font-size: 13.5px; font-weight: 650; color: var(--text-2); flex: 0 0 auto; }

.reminder-side { flex: 0 0 auto; text-align: right; }
.reminder-total {
  margin: 3px 0 0;
  font-size: 17px; font-weight: 700; letter-spacing: -.3px;
}

/* -------------------------------- 小控件 -------------------------------- */

.chip-btn {
  margin-left: 6px;
  padding: 1px 7px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--card-2);
  color: var(--text-2);
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
}
.chip-btn:hover { border-color: var(--primary); color: var(--primary); }

input[type="date"] {
  height: 46px;
  width: 100%;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--card-2);
  color: var(--text);
  font: inherit;
  font-size: 15px;
  outline: none;
}
input[type="date"]:focus { border-color: var(--primary); background: var(--card); }

/* -------------------------------- 汇总卡 ------------------------------ */
.summary {
  position: relative;
  overflow: hidden;
  border-radius: 22px;
  padding: 22px 20px 18px;
  color: #eaf0ff;
  background: linear-gradient(160deg, #24314a 0%, #1a2437 55%, #131b29 100%);
  box-shadow: 0 22px 44px -28px rgba(16, 24, 40, .9);
}
.summary::after {
  content: "";
  position: absolute;
  top: -70px; right: -60px;
  width: 220px; height: 220px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(84, 132, 255, .45), transparent 68%);
  pointer-events: none;
}
.summary-label { font-size: 12.5px; color: #9fb0c9; letter-spacing: .3px; }
.summary-value {
  margin-top: 6px;
  font-size: 36px;
  line-height: 1.1;
  font-weight: 700;
  letter-spacing: -1px;
  font-variant-numeric: tabular-nums;
  display: flex; align-items: baseline; gap: 4px;
}
.summary-value .cny { font-size: 18px; font-weight: 600; color: #9fb0c9; }
.summary-sub { margin-top: 6px; font-size: 12.5px; color: #8fa1bb; }

.summary-grid {
  margin-top: 18px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 2px;
  border-top: 1px solid rgba(255, 255, 255, .09);
  padding-top: 14px;
}
.summary-cell { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.cell-label { font-size: 11px; color: #8fa1bb; white-space: nowrap; }
.cell-value {
  font-size: 13.5px; font-weight: 650;
  font-variant-numeric: tabular-nums;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* -------------------------------- 列表 -------------------------------- */
.list-section { margin-top: 26px; }
.section-head {
  display: flex; align-items: baseline; justify-content: space-between;
  margin-bottom: 12px;
}
.section-head h2 { font-size: 15px; font-weight: 700; }
.muted { color: var(--muted); font-size: 12.5px; }

.loan-list { display: flex; flex-direction: column; gap: 12px; }

.loan-card {
  position: relative;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 16px 14px;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: transform .14s ease, box-shadow .2s ease, border-color .2s;
  text-align: left;
  width: 100%;
  font-family: inherit;
  color: inherit;
}
.loan-card:hover { box-shadow: var(--shadow); border-color: color-mix(in srgb, var(--primary) 30%, var(--line)); }
.loan-card:active { transform: scale(.99); }

.loan-top { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.loan-name {
  font-size: 15.5px; font-weight: 650; letter-spacing: -.2px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  flex: 1 1 auto; min-width: 7em;
}
.chip {
  font-size: 11px; padding: 3px 8px; border-radius: 999px;
  background: var(--card-2); color: var(--text-2);
  font-weight: 600; white-space: nowrap;
}
.chip-accent { background: var(--primary-soft); color: var(--primary); }

.loan-money {
  margin-top: 12px;
  display: flex; align-items: baseline; gap: 6px;
  font-variant-numeric: tabular-nums;
}
.loan-money .amount { font-size: 21px; font-weight: 700; letter-spacing: -.5px; }
.loan-money .unit { font-size: 12px; color: var(--muted); }
.loan-money .amount-missing { font-size: 15px; font-weight: 600; color: var(--muted); letter-spacing: 0; }

.loan-meta {
  margin-top: 10px;
  display: flex; flex-wrap: wrap; gap: 6px 16px;
  font-size: 12.5px; color: var(--text-2);
  font-variant-numeric: tabular-nums;
}
.loan-meta b { font-weight: 650; color: var(--text); }

.progress {
  margin-top: 12px;
  height: 5px;
  border-radius: 999px;
  background: var(--card-2);
  overflow: hidden;
}
.progress-bar {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #4c86ff, #2f6bf6);
  transition: width .5s cubic-bezier(.2, .8, .2, 1);
}
.loan-progress-label {
  margin-top: 7px;
  display: flex; justify-content: space-between;
  font-size: 11px; color: var(--muted);
}
.loan-incomplete {
  margin-top: 10px;
  font-size: 12px;
  color: var(--warn);
  background: var(--warn-soft);
  padding: 7px 10px;
  border-radius: 9px;
  line-height: 1.5;
}

.empty {
  text-align: center;
  padding: 44px 20px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--card) 60%, transparent);
}
.empty-icon { font-size: 32px; }
.empty-title { margin-top: 10px; font-weight: 650; font-size: 14.5px; }
.empty-desc { margin-top: 6px; font-size: 13px; color: var(--muted); line-height: 1.7; }

/* --------------------------------- FAB -------------------------------- */
.fab {
  position: fixed;
  right: max(20px, calc(50vw - 340px));
  bottom: calc(22px + env(safe-area-inset-bottom));
  width: 58px; height: 58px;
  border-radius: 19px;
  border: 0;
  display: grid; place-items: center;
  color: #fff;
  background: linear-gradient(150deg, #4c86ff, #2350d8);
  box-shadow: 0 16px 30px -12px rgba(47, 107, 246, .8);
  cursor: pointer;
  transition: transform .16s ease;
  z-index: 30;
}
.fab:hover { transform: translateY(-2px); }
.fab:active { transform: scale(.94); }
.fab svg { width: 26px; height: 26px; }

/* ------------------------------- 弹层 --------------------------------- */
.sheet {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.sheet[hidden] { display: none; }
.sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(9, 14, 22, .48);
  backdrop-filter: blur(3px);
  animation: fade .2s ease;
}
.sheet-panel {
  position: relative;
  width: 100%;
  max-width: 560px;
  max-height: 92dvh;
  display: flex;
  flex-direction: column;
  background: var(--card);
  border-radius: 24px 24px 0 0;
  box-shadow: 0 -18px 50px -24px rgba(0, 0, 0, .5);
  animation: slide-up .26s cubic-bezier(.2, .85, .25, 1);
  overflow: hidden;
}
@keyframes slide-up { from { transform: translateY(24px); opacity: .6; } to { transform: none; opacity: 1; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.sheet-head {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 12px 10px;
  border-bottom: 1px solid var(--line);
  flex: none;
}
.sheet-head h2 { flex: 1; font-size: 15.5px; font-weight: 700; text-align: center; }
.head-actions { display: flex; gap: 2px; }

.sheet-body {
  padding: 16px 18px calc(28px + env(safe-area-inset-bottom));
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 0;
}
/* 关键：子元素不允许被压缩，否则计算面板会被挤成 2px 高、表单也不会滚动 */
.sheet-body > * { flex: 0 0 auto; }

@media (min-width: 640px) {
  .sheet { align-items: center; }
  .sheet-panel { border-radius: 22px; max-height: 88dvh; }
}

@media (min-width: 860px) {
  .app { max-width: 940px; }
  .loan-list { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; align-items: start; }
}

/* ------------------------------- 表单 --------------------------------- */
.field { display: flex; flex-direction: column; gap: 7px; }
.field > span {
  font-size: 12.5px; font-weight: 600; color: var(--text-2);
}
.field > span em, .hint-inline {
  font-style: normal; font-weight: 500; color: var(--muted); font-size: 11.5px;
}
.field input, .field select, .field textarea {
  width: 100%;
  font-family: inherit;
  font-size: 15px;
  color: var(--text);
  background: var(--card-2);
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 12px 14px;
  outline: none;
  transition: border-color .18s, background .18s, box-shadow .18s;
}
.field textarea { resize: vertical; min-height: 54px; line-height: 1.55; }
.field input::placeholder, .field textarea::placeholder { color: var(--muted); opacity: .8; }
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--primary);
  background: var(--card);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 16%, transparent);
}
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field-wide { grid-column: 1 / -1; }

.input-wrap { position: relative; display: flex; align-items: center; }
.input-wrap input { padding-right: 42px; font-variant-numeric: tabular-nums; }
.input-wrap em {
  position: absolute; right: 14px;
  font-style: normal; font-size: 12px; color: var(--muted);
  pointer-events: none;
}

.tip {
  font-size: 12.5px;
  line-height: 1.7;
  color: var(--text-2);
  background: var(--primary-soft);
  border-radius: 12px;
  padding: 11px 13px;
}
.tip strong { color: var(--primary); }

/* --------------------------- 实时计算面板 ----------------------------- */
.calc-panel {
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
  background: var(--card-2);
}
.calc-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 13px;
  font-size: 12px; font-weight: 700; color: var(--text-2);
  background: color-mix(in srgb, var(--primary) 7%, transparent);
}
.calc-head .badge { font-weight: 600; }
.calc-rows { display: flex; flex-direction: column; }
.calc-row {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 13px;
  font-size: 13px;
  border-top: 1px solid var(--line);
}
.calc-row:first-child { border-top: 0; }
.calc-row .k { color: var(--text-2); flex: none; width: 128px; }
.calc-row .v {
  flex: 1; text-align: right;
  font-variant-numeric: tabular-nums; font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.calc-row .tag {
  flex: none;
  font-size: 10px; font-weight: 700;
  padding: 2px 6px; border-radius: 6px;
  background: var(--accent-soft); color: var(--accent);
}
.calc-row .tag.manual { background: var(--card); color: var(--muted); border: 1px solid var(--line); }
.calc-row .tag.empty { background: var(--warn-soft); color: var(--warn); }
.calc-row.is-derived .v { color: var(--accent); }
.calc-row.is-total {
  background: var(--accent-soft);
  font-weight: 700;
}
.calc-row.is-total .k { color: var(--text); font-weight: 700; }
.calc-row.is-total .v { font-size: 14px; }
.calc-empty { padding: 16px 13px; font-size: 13px; color: var(--muted); line-height: 1.6; }
.calc-warn {
  padding: 10px 13px;
  font-size: 12.5px;
  line-height: 1.65;
  color: var(--warn);
  background: var(--warn-soft);
  border-top: 1px solid var(--line);
}
.calc-error {
  padding: 10px 13px;
  font-size: 12.5px;
  line-height: 1.65;
  color: var(--danger);
  background: var(--danger-soft);
  border-top: 1px solid var(--line);
}

/* ------------------------------- 详情 --------------------------------- */
.detail-hero {
  border-radius: 18px;
  padding: 18px;
  background: linear-gradient(160deg, #24314a, #151d2b);
  color: #eaf0ff;
}
.detail-hero .k { font-size: 12px; color: #9fb0c9; }
.detail-hero .v {
  margin-top: 4px; font-size: 30px; font-weight: 700;
  letter-spacing: -.8px; font-variant-numeric: tabular-nums;
}
.detail-hero .v small { font-size: 15px; color: #9fb0c9; margin-right: 3px; font-weight: 600; }

.kv { display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
.kv-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 11px 14px; font-size: 13.5px;
  border-top: 1px solid var(--line);
  background: var(--card);
}
.kv-row:first-child { border-top: 0; }
.kv-row .k { color: var(--text-2); }
.kv-row .v { font-weight: 650; font-variant-numeric: tabular-nums; text-align: right; }
.kv-row .v small { color: var(--muted); font-weight: 500; margin-left: 4px; }

.sched-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-top: 4px;
}
.sched-toggle {
  border: 0; background: transparent; color: var(--primary);
  font-size: 13px; font-weight: 650; cursor: pointer; padding: 6px 0;
  display: inline-flex; align-items: center; gap: 4px;
}
.sched-toggle svg { width: 15px; height: 15px; transition: transform .2s; }
.sched-toggle[aria-expanded="true"] svg { transform: rotate(90deg); }

table.sched {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  margin-top: 8px;
}
table.sched th {
  text-align: right; font-weight: 600; color: var(--muted);
  padding: 8px 6px; border-bottom: 1px solid var(--line);
  position: sticky; top: 0; background: var(--card); z-index: 1;
}
table.sched th:first-child, table.sched td:first-child { text-align: left; }
table.sched td { padding: 7px 6px; text-align: right; border-bottom: 1px solid var(--line); }
table.sched tr.is-paid td { color: var(--muted); }
table.sched tr.is-paid td:first-child::after {
  content: " · "; color: var(--accent); font-size: 10px;
}
.sched-wrap { max-height: 380px; overflow-y: auto; border-radius: 12px; }

/* -------------------------------- Toast ------------------------------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(96px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(8px);
  max-width: min(88vw, 420px);
  padding: 11px 16px;
  border-radius: 12px;
  background: rgba(23, 31, 44, .95);
  color: #f2f6fc;
  font-size: 13.5px;
  line-height: 1.5;
  box-shadow: 0 14px 34px -14px rgba(0, 0, 0, .7);
  opacity: 0;
  transition: opacity .2s ease, transform .25s cubic-bezier(.2, .8, .2, 1);
  z-index: 120;
  text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { background: rgba(180, 40, 44, .96); }

/* ------------------------------- 杂项 --------------------------------- */
body.lock { overflow: hidden; }

.badge {
  display: inline-flex;
  align-items: center;
  font-size: 10.5px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  white-space: nowrap;
}
.badge.muted { background: var(--card); color: var(--muted); }

.detail-hero .loan-progress-label { color: #9fb0c9; }
.detail-hero + .progress { margin-top: 14px; }

/* ------------------------------ 骨架加载 ------------------------------ */.skeleton {
  height: 96px;
  border-radius: var(--radius);
  background: linear-gradient(100deg, var(--card) 30%, var(--card-2) 50%, var(--card) 70%);
  background-size: 240% 100%;
  animation: shimmer 1.4s infinite linear;
}
@keyframes shimmer { from { background-position: 140% 0; } to { background-position: -40% 0; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}

/* ---------------------------- 类型筛选 chips ---------------------------- */
.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 2px 2px 12px;
  scrollbar-width: none;
}
.filters::-webkit-scrollbar { display: none; }
.filter-chip {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--card);
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
}
.filter-chip span {
  font-size: 11px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--line);
  color: var(--muted);
}
.filter-chip:hover { color: var(--text); }
.filter-chip.is-active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
.filter-chip.is-active span { background: rgba(255, 255, 255, .22); color: #fff; }

.empty-inline {
  padding: 28px 16px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
}

/* -------------------------- 多笔借款（循环贷）-------------------------- */
.parts-list { display: flex; flex-direction: column; gap: 12px; }
.part-card {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--card);
  padding: 12px 12px 10px;
}
.part-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 10px;
}
.part-title { font-size: 13px; font-weight: 700; color: var(--primary); }
.part-del {
  width: 26px; height: 26px;
  border: 0; border-radius: 50%;
  background: var(--danger-soft); color: var(--danger);
  font-size: 17px; line-height: 1; cursor: pointer;
}
.part-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px;
}
.part-grid .field > span { font-size: 12px; }
.part-grid .input-wrap input { font-size: 14px; }
.part-fee {
  display: flex; flex-direction: column; gap: 8px;
  margin-top: 10px;
}
.part-fee .check-inline { font-size: 12.5px; }
.part-fee .input-wrap { max-width: 200px; }
.part-fee .input-wrap input {
  width: 100%;
  font-family: inherit; font-size: 14px; color: var(--text);
  background: var(--card-2);
  border: 1px solid transparent; border-radius: 12px;
  padding: 10px 56px 10px 14px;
  outline: none;
  font-variant-numeric: tabular-nums;
}
.part-fee .input-wrap input:focus {
  border-color: var(--primary); background: var(--card);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 16%, transparent);
}
.part-calc {
  margin: 8px 0 0;
  font-size: 12px;
  line-height: 1.6;
  color: var(--accent);
}
.part-calc.is-warn { color: var(--warn); }
.part-need { display: block; color: var(--muted); }

/* -------------------------- 中途利率调整 -------------------------- */
.rate-head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  margin-bottom: 8px; font-size: 13px; color: var(--text-2);
}
.rates-list { display: flex; flex-direction: column; gap: 10px; }
.rate-card {
  border: 1px dashed var(--line);
  border-radius: var(--radius-sm);
  padding: 10px 10px 8px;
  background: var(--card-2);
}
.rate-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.rate-grid .field > span { font-size: 12px; }
.rate-grid .input-wrap input { font-size: 14px; }
.rate-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 8px; }
.rate-mode {
  flex: 1; min-width: 0;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--card); color: var(--text-2);
  font: inherit; font-size: 12px; padding: 7px 8px;
}
.chip-rate { background: rgba(224, 145, 42, .14); color: var(--warn); }
.rate-old { font-style: normal; color: var(--muted); font-size: 11px; }

.add-part-btn {
  width: 100%;
  margin-top: 12px;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 12px;
  border: 1px dashed var(--primary);
  border-radius: var(--radius-sm);
  background: var(--primary-soft);
  color: var(--primary);
  font: inherit; font-size: 14px; font-weight: 600;
  cursor: pointer;
}
.add-part-btn svg { width: 16px; height: 16px; }

/* 详情页的明细汇总 */
.parts-summary {
  margin: 14px 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--card);
  overflow: hidden;
}
.parts-summary-head {
  display: flex; justify-content: space-between;
  padding: 10px 14px;
  font-size: 12px; font-weight: 700; color: var(--muted);
  background: var(--primary-soft);
}
.part-item { padding: 11px 14px; border-top: 1px solid var(--line); }
.part-item-top {
  display: flex; justify-content: space-between; align-items: baseline;
  font-size: 13px;
}
.part-item-top b { font-weight: 700; }
.part-item-err { font-size: 11px; color: var(--warn); }
.part-item-meta { margin-top: 3px; font-size: 12px; color: var(--muted); }
.part-item-money { margin-top: 2px; font-size: 12px; color: var(--text); }

/* ------------------------------ 鼓励语 · 设置 ------------------------------ */
.encourage {
  margin: 10px 2px 2px;
  padding: 10px 14px;
  font-size: 12.5px;
  line-height: 1.6;
  color: var(--muted);
  background: var(--card);
  border: 1px dashed var(--line);
  border-radius: 12px;
  text-align: center;
}
.encourage-settings { margin: 4px 0 18px; text-align: left; }

/* 设置里的「进入管理后台」入口（只有管理员账号看得到） */
.settings-link {
  display: flex; align-items: center; gap: 10px;
  margin: 0 0 14px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--card-2);
  color: var(--text);
  font-size: 14px; font-weight: 650;
  text-decoration: none;
}
.settings-link:active { opacity: .8; }
.settings-link-icon { width: 18px; height: 18px; color: var(--primary); flex: 0 0 auto; }
.settings-link span { flex: 1 1 auto; }
.settings-link-arrow { width: 16px; height: 16px; color: var(--muted); flex: 0 0 auto; }

.profile-form { display: flex; flex-direction: column; gap: 12px; }.profile-form .btn-primary { margin-top: 4px; }

.danger-zone {
  border: 1px solid rgba(217, 58, 63, .28);
  border-radius: 14px;
  padding: 14px;
  background: rgba(217, 58, 63, .05);
}
.danger-zone h3 { margin: 0 0 6px; font-size: 14px; color: var(--danger); }
#delete-confirm .danger-desc { margin-top: 12px; }
.danger-desc { margin: 0 0 12px; font-size: 12.5px; line-height: 1.6; color: var(--muted); }
.danger-desc b { color: var(--text); }
.btn-danger {
  width: 100%;
  margin-top: 10px;
  padding: 13px;
  border: none;
  border-radius: 12px;
  background: var(--danger);
  color: #fff;
  font: inherit;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
}
.btn-danger:active { opacity: .85; }

/* ---------------------- 每期其他费用 / 金额口径切换 ---------------------- */
.summary-label-btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 0; border: 0; background: none; cursor: pointer;
  color: inherit; font: inherit;
}
.summary-label-btn .summary-label { border-bottom: 1px dashed rgba(159,176,201,.5); }
.summary-label-btn:hover .summary-label,
.summary-label-btn.is-total .summary-label { color: #dbe6f7; }
.swap-icon { width: 13px; height: 13px; flex: 0 0 auto; opacity: .6; }
.summary-label-btn:hover .swap-icon,
.summary-label-btn.is-total .swap-icon { opacity: 1; }

.loan-money[data-amount-toggle] { cursor: pointer; }
.loan-money[data-amount-toggle]:active .amount { opacity: .7; }
.loan-money .amount-swap { align-self: center; margin-left: 2px; opacity: .45; }
.loan-money[data-amount-toggle]:hover .amount-swap { opacity: .9; }

.fee-note { font-style: normal; color: var(--muted); font-size: 12px; }

.check-inline {
  display: inline-flex; align-items: center; gap: 8px;
  font-size: 13px; font-weight: 600; color: var(--text-2);
  cursor: pointer;
}
.check-inline input[type="checkbox"] {
  width: 18px; height: 18px; accent-color: var(--primary); cursor: pointer;
}
#fee-wrap { margin-top: 8px; }
.cell-note {
  display: inline-block; margin-left: 3px;
  font-size: 10px; font-style: normal; font-weight: 500;
  color: #8fa1bb; opacity: .9;
  padding: 0 3px; border-radius: 4px;
  background: rgba(255,255,255,.08);
}
.detail-switch {
  display: flex; gap: 6px;
  margin: 10px 0 4px;
  padding: 4px;
  border-radius: 12px;
  background: var(--field);
}
.detail-switch button {
  flex: 1 1 0;
  padding: 8px 6px;
  border: 0; border-radius: 9px;
  background: transparent;
  color: var(--muted);
  font: inherit; font-size: 12.5px; font-weight: 600;
  cursor: pointer;
}
.detail-switch button.is-active {
  background: var(--card);
  color: var(--primary);
  font-weight: 700;
  box-shadow: 0 1px 3px rgba(15, 23, 42, .12);
}

/* --------------------------- 只记欠款（最低还款） --------------------------- */
.owed-pay {
  margin: 4px 0 10px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--card);
  overflow: hidden;
}
.pay-form {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 10px;
  padding: 12px;
  border-bottom: 1px solid var(--line);
}
.pay-form .field { flex: 1 1 120px; min-width: 0; }
.pay-form .btn { flex: 0 0 auto; padding: 10px 16px; }
.pay-form input { font-size: 14px; }
.form-error {
  margin: 0 12px 10px;
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 12.5px;
  line-height: 1.6;
  color: var(--danger);
  background: var(--danger-soft);
}
.pay-list { padding: 4px 12px 10px; }
.pay-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 0;
  border-bottom: 1px dashed var(--line);
  font-size: 13.5px;
}
.pay-item:last-child { border-bottom: 0; }
.pay-date { color: var(--muted); flex: 1 1 auto; }
.pay-amount { font-weight: 700; font-variant-numeric: tabular-nums; }
.pay-del {
  flex: 0 0 auto;
  width: 24px; height: 24px;
  border: 0; border-radius: 50%;
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 15px; line-height: 1;
  cursor: pointer;
}
.brand-mark[href] { text-decoration: none; cursor: pointer; }
.brand-mark[href]:active { transform: scale(.96); }

/* ------------------------------- 广告位 ------------------------------- */
/* 一块固定比例的原生卡片：图片按 cover 填满，永不拉变形；没广告时是一块克制的虚线位。 */
.ad-slot { margin: 22px 0; }
.ad-slot[hidden] { display: none !important; }

.ad-card {
  position: relative;
  isolation: isolate;
  border-radius: 18px;
  overflow: hidden;
  border: 1px solid var(--line);
  background: var(--card);
  box-shadow: var(--shadow);
  aspect-ratio: var(--ad-ratio, 4 / 1);
  transition: transform .16s ease, box-shadow .16s ease;
}
.ad-card .ad-link { display: block; width: 100%; height: 100%; }
.ad-card img {
  position: relative;
  z-index: 0;
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
}
.ad-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.ad-card:has(.ad-link):hover { cursor: pointer; }

/* 「推广」角标：永远压在图片上面（动图也一样），不参与鼠标事件 */
.ad-badge {
  position: absolute;
  top: 10px; right: 10px;
  z-index: 3;
  font-size: 11px; line-height: 1;
  color: #fff;
  background: rgba(15, 23, 42, .55);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  padding: 5px 9px;
  border-radius: 999px;
  letter-spacing: .04em;
  pointer-events: none;
  box-shadow: 0 1px 3px rgba(15, 23, 42, .18);
}

.ad-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 76px;
  padding: 18px;
  border: 1px dashed var(--line);
  border-radius: 18px;
  background: rgba(246, 249, 253, .6);
  color: var(--muted);
  font-size: 12.5px;
}
.ad-empty-tag {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .04em;
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(47, 107, 246, .1);
  color: var(--primary);
}
.ad-empty-text { opacity: .9; }
@media (min-width: 860px) {
  /* 两列贷款列表时，广告位横跨整行 */
  .loan-list .ad-slot { grid-column: 1 / -1; }
}

/* ------------------- 左右两侧跟随滚动的广告位（宽屏才出现） ------------------- */
.ad-rail {
  position: fixed;
  top: 92px;
  width: 176px;
  display: none;
  flex-direction: column;
  gap: 16px;
  z-index: 5;
  pointer-events: auto;
}
.ad-rail-left { left: max(16px, calc((100vw - 1180px) / 2 - 196px)); }
.ad-rail-right { right: max(16px, calc((100vw - 1180px) / 2 - 196px)); }
/* 竖栏广告：默认按 176 × 440 显示（2:5），屏幕不够高时自动缩短，保证两条都完整可见 */
.ad-rail { top: 40px; gap: 16px; }
.ad-rail .ad-slot {
  width: 176px;
  aspect-ratio: auto;
  height: min(440px, calc((100dvh - 132px) / 2 - 8px));
}

/* 只有两侧真能腾出位置时才显示（窄屏藏起来，别糊在内容上） */
@media (min-width: 1600px) {
  .ad-rail { display: flex; }
}

/* ------------------------------- 友情链接 ------------------------------- */
.links {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin: 30px auto 6px;
}
.links-label {
  font-size: 12.5px;
  color: var(--muted-2, #6d819c);
  margin-right: 2px;
}
.link-chip {
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--line, rgba(0, 0, 0, .08));
  font-size: 13px;
  color: var(--muted, #6b7c93);
  text-decoration: none;
  transition: color .16s, border-color .16s, background .16s;
}
.link-chip:hover {
  color: var(--primary, #4b8bf5);
  border-color: var(--primary, #4b8bf5);
  background: rgba(75, 139, 245, .08);
}

/* 内容区广告位按设计尺寸封顶，超宽屏不再无限放大 */
.ad-slot { max-width: 960px; margin-left: auto; margin-right: auto; }
.loan-list .ad-slot { max-width: none; }

/* 竖栏里的空闲位：窄一点，改成竖排居中 */
.ad-rail .ad-empty {
  flex-direction: column;
  justify-content: center;
  gap: 8px;
  padding: 12px 10px;
  text-align: center;
  height: 100%;
}
.ad-rail .ad-empty-text { font-size: 11.5px; line-height: 1.5; }
.ad-rail .ad-empty-tag { font-size: 10.5px; }

/* ------------------- 顶栏固定：往下滚的时候一直贴在顶部 ------------------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  margin: 0 -16px;
  padding-left: 16px;
  padding-right: 16px;
  background: rgba(244, 247, 251, .9); /* 旧浏览器兜底 */
  background: color-mix(in srgb, var(--bg) 90%, transparent);
  -webkit-backdrop-filter: saturate(1.3) blur(10px);
  backdrop-filter: saturate(1.3) blur(10px);
}
