:root {
  color-scheme: light;
  --navy: #07182f;
  --navy-2: #10294b;
  --blue: #3b82f6;
  --blue-dark: #2563eb;
  --ink: #152033;
  --muted: #718096;
  --line: #e5eaf1;
  --bg: #f4f7fb;
  --white: #fff;
  --green: #079669;
  --red: #dc4c64;
  --amber: #d88718;
  --shadow: 0 14px 40px rgba(23, 43, 77, .08);
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; font-family: Inter, Manrope, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; background: var(--bg); color: var(--ink); }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
.app { min-height: 100vh; display: grid; grid-template-columns: 252px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; padding: 30px 18px 22px; background: var(--navy); color: #d9e4f3; display: flex; flex-direction: column; z-index: 20; }
.brand { display: flex; align-items: center; gap: 11px; padding: 0 10px 28px; color: #fff; font-size: 21px; font-weight: 800; }
.brand-mark { width: 31px; height: 31px; border: 2px solid #5a98ff; border-radius: 12px 7px 12px 7px; display: grid; place-items: center; color: #73a9ff; }
.brand span { color: #5796ff; }
.side-label { margin: 12px 11px 9px; color: #6f829e; font-size: 11px; letter-spacing: .13em; text-transform: uppercase; }
.nav { display: grid; gap: 7px; }
.nav a { min-height: 48px; display: flex; align-items: center; gap: 12px; padding: 0 14px; border-radius: 10px; color: #c4d0e0; text-decoration: none; font-size: 14px; font-weight: 650; }
.nav a.active, .nav a:hover { background: #17385f; color: #fff; }
.nav-icon { width: 22px; text-align: center; color: #91a7c3; font-size: 17px; }
.sidebar-bottom { margin-top: auto; }
.help { border: 1px solid #22436b; border-radius: 11px; padding: 13px; color: #fff; font-size: 13px; }
.help small { display: block; margin-top: 5px; color: #8397b2; }
.shell { min-width: 0; }
.topbar { min-height: 76px; padding: 0 34px; background: #fff; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: flex-end; gap: 13px; }
.mobile-menu { display: none; width: 44px; height: 44px; border: 1px solid var(--line); border-radius: 10px; background: #fff; }
.top-balance { min-height: 44px; display: flex; align-items: center; gap: 10px; padding: 0 16px; border: 1px solid var(--line); border-radius: 10px; background: #fff; color: var(--muted); font-size: 13px; }
.top-balance strong { color: var(--ink); font-size: 15px; }
.profile { min-height: 44px; display: flex; align-items: center; gap: 10px; padding: 5px 12px 5px 6px; border: 1px solid var(--line); border-radius: 10px; background: #fff; }
.avatar { width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center; background: #eaf2ff; color: var(--blue); font-weight: 800; }
.profile strong { display: block; font-size: 13px; }
.profile small { color: var(--muted); }
.content { padding: 44px 34px 70px; max-width: 1500px; margin: 0 auto; }
.eyebrow { margin: 0 0 8px; color: var(--blue); font-size: 12px; font-weight: 800; letter-spacing: .11em; text-transform: uppercase; }
.page-head { display: flex; justify-content: space-between; align-items: end; gap: 24px; margin-bottom: 28px; }
h1 { margin: 0; font-size: clamp(30px, 3.2vw, 44px); line-height: 1.08; letter-spacing: -.04em; }
.lead { margin: 10px 0 0; color: var(--muted); }
.primary { min-height: 46px; border: 0; border-radius: 9px; padding: 0 19px; background: var(--blue); color: #fff; font-weight: 750; box-shadow: 0 9px 18px rgba(59, 130, 246, .18); }
.primary:hover { background: var(--blue-dark); }
.secondary { min-height: 44px; border: 1px solid var(--line); border-radius: 9px; padding: 0 16px; background: #fff; color: var(--ink); font-weight: 700; }
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat, .panel, .balance-card { background: #fff; border: 1px solid var(--line); border-radius: 13px; box-shadow: var(--shadow); }
.stat { min-height: 118px; padding: 22px; display: flex; justify-content: space-between; gap: 18px; }
.stat p { margin: 0 0 8px; color: var(--muted); font-size: 13px; }
.stat strong { font-size: 25px; }
.stat small { display: block; margin-top: 6px; color: #9aa5b5; }
.stat-icon { width: 43px; height: 43px; flex: none; border-radius: 11px; display: grid; place-items: center; background: #edf4ff; color: var(--blue); font-size: 19px; }
.panel { overflow: hidden; }
.panel-head { min-height: 64px; padding: 0 22px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.panel-head h2 { margin: 0; font-size: 17px; }
.filters { padding: 15px 22px; display: grid; grid-template-columns: minmax(240px, 1.5fr) minmax(160px, .7fr) minmax(160px, .7fr); gap: 10px; border-bottom: 1px solid var(--line); }
.field { width: 100%; min-height: 44px; border: 1px solid #dce3ec; border-radius: 9px; padding: 0 13px; background: #fff; color: var(--ink); outline: none; }
.field:focus, textarea:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(59,130,246,.12); }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 900px; }
th { padding: 13px 16px; text-align: left; color: #8490a1; font-size: 11px; font-weight: 750; letter-spacing: .05em; text-transform: uppercase; }
td { padding: 15px 16px; border-top: 1px solid var(--line); font-size: 14px; vertical-align: middle; }
.money { font-weight: 850; white-space: nowrap; }
.zero { color: var(--muted); }
.client-name { font-weight: 800; }
.client-name small { display: block; margin-top: 3px; color: var(--muted); font-weight: 500; }
.balance-action { min-height: 36px; border: 1px solid #cfe0fb; border-radius: 8px; padding: 0 12px; background: #f4f8ff; color: var(--blue-dark); font-size: 13px; font-weight: 800; }
.balance-action:hover { background: #eaf2ff; }
.mobile-clients { display: none; }
.client-card { padding: 17px; border-top: 1px solid var(--line); }
.client-card:first-child { border-top: 0; }
.client-card-top { display: flex; justify-content: space-between; gap: 12px; }
.client-meta { margin: 12px 0 15px; display: grid; grid-template-columns: 1fr 1fr; gap: 9px; color: var(--muted); font-size: 13px; }
.client-meta strong { display: block; margin-top: 3px; color: var(--ink); font-size: 14px; }
.balance-card { padding: 27px; display: grid; grid-template-columns: 1fr auto; gap: 24px; align-items: center; margin-bottom: 20px; background: linear-gradient(120deg, #fff 0%, #f7faff 100%); }
.balance-caption { color: var(--muted); font-size: 14px; }
.balance-value { margin: 8px 0 5px; font-size: clamp(38px, 5vw, 58px); line-height: 1; letter-spacing: -.04em; }
.balance-note { max-width: 590px; color: var(--muted); font-size: 14px; line-height: 1.55; }
.balance-lock { width: 62px; height: 62px; border-radius: 18px; background: #eaf2ff; color: var(--blue); display: grid; place-items: center; font-size: 27px; }
.history-empty { padding: 54px 20px; text-align: center; color: var(--muted); }
.history-empty strong { display: block; margin-bottom: 7px; color: var(--ink); font-size: 17px; }
.modal-backdrop { position: fixed; inset: 0; z-index: 50; display: none; place-items: center; padding: 18px; background: rgba(4, 16, 34, .62); backdrop-filter: blur(4px); }
.modal-backdrop.open { display: grid; }
.modal { width: min(540px, 100%); max-height: calc(100vh - 36px); overflow: auto; background: #fff; border-radius: 17px; box-shadow: 0 24px 70px rgba(0,0,0,.24); }
.modal-head { padding: 22px 24px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; gap: 16px; }
.modal-head h2 { margin: 0; font-size: 21px; }
.modal-head p { margin: 5px 0 0; color: var(--muted); font-size: 13px; }
.close { width: 38px; height: 38px; border: 1px solid var(--line); border-radius: 10px; background: #fff; color: var(--muted); font-size: 21px; }
.modal-body { padding: 22px 24px 24px; }
.current-balance { margin-bottom: 18px; padding: 15px 16px; border-radius: 10px; background: #f4f8ff; display: flex; justify-content: space-between; align-items: center; gap: 15px; }
.current-balance span { color: var(--muted); font-size: 13px; }
.current-balance strong { font-size: 20px; }
.segmented { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 17px; padding: 4px; border-radius: 10px; background: #f1f4f8; }
.segmented button { min-height: 42px; border: 0; border-radius: 8px; background: transparent; color: var(--muted); font-weight: 750; }
.segmented button.active.credit { background: #fff; color: var(--green); box-shadow: 0 3px 10px rgba(21,40,70,.08); }
.segmented button.active.debit { background: #fff; color: var(--red); box-shadow: 0 3px 10px rgba(21,40,70,.08); }
.form-group { margin-bottom: 16px; }
.form-group label { display: block; margin-bottom: 7px; font-size: 13px; font-weight: 750; }
textarea.field { min-height: 90px; padding-top: 12px; resize: vertical; }
.result-line { margin: 6px 0 20px; display: flex; justify-content: space-between; gap: 16px; color: var(--muted); font-size: 14px; }
.result-line strong { color: var(--ink); }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; }
.toast { position: fixed; right: 24px; bottom: 24px; z-index: 70; display: none; max-width: 360px; padding: 14px 17px; border-radius: 10px; background: #10294b; color: #fff; box-shadow: var(--shadow); font-size: 14px; }
.toast.show { display: block; animation: toastIn .22s ease-out; }
@keyframes toastIn { from { transform: translateY(12px); opacity: 0; } }

@media (max-width: 1000px) {
  .stats { grid-template-columns: 1fr 1fr; }
  .filters { grid-template-columns: 1fr 1fr; }
  .filters .search { grid-column: 1 / -1; }
}

@media (max-width: 760px) {
  .app { display: block; }
  .sidebar { position: fixed; left: 0; transform: translateX(-102%); width: min(300px, 86vw); transition: transform .22s ease; box-shadow: 18px 0 50px rgba(0,0,0,.22); }
  .sidebar.open { transform: translateX(0); }
  .topbar { min-height: 68px; padding: 0 14px; justify-content: space-between; }
  .mobile-menu { display: inline-grid; place-items: center; }
  .top-balance { margin-left: auto; padding: 0 12px; }
  .profile { padding-right: 6px; }
  .profile div:last-child { display: none; }
  .content { padding: 29px 14px 50px; }
  .page-head { align-items: stretch; flex-direction: column; margin-bottom: 20px; }
  .page-head .primary { width: 100%; }
  .stats { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat { min-height: 104px; padding: 16px; }
  .stat strong { font-size: 22px; }
  .stat-icon { width: 38px; height: 38px; }
  .filters { grid-template-columns: 1fr; padding: 13px; }
  .filters .search { grid-column: auto; }
  .table-wrap { display: none; }
  .mobile-clients { display: block; }
  .balance-card { grid-template-columns: 1fr; padding: 22px; }
  .balance-lock { width: 52px; height: 52px; }
  .modal { border-radius: 14px; }
  .modal-head, .modal-body { padding-left: 18px; padding-right: 18px; }
  .modal-actions { flex-direction: column-reverse; }
  .modal-actions button { width: 100%; }
  .toast { left: 14px; right: 14px; bottom: 14px; }
}

@media (max-width: 480px) {
  .top-balance span { display: none; }
  .stats { grid-template-columns: 1fr; }
  .client-meta { grid-template-columns: 1fr; }
}
