.materials-page {
  min-width: 320px;
  font-family: "Aptos", "Microsoft YaHei UI", "Microsoft YaHei", sans-serif;
  color: var(--ink);
  background: #f4f7f5;
}

.materials-header {
  align-items: center;
}

.materials-header h1 {
  font-size: 32px;
  line-height: 1.2;
}

.materials-main {
  width: 100%;
  padding: 26px clamp(16px, 2.4vw, 36px) 42px;
}

.materials-controls {
  padding: 0 0 16px;
  border-bottom: 1px solid var(--line);
}

.materials-controls-title,
.materials-actions,
.materials-filter-row,
.materials-month-control {
  display: flex;
  align-items: center;
}

.materials-controls-title {
  justify-content: space-between;
  gap: 18px;
}

.materials-section-label {
  margin: 0 0 5px;
  color: var(--green);
  font-size: 12px;
  font-weight: 800;
}

.materials-controls-title h2 {
  margin: 0;
  font-size: 20px;
}

.materials-actions {
  gap: 8px;
}

.materials-page .primary-button {
  min-height: 42px;
  padding: 0 14px;
  border: 1px solid var(--green-dark);
  border-radius: 6px;
  background: var(--green-dark);
  color: #fff;
  font-size: 14px;
  font-weight: 750;
  cursor: pointer;
}

.materials-page .primary-button:hover,
.materials-page .primary-button:focus-visible {
  border-color: #064a3b;
  background: #064a3b;
  outline: 2px solid rgba(13, 124, 102, 0.2);
  outline-offset: 2px;
}

.materials-page .ghost-button {
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}

.materials-page .ghost-button:hover,
.materials-page .ghost-button:focus-visible {
  border-color: var(--green);
  outline: 2px solid rgba(13, 124, 102, 0.16);
  outline-offset: 2px;
}

.materials-filter-row {
  flex-wrap: wrap;
  gap: 12px 16px;
  margin-top: 18px;
}

.materials-filter-row label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.materials-filter-row input,
.materials-filter-row select,
.materials-ad-cell select,
.materials-count-cell input,
.materials-inventory-editor input {
  min-height: 38px;
  border: 1px solid #cbd5d0;
  border-radius: 5px;
  background: #fff;
  color: var(--ink);
  font-size: 14px;
}

.materials-filter-row input:focus-visible,
.materials-filter-row select:focus-visible,
.materials-ad-cell select:focus-visible,
.materials-count-cell input:focus-visible,
.materials-inventory-editor input:focus-visible {
  border-color: var(--green);
  outline: 2px solid rgba(13, 124, 102, 0.19);
  outline-offset: 1px;
}

.materials-page input[type="number"] {
  appearance: textfield;
  -moz-appearance: textfield;
}

.materials-page input[type="number"]::-webkit-inner-spin-button,
.materials-page input[type="number"]::-webkit-outer-spin-button {
  margin: 0;
  -webkit-appearance: none;
}

.materials-search input {
  width: min(320px, calc(100vw - 40px));
  padding: 0 11px;
}

.materials-filter select {
  min-width: 170px;
  padding: 0 30px 0 10px;
}

.materials-threshold-input {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.materials-threshold-input input {
  width: 70px;
  padding: 0 7px;
  text-align: center;
}

.materials-threshold-input small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
}

.materials-month-control {
  gap: 4px;
  margin-left: auto;
  padding-top: 15px;
}

.materials-month-control input {
  min-height: 38px;
  width: 160px;
  padding: 0 9px;
  color: var(--ink);
  font-size: 14px;
}

.materials-page .icon-button {
  display: inline-grid;
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
  place-items: center;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #fff;
  color: var(--green-dark);
  font-size: 21px;
  line-height: 1;
}

.materials-page .icon-button:hover,
.materials-page .icon-button:focus-visible {
  border-color: var(--green);
  background: #edf7f2;
  outline: 2px solid rgba(13, 124, 102, 0.17);
  outline-offset: 1px;
}

.materials-source-note {
  margin: 11px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.materials-demo-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: 14px;
  padding: 11px 13px;
  border: 1px solid #e9d7a2;
  border-radius: 5px;
  background: #fff9e9;
}

.materials-demo-banner[hidden] {
  display: none;
}

.materials-demo-copy {
  display: flex;
  align-items: center;
  gap: 11px;
  min-width: 0;
}

.materials-demo-tag {
  flex: 0 0 auto;
  padding: 4px 7px;
  border-radius: 3px;
  background: #f4e7c1;
  color: #765719;
  font-size: 11px;
  font-weight: 800;
}

.materials-demo-copy p {
  display: grid;
  gap: 3px;
  min-width: 0;
  margin: 0;
  color: #655d49;
  font-size: 13px;
  line-height: 1.45;
}

.materials-demo-copy strong {
  color: #43391f;
  font-size: 13px;
}

.materials-demo-copy p span {
  overflow-wrap: anywhere;
}

.materials-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(130px, 1fr));
  margin: 16px 0 6px;
  border-top: 1px solid #cbd7d1;
  border-bottom: 1px solid #cbd7d1;
  background: rgba(255, 255, 255, 0.65);
}

.materials-stat {
  min-width: 0;
  padding: 12px 16px;
  border-right: 1px solid #dce4df;
}

.materials-stat:last-child {
  border-right: 0;
}

.materials-stat > span {
  display: block;
  overflow: hidden;
  color: var(--muted);
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.materials-stat strong {
  display: block;
  margin-top: 3px;
  color: var(--ink);
  font-size: 25px;
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
}

.materials-stat strong small {
  margin-left: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.materials-status {
  min-height: 22px;
  margin: 9px 0;
  color: var(--muted);
  font-size: 13px;
}

.materials-table-section {
  border: 1px solid #d4ddd8;
  border-radius: 6px;
  background: #fff;
}

.materials-table-scroll {
  max-width: 100%;
  overflow: auto;
  scrollbar-gutter: stable;
}

.materials-table {
  width: max-content;
  min-width: 100%;
  table-layout: fixed;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 15px;
  font-variant-numeric: tabular-nums;
}

.materials-table th,
.materials-table td {
  height: 86px;
  padding: 6px 8px;
  border-right: 1px solid #edf0ee;
  border-bottom: 1px solid #e5eae7;
  text-align: center;
  vertical-align: middle;
  line-height: 1.25;
  font-size: 16px;
  white-space: nowrap;
}

.materials-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  height: 42px;
  background: #edf2ef;
  color: #5c6e66;
  font-size: 13px;
  font-weight: 750;
}

.materials-table thead th.materials-product-head {
  z-index: 4;
}

.materials-product-head,
.materials-product-cell {
  position: sticky;
  left: 0;
  width: 300px;
  min-width: 300px;
  max-width: 300px;
  text-align: left !important;
}

.materials-product-cell {
  z-index: 1;
  background: #fff;
}

.materials-product {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
}

.materials-product-image {
  display: grid;
  width: 72px;
  height: 72px;
  flex: 0 0 72px;
  overflow: hidden;
  place-items: center;
  border: 1px solid #e0e7e3;
  border-radius: 4px;
  background: #f5f7f6;
}

.materials-product-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.materials-no-image {
  color: #8a9691;
  font-size: 11px;
  font-weight: 500;
}

.materials-product-copy {
  display: grid;
  min-width: 0;
  gap: 0;
  align-content: center;
}

.materials-product-copy strong {
  overflow: hidden;
  color: var(--ink);
  font-size: 18px;
  font-weight: 750;
  text-overflow: ellipsis;
  line-height: 1.25;
}

.materials-product-name {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.materials-product-name strong {
  flex: 0 1 auto;
  min-width: 0;
}

.materials-pinned-badge {
  flex: 0 0 auto;
  padding: 3px 6px;
  border: 1px solid #d2e3e5;
  border-radius: 3px;
  background: #edf5f5;
  color: #426d72;
  font-size: 11px;
  font-weight: 750;
  line-height: 1.2;
  white-space: nowrap;
}

.materials-ad-head,
.materials-ad-cell {
  width: 150px;
  min-width: 150px;
}

.materials-count-head,
.materials-count-cell {
  width: 126px;
  min-width: 126px;
}

.materials-inventory-head,
.materials-inventory-cell {
  width: 166px;
  min-width: 166px;
}

.materials-ad-cell select {
  width: 132px;
  padding: 0 8px;
  font-size: 14px;
}

.materials-ad-display,
.materials-count-display {
  display: grid;
  min-height: 48px;
  place-items: center;
  color: var(--ink);
  line-height: 1.2;
}

.materials-ad-display {
  font-size: 16px;
  font-weight: 650;
}

.materials-count-display {
  font-size: 19px;
  font-weight: 800;
}

.materials-ad-display.is-editable,
.materials-count-display.is-editable,
.materials-inventory-value.is-editable {
  cursor: cell;
}

.materials-ad-display.is-editable:hover,
.materials-count-display.is-editable:hover,
.materials-inventory-value.is-editable:hover {
  color: var(--green-dark);
}

.materials-ad-display:focus-visible,
.materials-count-display:focus-visible,
.materials-inventory-value.is-editable:focus-visible {
  outline: 2px solid rgba(13, 124, 102, 0.28);
  outline-offset: -3px;
}

.materials-inline-editor {
  display: block;
  width: min(100%, 120px);
  box-sizing: border-box;
  min-height: 38px;
  margin: 0 auto;
  padding: 0 7px;
  border: 1px solid #7daf93;
  border-radius: 4px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

.materials-ad-cell .materials-inline-editor {
  width: min(132px, 100%);
}

.materials-count-cell .materials-inline-editor {
  width: 82px;
  font-size: 16px;
}

.materials-inventory-cell .materials-inline-editor {
  width: 94px;
  font-size: 16px;
}

.materials-inline-editor:focus-visible {
  border-color: var(--green);
  outline: 2px solid rgba(13, 124, 102, 0.19);
  outline-offset: 1px;
}

.materials-inventory-value small {
  display: block;
  color: var(--muted);
  font-size: 13px;
  font-weight: 550;
  line-height: 1.2;
}

.materials-inventory-value {
  display: inline-grid;
  min-width: 80px;
  min-height: 48px;
  align-content: center;
  justify-items: center;
  gap: 3px;
  color: var(--ink);
  line-height: 1.15;
}

.materials-inventory-value strong {
  color: var(--green-dark);
  font-size: 19px;
  font-weight: 800;
}

.materials-inventory-state {
  color: #7a8680;
  font-size: 14px;
}

.materials-inventory-state.loading {
  color: #60766b;
}

.materials-inventory-state.error {
  color: var(--red);
}

.materials-day-head,
.materials-day-cell {
  width: 44px;
  min-width: 44px;
  max-width: 44px;
  padding-inline: 3px !important;
}

.materials-day-head span {
  color: #52665d;
  font-size: 15px;
}

.materials-day-head.is-today {
  height: 46px;
  background: #eaf4ee;
  color: #176347;
  box-shadow: inset 1px 0 #d4e8db, inset -1px 0 #d4e8db, inset 0 -2px #b9d8c5;
}

.materials-day-head.is-today span {
  color: #176347;
  font-weight: 800;
}

.materials-today-label {
  display: block;
  margin-top: 2px;
  color: #35785a;
  font-size: 9px;
  font-weight: 700;
  line-height: 1;
}

.materials-day-cell {
  color: #a7b0ac;
  font-size: 16px;
  cursor: cell;
  transition: background-color 140ms ease, color 140ms ease;
}

.materials-day-cell.has-addition {
  background: #e5f3ec;
  color: #087154;
  font-weight: 800;
}

.materials-day-cell.is-today {
  background: #f5faf6;
  box-shadow: inset 1px 0 #e4f0e8, inset -1px 0 #e4f0e8;
}

.materials-day-cell.is-today.has-addition {
  background: #e2f1e7;
  color: #155f42;
}

.materials-day-cell:hover {
  background: #edf6f0;
  color: #176347;
}

.materials-day-cell:focus-visible {
  position: relative;
  z-index: 1;
  outline: 2px solid #4f9870;
  outline-offset: -2px;
}

.materials-day-cell.is-editing {
  background: #f1f7f3;
}

.materials-ad-cell.is-editing,
.materials-count-cell.is-editing,
.materials-inventory-cell.is-editing {
  background: #f5faf6;
}

.materials-day-editor {
  display: block;
  width: 100%;
  box-sizing: border-box;
  min-width: 0;
  min-height: 34px;
  margin: 0 auto;
  padding: 0 2px;
  border: 1px solid #82b798;
  border-radius: 4px;
  background: #fff;
  color: var(--ink);
  font-size: 15px;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

.materials-day-editor:focus-visible {
  outline: 2px solid rgba(61, 133, 90, 0.22);
  outline-offset: 1px;
}

.materials-day-editor:disabled {
  opacity: 0.65;
}

.materials-table tbody tr:last-child > * {
  border-bottom: 0;
}

.materials-table tr > *:last-child {
  border-right: 0;
}

.materials-table-message {
  height: 88px !important;
  color: var(--muted);
  text-align: center !important;
}

.materials-count-cell.is-low-materials {
  background: #fff8ea;
}

.materials-count-cell.is-low-materials .materials-count-display {
  color: #825e24;
}

.materials-inventory-cell.is-high-inventory {
  background: #eaf5ee;
}

.materials-inventory-cell.is-high-inventory .materials-inventory-value strong {
  color: #216b4d;
}

.materials-table tbody tr.is-pinned > .materials-product-cell {
  box-shadow: inset 3px 0 #76a98b;
}

.materials-table tbody tr[data-product-row]:focus-visible > .materials-product-cell {
  outline: 2px solid rgba(13, 124, 102, 0.46);
  outline-offset: -2px;
}

.materials-context-menu {
  position: fixed;
  z-index: 30;
  display: grid;
  min-width: 154px;
  padding: 4px;
  border: 1px solid #cfd9d3;
  border-radius: 5px;
  background: #fff;
  box-shadow: 0 8px 24px rgba(22, 45, 35, 0.16);
}

.materials-context-menu[hidden] {
  display: none;
}

.materials-context-menu button {
  min-height: 38px;
  padding: 0 11px;
  border: 0;
  border-radius: 3px;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 15px;
  text-align: left;
  cursor: pointer;
}

.materials-context-menu button:hover,
.materials-context-menu button:focus-visible {
  outline: 0;
  background: #edf5f0;
  color: #176347;
}

@media (max-width: 820px) {
  .materials-controls-title {
    align-items: flex-start;
    flex-direction: column;
  }

  .materials-month-control {
    margin-left: 0;
  }

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

  .materials-stat:nth-child(2) {
    border-right: 0;
  }

  .materials-stat:nth-child(-n + 2) {
    border-bottom: 1px solid #dce4df;
  }
}


@media (max-width: 520px) {
  .materials-main {
    padding-inline: 10px;
  }

  .materials-page .primary-button,
  .materials-page .ghost-button {
    min-height: 44px;
  }

  .materials-actions,
  .materials-actions > button {
    width: 100%;
  }

  .materials-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .materials-filter-row {
    align-items: flex-end;
    gap: 10px;
  }

  .materials-search {
    width: 100%;
  }

  .materials-search input {
    width: 100%;
  }

  .materials-month-control {
    padding-top: 0;
  }

  .materials-demo-banner {
    align-items: stretch;
    flex-direction: column;
  }

  .materials-demo-copy {
    align-items: flex-start;
  }

  .materials-demo-banner > button {
    width: 100%;
  }
}
