:root {
  --bg: #f4f3fb;
  --card: #ffffff;
  --ink: #26243d;
  --ink-soft: #6d6a8a;
  --line: #e6e4f2;
  --primary: #6c5ce7;
  --primary-dark: #5546d6;
  --primary-soft: #efecff;
  --green: #0da678;
  --green-soft: #e2f7ef;
  --red: #e05661;
  --red-soft: #fdeaec;
  --amber: #b26a00;
  --amber-soft: #fff3dd;
  --radius: 16px;
  --shadow: 0 2px 10px rgba(38, 36, 61, .07);
}

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

[hidden] { display: none !important; }

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

body {
  font-family: 'Inter', -apple-system, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  min-height: 100dvh;
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
}

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

/* Шапка */
.top {
  position: sticky; top: 0; z-index: 20;
  background: linear-gradient(135deg, #6c5ce7 0%, #8e7bff 100%);
  color: #fff;
  padding-top: env(safe-area-inset-top);
}
.top-inner {
  max-width: 640px; margin: 0 auto;
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; padding: 12px 16px;
}
.brand { display: flex; align-items: center; gap: 6px; font-weight: 800; font-size: 19px; }
.brand-plus {
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; border-radius: 9px;
  background: rgba(255, 255, 255, .22); font-size: 16px;
}
.top-right { display: flex; align-items: center; gap: 8px; }
.balance-chip {
  display: flex; align-items: baseline; gap: 5px;
  background: rgba(255, 255, 255, .18);
  border: 1px solid rgba(255, 255, 255, .35);
  border-radius: 999px; padding: 6px 12px;
  font-weight: 800; font-size: 16px;
}
.balance-chip.bump { animation: bump .4s ease; }
@keyframes bump { 40% { transform: scale(1.15); } }
.balance-unit { font-weight: 600; font-size: 11px; opacity: .85; }
.role-btn {
  background: rgba(255, 255, 255, .18);
  border: 1px solid rgba(255, 255, 255, .35);
  color: #fff; border-radius: 999px;
  padding: 6px 12px; font-size: 13px; font-weight: 600;
  white-space: nowrap;
}
.role-btn.parent-on { background: #fff; color: var(--primary-dark); }

/* Экран */
.screen { max-width: 640px; margin: 0 auto; padding: 16px; }

.h1 { font-size: 21px; font-weight: 800; margin: 4px 0 2px; }
.sub { color: var(--ink-soft); font-size: 14px; margin-bottom: 14px; }

.card {
  background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 14px;
  display: flex; align-items: center; gap: 12px;
  margin-bottom: 10px;
}
.card .emoji {
  flex: 0 0 auto; width: 46px; height: 46px; border-radius: 14px;
  display: flex; align-items: center; justify-content: center;
  font-size: 24px; background: var(--primary-soft);
}
.card.spend .emoji { background: var(--amber-soft); }
.card .body { flex: 1; min-width: 0; }
.card .title { font-weight: 700; font-size: 15px; line-height: 1.3; }
.card .meta { color: var(--ink-soft); font-size: 13px; margin-top: 2px; }

.pts { font-weight: 800; white-space: nowrap; }
.pts.in { color: var(--green); }
.pts.out { color: var(--red); }

.btn {
  border-radius: 12px; padding: 10px 16px;
  font-weight: 700; font-size: 14px;
  min-height: 44px;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:active { background: var(--primary-dark); }
.btn-green { background: var(--green); color: #fff; }
.btn-red-soft { background: var(--red-soft); color: var(--red); }
.btn-ghost { background: var(--primary-soft); color: var(--primary-dark); }
.btn[disabled] { opacity: .45; cursor: default; }
.btn-block { width: 100%; }
.btn-row { display: flex; gap: 8px; margin-top: 12px; }
.btn-row .btn { flex: 1; }

.status-pill {
  display: inline-block; border-radius: 999px;
  padding: 3px 10px; font-size: 12px; font-weight: 700;
}
.status-pill.pending { background: var(--amber-soft); color: var(--amber); }
.status-pill.rejected { background: var(--red-soft); color: var(--red); }
.status-pill.approved { background: var(--green-soft); color: var(--green); }

.review-card { display: block; }
.review-card .head { display: flex; align-items: center; gap: 12px; }
.review-card .photo {
  width: 100%; border-radius: 12px; margin-top: 10px;
  max-height: 320px; object-fit: cover; display: block;
}
.review-card .note {
  margin-top: 10px; background: var(--bg);
  border-radius: 10px; padding: 9px 12px; font-size: 14px;
}
.review-card .note.warn { background: var(--red-soft); color: #a13840; }

.empty {
  text-align: center; color: var(--ink-soft);
  padding: 44px 20px; font-size: 14px;
}
.empty .big { font-size: 42px; margin-bottom: 10px; }

/* Кошелёк */
.wallet-hero {
  background: linear-gradient(135deg, #6c5ce7, #8e7bff);
  color: #fff; border-radius: 20px;
  padding: 22px 20px; text-align: center;
  margin-bottom: 16px; box-shadow: var(--shadow);
}
.wallet-hero .label { font-size: 13px; font-weight: 600; opacity: .85; }
.wallet-hero .value { font-size: 44px; font-weight: 800; line-height: 1.15; }
.wallet-hero .unit { font-size: 15px; font-weight: 600; opacity: .85; }

.hist-item {
  display: flex; align-items: center; gap: 10px;
  background: var(--card); border-radius: 12px;
  padding: 11px 14px; margin-bottom: 8px; box-shadow: var(--shadow);
}
.hist-item .t { flex: 1; min-width: 0; font-size: 14px; font-weight: 600; }
.hist-item .d { color: var(--ink-soft); font-size: 12px; font-weight: 400; margin-top: 1px; }

.section-label {
  font-size: 13px; font-weight: 700; color: var(--ink-soft);
  text-transform: uppercase; letter-spacing: .04em;
  margin: 18px 0 8px;
}

/* Табы снизу */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs-inner { max-width: 640px; margin: 0 auto; display: flex; }
.tab {
  flex: 1; background: none; padding: 8px 4px 10px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  color: var(--ink-soft); font-size: 11px; font-weight: 600;
  position: relative; min-height: 56px;
}
.tab .ico { font-size: 22px; line-height: 1.2; }
.tab.on { color: var(--primary-dark); }
.tab .badge {
  position: absolute; top: 4px; left: calc(50% + 8px);
  background: var(--red); color: #fff;
  border-radius: 999px; min-width: 17px; height: 17px;
  font-size: 11px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  padding: 0 4px;
}

/* Модалка */
.modal-wrap {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(30, 27, 56, .5);
  display: flex; align-items: flex-end; justify-content: center;
}
.modal {
  background: var(--card); width: 100%; max-width: 640px;
  border-radius: 20px 20px 0 0; padding: 20px 16px calc(20px + env(safe-area-inset-bottom));
  max-height: 88dvh; overflow-y: auto;
  animation: rise .22s ease;
}
@keyframes rise { from { transform: translateY(30px); opacity: 0; } }
.modal h2 { font-size: 18px; margin-bottom: 4px; }
.modal .sub { margin-bottom: 12px; }

.field { margin-bottom: 12px; }
.field label { display: block; font-size: 13px; font-weight: 700; margin-bottom: 5px; }
.field input, .field textarea {
  width: 100%; border: 1.5px solid var(--line); border-radius: 12px;
  padding: 11px 12px; font-size: 15px; background: var(--card);
}
.field input:focus, .field textarea:focus { outline: none; border-color: var(--primary); }
.field textarea { resize: vertical; min-height: 70px; }
.field .hint { font-size: 12px; color: var(--ink-soft); margin-top: 4px; }

.photo-attach {
  border: 1.5px dashed var(--line); border-radius: 12px;
  padding: 12px; text-align: center; color: var(--ink-soft);
  font-size: 14px; font-weight: 600; background: var(--bg);
  width: 100%;
}
.photo-preview { width: 100%; border-radius: 12px; margin-top: 8px; max-height: 240px; object-fit: cover; }
.photo-attach.recording { border-color: var(--red); color: var(--red); background: var(--red-soft); }

.emoji-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(46px, 1fr));
  gap: 6px;
}
.emoji-opt {
  height: 46px; border-radius: 12px;
  background: var(--bg); font-size: 23px;
  display: flex; align-items: center; justify-content: center;
  border: 2px solid transparent;
}
.emoji-opt.sel { background: var(--primary-soft); border-color: var(--primary); }

/* Экран входа */
.auth { max-width: 420px; margin: 0 auto; padding-top: 8vh; text-align: center; }
.auth-logo {
  width: 76px; height: 76px; margin: 0 auto 12px;
  background: linear-gradient(135deg, #6c5ce7, #8e7bff);
  border-radius: 24px; color: #fff; font-size: 40px;
  display: flex; align-items: center; justify-content: center;
  box-shadow: var(--shadow);
}
.auth-title { font-size: 28px; font-weight: 800; }
.auth-sub { color: var(--ink-soft); font-size: 15px; margin: 6px 0 22px; }
.auth-card {
  background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px 16px;
  margin-bottom: 14px; text-align: left;
}
.auth-card h2 { font-size: 17px; margin-bottom: 2px; }
.auth-card .sub { margin-bottom: 12px; }
.tg-widget { display: flex; justify-content: center; padding: 4px 0; }

/* Категории у родителя */
.cat-block {
  background: var(--primary-soft); border-radius: 18px;
  padding: 12px; margin-bottom: 14px;
}
.cat-block .card { margin-bottom: 8px; }
.cat-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; margin-bottom: 10px; padding: 0 4px;
}
.cat-title { font-size: 16px; font-weight: 800; }
.cat-block .btn-block { margin-top: 2px; }

/* Семья */
.invite-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; margin-top: 10px;
  background: var(--bg); border-radius: 12px; padding: 10px 12px;
}
.invite-label { font-size: 12px; color: var(--ink-soft); font-weight: 600; }
.invite-code { font-size: 24px; font-weight: 800; letter-spacing: 4px; }

.field select {
  width: 100%; border: 1.5px solid var(--line); border-radius: 12px;
  padding: 11px 38px 11px 12px; font-size: 15px; font-family: inherit; font-weight: 600;
  background: var(--card) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='9' viewBox='0 0 14 9'%3E%3Cpath d='M1 1l6 6 6-6' fill='none' stroke='%236d6a8a' stroke-width='2' stroke-linecap='round'/%3E%3C/svg%3E") no-repeat right 13px center;
  -webkit-appearance: none; appearance: none;
}
.field select:focus { outline: none; border-color: var(--primary); }

/* Аватарки и профиль */
.avatar {
  flex: 0 0 auto; width: 46px; height: 46px;
  border-radius: 14px; object-fit: cover; display: block;
}
.avatar-lg { width: 96px; height: 96px; border-radius: 20px; margin-top: 8px; }
.avatar-hero {
  width: 72px; height: 72px; border-radius: 50%;
  margin: 0 auto 10px; border: 3px solid rgba(255, 255, 255, .6);
}
.avatar-emoji-hero {
  display: flex; align-items: center; justify-content: center;
  font-size: 40px; background: rgba(255, 255, 255, .22);
}
.seg { display: flex; gap: 8px; }
.seg-btn {
  flex: 1; border: 2px solid var(--line); border-radius: 12px;
  background: var(--card); padding: 10px; font-weight: 700; font-size: 14px;
}
.seg-btn.sel { border-color: var(--primary); background: var(--primary-soft); color: var(--primary-dark); }

.rate-line {
  background: var(--card); border-radius: 12px;
  padding: 9px 12px; font-size: 13px; font-weight: 600;
  color: var(--ink-soft); box-shadow: var(--shadow);
  margin-bottom: 12px;
}
.rate-line-parent { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.rate-line-parent .link-btn { padding: 0; flex: 0 0 auto; color: var(--primary-dark); }

.check-row {
  display: flex; align-items: center; gap: 10px;
  font-weight: 600; font-size: 14px; cursor: pointer;
}
.check-row input[type="checkbox"] { width: 20px; height: 20px; accent-color: var(--primary); }

.bday-banner {
  background: linear-gradient(135deg, #ffb75e, #ed8f03);
  color: #fff; font-weight: 700; font-size: 14px;
  border-radius: 14px; padding: 12px 14px;
  margin: 6px 0 10px; box-shadow: var(--shadow);
}
.audio-note { display: block; width: 100%; margin-top: 8px; }

.pin-input {
  font-size: 26px; letter-spacing: 8px; text-align: center; font-weight: 800;
}

/* Родительский режим */
.parent-bar {
  background: var(--amber-soft); color: var(--amber);
  font-size: 13px; font-weight: 700; text-align: center;
  padding: 7px 12px;
}
.mini-actions { display: flex; gap: 6px; flex: 0 0 auto; }
.mini-btn {
  width: 38px; height: 38px; border-radius: 10px;
  background: var(--bg); font-size: 16px;
  display: flex; align-items: center; justify-content: center;
}
.card.inactive { opacity: .55; }
.card.started { border: 2px solid var(--primary); }
.link-btn {
  background: none; padding: 4px 0 0; font-size: 13px; font-weight: 600;
  color: var(--ink-soft); text-decoration: underline; display: block;
}
.link-btn-light { color: rgba(255, 255, 255, .85); margin: 6px auto 0; }

.toast {
  position: fixed; left: 50%; bottom: calc(86px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--ink); color: #fff;
  border-radius: 12px; padding: 10px 18px;
  font-size: 14px; font-weight: 600; z-index: 60;
  max-width: 92vw; text-align: center;
  animation: rise .2s ease;
}
.toast.ok { background: var(--green); }
.toast.err { background: var(--red); }

@media (min-width: 480px) {
  .modal-wrap { align-items: center; padding: 20px; }
  .modal { border-radius: 20px; }
}
