:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --ink: #1f2933;
  --muted: #6b7280;
  --line: #e5e7eb;
  --accent: #2f6f4f;      /* ledger green */
  --accent-ink: #ffffff;
  --danger: #b4402a;
  --shadow: 0 1px 3px rgba(16, 24, 40, 0.08), 0 1px 2px rgba(16, 24, 40, 0.06);
  --radius: 10px;
  font-size: 15px;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
}
.mono { font-family: "SF Mono", ui-monospace, "Cascadia Code", Menlo, Consolas, monospace; font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.hidden { display: none !important; }

/* ── Top bar ─────────────────────────────────────────── */
.topbar {
  display: flex; align-items: center; gap: 24px;
  background: var(--panel); border-bottom: 1px solid var(--line);
  padding: 12px 22px; box-shadow: var(--shadow);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; }
.mark, .login-mark {
  display: inline-grid; place-items: center;
  width: 32px; height: 32px; border-radius: 8px;
  background: var(--accent); color: var(--accent-ink); font-weight: 700; font-size: 14px;
}
.brand-name { font-size: 16px; }
.entity-switch { display: flex; align-items: center; gap: 8px; }
.entity-switch label { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.entity-switch select {
  font-size: 15px; font-weight: 600; padding: 7px 10px;
  border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--ink);
}
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 14px; }

/* ── Tabs ─────────────────────────────────────────────── */
.tabs { display: flex; gap: 2px; padding: 0 18px; background: var(--panel); border-bottom: 1px solid var(--line); }
.tab {
  border: none; background: none; padding: 12px 16px; font-size: 14px; color: var(--muted);
  cursor: pointer; border-bottom: 2px solid transparent;
}
.tab:hover { color: var(--ink); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

/* ── Content ──────────────────────────────────────────── */
main { max-width: 1000px; margin: 0 auto; padding: 26px 22px 80px; }
h2 { margin: 4px 0 18px; font-size: 20px; }
.page { animation: fade .12s ease; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

/* ── Forms ────────────────────────────────────────────── */
.inline-form { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
.inline-form label { display: flex; gap: 6px; align-items: center; color: var(--muted); font-size: 14px; }
input, select {
  font: inherit; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--ink);
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
.num { text-align: right; }

.btn {
  font: inherit; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line);
  background: #fff; color: var(--ink); cursor: pointer;
}
.btn:hover { background: #f0f1f3; }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { background: #fff; color: var(--danger); border-color: var(--danger); }
.btn.danger:hover { background: var(--danger); color: #fff; }
.btn.link { border: none; background: none; color: var(--accent); padding: 6px 4px; }
.btn.link:hover { text-decoration: underline; background: none; }
.btn:disabled { opacity: .55; cursor: default; }

/* ── Tables ───────────────────────────────────────────── */
table.grid { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
table.grid th, table.grid td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--line); }
table.grid th { background: #fafbfc; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
table.grid th.num, table.grid td.num { text-align: right; }
table.grid tbody tr:last-child td { border-bottom: none; }
table.grid tbody tr.clickable { cursor: pointer; }
table.grid tbody tr.clickable:hover { background: #f6faf7; }
table.grid tfoot td { padding: 11px 14px; border-top: 2px solid var(--line); background: #fafbfc; }
.entry-grid input, .entry-grid select { width: 100%; }

/* ── Pills ────────────────────────────────────────────── */
.pill { display: inline-block; font-size: 11px; padding: 2px 8px; border-radius: 999px; background: #eef0f2; color: #4b5563; text-transform: capitalize; }
.pill-asset { background: #e6f0ff; color: #1d4ed8; }
.pill-liability { background: #fdece4; color: #b45309; }
.pill-equity { background: #ede7fb; color: #6d28d9; }
.pill-income { background: #e3f5ea; color: #1c7a45; }
.pill-expense { background: #fdeaea; color: #b91c1c; }
.pill-void { background: #fdeaea; color: #b4402a; }
.pill-reversal { background: #fff4d6; color: #92600a; }

.entry-meta { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 24px; margin: 6px 0 18px; color: var(--ink); }

.error-box { color: var(--danger); background: #fdecea; border: 1px solid #f3c6bd; padding: 12px 14px; border-radius: 8px; }

.import-box { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 16px; margin-bottom: 18px; box-shadow: var(--shadow); }
.import-box summary { cursor: pointer; font-weight: 600; color: var(--accent); }
.import-box .inline-form { margin-top: 12px; }
.import-box table.grid { margin-top: 8px; }

/* ── Toast ────────────────────────────────────────────── */
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); padding: 11px 18px; border-radius: 10px; color: #fff; box-shadow: var(--shadow); z-index: 50; }
.toast.ok { background: var(--accent); }
.toast.error { background: var(--danger); }

/* ── Login ────────────────────────────────────────────── */
.login-body { display: grid; place-items: center; min-height: 100vh; }
.login-card { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); padding: 34px 30px; width: 360px; max-width: 92vw; }
.login-brand { text-align: center; margin-bottom: 22px; }
.login-brand h1 { font-size: 20px; margin: 12px 0 2px; }
.login-mark { width: 44px; height: 44px; font-size: 17px; margin: 0 auto; }
.login-form { display: flex; flex-direction: column; gap: 14px; }
.login-form label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.login-form input[type=text] { font-size: 16px; }
#code { letter-spacing: .3em; text-align: center; font-size: 22px; }
.delivery-row { display: flex; gap: 16px; }
.radio { flex-direction: row !important; align-items: center; gap: 7px !important; color: var(--ink) !important; }
.login-msg { margin: 14px 0 0; text-align: center; font-size: 14px; min-height: 20px; }
.login-msg.error { color: var(--danger); }

@media (max-width: 620px) {
  .brand-name { display: none; }
  .entity-meta { grid-template-columns: 1fr; }
  main { padding: 18px 12px 70px; }
}
