/* =========================================================
   资金台账 — Apple blue / frosted glass design tokens
   ========================================================= */
:root {
  color-scheme: light;
  --bg: #eef2f8;
  --bg-soft: #e7edf6;
  --surface: rgba(255, 255, 255, 0.7);
  --surface-2: rgba(255, 255, 255, 0.52);
  --surface-3: rgba(255, 255, 255, 0.38);
  --glass-bg: rgba(255, 255, 255, 0.64);
  --glass-bg-strong: rgba(255, 255, 255, 0.8);
  --glass-bg-subtle: rgba(255, 255, 255, 0.48);
  --glass-border: rgba(255, 255, 255, 0.74);
  --glass-blur: blur(30px) saturate(180%);
  --glass-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.62), 0 18px 48px rgba(24, 50, 92, 0.12);
  --ink: #1d1d1f;
  --ink-2: #424245;
  --muted: #6e6e73;
  --faint: #86868b;
  --line: rgba(60, 60, 67, 0.12);
  --line-strong: rgba(60, 60, 67, 0.22);
  --hover: rgba(0, 113, 227, 0.07);
  --primary: #0071e3;
  --primary-strong: #0062c4;
  --primary-soft: rgba(0, 113, 227, 0.12);
  --primary-gradient: linear-gradient(180deg, #2b95ff 0%, #0071e3 100%);
  --on-primary: #ffffff;
  --action: var(--primary);
  --action-hover: var(--primary-strong);
  --on-action: #ffffff;
  --credit: #0071e3;
  --credit-soft: rgba(0, 113, 227, 0.1);
  --credit-line: rgba(0, 113, 227, 0.24);
  --prepaid: #3f6ea8;
  --prepaid-soft: rgba(63, 110, 168, 0.1);
  --danger: #d70015;
  --danger-soft: rgba(255, 59, 48, 0.1);
  --danger-line: rgba(255, 59, 48, 0.24);
  --corporate: #0071e3;
  --corporate-soft: rgba(0, 113, 227, 0.1);
  --personal: #6e6e73;
  --personal-soft: rgba(110, 110, 115, 0.09);
  --radius-xl: 32px;
  --radius-lg: 26px;
  --radius: 22px;
  --radius-sm: 18px;
  --radius-xs: 14px;
  --radius-pill: 999px;
  --bg-veil: linear-gradient(
    180deg,
    rgba(244, 248, 253, 0.72) 0%,
    rgba(242, 247, 253, 0.55) 18%,
    rgba(238, 244, 252, 0.24) 46%,
    rgba(244, 248, 253, 0.38) 100%
  );
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: "SFMono-Regular", "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --duration: 180ms;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #0b0b0d;
    --bg-soft: #101014;
    --surface: rgba(32, 32, 36, 0.66);
    --surface-2: rgba(44, 44, 50, 0.58);
    --surface-3: rgba(58, 58, 66, 0.48);
    --glass-bg: rgba(28, 28, 32, 0.62);
    --glass-bg-strong: rgba(34, 34, 40, 0.82);
    --glass-bg-subtle: rgba(28, 28, 32, 0.46);
    --glass-border: rgba(255, 255, 255, 0.12);
    --glass-blur: blur(30px) saturate(160%);
    --glass-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08), 0 20px 60px rgba(0, 0, 0, 0.48);
    --ink: #f5f5f7;
    --ink-2: #d2d2d7;
    --muted: #a1a1a6;
    --faint: #7c7c82;
    --line: rgba(255, 255, 255, 0.1);
    --line-strong: rgba(255, 255, 255, 0.18);
    --hover: rgba(10, 132, 255, 0.12);
    --primary: #0a84ff;
    --primary-strong: #409cff;
    --primary-soft: rgba(10, 132, 255, 0.18);
    --primary-gradient: linear-gradient(180deg, #3d9bff 0%, #0a84ff 100%);
    --on-primary: #ffffff;
    --action: var(--primary);
    --action-hover: var(--primary-strong);
    --on-action: #ffffff;
    --credit: #0a84ff;
    --credit-soft: rgba(10, 132, 255, 0.16);
    --credit-line: rgba(10, 132, 255, 0.3);
    --prepaid: #8fb6e8;
    --prepaid-soft: rgba(143, 182, 232, 0.12);
    --danger: #ff6961;
    --danger-soft: rgba(255, 105, 97, 0.14);
    --danger-line: rgba(255, 105, 97, 0.3);
    --corporate: #6cb2ff;
    --corporate-soft: rgba(10, 132, 255, 0.16);
    --personal: #a1a1a6;
    --personal-soft: rgba(255, 255, 255, 0.08);
    --bg-veil: linear-gradient(
      180deg,
      rgba(5, 8, 14, 0.72) 0%,
      rgba(5, 8, 14, 0.5) 18%,
      rgba(5, 8, 14, 0.28) 46%,
      rgba(5, 8, 14, 0.45) 100%
    );
  }
}

/* =========================================================
   Reset & base
   ========================================================= */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  touch-action: pan-x pan-y;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
  touch-action: pan-x pan-y;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

/* 全站风景背景：每次访问随机一张，固定铺满视口 */
.app-bg {
  position: fixed;
  inset: 0;
  z-index: -1;
  background-color: var(--bg);
  background-image: var(--app-bg-image, none);
  background-position: center;
  background-size: cover;
  background-repeat: no-repeat;
  pointer-events: none;
}

.app-bg::after {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--bg-veil);
}

body.no-scroll {
  overflow: hidden;
}

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

h1, h2, h3, h4 {
  line-height: 1.25;
  letter-spacing: -0.015em;
}

button,
input,
select,
textarea {
  font-family: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
}

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

a:hover {
  text-decoration: underline;
}

svg {
  display: block;
}

[hidden] {
  display: none !important;
}

::selection {
  background: var(--primary);
  color: #ffffff;
}

:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.shell {
  width: 100%;
  max-width: 1180px;
  margin: 0 auto;
  padding-left: 28px;
  padding-right: 28px;
}

.page {
  padding-top: 30px;
  padding-bottom: 80px;
  min-height: calc(100dvh - 64px);
}

.muted { color: var(--muted); }
.faint { color: var(--faint); }
.tnum { font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }
.align-right { text-align: right; }

.eyebrow {
  margin: 0 0 7px;
  color: var(--faint);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

/* =========================================================
   Brand
   ========================================================= */
.brand {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  color: inherit;
  text-decoration: none;
}

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

.brand-mark {
  display: inline-flex;
  width: 36px;
  height: 36px;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  background: var(--primary-gradient);
  color: #ffffff;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.35), 0 6px 16px rgba(0, 113, 227, 0.28);
  flex: 0 0 auto;
}

.brand-mark svg {
  width: 22px;
  height: 22px;
}

.brand-mark-lg {
  width: 44px;
  height: 44px;
  border-radius: 15px;
}

.brand-text {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}

.brand-name {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.brand-kicker {
  color: var(--faint);
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.18em;
}

/* =========================================================
   Boot / error screens
   ========================================================= */
.boot-screen {
  display: flex;
  min-height: 100vh;
  min-height: 100dvh;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 28px;
  padding: 24px;
}

.boot-brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.boot-title {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.boot-sub {
  color: var(--muted);
  font-size: 13px;
}

.boot-loader {
  width: 120px;
  height: 2px;
  overflow: hidden;
  border-radius: 2px;
  background: var(--line);
}

.boot-loader span {
  display: block;
  width: 40%;
  height: 100%;
  border-radius: 2px;
  background: var(--primary-gradient);
  animation: boot-slide 1.1s ease-in-out infinite;
}

@keyframes boot-slide {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(300%); }
}

.noscript {
  padding: 24px;
  text-align: center;
  color: var(--muted);
}

/* =========================================================
   Buttons
   ========================================================= */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 40px;
  padding: 9px 16px;
  border: 1px solid transparent;
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--ink);
  font-size: 13.5px;
  font-weight: 600;
  line-height: 1.2;
  white-space: nowrap;
  transition: background var(--duration), border-color var(--duration), color var(--duration),
    box-shadow var(--duration), transform var(--duration);
}

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

.btn:disabled,
.btn[aria-busy="true"] {
  opacity: 0.55;
}

.btn svg {
  flex: 0 0 auto;
}

.btn-primary {
  border-color: transparent;
  background: var(--primary-gradient);
  color: var(--on-primary);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.28), 0 6px 18px rgba(0, 113, 227, 0.26);
}

.btn-primary:hover {
  filter: brightness(1.06);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.32), 0 8px 22px rgba(0, 113, 227, 0.34);
  transform: translateY(-1px);
}

.btn-secondary {
  border-color: var(--glass-border);
  background: var(--glass-bg-subtle);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  color: var(--ink);
  box-shadow: var(--glass-shadow);
}

.btn-secondary:hover {
  border-color: var(--credit-line);
  background: var(--glass-bg);
  color: var(--primary-strong);
}

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

.btn-ghost:hover {
  background: var(--primary-soft);
  color: var(--primary-strong);
}

.btn-solid-danger {
  border-color: transparent;
  background: linear-gradient(180deg, #ff5f57 0%, var(--danger) 100%);
  color: #ffffff;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.24), 0 6px 18px rgba(215, 0, 21, 0.22);
}

.btn-sm {
  min-height: 32px;
  padding: 6px 12px;
  font-size: 12.5px;
  border-radius: var(--radius-pill);
}

.btn-lg {
  min-height: 48px;
  padding: 13px 22px;
  font-size: 15px;
  border-radius: var(--radius-pill);
}

.btn-block {
  width: 100%;
}

.btn-spinner {
  width: 14px;
  height: 14px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.icon-btn {
  display: inline-flex;
  width: 36px;
  height: 36px;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  transition: background var(--duration), color var(--duration);
}

.icon-btn:hover {
  background: var(--primary-soft);
  color: var(--primary-strong);
}

.icon-btn.is-danger:hover {
  background: var(--danger-soft);
  color: var(--danger);
}

.icon-btn.sm {
  width: 30px;
  height: 30px;
  border-radius: 50%;
}

.icon-btn.is-busy svg {
  animation: spin 0.8s linear infinite;
}

/* =========================================================
   Forms
   ========================================================= */
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.field-label {
  color: var(--ink-2);
  font-size: 12.5px;
  font-weight: 600;
}

.req {
  color: var(--danger);
}

.field-hint {
  color: var(--faint);
  font-size: 11.5px;
  line-height: 1.55;
}

.field-hint b {
  color: var(--muted);
}

.input,
.textarea {
  width: 100%;
  min-height: 42px;
  padding: 9px 15px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-pill);
  background: var(--glass-bg-subtle);
  backdrop-filter: blur(18px) saturate(160%);
  -webkit-backdrop-filter: blur(18px) saturate(160%);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.4;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.4);
  transition: border-color var(--duration), box-shadow var(--duration), background var(--duration);
}

.input::placeholder,
.textarea::placeholder {
  color: var(--faint);
}

.input:focus,
.textarea:focus {
  outline: none;
  border-color: var(--primary);
  background: var(--glass-bg);
  box-shadow: 0 0 0 4px var(--primary-soft), inset 0 1px 0 rgba(255, 255, 255, 0.45);
}

.textarea {
  min-height: 84px;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  resize: vertical;
}

.input-affix {
  display: flex;
  align-items: stretch;
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-pill);
  background: var(--glass-bg-subtle);
  backdrop-filter: blur(18px) saturate(160%);
  -webkit-backdrop-filter: blur(18px) saturate(160%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.4);
}

.input-affix:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px var(--primary-soft), inset 0 1px 0 rgba(255, 255, 255, 0.45);
}

.input-affix .input {
  border: 0;
  border-radius: 0;
  box-shadow: none;
  background: transparent;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}

.input-affix-prefix {
  display: inline-flex;
  align-items: center;
  padding: 0 13px;
  border-right: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  font-size: 13px;
}

.password-wrap {
  position: relative;
}

.password-wrap .input {
  padding-right: 44px;
}

.password-toggle {
  position: absolute;
  top: 50%;
  right: 4px;
  transform: translateY(-50%);
  width: 32px;
  height: 32px;
}

.choice-row {
  display: flex;
  width: 100%;
  flex-wrap: wrap;
  gap: 7px;
}

.choice-option {
  display: inline-flex;
  flex: 1 1 0;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-width: 0;
  min-height: 38px;
  padding: 7px 14px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-pill);
  background: var(--glass-bg-subtle);
  color: var(--ink-2);
  font-size: 13px;
  cursor: pointer;
  transition: border-color var(--duration), background var(--duration), color var(--duration),
    box-shadow var(--duration);
}

.choice-option input {
  accent-color: var(--primary);
  margin: 0;
}

.choice-option:has(input:checked) {
  border-color: var(--primary);
  background: var(--primary-soft);
  color: var(--primary-strong);
  font-weight: 600;
  box-shadow: 0 0 0 1px var(--primary);
}

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

.choice-card {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: 9px;
  padding: 12px 14px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--glass-bg-subtle);
  cursor: pointer;
  transition: border-color var(--duration), background var(--duration), box-shadow var(--duration);
}

.choice-card input {
  margin-top: 2px;
  accent-color: var(--primary);
}

.choice-card span {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.choice-card b {
  font-size: 13px;
}

.choice-card small {
  color: var(--muted);
  font-size: 11.5px;
}

.choice-card:has(input:checked) {
  border-color: var(--primary);
  background: var(--primary-soft);
  box-shadow: 0 0 0 1px var(--primary);
}

.method-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 7px;
}

.method-option {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 9px 6px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-pill);
  background: var(--glass-bg-subtle);
  font-size: 12.5px;
  cursor: pointer;
  transition: border-color var(--duration), background var(--duration), color var(--duration),
    box-shadow var(--duration);
}

.method-option input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.method-option:has(input:checked) {
  border-color: transparent;
  background: var(--primary-gradient);
  color: var(--on-primary);
  font-weight: 600;
  box-shadow: 0 4px 14px rgba(0, 113, 227, 0.3);
}

.form-section {
  padding: 18px 0;
  border-top: 1px solid var(--line);
}

.form-section:first-of-type,
.form-alert + .form-section {
  border-top: 0;
  padding-top: 0;
}

.form-section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.form-section-head h3 {
  font-size: 14px;
  font-weight: 700;
}

.form-section-head p {
  color: var(--faint);
  font-size: 11.5px;
}

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

.span-2 {
  grid-column: span 2;
}

.form-spacer {
  margin-top: 14px;
}

.form-spacer-sm {
  margin-top: 10px;
}

.form-alert {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 14px;
  padding: 10px 14px;
  border: 1px solid var(--danger-line);
  border-radius: var(--radius-sm);
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 12.5px;
  line-height: 1.5;
}

.form-alert svg {
  flex: 0 0 auto;
  margin-top: 1px;
}

.form-note {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 10px 14px;
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  background: var(--glass-bg-subtle);
  backdrop-filter: blur(18px) saturate(160%);
  -webkit-backdrop-filter: blur(18px) saturate(160%);
  color: var(--muted);
  font-size: 11.5px;
  line-height: 1.55;
}

.form-note svg {
  flex: 0 0 auto;
  margin-top: 2px;
}

.auto-time {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.account-row {
  display: grid;
  grid-template-columns: 1fr 1.2fr 1.2fr auto;
  align-items: end;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--glass-bg-subtle);
  margin-bottom: 12px;
}

.account-add {
  margin-top: 2px;
}

.credential-list {
  display: flex;
  flex-direction: column;
  margin-top: 14px;
}

/* =========================================================
   Auth
   ========================================================= */
.auth-page {
  display: flex;
  min-height: 100vh;
  min-height: 100dvh;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 22px;
  padding: 42px 20px calc(28px + env(safe-area-inset-bottom));
  background: transparent;
}

.auth-card {
  width: 100%;
  max-width: 430px;
  padding: 34px;
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-xl);
  background: var(--glass-bg-strong);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  box-shadow: var(--glass-shadow);
}

.auth-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 30px;
}

.auth-head h1 {
  margin-bottom: 8px;
  font-size: 27px;
  font-weight: 720;
  letter-spacing: -0.03em;
}

.auth-head p {
  color: var(--muted);
  font-size: 13.5px;
  line-height: 1.6;
}

.auth-form {
  margin-top: 25px;
}

.auth-form .field + .field {
  margin-top: 15px;
}

.auth-form .btn-block {
  margin-top: 22px;
}

.auth-note {
  margin-top: 18px;
  padding-top: 17px;
  border-top: 1px solid var(--line);
  color: var(--faint);
  font-size: 12px;
  line-height: 1.6;
}

.fatal-action {
  margin-top: 18px;
}

/* =========================================================
   Topbar
   ========================================================= */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  border-bottom: 0;
  background: transparent;
  box-shadow: none;
}

.topbar-inner {
  display: flex;
  min-height: 64px;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.topbar-left,
.topbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.ledger-switch {
  display: inline-flex;
  padding: 3px;
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-pill);
  background: var(--glass-bg-subtle);
  backdrop-filter: blur(20px) saturate(170%);
  -webkit-backdrop-filter: blur(20px) saturate(170%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.35);
}

.ledger-switch button {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 12px;
  border: 0;
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  transition: background var(--duration), color var(--duration), box-shadow var(--duration);
}

.ledger-switch button.active {
  background: var(--primary-gradient);
  color: var(--on-primary);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.28), 0 4px 12px rgba(0, 113, 227, 0.32);
}

.user-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  padding: 4px 11px 4px 4px;
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-pill);
  background: var(--glass-bg-subtle);
  backdrop-filter: blur(20px) saturate(170%);
  -webkit-backdrop-filter: blur(20px) saturate(170%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.35);
}

.user-avatar {
  display: inline-flex;
  width: 26px;
  height: 26px;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--primary-soft);
  color: var(--primary-strong);
  font-size: 11px;
  font-weight: 700;
}

.user-name {
  max-width: 120px;
  overflow: hidden;
  color: var(--ink-2);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* =========================================================
   Page head
   ========================================================= */
.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 24px;
}

.page-head h1 {
  font-size: 30px;
  font-weight: 740;
  letter-spacing: -0.035em;
}

.page-sub {
  margin-top: 7px;
  max-width: 620px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

.page-actions {
  display: flex;
  align-items: center;
  gap: 9px;
  flex: 0 0 auto;
}

/* =========================================================
   Stats
   ========================================================= */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.stat-card {
  position: relative;
  display: flex;
  min-height: 112px;
  flex-direction: column;
  padding: 15px 16px;
  overflow: hidden;
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  box-shadow: var(--glass-shadow);
}

.stat-icon {
  position: absolute;
  top: 14px;
  right: 14px;
  display: inline-flex;
  width: 28px;
  height: 28px;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--primary-gradient);
  color: var(--on-primary);
  box-shadow: 0 4px 12px rgba(0, 113, 227, 0.3);
}

.stat-label {
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.stat-value {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 8px;
  margin-top: 9px;
  color: var(--ink);
  font-size: 23px;
  font-weight: 720;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.035em;
  line-height: 1.15;
}

.stat-money {
  white-space: nowrap;
}

.stat-foot {
  margin-top: auto;
  padding-top: 8px;
  color: var(--faint);
  font-size: 10.5px;
}

/* =========================================================
   Toolbar
   ========================================================= */
.toolbar {
  display: flex;
  align-items: center;
  gap: 11px;
  margin: 22px 0 13px;
}

.search-box {
  position: relative;
  display: flex;
  flex: 0 1 300px;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 0 12px;
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-pill);
  background: var(--glass-bg-subtle);
  backdrop-filter: blur(20px) saturate(170%);
  -webkit-backdrop-filter: blur(20px) saturate(170%);
  color: var(--faint);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.35);
}

.search-box .input,
.search-box .input:focus {
  min-height: 36px;
  padding: 6px 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  font-size: 13px;
}

.search-box:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px var(--primary-soft);
}

.search-clear {
  display: inline-flex;
  width: 24px;
  height: 24px;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--faint);
}

.search-clear:hover {
  background: var(--primary-soft);
  color: var(--primary-strong);
}

.segmented {
  display: inline-flex;
  padding: 3px;
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-pill);
  background: var(--glass-bg-subtle);
  backdrop-filter: blur(20px) saturate(170%);
  -webkit-backdrop-filter: blur(20px) saturate(170%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.35);
}

.segmented button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border: 0;
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 600;
  white-space: nowrap;
  transition: background var(--duration), color var(--duration), box-shadow var(--duration);
}

.segmented button.active {
  background: var(--glass-bg-strong);
  color: var(--primary-strong);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}

.tab-count {
  min-width: 18px;
  padding: 1px 6px;
  border-radius: var(--radius-pill);
  background: var(--surface-3);
  color: var(--muted);
  font-size: 10.5px;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

.segmented button.active .tab-count {
  background: var(--primary-soft);
  color: var(--primary-strong);
}

.toolbar-spacer {
  flex: 1 1 auto;
}

.result-note {
  color: var(--faint);
  font-size: 11.5px;
  white-space: nowrap;
}

.inline-spinner {
  display: inline-block;
  width: 11px;
  height: 11px;
  border: 1.5px solid var(--line-strong);
  border-top-color: var(--ink);
  border-radius: 50%;
  vertical-align: -1px;
  animation: spin 0.8s linear infinite;
}

/* =========================================================
   Badges
   ========================================================= */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 22px;
  padding: 2px 9px;
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-pill);
  background: var(--glass-bg-subtle);
  color: var(--muted);
  font-size: 10.5px;
  font-weight: 650;
  line-height: 1.4;
  white-space: nowrap;
}

.badge-lg {
  min-height: 26px;
  padding: 3px 11px;
  font-size: 11.5px;
}

.badge-credit {
  border-color: transparent;
  background: var(--primary-gradient);
  color: var(--on-primary);
  box-shadow: 0 3px 10px rgba(0, 113, 227, 0.24);
}

.badge-prepaid {
  border-color: var(--credit-line);
  background: var(--prepaid-soft);
  color: var(--prepaid);
}

.badge-ghost {
  border-color: var(--line);
  background: transparent;
  color: var(--muted);
}

.badge-payment {
  border-color: var(--line);
  background: var(--glass-bg-subtle);
  color: var(--muted);
}

.badge-currency {
  border-color: var(--glass-border);
  background: var(--glass-bg-subtle);
  color: var(--ink-2);
}

.badge-rate {
  border-color: var(--credit-line);
  background: var(--primary-soft);
  color: var(--primary-strong);
  font-variant-numeric: tabular-nums;
}

.badge .dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: currentColor;
}

.source-badge {
  display: inline-flex;
  margin-left: 5px;
  padding: 1px 7px;
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  background: var(--glass-bg-subtle);
  color: var(--faint);
  font-size: 9.5px;
  font-weight: 650;
  vertical-align: 1px;
}

.source-badge.is-partial {
  border-color: var(--line-strong);
  color: var(--muted);
}

.source-badge.is-manual {
  color: var(--muted);
}

/* =========================================================
   Tables
   ========================================================= */
.table-card {
  overflow: hidden;
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  box-shadow: var(--glass-shadow);
}

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

.data-table th {
  padding: 11px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--faint);
  font-size: 10.5px;
  font-weight: 650;
  letter-spacing: 0.03em;
  text-align: left;
  white-space: nowrap;
}

.data-table td {
  padding: 13px 14px;
  border-top: 1px solid var(--line);
  vertical-align: middle;
}

.data-table tbody tr:first-child td {
  border-top: 0;
}

.data-table .clickable {
  cursor: pointer;
}

.data-table .clickable:hover td {
  background: var(--hover);
}

.party-cell {
  display: flex;
  align-items: center;
  gap: 11px;
  min-width: 0;
}

.party-cell-text {
  min-width: 0;
}

.party-name-row {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
}

.party-name {
  overflow: hidden;
  color: var(--ink);
  font-size: 13.5px;
  font-weight: 650;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.party-sub {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 3px;
  overflow: hidden;
  color: var(--faint);
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.avatar {
  display: inline-flex;
  width: 36px;
  height: 36px;
  flex: 0 0 36px;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  font-size: 14px;
  font-weight: 700;
}

.avatar.tone-0 { background: rgba(0, 113, 227, 0.16); color: #005cb8; }
.avatar.tone-1 { background: rgba(10, 132, 255, 0.14); color: #0071e3; }
.avatar.tone-2 { background: rgba(0, 113, 227, 0.22); color: #004a99; }
.avatar.tone-3 { background: rgba(64, 156, 255, 0.16); color: #0062c4; }
.avatar.tone-4 { background: rgba(0, 113, 227, 0.1); color: #3a7bd0; }

@media (prefers-color-scheme: dark) {
  .avatar.tone-0 { background: rgba(10, 132, 255, 0.24); color: #9cc9ff; }
  .avatar.tone-1 { background: rgba(10, 132, 255, 0.18); color: #8cc5ff; }
  .avatar.tone-2 { background: rgba(10, 132, 255, 0.3); color: #bfdfff; }
  .avatar.tone-3 { background: rgba(64, 156, 255, 0.22); color: #a5d1ff; }
  .avatar.tone-4 { background: rgba(10, 132, 255, 0.14); color: #7eb8ff; }
}

.settle-cell {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  max-width: 180px;
}

.cell-money {
  color: var(--ink-2);
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.cell-money.zero {
  color: var(--faint);
}

.cell-money.faint {
  color: var(--faint);
}

.cell-sub {
  margin-top: 2px;
  color: var(--faint);
  font-size: 10.5px;
}

.amount {
  color: var(--ink);
  font-size: 13px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.money-positive { color: var(--ink); }
.money-negative { color: var(--danger); }

.balance-total {
  color: var(--ink);
  font-weight: 650;
}

.balance-partial {
  margin-left: 4px;
  color: var(--faint);
  font-size: 10px;
  font-weight: 600;
}

.row-arrow {
  display: inline-flex;
  color: var(--faint);
}

.data-table .clickable:hover .row-arrow {
  color: var(--ink);
}

.note-cell {
  display: inline-block;
  max-width: 190px;
  overflow: hidden;
  color: var(--muted);
  text-overflow: ellipsis;
  vertical-align: bottom;
  white-space: nowrap;
}

.muted-cell {
  color: var(--muted);
}

/* =========================================================
   Mobile party cards
   ========================================================= */
.party-mobile-list {
  display: none;
}

.party-mobile-card {
  padding: 15px;
  border-top: 1px solid var(--line);
  background: transparent;
}

.party-mobile-card:first-child {
  border-top: 0;
}

.pmc-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.pmc-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 10px;
}

.pmc-metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-top: 11px;
}

.pmc-metrics > div {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.pmc-metrics span {
  color: var(--faint);
  font-size: 10.5px;
}

.pmc-metrics strong {
  color: var(--ink);
  font-size: 13px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}

.pmc-foot {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 6px;
  margin-top: 11px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
  color: var(--faint);
  font-size: 10.5px;
}

/* =========================================================
   Empty / skeleton / error
   ========================================================= */
.empty-state,
.error-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 58px 24px;
  text-align: center;
}

.empty-state.compact {
  padding: 34px 20px;
}

.empty-icon {
  display: inline-flex;
  width: 44px;
  height: 44px;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--primary-soft);
  color: var(--primary);
}

.empty-state h2,
.empty-state h3,
.error-state h2 {
  font-size: 16px;
  font-weight: 700;
}

.empty-state p,
.error-state p {
  max-width: 460px;
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.6;
}

.skeleton-row {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 17px 16px;
  border-bottom: 1px solid var(--line);
}

.skeleton-row:last-child {
  border-bottom: 0;
}

.skeleton {
  border-radius: 8px;
  background: var(--surface-3);
  animation: pulse 1.4s ease-in-out infinite;
}

.skeleton-circle {
  width: 36px;
  height: 36px;
  flex: 0 0 auto;
  border-radius: 50%;
}

.skeleton-lines {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 7px;
}

.skeleton-line {
  height: 10px;
}

@keyframes pulse {
  0%, 100% { opacity: 0.55; }
  50% { opacity: 1; }
}

.detail-loading {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 60px 0;
  color: var(--muted);
  font-size: 13px;
}

/* =========================================================
   Detail
   ========================================================= */
.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 18px;
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 600;
}

.back-link:hover {
  color: var(--ink);
  text-decoration: none;
}

.detail-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 20px;
}

.detail-title-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 7px;
}

.detail-title-row h1 {
  margin-right: 4px;
  font-size: 27px;
  font-weight: 740;
  letter-spacing: -0.035em;
}

.detail-sub {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  margin-top: 9px;
  color: var(--muted);
  font-size: 12px;
}

.detail-sub-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-width: 0;
}

.detail-sub-item a {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  color: var(--ink-2);
}

.detail-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  flex: 0 0 auto;
}

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

.balance-card {
  position: relative;
  display: flex;
  min-height: 138px;
  flex-direction: column;
  padding: 16px;
  overflow: hidden;
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  box-shadow: var(--glass-shadow);
}

.balance-card.credit {
  border-color: transparent;
  background: var(--primary-gradient);
  color: var(--on-primary);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.3), 0 18px 44px rgba(0, 113, 227, 0.32);
}

.balance-card.credit .balance-label,
.balance-card.credit .balance-hint,
.balance-card.credit .balance-note {
  color: rgba(255, 255, 255, 0.66);
}

.balance-card.credit .balance-dot {
  background: currentColor;
}

.balance-card.credit .balance-value {
  color: var(--on-primary);
}

.balance-card.credit .badge {
  border-color: rgba(255, 255, 255, 0.28);
  background: rgba(255, 255, 255, 0.12);
  color: var(--on-primary);
}

.balance-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.balance-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 600;
}

.balance-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--primary);
}

.balance-hint {
  color: var(--faint);
  font-size: 10.5px;
  text-align: right;
}

.balance-value {
  margin-top: 10px;
  color: var(--ink);
  font-size: 25px;
  font-weight: 740;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.035em;
  line-height: 1.15;
  word-break: break-all;
}

.balance-value.is-zero {
  color: var(--faint);
}

.balance-note {
  margin-top: auto;
  padding-top: 10px;
  color: var(--faint);
  font-size: 10.5px;
  line-height: 1.5;
}

.formula-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  margin-top: 12px;
  padding: 12px 16px;
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  box-shadow: var(--glass-shadow);
}

.formula-label {
  padding: 2px 9px;
  border-radius: var(--radius-pill);
  background: var(--primary-soft);
  color: var(--primary-strong);
  font-size: 10.5px;
  font-weight: 650;
}

.formula-expression {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 12px;
  color: var(--muted);
  font-size: 12px;
}

.formula-expression b {
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.formula-note {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
}

/* =========================================================
   Panels
   ========================================================= */
.detail-grid {
  display: grid;
  grid-template-columns: minmax(0, 0.85fr) minmax(0, 1.15fr);
  gap: 12px;
  margin-top: 12px;
}

.panel {
  overflow: hidden;
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  box-shadow: var(--glass-shadow);
}

.panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 15px 16px;
  border-bottom: 1px solid var(--line);
}

.panel-head h2 {
  font-size: 14px;
  font-weight: 700;
}

.panel-head p {
  margin-top: 3px;
  color: var(--faint);
  font-size: 11px;
}

.panel-head-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 5px;
  flex: 0 0 auto;
}

.panel-body {
  padding: 15px 16px;
}

.panel-empty {
  padding: 18px 0;
  color: var(--faint);
  font-size: 12px;
  line-height: 1.6;
}

.info-list {
  display: flex;
  flex-direction: column;
  margin: 0;
}

.info-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 14px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
}

.info-row:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.info-row:first-child {
  padding-top: 0;
}

.info-row dt {
  flex: 0 0 auto;
  color: var(--faint);
  font-size: 11.5px;
}

.info-row dd {
  margin: 0;
  color: var(--ink-2);
  font-size: 12px;
  font-weight: 550;
  text-align: right;
  overflow-wrap: anywhere;
}

.contact-chips {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 5px;
}

.contact-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 7px;
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  background: var(--surface-2);
  color: var(--muted);
  font-size: 10.5px;
}

.contact-chip.empty {
  border-style: dashed;
  color: var(--faint);
}

/* Upstream accounts */
.account-items {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.account-item {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--glass-bg-subtle);
}

.account-avatar {
  display: inline-flex;
  width: 32px;
  height: 32px;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--primary-soft);
  color: var(--primary);
}

.account-main {
  min-width: 0;
}

.account-label {
  color: var(--ink-2);
  font-size: 12.5px;
  font-weight: 650;
}

.account-user {
  overflow: hidden;
  color: var(--faint);
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.account-state {
  display: inline-flex;
  margin-top: 3px;
  padding: 0 7px;
  border-radius: var(--radius-pill);
  background: var(--primary-soft);
  color: var(--primary-strong);
  font-size: 9.5px;
  font-weight: 650;
}

.account-state.is-missing {
  color: var(--faint);
  background: var(--surface-3);
}

.account-metrics {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 4px 12px;
  color: var(--faint);
  font-size: 10.5px;
  text-align: right;
}

.account-metrics b {
  display: block;
  color: var(--ink-2);
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
}

.account-side {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
}

.account-secret {
  display: flex;
  align-items: center;
}

.secret-value {
  display: inline-block;
  max-width: 110px;
  overflow: hidden;
  color: var(--faint);
  font-family: var(--mono);
  font-size: 10.5px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.secret-value.revealed {
  color: var(--ink-2);
}

.account-actions {
  display: flex;
  align-items: center;
  gap: 1px;
}

/* =========================================================
   Ledger panel
   ========================================================= */
.ledger-panel {
  margin-top: 12px;
}

.ledger-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 15px 16px 0;
}

.ledger-head h2 {
  font-size: 14px;
  font-weight: 700;
}

.ledger-head p {
  margin-top: 3px;
  color: var(--faint);
  font-size: 11px;
}

.ledger-body {
  padding: 13px 16px 16px;
}

.ledger-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 9px;
  margin-bottom: 11px;
}

.ledger-actions {
  display: flex;
  gap: 7px;
}

.ledger-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}

.ledger-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
}

.ledger-table th {
  padding: 9px 11px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--faint);
  font-size: 10px;
  font-weight: 650;
  text-align: left;
  white-space: nowrap;
}

.ledger-table td {
  padding: 10px 11px;
  border-top: 1px solid var(--line);
  vertical-align: middle;
}

.ledger-table tbody tr:first-child td {
  border-top: 0;
}

.ledger-mobile-list {
  display: none;
}

.ledger-mobile-item {
  padding: 12px 0;
  border-top: 1px solid var(--line);
}

.ledger-mobile-item:first-child {
  border-top: 0;
  padding-top: 0;
}

.lmi-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.lmi-amount {
  color: var(--ink);
  font-size: 15px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.lmi-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 3px 12px;
  margin-top: 5px;
  color: var(--faint);
  font-size: 10.5px;
}

.lmi-meta b {
  color: var(--ink-2);
  font-weight: 600;
}

.lmi-actions {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
  margin-top: 8px;
}

/* =========================================================
   Modal
   ========================================================= */
.modal {
  width: min(560px, calc(100vw - 32px));
  max-height: calc(100dvh - 48px);
  margin: auto;
  padding: 0;
  border: 0;
  border-radius: var(--radius-xl);
  background: transparent;
  color: var(--ink);
  overflow: visible;
}

.modal.wide {
  width: min(760px, calc(100vw - 32px));
}

.modal::backdrop {
  background: rgba(8, 12, 20, 0.42);
  backdrop-filter: blur(20px) saturate(140%);
  -webkit-backdrop-filter: blur(20px) saturate(140%);
}

.modal-card {
  display: flex;
  max-height: calc(100dvh - 48px);
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-xl);
  background: var(--glass-bg-strong);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.5), 0 32px 96px rgba(10, 25, 50, 0.32);
}

.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 19px 20px 15px;
  border-bottom: 1px solid var(--line);
}

.modal-head h2 {
  font-size: 17px;
  font-weight: 720;
  letter-spacing: -0.02em;
}

.modal-head p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.modal-close {
  flex: 0 0 auto;
}

.modal-scroll {
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 19px 20px;
}

.modal-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  padding: 13px 20px calc(13px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: transparent;
}

.modal-lead {
  display: flex;
  align-items: center;
  gap: 11px;
  margin-bottom: 16px;
  padding: 12px 14px;
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  background: var(--glass-bg-subtle);
}

.modal-lead .party-name {
  font-size: 13.5px;
}

.modal-lead .party-sub {
  white-space: normal;
}

.confirm-icon {
  display: flex;
  width: 44px;
  height: 44px;
  margin: 0 auto 13px;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--danger-soft);
  color: var(--danger);
}

.confirm-text {
  color: var(--ink-2);
  font-size: 13px;
  line-height: 1.7;
  text-align: center;
}

/* File upload */
.file-input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.file-pick {
  display: flex;
  width: 100%;
  align-items: center;
  gap: 11px;
  padding: 16px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--glass-bg-subtle);
  color: var(--muted);
  text-align: left;
}

.file-pick:hover {
  border-color: var(--primary);
  color: var(--primary-strong);
}

.file-pick b {
  display: block;
  color: var(--ink-2);
  font-size: 12.5px;
}

.file-pick small {
  display: block;
  margin-top: 2px;
  color: var(--faint);
  font-size: 10.5px;
}

.file-preview {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 9px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--glass-bg-subtle);
}

.file-preview img {
  width: 54px;
  height: 54px;
  border-radius: 12px;
  object-fit: cover;
}

.file-preview span {
  color: var(--muted);
  font-size: 11px;
  overflow-wrap: anywhere;
}

.balance-preview {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 15px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--glass-bg-subtle);
}

.balance-preview > div {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.balance-preview span {
  color: var(--faint);
  font-size: 10.5px;
}

.balance-preview strong {
  color: var(--ink);
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

.screenshot-summary {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 8px 14px;
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 12px;
}

.screenshot-amount {
  color: var(--ink);
  font-size: 20px;
  font-weight: 720;
  font-variant-numeric: tabular-nums;
}

.screenshot-frame {
  display: flex;
  min-height: 200px;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-3);
}

.receipt-image {
  display: block;
  max-width: 100%;
  max-height: 65vh;
  object-fit: contain;
}

.screenshot-error {
  padding: 30px;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

/* =========================================================
   Toast
   ========================================================= */
.toast-region {
  position: fixed;
  right: 16px;
  bottom: calc(16px + env(safe-area-inset-bottom));
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  pointer-events: none;
}

.toast {
  display: flex;
  max-width: min(360px, calc(100vw - 32px));
  align-items: center;
  gap: 8px;
  padding: 11px 15px;
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  background: var(--glass-bg-strong);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  color: var(--ink);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.5), 0 14px 40px rgba(10, 25, 50, 0.2);
  font-size: 12px;
  line-height: 1.5;
  animation: toast-in 0.18s ease-out;
}

.toast svg {
  flex: 0 0 auto;
}

.toast.success svg { color: var(--ink); }
.toast.error { border-color: var(--danger-line); color: var(--danger); }
.toast.leaving { opacity: 0; transform: translateY(4px); }

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

/* =========================================================
   Responsive
   ========================================================= */
@media (max-width: 1000px) {
  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .balance-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .detail-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 860px) {
  .desktop-only {
    display: none !important;
  }

  .party-mobile-list {
    display: block;
  }

  .ledger-table-wrap {
    display: none;
  }

  .ledger-mobile-list {
    display: block;
  }

  .page {
    padding-top: 20px;
    padding-bottom: 60px;
  }

  .page-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .page-head h1 {
    font-size: 26px;
  }

  .detail-head {
    flex-direction: column;
  }

  .detail-actions {
    justify-content: flex-start;
    width: 100%;
  }

  .detail-actions .btn {
    flex: 1 1 auto;
  }

  .toolbar {
    flex-wrap: wrap;
  }

  .search-box {
    flex: 1 1 100%;
  }

  .toolbar-spacer {
    display: none;
  }

  .result-note {
    width: 100%;
  }

  .user-name {
    display: none;
  }

  .user-chip {
    padding-right: 4px;
  }
}

@media (max-width: 700px) {
  .shell {
    padding-left: 16px;
    padding-right: 16px;
  }

  .topbar-inner {
    min-height: 58px;
    gap: 8px;
  }

  .brand-kicker {
    display: none;
  }

  .brand-name {
    font-size: 14.5px;
  }

  .ledger-switch button {
    padding: 5px 8px;
    font-size: 11.5px;
  }

  .topbar-actions {
    gap: 2px;
  }

  .topbar-left .brand-text {
    display: none;
  }

  .user-chip {
    display: none;
  }

  .stats-grid {
    gap: 9px;
  }

  .stat-card {
    min-height: 98px;
    padding: 12px 13px;
  }

  .stat-value {
    font-size: 19px;
  }

  .stat-icon {
    display: none;
  }

  .balance-grid {
    gap: 9px;
  }

  .balance-card {
    min-height: 124px;
    padding: 13px;
  }

  .balance-value {
    font-size: 21px;
  }

  .formula-bar {
    padding: 11px 12px;
  }

  .panel-head {
    flex-direction: column;
  }

  .panel-head-actions {
    width: 100%;
    justify-content: flex-start;
  }

  .account-item {
    grid-template-columns: auto minmax(0, 1fr);
  }

  .account-metrics {
    grid-column: 1 / -1;
    justify-content: flex-start;
    text-align: left;
    padding-top: 4px;
    border-top: 1px dashed var(--line);
    margin-top: 2px;
  }

  .account-side {
    grid-column: 1 / -1;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    padding-top: 4px;
    border-top: 1px dashed var(--line);
    margin-top: 2px;
  }

  .account-row {
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .account-row .icon-btn {
    justify-self: end;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .span-2 {
    grid-column: span 1;
  }

  .choice-cards {
    grid-template-columns: 1fr;
  }

  .method-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .input,
  .textarea {
    font-size: 16px;
  }

  .modal {
    width: 100vw;
    max-width: 100vw;
    max-height: 92dvh;
    margin: auto 0 0;
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  }

  .modal.wide {
    width: 100vw;
    max-width: 100vw;
  }

  .modal-card {
    max-height: 92dvh;
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    border-bottom: 0;
  }

  .modal-actions {
    justify-content: stretch;
  }

  .modal-actions .btn {
    flex: 1 1 auto;
  }

  .toast-region {
    left: 16px;
    right: 16px;
    align-items: stretch;
  }

  .toast {
    max-width: none;
  }

  .balance-preview {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 420px) {
  .form-section-head {
    flex-wrap: wrap;
    row-gap: 2px;
  }

  .form-section-head h3 {
    white-space: nowrap;
  }

  .choice-option {
    gap: 4px;
    padding: 7px 5px;
    font-size: 11.5px;
    white-space: nowrap;
  }

  .brand-mark {
    width: 32px;
    height: 32px;
  }

  .brand-mark svg {
    width: 19px;
    height: 19px;
  }

  .ledger-switch button {
    padding: 5px 7px;
  }

  .ledger-switch button svg {
    display: none;
  }

  .topbar-actions .icon-btn {
    width: 32px;
    height: 32px;
  }
}

@media (max-width: 480px) {
  .detail-title-row h1 {
    width: 100%;
    font-size: 23px;
  }

  .balance-grid {
    grid-template-columns: 1fr;
  }

  .pmc-metrics {
    grid-template-columns: 1fr 1fr;
  }

  .segmented button {
    padding: 5px 8px;
    font-size: 11.5px;
  }

  .sort-toggle {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
