@import url('https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,400;9..144,600&family=IBM+Plex+Mono:wght@400;500&family=IBM+Plex+Sans:wght@400;500;600&display=swap');

/* ============================================================
   Ledger — warm paper, ink, brass. Built for daily use on
   a phone and for printing at year end.
   ============================================================ */

:root {
  --paper:      #f4efe4;
  --paper-2:    #fbf8f1;
  --card:       #fffdf8;
  --ink:        #17140f;
  --ink-2:      #4a4338;
  --ink-3:      #8a8073;
  --rule:       #ddd4c2;
  --rule-2:     #eae2d3;
  --brass:      #a1691f;
  --brass-soft: #f0e3cd;
  --green:      #1d5a48;
  --red:        #a03422;
  --radius:     4px;
  --shadow:     0 1px 0 var(--rule), 0 12px 28px -22px rgba(23, 20, 15, .5);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: 'IBM Plex Sans', system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.55;
  color: var(--ink);
  background:
    repeating-linear-gradient(90deg, rgba(0,0,0,.012) 0 1px, transparent 1px 46px),
    var(--paper);
}

h1, h2, h3 {
  font-family: 'Fraunces', Georgia, serif;
  font-weight: 600;
  letter-spacing: -.01em;
  margin: 0;
}
h1 { font-size: 1.9rem; line-height: 1.15; }
h2 { font-size: 1.06rem; }

a { color: var(--brass); text-decoration: none; }
a:hover { text-decoration: underline; }

.wrap { width: min(1180px, 100% - 2rem); margin-inline: auto; }
.muted { color: var(--ink-3); }
.small { font-size: .82rem; }
.strong { font-weight: 600; }
.nowrap { white-space: nowrap; }
.r { text-align: right; }
.pad { padding: 1.2rem 0; }
.warn { color: var(--red); }
.num {
  font-family: 'IBM Plex Mono', ui-monospace, monospace;
  font-variant-numeric: tabular-nums;
  font-size: .9em;
}

.eyebrow {
  margin: 0 0 .25rem;
  font-size: .72rem;
  letter-spacing: .13em;
  text-transform: uppercase;
  color: var(--brass);
}

/* ---------------- top bar ---------------- */

.topbar {
  position: sticky; top: 0; z-index: 20;
  background: rgba(244, 239, 228, .93);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--rule);
}
.topbar-in {
  display: flex; align-items: center; gap: 1.5rem;
  min-height: 60px; flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: .55rem; color: var(--ink); }
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 11px; height: 11px; border-radius: 2px;
  background: var(--brass);
  box-shadow: 0 0 0 3px var(--brass-soft);
}
.brand-name {
  font-family: 'Fraunces', serif; font-size: 1.12rem; font-weight: 600;
  letter-spacing: -.01em;
}
.nav {
  display: flex; align-items: center; gap: .15rem;
  margin-left: auto; overflow-x: auto; scrollbar-width: none;
}
.nav::-webkit-scrollbar { display: none; }
.nav-link {
  padding: .38rem .7rem; border-radius: 99px;
  color: var(--ink-2); font-size: .9rem; white-space: nowrap;
  transition: background .15s, color .15s;
}
.nav-link:hover { background: var(--brass-soft); text-decoration: none; }
.nav-link.is-on { background: var(--ink); color: var(--paper-2); }
.nav-out { color: var(--ink-3); }

.page { padding: 1.8rem 0 3rem; }

.page-head {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 1rem; flex-wrap: wrap; margin-bottom: 1.4rem;
}

/* ---------------- panels ---------------- */

.panel {
  background: var(--card);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.15rem 1.25rem;
  margin-bottom: 1.15rem;
}
.panel-head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 1rem; margin-bottom: .85rem;
  padding-bottom: .6rem; border-bottom: 1px solid var(--rule-2);
}
.split { display: grid; grid-template-columns: 1fr 1fr; gap: 1.15rem; }
@media (max-width: 800px) { .split { grid-template-columns: 1fr; } }

.big-number {
  font-family: 'Fraunces', serif; font-size: 2.1rem;
  margin: .2rem 0 .1rem; letter-spacing: -.02em;
}

/* ---------------- kpis ---------------- */

.kpis {
  display: grid; gap: .8rem; margin-bottom: 1.15rem;
  grid-template-columns: repeat(5, 1fr);
}
@media (max-width: 1000px) { .kpis { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 460px)  { .kpis { grid-template-columns: 1fr; } }

.kpi {
  background: var(--card);
  border: 1px solid var(--rule);
  border-top: 2px solid var(--rule);
  border-radius: var(--radius);
  padding: .85rem .95rem 1rem;
  display: flex; flex-direction: column; gap: .1rem;
}
.kpi-lead { border-top-color: var(--brass); }
.kpi-net  { border-top-color: var(--green); background: linear-gradient(180deg, #f6faf7, var(--card)); }
.kpi-label {
  font-size: .7rem; letter-spacing: .1em; text-transform: uppercase; color: var(--ink-3);
}
.kpi-value {
  font-family: 'Fraunces', serif; font-size: 1.42rem; letter-spacing: -.02em;
  font-variant-numeric: tabular-nums; margin-top: .15rem;
}
.kpi-net .kpi-value { color: var(--green); }
.kpi-foot { font-size: .76rem; color: var(--ink-3); margin-top: .2rem; }

/* ---------------- chart ---------------- */

.chart {
  display: grid; grid-template-columns: repeat(12, 1fr);
  gap: .4rem; height: 190px; align-items: end;
  padding-top: .5rem;
  background: repeating-linear-gradient(180deg, var(--rule-2) 0 1px, transparent 1px 38px);
}
.col { display: flex; flex-direction: column; align-items: center; gap: .35rem; height: 100%; }
.bars {
  flex: 1; width: 100%; display: flex; align-items: flex-end;
  justify-content: center; gap: 2px;
}
.bar { width: 42%; border-radius: 2px 2px 0 0; min-height: 2px; transition: height .3s ease; }
.bar-r { background: var(--brass); opacity: .82; }
.bar-n { background: var(--green); opacity: .82; }
.col:hover .bar { opacity: 1; }
.col-label { font-size: .68rem; color: var(--ink-3); letter-spacing: .04em; }
.legend { display: flex; gap: .9rem; font-size: .76rem; color: var(--ink-3); }
.key::before {
  content: ''; display: inline-block; width: 9px; height: 9px;
  border-radius: 2px; margin-right: .35rem;
}
.key-r::before { background: var(--brass); }
.key-n::before { background: var(--green); }

/* ---------------- tables ---------------- */

.scroll-x { overflow-x: auto; margin: 0 -1.25rem; padding: 0 1.25rem; }
.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th {
  text-align: left; font-weight: 500; font-size: .7rem;
  letter-spacing: .1em; text-transform: uppercase; color: var(--ink-3);
  padding: .4rem .55rem; border-bottom: 1px solid var(--rule);
  white-space: nowrap;
}
.table td { padding: .55rem; border-bottom: 1px solid var(--rule-2); vertical-align: top; }
.table tbody tr:hover { background: #fdf6e9; }
.table tfoot th {
  border-top: 2px solid var(--ink); border-bottom: none;
  color: var(--ink); font-size: .82rem; text-transform: none; letter-spacing: 0;
  padding-top: .5rem;
}
.table.compact td { padding: .38rem .55rem; }
.table.summary td { padding: .55rem .2rem; font-size: .95rem; }
.table.summary tr.rule td { border-top: 1px solid var(--rule); }
.table.summary tr.total td {
  border-top: 2px solid var(--ink); border-bottom: none;
  font-family: 'Fraunces', serif; font-size: 1.1rem; padding-top: .7rem;
}
.faint td { color: var(--ink-3); }
.row-late { background: #fdf1ee; }
.row-late:hover { background: #fbe8e3; }

.tag {
  display: inline-block; padding: .1rem .5rem; border-radius: 99px;
  background: var(--brass-soft); color: #7a4d12;
  font-size: .7rem; letter-spacing: .04em; white-space: nowrap;
}
.tag-ok  { background: #dcece3; color: var(--green); }
.tag-bad { background: #f6ded8; color: var(--red); }

.totals {
  display: flex; flex-wrap: wrap; gap: .4rem 1.6rem;
  padding: .75rem 0; margin-bottom: .3rem;
  border-top: 1px solid var(--rule-2); border-bottom: 1px solid var(--rule-2);
  font-size: .82rem; color: var(--ink-3);
}
.totals strong { display: block; color: var(--ink); font-size: 1rem; }
.totals .hl strong { color: var(--green); }

.pager {
  display: flex; align-items: center; justify-content: center;
  gap: 1rem; padding-top: 1rem; font-size: .85rem;
}

/* ---------------- forms ---------------- */

label { display: block; margin-bottom: .8rem; font-size: .78rem; color: var(--ink-2); }
input, select, textarea {
  display: block; width: 100%; margin-top: .25rem;
  padding: .5rem .6rem;
  font: inherit; font-size: .92rem; color: var(--ink);
  background: var(--paper-2);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--brass);
  box-shadow: 0 0 0 3px var(--brass-soft);
  background: #fff;
}
input[type="number"], input[type="date"] {
  font-family: 'IBM Plex Mono', monospace; font-size: .88rem;
}
.hint { display: block; margin-top: .2rem; font-size: .7rem; color: var(--ink-3); }

.form-panel { border-left: 3px solid var(--brass); }
.form-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0 .9rem; }
.form-grid .span-2 { grid-column: span 2; }
@media (max-width: 900px) { .form-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 520px) {
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .span-2 { grid-column: span 1; }
}

.calc {
  display: flex; gap: 1.8rem; flex-wrap: wrap;
  padding: .65rem .85rem; margin: .3rem 0 1rem;
  background: var(--paper); border: 1px dashed var(--rule);
  border-radius: var(--radius);
  font-size: .78rem; color: var(--ink-3);
}
.calc strong {
  display: block; color: var(--ink); font-size: 1.05rem;
  font-family: 'IBM Plex Mono', monospace; font-variant-numeric: tabular-nums;
}

.form-actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.filters { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; margin-bottom: .3rem; }
.filters input, .filters select { width: auto; margin-top: 0; }
.filters input[type="search"] { min-width: 240px; flex: 1; }
.inline-form { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.inline-form select { width: auto; margin-top: 0; }
form.inline { display: inline; }

.btn {
  display: inline-block; cursor: pointer;
  padding: .45rem .9rem;
  font: inherit; font-size: .85rem; color: var(--ink);
  background: var(--paper-2);
  border: 1px solid var(--rule); border-radius: var(--radius);
  transition: background .15s, border-color .15s, transform .08s;
}
.btn:hover { background: #fff; border-color: var(--ink-3); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--ink); border-color: var(--ink); color: var(--paper-2); }
.btn-primary:hover { background: #2b251c; border-color: #2b251c; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--ink-3); }
.btn.block { display: block; width: 100%; text-align: center; margin-top: .4rem; }

.link {
  background: none; border: none; padding: 0 .35rem 0 0;
  font: inherit; font-size: .82rem; color: var(--brass); cursor: pointer;
}
.link:hover { text-decoration: underline; }
.link.danger { color: var(--red); }

.note {
  padding: .7rem .9rem; margin-bottom: 1.1rem;
  border-radius: var(--radius); border: 1px solid;
  font-size: .88rem;
}
.note.ok  { background: #e9f2ec; border-color: #c3ddcd; color: #17452f; }
.note.bad { background: #fbeae5; border-color: #eec8bd; color: #7d2716; }

/* ---------------- auth pages ---------------- */

.auth-body { display: grid; place-items: center; min-height: 100vh; padding: 1.5rem; }
.auth-card {
  width: min(420px, 100%);
  background: var(--card);
  border: 1px solid var(--rule);
  border-top: 3px solid var(--brass);
  border-radius: var(--radius);
  box-shadow: 0 20px 50px -30px rgba(23, 20, 15, .6);
  padding: 1.8rem 1.7rem 2rem;
}
.auth-title { font-size: 1.7rem; margin-bottom: 1.2rem; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 .8rem; }

/* ---------------- footer ---------------- */

.foot {
  border-top: 1px solid var(--rule);
  padding: 1.1rem 0 2rem;
  font-size: .76rem; color: var(--ink-3);
}
.foot .wrap { display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }

/* ---------------- print (ITR page) ---------------- */

@media print {
  body { background: #fff; font-size: 11pt; }
  .topbar, .foot, .page-head form, .btn, .link, .note { display: none !important; }
  .panel { box-shadow: none; border: 1px solid #ccc; break-inside: avoid; margin-bottom: 12pt; }
  .scroll-x { overflow: visible; margin: 0; padding: 0; }
  a { color: inherit; }
}

/* ============================================================
   Installed-app behaviour: bottom tab bar, floating add button,
   notch-safe padding. Phone-only; desktop keeps the top nav.
   ============================================================ */

.tabbar { display: none; }
.fab { display: none; }

.nav-install {
  border: 1px solid var(--brass);
  color: var(--brass);
  background: transparent;
  cursor: pointer;
  font: inherit;
  font-size: .82rem;
}
.nav-install:hover { background: var(--brass-soft); }

@media (max-width: 700px) {
  /* the tab bar takes over navigation */
  .nav .nav-link:not(.nav-out):not(.nav-install) { display: none; }

  body { padding-bottom: calc(64px + env(safe-area-inset-bottom)); }

  .topbar { padding-top: env(safe-area-inset-top); }
  .topbar-in { min-height: 54px; }

  .tabbar {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    display: grid; grid-template-columns: repeat(5, 1fr);
    background: rgba(251, 248, 241, .96);
    backdrop-filter: blur(10px);
    border-top: 1px solid var(--rule);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .tab {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 2px; padding: .5rem .2rem .55rem;
    color: var(--ink-3); font-size: .62rem; letter-spacing: .04em;
    text-transform: uppercase; text-decoration: none;
    -webkit-tap-highlight-color: transparent;
  }
  .tab svg { width: 21px; height: 21px; }
  .tab:hover { text-decoration: none; }
  .tab.is-on { color: var(--brass); }
  .tab.is-on svg { stroke-width: 1.9; }

  .fab {
    position: fixed; right: 1rem; z-index: 31;
    bottom: calc(72px + env(safe-area-inset-bottom));
    display: grid; place-items: center;
    width: 52px; height: 52px; border-radius: 50%;
    background: var(--ink); color: var(--paper-2);
    font-size: 1.7rem; line-height: 1; padding-bottom: 3px;
    box-shadow: 0 8px 22px -8px rgba(23, 20, 15, .6);
    text-decoration: none;
  }
  .fab:active { transform: translateY(1px); }

  /* comfortable tap targets and no iOS zoom-on-focus */
  input, select, textarea { font-size: 16px; padding: .6rem .65rem; }
  .btn { padding: .55rem 1rem; }
  .link { padding: .3rem .5rem .3rem 0; display: inline-block; }
  h1 { font-size: 1.55rem; }
  .page { padding: 1.2rem 0 2rem; }
  .panel { padding: 1rem .9rem; }
  .scroll-x { margin: 0 -.9rem; padding: 0 .9rem; }
  .filters input[type="search"] { min-width: 100%; }
  .totals { gap: .4rem 1.1rem; font-size: .76rem; }
}

/* Installed app: it isn't a web page any more, so drop the web-page furniture */
.standalone .foot { display: none; }
.standalone .brand-name::after {
  content: ''; /* keeps the brand tidy in standalone */
}
@media (display-mode: standalone) {
  .nav-install { display: none; }
}

@media print {
  .tabbar, .fab { display: none !important; }
  body { padding-bottom: 0; }
}
