:root {
  color-scheme: light dark;
  --bg: #fafafa;
  --fg: #1a1a1a;
  --muted: #6b7280;
  --accent: #1a1a1a;
  --accent-fg: #ffffff;
  --border: #e5e7eb;
  --hint-bg: #fef3c7;
  --hint-fg: #78350f;
  --ok-bg: #d1fae5;
  --ok-fg: #065f46;
  --warn-bg: #fee2e2;
  --warn-fg: #991b1b;
  --partial-bg: #fef3c7;
  --partial-fg: #78350f;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f0f10;
    --fg: #f3f4f6;
    --muted: #9ca3af;
    --accent: #f3f4f6;
    --accent-fg: #0f0f10;
    --border: #27272a;
    --hint-bg: #422006;
    --hint-fg: #fbbf24;
    --ok-bg: #064e3b;
    --ok-fg: #a7f3d0;
    --warn-bg: #7f1d1d;
    --warn-fg: #fecaca;
    --partial-bg: #422006;
    --partial-fg: #fbbf24;
  }
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, system-ui, sans-serif;
  background: var(--bg);
  color: var(--fg);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.wrap { max-width: 480px; margin: 0 auto; padding: 32px 20px 64px; }

h1 { font-size: 28px; font-weight: 700; margin: 0 0 8px; letter-spacing: -0.01em; }
h2.section-title { font-size: 14px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 32px 0 12px; }

.subtitle { color: var(--muted); margin: 4px 0 24px; }
p { margin: 12px 0; }
a { color: var(--accent); }
em { font-style: normal; color: var(--muted); }
.muted { color: var(--muted); font-size: 14px; }

.stack { display: flex; flex-direction: column; gap: 12px; margin: 24px 0; }

label { font-size: 14px; font-weight: 600; color: var(--muted); }

input[type="email"],
input[type="text"],
input[type="number"],
textarea {
  font: inherit;
  min-height: 48px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--fg);
  width: 100%;
}
textarea { min-height: 80px; resize: vertical; }
input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

button, .btn-primary, .btn-secondary {
  font: inherit; font-weight: 600; min-height: 48px;
  padding: 12px 20px; border-radius: 8px; border: 1px solid transparent;
  cursor: pointer; width: 100%; text-align: center;
}
.btn-primary { background: var(--accent); color: var(--accent-fg); }
.btn-secondary { background: transparent; color: var(--fg); border-color: var(--border); }
.btn-link { display: block; text-decoration: none; }

.hint {
  background: var(--hint-bg); color: var(--hint-fg);
  border-radius: 8px; padding: 12px 14px; font-size: 14px; margin: 16px 0;
}

/* Parent-dashboard callout for pending requests */
.callout {
  display: flex; justify-content: space-between; align-items: center;
  background: var(--accent); color: var(--accent-fg);
  padding: 16px 18px; border-radius: 12px; text-decoration: none;
  margin: 16px 0; min-height: 56px;
}
.callout strong { font-size: 16px; }
.callout span:last-child { opacity: 0.85; font-size: 14px; }

/* Card list (kid links on dashboard) */
.card-list { display: flex; flex-direction: column; gap: 10px; }
.card {
  display: flex; justify-content: space-between; align-items: center;
  background: transparent; border: 1px solid var(--border);
  padding: 14px 16px; border-radius: 12px; text-decoration: none;
  color: var(--fg); min-height: 56px;
}
.card span:first-child { font-weight: 600; }

/* RTA banner on kid view */
.rta {
  display: flex; justify-content: space-between; align-items: baseline;
  background: var(--accent); color: var(--accent-fg);
  padding: 18px 20px; border-radius: 12px; margin: 16px 0 8px;
}
.rta-label { font-size: 14px; opacity: 0.85; }
.rta-amount { font-size: 28px; font-weight: 700; letter-spacing: -0.02em; }

/* Envelope cards */
.envelope-card {
  display: flex; flex-direction: column; gap: 10px;
  border: 1px solid var(--border); border-radius: 12px;
  padding: 16px 18px; min-height: 56px;
}
.envelope-row { display: flex; justify-content: space-between; align-items: center; }
.envelope-name { font-weight: 600; }
.envelope-amount { font-size: 18px; font-variant-numeric: tabular-nums; }

/* Inline assign form per envelope */
.assign-form {
  display: flex; gap: 8px; align-items: center;
  padding-top: 8px; border-top: 1px dashed var(--border);
}
.assign-form .dollar-wrap { flex: 1; }
.assign-input {
  min-height: 40px; padding: 8px 8px 8px 22px; width: 100%;
  font-variant-numeric: tabular-nums;
}
.assign-form .dollar-wrap::before {
  content: "$"; position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
  color: var(--muted); font-weight: 600;
}
.assign-btn { width: auto; padding: 8px 14px; min-height: 40px; font-size: 14px; }

/* History list on kid view */
.history { list-style: none; padding: 0; margin: 8px 0; display: flex; flex-direction: column; gap: 8px; }
.history-item { border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; }
.history-row { display: flex; justify-content: space-between; align-items: center; }
.history-reason, .history-note { margin-top: 4px; font-size: 13px; }
.amount { font-variant-numeric: tabular-nums; font-weight: 600; }

.status-pill {
  display: inline-block; padding: 2px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em;
}
.status-pending  { background: var(--hint-bg);    color: var(--hint-fg); }
.status-approved { background: var(--ok-bg);      color: var(--ok-fg); }
.status-partial  { background: var(--partial-bg); color: var(--partial-fg); }
.status-declined { background: var(--warn-bg);    color: var(--warn-fg); }
.status-withdrawn{ background: var(--border);     color: var(--muted); }

/* Ask form: envelope radio rows */
.envelope-radio, .decision-radio {
  border: 1px solid var(--border); border-radius: 12px; padding: 8px;
  display: flex; flex-direction: column; gap: 4px;
}
.envelope-radio legend { padding: 0 6px; font-size: 12px; color: var(--muted); }
.radio-row {
  display: flex; align-items: center; gap: 12px;
  padding: 12px; border-radius: 8px; min-height: 48px; cursor: pointer;
}
.radio-row input[type="radio"] { width: 20px; height: 20px; flex-shrink: 0; }
.radio-row .envelope-name { flex: 1; }

/* Dollar prefix wrap for amount input */
.dollar-wrap { position: relative; }
.dollar-prefix {
  position: absolute; left: 14px; top: 50%; transform: translateY(-50%);
  color: var(--muted); pointer-events: none; font-weight: 600;
}
.dollar-wrap input { padding-left: 28px; }

/* Approval queue */
.queue-item {
  border: 1px solid var(--border); border-radius: 12px;
  padding: 16px; margin: 16px 0;
  display: flex; flex-direction: column; gap: 12px;
}
.queue-head { display: flex; justify-content: space-between; align-items: baseline; }
.queue-reason { font-style: italic; color: var(--muted); margin: 0; }
.line-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.line-row {
  display: grid; grid-template-columns: 1fr auto auto; gap: 8px; align-items: center;
}
.line-name { font-weight: 600; }
.line-amount { font-variant-numeric: tabular-nums; color: var(--muted); }
.grant-input {
  width: 100px; min-height: 40px; padding: 8px 10px;
  text-align: right; font-variant-numeric: tabular-nums;
}

/* Admin / SimpleFIN onboarding */
.btn-danger {
  background: var(--warn-bg); color: var(--warn-fg);
  border-color: transparent; width: auto; padding: 8px 14px; min-height: 0;
  font-size: 14px;
}
.btn-secondary { width: auto; padding: 8px 14px; min-height: 0; font-size: 14px; }

.alert {
  background: var(--warn-bg); color: var(--warn-fg);
  padding: 12px 14px; border-radius: 8px; margin: 16px 0; font-size: 14px;
}
.alert ul { margin: 4px 0 0 16px; padding: 0; }

.tenant-block {
  margin: 24px 0; padding: 16px; border: 1px solid var(--border); border-radius: 12px;
}
.tenant-block h2 { font-size: 18px; margin: 0 0 8px; }

.bridge-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.bridge-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; gap: 12px;
}
.bridge-actions { display: flex; gap: 8px; }
.inline-form { display: inline-block; margin: 0; }

.hint-list { padding-left: 20px; color: var(--muted); font-size: 14px; line-height: 1.7; }
.hint-list li { margin: 4px 0; }

.sf-account {
  border: 1px solid var(--border); border-radius: 12px;
  padding: 12px 16px; margin: 16px 0; display: flex; flex-direction: column; gap: 8px;
}
.sf-account legend { font-size: 14px; padding: 0 6px; color: var(--muted); }
.sf-account legend strong { color: var(--fg); font-size: 16px; }
.indent { padding-left: 24px; display: flex; flex-direction: column; gap: 8px; font-size: 14px; }
.indent label { display: flex; flex-direction: column; gap: 4px; font-weight: 500; }
.indent input[type="checkbox"] { transform: translateY(1px); margin-right: 6px; }

.summary { list-style: none; padding: 0; margin: 16px 0; }
.summary li {
  padding: 10px 14px; background: var(--ok-bg); color: var(--ok-fg);
  border-radius: 8px; margin: 6px 0; font-weight: 500;
}

/* Envelope admin list */
.envelope-admin-list { list-style: none; padding: 0; margin: 16px 0; }
.envelope-group-header {
  font-size: 12px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--muted);
  margin: 16px 0 6px; padding: 0 4px;
}
.envelope-admin-row {
  border: 1px solid var(--border); border-radius: 10px;
  margin: 6px 0; padding: 0;
}
.envelope-admin-row.is-hidden { opacity: 0.55; }
.envelope-admin-row[draggable="true"] { cursor: grab; }
.envelope-admin-row[draggable="true"]:active { cursor: grabbing; }
.envelope-admin-row.is-dragging { opacity: 0.4; transform: scale(0.98); }
.envelope-admin-row details { padding: 12px 14px; }
.envelope-admin-row summary {
  cursor: pointer; list-style: none;
  display: grid; grid-template-columns: 1fr auto auto; gap: 12px;
  align-items: baseline;
}
.envelope-admin-row summary::-webkit-details-marker { display: none; }
.envelope-admin-name { font-weight: 600; }
.envelope-admin-owner { font-size: 13px; }
.envelope-admin-amount { font-variant-numeric: tabular-nums; font-size: 14px; }
.envelope-admin-controls {
  display: flex; flex-direction: column; gap: 10px;
  margin-top: 12px; padding-top: 12px; border-top: 1px dashed var(--border);
}
.envelope-admin-controls .inline-form {
  display: flex; gap: 8px; align-items: center;
}
.envelope-admin-controls input[type="text"],
.envelope-admin-controls select { flex: 1; min-height: 40px; }

/* Grant page */
.grant-card {
  border: 1px solid var(--border); border-radius: 12px;
  padding: 16px; margin: 16px 0;
  display: flex; flex-direction: column; gap: 12px;
}
.grant-card-head {
  display: flex; justify-content: space-between; align-items: center;
}
.grant-card-head h2 { font-size: 18px; margin: 0; }
.grant-mode-badge {
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.06em; padding: 4px 8px; border-radius: 999px;
}
.mode-autonomous { background: var(--ok-bg); color: var(--ok-fg); }
.mode-prescriptive { background: var(--partial-bg); color: var(--partial-fg); }

.grant-alloc-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.grant-alloc-row {
  display: grid; grid-template-columns: 1fr 120px; gap: 8px; align-items: center;
}
.grant-alloc-name { font-weight: 500; }
.grant-alloc-input { min-height: 40px; padding: 8px 8px 8px 22px; text-align: right; font-variant-numeric: tabular-nums; }
.grant-alloc-row .dollar-wrap::before {
  content: "$"; position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
  color: var(--muted); font-weight: 600;
}
.autonomy-toggle { margin-top: 8px; }

/* Alert dashboard */
.overspend-list { list-style: none; padding: 0; margin: 12px 0; display: flex; flex-direction: column; gap: 8px; }
.overspend-row {
  border: 1px solid var(--warn-bg); background: var(--warn-bg);
  color: var(--warn-fg); border-radius: 10px; padding: 12px 14px;
  display: flex; flex-direction: column; gap: 4px;
}
.overspend-head { font-size: 16px; }
.overspend-amount { font-size: 14px; display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; font-variant-numeric: tabular-nums; }
.overspend-amount .warn { font-weight: 600; }

.alert-history { list-style: none; padding: 0; margin: 12px 0; display: flex; flex-direction: column; gap: 6px; font-size: 13px; }
.alert-history-row {
  display: grid; grid-template-columns: auto 1fr auto; gap: 10px;
  padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px;
}

/* Tips Jar / shared visibility envelopes on the kid view */
.shared-jar {
  background: var(--hint-bg); color: var(--hint-fg);
  border-color: transparent;
}
.shared-jar .envelope-name { color: var(--hint-fg); }
.shared-jar .envelope-amount { color: var(--hint-fg); }

/* Manual accounts admin */
.account-list { list-style: none; padding: 0; margin: 16px 0; display: flex; flex-direction: column; gap: 8px; }
.account-row { border: 1px solid var(--border); border-radius: 10px; }
.account-link {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 16px; text-decoration: none; color: var(--fg); gap: 12px;
}
.account-head { display: flex; flex-direction: column; gap: 2px; }
.account-balance { font-variant-numeric: tabular-nums; font-size: 18px; font-weight: 600; }

.txn-list { list-style: none; padding: 0; margin: 12px 0; display: flex; flex-direction: column; gap: 4px; }
.txn-row {
  display: grid; grid-template-columns: auto 1fr auto; gap: 12px;
  padding: 8px 10px; border-bottom: 1px dashed var(--border); font-size: 14px;
}
.txn-payee { font-weight: 500; }
.txn-amount { font-variant-numeric: tabular-nums; font-weight: 600; }
.txn-amount.negative { color: var(--warn-fg); }
.txn-amount.positive { color: var(--ok-fg); }

/* Envelope link (clickable rows leading to detail) */
.envelope-link {
  display: flex; justify-content: space-between; align-items: center;
  text-decoration: none; color: inherit; padding: 4px 0;
}
.envelope-link:hover { text-decoration: none; }

/* Audit log */
.audit-log { list-style: none; padding: 0; margin: 12px 0; display: flex; flex-direction: column; gap: 6px; }
.audit-row {
  display: grid; grid-template-columns: 140px 1fr; gap: 12px;
  padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px;
  font-size: 14px;
}
.audit-when { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 13px; }
.audit-line { display: flex; gap: 8px; flex-wrap: wrap; }
.audit-actor { font-weight: 600; }
.audit-desc { color: var(--fg); font-variant-numeric: tabular-nums; }
.audit-note { color: var(--muted); font-style: italic; margin-top: 4px; font-size: 13px; }

/* Goal card on /envelope/<id> + inline progress on /admin/envelopes */
.goal-card {
  border: 1px solid var(--border); border-radius: 12px;
  padding: 14px 16px; margin: 16px 0;
  display: flex; flex-direction: column; gap: 8px;
}
.goal-head { display: flex; justify-content: space-between; align-items: baseline; }
.goal-bar {
  height: 8px; background: var(--border); border-radius: 4px; overflow: hidden;
}
.goal-bar-fill { height: 100%; transition: width 0.3s ease; }
.goal-fill-green { background: var(--ok-fg); }
.goal-fill-yellow { background: var(--partial-fg); }
.goal-fill-red { background: var(--warn-fg); }
.goal-numbers { font-variant-numeric: tabular-nums; font-size: 18px; font-weight: 600; display: flex; gap: 6px; align-items: baseline; }
.goal-card.goal-green { border-color: var(--ok-fg); }
.goal-card.goal-yellow { border-color: var(--partial-fg); }
.goal-card.goal-red { border-color: var(--warn-fg); }

/* Inline progress text on the admin envelopes page */
.goal-progress {
  margin: 6px 0; font-size: 13px;
  padding: 6px 10px; border-radius: 6px;
}
.goal-progress.goal-green { background: var(--ok-bg); color: var(--ok-fg); }
.goal-progress.goal-yellow { background: var(--partial-bg); color: var(--partial-fg); }
.goal-progress.goal-red { background: var(--warn-bg); color: var(--warn-fg); }

.goal-form { gap: 6px; flex-wrap: wrap; }
.goal-form select, .goal-form input { min-height: 36px; font-size: 13px; }

/* Invites */
.invite-list { list-style: none; padding: 0; margin: 16px 0; display: flex; flex-direction: column; gap: 8px; }
.invite-row {
  border: 1px solid var(--border); border-radius: 10px;
  padding: 12px 14px; display: flex; flex-direction: column; gap: 6px;
}
.invite-row.claimed { opacity: 0.7; border-color: var(--ok-fg); }
.invite-row.revoked { opacity: 0.5; border-color: var(--warn-fg); }
.invite-head { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.invite-role-pill {
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.06em; padding: 3px 8px; border-radius: 999px;
  background: var(--border); color: var(--fg);
}
.invite-meta { font-size: 13px; }

/* Recurring admin */
.recurring-list { list-style: none; padding: 0; margin: 16px 0; display: flex; flex-direction: column; gap: 8px; }
.recurring-row {
  border: 1px solid var(--border); border-radius: 10px;
  padding: 12px 14px; display: flex; flex-direction: column; gap: 6px;
}
.recurring-head { font-size: 16px; }
.recurring-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 4px; }

/* Transaction inbox */
.txn-inbox { list-style: none; padding: 0; margin: 12px 0; display: flex; flex-direction: column; gap: 10px; }
.txn-inbox-row {
  border: 1px solid var(--border); border-radius: 10px;
  padding: 12px 14px; display: flex; flex-direction: column; gap: 6px;
}
.txn-inbox-head {
  display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: baseline;
}
.txn-inbox-row .inline-form { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.txn-inbox-row select { flex: 1; min-height: 36px; }

/* Rules */
.rule-list { list-style: none; padding: 0; margin: 12px 0; display: flex; flex-direction: column; gap: 8px; }
.rule-row {
  border: 1px solid var(--border); border-radius: 10px;
  padding: 12px 14px; display: flex; flex-direction: column; gap: 6px;
}
.rule-row.is-disabled { opacity: 0.55; }
.rule-head { display: flex; gap: 12px; justify-content: space-between; align-items: baseline; }
.rule-conditions { font-size: 13px; }
.rule-conditions code { background: var(--border); padding: 1px 4px; border-radius: 3px; font-size: 12px; }
.rule-actions { display: flex; gap: 8px; }
