:root {
  --bg: #f4f6f9;
  --bg-card: #ffffff;
  --bg-input: #ffffff;
  --text: #1a1d26;
  --text-muted: #2695a3;
  --border: #e5e9eb;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --danger: #dc2626;
  --success: #16a34a;
  --warning: #d97706;
  --sidebar-w: 240px;
  --shadow: 0 1px 3px rgba(0,0,0,.08);
  --radius: 8px;
  --highlight: #fef08a;
}

[data-theme="dark"] {
  --bg: #0f1117;
  --bg-card: #1a1d26;
  --bg-input: #252830;
  --text: #f3f4f6;
  --text-muted: #9ca3af;
  --border: #374151;
  --primary: #3b82f6;
  --primary-hover: #60a5fa;
  --shadow: 0 1px 3px rgba(0,0,0,.4);
  --highlight: #854d0e;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 14px; scroll-behavior: smooth; }

body {
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Layout */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  transition: transform .25s;
}

.sidebar-header {
  padding: 1.25rem 1rem;
  border-bottom: 1px solid var(--border);
}

.sidebar-header h1 {
  font-size: 1rem;
  font-weight: 700;
  line-height: 1.3;
}

.sidebar-header .subtitle {
  font-size: .75rem;
  color: var(--text-muted);
  margin-top: .25rem;
}

.nav-list { list-style: none; padding: .75rem 0; flex: 1; overflow-y: auto; }

.nav-list a {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .65rem 1rem;
  color: var(--text);
  text-decoration: none;
  font-weight: 500;
  border-left: 3px solid transparent;
  transition: background .15s;
}

.nav-list a:hover { background: var(--bg); text-decoration: none; }
.nav-list a.active {
  background: color-mix(in srgb, var(--primary) 12%, transparent);
  border-left-color: var(--primary);
  color: var(--primary);
}

.nav-icon { width: 1.25rem; text-align: center; opacity: .8; }

.sidebar-footer {
  padding: 1rem;
  border-top: 1px solid var(--border);
  display: flex;
  gap: .5rem;
}

.main-content {
  flex: 1;
  margin-left: var(--sidebar-w);
  padding: 1.5rem;
  max-width: 100%;
}

.mobile-toggle {
  display: none;
  position: fixed;
  top: .75rem; left: .75rem;
  z-index: 200;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .5rem .75rem;
  cursor: pointer;
  font-size: 1.25rem;
}

/* Cards & stats */
.page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.page-header h2 { font-size: 1.5rem; font-weight: 700; }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
}

.stat-card .label { font-size: .8rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .03em; }
.stat-card .value { font-size: 1.75rem; font-weight: 700; margin-top: .25rem; }
.stat-card .value.primary { color: var(--primary); }

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 1.5rem;
}

.card-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
}

.card-header h3 { font-size: 1rem; font-weight: 600; }
.card-body { padding: 1.25rem; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; }
@media (max-width: 900px) { .grid-2 { grid-template-columns: 1fr; } }

/* Forms */
.form-group { margin-bottom: 1rem; }
.form-group label {
  display: block;
  font-size: .85rem;
  font-weight: 600;
  margin-bottom: .35rem;
  color: var(--text-muted);
}

.form-row { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 1rem; }

input, select, textarea {
  width: 100%;
  padding: .55rem .75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-input);
  color: var(--text);
  font-size: .9rem;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 20%, transparent);
}

textarea { resize: vertical; min-height: 80px; }

.chip-input-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: .35rem;
  padding: .35rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-input);
  min-height: 42px;
  align-items: center;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  padding: .2rem .55rem;
  border-radius: 999px;
  font-size: .8rem;
  background: color-mix(in srgb, var(--primary) 15%, transparent);
  color: var(--primary);
  cursor: pointer;
}

.chip button {
  background: none; border: none; cursor: pointer;
  color: inherit; font-size: 1rem; line-height: 1; padding: 0;
}

.chip-input-wrap input {
  border: none; flex: 1; min-width: 120px;
  padding: .25rem; background: transparent;
  box-shadow: none;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  padding: .5rem 1rem;
  border: none;
  border-radius: 6px;
  font-size: .875rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, opacity .15s;
  white-space: nowrap;
}

.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-secondary { background: var(--bg); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover:not(:disabled) { border-color: var(--primary); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-sm { padding: .35rem .65rem; font-size: .8rem; }
.btn-icon { padding: .4rem; min-width: 2rem; }

.btn-group { display: flex; flex-wrap: wrap; gap: .5rem; }

/* Table & virtual scroll */
.table-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: .75rem;
  align-items: center;
  margin-bottom: 1rem;
}

.inv-toolbar {
  gap: .6rem .75rem;
  margin-bottom: .75rem;
}

.inv-filter-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .45rem;
}

.inv-filter-select,
.inv-filter-input {
  width: auto;
  min-width: 0;
  max-width: 118px;
  padding: .38rem .5rem;
  font-size: .82rem;
  line-height: 1.2;
  height: 34px;
  border-radius: 6px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text);
}

.inv-filter-tag { max-width: 138px; }
.inv-filter-state { max-width: 108px; }
.inv-filter-input { max-width: 112px; }

.inv-tag-exclude-wrap {
  position: relative;
  flex-shrink: 0;
}

.inv-tag-exclude-btn {
  display: inline-flex;
  align-items: center;
  gap: .25rem;
  height: 34px;
  padding: 0 .65rem;
  font-size: .82rem;
  font-weight: 500;
  color: var(--text);
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  white-space: nowrap;
  transition: border-color .15s, background .15s;
}

.inv-tag-exclude-btn:hover {
  border-color: var(--primary);
}

.inv-tag-exclude-btn-active {
  border-color: var(--danger);
  background: color-mix(in srgb, var(--danger) 8%, var(--bg-input));
  color: var(--danger);
}

.inv-tag-exclude-caret {
  font-size: .7rem;
  opacity: .7;
}

.inv-tag-exclude-panel {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  z-index: 50;
  min-width: 168px;
  padding: .5rem .65rem .65rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .18);
}

.inv-tag-exclude-hint {
  margin: 0 0 .45rem;
  padding-bottom: .4rem;
  border-bottom: 1px solid var(--border);
  font-size: .72rem;
  color: var(--text-muted);
  line-height: 1.35;
}

.inv-tag-exclude-option {
  display: flex;
  align-items: center;
  gap: .45rem;
  padding: .35rem .25rem;
  font-size: .85rem;
  cursor: pointer;
  border-radius: 4px;
}

.inv-tag-exclude-option:hover {
  background: color-mix(in srgb, var(--primary) 8%, transparent);
}

.inv-tag-exclude-option input {
  width: auto;
  height: auto;
  margin: 0;
  cursor: pointer;
  accent-color: var(--danger);
}

.inv-tag-exclude-clear {
  width: 100%;
  margin-top: .5rem;
}

.inv-filter-select:focus,
.inv-filter-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--primary) 18%, transparent);
}

@media (max-width: 640px) {
  .inv-toolbar .search-box {
    flex: 1 1 100%;
    max-width: none;
  }
  .inv-filter-row {
    flex: 1 1 100%;
  }
  .inv-filter-select,
  .inv-filter-input {
    flex: 1 1 calc(50% - .25rem);
    max-width: none;
  }
}

.search-box { position: relative; flex: 1; min-width: 200px; max-width: 400px; }
.search-box input { padding-left: 2rem; }
.inv-search-wrap {
  display: flex;
  align-items: center;
  gap: .45rem;
  max-width: 480px;
}
.inv-search-wrap input {
  flex: 1;
  min-width: 0;
  padding-left: 2rem;
}
.inv-search-clear {
  flex-shrink: 0;
  height: 34px;
  padding: 0 .65rem;
  font-size: .82rem;
  white-space: nowrap;
}
.inv-search-clear.hidden { display: none; }
.search-box::before,
.inv-search-wrap::before {
  content: "🔍";
  position: absolute;
  left: .65rem;
  top: 50%;
  transform: translateY(-50%);
  font-size: .85rem;
  opacity: .5;
}

.virtual-table-wrap {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.virtual-table-header {
  display: grid;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  font-size: .75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-muted);
  position: sticky;
  top: 0;
  z-index: 2;
}

.virtual-table-body {
  overflow-y: auto;
  position: relative;
}

.virtual-table-row {
  display: grid;
  border-bottom: 1px solid var(--border);
  align-items: center;
  font-size: .875rem;
  cursor: pointer;
  transition: background .1s;
}

.virtual-table-row:hover { background: color-mix(in srgb, var(--primary) 6%, transparent); }

.virtual-table-header > div,
.virtual-table-row > div,
.virtual-table-header .vt-header-cell,
.virtual-table-row .vt-cell {
  padding: .65rem .75rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* 库存列表：单元格换行、行高自适应 */
.vt-wrap-cells .virtual-table-header .vt-header-cell,
.vt-wrap-cells .virtual-table-row-wrap .vt-cell {
  overflow: visible;
  text-overflow: unset;
  white-space: normal;
  word-break: break-word;
  line-height: 1.45;
}

.vt-wrap-cells .virtual-table-row-wrap {
  align-items: flex-start;
  height: auto !important;
}

.vt-wrap-cells .virtual-table-row-wrap .vt-cell .id-list,
.vt-wrap-cells .virtual-table-row-wrap .vt-cell .zip-list,
.vt-wrap-cells .virtual-table-row-wrap .vt-cell .tag-badge {
  margin-bottom: .2rem;
}

.vt-header-cell {
  position: relative;
  display: flex;
  align-items: center;
  min-width: 0;
  user-select: none;
}

.col-resize-handle {
  position: absolute;
  top: 0;
  right: 0;
  width: 6px;
  height: 100%;
  cursor: col-resize;
  z-index: 3;
}

.col-resize-handle:hover,
body.col-resizing .col-resize-handle {
  background: color-mix(in srgb, var(--primary) 35%, transparent);
}

body.col-resizing {
  cursor: col-resize;
  user-select: none;
}

.vt-wrap-cells.virtual-table-wrap {
  overflow: auto;
}

.vt-wrap-cells .virtual-table-body {
  overflow-x: auto;
}

.inv-seq {
  display: block;
  text-align: center;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

mark.highlight {
  background: var(--highlight);
  color: inherit;
  border-radius: 2px;
  padding: 0 1px;
}

.tag-badge {
  display: inline-block;
  padding: .15rem .45rem;
  border-radius: 4px;
  font-size: .7rem;
  margin-right: .25rem;
  color: #fff;
}

.stock-badge {
  display: inline-block;
  padding: .2rem .5rem;
  border-radius: 4px;
  font-size: .75rem;
  font-weight: 600;
}

.stock-badge-in {
  background: color-mix(in srgb, var(--success) 18%, transparent);
  color: var(--success);
}

.stock-badge-out {
  background: color-mix(in srgb, var(--danger) 18%, transparent);
  color: var(--danger);
}

#stock-item-select option {
  padding: .35rem;
}

.id-list { font-size: .75rem; color: var(--text-muted); }
.zip-list { font-size: .75rem; color: var(--text-muted); }

.cell-chip-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: .25rem .35rem;
  width: 100%;
}

.id-tag {
  display: block;
  min-width: 0;
  padding: .1rem .25rem;
  border-radius: 4px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: .7rem;
  line-height: 1.35;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.zip-tag {
  display: block;
  min-width: 0;
  padding: .1rem .2rem;
  border-radius: 4px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: .7rem;
  line-height: 1.35;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.id-tag.id-used {
  color: var(--danger);
  border-color: rgba(239, 68, 68, .45);
  background: rgba(239, 68, 68, .08);
  font-weight: 600;
}
.chip.chip-id-used {
  color: var(--danger);
  border-color: rgba(239, 68, 68, .45);
  background: rgba(239, 68, 68, .1);
}
.chip.chip-id-used button { opacity: .85; }
.stock-id-pick { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .35rem; }
.stock-id-pick label {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  font-size: .85rem;
  cursor: pointer;
  padding: .25rem .5rem;
  border-radius: 4px;
  border: 1px solid var(--border);
}
.stock-id-pick label.id-used-label {
  color: var(--danger);
  border-color: rgba(239, 68, 68, .45);
  background: rgba(239, 68, 68, .08);
  cursor: default;
  opacity: .9;
}
.stock-id-pick input:disabled { cursor: not-allowed; }

.stock-recipient-label {
  color: var(--danger);
  font-weight: 600;
}

.stock-recipient-cell {
  color: var(--danger);
  font-weight: 600;
}

/* Pagination */
.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: .75rem;
  padding: .75rem 0;
  font-size: .85rem;
  color: var(--text-muted);
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 17, 23, .55);
  backdrop-filter: blur(4px);
  z-index: 1000;
  overflow-y: auto;
  opacity: 0;
  visibility: hidden;
  transition: opacity .2s, visibility .2s;
}

.modal-overlay.open { opacity: 1; visibility: visible; }

.modal {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: var(--bg-card);
  border-radius: 12px;
  width: min(560px, calc(100vw - 2rem));
  max-height: min(85vh, 720px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 24px 64px rgba(0,0,0,.28);
  border: 1px solid var(--border);
  z-index: 1001;
}

.modal-overlay.open .modal {
  animation: modalPop .22s ease;
}

@keyframes modalPop {
  from { opacity: 0; transform: translate(-50%, -48%) scale(.97); }
  to { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

.modal-lg {
  max-width: 900px;
  width: min(900px, calc(100vw - 2rem));
}

.modal-sm {
  max-width: 420px;
  width: min(420px, calc(100vw - 2rem));
}

.modal-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  flex-shrink: 0;
  background: color-mix(in srgb, var(--bg) 40%, var(--bg-card));
}

.modal-header-text { min-width: 0; flex: 1; }

.modal-header h3 { font-size: 1.15rem; font-weight: 700; line-height: 1.3; }

.modal-subtitle {
  margin-top: .2rem;
  font-size: .85rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.modal-body {
  padding: 1.25rem;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.modal-body::-webkit-scrollbar { display: none; }

.modal-body .form-group { margin-bottom: 0.75rem; }
.modal-body .form-hint { margin: 0.2rem 0 0.35rem; font-size: 0.8rem; }
.modal-body textarea { min-height: 56px; max-height: 120px; }

.modal-footer {
  padding: 0.85rem 1.25rem;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 10px;
  flex-shrink: 0;
  background: var(--bg-card);
  box-shadow: 0 -6px 16px rgba(0, 0, 0, 0.08);
}

.modal-footer-actions {
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 10px;
  width: 100%;
}

.modal-close {
  background: var(--bg);
  border: 1px solid var(--border);
  width: 2rem;
  height: 2rem;
  border-radius: 8px;
  font-size: 1.25rem;
  cursor: pointer;
  color: var(--text-muted);
  line-height: 1;
  flex-shrink: 0;
  transition: background .15s, color .15s;
}

.modal-close:hover {
  background: var(--border);
  color: var(--text);
}

/* 出入库弹窗 */
.modal-stock {
  width: min(520px, calc(100vw - 2rem));
}

.modal-stock-in .modal-header {
  border-top: 3px solid var(--success);
}

.modal-stock-out .modal-header {
  border-top: 3px solid var(--danger);
}

.stock-modal-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: .85rem 1rem;
  margin-bottom: 1rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.stock-modal-summary-main {
  display: flex;
  flex-direction: column;
  gap: .15rem;
  min-width: 0;
}

.stock-modal-item-name {
  font-weight: 700;
  font-size: 1rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stock-modal-item-meta {
  font-size: .82rem;
  color: var(--text-muted);
}

.stock-modal-type-badge {
  flex-shrink: 0;
  padding: .35rem .75rem;
  border-radius: 999px;
  font-size: .78rem;
  font-weight: 700;
  letter-spacing: .02em;
}

.stock-modal-type-badge.is-in {
  color: var(--success);
  background: color-mix(in srgb, var(--success) 14%, transparent);
  border: 1px solid color-mix(in srgb, var(--success) 35%, transparent);
}

.stock-modal-type-badge.is-out {
  color: var(--danger);
  background: color-mix(in srgb, var(--danger) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--danger) 35%, transparent);
}

.stock-modal-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 .85rem;
}

.stock-modal-fields .form-group:last-child,
.stock-recipient-group,
.modal-stock .form-group:not(.stock-modal-fields .form-group) {
  grid-column: 1 / -1;
}

.stock-qty-input {
  font-size: 1.1rem;
  font-weight: 600;
  text-align: center;
}

.stock-recipient-pick {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  margin-top: .35rem;
}

.stock-recipient-btn {
  padding: .45rem .9rem;
  border-radius: 999px;
  border: 1.5px solid var(--border);
  background: var(--bg-input);
  color: var(--text);
  font-size: .85rem;
  font-weight: 500;
  cursor: pointer;
  transition: border-color .15s, background .15s, color .15s, transform .1s;
}

.stock-recipient-btn:hover {
  border-color: color-mix(in srgb, var(--danger) 50%, var(--border));
}

.stock-recipient-btn.selected {
  border-color: var(--danger);
  background: color-mix(in srgb, var(--danger) 12%, var(--bg-input));
  color: var(--danger);
  font-weight: 700;
  transform: translateY(-1px);
}

.stock-recipient-pick-error {
  padding: .5rem;
  border-radius: 10px;
  border: 1px dashed var(--danger);
  background: color-mix(in srgb, var(--danger) 6%, transparent);
}

.stock-recipient-group .form-hint {
  color: var(--text-muted);
  margin-bottom: .35rem;
}

/* Toast — 顶部居中，避免右下角看不见 */
.toast-container {
  position: fixed;
  top: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 11000;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .5rem;
  width: min(420px, calc(100vw - 2rem));
  pointer-events: none;
}

.toast {
  padding: .75rem 1.25rem;
  border-radius: var(--radius);
  background: var(--bg-card);
  border: 1px solid var(--border);
  box-shadow: 0 8px 24px rgba(0,0,0,.15);
  animation: toastDropIn .3s ease;
  max-width: 100%;
  width: 100%;
  text-align: center;
  pointer-events: auto;
}

.toast.success { border-top: 3px solid var(--success); }
.toast.error { border-top: 3px solid var(--danger); }
.toast.warning { border-top: 3px solid var(--warning); }

@keyframes toastDropIn {
  from { transform: translateY(-12px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* Progress */
.progress-bar-wrap {
  background: var(--bg);
  border-radius: 999px;
  height: 8px;
  overflow: hidden;
  margin: .5rem 0;
}

.progress-bar {
  height: 100%;
  background: var(--primary);
  border-radius: 999px;
  transition: width .2s;
}

/* Heatmap */
.chart-container { width: 100%; height: 400px; min-height: 300px; }
.chart-container.lg { height: 560px; }
.chart-container.sm { height: 220px; }

.breadcrumb-nav {
  display: flex;
  align-items: center;
  gap: .5rem;
  font-size: .85rem;
  margin-bottom: 1rem;
  color: var(--text-muted);
}

.breadcrumb-nav button {
  background: none; border: none;
  color: var(--primary); cursor: pointer;
  font-size: inherit;
}

.filter-panel {
  display: flex;
  flex-wrap: wrap;
  gap: .75rem;
  margin-bottom: 1rem;
  align-items: flex-end;
}

.filter-panel .form-group { margin-bottom: 0; min-width: 140px; }

.hm-color-group { min-width: 100px; }
.hm-color-pickers {
  display: flex;
  align-items: center;
  gap: .35rem;
  min-width: auto;
}
.hm-color-pickers label {
  font-size: .75rem;
  color: var(--text-muted);
  margin: 0;
}
.hm-color-pickers .hm-color-dark-label { margin-left: .25rem; }
.hm-color-pickers input[type="color"] {
  width: 2rem;
  height: 1.75rem;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  background: var(--surface);
}

.recipient-stats-filters {
  align-items: flex-end;
}

.recipient-stats-filters .form-group { min-width: 150px; }

.stock-return-group {
  padding: .75rem;
  margin-bottom: .75rem;
  border: 1px dashed color-mix(in srgb, var(--success) 40%, var(--border));
  border-radius: 10px;
  background: color-mix(in srgb, var(--success) 5%, var(--bg-card));
}

/* Tags page */
.tag-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
}

.category-block {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
}

.category-block h4 {
  font-size: .9rem;
  margin-bottom: .75rem;
  padding-bottom: .5rem;
  border-bottom: 1px solid var(--border);
}

.tag-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .4rem 0;
  gap: .5rem;
}

.color-dot {
  width: 12px; height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-muted);
}

.empty-state .icon { font-size: 3rem; margin-bottom: 1rem; opacity: .4; }

/* Logs */
.log-list { font-size: .8rem; max-height: 300px; overflow-y: auto; }
.log-item {
  padding: .5rem 0;
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: .75rem;
}
.log-time { color: var(--text-muted); white-space: nowrap; }

/* Detail */
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; }
@media (max-width: 768px) { .detail-grid { grid-template-columns: 1fr; } }

.detail-section h4 {
  font-size: .8rem;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: .5rem;
}

.detail-value { font-size: 1rem; margin-bottom: 1rem; }

/* Responsive */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }
  .sidebar.open { transform: translateX(0); }
  .main-content { margin-left: 0; padding: 1rem; padding-top: 3.5rem; }
  .mobile-toggle { display: block; }
  .sidebar-backdrop {
    display: none;
    position: fixed; inset: 0;
    background: rgba(0,0,0,.4);
    z-index: 99;
  }
  .sidebar-backdrop.open { display: block; }
}

/* 登录层 */
.auth-overlay {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
  background:
    radial-gradient(ellipse 80% 60% at 20% 10%, rgba(59, 130, 246, 0.35), transparent 55%),
    radial-gradient(ellipse 70% 50% at 90% 80%, rgba(30, 58, 138, 0.4), transparent 50%),
    linear-gradient(145deg, #0f172a 0%, #1e293b 45%, #0f172a 100%);
  backdrop-filter: blur(8px);
}

.auth-layout {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.75rem;
  width: 100%;
  max-width: 420px;
}

.access-busy-overlay {
  display: flex;
  align-items: center;
  justify-content: center;
}

.access-busy-error {
  text-align: center;
  color: #f3f4f6;
  max-width: 24rem;
  padding: 2rem;
}

.access-busy-code {
  font-size: 4.5rem;
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.04em;
  color: rgba(248, 113, 113, 0.95);
  margin-bottom: 0.75rem;
}

.access-busy-title {
  font-size: 1.5rem;
  font-weight: 700;
  margin: 0 0 0.5rem;
  color: #f9fafb;
}

.access-busy-desc {
  font-size: 0.95rem;
  color: #9ca3af;
  margin: 0;
  line-height: 1.6;
}

.auth-layout-wide {
  max-width: 520px;
}

@media (min-width: 768px) {
  .auth-layout {
    flex-direction: row;
    align-items: stretch;
    max-width: 860px;
    gap: 0;
  }

  .auth-layout-wide {
    max-width: 920px;
  }

  .auth-brand {
    flex: 1;
    justify-content: center;
    padding: 2.5rem 2rem;
    border-radius: var(--radius) 0 0 var(--radius);
    background: linear-gradient(160deg, rgba(37, 99, 235, 0.25) 0%, rgba(15, 23, 42, 0.6) 100%);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-right: none;
  }

  .auth-card-login {
    flex: 1;
    border-radius: 0 var(--radius) var(--radius) 0;
    max-width: none;
  }
}

.auth-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  color: #f8fafc;
}

.auth-logo-wrap {
  width: 88px;
  height: 88px;
  margin-bottom: 1.1rem;
  filter: drop-shadow(0 12px 28px rgba(37, 99, 235, 0.45));
  animation: auth-logo-float 4s ease-in-out infinite;
}

@keyframes auth-logo-float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}

.auth-logo-svg {
  width: 100%;
  height: 100%;
  display: block;
}

.auth-brand-title {
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  margin: 0 0 0.35rem;
  line-height: 1.35;
}

.auth-brand-sub {
  margin: 0;
  font-size: 0.85rem;
  color: rgba(248, 250, 252, 0.72);
}

.auth-card {
  width: 100%;
  max-width: 420px;
  padding: 1.75rem 1.85rem 1.65rem;
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow:
    0 4px 6px rgba(0, 0, 0, 0.06),
    0 24px 48px rgba(0, 0, 0, 0.28);
  border: 1px solid var(--border);
}

.auth-card-login {
  backdrop-filter: saturate(1.2);
}

.auth-card-wide {
  max-width: 520px;
}

.auth-form-title {
  font-size: 1.25rem;
  font-weight: 700;
  margin: 0 0 0.25rem;
  color: var(--text);
}

.auth-form-desc {
  margin: 0 0 1.25rem;
  font-size: 0.875rem;
  color: var(--text-muted);
}

.auth-error {
  display: none;
  margin: 0 0 1rem;
  padding: 0.65rem 0.85rem;
  border-radius: 10px;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--danger);
  background: color-mix(in srgb, var(--danger) 10%, var(--bg-card));
  border: 1px solid color-mix(in srgb, var(--danger) 35%, transparent);
  border-top: 3px solid var(--danger);
}

.auth-error.visible {
  display: block;
  animation: toastDropIn .25s ease;
}

.auth-field label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 0.35rem;
}

.auth-input {
  width: 100%;
  padding: 0.65rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-input);
  color: var(--text);
  font-size: 0.95rem;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.auth-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 22%, transparent);
}

.auth-input::placeholder {
  color: var(--text-muted);
  opacity: 0.65;
}

.auth-submit-btn {
  width: 100%;
  margin-top: 0.5rem;
  padding: 0.7rem 1rem;
  font-size: 0.95rem;
  font-weight: 600;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--primary) 0%, #1d4ed8 100%);
  border: none;
  box-shadow: 0 4px 14px color-mix(in srgb, var(--primary) 40%, transparent);
}

.auth-submit-btn:hover {
  filter: brightness(1.06);
}

.auth-role-hints {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 1.15rem;
  padding-top: 1rem;
  border-top: 1px dashed var(--border);
}

.auth-hint-chip {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  font-size: 0.75rem;
  line-height: 1.45;
  color: var(--text-muted);
}

.auth-hint-dot {
  flex-shrink: 0;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-top: 0.35rem;
}

.auth-hint-dot.employee {
  background: #22c55e;
  box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.25);
}

.auth-hint-dot.boss {
  background: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 30%, transparent);
}

.auth-role-chip {
  display: inline-block;
  padding: 0.12rem 0.55rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  background: color-mix(in srgb, var(--primary) 22%, transparent);
  color: var(--primary);
  vertical-align: middle;
}

.sidebar-footer-stack {
  flex-direction: column;
  align-items: stretch;
  gap: 0.5rem;
}

.auth-user-line {
  font-size: 0.8rem;
  line-height: 1.4;
  word-break: break-all;
}

.sidebar-footer-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  align-items: center;
}

.account-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.account-table th,
.account-table td {
  padding: 0.5rem 0.4rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.account-table th { color: var(--text-muted); font-weight: 600; font-size: 0.8rem; text-transform: uppercase; }

.hidden { display: none !important; }
.text-muted { color: var(--text-muted); }
.text-sm { font-size: .85rem; }
.mt-1 { margin-top: .5rem; }
.mb-1 { margin-bottom: .5rem; }
