:root {
  --bg: #f5f7fb;
  --panel: #ffffff;
  --ink: #172033;
  --muted: #647184;
  --accent: #116d5e;
  --accent-dark: #0b4c42;
  --line: #dce3eb;
  --warning: #fff4db;
  --warning-line: #f0c46a;
  --danger: #b3261e;
  --shadow: 0 14px 36px rgba(17, 34, 51, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Aptos", "Segoe UI", Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
}

.shell {
  width: min(1240px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 56px;
}

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

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 0;
  font-size: 2.1rem;
  line-height: 1.1;
}

h2 {
  margin-bottom: 8px;
  font-size: 1.12rem;
}

p {
  color: var(--muted);
  line-height: 1.55;
}

.status-pill {
  padding: 9px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  color: var(--muted);
  font-weight: 700;
}

.workbench {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(280px, 0.6fr);
  gap: 18px;
  align-items: stretch;
}

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

.upload-panel {
  padding: 22px;
}

.sage-panel {
  padding: 22px;
  margin-bottom: 18px;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
}

.sage-status {
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--accent-dark);
  background: #edf3f0;
  font-size: 0.86rem;
  font-weight: 800;
  align-self: start;
}

.sage-form {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(180px, 1fr) minmax(220px, 1fr) auto auto;
  gap: 12px;
  align-items: end;
  margin-top: 16px;
}

.sage-form label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
}

.sage-report-meta {
  min-height: 20px;
  margin-top: 12px;
  color: var(--muted);
  font-size: 0.88rem;
}

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

.file-field,
.controls label,
.export-format,
.filter {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
}

input,
select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  padding: 9px 10px;
}

input[type="file"] {
  padding: 8px;
}

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

.actions {
  display: flex;
  align-items: end;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 18px;
}

.export-format {
  width: 130px;
}

button {
  min-height: 42px;
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-weight: 800;
  padding: 9px 16px;
  cursor: pointer;
}

button[type="button"] {
  background: #fff;
  color: var(--accent-dark);
}

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

.summary-panel {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1px;
  overflow: hidden;
}

.metric {
  display: grid;
  gap: 7px;
  padding: 18px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.metric span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.metric strong {
  font-size: 1.18rem;
}

.results {
  margin-top: 18px;
}

.results-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 16px;
  margin-bottom: 10px;
}

.result-filters {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  flex-wrap: wrap;
}

.filter {
  width: min(220px, 100%);
}

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

table {
  width: 100%;
  max-width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

th,
td {
  padding: 9px 8px;
  border-bottom: 1px solid var(--line);
  text-align: right;
  vertical-align: top;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: normal;
}

th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #edf3f0;
  color: #3d514c;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.sort-button {
  width: 100%;
  min-height: 0;
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: inherit;
  padding: 0;
  font: inherit;
  font-weight: 800;
  letter-spacing: inherit;
  text-transform: inherit;
  cursor: pointer;
}

.sort-button::after {
  content: "";
  width: 0.8em;
  color: var(--accent);
  font-size: 0.9em;
}

.sort-button.active[data-direction="asc"]::after {
  content: "▲";
}

.sort-button.active[data-direction="desc"]::after {
  content: "▼";
}

th:nth-child(1),
td:nth-child(1),
th:nth-child(2),
td:nth-child(2) {
  text-align: left;
}

th:nth-child(1) .sort-button,
th:nth-child(2) .sort-button {
  justify-content: flex-start;
}

th:nth-child(1),
td:nth-child(1) {
  width: 13%;
}

th:nth-child(2),
td:nth-child(2) {
  width: 34%;
}

th:nth-child(3),
td:nth-child(3),
th:nth-child(4),
td:nth-child(4),
th:nth-child(5),
td:nth-child(5),
th:nth-child(6),
td:nth-child(6),
th:nth-child(7),
td:nth-child(7),
th:nth-child(8),
td:nth-child(8) {
  width: 7%;
}

th:nth-child(9),
td:nth-child(9) {
  width: 11%;
}

td span {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.82rem;
}

.needs-order {
  background: var(--warning);
}

.needs-order td:nth-child(7),
.needs-order td:nth-child(8) {
  color: var(--danger);
}

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

@media (max-width: 860px) {
  .topbar,
  .workbench,
  .sage-form,
  .upload-grid,
  .controls,
  .results-toolbar,
  .result-filters {
    grid-template-columns: 1fr;
    display: grid;
  }

  .summary-panel {
    grid-template-columns: 1fr;
  }

  h1 {
    font-size: 1.65rem;
  }

  .table-wrap {
    border: 0;
    box-shadow: none;
    background: transparent;
  }

  table,
  thead,
  tbody,
  tr,
  th,
  td {
    display: block;
    width: 100%;
  }

  thead {
    display: none;
  }

  tr {
    margin-bottom: 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    box-shadow: var(--shadow);
    overflow: hidden;
  }

  td {
    display: grid;
    grid-template-columns: 110px minmax(0, 1fr);
    gap: 12px;
    padding: 9px 12px;
    text-align: left;
    white-space: normal;
  }

  td::before {
    color: var(--muted);
    font-size: 0.75rem;
    font-weight: 800;
    text-transform: uppercase;
  }

  td:nth-child(1)::before {
    content: "Code";
  }

  td:nth-child(2)::before {
    content: "Description";
  }

  td:nth-child(3)::before {
    content: "In Stock";
  }

  td:nth-child(4)::before {
    content: "Sold";
  }

  td:nth-child(5)::before {
    content: "Daily";
  }

  td:nth-child(6)::before {
    content: "Projected";
  }

  td:nth-child(7)::before {
    content: "Short";
  }

  td:nth-child(8)::before {
    content: "Order";
  }

  td:nth-child(9)::before {
    content: "Stock Out";
  }
}
