/* =========================================================
   一桶姜山.进销存 · 界面主题
   企业级浅色 SaaS 风格（参考金蝶精斗云视觉规范）
   ========================================================= */

:root {
  --primary: #1677ff;
  --primary-hover: #4096ff;
  --primary-active: #0958d9;
  --primary-soft: #e8f1ff;
  --primary-line: #bcd9ff;

  --green: #1f8a5b;
  --green-soft: #e8f7f0;
  --orange: #fa8c16;
  --orange-soft: #fff4e5;
  --red: #d93a2b;
  --red-soft: #ffece8;
  --purple: #722ed1;
  --purple-soft: #f4ecff;

  --bg: #f5f7fa;
  --card: #ffffff;
  --border: #e6e9f0;
  --border-strong: #d8dee8;
  --text: #1f2733;
  --text-2: #4e5969;
  --muted: #86909c;
  --muted-2: #a9b1bf;

  --shadow-sm: 0 1px 2px rgba(17, 24, 39, 0.04);
  --shadow-md: 0 6px 24px -16px rgba(17, 24, 39, 0.35);
  --radius: 10px;
  --radius-sm: 8px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", "PingFang SC", sans-serif;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, p { margin: 0; }
button { font-family: inherit; }

::selection { background: rgba(22, 119, 255, 0.16); }

[hidden] { display: none !important; }

.app {
  display: flex;
  min-height: 100vh;
  align-items: stretch;
}

/* ---------------- Sidebar ---------------- */
.sidebar {
  width: 224px;
  flex: 0 0 224px;
  background: #fff;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding-bottom: 12px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 16px 16px;
  margin-bottom: 6px;
  border-bottom: 1px solid #f0f2f6;
}

.brand-mark {
  width: 36px;
  height: 36px;
  flex: 0 0 36px;
  border-radius: 8px;
  overflow: hidden;
  background: transparent;
}

.brand-mark img { width: 100%; height: 100%; object-fit: cover; display: block; }
.brand-mark svg { width: 22px; height: 22px; }

.brand-text { display: flex; flex-direction: column; line-height: 1.35; min-width: 0; }
.brand-text strong {
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.2px;
  white-space: nowrap;
}
.brand-text span {
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
  padding: 0 10px;
  overflow-y: auto;
}

.nav-group { display: flex; flex-direction: column; gap: 2px; }

.nav-group-label {
  padding: 14px 10px 5px;
  font-size: 11px;
  color: var(--muted-2);
  letter-spacing: 0.6px;
}
.nav-group:first-child .nav-group-label { padding-top: 4px; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 10px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text-2);
  font-size: 13.5px;
  cursor: pointer;
  text-align: left;
  transition: background 0.15s ease, color 0.15s ease;
}

.nav-item svg { width: 17px; height: 17px; flex: 0 0 17px; opacity: 0.85; }

.nav-short { display: none; }

.nav-item:hover { background: #f2f4f8; color: var(--text); }

.nav-item.active {
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 600;
}
.nav-item.active svg { opacity: 1; }

.sidebar-foot {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 10px 16px 0;
  padding-top: 12px;
  border-top: 1px solid #f0f2f6;
  font-size: 11.5px;
  color: var(--muted-2);
}

.dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #22c55e;
  box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.14);
}

/* ---------------- Main ---------------- */
.main {
  flex: 1;
  min-width: 0;
  padding: 0 24px 16px;
  max-width: 1440px;
  margin: 0 auto;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin: 0 -24px 20px;
  padding: 14px 24px;
  background: #fff;
  border-bottom: 1px solid var(--border);
}

.topbar-title { min-width: 0; }

.crumb {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted-2);
  line-height: 1.5;
}
.crumb-sep { color: #c9cfda; }
.crumb-current { color: var(--muted); }

.topbar-title h1 { font-size: 20px; font-weight: 600; letter-spacing: 0.2px; line-height: 1.4; }
.topbar-title p { color: var(--muted); font-size: 12.5px; margin-top: 1px; }

.topbar-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.date-chip {
  font-size: 12.5px;
  color: var(--muted);
  background: #f7f8fa;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 12px;
  white-space: nowrap;
}

/* ---------------- Buttons ---------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  border-radius: 6px;
  border: 1px solid transparent;
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
  white-space: nowrap;
}

.btn.sm { padding: 6px 12px; font-size: 12.5px; }

.btn.primary { background: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-hover); }
.btn.primary:active { background: var(--primary-active); }

.btn.ghost {
  background: #fff;
  border-color: var(--border-strong);
  color: var(--text-2);
}
.btn.ghost:hover { border-color: var(--primary); color: var(--primary); background: #f7faff; }

.btn.danger-text { color: var(--red); }
.btn.danger-text:hover { background: #fff4f2; border-color: #f7c9c2; color: var(--red); }

.btn:focus-visible,
.nav-item:focus-visible,
.link-btn:focus-visible,
.icon-btn:focus-visible {
  outline: 2px solid rgba(22, 119, 255, 0.4);
  outline-offset: 1px;
}

.btn:disabled {
  opacity: 0.62;
  cursor: not-allowed;
}

.icon-btn {
  width: 30px;
  height: 30px;
  border-radius: 6px;
  border: 0;
  background: #f2f4f8;
  color: #6b7480;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
.icon-btn:hover { background: #e9edf4; color: var(--text); }

/* ---------------- Views ---------------- */
.view { display: none; }
.view.active { display: block; animation: fade 0.22s ease; }

@keyframes fade {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}

/* ---------------- Cards ---------------- */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow-sm);
  transition: border-color 0.18s ease, box-shadow 0.18s ease;
}

.card:hover { border-color: #dbe2ee; box-shadow: var(--shadow-md); }

.card.block { margin-bottom: 16px; }

.card-more { text-align: center; padding-top: 10px; }

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.card-head h2 { font-size: 15px; font-weight: 600; letter-spacing: 0.1px; }
.card-head .hint { font-size: 12px; color: var(--muted); margin-left: 6px; }
.card-head .sub { font-size: 12px; color: var(--muted-2); }

.toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* ---------------- Stats ---------------- */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.stat {
  position: relative;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  display: flex;
  gap: 12px;
  align-items: flex-start;
  box-shadow: var(--shadow-sm);
  transition: border-color 0.18s ease, box-shadow 0.18s ease;
  animation: rise 0.35s ease both;
}

.stat:nth-child(2) { animation-delay: 0.03s; }
.stat:nth-child(3) { animation-delay: 0.06s; }
.stat:nth-child(4) { animation-delay: 0.09s; }
.stat:nth-child(5) { animation-delay: 0.12s; }

@keyframes rise {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

.stat:hover { border-color: #d5deec; box-shadow: var(--shadow-md); }

.stat-icon {
  width: 40px;
  height: 40px;
  flex: 0 0 40px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: var(--primary-soft);
  color: var(--primary);
}
.stat-icon.amber { background: var(--orange-soft); color: var(--orange); }
.stat-icon.red { background: var(--red-soft); color: var(--red); }
.stat-icon.blue { background: var(--purple-soft); color: var(--purple); }
.stat-icon svg { width: 20px; height: 20px; }

.stat-label { font-size: 12.5px; color: var(--muted); display: block; }
.stat strong {
  display: block;
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.2px;
  font-variant-numeric: tabular-nums;
  margin: 1px 0;
}
.stat strong small {
  font-size: 12px !important;
  font-weight: 500 !important;
  color: var(--muted) !important;
}
.stat em { font-style: normal; font-size: 11.5px; color: var(--muted-2); }

/* ---------------- Grids ---------------- */
.grid-2 {
  display: grid;
  grid-template-columns: 1.5fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
}

.grid-2.equal { grid-template-columns: 1fr 1fr; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }

/* ---------------- Chart ---------------- */
.bars {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  height: 190px;
  padding-top: 8px;
}

.bar-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  height: 100%;
  min-width: 0;
}

.bar-value {
  font-size: 10.5px;
  color: var(--muted-2);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.bar {
  width: 100%;
  max-width: 42px;
  border-radius: 4px 4px 0 0;
  background: linear-gradient(180deg, #69b1ff, var(--primary));
  transition: height 0.45s cubic-bezier(0.2, 0.8, 0.2, 1), filter 0.18s ease;
  min-height: 4px;
}

.bar-item:hover .bar { filter: brightness(1.06); }

.bar-item.is-today .bar {
  background: linear-gradient(180deg, #ffc069, var(--orange));
}

.bar-label { font-size: 11px; color: var(--muted); white-space: nowrap; }
.bar-item.is-today .bar-label { color: #d46b08; font-weight: 600; }

/* ---------------- Category bars ---------------- */
.cat-list { display: flex; flex-direction: column; gap: 15px; }

.cat-row .cat-top {
  display: flex;
  justify-content: space-between;
  font-size: 12.5px;
  margin-bottom: 5px;
}
.cat-row .cat-top span:first-child { color: var(--text-2); font-weight: 500; }
.cat-row .cat-top span:last-child { color: var(--muted); font-variant-numeric: tabular-nums; }

.cat-track { height: 8px; border-radius: 99px; background: #eef1f6; overflow: hidden; }
.cat-fill {
  height: 100%;
  border-radius: 99px;
  background: linear-gradient(90deg, var(--primary), #69b1ff);
  animation: grow 0.6s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

.cat-fill.amber { background: linear-gradient(90deg, var(--orange), #ffc069); }

/* ---------------- Expense summary ---------------- */
.expense-total {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 2px 0 15px;
  margin-bottom: 15px;
  border-bottom: 1px dashed var(--border);
}

.expense-total span { font-size: 12.5px; color: var(--muted); }
.expense-total strong {
  font-size: 24px;
  font-weight: 600;
  letter-spacing: -0.4px;
  font-variant-numeric: tabular-nums;
}

@keyframes grow { from { width: 0 !important; } }

/* ---------------- Tables ---------------- */
.table-wrap {
  width: 100%;
  overflow-x: auto;
  scrollbar-width: thin;
  scrollbar-color: #d3d9e3 transparent;
  -webkit-overflow-scrolling: touch;
}

.table-wrap::-webkit-scrollbar { height: 8px; }
.table-wrap::-webkit-scrollbar-thumb { background: #d3d9e3; border-radius: 99px; }

.table-wrap > .data-table:not(.mini) { min-width: 620px; }

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.data-table th {
  text-align: left;
  font-weight: 500;
  font-size: 12px;
  color: var(--muted);
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  background: #f7f8fa;
}

.data-table th:first-child { border-radius: 6px 0 0 6px; }
.data-table th:last-child { border-radius: 0 6px 6px 0; }

.data-table td {
  padding: 12px;
  border-bottom: 1px solid #f0f2f6;
  vertical-align: middle;
  white-space: nowrap;
}

.data-table td.log-detail { white-space: normal; }

.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table tbody tr { transition: background 0.12s ease; }
.data-table tbody tr:hover td { background: #f7f9fc; }

.data-table .num, .data-table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.data-table .muted-cell { color: var(--muted); font-size: 12.5px; white-space: nowrap; }
.data-table .strong-cell { font-weight: 600; }

.product-name { font-weight: 600; color: var(--text); }
.product-spec { font-size: 11.5px; color: var(--muted-2); margin-top: 2px; }

/* ---------------- Badges / pills ---------------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 1px 8px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
  line-height: 1.7;
}
.badge.in { background: var(--green-soft); color: #0f7a4d; }
.badge.out { background: var(--primary-soft); color: var(--primary); }
.badge.warn { background: var(--orange-soft); color: #d46b08; }
.badge.danger { background: var(--red-soft); color: var(--red); }
.badge.ok { background: var(--green-soft); color: #0f7a4d; }

.stock-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}
.stock-pill .mini-track { width: 46px; height: 5px; border-radius: 99px; background: #eef1f6; overflow: hidden; }
.stock-pill .mini-fill { height: 100%; border-radius: 99px; background: var(--primary); }
.stock-pill.low .mini-fill { background: var(--red); }
.stock-pill.low { color: var(--red); }

/* ---------------- Forms ---------------- */
.form { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form .field.span-2 { grid-column: span 2; }

.field { display: flex; flex-direction: column; gap: 5px; }
.field > span { font-size: 12.5px; color: var(--text-2); font-weight: 500; }

.field input, .field select, .toolbar input, .toolbar select {
  width: 100%;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  padding: 8px 11px;
  font-size: 13px;
  font-family: inherit;
  color: var(--text);
  background: #fff;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.field input::placeholder, .toolbar input::placeholder { color: var(--muted-2); }

.field input:focus, .field select:focus, .toolbar input:focus, .toolbar select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(22, 119, 255, 0.12);
}

.form-actions { grid-column: span 2; display: flex; justify-content: flex-end; gap: 10px; padding-top: 2px; }
.form-note { font-size: 11.5px; color: var(--muted-2); margin-top: 12px; }

.toolbar input { width: 200px; }
.toolbar select { width: auto; }

/* ---------------- Empty / alerts ---------------- */
.empty {
  padding: 36px 16px;
  text-align: center;
  color: var(--muted-2);
  font-size: 13px;
}
.empty .empty-title { color: var(--text-2); font-weight: 500; display: block; margin-bottom: 3px; }
.empty .empty-sub { font-size: 12px; }

.alert-list { display: flex; flex-direction: column; gap: 10px; }

.alert-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid #f5e4c8;
  background: #fffcf5;
  border-radius: var(--radius-sm);
  transition: border-color 0.15s ease, background 0.15s ease;
}

.alert-item:hover { background: #fffaf0; border-color: #f0d9b0; }

.alert-icon {
  width: 32px;
  height: 32px;
  flex: 0 0 32px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  background: var(--orange-soft);
  color: #d46b08;
  font-size: 15px;
  font-weight: 700;
}

.alert-body { flex: 1; min-width: 0; }
.alert-body strong { font-size: 13.5px; display: block; font-weight: 500; }
.alert-body span { font-size: 11.5px; color: var(--muted); }
.alert-qty { font-size: 12.5px; color: var(--red); font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }

.alert-item .link-btn { flex: 0 0 auto; }

/* ---------------- Modal ---------------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(17, 24, 39, 0.45);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 50;
}
.modal-backdrop.open { display: flex; animation: fade 0.16s ease; }

.modal {
  background: #fff;
  border-radius: 12px;
  width: 100%;
  max-width: 560px;
  max-height: calc(100vh - 40px);
  overflow: auto;
  box-shadow: 0 24px 60px -20px rgba(17, 24, 39, 0.45);
  animation: pop 0.2s ease;
}

@keyframes pop {
  from { opacity: 0; transform: translateY(10px) scale(0.99); }
  to { opacity: 1; transform: none; }
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px 12px;
  position: sticky;
  top: 0;
  background: #fff;
  z-index: 1;
}
.modal-head h3 { font-size: 16px; font-weight: 600; }

.modal-body { padding: 4px 20px 18px; }
.modal-body .form-grid { gap: 12px 14px; }

.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  background: #fafbfc;
  position: sticky;
  bottom: 0;
}

/* ---------------- Install guide ---------------- */
.guide-list { display: flex; flex-direction: column; gap: 10px; }

.guide-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 14px;
  background: #f8f9fb;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.guide-badge {
  flex: 0 0 auto;
  margin-top: 2px;
  padding: 1px 9px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  color: var(--primary);
  background: var(--primary-soft);
  white-space: nowrap;
}

.guide-item p { font-size: 12.5px; color: var(--text-2); line-height: 1.65; }

/* ---------------- Toast ---------------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 32px;
  transform: translate(-50%, 20px);
  padding: 10px 18px;
  border-radius: 6px;
  background: #1f2733;
  color: #f5f7fa;
  font-size: 13px;
  box-shadow: 0 12px 30px -12px rgba(0, 0, 0, 0.5);
  opacity: 0;
  pointer-events: none;
  transition: all 0.22s ease;
  z-index: 80;
  max-width: min(90vw, 460px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: #c0392b; }
.toast.success { background: #13845a; }

/* ---------------- Footer ---------------- */
.foot {
  margin-top: 24px;
  padding: 14px 4px;
  text-align: center;
  font-size: 11.5px;
  color: var(--muted-2);
}

/* ---------------- Helpers ---------------- */
.strong { font-weight: 600; }
.muted { color: var(--muted); }
.link-btn {
  border: 0;
  background: transparent;
  color: var(--primary);
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  padding: 3px 6px;
  border-radius: 4px;
  transition: background 0.15s ease;
}
.link-btn:hover { background: var(--primary-soft); }
.link-btn.danger { color: var(--red); }
.link-btn.danger:hover { background: var(--red-soft); }
.row-actions { display: flex; gap: 2px; justify-content: flex-end; white-space: nowrap; }

/* ---------------- Login ---------------- */
.login-backdrop {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 24px;
  overflow-y: auto;
  background:
    radial-gradient(800px 480px at 82% -12%, rgba(22, 119, 255, 0.1), transparent 62%),
    radial-gradient(700px 440px at -8% 110%, rgba(31, 138, 91, 0.08), transparent 60%),
    var(--bg);
}

body.login-open { overflow: hidden; }

.login-card {
  width: 100%;
  max-width: 380px;
  margin: auto;
  padding: 32px 28px 26px;
  border-radius: 12px;
  background: #fff;
  border: 1px solid var(--border);
  box-shadow: 0 18px 48px -24px rgba(17, 24, 39, 0.3);
  display: flex;
  flex-direction: column;
  gap: 14px;
  animation: pop 0.24s ease;
}

.login-brand { text-align: center; padding-bottom: 2px; }

.login-brand img {
  width: 56px;
  height: 56px;
  border-radius: 12px;
  display: block;
  margin: 0 auto 12px;
  object-fit: cover;
}

.login-brand h1 {
  font-size: 20px;
  font-weight: 600;
  letter-spacing: 0.4px;
  color: var(--text);
}

.login-brand p {
  margin-top: 3px;
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 0.2px;
}

.login-error {
  min-height: 18px;
  font-size: 12.5px;
  line-height: 1.4;
  color: var(--red);
}

.login-btn {
  width: 100%;
  padding: 10px 16px;
  font-size: 14px;
}

.user-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  max-width: 180px;
  padding: 3px 10px 3px 4px;
  border-radius: 999px;
  background: #f7f8fa;
  border: 1px solid var(--border);
  color: var(--text-2);
  font-size: 12.5px;
  font-family: inherit;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.user-chip:hover { background: #fff; border-color: var(--border-strong); }

.user-menu { position: relative; display: inline-flex; }

.user-caret { width: 12px; height: 12px; flex: 0 0 12px; color: var(--muted); }

.user-dropdown {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  min-width: 152px;
  padding: 5px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 12px 32px -14px rgba(17, 24, 39, 0.35);
  display: flex;
  flex-direction: column;
  gap: 2px;
  z-index: 60;
}

.menu-item {
  border: 0;
  background: transparent;
  text-align: left;
  padding: 8px 10px;
  border-radius: 5px;
  font-size: 13px;
  font-family: inherit;
  color: var(--text-2);
  cursor: pointer;
  white-space: nowrap;
}
.menu-item:hover { background: #f2f4f8; color: var(--text); }
.menu-item.danger { color: var(--red); }
.menu-item.danger:hover { background: var(--red-soft); color: var(--red); }

.user-avatar {
  width: 22px;
  height: 22px;
  flex: 0 0 22px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--primary);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
}

.user-chip .user-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 140px;
}

.user-chip .user-role {
  flex: 0 0 auto;
  padding: 0 7px;
  border-radius: 4px;
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 10.5px;
  font-weight: 600;
  white-space: nowrap;
  line-height: 1.7;
}

/* ---------------- 迁移横幅 / 用户 / 日志 ---------------- */
.migrate-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  margin: 16px 0;
  padding: 12px 16px;
  border: 1px solid var(--primary-line);
  border-radius: var(--radius-sm);
  background: #f5f9ff;
  box-shadow: var(--shadow-sm);
}

.migrate-text strong {
  display: block;
  font-size: 13.5px;
  color: #1d4ed8;
  font-weight: 600;
}

.migrate-text span {
  font-size: 12px;
  color: #4a6a9b;
}

.migrate-actions { display: flex; gap: 8px; }

.modal-hint {
  margin: 0 0 12px;
  font-size: 12.5px;
  color: var(--muted);
}

#view-users .card + .card,
#view-logs .card + .card { margin-top: 16px; }

.user-form { grid-template-columns: repeat(2, 1fr); }

.role-select {
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  padding: 3px 8px;
  font-size: 12.5px;
  font-family: inherit;
  color: var(--text);
  background: #fff;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.role-select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(22, 119, 255, 0.12);
}

.table-wrap > .data-table.admin-table { min-width: 720px; }

.log-table .log-detail {
  min-width: 240px;
  max-width: 460px;
  color: var(--text-2);
  font-size: 12.5px;
  word-break: break-word;
}

.pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding-top: 14px;
}

.pager > span { font-size: 12px; color: var(--muted-2); }
.pager-actions { display: flex; align-items: center; gap: 8px; }
.pager-actions > span { font-size: 12px; color: var(--muted); }

/* ---------------- Responsive ---------------- */
@media (max-width: 1020px) {
  .grid-2, .grid-2.equal { grid-template-columns: 1fr; }
}

@media (max-width: 820px) {
  body { padding-bottom: calc(64px + env(safe-area-inset-bottom)); }

  .app { flex-direction: column; }

  .sidebar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    top: auto;
    width: 100%;
    height: auto;
    flex: none;
    z-index: 40;
    flex-direction: row;
    align-items: stretch;
    padding: 5px 6px calc(5px + env(safe-area-inset-bottom));
    background: rgba(255, 255, 255, 0.98);
    backdrop-filter: blur(12px);
    border-top: 1px solid var(--border);
    border-right: 0;
    box-shadow: 0 -4px 16px -12px rgba(17, 24, 39, 0.35);
    overflow: visible;
  }

  .brand, .sidebar-foot { display: none; }

  .nav {
    flex-direction: row;
    gap: 2px;
    width: 100%;
    flex: 1;
    padding: 0;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .nav::-webkit-scrollbar { display: none; }

  .nav-group { display: contents; }
  .nav-group-label { display: none; }

  .nav-item {
    flex: 0 0 64px;
    min-width: 64px;
    flex-direction: column;
    justify-content: center;
    gap: 3px;
    padding: 6px 0;
    font-size: 10.5px;
    border-radius: 8px;
    text-align: center;
  }

  .nav-label { display: none; }
  .nav-short { display: block; font-size: 10px; letter-spacing: 0.2px; }
  .nav-item svg { width: 19px; height: 19px; flex: 0 0 19px; }

  .nav-item.active {
    background: var(--primary-soft);
    color: var(--primary);
  }

  .main {
    padding: 0 14px 8px;
    max-width: 100%;
    width: 100%;
  }

  .topbar {
    position: sticky;
    top: 0;
    z-index: 30;
    gap: 8px;
    margin: 0 -14px 14px;
    padding: 10px 14px;
    background: rgba(255, 255, 255, 0.97);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
  }

  .crumb { font-size: 11px; }
  .topbar-title h1 { font-size: 17px; }
  .topbar-title p { font-size: 11.5px; }

  .topbar-actions {
    gap: 6px;
    width: 100%;
    flex-wrap: wrap;
    padding-bottom: 1px;
  }
  .topbar-actions .btn.sm { flex: 0 0 auto; font-size: 12px; padding: 6px 10px; }
  .topbar-actions .user-chip { flex: 0 0 auto; max-width: 40vw; }
  .user-dropdown { left: 0; right: auto; }
  .date-chip { display: none; }

  .stats { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat { padding: 13px; gap: 10px; flex-direction: column; align-items: flex-start; }
  .stat-icon { width: 34px; height: 34px; flex-basis: 34px; border-radius: 7px; }
  .stat-icon svg { width: 17px; height: 17px; }
  .stat-label { font-size: 11.5px; }
  .stat strong { font-size: 18px; }
  .stat em { font-size: 10.5px; line-height: 1.45; }

  .card { padding: 15px; border-radius: var(--radius-sm); }
  .card-head { margin-bottom: 12px; }
  .card-head h2 { font-size: 14.5px; }

  .bars { height: 150px; gap: 6px; }
  .bar-value { font-size: 9px; }
  .bar-label { font-size: 10px; }

  .form, .form-grid { grid-template-columns: 1fr; gap: 12px; }
  .form .field.span-2, .form-actions { grid-column: span 1; }
  .form-actions .btn { width: 100%; }

  .toolbar { width: 100%; }
  .toolbar input, .toolbar select { width: 100%; flex: 1; }
  .toolbar .btn { width: 100%; }

  .modal-backdrop { align-items: flex-end; padding: 0; }
  .modal {
    max-width: 100%;
    border-radius: 12px 12px 0 0;
    max-height: 92vh;
    animation: sheet 0.24s ease;
  }
  @keyframes sheet {
    from { opacity: 0; transform: translateY(30px); }
    to { opacity: 1; transform: none; }
  }

  .toast { bottom: calc(74px + env(safe-area-inset-bottom)); }

  .data-table th { padding: 9px 10px; }
  .data-table td { padding: 10px; }
  .data-table { font-size: 12.5px; }

  .stock-table.compact th:nth-child(2), .stock-table.compact td:nth-child(2),
  .stock-table.compact th:nth-child(4), .stock-table.compact td:nth-child(4) { display: none; }

  .foot { padding-bottom: 4px; }

  .migrate-banner { margin-top: 12px; }
  .migrate-actions { width: 100%; }
  .migrate-actions .btn { flex: 1; }

  .user-chip { max-width: 40vw; }

  .user-form { grid-template-columns: 1fr; }
  .user-form .form-actions { grid-column: span 1; }
  .pager { justify-content: center; }
  .pager > span { width: 100%; text-align: center; }

  .login-backdrop { padding: 18px; }
  .login-card { padding: 26px 20px 22px; border-radius: 12px; }
}

@media (max-width: 420px) {
  .topbar-title h1 { font-size: 16px; }
  .topbar-title p { display: none; }
  .stat strong { font-size: 17px; }
  .stat { padding: 12px; }
  .stats { gap: 8px; }
  .bar-value { display: none; }
  .bars { height: 132px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001s !important;
    transition-duration: 0.001s !important;
  }
}
