:root {
  --bg: #f6f8fc;
  --surface: rgba(255, 255, 255, .78);
  --surface-strong: #ffffff;
  --text: #151821;
  --muted: #697386;
  --line: rgba(31, 42, 68, .1);
  --shadow: 0 10px 28px rgba(22, 27, 45, .08);
  --primary: #8a5cff;
  --primary-2: #ff4fb8;
  --success: #15b879;
  --warning: #e4a11b;
  --danger: #ef476f;
  --info: #6c5ce7;
  --nav-h: 62px;
  --radius: 18px;
  --font: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

:root[data-theme="dark"] {
  --bg: #0f1115;
  --surface: rgba(28, 31, 39, .76);
  --surface-strong: #191d25;
  --text: #f4f6fb;
  --muted: #a3adbf;
  --line: rgba(255, 255, 255, .1);
  --shadow: 0 12px 32px rgba(0, 0, 0, .28);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  letter-spacing: 0;
}

body { overflow-x: hidden; }

button, input, select, textarea { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }

.app-shell {
  min-height: 100vh;
  padding: env(safe-area-inset-top) 12px calc(var(--nav-h) + env(safe-area-inset-bottom) + 14px);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 52px;
  padding: 8px 0;
  background: linear-gradient(to bottom, var(--bg) 72%, rgba(246, 248, 252, 0));
}

:root[data-theme="dark"] .topbar {
  background: linear-gradient(to bottom, var(--bg) 72%, rgba(15, 17, 21, 0));
}

.brand {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 9px;
  flex: 1;
}

.brand-mark, .avatar {
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  color: white;
  background: linear-gradient(135deg, var(--primary-2), var(--primary));
  box-shadow: 0 8px 18px rgba(138, 92, 255, .24);
  font-weight: 800;
  font-size: 13px;
}

.brand-title {
  margin: 0;
  font-size: 17px;
  line-height: 1.1;
  font-weight: 800;
}

.brand-subtitle {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 7px;
}

.icon-btn, .small-btn {
  border: 1px solid var(--line);
  color: var(--text);
  background: var(--surface);
  backdrop-filter: blur(16px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, .04);
  cursor: pointer;
  transition: transform .18s ease, border-color .18s ease, background .18s ease;
}

.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 13px;
  display: grid;
  place-items: center;
}

.icon-btn:active, .small-btn:active, .btn:active { transform: scale(.97); }

.screen {
  display: grid;
  gap: 12px;
  animation: fade-in .2s ease;
}

.hero-balance {
  position: relative;
  overflow: hidden;
  border-radius: 20px;
  padding: 15px;
  color: white;
  background:
    linear-gradient(135deg, rgba(255, 79, 184, .95), rgba(138, 92, 255, .95)),
    radial-gradient(circle at 80% 0%, rgba(255, 255, 255, .24), transparent 34%);
  box-shadow: 0 14px 30px rgba(138, 92, 255, .23);
}

.hero-balance .label {
  font-size: 12px;
  opacity: .86;
}

.hero-balance .amount {
  margin-top: 4px;
  font-size: 25px;
  font-weight: 850;
  line-height: 1.1;
}

.hero-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-top: 12px;
  font-size: 12px;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 9px;
}

.overview-totals {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 9px;
}

@media (min-width: 720px) {
  .app-shell { max-width: 980px; margin: 0 auto; }
  .stat-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .grid-two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

.stat-card, .panel, .list-card, .empty-state {
  border: 1px solid var(--line);
  background: var(--surface);
  backdrop-filter: blur(18px);
  box-shadow: var(--shadow);
}

.stat-card {
  min-height: 74px;
  border-radius: 18px;
  padding: 10px;
  display: grid;
  gap: 5px;
}

.stat-card.primary {
  min-height: 92px;
  color: white;
  border-color: transparent;
  background: linear-gradient(135deg, rgba(255, 79, 184, .96), rgba(138, 92, 255, .96));
  box-shadow: 0 14px 30px rgba(138, 92, 255, .22);
}

.stat-card.primary .stat-label,
.stat-card.primary .stat-note {
  color: rgba(255, 255, 255, .78);
}

.stat-card.primary .stat-icon {
  color: var(--primary);
  background: rgba(255, 255, 255, .9);
}

.stat-card.actionable {
  cursor: pointer;
}

.stat-card.actionable:active {
  transform: scale(.98);
}

.stat-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.stat-icon {
  width: 26px;
  height: 26px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  color: white;
  background: linear-gradient(135deg, var(--primary-2), var(--primary));
}

.stat-label {
  color: var(--muted);
  font-size: 11px;
}

.stat-value {
  font-size: 17px;
  font-weight: 800;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stat-note {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.25;
}

.panel {
  border-radius: var(--radius);
  padding: 12px;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.panel-title {
  margin: 0;
  font-size: 16px;
  line-height: 1.2;
  font-weight: 800;
}

.panel-caption {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.toolbar {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(132px, 1fr));
  gap: 8px;
  margin-bottom: 9px;
}

.searchbox, .field input, .field select, .field textarea {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 9px 11px;
  outline: none;
  color: var(--text);
  background: var(--surface-strong);
  transition: border-color .18s ease, box-shadow .18s ease;
}

.field textarea {
  resize: vertical;
  min-height: 74px;
}

.searchbox:focus, .field input:focus, .field select:focus, .field textarea:focus {
  border-color: rgba(138, 92, 255, .72);
  box-shadow: 0 0 0 3px rgba(138, 92, 255, .12);
}

.field {
  display: grid;
  gap: 5px;
  margin-bottom: 9px;
}

.field label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.field-hint {
  min-height: 14px;
  color: var(--danger);
  font-size: 11px;
}

.form-grid {
  display: grid;
  gap: 8px;
}

.grid-two {
  display: grid;
  gap: 8px;
}

.btn-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.btn {
  min-height: 40px;
  border: 0;
  border-radius: 14px;
  padding: 9px 13px;
  color: white;
  background: linear-gradient(135deg, var(--primary-2), var(--primary));
  box-shadow: 0 8px 18px rgba(138, 92, 255, .22);
  cursor: pointer;
  font-weight: 750;
  transition: transform .18s ease, box-shadow .18s ease, opacity .18s ease;
}

.btn.secondary {
  color: var(--text);
  background: var(--surface-strong);
  border: 1px solid var(--line);
  box-shadow: none;
}

.btn.success { background: var(--success); box-shadow: 0 8px 18px rgba(21, 184, 121, .18); }
.btn.warning { background: var(--warning); box-shadow: 0 8px 18px rgba(228, 161, 27, .16); }
.btn.danger { background: var(--danger); box-shadow: 0 8px 18px rgba(239, 71, 111, .18); }

.small-btn {
  min-height: 30px;
  border-radius: 11px;
  padding: 6px 9px;
  font-size: 12px;
  font-weight: 700;
}

.list {
  display: grid;
  gap: 8px;
}

.list-card {
  border-radius: 16px;
  padding: 10px;
  display: grid;
  grid-template-columns: 34px 1fr auto;
  gap: 9px;
  align-items: center;
  cursor: pointer;
  transition: transform .18s ease, border-color .18s ease;
}

.list-card:active { transform: scale(.99); }

.card-main { min-width: 0; }

.card-title {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  font-size: 14px;
  font-weight: 800;
}

.truncate {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-meta {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.card-side {
  display: grid;
  justify-items: end;
  gap: 6px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 11px;
  font-weight: 800;
  color: var(--info);
  background: rgba(108, 92, 231, .12);
}

.badge.success { color: var(--success); background: rgba(21, 184, 121, .13); }
.badge.warning { color: var(--warning); background: rgba(228, 161, 27, .14); }
.badge.danger { color: var(--danger); background: rgba(239, 71, 111, .13); }
.badge.muted { color: var(--muted); background: rgba(105, 115, 134, .12); }

.chips {
  display: flex;
  gap: 7px;
  overflow-x: auto;
  padding-bottom: 2px;
  scrollbar-width: none;
}

.chips::-webkit-scrollbar, .bottom-nav::-webkit-scrollbar { display: none; }

.chip {
  flex: 0 0 auto;
  min-height: 32px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 11px;
  color: var(--text);
  background: var(--surface);
  cursor: pointer;
  font-size: 12px;
  font-weight: 750;
}

.chip.active {
  color: white;
  border-color: transparent;
  background: linear-gradient(135deg, var(--primary-2), var(--primary));
}

.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  display: flex;
  gap: 4px;
  overflow-x: auto;
  padding: 6px 10px calc(6px + env(safe-area-inset-bottom));
  background: rgba(255, 255, 255, .72);
  border-top: 1px solid var(--line);
  backdrop-filter: blur(20px);
}

:root[data-theme="dark"] .bottom-nav { background: rgba(19, 22, 29, .78); }

.nav-item {
  min-width: 64px;
  flex: 1 0 64px;
  border: 0;
  border-radius: 16px;
  background: transparent;
  color: var(--muted);
  display: grid;
  place-items: center;
  align-content: center;
  gap: 2px;
  cursor: pointer;
  font-size: 11px;
  font-weight: 750;
}

.nav-item .nav-icon {
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
}

.nav-item.active {
  color: white;
  background: linear-gradient(135deg, var(--primary-2), var(--primary));
  box-shadow: 0 8px 18px rgba(138, 92, 255, .24);
  transform: translateY(-2px);
}

.empty-state {
  border-radius: 16px;
  padding: 18px 12px;
  text-align: center;
  color: var(--muted);
}

.skeleton {
  min-height: 74px;
  border-radius: 16px;
  background: linear-gradient(90deg, rgba(128, 128, 128, .08), rgba(128, 128, 128, .18), rgba(128, 128, 128, .08));
  background-size: 200% 100%;
  animation: shimmer 1.1s linear infinite;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 70;
  background: rgba(9, 12, 18, .46);
  display: grid;
  place-items: end center;
  padding: 16px 10px calc(16px + env(safe-area-inset-bottom));
  animation: fade-in .16s ease;
}

.modal {
  width: min(620px, 100%);
  max-height: min(82vh, 720px);
  overflow: auto;
  border-radius: 22px;
  border: 1px solid var(--line);
  background: var(--surface-strong);
  box-shadow: 0 20px 60px rgba(0, 0, 0, .26);
  animation: sheet-up .18s ease;
}

.modal-head {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  background: var(--surface-strong);
  border-bottom: 1px solid var(--line);
}

.modal-body {
  padding: 12px;
}

.member-modal {
  max-height: min(88vh, 760px);
}

.member-detail {
  display: grid;
  gap: 10px;
}

.member-summary {
  display: grid;
  grid-template-columns: 38px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(128, 128, 128, .06);
}

.member-summary h3 {
  margin: 0;
  font-size: 15px;
}

.member-summary p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.compact-section {
  display: grid;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(128, 128, 128, .05);
}

.compact-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.compact-head h3 {
  margin: 0;
  font-size: 14px;
}

.compact-head span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.mini-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 9px;
  align-items: center;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface-strong);
}

.mini-row.clickable {
  cursor: pointer;
}

.mini-row b {
  display: block;
  font-size: 13px;
}

.mini-row p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.rank {
  width: 28px;
  height: 28px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  color: white;
  background: linear-gradient(135deg, var(--primary-2), var(--primary));
  font-size: 12px;
  font-weight: 850;
}

.detail-grid {
  display: grid;
  gap: 8px;
}

.detail-row {
  display: grid;
  grid-template-columns: 118px 1fr;
  gap: 8px;
  padding: 8px;
  border-radius: 12px;
  background: rgba(128, 128, 128, .06);
  font-size: 12px;
}

.detail-key { color: var(--muted); }
.detail-val { min-width: 0; overflow-wrap: anywhere; font-weight: 650; }

.toast-stack {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 10px);
  z-index: 100;
  display: grid;
  gap: 8px;
  pointer-events: none;
}

.toast {
  width: min(520px, 100%);
  margin: 0 auto;
  border: 1px solid var(--line);
  border-radius: 15px;
  padding: 10px 12px;
  color: var(--text);
  background: var(--surface-strong);
  box-shadow: var(--shadow);
  pointer-events: auto;
  animation: toast-in .2s ease;
}

.toast.error { border-color: rgba(239, 71, 111, .38); }
.toast.success { border-color: rgba(21, 184, 121, .38); }

.pre {
  max-height: 260px;
  overflow: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  margin: 0;
  padding: 10px;
  border-radius: 14px;
  background: rgba(128, 128, 128, .08);
  font-size: 11px;
}

.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;
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes sheet-up {
  from { transform: translateY(16px) scale(.98); opacity: .7; }
  to { transform: translateY(0) scale(1); opacity: 1; }
}

@keyframes toast-in {
  from { transform: translateY(8px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

@keyframes shimmer {
  from { background-position: 200% 0; }
  to { background-position: -200% 0; }
}
