/* ══════════════════════════════════════════════════════════════
   NauLedger — an account book, not a dashboard.
   Warm ruled paper, oxide-red margin rule, ink-black tabular figures.
   ══════════════════════════════════════════════════════════════ */

:root {
  --paper:      #f4efe3;
  --paper-2:    #ebe4d3;
  --paper-3:    #e3dac6;
  --edge:       #d9cfb8;
  --rule:       #d5c9ae;
  --rule-soft:  #e5dcc8;
  --ink:        #17150f;
  --ink-2:      #4d4636;
  --ink-3:      #837a64;
  --red:        #a63a2b;
  --red-soft:   #c4674e;
  --green:      #2f6b4a;
  --brass:      #a8823c;

  --shadow-lift: 0 1px 0 rgba(255,255,255,.55), 0 10px 28px -18px rgba(23,21,15,.45);
  --shadow-card: 0 1px 0 rgba(255,255,255,.6), 0 18px 40px -30px rgba(23,21,15,.6);

  --display: "Fraunces", "Iowan Old Style", Georgia, serif;
  --body: "IBM Plex Sans", ui-sans-serif, system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;

  --pad: clamp(14px, 4vw, 26px);
  --radius: 3px; /* paper doesn't have rounded corners */
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper:      #16140f;
    --paper-2:    #1d1a13;
    --paper-3:    #242017;
    --edge:       #2e2819;
    --rule:       #352e1f;
    --rule-soft:  #262114;
    --ink:        #ece5d3;
    --ink-2:      #b6ad94;
    --ink-3:      #837a64;
    --red:        #e0805f;
    --red-soft:   #c4674e;
    --green:      #83c4a0;
    --brass:      #d4a94f;

    --shadow-lift: 0 1px 0 rgba(255,255,255,.03), 0 10px 28px -18px rgba(0,0,0,.9);
    --shadow-card: 0 1px 0 rgba(255,255,255,.04), 0 18px 40px -30px rgba(0,0,0,1);
  }
}

* { box-sizing: border-box; }

/* An author `display` rule outranks the UA stylesheet's [hidden] rule, so
 * elements like .gate (display:grid) would stay visible when hidden. */
[hidden] { display: none !important; }

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

body {
  margin: 0;
  background-color: var(--paper);
  color: var(--ink);
  font-family: var(--body);
  font-size: 16px;
  line-height: 1.5;
  padding-bottom: env(safe-area-inset-bottom);
  /* Paper grain over faint horizontal ruling, like account paper.
   *
   * The grain used to be a full-page fixed overlay using mix-blend-mode. Don't
   * go back to that: blending against the whole document composites
   * unpredictably (it rendered as a heavy dark veil in testing) and forces a
   * repaint of the entire page on every scroll. As plain background layers it
   * is free and behaves identically everywhere. */
  background-image:
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2'/></filter><rect width='160' height='160' filter='url(%23n)' opacity='.05'/></svg>"),
    repeating-linear-gradient(
      to bottom,
      transparent 0 31px,
      var(--rule-soft) 31px 32px
    );
}

::selection { background: var(--brass); color: var(--paper); }

/* ─────────── masthead ─────────── */

.masthead {
  position: sticky; top: 0; z-index: 8;
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  backdrop-filter: blur(12px) saturate(1.1);
  border-bottom: 1px solid var(--edge);
  box-shadow: 0 1px 0 rgba(255,255,255,.4);
}
.masthead-inner {
  max-width: 940px; margin: 0 auto;
  padding: 12px var(--pad);
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
}
.brand { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.brand-mark {
  font-family: var(--display);
  font-weight: 600; font-size: 20px; letter-spacing: -.015em;
  font-variation-settings: "SOFT" 20, "WONK" 1;
}
.brand-rule { width: 18px; height: 1px; background: var(--red); flex: none; transform: translateY(-5px); }
.brand-party {
  font-size: 13px; letter-spacing: .16em; text-transform: uppercase;
  color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.nav { display: flex; gap: 2px; }
.nav-btn {
  appearance: none; border: 0; background: none; cursor: pointer;
  font-family: var(--body); font-size: 13px; color: var(--ink-3);
  padding: 7px 11px; border-radius: var(--radius);
  letter-spacing: .02em; position: relative;
  transition: color .18s ease;
}
.nav-btn:hover { color: var(--ink); }
.nav-btn.is-active { color: var(--ink); font-weight: 600; }
.nav-btn.is-active::after {
  content: ""; position: absolute; left: 11px; right: 11px; bottom: 1px;
  height: 2px; background: var(--red);
}

/* on phones the nav drops to a fixed bottom bar — thumb reach */
@media (max-width: 640px) {
  /* backdrop-filter makes an element a containing block for position:fixed
   * descendants, which would pin the nav to the header instead of the screen.
   * Drop the blur here; the bar is solid enough without it. */
  .masthead { backdrop-filter: none; background: var(--paper); }
  .masthead-inner { padding-bottom: 12px; }
  .nav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
    background: color-mix(in srgb, var(--paper) 94%, transparent);
    backdrop-filter: blur(14px);
    border-top: 1px solid var(--edge);
    padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
    justify-content: space-around; gap: 0;
  }
  .nav-btn { flex: 1; padding: 10px 4px; font-size: 12px; }
  .nav-btn.is-active::after { left: 22%; right: 22%; bottom: 4px; }
  body { padding-bottom: calc(74px + env(safe-area-inset-bottom)); }
}

/* ─────────── layout ─────────── */

.sheet { max-width: 940px; margin: 0 auto; padding: var(--pad); }

.view { display: none; animation: rise .34s cubic-bezier(.2,.7,.3,1) both; }
.view.is-active { display: block; }

@keyframes rise {
  from { opacity: 0; transform: translateY(9px); }
  to   { opacity: 1; transform: none; }
}

/* ─────────── the balance plate ─────────── */

.plate {
  position: relative;
  background: var(--paper-2);
  border: 1px solid var(--edge);
  border-left: 3px double var(--red);
  padding: 22px var(--pad) 20px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-lift);
  overflow: hidden;
}
.plate::after { /* engraved corner tick */
  content: ""; position: absolute; top: 10px; right: 10px;
  width: 16px; height: 16px;
  border-top: 1px solid var(--edge); border-right: 1px solid var(--edge);
}
.plate-label {
  font-size: 11px; letter-spacing: .2em; text-transform: uppercase;
  color: var(--ink-3); margin-bottom: 6px;
}
.plate-figure {
  font-family: var(--display);
  font-size: clamp(46px, 13vw, 76px);
  font-weight: 600; line-height: .95; letter-spacing: -.03em;
  font-variant-numeric: tabular-nums;
  font-variation-settings: "SOFT" 0, "WONK" 0;
}
.plate-figure.is-neg { color: var(--red); }
/* keeps clear of the SETTLED stamp in the bottom-right corner */
.plate-meta { font-size: 13px; color: var(--ink-3); margin-top: 8px; padding-right: 116px; }

.plate-stamp {
  position: absolute; right: 16px; bottom: 12px;
  font-family: var(--display); font-size: 15px; font-weight: 700;
  letter-spacing: .18em; color: var(--green);
  border: 2px solid var(--green); border-radius: 2px;
  padding: 3px 10px; transform: rotate(-6deg); opacity: .8;
}

/* ─────────── cards ─────────── */

.card {
  background: var(--paper-2);
  border: 1px solid var(--edge);
  box-shadow: var(--shadow-card);
  padding: var(--pad);
  margin-bottom: 20px;
}
.card-entry { border-left: 3px double var(--red); }

.card-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 14px;
  padding-bottom: 10px; border-bottom: 1px solid var(--rule);
}
.card-title {
  margin: 0; font-family: var(--display); font-size: 19px; font-weight: 600;
  letter-spacing: -.01em;
}
.note, .hint {
  font-size: 13px; color: var(--ink-3); margin: 0 0 14px;
  line-height: 1.45;
}

/* ─────────── entry lines ─────────── */

.lines { display: flex; flex-direction: column; }

.line {
  display: grid;
  /* The middle column carries the + button and the input; the amount column is
     tight because it only ever shows four or five digits. */
  grid-template-columns: 1fr 150px 66px;
  align-items: center; gap: 10px;
  padding: 9px 0;
  border-bottom: 1px solid var(--rule-soft);
  animation: rise .3s cubic-bezier(.2,.7,.3,1) both;
}
.line-name { min-width: 0; }
.line-item {
  font-weight: 500; font-size: 15px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.line-rate {
  font-family: var(--mono); font-size: 11.5px; color: var(--ink-3);
  letter-spacing: -.01em;
}
.line.is-theirs .line-item { color: var(--red); }
.line.is-theirs .line-item::before { content: "− "; font-family: var(--mono); }

.qty-cell { display: flex; align-items: center; gap: 6px; min-width: 0; }
.qty-stack { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }

.qty-plus {
  flex: none; width: 32px; height: 39px;
  font-family: var(--mono); font-size: 18px; line-height: 1;
  color: var(--ink-3); background: transparent;
  border: 1px dashed var(--edge); border-radius: var(--radius);
  cursor: pointer;
  transition: color .16s ease, border-color .16s ease, background .16s ease;
}
.qty-plus:hover { color: var(--ink); border-color: var(--ink-2); }
.qty-plus:active { background: var(--paper-3); }
.line.is-theirs .qty-plus:hover { color: var(--red); border-color: var(--red); }

/* The resolved total, shown only while the box holds arithmetic. */
.qty-sum {
  font-family: var(--mono); font-size: 11.5px;
  text-align: right; color: var(--brass);
  font-variant-numeric: tabular-nums;
}

.qty {
  width: 100%; text-align: right;
  font-family: var(--mono); font-size: 17px; font-weight: 500;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--edge);
  border-radius: var(--radius);
  padding: 9px 10px;
  transition: border-color .16s ease, box-shadow .16s ease;
}
.qty:focus {
  outline: none; border-color: var(--ink-2);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--brass) 24%, transparent);
}
.line.is-theirs .qty:focus {
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--red) 20%, transparent);
}
.qty.is-expr { font-size: 13.5px; }
.qty.is-bad { border-color: var(--red); color: var(--red); }
.qty.is-bad:focus {
  border-color: var(--red);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--red) 22%, transparent);
}
.line-amount {
  text-align: right; font-family: var(--mono); font-size: 14px;
  font-variant-numeric: tabular-nums; color: var(--ink-2);
}
.line.is-theirs .line-amount { color: var(--red); }

/* ─────────── tally ─────────── */

.tally { margin-top: 14px; padding-top: 4px; }
.tally-row {
  display: flex; justify-content: space-between; align-items: baseline;
  padding: 6px 0; font-size: 14px; color: var(--ink-2);
}
.tally-row .num {
  font-family: var(--mono); font-variant-numeric: tabular-nums;
  font-weight: 500; color: var(--ink);
}
.tally-row.is-theirs, .tally-row.is-theirs .num { color: var(--red); }
.tally-row.is-net {
  margin-top: 6px; padding-top: 12px;
  border-top: 2px solid var(--ink);
  font-size: 15px; font-weight: 600; color: var(--ink);
}
.tally-row.is-net .num {
  font-family: var(--display); font-size: 27px; font-weight: 600;
  letter-spacing: -.02em;
}

.entry-status {
  font-size: 12.5px; color: var(--brass);
  border-left: 2px solid var(--brass); padding: 4px 0 4px 10px;
  margin-bottom: 12px;
}

/* ─────────── buttons ─────────── */

.card-actions { display: flex; gap: 10px; margin-top: 18px; flex-wrap: wrap; }

.btn {
  appearance: none; cursor: pointer;
  font-family: var(--body); font-size: 14.5px; font-weight: 500;
  padding: 12px 20px; border-radius: var(--radius);
  border: 1px solid var(--edge); background: var(--paper);
  color: var(--ink);
  transition: transform .1s ease, box-shadow .18s ease, background .18s ease;
}
.btn:active { transform: translateY(1px); }

.btn-ink {
  background: var(--ink); color: var(--paper); border-color: var(--ink);
  box-shadow: 0 6px 16px -12px var(--ink);
}
.btn-ink:hover { background: color-mix(in srgb, var(--ink) 88%, var(--brass)); }
.btn-ink:disabled { opacity: .45; cursor: default; }

.btn-quiet:hover { background: var(--paper-3); }
.btn-wide { width: 100%; }
.btn-add { width: 100%; margin-top: 10px; border-style: dashed; color: var(--ink-3); }

.btn-close-cycle {
  appearance: none; cursor: pointer; width: 100%;
  background: none; border: 1px dashed var(--red); color: var(--red);
  font-family: var(--body); font-size: 14px;
  padding: 14px; border-radius: var(--radius);
  letter-spacing: .04em;
  transition: background .18s ease;
}
.btn-close-cycle:hover { background: color-mix(in srgb, var(--red) 8%, transparent); }

/* ─────────── day list ─────────── */

.section-head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 12px; margin: 26px 0 10px;
}
.section-title {
  margin: 0; font-family: var(--display); font-size: 17px; font-weight: 600;
}
.section-note { font-size: 12px; color: var(--ink-3); }

.daylist { list-style: none; margin: 0 0 20px; padding: 0; }

.day {
  display: grid;
  grid-template-columns: 88px 1fr auto;
  align-items: center; gap: 12px;
  padding: 13px 12px;
  background: var(--paper-2);
  border: 1px solid var(--edge);
  border-left: 3px solid transparent;
  margin-bottom: 6px;
  cursor: pointer;
  animation: rise .3s cubic-bezier(.2,.7,.3,1) both;
  transition: border-left-color .18s ease, background .18s ease;
}
.day:hover { border-left-color: var(--brass); background: var(--paper-3); }
.day.is-editing { border-left-color: var(--red); }

.day-date {
  font-family: var(--mono); font-size: 13px; font-weight: 500;
  letter-spacing: -.02em; color: var(--ink-2);
}
.day-lines {
  font-family: var(--mono); font-size: 11.5px; color: var(--ink-3);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.day-figs { text-align: right; display: flex; flex-direction: column; gap: 1px; }
.day-net {
  font-family: var(--mono); font-size: 15px; font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.day-run { font-family: var(--mono); font-size: 11px; color: var(--ink-3); }

.empty {
  font-size: 14px; color: var(--ink-3); text-align: center;
  padding: 26px 0; font-style: italic;
}

/* ─────────── send / export ─────────── */

.presets { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.layouts {
  display: flex; gap: 8px; flex-wrap: wrap;
  margin: 0 0 16px; padding-top: 14px; border-top: 1px solid var(--rule-soft);
}
.chip {
  appearance: none; cursor: pointer;
  background: var(--paper); border: 1px solid var(--edge); color: var(--ink-2);
  font-family: var(--body); font-size: 13px;
  padding: 8px 14px; border-radius: 100px;
  transition: all .16s ease;
}
.chip:hover { border-color: var(--ink-3); color: var(--ink); }
.chip.is-on { background: var(--ink); color: var(--paper); border-color: var(--ink); }

.range { display: flex; align-items: flex-end; gap: 12px; margin-bottom: 16px; }
.range-arrow { color: var(--ink-3); padding-bottom: 12px; }

.field { display: flex; flex-direction: column; gap: 5px; flex: 1; min-width: 0; margin-bottom: 12px; }
.field-label {
  font-size: 11px; letter-spacing: .14em; text-transform: uppercase; color: var(--ink-3);
}
.field input, .date-input {
  font-family: var(--mono); font-size: 15px; color: var(--ink);
  background: var(--paper); border: 1px solid var(--edge);
  border-radius: var(--radius); padding: 10px 12px;
  width: 100%;
}
.date-input { width: auto; font-size: 13.5px; padding: 8px 10px; }
.field input:focus, .date-input:focus {
  outline: none; border-color: var(--ink-2);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--brass) 24%, transparent);
}

.toggles { display: flex; flex-direction: column; gap: 10px; }
.switch { display: flex; align-items: center; gap: 10px; font-size: 14px; color: var(--ink-2); cursor: pointer; }
.switch input { width: 17px; height: 17px; accent-color: var(--red); }

.preview-wrap { margin-bottom: 18px; }
.preview-label {
  font-size: 11px; letter-spacing: .2em; text-transform: uppercase;
  color: var(--ink-3); margin-bottom: 8px;
}
.preview {
  background: var(--paper-3);
  border: 1px solid var(--edge);
  padding: 14px;
  max-height: 62vh; overflow-y: auto;
  box-shadow: inset 0 2px 12px -8px rgba(0,0,0,.5);
}
.preview canvas {
  display: block; width: 100%; height: auto;
  box-shadow: 0 14px 34px -22px rgba(23,21,15,.8);
}

.send-actions { display: flex; flex-direction: column; gap: 10px; }
.send-row { display: flex; gap: 10px; }
.send-row .btn { flex: 1; }

/* ─────────── rates ─────────── */

.itemrows { display: flex; flex-direction: column; gap: 8px; }
.itemrow {
  display: grid;
  grid-template-columns: 1fr 84px 104px 34px;
  gap: 8px; align-items: center;
}
.itemrow input, .itemrow select {
  font-family: var(--body); font-size: 14px; color: var(--ink);
  background: var(--paper); border: 1px solid var(--edge);
  border-radius: var(--radius); padding: 9px 10px; width: 100%;
}
.itemrow input[data-k="rate"] { font-family: var(--mono); text-align: right; }
.itemrow input:focus, .itemrow select:focus { outline: none; border-color: var(--ink-2); }
.itemrow-del {
  appearance: none; cursor: pointer; background: none;
  border: 1px solid var(--edge); border-radius: var(--radius);
  color: var(--ink-3); font-size: 16px; line-height: 1; padding: 8px 0;
}
.itemrow-del:hover { color: var(--red); border-color: var(--red); }

/* ─────────── settlements ─────────── */

.settlelist { list-style: none; margin: 0; padding: 0; }
.settle {
  display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: center;
  padding: 14px 0; border-bottom: 1px solid var(--rule-soft);
}
.settle-date { font-family: var(--mono); font-size: 13.5px; font-weight: 500; }
.settle-sub { font-size: 12px; color: var(--ink-3); margin-top: 2px; }
.settle-amt {
  font-family: var(--display); font-size: 21px; font-weight: 600;
  color: var(--green); text-align: right;
}
.settle-carry { font-size: 11.5px; color: var(--red); text-align: right; }
.settle-del {
  appearance: none; background: none; border: 0; cursor: pointer;
  color: var(--ink-3); font-size: 11px; text-decoration: underline;
  padding: 0; margin-top: 4px;
}
.settle-del:hover { color: var(--red); }

/* ─────────── modal ─────────── */

.modal {
  border: 1px solid var(--edge); border-top: 3px double var(--red);
  background: var(--paper-2); color: var(--ink);
  padding: 0; max-width: 400px; width: calc(100% - 32px);
  box-shadow: 0 40px 80px -40px rgba(0,0,0,.7);
}
.modal::backdrop { background: rgba(23,21,15,.55); backdrop-filter: blur(3px); }
.modal-card { padding: var(--pad); }
.modal-title { margin: 0 0 6px; font-family: var(--display); font-size: 21px; font-weight: 600; }
.modal-note { font-size: 13px; color: var(--ink-3); margin: 0 0 16px; }
.modal-carry {
  font-size: 13px; color: var(--ink-2); margin: 4px 0 0;
  padding: 10px 12px; background: var(--paper-3); border-left: 2px solid var(--brass);
}
.modal-actions { display: flex; gap: 10px; margin-top: 18px; }
.modal-actions .btn { flex: 1; }

/* ─────────── gate ─────────── */

.gate {
  position: fixed; inset: 0; z-index: 20;
  display: grid; place-items: center; padding: 24px;
  background: var(--paper);
}
.gate-card {
  width: 100%; max-width: 330px;
  background: var(--paper-2); border: 1px solid var(--edge);
  border-left: 3px double var(--red);
  padding: 30px 26px; box-shadow: var(--shadow-card);
}
.gate-mark {
  font-family: var(--display); font-size: 24px; font-weight: 600;
  margin-bottom: 22px; letter-spacing: -.02em;
}
.gate-card .btn { width: 100%; margin-top: 6px; }
.gate-error { color: var(--red); font-size: 13px; margin: 12px 0 0; }

/* ─────────── toast ─────────── */

.toast {
  position: fixed; z-index: 30;
  left: 50%; bottom: calc(88px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--ink); color: var(--paper);
  font-size: 13.5px; padding: 11px 18px; border-radius: var(--radius);
  box-shadow: 0 18px 40px -20px rgba(0,0,0,.8);
  animation: toastIn .26s cubic-bezier(.2,.7,.3,1) both;
  max-width: calc(100% - 40px); text-align: center;
}
.toast.is-bad { background: var(--red); }
@media (min-width: 641px) { .toast { bottom: 28px; } }
@keyframes toastIn {
  from { opacity: 0; transform: translate(-50%, 10px); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
