:root {
  --bg: #0f1419;
  --surface: #1a2332;
  --border: #2d3a4d;
  --text: #e8edf4;
  --muted: #8b9cb3;
  --credit: #50c878;
  --debit: #e06c75;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

a { color: inherit; text-decoration: none; }

header {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

header h1 { margin: 0; font-size: 1.25rem; }

nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

nav a {
  color: var(--muted);
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
}

nav a.active, nav a:hover { color: var(--text); background: var(--bg); }

@media (min-width: 769px) {
  header {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.5rem;
  }

  nav {
    border-top: none;
    padding-top: 0;
  }
}

main { max-width: 1100px; margin: 0 auto; padding: 1.5rem; }

.grid {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 1.5rem;
}

@media (max-width: 768px) {
  .grid { grid-template-columns: 1fr; }
}

.dashboard-grid {
  display: grid;
  grid-template-columns: 1fr 320px;
  grid-template-areas: "main form";
  gap: 1.5rem;
  align-items: start;
}

#dashboard-body {
  grid-area: main;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.form-panel {
  grid-area: form;
}

.recent-panel h3 {
  margin-top: 0;
}

@media (max-width: 768px) {
  .dashboard-grid {
    display: flex;
    flex-direction: column;
    align-items: stretch;
  }

  #dashboard-body {
    display: contents;
  }

  .balances-panel { order: 1; }
  .form-panel { order: 2; }
  .recent-panel { order: 3; }
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.25rem;
}

.panel h2, .panel h3 { margin-top: 0; }

.balances {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

.balance-card {
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: 6px;
  padding: 0.75rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.balance-card .name { font-weight: 600; }
.balance-card .amount { font-size: 1.25rem; font-variant-numeric: tabular-nums; }

.txn-form, .filter-form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.875rem;
  color: var(--muted);
}

input, select, button {
  font: inherit;
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}

button {
  cursor: pointer;
  background: #4a90d9;
  border-color: #4a90d9;
  font-weight: 600;
}

button:hover { filter: brightness(1.1); }

.txn-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.txn-table th, .txn-table td {
  text-align: left;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--border);
}

.txn-table th { color: var(--muted); font-weight: 500; }

.txn-row { cursor: pointer; }

.txn-row.selected {
  background: color-mix(in srgb, #4a90d9 18%, var(--surface));
}

.txn-row:focus-visible {
  outline: 2px solid #4a90d9;
  outline-offset: -2px;
}

.txn-deleted td {
  color: var(--muted);
}

.txn-deleted td.credit,
.txn-deleted td.debit {
  text-decoration: line-through;
}

.txn-deleted-badge {
  display: inline-block;
  margin-left: 0.35rem;
  padding: 0.1rem 0.4rem;
  border-radius: 999px;
  font-size: 0.75rem;
  color: var(--debit);
  border: 1px solid var(--debit);
}

.txn-actions-row td {
  background: var(--bg);
  padding: 0.75rem;
}

.txn-panel {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.txn-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.txn-edit-form {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: flex-end;
}

.txn-edit-form label {
  min-width: 8rem;
  flex: 1;
}

.txn-edit-actions {
  display: flex;
  gap: 0.5rem;
}

.txn-events {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  font-size: 0.85rem;
}

.txn-events li {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 0.75rem;
  align-items: center;
  padding: 0.35rem 0;
  border-bottom: 1px solid var(--border);
}

.txn-events li:last-child { border-bottom: none; }

.txn-event-action {
  font-weight: 600;
  text-transform: capitalize;
  min-width: 4.5rem;
}

.credit { color: var(--credit); }
.debit { color: var(--debit); }

.pill {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.8rem;
  background: color-mix(in srgb, var(--accent) 20%, transparent);
  border: 1px solid var(--accent);
}

.muted { color: var(--muted); }

.hint {
  font-size: 0.75rem;
  color: var(--muted);
}

.multi-toggle {
  flex-direction: row;
  align-items: center;
  gap: 0.5rem;
  color: var(--text);
  font-size: 0.875rem;
}

.multi-toggle input {
  width: auto;
  margin: 0;
}

.form-error {
  margin: 0 0 0.75rem;
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
  background: color-mix(in srgb, var(--debit) 15%, transparent);
  border: 1px solid var(--debit);
  color: var(--debit);
  font-size: 0.875rem;
}

.child-multiselect {
  height: 2.5rem;
  overflow: hidden;
}

.child-multiselect:focus {
  height: auto;
  min-height: 2.5rem;
}

.pager {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  margin-top: 1rem;
  font-size: 0.875rem;
}

.pager-disabled {
  color: var(--muted);
}

.pager-status {
  color: var(--muted);
}

.allowance-page {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.allowance-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.allowance-header h2 { margin: 0; }

.allowance-table td:last-child { text-align: right; }

.btn-secondary {
  background: var(--bg);
  border-color: var(--border);
  font-weight: 500;
}

.btn-link {
  background: none;
  border: none;
  padding: 0;
  color: #4a90d9;
  font-weight: 500;
}

.edit-dialog {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.25rem;
  background: var(--surface);
  color: var(--text);
  max-width: 400px;
}

.edit-dialog::backdrop {
  background: rgba(0, 0, 0, 0.5);
}

.edit-dialog h3 { margin-top: 0; }

.dialog-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.auth-card {
  width: 100%;
  max-width: 400px;
  padding: 2rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  text-align: center;
}

.auth-card h1 {
  margin: 0 0 0.5rem;
  font-size: 1.5rem;
}

.auth-subtitle {
  color: var(--muted);
  margin: 0 0 1.5rem;
}

.auth-error {
  color: var(--debit);
  margin: 0;
}

.auth-providers {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.btn-google {
  display: inline-block;
  padding: 0.75rem 1.25rem;
  background: #fff;
  color: #1f1f1f;
  border-radius: 6px;
  font-weight: 500;
}

.btn-google:hover {
  background: #f0f0f0;
}

.btn-microsoft {
  display: inline-block;
  padding: 0.75rem 1.25rem;
  background: #2f2f2f;
  color: #fff;
  border-radius: 6px;
  font-weight: 500;
}

.btn-microsoft:hover {
  background: #1a1a1a;
}

.auth-card-wide {
  max-width: 42rem;
}

.preview-section {
  margin-top: 1.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
  text-align: left;
}

.preview-section:first-of-type {
  margin-top: 1rem;
  padding-top: 0;
  border-top: none;
}

.preview-section h2 {
  margin: 0 0 0.35rem;
  font-size: 1.15rem;
}

.preview-section > p {
  margin: 0 0 0.75rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.preview-options {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  text-align: left;
}

.preview-option {
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.preview-option h2,
.preview-option h3 {
  margin: 0 0 0.35rem;
  font-size: 1.1rem;
}

.preview-option p {
  margin: 0 0 0.75rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.child-edit {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  margin: 0.75rem 0;
}

.child-edit-name {
  flex: 1;
  min-width: 8rem;
}

.onboarding-children {
  margin: 1.25rem 0;
}

.onboarding-children h3 {
  margin: 0 0 0.35rem;
}

.onboarding-children-help {
  margin: 0 0 0.75rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.onboarding-child-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: flex-end;
  margin-bottom: 0.75rem;
}

.onboarding-child-row label {
  flex: 1 1 10rem;
  margin: 0;
}

#add-child-row {
  margin-top: 0.25rem;
}

.invite-url code {
  word-break: break-all;
}

.settings-page h2 {
  margin: 0 0 1rem;
}

.settings-page {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.settings-page .panel {
  padding: 1.5rem;
}

.settings-list {
  margin: 0 0 1rem;
}

.settings-row {
  display: flex;
  gap: 1rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
}

.settings-row:last-child {
  border-bottom: none;
}

.settings-list dt {
  flex: 0 0 5rem;
  margin: 0;
  color: var(--muted);
  font-size: 0.875rem;
}

.settings-list dd {
  margin: 0;
  min-width: 0;
  word-break: break-word;
}

.build-version {
  font-size: 0.875rem;
  color: var(--muted);
  font-family: ui-monospace, monospace;
  letter-spacing: -0.02em;
}

.add-child-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.add-child-name {
  flex: 1;
  min-width: 0;
}

.archived-child-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
}

.archived-child-row:last-child {
  border-bottom: none;
}

.archived-child-actions {
  display: flex;
  gap: 0.5rem;
  margin: 0;
}

.btn-danger {
  background: color-mix(in srgb, var(--debit) 20%, var(--surface));
  border: 1px solid var(--debit);
  color: var(--debit);
  border-radius: 6px;
  padding: 0.5rem 0.75rem;
  cursor: pointer;
  font: inherit;
}

.btn-danger:hover {
  background: color-mix(in srgb, var(--debit) 30%, var(--surface));
}

.color-picker {
  position: relative;
  flex-shrink: 0;
}

.color-picker-trigger {
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 50%;
  border: 2px solid var(--border);
  cursor: pointer;
  padding: 0;
  flex-shrink: 0;
}

.color-picker-trigger:hover {
  border-color: var(--muted);
}

.color-picker-popover {
  position: absolute;
  top: calc(100% + 0.35rem);
  right: 0;
  z-index: 20;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem;
  min-width: 11rem;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
}

.color-picker-palette {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.color-swatch {
  width: 1.75rem;
  height: 1.75rem;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  padding: 0;
}

.color-swatch.selected {
  border-color: var(--text);
  box-shadow: 0 0 0 2px var(--surface);
}

.color-picker-custom {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.875rem;
  color: var(--muted);
}

.color-picker-custom input[type="color"] {
  width: 2rem;
  height: 2rem;
  padding: 0;
  border: none;
  background: none;
  cursor: pointer;
}

.onboarding-child-row {
  display: flex;
  align-items: flex-end;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.onboarding-child-row label:first-child {
  flex: 1;
}

.auth-footer {
  margin: 1.5rem 0 0;
  font-size: 0.875rem;
  color: var(--muted);
}

.auth-footer a {
  text-decoration: underline;
}

.privacy-copy {
  text-align: left;
  color: var(--text);
}

.privacy-copy a,
.beta-ack a {
  text-decoration: underline;
}

.beta-ack {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  margin: 1rem 0;
  text-align: left;
}

.beta-ack input {
  width: auto;
  margin-top: 0.3rem;
}

.feedback-form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.feedback-form textarea {
  width: 100%;
  resize: vertical;
}

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

.feedback-inbox li {
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--border);
}

.feedback-inbox li:last-child {
  border-bottom: none;
}

.feedback-meta {
  color: var(--muted);
  font-size: 0.875rem;
  margin: 0 0 0.25rem;
}

