:root {
  --c-primary: #1B4D3E;
  --c-primary-dark: #103B30;
  --c-base: #F0F2F5;
  --c-surface: #FFFFFF;
  --c-surface-soft: #FAFAF8;
  --c-border: #D7DDE2;
  --c-border-soft: #E8ECEF;
  --c-text: #111111;
  --c-text-sub: #4F5653;
  --c-muted: #7A807D;
  --c-accent: #F28C28;
  --c-good: #1B4D3E;
  --c-warn: #F28C28;
  --c-bad: #B8392B;
  --c-blue: #3568A8;
  --shadow-soft: 0 1px 2px rgba(17, 17, 17, 0.06);
  --shadow-panel: 0 18px 42px rgba(17, 17, 17, 0.08);
  --ff-gothic: "BIZ UDPGothic", -apple-system, BlinkMacSystemFont, "Hiragino Sans", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; overflow-x: hidden; }
body {
  font-family: var(--ff-gothic);
  color: var(--c-text);
  background:
    linear-gradient(118deg, rgba(27, 77, 62, 0.04) 0 18%, transparent 18%),
    linear-gradient(180deg, #FAFBFA 0, var(--c-base) 100%);
  font-size: 13px;
  letter-spacing: 0;
}

button, input, select { font: inherit; }
button { cursor: pointer; }
.material-icons-outlined { font-size: 18px; line-height: 1; }
.num, td, dd, strong { font-variant-numeric: tabular-nums; }

.boot {
  min-height: 100vh;
  display: grid;
  place-content: center;
  gap: 10px;
  text-align: center;
  padding: 32px;
}

.boot__eyebrow {
  color: var(--c-primary);
  font-weight: 700;
  letter-spacing: 0.12em;
}

.boot__text,
.boot p {
  color: var(--c-muted);
  line-height: 1.7;
}

.boot--error {
  max-width: 720px;
  margin: 0 auto;
  text-align: left;
  justify-items: start;
}

.boot--error h1 {
  margin: 0;
  color: var(--c-primary);
}

.boot--error pre {
  width: 100%;
  overflow: auto;
  padding: 14px;
  border: 1px solid var(--c-border);
  border-radius: 6px;
  background: #fff;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
}

.command-rail {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  padding: 14px 18px 10px;
  background: rgba(250, 250, 248, 0.96);
  border-bottom: 1px solid var(--c-border);
  backdrop-filter: blur(16px);
}

.brand-block {
  min-width: 0;
  display: grid;
  grid-template-columns: 148px 20px minmax(0, 1fr);
  gap: 14px;
  align-items: center;
}

.brand-logo {
  width: 148px;
  height: 30px;
  object-fit: contain;
  object-position: left center;
}

.brand-slash {
  width: 2px;
  height: 48px;
  transform: skew(-18deg);
  background: var(--c-accent);
}

h1, h2, h3, p { margin: 0; }
h1 {
  color: var(--c-text);
  font-size: 20px;
  line-height: 1.25;
}

.period-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 7px;
  color: var(--c-text-sub);
  font-size: 12px;
}

.sync-dot::after {
  content: "";
  width: 8px;
  height: 8px;
  margin-left: 6px;
  display: inline-block;
  border-radius: 50%;
  background: #2F8F5B;
}

.source-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.source-badges span,
.month-select,
.refresh-button,
.rule-button,
.mini-action,
.inspector-actions button {
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 0 12px;
  border: 1px solid var(--c-border);
  border-radius: 6px;
  background: #fff;
  color: var(--c-text);
  text-decoration: none;
  box-shadow: var(--shadow-soft);
}

.source-badges span {
  color: var(--c-text-sub);
  white-space: nowrap;
}

.source-badges .material-icons-outlined {
  color: var(--c-primary);
}

.status-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.status-tabs button {
  min-width: 68px;
  padding: 7px 10px;
  border: 1px solid var(--c-border);
  border-radius: 6px;
  background: #fff;
  color: var(--c-text);
  display: grid;
  gap: 2px;
  box-shadow: var(--shadow-soft);
}

.status-tabs button span {
  font-size: 12px;
  color: var(--c-text-sub);
}

.status-tabs button strong {
  font-size: 14px;
}

.status-tabs button.is-active {
  border-color: var(--c-primary);
  box-shadow: inset 0 -3px 0 var(--c-primary);
}

.command-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.month-select select {
  border: 0;
  background: transparent;
  min-width: 112px;
  color: var(--c-text);
}

.refresh-button {
  border-color: var(--c-primary);
  background: var(--c-primary);
  color: #fff;
  font-weight: 700;
}

.workbench {
  max-width: 100vw;
  display: grid;
  grid-template-columns: minmax(250px, 0.78fr) minmax(0, 1.55fr) minmax(300px, 0.92fr);
  grid-template-rows: auto 1fr auto;
  grid-template-areas:
    "sample sample sample"
    "queue map inspector"
    "kpis kpis kpis";
  gap: 14px;
  padding: 14px 18px 18px;
  overflow-x: hidden;
}

.sample-banner {
  grid-area: sample;
  padding: 9px 12px;
  border: 1px solid rgba(242, 140, 40, 0.36);
  border-radius: 6px;
  background: rgba(242, 140, 40, 0.08);
  color: #7A3D00;
}

.queue-pane,
.map-canvas,
.inspector-pane,
.kpi-ledger {
  min-width: 0;
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid var(--c-border);
  border-radius: 8px;
  box-shadow: var(--shadow-panel);
}

.queue-pane {
  grid-area: queue;
  display: grid;
  grid-template-rows: auto 1fr;
  overflow: hidden;
}

.map-canvas {
  grid-area: map;
  position: relative;
  padding: 14px;
  overflow: hidden;
}

.inspector-pane {
  grid-area: inspector;
  padding: 14px;
}

.kpi-ledger {
  grid-area: kpis;
  display: grid;
  grid-template-columns: 1.35fr repeat(7, minmax(120px, 1fr));
  gap: 0;
  overflow: hidden;
}

.pane-head,
.map-head {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 12px;
  padding: 14px;
  border-bottom: 1px solid var(--c-border-soft);
}

.map-head {
  padding: 0 0 12px;
}

.pane-head h2,
.map-head h2 {
  color: var(--c-text);
  font-size: 16px;
  line-height: 1.35;
}

.pane-head p,
.map-head p {
  margin-top: 3px;
  color: var(--c-muted);
  font-size: 12px;
}

.queue-tools {
  display: flex;
  align-items: center;
  gap: 8px;
}

.queue-tools button {
  width: 34px;
  height: 34px;
  border: 1px solid var(--c-border);
  border-radius: 6px;
  background: #fff;
  color: var(--c-primary);
}

.queue-tools input {
  width: 150px;
  min-height: 34px;
  border: 1px solid var(--c-border);
  border-radius: 6px;
  padding: 0 9px;
}

.queue-groups {
  overflow: auto;
  padding: 10px;
}

.queue-group {
  border-bottom: 1px solid var(--c-border-soft);
  padding-bottom: 10px;
  margin-bottom: 10px;
}

.queue-group__head {
  width: 100%;
  min-height: 32px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border: 0;
  background: transparent;
  color: var(--c-text);
  font-weight: 700;
}

.queue-row {
  width: 100%;
  min-height: 52px;
  margin-top: 4px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 9px 10px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--c-text);
  text-align: left;
}

.queue-row:hover,
.queue-row.is-selected {
  border-color: rgba(242, 140, 40, 0.72);
  background: rgba(242, 140, 40, 0.06);
}

.queue-row span {
  min-width: 0;
  display: grid;
  gap: 3px;
}

.queue-row small {
  overflow: hidden;
  color: var(--c-text-sub);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.is-bad { color: var(--c-bad) !important; }

.status-pill {
  padding: 5px 9px;
  border-radius: 999px;
  border: 1px solid var(--c-border);
  font-size: 12px;
  font-weight: 700;
}

.status-ok { color: var(--c-primary); background: rgba(27, 77, 62, 0.08); border-color: rgba(27, 77, 62, 0.25); }
.status-warn, .status-freight { color: #8A4A00; background: rgba(242, 140, 40, 0.12); border-color: rgba(242, 140, 40, 0.34); }
.status-bad { color: var(--c-bad); background: rgba(184, 57, 43, 0.08); border-color: rgba(184, 57, 43, 0.25); }
.status-ocr { color: var(--c-blue); background: rgba(53, 104, 168, 0.08); border-color: rgba(53, 104, 168, 0.25); }

.record-node {
  position: relative;
  z-index: 1;
  margin: 12px 0 18px;
  display: grid;
  grid-template-columns: minmax(220px, 1fr) 1.4fr;
  gap: 14px;
  align-items: center;
  padding: 14px;
  border: 1px solid var(--c-primary);
  border-radius: 8px;
  background: linear-gradient(90deg, rgba(27, 77, 62, 0.05), #fff);
}

.node-label {
  display: inline-flex;
  margin-bottom: 7px;
  padding: 4px 8px;
  border-radius: 5px;
  background: var(--c-primary);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
}

.record-node strong {
  display: block;
  font-size: 24px;
}

.record-node dl,
.invoice-preview dl {
  margin: 0;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.invoice-preview dl {
  grid-template-columns: 1fr;
}

dt {
  color: var(--c-muted);
  font-size: 11px;
}

dd {
  margin: 3px 0 0;
  color: var(--c-text);
  font-weight: 700;
}

.map-lines {
  position: absolute;
  inset: 110px 22px auto;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(27, 77, 62, 0.55), transparent);
}

.line-section {
  position: relative;
  z-index: 1;
  margin-top: 12px;
  border: 1px solid var(--c-border);
  border-radius: 7px;
  overflow: hidden;
  background: #fff;
}

.line-section {
  overflow-x: auto;
}

.line-section::before {
  content: "";
  position: absolute;
  left: 50%;
  top: -13px;
  width: 1px;
  height: 13px;
  background: var(--c-primary);
}

.line-section__head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  border-bottom: 1px solid var(--c-border-soft);
}

.line-section__head h3 {
  font-size: 13px;
}

.line-section__head span {
  color: var(--c-primary);
  font-size: 12px;
  font-weight: 700;
}

table {
  width: 100%;
  border-collapse: collapse;
}

.line-section table {
  min-width: 620px;
}

th, td {
  padding: 9px 8px;
  border-bottom: 1px solid var(--c-border-soft);
  text-align: left;
  vertical-align: middle;
  white-space: nowrap;
}

th {
  color: var(--c-text-sub);
  background: #FAFBFA;
  font-size: 11px;
  font-weight: 700;
}

td {
  color: var(--c-text);
  font-size: 12px;
}

.warning-callout {
  margin-top: 12px;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 10px 12px;
  border: 1px solid rgba(242, 140, 40, 0.35);
  border-radius: 7px;
  background: rgba(242, 140, 40, 0.08);
  color: #7A3D00;
}

.check-table {
  border: 1px solid var(--c-border);
  border-radius: 7px;
  overflow: hidden;
  display: block;
  max-width: 100%;
  overflow-x: auto;
}

.check {
  width: 22px;
  height: 22px;
  display: inline-grid;
  place-items: center;
  border-radius: 50%;
  color: #fff;
  font-weight: 700;
}

.check-pass { background: var(--c-primary); }
.check-warn { background: var(--c-accent); }
.check-fail { background: var(--c-bad); }

.rule-button,
.mini-action {
  min-height: 30px;
  padding: 0 10px;
  box-shadow: none;
}

.invoice-card {
  margin-top: 14px;
  border: 1px solid var(--c-border);
  border-radius: 8px;
  overflow: hidden;
}

.invoice-card__head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 11px 12px;
  border-bottom: 1px solid var(--c-border-soft);
}

.invoice-card__head h3 {
  font-size: 14px;
}

.invoice-card__head a {
  color: var(--c-primary);
  font-weight: 700;
  text-decoration: none;
}

.invoice-preview {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  padding: 12px;
}

.invoice-preview > div:first-child {
  min-height: 152px;
  padding: 16px;
  display: grid;
  place-items: center;
  text-align: center;
  border: 1px dashed rgba(184, 57, 43, 0.42);
  background:
    linear-gradient(0deg, rgba(184,57,43,0.04), rgba(184,57,43,0.04)),
    #fff;
}

.invoice-preview span {
  color: var(--c-text-sub);
  font-size: 12px;
}

.invoice-preview b {
  color: var(--c-text);
  font-size: 17px;
}

.inspector-actions {
  margin-top: 12px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.inspector-actions button {
  justify-content: center;
  min-height: 42px;
  font-weight: 700;
}

.primary-action {
  border-color: var(--c-primary) !important;
  background: var(--c-primary) !important;
  color: #fff !important;
}

.warn-action {
  border-color: rgba(242, 140, 40, 0.54) !important;
  color: #9A5200 !important;
}

.is-tapped {
  transform: translateY(1px);
}

.kpi-title {
  padding: 15px 18px;
  display: grid;
  align-content: center;
  border-right: 1px solid var(--c-border);
}

.kpi-title strong {
  color: var(--c-text);
  font-size: 15px;
}

.kpi-title span {
  margin-top: 5px;
  color: var(--c-text-sub);
  font-size: 12px;
}

.ledger-item {
  min-width: 0;
  padding: 15px 16px;
  border-right: 1px solid var(--c-border);
}

.ledger-item span {
  display: block;
  color: var(--c-text-sub);
  font-size: 12px;
}

.ledger-item strong {
  display: block;
  margin-top: 7px;
  font-size: 20px;
}

.ledger-item small {
  margin-left: 4px;
  color: var(--c-text-sub);
  font-size: 11px;
}

.ledger-bar {
  height: 5px;
  margin-top: 10px;
  border-radius: 999px;
  background: var(--c-border-soft);
  overflow: hidden;
}

.ledger-bar i {
  height: 100%;
  display: block;
  border-radius: inherit;
}

.empty-panel {
  padding: 24px;
  color: var(--c-muted);
}

.empty-panel h2 {
  margin-bottom: 8px;
  color: var(--c-primary);
}

@media (max-width: 1180px) {
  .command-rail {
    grid-template-columns: 1fr;
  }

  .source-badges,
  .status-tabs,
  .command-actions {
    overflow-x: auto;
  }

  .workbench {
    grid-template-columns: 1fr;
    grid-template-areas:
      "sample"
      "queue"
      "map"
      "inspector"
      "kpis";
  }

  .queue-pane {
    max-height: 520px;
  }

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

  .kpi-title,
  .ledger-item {
    border-bottom: 1px solid var(--c-border);
  }
}

@media (max-width: 720px) {
  body {
    font-size: 12px;
  }

  .command-rail,
  .workbench {
    padding-left: 10px;
    padding-right: 10px;
  }

  .brand-block {
    grid-template-columns: 112px 12px minmax(0, 1fr);
  }

  .brand-logo {
    width: 112px;
  }

  h1 {
    font-size: 17px;
  }

  .record-node,
  .invoice-preview {
    grid-template-columns: 1fr;
  }

  .record-node dl {
    grid-template-columns: 1fr 1fr;
  }

  .inspector-actions,
  .kpi-ledger {
    grid-template-columns: 1fr;
  }
}
