html {
  font-size: 15px;
  min-height: 100%;
}

body {
  background: #eef3f1;
  color: #1c2733;
  display: flex;
  flex-direction: column;
  font-family: "Segoe UI", Arial, sans-serif;
  margin: 0;
  min-height: 100vh;
}

body > .container {
  flex: 1 0 auto;
}

.container {
  max-width: 1240px;
}

.navbar {
  background: #101417;
  border-bottom: 4px solid #ffc400;
  min-height: 66px;
}

.navbar-brand {
  color: #ffffff;
  font-weight: 700;
}

.navbar-brand:hover,
.navbar-brand:focus {
  color: #ffffff;
}

.app-brand-mini {
  align-items: center;
  display: inline-flex;
  gap: 10px;
}

.app-brand-mini img {
  background: #ffc400;
  border-radius: 6px;
  height: 42px;
  object-fit: contain;
  width: 42px;
}

.nav-link {
  color: #dfe7e3;
  font-weight: 650;
}

.nav-link:hover,
.nav-link:focus {
  color: #ffc400;
}

.review-shell {
  display: grid;
  gap: 14px;
  padding: 14px 0 26px;
}

.review-header,
.panel,
.status-bar,
.warning-panel {
  background: #ffffff;
  border: 1px solid #d3ded9;
  border-radius: 8px;
  box-shadow: 0 8px 22px rgba(16, 20, 23, 0.06);
}

.review-header {
  align-items: center;
  background:
    linear-gradient(90deg, rgba(255, 196, 0, 0.18), rgba(10, 113, 68, 0.08)),
    #ffffff;
  display: grid;
  gap: 18px;
  grid-template-columns: minmax(320px, 1fr) minmax(390px, 520px);
  padding: 14px 18px;
}

.brand-hero {
  align-items: center;
  display: grid;
  gap: 14px;
  grid-template-columns: 64px 1fr;
}

.brand-hero img {
  background: #ffc400;
  border: 1px solid #d8a800;
  border-radius: 10px;
  box-shadow: 0 8px 18px rgba(16, 20, 23, 0.12);
  height: 64px;
  object-fit: contain;
  padding: 4px;
  width: 64px;
}

.process-steps {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 7px;
}

.process-steps span {
  background: rgba(10, 113, 68, 0.1);
  border: 1px solid rgba(10, 113, 68, 0.18);
  border-radius: 999px;
  color: #0a7144;
  font-size: 0.76rem;
  font-weight: 800;
  padding: 4px 8px;
}

.eyebrow {
  color: #0a7144;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0;
  margin: 0 0 4px;
  text-transform: uppercase;
}

h1,
h2 {
  letter-spacing: 0;
  margin: 0;
}

h1 {
  font-size: 1.55rem;
  line-height: 1.2;
}

h2 {
  font-size: 0.98rem;
}

.muted,
.empty {
  color: #667483;
  margin: 6px 0 0;
}

.upload-strip {
  align-items: end;
  display: grid;
  gap: 10px;
  grid-template-columns: minmax(220px, 1fr) 116px;
}

.file-picker {
  display: grid;
  gap: 6px;
}

.file-picker span,
.label,
.amount-words span {
  color: #667483;
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
}

.file-picker input {
  background: #f8fafc;
  border: 1px solid #cbd5df;
  border-radius: 6px;
  min-height: 40px;
  padding: 8px;
  width: 100%;
}

button {
  background: #0a7144;
  border: 0;
  border-radius: 6px;
  color: #ffffff;
  font-weight: 700;
  min-height: 40px;
  padding: 0 16px;
}

button:hover,
button:focus {
  background: #075c38;
}

.run-button {
  align-items: center;
  display: inline-flex;
  gap: 8px;
  justify-content: center;
}

.button-spinner {
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: #ffffff;
  border-radius: 50%;
  display: none;
  height: 16px;
  width: 16px;
}

body.is-loading .button-spinner {
  animation: spin 0.8s linear infinite;
  display: inline-block;
}

body.is-loading .run-button {
  opacity: 0.82;
}

.loading-overlay {
  align-items: center;
  background: rgba(16, 20, 23, 0.58);
  bottom: 0;
  display: flex;
  justify-content: center;
  left: 0;
  padding: 24px;
  position: fixed;
  right: 0;
  top: 0;
  z-index: 30;
}

.loading-overlay[hidden] {
  display: none;
}

.loading-card {
  align-items: center;
  background: #ffffff;
  border: 1px solid #d3ded9;
  border-radius: 14px;
  box-shadow: 0 24px 60px rgba(16, 20, 23, 0.28);
  display: grid;
  gap: 10px;
  justify-items: center;
  min-width: 280px;
  padding: 26px;
  text-align: center;
}

.loading-card img {
  background: #ffc400;
  border-radius: 8px;
  height: 58px;
  object-fit: contain;
  width: 58px;
}

.loading-card span {
  color: #667483;
}

.loader-ring {
  animation: spin 0.85s linear infinite;
  border: 4px solid #e5ece8;
  border-top-color: #0a7144;
  border-radius: 50%;
  height: 42px;
  width: 42px;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.alert {
  background: #fff0f0;
  border: 1px solid #e5b0b0;
  border-radius: 7px;
  color: #842222;
  padding: 10px 12px;
}

.status-bar {
  display: grid;
  gap: 1px;
  grid-template-columns: 1.35fr 1fr 1fr 0.7fr 0.8fr 0.8fr;
  overflow: hidden;
}

.status-bar > div {
  background: #ffffff;
  display: grid;
  gap: 4px;
  min-width: 0;
  padding: 12px 14px;
}

.status-bar strong {
  overflow-wrap: anywhere;
}

.ok {
  color: #0b6b43;
}

.warn {
  color: #9a5b00;
}

.status-pill,
.confidence-pill {
  border-radius: 999px;
  display: inline-flex;
  font-size: 0.88rem;
  line-height: 1;
  padding: 6px 9px;
  white-space: nowrap;
}

.status-pill {
  background: #101417;
  color: #ffc400;
}

.confidence-pill {
  background: #e8f5ee;
  color: #0a7144;
}

.party-grid,
.review-grid,
.debug-grid {
  display: grid;
  gap: 14px;
}

.party-grid {
  grid-template-columns: 1fr 1fr;
}

.review-grid {
  align-items: start;
  grid-template-columns: minmax(0, 1fr) 304px;
}

.debug-grid {
  grid-template-columns: 1.05fr 0.9fr 1.05fr;
}

.panel {
  display: grid;
  gap: 12px;
  min-width: 0;
  padding: 14px;
}

.panel-title {
  align-items: center;
  border-bottom: 1px solid #e4e9ef;
  display: flex;
  gap: 10px;
  justify-content: space-between;
  padding-bottom: 10px;
}

.panel-title span {
  color: #667483;
  font-size: 0.86rem;
  overflow-wrap: anywhere;
  text-align: right;
}

.party-name {
  font-size: 1rem;
  overflow-wrap: anywhere;
}

.party-grid p {
  color: #526170;
  margin: 0;
  min-height: 18px;
}

.warning-panel {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px;
}

.warning-panel span {
  background: #fff8e5;
  border: 1px solid #e8c66e;
  border-radius: 999px;
  color: #604700;
  font-size: 0.86rem;
  padding: 5px 10px;
}

.items-panel {
  padding: 0;
}

.items-panel .panel-title {
  margin: 0 14px;
  padding-top: 14px;
}

.table-wrap {
  overflow: auto;
}

.items-table {
  border-collapse: collapse;
  font-size: 0.91rem;
  min-width: 820px;
  width: 100%;
}

.items-table th,
.items-table td {
  border-bottom: 1px solid #e5eaf0;
  padding: 10px 9px;
  text-align: left;
  vertical-align: top;
}

.items-table th {
  background: #f4f7f5;
  color: #435160;
  font-size: 0.76rem;
  font-weight: 800;
  position: sticky;
  text-transform: uppercase;
  top: 0;
  z-index: 1;
}

.items-table tbody tr:hover {
  background: #f8fbfd;
}

.item-name {
  font-weight: 700;
  min-width: 260px;
}

.num {
  font-variant-numeric: tabular-nums;
  text-align: right !important;
  white-space: nowrap;
}

.strong {
  font-weight: 800;
}

.totals-panel {
  position: sticky;
  top: 12px;
}

.totals-list,
.file-meta {
  display: grid;
  gap: 0;
  margin: 0;
}

.totals-list {
  border: 1px solid #e4e9ef;
  border-radius: 7px;
  overflow: hidden;
}

.totals-list dt,
.totals-list dd,
.file-meta dt,
.file-meta dd {
  margin: 0;
  padding: 8px 10px;
}

.totals-list dt,
.file-meta dt {
  color: #5a6877;
  font-weight: 700;
}

.totals-list dd {
  border-bottom: 1px solid #e4e9ef;
  font-size: 1rem;
  font-weight: 800;
  text-align: right;
}

.totals-list dt {
  background: #f7f9fb;
}

.totals-list dt:last-of-type,
.totals-list dd:last-of-type {
  border-bottom: 0;
}

.amount-words {
  background: #f5faf9;
  border: 1px solid #cde3df;
  border-radius: 7px;
  display: grid;
  gap: 6px;
  padding: 10px;
}

.amount-words strong {
  line-height: 1.35;
}

.file-meta {
  grid-template-columns: 1fr auto;
}

.file-meta dd {
  color: #1c2733;
  font-weight: 700;
}

details.panel {
  align-content: start;
  max-height: 520px;
  overflow: auto;
}

summary {
  cursor: pointer;
  font-weight: 800;
  list-style-position: inside;
}

pre {
  background: #111923;
  border-radius: 6px;
  color: #dce9f3;
  font-size: 0.84rem;
  line-height: 1.45;
  margin: 0;
  max-height: 430px;
  overflow: auto;
  padding: 12px;
  white-space: pre-wrap;
  word-break: break-word;
}

.json-rainbow {
  background:
    linear-gradient(180deg, rgba(255, 196, 0, 0.06), rgba(10, 113, 68, 0.06)),
    #111923;
}

.json-key {
  color: #7dd3fc;
}

.json-string {
  color: #fde68a;
}

.json-number {
  color: #86efac;
}

.json-boolean {
  color: #f0abfc;
}

.json-null {
  color: #fb7185;
}

.debug-panel summary {
  align-items: center;
  display: flex;
  justify-content: space-between;
}

.debug-panel summary::after {
  background: #eef3f1;
  border: 1px solid #d3ded9;
  border-radius: 999px;
  color: #526170;
  content: "debug";
  font-size: 0.72rem;
  font-weight: 800;
  padding: 3px 8px;
  text-transform: uppercase;
}

.review-tabs {
  display: grid;
  gap: 14px;
}

.review-tabs > input {
  display: none;
}

.tab-list {
  background: #ffffff;
  border: 1px solid #d3ded9;
  border-radius: 10px;
  box-shadow: 0 8px 22px rgba(16, 20, 23, 0.06);
  display: grid;
  gap: 6px;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  padding: 6px;
  position: sticky;
  top: 0;
  z-index: 5;
}

.tab-list label {
  align-items: center;
  border-radius: 8px;
  color: #435160;
  cursor: pointer;
  display: flex;
  font-weight: 800;
  justify-content: center;
  min-height: 42px;
  padding: 8px 10px;
  text-align: center;
}

.tab-list label:hover {
  background: #f4f7f5;
}

.tab-icon {
  display: inline-block;
  font-weight: 900;
  margin-right: 6px;
  min-width: 22px;
}

#tab-overview:checked ~ .tab-list label[for="tab-overview"],
#tab-items:checked ~ .tab-list label[for="tab-items"],
#tab-mapped:checked ~ .tab-list label[for="tab-mapped"],
#tab-ocr:checked ~ .tab-list label[for="tab-ocr"],
#tab-raw:checked ~ .tab-list label[for="tab-raw"] {
  background: #101417;
  color: #ffc400;
}

.tab-panels {
  display: grid;
}

.tab-panel {
  background: #ffffff;
  border: 1px solid #d3ded9;
  border-radius: 10px;
  box-shadow: 0 8px 22px rgba(16, 20, 23, 0.06);
  display: none;
  min-height: 560px;
  min-width: 0;
  padding: 14px;
}

#tab-overview:checked ~ .tab-panels .tab-panel:nth-child(1),
#tab-items:checked ~ .tab-panels .tab-panel:nth-child(2),
#tab-mapped:checked ~ .tab-panels .tab-panel:nth-child(3),
#tab-ocr:checked ~ .tab-panels .tab-panel:nth-child(4),
#tab-raw:checked ~ .tab-panels .tab-panel:nth-child(5) {
  display: grid;
}

.overview-panel {
  gap: 14px;
}

.overview-grid {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(2, minmax(0, 1fr)) 304px;
}

.seller-card,
.buyer-card {
  min-height: 126px;
}

.totals-panel {
  grid-row: span 2;
}

.metrics-card {
  align-items: stretch;
  grid-column: span 2;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.metrics-card > div {
  background: #f7faf8;
  border: 1px solid #dfe8e4;
  border-radius: 8px;
  display: grid;
  gap: 5px;
  min-height: 84px;
  padding: 12px;
}

.metrics-card strong {
  font-size: 1.05rem;
}

.item-preview {
  padding: 0;
}

.item-preview .panel-title {
  margin: 0 14px;
  padding-top: 14px;
}

.compact-table {
  min-width: 760px;
}

.full-table-panel,
.code-panel,
.ocr-panel {
  align-content: start;
  gap: 12px;
}

.panel-title-bar {
  border-bottom: 1px solid #dfe8e4;
  margin: 0;
  padding: 0 0 12px;
}

.full-table-wrap {
  border: 1px solid #dfe8e4;
  border-radius: 8px;
  max-height: 68vh;
}

.full-items-table {
  min-width: 1080px;
}

.copy-button {
  background: #ffc400;
  color: #101417;
  min-height: 32px;
  padding: 0 12px;
}

.copy-button:hover,
.copy-button:focus {
  background: #e2ad00;
}

.secondary-button {
  background: #eef3f1;
  border: 1px solid #cfdcd6;
  color: #1c2733;
  min-height: 32px;
  padding: 0 12px;
}

.secondary-button:hover,
.secondary-button:focus {
  background: #dde9e4;
}

.panel-actions {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.panel-actions span {
  white-space: nowrap;
}

.download-menu {
  position: relative;
}

.download-options {
  background: #ffffff;
  border: 1px solid #cfdcd6;
  border-radius: 8px;
  box-shadow: 0 14px 34px rgba(16, 20, 23, 0.14);
  display: none;
  min-width: 156px;
  padding: 6px;
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  z-index: 20;
}

.download-menu:hover .download-options,
.download-menu:focus-within .download-options {
  display: grid;
  gap: 4px;
}

.download-options button {
  background: transparent;
  border-radius: 6px;
  color: #1c2733;
  font-weight: 700;
  justify-content: flex-start;
  min-height: 34px;
  padding: 0 10px;
  text-align: left;
}

.download-options button:hover,
.download-options button:focus {
  background: #eef3f1;
}

.close-focus,
.focus-panel .close-focus {
  display: none !important;
}

body.focus-active {
  overflow: hidden;
}

.focus-panel.is-focused {
  border-radius: 0;
  bottom: 0;
  display: grid !important;
  left: 0;
  max-height: none;
  min-height: 0;
  overflow: hidden;
  padding: 18px;
  position: fixed;
  right: 0;
  top: 0;
  z-index: 40;
}

.focus-panel.is-focused .close-focus {
  display: inline-flex !important;
}

.focus-panel.is-focused .panel-title-bar {
  align-items: center;
}

.focus-panel.is-focused .code-view,
.focus-panel.is-focused .full-ocr-lines,
.focus-panel.is-focused .full-table-wrap {
  max-height: calc(100vh - 86px);
  min-height: calc(100vh - 86px);
}

.code-view {
  font-size: 0.92rem;
  line-height: 1.55;
  max-height: 72vh;
  min-height: 520px;
}

.full-ocr-lines {
  max-height: 72vh;
}

.full-ocr-lines div {
  grid-template-columns: minmax(0, 1fr) 86px;
  padding: 11px 12px;
}

.full-ocr-lines strong {
  font-size: 0.96rem;
}

.ocr-lines {
  border: 1px solid #e4e9ef;
  border-radius: 7px;
  display: grid;
  max-height: 430px;
  overflow: auto;
}

.ocr-lines div {
  align-items: start;
  border-bottom: 1px solid #edf1f5;
  display: grid;
  gap: 10px;
  grid-template-columns: 1fr 58px;
  padding: 8px 10px;
}

.ocr-lines div:last-child {
  border-bottom: 0;
}

.ocr-lines strong {
  overflow-wrap: anywhere;
}

.ocr-lines span {
  color: #667483;
  font-size: 0.82rem;
  text-align: right;
}

.empty-state {
  min-height: 180px;
  place-content: center;
  text-align: center;
}

.metrics-card {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.success-metric {
  background: #ecfdf3 !important;
  border-color: #bfe9cd !important;
}

.icon-button {
  align-items: center;
  background: #eef3f1;
  border: 1px solid #cfdcd6;
  border-radius: 7px;
  color: #1c2733;
  display: inline-flex;
  font-size: 1rem;
  font-weight: 900;
  justify-content: center;
  min-height: 32px;
  padding: 0;
  width: 36px;
}

.icon-button:hover,
.icon-button:focus {
  background: #dde9e4;
}

.panel-search {
  border: 1px solid #cfdcd6;
  border-radius: 7px;
  min-height: 32px;
  min-width: 210px;
  padding: 0 10px;
}

.line-code {
  padding: 0;
}

.download-source {
  display: none;
}

.code-line {
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr);
  min-height: 22px;
}

.line-no {
  background: rgba(255, 255, 255, 0.04);
  border-right: 1px solid rgba(255, 255, 255, 0.08);
  color: #7b8a99;
  padding: 0 10px;
  text-align: right;
  user-select: none;
}

.line-text {
  padding: 0 12px;
  white-space: pre-wrap;
}

.ocr-lines div {
  grid-template-columns: minmax(0, 1fr) 94px;
}

.ocr-lines div.is-hidden {
  display: none;
}

.confidence-badge {
  border-radius: 999px;
  font-weight: 800;
  padding: 3px 8px;
}

.confidence-badge.good {
  background: #e8f5ee;
  color: #0a7144;
}

.confidence-badge.medium {
  background: #fff8e5;
  color: #8a6200;
}

.confidence-badge.low {
  background: #fff0f0;
  color: #842222;
}

@media (max-width: 980px) {
  .review-header,
  .party-grid,
  .review-grid,
  .debug-grid,
  .status-bar,
  .overview-grid,
  .metrics-card {
    grid-template-columns: 1fr;
  }

  .totals-panel {
    position: static;
    grid-row: auto;
  }

  .metrics-card {
    grid-column: auto;
  }

  .brand-hero {
    grid-template-columns: 58px 1fr;
  }

  .brand-hero img {
    height: 58px;
    width: 58px;
  }
}

@media (max-width: 620px) {
  .upload-strip {
    grid-template-columns: 1fr;
  }

  .review-shell {
    padding-top: 10px;
  }

  .tab-list {
    grid-template-columns: 1fr 1fr;
    position: static;
  }

  .tab-list label {
    justify-content: flex-start;
  }

  .tab-panel {
    min-height: 420px;
  }

  .code-view {
    min-height: 360px;
  }
}
