/* ============================================================================
   LEDGERBOOK — ink on ledger
   ----------------------------------------------------------------------------
   The palette comes from the subject's own world: a columnar register ruled in
   black ink, with credits entered in red. Debit blue and credit oxblood carry
   meaning on every screen, so colour is information rather than decoration.
   Brass is reserved for one thing only — the balanced seal.

   Figures are set in a monospaced face with tabular numerals because columns of
   money that do not align are harder to read, not just less pretty.
   ========================================================================== */

:root {
  --ink: #131A2E;
  --ink-2: #1D2740;
  --paper: #F5F6F9;
  --surface: #FFFFFF;
  --rule: #DDE2EC;
  --rule-2: #EDF0F5;
  --muted: #6B7489;
  --dr: #1D4E89;
  --cr: #8C2F39;
  --brass: #A8811F;
  --good: #2C6E4F;
  --bad: #A32C2C;
  --r: 2px;

  --sans: "IBM Plex Sans", system-ui, -apple-system, sans-serif;
  --serif: "IBM Plex Serif", Georgia, serif;
  --mono: "IBM Plex Mono", ui-monospace, "SF Mono", monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body, #root { height: 100%; }

body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { font-family: var(--serif); font-weight: 600; }
h1 { font-size: 24px; letter-spacing: -0.01em; }
h2 { font-size: 14px; letter-spacing: 0.01em; }
h3 { font-size: 15px; }

.app { display: flex; min-height: 100vh; }

/* ---- text utilities -------------------------------------------------------- */
.mono, .num { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.dim { color: var(--muted); }
.small { font-size: 12px; }
.strongish { font-weight: 500; }
.hot { color: var(--bad); }
.r { text-align: right; }
.center { text-align: center; }

.eyebrow {
  font-size: 10px; font-weight: 600; letter-spacing: 0.14em;
  text-transform: uppercase; color: var(--muted);
}
.num { font-size: 13px; }
.num.strong { font-weight: 600; }
.num.dim { color: var(--muted); }
.num.dr { color: var(--dr); }
.num.cr { color: var(--cr); }

/* ---- sidebar --------------------------------------------------------------- */
.nav {
  width: 244px; flex: 0 0 244px;
  background: var(--ink); color: #C7CEDE;
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.brand {
  padding: 20px 18px 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.09);
  display: flex; flex-direction: column; gap: 2px;
}
.brand-mark {
  font-family: var(--mono); font-size: 11px; font-weight: 600;
  letter-spacing: 0.1em; color: var(--brass);
}
.brand-mark i { color: rgba(255, 255, 255, 0.3); font-style: normal; padding: 0 1px; }
.brand-name {
  font-family: var(--serif); font-size: 19px; font-weight: 600;
  color: #fff; letter-spacing: -0.01em;
}
.orgpick {
  padding: 14px 18px; border-bottom: 1px solid rgba(255, 255, 255, 0.09);
  display: flex; flex-direction: column; gap: 6px;
}
.orgpick .eyebrow { color: rgba(255, 255, 255, 0.4); }
.orgpick select {
  width: 100%; background: var(--ink-2); color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.14); border-radius: var(--r);
  padding: 7px 8px; font-family: inherit; font-size: 13px; font-weight: 500;
}
.orgpick-gstin { font-size: 10.5px; color: rgba(255, 255, 255, 0.38); letter-spacing: 0.03em; }

.nav nav { padding: 6px 0 32px; }
.navgroup { padding: 4px 0; }
.navsection {
  font-size: 9.5px; font-weight: 600; letter-spacing: 0.15em; text-transform: uppercase;
  color: rgba(255, 255, 255, 0.32); padding: 12px 18px 5px;
}
.navitem {
  display: block; width: 100%; text-align: left; background: none; border: 0;
  cursor: pointer; padding: 6px 18px; font-family: inherit; font-size: 13px;
  color: #B6BFD2; border-left: 2px solid transparent;
}
.navitem:hover { color: #fff; background: rgba(255, 255, 255, 0.045); }
.navitem.on {
  color: #fff; background: rgba(255, 255, 255, 0.08);
  border-left-color: var(--brass); font-weight: 500;
}
.navitem:focus-visible { outline: 2px solid var(--brass); outline-offset: -2px; }

/* ---- main ------------------------------------------------------------------ */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 5;
  background: rgba(245, 246, 249, 0.94); backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--rule);
  padding: 0 24px; height: 52px; display: flex; align-items: center; gap: 14px;
}
.crumb { font-size: 13px; flex: 1; }
.crumb i { color: var(--rule); font-style: normal; padding: 0 4px; }
.burger { display: none; background: none; border: 0; font-size: 17px; cursor: pointer; color: var(--ink); }
.content { padding: 24px; max-width: 1280px; width: 100%; }
.scrim { display: none; }

.stack { display: flex; flex-direction: column; gap: 16px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
.two.wide { grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); }
.sticky { position: sticky; top: 76px; }
.scrollx { overflow-x: auto; }

/* ---- panels ---------------------------------------------------------------- */
.panel { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--r); }
.panel.pad { padding: 16px; }
.panel-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 16px; border-bottom: 1px solid var(--rule-2);
}
.panel-head-right { display: flex; align-items: center; gap: 12px; }
.panel-foot {
  padding: 12px 16px; border-top: 1px solid var(--rule-2);
  display: flex; justify-content: flex-end; align-items: center;
}
.panel-foot.notes { display: block; text-align: left; }
.notbuilt h3 { margin: 6px 0 4px; }
.notbuilt ul { margin: 10px 0 0 18px; }
.notbuilt li { margin-bottom: 3px; }

/* ---- tables ---------------------------------------------------------------- */
.tbl { width: 100%; border-collapse: collapse; }
.tbl th {
  font-size: 10px; font-weight: 600; letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--muted); text-align: left; padding: 9px 14px;
  border-bottom: 1px solid var(--rule); white-space: nowrap;
}
.tbl th.r { text-align: right; }
.tbl td { padding: 9px 14px; border-bottom: 1px solid var(--rule-2); vertical-align: top; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl tr.click { cursor: pointer; }
.tbl tr.click:hover td { background: #F8F9FC; }
.tbl tr.secthead td {
  font-size: 10px; font-weight: 600; letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--muted); padding-top: 14px; border-bottom: 1px solid var(--rule);
}
.tbl td.indent { padding-left: 26px; }
.tbl tr.sub td { border-top: 1px solid var(--rule); border-bottom: 0; font-weight: 500; }
.tbl tr.grand td {
  border-top: 1.5px solid var(--ink); border-bottom: 0; font-weight: 600;
  font-family: var(--serif); padding-top: 11px;
}
.tbl tr.grand.big td { border-top: 3px double var(--ink); font-size: 15px; }
.tbl.report td:first-child { width: 58%; }
.tbl.form td { padding: 5px 8px; vertical-align: middle; }
.tbl.form td:first-child { padding-left: 14px; min-width: 200px; }

/* ---- form controls --------------------------------------------------------- */
.field { display: flex; flex-direction: column; gap: 4px; }
.flabel {
  font-size: 10px; font-weight: 600; letter-spacing: 0.1em;
  text-transform: uppercase; color: var(--muted);
}
.fhint { font-size: 11.5px; color: var(--muted); }
.ferr { font-size: 11.5px; color: var(--bad); }

input, select, textarea {
  width: 100%; font-family: inherit; font-size: 13.5px; color: var(--ink);
  background: var(--surface); border: 1px solid var(--rule);
  border-radius: var(--r); padding: 7px 9px;
}
input.mono, select.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
input.r { text-align: right; }
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--dr); outline-offset: -1px; border-color: var(--dr);
}
select:disabled { background: var(--rule-2); color: var(--muted); }
textarea { resize: vertical; }

.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.w-sac { width: 88px; } .w-qty { width: 66px; } .w-rate { width: 104px; }
.w-disc { width: 64px; } .w-gst { width: 76px; }
.itempick { margin-bottom: 5px; font-size: 12px; color: var(--muted); }
.xbtn {
  background: none; border: 0; color: var(--muted); font-size: 17px;
  cursor: pointer; line-height: 1; padding: 2px 6px;
}
.xbtn:hover { color: var(--bad); }
.search { max-width: 260px; }

.listbar { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.listbar-meta { flex: 1; font-size: 12.5px; color: var(--muted); }
.row-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }

.segmented { display: flex; border: 1px solid var(--rule); border-radius: var(--r); overflow: hidden; }
.segmented button {
  background: var(--surface); border: 0; border-right: 1px solid var(--rule);
  padding: 5px 11px; font-family: inherit; font-size: 12px; color: var(--muted);
  cursor: pointer; text-transform: capitalize;
}
.segmented button:last-child { border-right: 0; }
.segmented button.on { background: var(--ink); color: #fff; font-weight: 500; }

/* ---- buttons --------------------------------------------------------------- */
.btn {
  font-family: inherit; font-size: 13px; font-weight: 500; padding: 8px 14px;
  border-radius: var(--r); border: 1px solid var(--ink);
  background: var(--ink); color: #fff; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--ink-2); }
.btn:disabled { opacity: 0.35; cursor: not-allowed; }
.btn.ghost { background: none; color: var(--ink); border-color: var(--rule); }
.btn.ghost:hover { border-color: var(--ink); background: #F8F9FC; }
.btn.ghost:disabled:hover { border-color: var(--rule); background: none; }
.btn.sm { padding: 5px 10px; font-size: 12px; }
.btn:focus-visible { outline: 2px solid var(--brass); outline-offset: 2px; }

/* ---- pills ----------------------------------------------------------------- */
.pill {
  display: inline-block; font-size: 10px; font-weight: 600; letter-spacing: 0.08em;
  text-transform: uppercase; padding: 3px 7px; border-radius: var(--r);
  border: 1px solid; margin-left: 4px;
}
.pill:first-child { margin-left: 0; }
.pill.good { color: var(--good); border-color: #BFDACB; background: #F1F8F4; }
.pill.warn { color: var(--brass); border-color: #E4D5A8; background: #FBF7EB; }
.pill.bad { color: var(--bad); border-color: #E5C0C0; background: #FBF1F1; }
.pill.info { color: var(--dr); border-color: #C2D3E7; background: #F1F5FA; }
.pill.mute { color: var(--muted); border-color: var(--rule); background: #F7F8FA; }

/* ---- tiles and notices ----------------------------------------------------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; }
.kpi {
  text-align: left; background: var(--surface); border: 1px solid var(--rule);
  border-radius: var(--r); padding: 14px 16px;
  display: flex; flex-direction: column; gap: 5px; font-family: inherit;
}
.kpi.tap { cursor: pointer; }
.kpi.tap:hover { border-color: var(--ink); }
.kpi-val {
  font-family: var(--mono); font-size: 21px; font-weight: 500;
  letter-spacing: -0.02em; font-variant-numeric: tabular-nums;
}
.kpi-val.dr { color: var(--dr); }
.kpi-val.cr { color: var(--cr); }
.kpi-sub { font-size: 11.5px; color: var(--muted); }

.notice {
  display: flex; align-items: center; justify-content: space-between;
  gap: 14px; flex-wrap: wrap; padding: 12px 16px; font-size: 13px;
  background: #FBF7EB; border: 1px solid #E4D5A8;
  border-left: 3px solid var(--brass); border-radius: var(--r);
}
.notice.info { background: #F1F5FA; border-color: #C2D3E7; border-left-color: var(--dr); }
.notice.bad-tone { background: #FBF1F1; border-color: #E5C0C0; border-left-color: var(--bad); }

/* ---- bars ------------------------------------------------------------------ */
.agebars { padding: 14px 16px; display: flex; flex-direction: column; gap: 9px; }
.agebar { display: grid; grid-template-columns: 78px 1fr 104px; align-items: center; gap: 10px; }
.agebar-lbl { font-size: 11.5px; color: var(--muted); }
.agebar-track { height: 8px; background: var(--rule-2); border-radius: 1px; overflow: hidden; }
.agebar-fill { height: 100%; background: var(--dr); transition: width 0.4s ease; }
.agebar-fill.hot { background: var(--cr); }
.agebar-val { text-align: right; }

.sharebar { display: flex; align-items: center; gap: 7px; justify-content: flex-end; }
.sharebar-fill { height: 6px; background: var(--dr); opacity: 0.55; border-radius: 1px; min-width: 1px; }
.sharebar-fill.cr { background: var(--cr); }
.sharebar span { color: var(--muted); width: 34px; text-align: right; }

/* ---- headers --------------------------------------------------------------- */
.dochead { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.dochead h1 { margin-top: 3px; }
.dochead-blurb { max-width: 62ch; margin-top: 4px; }
.dochead-meta {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  margin-top: 5px; font-size: 13px;
}
.dochead-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.rephead { border-bottom: 2px solid var(--ink); padding-bottom: 12px; }
.rephead h1 { margin: 5px 0 3px; }

/* ---- totals block ---------------------------------------------------------- */
.totals {
  padding: 12px 16px; border-top: 1px solid var(--rule);
  display: flex; flex-direction: column; gap: 5px;
  margin-left: auto; max-width: 360px;
}
.totals > div { display: flex; justify-content: space-between; gap: 20px; font-size: 13px; }
.totals > div > span:first-child { color: var(--muted); }
.totals > div.grand {
  border-top: 1px solid var(--rule); padding-top: 6px; margin-top: 2px;
  font-family: var(--serif); font-weight: 600;
}
.totals > div.grand > span:first-child { color: var(--ink); }

/* ---- reports index --------------------------------------------------------- */
.repgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 0; }
.repcard {
  display: flex; flex-direction: column; gap: 3px; text-align: left;
  padding: 13px 16px; background: none; border: 0;
  border-right: 1px solid var(--rule-2); border-bottom: 1px solid var(--rule-2);
  font-family: inherit; cursor: pointer;
}
.repcard:hover { background: #F8F9FC; }
.repcard-name { font-weight: 500; font-size: 13.5px; }
.repcard-note { font-size: 11.5px; color: var(--muted); }

/* ---- print preview --------------------------------------------------------- */
.invoice-preview { display: flex; flex-direction: column; gap: 12px; }
.ip-head { display: flex; justify-content: space-between; gap: 16px; padding-bottom: 12px; border-bottom: 1px solid var(--rule); }
.ip-org { font-family: var(--serif); font-weight: 600; font-size: 15px; }
.ip-title { font-family: var(--serif); font-weight: 600; font-size: 15px; }
.ip-party { display: flex; flex-direction: column; gap: 2px; }
.ip-total {
  display: flex; justify-content: space-between; align-items: baseline;
  border-top: 1.5px solid var(--ink); padding-top: 10px;
  font-family: var(--serif); font-weight: 600;
}

/* ============================================================================
   THE JOURNAL RIBBON — the one place boldness is spent
   ========================================================================== */
.ribbon { background: var(--surface); border: 1px solid var(--ink); border-radius: var(--r); overflow: hidden; }
.ribbon-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 11px 14px; background: var(--ink); color: #fff;
}
.ribbon-head .eyebrow { color: rgba(255, 255, 255, 0.55); }

.seal {
  font-family: var(--mono); font-size: 9.5px; font-weight: 600; letter-spacing: 0.14em;
  text-transform: uppercase; color: var(--brass); border: 1.5px solid var(--brass);
  padding: 3px 8px; border-radius: var(--r); white-space: nowrap; display: inline-block;
}
.seal.off { color: #E39B9B; border-color: #B96A6A; }
.panel-foot .seal.off, .panel .center .seal.off { color: var(--bad); border-color: var(--bad); }
.seal.stamp { animation: stamp 0.55s cubic-bezier(0.2, 1.5, 0.4, 1); }

@keyframes stamp {
  0%   { transform: scale(1.9) rotate(-7deg); opacity: 0; }
  55%  { transform: scale(0.94) rotate(1deg); opacity: 1; }
  100% { transform: scale(1) rotate(0); opacity: 1; }
}

.ribbon-body { display: grid; grid-template-columns: 1fr 1fr; }
.ribbon-col { padding: 12px 14px; }
.ribbon-col + .ribbon-col { border-left: 1px solid var(--rule); }
.ribbon-colhead {
  font-family: var(--mono); font-size: 9.5px; font-weight: 600; letter-spacing: 0.14em;
  text-transform: uppercase; padding-bottom: 7px;
  border-bottom: 1px solid var(--rule-2); margin-bottom: 8px;
}
.ribbon-colhead.dr { color: var(--dr); }
.ribbon-colhead.cr { color: var(--cr); }
.ribbon-row {
  display: flex; justify-content: space-between; gap: 10px;
  padding: 4px 0; font-size: 12px; align-items: baseline;
}
.ribbon-acc { color: var(--ink); line-height: 1.35; }
.ribbon-acc b {
  font-family: var(--mono); font-weight: 500; color: var(--muted);
  font-size: 11px; margin-right: 4px;
}
.ribbon-none { font-size: 12px; color: var(--muted); padding: 4px 0; }
.ribbon-total {
  display: flex; justify-content: space-between; gap: 10px; align-items: baseline;
  border-top: 1.5px solid var(--ink); margin-top: 8px; padding-top: 7px;
  font-size: 11px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase;
}
.ribbon-total.dr { color: var(--dr); }
.ribbon-total.cr { color: var(--cr); }
.ribbon-problems {
  padding: 9px 14px; border-top: 1px solid var(--rule);
  background: #FBF1F1; color: var(--bad); font-size: 12px;
}

/* ---- empty ----------------------------------------------------------------- */
.empty { padding: 44px 20px; text-align: center; }
.empty h3 { font-size: 15px; margin-bottom: 5px; }
.empty p { color: var(--muted); font-size: 13px; margin-bottom: 14px; max-width: 46ch; margin-left: auto; margin-right: auto; }

/* ---- responsive and accessibility ----------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

@media (max-width: 1120px) {
  .two, .two.wide { grid-template-columns: 1fr; }
  .sticky { position: static; }
}

@media (max-width: 780px) {
  .nav {
    position: fixed; z-index: 30; left: 0; top: 0;
    transform: translateX(-100%); transition: transform 0.22s ease;
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.3);
  }
  .nav.open { transform: none; }
  .burger { display: block; }
  .scrim {
    display: block; position: fixed; inset: 0;
    background: rgba(19, 26, 46, 0.45); z-index: 20;
  }
  .content { padding: 16px; }
  .grid3 { grid-template-columns: 1fr; }
  .ribbon-body { grid-template-columns: 1fr; }
  .ribbon-col + .ribbon-col { border-left: 0; border-top: 1px solid var(--rule); }
  .tbl th, .tbl td { padding: 8px 10px; }
  .totals { max-width: none; }
  .repgrid { grid-template-columns: 1fr; }
  .repcard { border-right: 0; }
  .search { max-width: none; }
}
