:root {
  --bg: #f5f5f7;
  --card: #ffffff;
  --text: #1d1d1f;
  --muted: #6e6e73;
  --green: #1a8a3a;
  --red: #c4320a;
  --blue: #0a6cff;
  --line: #e3e3e6;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000; --card: #1c1c1e; --text: #f5f5f7; --muted: #8e8e93;
    --green: #30d158; --red: #ff453a; --blue: #0a84ff; --line: #2c2c2e;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  padding-bottom: calc(60px + env(safe-area-inset-bottom, 0px)); /* room for the fixed tab bar */
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", Segoe UI, Roboto, sans-serif;
}

/* Panel header: title + context action, one per tab */
.panel-head { display: flex; align-items: center; justify-content: space-between; margin: 18px 0 10px; }
.panel-head h2 { margin: 0; }

/* Bottom tab bar (app-like navigation) */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
  display: flex; background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.tabbar button {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 8px 4px 10px; border: 0; background: none; cursor: pointer;
  color: var(--muted); font-size: 11px; font-weight: 600; font-family: inherit;
}
.tabbar button .ti { width: 23px; height: 23px; display: block; }
.tabbar button.active { color: var(--blue); }

/* App-like list rows (accounts + transactions) */
.muted { color: var(--muted); }
.group-head, .day-head {
  font-size: 12px; font-weight: 700; letter-spacing: .03em; color: var(--muted);
  margin: 16px 2px 7px; text-transform: uppercase;
}
.day-head { position: sticky; top: 54px; background: var(--bg); padding: 4px 2px; z-index: 5; margin: 14px 0 6px; }
.group-head:first-child, .day-head:first-of-type { margin-top: 6px; }
.list { background: var(--card); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.row { display: flex; align-items: center; gap: 12px; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.row:last-child { border-bottom: none; }
.acct-row, .tx-row { cursor: pointer; }
.acct-row:hover, .tx-row:hover { background: color-mix(in srgb, var(--blue) 7%, transparent); }
.avatar {
  flex: 0 0 auto; width: 34px; height: 34px; border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; font-size: 15px;
}
.row-main { flex: 1; min-width: 0; }
.row-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-sub { color: var(--muted); font-size: 12px; margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-amt { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.row-amt.neg { color: var(--red); }
.row-amt.pos { color: var(--green); }
.row-amt.xfer { color: var(--blue); }
.row-amt.zero { color: var(--muted); }
.tx-future { opacity: .55; font-style: italic; }
header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--line);
  position: sticky; top: 0; background: var(--bg);
}
h1 { font-size: 20px; margin: 0; }
h2 { font-size: 16px; margin: 24px 0 10px; }
main { max-width: 480px; margin: 0 auto; padding: 8px 16px 40px; }

.status { color: var(--muted); }
.pending {
  background: color-mix(in srgb, var(--blue) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--blue) 35%, transparent);
  color: var(--text); border-radius: 10px; padding: 8px 12px; margin: 4px 0 8px; font-size: 13px;
}

.totals { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 14px; }
.total-pill {
  background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  padding: 8px 12px; font-weight: 600;
}

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; }
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px;
}
.card .name { font-weight: 600; }
.card .sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.card .bal { margin-top: 8px; font-size: 17px; font-weight: 600; }

table { width: 100%; border-collapse: collapse; background: var(--card); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line); }
th { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .02em; }
tr:last-child td { border-bottom: none; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

.amount.pos { color: var(--green); }
.amount.neg { color: var(--red); }
.amount.xfer { color: var(--blue); }

tr.tx-row { cursor: pointer; }
tr.tx-row:hover td { background: color-mix(in srgb, var(--blue) 8%, transparent); }
#add-form .actions .delete, #acct-form .actions .delete { background: var(--red); color: #fff; border-color: var(--red); }
.acct-card { cursor: pointer; }
.acct-card:hover { border-color: var(--blue); }

#acct-form { display: flex; flex-direction: column; gap: 10px; padding: 20px; }
#acct-form h2 { margin: 0 0 4px; }
#acct-form label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
#acct-form input, #acct-form select { font-size: 15px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--text); }
#acct-form .actions { display: flex; gap: 10px; margin-top: 8px; }
#acct-form .actions button { padding: 8px 16px; border-radius: 8px; font-weight: 600; cursor: pointer; border: 1px solid var(--line); background: var(--bg); color: var(--text); }
#acct-form .actions button[type=submit] { background: var(--blue); color: #fff; border-color: var(--blue); }

.mini-btn { font-size: 12px; padding: 3px 10px; border-radius: 6px; border: 1px solid var(--line); background: var(--bg); color: var(--blue); cursor: pointer; margin-left: 8px; vertical-align: middle; }
.small { font-size: 12px; }
/* Settings: Categories + Payees stacked full-width (the 480px column is too
   narrow for two side-by-side lists — names wrapped and buttons overflowed). */
#manage-section { display: block; margin-top: 2px; }
.manage-col { margin-bottom: 24px; }
.mlist { background: var(--card); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.mrow { display: flex; align-items: center; gap: 10px; padding: 9px 8px 9px 14px; border-bottom: 1px solid var(--line); }
.mrow:last-child { border-bottom: none; }
.mrow.muted { padding: 14px; justify-content: center; }
.mname { flex: 1; min-width: 0; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mrow.sub { padding-left: 32px; }
.mrow.sub .mname { color: var(--muted); font-weight: 400; }
.mrow.sub .mname::before { content: "↳"; color: var(--line); margin-right: 6px; }
.mact { flex: 0 0 auto; display: flex; align-items: center; gap: 2px; }
.iconbtn {
  width: 30px; height: 30px; flex: 0 0 auto; padding: 0; border: 0; background: none;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 7px; color: var(--muted); cursor: pointer;
}
.iconbtn svg { width: 17px; height: 17px; display: block; }
.iconbtn:hover { background: color-mix(in srgb, var(--blue) 12%, transparent); color: var(--blue); }
.iconbtn.danger:hover { background: color-mix(in srgb, var(--red) 12%, transparent); color: var(--red); }

#apple-sign-in-button, #apple-sign-out-button { cursor: pointer; }

#auth { display: flex; align-items: center; gap: 12px; }
.add-btn {
  background: var(--blue); color: #fff; border: 0; border-radius: 8px;
  padding: 8px 14px; font-weight: 600; font-size: 14px; cursor: pointer;
}
.add-btn:hover { filter: brightness(1.05); }

dialog {
  border: 1px solid var(--line); border-radius: 14px; padding: 0;
  background: var(--card); color: var(--text); max-width: 420px; width: 92%;
}
dialog::backdrop { background: rgba(0,0,0,.4); }
#add-form { display: flex; flex-direction: column; gap: 10px; padding: 20px; }
#add-form h2 { margin: 0 0 4px; }
#add-form label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
#add-form input, #add-form select {
  font-size: 15px; padding: 8px 10px; border: 1px solid var(--line);
  border-radius: 8px; background: var(--bg); color: var(--text);
}
#add-form .actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 8px; }
#add-form .actions button {
  padding: 8px 16px; border-radius: 8px; font-weight: 600; cursor: pointer; border: 1px solid var(--line);
  background: var(--bg); color: var(--text);
}
#add-form .actions button[type=submit] { background: var(--blue); color: #fff; border-color: var(--blue); }
