/* 甲油胶灌装 ERP —— 界面样式
   配色和排版集中在这里，想改外观只动这个文件。 */

:root {
  color-scheme: light dark;
  --bg: light-dark(#e8ebf2, #0e1116);
  --shell: light-dark(#ffffff, #1b1f27);
  --rail: light-dark(#f6f7fb, #161a21);
  --text: light-dark(#1c2129, #e7eaf0);
  --muted: light-dark(#6c7480, #98a1ae);
  --line: light-dark(#e0e4ec, #2b3039);
  --soft: light-dark(#f3f5f9, #22262f);
  --accent: light-dark(#5a51c9, #9089ff);
  --accent-soft: light-dark(#ecebfd, #2b2848);
  --ok: light-dark(#10795a, #52cfa6);
  --ok-soft: light-dark(#e5f5ef, #1c3029);
  --warn: light-dark(#8f5c00, #e2ac55);
  --warn-soft: light-dark(#fdf2df, #33290f);
  --danger: light-dark(#b0242c, #f18a90);
  --danger-soft: light-dark(#fdeceb, #3a1f22);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Microsoft YaHei", "PingFang SC", "Noto Sans SC", system-ui, sans-serif;
  font-size: 13.5px;
  line-height: 1.6;
}

a { color: var(--accent); }

/* ---------- 整体骨架 ---------- */
.window { display: grid; grid-template-columns: 200px minmax(0, 1fr); min-height: 100vh; }

.rail {
  background: var(--rail);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  max-height: 100vh;
  position: sticky;
  top: 0;
}

.brand { display: flex; align-items: center; gap: 8px; padding: 15px 14px 12px; font-weight: 500; }
.mark { width: 20px; height: 20px; border-radius: 6px; background: var(--accent); flex: none; }

.nav { overflow-y: auto; padding: 4px 8px 12px; flex: 1; }

.nav-item {
  display: block;
  padding: 6px 10px;
  border-radius: 7px;
  color: var(--muted);
  text-decoration: none;
  white-space: nowrap;
}
.nav-item:hover { background: var(--soft); color: var(--text); }
.nav-item.is-active { background: var(--accent-soft); color: var(--accent); font-weight: 500; }

.group { margin-top: 2px; }
.group-head {
  display: flex; align-items: center; gap: 7px;
  width: 100%; text-align: left; padding: 8px 10px;
  border: 0; border-radius: 7px; background: transparent;
  color: var(--text); font: inherit; font-weight: 500; cursor: pointer;
}
.group-head:hover { background: var(--soft); }
.group-head[aria-expanded="true"] { color: var(--accent); }
.caret {
  flex: none; width: 0; height: 0;
  border-left: 4px solid currentColor;
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  transition: transform .15s ease;
}
.group-head[aria-expanded="true"] .caret { transform: rotate(90deg); }
.group-body { padding: 2px 0 4px 12px; }
.group-body[hidden] { display: none; }

.rail-foot {
  margin-top: auto; padding: 12px 14px;
  border-top: 1px solid var(--line);
  color: var(--muted); font-size: 12px;
}
.rail-foot strong { display: block; color: var(--text); font-size: 13px; font-weight: 500; }

.main { display: flex; flex-direction: column; min-width: 0; }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 18px; background: var(--shell);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5;
}
.page-title { font-weight: 500; font-size: 15px; }
.topbar-user {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 6px 10px;
}
.topbar-user .who { color: var(--muted); font-size: 12px; }
.topbar-user form { margin: 0; }

.presence-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  color: var(--muted);
  background: var(--soft);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 12px;
  white-space: nowrap;
}
.presence-pill strong { color: var(--ok); font-weight: 600; }
.presence-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 18%, transparent);
}

.body { padding: 18px; display: flex; flex-direction: column; gap: 14px; }

/* ---------- 面板与表格 ---------- */
.panel { background: var(--shell); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; }
.panel-title {
  font-weight: 500; margin-bottom: 10px;
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
}
.hint { color: var(--muted); font-size: 12px; }

/* 列多了不再硬挤：放不下时由外层 .scroll 左右滑动，避免文字被压成竖排 */
table { min-width: 100%; width: max-content; border-collapse: collapse; }
th {
  text-align: left; font-weight: 500; color: var(--muted);
  background: var(--soft); padding: 8px 10px;
  position: relative; overflow: hidden; text-overflow: ellipsis;
  border-bottom: 1px solid var(--line); white-space: nowrap;
}
td { padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--soft); }
.scroll {
  overflow-x: auto;
  scrollbar-color: var(--accent) var(--soft);
  scrollbar-width: auto;
}

/* 放在表格上方的横向拖动条：
   长表格的原始横向滚动条在表格最底部，屏幕较矮时必须滚完很多行才看得到。
   这里增加一条始终在表格顶部附近的同步拖动条，所有 .scroll 表格通用。 */
.table-scroll-top {
  position: sticky;
  top: 54px;
  z-index: 4;
  width: 100%;
  height: 18px;
  margin: 0 0 6px;
  overflow-x: auto;
  overflow-y: hidden;
  background: var(--shell);
  border: 1px solid var(--line);
  border-radius: 6px;
  scrollbar-color: var(--accent) var(--soft);
  scrollbar-width: auto;
  overscroll-behavior-x: contain;
}
.table-scroll-top[hidden] { display: none; }
.table-scroll-top:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.table-scroll-top-inner { width: 1px; height: 1px; }

.scroll::-webkit-scrollbar,
.table-scroll-top::-webkit-scrollbar {
  width: 14px;
  height: 14px;
}
.scroll::-webkit-scrollbar-track,
.table-scroll-top::-webkit-scrollbar-track {
  background: var(--soft);
  border-radius: 8px;
}
.scroll::-webkit-scrollbar-thumb,
.table-scroll-top::-webkit-scrollbar-thumb {
  background: color-mix(in srgb, var(--accent) 62%, var(--muted));
  border: 3px solid var(--soft);
  border-radius: 8px;
}
.scroll::-webkit-scrollbar-thumb:hover,
.table-scroll-top::-webkit-scrollbar-thumb:hover {
  background: var(--accent);
}

.tag { display: inline-block; padding: 1px 8px; border-radius: 20px; font-size: 12px; white-space: nowrap; }
.tag-ok { background: var(--ok-soft); color: var(--ok); }
.tag-warn { background: var(--warn-soft); color: var(--warn); }
.tag-danger { background: var(--danger-soft); color: var(--danger); }
.tag-accent { background: var(--accent-soft); color: var(--accent); }

.mono { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- 统计卡片 ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.stat { background: var(--shell); border: 1px solid var(--line); border-radius: 10px; padding: 13px 16px; }
.stat-label { color: var(--muted); font-size: 12px; }
.stat-value { font-size: 23px; font-weight: 500; margin-top: 2px; }

/* ---------- 表单 ---------- */
.fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px 18px; }
.field label { display: block; color: var(--muted); font-size: 12px; margin-bottom: 3px; }

input[type="text"], input[type="password"], input[type="date"], input[type="number"], select, textarea {
  width: 100%; padding: 7px 10px; border-radius: 7px;
  border: 1px solid var(--line); background: var(--soft); color: var(--text);
  font: inherit;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }

.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.actions form { margin: 0; }

.btn {
  font: inherit; padding: 6px 14px; border-radius: 7px;
  border: 1px solid var(--line); background: var(--shell); color: var(--text);
  cursor: pointer; text-decoration: none; display: inline-block;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { color: #fff; opacity: .9; }
.btn-plain { border: 0; background: transparent; color: var(--accent); padding: 4px 6px; }
.btn-sm { padding: 3px 10px; font-size: 12px; }
.btn-danger { border-color: var(--danger); color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); border-color: var(--danger); color: var(--danger); }

/* 表头右边缘的拖动条：拖它就能调这一列的宽度 */
.col-grip {
  position: absolute;
  top: 0;
  right: 0;
  width: 8px;
  height: 100%;
  cursor: col-resize;
  user-select: none;
}
.col-grip:hover { background: var(--accent-soft); }
body.is-col-resizing { cursor: col-resize; user-select: none; }

.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end; }
.toolbar .field { flex: 1 1 160px; }

/* ---------- 提示条 ---------- */
.flashes { display: flex; flex-direction: column; gap: 8px; }
.flash { padding: 9px 12px; border-radius: 8px; font-size: 13px; }
.flash-ok { background: var(--ok-soft); color: var(--ok); }
.flash-error { background: var(--danger-soft); color: var(--danger); }
.flash-warn { background: var(--warn-soft); color: var(--warn); }

.note { background: var(--accent-soft); color: var(--accent); border-radius: 8px; padding: 9px 12px; font-size: 12.5px; }
.empty { color: var(--muted); padding: 18px 4px; text-align: center; }

/* ---------- 看板图表 ---------- */
.chart-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 14px; }
.chart { width: 100%; height: auto; display: block; }

/* ---------- 可打字筛选的下拉框 ---------- */
.combo { display: block; position: relative; }
.combo-native { display: none !important; }
.combo-input { width: 100%; }

.combo-panel {
  position: fixed;
  z-index: 60;
  max-height: 260px;
  overflow-y: auto;
  background: var(--shell);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 8px 22px rgba(0, 0, 0, .18);
  padding: 4px;
}
.combo-panel[hidden] { display: none; }

.combo-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 7px 10px;
  border: 0;
  border-radius: 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  background: transparent;
  color: var(--text);
  font: inherit;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.combo-item:hover,
.combo-item.is-selected { background: var(--accent-soft); color: var(--accent); }

.combo-empty { padding: 8px 10px; color: var(--muted); font-size: 12px; }

/* ---------- 类别树：大类 → 小类 点选 ---------- */
.cat-picker-row { display: flex; gap: 6px; align-items: center; }
.cat-picker-row .cat-picker-input { flex: 1 1 auto; min-width: 0; }
.cat-picker-toggle { flex: 0 0 auto; white-space: nowrap; }

.cat-picker-panel {
  position: fixed;
  z-index: 61;
  max-height: 340px;
  overflow-y: auto;
  background: var(--shell);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 8px 22px rgba(0, 0, 0, .18);
  padding: 6px;
}
.cat-picker-panel[hidden] { display: none; }

.cat-picker-filter {
  width: 100%;
  margin-bottom: 6px;
  box-sizing: border-box;
}

.cat-node {
  display: block;
  width: 100%;
  text-align: left;
  padding: 5px 8px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cat-node:hover { background: var(--accent-soft); color: var(--accent); }
.cat-node.is-parent { font-weight: 600; }
.cat-node[hidden] { display: none; }
.cat-node .cat-branch { color: var(--muted); margin-right: 4px; }
.cat-node .cat-count {
  color: var(--muted);
  font-size: 11px;
  margin-left: 8px;
}
.cat-node:hover .cat-count { color: var(--accent); }

/* ---------- 物料多选（按物料盘点）：搜索后勾选 ---------- */
.mat-multi { margin-top: 6px; }
.mat-multi-search { width: 100%; box-sizing: border-box; }

.mat-multi-results {
  margin-top: 6px;
  max-height: 260px;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 8px;
}
.mat-multi-results .mat-item {
  display: block;
  padding: 3px 4px;
  cursor: pointer;
  border-radius: 6px;
}
.mat-multi-results .mat-item:hover { background: var(--accent-soft); }

.mat-multi-picked {
  margin-top: 8px;
  padding: 6px 8px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  min-height: 34px;
}
.mat-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin: 2px 6px 2px 0;
  padding: 2px 4px 2px 8px;
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 999px;
  font-size: 12px;
}
.mat-chip-x {
  border: 0;
  background: transparent;
  color: inherit;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  padding: 0 4px;
}

/* 批量粘贴：一次加很多条物料 */
.mat-multi-bulk { margin-top: 8px; }
.mat-multi-bulk > summary {
  cursor: pointer;
  color: var(--accent);
  font-size: 13px;
}
.mat-multi-bulk-text {
  width: 100%;
  box-sizing: border-box;
  margin-top: 6px;
}
.mat-multi-bulk .actions { margin-top: 6px; }
.mat-multi-bulk-msg { margin-top: 6px; }

/* ---------- 登录与账套选择 ---------- */
.center-stage {
  min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px 16px;
}
.center-card {
  width: 100%; max-width: 420px; background: var(--shell);
  border: 1px solid var(--line); border-radius: 14px; padding: 26px;
}
.center-card h1 { font-size: 17px; font-weight: 500; margin: 16px 0 4px; }
.center-sub { color: var(--muted); font-size: 12.5px; margin-bottom: 18px; }

.captcha-row {
  display: flex;
  align-items: stretch;
  gap: 9px;
}
.captcha-row input { flex: 1 1 auto; min-width: 0; }
.captcha-refresh {
  flex: 0 0 168px;
  width: 168px;
  height: 50px;
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--soft);
  cursor: pointer;
}
.captcha-refresh img {
  display: block;
  width: 166px;
  height: 48px;
}
.captcha-refresh:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.book-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  width: 100%; text-align: left; padding: 12px 14px; margin-bottom: 8px;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--soft); color: var(--text); font: inherit; cursor: pointer;
}
.book-row:hover { border-color: var(--accent); }
.book-name { font-weight: 500; }
.book-meta { display: block; color: var(--muted); font-size: 12px; }
.go { color: var(--accent); font-size: 12.5px; white-space: nowrap; }

/* ---------- 窄屏 ---------- */
@media (max-width: 820px) {
  .window { grid-template-columns: minmax(0, 1fr); }
  .rail { position: static; max-height: 280px; border-right: 0; border-bottom: 1px solid var(--line); }
  .rail-foot { display: none; }
  .body { padding: 12px; }
}

/* ---------- 手机：老板随时看数据用 ---------- */
@media (max-width: 620px) {
  body { font-size: 14px; }

  .rail { max-height: 230px; }
  .nav { padding: 4px 6px 8px; }
  .nav-item, .group-head { padding: 9px 10px; }          /* 手指点得准 */
  .group-body { padding-left: 8px; }

  .topbar { flex-wrap: wrap; gap: 6px; padding: 10px 12px; position: static; }
  .page-title { font-size: 14px; }
  .topbar-user { width: 100%; justify-content: flex-end; }
  .topbar-user .who { margin-right: auto; }

  .body { padding: 10px; gap: 10px; }
  .panel { padding: 12px; }
  .panel-title { flex-wrap: wrap; gap: 4px; }

  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .stat { padding: 10px 12px; }
  .stat-value { font-size: 20px; }

  .fields { grid-template-columns: minmax(0, 1fr); }
  .field[style*="grid-column"] { grid-column: auto !important; }
  .toolbar .field { flex: 1 1 100%; }

  table { font-size: 12.5px; }
  th, td { padding: 7px 8px; }
  .table-scroll-top { position: static; }
  .chart-row { grid-template-columns: minmax(0, 1fr); }
}

/* ---------- 打印：只留单据本身，去掉菜单、按钮和操作栏 ---------- */
.print-only { display: none; }

@media print {
  .rail,
  .topbar,
  .flashes,
  .actions,
  .toolbar,
  .no-print { display: none !important; }

  html, body { background: #fff; color: #000; }
  .window { display: block; }
  .main { display: block; }
  .body { padding: 0; gap: 0; }

  .panel {
    border: 0;
    border-radius: 0;
    padding: 0 0 6px;
    margin: 0 0 8px;
  }
  /* 内容接着往上排，不要因为放不下就整块跳到下一页，白白空出一大片 */
  .panel + .panel { margin-top: 10px; }
  table, tr, td, th { break-inside: auto; }
  thead { display: table-header-group; }
  tr { break-inside: avoid; }
  .panel-title {
    border-bottom: 1px solid #666;
    padding-bottom: 4px;
    margin-bottom: 8px;
    font-weight: 600;
  }

  .print-only { display: block; }
  .print-head { text-align: center; margin-bottom: 16px; }
  .print-head h1 { font-size: 16px; margin: 0 0 6px; font-weight: 600; }
  .print-title { font-size: 19px; font-weight: 600; letter-spacing: 6px; margin: 8px 0; }
  .print-meta { font-size: 12px; color: #333; }
  .print-sign {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    margin-top: 28px;
    font-size: 12px;
  }
  .print-foot {
    margin-top: 18px;
    font-size: 11px;
    color: #444;
    border-top: 1px solid #ccc;
    padding-top: 6px;
  }

  /* 打印要把整张表缩进纸张宽度，不能左右滑动 */
  .scroll { overflow: visible !important; }
  .table-scroll-top { display: none !important; }
  table { font-size: 11px; width: 100% !important; }
  th, td { white-space: normal; word-break: break-word; }
  th {
    background: #eee !important;
    color: #000 !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  /* 排产单打印：只留 名称 / 代码 / 规格 / 批号 / 需求量，
     去掉算料过程和齐套等辅助列，字号再小一号，省纸 */
  .no-print-col,
  .print-compact .calc,
  .print-compact .print-hide { display: none !important; }
  .print-compact table { font-size: 10px; }
  .print-compact th,
  .print-compact td { padding: 3px 4px; }
  th, td { border-bottom: 1px solid #aaa; padding: 4px 6px; }
  a { color: #000; text-decoration: none; }
  .hint { color: #444 !important; }
  .tag { border: 1px solid #999; background: none !important; color: #000 !important; }
}
