:root {
  --paper: #efe6d4;
  --card: #fffdf8;
  --ink: #1d2430;
  --muted: #5c6570;
  --line: #e2d8c4;
  --teal: #0d5c56;
  --teal-ink: #f4fffc;
  --warn: #fff3c4;
  --warn-line: #c4921a;
  --danger: #8e2e2e;
  --danger-bg: #fde8e4;
  --ok: #1d6b45;
  --shadow: 0 10px 30px rgba(60, 42, 20, 0.08);
  font-family: "Segoe UI", "Helvetica Neue", system-ui, sans-serif;
  color: var(--ink);
  background: var(--paper);
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; }
a { color: var(--teal); }
img { max-width: 100%; height: auto; display: block; }
h1 { font-family: Georgia, "Iowan Old Style", serif; font-weight: 600; font-size: 1.7rem; margin: 0.2rem 0 0.4rem; letter-spacing: -0.02em; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }

.top, main, footer { width: min(960px, calc(100% - 1.5rem)); margin: 0 auto; }
.top { display: flex; align-items: center; justify-content: space-between; padding: 0.9rem 0; gap: 1rem; }
.mark { color: var(--ink); text-decoration: none; font-weight: 700; letter-spacing: 0.01em; }
.mark span { color: var(--teal); font-weight: 600; }
nav { display: flex; gap: 0.9rem; align-items: center; }
nav a, button.link { background: none; border: 0; padding: 0; color: var(--teal); text-decoration: none; font-weight: 600; }
nav form { margin: 0; }
main { padding-bottom: 2rem; }
footer { color: var(--muted); font-size: 0.82rem; padding: 1.5rem 0 2rem; }

.card, .line, .ledger a { background: var(--card); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); }
.card { padding: 1.1rem 1.1rem 1.3rem; }
.narrow { max-width: 28rem; }
.kicker { text-transform: uppercase; letter-spacing: 0.14em; font-size: 0.72rem; color: var(--teal); font-weight: 700; margin: 0; }
.lead { color: var(--muted); margin-top: 0; }
.stack { display: flex; flex-direction: column; gap: 0.85rem; }
label { display: flex; flex-direction: column; gap: 0.3rem; font-size: 0.92rem; font-weight: 600; }
label em { font-style: normal; font-weight: 700; color: #8a6410; font-size: 0.75rem; letter-spacing: 0.04em; text-transform: uppercase; }
input, select {
  min-height: 48px;
  border: 1px solid #d9cdb6;
  border-radius: 10px;
  padding: 0.55rem 0.7rem;
  background: #fff;
  font-weight: 500;
}
input:focus, select:focus { outline: 2px solid var(--teal); border-color: var(--teal); }
.is-low > input, .is-low > select, .line.is-low { background: var(--warn); border-color: var(--warn-line); }

.primary, .secondary, .primary.small {
  min-height: 48px;
  border: 0;
  border-radius: 12px;
  padding: 0.7rem 1rem;
  font-weight: 700;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.primary { background: var(--teal); color: var(--teal-ink); }
.secondary { background: transparent; color: var(--teal); border: 1.5px solid var(--teal); }
.primary.small { min-height: 40px; padding: 0.4rem 0.8rem; }
.danger { color: var(--danger); }

.file input { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.file-face {
  display: flex; flex-direction: column; justify-content: center; min-height: 7.5rem;
  border: 1.5px dashed var(--teal); border-radius: 16px; padding: 1rem;
  background: #f3faf8; text-align: center; gap: 0.25rem;
}
.file-face small { color: var(--muted); font-weight: 500; }
.file input:focus + .file-face { outline: 2px solid var(--teal); }

.alert { background: var(--danger-bg); color: var(--danger); border-radius: 12px; padding: 0.75rem 0.9rem; }
.alert.warn { background: var(--warn); color: #6d5310; }
.alert p { margin: 0.2rem 0; }
.hint { color: var(--muted); font-size: 0.85rem; margin: 0.2rem 0; }

.fields, .rx { display: grid; grid-template-columns: 1fr 1fr; gap: 0.7rem; min-width: 0; }
.fields > *, .rx > *, .line, .split, .sheet, main { min-width: 0; max-width: 100%; }
input, select { width: 100%; min-width: 0; max-width: 100%; }
.wide { grid-column: 1 / -1; }
.split { display: flex; flex-direction: column; gap: 1rem; }
.sheet { margin: 0; background: #fff; border-radius: 16px; overflow: hidden; border: 1px solid var(--line); }
.line { padding: 0.85rem; margin: 0.6rem 0; }
.line header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.5rem; }
.row-title { display: flex; justify-content: space-between; align-items: center; gap: 0.8rem; }

.filters, .totals { display: grid; gap: 0.7rem; margin: 0.8rem 0 1rem; }
.filters { grid-template-columns: 1fr; }
.filter-actions { display: flex; gap: 0.6rem; align-items: end; }
.filter-actions .secondary, .filter-actions .primary { flex: 1; }
.totals { grid-template-columns: 1fr 1fr; }
.totals div, .pay { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 0.7rem 0.8rem; }
.totals dt { color: var(--muted); font-size: 0.75rem; }
.totals dd { margin: 0.15rem 0 0; font-weight: 700; font-variant-numeric: tabular-nums; }
h2 { font-family: Georgia, "Iowan Old Style", serif; font-size: 1.25rem; margin: 0 0 0.6rem; }
.pays { list-style: none; padding: 0; margin: 0 0 0.8rem; display: flex; flex-direction: column; gap: 0.45rem; }
.pays li { display: flex; flex-wrap: wrap; gap: 0.35rem 0.7rem; align-items: baseline; }
.sisa { grid-column: 1 / -1; color: var(--muted); font-size: 0.85rem; }
.template-row {
  display: flex; flex-wrap: wrap; gap: 0.4rem 0.8rem; align-items: center; justify-content: space-between;
  background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 0.9rem 1rem;
}
.template-actions { display: flex; gap: 0.8rem; align-items: center; }
.template-actions form { margin: 0; }
.editor { display: flex; flex-direction: column; gap: 1rem; }
.stage { position: relative; background: #fff; border-radius: 16px; overflow: hidden; border: 1px solid var(--line); touch-action: none; }
.stage img { width: 100%; height: auto; display: block; }
.token-box {
  position: absolute; border: 1px solid rgba(13, 92, 86, 0.85);
  background: rgba(13, 92, 86, 0.14); padding: 0; min-height: 0;
}
.token-box.is-selected { background: rgba(224, 184, 74, 0.55); border-color: #8a6410; z-index: 2; }
.drawn { position: absolute; border: 2px solid var(--danger); background: rgba(142, 46, 46, 0.15); pointer-events: none; }
.plain { list-style: none; padding: 0; margin: 0.3rem 0 0.6rem; }
.plain li { display: flex; justify-content: space-between; gap: 0.5rem; padding: 0.25rem 0; }
.check { flex-direction: row; align-items: center; gap: 0.5rem; font-weight: 600; }
.check input { min-height: 0; width: auto; }
textarea { min-height: 4.5rem; border: 1px solid #d9cdb6; border-radius: 10px; padding: 0.55rem 0.7rem; font: inherit; }
.ledger { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 0.7rem; }
.ledger a {
  display: grid; grid-template-columns: 1fr auto; gap: 0.15rem 0.8rem;
  padding: 0.9rem 1rem; text-decoration: none; color: inherit;
}
.who { font-weight: 700; }
.num, .when { color: var(--muted); font-size: 0.9rem; }
.money { font-variant-numeric: tabular-nums; font-weight: 700; text-align: right; }
.badge {
  justify-self: end; align-self: center; font-size: 0.75rem; font-weight: 700;
  border-radius: 999px; padding: 0.25rem 0.55rem; background: var(--warn); color: #6d5310;
}
.badge-lunas { background: #e5f6ec; color: var(--ok); }
.badge-sebagian { background: #e7f1fb; color: #1d4e89; }
.facts { display: grid; grid-template-columns: 1fr 1fr; gap: 0.7rem; margin: 1rem 0; }
.facts div { background: var(--card); border-radius: 12px; padding: 0.6rem 0.75rem; border: 1px solid var(--line); }
.facts dt { color: var(--muted); font-size: 0.75rem; }
.facts dd { margin: 0.15rem 0 0; font-weight: 700; }
.rx-read, .money-line { margin: 0.25rem 0; }
.money-line { font-variant-numeric: tabular-nums; }

@media (max-width: 520px) {
  .fields, .facts { grid-template-columns: 1fr; }
  .ledger a { grid-template-columns: 1fr; }
  .money, .badge { justify-self: start; }
}

@media (min-width: 720px) {
  .filters { grid-template-columns: 1.2fr 1fr 0.8fr 0.7fr 0.7fr auto; align-items: end; }
  .totals { grid-template-columns: repeat(4, 1fr); }
  .filter-actions { flex-direction: column; }
}
@media (min-width: 860px) {
  .editor { display: grid; grid-template-columns: 1.15fr 0.85fr; align-items: start; }
  .stage { position: sticky; top: 0.6rem; }
  .split { display: grid; grid-template-columns: 0.9fr 1.1fr; align-items: start; }
  .sheet { position: sticky; top: 0.8rem; }
  .fields { grid-template-columns: 1fr 1fr; }
}
