:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-soft: #eef3f2;
  --text: #172026;
  --muted: #64727d;
  --border: #d5dde3;
  --primary: #166a8f;
  --primary-dark: #10506d;
  --success: #25836d;
  --warning: #b86f18;
  --danger: #b74335;
  --focus: #7ab7d1;
  --shadow: 0 8px 24px rgba(25, 39, 52, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Arial, "Microsoft YaHei", sans-serif;
  font-size: 14px;
  line-height: 1.45;
}

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

input,
select,
textarea {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  padding: 8px 10px;
  outline: none;
}

textarea {
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(122, 183, 209, 0.28);
}

a {
  color: inherit;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 76px;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(10px);
}

.app-header h1 {
  margin: 0;
  font-size: 22px;
  line-height: 1.2;
}

.app-header p {
  margin: 4px 0 0;
  color: var(--muted);
}

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

.sync-pill {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 5px 10px;
  border-radius: 999px;
  background: #e8f3ed;
  color: #1f6b55;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.sync-pill.offline {
  background: #f8e8e3;
  color: #9b3f31;
}

.user-pill {
  background: #edf2f5;
  color: #40505d;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 38px;
  border: 0;
  border-radius: 6px;
  padding: 8px 13px;
  color: #fff;
  background: var(--primary);
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}

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

.button.secondary {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
}

.button.secondary:hover {
  border-color: #aebbc5;
  background: #f8fafb;
}

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

.button.danger {
  background: var(--danger);
}

.button.danger:hover {
  background: #96382d;
}

.button.small {
  min-height: 32px;
  padding: 6px 10px;
  font-size: 12px;
}

.button.full {
  width: 100%;
}

.button.disabled,
.button:disabled {
  opacity: 0.5;
  pointer-events: none;
}

.disabled-panel {
  opacity: 0.55;
  pointer-events: none;
}

.app-shell {
  display: grid;
  min-height: calc(100vh - 76px);
}

.office-shell {
  grid-template-columns: minmax(300px, 360px) minmax(0, 1fr);
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 18px;
  border-right: 1px solid var(--border);
  background: var(--surface-soft);
}

.main-content {
  min-width: 0;
  padding: 18px 22px 28px;
}

.tool-panel {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 16px;
}

.tool-panel h2,
.inventory-toolbar h2 {
  margin: 0 0 12px;
  font-size: 17px;
  line-height: 1.25;
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.panel-heading h2 {
  margin: 0;
}

.stack {
  display: grid;
  gap: 11px;
}

.compact-form {
  margin-top: 10px;
  gap: 8px;
}

label span {
  display: block;
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.inline-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
}

.selected-panel .inline-form {
  margin: 12px 0 8px;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(130px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.metric-card {
  min-height: 82px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  padding: 13px 14px;
}

.metric-card span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.metric-card strong {
  display: block;
  margin-top: 8px;
  font-size: 28px;
  line-height: 1;
}

.inventory-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 10px;
}

.inventory-toolbar h2 {
  margin-bottom: 2px;
}

.inventory-toolbar p {
  margin: 0;
  color: var(--muted);
}

.toolbar-controls {
  display: flex;
  gap: 8px;
  width: min(540px, 100%);
}

.search-input {
  min-width: 220px;
}

.toolbar-controls select {
  width: 118px;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 850px;
}

th,
td {
  border-bottom: 1px solid var(--border);
  padding: 11px 12px;
  text-align: left;
  vertical-align: middle;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #edf2f5;
  color: #40505d;
  font-size: 12px;
  font-weight: 800;
}

tbody tr {
  cursor: pointer;
}

tbody tr:hover,
tbody tr.selected-row {
  background: #edf7f5;
}

.mono {
  font-family: "Cascadia Mono", Consolas, monospace;
}

.muted {
  color: var(--muted);
}

.row-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 4px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.status-badge.in_stock {
  background: #e6f5ee;
  color: #1f755e;
}

.status-badge.pending_inspection {
  background: #fff2d8;
  color: #8a5a12;
}

.status-badge.inspection_failed {
  background: #f8e8e3;
  color: #9b3f31;
}

.status-badge.outbound {
  background: #e8edf2;
  color: #4b5d6b;
}

.status-badge.voided {
  background: #f8e8e3;
  color: #9b3f31;
}

.subtle-code {
  display: inline-block;
  max-width: 230px;
  overflow: hidden;
  color: var(--muted);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.detail-grid {
  display: grid;
  grid-template-columns: minmax(280px, 390px) minmax(0, 1fr);
  gap: 14px;
  margin-top: 16px;
}

.label-preview {
  display: grid;
  grid-template-columns: 138px minmax(0, 1fr);
  gap: 14px;
  align-items: center;
}

.label-preview img {
  width: 138px;
  height: 138px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
}

.fact-list {
  display: grid;
  grid-template-columns: 56px minmax(0, 1fr);
  gap: 7px 10px;
  margin: 0;
}

.fact-list dt {
  color: var(--muted);
  font-weight: 700;
}

.fact-list dd {
  margin: 0;
  min-width: 0;
  font-weight: 800;
  word-break: break-word;
}

.large-facts {
  grid-template-columns: 72px minmax(0, 1fr);
  margin-bottom: 16px;
  font-size: 16px;
}

.activity-panel {
  min-height: 250px;
}

.activity-list {
  display: grid;
  gap: 8px;
  max-height: 320px;
  margin: 0;
  padding: 0;
  overflow: auto;
  list-style: none;
}

.activity-list li {
  display: grid;
  grid-template-columns: 92px minmax(0, 1fr);
  gap: 10px;
  border-bottom: 1px solid #edf1f4;
  padding: 8px 0;
}

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

.users-list {
  display: grid;
  gap: 8px;
  margin: 12px 0 0;
  padding: 0;
  list-style: none;
}

.users-list li {
  display: grid;
  gap: 8px;
  border-top: 1px solid var(--border);
  padding-top: 10px;
}

.users-list strong,
.users-list span {
  display: block;
}

.users-list span {
  color: var(--muted);
  font-size: 12px;
}

.activity-list.compact {
  max-height: 240px;
}

.activity-time {
  color: var(--muted);
  font-size: 12px;
}

.activity-message {
  min-width: 0;
  font-weight: 700;
  word-break: break-word;
}

.activity-meta {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 400;
}

.empty-state {
  display: grid;
  place-items: center;
  min-height: 72px;
  border: 1px dashed #c8d2da;
  border-radius: 8px;
  color: var(--muted);
  background: #f8fafb;
  text-align: center;
  padding: 14px;
}

.hidden {
  display: none !important;
}

.login-modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(23, 32, 38, 0.58);
}

.login-card {
  width: min(420px, 100%);
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 22px 52px rgba(23, 32, 38, 0.28);
  padding: 20px;
  display: grid;
  gap: 12px;
}

.login-card h2 {
  margin: 0;
  font-size: 20px;
}

.login-card p {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 13px;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 40;
  max-width: min(420px, calc(100vw - 36px));
  border-radius: 8px;
  background: #172026;
  color: #fff;
  padding: 12px 14px;
  box-shadow: 0 16px 34px rgba(23, 32, 38, 0.28);
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.toast.error {
  background: #96382d;
}

.mobile-body {
  min-height: 100vh;
}

.mobile-header {
  position: static;
}

.mobile-shell {
  display: grid;
  grid-template-columns: minmax(280px, 360px) minmax(0, 1fr) minmax(280px, 420px);
  gap: 14px;
  width: min(1320px, 100%);
  margin: 0 auto;
  padding: 16px;
}

.scan-panel {
  min-width: 0;
}

.scanner-frame {
  position: relative;
  overflow: hidden;
  width: 100%;
  aspect-ratio: 4 / 3;
  border-radius: 8px;
  background: #10181d;
}

.scanner-frame video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.scanner-message {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 12px;
  border-radius: 6px;
  background: rgba(16, 24, 29, 0.78);
  color: #fff;
  padding: 9px 10px;
  text-align: center;
  font-weight: 700;
}

.mobile-manual {
  margin-top: 12px;
}

.location-field {
  display: block;
  margin-bottom: 12px;
}

.mobile-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.mobile-log {
  grid-column: 1 / -1;
}

.mobile-inbound-panel {
  align-self: start;
}

@media (max-width: 1100px) {
  .summary-grid {
    grid-template-columns: repeat(3, minmax(130px, 1fr));
  }
}

@media (max-width: 900px) {
  .app-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .header-actions {
    justify-content: flex-start;
  }

  .office-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  .detail-grid,
  .mobile-shell {
    grid-template-columns: 1fr;
  }

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

@media (max-width: 620px) {
  body {
    font-size: 13px;
  }

  .app-header {
    padding: 12px 14px;
  }

  .app-header h1 {
    font-size: 20px;
  }

  .main-content,
  .sidebar,
  .mobile-shell {
    padding: 12px;
  }

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

  .metric-card {
    min-height: 72px;
    padding: 11px;
  }

  .metric-card strong {
    font-size: 24px;
  }

  .inventory-toolbar,
  .toolbar-controls {
    align-items: stretch;
    flex-direction: column;
  }

  .toolbar-controls,
  .toolbar-controls select,
  .search-input {
    width: 100%;
    min-width: 0;
  }

  .inline-form,
  .mobile-actions {
    grid-template-columns: 1fr;
  }

  .label-preview {
    grid-template-columns: 1fr;
  }

  .label-preview img {
    justify-self: center;
  }

  .activity-list li {
    grid-template-columns: 1fr;
    gap: 2px;
  }
}
