:root {
  --ink: #2a2520;
  --muted: #756c63;
  --line: #e7ded4;
  --paper: #fffaf3;
  --soft: #f4eadf;
  --brand: #8b4b2f;
  --brand-dark: #60331f;
  --ok: #1f7a5c;
  --danger: #b64034;
  --shadow: 0 18px 50px rgba(67, 43, 27, 0.12);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  color: var(--ink);
  background: var(--paper);
}
button, input, select, textarea { font: inherit; }
button {
  border: 0;
  border-radius: 8px;
  padding: 10px 14px;
  cursor: pointer;
  transition: transform .16s ease, box-shadow .16s ease, background .16s ease;
}
button:hover { transform: translateY(-1px); box-shadow: 0 8px 20px rgba(96, 51, 31, .15); }
button:disabled { opacity: .6; cursor: wait; transform: none; }
.primary { background: var(--brand); color: white; }
.secondary { background: var(--soft); color: var(--brand-dark); }
.ghost { background: transparent; color: var(--brand-dark); border: 1px solid var(--line); }
.danger { background: var(--danger); color: white; }
.hidden { display: none !important; }
.eyebrow { margin: 0 0 8px; color: var(--brand); font-size: 13px; letter-spacing: 0; }
.subtitle, .muted, .hint { color: var(--muted); }

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(rgba(255,250,243,.76), rgba(255,250,243,.9)),
    url("https://images.unsplash.com/photo-1556911220-bff31c812dba?auto=format&fit=crop&w=1800&q=80") center/cover;
}
.login-panel {
  width: min(440px, 100%);
  padding: 34px;
  background: rgba(255, 250, 243, .92);
  border: 1px solid rgba(231, 222, 212, .9);
  border-radius: 8px;
  box-shadow: var(--shadow);
}
.login-panel h1 { margin: 0; font-size: 38px; }
.form-grid, .card-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}
.form-grid { grid-template-columns: 1fr; margin-top: 28px; }
label { display: grid; gap: 6px; color: var(--muted); font-size: 14px; }
.field-hint {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}
input, select, textarea {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 11px;
  color: var(--ink);
  background: #fff;
}
input.locked-field,
select.locked-field,
input:read-only.locked-field,
select:disabled.locked-field {
  color: var(--muted);
  background: #f8f1e9;
  opacity: 1;
  cursor: not-allowed;
}
textarea { min-height: 88px; resize: vertical; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 260px 1fr; }
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 24px;
  background: #fff6eb;
  border-right: 1px solid var(--line);
}
.sidebar h2 { margin: 0; font-size: 26px; }
nav { display: grid; gap: 8px; }
nav button { text-align: left; background: transparent; color: var(--ink); border: 1px solid transparent; }
nav button.active { background: #fff; border-color: var(--line); color: var(--brand-dark); }
.workspace { padding: 28px; min-width: 0; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 18px; margin-bottom: 26px; }
.topbar h1 { margin: 2px 0 0; font-size: 30px; }
.user-badge { background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; color: var(--muted); }
.metric-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.metric, .card-form, .list, .table-list {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 10px 30px rgba(67, 43, 27, .06);
}
.metric { padding: 18px; display: grid; gap: 8px; }
.metric span { color: var(--muted); }
.metric strong { font-size: 28px; }
.section-head, .toolbar, .actions {
  display: flex;
  align-items: center;
  gap: 12px;
  justify-content: space-between;
  margin: 24px 0 12px;
}
.toolbar { flex-wrap: wrap; justify-content: flex-start; }
.toolbar input, .toolbar select { width: auto; min-width: 160px; }
.check { display: flex; grid-template-columns: auto 1fr; align-items: center; gap: 8px; }
.check input { width: auto; min-height: auto; }
.card-form { padding: 22px; max-width: 900px; }
.card-form h2 { grid-column: 1 / -1; margin: 0 0 4px; }
.card-form button, .wide { grid-column: 1 / -1; }
.inline-form {
  display: grid;
  grid-template-columns: repeat(5, minmax(120px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}
.list, .table-list { overflow: hidden; }
.empty { padding: 24px; color: var(--muted); }
.row {
  display: grid;
  grid-template-columns: 1.4fr .8fr .8fr .8fr 1fr;
  gap: 10px;
  align-items: center;
  padding: 13px 16px;
  border-bottom: 1px solid var(--line);
}
.stock-row {
  display: grid;
  grid-template-columns: 1.2fr .75fr .75fr .75fr 130px .55fr .65fr .7fr .65fr auto;
  gap: 10px;
  align-items: center;
  padding: 13px 16px;
  border-bottom: 1px solid var(--line);
}
.stock-row:last-child { border-bottom: 0; }
.stock-row input { min-height: 36px; }
.status-ok { background: #f0faf5; }
.status-diff { background: #fff1ee; color: #7b261e; }
.row:last-child { border-bottom: 0; }
.row.low { background: #fff1ee; color: #7b261e; }
.row .actions { margin: 0; justify-content: flex-end; }
.inventory-title {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.inventory-id {
  flex: 0 0 auto;
  min-width: 42px;
  padding: 4px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  background: rgba(244, 234, 223, .7);
  font-size: 12px;
  font-weight: 600;
  text-align: center;
}
.inventory-name {
  color: var(--ink);
  font-size: 16px;
  font-weight: 700;
  overflow-wrap: anywhere;
}
.inventory-row.low .inventory-id {
  border-color: rgba(182, 64, 52, .24);
  color: #7b261e;
  background: rgba(255, 250, 243, .85);
}
.record-row {
  display: grid;
  grid-template-columns: minmax(180px, 1.2fr) minmax(280px, 2fr) auto auto;
  gap: 14px;
  align-items: center;
  padding: 16px;
  border-bottom: 1px solid var(--line);
  background: #fff;
}
.record-row:last-child { border-bottom: 0; }
.record-row:nth-child(even) { background: #fffdf9; }
.record-main {
  display: grid;
  gap: 5px;
  min-width: 0;
}
.record-main strong {
  color: var(--ink);
  overflow-wrap: anywhere;
}
.record-main span {
  color: var(--muted);
  font-size: 13px;
}
.record-meta {
  display: grid;
  grid-template-columns: repeat(4, minmax(92px, 1fr));
  gap: 10px;
}
.inbound-record .record-meta {
  grid-template-columns: repeat(5, minmax(86px, 1fr));
}
.record-meta span {
  display: grid;
  gap: 3px;
  min-width: 0;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(250, 247, 239, .72);
  color: var(--ink);
  overflow-wrap: anywhere;
}
.record-meta em {
  color: var(--muted);
  font-size: 12px;
  font-style: normal;
}
.record-row .actions { margin: 0; justify-content: flex-end; }
.pill { display: inline-flex; align-items: center; width: fit-content; min-height: 26px; border-radius: 999px; padding: 4px 9px; background: var(--soft); color: var(--brand-dark); font-size: 12px; }
#toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  max-width: 360px;
  padding: 12px 14px;
  color: white;
  background: var(--brand-dark);
  border-radius: 8px;
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity .16s ease, transform .16s ease;
}
#toast.show { opacity: 1; transform: translateY(0); }
dialog { border: 0; border-radius: 8px; box-shadow: var(--shadow); }
.dialog-form { min-width: min(420px, 80vw); display: grid; gap: 14px; padding: 10px; }

@media (max-width: 860px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  nav { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .workspace { padding: 18px; }
  .topbar, .section-head { align-items: flex-start; flex-direction: column; }
  .metric-grid, .form-grid, .card-form, .inline-form { grid-template-columns: 1fr; }
  .row { grid-template-columns: 1fr; }
  .inventory-title { align-items: flex-start; }
  .record-row { grid-template-columns: 1fr; }
  .record-meta, .inbound-record .record-meta { grid-template-columns: 1fr; }
  .stock-row { grid-template-columns: 1fr; }
  .toolbar input, .toolbar select, .toolbar button { width: 100%; }
}
