:root {
  --navy: #123154;
  --navy-2: #204b77;
  --blue-soft: #eaf2fb;
  --bg: #f4f7fb;
  --card: #fff;
  --text: #172232;
  --muted: #687789;
  --border: #dfe6ee;
  --green: #16845a;
  --green-soft: #e4f5ed;
  --orange: #a95a0b;
  --orange-soft: #fff1df;
  --red: #b43a3a;
  --red-soft: #fdeaea;
  --shadow: 0 8px 24px rgba(21, 44, 70, .07);
}

* { box-sizing: border-box; }
html { background: var(--bg); color: var(--text); font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif; }
body { margin: 0; min-width: 320px; }
a { color: var(--navy-2); text-decoration: none; }
button, input, select, textarea { font: inherit; }
button, summary { -webkit-tap-highlight-color: transparent; }

.app-shell { width: 100%; max-width: 720px; min-height: 100vh; margin: 0 auto; background: var(--bg); }
.topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; justify-content: space-between; min-height: 72px; padding: max(12px, env(safe-area-inset-top)) 20px 12px; background: rgba(244, 247, 251, .94); border-bottom: 1px solid rgba(223, 230, 238, .8); backdrop-filter: blur(14px); }
.topbar strong { font-size: 18px; }
.eyebrow { margin: 0 0 3px; color: var(--muted); font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
.user-chip { max-width: 132px; padding: 7px 11px; overflow: hidden; color: var(--navy); background: var(--blue-soft); border-radius: 999px; font-size: 13px; text-overflow: ellipsis; white-space: nowrap; }
.page { padding: 22px 18px calc(100px + env(safe-area-inset-bottom)); }
.page-auth { display: grid; min-height: 100vh; place-items: center; padding-bottom: 22px; }
.page-heading { display: flex; align-items: flex-end; justify-content: space-between; margin-bottom: 20px; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 6px; font-size: clamp(26px, 7vw, 34px); line-height: 1.15; letter-spacing: -.025em; }
h2 { margin-bottom: 0; font-size: 19px; }
.muted { color: var(--muted); line-height: 1.65; }

.bottom-nav { position: fixed; right: 0; bottom: 0; left: 0; z-index: 20; display: grid; grid-template-columns: repeat(4, 1fr); max-width: 720px; min-height: 68px; margin: auto; padding-bottom: env(safe-area-inset-bottom); background: rgba(255,255,255,.97); border-top: 1px solid var(--border); box-shadow: 0 -6px 24px rgba(18, 49, 84, .06); backdrop-filter: blur(14px); }
.bottom-nav a, .bottom-nav form { display: grid; min-height: 64px; margin: 0; place-items: center; }
.bottom-nav a, .bottom-nav button { color: var(--muted); font-size: 13px; font-weight: 650; }
.bottom-nav a.active { color: var(--navy); }
.bottom-nav button { width: 100%; height: 100%; padding: 0; background: none; border: 0; cursor: pointer; }

.metric-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.metric { display: flex; min-height: 112px; padding: 15px; flex-direction: column; justify-content: space-between; color: var(--text); background: var(--card); border: 1px solid var(--border); border-radius: 17px; box-shadow: var(--shadow); }
.metric span { color: var(--muted); font-size: 13px; }
.metric strong { font-size: clamp(18px, 5vw, 24px); letter-spacing: -.03em; overflow-wrap: anywhere; }
.metric.success { background: var(--green-soft); border-color: #c9eadc; }
.metric.warning { background: var(--orange-soft); border-color: #f0dcc3; }
.metric.danger { background: var(--red-soft); border-color: #f2d0d0; }

.section-block { margin-top: 28px; }
.section-title { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 12px; }
.section-title > span, .section-title > a { color: var(--muted); font-size: 13px; }
.card-list { display: grid; gap: 10px; }
.receivable-card, .customer-card { display: block; padding: 16px; color: var(--text); background: var(--card); border: 1px solid var(--border); border-radius: 16px; box-shadow: 0 3px 14px rgba(21,44,70,.04); }
.card-line, .money-line { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.receivable-card p, .customer-card p { margin: 8px 0; color: var(--muted); font-size: 13px; }
.receivable-card small, .customer-card small { color: var(--muted); }
.money-line { margin: 14px 0 7px; }
.money-line strong { font-size: 18px; }
.money-line span { color: var(--muted); font-size: 13px; }
.status { display: inline-flex; min-height: 25px; padding: 4px 9px; align-items: center; color: var(--navy-2); background: var(--blue-soft); border-radius: 999px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.status-paid { color: var(--green); background: var(--green-soft); }
.status-overdue { color: var(--red); background: var(--red-soft); }
.status-partial, .status-promised { color: var(--orange); background: var(--orange-soft); }
.empty-state { padding: 34px 20px; color: var(--muted); background: rgba(255,255,255,.55); border: 1px dashed var(--border); border-radius: 16px; text-align: center; }
.empty-state.compact { padding: 20px; }

.search-form { display: grid; grid-template-columns: 1fr auto; gap: 8px; margin-bottom: 18px; }
input, select, textarea { width: 100%; min-height: 46px; padding: 11px 12px; color: var(--text); background: #fff; border: 1px solid #cfd8e3; border-radius: 11px; outline: none; }
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--navy-2); box-shadow: 0 0 0 3px rgba(32, 75, 119, .12); }
.search-form button { padding: 0 17px; color: #fff; background: var(--navy); border: 0; border-radius: 11px; }

.detail-hero, .confirm-card { padding: 19px; background: var(--card); border: 1px solid var(--border); border-radius: 20px; box-shadow: var(--shadow); }
.detail-hero h1 { margin-top: 12px; }
.detail-hero > p { color: var(--muted); }
.back-link { display: inline-flex; min-height: 44px; margin: -8px 0 8px; align-items: center; font-size: 14px; }
.info-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px 12px; margin: 22px 0 0; }
.info-grid div { min-width: 0; }
.info-grid dt { margin-bottom: 4px; color: var(--muted); font-size: 12px; }
.info-grid dd { margin: 0; overflow-wrap: anywhere; font-weight: 650; }
.amount-summary { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); margin: 22px -6px 0; }
.amount-summary > div { display: flex; min-width: 0; padding: 0 10px; flex-direction: column; gap: 5px; border-right: 1px solid var(--border); }
.amount-summary > div:last-child { border: 0; }
.amount-summary span { color: var(--muted); font-size: 12px; }
.amount-summary strong { font-size: clamp(15px, 4vw, 20px); overflow-wrap: anywhere; }
.amount-summary .outstanding strong { color: var(--red); }

.action-panel { margin-top: 12px; }
.action-panel summary { list-style: none; cursor: pointer; }
.action-panel summary::-webkit-details-marker { display: none; }
.action-panel[open] { padding: 14px; background: #fff; border: 1px solid var(--border); border-radius: 16px; }
.action-panel[open] summary { margin-bottom: 16px; }
.button { display: flex; width: 100%; min-height: 48px; padding: 11px 16px; align-items: center; justify-content: center; border: 0; border-radius: 12px; font-weight: 750; cursor: pointer; }
.button.primary { color: #fff; background: var(--navy); }
.button.secondary { color: var(--navy); background: var(--blue-soft); border: 1px solid #d5e4f4; }
.danger-button { color: #fff; background: var(--red); }
.danger-link, .danger-text { color: var(--red); }
.stack-form { display: grid; gap: 9px; }
.stack-form p { margin: 0; }
.stack-form label { display: block; margin-bottom: 6px; font-size: 13px; font-weight: 650; }
.stack-form .helptext, .form-help { color: var(--muted); font-size: 12px; line-height: 1.5; }
.stack-form ul.errorlist, .form-error { margin: 0; padding: 9px 11px; color: var(--red); background: var(--red-soft); border-radius: 9px; font-size: 13px; list-style: none; }

.timeline { display: grid; gap: 10px; }
.timeline-item { position: relative; padding: 14px 15px; background: #fff; border: 1px solid var(--border); border-radius: 14px; }
.timeline-item p { margin: 8px 0; color: var(--muted); font-size: 13px; line-height: 1.5; }
.timeline-item a { display: inline-block; margin-right: 14px; font-size: 13px; }
.timeline-item small { display: block; margin-top: 7px; color: var(--muted); }
.timeline-item.voided { opacity: .68; background: #f1f3f6; }

.login-card { width: 100%; max-width: 430px; padding: 28px 22px; background: #fff; border: 1px solid var(--border); border-radius: 24px; box-shadow: var(--shadow); }
.brand-mark { display: grid; width: 52px; height: 52px; margin-bottom: 22px; place-items: center; color: #fff; background: var(--navy); border-radius: 15px; font-size: 24px; font-weight: 800; }
.login-card .stack-form { margin-top: 24px; }
.security-note { margin: 20px 0 0; color: var(--muted); font-size: 12px; line-height: 1.6; }
.confirm-card > p { line-height: 1.7; }
.messages { position: fixed; top: 80px; right: 14px; left: 14px; z-index: 50; max-width: 680px; margin: auto; }
.message { padding: 12px 14px; color: var(--green); background: #f3fff9; border: 1px solid #bfe5d3; border-radius: 12px; box-shadow: var(--shadow); }

@media (min-width: 560px) {
  .page { padding-inline: 28px; }
  .metric-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .metric { min-height: 120px; }
  .metric strong { font-size: 19px; }
}

@media (prefers-reduced-motion: no-preference) {
  .receivable-card, .customer-card, .button { transition: transform .15s ease, box-shadow .15s ease; }
  .receivable-card:active, .customer-card:active, .button:active { transform: scale(.985); }
}
