/* ========================================================================
 * 仓流 WMS · 中小型智能仓储管理系统 —— 样式
 * 设计语言：工业单证 / 安全橙强调 / 深墨侧栏 / 等宽数字
 * ======================================================================== */

:root {
  /* 墨色与背景 */
  --ink: #1c2025;
  --ink-2: #4a515a;
  --muted: #848b94;
  --paper: #f4f5f6;
  --sheet: #ffffff;
  --line: #e6e8eb;
  --line-strong: #d4d8dd;
  --sidebar: #171b20;

  /* 强调色：安全橙 */
  --accent: #e8540c;
  --accent-deep: #c7470a;
  --accent-soft: #fdeade;
  --accent-ink: #a63d08;

  /* 语义色 */
  --green: #1f8a52;
  --green-soft: #e7f4ec;
  --amber: #a8620a;
  --amber-soft: #fbf0dc;
  --red: #c93b3b;
  --red-soft: #fbeaea;
  --blue: #2b6cb0;
  --blue-soft: #eaf1f8;

  --radius: 12px;
  --radius-sm: 8px;

  --font-ui: "Inter", "Segoe UI", system-ui, -apple-system, "Microsoft YaHei", "PingFang SC", "Helvetica Neue", sans-serif;
  --font-mono: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, "Segoe UI Mono", monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
/* hidden 属性必须始终生效，避免被 display 规则覆盖（否则弹窗/遮罩无法关闭） */
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  font-family: var(--font-ui);
  background: var(--paper);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* 数字统一等宽对齐，便于纵向比读 */
table, .summary-value, .kpi, .bar-val, .act-qty, .donut-center .dv, .score-ring .ring {
  font-variant-numeric: tabular-nums;
}

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
::selection { background: var(--accent-soft); }

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

/* ---------------- 侧边栏 ---------------- */
.sidebar {
  width: 232px; flex: 0 0 232px;
  background: var(--sidebar);
  color: #c7ccd3;
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
  transition: transform .25s ease;
  z-index: 40;
}
.brand {
  display: flex; align-items: center; gap: 12px;
  padding: 22px 20px 20px;
}
.brand-logo {
  width: 42px; height: 42px; flex: 0 0 42px;
  background: #f4f5f6; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
}
.brand-logo svg { width: 34px; height: 22px; }
.brand-name { font-size: 17px; font-weight: 700; color: #fff; letter-spacing: .02em; }
.brand-sub { font-size: 11px; color: #6b727c; letter-spacing: .04em; }

.nav { flex: 1; padding: 10px 12px; display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 12px;
  width: 100%; padding: 11px 13px; border: 0; border-radius: 9px;
  background: transparent; color: #aeb4bd; font-size: 14px; text-align: left;
  cursor: pointer; transition: background .15s, color .15s;
  position: relative;
}
.nav-item:hover { background: rgba(255, 255, 255, .05); color: #fff; }
.nav-item.active { background: var(--accent); color: #fff; font-weight: 600; }
.nav-ico { width: 19px; height: 19px; flex: 0 0 19px; display: flex; align-items: center; justify-content: center; }
.nav-ico svg { width: 19px; height: 19px; }
.sidebar-foot { padding: 12px; border-top: 1px solid rgba(255, 255, 255, .06); }
.sidebar-foot .nav-item { color: #7d848e; }

/* 移动端侧边栏遮罩（点击空白处关闭） */
.sidebar-backdrop { position: fixed; inset: 0; background: rgba(16, 24, 40, .42); z-index: 35; }
@media (min-width: 721px) { .sidebar-backdrop { display: none !important; } }

/* ---------------- 主区域 ---------------- */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 14px;
  padding: 15px 26px; background: var(--sheet);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 30;
}
.page-title { font-size: 18px; font-weight: 700; letter-spacing: -.01em; }
.menu-toggle { display: none; border: 0; background: transparent; font-size: 22px; cursor: pointer; color: var(--ink); }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 7px; font-size: 12px; color: var(--muted); }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--amber); }
.status-dot.ok { background: var(--green); }

.content { padding: 24px 26px 48px; max-width: 1200px; width: 100%; }
.app-footer { width: 100%; max-width: 1200px; padding: 0 26px 24px; text-align: center; color: var(--muted); font-size: 12px; line-height: 1.8; }
.app-footer a { color: inherit; text-decoration: none; }
.app-footer a:hover { color: var(--accent); text-decoration: underline; }
.account-button { font-size: 12px; padding: 7px 12px; }
.account-email-row { padding: 12px 14px; margin-bottom: 18px; border: 1px solid var(--line); background: var(--paper); font-size: 12px; color: var(--ink-2); }
.account-email-row strong { color: var(--accent-ink); overflow-wrap: anywhere; }
#account-mask h3 { font-size: 15px; margin: 4px 0 10px; }
#account-mask .auth-code-row { display: grid; grid-template-columns: minmax(0,1fr) 120px; gap: 10px; align-items: end; }
#account-mask .auth-code-row label { margin-bottom: 18px; }
.account-foot { padding: 0; border: 0; margin-top: 4px; }
.account-password-box { border-top: 1px solid var(--line); margin-top: 20px; padding-top: 18px; }
.account-password-box h3 { margin-bottom: 8px; }
.account-password-box label { display: block; font-size: 12px; color: var(--ink-2); margin-bottom: 14px; }
.account-password-box input { display: block; width: 100%; margin-top: 6px; padding: 9px 10px; border: 1px solid var(--line-strong); border-radius: 7px; font: inherit; }
#account-admin-link { margin-top: 16px; }

/* ---------------- 卡片（单证样式：细线 + 极浅阴影） ---------------- */
.card {
  background: var(--sheet); border: 1px solid var(--line);
  border-radius: var(--radius); margin-bottom: 18px; overflow: hidden;
  box-shadow: 0 1px 2px rgba(16, 24, 40, .03);
}
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; padding: 18px 20px 0; }
.card-title { font-size: 15px; font-weight: 700; }
.card-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.card-body { padding: 16px 20px 20px; }
.card-body.flush { padding: 0; }

/* ---------------- 汇总条（单证表头式） ---------------- */
.summary-strip {
  display: grid; grid-template-columns: repeat(6, 1fr);
  gap: 1px; background: var(--line);
  border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden; margin-bottom: 18px;
}
.summary-cell { background: var(--sheet); padding: 15px 18px; }
.summary-label { display: flex; align-items: center; gap: 7px; font-size: 12px; color: var(--muted); }
.summary-dot { width: 7px; height: 7px; border-radius: 2px; background: var(--muted); flex: 0 0 7px; }
.summary-value { font-size: 24px; font-weight: 700; letter-spacing: -.02em; margin-top: 5px; line-height: 1.1; }
.summary-unit { font-size: 12px; font-weight: 500; color: var(--muted); margin-left: 3px; }
.summary-cell .dot-ink { background: var(--ink-2); }
.summary-cell .dot-green { background: var(--green); }
.summary-cell .dot-orange { background: var(--accent); }
.summary-cell .dot-red { background: var(--red); }
.summary-cell .dot-blue { background: var(--blue); }

/* ---------------- 按钮 ---------------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 9px 16px; border-radius: var(--radius-sm); border: 1px solid var(--line-strong);
  font-size: 14px; font-weight: 600; cursor: pointer; transition: background .15s, border-color .15s, color .15s;
  background: var(--sheet); color: var(--ink); font-family: inherit;
}
.btn:hover { background: #f6f7f8; border-color: var(--muted); }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.primary:hover { background: var(--accent-deep); border-color: var(--accent-deep); }
.btn.green { background: var(--green); color: #fff; border-color: var(--green); }
.btn.green:hover { background: #187344; border-color: #187344; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { background: #f6f7f8; color: var(--ink); border-color: transparent; }
.btn.danger { background: var(--sheet); color: var(--red); border-color: #f3c6c6; }
.btn.danger:hover { background: var(--red-soft); }
.btn.small { padding: 5px 10px; font-size: 12px; border-radius: 6px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------------- 工具条 / 搜索 ---------------- */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 16px; }
.tabs { display: flex; gap: 4px; background: #eef0f2; padding: 3px; border-radius: 9px; }
.tab {
  padding: 6px 14px; border-radius: 7px; border: 0; background: transparent;
  cursor: pointer; font-size: 13px; font-weight: 600; color: var(--ink-2); font-family: inherit;
  transition: background .15s, color .15s;
}
.tab:hover { color: var(--ink); }
.tab.active { background: var(--sheet); color: var(--accent); box-shadow: 0 1px 2px rgba(16,24,40,.08); }
input:disabled { background: #f3f4f6; color: var(--muted); cursor: not-allowed; }
.search-box { position: relative; flex: 1; min-width: 200px; max-width: 360px; }
.search-box input {
  width: 100%; padding: 9px 12px 9px 34px; border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm); font-size: 14px; background: var(--sheet); color: var(--ink); font-family: inherit;
}
.search-box::before { content: "⌕"; position: absolute; left: 11px; top: 7px; color: var(--muted); font-size: 17px; line-height: 1; }
select, input[type="text"], input[type="number"] {
  padding: 9px 12px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  font-size: 14px; background: var(--sheet); color: var(--ink); width: 100%; font-family: inherit;
}
select:focus, input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input::placeholder { color: var(--muted); }

/* ---------------- 表格 ---------------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 11px 14px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { background: #fafbfc; color: var(--muted); font-weight: 600; font-size: 12px; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fafbfd; }
td.num, th.num { text-align: right; }
.sku { font-family: var(--font-mono); font-size: 12px; color: var(--ink-2); letter-spacing: .01em; }
.empty { padding: 44px 20px; text-align: center; color: var(--muted); font-size: 13px; }

.badge {
  display: inline-block; padding: 2px 9px; border-radius: 6px;
  font-size: 12px; font-weight: 600; line-height: 1.6; white-space: nowrap;
}
.badge.in { background: var(--green-soft); color: var(--green); }
.badge.out { background: var(--accent-soft); color: var(--accent-ink); }
.badge.low { background: var(--red-soft); color: var(--red); }
.badge.ok { background: var(--green-soft); color: var(--green); }
.badge.lv0, .badge.lv1 { background: var(--red-soft); color: var(--red); }
.badge.lv2 { background: var(--amber-soft); color: var(--amber); }
.badge.lv3 { background: var(--blue-soft); color: var(--blue); }
.badge.abc-A { background: var(--red-soft); color: var(--red); }
.badge.abc-B { background: var(--amber-soft); color: var(--amber); }
.badge.abc-C { background: #eef0f2; color: var(--muted); }
.badge.zone { background: var(--accent-soft); color: var(--accent-ink); }
.badge.draft { background: var(--amber-soft); color: var(--amber); }
.badge.posted { background: var(--green-soft); color: var(--green); }
.badge.void { background: #eef0f2; color: var(--muted); }
.badge.move { background: var(--primary-soft); color: var(--primary); }

/* ---------------- AI 助手 ---------------- */
.ai-qs { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.ai-msgs {
  display: flex; flex-direction: column; gap: 10px;
  max-height: 380px; overflow-y: auto;
  background: var(--paper); border: 1px solid var(--line); border-radius: 10px;
  padding: 14px; margin-bottom: 12px;
}
.ai-msg { max-width: 86%; padding: 9px 13px; border-radius: 12px; font-size: 13px; line-height: 1.7; word-break: break-word; }
.ai-msg.user { align-self: flex-end; background: var(--accent); color: #fff; border-bottom-right-radius: 4px; }
.ai-msg.asst { align-self: flex-start; background: var(--sheet); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.ai-reason { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.ai-reason summary { cursor: pointer; user-select: none; color: var(--ink-2); font-weight: 600; }
.ai-reason div { margin-top: 4px; white-space: pre-wrap; }
.ai-input-row { display: flex; gap: 10px; }
.ai-input-row input { flex: 1; }

/* ---------------- 表单 ---------------- */
.form-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px 16px; }
.form-grid label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); font-weight: 500; }
.form-grid label i { color: var(--red); font-style: normal; }
.quick-form { display: grid; grid-template-columns: 1.6fr 1fr 1fr 1fr; gap: 12px; align-items: end; }
.quick-form .field { display: flex; flex-direction: column; gap: 6px; }
.quick-form .field > span { font-size: 12px; color: var(--muted); font-weight: 500; }
.hint { font-size: 12px; color: var(--muted); margin-top: 10px; line-height: 1.7; }
.hint kbd {
  background: #f3f4f6; border: 1px solid var(--line-strong); border-bottom-width: 2px;
  border-radius: 4px; padding: 1px 6px; font-size: 11px; font-family: inherit;
}

/* 可搜索下拉 */
.combo { position: relative; }
.combo .combo-panel {
  position: absolute; top: 100%; left: 0; right: 0; z-index: 20;
  background: var(--sheet); border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  box-shadow: 0 12px 32px rgba(16, 24, 40, .14); max-height: 260px; overflow-y: auto; margin-top: 4px;
}
.combo .combo-opt { padding: 9px 12px; cursor: pointer; display: flex; justify-content: space-between; gap: 10px; }
.combo .combo-opt:hover, .combo .combo-opt.sel { background: var(--accent-soft); }
.combo .combo-opt .c-name { font-weight: 600; color: var(--ink); }
.combo .combo-opt .c-sub { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }

/* ---------------- 分析图表 ---------------- */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.bars { display: flex; flex-direction: column; gap: 13px; }
.bar-row { display: grid; grid-template-columns: 132px 1fr 92px; align-items: center; gap: 10px; }
.bar-row .bar-name { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink-2); }
.bar-track { height: 10px; background: #eef0f2; border-radius: 5px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 5px; background: var(--accent); }
.bar-row .bar-val { font-size: 12px; color: var(--muted); text-align: right; }

.donut-wrap { display: flex; align-items: center; gap: 22px; flex-wrap: wrap; }
.donut { width: 150px; height: 150px; border-radius: 50%; flex: 0 0 150px; position: relative; }
.donut::after { content: ""; position: absolute; inset: 27px; background: var(--sheet); border-radius: 50%; }
.donut-center { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; z-index: 2; }
.donut-center .dv { font-size: 24px; font-weight: 700; }
.donut-center .dl { font-size: 11px; color: var(--muted); }
.legend { display: flex; flex-direction: column; gap: 9px; min-width: 160px; }
.legend-item { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--ink-2); }
.legend-dot { width: 10px; height: 10px; border-radius: 3px; flex: 0 0 10px; }

/* AI 洞察 */
.insights { display: flex; flex-direction: column; gap: 9px; }
.insight {
  display: flex; gap: 10px; padding: 12px 14px; border-radius: 10px;
  background: var(--accent-soft); font-size: 13px; line-height: 1.65; color: var(--accent-ink);
  border-left: 3px solid var(--accent);
}
.insight .ico { flex: 0 0 auto; }
.insight.warn { background: var(--amber-soft); color: var(--amber); border-left-color: var(--amber); }
.insight.danger { background: var(--red-soft); color: var(--red); border-left-color: var(--red); }

/* 最近活动 */
.act-item { display: flex; align-items: center; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--line); }
.act-item:last-child { border-bottom: 0; }
.act-ico {
  width: 30px; height: 30px; border-radius: 8px; flex: 0 0 30px;
  display: flex; align-items: center; justify-content: center; font-size: 15px; font-weight: 700;
}
.act-ico.in { background: var(--green-soft); color: var(--green); }
.act-ico.out { background: var(--accent-soft); color: var(--accent-ink); }
.act-main { flex: 1; min-width: 0; }
.act-name { font-weight: 600; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.act-meta { font-size: 12px; color: var(--muted); }
.act-qty { font-weight: 700; }

/* 分数环 */
.score-ring { display: flex; align-items: center; gap: 18px; }
.score-ring .ring {
  width: 96px; height: 96px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  font-size: 28px; font-weight: 800; flex: 0 0 96px; background-clip: padding-box;
}
.score-ring .ring.good { background: var(--green-soft); color: var(--green); border: 6px solid var(--green); }
.score-ring .ring.mid { background: var(--amber-soft); color: var(--amber); border: 6px solid var(--amber); }
.score-ring .ring.bad { background: var(--red-soft); color: var(--red); border: 6px solid var(--red); }

/* ---------------- 弹窗 ---------------- */
.modal-mask {
  position: fixed; inset: 0; background: rgba(16, 24, 40, .5); z-index: 100;
  display: flex; align-items: center; justify-content: center; padding: 20px;
  backdrop-filter: blur(2px);
}
.modal { background: var(--sheet); border-radius: 14px; width: 100%; max-width: 640px; max-height: 90vh; overflow-y: auto; box-shadow: 0 24px 60px rgba(16, 24, 40, .2); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 22px; border-bottom: 1px solid var(--line); }
.modal-head h2 { font-size: 16px; font-weight: 700; }
.modal-close { border: 0; background: transparent; font-size: 24px; cursor: pointer; color: var(--muted); line-height: 1; }
.modal-body { padding: 20px 22px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 16px 22px; border-top: 1px solid var(--line); }

/* ---------------- Toast ---------------- */
.toast-wrap { position: fixed; top: 20px; right: 20px; z-index: 200; display: flex; flex-direction: column; gap: 10px; }
.toast {
  background: var(--ink); color: #fff; padding: 12px 16px; border-radius: 10px;
  box-shadow: 0 12px 32px rgba(16, 24, 40, .2); font-size: 13px; min-width: 200px; max-width: 340px;
  animation: toastIn .22s ease;
}
.toast.ok { background: var(--green); }
.toast.err { background: var(--red); }
@keyframes toastIn { from { opacity: 0; transform: translateX(18px); } to { opacity: 1; transform: none; } }

/* ---------------- 响应式 ---------------- */
@media (max-width: 1040px) {
  .summary-strip { grid-template-columns: repeat(3, 1fr); }
  .form-grid { grid-template-columns: 1fr 1fr; }
  .quick-form { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 860px) {
  .grid-2 { grid-template-columns: 1fr; }
  .bar-row { grid-template-columns: 104px 1fr 74px; }
}
@media (max-width: 720px) {
  .sidebar { position: fixed; left: 0; transform: translateX(-100%); width: 240px; }
  .sidebar.open { transform: translateX(0); box-shadow: 0 0 40px rgba(0, 0, 0, .3); }
  .menu-toggle { display: block; }
  .content { padding: 16px 14px 36px; }
  .app-footer { padding: 0 14px 20px; }
  .summary-strip { grid-template-columns: repeat(2, 1fr); }
  .form-grid { grid-template-columns: 1fr; }
  .quick-form { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
