:root {
  --bg: #f3f3f9;
  --card: #ffffff;
  --ink: #17152b;
  --ink-2: #5c5a72;
  --ink-3: #9a98ad;
  --line: #e8e7f1;
  --wb: #b5179e;
  --wb-2: #7b2ff7;
  --wb-soft: #f6e8f8;
  --navy: #1c1640;
  --navy-2: #3a1f7a;
  --ok: #138a52;
  --ok-soft: #e4f6ec;
  --warn: #b45309;
  --warn-soft: #fff3e0;
  --bad: #c62839;
  --bad-soft: #fde8eb;
  --radius: 20px;
  --radius-s: 12px;
  --shadow: 0 1px 2px rgba(23, 21, 43, 0.04), 0 6px 24px rgba(23, 21, 43, 0.06);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

button, input, select, textarea { font: inherit; color: inherit; }

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

h1, h2, h3 { margin: 0; letter-spacing: -0.01em; }

.num { font-variant-numeric: tabular-nums; }

.wrap {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(12px + var(--safe-top)) 16px calc(32px + var(--safe-bottom));
}

.wrap.wide { max-width: 1080px; }

.boot, .center { min-height: 60vh; display: grid; place-items: center; }

.spinner {
  width: 32px; height: 32px; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: var(--wb);
  animation: spin 0.8s linear infinite;
}

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

.busy main { opacity: 0.55; pointer-events: none; transition: opacity 0.15s; }

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-top: 12px;
}

.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.card-head h2 { font-size: 17px; }
.muted { color: var(--ink-2); }
.faint { color: var(--ink-3); font-size: 13px; }
.small { font-size: 13px; }

.top {
  display: flex; align-items: center; gap: 12px; padding: 4px 0 8px;
}
.avatar {
  width: 40px; height: 40px; border-radius: 50%; flex: none;
  display: grid; place-items: center; font-weight: 700; color: #fff;
  background: linear-gradient(135deg, var(--wb), var(--wb-2));
}
.top .who { flex: 1; min-width: 0; }
.top .who b { display: block; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 8px; }
.tile {
  border-radius: 18px; padding: 12px; color: #fff; min-height: 104px;
  display: flex; flex-direction: column; justify-content: space-between;
  background: linear-gradient(160deg, #2a2350, var(--navy));
}
.tile.wb { background: linear-gradient(160deg, #d63bbd, var(--wb) 55%, #8f137d); }
.tile.alt { background: linear-gradient(160deg, #8b5cf6, #5b21b6); }
.tile .label { font-size: 13px; font-weight: 600; opacity: 0.92; }
.tile .sub { font-size: 11px; opacity: 0.7; }
.tile .value { font-size: 30px; font-weight: 750; line-height: 1; letter-spacing: -0.02em; }
.tile .row { display: flex; align-items: flex-end; justify-content: space-between; gap: 4px; }
.delta {
  font-size: 12px; font-weight: 700; padding: 3px 7px; border-radius: 999px;
  background: rgba(255, 255, 255, 0.18); white-space: nowrap;
}

.balance {
  margin-top: 8px; border-radius: var(--radius); padding: 18px; color: #fff;
  background: radial-gradient(120% 140% at 100% 0%, #5b2bb5 0%, var(--navy-2) 35%, var(--navy) 75%);
  box-shadow: 0 10px 30px rgba(28, 22, 64, 0.25);
}
.balance .head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.balance .head b { font-size: 16px; }
.chip-dark {
  font-size: 12px; padding: 4px 10px; border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.22); color: rgba(255, 255, 255, 0.85); white-space: nowrap;
}
.balance .total { font-size: 40px; font-weight: 800; letter-spacing: -0.03em; margin: 10px 0 14px; }
.balance .parts { display: grid; grid-template-columns: 1fr 1fr; border-top: 1px solid rgba(255, 255, 255, 0.14); padding-top: 12px; }
.balance .parts div + div { border-left: 1px solid rgba(255, 255, 255, 0.14); padding-left: 14px; }
.balance .parts span { display: block; font-size: 12px; color: rgba(255, 255, 255, 0.6); }
.balance .parts b { font-size: 17px; }
.balance .plus { color: #7cf0b4; }
.balance .hint { margin-top: 10px; font-size: 12px; color: rgba(255, 255, 255, 0.7); }

.seg {
  display: inline-flex; background: #f0eff6; border-radius: 10px; padding: 3px; gap: 2px;
}
.seg button {
  border: 0; background: transparent; padding: 6px 10px; border-radius: 8px;
  font-size: 13px; color: var(--ink-2); cursor: pointer;
}
.seg button.on { background: #fff; color: var(--wb); font-weight: 650; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08); }

.dates { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 10px; }

.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 8px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  border: 1px solid var(--line); background: #fff; border-radius: 999px;
  padding: 6px 12px; font-size: 13px; white-space: nowrap; cursor: pointer;
}
.chip.on { background: var(--wb-soft); border-color: transparent; color: var(--wb); font-weight: 650; }

.chart svg { display: block; width: 100%; height: auto; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .axis { fill: var(--ink-3); font-size: 10px; }
.chart .bar { fill: var(--wb); cursor: pointer; }
.chart .bar.zero { fill: #ece9f3; }
.chart .bar.sel { fill: var(--wb-2); }
.chart .val { fill: var(--ink); font-size: 10px; font-weight: 700; }
.chart-caption { min-height: 20px; font-size: 13px; color: var(--ink-2); margin-top: 6px; text-align: center; }

.funnel { display: grid; gap: 8px; }
.stage { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; align-items: center; }
.stage .shape {
  height: 34px; border-radius: 8px;
  background: linear-gradient(90deg, #c084fc, #a855f7);
  display: flex; align-items: center; padding: 0 12px; color: #fff; font-weight: 750;
}
.stage:nth-child(2) .shape { width: 74%; background: linear-gradient(90deg, #a855f7, #8b2fe0); }
.stage:nth-child(3) .shape { width: 50%; background: linear-gradient(90deg, #8b2fe0, #6d18c8); }
.stage .meta { font-size: 12px; color: var(--ink-2); text-align: right; white-space: nowrap; }
.stage .meta b { display: block; color: var(--ink); font-size: 13px; }
.funnel-total {
  display: flex; justify-content: space-between; align-items: center;
  border-top: 1px solid var(--line); margin-top: 6px; padding-top: 10px; font-size: 13px;
}
.funnel-total b { color: var(--wb); font-size: 16px; }

.list { display: grid; gap: 8px; }
.item {
  border: 1px solid var(--line); border-radius: 14px; padding: 12px;
  display: grid; gap: 8px; background: #fff;
}
.item.hidden { opacity: 0.6; background: #fafafd; }
.item .head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.tag {
  font-size: 11px; font-weight: 650; padding: 3px 8px; border-radius: 999px;
  background: #f0eff6; color: var(--ink-2); white-space: nowrap;
}
.tag.wb { background: var(--wb-soft); color: var(--wb); }
.tag.ok { background: var(--ok-soft); color: var(--ok); }
.tag.bad { background: var(--bad-soft); color: var(--bad); }
.field {
  display: flex; align-items: center; gap: 8px; background: #f7f6fb; border-radius: 10px; padding: 8px 10px;
}
.field .k { font-size: 11px; color: var(--ink-3); display: block; }
.field .v { font-weight: 650; word-break: break-word; }
.field .grow { flex: 1; min-width: 0; }
.copy {
  border: 0; background: #fff; border-radius: 8px; width: 32px; height: 32px; flex: none;
  display: grid; place-items: center; cursor: pointer; color: var(--wb-2);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}
.copy svg { width: 16px; height: 16px; }
.metrics { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; text-align: center; }
.metrics div { background: #faf9fd; border-radius: 10px; padding: 6px 4px; }
.metrics span { display: block; font-size: 11px; color: var(--ink-3); }
.metrics b { font-size: 15px; }

.empty { text-align: center; color: var(--ink-2); padding: 20px 8px; }

.btn {
  border: 0; border-radius: 12px; padding: 11px 16px; cursor: pointer; font-weight: 650;
  background: linear-gradient(135deg, var(--wb), var(--wb-2)); color: #fff;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.btn:disabled { opacity: 0.55; cursor: default; }
.btn.ghost { background: #fff; color: var(--ink); border: 1px solid var(--line); }
.btn.danger { background: var(--bad-soft); color: var(--bad); }
.btn.small { padding: 7px 11px; font-size: 13px; border-radius: 10px; }
.btn.block { width: 100%; }
.link { border: 0; background: none; color: var(--wb-2); cursor: pointer; padding: 4px 0; font-weight: 600; }

label.f { display: grid; gap: 4px; font-size: 13px; color: var(--ink-2); }
input[type="text"], input[type="password"], input[type="number"], input[type="date"], input[type="month"], select, textarea {
  width: 100%; border: 1px solid var(--line); background: #fff; border-radius: 10px;
  padding: 10px 12px; font-size: 16px; color: var(--ink); min-height: 44px;
}
textarea { min-height: 120px; resize: vertical; font-size: 14px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(123, 47, 247, 0.35); border-color: var(--wb-2); }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--ink); }
.check input { width: 18px; height: 18px; accent-color: var(--wb-2); }
.form { display: grid; gap: 10px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

.login-wrap { max-width: 380px; margin: 0 auto; padding: calc(48px + var(--safe-top)) 16px 32px; }
.logo {
  width: 56px; height: 56px; border-radius: 16px; margin-bottom: 16px;
  background: linear-gradient(135deg, var(--wb), var(--wb-2)); display: grid; place-items: center; color: #fff;
}
.logo svg { width: 28px; height: 28px; }
.error-box { background: var(--bad-soft); color: var(--bad); padding: 10px 12px; border-radius: 10px; font-size: 14px; }
.note { background: var(--warn-soft); color: var(--warn); padding: 10px 12px; border-radius: 12px; font-size: 14px; margin-top: 12px; }
.note.bad { background: var(--bad-soft); color: var(--bad); }
.note.ok { background: var(--ok-soft); color: var(--ok); }

.topbar {
  position: sticky; top: 0; z-index: 5; background: rgba(243, 243, 249, 0.92);
  backdrop-filter: saturate(1.4) blur(10px); -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--line);
}
.topbar .in {
  max-width: 1080px; margin: 0 auto; padding: calc(10px + var(--safe-top)) 16px 0;
}
.topbar .row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.topbar b { font-size: 16px; }
.tabs { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; padding: 8px 0 0; }
.tabs::-webkit-scrollbar { display: none; }
.tabs a {
  padding: 8px 12px 10px; color: var(--ink-2); font-size: 14px; white-space: nowrap;
  border-bottom: 2px solid transparent; font-weight: 550;
}
.tabs a.on { color: var(--wb); border-bottom-color: var(--wb); }

.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.kpi { background: #fff; border-radius: 16px; padding: 12px; box-shadow: var(--shadow); }
.kpi span { display: block; font-size: 12px; color: var(--ink-3); }
.kpi b { font-size: 22px; }

.rows { display: grid; gap: 8px; }
.brow {
  display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; align-items: center;
  border: 1px solid var(--line); border-radius: 14px; padding: 12px;
}
.brow .name { font-weight: 650; }
.brow .nums { display: flex; gap: 14px; flex-wrap: wrap; font-size: 13px; color: var(--ink-2); }
.brow .nums b { color: var(--ink); }
.brow .pay { text-align: right; }
.brow .pay b { font-size: 18px; }
.brow .acts { grid-column: 1 / -1; display: flex; gap: 8px; flex-wrap: wrap; }

table.t { width: 100%; border-collapse: collapse; font-size: 14px; }
table.t th { text-align: left; font-size: 12px; color: var(--ink-3); font-weight: 600; padding: 6px 8px; border-bottom: 1px solid var(--line); }
table.t td { padding: 8px; border-bottom: 1px solid var(--line); }
table.t td.n, table.t th.n { text-align: right; font-variant-numeric: tabular-nums; }
.scroll-x { overflow-x: auto; }

.picklist { max-height: 300px; overflow-y: auto; display: grid; gap: 4px; border: 1px solid var(--line); border-radius: 12px; padding: 8px; }
.picklist label { display: flex; gap: 8px; align-items: center; font-size: 14px; padding: 4px; border-radius: 8px; }
.picklist label:hover { background: #faf9fd; }

details.card summary { cursor: pointer; font-weight: 650; list-style: none; }
details.card summary::-webkit-details-marker { display: none; }
details.card[open] summary { margin-bottom: 12px; }

.toast {
  position: fixed; left: 50%; bottom: calc(20px + var(--safe-bottom)); transform: translate(-50%, 20px);
  background: var(--navy); color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 14px;
  opacity: 0; pointer-events: none; transition: all 0.2s; max-width: calc(100% - 32px); z-index: 50;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.bad { background: var(--bad); }
.clip { position: fixed; top: -100px; opacity: 0; }

@media (max-width: 380px) {
  .tile .value { font-size: 26px; }
  .balance .total { font-size: 34px; }
  .tiles { gap: 6px; }
  .tile { padding: 10px; }
}

@media (max-width: 640px) {
  .grid3 { grid-template-columns: 1fr; }
  .kpis { grid-template-columns: 1fr 1fr; }
  .kpis .kpi:last-child { grid-column: 1 / -1; }
}

@media (min-width: 900px) {
  .split { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; align-items: start; }
  .split > .card { margin-top: 12px; }
}

.chart .hit { fill: transparent; cursor: pointer; }
a.brow { color: inherit; }
.top .who .faint { display: block; }
.card-head { flex-wrap: wrap; }
.seg button { white-space: nowrap; }
.actions input[type="month"] { width: auto; }
.inline { display: flex; gap: 8px; align-items: center; }
.inline input { flex: 1; min-width: 0; }
.inline .btn { flex: none; }
.item .head[data-click] { cursor: pointer; }
.empty .spinner { margin: 0 auto 8px; }
.actions select { width: auto; }
.loading-note { font-size: 12px; color: var(--ink-3); margin-top: 4px; }
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.imp { font-size: 13px; }
table.imp td:nth-child(2) { white-space: nowrap; }
table.imp td { vertical-align: top; }
table.imp tr.bad td { background: color-mix(in srgb, #e5484d 8%, transparent); }
table.imp tr.muted td { color: var(--ink-3); }
.import-card { margin-bottom: 16px; }
details.card summary::after { content: "›"; float: right; color: var(--ink-3); transition: transform .15s; }
details.card[open] summary::after { transform: rotate(90deg); }
