:root {
  --bg: #f3f5f6;
  --surface: #ffffff;
  --surface-alt: #eef2f4;
  --line: #cfd8de;
  --line-strong: #a9b8c1;
  --text: #162027;
  --muted: #60717d;
  --teal: #0f766e;
  --teal-dark: #0a5f59;
  --blue: #1f5f99;
  --blue-soft: #e5f0fa;
  --green: #176b48;
  --green-soft: #e2f4ea;
  --amber: #946200;
  --amber-soft: #fff1cb;
  --red: #b42318;
  --red-soft: #ffe3df;
  --violet: #5e4aa8;
  --violet-soft: #ece8fb;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

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

.app {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto auto auto auto minmax(0, 1fr);
}

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 14px 18px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.kicker {
  margin: 0 0 3px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 22px;
  line-height: 1.1;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 0;
  font-size: 16px;
  letter-spacing: 0;
}

.header-actions,
.filters,
.views {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.button,
.icon-button,
.view-tab,
.source-tab {
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
  color: var(--text);
  min-height: 32px;
  padding: 0 10px;
  cursor: pointer;
}

.button.primary {
  border-color: var(--teal);
  background: var(--teal);
  color: #fff;
}

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

.button.dirty {
  border-color: var(--amber);
  background: var(--amber-soft);
  color: var(--amber);
  font-weight: 800;
}

.button.compact {
  min-height: 28px;
  padding: 0 8px;
}

.icon-button {
  width: 32px;
  padding: 0;
  font-weight: 800;
}

.control-band {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 10px 18px;
  background: #fbfcfd;
  border-bottom: 1px solid var(--line);
}

.view-tab.active {
  border-color: var(--teal);
  background: #dff3ef;
  color: var(--teal-dark);
  font-weight: 800;
}

.source-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.source-tab {
  min-height: 28px;
  padding: 0 9px;
  font-size: 12px;
}

.source-tab.active {
  border-color: var(--blue);
  background: var(--blue-soft);
  color: var(--blue);
  font-weight: 800;
}

.source-tab:disabled,
.button:disabled {
  cursor: wait;
  opacity: 0.6;
}

.source-status {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 0 8px;
  background: var(--surface-alt);
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.source-status.ok {
  border-color: #b9d9c7;
  background: var(--green-soft);
  color: var(--green);
}

.source-status.warn,
.source-status.loading {
  border-color: #f1d999;
  background: var(--amber-soft);
  color: var(--amber);
}

.source-status.danger {
  border-color: #f4b4ad;
  background: var(--red-soft);
  color: var(--red);
}

input,
select,
textarea {
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
  color: var(--text);
}

input,
select {
  height: 32px;
  padding: 0 9px;
}

#searchInput {
  width: min(380px, 42vw);
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(120px, 1fr));
  border-bottom: 1px solid var(--line);
  background: var(--line);
  gap: 1px;
}

.summary-item {
  background: var(--surface);
  padding: 9px 18px;
}

.summary-item span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

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

.summary-item.warn strong {
  color: var(--amber);
}

.summary-item.danger strong {
  color: var(--red);
}

.forecast-panel {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  padding: 12px 18px 14px;
}

.forecast-panel.hidden {
  display: none;
}

.forecast-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.mini-legend {
  display: flex;
  gap: 14px;
  color: var(--muted);
  font-size: 12px;
}

.legend {
  display: inline-block;
  width: 10px;
  height: 10px;
  margin-right: 5px;
  border-radius: 2px;
}

.legend.rr {
  background: var(--blue);
}

.legend.mm {
  background: var(--violet);
}

.legend.teams {
  background: var(--teal);
}

.legend.warehouse-ready {
  background: var(--green);
}

.legend.warehouse-addendum {
  background: var(--amber);
}

.forecast-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(140px, 1fr));
  gap: 10px;
}

.forecast-week {
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 10px;
  background: #fbfcfd;
}

.forecast-week strong {
  display: block;
  margin-bottom: 8px;
}

.bar {
  height: 8px;
  margin: 5px 0;
  border-radius: 999px;
  background: var(--surface-alt);
  overflow: hidden;
}

.bar span {
  display: block;
  height: 100%;
  background: var(--teal);
}

.warehouse-worklist-panel {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  padding: 12px 18px 14px;
}

.warehouse-worklist-panel.hidden {
  display: none;
}

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

.warehouse-worklist-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(280px, 1fr));
  gap: 12px;
}

.warehouse-lane {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fbfcfd;
}

.warehouse-lane-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 34px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.warehouse-lane-head span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 24px;
  height: 22px;
  border-radius: 999px;
  background: var(--surface-alt);
  color: var(--text);
  font-weight: 800;
}

.warehouse-items {
  display: grid;
  gap: 8px;
  padding: 9px;
}

.warehouse-item {
  border: 1px solid var(--line);
  border-left: 4px solid var(--green);
  border-radius: 7px;
  background: var(--surface);
  padding: 9px;
}

.warehouse-item.addendum {
  border-left-color: var(--amber);
}

.warehouse-item-top {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.warehouse-item-top strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.warehouse-worklist-fields {
  display: grid;
  grid-template-columns: 86px minmax(0, 1fr);
  gap: 5px 9px;
  margin: 0;
  font-size: 12px;
}

.warehouse-worklist-fields dt {
  color: var(--muted);
  font-weight: 800;
  text-transform: uppercase;
}

.warehouse-worklist-fields dd {
  margin: 0;
  min-width: 0;
  overflow-wrap: anywhere;
}

.warehouse-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 9px;
  padding-top: 9px;
  border-top: 1px solid var(--line);
}

.warehouse-action {
  min-height: 28px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
  color: var(--text);
  padding: 0 8px;
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
}

.warehouse-action.primary {
  border-color: #b9d9c7;
  background: var(--green-soft);
  color: var(--green);
}

.warehouse-action.success {
  border-color: var(--teal);
  background: var(--teal);
  color: #fff;
}

.warehouse-action.danger {
  border-color: #f4b4ad;
  background: var(--red-soft);
  color: var(--red);
}

.warehouse-action:disabled {
  cursor: default;
  opacity: 0.48;
}

.worklist-link {
  margin-left: 6px;
  color: var(--blue);
  font-weight: 800;
  text-decoration: none;
}

.matrix-wrap {
  min-height: 0;
  overflow: auto;
  background: var(--surface);
}

.matrix-table {
  width: max(1720px, 100%);
  border-collapse: separate;
  border-spacing: 0;
  font-size: 12px;
  line-height: 1.25;
}

.matrix-table th,
.matrix-table td {
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding: 5px 7px;
  vertical-align: middle;
  background: var(--surface);
  white-space: nowrap;
}

.matrix-table th {
  position: sticky;
  top: 0;
  z-index: 4;
  height: 34px;
  background: #e7edf1;
  color: #25313a;
  font-size: 11px;
  text-align: left;
  text-transform: uppercase;
}

.matrix-table td {
  height: 34px;
  max-width: 240px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.matrix-table .sticky {
  position: sticky;
  z-index: 5;
}

.matrix-table th.sticky {
  z-index: 8;
}

.col-line {
  left: 0;
  width: 42px;
  min-width: 42px;
}

.col-sap {
  left: 42px;
  width: 180px;
  min-width: 180px;
}

.col-lead {
  left: 222px;
  width: 170px;
  min-width: 170px;
}

.matrix-table td.col-line,
.matrix-table td.col-sap,
.matrix-table td.col-lead,
.matrix-table th.col-line,
.matrix-table th.col-sap,
.matrix-table th.col-lead {
  box-shadow: 1px 0 0 var(--line-strong);
}

.matrix-table tr:hover td {
  background: #f7fbfc;
}

.cell-select {
  width: 100%;
  min-width: 96px;
  height: 25px;
  border-radius: 5px;
  font-size: 12px;
  padding: 0 5px;
}

.cell-input {
  width: 100%;
  min-width: 150px;
  height: 25px;
  border-radius: 5px;
  padding: 0 6px;
  font-size: 12px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 20px;
  border-radius: 999px;
  padding: 2px 7px;
  font-size: 11px;
  font-weight: 800;
}

.badge.rr {
  background: var(--blue-soft);
  color: var(--blue);
}

.badge.mm {
  background: var(--violet-soft);
  color: var(--violet);
}

.state-ok,
td.state-ok {
  background: var(--green-soft);
}

.state-warn,
td.state-warn {
  background: var(--amber-soft);
}

.state-danger,
td.state-danger {
  background: var(--red-soft);
}

.package-cell {
  display: grid;
  grid-template-columns: minmax(150px, 1fr) 26px;
  gap: 4px;
  align-items: center;
}

.package-select {
  min-width: 150px;
  background: var(--blue-soft);
  color: var(--blue);
  font-weight: 700;
}

.asset-select {
  min-width: 128px;
  background: #fbfcfd;
}

.readonly-value,
.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 23px;
  max-width: 100%;
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 2px 7px;
  overflow: hidden;
  color: var(--text);
  font-size: 12px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.readonly-value {
  background: #fbfcfd;
}

.package-readonly {
  color: var(--blue);
  background: var(--blue-soft);
}

.status-pill {
  border-color: transparent;
}

.system-pill {
  background: var(--surface-alt);
  color: var(--muted);
}

.app-pill {
  border-color: #d6ccef;
  background: var(--violet-soft);
  color: var(--violet);
}

.package-open {
  width: 26px;
  height: 25px;
  min-height: 25px;
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 0;
  background: var(--surface);
  color: var(--blue);
  font-size: 17px;
  font-weight: 900;
  line-height: 1;
}

.side-panel {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 20;
  width: min(460px, 92vw);
  height: 100vh;
  border-left: 1px solid var(--line);
  background: var(--surface);
  box-shadow: -18px 0 30px rgba(24, 36, 44, 0.16);
  transform: translateX(105%);
  transition: transform 160ms ease;
  display: flex;
  flex-direction: column;
}

.side-panel.open {
  transform: translateX(0);
}

.side-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.side-content {
  overflow: auto;
  padding: 16px;
}

.field-list {
  display: grid;
  grid-template-columns: 140px minmax(0, 1fr);
  gap: 9px 12px;
  margin: 0;
}

.field-list dt {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

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

.side-section {
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
}

.side-section:first-child {
  padding-top: 0;
}

.side-section h3 {
  margin: 0 0 10px;
  font-size: 14px;
}

.auth-form {
  display: grid;
  gap: 12px;
  padding-top: 14px;
}

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

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

.auth-form input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px 10px;
  background: var(--surface);
}

.form-error {
  margin: 0;
  border: 1px solid #f0b7ad;
  border-radius: 6px;
  padding: 10px;
  background: var(--red-soft);
  color: var(--red);
  overflow-wrap: anywhere;
}

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

.mini-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.mini-table th,
.mini-table td {
  border-bottom: 1px solid var(--line);
  padding: 6px 4px;
  text-align: left;
  vertical-align: top;
}

.mini-table th {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
}

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

.code-preview {
  width: 100%;
  min-height: 240px;
  border-radius: 7px;
  padding: 10px;
  resize: vertical;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 11px;
  line-height: 1.45;
  white-space: pre;
}

.step-list {
  margin: 0;
  padding-left: 18px;
}

.step-list li {
  margin-bottom: 8px;
}

.hidden-col {
  display: none;
}

@media (max-width: 920px) {
  .header,
  .control-band {
    align-items: flex-start;
    flex-direction: column;
  }

  #searchInput {
    width: min(100%, 520px);
  }

  .summary-grid,
  .forecast-grid,
  .warehouse-worklist-grid {
    grid-template-columns: repeat(2, minmax(130px, 1fr));
  }
}

@media (max-width: 640px) {
  .warehouse-worklist-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .warehouse-worklist-grid {
    grid-template-columns: minmax(0, 1fr);
  }
}
