:root {
  --green-50: #f0fdf4;
  --green-100: #dcfce7;
  --green-500: #22c55e;
  --green-600: #16a34a;
  --green-700: #15803d;
  --green-800: #166534;
  --red-500: #ef4444;
  --red-600: #dc2626;
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-400: #9ca3af;
  --gray-500: #6b7280;
  --gray-700: #374151;
  --gray-800: #1f2937;
  --gray-900: #111827;
  --amber-500: #f59e0b;
  --white: #ffffff;
  --radius: 0.5rem;
  font-family: "Nunito", system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  height: 100%;
}

body {
  background: var(--gray-50);
  color: var(--gray-900);
}

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

/* --- Topbar --- */

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1rem;
  background: var(--green-600);
  color: var(--white);
}

.topbar-inner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.topbar h1 {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 700;
}

.icon-btn {
  background: none;
  border: none;
  color: inherit;
  font-size: 1.3rem;
  cursor: pointer;
  padding: 0.25rem;
  line-height: 1;
}

.hidden {
  display: none !important;
}

/* --- Main content area --- */

#main-content {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
}

/* --- Cards --- */

.card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  padding: 1rem;
  margin-bottom: 0.75rem;
}

.card-kid {
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  transition: box-shadow 0.15s;
}

.card-kid:hover {
  box-shadow: 0 2px 8px rgba(0,0,0,0.12);
}

.card-kid .kid-name {
  font-size: 1.1rem;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.card-kid .kid-balance {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--green-700);
  flex-shrink: 0;
  margin-left: 0.75rem;
}

/* --- Balance display --- */

.balance-hero {
  text-align: center;
  padding: 1.5rem 0 1rem;
}

.balance-hero .label {
  font-size: 0.85rem;
  color: var(--gray-500);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.balance-hero .amount {
  font-size: 2.5rem;
  font-weight: 800;
  color: var(--green-700);
  margin: 0.25rem 0;
}

/* --- Buttons --- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  border: none;
  border-radius: var(--radius);
  padding: 0.6rem 1.2rem;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-primary {
  background: var(--green-600);
  color: var(--white);
}

.btn-primary:hover {
  background: var(--green-700);
}

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

.btn-danger:hover {
  background: var(--red-600);
}

.btn-outline {
  background: var(--white);
  color: var(--gray-700);
  border: 1px solid var(--gray-300);
}

.btn-outline:hover {
  background: var(--gray-100);
}

.btn-block {
  width: 100%;
}

.btn-group {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.btn-group .btn {
  flex: 1;
}

/* --- Forms --- */

.form-group {
  margin-bottom: 1rem;
}

.form-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--gray-700);
  margin-bottom: 0.3rem;
}

.form-group input,
.form-group select {
  width: 100%;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius);
  font-size: 1rem;
  color: var(--gray-900);
  background: var(--white);
}

.form-group input:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--green-500);
  box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.2);
}

.form-group input[type="number"] {
  font-variant-numeric: tabular-nums;
}

/* --- Transaction list --- */

.tx-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.tx-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--gray-100);
}

.tx-item:last-child {
  border-bottom: none;
}

.tx-item .tx-info .tx-type {
  font-weight: 600;
  font-size: 0.9rem;
  text-transform: capitalize;
}

.tx-item .tx-info .tx-desc {
  font-size: 0.8rem;
  color: var(--gray-500);
}

.tx-item .tx-info .tx-date {
  font-size: 0.75rem;
  color: var(--gray-400);
}

.tx-item .tx-amount {
  font-weight: 700;
  font-size: 1rem;
  white-space: nowrap;
}

.tx-amount.positive {
  color: var(--green-600);
}

.tx-amount.negative {
  color: var(--red-500);
}

/* --- Settings --- */

.settings-section {
  margin-bottom: 1.5rem;
}

.settings-section h2 {
  font-size: 1rem;
  margin: 0 0 0.75rem;
  color: var(--gray-700);
}

.radio-group {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.radio-group label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.95rem;
  cursor: pointer;
}

/* --- Empty states --- */

.empty {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--gray-400);
}

.empty p {
  margin: 0.5rem 0;
}

/* --- Section headers --- */

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
}

.section-header h2 {
  font-size: 1rem;
  margin: 0;
  color: var(--gray-700);
}

/* --- Misc --- */

.error {
  margin: 1rem;
  border: 1px solid var(--red-500);
  background: #fef2f2;
  color: var(--red-600);
  border-radius: var(--radius);
  padding: 0.8rem;
}

.text-center {
  text-align: center;
}

.mt-1 {
  margin-top: 1rem;
}

/* --- Interest callout --- */

.interest-callout {
  background: var(--green-50);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  margin-bottom: 1rem;
  font-size: 0.9rem;
  color: var(--green-800);
  line-height: 1.5;
}

.interest-callout p {
  margin: 0.25rem 0;
}

/* --- Chart --- */

.chart-container {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  padding: 0.75rem;
  margin-bottom: 1rem;
}

.chart-container svg {
  width: 100%;
  height: auto;
  display: block;
}

.chart-container .chart-label {
  font-size: 0.8rem;
  color: var(--gray-400);
  margin-bottom: 0.25rem;
}

.chart-legend {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.75rem;
  color: var(--gray-500);
  margin-top: 0.4rem;
}

.legend-line {
  display: inline-block;
  width: 1.25rem;
  height: 2px;
  vertical-align: middle;
}

.legend-line.legend-solid {
  background: #16a34a;
}

.legend-line.legend-dashed {
  background-image: repeating-linear-gradient(
    90deg,
    #16a34a 0,
    #16a34a 4px,
    transparent 4px,
    transparent 7px
  );
  background-color: transparent;
}

.legend-line.legend-savings {
  background-image: repeating-linear-gradient(
    90deg,
    #94a3b8 0,
    #94a3b8 4px,
    transparent 4px,
    transparent 7px
  );
  background-color: transparent;
}

/* --- Growth breakdown expando --- */

.growth-details {
  margin-top: 0.5rem;
  border-top: 1px solid var(--gray-200);
  padding-top: 0.5rem;
}

.growth-details summary {
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--green-600);
  user-select: none;
  padding: 0.25rem 0;
  list-style: none;
}

.growth-details summary::-webkit-details-marker {
  display: none;
}

.growth-details summary::before {
  content: "\25B6\FE0E";
  display: inline-block;
  margin-right: 0.4rem;
  font-size: 0.7rem;
  transition: transform 0.15s;
}

.growth-details[open] summary::before {
  transform: rotate(90deg);
}

.growth-details summary:hover {
  color: var(--green-700);
}

.growth-breakdown {
  margin-top: 0.5rem;
  overflow-x: auto;
}

.growth-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
}

.growth-table td {
  padding: 0.3rem 0.5rem;
  border-bottom: 1px solid var(--gray-100);
  white-space: nowrap;
}

.growth-table .right {
  text-align: right;
}

.growth-table .positive {
  color: var(--green-600);
}

.growth-start-row {
  font-weight: 600;
  color: var(--gray-500);
}

.growth-interest-row td {
  border-bottom-width: 2px;
  border-bottom-color: var(--gray-200);
}

.growth-total-row td {
  border-top: 2px solid var(--gray-300);
  border-bottom: none;
  padding-top: 0.5rem;
  font-weight: 600;
}

.growth-subtotal-row td {
  border-bottom: none;
  padding-top: 0.25rem;
  font-size: 0.78rem;
  color: var(--gray-500);
}

/* --- Action button pair (goal + contribution) --- */

.action-btn-pair {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.action-btn-pair .btn {
  width: 100%;
}

/* --- Contribution bar --- */

.contribution-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  padding: 0.75rem 1rem;
  font-size: 0.85rem;
  color: var(--gray-700);
}

.contribution-bar .contribution-clear {
  background: none;
  border: none;
  color: var(--green-600);
  cursor: pointer;
  font-size: 1.1rem;
  padding: 0 0.25rem;
  line-height: 1;
}

.contribution-bar .contribution-clear:hover {
  color: var(--green-800);
}

.contribution-form {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  padding: 1rem;
  margin-bottom: 1rem;
  min-width: 0;
}

.contribution-form label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--gray-700);
  margin-bottom: 0.4rem;
}

.contribution-input-row {
  display: flex;
  gap: 0.5rem;
}

.contribution-input-row input {
  flex: 1;
  min-width: 0;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius);
  font-size: 1rem;
}

.contribution-input-row input:focus {
  outline: none;
  border-color: var(--green-500);
  box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.2);
}

/* --- Goal thermometer --- */

.goal-section {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-bottom: 1rem;
  min-width: 0;
}

.goal-card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  padding: 1rem;
}

.goal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
}

.goal-header .goal-name {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--gray-800);
}

.goal-header .goal-clear {
  background: none;
  border: none;
  color: var(--gray-400);
  cursor: pointer;
  font-size: 1.1rem;
  padding: 0 0.25rem;
  line-height: 1;
}

.goal-header .goal-clear:hover {
  color: var(--gray-600);
}

.thermometer {
  height: 1.25rem;
  background: var(--gray-200);
  border-radius: 0.625rem;
  overflow: hidden;
  position: relative;
}

.thermometer-fill {
  height: 100%;
  background: var(--green-500);
  border-radius: 0.625rem;
  transition: width 0.4s ease;
  min-width: 0;
}

.goal-progress-text {
  font-size: 0.8rem;
  color: var(--gray-500);
  margin-top: 0.35rem;
  text-align: right;
}

.goal-complete-badge {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  color: var(--green-600);
  font-weight: 700;
  font-size: 1rem;
  margin-top: 0.5rem;
}

.goal-complete-badge .check {
  font-size: 1.2rem;
}

/* --- Confetti --- */

.confetti-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 9999;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding-top: 30%;
}

.confetti-particle {
  position: absolute;
  width: 10px;
  height: 10px;
  border-radius: 2px;
  animation: confetti-burst var(--duration, 1.8s) ease-out var(--delay, 0ms) forwards;
  opacity: 0;
}

@keyframes confetti-burst {
  0% {
    transform: translate(0, 0) rotate(0deg) scale(1);
    opacity: 1;
  }
  100% {
    transform: translate(var(--x, 0), var(--y, -200px)) rotate(var(--r, 360deg)) scale(0.3);
    opacity: 0;
  }
}

/* --- Settings kid list --- */

.kid-list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--gray-100);
}

.kid-list-item:last-child {
  border-bottom: none;
}

.kid-list-item .kid-list-info {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  flex: 1;
  min-width: 0;
}

.kid-list-item .kid-list-name {
  font-size: 0.95rem;
  font-weight: 600;
}

.kid-list-item .kid-interest-day {
  font-size: 0.8rem;
  color: var(--gray-500);
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-wrap: wrap;
}

.kid-list-item .interest-day-select {
  padding: 0.2rem 0.35rem;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius);
  background: var(--white);
  font-size: 0.8rem;
  color: var(--gray-800);
  cursor: pointer;
}

.kid-list-item .interest-day-select:focus {
  outline: none;
  border-color: var(--green-500);
  box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.2);
}

.kid-list-item .kid-edit-btn {
  background: none;
  border: none;
  color: var(--gray-400);
  cursor: pointer;
  font-size: 0.85rem;
  padding: 0.2rem 0.5rem;
}

.kid-list-item .kid-edit-btn:hover {
  color: var(--green-600);
}

.kid-edit-inline {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex: 1;
}

.kid-edit-inline input {
  flex: 1;
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius);
  font-size: 0.9rem;
}

.kid-edit-inline button {
  padding: 0.35rem 0.75rem;
  font-size: 0.8rem;
}

/* --- Responsive: Desktop --- */

@media (min-width: 600px) {
  #main-content {
    padding: 1.5rem 2rem;
  }

  .topbar {
    padding: 0.75rem 2rem;
  }

  .dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 0.75rem;
  }

  .dashboard-grid .card-kid {
    margin-bottom: 0;
  }

  .kid-detail-layout {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    align-items: start;
  }

  .kid-detail-main {
    min-width: 0;
  }

  .kid-detail-sidebar {
    min-width: 0;
  }

  .balance-hero .amount {
    font-size: 3rem;
  }

  .card-kid .kid-name {
    font-size: 1.15rem;
  }

  .card-kid .kid-balance {
    font-size: 1.35rem;
  }
}

/* --- Buckets: save / spend / give --- */

:root {
  --bucket-save: var(--green-600);
  --bucket-spend: #3b82f6;
  --bucket-give: #a855f7;
}

.kid-buckets {
  display: block;
  margin-top: 0.2rem;
  font-size: 0.75rem;
  color: var(--gray-500);
}

.bucket-cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.6rem;
  margin: 0 0 1rem;
}

.bucket-card {
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-top: 3px solid var(--gray-300);
  border-radius: var(--radius);
  padding: 0.6rem 0.5rem;
  text-align: center;
}

.bucket-card.bucket-save { border-top-color: var(--bucket-save); }
.bucket-card.bucket-spend { border-top-color: var(--bucket-spend); }
.bucket-card.bucket-give { border-top-color: var(--bucket-give); }

.bucket-card-label {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--gray-500);
}

.bucket-card-amount {
  font-size: 1.15rem;
  font-weight: 800;
  margin: 0.15rem 0;
}

.bucket-card-note {
  font-size: 0.7rem;
  color: var(--gray-400);
}

.bucket-chip {
  display: inline-block;
  margin-left: 0.35rem;
  padding: 0.05rem 0.35rem;
  border-radius: 999px;
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--white);
  background: var(--gray-400);
  vertical-align: middle;
}

.bucket-chip.bucket-save { background: var(--bucket-save); }
.bucket-chip.bucket-spend { background: var(--bucket-spend); }
.bucket-chip.bucket-give { background: var(--bucket-give); }

/* --- Deposit split preview --- */

.split-preview-inner {
  background: var(--green-50);
  border-radius: var(--radius);
  padding: 0.6rem 0.75rem;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

.split-preview-label {
  font-size: 0.75rem;
  color: var(--gray-500);
  margin-bottom: 0.25rem;
}

.split-parts {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.split-part::before {
  content: "";
  display: inline-block;
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 50%;
  margin-right: 0.3rem;
  background: var(--gray-400);
}

.split-part.split-save::before { background: var(--bucket-save); }
.split-part.split-spend::before { background: var(--bucket-spend); }
.split-part.split-give::before { background: var(--bucket-give); }

/* --- Settings: split editor --- */

.settings-help {
  font-size: 0.8rem;
  color: var(--gray-500);
  margin: 0 0 0.6rem;
}

.split-input-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.4rem;
}

.split-input-label {
  flex: 1;
  font-weight: 700;
}

.split-input-label.bucket-save { color: var(--bucket-save); }
.split-input-label.bucket-spend { color: var(--bucket-spend); }
.split-input-label.bucket-give { color: var(--bucket-give); }

.split-input {
  width: 5rem;
  text-align: right;
}

.split-pct {
  color: var(--gray-500);
}

.split-total {
  font-size: 0.85rem;
  color: var(--gray-500);
  margin-top: 0.4rem;
}

.split-total-invalid {
  color: var(--red-600);
  font-weight: 700;
}

/* --- Transfers between jars (deliberately low-key) --- */

.transfer-details {
  margin-top: 1.25rem;
  border-top: 1px solid var(--gray-200);
  padding-top: 0.6rem;
}

.transfer-details > summary {
  cursor: pointer;
  font-size: 0.8rem;
  color: var(--gray-400);
  list-style: none;
}

.transfer-details > summary::-webkit-details-marker {
  display: none;
}

.transfer-details > summary::before {
  content: "\2699";
  margin-right: 0.35rem;
}

.transfer-details > summary:hover {
  color: var(--gray-700);
}

.transfer-form {
  margin-top: 0.6rem;
}

.transfer-row {
  display: flex;
  align-items: flex-end;
  gap: 0.6rem;
  margin-bottom: 0.5rem;
}

.transfer-row label {
  flex: 1;
  font-size: 0.8rem;
  color: var(--gray-500);
}

.transfer-row select,
.transfer-row input {
  width: 100%;
}

.transfer-error {
  color: var(--red-600);
  font-size: 0.85rem;
  margin: 0.25rem 0 0;
}

@media (max-width: 480px) {
  .bucket-cards {
    gap: 0.4rem;
  }

  .bucket-card-amount {
    font-size: 1rem;
  }
}
