:root {
  color-scheme: light;
  --ink: #17211c;
  --muted: #66736e;
  --line: #d7ded8;
  --panel: #ffffff;
  --surface: #f5f7f4;
  --brand: #137a4b;
  --brand-dark: #0f5e3b;
  --amber: #a15c00;
  --red: #a33b3b;
  --blue: #245a8d;
  --shadow: 0 10px 30px rgba(15, 38, 28, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--surface);
  color: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
  font-size: 14px;
}

button,
input,
select,
textarea {
  font: inherit;
}

.topbar {
  align-items: center;
  background: #ffffff;
  border-bottom: 1px solid var(--line);
  display: flex;
  gap: 24px;
  justify-content: space-between;
  padding: 18px 24px;
  position: sticky;
  top: 0;
  z-index: 5;
}

.brand {
  color: var(--brand);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0;
}

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

h1 {
  font-size: 24px;
}

h2 {
  font-size: 16px;
}

main {
  margin: 0 auto;
  max-width: 1440px;
  padding: 18px 24px 40px;
}

.run-panel,
.toolbar,
.tabs,
.status-row {
  align-items: end;
  display: flex;
  gap: 10px;
}

.run-panel {
  flex-wrap: wrap;
  justify-content: end;
}

.status-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  margin-bottom: 14px;
}

.metric {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  min-height: 76px;
  padding: 13px 14px;
}

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

.metric strong {
  display: block;
  font-size: 21px;
  margin-top: 8px;
}

.tabs {
  border-bottom: 1px solid var(--line);
  margin: 16px 0 14px;
}

.tab {
  background: transparent;
  border: 0;
  border-bottom: 3px solid transparent;
  color: var(--muted);
  cursor: pointer;
  padding: 11px 14px 10px;
}

.tab.active {
  border-color: var(--brand);
  color: var(--ink);
  font-weight: 700;
}

.toolbar {
  background: #ecf1ee;
  border: 1px solid var(--line);
  border-radius: 8px;
  flex-wrap: wrap;
  margin-bottom: 14px;
  padding: 10px;
}

.field {
  display: grid;
  gap: 5px;
  min-width: 150px;
}

.field.compact {
  min-width: 120px;
}

.field span {
  color: var(--muted);
  font-size: 12px;
}

input,
select,
textarea {
  background: #ffffff;
  border: 1px solid #c7d0c9;
  border-radius: 6px;
  color: var(--ink);
  min-height: 36px;
  padding: 7px 9px;
  width: 100%;
}

input[readonly] {
  background: #f8faf7;
  color: var(--muted);
}

.table-number-input {
  min-height: 30px;
  max-width: 112px;
  padding: 5px 7px;
  text-align: right;
}

textarea {
  resize: vertical;
}

.filter-picker {
  position: relative;
}

.filter-picker-menu {
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 1px;
  left: 0;
  margin-top: 6px;
  max-height: 320px;
  overflow: auto;
  padding: 8px;
  position: absolute;
  right: 0;
  top: 100%;
  z-index: 20;
}

.filter-picker-menu.hidden {
  display: none;
}

.filter-picker-group {
  color: var(--ink);
  font-size: 13px;
  font-weight: 800;
  padding: 8px 8px 3px;
}

.filter-picker-option {
  background: transparent;
  border: 0;
  border-radius: 4px;
  color: var(--ink);
  cursor: pointer;
  justify-content: flex-start;
  min-height: 28px;
  padding: 5px 18px;
  text-align: left;
  width: 100%;
}

.filter-picker-option:hover,
.filter-picker-option.selected {
  background: #e9f2ed;
  color: var(--brand-dark);
}

.filter-picker-empty {
  color: var(--muted);
  padding: 8px;
}

.multi-select {
  position: relative;
}

.multi-select summary {
  align-items: center;
  background: #ffffff;
  border: 1px solid #c7d0c9;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  min-height: 36px;
  padding: 7px 9px;
}

.multi-select[open] summary {
  border-color: var(--brand);
}

.multi-select-menu {
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 2px;
  margin-top: 6px;
  max-height: 220px;
  overflow: auto;
  padding: 8px;
}

.check-group-label {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  padding: 8px 8px 3px;
  text-transform: uppercase;
}

.check-option {
  align-items: center;
  border-radius: 6px;
  display: flex;
  gap: 8px;
  min-height: 32px;
  padding: 6px 8px;
}

.check-option:hover {
  background: #eef4f0;
}

.check-option input {
  min-height: 16px;
  padding: 0;
}

.button,
button {
  align-items: center;
  border-radius: 6px;
  cursor: pointer;
  display: inline-flex;
  justify-content: center;
  min-height: 36px;
  padding: 8px 12px;
  text-decoration: none;
}

button {
  border: 1px solid #c1cbc3;
  background: #ffffff;
  color: var(--ink);
}

.button {
  border: 1px solid #c1cbc3;
  background: #ffffff;
  color: var(--ink);
}

.primary {
  background: var(--brand);
  border-color: var(--brand);
  color: #ffffff;
  font-weight: 700;
}

.primary:hover {
  background: var(--brand-dark);
}

.link-button {
  background: transparent;
  border: 0;
  color: var(--ink);
  display: inline;
  font: inherit;
  font-weight: 700;
  min-height: 0;
  padding: 0;
  text-align: left;
}

.link-button:hover {
  color: var(--brand-dark);
  text-decoration: underline;
}

.ghost-button {
  background: #f8faf7;
}

.small-button {
  min-height: 30px;
  padding: 5px 10px;
}

.view-toggle {
  background: #edf3ef;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: inline-flex;
  gap: 2px;
  padding: 3px;
}

.view-toggle-button {
  background: transparent;
  border: 0;
  color: var(--muted);
  min-height: 32px;
  padding: 6px 10px;
}

.view-toggle-button.active {
  background: #ffffff;
  box-shadow: 0 1px 4px rgba(15, 38, 28, 0.12);
  color: var(--brand-dark);
  font-weight: 700;
}

.loading-panel {
  align-items: center;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  color: var(--muted);
  display: flex;
  gap: 10px;
  justify-content: center;
  min-height: 220px;
  margin-bottom: 10px;
}

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

.loading-spinner {
  animation: spin 0.8s linear infinite;
  border: 3px solid #d9e3dc;
  border-top-color: var(--brand);
  border-radius: 999px;
  height: 22px;
  width: 22px;
}

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

.sort-button {
  background: transparent;
  border: 0;
  color: inherit;
  font: inherit;
  font-weight: 700;
  justify-content: flex-start;
  min-height: 0;
  padding: 0;
  width: 100%;
}

.sort-button:hover,
.sort-button[data-active="true"] {
  color: var(--brand-dark);
}

.header-with-info {
  align-items: center;
  display: flex;
  gap: 5px;
  justify-content: flex-end;
}

.header-with-info .sort-button {
  flex: 1;
}

.info-badge {
  align-items: center;
  background: #fff0d9;
  border: 1px solid #e2b566;
  border-radius: 999px;
  color: var(--amber);
  cursor: help;
  display: inline-flex;
  flex: 0 0 auto;
  font-size: 11px;
  font-weight: 800;
  height: 18px;
  justify-content: center;
  min-height: 18px;
  padding: 0;
  user-select: none;
  width: 18px;
}

.promo-month-cell {
  background: #fffaf0;
}

.promo-cell-button {
  background: transparent;
  border: 0;
  color: var(--amber);
  display: inline-flex;
  gap: 5px;
  justify-content: flex-end;
  min-height: 0;
  padding: 0;
  width: auto;
}

.promo-dot {
  background: var(--amber);
  border-radius: 999px;
  display: inline-block;
  height: 7px;
  margin-top: 5px;
  width: 7px;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.section-head {
  align-items: center;
  display: flex;
  gap: 12px;
  justify-content: space-between;
  margin: 10px 0;
  flex-wrap: wrap;
}

.muted {
  color: var(--muted);
  font-size: 12px;
}

.table-wrap,
.panel,
.panel-table {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.table-wrap {
  overflow: auto;
}

.detail-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 14px;
}

.detail-page-head {
  align-items: center;
  display: flex;
  gap: 16px;
  justify-content: space-between;
  margin: 10px 0;
}

.detail-page-head h3 {
  margin: 0 0 4px;
}

.detail-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

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

table {
  border-collapse: collapse;
  min-width: 900px;
  width: 100%;
}

#tab-hq table {
  min-width: 1260px;
}

th,
td {
  border-bottom: 1px solid #e7ece8;
  padding: 10px 11px;
  text-align: left;
  vertical-align: top;
}

th {
  background: #f8faf7;
  color: #35433c;
  font-size: 12px;
  position: sticky;
  top: 0;
}

td.numeric,
th.numeric {
  text-align: right;
}

.pill {
  border-radius: 999px;
  display: inline-block;
  font-size: 12px;
  font-weight: 700;
  padding: 4px 8px;
}

.pill.ok {
  background: #e6f2ec;
  color: var(--brand-dark);
}

.pill.warn {
  background: #fff0d9;
  color: var(--amber);
}

.pill.risk {
  background: #ffe8e8;
  color: var(--red);
}

.priority-pill {
  border-radius: 999px;
  display: inline-block;
  font-size: 12px;
  font-weight: 700;
  padding: 4px 8px;
}

.priority-urgency {
  background: #fbe6e6;
  color: #8f2727;
}

.priority-order-now {
  background: #e4f2ea;
  color: #11623f;
}

.priority-boss-approval {
  background: #fbe6e6;
  color: #8f2727;
}

.priority-trim {
  background: #fff1d6;
  color: #815000;
}

.priority-priority {
  background: #fff1d6;
  color: #815000;
}

.priority-normal {
  background: #e4f2ea;
  color: #11623f;
}

.priority-defer {
  background: #e8edf1;
  color: #40505a;
}

.ok-text {
  color: var(--brand-dark);
  font-weight: 700;
}

.risk-text {
  color: var(--red);
  font-weight: 700;
}

.split {
  align-items: start;
  display: grid;
  gap: 14px;
  grid-template-columns: minmax(280px, 360px) 1fr;
}

.panel {
  padding: 16px;
}

.panel h2 {
  margin-bottom: 14px;
}

.panel form,
form.panel {
  align-content: start;
  display: grid;
  gap: 12px;
}

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

.two-col .field {
  min-width: 0;
}

.panel-heading {
  align-items: center;
  display: flex;
  gap: 12px;
  justify-content: space-between;
  margin-bottom: 12px;
}

.panel-heading h2 {
  margin: 0;
}

.supplier-rules-panel {
  overflow: auto;
}

.purchase-rule-panel {
  margin-bottom: 14px;
}

.rule-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.rule-grid {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
}

.supplier-rules-panel table {
  min-width: 0;
}

.supplier-rules-panel tbody tr[data-supplier-id] {
  cursor: pointer;
}

.supplier-rules-panel tbody tr[data-supplier-id]:hover {
  background: #f3f7f4;
}

.clickable-row {
  cursor: pointer;
}

.clickable-row:hover {
  background: #f3f7f4;
}

.modal-overlay {
  align-items: center;
  background: rgba(12, 24, 18, 0.45);
  display: flex;
  inset: 0;
  justify-content: center;
  padding: 24px;
  position: fixed;
  z-index: 20;
}

.modal-overlay.hidden {
  display: none;
}

.modal {
  background: var(--panel);
  border-radius: 8px;
  box-shadow: 0 20px 70px rgba(15, 38, 28, 0.22);
  max-height: 86vh;
  max-width: 1180px;
  overflow: auto;
  padding: 16px;
  width: min(1180px, 100%);
}

.narrow-modal {
  max-width: 680px;
}

.modal-head {
  align-items: center;
  display: flex;
  gap: 16px;
  justify-content: space-between;
  margin-bottom: 12px;
}

.modal-table table {
  min-width: 1100px;
}

.sticky-totals {
  align-items: center;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
  bottom: 0;
  box-shadow: 0 -10px 28px rgba(15, 38, 28, 0.1);
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(5, minmax(150px, 1fr));
  margin-top: 10px;
  padding: 12px;
  position: sticky;
  z-index: 4;
}

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

.total-block strong {
  display: block;
  font-size: 18px;
  margin-top: 4px;
}

.total-action {
  display: grid;
  gap: 4px;
}

.total-action span {
  color: var(--muted);
  font-size: 12px;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

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

.list {
  display: grid;
  gap: 8px;
}

.list-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 5px;
  padding: 10px;
}

.list-item strong {
  font-size: 13px;
}

.list-item button {
  justify-self: start;
  min-height: 30px;
  padding: 5px 8px;
}

.spaced {
  margin-top: 18px;
}

.kv {
  display: grid;
  gap: 8px;
  grid-template-columns: 150px 1fr;
  margin: 0;
}

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

.kv dd {
  margin: 0;
  overflow-wrap: anywhere;
}

pre {
  background: #121a16;
  border-radius: 8px;
  color: #d9f2e5;
  margin: 0;
  max-height: 430px;
  overflow: auto;
  padding: 14px;
  white-space: pre-wrap;
}

.toast {
  background: #17211c;
  border-radius: 8px;
  bottom: 18px;
  color: #ffffff;
  left: 50%;
  max-width: min(640px, calc(100vw - 32px));
  opacity: 0;
  padding: 10px 14px;
  position: fixed;
  transform: translate(-50%, 12px);
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media (max-width: 900px) {
  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .run-panel,
  .toolbar {
    justify-content: stretch;
  }

  .status-row {
    grid-template-columns: repeat(2, minmax(130px, 1fr));
  }

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

@media (max-width: 560px) {
  main {
    padding: 14px;
  }

  .topbar {
    padding: 14px;
  }

  .status-row,
  .two-col {
    grid-template-columns: 1fr;
  }

  .sticky-totals {
    grid-template-columns: 1fr;
  }

  .field,
  .field.compact {
    min-width: 100%;
  }

  .run-panel .button,
  .run-panel button {
    width: 100%;
  }
}
