:root {
  color-scheme: light;
  --ink: #1d2926;
  --muted: #65716c;
  --paper: #f1efe8;
  --card: #fffdf8;
  --card-strong: #ffffff;
  --line: #d7dcd7;
  --line-strong: #bcc7c0;
  --green: #174f40;
  --green-deep: #103c31;
  --green-soft: #dcebe4;
  --amber: #995d10;
  --amber-soft: #fff3dc;
  --red: #9a3835;
  --red-soft: #fbe9e7;
  --shadow: 0 18px 45px rgba(24, 49, 41, 0.08);
  --radius: 18px;
  --font: "Microsoft YaHei", "PingFang SC", "Noto Sans CJK SC", Arial, sans-serif;
  --mono: "Cascadia Mono", "Consolas", "SFMono-Regular", monospace;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  min-width: 320px;
  background: var(--paper);
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 8% 4%, rgba(23, 79, 64, 0.08), transparent 25rem),
    radial-gradient(circle at 94% 18%, rgba(184, 132, 55, 0.09), transparent 23rem),
    var(--paper);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
}

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

button,
a {
  -webkit-tap-highlight-color: transparent;
}

button {
  color: inherit;
}

a {
  color: inherit;
}

.login-screen {
  display: grid;
  min-height: 100vh;
  padding: 24px;
  place-items: center;
}

.login-card {
  width: min(100%, 430px);
  padding: 34px;
  border: 1px solid rgba(188, 199, 192, 0.85);
  border-radius: 22px;
  background: var(--card-strong);
  box-shadow: var(--shadow);
}

.login-brand {
  width: 58px;
  height: 58px;
  margin-bottom: 24px;
  border-radius: 17px;
}

.login-brand svg {
  width: 37px;
  height: 37px;
}

.login-card h1 {
  margin: 0;
  font-size: 27px;
  letter-spacing: -0.025em;
}

.login-copy {
  margin: 10px 0 24px;
  color: var(--muted);
  font-size: 13px;
}

.login-form {
  display: grid;
  gap: 14px;
}

.login-submit {
  width: 100%;
  margin-top: 4px;
}

.login-note {
  margin: 18px 0 0;
  color: #84908a;
  font-size: 11px;
  text-align: center;
}

.page-shell {
  width: min(100%, 1380px);
  margin: 0 auto;
  padding: 36px 34px 28px;
}

.masthead {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 32px;
  padding: 10px 2px 28px;
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 20px;
}

.brand-mark {
  display: grid;
  flex: 0 0 auto;
  width: 68px;
  height: 68px;
  place-items: center;
  border-radius: 20px;
  background: var(--green);
  box-shadow: 0 13px 30px rgba(23, 79, 64, 0.22);
}

.brand-mark svg {
  width: 43px;
  height: 43px;
  fill: none;
  stroke: #f8f4ea;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2.25;
}

.brand-mark circle {
  fill: #f8f4ea;
  stroke: none;
}

.eyebrow,
.section-kicker {
  margin: 0 0 4px;
  color: var(--green);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.13em;
}

.masthead h1 {
  margin: 0;
  font-size: clamp(26px, 3.4vw, 42px);
  font-weight: 750;
  letter-spacing: -0.035em;
  line-height: 1.15;
}

.lede {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.header-actions,
.footer-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.button {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 10px 17px;
  border: 1px solid transparent;
  border-radius: 11px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 650;
  line-height: 1.2;
  text-decoration: none;
  transition:
    background-color 160ms ease,
    border-color 160ms ease,
    box-shadow 160ms ease,
    transform 160ms ease;
}

.button:hover {
  transform: translateY(-1px);
}

.button:active {
  transform: translateY(0);
}

.button-primary {
  background: var(--green);
  color: #fffdf8;
  box-shadow: 0 9px 20px rgba(23, 79, 64, 0.17);
}

.button-primary:hover {
  background: var(--green-deep);
}

.button-secondary {
  border-color: var(--line-strong);
  background: var(--card);
  color: var(--ink);
}

.button-secondary:hover {
  border-color: var(--green);
  background: #fff;
}

.button-quiet {
  border-color: transparent;
  background: transparent;
  color: var(--muted);
}

.button-quiet:hover {
  background: rgba(255, 255, 255, 0.6);
  color: var(--ink);
}

.button-danger {
  background: var(--red);
  color: #fff;
}

.button-danger:hover {
  background: #7e2c29;
}

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

.metric {
  position: relative;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: end;
  gap: 2px 16px;
  overflow: hidden;
  padding: 20px 22px;
  border: 1px solid rgba(188, 199, 192, 0.7);
  border-radius: 15px;
  background: rgba(255, 253, 248, 0.8);
}

.metric::before {
  position: absolute;
  inset: 0 auto 0 0;
  width: 4px;
  background: var(--green);
  content: "";
  opacity: 0.78;
}

.metric-label {
  grid-column: 1;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

.metric strong {
  grid-row: 1 / span 2;
  grid-column: 2;
  color: var(--green-deep);
  font-size: 32px;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.metric-note {
  grid-column: 1;
  color: #84908a;
  font-size: 12px;
}

.inventory-panel {
  overflow: hidden;
  border: 1px solid rgba(188, 199, 192, 0.8);
  border-radius: var(--radius);
  background: var(--card-strong);
  box-shadow: var(--shadow);
}

.panel-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  padding: 23px 24px 17px;
}

.panel-heading h2,
.dialog-heading h2 {
  margin: 0;
  font-size: 21px;
  letter-spacing: -0.02em;
}

.result-count {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.toolbar {
  display: grid;
  grid-template-columns: minmax(290px, 1fr) minmax(150px, 0.35fr) minmax(160px, 0.38fr) auto;
  align-items: end;
  gap: 11px;
  padding: 0 24px 18px;
}

.search-field {
  display: flex;
  height: 46px;
  align-items: center;
  gap: 10px;
  padding: 0 13px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: #f8f8f4;
  transition:
    border-color 160ms ease,
    box-shadow 160ms ease,
    background-color 160ms ease;
}

.search-field:focus-within {
  border-color: var(--green);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(23, 79, 64, 0.1);
}

.search-field svg {
  width: 19px;
  height: 19px;
  flex: 0 0 auto;
  fill: none;
  stroke: #73807a;
  stroke-linecap: round;
  stroke-width: 1.8;
}

.search-field input {
  min-width: 0;
  flex: 1;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
}

.search-field input::placeholder {
  color: #929b96;
}

.search-field kbd {
  flex: 0 0 auto;
  min-width: 22px;
  padding: 1px 6px;
  border: 1px solid #d2d8d3;
  border-bottom-width: 2px;
  border-radius: 5px;
  background: #fff;
  color: #7f8983;
  font-family: var(--mono);
  font-size: 11px;
  text-align: center;
}

.filter-control {
  display: grid;
  gap: 5px;
}

.filter-control > span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0.03em;
}

.filter-control select {
  width: 100%;
  height: 46px;
  padding: 0 34px 0 12px;
  border: 1px solid var(--line);
  border-radius: 11px;
  outline: 0;
  background: #f8f8f4;
  color: var(--ink);
  cursor: pointer;
}

.filter-control select:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(23, 79, 64, 0.1);
}

.text-button {
  width: fit-content;
  padding: 7px 3px;
  border: 0;
  background: transparent;
  color: var(--green);
  cursor: pointer;
  font-size: 13px;
  font-weight: 650;
  text-decoration: underline;
  text-decoration-color: transparent;
  text-underline-offset: 4px;
}

.text-button:hover {
  text-decoration-color: currentColor;
}

.text-button-danger {
  color: #8b4a46;
}

.table-wrap {
  max-height: min(62vh, 720px);
  overflow: auto;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  scrollbar-color: #aebbb4 transparent;
  scrollbar-width: thin;
}

table {
  width: 100%;
  min-width: 940px;
  border-collapse: separate;
  border-spacing: 0;
  table-layout: fixed;
}

thead {
  position: sticky;
  z-index: 3;
  top: 0;
  background: #e8ede9;
}

th,
td {
  padding: 13px 15px;
  border-bottom: 1px solid #e6eae6;
  text-align: left;
  vertical-align: middle;
}

th {
  color: #52605a;
  font-size: 11px;
  font-weight: 750;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

th:nth-child(1),
td:nth-child(1) {
  width: 72px;
  text-align: center;
}

th:nth-child(2),
td:nth-child(2) {
  width: 118px;
}

th:nth-child(3),
td:nth-child(3) {
  width: 29%;
}

th:nth-child(4),
td:nth-child(4) {
  width: 105px;
  text-align: center;
}

th:nth-child(5),
td:nth-child(5) {
  width: 145px;
}

th:nth-child(6),
td:nth-child(6) {
  width: 24%;
}

th:nth-child(7),
td:nth-child(7) {
  width: 92px;
  text-align: center;
}

tbody tr {
  background: #fff;
  transition: background-color 130ms ease;
}

tbody tr:nth-child(even) {
  background: #fbfcfa;
}

tbody tr:hover {
  background: #f1f7f3;
}

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

td {
  color: #2f3c37;
  font-size: 13.5px;
}

.serial {
  color: #8b9690;
  font-family: var(--mono);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.location-pill {
  display: inline-flex;
  max-width: 100%;
  align-items: center;
  padding: 4px 9px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--green-soft);
  color: var(--green-deep);
  font-size: 12px;
  font-weight: 650;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.name-cell {
  color: #1c2a26;
  font-weight: 650;
  overflow-wrap: anywhere;
}

.spec {
  color: #4a5752;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

.cas-code {
  font-family: var(--mono);
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.cas-code.is-missing {
  display: inline-flex;
  padding: 3px 8px;
  border-radius: 6px;
  background: var(--amber-soft);
  color: var(--amber);
  font-family: var(--font);
  font-size: 11px;
  font-weight: 700;
}

.note-cell {
  color: #6d7873;
  font-size: 12px;
  overflow-wrap: anywhere;
}

.note-cell.is-missing-note {
  color: #8e5511;
}

.row-actions {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
}

.edit-row,
.delete-row {
  display: inline-grid;
  width: 30px;
  height: 30px;
  place-items: center;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  cursor: pointer;
  line-height: 1;
  transition:
    color 130ms ease,
    background-color 130ms ease,
    border-color 130ms ease;
}

.edit-row {
  color: #547a6b;
}

.edit-row svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.edit-row:hover {
  border-color: #bfd9cd;
  background: #e8f3ed;
  color: var(--green);
}

.delete-row {
  color: #9a6b67;
  font-size: 20px;
}

.delete-row:hover {
  border-color: #efcfcc;
  background: var(--red-soft);
  color: var(--red);
}

.empty-state {
  padding: 56px 20px 62px;
  text-align: center;
}

.empty-icon {
  display: grid;
  width: 52px;
  height: 52px;
  margin: 0 auto 13px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: #f6f6f2;
  color: #71807a;
  font-size: 26px;
}

.empty-state h3 {
  margin: 0 0 5px;
  font-size: 17px;
}

.empty-state p {
  margin: 0 0 18px;
  color: var(--muted);
  font-size: 13px;
}

.panel-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 13px 24px;
  background: #f8f9f6;
}

.storage-note {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  color: #75817b;
  font-size: 12px;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #4c8d70;
  box-shadow: 0 0 0 4px rgba(76, 141, 112, 0.12);
}

.storage-note.is-error {
  color: var(--red);
}

.storage-note.is-error .status-dot {
  background: var(--red);
  box-shadow: 0 0 0 4px rgba(154, 56, 53, 0.12);
}

.page-footer {
  display: flex;
  justify-content: center;
  gap: 9px;
  padding: 22px 10px 0;
  color: #8a938f;
  font-size: 11px;
}

dialog {
  color: var(--ink);
}

.dialog {
  width: min(92vw, 610px);
  max-height: min(88vh, 760px);
  padding: 0;
  overflow: auto;
  border: 1px solid rgba(188, 199, 192, 0.85);
  border-radius: 19px;
  background: var(--card-strong);
  box-shadow: 0 28px 80px rgba(16, 42, 34, 0.24);
}

.dialog::backdrop {
  background: rgba(18, 27, 24, 0.48);
  backdrop-filter: blur(3px);
}

.dialog > form,
.dialog-compact {
  padding: 24px;
}

.dialog-compact {
  max-width: 470px;
}

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

.section-kicker-danger {
  color: var(--red);
}

.icon-button {
  display: grid;
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: transparent;
  color: #6e7974;
  cursor: pointer;
  font-size: 24px;
  line-height: 1;
}

.icon-button:hover {
  background: #f2f3ef;
  color: var(--ink);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 15px;
}

.field {
  display: grid;
  gap: 7px;
}

.field-wide {
  grid-column: 1 / -1;
}

.field > span {
  color: #43514b;
  font-size: 12px;
  font-weight: 700;
}

.field em {
  color: var(--red);
  font-size: 10px;
  font-style: normal;
}

.field small {
  color: #838d88;
  font-size: 11px;
}

.field input,
.field textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 9px;
  outline: 0;
  background: #fafaf7;
  color: var(--ink);
  transition:
    border-color 150ms ease,
    box-shadow 150ms ease,
    background-color 150ms ease;
}

.field input {
  height: 43px;
  padding: 0 12px;
}

.field textarea {
  min-height: 88px;
  padding: 10px 12px;
  resize: vertical;
}

.field input:focus,
.field textarea:focus {
  border-color: var(--green);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(23, 79, 64, 0.1);
}

.field input::placeholder,
.field textarea::placeholder {
  color: #a0a8a4;
}

.form-error {
  margin: 13px 0 0;
  padding: 9px 11px;
  border-radius: 8px;
  background: var(--red-soft);
  color: var(--red);
  font-size: 12px;
  font-weight: 650;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 24px;
}

.delete-copy {
  margin: -5px 0 4px;
  color: var(--muted);
  font-size: 13px;
}

.delete-copy strong {
  color: var(--ink);
}

.toast {
  position: fixed;
  z-index: 20;
  right: 24px;
  bottom: 24px;
  max-width: min(360px, calc(100vw - 48px));
  padding: 11px 16px;
  border: 1px solid rgba(23, 79, 64, 0.2);
  border-radius: 10px;
  background: var(--green-deep);
  box-shadow: 0 15px 35px rgba(16, 42, 34, 0.23);
  color: #fff;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transform: translateY(12px);
  transition:
    opacity 180ms ease,
    transform 180ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.noscript-message {
  position: fixed;
  inset: 20px;
  z-index: 30;
  display: grid;
  place-items: center;
  border-radius: 16px;
  background: var(--card);
  color: var(--red);
  font-weight: 700;
}

.visually-hidden {
  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;
}

@media (max-width: 900px) {
  .page-shell {
    padding: 24px 18px 20px;
  }

  .masthead {
    align-items: flex-start;
    flex-direction: column;
    gap: 22px;
  }

  .header-actions {
    width: 100%;
  }

  .header-actions .button {
    flex: 1;
  }

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

  .metric {
    grid-template-columns: 1fr auto;
  }

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

  .search-field {
    grid-column: 1 / -1;
  }

  .toolbar > .text-button {
    justify-self: end;
  }

  .panel-footer {
    align-items: flex-start;
    flex-direction: column;
  }
}

@media (max-width: 680px) {
  .page-shell {
    padding: 18px 12px 16px;
  }

  .brand-block {
    align-items: flex-start;
    gap: 13px;
  }

  .brand-mark {
    width: 52px;
    height: 52px;
    border-radius: 15px;
  }

  .brand-mark svg {
    width: 34px;
    height: 34px;
  }

  .lede {
    font-size: 12px;
  }

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

  .metrics {
    grid-template-columns: 1fr 1fr 1fr;
    gap: 8px;
  }

  .metric {
    display: block;
    min-width: 0;
    padding: 14px 12px 13px 15px;
    border-radius: 12px;
  }

  .metric-label,
  .metric-note {
    display: block;
  }

  .metric strong {
    display: block;
    margin: 7px 0 2px;
    font-size: 25px;
  }

  .metric-note {
    overflow: hidden;
    font-size: 10px;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .panel-heading {
    align-items: flex-start;
    flex-direction: column;
    gap: 8px;
    padding: 19px 16px 14px;
  }

  .toolbar {
    grid-template-columns: 1fr 1fr;
    padding: 0 16px 15px;
  }

  .filter-control:nth-of-type(3) {
    grid-column: 1;
  }

  .toolbar > .text-button {
    grid-column: 2;
  }

  .table-wrap {
    max-height: none;
    overflow: visible;
    border-top: 1px solid var(--line);
  }

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

  table {
    min-width: 0;
  }

  thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
  }

  tbody {
    display: grid;
    gap: 10px;
    padding: 12px;
    background: #f5f5f0;
  }

  tbody tr,
  tbody tr:nth-child(even) {
    position: relative;
    display: grid;
    grid-template-columns: 1fr 1fr;
    overflow: hidden;
    padding: 12px 76px 12px 13px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: #fff;
  }

  tbody tr:hover {
    background: #fff;
  }

  tbody td,
  tbody td:nth-child(n) {
    width: auto;
    padding: 5px 0;
    border: 0;
    text-align: left;
  }

  tbody td::before {
    display: block;
    margin-bottom: 2px;
    color: #8b9690;
    content: attr(data-label);
    font-size: 9px;
    font-weight: 700;
    letter-spacing: 0.04em;
  }

  tbody td:nth-child(1),
  tbody td:nth-child(2) {
    display: inline-block;
    width: 50%;
    padding-bottom: 7px;
  }

  tbody td:nth-child(1)::before,
  tbody td:nth-child(2)::before {
    display: none;
  }

  tbody td:nth-child(3),
  tbody td:nth-child(6) {
    grid-column: 1 / -1;
  }

  tbody td:nth-child(3) {
    padding-top: 7px;
  }

  tbody td:nth-child(3)::before,
  tbody td:nth-child(7)::before {
    display: none;
  }

  tbody td:nth-child(3) {
    font-size: 15px;
  }

  tbody td:nth-child(4) {
    grid-column: 1;
  }

  tbody td:nth-child(5) {
    grid-column: 2;
  }

  tbody td:nth-child(7) {
    position: absolute;
    top: 8px;
    right: 7px;
    width: auto;
    padding: 0;
  }

  .edit-row,
  .delete-row {
    width: 32px;
    height: 32px;
  }

  .empty-state {
    border-top: 1px solid var(--line);
  }

  .panel-footer {
    padding: 14px 16px;
  }

  .footer-actions {
    width: 100%;
    justify-content: space-between;
  }

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

  .field-wide {
    grid-column: auto;
  }

  .dialog > form,
  .dialog-compact {
    padding: 19px;
  }

  .dialog-actions .button {
    flex: 1;
  }

  .toast {
    right: 14px;
    bottom: 14px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}

@media print {
  body {
    background: #fff;
  }

  .page-shell {
    width: 100%;
    padding: 0;
  }

  .header-actions,
  .toolbar,
  .panel-footer,
  .page-footer,
  th:nth-child(7),
  td:nth-child(7),
  .toast {
    display: none !important;
  }

  .inventory-panel {
    border: 0;
    box-shadow: none;
  }

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

  table {
    min-width: 0;
  }

  thead {
    position: table-header-group;
  }

  tbody tr {
    break-inside: avoid;
  }
}
