/* ═══════════════════════════════════════════════════════════
   Validate page — new upload view + topbar.
   Loads AFTER upload.css + ui/tokens.css + ui/components.css,
   overriding the legacy upload-view styles. Results view /
   loader / lightbox still use upload.css (redesign later).
   ═══════════════════════════════════════════════════════════ */

#invoice-form { max-width: 1080px; }

/* ── Topbar ─────────────────────────────────────── */
.topbar {
  background: rgba(253, 250, 247, .9);
  border-bottom: 1px solid var(--border);
  padding: 12px 24px;
}
.topbar-left { display: flex; align-items: center; gap: 14px; min-width: 0; }
.brand { gap: 10px; }
.brand-mark {
  width: 38px; height: 38px;
  background: none; border-radius: 0;
  display: block; object-fit: contain;
}
.brand-name { font-size: 18px; font-weight: 800; letter-spacing: -.02em; }
.brand-accent { color: var(--primary); }

.org-trigger {
  font-size: 13.5px;
  border-color: var(--border);
  box-shadow: var(--shadow-paper);
  color: var(--foreground);
}
.org-trigger:hover { background: var(--surface-soft); border-color: var(--border-strong); }
.org-avatar { width: 26px; height: 26px; font-size: 12px; background: var(--primary); }
.org-dropdown { border-color: var(--border); box-shadow: var(--shadow-paper-lg); }
.org-item svg { color: var(--primary); }
.org-item.is-active { color: var(--primary); }

.topbar-actions { gap: 6px; }
.nav-pill {
  font-size: 14px; font-weight: 600; text-decoration: none;
  color: var(--muted-foreground);
  padding: 8px 14px; border-radius: 999px;
  transition: background .12s, color .12s;
}
.nav-pill:hover { color: var(--foreground); background: var(--surface-soft); }
.nav-pill--current { color: var(--foreground); background: var(--surface-soft); }

.btn-new {
  font-size: 14px;
  border-color: var(--border);
  box-shadow: var(--shadow-paper);
}
.btn-new:hover { background: var(--surface-soft); border-color: var(--border-strong); }

/* ── Layout ─────────────────────────────────────── */
.content.view-upload { padding: 44px 24px 80px; }
.v-grid {
  display: grid;
  grid-template-columns: 1.55fr 1fr;
  gap: 28px;
  align-items: start;
}

.v-eyebrow {
  font-family: var(--font-mono);
  font-size: 11.5px; font-weight: 600;
  letter-spacing: .14em; text-transform: uppercase;
  color: var(--faint-foreground);
}
.v-title {
  margin-top: 8px;
  font-size: clamp(26px, 3.4vw, 34px);
  font-weight: 800; letter-spacing: -.03em; line-height: 1.15;
  color: var(--foreground);
}
.v-lede {
  margin: 12px 0 28px;
  font-size: 15.5px; line-height: 1.6;
  color: var(--muted-foreground);
  max-width: 560px;
}

/* ── Attach dropzones ───────────────────────────── */
.v-drop {
  display: flex; align-items: center; gap: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-paper);
  padding: 22px 24px;
  cursor: pointer;
  user-select: none;
  transition: border-color .15s, background .15s, box-shadow .15s;
}
.v-drop + .v-drop { margin-top: 14px; }
.v-drop:hover, .v-drop:focus-visible {
  border-color: var(--primary);
  outline: none;
  box-shadow: 0 0 0 3px var(--primary-soft), var(--shadow-paper);
}
.v-drop.is-drag {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.v-drop-icon {
  width: 46px; height: 46px; flex: none;
  border-radius: var(--radius-md);
  background: var(--primary-soft); color: var(--primary);
  display: flex; align-items: center; justify-content: center;
  transition: background .15s, color .15s;
}
.v-drop-icon--contract { background: var(--surface-soft); color: var(--muted-foreground); }

.v-drop-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.v-drop-title {
  display: flex; align-items: center; gap: 10px;
  font-size: 16.5px; font-weight: 700; letter-spacing: -.01em;
}
.v-drop-meta {
  font-size: 13.5px; color: var(--muted-foreground);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.v-browse {
  flex: none;
  display: inline-flex; align-items: center; gap: 7px;
  font-size: 13.5px; font-weight: 600;
  color: var(--muted-foreground);
  border: 1px solid var(--border); border-radius: 999px;
  padding: 8px 15px;
  background: var(--surface);
  transition: color .12s, border-color .12s;
}
.v-drop:hover .v-browse { color: var(--primary); border-color: var(--primary); }

/* Filled state */
.v-drop[data-empty="false"] { border-color: var(--pass); }
.v-drop[data-empty="false"] .badge { display: none; }
.v-drop[data-empty="false"] .v-drop-icon { background: var(--pass-soft); color: var(--pass); }
.v-drop[data-empty="false"] .v-drop-meta { color: var(--pass-foreground); font-weight: 600; }
.v-drop[data-empty="false"] .v-browse { display: none; }
.v-drop .attach-remove { display: none; }
.v-drop[data-empty="false"] .attach-remove { display: inline-flex; }

/* ── Right column ───────────────────────────────── */
.v-check-card { padding: 22px 24px; }
.v-check-list { list-style: none; margin-top: 14px; }
.v-check-list li {
  position: relative;
  padding: 7px 0 7px 22px;
  font-size: 14.5px;
  color: var(--foreground);
}
.v-check-list li::before {
  content: "";
  position: absolute; left: 4px; top: 50%; transform: translateY(-50%);
  width: 7px; height: 7px; border-radius: 999px;
  background: var(--primary);
}

.v-note {
  display: flex; gap: 12px; align-items: flex-start;
  margin-top: 14px;
  background: var(--sev-info-soft);
  color: var(--sev-info-foreground);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  font-size: 13.5px; line-height: 1.55;
}
.v-note svg { flex: none; margin-top: 2px; }
.v-note p { margin: 0; }

/* CTA */
.v-cta { margin-top: 18px; }
.btn-validate {
  max-width: none;
  border-radius: var(--radius-md);
  padding: 15px 20px;
  font-size: 15.5px;
  font-weight: 700;
  background: var(--primary-soft);
  color: var(--primary);
  box-shadow: none;
}
.btn-validate:disabled { background: var(--primary-soft); color: rgba(194, 65, 12, .55); }
.btn-validate:not(:disabled) { background: var(--primary); color: var(--primary-foreground); box-shadow: var(--shadow-paper); }
.btn-validate:not(:disabled):hover { background: var(--primary-hover); }
.v-cta-hint {
  margin-top: 10px;
  text-align: center;
  font-size: 13px;
  color: var(--faint-foreground);
}
.v-cta-hint[hidden] { display: none; }

/* ═══════════════════════════════════════════════════════════
   RESULTS VIEW
   ═══════════════════════════════════════════════════════════ */
.content.view-results { padding: 28px 24px 80px; }

/* ── Degraded / fallback-model notice ───────────── */
.notice {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 14px 16px; margin-bottom: 20px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface);
}
.notice[hidden] { display: none; }
.notice--warn {
  background: var(--review-soft);
  border-color: color-mix(in srgb, var(--review) 28%, transparent);
  color: var(--review-foreground);
}
.notice-ic { flex: none; color: var(--review); margin-top: 1px; }
.notice-body { flex: 1 1 auto; min-width: 0; }
.notice-title { font-weight: 700; font-size: 14.5px; }
.notice-text { font-size: 13.5px; color: var(--review-foreground); margin-top: 2px; }
.notice-action {
  flex: none; align-self: center;
  border: 1px solid color-mix(in srgb, var(--review) 40%, transparent);
  background: var(--surface); color: var(--review-foreground);
  font-weight: 600; font-size: 13px;
  padding: 7px 14px; border-radius: 999px;
  transition: background .12s, border-color .12s;
}
.notice-action:hover { background: var(--surface-soft); border-color: var(--review); }
.notice-close {
  flex: none; align-self: flex-start;
  background: none; border: none; color: var(--review-foreground);
  opacity: .6; padding: 2px; border-radius: 6px;
  display: inline-flex; transition: opacity .12s, background .12s;
}
.notice-close:hover { opacity: 1; background: color-mix(in srgb, var(--review) 14%, transparent); }

/* ── Error state (failed run) ───────────────────── */
.error-state {
  display: flex; flex-direction: column; align-items: center; text-align: center;
  max-width: 460px; margin: 48px auto;
  padding: 40px 32px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-paper);
}
.error-state[hidden] { display: none; }
.error-ic {
  display: inline-flex; align-items: center; justify-content: center;
  width: 56px; height: 56px; border-radius: 50%;
  margin-bottom: 18px;
  background: var(--fix-soft); color: var(--fix);
}
.error-state.is-warn .error-ic { background: var(--sev-warn-soft); color: var(--sev-warn); }
.error-state.is-info .error-ic { background: var(--sev-info-soft); color: var(--sev-info); }
.error-ic svg { width: 28px; height: 28px; }
.error-title { font-size: 20px; font-weight: 800; letter-spacing: -.01em; }
.error-text {
  font-size: 14.5px; color: var(--muted-foreground);
  margin-top: 8px; line-height: 1.55; max-width: 40ch;
}
.error-actions { display: flex; gap: 10px; margin-top: 22px; flex-wrap: wrap; justify-content: center; }
.error-retry[hidden] { display: none; }

/* ── Verdict hero ───────────────────────────────── */
.r-hero {
  display: flex; align-items: center; gap: 28px;
  padding: 26px 30px;
}
.r-ring { position: relative; flex: none; width: 112px; height: 112px; }
.r-ring svg { transform: rotate(-90deg); display: block; }
.ring-track { stroke: var(--surface-soft); }
.r-hero .ring-value { stroke: var(--na); }
.r-hero.is-pass   .ring-value { stroke: var(--pass); }
.r-hero.is-review .ring-value { stroke: var(--review); }
.r-hero.is-fix    .ring-value { stroke: var(--fix); }
.r-ring-label {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.r-ring-label b { font-size: 23px; font-weight: 800; letter-spacing: -.02em; }
.r-ring-label small {
  font-family: var(--font-mono); font-size: 8.5px; font-weight: 600;
  letter-spacing: .12em; color: var(--faint-foreground); margin-top: 2px;
}

.r-copy { flex: 1; min-width: 0; }
.r-eyebrow {
  display: inline-block;
  font-family: var(--font-mono); font-size: 10.5px; font-weight: 700;
  letter-spacing: .12em; text-transform: uppercase;
  border-radius: 6px; padding: 3px 9px;
  background: var(--na-soft); color: var(--na-foreground);
}
.r-hero.is-pass   .r-eyebrow { background: var(--pass-soft);   color: var(--pass-foreground); }
.r-hero.is-review .r-eyebrow { background: var(--review-soft); color: var(--review-foreground); }
.r-hero.is-fix    .r-eyebrow { background: var(--fix-soft);    color: var(--fix-foreground); }
.r-title { font-size: clamp(20px, 3vw, 26px); font-weight: 800; letter-spacing: -.02em; margin-top: 10px; }
.r-sub { color: var(--muted-foreground); font-size: 14px; margin-top: 6px; max-width: 520px; }
.r-meta { font-family: var(--font-mono); font-size: 12px; color: var(--faint-foreground); margin-top: 10px; word-break: break-all; }
.r-actions { flex: none; display: flex; gap: 8px; align-self: flex-start; }

/* ── Stat cards ─────────────────────────────────── */
.view-results .stats { gap: 14px; margin-top: 16px; }
.view-results .stat {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-paper);
  padding: 18px 20px 16px;
  display: flex; flex-direction: column; gap: 10px;
}
.stat-head { display: flex; align-items: center; gap: 8px; }
.view-results .stat-cap {
  margin: 0;
  font-family: var(--font-mono); font-size: 10.5px; font-weight: 600; letter-spacing: .12em;
}
/* Tint the whole card per status so Passed / Human review / To fix are
   separable at a glance (mint vs peach vs lavender), not only by the small
   head colour. */
.stat--pass   { background: var(--pass-soft);   border-color: color-mix(in srgb, var(--pass) 22%, transparent); }
.stat--review { background: var(--review-soft); border-color: color-mix(in srgb, var(--review) 30%, transparent); }
.stat--fix    { background: var(--fix-soft);    border-color: color-mix(in srgb, var(--fix) 26%, transparent); }
.stat--pass   .stat-head { color: var(--pass-foreground); }
.stat--review .stat-head { color: var(--review-foreground); }
.stat--fix    .stat-head { color: var(--fix-foreground); }
.view-results .stat-num { margin: 0; font-size: 30px; font-weight: 800; color: var(--foreground); line-height: 1; }
.stat-unit {
  position: absolute; right: 18px; bottom: 14px;
  font-size: 12px; color: var(--faint-foreground);
}
.stat--jump:focus-visible { outline: 2px solid var(--primary); outline-offset: 3px; }

/* ── Document viewer (full width — reviews live in the report) ── */
.r-docgrid { margin-top: 16px; }
.r-docgrid > [hidden] { display: none; }

.r-doc { overflow: hidden; margin: 0; }
.r-doc-head {
  display: flex; align-items: center; gap: 9px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  color: var(--muted-foreground);
}
.r-doc-title {
  font-family: var(--font-mono); font-size: 12px; font-weight: 600;
  color: var(--foreground);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.r-doc-meta { font-family: var(--font-mono); font-size: 11.5px; color: var(--faint-foreground); white-space: nowrap; }
.r-doc-pager { margin-left: auto; display: flex; align-items: center; gap: 7px; }
.r-doc-pager span { font-family: var(--font-mono); font-size: 11.5px; color: var(--muted-foreground); }
.r-doc-pager button {
  width: 26px; height: 26px;
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--muted-foreground);
}
.r-doc-pager button:hover:not(:disabled) { background: var(--surface-soft); color: var(--foreground); }
.r-doc-pager button:disabled { opacity: .4; cursor: default; }

.r-doc-body { display: flex; gap: 14px; padding: 16px; background: var(--surface-soft); }
.r-doc-rail {
  display: flex; flex-direction: column; gap: 10px;
  width: 72px; flex: none;
  max-height: 540px; overflow-y: auto;
}
.r-doc-rail .doc-thumb { width: 72px; border-radius: 8px; }
.r-doc-rail .doc-thumb.is-current {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-soft);
}
.r-doc-rail:empty { display: none; }
.r-doc-stage { flex: 1; display: flex; align-items: flex-start; justify-content: center; min-width: 0; }
.r-doc-stage img {
  max-width: 100%; max-height: 560px;
  border: 1px solid var(--border); border-radius: 6px;
  background: #fff; box-shadow: var(--shadow-paper);
  cursor: zoom-in;
}

/* ── Issues column beside the document ──────────── */
.r-doc-issues {
  width: 264px; flex: none;
  padding-left: 18px;
  border-left: 1px solid var(--border);
  max-height: 560px; overflow-y: auto;
}
.r-issues-eyebrow {
  font-family: var(--font-mono); font-size: 10.5px; font-weight: 700;
  letter-spacing: .12em; text-transform: uppercase;
  color: var(--muted-foreground);
}
.r-issues-list { list-style: none; margin-top: 6px; }
.r-issue { display: flex; gap: 10px; padding: 11px 0; border-top: 1px solid var(--border); }
.r-issue:first-child { border-top: none; }
.r-issue-num {
  width: 20px; height: 20px; flex: none; margin-top: 1px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-mono); font-size: 10.5px; font-weight: 700;
  color: #fff;
}
.r-issue.is-fix    .r-issue-num { background: var(--fix); }
.r-issue.is-review .r-issue-num { background: var(--review); }
.r-issue-body { min-width: 0; }
.r-issue-label { font-size: 12.5px; font-weight: 700; line-height: 1.4; margin-top: 2px; }
.r-issue-note { font-size: 11.5px; color: var(--muted-foreground); margin-top: 3px; line-height: 1.5; }

/* ── Detailed checks ────────────────────────────── */
.r-checks-head { margin: 30px 0 12px; }
.r-checks-title { font-size: 17px; font-weight: 800; letter-spacing: -.01em; }
.r-checks-sub { font-size: 12.5px; color: var(--faint-foreground); margin-top: 3px; }

.view-results .panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-paper);
}
.view-results .cat-title { font-size: 15px; font-weight: 700; }
.cat-counts { display: flex; gap: 10px; flex: none; }
.cnt { font-family: var(--font-mono); font-size: 11px; font-weight: 600; white-space: nowrap; }
.cnt-pass { color: var(--pass); }
.cnt-warn { color: var(--review); }
.cnt-fix  { color: var(--fix); }

.view-results .detail-title { font-size: 13.5px; }
.view-results .detail-ic { width: 36px; height: 36px; border-radius: 10px; background: var(--surface-soft); color: var(--muted-foreground); }
.view-results .detail-ic svg { width: 18px; height: 18px; }
.view-results .detail-status { font-size: 12px; padding: 5px 11px 5px 8px; }
.view-results .detail-status svg { width: 13px; height: 13px; }

/* Verdict-token chip colors (override upload.css legacy palette) */
.detail-item.is-checked .detail-status,
.detail-cat.is-checked > .cat-head .detail-status { background: var(--pass-soft); color: var(--pass-foreground); }
.detail-item.is-missing .detail-status,
.detail-cat.is-missing > .cat-head .detail-status { background: var(--fix-soft); color: var(--fix-foreground); }
.detail-item.is-check .detail-status,
.detail-cat.is-check > .cat-head .detail-status { background: var(--review-soft); color: var(--review-foreground); }
.detail-item.is-na .detail-status,
.detail-cat.is-na > .cat-head .detail-status { background: var(--na-soft); color: var(--na-foreground); }

.detail-head .sev { flex: none; }
.view-results .detail-extra { font-size: 14px; color: var(--muted-foreground); }
.view-results .results-error { color: var(--fix); }

@keyframes detail-flash {
  0%, 15% { background: var(--primary-soft); box-shadow: inset 3px 0 0 var(--primary); }
  100%    { background: transparent; box-shadow: inset 3px 0 0 transparent; }
}

/* ═══════════════════════════════════════════════════════════
   PRINTABLE REPORT (#print-report)
   Hidden on screen; the only thing rendered when printing, so
   "Download report" → browser print → Save as PDF.
   ═══════════════════════════════════════════════════════════ */
#print-report { display: none; }

@media print {
  body > * { display: none !important; }
  body > #print-report {
    display: block !important;
    font-family: var(--font-sans);
    font-variant-numeric: tabular-nums;
    color: #000;
    font-size: 12px;
    line-height: 1.5;
  }
  .pr-head { display: flex; align-items: baseline; justify-content: space-between; gap: 16px;
    border-bottom: 1.5px solid #000; padding-bottom: 10px; }
  .pr-brand { font-size: 15px; font-weight: 800; letter-spacing: -.01em; }
  .pr-brand b { color: var(--primary); }
  .pr-meta { font-family: var(--font-mono); font-size: 10px; color: #555; text-align: right; }
  .pr-stats { font-family: var(--font-mono); font-size: 10px; color: #333; margin-top: 10px; }
  .pr-eyebrow { font-family: var(--font-mono); font-size: 9.5px; font-weight: 700;
    letter-spacing: .12em; text-transform: uppercase; color: #555; }

  /* Document + issues side by side, like the on-screen viewer */
  .pr-grid { display: flex; gap: 16px; margin-top: 12px; align-items: flex-start; }
  .pr-doc { flex: 1; min-width: 0; }
  .pr-page { display: block; width: 100%; border: 1px solid #ddd; border-radius: 4px;
    margin-bottom: 10px; break-inside: avoid; }
  .pr-issues-col { width: 34%; flex: none; }
  .pr-issues-col .r-issues-list { list-style: none; margin-top: 6px; padding: 0; }
  .pr-issues-col .r-issue { display: flex; gap: 8px; padding: 7px 0;
    border-top: 1px solid #ddd; break-inside: avoid; }
  .pr-issues-col .r-issue:first-child { border-top: none; }
  .pr-issues-col .r-issue-num { width: 16px; height: 16px; flex: none; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-family: var(--font-mono); font-size: 9px; font-weight: 700; color: #fff; }
  .pr-issues-col .r-issue.is-fix    .r-issue-num { background: var(--fix); }
  .pr-issues-col .r-issue.is-review .r-issue-num { background: var(--review); }
  .pr-issues-col .r-issue-label { font-size: 10px; font-weight: 700; line-height: 1.4; }
  .pr-issues-col .r-issue-note { font-size: 9px; color: #444; margin-top: 2px; line-height: 1.45; }
  .pr-note { color: #555; font-size: 10px; }
  .pr-foot { margin-top: 18px; padding-top: 8px; border-top: 1px solid #ccc;
    font-size: 9.5px; color: #777; }
}

/* ── Responsive ─────────────────────────────────── */
@media (max-width: 860px) {
  .nav-pill { display: none; }
}
@media (max-width: 760px) {
  .content.view-results { padding: 20px 16px 60px; }
  .r-hero { flex-direction: column; text-align: center; gap: 18px; padding: 24px 20px; }
  .r-sub { margin-left: auto; margin-right: auto; }
  .r-actions { align-self: center; }
  .view-results .stats { grid-template-columns: 1fr; gap: 10px; }
  .r-doc-body { flex-direction: column; }
  .r-doc-rail {
    flex-direction: row; width: 100%;
    max-height: none; overflow-x: auto; overflow-y: hidden;
    order: 2;
  }
  .r-doc-rail .doc-thumb { flex: none; }
  .r-doc-issues {
    width: 100%; max-height: none;
    padding-left: 0; border-left: none;
    border-top: 1px solid var(--border); padding-top: 14px;
    order: 3;
  }
  .r-doc-meta { display: none; }
  .cat-counts { display: none; }
}
@media (min-width: 761px) and (max-width: 1080px) {
  .r-doc-issues { width: 220px; }
}
@media (max-width: 760px) {
  .content.view-upload { padding: 28px 18px 140px; }
  .v-grid { grid-template-columns: 1fr; gap: 20px; }
  .v-lede { margin-bottom: 20px; }
  .v-drop { padding: 18px; gap: 13px; flex-wrap: wrap; }
  .v-drop-meta { white-space: normal; }
  .v-browse { display: none; }

  /* CTA docks to the bottom of the screen */
  .v-cta {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    margin: 0;
    padding: 12px 18px calc(12px + env(safe-area-inset-bottom));
    background: linear-gradient(to top, var(--background) 78%, rgba(253, 250, 247, 0));
  }
  .btn-validate { width: 100%; }
  .v-cta-hint { margin-top: 8px; }
}
@media (max-width: 480px) {
  .org-name { max-width: 110px; }
  .topbar { padding: 10px 14px; }
}
