:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --head: #f7f9fb;
  --filter: #fbfcfd;
  --line: #cfd8df;
  --line-dark: #aebbc5;
  --text: #101820;
  --muted: #5c6b76;
  --green: #13795b;
  --green-soft: #def7ec;
  --blue: #0b63ce;
  --blue-soft: #e7f0ff;
  --yellow: #fff45c;
  --amber: #a15c00;
  --amber-soft: #fff0cf;
  --red: #b3261e;
  --red-soft: #ffe4e0;
  --shadow: 0 10px 24px rgba(15, 23, 42, 0.08);
  --row-h: 27px;
  --font: 12px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: var(--font);
  letter-spacing: 0;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  min-height: 48px;
  padding: 6px 10px;
  background: rgba(255, 255, 255, 0.96);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(10px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  font-size: 13px;
  font-weight: 850;
}

.nav-pill {
  display: inline-flex;
  align-items: center;
  height: 28px;
  padding: 0 9px;
  color: var(--blue);
  font-size: 11px;
  font-weight: 850;
  text-decoration: none;
  white-space: nowrap;
  background: var(--blue-soft);
  border: 1px solid #bcd4ff;
  border-radius: 7px;
}

.nav-pill:hover {
  background: #dceaff;
}

.mark {
  display: grid;
  width: 28px;
  height: 28px;
  place-items: center;
  color: #fff;
  background: var(--green);
  border-radius: 6px;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  justify-content: flex-end;
  min-width: 0;
  overflow-x: visible;
}

.live-status {
  grid-column: 1 / -1;
  min-width: 0;
  color: var(--muted);
  font-weight: 740;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.live-status[data-tone="good"] {
  color: var(--green);
}

.live-status[data-tone="bad"] {
  color: var(--red);
}

.avatar {
  display: grid;
  width: 30px;
  height: 30px;
  place-items: center;
  color: #fff;
  background: var(--blue);
  border-radius: 999px;
  font-weight: 900;
  letter-spacing: 0;
}

.pill,
.field,
.mini-input {
  height: 30px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}

.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 0 9px;
  color: var(--text);
  font-weight: 800;
  white-space: nowrap;
}

.pill.primary {
  color: var(--blue);
  background: var(--blue-soft);
  border-color: #bcd4ff;
}

.field {
  min-width: 108px;
  padding: 0 8px;
  font-weight: 760;
}

.field.search {
  min-width: 150px;
}

.mini-input {
  width: 56px;
  padding: 0 6px;
  text-align: right;
  font-weight: 820;
}

.wrap {
  max-width: 1920px;
  margin: 0 auto;
  padding: 8px;
}

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

.grid-head {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) auto;
  gap: 8px;
  align-items: center;
  min-height: 38px;
  padding: 6px 8px;
  border-bottom: 1px solid var(--line);
}

.grid-title {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
}

.grid-title h1 {
  margin: 0;
  font-size: 15px;
  line-height: 1.15;
}

.grid-title span {
  color: var(--muted);
  font-weight: 720;
}

.formula-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  justify-content: flex-end;
}

.formula-chip {
  display: inline-flex;
  align-items: center;
  height: 26px;
  padding: 0 8px;
  color: #25313a;
  font-weight: 780;
  background: #f0f4f7;
  border: 1px solid var(--line);
  border-radius: 6px;
  white-space: nowrap;
}

.data-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  align-items: center;
  min-height: 30px;
  padding: 4px 8px;
  color: #2d3a43;
  background: #fbfcfd;
  border-bottom: 1px solid var(--line);
}

.data-summary span,
.summary-chip {
  display: inline-flex;
  align-items: center;
  min-height: 21px;
  padding: 0 7px;
  color: #2d3a43;
  font-weight: 780;
  background: #eef3f7;
  border: 1px solid #d7e0e7;
  border-radius: 999px;
  white-space: nowrap;
}

.summary-chip {
  gap: 2px;
}

.summary-chip.active {
  outline: 2px solid var(--blue);
  outline-offset: 1px;
}

.data-summary strong,
.summary-chip strong {
  margin: 0 2px;
  font-weight: 920;
}

.data-summary .bad,
.summary-chip.bad {
  color: var(--red);
  background: var(--red-soft);
  border-color: #ffc4bd;
}

.data-summary .warn,
.summary-chip.warn {
  color: var(--amber);
  background: var(--amber-soft);
  border-color: #ffd98a;
}

.summary-chip.good {
  color: var(--green);
  background: var(--green-soft);
  border-color: #b9ebd2;
}

.table-shell {
  max-height: calc(100vh - 152px);
  overflow: auto;
}

table {
  width: max-content;
  min-width: 1380px;
  border-collapse: separate;
  border-spacing: 0;
  table-layout: fixed;
}

col.item {
  width: 128px;
}

col.brand {
  width: 55px;
}

col.month {
  width: 38px;
}

col.sales {
  width: 58px;
}

col.daily {
  width: 58px;
}

col.stock {
  width: 45px;
}

col.target {
  width: 56px;
}

col.need {
  width: 54px;
}

col.status {
  width: 72px;
}

col.trailing-blank-col {
  width: 72px;
}

col.otw-col {
  width: 112px;
}

th,
td {
  height: var(--row-h);
  padding: 2px 4px;
  overflow: hidden;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  text-align: right;
  text-overflow: ellipsis;
  vertical-align: middle;
  white-space: nowrap;
}

th {
  position: sticky;
  z-index: 10;
  color: #27333c;
  font-weight: 880;
  background: var(--head);
  user-select: none;
}

thead tr.labels th {
  top: 0;
  height: 27px;
}

thead tr.filters th {
  top: 27px;
  height: 24px;
  background: var(--filter);
}

th:first-child,
td:first-child,
th.sticky-col,
td.sticky-col {
  position: sticky;
  left: 0;
  z-index: 12;
  text-align: left;
}

thead th:first-child,
thead th.sticky-col {
  z-index: 22;
}

td:first-child,
td.sticky-col {
  background: var(--row-bg);
}

.filter-input {
  width: 100%;
  height: 18px;
  padding: 0 3px;
  color: var(--text);
  background: #fff;
  border: 1px solid #dae2e8;
  border-radius: 3px;
  outline: none;
}

.filter-input:focus {
  border-color: var(--blue);
}

.sort-btn {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 3px;
  align-items: center;
  width: 100%;
  min-height: 22px;
  padding: 0;
  color: inherit;
  text-align: inherit;
  background: transparent;
  border: 0;
  font-weight: inherit;
}

.sort-indicator {
  color: var(--blue);
  font-size: 9px;
  font-weight: 900;
}

.dynamic-sort-btn {
  min-width: 0;
  cursor: pointer;
  font-size: 11px;
  font-weight: 900;
}

.dynamic-sort-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.keep-sort-btn {
  min-height: 20px;
  text-align: left;
}

tbody tr {
  --row-bg: #fff;
  background: var(--row-bg);
}

tbody tr:nth-child(even) {
  --row-bg: #f5f7f9;
}

tbody td {
  background: var(--row-bg);
  font-weight: 560;
}

tbody td[data-col-tone="strong"] {
  font-weight: 840;
}

tbody td[data-col-tone="normal"] {
  font-weight: 560;
}

tbody tr:hover td {
  --row-bg: #f3f8ff;
  background: var(--row-bg);
}

tbody tr.child td {
  color: #2b3b4a;
  --row-bg: #eef5ff;
  background: var(--row-bg);
}

tbody tr.row-order td.sticky-col,
tbody tr.row-order td:first-child {
  box-shadow: inset 4px 0 0 var(--red);
}

tbody tr.row-watch td.sticky-col,
tbody tr.row-watch td:first-child {
  box-shadow: inset 4px 0 0 #d18800;
}

tbody tr.row-ok td.sticky-col,
tbody tr.row-ok td:first-child {
  box-shadow: inset 4px 0 0 #74c69d;
}

tbody tr.row-no-stock td:first-child .sub,
tbody tr.row-no-sales td:first-child .sub {
  color: var(--red);
}

tbody tr.child td:first-child {
  padding-left: 18px;
}

tbody tr.dragging {
  opacity: 0.55;
}

tbody tr.drop-before td {
  border-top: 2px solid var(--blue);
}

tfoot td {
  position: sticky;
  bottom: 0;
  z-index: 14;
  color: #172c3d;
  background: #eaf3ff;
  border-top: 2px solid var(--blue);
  border-bottom: 0;
  font-weight: 900;
  box-shadow: 0 -2px 6px rgba(28, 72, 112, 0.1);
}

tfoot td:first-child,
tfoot td.sticky-col {
  z-index: 18;
  background: #dcecff;
}

.total-label {
  display: flex;
  gap: 6px;
  align-items: baseline;
}

.total-label strong {
  color: #075fbd;
  font-size: 12px;
  font-weight: 950;
}

.total-label span,
.total-not-additive {
  color: var(--muted);
  font-size: 10px;
  font-weight: 750;
}

.total-need {
  color: var(--red);
  background: #fff0b8 !important;
}

tfoot td.total-otw.otw-pg,
tfoot td.total-keep.keep-pg {
  background: #def2e8;
}

tfoot td.total-otw.otw-kl,
tfoot td.total-keep.keep-kl {
  background: #e0edff;
}

tfoot td.trailing-blank-cell {
  background: #f4f8fc;
}

th.draggable-column {
  cursor: grab;
}

th.column-dragging {
  opacity: 0.55;
}

th.column-drop-before {
  box-shadow: inset 2px 0 0 var(--blue);
}

th.column-drop-after {
  box-shadow: inset -2px 0 0 var(--blue);
}

th.trailing-blank-cell,
td.trailing-blank-cell {
  color: transparent;
  background: #fff;
  cursor: default;
}

thead tr.filters th.trailing-blank-cell {
  background: var(--filter);
}

tbody tr:nth-child(even) td.trailing-blank-cell {
  background: #f5f7f9;
}

th.otw-header,
th.otw-date-cell,
td.otw-cell,
th.keep-header,
th.keep-subheader,
td.keep-cell {
  padding: 3px 4px;
}

th.otw-pg,
td.otw-pg {
  background: #eef8f3;
}

th.otw-kl,
td.otw-kl {
  background: #eef5ff;
}

tbody tr:nth-child(even) td.otw-pg {
  background: #e8f4ee;
}

tbody tr:nth-child(even) td.otw-kl {
  background: #e8f1fc;
}

tbody tr:hover td.otw-pg,
tbody tr:hover td.otw-kl {
  background: #e4f0ff;
}

th.keep-pg,
td.keep-pg {
  background: #edf7f1;
  box-shadow: inset 0 2px 0 #d18a00;
}

th.keep-kl,
td.keep-kl {
  background: #edf4fd;
  box-shadow: inset 0 2px 0 #d18a00;
}

tbody tr:nth-child(even) td.keep-pg {
  background: #e7f2eb;
}

tbody tr:nth-child(even) td.keep-kl {
  background: #e7eff9;
}

tbody tr:hover td.keep-pg,
tbody tr:hover td.keep-kl {
  background: #fff3d8;
}

th.keep-header strong,
th.keep-header .keep-sort-btn {
  display: block;
  font-size: 11px;
  font-weight: 900;
  text-align: left;
}

th.keep-subheader {
  color: var(--muted);
  font-size: 9px;
  font-weight: 800;
  text-align: left;
}

.otw-head-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 3px;
  align-items: center;
  width: 100%;
}

.otw-head-row strong,
.otw-head-row .otw-sort-btn {
  overflow: hidden;
  font-size: 11px;
  font-weight: 900;
  text-align: left;
  text-overflow: ellipsis;
}

.otw-head-actions {
  display: flex;
  flex: 0 0 auto;
  gap: 2px;
  align-items: center;
}

.otw-head-actions button {
  display: grid;
  width: 18px;
  height: 18px;
  padding: 0;
  place-items: center;
  color: #33424c;
  font-size: 13px;
  line-height: 1;
  background: rgba(255, 255, 255, 0.88);
  border: 1px solid #cbd6dd;
  border-radius: 4px;
}

.otw-head-actions button:hover:not(:disabled) {
  color: var(--blue);
  border-color: #9dbce9;
}

.otw-head-actions button:disabled {
  cursor: not-allowed;
  opacity: 0.42;
}

th.otw-header[draggable="true"] {
  cursor: grab;
}

th.otw-column-dragging {
  opacity: 0.55;
}

th.otw-drop-before {
  box-shadow: inset 3px 0 0 var(--blue);
}

th.otw-drop-after {
  box-shadow: inset -3px 0 0 var(--blue);
}

.otw-date-input,
.otw-qty-input,
.keep-qty-input {
  width: 100%;
  min-width: 0;
  height: 22px;
  padding: 0 4px;
  color: var(--text);
  font: inherit;
  font-weight: 780;
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid #cad6df;
  border-radius: 4px;
  outline: 0;
}

.otw-date-input {
  font-size: 10px;
}

.otw-qty-input,
.keep-qty-input {
  text-align: right;
}

.otw-date-input:focus,
.otw-qty-input:focus,
.keep-qty-input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 1px rgba(11, 99, 206, 0.15);
}

.otw-date-input:disabled,
.otw-qty-input:disabled,
.keep-qty-input:disabled {
  color: var(--muted);
  cursor: not-allowed;
  opacity: 0.62;
}

td.stock-with-otw {
  color: var(--blue);
  font-weight: 900 !important;
  box-shadow: inset 0 -2px 0 #8fb7ec;
}

.col-resizer {
  position: absolute;
  top: 0;
  right: -3px;
  z-index: 4;
  width: 7px;
  height: 100%;
  cursor: col-resize;
  touch-action: none;
}

.col-resizer:hover,
body.resizing-column .col-resizer {
  background: rgba(11, 99, 206, 0.16);
}

.drag-handle {
  flex: 0 0 12px;
  color: #81909c;
  font-size: 12px;
  text-align: center;
  cursor: grab;
}

.drag-spacer {
  flex: 0 0 12px;
}

.item-cell {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
}

.expandable-code-cell {
  cursor: pointer;
}

.expandable-code-cell:hover .code,
.expandable-code-cell:hover .sub {
  color: var(--blue);
}

.expandable-code-cell:hover .sub {
  text-decoration: underline;
  text-underline-offset: 2px;
}

.expand {
  display: grid;
  flex: 0 0 auto;
  width: 17px;
  height: 17px;
  margin-left: 2px;
  place-items: center;
  color: var(--blue);
  font-weight: 900;
  background: var(--blue-soft);
  border: 0;
  border-radius: 999px;
}

.code-stack {
  flex: 1 1 auto;
  min-width: 0;
}

.code {
  overflow: hidden;
  font-weight: 900;
  text-overflow: ellipsis;
}

.sub {
  overflow: hidden;
  color: var(--muted);
  font-size: 10px;
  font-weight: 720;
  line-height: 1.05;
  text-overflow: ellipsis;
}

.need-cell {
  background: #fff36b !important;
}

.negative {
  color: var(--red);
}

.positive {
  color: var(--green);
}

.status {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 58px;
  height: 18px;
  padding: 0 5px;
  font-size: 11px;
  font-weight: 900;
  border-radius: 999px;
}

.status.order {
  color: var(--red);
  background: var(--red-soft);
}

.status.watch {
  color: var(--amber);
  background: var(--amber-soft);
}

.status.ok {
  color: var(--green);
  background: var(--green-soft);
}

.selected-cell {
  position: relative;
  background: #dcecff !important;
  outline: 1px solid #71a7f8;
  outline-offset: -1px;
}

.selection-bar {
  position: sticky;
  bottom: 0;
  z-index: 25;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  min-height: 30px;
  padding: 5px 8px;
  color: #24313b;
  background: rgba(255, 255, 255, 0.96);
  border-top: 1px solid var(--line);
  backdrop-filter: blur(10px);
}

.selection-bar strong {
  font-weight: 900;
}

.notes {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-top: 8px;
}

.note {
  padding: 8px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.note strong {
  display: block;
  margin-bottom: 4px;
  font-size: 12px;
}

.note span {
  color: var(--muted);
  font-weight: 650;
  line-height: 1.35;
}

@media (max-width: 1000px) {
  :root {
    --font: 10px;
    --row-h: 23px;
  }

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

  .toolbar {
    justify-content: flex-start;
  }

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

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

.topbar {
  display: block;
  min-height: 0;
  padding: 0;
}

.header-row {
  display: grid;
  grid-template-columns: minmax(250px, 1fr) auto;
  gap: 14px;
  align-items: center;
  min-height: 58px;
  padding: 8px 16px;
}

.brand-copy {
  min-width: 0;
}

.brand-copy strong {
  display: block;
  font-size: 16px;
  line-height: 1.1;
}

.brand-copy span {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 650;
}

.header-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  align-items: center;
  justify-content: flex-end;
}

.language-toggle {
  min-width: 52px;
  white-space: nowrap;
}

.sync-strip {
  display: block;
  min-height: 30px;
  padding: 6px 16px;
  background: #fbfcfd;
  border-top: 1px solid #edf1f3;
  border-bottom: 0;
  font-size: 11px;
}

.wrap {
  max-width: 1800px;
  padding: 12px 14px 28px;
}

.command-bar {
  display: grid;
  grid-template-columns: minmax(210px, 1fr) auto auto auto auto;
  gap: 8px;
  align-items: center;
  margin-bottom: 10px;
}

.command-bar .field {
  width: 100%;
  height: 34px;
  min-width: 128px;
  border-color: var(--line-dark);
  border-radius: 7px;
}

.filter-group,
.preset-group,
.buffer-group {
  display: flex;
  gap: 6px;
  align-items: center;
}

.preset-control {
  display: grid;
  grid-template-columns: auto 58px;
  align-items: center;
  min-height: 34px;
  overflow: hidden;
  background: #fff;
  border: 1px solid var(--line-dark);
  border-radius: 7px;
}

.preset-control span {
  padding-left: 9px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 850;
  white-space: nowrap;
}

.preset-control select {
  width: 58px;
  height: 32px;
  padding: 0 5px;
  background: #fff;
  border: 0;
  border-left: 1px solid var(--line);
  outline: 0;
  font-weight: 850;
}

.segmented {
  display: inline-flex;
  min-height: 34px;
  padding: 3px;
  gap: 2px;
  background: #fff;
  border: 1px solid var(--line-dark);
  border-radius: 7px;
}

.segmented button {
  min-width: 64px;
  min-height: 26px;
  padding: 0 9px;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-radius: 5px;
  font-weight: 850;
}

.segmented button.active {
  color: #fff;
  background: var(--green);
}

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

.number-control {
  display: grid;
  grid-template-columns: auto 50px;
  align-items: center;
  min-height: 34px;
  overflow: hidden;
  background: #fff;
  border: 1px solid var(--line-dark);
  border-radius: 7px;
}

.number-control span {
  padding-left: 9px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 850;
}

.number-control input {
  width: 50px;
  height: 32px;
  padding: 0 5px;
  text-align: right;
  background: #fff;
  border: 0;
  border-left: 1px solid var(--line);
  outline: 0;
  font-weight: 850;
}

.sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(145px, 1fr));
  gap: 8px;
  margin-bottom: 10px;
}

.kpi {
  min-height: 84px;
  padding: 10px 13px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 4px 14px rgba(31, 45, 55, 0.04);
}

.kpi.order { border-top: 3px solid var(--red); }
.kpi.watch { border-top: 3px solid #d18800; }
.kpi.stock { border-top: 3px solid var(--green); }
.kpi.cover { border-top: 3px solid var(--blue); }
.kpi.health { border-top: 3px solid #635bba; }

.kpi-label {
  color: var(--muted);
  font-size: 11px;
  font-weight: 820;
  text-transform: uppercase;
}

.kpi-value {
  display: flex;
  gap: 7px;
  align-items: baseline;
  margin-top: 5px;
  font-size: 25px;
  line-height: 1;
  font-weight: 900;
}

.kpi-value small {
  color: var(--muted);
  font-size: 11px;
  font-weight: 750;
}

.kpi-detail {
  margin-top: 7px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 650;
}

.kpi.order .kpi-value { color: var(--red); }
.kpi.watch .kpi-value { color: var(--amber); }

.main-grid-card {
  box-shadow: 0 10px 28px rgba(31, 45, 55, 0.08);
}

.grid-head {
  min-height: 52px;
  padding: 8px 10px;
}

.grid-title h1 {
  font-size: 17px;
}

.formula-chip {
  height: 25px;
  border-radius: 999px;
  font-size: 11px;
}

.formula-chip.blue {
  color: var(--blue);
  background: var(--blue-soft);
  border-color: #c6d9fa;
}

.view-bar {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  min-height: 46px;
  padding: 6px 10px;
  background: #fbfcfd;
  border-bottom: 1px solid var(--line);
}

.view-tabs {
  display: flex;
  gap: 3px;
  align-items: center;
}

.view-tabs button {
  min-height: 31px;
  padding: 0 11px;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-radius: 6px;
  font-weight: 850;
}

.view-tabs button.active {
  color: var(--blue);
  background: var(--blue-soft);
}

.view-tabs button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.view-bar .data-summary {
  min-width: 0;
  min-height: 0;
  padding: 0;
  overflow: hidden;
  background: transparent;
  border: 0;
  flex-wrap: nowrap;
}

.view-actions {
  position: relative;
  display: flex;
  gap: 5px;
  align-items: center;
}

.pill.compact {
  height: 29px;
  padding: 0 9px;
  font-size: 11px;
}

.columns-menu {
  position: absolute;
  top: 34px;
  right: 0;
  z-index: 100;
  display: none;
  width: 240px;
  max-height: 340px;
  overflow: auto;
  padding: 8px;
  background: #fff;
  border: 1px solid var(--line-dark);
  border-radius: 8px;
  box-shadow: 0 16px 34px rgba(24, 35, 42, 0.18);
}

.columns-menu.open { display: block; }

.columns-menu label {
  display: flex;
  gap: 8px;
  align-items: center;
  min-height: 30px;
  padding: 0 6px;
  border-radius: 5px;
  font-weight: 720;
}

.columns-menu label:hover { background: #f5f7f9; }

.table-shell {
  max-height: 540px;
}

table {
  min-width: 100%;
}

th,
td {
  height: 34px;
  padding: 4px 7px;
  font-size: 13px;
}

thead tr.labels th {
  height: 34px;
}

thead tr.filters th {
  top: 34px;
  height: 29px;
}

.filter-input {
  height: 22px;
  border-radius: 4px;
}

.sub {
  font-size: 10px;
}

.need-cell {
  background: #fff7bf !important;
}

.need-cell.negative {
  color: var(--red);
  background: #ffe8a8 !important;
  font-weight: 900 !important;
}

.need-cell.positive {
  color: var(--green);
}

.text-cell {
  text-align: left;
}

.context-menu {
  position: fixed;
  z-index: 200;
  display: none;
  width: 190px;
  padding: 6px;
  background: #fff;
  border: 1px solid var(--line-dark);
  border-radius: 7px;
  box-shadow: 0 15px 35px rgba(22, 35, 43, 0.2);
}

.context-menu.open { display: block; }

.context-menu button {
  width: 100%;
  min-height: 31px;
  padding: 0 8px;
  text-align: left;
  background: transparent;
  border: 0;
  border-radius: 5px;
  font-weight: 750;
}

.context-menu button:hover { background: #f5f7f9; }

.below-grid {
  display: grid;
  grid-template-columns: 1.1fr 1.5fr 0.9fr;
  gap: 10px;
  margin-top: 10px;
}

.purchasing-insights {
  display: flex;
  flex-direction: column;
}

.stockout-risk-card {
  min-height: 340px;
  border-top: 3px solid var(--red);
}

.stockout-risk-head {
  min-height: 54px;
}

.stockout-horizon {
  display: inline-flex;
  gap: 0;
  overflow: hidden;
  border: 1px solid #c7d4de;
  border-radius: 6px;
  background: #f5f8fa;
}

.stockout-horizon button {
  min-width: 48px;
  height: 30px;
  padding: 0 10px;
  border: 0;
  border-right: 1px solid #c7d4de;
  background: transparent;
  color: #52626f;
  font: inherit;
  font-size: 11px;
  font-weight: 850;
  cursor: pointer;
}

.stockout-horizon button:last-child { border-right: 0; }
.stockout-horizon button.active { color: #fff; background: var(--red); }

.stockout-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  border-bottom: 1px solid var(--line);
  background: #fbfcfd;
}

.stockout-summary > div {
  min-height: 56px;
  padding: 9px 12px;
  border-right: 1px solid var(--line);
}

.stockout-summary > div:last-child { border-right: 0; }
.stockout-summary span { display: block; color: var(--muted); font-size: 10px; font-weight: 800; }
.stockout-summary strong { color: var(--ink); font-size: 22px; line-height: 1.15; }
.stockout-summary > div:nth-child(2) strong,
.stockout-summary > div:nth-child(3) strong { color: var(--red); }
.stockout-summary small { margin-left: 4px; color: var(--muted); font-size: 10px; font-weight: 800; }

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

.stockout-table {
  width: 100%;
  min-width: 850px;
  border-collapse: collapse;
  table-layout: fixed;
}

.stockout-table th,
.stockout-table td {
  position: static;
  height: 34px;
  padding: 5px 10px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  font-size: 11px;
  text-align: right;
  white-space: nowrap;
}

.stockout-table th {
  color: var(--muted);
  background: #f4f7f9;
  font-size: 9px;
  text-transform: uppercase;
}

.stockout-table th:first-child,
.stockout-table th:nth-child(2),
.stockout-table td:first-child,
.stockout-table td:nth-child(2) { text-align: left; }
.stockout-table tbody tr:nth-child(even) { background: #fafbfc; }
.stockout-table .empty-cell { height: 90px; color: var(--muted); text-align: center; }
.stockout-required { color: var(--red); font-weight: 900; }

.stockout-date strong { display: block; font-size: 11px; }
.stockout-date small { display: block; color: var(--red); font-size: 8px; font-weight: 900; text-transform: uppercase; }

.stockout-risk-badge,
.stockout-branch {
  display: inline-flex;
  align-items: center;
  min-height: 20px;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 9px;
  font-weight: 900;
}

.stockout-risk-badge.out,
.stockout-risk-badge.critical { color: #a91f1f; background: #ffe1dd; }
.stockout-risk-badge.high { color: #b54d09; background: #ffedcf; }
.stockout-risk-badge.warning { color: #8a6500; background: #fff5bf; }
.stockout-risk-badge.watch { color: #315d89; background: #e5f0fb; }
.stockout-branch.pg { color: #087a54; background: #ddf5eb; }
.stockout-branch.kl { color: #075fbd; background: #e3efff; }

.dashboard-widget-section[hidden],
.dashboard-widget-item[hidden],
.widget-manager-backdrop[hidden] {
  display: none !important;
}

.dashboard-widget-section,
.dashboard-widget-item {
  transition: box-shadow 120ms ease, opacity 120ms ease;
}

.widget-dragging {
  opacity: 0.55;
  outline: 2px solid var(--blue);
  outline-offset: -2px;
}

.widget-controls {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 4px;
}

.widget-controls-section {
  margin-left: auto;
}

.widget-icon-button,
.widget-manager-close {
  display: inline-grid;
  place-items: center;
  width: 25px;
  height: 25px;
  padding: 0;
  border: 1px solid #c7d4de;
  border-radius: 5px;
  background: #fff;
  color: #40515e;
  font: inherit;
  font-size: 15px;
  font-weight: 900;
  line-height: 1;
  cursor: pointer;
}

.widget-icon-button:hover,
.widget-manager-close:hover {
  border-color: #8fa9bb;
  background: #f2f7fa;
  color: var(--blue);
}

.widget-icon-button:focus-visible,
.widget-manager-close:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 1px;
}

.widget-drag-handle {
  cursor: grab;
  font-size: 17px;
}

.widget-drag-handle:active {
  cursor: grabbing;
}

.below-card {
  min-height: 220px;
  overflow: hidden;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 5px 18px rgba(31, 45, 55, 0.05);
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 44px;
  padding: 8px 11px;
  border-bottom: 1px solid var(--line);
}

.card-head h2 {
  margin: 0;
  font-size: 14px;
}

.card-head span {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
}

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

.mini-table {
  width: 100%;
  min-width: 500px;
  border-collapse: collapse;
  table-layout: fixed;
}

.mini-table th,
.mini-table td {
  position: static;
  height: 32px;
  padding: 4px 8px;
  font-size: 11px;
}

.mini-table th {
  color: var(--muted);
  background: #f7f9fa;
  text-transform: uppercase;
}

.mini-table tbody tr:nth-child(even) { background: #f7f9fa; }
.mini-table .empty-cell { color: var(--muted); text-align: left; }
.shortage-value { color: var(--red); font-weight: 900; }

.decision-list {
  margin: 0;
  padding: 5px 11px 10px;
  list-style: none;
}

.decision-list li {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  min-height: 48px;
  border-bottom: 1px solid #edf1f3;
}

.decision-list li:last-child { border-bottom: 0; }
.decision-list strong { display: block; font-size: 12px; }
.decision-list small { display: block; margin-top: 2px; color: var(--muted); font-weight: 650; }
.decision-value { color: var(--blue); text-align: right; font-weight: 900; }
.setup-state { color: var(--amber); font-weight: 900; }
.setup-state.ready { color: var(--green); }

.transfer-direction,
.transfer-cell {
  text-align: center;
}

.transfer-cell {
  color: var(--muted);
  font-weight: 850;
}

.transfer-cell.transfer-active {
  background: #e8f1ff;
  color: #075fc7;
}

#transferList {
  padding-top: 0;
}

.decision-list .transfer-opportunity {
  display: block;
  padding: 12px 0;
}

.transfer-opportunity-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.transfer-opportunity-head > div {
  min-width: 0;
}

.transfer-opportunity-head strong {
  font-size: 13px;
}

.transfer-route {
  display: inline-flex;
  align-items: center;
  min-height: 19px;
  margin-right: 4px;
  padding: 0 6px;
  border-radius: 5px;
  background: var(--blue-soft);
  color: var(--blue);
  font-size: 9px;
  font-weight: 900;
}

.transfer-opportunity-head .decision-value {
  flex: 0 0 auto;
  font-size: 12px;
}

.transfer-compare {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 34px minmax(0, 1fr);
  gap: 6px;
  align-items: stretch;
  margin-top: 9px;
}

.transfer-branch {
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fbfcfd;
}

.transfer-branch-head {
  min-height: 31px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 6px 7px;
  border-bottom: 1px solid var(--line);
}

.transfer-branch-head strong {
  overflow: hidden;
  font-size: 10px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.transfer-branch-head span {
  flex: 0 0 auto;
  padding: 2px 5px;
  border-radius: 4px;
  font-size: 8px;
  font-weight: 900;
}

.transfer-branch.surplus .transfer-branch-head span {
  background: var(--green-soft);
  color: var(--green);
}

.transfer-branch.short .transfer-branch-head span {
  background: var(--red-soft);
  color: var(--red);
}

.transfer-metrics {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0;
  padding: 3px 7px 6px;
}

.transfer-metrics > span {
  min-width: 0;
  padding: 5px 4px;
  border-bottom: 1px solid #edf1f3;
}

.transfer-metrics > span:last-child {
  grid-column: 1 / -1;
  border-bottom: 0;
}

.transfer-metrics small,
.transfer-metrics strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.transfer-metrics small {
  margin: 0;
  color: var(--muted);
  font-size: 8px;
  font-weight: 750;
  text-transform: uppercase;
}

.transfer-metrics strong {
  margin-top: 2px;
  font-size: 11px;
}

.transfer-after {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  min-height: 31px;
  padding: 5px 7px;
  background: #f1f5f9;
  font-size: 8px;
}

.transfer-after span {
  color: var(--muted);
  font-weight: 750;
}

.transfer-after strong {
  font-size: 9px;
  text-align: right;
}

.transfer-flow {
  display: grid;
  place-content: center;
  align-content: center;
  gap: 2px;
  color: var(--blue);
  text-align: center;
}

.transfer-flow span {
  font-size: 19px;
  font-weight: 900;
  line-height: 1;
}

.transfer-flow small {
  color: var(--muted);
  font-size: 8px;
  font-weight: 800;
}

.transfer-reason {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 9px;
  font-weight: 650;
  line-height: 1.45;
}

.transfer-reason strong {
  display: inline;
  color: var(--text);
  font-size: inherit;
}

.readiness-card {
  min-height: 0;
  margin-top: 10px;
}

.health-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  padding: 10px;
}

.health-box {
  position: relative;
  min-height: 66px;
  padding: 9px 70px 9px 9px;
  background: #fbfcfd;
  border: 1px solid var(--line);
  border-radius: 7px;
}

.health-box > .widget-controls {
  position: absolute;
  top: 7px;
  right: 7px;
}

.health-box strong { display: block; color: var(--green); font-size: 18px; }
.health-box span { display: block; margin-top: 4px; color: var(--muted); font-size: 10px; font-weight: 700; }

.market-watch-card {
  min-height: 0;
  margin-top: 10px;
}

.market-watch-head {
  gap: 12px;
}

.market-watch-head h2 {
  font-size: 18px;
}

.market-watch-head p {
  font-size: 11px;
}

.market-cadence {
  flex: 0 0 auto;
  margin: 0 !important;
  padding: 4px 7px;
  border: 1px solid #cbd8e2;
  border-radius: 6px;
  background: #f5f8fa;
  color: #40515e !important;
  font-size: 11px !important;
  font-weight: 850 !important;
}

.market-watch-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  border-bottom: 1px solid var(--line);
}

.market-metric {
  min-width: 0;
  min-height: 142px;
  padding: 13px 14px;
  border-right: 1px solid var(--line);
  background: #fff;
}

.market-metric:last-child {
  border-right: 0;
}

.market-port {
  box-shadow: inset 0 3px 0 #1976d2;
}

.market-cost {
  box-shadow: inset 0 3px 0 #16815b;
}

.market-metric-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 24px;
}

.market-metric-head .widget-controls {
  margin-left: auto;
}

.market-metric-head > span {
  min-width: 0;
  overflow: hidden;
  color: #273640;
  font-size: 15px;
  font-weight: 850;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.market-risk {
  flex: 0 0 auto;
  padding: 3px 7px;
  border-radius: 5px;
  background: #eef2f5;
  color: #647481;
  font-size: 10px;
  font-weight: 900;
  line-height: 1.4;
  text-transform: uppercase;
}

.market-risk.low {
  background: var(--green-soft);
  color: var(--green);
}

.market-risk.medium {
  background: #fff3cc;
  color: #a45c00;
}

.market-risk.high {
  background: var(--red-soft);
  color: var(--red);
}

.market-risk.reference {
  background: var(--blue-soft);
  color: var(--blue);
}

.market-risk.stale,
.market-risk.unknown {
  background: #eef2f5;
  color: #657581;
}

.market-value {
  display: flex;
  align-items: baseline;
  gap: 5px;
  min-height: 49px;
  padding-top: 9px;
}

.market-value strong {
  overflow: hidden;
  color: #0f1c27;
  font-size: 34px;
  font-weight: 900;
  letter-spacing: 0;
  line-height: 1;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.market-value span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.market-value-wide strong {
  font-size: 23px;
}

.market-metric p,
.market-metric small {
  display: block;
  overflow: hidden;
  margin: 0;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.market-metric p {
  color: #42525e;
  font-size: 11px;
  font-weight: 750;
}

.market-metric small {
  margin-top: 6px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 650;
}

.market-method {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 42px;
  padding: 8px 14px;
  background: #f8fafb;
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
}

.market-method a {
  color: var(--blue);
  font-weight: 850;
  text-decoration: none;
}

.market-method a:hover {
  text-decoration: underline;
}

.widget-manager-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1200;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(15, 28, 39, 0.44);
}

.widget-manager-dialog {
  width: min(520px, 100%);
  max-height: min(720px, calc(100vh - 36px));
  overflow: hidden;
  background: #fff;
  border: 1px solid #bac9d4;
  border-radius: 8px;
  box-shadow: 0 22px 60px rgba(15, 28, 39, 0.24);
}

.widget-manager-head,
.widget-manager-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
}

.widget-manager-head {
  border-bottom: 1px solid var(--line);
}

.widget-manager-head h2,
.widget-manager-head p {
  margin: 0;
}

.widget-manager-head h2 {
  font-size: 16px;
}

.widget-manager-head p {
  margin-top: 3px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
}

.widget-manager-list {
  max-height: min(540px, calc(100vh - 190px));
  overflow-y: auto;
  padding: 8px 14px;
}

.widget-manager-group + .widget-manager-group {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
}

.widget-manager-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 32px;
  color: var(--text);
  font-size: 12px;
  cursor: pointer;
}

.widget-manager-row input {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--blue);
}

.widget-manager-child {
  padding-left: 24px;
  color: #40515e;
}

.widget-manager-actions {
  justify-content: flex-end;
  border-top: 1px solid var(--line);
  background: #f8fafb;
}

@media (max-width: 1100px) {
  .command-bar { grid-template-columns: 1fr auto; }
  .kpi-grid { grid-template-columns: repeat(3, minmax(145px, 1fr)); }
  .grid-head { grid-template-columns: 1fr; }
  .formula-bar { justify-content: flex-start; }
  .view-bar { grid-template-columns: 1fr; }
  .view-actions { justify-content: flex-start; }
  .below-grid { grid-template-columns: 1fr 1fr; }
  .market-watch-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .market-metric:nth-child(3) { border-right: 0; }
  .market-metric:nth-child(n + 4) { border-top: 1px solid var(--line); }
}

@media (max-width: 760px) {
  .header-row { grid-template-columns: 1fr; }
  .header-actions { justify-content: flex-start; }
  .command-bar { grid-template-columns: 1fr; }
  .segmented { width: 100%; }
  .segmented button { flex: 1; }
  .filter-group { width: 100%; }
  .filter-group .field { min-width: 0; }
  .buffer-group { overflow-x: auto; }
  .preset-group { overflow-x: auto; }
  .kpi-grid { grid-template-columns: 1fr 1fr; }
  .view-tabs { overflow-x: auto; }
  .below-grid { grid-template-columns: 1fr; }
  .stockout-risk-card { min-height: 300px; }
  .stockout-risk-head {
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 7px;
  }
  .stockout-horizon { order: 2; }
  .stockout-horizon button { min-width: 42px; height: 27px; padding: 0 7px; }
  .stockout-summary { grid-template-columns: 1fr 1fr; }
  .stockout-summary > div { min-height: 47px; padding: 6px 8px; }
  .stockout-summary > div:nth-child(2) { border-right: 0; }
  .stockout-summary > div:nth-child(-n + 2) { border-bottom: 1px solid var(--line); }
  .stockout-summary strong { font-size: 18px; }
  .stockout-table { min-width: 720px; }
  .stockout-table th,
  .stockout-table td { height: 30px; padding: 4px 7px; font-size: 10px; }
  .health-grid { grid-template-columns: 1fr 1fr; }
  .market-watch-grid { grid-template-columns: 1fr 1fr; }
  .health-box { padding-right: 64px; }
  .widget-icon-button { width: 23px; height: 23px; }
  .market-metric {
    min-height: 108px;
    border-top: 1px solid var(--line);
  }
  .market-metric:nth-child(-n + 2) { border-top: 0; }
  .market-metric:nth-child(odd) { border-right: 1px solid var(--line); }
  .market-metric:nth-child(even) { border-right: 0; }
  .market-metric:last-child {
    grid-column: 1 / -1;
    border-right: 0;
  }
  .market-method {
    align-items: flex-start;
    flex-direction: column;
    gap: 4px;
  }
  .transfer-compare { grid-template-columns: 1fr; }
  .transfer-flow { min-height: 28px; }
  .transfer-flow span { transform: rotate(90deg); }
}

@media print {
  @page {
    size: A4 landscape;
    margin: 7mm;
  }

  :root {
    --font: 8px;
    --row-h: 16px;
  }

  body {
    background: #fff;
  }

  .topbar,
  .command-bar,
  .kpi-grid,
  .below-grid,
  .readiness-card,
  .market-watch-card,
  .view-actions,
  .view-tabs,
  .notes,
  .data-summary,
  .selection-bar,
  .filters,
  .expand,
  .drag-handle {
    display: none !important;
  }

  tfoot td {
    position: static;
  }

  .wrap {
    max-width: none;
    padding: 0;
  }

  .main-grid-card {
    border: 0;
    box-shadow: none;
  }

  .grid-head {
    min-height: auto;
    padding: 0 0 4px;
    border-bottom: 1px solid #999;
  }

  .table-shell {
    max-height: none;
    overflow: visible;
  }

  table {
    min-width: 0;
    width: 100%;
    table-layout: fixed;
  }

  th,
  td {
    padding: 1px 2px;
    border-color: #aaa;
  }

  th,
  td:first-child,
  th:first-child {
    position: static;
  }
}
