/* ============================================
   Сбор — Group Savings Dashboard
   Palette: warm cream + graphite + sage/terracotta/ochre
   ============================================ */

:root {
  --bg: #F5F2EC;
  --bg-2: #EFEBE3;
  --surface: #FFFFFF;
  --surface-2: #FBF9F5;
  --ink: #161514;
  --ink-2: #3D3B37;
  --muted: #807C73;
  --muted-2: #ADA89E;
  --line: #E5E0D5;
  --line-2: #EFEBE0;

  --sage: #3F6E54;
  --sage-soft: #E2EBE3;
  --sage-ink: #234836;

  --terra: #B85C3B;
  --terra-soft: #F1DBCD;
  --terra-ink: #6E2F18;

  --ochre: #B68A3E;
  --ochre-soft: #EFE2C2;
  --ochre-ink: #5C4317;

  --indigo: #3D4F6E;
  --indigo-soft: #DDE2EC;

  --radius-sm: 8px;
  --radius: 14px;
  --radius-lg: 20px;

  --shadow-sm: 0 1px 0 rgba(22, 21, 20, 0.04), 0 1px 2px rgba(22, 21, 20, 0.04);
  --shadow: 0 1px 0 rgba(22, 21, 20, 0.04), 0 8px 24px -12px rgba(22, 21, 20, 0.12);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

body {
  font-family: 'Geist', 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: "ss01", "cv11";
}

/* ---------- Layout ---------- */
.app {
  max-width: 1240px;
  margin: 0 auto;
  padding: 28px 24px 80px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 28px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}
.brand-mark {
  width: 36px; height: 36px;
  border-radius: 10px;
  background: var(--ink);
  color: var(--bg);
  display: grid; place-items: center;
  font-weight: 600;
  font-size: 14px;
  letter-spacing: 0.02em;
  position: relative;
}
.brand-mark::after {
  content: "";
  position: absolute;
  inset: 4px;
  border: 1px solid rgba(255,255,255,0.18);
  border-radius: 7px;
}
.brand-name {
  font-weight: 600;
  font-size: 16px;
  letter-spacing: -0.01em;
}
.brand-sub {
  font-size: 12px;
  color: var(--muted);
  margin-top: -2px;
}

.topbar-actions {
  display: flex; align-items: center; gap: 10px;
}

/* ---------- Buttons ---------- */
.btn {
  height: 38px;
  padding: 0 14px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-weight: 500;
  font-size: 13px;
  cursor: pointer;
  display: inline-flex; align-items: center; gap: 8px;
  transition: background 0.15s, border-color 0.15s, transform 0.05s;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }

.btn-primary {
  background: var(--ink);
  color: var(--bg);
  border-color: var(--ink);
}
.btn-primary:hover { background: #292724; }

.btn-ghost {
  background: transparent;
  border-color: transparent;
}
.btn-ghost:hover { background: var(--bg-2); }

.btn-icon {
  width: 38px; padding: 0;
  display: grid; place-items: center;
}

.icon-btn-sm {
  width: 28px; height: 28px;
  border-radius: 7px;
  border: 1px solid var(--line);
  background: transparent;
  cursor: pointer;
  display: grid; place-items: center;
  color: var(--muted);
}
.icon-btn-sm:hover { background: var(--bg-2); color: var(--ink); }

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-sm);
}
.card-head {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}
.card-title {
  font-size: 14px; font-weight: 600; letter-spacing: -0.005em;
  color: var(--ink);
  margin: 0;
}
.card-sub {
  font-size: 12px; color: var(--muted); margin-top: 3px;
}

/* ---------- Stats Row ---------- */
.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}

.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px;
  position: relative;
  overflow: hidden;
}
.stat-label {
  font-size: 12px;
  color: var(--muted);
  font-weight: 500;
  display: flex; align-items: center; gap: 6px;
  margin-bottom: 12px;
}
.stat-value {
  font-size: 26px;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--ink);
  font-feature-settings: "tnum";
  display: flex; align-items: baseline; gap: 6px;
}
.stat-value .unit {
  font-size: 13px; color: var(--muted); font-weight: 500;
  letter-spacing: 0;
}
.stat-meta {
  margin-top: 10px;
  font-size: 12px;
  color: var(--muted);
  display: flex; align-items: center; gap: 6px;
}
.stat-meta .delta-up { color: var(--sage); }
.stat-meta .delta-down { color: var(--terra); }

.stat.is-accent {
  background: var(--ink);
  color: var(--bg);
  border-color: var(--ink);
}
.stat.is-accent .stat-label,
.stat.is-accent .stat-meta { color: rgba(245, 242, 236, 0.6); }
.stat.is-accent .stat-value { color: var(--bg); }

/* ---------- Main grid ---------- */
.grid {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
}
.grid-3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 16px;
}

/* ---------- Members Table ---------- */
.tabs {
  display: inline-flex;
  background: var(--bg-2);
  border-radius: 9px;
  padding: 3px;
  gap: 2px;
}
.tab {
  border: none;
  background: transparent;
  height: 28px;
  padding: 0 12px;
  border-radius: 7px;
  font: inherit;
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
}
.tab.is-active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-sm);
}

.members {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.members th {
  text-align: left;
  font-weight: 500;
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0 10px 10px;
  border-bottom: 1px solid var(--line);
}
.members td {
  padding: 14px 10px;
  border-bottom: 1px solid var(--line-2);
  vertical-align: middle;
}
.members tr:last-child td { border-bottom: none; }
.members td.num {
  font-feature-settings: "tnum";
  font-variant-numeric: tabular-nums;
  text-align: right;
}
.members th.num { text-align: right; }

.avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  display: inline-grid; place-items: center;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink);
  background: var(--bg-2);
  border: 1px solid var(--line);
  margin-right: 10px;
  vertical-align: middle;
  flex-shrink: 0;
}
.avatar.a-1 { background: #E2EBE3; }
.avatar.a-2 { background: #F1DBCD; }
.avatar.a-3 { background: #EFE2C2; }
.avatar.a-4 { background: #DDE2EC; }
.avatar.a-5 { background: #E8DDE6; }
.avatar.a-6 { background: #E2E6D9; }

.cell-name {
  display: flex; align-items: center;
}
.cell-name-text {
  display: flex; flex-direction: column;
  line-height: 1.2;
}
.cell-name-text .nm { font-weight: 500; color: var(--ink); }
.cell-name-text .ph { font-size: 11px; color: var(--muted); margin-top: 2px; }

.pill {
  display: inline-flex; align-items: center; gap: 5px;
  height: 22px; padding: 0 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 500;
}
.pill .dot {
  width: 6px; height: 6px; border-radius: 50%;
}
.pill-paid { background: var(--sage-soft); color: var(--sage-ink); }
.pill-paid .dot { background: var(--sage); }
.pill-overdue { background: var(--terra-soft); color: var(--terra-ink); }
.pill-overdue .dot { background: var(--terra); }
.pill-pending { background: var(--bg-2); color: var(--muted); }
.pill-pending .dot { background: var(--muted-2); }
.pill-borrow { background: var(--ochre-soft); color: var(--ochre-ink); }
.pill-borrow .dot { background: var(--ochre); }

/* months strip */
.months {
  display: inline-flex; gap: 3px;
}
.month-cell {
  width: 14px; height: 18px;
  border-radius: 3px;
  background: var(--bg-2);
  position: relative;
}
.month-cell.is-paid { background: var(--sage); }
.month-cell.is-late { background: var(--terra); }
.month-cell.is-double { background: var(--ochre); }
.month-cell.is-future { background: transparent; border: 1px dashed var(--line); }

/* ---------- Transactions ---------- */
.txn {
  display: grid;
  grid-template-columns: 36px 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--line-2);
}
.txn:last-child { border-bottom: none; }
.txn-ic {
  width: 36px; height: 36px;
  border-radius: 10px;
  display: grid; place-items: center;
}
.txn-ic.t-in { background: var(--sage-soft); color: var(--sage-ink); }
.txn-ic.t-out { background: var(--ochre-soft); color: var(--ochre-ink); }
.txn-ic.t-return { background: var(--indigo-soft); color: var(--indigo); }
.txn-ic.t-fee { background: var(--terra-soft); color: var(--terra-ink); }
.txn-body { min-width: 0; }
.txn-title { font-weight: 500; font-size: 13px; color: var(--ink); }
.txn-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.txn-amt {
  font-weight: 600;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  text-align: right;
}
.txn-amt .u { font-size: 11px; color: var(--muted); font-weight: 500; margin-left: 3px; }
.txn-amt.pos { color: var(--sage); }
.txn-amt.neg { color: var(--terra); }

/* ---------- Donut + Chart ---------- */
.donut-wrap {
  display: flex; align-items: center; gap: 24px;
}
.donut {
  width: 160px; height: 160px; flex-shrink: 0;
  position: relative;
}
.donut svg { display: block; }
.donut-center {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  text-align: center;
}
.donut-center .lbl { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.donut-center .val { font-size: 18px; font-weight: 600; letter-spacing: -0.01em; font-variant-numeric: tabular-nums; }

.legend {
  display: flex; flex-direction: column; gap: 10px;
  flex: 1; min-width: 0;
}
.legend-row {
  display: flex; align-items: center; gap: 10px;
  font-size: 12px;
}
.legend-row .sw {
  width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0;
}
.legend-row .nm { color: var(--ink-2); flex: 1; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.legend-row .vl { font-variant-numeric: tabular-nums; font-weight: 500; color: var(--ink); }
.legend-row .pc { color: var(--muted); font-size: 11px; margin-left: 6px; width: 36px; text-align: right; }

/* Bar chart */
.bars {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 8px;
  height: 180px;
  align-items: end;
  margin-top: 10px;
}
.bar-col {
  display: flex; flex-direction: column; align-items: stretch;
  gap: 4px;
  height: 100%;
  justify-content: flex-end;
}
.bar {
  width: 100%;
  border-radius: 5px 5px 2px 2px;
  background: var(--ink);
  min-height: 2px;
  transition: opacity 0.15s;
  position: relative;
}
.bar.b-paid { background: var(--sage); }
.bar.b-late { background: var(--terra); }
.bar-col:hover .bar { opacity: 0.85; }
.bar-label {
  font-size: 10px; color: var(--muted); text-align: center; margin-top: 6px;
  font-feature-settings: "tnum";
}

/* ---------- Requisites ---------- */
.req-card {
  background: linear-gradient(135deg, #1B1A18 0%, #2A2724 100%);
  color: var(--bg);
  border-radius: var(--radius);
  padding: 22px;
  position: relative;
  overflow: hidden;
  border: 1px solid #2A2724;
}
.req-card::before {
  content: "";
  position: absolute;
  width: 280px; height: 280px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(182,138,62,0.18) 0%, transparent 70%);
  right: -100px; top: -100px;
  pointer-events: none;
}
.req-head { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 24px; position: relative; }
.req-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: rgba(245,242,236,0.55); }
.req-name { font-size: 15px; font-weight: 500; margin-top: 4px; }
.req-bank {
  font-size: 11px;
  background: rgba(245,242,236,0.1);
  padding: 4px 10px;
  border-radius: 6px;
  color: rgba(245,242,236,0.8);
}

.req-rows { display: flex; flex-direction: column; gap: 14px; position: relative; }
.req-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid rgba(245,242,236,0.08);
}
.req-row:last-child { border-bottom: none; padding-bottom: 0; }
.req-row-info { min-width: 0; }
.req-row-label { font-size: 11px; color: rgba(245,242,236,0.55); text-transform: uppercase; letter-spacing: 0.05em; }
.req-row-value {
  font-size: 14px; font-weight: 500; margin-top: 3px;
  font-feature-settings: "tnum";
  letter-spacing: 0.02em;
  overflow-wrap: anywhere;
}
.copy-btn {
  width: 32px; height: 32px;
  border-radius: 8px;
  border: 1px solid rgba(245,242,236,0.15);
  background: rgba(245,242,236,0.06);
  color: var(--bg);
  cursor: pointer;
  display: grid; place-items: center;
  flex-shrink: 0;
  transition: background 0.15s;
}
.copy-btn:hover { background: rgba(245,242,236,0.14); }
.copy-btn.copied {
  background: var(--sage);
  border-color: var(--sage);
}

/* ---------- Borrowers list ---------- */
.borrower {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--line-2);
}
.borrower:last-child { border-bottom: none; }
.borrower-info { min-width: 0; }
.borrower-name { font-weight: 500; font-size: 13px; }
.borrower-meta { font-size: 11px; color: var(--muted); margin-top: 2px; display: flex; gap: 8px; }
.borrower-amt {
  font-weight: 600;
  color: var(--ochre-ink);
  font-variant-numeric: tabular-nums;
  font-size: 14px;
}
.progress {
  height: 4px;
  background: var(--bg-2);
  border-radius: 2px;
  overflow: hidden;
  margin-top: 6px;
}
.progress-fill {
  height: 100%;
  background: var(--ochre);
  border-radius: 2px;
}

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(22, 21, 20, 0.5);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 100;
  display: grid; place-items: center;
  padding: 16px;
  animation: fadeIn 0.2s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { transform: translateY(12px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

.modal {
  background: var(--surface);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 460px;
  padding: 24px;
  box-shadow: 0 24px 60px -20px rgba(0,0,0,0.3);
  animation: slideUp 0.22s ease;
  max-height: 90vh;
  overflow-y: auto;
}
.modal-head {
  display: flex; justify-content: space-between; align-items: flex-start;
  margin-bottom: 20px;
}
.modal-title { font-size: 16px; font-weight: 600; letter-spacing: -0.01em; }
.modal-sub { font-size: 12px; color: var(--muted); margin-top: 3px; }

/* Form */
.field { margin-bottom: 14px; }
.field-label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--ink-2);
  margin-bottom: 6px;
}
.input, .select {
  width: 100%;
  height: 40px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  font: inherit;
  font-size: 13px;
  color: var(--ink);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.input:focus, .select:focus {
  border-color: var(--ink);
  box-shadow: 0 0 0 3px rgba(22,21,20,0.07);
}
textarea.input { height: 80px; padding: 10px 12px; resize: vertical; font-family: inherit; }

.seg {
  display: grid;
  grid-template-columns: repeat(var(--cols, 3), 1fr);
  gap: 6px;
  padding: 4px;
  background: var(--bg-2);
  border-radius: 11px;
}
.seg-btn {
  height: 36px;
  border-radius: 8px;
  border: none;
  background: transparent;
  font: inherit;
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 6px;
}
.seg-btn.is-active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-sm);
}

.modal-actions {
  display: flex; gap: 10px;
  margin-top: 22px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}
.modal-actions .btn { flex: 1; height: 42px; justify-content: center; }

/* ---------- Mobile members card view ---------- */
.member-card {
  display: none;
}

/* ---------- Sparkline ---------- */
.spark { width: 100%; height: 36px; display: block; }

.section-title {
  font-size: 11px; font-weight: 500;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin: 28px 0 12px;
  display: flex; align-items: center; gap: 8px;
}
.section-title::after {
  content: ""; flex: 1; height: 1px; background: var(--line);
}

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

@media (max-width: 640px) {
  .app { padding: 16px 14px 80px; }
  .topbar { flex-wrap: wrap; }
  .brand-name { font-size: 15px; }
  .stat-value { font-size: 22px; }
  .stats { gap: 8px; }
  .stat { padding: 14px 16px; }

  /* Hide table, show cards */
  .members-table-wrap { display: none; }
  .members-cards { display: flex; flex-direction: column; gap: 10px; }
  .member-card {
    display: block;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 14px;
  }
  .member-card-head {
    display: flex; align-items: center; gap: 12px;
    margin-bottom: 12px;
  }
  .member-card-head .nm { font-weight: 500; }
  .member-card-head .ph { font-size: 11px; color: var(--muted); }
  .member-card-stats {
    display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px;
    margin-bottom: 12px;
  }
  .mc-stat-lbl { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
  .mc-stat-val { font-size: 14px; font-weight: 600; margin-top: 2px; font-variant-numeric: tabular-nums; }

  .donut-wrap { flex-direction: column; align-items: stretch; }
  .donut { margin: 0 auto; }

  .req-card { padding: 18px; }
  .req-row-value { font-size: 13px; }

  .modal { padding: 18px; border-radius: 18px; }

  .bars { gap: 4px; height: 140px; }
  .bar-label { font-size: 9px; }

  .section-title { margin-top: 22px; }
}

@media (min-width: 641px) {
  .members-cards { display: none; }
}

/* small util */
.row { display: flex; align-items: center; gap: 10px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.muted { color: var(--muted); }
.tnum { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }
.empty-state { padding: 24px; text-align: center; color: var(--muted); font-size: 13px; }

/* Search input */
.search {
  position: relative;
  flex: 1;
  max-width: 240px;
}
.search input {
  width: 100%;
  height: 36px;
  padding: 0 12px 0 34px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface);
  font: inherit; font-size: 13px;
  outline: none;
}
.search input:focus { border-color: var(--ink-2); }
.search svg {
  position: absolute; left: 11px; top: 50%; transform: translateY(-50%);
  color: var(--muted);
}

/* toast */
.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: var(--bg);
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 13px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.2);
  z-index: 200;
  animation: slideUp 0.2s ease;
  display: flex; align-items: center; gap: 8px;
}
