:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --ink: #17202a;
  --muted: #697586;
  --line: #d9dee7;
  --accent: #176b87;
  --accent-strong: #0e4d64;
  --danger: #b42318;
  --warning-bg: #fff4db;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 15px;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.topbar {
  align-items: center;
  background: #ffffff;
  border-bottom: 1px solid var(--line);
  display: flex;
  gap: 28px;
  min-height: 64px;
  padding: 0 28px;
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand {
  color: var(--ink);
  font-size: 18px;
  font-weight: 800;
}

.nav {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
}

.nav a {
  color: #344054;
  font-weight: 600;
}

.nav-form {
  margin: 0;
}

.link-button {
  background: transparent;
  border: 0;
  color: #344054;
  cursor: pointer;
  font-weight: 600;
  min-height: 0;
  padding: 0;
}

.page {
  margin: 0 auto;
  max-width: 1280px;
  padding: 28px;
}

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

.page-header h1 {
  font-size: 28px;
  line-height: 1.2;
  margin: 0;
}

.page-header p {
  color: var(--muted);
  margin: 6px 0 0;
}

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

.metrics.narrow {
  grid-template-columns: repeat(2, minmax(0, 220px));
}

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

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

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

.metric.danger {
  background: var(--warning-bg);
  border-color: #f2cc7a;
}

.metric.danger strong {
  color: var(--danger);
}

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

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

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

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

.panel-header h2 {
  font-size: 18px;
  margin: 0;
}

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

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

th {
  background: #f9fafb;
  color: #344054;
  font-size: 13px;
}

td small,
.line-item {
  color: var(--muted);
  display: block;
  margin-top: 4px;
}

.status-row {
  display: grid;
  gap: 4px;
  margin-bottom: 10px;
}

.status-row:last-child {
  margin-bottom: 0;
}

.pill {
  border-radius: 999px;
  display: inline-flex;
  font-size: 12px;
  font-weight: 800;
  padding: 4px 9px;
  white-space: nowrap;
}

.pill.good {
  background: #e8f5ef;
  color: #1f7a4d;
}

.pill.warn {
  background: #fff4db;
  color: #9a5b00;
}

.pill.danger {
  background: #fff0ed;
  color: #b42318;
}

.pill.neutral {
  background: #eef2f6;
  color: #475467;
}

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

.toolbar {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}

.inline-form {
  display: inline-flex;
  gap: 8px;
}

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

.field-grid label {
  color: #344054;
  display: block;
  font-weight: 700;
  margin-bottom: 6px;
}

.field-grid input,
.field-grid select {
  width: 100%;
}

.form-actions {
  border-top: 1px solid var(--line);
  padding: 16px 18px;
}

tr:last-child td {
  border-bottom: 0;
}

.empty {
  color: var(--muted);
  padding: 32px 16px;
  text-align: center;
}

.search-form {
  align-items: center;
  display: flex;
  gap: 8px;
}

input,
select,
textarea,
button,
.action {
  border: 1px solid var(--line);
  border-radius: 6px;
  font: inherit;
  min-height: 38px;
  padding: 8px 12px;
}

input,
select,
textarea {
  background: #ffffff;
}

button,
.action {
  background: var(--accent);
  color: #ffffff;
  cursor: pointer;
  font-weight: 700;
}

button.secondary,
.action.secondary {
  background: #eef2f6;
  color: #344054;
}

button.secondary:hover,
.action.secondary:hover {
  background: #dfe5ee;
}

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

button:hover,
.action:hover {
  background: var(--accent-strong);
  text-decoration: none;
}

.link-button,
.link-button:hover {
  background: transparent;
  border: 0;
  color: #344054;
  font-weight: 600;
  min-height: 0;
  padding: 0;
}

.messages {
  margin-bottom: 18px;
}

.message {
  background: #e8f5ef;
  border: 1px solid #a6d7bd;
  border-radius: 8px;
  padding: 12px 14px;
}

.message.warning,
.message.error {
  background: #fff4db;
  border-color: #f2cc7a;
}

.message.error {
  background: #fff0ed;
  border-color: #f1b8b0;
}

.inventory-panel {
  overflow-x: auto;
}

.inventory-table {
  min-width: 1240px;
}

.inventory-table th,
.inventory-table td {
  white-space: normal;
}

.product-heading small {
  font-weight: 600;
}

.rail-table tbody tr.product-start > td {
  border-top: 12px solid var(--bg);
}

.rail-table tbody tr.product-start:first-child > td {
  border-top: 0;
}

.rail-option > td {
  background: #ffffff;
}

.rail-option.product-start > td:nth-child(2),
.rail-option.option-extra > td:first-child {
  border-left: 5px solid #dfe8ee;
}

.rail-product {
  background: #f9fafb;
  border-left: 5px solid var(--accent);
  min-width: 270px;
  width: 290px;
}

.rail-product > strong,
.product-name {
  display: block;
}

.rail-product > strong {
  margin-top: 8px;
}

.product-name {
  font-weight: 800;
  line-height: 1.35;
  margin-top: 8px;
}

.product-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin: 10px 0 8px;
}

.product-memo {
  margin-top: 12px;
  min-width: 0;
}

.product-row {
  background: #f9fafb;
}

.stock-editor {
  align-items: center;
  display: grid;
  gap: 6px;
  grid-template-columns: 44px 44px 88px 44px 44px;
}

.stock-editor input {
  text-align: right;
  width: 88px;
}

.stock-empty {
  background: #fff0ed;
}

.stock-low {
  background: #fff4db;
}

.rail-option > td.stock-empty {
  background: #fff0ed;
}

.rail-option > td.stock-low {
  background: #fff4db;
}

.changed {
  background: #e8f5ef;
}

.rail-option.changed > td:not(.rail-product) {
  background: #e8f5ef;
}

.failed {
  background: #fff0ed;
}

.locked {
  color: #697586;
}

.memo-cell {
  min-width: 180px;
}

.memo-cell textarea {
  min-height: 84px;
  width: 100%;
}

.compact {
  grid-template-columns: minmax(240px, 420px);
}

@media (max-width: 860px) {
  .topbar,
  .page-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .page {
    padding: 18px;
  }

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

  .panel {
    overflow-x: auto;
  }

  table {
    min-width: 760px;
  }

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