/* AI Inventory 设计系统 — product register / Restrained
   参考 QClaw 风格：中性近白底 + 珊瑚红品牌色（#f15642）双层用法——
   亮珊瑚只做品牌标识（--brand），交互主色用深一号珊瑚保证白字对比度 */
:root {
  --bg: oklch(1 0 0);
  --panel: oklch(0.985 0.002 30);          /* 侧栏/工具条第二中性层，近白 */
  --line: oklch(0.925 0.004 30);           /* 更轻的发丝线 */
  --ink: oklch(0.23 0.008 30);
  --ink-2: oklch(0.45 0.012 30);           /* 次级文字，白底 ≥4.5:1 */
  --brand: oklch(0.66 0.195 29);           /* 品牌标识色 = logo 珊瑚红 #f15642 */
  --primary: oklch(0.60 0.2 29);           /* 主操作/选中态 · 深一号珊瑚（白字可读）*/
  --primary-ink: oklch(0.54 0.19 29);      /* 白底上的主色文字 */
  --primary-hover: oklch(0.55 0.2 29);
  --primary-tint: oklch(0.972 0.014 35);   /* 淡蜜桃，参考卡片粉彩 */
  --ok: oklch(0.55 0.12 152);
  --ok-tint: oklch(0.968 0.024 152);
  --warn: oklch(0.57 0.13 65);             /* 琥珀，非棕 */
  --warn-tint: oklch(0.975 0.03 78);
  --danger: oklch(0.50 0.17 25);
  --danger-tint: oklch(0.968 0.018 25);
  --info: oklch(0.52 0.11 260);
  --info-tint: oklch(0.968 0.014 260);
  --radius: 10px;
  --radius-s: 7px;
  --shadow: 0 1px 2px oklch(0.2 0.008 30 / 0.05), 0 4px 16px oklch(0.2 0.008 30 / 0.04);
  --font: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, monospace;
  /* z-index 语义层级 */
  --z-sticky: 20; --z-drop: 30; --z-toast: 50;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.6 var(--font);
}
h1, h2, h3 { line-height: 1.3; text-wrap: balance; margin: 0 0 .5em; }
h1 { font-size: 1.5rem; font-weight: 700; }
h2 { font-size: 1.2rem; font-weight: 650; }
h3 { font-size: 1.05rem; font-weight: 600; }
p { margin: 0 0 1em; max-width: 72ch; }
a { color: var(--primary-ink); text-decoration: none; }
a:hover { text-decoration: underline; }
::placeholder { color: var(--ink-2); opacity: 1; }

/* ===== 表单控件 ===== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 8px 18px; border-radius: var(--radius-s);
  border: 1px solid var(--line); background: var(--bg); color: var(--ink);
  font: 600 14px/1 var(--font); cursor: pointer;
  transition: background .15s ease-out, border-color .15s ease-out, opacity .15s ease-out, transform .1s ease-out;
}
.btn:hover { background: var(--panel); }
.btn:active:not(:disabled) { transform: scale(.98); }
.btn:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible {
  outline: 2px solid var(--primary); outline-offset: 1px;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-danger { color: var(--danger); border-color: currentColor; }
.btn-danger:hover { background: var(--danger-tint); }
.btn-sm { min-height: 32px; padding: 4px 12px; font-size: 13px; }
input, textarea, select {
  font: 15px/1.5 var(--font); color: var(--ink);
  border: 1px solid var(--line); border-radius: var(--radius-s);
  padding: 9px 12px; background: var(--bg); min-height: 40px;
  transition: border-color .15s ease-out;
}
input:hover, textarea:hover, select:hover { border-color: oklch(0.80 0.01 30); }
textarea { resize: vertical; }
/* Safari 的 select 默认走原生小号弹出按钮，无视上面的 padding/min-height，
   和旁边的输入框/日期框高矮不一。关掉原生外观、自绘箭头，各引擎同一尺寸。 */
select {
  appearance: none; -webkit-appearance: none;
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%23857e78' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center;
  padding-right: 34px; cursor: pointer;
}
label { font-size: 13px; font-weight: 600; color: var(--ink-2); display: block; margin-bottom: 5px; }
.field { margin-bottom: 14px; }
.field input, .field textarea, .field select { width: 100%; }

/* 工具栏：一排并列的筛选控件必须同高。min-height 只是下限，
   select / 日期框 / 小按钮会各自按内容长高，一排高矮不齐——这里定死 40px。 */
.toolbar { display: flex; gap: 10px; align-items: end; flex-wrap: wrap; margin-bottom: 16px; }
.toolbar .field { margin: 0; }
.toolbar .field input:not([type="checkbox"]):not([type="radio"]),
.toolbar .field select { height: 40px; padding-top: 0; padding-bottom: 0; }
.toolbar .btn { min-height: 40px; }

/* ===== 徽标（状态 = 颜色 + 文字双通道）===== */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 12px; font-weight: 600; padding: 2px 9px; border-radius: 999px;
  white-space: nowrap;
}
.badge-warn { background: var(--warn-tint); color: var(--warn); }
.badge-ok { background: var(--ok-tint); color: var(--ok); }
.badge-danger { background: var(--danger-tint); color: var(--danger); }
.badge-info { background: var(--info-tint); color: var(--info); }
.badge-neutral { background: var(--panel); color: var(--ink-2); }

/* ===== 表格 ===== */
.tbl-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg); }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th {
  text-align: left; font-weight: 600; color: var(--ink-2); font-size: 12.5px;
  padding: 9px 14px; border-bottom: 1px solid var(--line); background: var(--panel);
  white-space: nowrap;
}
td { padding: 10px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: none; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr:hover { background: oklch(0.987 0.002 30); }

/* ===== 布局元素 ===== */
.card { border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg); padding: 18px 20px; }
.stack > * + * { margin-top: 16px; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.spread { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.muted { color: var(--ink-2); }
.small { font-size: 13px; }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
hr { border: none; border-top: 1px solid var(--line); margin: 16px 0; }

/* ===== 内联 SVG 图标（全站禁 emoji，图形一律用 SVG）===== */
.icon { width: 16px; height: 16px; flex: none; vertical-align: -3px; }
/* 折叠面板展开指示箭头（统一用 SVG，替代默认三角 marker） */
summary { list-style: none; }
summary::-webkit-details-marker { display: none; }
summary .chev { color: var(--ink-2); transition: transform .15s ease-out; }
details[open] > summary .chev { transform: rotate(90deg); }

/* ===== 空状态 ===== */
.empty {
  text-align: center; padding: 42px 20px; color: var(--ink-2);
  border: 1px dashed var(--line); border-radius: var(--radius);
}
.empty::before {
  content: ""; display: block; width: 30px; height: 30px; margin: 0 auto 12px;
  background: var(--ink-2); opacity: .55;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='22 12 16 12 14 15 10 15 8 12 2 12'/%3E%3Cpath d='M5.45 5.11 2 12v6a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-6l-3.45-6.89A2 2 0 0 0 16.76 4H7.24a2 2 0 0 0-1.79 1.11z'/%3E%3C/svg%3E") center / contain no-repeat;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='22 12 16 12 14 15 10 15 8 12 2 12'/%3E%3Cpath d='M5.45 5.11 2 12v6a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-6l-3.45-6.89A2 2 0 0 0 16.76 4H7.24a2 2 0 0 0-1.79 1.11z'/%3E%3C/svg%3E") center / contain no-repeat;
}
.empty strong { color: var(--ink); display: block; margin-bottom: 4px; font-size: 15px; }

/* ===== 骨架屏 ===== */
.skeleton { position: relative; overflow: hidden; background: var(--panel); border-radius: var(--radius-s); min-height: 16px; }
.skeleton::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, oklch(1 0 0 / .6), transparent);
  animation: shimmer 1.4s ease-out infinite;
}
@keyframes shimmer { from { transform: translateX(-100%); } to { transform: translateX(100%); } }

/* ===== Dialog（原生 <dialog>，用于改密码等标准小表单）===== */
dialog {
  border: 1px solid var(--line); border-radius: 12px; padding: 24px 26px;
  width: min(380px, calc(100vw - 40px)); box-shadow: var(--shadow);
  color: var(--ink); font: 15px/1.6 var(--font);
  opacity: 0; transform: translateY(6px) scale(.985);
  transition: opacity .18s ease-out, transform .18s ease-out,
    display .18s allow-discrete, overlay .18s allow-discrete;
}
dialog[open] { opacity: 1; transform: none; }
/* 面板内容超高（如网点数据明细）时面板内滚动，别把按钮顶出屏幕 */
dialog { max-height: calc(100dvh - 48px); overflow-y: auto; }
@starting-style {
  dialog[open] { opacity: 0; transform: translateY(6px) scale(.985); }
}
dialog::backdrop { background: oklch(0.2 0.008 30 / 0.35); }
dialog h3 { margin-top: 0; }
dialog .field input { width: 100%; }
/* width:100% 不该殃及勾选框，否则被拉成巨大方块 */
dialog .field input[type="checkbox"] { width: 16px; height: 16px; min-height: 0; flex: none; }

/* ===== Toast ===== */
#toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(8px);
  background: var(--ink); color: #fff; padding: 10px 18px; border-radius: var(--radius-s);
  font-size: 14px; opacity: 0; pointer-events: none; z-index: var(--z-toast);
  transition: opacity .2s ease-out, transform .2s ease-out; max-width: min(90vw, 480px);
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.err { background: var(--danger); }

/* ===== 页面 / 面板切换：轻微上移淡入，传达状态切换 ===== */
@keyframes fade-slide { from { opacity: 0; transform: translateY(4px); } }
section.page:not([hidden]), .tab-panel:not([hidden]) { animation: fade-slide .18s ease-out; }

/* ===== 登录页 ===== */
.login-wrap { min-height: 100dvh; display: grid; place-items: center; padding: 20px; background: var(--panel); }
.login-card { width: min(400px, 100%); background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 32px; box-shadow: var(--shadow); animation: fade-slide .25s ease-out; }
/* 品牌标志：compact 版描边加粗，22-40px 仍清晰；hairline 版用于 ≥40px 的展示位 */
.logo-mark { display: inline-flex; align-items: center; gap: 10px; font-weight: 650; font-size: 15px; color: var(--ink); }
.logo-wordmark { display: block; width: auto; height: 28px; }
.logo-glyph { display: block; width: auto; height: 21px; }
.logo-mark .div { flex: none; width: 1px; height: 16px; background: var(--line); }

/* ===== 应用壳 ===== */
.topbar {
  position: sticky; top: 0; z-index: var(--z-sticky);
  display: flex; align-items: center; gap: 14px; padding: 10px 20px;
  background: var(--bg); border-bottom: 1px solid var(--line);
}
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tab {
  padding: 10px 16px; font: 600 14px/1 var(--font); color: var(--ink-2);
  background: none; border: none; border-bottom: 2px solid transparent; cursor: pointer;
  white-space: nowrap; min-height: 42px;
  transition: color .15s ease-out;
}
.tab:hover { color: var(--ink); }
.tab.active { color: var(--primary-ink); border-bottom-color: var(--primary); }

/* 管理端侧栏 */
.shell { display: grid; grid-template-columns: 216px 1fr; min-height: 100dvh; }
.side { background: var(--panel); border-right: 1px solid var(--line); padding: 16px 10px; position: sticky; top: 0; height: 100dvh; overflow-y: auto; }
.side .logo-mark { padding: 4px 12px 16px; }
.nav-item {
  display: flex; align-items: center; gap: 9px; width: 100%;
  padding: 9px 12px; border-radius: var(--radius-s); border: none; background: none;
  font: 500 14px/1.4 var(--font); color: var(--ink-2); cursor: pointer; text-align: left;
  transition: background .15s ease-out, color .15s ease-out;
}
.nav-item:hover { background: oklch(0.95 0.004 30); color: var(--ink); }
.nav-item.active { background: var(--primary-tint); color: var(--primary-ink); font-weight: 650; }
.nav-item .icon { opacity: .72; transition: opacity .15s ease-out; }
.nav-item:hover .icon, .nav-item.active .icon { opacity: 1; }
.nav-item .n {
  margin-left: auto; font-size: 11.5px; font-weight: 700; background: var(--primary); color: #fff;
  border-radius: 999px; min-width: 19px; height: 19px; display: grid; place-items: center; padding: 0 5px;
}
.main { padding: 24px 28px 60px; min-width: 0; }

/* 统计块：数字即界面（非卡片网格，用分隔线节奏）*/
.stats { display: flex; flex-wrap: wrap; gap: 0; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.stat { flex: 1 1 130px; padding: 16px 20px; border-right: 1px solid var(--line); background: var(--bg); }
.stat:last-child { border-right: none; }
.stat b { display: block; font-size: 1.55rem; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.stat span { font-size: 12.5px; color: var(--ink-2); }
.stat.alert b { color: var(--danger); }
.stat.warn b { color: var(--warn); }

/* ===== 物资卡片网格：名称在上、三个自选指标在下，整张可点 ===== */
/* 一行三张是刻意固定的：宽表格八列在笔电上要横滑，卡片按行扫更快找到东西 */
/* 限宽：大屏上三等分会把卡片抻成 540px 的长条，卡片就不像卡片了 */
.tile-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; max-width: 1100px; }
.tile {
  position: relative; display: block; width: 100%; text-align: left;
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg);
  padding: 14px 16px; font: inherit; color: inherit; cursor: pointer;
  transition: border-color .15s ease-out, box-shadow .15s ease-out, background .15s ease-out;
}
.tile:hover { border-color: var(--primary); box-shadow: var(--shadow); }
.tile.picked { border-color: var(--primary); background: var(--primary-tint); }
.tile.low { border-left: 3px solid var(--danger); padding-left: 14px; }
.tile-head { display: flex; align-items: flex-start; gap: 8px; margin-bottom: 10px; }
.tile-name { font-size: 15px; font-weight: 650; line-height: 1.35; overflow-wrap: anywhere; }
/* 复选框自成点击区：勾选不应该顺带把编辑面板弹出来 */
.tile-pick { flex: none; margin-left: auto; display: grid; place-items: center; padding: 2px; cursor: pointer; }
.tile-pick input { width: 16px; height: 16px; margin: 0; cursor: pointer; }
.tile-meta { margin: 0; display: grid; gap: 5px; font-size: 13px; }
.tile-meta > div { display: flex; align-items: baseline; gap: 8px; }
.tile-meta dt { flex: none; color: var(--ink-2); min-width: 4.5em; }
.tile-meta dd { margin: 0; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.tile-meta dd.danger { color: var(--danger); font-weight: 650; }
/* 选中批量操作条：只在有勾选时出现，不常驻占位 */
.bulk-bar {
  position: sticky; top: 0; z-index: var(--z-sticky);
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 10px 14px; margin-bottom: 14px; max-width: 1100px;
  border: 1px solid var(--primary); border-radius: var(--radius-s); background: var(--primary-tint);
}
@media (max-width: 1180px) { .tile-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 620px) { .tile-grid { grid-template-columns: 1fr; } }
/* 物资编辑面板字段多，比默认 dialog 宽 */
dialog.wide { width: min(620px, calc(100vw - 32px)); }
dialog.wide .row { gap: 10px; }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: static; height: auto; display: flex; align-items: center; gap: 4px; overflow-x: auto; padding: 8px 10px; border-right: none; border-bottom: 1px solid var(--line); }
  .side .logo-mark { padding: 0 8px; white-space: nowrap; }
  .nav-item { white-space: nowrap; width: auto; }
  .main { padding: 16px 14px 60px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
