:root {
  --ink: #17262d;
  --muted: #66777f;
  --soft: #eef3f5;
  --line: #dbe4e7;
  --surface: #ffffff;
  --canvas: #f4f7f8;
  --brand: #153e52;
  --brand-2: #1c5a70;
  --accent: #f6c453;
  --positive: #0f7a64;
  --negative: #bd3f4b;
  --shadow: 0 18px 50px rgba(21, 62, 82, 0.09);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--ink);
  background: var(--canvas);
  font-synthesis: none;
}

* { box-sizing: border-box; }
html { min-width: 320px; scroll-behavior: smooth; }
body { min-height: 100vh; margin: 0; background: var(--canvas); }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
svg { width: 1.2rem; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 242px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; padding: 30px 20px 24px; color: #eaf3f5; background: var(--brand); }
.brand { display: flex; align-items: center; gap: 12px; color: inherit; text-decoration: none; padding: 0 8px 34px; }
.brand-mark { display: grid; place-items: center; width: 38px; height: 38px; flex: 0 0 auto; border-radius: 12px; color: var(--accent); background: rgba(255,255,255,.09); }
.brand-mark svg { width: 25px; }
.brand strong, .brand small { display: block; }
.brand strong { font-size: 1rem; letter-spacing: .02em; }
.brand small { margin-top: 3px; color: #9eb9c4; font-size: .72rem; letter-spacing: .06em; }
.nav-item { display: flex; align-items: center; gap: 12px; padding: 13px 14px; border-radius: 10px; color: #b8cdd5; text-decoration: none; font-size: .92rem; }
.nav-item.active { color: white; background: rgba(255,255,255,.1); box-shadow: inset 3px 0 var(--accent); }
.sidebar-note { display: flex; align-items: flex-start; gap: 10px; margin-top: auto; padding: 14px; border: 1px solid rgba(255,255,255,.1); border-radius: 12px; background: rgba(0,0,0,.08); }
.sidebar-note strong, .sidebar-note small { display: block; }
.sidebar-note strong { font-size: .8rem; }
.sidebar-note small { margin-top: 3px; color: #9eb9c4; font-size: .7rem; line-height: 1.5; }
.security-dot { width: 8px; height: 8px; margin-top: 5px; flex: 0 0 auto; border-radius: 50%; background: #5fe0b9; box-shadow: 0 0 0 4px rgba(95,224,185,.12); }
.logout-button { display: flex; align-items: center; gap: 10px; margin-top: 10px; padding: 11px 14px; border: 0; border-radius: 10px; color: #abc3cd; background: transparent; text-align: left; font-size: .82rem; }
.logout-button:hover { color: white; background: rgba(255,255,255,.07); }

.main-content { width: min(1500px, 100%); margin: 0 auto; padding: 38px 42px 56px; }
.topbar { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; margin-bottom: 26px; }
.eyebrow { margin: 0 0 6px; color: var(--muted); font-size: .72rem; font-weight: 700; letter-spacing: .14em; text-transform: uppercase; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: clamp(1.7rem, 2.3vw, 2.25rem); letter-spacing: -.04em; }
h2 { margin-bottom: 4px; font-size: 1.06rem; letter-spacing: -.015em; }

.primary-button, .quiet-button, .danger-button, .icon-button, .text-button { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border-radius: 9px; min-height: 40px; transition: .18s ease; }
.primary-button { padding: 10px 16px; border: 1px solid var(--brand); color: white; background: var(--brand); box-shadow: 0 7px 18px rgba(21,62,82,.16); font-weight: 700; }
.primary-button:hover { border-color: var(--brand-2); background: var(--brand-2); transform: translateY(-1px); }
.primary-button--wide { width: 100%; min-height: 46px; }
.quiet-button { padding: 9px 13px; border: 1px solid var(--line); color: #39505a; background: white; }
.quiet-button:hover { border-color: #b4c5cb; background: #f8fafb; }
.danger-button { padding: 9px 14px; border: 1px solid var(--negative); color: white; background: var(--negative); font-weight: 700; }
.icon-button { width: 38px; padding: 0; border: 1px solid var(--line); color: var(--muted); background: white; }
.icon-button:hover:not(:disabled) { color: var(--ink); border-color: #b4c5cb; }
.icon-button:disabled { cursor: not-allowed; opacity: .42; }
.text-button { min-height: 38px; padding: 7px 10px; border: 0; color: var(--brand-2); background: transparent; }
button:focus-visible, input:focus-visible, textarea:focus-visible { outline: 3px solid rgba(28,90,112,.23); outline-offset: 2px; }
button[disabled] { cursor: wait; opacity: .58; }

.summary-grid { display: grid; grid-template-columns: 1.35fr repeat(3, 1fr); gap: 16px; margin-bottom: 20px; }
.summary-card { min-height: 142px; padding: 23px; border: 1px solid var(--line); border-radius: 15px; background: var(--surface); box-shadow: 0 8px 26px rgba(21,62,82,.035); }
.summary-card--featured { position: relative; overflow: hidden; color: white; border-color: var(--brand); background: var(--brand); }
.summary-card--featured::after { content: ""; position: absolute; right: -30px; bottom: -70px; width: 160px; height: 160px; border: 30px solid rgba(246,196,83,.12); border-radius: 50%; }
.summary-card p, .summary-label { display: block; margin: 0 0 13px; color: var(--muted); font-size: .8rem; }
.summary-card--featured p { color: #b9d0d9; }
.summary-card strong { display: block; margin-bottom: 9px; font-size: clamp(1.35rem, 2vw, 1.75rem); letter-spacing: -.025em; font-variant-numeric: tabular-nums; }
.summary-card small { color: #8a999f; font-size: .73rem; }
.summary-card--featured small { color: #a8c1cb; }
.summary-icon { position: absolute; top: 20px; right: 22px; display: grid; place-items: center; width: 36px; height: 36px; color: var(--accent); border-radius: 10px; background: rgba(255,255,255,.08); }

.ledger-panel { overflow: hidden; border: 1px solid var(--line); border-radius: 16px; background: var(--surface); box-shadow: var(--shadow); }
.panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 21px 23px 16px; }
.panel-heading p { margin-bottom: 0; color: var(--muted); font-size: .78rem; }
.panel-actions { display: flex; gap: 8px; }
.filters { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; padding: 0 23px 18px; border-bottom: 1px solid var(--line); }
.filter-choice select { margin: 0; height: 40px; min-width: 120px; }
.search-field { position: relative; flex: 1; min-width: 220px; }
.search-field svg { position: absolute; left: 12px; top: 50%; width: 17px; color: #829197; transform: translateY(-50%); }
.search-field input, .date-field { height: 40px; border: 1px solid var(--line); border-radius: 9px; background: #f9fbfb; }
.search-field input { width: 100%; padding: 8px 12px 8px 39px; color: var(--ink); }
.date-field { display: flex; align-items: center; gap: 7px; padding: 0 9px; color: var(--muted); font-size: .75rem; }
.date-field span { white-space: nowrap; }
.date-field input { min-width: 125px; padding: 0; border: 0; color: var(--ink); background: transparent; font-size: .8rem; }

.table-wrap { position: relative; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 1280px; }
th { padding: 12px 15px; color: #7b8b91; background: #f8fafb; font-size: .7rem; font-weight: 700; letter-spacing: .04em; text-align: left; white-space: nowrap; }
td { padding: 15px; border-top: 1px solid #edf1f2; color: #4c5f67; font-size: .8rem; vertical-align: middle; }
tbody tr { transition: background .15s ease; }
tbody tr:hover { background: #fafcfc; }
.cell-primary { display: block; margin-bottom: 4px; color: var(--ink); font-size: .82rem; font-weight: 700; }
.cell-secondary { display: block; color: #87969c; font-size: .72rem; line-height: 1.4; }
.account-chip { display: inline-flex; padding: 6px 9px; border: 1px solid #d9e4e7; border-radius: 7px; color: var(--brand); background: #f7fafb; font-weight: 700; }
.contact-badges { display: flex; flex-wrap: wrap; gap: 4px; margin: 6px 0; }
.status-badge { display: inline-flex; padding: 3px 6px; border-radius: 5px; color: #849298; background: #eef2f3; font-size: .65rem; font-weight: 700; }
.status-badge.active { color: #0d705c; background: #e3f5ef; }
.status-badge.generosity-generous { color: #8a6411; background: #fff4d4; }
.redeem-link { display: inline-flex; margin-top: 2px; color: var(--brand-2); font-size: .72rem; font-weight: 700; text-decoration: none; }
.redeem-link:hover { text-decoration: underline; }
.money-cell { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.profit-positive { color: var(--positive); font-weight: 800; }
.profit-negative { color: var(--negative); font-weight: 800; }
.card-mask { display: inline-flex; align-items: center; gap: 6px; padding: 5px 8px; border-radius: 6px; color: #52666e; background: var(--soft); font: 700 .72rem ui-monospace, SFMono-Regular, Menlo, monospace; }
.reveal-button { padding: 4px 5px; border: 0; color: var(--brand-2); background: transparent; font-size: .7rem; }
.row-actions { display: flex; justify-content: flex-end; gap: 3px; }
.row-action { width: 32px; height: 32px; border: 0; border-radius: 7px; color: #71838a; background: transparent; }
.row-action:hover { color: var(--brand); background: var(--soft); }
.row-action.danger:hover { color: var(--negative); background: #fff1f2; }
.empty-state { padding: 65px 20px 70px; text-align: center; }
.empty-state > span { display: grid; place-items: center; width: 58px; height: 58px; margin: 0 auto 16px; color: var(--brand-2); border-radius: 18px; background: var(--soft); }
.empty-state svg { width: 29px; }
.empty-state h3 { margin-bottom: 8px; font-size: 1rem; }
.empty-state p { margin-bottom: 18px; color: var(--muted); font-size: .82rem; }
.pagination { display: flex; align-items: center; justify-content: space-between; padding: 14px 23px; border-top: 1px solid var(--line); color: var(--muted); font-size: .76rem; }
.pagination > div { display: flex; align-items: center; gap: 12px; }

.login-screen { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 24px; background: radial-gradient(circle at 20% 10%, #23586b 0, var(--brand) 35%, #0d2b38 100%); }
.login-screen[hidden] { display: none; }
.login-screen::before { content: ""; position: fixed; width: 360px; height: 360px; right: -100px; bottom: -100px; border: 70px solid rgba(246,196,83,.07); border-radius: 50%; }
.login-card { position: relative; width: min(410px, 100%); padding: 42px; border: 1px solid rgba(255,255,255,.55); border-radius: 20px; background: rgba(255,255,255,.96); box-shadow: 0 28px 80px rgba(0,0,0,.25); }
.brand-mark--large { width: 48px; height: 48px; margin-bottom: 24px; color: var(--brand); background: #edf3f4; }
.login-card h1 { margin-bottom: 10px; }
.login-card > p:not(.eyebrow) { margin-bottom: 28px; color: var(--muted); font-size: .9rem; }

.modal { width: min(720px, calc(100% - 28px)); max-height: calc(100vh - 38px); padding: 0; border: 0; border-radius: 18px; color: var(--ink); background: white; box-shadow: 0 30px 90px rgba(15,38,48,.32); }
.modal::backdrop { background: rgba(11,31,40,.56); backdrop-filter: blur(3px); }
.modal--small { width: min(500px, calc(100% - 28px)); padding-bottom: 24px; }
.modal--small > p, .modal--small > .card-code-box { margin-left: 25px; margin-right: 25px; }
.modal-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; padding: 24px 25px 18px; border-bottom: 1px solid var(--line); }
.modal-header h2 { margin: 0; font-size: 1.25rem; }
.modal-header .icon-button { border: 0; background: #f3f6f7; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 17px; padding: 22px 25px 10px; }
label { color: #43565e; font-size: .78rem; font-weight: 700; }
label small { float: right; color: #89989e; font-size: .7rem; font-weight: 500; }
input, textarea, select { width: 100%; margin-top: 7px; padding: 10px 11px; border: 1px solid #ccd8dc; border-radius: 8px; color: var(--ink); background: #fbfcfc; font-size: .9rem; font-weight: 500; }
input { height: 42px; }
select { height: 42px; }
textarea { resize: vertical; min-height: 80px; }
input:focus, textarea:focus, select:focus { border-color: var(--brand-2); background: white; }
.field-wide { grid-column: 1 / -1; }
.form-section-title { margin: 5px 0 -4px; padding-bottom: 8px; border-bottom: 1px solid #edf1f2; color: var(--brand); font-size: .75rem; font-weight: 800; letter-spacing: .06em; }
.form-section-title:first-child { margin-top: 0; }
.contact-options { display: flex; flex-wrap: wrap; gap: 10px; }
.check-option { display: inline-flex; align-items: center; gap: 8px; padding: 10px 12px; border: 1px solid #d6e1e4; border-radius: 8px; background: #f9fbfb; }
.check-option input { width: 17px; height: 17px; margin: 0; accent-color: var(--brand-2); }
.profit-preview { align-self: end; min-height: 42px; display: flex; align-items: center; justify-content: space-between; padding: 9px 12px; border: 1px solid #cbe2dd; border-radius: 8px; color: var(--positive); background: #f1faf7; }
.profit-preview span { font-size: .75rem; font-weight: 700; }
.profit-preview strong { font-size: 1rem; font-variant-numeric: tabular-nums; }
.profit-preview.negative { color: var(--negative); border-color: #e8bdc3; background: #fff5f6; }
.field-help { color: #52666e; font-size: .875rem; line-height: 1.65; margin: 0; }
.contact-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.contact-card { min-width: 0; padding: 14px; border: 1px solid var(--line); border-radius: 10px; background: #f9fbfc; }
.qr-zone { margin-top: 10px; padding: 10px; border: 1px dashed #a5bbc4; border-radius: 8px; background: white; color: #52666e; font-size: .875rem; line-height: 1.5; }
.qr-zone:focus { outline: 3px solid #c7dce4; }
.qr-zone img { width: 100px; height: 100px; object-fit: contain; display: block; margin-top: 10px; }
.qr-zone img[hidden] { display: none; }
.qr-zone p { margin: 8px 0 0; overflow-wrap: anywhere; }
.qr-upload { color: var(--brand-2); cursor: pointer; text-decoration: underline; font-size: .875rem; }
.qr-upload input { width: 100%; height: auto; font-size: .75rem; padding: 5px; }
.qr-payload-label { display: block; margin-top: 10px; }
.qr-payload-label textarea { min-height: 48px; font-size: .8rem; overflow-wrap: anywhere; }
.form-grid > label { font-size: .875rem; }
.modal-footer { display: flex; justify-content: flex-end; gap: 9px; padding: 17px 25px 23px; }
.form-error { min-height: 18px; margin: 8px 25px 0; color: var(--negative); font-size: .76rem; }
.login-card .form-error { margin: 9px 0; }
.sensitive-note { margin-top: 20px; color: var(--muted); font-size: .8rem; line-height: 1.6; }
.card-code-box { display: flex; align-items: center; gap: 12px; padding: 13px; border: 1px solid #d7e2e5; border-radius: 10px; background: #f7fafb; }
.card-code-box code { flex: 1; min-width: 0; overflow-wrap: anywhere; color: var(--ink); font-size: .88rem; }
.danger-text { color: var(--negative); }

.toast-region { position: fixed; right: 22px; bottom: 22px; z-index: 50; display: grid; gap: 9px; width: min(360px, calc(100% - 44px)); }
.toast { padding: 13px 15px; border: 1px solid #cfe0e4; border-radius: 10px; color: #27424d; background: white; box-shadow: 0 16px 40px rgba(12,41,52,.18); font-size: .8rem; animation: toast-in .2s ease-out; }
.toast.error { color: #8f2f39; border-color: #f1c8cc; background: #fff7f7; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

@media (max-width: 1080px) {
  .app-shell { grid-template-columns: 88px minmax(0,1fr); }
  .sidebar { padding: 28px 14px 20px; align-items: center; }
  .brand { padding-inline: 0; }
  .brand > span:last-child, .nav-item:not(.active), .nav-item.active { font-size: 0; }
  .nav-item { justify-content: center; width: 54px; padding: 14px; }
  .nav-item svg { width: 22px; }
  .sidebar-note { padding: 13px; }
  .sidebar-note div { display: none; }
  .logout-button { width: 52px; justify-content: center; font-size: 0; }
  .summary-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 720px) {
  .app-shell { display: block; }
  .sidebar { position: static; width: 100%; height: 66px; flex-direction: row; padding: 10px 16px; }
  .brand { padding: 0; }
  .brand > span:last-child { display: none; }
  .brand-mark { width: 42px; height: 42px; }
  .sidebar nav, .sidebar-note { display: none; }
  .logout-button { margin: 0 0 0 auto; }
  .main-content { padding: 24px 16px 40px; }
  .topbar { align-items: center; margin-bottom: 20px; }
  .topbar .eyebrow { display: none; }
  .topbar .primary-button { min-width: 42px; padding: 10px 12px; font-size: 0; }
  .topbar .primary-button svg { width: 20px; }
  .summary-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .summary-card { min-height: 120px; padding: 18px; }
  .summary-card--featured { grid-column: 1 / -1; }
  .summary-grid .summary-card:last-child { grid-column: 1 / -1; min-height: 104px; }
  .panel-heading { align-items: flex-start; flex-direction: column; }
  .panel-actions { width: 100%; }
  .panel-actions button { flex: 1; }
  .filters { flex-wrap: wrap; }
  .search-field { flex-basis: 100%; }
  .date-field { flex: 1; }
  .date-field input { min-width: 0; }
  .form-grid { grid-template-columns: 1fr; }
  .contact-grid { grid-template-columns: 1fr; }
  .field-wide { grid-column: auto; }
  .modal { max-height: calc(100vh - 18px); }
  .login-card { padding: 32px 24px; }
}

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