:root {
  --bg: #f6f7f9; --panel: #fff; --ink: #111827; --muted: #6b7280; --line: #e5e7eb;
  --accent: #0f766e; --accent-ink: #fff; --danger: #b91c1c; --warn-bg: #fef3c7; --warn-ink: #92400e;
  --ok-bg: #dcfce7; --ok-ink: #166534; --row-hover: #f9fafb; --credit: #15803d;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 1px solid var(--line); background: var(--panel); border-radius: 7px; padding: 6px 12px; }
button:hover { border-color: #cbd5e1; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button.danger { color: var(--danger); }
button.link { border: 0; background: none; padding: 0; color: var(--accent); }
button:disabled { opacity: .5; cursor: default; }
input, select, textarea { border: 1px solid var(--line); border-radius: 7px; padding: 6px 8px; background: var(--panel); min-width: 0; }
textarea { width: 100%; min-height: 60px; }
label.f { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); }
label.f > * { color: var(--ink); font-size: 14px; }

.shell { display: grid; grid-template-columns: 210px 1fr; min-height: 100vh; }
nav.side { background: #0b1f1d; color: #d1e7e4; padding: 18px 12px; display: flex; flex-direction: column; gap: 2px; }
nav.side .brand { font-weight: 700; font-size: 16px; color: #fff; padding: 0 10px 16px; display: flex; gap: 8px; align-items: center; }
nav.side a { color: inherit; text-decoration: none; padding: 8px 10px; border-radius: 7px; display: flex; justify-content: space-between; }
nav.side a.on, nav.side a:hover { background: #134e4a; color: #fff; }
nav.side .grow { flex: 1; }
nav.side .who { font-size: 12px; color: #8fb3ae; padding: 8px 10px; }
.badge { background: #f59e0b; color: #111; border-radius: 999px; font-size: 11px; padding: 0 7px; font-weight: 600; }
main { padding: 22px 26px; min-width: 0; }
h1 { font-size: 22px; margin: 0 0 16px; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
h1 .sp { flex: 1; }
h2 { font-size: 16px; margin: 22px 0 10px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 16px; }
.muted { color: var(--muted); }
.row { display: flex; gap: 10px; align-items: end; flex-wrap: wrap; }
.filters { margin-bottom: 12px; }
.stats { display: flex; gap: 18px; margin: 4px 0 12px; color: var(--muted); flex-wrap: wrap; }
.stats b { color: var(--ink); }

table { width: 100%; border-collapse: collapse; background: var(--panel); }
.tablewrap { border: 1px solid var(--line); border-radius: 10px; overflow-x: auto; background: var(--panel); }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 12px; color: var(--muted); font-weight: 600; background: #fafafa; position: sticky; top: 0; white-space: nowrap; }
tr:hover td { background: var(--row-hover); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
td.credit { color: var(--credit); }
td select { max-width: 160px; }
.merchant { font-weight: 600; }
.desc { font-size: 12px; color: var(--muted); max-width: 340px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pill { display: inline-block; font-size: 11px; border-radius: 999px; padding: 1px 8px; background: #eef2f7; color: #374151; white-space: nowrap; }
.pill.warn { background: var(--warn-bg); color: var(--warn-ink); }
.pill.ok { background: var(--ok-bg); color: var(--ok-ink); }
.pill.err { background: #fee2e2; color: var(--danger); }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }
.unset { border-color: #f59e0b; background: #fffbeb; }
.bulkbar { position: sticky; top: 0; z-index: 5; background: #ecfeff; border: 1px solid #99f6e4; border-radius: 10px; padding: 8px 12px; margin-bottom: 10px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

.cards { display: grid; gap: 14px; }
.card-item { display: grid; grid-template-columns: 1fr auto; gap: 10px; }
.acct { display: grid; grid-template-columns: 1.4fr 1fr 1fr auto; gap: 10px; align-items: center; padding: 8px 0; border-top: 1px solid var(--line); }

.report-grid td, .report-grid th { white-space: nowrap; }
.bar { height: 8px; border-radius: 4px; background: var(--accent); }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; }
.kpi .v { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.kpi .l { font-size: 12px; color: var(--muted); }

.modal-bg { position: fixed; inset: 0; background: rgba(15, 23, 42, .45); display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px; z-index: 50; overflow-y: auto; }
.modal { background: var(--panel); border-radius: 12px; width: 100%; max-width: 560px; padding: 20px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.modal h3 { margin: 0 0 12px; }
.modal .grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.modal .grid .full { grid-column: 1 / -1; }
.modal .actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; margin-top: 16px; }
.receipts { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 6px; }
.receipts .r { border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; font-size: 12px; display: flex; gap: 6px; align-items: center; }
.receipts img { width: 54px; height: 54px; object-fit: cover; border-radius: 5px; }

.login { max-width: 360px; margin: 14vh auto; }
.login .panel { display: grid; gap: 12px; }
.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: #111827; color: #fff; padding: 10px 16px; border-radius: 8px; z-index: 99; max-width: calc(100vw - 32px); }
.toast.err { background: var(--danger); }
.empty { padding: 40px; text-align: center; color: var(--muted); }
.swatch { width: 34px; height: 30px; padding: 2px; }

@media (max-width: 820px) {
  .shell { grid-template-columns: 1fr; }
  nav.side { flex-direction: row; overflow-x: auto; padding: 8px; gap: 4px; position: sticky; top: 0; z-index: 10; }
  nav.side .brand, nav.side .grow, nav.side .who { display: none; }
  nav.side a { white-space: nowrap; }
  main { padding: 16px; }
  .acct { grid-template-columns: 1fr 1fr; }
  .modal .grid { grid-template-columns: 1fr; }
  .desc { max-width: 180px; }
}
