:root {
  color-scheme: light;
  --ink: #16211d;
  --muted: #5d6c66;
  --line: #d8e0dc;
  --paper: #f7f8f5;
  --panel: #ffffff;
  --accent: #0f6f65;
  --danger: #b42318;
  --danger-soft: #fee4e2;
  --success: #067647;
  --success-soft: #dcfae6;
  --warning: #93620b;
  --warning-soft: #fff8e6;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body.is-busy {
  cursor: wait;
}

.shell {
  max-width: 1180px;
  margin: 0 auto;
  padding: 32px 20px 56px;
}

.app-frame {
  display: grid;
  grid-template-columns: 236px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  background: #10251f;
  color: white;
  display: flex;
  flex-direction: column;
  padding: 22px 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 28px;
  font-weight: 800;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: #f0c85a;
  color: #10251f;
  font-size: 13px;
  font-weight: 900;
}

.side-nav {
  align-content: start;
  display: grid;
  flex: 0 0 auto;
  gap: 6px;
}

.side-nav a {
  border-radius: 6px;
  color: #dce8e3;
  padding: 10px 12px;
}

.side-nav a.active,
.side-nav a:hover {
  background: #1f3c33;
  color: white;
}

.side-nav__section {
  border-top: 1px solid #315047;
  color: #91aaa0;
  font-size: 10px;
  font-weight: 800;
  margin-top: 10px;
  padding: 16px 12px 4px;
  text-transform: uppercase;
}

.impersonation-notice {
  background: #f0c85a;
  border-radius: 6px;
  color: #10251f;
  display: grid;
  gap: 5px;
  margin: -8px 0 18px;
  padding: 12px;
}

.impersonation-notice span {
  font-size: 12px;
  overflow-wrap: anywhere;
}

.impersonation-notice button {
  background: #10251f;
  min-height: 32px;
  padding: 5px 9px;
  width: 100%;
}

.main {
  min-width: 0;
  padding: 24px clamp(18px, 3vw, 40px) 56px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 28px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

.muted {
  color: var(--muted);
}

.language-pill {
  display: flex;
  gap: 4px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: white;
  padding: 4px;
  text-align: center;
  font-size: 12px;
  font-weight: 800;
}

.language-pill a {
  border-radius: 999px;
  color: var(--muted);
  padding: 4px 7px;
}

.language-pill a.active {
  background: #10251f;
  color: white;
}

.page-title {
  margin-bottom: 22px;
}

.page-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 24px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

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

h1 {
  font-size: 32px;
}

h2 {
  font-size: 18px;
  margin-bottom: 16px;
}

.panel,
.notice {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-bottom: 18px;
  padding: 18px;
}

.notice {
  border-color: #efd28a;
  background: var(--warning-soft);
  color: var(--warning);
}

.busy-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(16, 37, 31, 0.42);
  backdrop-filter: blur(2px);
}

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

.busy-overlay__panel {
  display: grid;
  justify-items: center;
  gap: 10px;
  min-width: min(320px, 90vw);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 24px;
  background: var(--panel);
  box-shadow: 0 20px 60px rgba(15, 23, 42, 0.22);
  text-align: center;
}

.busy-overlay__panel span:last-child {
  color: var(--muted);
  font-size: 13px;
}

.busy-hourglass {
  position: relative;
  width: 34px;
  height: 46px;
  animation: busy-hourglass-flip 1.6s ease-in-out infinite;
}

.busy-hourglass::before,
.busy-hourglass::after {
  content: "";
  position: absolute;
  left: 4px;
  width: 26px;
  height: 20px;
  border: 2px solid var(--accent);
}

.busy-hourglass::before {
  top: 0;
  border-radius: 14px 14px 4px 4px;
  background: linear-gradient(to bottom, rgba(15, 111, 101, 0.24) 55%, transparent 56%);
}

.busy-hourglass::after {
  bottom: 0;
  border-radius: 4px 4px 14px 14px;
  background: linear-gradient(to top, rgba(15, 111, 101, 0.24) 40%, transparent 41%);
}

@keyframes busy-hourglass-flip {
  0%,
  45% {
    transform: rotate(0deg);
  }
  55%,
  100% {
    transform: rotate(180deg);
  }
}

.nav-link,
a {
  color: var(--accent);
  font-weight: 650;
  text-decoration: none;
}

.job-form {
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr)) auto;
  align-items: end;
  gap: 14px;
}

.job-form--compact {
  grid-template-columns: minmax(150px, 220px) auto;
  justify-content: start;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

input {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  color: var(--ink);
  font: inherit;
}

select {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: white;
  color: var(--ink);
  font: inherit;
  padding: 8px 10px;
}

.order-form {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) minmax(160px, 220px) auto;
  align-items: end;
  gap: 14px;
}

.report-form {
  display: grid;
  grid-template-columns: minmax(120px, 180px) minmax(280px, 1fr) auto;
  align-items: end;
  gap: 14px;
}

.filter-form {
  align-items: end;
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(2, minmax(170px, 240px)) auto;
}

.filter-form input,
.filter-form select {
  min-width: 0;
  width: 100%;
}

.filter-actions {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.secondary-link {
  background: #e8efec;
  color: var(--ink);
}

.secondary-link:hover {
  color: var(--ink);
}

.scenario-form {
  display: grid;
  gap: 18px;
}

.scenario-form__header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 18px;
}

.scenario-form__header p {
  margin: 6px 0 0;
}

.scenario-form__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

.config-form {
  display: grid;
  gap: 14px;
}

.config-form input {
  width: 100%;
}

.field-hint {
  color: var(--muted);
  display: block;
  font-size: 12px;
  margin-top: 4px;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
}

.scenario-controls {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 14px;
}

.scenario-split {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

fieldset {
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 12px;
  margin: 0;
  padding: 14px;
}

legend {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

input[type="range"] {
  accent-color: var(--accent);
  padding: 0;
}

.range-value {
  color: var(--ink);
  font-size: 12px;
  font-weight: 800;
}

.return-control {
  align-items: end;
  display: grid;
  gap: 10px;
  grid-template-columns: minmax(0, 1fr) 92px;
}

.return-control__number {
  min-width: 0;
}

.scenario-switch {
  display: grid;
  gap: 10px;
  max-width: 760px;
}

.scenario-switch__title {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.scenario-switch__control {
  align-items: center;
  color: var(--ink);
  display: grid;
  font-size: 13px;
  font-weight: 750;
  gap: 12px;
  grid-template-columns: minmax(0, 1fr) 54px minmax(0, 1fr);
}

.scenario-switch__control input {
  inline-size: 1px;
  block-size: 1px;
  opacity: 0;
  position: absolute;
}

.scenario-switch__track {
  background: #dbe5e1;
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
  display: block;
  height: 30px;
  position: relative;
  width: 54px;
}

.scenario-switch__track::after {
  background: white;
  border: 1px solid #c6d3ce;
  border-radius: 999px;
  box-shadow: 0 1px 4px rgb(16 37 31 / 18%);
  content: "";
  height: 24px;
  left: 2px;
  position: absolute;
  top: 2px;
  transition: transform 140ms ease, border-color 140ms ease;
  width: 24px;
}

.scenario-switch__control input:checked + .scenario-switch__track {
  background: var(--accent);
  border-color: var(--accent);
}

.scenario-switch__control input:checked + .scenario-switch__track::after {
  border-color: var(--accent);
  transform: translateX(24px);
}

.scenario-switch__control input:focus-visible + .scenario-switch__track {
  outline: 3px solid #b7ded8;
  outline-offset: 2px;
}

.scenario-results .kpi-grid {
  margin-top: 12px;
}

.scenario-comparison,
.scenario-waterfall,
.scenario-variants {
  border-top: 1px solid var(--line);
  display: grid;
  gap: 12px;
  margin-top: 18px;
  padding-top: 18px;
}

.scenario-comparison h3,
.scenario-waterfall h3,
.scenario-variants h3 {
  font-size: 16px;
  margin: 0;
}

.scenario-audit {
  border-top: 1px solid var(--line);
  display: grid;
  gap: 16px;
  margin-top: 18px;
  padding-top: 18px;
}

.scenario-audit h3,
.scenario-audit h4 {
  margin: 0;
}

.scenario-audit h3 {
  font-size: 16px;
}

.scenario-audit h4 {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

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

.scenario-audit__list,
.scenario-audit__files {
  display: grid;
  gap: 8px;
  margin: 8px 0 0;
  padding-left: 18px;
}

.scenario-audit__files code {
  font-size: 12px;
}

.checkbox {
  grid-template-columns: 18px auto;
  align-items: center;
  gap: 8px;
  min-height: 40px;
}

.checkbox input {
  min-height: 0;
}

button {
  min-height: 40px;
  border: 0;
  border-radius: 6px;
  background: var(--accent);
  color: white;
  cursor: pointer;
  font: inherit;
  font-weight: 750;
  padding: 8px 16px;
}

.button-link {
  align-items: center;
  background: var(--accent);
  border-radius: 6px;
  color: white;
  display: inline-flex;
  font-weight: 800;
  min-height: 40px;
  padding: 8px 16px;
}

.button-link:hover {
  color: white;
}

.action-panel {
  align-items: center;
  display: flex;
  justify-content: space-between;
  gap: 20px;
}

.action-panel p,
.empty-state p {
  color: var(--muted);
  margin: 8px 0 0;
}

.empty-state {
  min-height: 220px;
  display: grid;
  align-content: center;
  justify-items: start;
  gap: 12px;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.kpi-card {
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
}

.kpi-card p {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  margin: 0 0 8px;
  text-transform: uppercase;
}

.kpi-card strong {
  display: block;
  font-size: clamp(22px, 2vw, 30px);
  line-height: 1.1;
}

.kpi-card span {
  color: var(--muted);
  display: block;
  font-size: 13px;
  margin-top: 8px;
}

.kpi-card--cost strong,
.cost {
  color: var(--danger);
}

.kpi-card--loss strong,
.loss {
  color: var(--danger);
  font-weight: 800;
}

.kpi-card--profit strong,
.profit {
  color: var(--success);
  font-weight: 800;
}

.kpi-card--warning {
  background: var(--warning-soft);
  border-color: #efd28a;
}

.cost-list {
  display: grid;
  gap: 10px;
}

.cost-row {
  align-items: center;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 10px;
}

.cost-row:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.view-switch {
  align-items: end;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 14px;
}

.view-switch label {
  min-width: min(280px, 100%);
}

.source-panel {
  display: grid;
  gap: 10px;
}

.calculation-flow {
  background: #fbfcfa;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow-x: auto;
}

.calculation-flow svg {
  display: block;
  min-width: 920px;
  width: 100%;
}

.flow-basis {
  border-top: 1px solid var(--line);
  padding: 14px 18px 16px;
}

.flow-basis h3 {
  font-size: 14px;
  margin: 0 0 10px;
}

.flow-basis ul {
  display: grid;
  gap: 8px;
  list-style: none;
  margin: 0;
  padding: 0;
}

.flow-basis li {
  align-items: baseline;
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
}

.flow-basis span {
  color: var(--muted);
  font-size: 13px;
}

.flow-node rect,
.flow-running rect {
  fill: white;
  stroke: var(--line);
}

.flow-node--revenue rect {
  fill: #e4f6ef;
  stroke: #8ed8bd;
}

.flow-node--cost rect {
  fill: #fff1f0;
  stroke: #ffb4ab;
}

.flow-node--profit rect {
  fill: #e4f6ef;
  stroke: #8ed8bd;
}

.flow-node--loss rect {
  fill: #fff1f0;
  stroke: #ffb4ab;
}

.flow-node-label,
.flow-amount text:first-child,
.flow-running text:first-child {
  fill: var(--ink);
  font-size: 16px;
  font-weight: 800;
}

.flow-node-field,
.flow-formula,
.flow-basis-inline {
  fill: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 12px;
}

.flow-basis-inline {
  fill: #45564f;
  font-weight: 700;
}

.flow-connector {
  stroke: #9aaba4;
  stroke-width: 2;
}

.flow-arrow-head {
  fill: #9aaba4;
}

.flow-cost,
.flow-loss {
  fill: var(--danger) !important;
}

.flow-profit {
  fill: var(--success) !important;
}

.schema-diagram {
  background: #fbfcfa;
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-bottom: 18px;
  overflow-x: auto;
}

.schema-diagram svg {
  display: block;
  min-width: 1060px;
  width: 100%;
}

.schema-node rect {
  fill: #fffaf0;
  stroke: #d9b77e;
  stroke-width: 1.2;
}

.schema-node__header {
  fill: #7cc9df !important;
  stroke: #5799aa !important;
}

.schema-node--document rect {
  fill: #fff1f0;
  stroke: #ffb4ab;
}

.schema-node--document .schema-node__header {
  fill: #ffb4ab !important;
  stroke: #d77d74 !important;
}

.schema-node--bridge rect {
  fill: #eff8d7;
  stroke: #b5d36d;
}

.schema-node--bridge .schema-node__header {
  fill: #bfe06a !important;
  stroke: #8ead42 !important;
}

.schema-node--marketplace rect {
  fill: #eef4ff;
  stroke: #9ebcea;
}

.schema-node--marketplace .schema-node__header {
  fill: #9ebcea !important;
  stroke: #6f93ca !important;
}

.schema-node__title {
  fill: var(--ink);
  font-size: 14px;
  font-weight: 800;
}

.schema-node__column {
  fill: var(--ink);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 12px;
}

.schema-edge line {
  stroke: #64736d;
  stroke-width: 1.8;
}

.schema-edge text {
  fill: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 11px;
}

.schema-arrow-head {
  fill: #64736d;
}

.schema-legend rect {
  fill: white;
  stroke: var(--line);
}

.schema-legend text {
  fill: var(--muted);
  font-size: 13px;
}

.schema-legend__title {
  fill: var(--ink) !important;
  font-weight: 800;
}

.schema-role--source {
  fill: #7cc9df;
}

.schema-role--document {
  fill: #ffb4ab;
}

.schema-role--bridge {
  fill: #bfe06a;
}

.schema-role--marketplace {
  fill: #9ebcea;
}

.relation-map {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.relation-node {
  background: #fbfcfa;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
}

.relation-node h3,
.formula-card h3,
.relation-edges h3 {
  font-size: 15px;
  margin: 0 0 8px;
}

.relation-node p {
  color: var(--muted);
  font-size: 13px;
  margin: 0 0 10px;
}

.relation-node ul,
.formula-card ul,
.relation-edges ol {
  display: grid;
  gap: 8px;
  margin: 0;
  padding-left: 18px;
}

.relation-node li {
  display: grid;
  gap: 3px;
}

.relation-node li span {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.relation-node code,
.formula-card code,
.relation-edges code {
  display: inline;
  font-size: 12px;
  overflow-wrap: anywhere;
  padding: 2px 5px;
}

.relation-edges {
  border-top: 1px solid var(--line);
  margin-top: 16px;
  padding-top: 16px;
}

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

.formula-card {
  background: #fbfcfa;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 12px;
  padding: 14px;
}

.formula-card > code {
  display: block;
  line-height: 1.5;
  padding: 10px;
}

.section-head {
  align-items: start;
  display: flex;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 14px;
}

.section-head h2 {
  margin-bottom: 4px;
}

.section-head p {
  margin: 0;
}

.section-head strong {
  background: #e8efec;
  border-radius: 999px;
  color: var(--ink);
  display: inline-flex;
  font-size: 13px;
  padding: 6px 10px;
  white-space: nowrap;
}

.pagination-bar {
  align-items: center;
  border-top: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  padding-top: 12px;
}

.pagination-actions {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.meta-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 12px;
}

.meta-grid > div {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

.meta-grid strong {
  display: block;
  overflow-wrap: anywhere;
}

code {
  background: #eef3f0;
  border: 1px solid var(--line);
  border-radius: 6px;
  display: block;
  overflow-x: auto;
  padding: 10px;
}

.report-viewer pre {
  background: #fbfcfa;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  font: 13px/1.55 ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  margin: 0;
  overflow-x: auto;
  padding: 16px;
  white-space: pre-wrap;
}

button:disabled {
  cursor: not-allowed;
  opacity: .48;
}

button.secondary {
  background: #e8efec;
  color: var(--ink);
}

.table-wrap {
  overflow-x: auto;
}

.inventory-summary {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.inventory-filter-form {
  grid-template-columns: minmax(190px, 240px) minmax(240px, 1fr) minmax(170px, 220px) minmax(180px, 230px) minmax(120px, 160px) auto;
}

.inventory-list-heading,
.inventory-pager {
  align-items: center;
  display: flex;
  gap: 16px;
  justify-content: space-between;
}

.inventory-pager {
  color: var(--muted);
  margin-bottom: 12px;
}

.inventory-pager > span:last-child {
  display: inline-flex;
  gap: 10px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

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

th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.audit-table {
  min-width: 920px;
}

.audit-table th {
  background: #f2f6f4;
  border-bottom-color: #c8d4cf;
  position: sticky;
  top: 0;
  z-index: 1;
}

table tbody tr:nth-child(even),
.zebra-table tbody tr:nth-child(even) {
  background: #f4f7f5;
}

table tbody tr:hover,
.zebra-table tbody tr:hover {
  background: #edf4f1;
}

.inventory-table td:first-child {
  min-width: 260px;
  white-space: normal;
}

.inventory-table .table-subtle {
  color: var(--muted);
  display: block;
  font-size: 12px;
  font-weight: 650;
  margin-top: 3px;
}

.number-cell {
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.warehouse-summary-groups {
  display: grid;
  gap: 18px;
  margin-bottom: 18px;
}

.warehouse-summary-heading {
  margin-bottom: 12px;
}

.warehouse-summary-heading h2 {
  margin-bottom: 4px;
}

.warehouse-summary-heading p {
  margin: 0;
}

.warehouse-summary-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin-bottom: 0;
}

.sort-link {
  align-items: center;
  color: inherit;
  display: inline-flex;
  gap: 5px;
}

.sort-link.is-active {
  color: var(--accent);
}

.empty {
  color: var(--muted);
  text-align: center;
}

.status {
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 2px 10px;
  background: #e8efec;
  color: var(--ink);
  font-size: 12px;
  font-weight: 750;
}

.status-running,
.status-queued {
  background: #e7f2ff;
  color: #175cd3;
}

.status-failed,
.status-timeout,
.status-cancelled {
  background: #fee4e2;
  color: var(--danger);
}

.status-success {
  background: #dcfae6;
  color: #067647;
}

.returns-table .status-pill,
.product-sales-table .status-pill,
.return-details-panel .status-pill {
  background: #eef3ef;
  border: 1px solid #c8d4cf;
  border-radius: 999px;
  color: var(--muted);
  display: inline-flex;
  font-size: 12px;
  font-weight: 750;
  padding: 3px 8px;
  white-space: nowrap;
}

.returns-table .status-pill.warning,
.return-details-panel .status-pill.warning {
  background: #fff7e6;
  border-color: #f1c56d;
  color: #7a4b00;
}

.return-details-row[hidden] {
  display: none;
}

.return-details-row > td {
  background: #fbfcfb;
  padding: 0;
  white-space: normal;
}

.return-details-slot[hidden],
.return-details-slot:empty {
  display: none;
}

.return-details-panel {
  border-top: 1px solid #d8e2dd;
  padding: 18px;
}

.return-details-panel > header {
  align-items: flex-start;
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.return-details-panel h3,
.return-details-panel h4 {
  margin: 0;
}

.return-details-panel header p,
.return-credit-note p {
  margin: 6px 0 0;
}

.return-credit-note {
  border-top: 1px solid #e0e8e4;
  padding-top: 14px;
}

.return-credit-note + .return-credit-note {
  margin-top: 16px;
}

.return-entry-table {
  min-width: 860px;
}

.job-status {
  display: grid;
  gap: 14px;
}

.job-status__main,
.job-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
}

.job-log-panel {
  margin-top: 16px;
}

.job-log-inline {
  min-width: 180px;
}

.job-log {
  max-height: 280px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
  margin-top: 10px;
  padding: 12px;
  background: #0f172a;
  color: #e2e8f0;
  font-size: 12px;
  line-height: 1.55;
  white-space: pre-wrap;
}

dl {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin: 0;
}

dt {
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
  text-transform: uppercase;
}

dd {
  margin: 4px 0 0;
  overflow-wrap: anywhere;
}

.sidebar-account {
  border-top: 1px solid #315047;
  display: grid;
  gap: 8px;
  margin-top: 22px;
  padding: 16px 4px 0;
}

.sidebar-account a,
.sidebar-logout {
  color: #dce8e3;
  font-size: 13px;
  text-align: left;
}

.sidebar-account a:first-child {
  display: grid;
  gap: 3px;
}

.sidebar-account small {
  color: #9eb3aa;
  font-weight: 500;
  overflow-wrap: anywhere;
}

.sidebar-logout {
  background: transparent;
  min-height: 32px;
  padding: 4px 0;
}

.auth-body {
  background: #edf1ee;
  min-height: 100vh;
}

.auth-shell {
  margin: 0 auto;
  max-width: 1040px;
  padding: clamp(22px, 5vw, 64px) 20px;
}

.auth-masthead {
  align-items: center;
  display: flex;
  justify-content: space-between;
  margin-bottom: 18px;
}

.auth-brand {
  align-items: center;
  color: var(--ink);
  display: flex;
  gap: 12px;
}

.auth-brand > span:last-child {
  display: grid;
  gap: 2px;
}

.auth-brand small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.auth-surface {
  background: white;
  border: 1px solid #cad5cf;
  border-radius: 8px;
  display: grid;
  grid-template-columns: minmax(220px, .72fr) minmax(360px, 1fr);
  min-height: 570px;
  overflow: hidden;
}

.auth-context {
  align-content: end;
  background: #16352c;
  color: white;
  display: grid;
  gap: 0;
  padding: 32px;
}

.auth-context span {
  border-top: 1px solid #47665c;
  font-size: 13px;
  font-weight: 700;
  padding: 16px 0;
}

.auth-context span::before {
  color: #f0c85a;
  content: "✓";
  margin-right: 9px;
}

.auth-form-panel {
  align-content: center;
  display: grid;
  padding: clamp(30px, 6vw, 72px);
}

.auth-form-panel h1 {
  font-size: 30px;
}

.auth-lead {
  color: var(--muted);
  line-height: 1.55;
  margin: 10px 0 24px;
}

.auth-form {
  display: grid;
  gap: 16px;
}

.auth-form label small {
  color: var(--muted);
  font-weight: 500;
  line-height: 1.4;
}

.auth-form input:focus,
.auth-form select:focus,
button:focus-visible,
a:focus-visible {
  outline: 3px solid rgba(15, 111, 101, .24);
  outline-offset: 2px;
}

.auth-secondary-action {
  display: inline-block;
  font-size: 13px;
  margin-top: 18px;
}

.form-error {
  background: var(--danger-soft);
  border: 1px solid #f4aaa5;
  border-radius: 6px;
  color: var(--danger);
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 18px;
  padding: 12px;
}

.form-success {
  background: var(--success-soft);
  border: 1px solid #8bd8a9;
  border-radius: 6px;
  color: var(--success);
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 18px;
  padding: 12px;
}

.form-warning {
  background: var(--warning-soft);
  border: 1px solid #efd28a;
  border-radius: 6px;
  color: var(--warning);
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 18px;
  padding: 12px;
}

.form-warning a {
  color: inherit;
  text-decoration: underline;
}

.totp-enrollment {
  align-items: center;
  border-bottom: 1px solid var(--line);
  display: grid;
  gap: 24px;
  grid-template-columns: 220px 1fr;
  margin-bottom: 22px;
  padding-bottom: 22px;
}

.totp-enrollment img {
  aspect-ratio: 1;
  background: white;
  border: 1px solid var(--line);
  border-radius: 6px;
  display: block;
  height: auto;
  max-width: 100%;
}

.secret-code {
  display: block;
  font-size: 13px;
  overflow-wrap: anywhere;
}

.recovery-code-list {
  columns: 2;
  list-style-position: inside;
  margin: 22px 0;
  padding: 0;
}

.recovery-code-list li {
  break-inside: avoid;
  padding: 7px 0;
}

.start-heading {
  align-items: end;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  margin-bottom: 4px;
  padding: 18px 0 26px;
}

.snapshot-readiness {
  border-left: 4px solid var(--warning);
  display: grid;
  gap: 3px;
  min-width: 220px;
  padding: 6px 0 6px 14px;
}

.snapshot-readiness.is-ready {
  border-color: var(--success);
}

.snapshot-readiness span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.module-directory {
  display: grid;
  margin-bottom: 26px;
}

.module-entry {
  align-items: center;
  border-bottom: 1px solid var(--line);
  color: var(--ink);
  display: grid;
  gap: 18px;
  grid-template-columns: 42px minmax(0, 1fr) 28px;
  min-height: 86px;
  padding: 16px 4px;
}

.module-entry:hover {
  background: #eef4f1;
  color: var(--ink);
}

.module-entry__index {
  color: var(--accent);
  font: 800 13px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
}

.module-entry > span:nth-child(2) {
  display: grid;
  gap: 5px;
}

.module-entry small {
  color: var(--muted);
  font-weight: 500;
}

.module-entry__arrow {
  color: var(--accent);
  font-size: 20px;
}

.start-status-band {
  align-items: center;
  background: #e5ece8;
  border-left: 4px solid var(--accent);
  display: grid;
  gap: 18px;
  grid-template-columns: minmax(0, 1fr) auto auto;
  padding: 16px 18px;
}

.start-status-band > div {
  display: grid;
  gap: 3px;
}

.start-status-band div span {
  color: var(--muted);
  font-size: 12px;
}

.account-panel {
  max-width: 680px;
}

.account-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.button-quiet {
  background: #e8efec;
  color: var(--ink);
  min-height: 32px;
  padding: 5px 10px;
}

.admin-create-grid {
  align-items: end;
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(4, minmax(150px, 1fr)) auto;
}

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

.admin-user-fields h2 {
  grid-column: 1 / -1;
}

.admin-user-fields label small {
  color: var(--muted);
  font-weight: 500;
}

.permission-table select {
  min-width: 130px;
}

.admin-action-zone {
  border-color: #ebc7c4;
  margin-top: 22px;
}

.admin-actions {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.danger-button {
  background: var(--danger);
}

.admin-role-create {
  align-items: end;
  display: grid;
  gap: 14px;
  grid-template-columns: 180px minmax(180px, 1fr) minmax(240px, 2fr) auto;
}

.role-editor > header {
  align-items: start;
  display: flex;
  justify-content: space-between;
  margin-bottom: 18px;
}

.role-editor header h2 {
  margin-bottom: 4px;
}

.admin-role-fields {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-bottom: 18px;
}

.compact-checkbox {
  min-height: 18px;
  width: 18px;
}

.smtp-form {
  align-items: end;
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(4, minmax(150px, 1fr));
}

.smtp-form button {
  grid-column: 1 / -1;
  justify-self: start;
}

.audit-table {
  min-width: 1180px;
}

.audit-table td:last-child code {
  display: block;
  max-width: 360px;
  overflow-wrap: anywhere;
  white-space: normal;
}

.mode-switch {
  margin-bottom: 18px;
}

.filter-form.order-list-filter-form,
.filter-form.returns-filter-form {
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
}

.comparison-form {
  align-items: start;
  display: grid;
  gap: 24px;
  grid-template-columns: minmax(240px, 1fr) minmax(400px, 1.1fr) minmax(240px, 1fr);
}

.comparison-form fieldset {
  border: 0;
  margin: 0;
  min-width: 0;
  padding: 0;
}

.comparison-form legend {
  color: var(--ink);
  font-size: 15px;
  font-weight: 800;
  margin-bottom: 12px;
}

.comparison-side,
.comparison-thresholds {
  display: grid;
  gap: 12px;
}

.comparison-side p,
.comparison-period-note {
  color: var(--muted);
  font-size: 12px;
  margin: 0;
}

.comparison-thresholds {
  border-left: 1px solid var(--line) !important;
  border-right: 1px solid var(--line) !important;
  column-gap: 16px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  padding: 0 24px !important;
}

.comparison-thresholds label {
  overflow-wrap: anywhere;
}

.comparison-thresholds legend {
  grid-column: 1 / -1;
}

.comparison-period-note {
  border-top: 1px solid var(--line);
  margin-top: 16px;
  padding-top: 12px;
}

.comparison-summary-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr));
  margin-bottom: 18px;
  padding-bottom: 2px;
}

.comparison-summary-item {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  min-width: 0;
  padding: 14px;
}

.comparison-summary-item > p {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  margin: 0 0 12px;
  min-height: 28px;
  text-transform: uppercase;
}

.comparison-summary-item > div {
  align-items: end;
  display: grid;
  gap: 8px;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr) minmax(0, 1fr);
}

.comparison-summary-item span {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.comparison-summary-item span:last-child {
  text-align: right;
}

.comparison-summary-item small {
  color: var(--muted);
  font-size: 10px;
}

.comparison-summary-item strong {
  font-size: 16px;
  font-variant-numeric: tabular-nums;
  line-height: 1.25;
  overflow-wrap: break-word;
}

.comparison-summary-delta {
  border-left: 1px solid var(--line);
  border-right: 1px solid var(--line);
  padding: 0 8px;
  text-align: center !important;
}

.comparison-summary-item--anomalies {
  border-color: #efd28a;
  background: var(--warning-soft);
}

.comparison-table {
  min-width: 1040px;
}

.comparison-table thead th {
  background: #f2f6f4;
  position: sticky;
  top: 0;
  z-index: 2;
}

.comparison-table thead th:nth-child(2),
.comparison-table thead th:nth-child(4) {
  width: 25%;
}

.comparison-table thead th strong,
.comparison-table thead th small {
  display: block;
}

.comparison-table thead th small {
  font-size: 10px;
  margin-top: 4px;
}

.comparison-delta-column {
  width: 190px;
}

.comparison-group-header th {
  background: #e7efeb;
  border-top: 2px solid #b8c9c1;
  vertical-align: middle;
}

.comparison-group-header button {
  align-items: center;
  background: transparent;
  color: var(--ink);
  display: inline-flex;
  gap: 8px;
  min-height: 32px;
  padding: 0;
}

.comparison-group-header button span {
  color: var(--accent);
  width: 12px;
}

.comparison-group-status,
.comparison-change-state,
.comparison-anomaly-badge {
  border-radius: 999px;
  display: inline-flex;
  font-size: 10px;
  font-weight: 800;
  margin-left: 8px;
  padding: 3px 7px;
  white-space: nowrap;
}

.comparison-group-status,
.comparison-change-state {
  background: #edf1ef;
  color: var(--muted);
}

.comparison-anomaly-badge {
  background: #f5cf77;
  color: #5d3a00;
}

.comparison-audit-links {
  display: table-cell;
  text-align: right;
}

.comparison-audit-links a {
  color: var(--accent);
  display: inline-block;
  font-size: 11px;
  margin-left: 10px;
  text-decoration: underline;
}

.comparison-category-row th {
  background: #f8faf8;
  color: var(--muted);
  font-size: 11px;
  padding-top: 14px;
}

.comparison-delta-cell {
  border-left: 1px solid #e0e7e3;
  border-right: 1px solid #e0e7e3;
  width: 190px;
}

.comparison-delta-cell strong,
.comparison-delta-cell small {
  display: block;
}

.comparison-delta-cell small {
  margin-top: 3px;
}

.comparison-tone--positive {
  color: var(--success);
}

.comparison-tone--negative {
  color: var(--danger);
}

.comparison-tone--neutral {
  color: var(--muted);
}

.comparison-table tbody tr.comparison-anomaly-row {
  background: var(--warning-soft);
  box-shadow: inset 3px 0 0 #d99b22;
}

.comparison-chart-head {
  align-items: end;
}

.comparison-chart-head label {
  min-width: 240px;
}

.comparison-chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 18px;
  margin-bottom: 10px;
}

.comparison-chart-legend span {
  align-items: center;
  display: inline-flex;
  font-size: 12px;
  font-weight: 750;
  gap: 7px;
}

.comparison-chart-legend span::before {
  background: var(--accent);
  border-radius: 2px;
  content: "";
  height: 4px;
  width: 24px;
}

.comparison-chart-legend .comparison-chart-legend--right::before {
  background: #c48312;
}

.comparison-chart {
  border-top: 1px solid var(--line);
  overflow-x: auto;
  padding-top: 10px;
}

.comparison-chart[hidden] {
  display: none;
}

.comparison-chart svg {
  display: block;
  min-width: 760px;
  width: 100%;
}

.comparison-chart-grid {
  stroke: #dde5e1;
  stroke-width: 1;
}

.comparison-chart-axis-label {
  fill: var(--muted);
  font-size: 10px;
}

.comparison-chart-line {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 3;
}

.comparison-chart-line--left,
.comparison-chart-point--left {
  stroke: var(--accent);
}

.comparison-chart-line--right,
.comparison-chart-point--right {
  stroke: #c48312;
}

.comparison-chart-point--left {
  fill: white;
}

.comparison-chart-point--right {
  fill: #fff7e6;
}

@media (max-width: 860px) {
  .app-frame {
    grid-template-columns: minmax(0, 1fr);
    max-width: 100vw;
    overflow-x: hidden;
  }

  .sidebar {
    max-width: 100vw;
    min-width: 0;
    overflow: hidden;
    position: static;
    width: 100%;
  }

  .side-nav {
    display: flex;
    flex: initial;
    max-width: 100%;
    min-width: 0;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    width: 100%;
  }

  .side-nav a,
  .side-nav__section {
    flex: 0 0 auto;
  }

  .sidebar-account {
    grid-template-columns: 1fr auto auto;
  }

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

  .action-panel,
  .topbar {
    align-items: start;
    flex-direction: column;
  }

  .job-form,
  .order-form,
  .report-form,
  .filter-form,
  .inventory-filter-form,
  .scenario-controls,
  .scenario-split,
  .scenario-audit__grid,
  .scenario-switch__control,
  .admin-create-grid,
  .admin-role-create,
  .admin-role-fields,
  .smtp-form,
  .admin-user-fields,
  .comparison-form,
  dl {
    grid-template-columns: 1fr;
  }

  .comparison-thresholds {
    border-bottom: 1px solid var(--line) !important;
    border-left: 0 !important;
    border-right: 0 !important;
    border-top: 1px solid var(--line) !important;
    padding: 18px 0 !important;
  }

  .scenario-switch__control {
    justify-items: start;
  }

  .relation-map,
  .formula-grid {
    grid-template-columns: 1fr;
  }

  .page-header {
    align-items: start;
    flex-direction: column;
  }

  .auth-surface {
    grid-template-columns: 1fr;
  }

  .auth-context {
    display: none;
  }

  .auth-form-panel {
    padding: 30px 22px;
  }

  .totp-enrollment {
    grid-template-columns: 1fr;
  }

  .start-heading {
    align-items: start;
    flex-direction: column;
    gap: 20px;
  }

  .start-status-band {
    align-items: start;
    grid-template-columns: 1fr;
  }
}

@media (max-width: 520px) {
  .comparison-summary-grid,
  .comparison-thresholds {
    grid-template-columns: 1fr;
  }

  .auth-masthead {
    align-items: flex-start;
    gap: 18px;
  }

  .recovery-code-list {
    columns: 1;
  }

  .sidebar-account {
    grid-template-columns: 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  .busy-hourglass {
    animation: none;
  }
}

.filter-form.product-sales-filter-form {
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
}

.product-sales-filter-form .checkbox-group {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
  grid-column: 1 / -1;
  padding: 8px 14px;
}

.product-sales-filter-form .checkbox-group .checkbox,
.product-sales-filter-form > .checkbox {
  display: grid;
  min-height: 32px;
}

.product-sales-table .group-header {
  border-left: 2px solid var(--line);
  text-align: center;
}
