:root {
  --paper: #f4f1ea;
  --card: #fffcf7;
  --ink: #1c1915;
  --muted: #5e574c;
  --line: #e2d9cc;
  --teal: #0e4f4a;
  --teal-soft: #e5f1ef;
  --good: #1b5e34;
  --good-soft: #e5f3ea;
  --bad: #8a2e2e;
  --bad-soft: #f8e8e6;
  --shadow: 0 1px 0 rgba(28, 25, 21, 0.04);
  font-family: "Avenir Next", "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--paper);
}

* { box-sizing: border-box; }
body {
  margin: 0 auto;
  max-width: 1040px;
  padding: 32px 20px 64px;
}
h1, h2, p { margin: 0; }
h1 { font-size: 32px; font-weight: 650; letter-spacing: -0.03em; }
h2 { font-size: 18px; font-weight: 650; }
table { width: 100%; border-collapse: collapse; }
button, input { font: inherit; }

.top { display: grid; gap: 10px; margin-bottom: 22px; }
.title-row { display: flex; justify-content: space-between; align-items: end; gap: 16px; }
#pdf-toggle, .viewer-nav button {
  border: 1px solid var(--line);
  background: white;
  border-radius: 999px;
  padding: 6px 12px;
  cursor: pointer;
}
.eyebrow {
  color: var(--teal);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}
.lede { max-width: 62ch; color: var(--muted); line-height: 1.45; }

.drop {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 18px;
  border: 1.5px dashed #b7aa96;
  border-radius: 14px;
  background: rgba(255, 252, 247, 0.7);
}
.drop strong { display: block; }
.drop span { color: var(--muted); font-size: 14px; }
.drop input { max-width: 220px; }
.drop.over { border-color: var(--teal); background: var(--teal-soft); }
.status { margin: 14px 0; color: var(--muted); }
.stack { display: grid; gap: 16px; margin-top: 18px; }
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 16px 18px 18px;
}
.banner {
  border-radius: 14px;
  padding: 14px 16px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: baseline;
}
.banner.good { background: var(--good-soft); color: var(--good); }
.banner.bad { background: var(--bad-soft); color: var(--bad); }
.banner strong { font-size: 16px; }
.meta {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px 18px;
}
.meta div { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.meta span, .muted { color: var(--muted); font-size: 12px; letter-spacing: 0.04em; text-transform: uppercase; }
.meta strong { font-size: 15px; line-height: 1.35; }
.meta strong, .num { font-variant-numeric: tabular-nums; font-weight: 650; }
.card-head {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 12px;
  margin-bottom: 10px;
}
.card-head p { color: var(--muted); font-size: 14px; max-width: 62ch; }
th, td {
  text-align: left;
  padding: 11px 10px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
  font-size: 14.5px;
  line-height: 1.4;
}
th { color: var(--muted); font-size: 12px; font-weight: 650; letter-spacing: 0.04em; text-transform: uppercase; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tbody tr.stripe td { background: #f6f2ea; }
tr.total td { font-weight: 700; border-bottom: 0; background: transparent; }
tr.section-break td {
  padding: 18px 10px 6px;
  border-bottom: 0;
  background: transparent;
  color: var(--teal);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
tr.section-break:first-child td { padding-top: 2px; }
.lines td.kicker, .lines td.who { white-space: nowrap; }
.reason { color: #3f382f; line-height: 1.45; min-width: 220px; }
.actions { display: flex; gap: 8px; }
.actions button, .ghost {
  border: 1px solid var(--line);
  background: white;
  border-radius: 999px;
  padding: 6px 12px;
  cursor: pointer;
}
.warn { margin: 8px 0 0; color: var(--bad); line-height: 1.4; }
.checks { margin: 16px 0 0; padding: 0; list-style: none; display: grid; gap: 6px; }
.checks li {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 4px 16px;
  padding: 8px 12px;
  border-radius: 10px;
  line-height: 1.35;
}
.checks .check-name { flex: 1 1 200px; }
.checks .check-fig { font-variant-numeric: tabular-nums; font-weight: 650; white-space: nowrap; }
.checks li.ok { color: var(--good); background: var(--good-soft); }
.checks li.bad { color: var(--bad); background: var(--bad-soft); }

.linked { cursor: pointer; }
tbody tr.linked:hover td, .meta .linked:hover { background: #efeae1; }
tbody tr.linked.selected td, .meta .linked.selected { background: var(--teal-soft); }
.checks li.linked { cursor: pointer; }
.checks li.linked.selected { outline: 2px solid currentColor; outline-offset: -2px; }

.workspace { display: block; }
#out {
  min-width: 0;
  container-type: inline-size;
  container-name: results;
}
.card { overflow-x: auto; }
body.viewer-open { max-width: none; }
body.resizing { cursor: ew-resize; user-select: none; }
#viewer[hidden] { display: none !important; }
#viewer {
  position: fixed;
  z-index: 20;
  top: 12px;
  right: 12px;
  width: var(--viewer-w, min(46vw, 720px));
  height: calc(100vh - 24px);
  display: flex;
  flex-direction: column;
  background: #2a2824;
  color: #f4f1ea;
  border-radius: 14px;
  overflow: hidden;
  box-shadow: 0 12px 40px rgba(28, 25, 21, 0.28);
}
body.viewer-open {
  padding-right: calc(var(--viewer-w, min(46vw, 720px)) + 28px);
}
#viewer-resize {
  position: absolute;
  z-index: 3;
  left: 0;
  top: 0;
  bottom: 0;
  width: 14px;
  cursor: ew-resize;
  touch-action: none;
}
#viewer-resize::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 5px;
  width: 3px;
  height: 42px;
  margin-top: -21px;
  border-radius: 99px;
  background: rgba(244, 241, 234, 0.5);
}
.viewer-bar {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: start;
  padding: 12px 12px 8px 18px;
}
.viewer-bar p { color: #cfc6b8; font-size: 13px; margin-top: 2px; }
.viewer-nav { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.viewer-nav button { background: #3a372f; color: #f4f1ea; border-color: #5c564c; }
.viewer-nav button[hidden] { display: none; }
#viewer-scroll {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 0 10px 12px;
  cursor: grab;
  touch-action: none;
}
#viewer-scroll.dragging { cursor: grabbing; user-select: none; }
#zoom-fit { min-width: 52px; }
#viewer-stage { position: relative; width: fit-content; }
#viewer-marks { position: absolute; inset: 0; }
.hl {
  position: absolute;
  background: rgba(242, 184, 75, 0.28);
  border: 2px solid #c47d12;
  border-radius: 3px;
  pointer-events: none;
}
.hl.active {
  background: rgba(242, 184, 75, 0.5);
  border-color: #8a4b00;
  box-shadow: 0 0 0 3px rgba(242, 184, 75, 0.35);
}

@container results (max-width: 640px) {
  .card { overflow: visible; }
  .banner { flex-direction: column; align-items: start; }
  .card-head { flex-direction: column; align-items: start; }
  .meta { grid-template-columns: 1fr 1fr; gap: 8px; }
  .meta div {
    background: #fbf8f3;
    border: 1px solid var(--line);
    border-radius: 16px;
    padding: 10px 12px;
  }
  .stack table { display: block; min-width: 0; }
  .stack thead { display: none; }
  .stack tbody { display: grid; gap: 10px; }
  .stack tr {
    display: flex;
    flex-direction: column;
    gap: 7px;
    padding: 12px 14px;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: #fbf8f3;
  }
  .stack td {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 12px;
    border: 0;
    padding: 0;
    font-size: 14px;
  }
  .stack td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 11px;
    font-weight: 650;
    letter-spacing: 0.06em;
    text-transform: uppercase;
  }
  .stack td.lead {
    font-size: 18px;
    font-weight: 700;
  }
  .stack td.lead::before { content: none; }
  .stack td.kicker {
    color: var(--teal);
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
  }
  .stack td.kicker::before { content: none; }
  .stack td.who { font-size: 18px; font-weight: 700; }
  .stack td.who::before { content: none; }
  .stack td.paid { font-size: 16px; }
  .stack td.reason { display: block; color: var(--ink); }
  .stack td.reason::before { display: block; margin-bottom: 3px; }
  .stack tr.stripe { background: #f3efe6; }
  .stack tr.section-break {
    display: block;
    padding: 6px 2px 0;
    border: 0;
    border-radius: 0;
    background: transparent;
  }
  .stack tr.section-break td {
    display: block;
    padding: 0;
    color: var(--teal);
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
  }
  .stack tr.section-break td::before { content: none; }
  .stack tr.linked:hover td,
  .stack tr.linked.selected td { background: transparent; }
  .stack tr.linked.selected {
    background: var(--teal-soft);
    border-color: #9ec9c4;
  }
  .stack tr.total {
    background: var(--teal);
    color: #f4f1ea;
    border-color: var(--teal);
  }
  .stack tr.total td::before { color: rgba(244, 241, 234, 0.72); }
  .checks li { border-radius: 14px; }
}

@container results (max-width: 380px) {
  .meta { grid-template-columns: 1fr; }
}

@media (max-width: 720px) {
  body { padding: 18px 14px 40px; }
  h1 { font-size: 28px; }
  .drop { flex-direction: column; align-items: stretch; }
  .drop input { max-width: none; width: 100%; }
  .title-row { align-items: start; }
  #viewer {
    top: auto;
    right: 0;
    bottom: 0;
    left: 0;
    width: 100%;
    height: var(--viewer-h, 68vh);
    border-radius: 18px 18px 0 0;
  }
  body.viewer-open {
    padding-right: 14px;
    padding-bottom: calc(var(--viewer-h, 68vh) + 12px);
  }
  body.resizing { cursor: ns-resize; }
  #viewer-resize {
    left: 0;
    right: 0;
    top: 0;
    bottom: auto;
    width: 100%;
    height: 18px;
    cursor: ns-resize;
  }
  #viewer-resize::before {
    top: 8px;
    left: 50%;
    width: 42px;
    height: 4px;
    margin: 0 0 0 -21px;
  }
  .viewer-bar { padding: 18px 12px 8px; }
}
