:root {
  --bg: var(--tg-theme-bg-color, #0e1621);
  --surface: var(--tg-theme-secondary-bg-color, #17212b);
  --surface-2: var(--tg-theme-section-bg-color, #1f2c38);
  --text: var(--tg-theme-text-color, #f3f4f6);
  --muted: var(--tg-theme-hint-color, #8e9aa6);
  --accent: var(--tg-theme-button-color, #2ea6ff);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --link: var(--tg-theme-link-color, #64b5f6);
  --separator: var(--tg-theme-section-separator-color, rgba(255,255,255,.08));
  --danger: #ff5b5b;
  --warning: #f7b955;
  --success: #4dd17b;
  --radius: 20px;
  --shadow: 0 14px 40px rgba(0,0,0,.16);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
}

button, input, select {
  font: inherit;
}

button {
  color: inherit;
}

#app {
  max-width: 760px;
  margin: 0 auto;
  min-height: 100dvh;
  padding-bottom: calc(92px + env(safe-area-inset-bottom));
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(16px + env(safe-area-inset-top)) 18px 12px;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(18px);
}

.eyebrow {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .13em;
}

h1 {
  margin: 3px 0 0;
  font-size: 27px;
  letter-spacing: -.04em;
}

h2, h3, p {
  margin-top: 0;
}

.view {
  padding: 4px 14px 28px;
}

.icon-btn {
  border: 0;
  width: 42px;
  height: 42px;
  border-radius: 14px;
  background: var(--surface);
  font-size: 24px;
  display: grid;
  place-items: center;
  cursor: pointer;
}

.hero {
  position: relative;
  overflow: hidden;
  border-radius: 26px;
  padding: 22px;
  background:
    radial-gradient(circle at 100% 0%, color-mix(in srgb, var(--accent) 35%, transparent), transparent 46%),
    var(--surface);
  box-shadow: var(--shadow);
  margin-bottom: 14px;
}

.hero h2 {
  font-size: 25px;
  margin-bottom: 7px;
  letter-spacing: -.03em;
}

.hero p {
  color: var(--muted);
  margin-bottom: 0;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin: 12px 0 18px;
}

.stat-card {
  border: 0;
  text-align: left;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  min-height: 108px;
  cursor: pointer;
}

.stat-icon {
  font-size: 22px;
  display: block;
  margin-bottom: 12px;
}

.stat-value {
  font-size: 28px;
  font-weight: 800;
  letter-spacing: -.04em;
  display: block;
}

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

.section {
  margin-top: 18px;
}

.section-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 0 4px 9px;
}

.section-title h2 {
  font-size: 17px;
  margin: 0;
}

.section-title button {
  border: 0;
  background: none;
  color: var(--link);
  cursor: pointer;
}

.card {
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
}

.list-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 15px;
  min-height: 58px;
  border-bottom: 1px solid var(--separator);
}

.list-row:last-child {
  border-bottom: 0;
}

.row-main {
  flex: 1;
  min-width: 0;
}

.row-title {
  font-weight: 650;
  overflow: hidden;
  text-overflow: ellipsis;
}

.row-sub {
  margin-top: 3px;
  color: var(--muted);
  font-size: 13px;
}

.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 5px 9px;
  background: var(--surface-2);
  font-size: 12px;
  color: var(--muted);
}

.badge.danger { color: var(--danger); }
.badge.warn { color: var(--warning); }
.badge.good { color: var(--success); }

.empty {
  padding: 26px 18px;
  text-align: center;
  color: var(--muted);
}

.system-card {
  padding: 16px;
}

.system-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}

.system-temp {
  font-size: 29px;
  font-weight: 800;
}

.progress-wrap {
  margin-top: 11px;
}

.progress-label {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 6px;
}

.progress {
  height: 7px;
  border-radius: 999px;
  background: var(--surface-2);
  overflow: hidden;
}

.progress > i {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
}

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  margin: 9px 3px 12px;
}

.page-head h2 {
  margin: 0;
  font-size: 24px;
  letter-spacing: -.03em;
}

.primary-btn, .secondary-btn, .danger-btn {
  border: 0;
  border-radius: 14px;
  padding: 11px 14px;
  font-weight: 700;
  cursor: pointer;
}

.primary-btn {
  background: var(--accent);
  color: var(--accent-text);
}

.secondary-btn {
  background: var(--surface-2);
}

.danger-btn {
  color: white;
  background: var(--danger);
}

.full-btn {
  width: 100%;
  padding: 14px;
}

.round-action {
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: var(--surface-2);
  cursor: pointer;
  flex: 0 0 auto;
}

.round-action.done {
  background: color-mix(in srgb, var(--success) 18%, var(--surface-2));
  color: var(--success);
}

.round-action.delete {
  color: var(--danger);
}

.shopping-check {
  width: 25px;
  height: 25px;
  border: 2px solid var(--muted);
  border-radius: 8px;
  background: transparent;
  cursor: pointer;
  flex: 0 0 auto;
}

.shopping-check.checked {
  border-color: var(--success);
  background: var(--success);
  position: relative;
}

.shopping-check.checked::after {
  content: "✓";
  position: absolute;
  inset: 0;
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 900;
}

.purchased .row-title {
  text-decoration: line-through;
  color: var(--muted);
}

.category-title {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  padding: 17px 4px 7px;
  text-transform: uppercase;
  letter-spacing: .06em;
}

.stepper {
  display: flex;
  align-items: center;
  gap: 6px;
}

.stepper button {
  border: 0;
  background: var(--surface-2);
  border-radius: 10px;
  min-width: 34px;
  height: 34px;
  cursor: pointer;
  font-weight: 800;
}

.stepper-value {
  min-width: 64px;
  text-align: center;
  font-weight: 700;
}

.bottom-nav {
  position: fixed;
  z-index: 20;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: min(760px, 100%);
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  backdrop-filter: blur(20px);
  border-top: 1px solid var(--separator);
}

.nav-btn {
  border: 0;
  background: transparent;
  color: var(--muted);
  min-height: 56px;
  border-radius: 15px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
}

.nav-btn span {
  font-size: 20px;
}

.nav-btn small {
  font-size: 10px;
  font-weight: 700;
}

.nav-btn.active {
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 11%, transparent);
}

.sheet-backdrop {
  position: fixed;
  z-index: 100;
  inset: 0;
  background: rgba(0,0,0,.45);
  display: flex;
  align-items: flex-end;
}

.sheet-backdrop.hidden {
  display: none;
}

.sheet {
  width: min(760px, 100%);
  margin: 0 auto;
  background: var(--surface);
  border-radius: 26px 26px 0 0;
  padding: 8px 18px calc(22px + env(safe-area-inset-bottom));
  max-height: 88dvh;
  overflow: auto;
  box-shadow: 0 -20px 60px rgba(0,0,0,.22);
}

.sheet-handle {
  width: 40px;
  height: 5px;
  border-radius: 999px;
  background: var(--muted);
  opacity: .35;
  margin: 2px auto 18px;
}

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

.field label {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin: 0 0 6px 3px;
}

.field input, .field select {
  width: 100%;
  border: 1px solid var(--separator);
  outline: 0;
  border-radius: 14px;
  padding: 13px 14px;
  background: var(--surface-2);
  color: var(--text);
}

.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 9px;
  margin-top: 16px;
}

.actions.one {
  grid-template-columns: 1fr;
}

.toast {
  position: fixed;
  z-index: 200;
  left: 50%;
  bottom: calc(94px + env(safe-area-inset-bottom));
  transform: translate(-50%, 20px);
  opacity: 0;
  pointer-events: none;
  background: var(--text);
  color: var(--bg);
  padding: 10px 14px;
  border-radius: 999px;
  font-weight: 700;
  transition: .2s ease;
  max-width: calc(100vw - 30px);
  text-align: center;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.loading-card {
  margin-top: 25vh;
  display: grid;
  place-items: center;
  gap: 12px;
  color: var(--muted);
}

.spinner {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 3px solid var(--surface-2);
  border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}

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

.error-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
  margin-top: 16px;
}

.error-card code {
  display: block;
  white-space: pre-wrap;
  color: var(--muted);
  margin-top: 8px;
}

@media (min-width: 640px) {
  .stats-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}


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

.more-card {
  border: 0;
  text-align: left;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 18px;
  min-height: 118px;
  cursor: pointer;
}

.more-card .more-icon {
  display: block;
  font-size: 25px;
  margin-bottom: 14px;
}

.more-card strong {
  display: block;
  font-size: 17px;
}

.more-card small {
  display: block;
  color: var(--muted);
  margin-top: 5px;
  line-height: 1.35;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 5px;
  padding: 5px;
  border-radius: 16px;
  background: var(--surface);
  margin-bottom: 13px;
}

.segmented button {
  border: 0;
  border-radius: 12px;
  padding: 10px 8px;
  color: var(--muted);
  background: transparent;
  font-weight: 700;
  cursor: pointer;
}

.segmented button.active {
  background: var(--surface-2);
  color: var(--text);
}

.note-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 10px;
  cursor: pointer;
}

.note-top {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
}

.note-title {
  font-size: 17px;
  font-weight: 750;
  line-height: 1.25;
}

.note-body {
  color: var(--muted);
  margin-top: 9px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.45;
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.note-meta {
  color: var(--muted);
  font-size: 11px;
  margin-top: 12px;
}

.note-scope {
  flex: 0 0 auto;
  font-size: 12px;
  border-radius: 999px;
  padding: 5px 8px;
  background: var(--surface-2);
}

.note-scope.private {
  color: var(--warning);
}

.note-scope.shared {
  color: var(--link);
}

textarea.note-textarea {
  width: 100%;
  min-height: 180px;
  resize: vertical;
  border: 1px solid var(--separator);
  outline: 0;
  border-radius: 14px;
  padding: 13px 14px;
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  line-height: 1.45;
}

.privacy-hint {
  padding: 12px 13px;
  border-radius: 14px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}


/* ========================= v2.2 UX ========================= */

body.modal-open { overflow: hidden; }
.view { min-height: 72dvh; }

button, .list-row, .note-card, .more-card {
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
button:active { transform: scale(.985); }

.sheet { max-width: 720px; animation: sheetUp .2s ease-out; }
@keyframes sheetUp {
  from { transform: translateY(18px); opacity: .6; }
  to { transform: translateY(0); opacity: 1; }
}

.confirm-icon {
  width: 54px; height: 54px; border-radius: 18px;
  display: grid; place-items: center; font-size: 26px;
  background: color-mix(in srgb, var(--danger) 12%, var(--surface-2));
  margin-bottom: 14px;
}
.confirm-copy { color: var(--muted); line-height: 1.45; }

.empty-state {
  min-height: 220px; display: grid; place-items: center;
  text-align: center; padding: 32px 22px;
  background: var(--surface); border-radius: 24px;
}
.empty-state .empty-icon {
  width: 64px; height: 64px; border-radius: 22px;
  display: grid; place-items: center; margin: 0 auto 14px;
  font-size: 30px; background: var(--surface-2);
}
.empty-state h3 { margin: 0 0 7px; font-size: 18px; }
.empty-state p {
  color: var(--muted); margin: 0 auto 17px;
  max-width: 300px; line-height: 1.45;
}

.skeleton {
  position: relative; overflow: hidden;
  background: var(--surface); border-radius: var(--radius);
}
.skeleton::after {
  content: ""; position: absolute; inset: 0;
  transform: translateX(-100%);
  background: linear-gradient(
    90deg, transparent,
    color-mix(in srgb, var(--text) 7%, transparent), transparent
  );
  animation: shimmer 1.15s infinite;
}
@keyframes shimmer { 100% { transform: translateX(100%); } }
.skeleton-line { height: 14px; border-radius: 7px; background: var(--surface-2); }
.skeleton-card { height: 86px; margin-bottom: 10px; }
.skeleton-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.skeleton-grid .skeleton { height: 112px; }

.swipe-row {
  position: relative; overflow: hidden;
  border-bottom: 1px solid var(--separator);
  background: var(--surface);
}
.swipe-row:last-child { border-bottom: 0; }
.swipe-actions {
  position: absolute; inset: 0 0 0 auto;
  display: flex; justify-content: flex-end; min-width: 148px;
}
.swipe-action {
  width: 74px; border: 0; border-radius: 0;
  font-weight: 800; font-size: 12px;
  display: grid; place-items: center;
}
.swipe-action.good { background: var(--success); color: white; }
.swipe-action.danger { background: var(--danger); color: white; }
.swipe-content {
  position: relative; z-index: 2; background: var(--surface);
  transform: translateX(0); transition: transform .18s ease;
  will-change: transform;
}
.swipe-row.open .swipe-content { transform: translateX(-148px); }

.person-chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 5px 8px; border-radius: 999px;
  background: var(--surface-2); color: var(--muted);
  font-size: 11px; max-width: 150px;
}
.avatar {
  width: 38px; height: 38px; border-radius: 14px;
  display: grid; place-items: center; flex: 0 0 auto;
  background: color-mix(in srgb, var(--accent) 15%, var(--surface-2));
  color: var(--accent); font-weight: 900;
}

.expense-total {
  font-size: 34px; font-weight: 850; letter-spacing: -.05em; margin: 4px 0;
}
.expense-sub { color: var(--muted); font-size: 13px; }
.chart-card { padding: 16px; }
.bar-list { display: grid; gap: 11px; }
.bar-row-label {
  display: flex; justify-content: space-between; gap: 10px;
  font-size: 13px; margin-bottom: 5px;
}
.bar-track {
  height: 9px; background: var(--surface-2);
  border-radius: 999px; overflow: hidden;
}
.bar-fill {
  height: 100%; background: var(--accent);
  border-radius: inherit; min-width: 2px;
}
.trend-chart { height: 160px; width: 100%; overflow: visible; }
.trend-grid { stroke: color-mix(in srgb, var(--muted) 20%, transparent); stroke-width: 1; }
.trend-line {
  fill: none; stroke: var(--accent); stroke-width: 3;
  stroke-linecap: round; stroke-linejoin: round;
}
.trend-dot { fill: var(--accent); }
.trend-label { fill: var(--muted); font-size: 10px; }
.month-switcher { display: flex; align-items: center; gap: 8px; }
.month-switcher button {
  width: 38px; height: 38px; border: 0; border-radius: 12px;
  background: var(--surface-2); cursor: pointer;
}
.month-title {
  min-width: 120px; text-align: center; font-weight: 750;
  text-transform: capitalize;
}
.family-grid { display: grid; gap: 10px; }
.family-card {
  background: var(--surface); border-radius: var(--radius);
  padding: 15px; display: flex; gap: 12px; align-items: center;
}
.metric { text-align: right; }
.metric strong { display: block; font-size: 20px; }
.metric small { color: var(--muted); font-size: 10px; }
.quick-actions {
  display: flex; gap: 8px; overflow-x: auto;
  padding-bottom: 3px; scrollbar-width: none;
}
.quick-actions::-webkit-scrollbar { display: none; }
.quick-pill {
  border: 0; flex: 0 0 auto; padding: 9px 12px;
  border-radius: 999px; background: var(--surface);
  cursor: pointer; font-weight: 700; font-size: 12px;
}

@media (max-width: 420px) {
  .view { padding-left: 10px; padding-right: 10px; }
  .topbar { padding-left: 14px; padding-right: 14px; }
  .stat-card { min-height: 98px; padding: 14px; }
  .stat-value { font-size: 25px; }
  .page-head { align-items: center; }
  .page-head h2 { font-size: 22px; }
  .primary-btn, .secondary-btn, .danger-btn { min-height: 44px; }
  .list-row { padding: 13px 12px; }
  .stepper-value { min-width: 54px; }
}
@media (max-width: 350px) {
  .bottom-nav small { font-size: 9px; }
  .bottom-nav { padding-left: 3px; padding-right: 3px; }
  .nav-btn { min-height: 52px; }
}
@media (orientation: landscape) and (max-height: 520px) {
  .topbar { position: static; padding-top: 10px; }
  .sheet { max-height: 96dvh; }
}


/* ====================== v2.3 subscriptions ====================== */
.subscription-summary {
  background: radial-gradient(circle at 100% 0%,
    color-mix(in srgb, var(--accent) 26%, transparent), transparent 48%),
    var(--surface);
  border-radius: 24px; padding: 18px;
}
.subscription-money {
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 13px;
}
.subscription-money > div {
  background: var(--surface-2); border-radius: 16px; padding: 13px;
}
.subscription-money strong { display: block; font-size: 20px; letter-spacing: -.03em; }
.subscription-money small { color: var(--muted); }
.subscription-card { background: var(--surface); border-radius: var(--radius); margin-bottom: 10px; overflow: hidden; }
.subscription-logo {
  width: 42px; height: 42px; border-radius: 15px; display: grid; place-items: center;
  background: var(--surface-2); font-size: 21px; flex: 0 0 auto;
}
.subscription-price { text-align: right; flex: 0 0 auto; }
.subscription-price strong { display: block; font-size: 16px; }
.subscription-price small { color: var(--muted); font-size: 11px; }
.subscription-paused { opacity: .58; }
.subscription-next { margin-top: 6px; display: flex; flex-wrap: wrap; gap: 6px; }
.subscription-note {
  padding: 12px 14px; color: var(--muted); font-size: 12px; line-height: 1.45;
  background: color-mix(in srgb, var(--surface-2) 75%, transparent);
}
@media (max-width: 380px) {
  .subscription-money { grid-template-columns: 1fr; }
}
