:root {
  --bg: #eef2ef;
  --bg-grid: rgba(23, 71, 58, 0.06);
  --surface: #ffffff;
  --surface-2: #f3f7f4;
  --ink: #20241f;
  --muted: #687067;
  --line: #d9d8cf;
  --line-strong: #b9b8ae;
  --accent: #0f6b5b;
  --accent-ink: #ffffff;
  --gold: #b8842f;
  --red: #b4473e;
  --green: #19705b;
  --shadow: 0 18px 45px rgba(44, 47, 39, 0.12);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: "Aptos", "Segoe UI", "Microsoft YaHei", sans-serif;
  background:
    linear-gradient(90deg, var(--bg-grid) 1px, transparent 1px),
    linear-gradient(180deg, rgba(255, 255, 255, 0.72), rgba(238, 242, 239, 0.94)),
    var(--bg);
  background-size: 28px 28px, 100% 100%, auto;
}

button,
.button,
input {
  font: inherit;
}

h1,
h2,
p,
dl {
  margin: 0;
}

.app-shell {
  width: min(1680px, calc(100vw - 32px));
  margin: 18px auto;
}

.topbar {
  min-height: 76px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 16px 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
}

.identity,
.topbar-meta,
.section-heading,
.panel-head,
.button-row,
.output-actions,
.group-title,
.group-stats {
  display: flex;
  align-items: center;
}

.identity {
  gap: 14px;
  min-width: 0;
}

.brand-mark {
  width: 52px;
  height: 52px;
  display: grid;
  place-items: center;
  border: 2px solid var(--ink);
  border-radius: 6px;
  font-weight: 850;
  letter-spacing: 0;
  background: #e4f0ea;
}

.eyebrow {
  color: var(--gold);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  margin-top: 3px;
  font-size: 26px;
  line-height: 1.12;
}

h2 {
  font-size: 17px;
  line-height: 1.2;
}

.topbar-meta {
  justify-content: flex-end;
  gap: 10px;
  min-width: 0;
}

.dealer-breakdown {
  max-width: 420px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.state-pill {
  min-width: 82px;
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  padding: 0 12px;
  color: var(--ink);
  background: var(--surface-2);
  font-size: 13px;
  font-weight: 750;
}

.state-pill[data-type="busy"] {
  border-color: #9c7b34;
  color: #6b4e12;
  background: #fff7df;
}

.state-pill[data-type="ok"] {
  border-color: rgba(15, 107, 91, 0.42);
  color: var(--green);
  background: #e8f4ee;
}

.state-pill[data-type="error"] {
  border-color: rgba(180, 71, 62, 0.45);
  color: var(--red);
  background: #fff0ec;
}

.workbench {
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  gap: 16px;
  margin-top: 16px;
}

.control-rail,
.preview-panel,
.info-panel,
.metric {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.96);
  box-shadow: var(--shadow);
}

.control-rail {
  position: sticky;
  top: 18px;
  align-self: start;
  display: grid;
  gap: 14px;
  padding: 16px;
}

.rail-section {
  display: grid;
  gap: 12px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

.rail-section:last-child {
  padding-bottom: 0;
  border-bottom: 0;
}

.section-heading {
  justify-content: space-between;
  gap: 10px;
}

.section-index {
  color: var(--muted);
  font-family: "Cascadia Mono", Consolas, monospace;
  font-size: 12px;
}

label {
  display: grid;
  gap: 7px;
  min-width: 0;
}

label:has(#output-root) {
  grid-template-columns: minmax(0, 1fr) auto;
}

label:has(#output-root) span {
  grid-column: 1 / -1;
}

label span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 760;
}

input {
  width: 100%;
  min-width: 0;
  min-height: 40px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  padding: 8px 10px;
  color: var(--ink);
  background: #ffffff;
}

input:focus {
  outline: 3px solid rgba(15, 107, 91, 0.16);
  border-color: var(--accent);
}

.button-row {
  gap: 8px;
}

button,
.button {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  padding: 8px 13px;
  color: var(--ink);
  background: #ffffff;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}

button:hover,
.button:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.primary {
  border-color: var(--accent);
  color: var(--accent-ink);
  background: var(--accent);
}

.primary:hover {
  color: var(--accent-ink);
  background: #0b5e50;
}

.secondary-action {
  padding-inline: 12px;
}

.message {
  min-height: 42px;
  display: flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px 10px;
  color: var(--muted);
  background: var(--surface-2);
  font-size: 13px;
  font-weight: 680;
}

.message[data-type="ok"] {
  color: var(--green);
}

.message[data-type="warn"] {
  color: #866016;
}

.message[data-type="error"] {
  color: var(--red);
}

.main-stage {
  min-width: 0;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.metric {
  min-height: 94px;
  padding: 15px 16px;
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 740;
}

.metric strong {
  display: block;
  margin-top: 10px;
  font-size: 34px;
  line-height: 1;
}

.stage-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 16px;
  margin-top: 16px;
}

.preview-panel,
.info-panel {
  padding: 16px;
}

.panel-head {
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}

.panel-head.compact {
  margin-bottom: 12px;
}

.panel-note {
  color: var(--muted);
  font-size: 12px;
  font-weight: 720;
}

.invoice-list,
.inspector,
.output-box {
  display: grid;
  gap: 12px;
}

.invoice-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
  overflow: hidden;
}

.invoice-card-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  padding: 13px 14px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #ffffff, #f3f7f4);
}

.group-title {
  gap: 8px;
  min-width: 0;
}

.dealer-badge {
  border: 1px solid rgba(15, 107, 91, 0.32);
  border-radius: 999px;
  padding: 4px 9px;
  color: var(--accent);
  background: #e9f4ef;
  font-size: 12px;
  font-weight: 800;
}

.invoice-number {
  font-family: "Cascadia Mono", Consolas, monospace;
  font-size: 13px;
  font-weight: 780;
}

.remark {
  margin-top: 8px;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.group-stats {
  justify-content: flex-end;
  gap: 6px;
  flex-wrap: wrap;
}

.stat-chip {
  min-height: 28px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 9px;
  color: #3b403a;
  background: #ffffff;
  font-size: 12px;
  font-weight: 760;
}

.file-strip {
  padding: 10px 14px;
  color: #38403a;
  background: #fbfbf7;
  border-bottom: 1px solid var(--line);
  overflow-wrap: anywhere;
  font-size: 13px;
}

details {
  padding: 0;
}

summary {
  min-height: 40px;
  display: flex;
  align-items: center;
  padding: 0 14px;
  color: var(--accent);
  cursor: pointer;
  font-weight: 760;
}

.line-details {
  overflow: auto;
  border-top: 1px solid var(--line);
}

table {
  width: 100%;
  min-width: 860px;
  border-collapse: collapse;
  font-size: 12px;
}

th,
td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  color: #36403a;
  background: #eef2ea;
  font-weight: 800;
}

.line-table td:first-child,
.line-table td:nth-child(2) {
  min-width: 250px;
}

.field-list {
  display: grid;
  grid-template-columns: 106px minmax(0, 1fr);
  gap: 8px 10px;
  font-size: 13px;
}

.field-list dt {
  color: var(--muted);
}

.field-list dd {
  min-width: 0;
  margin: 0;
  font-weight: 760;
  overflow-wrap: anywhere;
}

.path {
  padding: 10px;
  border: 1px dashed var(--line-strong);
  border-radius: 6px;
  background: var(--surface-2);
  overflow-wrap: anywhere;
  font-family: "Cascadia Mono", Consolas, monospace;
  font-size: 12px;
}

.output-actions {
  gap: 8px;
  flex-wrap: wrap;
}

.output-count {
  color: #394139;
  font-weight: 760;
}

.warnings {
  margin: 0;
  padding-left: 18px;
  color: #866016;
}

.muted,
.empty-state {
  color: var(--muted);
}

.empty-state {
  min-height: 220px;
  display: grid;
  place-items: center;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.62);
  font-weight: 720;
}

@media (max-width: 1180px) {
  .workbench,
  .stage-grid {
    grid-template-columns: 1fr;
  }

  .control-rail {
    position: static;
  }

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

@media (max-width: 720px) {
  .app-shell {
    width: min(100vw - 20px, 680px);
    margin: 10px auto;
  }

  .topbar,
  .topbar-meta,
  .invoice-card-header {
    align-items: stretch;
    flex-direction: column;
  }

  .section-heading {
    justify-content: flex-start;
  }

  input[type="file"] {
    font-size: 13px;
  }

  label:has(#output-root) {
    grid-template-columns: 1fr;
  }

  .dealer-breakdown {
    max-width: 100%;
  }

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

  .button-row,
  .output-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  button,
  .button {
    width: 100%;
  }

  .group-stats {
    justify-content: flex-start;
  }
}
