:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #eef1f9;
  --text: #1a2130;
  --text-muted: #667085;
  --primary: #4f6df5;
  --primary-dark: #3b53c9;
  --primary-soft: #e8ecfe;
  --success: #22c55e;
  --success-soft: #e7f9ee;
  --danger: #ef4444;
  --danger-soft: #fdeaea;
  --warning: #f59e0b;
  --warning-soft: #fef3e2;
  --border: #e5e9f2;
  --radius-lg: 22px;
  --radius-md: 16px;
  --radius-sm: 10px;
  --shadow: 0 6px 24px rgba(24, 33, 66, .08);
  --shadow-sm: 0 2px 10px rgba(24, 33, 66, .06);
  --nav-h: 68px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d111c;
    --surface: #161c2b;
    --surface-2: #1e2536;
    --text: #eef1f8;
    --text-muted: #8b96ae;
    --primary-soft: #232a4a;
    --success-soft: #123324;
    --danger-soft: #3a1b1e;
    --warning-soft: #3a2c10;
    --border: #262f45;
    --shadow: 0 6px 28px rgba(0, 0, 0, .45);
    --shadow-sm: 0 2px 12px rgba(0, 0, 0, .35);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
h1, h2, h3, p { margin: 0; }
button { font-family: inherit; }

.app { min-height: 100%; display: flex; flex-direction: column; }

/* ---------- buttons & inputs ---------- */
.btn {
  appearance: none; border: none; cursor: pointer;
  border-radius: var(--radius-sm);
  padding: .7rem 1.1rem;
  font-size: .95rem; font-weight: 600;
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  transition: transform .08s ease, opacity .15s ease, background .15s ease;
}
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success { background: var(--success); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-ghost { background: var(--surface-2); color: var(--text); }
.btn-outline { background: transparent; color: var(--primary); border: 1.5px solid var(--primary); }
.btn-sm { padding: .45rem .8rem; font-size: .82rem; border-radius: 8px; }
.btn-block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.icon-btn {
  border: none; background: var(--surface-2); color: var(--text);
  width: 40px; height: 40px; border-radius: 12px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; font-size: 1.1rem;
}

.field { display: flex; flex-direction: column; gap: .35rem; margin-bottom: .9rem; text-align: left; }
.field label { font-size: .82rem; font-weight: 600; color: var(--text-muted); }
.field input, .field select, .field textarea {
  border: 1.5px solid var(--border); background: var(--surface);
  color: var(--text); border-radius: var(--radius-sm); padding: .65rem .8rem;
  font-size: 1rem; outline: none; transition: border-color .15s ease;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--primary); }
.field-row { display: flex; gap: .7rem; }
.field-row .field { flex: 1; }

/* ---------- login / setup ---------- */
.auth-screen {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 2rem 1.2rem; gap: 1.6rem; text-align: center;
}
.auth-brand { display: flex; flex-direction: column; align-items: center; gap: .4rem; }
.auth-brand .emoji { font-size: 3rem; }
.auth-brand h1 { font-size: 1.5rem; }
.auth-brand p { color: var(--text-muted); }

.profile-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 1rem; width: 100%; max-width: 520px;
}
.profile-card {
  background: var(--surface); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm);
  padding: 1.2rem .8rem; display: flex; flex-direction: column; align-items: center; gap: .5rem;
  cursor: pointer; border: 2px solid transparent; transition: border-color .15s ease, transform .1s ease;
}
.profile-card:hover { border-color: var(--primary); transform: translateY(-2px); }
.profile-avatar {
  width: 64px; height: 64px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  font-size: 2rem; color: #fff;
}
.profile-card .name { font-weight: 700; }
.profile-card .role { font-size: .75rem; color: var(--text-muted); }

.pinpad-wrap { display: flex; flex-direction: column; align-items: center; gap: 1.4rem; }
.pin-dots { display: flex; gap: .8rem; }
.pin-dots span {
  width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--primary);
  background: transparent; transition: background .1s ease;
}
.pin-dots span.filled { background: var(--primary); }
.pin-dots.error span { border-color: var(--danger); }
.pinpad {
  display: grid; grid-template-columns: repeat(3, 72px); gap: .8rem;
}
.pinpad button {
  width: 72px; height: 72px; border-radius: 50%; border: none; background: var(--surface);
  box-shadow: var(--shadow-sm); font-size: 1.4rem; font-weight: 600; color: var(--text); cursor: pointer;
}
.pinpad button:active { background: var(--surface-2); }
.pinpad button.wide { font-size: 1rem; color: var(--text-muted); }

/* ---------- app shell ---------- */
.shell { flex: 1; display: flex; flex-direction: column; padding-bottom: calc(var(--nav-h) + 12px); }
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: 1rem 1.1rem; background: var(--bg);
}
.topbar .who { display: flex; align-items: center; gap: .7rem; }
.topbar .who .profile-avatar { width: 42px; height: 42px; font-size: 1.3rem; }
.topbar .who .name { font-weight: 700; font-size: 1rem; }
.topbar .who .role { font-size: .72rem; color: var(--text-muted); }

.content { flex: 1; padding: 0 1.1rem 1.5rem; max-width: 880px; width: 100%; margin: 0 auto; }

.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0; height: var(--nav-h);
  background: var(--surface); border-top: 1px solid var(--border);
  display: flex; padding-bottom: env(safe-area-inset-bottom); z-index: 20;
}
.bottom-nav button {
  position: relative;
  flex: 1; border: none; background: transparent; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: .15rem; color: var(--text-muted);
  font-size: .68rem; font-weight: 600; cursor: pointer;
}
.bottom-nav button .ic { font-size: 1.25rem; }
.bottom-nav button.active { color: var(--primary); }
.bottom-nav .badge {
  position: absolute; top: 4px; right: 18%;
  min-width: 18px; height: 18px; border-radius: 50%; box-shadow: 0 0 0 2px var(--surface);
  background: var(--danger); color: #fff; font-weight: 700;
  font-size: .62rem; line-height: 1; display: flex;
  align-items: center; justify-content: center; padding: 0 2px;
}

/* ---------- cards / sections ---------- */
.section-title {
  font-size: 1.05rem; font-weight: 700; margin: 1.5rem 0 .8rem;
  display: flex; align-items: center; justify-content: space-between;
}
.card {
  background: var(--surface); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm);
  padding: 1.1rem 1.2rem;
}
.balance-card {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff; border-radius: var(--radius-lg); padding: 1.4rem 1.3rem;
  box-shadow: var(--shadow); display: flex; flex-direction: column; gap: .3rem;
}
.balance-card .label { font-size: .82rem; opacity: .85; }
.balance-card .amount { font-size: 2.4rem; font-weight: 800; letter-spacing: -.02em; }

.list { display: flex; flex-direction: column; gap: .7rem; }

.task-card {
  background: var(--surface); border-radius: var(--radius-md); box-shadow: var(--shadow-sm);
  padding: .9rem 1rem; display: flex; align-items: center; gap: .8rem; flex-wrap: wrap;
}
.task-card > .btn { flex-basis: 100%; }
.task-card .info { flex: 1; min-width: 0; }
.task-card .title { font-weight: 700; }
.task-card .meta { font-size: .78rem; color: var(--text-muted); margin-top: .15rem; }
.task-card .reward { font-weight: 700; color: var(--success); white-space: nowrap; }

.status-pill {
  font-size: .68rem; font-weight: 700; padding: .25rem .55rem; border-radius: 999px;
  white-space: nowrap;
}
.status-pill.todo { background: var(--surface-2); color: var(--text-muted); }
.status-pill.awaiting_approval { background: var(--warning-soft); color: var(--warning); }
.status-pill.approved { background: var(--success-soft); color: var(--success); }
.status-pill.rejected { background: var(--danger-soft); color: var(--danger); }

.goal-card { display: flex; flex-direction: column; gap: .55rem; }
.goal-card .head { display: flex; align-items: center; gap: .6rem; }
.goal-card .head .icon { font-size: 1.4rem; }
.goal-card .head .title { font-weight: 700; flex: 1; }
.goal-card .head .target { font-size: .8rem; color: var(--text-muted); }
.progress-bar { height: 10px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.progress-bar .fill { height: 100%; background: linear-gradient(90deg, var(--primary), #7c93ff); border-radius: 999px; transition: width .3s ease; }
.progress-label { font-size: .76rem; color: var(--text-muted); display: flex; justify-content: space-between; }

.tx-row { display: flex; align-items: center; gap: .7rem; padding: .7rem 0; border-bottom: 1px solid var(--border); }
.tx-row:last-child { border-bottom: none; }
.tx-row .dot { width: 38px; height: 38px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 1.1rem; flex: none; }
.tx-row .dot.pos { background: var(--success-soft); }
.tx-row .dot.neg { background: var(--danger-soft); }
.tx-row .dot.payment { background: var(--primary-soft); }
.tx-row .info { flex: 1; min-width: 0; }
.tx-row .note { font-weight: 600; }
.tx-row .date { font-size: .74rem; color: var(--text-muted); }
.tx-row .amount { font-weight: 700; white-space: nowrap; }
.tx-row .amount.pos { color: var(--success); }
.tx-row .amount.neg { color: var(--danger); }
.tx-row .tx-edit, .tx-row .tx-delete { width: 28px; height: 28px; font-size: .8rem; flex: none; }

.kid-card { display: flex; align-items: center; gap: .8rem; cursor: pointer; }
.kid-card .profile-avatar { width: 52px; height: 52px; font-size: 1.5rem; }
.kid-card .info { flex: 1; }
.kid-card .name { font-weight: 700; }
.kid-card .balance { font-size: .85rem; color: var(--text-muted); }
.kid-card .chev { color: var(--text-muted); }

.approval-card { display: flex; flex-direction: column; gap: .7rem; }
.approval-card .head { display: flex; align-items: center; gap: .7rem; }
.approval-card .head .info { flex: 1; }
.approval-card .head .title { font-weight: 700; }
.approval-card .head .who { font-size: .8rem; color: var(--text-muted); }
.approval-card .actions { display: flex; gap: .6rem; }
.approval-card .actions .btn { flex: 1; }

.empty-state {
  text-align: center; padding: 2.4rem 1rem; color: var(--text-muted);
}
.empty-state .emoji { font-size: 2.2rem; display: block; margin-bottom: .5rem; }

/* ---------- fab ---------- */
.fab {
  position: fixed; right: 1.1rem; bottom: calc(var(--nav-h) + 20px); z-index: 15;
  width: 56px; height: 56px; border-radius: 50%; border: none; background: var(--primary);
  color: #fff; font-size: 1.6rem; box-shadow: var(--shadow); cursor: pointer;
}

/* ---------- modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(10, 14, 25, .5); z-index: 50;
  display: flex; align-items: flex-end; justify-content: center; padding: 0;
}
.modal {
  background: var(--surface); width: 100%; max-width: 480px; max-height: 90vh; overflow-y: auto;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0; padding: 1.4rem 1.3rem calc(1.4rem + env(safe-area-inset-bottom));
  box-shadow: var(--shadow);
}
.modal-header { display: flex; align-items: flex-start; justify-content: space-between; gap: .8rem; margin-bottom: 1rem; }
.modal .modal-title { font-size: 1.1rem; font-weight: 800; }
.modal-close { flex: none; }
.modal-actions { display: flex; gap: .7rem; margin-top: .6rem; }
.modal-actions .btn { flex: 1; }
.modal.modal-lg { max-width: 95vw; width: 95vw; max-height: 92vh; }
@media (min-width: 900px) {
  .modal.modal-lg { max-width: 900px; width: 90vw; }
}

.avatar-picker, .color-picker { display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: .9rem; }
.avatar-choice {
  width: 42px; height: 42px; border-radius: 12px; background: var(--surface-2); border: 2px solid transparent;
  font-size: 1.3rem; display: flex; align-items: center; justify-content: center; cursor: pointer;
}
.avatar-choice.active { border-color: var(--primary); }
.color-choice { width: 30px; height: 30px; border-radius: 50%; cursor: pointer; border: 2px solid transparent; }
.color-choice.active { border-color: var(--text); }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--nav-h) + 18px); transform: translate(-50%, 20px);
  background: var(--text); color: var(--bg); padding: .7rem 1.1rem; border-radius: 999px;
  font-size: .85rem; font-weight: 600; opacity: 0; pointer-events: none; transition: all .25s ease;
  z-index: 100; box-shadow: var(--shadow);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.top-actions { display: flex; gap: .6rem; }

/* ---------- desktop ---------- */
@media (min-width: 900px) {
  .shell { flex-direction: row; padding-bottom: 0; }
  .bottom-nav {
    position: sticky; top: 0; left: 0; height: 100vh; width: 240px; flex-direction: column;
    border-top: none; border-right: 1px solid var(--border); padding: 1.5rem 1rem; gap: .3rem;
  }
  .bottom-nav button {
    flex-direction: row; justify-content: flex-start; gap: .7rem; padding: .8rem .9rem;
    border-radius: var(--radius-sm); font-size: .9rem;
  }
  .bottom-nav button.active { background: var(--primary-soft); }
  .bottom-nav .badge { position: static; margin-left: auto; margin-top: 0; }
  .main-col { flex: 1; display: flex; flex-direction: column; min-width: 0; }
  .content { padding: 0 2rem 2.5rem; max-width: 760px; }
  .topbar { padding: 1.3rem 2rem; }
  .fab { right: 2.4rem; bottom: 2.4rem; }
  .modal-backdrop { align-items: center; }
  .modal { border-radius: var(--radius-lg); }
}

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: .9rem; }
@media (max-width: 480px) { .grid-2 { grid-template-columns: 1fr; } }

.muted { color: var(--text-muted); }
.center { text-align: center; }
.stack { display: flex; flex-direction: column; gap: .9rem; }
.row { display: flex; align-items: center; gap: .6rem; }
.spacer { flex: 1; }
.mt { margin-top: 1rem; }
.small { font-size: .8rem; }

/* ---------- print export ---------- */
.print-area { display: none; }
@media print {
  body * { visibility: hidden; }
  .print-area, .print-area * { visibility: visible; }
  .print-area {
    display: block; position: absolute; top: 0; left: 0; width: 100%;
    padding: 2rem; color: #000; background: #fff;
  }
  .print-area h1 { font-size: 1.3rem; margin: 0 0 .2rem; }
  .print-area table { width: 100%; border-collapse: collapse; margin-top: 1rem; }
  .print-area th, .print-area td { border-bottom: 1px solid #ccc; padding: .5rem; text-align: left; font-size: .9rem; }
  .print-area tfoot td { font-weight: 700; border-top: 2px solid #000; border-bottom: none; }
}
