/* Medium Ledger — clean-fintech design system.
   Warm paper surfaces, one wine-plum accent, all figures in IBM Plex Mono (receipt/bank-tape
   motif). Green/red/amber are reserved for money semantics. No build step. */

:root {
  --paper: #fafaf8;
  --panel: #ffffff;
  --ink: #24222b;
  --muted: #6e6a76;
  --faint: #99949f;
  --line: #e7e5ec;
  --line-soft: #f0eef4;
  --accent: #7a2e5a;
  --accent-ink: #632548;
  --accent-soft: #f7eef4;
  --pos: #1b7a46;
  --pos-soft: #e9f5ee;
  --neg: #c0303c;
  --neg-soft: #fbeef0;
  --warn: #9a6a00;
  --warn-soft: #fdf6e3;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(36, 34, 43, .05), 0 4px 16px rgba(36, 34, 43, .04);
  --sans: "IBM Plex Sans", "Segoe UI", system-ui, -apple-system, sans-serif;
  --mono: "IBM Plex Mono", "Cascadia Mono", Consolas, monospace;
}

* { box-sizing: border-box; }
html { height: 100%; }
body {
  margin: 0; min-height: 100%;
  background: var(--paper); color: var(--ink);
  font: 14px/1.55 var(--sans);
  -webkit-font-smoothing: antialiased;
}
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}

/* ---------- app shell ---------- */
.app { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; min-height: 100dvh; }

.side {
  position: sticky; top: 0; height: 100vh; height: 100dvh;
  display: flex; flex-direction: column;
  background: var(--panel); border-right: 1px solid var(--line);
  padding: 20px 14px 14px;
}
.brand {
  display: block; text-decoration: none; color: var(--ink);
  font: 600 15px/1.2 var(--mono); letter-spacing: .12em; text-transform: uppercase;
  padding: 4px 10px 18px;
}
.brand span { display: block; color: var(--accent); font-size: 11px; letter-spacing: .3em; }
.side nav { flex: 1; overflow-y: auto; }
.navlabel {
  margin: 14px 10px 4px; font-size: 10.5px; font-weight: 600;
  letter-spacing: .14em; text-transform: uppercase; color: var(--faint);
}
.side nav a {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 7px 10px; margin: 1px 0; border-radius: 7px;
  color: var(--ink); text-decoration: none; font-size: 13.5px;
  transition: background .15s;
}
.side nav a:hover { background: var(--line-soft); }
.side nav a.active { background: var(--accent-soft); color: var(--accent-ink); font-weight: 600; }
.side nav a .count {
  font: 500 11px var(--mono); background: var(--accent); color: #fff;
  border-radius: 999px; padding: 0 7px; line-height: 18px;
}
.side-foot {
  border-top: 1px solid var(--line); padding-top: 10px; margin-top: 10px;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.side-foot .who { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; }
.side-foot button {
  background: none; border: 1px solid var(--line); color: var(--muted);
  border-radius: 7px; padding: 4px 10px; font: 500 12px var(--sans); cursor: pointer;
}
.side-foot button:hover { color: var(--neg); border-color: var(--neg); }
.side-foot-link { font-size: 12px; color: var(--muted); text-decoration: none; white-space: nowrap; }
.side-foot-link:hover { color: var(--fg); }

.narrow-form { max-width: 380px; display: flex; flex-direction: column; gap: 14px; }
.narrow-form label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); }
.narrow-form .hint { margin: 0; font-size: 12.5px; color: var(--muted); line-height: 1.5; }

.main-wrap { min-width: 0; display: flex; flex-direction: column; }
main { flex: 1; width: 100%; max-width: 1200px; margin: 0 auto; padding: 28px 32px 16px; }
footer {
  width: 100%; max-width: 1200px; margin: 0 auto; padding: 8px 32px 28px;
  color: var(--faint); font-size: 12px;
}

/* mobile shell: sidebar becomes a top bar with a CSS-only menu */
#menu-toggle, .menu-btn { display: none; }
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .side { position: static; height: auto; padding: 10px 16px; }
  .brand { padding: 4px 0; }
  .brand span { display: inline; margin-left: 8px; }
  .menu-btn {
    display: block; position: absolute; top: 12px; right: 16px;
    padding: 6px 12px; border: 1px solid var(--line); border-radius: 7px;
    font-size: 13px; cursor: pointer; user-select: none; background: var(--panel);
  }
  .side { position: relative; }
  .side nav, .side-foot { display: none; }
  #menu-toggle:checked ~ nav, #menu-toggle:checked ~ .side-foot { display: block; }
  #menu-toggle:checked ~ .side-foot { display: flex; }
  main, footer { padding-left: 16px; padding-right: 16px; }
}

/* ---------- type ---------- */
h1 { font-size: 21px; font-weight: 600; letter-spacing: -.01em; margin: 0 0 4px; }
h2 {
  font-size: 11.5px; font-weight: 600; letter-spacing: .12em; text-transform: uppercase;
  color: var(--muted); margin: 30px 0 8px;
}
.sub { color: var(--muted); margin: 0 0 20px; font-size: 13.5px; }
.muted { color: var(--muted); }
.empty { color: var(--muted); font-style: italic; }
.range { color: var(--muted); font-size: 12px; }

/* every figure reads like the bank tape */
.num, .code, td.num, .card .value {
  font-family: var(--mono); font-size: 12.5px;
  font-variant-numeric: tabular-nums;
}
.num { text-align: right; white-space: nowrap; }
.code { color: var(--muted); white-space: nowrap; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }

/* ---------- cards ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; }
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: var(--shadow);
}
.card .label {
  color: var(--muted); font-size: 11px; font-weight: 600;
  letter-spacing: .08em; text-transform: uppercase;
}
.card .value { font-size: 22px; font-weight: 500; margin-top: 6px; }
.card .drill { display: inline-block; margin-top: 8px; font-size: 12px; }

/* ---------- panels & tables ---------- */
.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden; box-shadow: var(--shadow);
}
table { width: 100%; border-collapse: collapse; }
th, td { padding: 8px 14px; text-align: left; border-bottom: 1px solid var(--line-soft); }
th {
  background: #fcfcfb; color: var(--muted); font-weight: 600; font-size: 10.5px;
  text-transform: uppercase; letter-spacing: .1em;
}
tbody tr { transition: background .15s; }
tbody tr:hover { background: #fbfafc; }
tr:last-child td { border-bottom: none; }
.header-row td { font-weight: 600; }
.subtotal-row td { font-weight: 600; border-top: 1px solid var(--line); }
.total-row td { font-weight: 700; border-top: 2px solid var(--line); background: #fcfcfb; }
td a, .panel a { color: var(--accent); text-decoration: none; }
td a:hover, .panel a:hover { text-decoration: underline; }

tr.match-matched td { background: var(--pos-soft); }
tr.match-partial td { background: var(--warn-soft); }
tr.match-unmatched td { background: var(--neg-soft); }
.balanced { color: var(--pos); font-weight: 600; }
.unbalanced { color: var(--neg); font-weight: 700; }

/* ---------- buttons ---------- */
button, a.btn {
  display: inline-block; background: var(--accent); color: #fff; border: 0;
  border-radius: 7px; padding: 7px 14px; font: 500 13px var(--sans);
  cursor: pointer; text-decoration: none; transition: background .15s;
}
button:hover, a.btn:hover { background: var(--accent-ink); text-decoration: none; }
button.secondary, a.btn.secondary {
  background: var(--panel); color: var(--ink); border: 1px solid var(--line);
}
button.secondary:hover, a.btn.secondary:hover { background: var(--line-soft); }
button.ok { background: var(--pos); }
button.ok:hover { background: #14603a; }
button.danger { background: var(--panel); color: var(--neg); border: 1px solid var(--line); }
button.danger:hover { background: var(--neg-soft); border-color: var(--neg); }
button:disabled { opacity: .45; cursor: not-allowed; }

/* ---------- pills ---------- */
.pill {
  display: inline-block; padding: 1px 9px; border-radius: 999px;
  font-size: 11.5px; font-weight: 500; background: var(--line-soft); color: var(--muted);
}
.pill.ok { background: var(--pos-soft); color: var(--pos); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.void, .pill.bad { background: var(--neg-soft); color: var(--neg); }
.pill.accent { background: var(--accent-soft); color: var(--accent-ink); }
.sub.warn { color: var(--warn); }

/* ---------- forms & filters ---------- */
input[type="text"], input[type="date"], input[type="password"], input[type="number"],
input:not([type]), select, textarea {
  padding: 6px 9px; border: 1px solid var(--line); border-radius: 7px;
  font: inherit; background: var(--panel); color: var(--ink);
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); outline: none; }
form.filters, .addform {
  display: flex; gap: 12px; align-items: end; flex-wrap: wrap; margin: 0 0 16px;
}
form.filters label, .addform label {
  display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted);
}
.addform input.n, form.filters input.n { width: 90px; text-align: right; font-family: var(--mono); }

.flash {
  background: var(--pos-soft); color: var(--pos); border: 1px solid #bfe0cc;
  border-radius: 8px; padding: 9px 14px; margin: 0 0 16px; font-size: 13px;
}
.flash.error { background: var(--neg-soft); color: var(--neg); border-color: #ecc3c8; }

/* Feed health. Deliberately louder than a flash: it persists across every page until fixed,
   because the failure it reports is one nobody noticed for weeks. */
.feed-alert {
  display: flex; flex-direction: column; gap: 3px;
  background: var(--warn-soft, #fff6e5); color: var(--warn, #8a5a00);
  border: 1px solid #f0d9a8; border-left: 4px solid var(--warn, #d99500);
  border-radius: 8px; padding: 11px 15px; margin: 0 0 16px; font-size: 13px;
}
.feed-alert.stale { background: var(--neg-soft); color: var(--neg); border-color: #ecc3c8; border-left-color: var(--neg); }
.feed-alert .detail { font-size: 12px; opacity: .85; }
.feed-alert code { font: 12px/1.4 var(--mono, monospace); }

.alertbox {
  background: var(--warn-soft); border: 2px solid var(--warn); border-radius: 8px;
  padding: 12px 16px; margin: 0 0 18px; font-size: 13px; color: var(--warn);
}
.alertbox table { margin-top: 10px; background: #fff; border-radius: 6px; }
.alertbox table th, .alertbox table td { color: var(--ink); }

.addbox {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 16px; margin: 0 0 16px;
}
.addbox summary { cursor: pointer; font-weight: 600; font-size: 13.5px; }
.addform { margin: 14px 0 4px; }

.pager { display: flex; gap: 12px; align-items: center; margin-top: 14px; }

/* ---------- tabs (workbench, forms) ---------- */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 12px; }
.tabs button {
  background: none; color: var(--muted); border: 0; border-bottom: 2px solid transparent;
  border-radius: 0; padding: 7px 12px; font-weight: 500;
}
.tabs button:hover { background: none; color: var(--ink); }
.tabs button.active { color: var(--accent-ink); border-bottom-color: var(--accent); font-weight: 600; }
.tabpane { display: none; }
.tabpane.active { display: block; }

/* ---------- inventory / recipes editable tables ---------- */
table.inv td, table.inv th { padding: 5px 10px; }
table.inv input[type="text"], table.inv input:not([type]) {
  padding: 4px 6px; border-radius: 5px;
}
table.inv input.n { width: 78px; text-align: right; font-family: var(--mono); font-size: 12.5px; }
table.inv input[name="unit"] { width: 42px; }
table.inv button { padding: 4px 10px; font-size: 12px; }
tr.invrow.inactive td { opacity: .55; }
tr.invrow .ed, tr.invrow.editing .ro { display: none; }
tr.invrow.editing .ed { display: inline-block; }
tr.invrow.editing .editbtn { display: none; }
tr.invrow.editing td { background: #fffdf5; }
table.inv select[name="unit"] { padding: 4px 6px; border-radius: 5px; }
table.inv .cq, table.inv .cu { color: var(--muted); font-family: var(--mono); font-size: 12px; }
table.inv tfoot th {
  background: #fcfcfb; border-top: 2px solid var(--line); color: var(--ink);
  text-transform: none; font-size: 13px; letter-spacing: 0;
}
.rowbtns { white-space: nowrap; }
.rowbtns button { margin-right: 4px; }

.summary {
  display: flex; gap: 22px; align-items: center; flex-wrap: wrap;
  padding: 12px 16px; margin: 0 0 16px;
}
.summary span { font-size: 13px; }
.summary b {
  color: var(--muted); font-weight: 600; font-size: 11px; margin-right: 4px;
  text-transform: uppercase; letter-spacing: .08em;
}
.summary a.btn { margin-left: auto; }

/* ---------- ledger page ---------- */
.ledger-layout { display: flex; gap: 20px; align-items: flex-start; }
.ledger-filters {
  width: 260px; flex-shrink: 0; background: var(--panel);
  border: 1px solid var(--line); border-radius: var(--radius); padding: 16px;
  box-shadow: var(--shadow);
}
.ledger-filters h2 { margin: 0 0 12px; }
.ledger-filters input[type="text"] { width: 100%; margin-bottom: 8px; }
.account-actions { display: flex; gap: 8px; margin-bottom: 8px; }
.account-actions button {
  flex: 1; padding: 5px 8px; font-size: 12px;
  background: var(--line-soft); color: var(--ink);
}
.account-actions button:hover { background: var(--line); }
.account-list {
  max-height: 420px; overflow-y: auto; border: 1px solid var(--line);
  border-radius: 7px; padding: 6px;
}
.account-item { display: flex; align-items: baseline; gap: 6px; padding: 4px 0; cursor: pointer; }
.account-item input { margin: 0; }
.account-item .acct-code { color: var(--muted); font: 12px var(--mono); min-width: 34px; }
.account-item .acct-name { font-size: 13px; }
.apply-btn { width: 100%; margin-top: 12px; }
.ledger-results { flex: 1; min-width: 0; }
.line-memo { color: var(--muted); font-size: 12px; }
@media (max-width: 900px) {
  .ledger-layout { flex-direction: column; }
  .ledger-filters { width: 100%; }
}

/* ---------- analytics ---------- */
.chart-panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: var(--shadow);
}
.chart-panel h2 { margin: 0 0 10px; }
.chart-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.chart-box { position: relative; height: 300px; }
@media (max-width: 900px) { .chart-grid { grid-template-columns: 1fr; } }

/* ---------- reconciliation workbench ---------- */
.wb-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); margin-bottom: 14px;
  display: grid; grid-template-columns: minmax(230px, 300px) 1fr;
}
.wb-line { padding: 16px 18px; border-right: 1px solid var(--line-soft); }
.wb-line .amt { font: 500 20px var(--mono); font-variant-numeric: tabular-nums; margin: 2px 0 6px; }
.wb-line .amt.neg { color: var(--neg); }
.wb-line .when { font: 12px var(--mono); color: var(--muted); }
.wb-line .cp { font-weight: 600; font-size: 13.5px; margin-top: 6px; overflow-wrap: anywhere; }
.wb-line .desc { color: var(--muted); font-size: 12.5px; margin-top: 2px; overflow-wrap: anywhere; }
.wb-line .pill { margin-top: 8px; }
.wb-line .note-badge { display: block; margin-top: 8px; font-size: 12px; color: var(--warn); }
.wb-action { padding: 12px 18px 16px; min-width: 0; }
.wb-suggest { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.wb-suggest .detail { flex: 1; min-width: 200px; font-size: 13px; }
.wb-suggest .detail .num { font-size: 12.5px; }
.wb-pay-list { margin: 6px 0 0; padding: 0; list-style: none; }
.wb-pay-list li { display: flex; justify-content: space-between; gap: 12px; padding: 2px 0; font-size: 12.5px; }
.wb-fee { color: var(--muted); font-size: 12px; margin-top: 6px; }
.wb-search { display: flex; gap: 8px; margin-bottom: 8px; }
.wb-search input { flex: 1; }
.wb-results { max-height: 220px; overflow-y: auto; border: 1px solid var(--line); border-radius: 7px; }
.wb-results table td, .wb-results table th { padding: 5px 10px; font-size: 12.5px; }
.wb-total { font: 500 13px var(--mono); margin: 8px 0; }
.wb-total.bad { color: var(--neg); }
.wb-total.good { color: var(--pos); }
.wb-empty { color: var(--muted); font-size: 13px; padding: 6px 0; }
@media (max-width: 900px) {
  .wb-card { grid-template-columns: 1fr; }
  .wb-line { border-right: 0; border-bottom: 1px solid var(--line-soft); }
}

/* ---------- journal entry ---------- */
.je-lines td { padding: 4px 8px; }
.je-lines input.amt-in { width: 110px; text-align: right; font-family: var(--mono); }
.je-lines input.acct-in { width: 100%; min-width: 220px; }
.je-foot { display: flex; gap: 24px; align-items: center; margin: 14px 2px; }
.je-foot .t { font: 500 13px var(--mono); }

/* ---------- login ---------- */
.login-page { display: flex; min-height: 100vh; min-height: 100dvh; align-items: center; justify-content: center; background: var(--paper); }
main.login {
  max-width: 340px; width: 100%; background: var(--panel);
  border: 1px solid var(--line); border-radius: 14px; padding: 28px; margin: 24px;
  box-shadow: var(--shadow);
}
main.login h1 { font: 600 15px var(--mono); letter-spacing: .12em; text-transform: uppercase; }
main.login h1 span { color: var(--accent); }
main.login form { display: flex; flex-direction: column; gap: 14px; margin-top: 16px; }
main.login label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); }
main.login input { padding: 9px 10px; }
main.login button { padding: 10px; font-size: 14px; }
.login-error {
  background: var(--neg-soft); color: var(--neg); border-radius: 7px;
  padding: 8px 12px; font-size: 13px;
}

/* ---------- trial balance tree ---------- */
.tb-parent td { font-weight: 600; }
.tb-toggle {
  width: 20px; height: 20px; padding: 0; margin-right: 6px; line-height: 1;
  font: 600 13px var(--mono); text-align: center; vertical-align: middle;
  background: var(--panel); color: var(--accent-ink); border: 1px solid var(--line); border-radius: 5px;
}
.tb-toggle:hover { background: var(--line-soft); color: var(--accent-ink); }

/* ---------- daily cash sheet (mobile-first) ---------- */
.cash-form h2 { margin: 18px 0 8px; }
.cash-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px 18px; align-items: end;
}
.cash-grid label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); }
.cash-grid input { padding: 12px 10px; font-size: 16px; }
.cash-fact {
  display: flex; flex-direction: column; gap: 3px; padding: 8px 12px;
  background: var(--line-soft); border-radius: 8px;
}
.cash-fact span { font-size: 12px; color: var(--muted); }
.cash-fact strong { font-family: var(--mono); font-size: 16px; }
#movements input, #movements select { padding: 10px 8px; font-size: 15px; width: 100%; }
#movements td.num input { text-align: right; font-family: var(--mono); max-width: 110px; }
.cash-submit { width: 100%; padding: 14px; font-size: 16px; margin-top: 8px; }
#var.balanced { color: var(--pos); }
#var.unbalanced { color: var(--neg); }
@media (min-width: 700px) { .cash-submit { width: auto; padding: 12px 28px; } }

/* ---------- phone / touch ---------- */

/* Tables pan inside their panel instead of scrolling the whole page sideways.
   Headers and codes stay on one line so only genuinely wide tables overflow. */
@media (max-width: 900px) {
  .panel { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  th { white-space: nowrap; }
}

/* Touch input: iOS Safari zooms the page on focus for any field under 16px,
   and finger targets need far more padding than cursor targets. */
@media (pointer: coarse) {
  input[type="text"], input[type="date"], input[type="password"], input[type="number"],
  input:not([type]), select, textarea,
  table.inv input[type="text"], table.inv input:not([type]), table.inv select[name="unit"] {
    font-size: 16px; padding: 9px 10px;
  }
  table.inv input.n, .addform input.n, form.filters input.n, .je-lines input.amt-in { width: 96px; }
  table.inv input[name="unit"] { width: 60px; }

  button, a.btn { padding: 11px 18px; font-size: 14px; }
  .tabs button { padding: 12px 16px; }
  .side nav a { padding: 12px 10px; font-size: 15px; }
  .side-foot button, table.inv button, .account-actions button { padding: 9px 14px; font-size: 13px; }
  .rowbtns button { margin-bottom: 4px; }
  .tb-toggle { width: 32px; height: 32px; font-size: 15px; }
  .account-item { padding: 9px 0; }
  .menu-btn { padding: 10px 16px; }
}
