:root {
  color-scheme: light;
  font: 14px/1.55 system-ui, "Segoe UI", sans-serif;
  --ink: #202824;
  --secondary: #46514b;
  --muted: #616a64;
  --canvas: #f5f6f3;
  --paper: #fff;
  --quiet: #f5f7f4;
  --line: #dce3dd;
  --green: #246140;
  --green-dark: #194d32;
  --green-soft: #edf5ee;
  --warning: #724a21;
  --warning-bg: #fbf2e6;
  --error: #85433e;
  --error-bg: #f9edeb;
  --measure: 1440px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--canvas); color: var(--ink); }
button, input, select { font: inherit; }
button, a, input, select { -webkit-tap-highlight-color: transparent; }
button {
  min-height: 40px; padding: 8px 12px; color: var(--ink); background: var(--paper);
  border: 1px solid var(--line); border-radius: 8px; cursor: pointer; font-weight: 600;
  transition: background-color 140ms ease, border-color 140ms ease, color 140ms ease;
}
button:hover { background: var(--quiet); border-color: #a8b8aa; }
button:disabled { opacity: .62; cursor: default; }
.primary { background: var(--green); border-color: var(--green); color: white; }
.primary:hover { background: var(--green-dark); border-color: var(--green-dark); }
:focus-visible { outline: 2px solid var(--green); outline-offset: 3px; }
a { color: var(--green-dark); text-underline-offset: 3px; overflow-wrap: anywhere; }
h1, h2, h3, h4, p { margin: 0; }
h1 { font-size: clamp(24px, 3vw, 32px); font-weight: 650; line-height: 1.15; }
h2 { font-size: clamp(18px, 2vw, 22px); font-weight: 650; line-height: 1.28; }
h3 { font-size: 16px; font-weight: 650; }
h4 { font-size: 16px; font-weight: 650; line-height: 1.4; }
p { overflow-wrap: anywhere; }
.small { font-size: 12px; }
.small, .muted { color: var(--muted); }
.number, .record-number, .card-facts b { font-variant-numeric: tabular-nums; }

.bar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 24px;
  min-height: 60px; padding: 8px max(24px, calc((100% - var(--measure))/2 + 24px));
  background: #202824; color: #f5f7f4;
}
.top { display: flex; flex: none; gap: 12px; align-items: center; }
.brand-logo { display: block; width: 112px; height: auto; }
.product-name { color: #c9d2ca; font-size: 12px; white-space: nowrap; }
.bar nav { display: flex; gap: 4px; min-width: 0; }
.bar nav button, .bar .exit { min-height: 36px; border-color: transparent; color: #e8eee9; background: transparent; white-space: nowrap; }
.bar nav button:hover, .bar nav button[aria-current=page], .bar .exit:hover { background: #36463c; color: #fff; }
.bar .exit { margin-left: auto; border-color: #526459; }
.bar :focus-visible { outline-color: #b5e0c0; }

main { width: min(var(--measure), 100%); margin-inline: auto; padding: 24px 24px 48px; }
.sheet { min-width: 0; border: 1px solid var(--line); border-radius: 12px; background: var(--paper); }
.heading { display: flex; justify-content: space-between; gap: 16px; align-items: center; margin-bottom: 16px; }
.heading p { margin-top: 4px; color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.filters { display: grid; grid-template-columns: minmax(0,1.5fr) minmax(0,1fr) minmax(0,.56fr) minmax(0,.8fr); gap: 12px; padding: 12px; margin-bottom: 16px; }
label { font-size: 13px; font-weight: 600; }
.filters label, form label { display: grid; gap: 4px; min-width: 0; }
input, select {
  min-width: 0; max-width: 100%; width: 100%; min-height: 40px; padding: 8px 10px;
  color: var(--ink); background: var(--paper); border: 1px solid #c8d1c9; border-radius: 8px;
  font-weight: 450;
}
input::placeholder { color: var(--muted); opacity: 1; }
input[type=file] { padding: 6px; }
fieldset { min-width: 0; padding: 12px; border: 1px solid var(--line); border-radius: 8px; }
form { display: grid; gap: 12px; }
form button { justify-self: start; }
.notice { margin: 12px 0; padding: 12px; border: 1px solid #e8dac7; border-radius: 8px; color: var(--warning); background: var(--warning-bg); }
.empty { padding: 12px 0; color: var(--muted); }
.detail-empty { padding: 24px; }

.workspace { display: grid; grid-template-columns: minmax(300px, .84fr) minmax(0, 1.55fr); align-items: start; gap: 16px; }
.listing { position: sticky; top: 76px; }
.listing-head {
  display: flex; align-items: baseline; justify-content: space-between; padding: 12px 16px;
  border-bottom: 1px solid var(--line);
}
.listing-head h2 { font-size: 16px; }
.listing-body { max-height: calc(100dvh - 252px); min-height: 100px; overflow-y: auto; scrollbar-width: thin; }
.listing-body > .empty { padding: 16px; }
#more { margin: 8px 16px 12px; }
.card {
  display: grid; gap: 4px; width: 100%; min-height: 112px; padding: 12px 16px;
  border: 0; border-radius: 0; border-bottom: 1px solid var(--line); text-align: left;
  font-weight: 450; overflow-wrap: anywhere;
}
.card:last-child { border-bottom: 0; }
.card:hover { background: var(--quiet); }
.card:focus-visible { position: relative; z-index: 1; outline-offset: -3px; }
.card.selected { background: var(--green-soft); box-shadow: inset 3px 0 var(--green); }
.card strong { color: var(--ink); font-weight: 620; font-size: 14px; line-height: 1.38; }
.card-meta, .card-facts { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 8px; color: var(--muted); font-size: 12px; }
.card-facts { justify-content: space-between; }
.card-facts b { color: var(--ink); font-size: 13px; font-weight: 650; }
.card-buyer, .card-tags { color: var(--muted); font-size: 12px; }
.card-buyer { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-tags { color: var(--green-dark); }
.badge { display: inline-block; padding: 0 4px; border-radius: 4px; font-size: 12px; font-weight: 600; color: var(--secondary); background: #ebefea; }
.badge.good { color: var(--green-dark); background: #e4efe5; }
.badge.bad { color: var(--error); background: var(--error-bg); }
.badge.flag { color: var(--warning); background: var(--warning-bg); }

.detail { scroll-margin-top: 76px; }
.record-head { padding: 20px 24px 16px; }
.record-number { margin-bottom: 4px; color: var(--green-dark); font-size: 12px; }
.record-buyer { margin: 8px 0 16px; color: var(--secondary); font-size: 13px; }
.record-facts { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 0; border: 1px solid var(--line); border-radius: 8px; }
.record-facts .rowline { display: grid; justify-content: stretch; gap: 4px; padding: 8px 12px; border-bottom: 0; border-right: 1px solid var(--line); }
.record-facts .rowline:last-child { border-right: 0; }
.record-facts .rowline span { font-size: 12px; }
.record-facts .rowline strong { text-align: left; font-weight: 650; }
.record-actions { margin-top: 12px; }
.record-link { margin-left: auto; font-weight: 600; font-size: 13px; }
.record-nav { display: flex; overflow-x: auto; gap: 12px; padding: 0 24px; border-bottom: 1px solid var(--line); scrollbar-width: thin; }
.record-nav button { min-height: 40px; padding: 8px 4px; color: var(--secondary); background: transparent; border: 0; border-bottom: 2px solid transparent; border-radius: 0; white-space: nowrap; }
.record-nav button:hover { color: var(--green-dark); }
.record-nav button[aria-current=page] { color: var(--green-dark); border-bottom-color: var(--green); }
.record-nav :focus-visible { outline-offset: -2px; }
.record-body { padding: 20px 24px 24px; }
.record-section { min-width: 0; }
.record-section > h3 { margin-bottom: 8px; }
.record-section > h3:not(:first-child) { margin-top: 16px; }
.record-checks { margin: 8px 0 0; padding-left: 20px; color: var(--secondary); }
.mobile-back { display: none; }

.review-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.review-status {
  display: flex; align-items: baseline; justify-content: space-between; flex-wrap: wrap; gap: 4px 12px;
  margin-bottom: 12px; padding: 8px 12px; border-radius: 8px; background: var(--green-soft); color: var(--green-dark);
}
.review-status strong::before { content: ""; display: inline-block; width: 8px; height: 8px; margin-right: 8px; border-radius: 50%; background: currentColor; }
.review-status span { font-size: 12px; }
.review-status[data-state=running] { color: var(--secondary); background: var(--quiet); }
.review-status[data-state=error] { color: var(--error); background: var(--error-bg); }
.review-findings { display: grid; gap: 12px; margin-bottom: 12px; }
.review-findings:empty { display: none; }
.finding { padding: 12px 16px; border: 1px solid var(--line); border-radius: 8px; }
.finding-topic { margin-bottom: 4px; font-size: 12px; font-weight: 600; color: var(--green-dark); }
.finding blockquote { margin: 8px 0; padding: 4px 0 4px 12px; border-left: 2px solid #73957a; color: var(--secondary); overflow-wrap: anywhere; }
.finding-source { overflow-wrap: anywhere; }
.document-list { margin-bottom: 12px; }
.document-list p { padding: 8px 0; border-bottom: 1px solid var(--line); }
.attachment-status { display: block; margin-top: 3px; }
.document-list .attached-document { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.attached-document span { min-width: 0; overflow-wrap: anywhere; }
.attached-document button { flex: none; }
.document-add { display: flex; flex-wrap: wrap; align-items: end; gap: 8px; margin-bottom: 12px; }
.document-add label { flex: 1 1 240px; }
.document-report { margin-top: 16px; padding: 12px; background: var(--quiet); border-radius: 8px; }
.document-report pre { margin: 12px 0 0; }

.login, .settings { margin-inline: auto; padding: 24px; }
.login { width: min(100%,400px); margin-top: clamp(24px, 9vh, 96px); }
.settings { width: min(100%,780px); }
.login h1, .settings h1 { margin-bottom: 16px; }
.login .primary { width: 100%; }
.settings form, .settings .actions { margin: 12px 0; }
.settings + .settings { margin-top: 0; }
.block { margin: 16px 0 0; padding-top: 16px; border-top: 1px solid var(--line); }
.block:first-child { margin-top: 0; padding-top: 0; border-top: 0; }
.block h3, .block > p { margin-bottom: 8px; }
.actions, .two { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.two > * { flex: 1; min-width: 140px; }
.check { display: flex !important; align-items: start; gap: 8px; padding: 4px; }
.check input { width: 16px; height: 16px; min-height: 0; margin: 4px 0 0; accent-color: var(--green); }
.criteria { display: grid; grid-template-columns: minmax(0,1fr) minmax(0,.8fr) minmax(0,1fr) auto; gap: 4px; align-items: end; margin: 8px 0; }
.criteria button { min-width: 36px; padding-inline: 8px; }
.items { grid-template-columns: minmax(0,1.2fr) minmax(0,.55fr) minmax(0,.8fr) auto; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
td, th { padding: 8px; border-bottom: 1px solid var(--line); text-align: left; }
th { color: var(--secondary); font-size: 12px; }
.result, .entry { margin: 8px 0; padding: 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--quiet); }
.result { background: var(--green-soft); font-variant-numeric: tabular-nums; }
.result.bad { background: var(--warning-bg); color: var(--warning); }
.rowline { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.rowline strong { min-width: 0; text-align: right; overflow-wrap: anywhere; font-weight: 600; }
details > summary { cursor: pointer; font-weight: 650; }
pre { white-space: pre-wrap; overflow-wrap: anywhere; font: inherit; }
.scroll-anchor { scroll-margin-top: 76px; }

.logs-page { width: min(100%,1080px); }
.logs-page h1 { margin-bottom: 4px; }
.log-controls { display: grid; grid-template-columns: minmax(180px,1fr) minmax(190px,1fr) minmax(240px,1.2fr); gap: 12px; align-items: end; margin-bottom: 12px; }
.log-controls > label { display: grid; gap: 4px; }
.log-options { display: flex; flex-wrap: wrap; gap: 4px 12px; align-self: center; }
.log-output { min-height: 200px; max-height: 60vh; overflow: auto; margin: 0; padding: 12px 16px; border: 1px solid var(--line); border-radius: 8px; background: var(--quiet); font: 12px/1.6 ui-monospace, Consolas, monospace; }
.log-entry { display: block; overflow-wrap: anywhere; }
.log-issue { color: var(--warning); }
.log-empty { color: var(--muted); }

@media (max-width: 980px) { .product-name { display: none; } .bar { gap: 12px; } }
@media (max-width: 760px) {
  .bar { padding: 8px 12px; gap: 4px 8px; flex-wrap: wrap; }
  .bar nav { order: 3; flex-basis: 100%; gap: 4px; overflow-x: auto; scrollbar-width: thin; }
  .bar nav button { padding-inline: 4px; font-size: 12px; }
  main { padding: 16px 12px 32px; }
  .heading { gap: 8px; margin-bottom: 12px; }
  .heading p { font-size: 12px; }
  .filters { grid-template-columns: 1fr 1fr; gap: 8px; padding: 8px; margin-bottom: 12px; }
  .filters label:nth-child(-n+2) { grid-column: 1 / -1; }
  .workspace { display: block; }
  .listing { position: static; }
  .listing-body { max-height: none; }
  #home[data-view=detail] .listing, #home[data-view=detail] .heading, #home[data-view=detail] .filters { display: none; }
  #home:not([data-view=detail]) .detail { display: none; }
  .mobile-back { display: inline-block; margin-bottom: 8px; }
  .detail, .scroll-anchor { scroll-margin-top: 104px; }
  .record-head { padding: 12px; }
  .record-nav { padding: 0 12px; gap: 8px; }
  .record-nav button { font-size: 12px; }
  .record-body { padding: 12px; }
  .record-facts .rowline { padding: 8px; }
  .record-link { margin-left: 0; }
  .review-head { flex-wrap: wrap; }
  .rowline { flex-wrap: wrap; }
  .rowline strong { text-align: left; }
  .login, .settings { padding: 16px; }
  .logs-page .heading { align-items: flex-start; flex-wrap: wrap; }
  .log-controls { grid-template-columns: 1fr; gap: 8px; }
  .log-output { padding: 8px; }
}

@media (max-width: 400px) {
  .record-facts { grid-template-columns: 1fr; }
  .record-facts .rowline { display: flex; padding: 8px; border-right: 0; border-bottom: 1px solid var(--line); }
  .record-facts .rowline:last-child { border-bottom: 0; }
  .criteria { grid-template-columns: minmax(0,1fr) minmax(0,1fr); }
}

@media (prefers-reduced-motion: reduce) { button { transition: none; } }
