/* Cashback Ledger — minimal, mobile-first, light + dark. */

:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface2: #eef0f3;
  --text: #1a2027;
  --muted: #5c6773;
  --border: #dde1e6;
  --accent: #0b6e4f;
  --accent-contrast: #ffffff;
  --credit: #0b7a3e;
  --debit: #b3261e;
  --pending: #9a6700;
  --danger: #b3261e;
  --shadow: 0 1px 3px rgba(15, 23, 42, .08), 0 4px 14px rgba(15, 23, 42, .06);
}
[data-theme="dark"] {
  --bg: #101418;
  --surface: #1a2027;
  --surface2: #232b33;
  --text: #e8ecf0;
  --muted: #98a4b0;
  --border: #2e3841;
  --accent: #38b58a;
  --accent-contrast: #0b1310;
  --credit: #4cc38a;
  --debit: #ff8a80;
  --pending: #e2b93b;
  --danger: #ff8a80;
  --shadow: 0 1px 3px rgba(0, 0, 0, .4);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #101418;
    --surface: #1a2027;
    --surface2: #232b33;
    --text: #e8ecf0;
    --muted: #98a4b0;
    --border: #2e3841;
    --accent: #38b58a;
    --accent-contrast: #0b1310;
    --credit: #4cc38a;
    --debit: #ff8a80;
    --pending: #e2b93b;
    --danger: #ff8a80;
    --shadow: 0 1px 3px rgba(0, 0, 0, .4);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
  padding-bottom: calc(64px + env(safe-area-inset-bottom));
}
a { color: inherit; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px;
  position: sticky; top: 0; z-index: 5;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 1.05rem; margin: 0; font-weight: 700; }
.topbar a { text-decoration: none; }

main { max-width: 720px; margin: 0 auto; padding: 16px; }

/* ---------- cards & stats ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px 16px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 14px; }
.stat { text-align: center; padding: 12px 6px; }
.stat .label { font-size: .72rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.stat .value { font-size: 1.15rem; font-weight: 700; margin-top: 2px; }
@media (max-width: 380px) { .stat .value { font-size: 1rem; } }

h2 { font-size: .95rem; margin: 18px 0 8px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }

/* ---------- friend list ---------- */
.friend-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 16px; margin-bottom: 8px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  text-decoration: none; box-shadow: var(--shadow);
}
.friend-row .name { font-weight: 600; }
.friend-row .sub { font-size: .8rem; color: var(--muted); }
.friend-row .amounts { text-align: right; }
.friend-row .avail { font-weight: 700; }

/* ---------- amounts ---------- */
.amt-credit { color: var(--credit); }
.amt-debit { color: var(--debit); }
.amt-pending { color: var(--pending); }
.amt-negative { color: var(--debit); font-weight: 700; }

.pill {
  display: inline-block; padding: 1px 8px; border-radius: 999px;
  font-size: .7rem; font-weight: 600; border: 1px solid var(--border);
  background: var(--surface2); color: var(--muted); vertical-align: middle;
}
.pill.pending { color: var(--pending); border-color: currentColor; }
.pill.credit { color: var(--credit); border-color: currentColor; }
.pill.debit { color: var(--debit); border-color: currentColor; }
.pill.voided { text-decoration: none; color: var(--muted); }

/* ---------- transaction rows ---------- */
.txn {
  display: flex; justify-content: space-between; gap: 10px;
  padding: 10px 0; border-bottom: 1px solid var(--border);
}
.txn:last-child { border-bottom: none; }
.txn .desc { font-weight: 500; overflow-wrap: anywhere; }
.txn .meta { font-size: .78rem; color: var(--muted); }
.txn .right { text-align: right; white-space: nowrap; }
.txn .running { font-size: .78rem; color: var(--muted); }
.txn.voided .desc, .txn.voided .right > div:first-child { text-decoration: line-through; opacity: .6; }
.txn-actions { margin-top: 4px; display: flex; gap: 6px; flex-wrap: wrap; }

/* ---------- buttons ---------- */
button { font: inherit; }
.btn {
  display: inline-block; border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface2); color: var(--text);
  padding: 8px 14px; cursor: pointer; font-weight: 600; font-size: .88rem;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-contrast); }
.btn.danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn.small { padding: 4px 10px; font-size: .78rem; border-radius: 8px; }
.btn:active { transform: translateY(1px); }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin: 10px 0; }

.action-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0;
}
.action-grid .btn { padding: 11px 0; text-align: center; white-space: nowrap; }

.hero-links { margin-top: 10px; display: flex; justify-content: center; gap: 18px; }
.link-btn {
  border: none; background: none; cursor: pointer; padding: 2px 4px;
  color: var(--muted); font-size: .82rem; font-weight: 600;
  text-decoration: underline; text-underline-offset: 3px;
}
.link-btn:hover { color: var(--text); }

.icon-btn {
  border: none; background: none; color: var(--text);
  font-size: 1.2rem; cursor: pointer; padding: 6px 10px; border-radius: 10px;
}
.icon-btn:hover { background: var(--surface2); }

/* ---------- bottom nav ---------- */
.bottomnav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 5;
  display: flex; justify-content: space-around;
  background: var(--surface); border-top: 1px solid var(--border);
  padding: 6px 0 calc(6px + env(safe-area-inset-bottom));
}
.bottomnav a {
  text-decoration: none; color: var(--muted); font-size: .8rem; font-weight: 600;
  padding: 8px 14px; border-radius: 10px;
}
.bottomnav a.active { color: var(--accent); background: var(--surface2); }
.badge {
  background: var(--pending); color: #fff; border-radius: 999px;
  font-size: .68rem; padding: 0 6px; margin-left: 2px;
}

/* ---------- forms & dialogs ---------- */
dialog {
  border: 1px solid var(--border); border-radius: 16px;
  background: var(--surface); color: var(--text);
  width: min(440px, calc(100vw - 32px));
  padding: 18px; margin: auto;
}
dialog::backdrop { background: rgba(0, 0, 0, .45); }
dialog h3 { margin: 0 0 12px; font-size: 1.05rem; }
form label { display: block; font-size: .8rem; font-weight: 600; color: var(--muted); margin: 10px 0 4px; }
input, select, textarea {
  width: 100%; padding: 9px 10px;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--bg); color: var(--text); font: inherit;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
.form-error { color: var(--danger); font-size: .85rem; margin: 10px 0 0; min-height: 1em; }
.form-warn { color: var(--pending); font-size: .8rem; margin: 6px 0 0; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
/* Bottom-align inputs in paired rows so a wrapped label doesn't stagger them. */
.grid2 .field { display: flex; flex-direction: column; justify-content: flex-end; }
.hint { font-size: .78rem; color: var(--muted); }

/* ---------- bulk confirm ---------- */
.bulk-list { max-height: 45vh; overflow-y: auto; }
.bulk-row {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 0; border-bottom: 1px solid var(--border);
}
.bulk-row:last-child { border-bottom: none; }
.bulk-row input[type="checkbox"] { width: 18px; height: 18px; flex: none; accent-color: var(--accent); }
.bulk-info { flex: 1; min-width: 0; }
.bulk-info .desc { font-weight: 500; font-size: .9rem; overflow-wrap: anywhere; }
.bulk-info .meta { font-size: .75rem; color: var(--muted); }
.bulk-amt { max-width: 96px; text-align: right; flex: none; }
.bulk-row.off { opacity: .45; }

/* ---------- filters ---------- */
.filters { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 12px; }
.filters .full { grid-column: 1 / -1; }

/* ---------- misc ---------- */
.empty { text-align: center; color: var(--muted); padding: 28px 10px; }
.muted { color: var(--muted); }
.small { font-size: .8rem; }
.balance-hero { text-align: center; padding: 18px 12px; }
.balance-hero .big { font-size: 1.9rem; font-weight: 800; }
.balance-hero .sub { color: var(--muted); font-size: .85rem; margin-top: 2px; }
details.archived summary { cursor: pointer; color: var(--muted); font-size: .85rem; padding: 6px 0; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(88px + env(safe-area-inset-bottom));
  background: var(--text); color: var(--bg);
  padding: 9px 16px; border-radius: 10px; font-size: .85rem; font-weight: 600;
  z-index: 20; box-shadow: var(--shadow); max-width: 90vw;
}
