/* ===== 全局 ===== */
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
               "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: #f5f7fa;
  color: #222;
  font-size: 16px;
  -webkit-tap-highlight-color: transparent;
}
body { min-height: 100vh; }
button { font: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, select, textarea { font: inherit; }
a { color: #1976d2; text-decoration: none; }
a:hover { text-decoration: underline; }
ul { list-style: none; }

/* ===== 登录页 ===== */
.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  padding: 20px;
  min-height: 100vh;
}
.login-card {
  background: white;
  padding: 40px 28px;
  border-radius: 16px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
  width: 100%;
  max-width: 380px;
}
.login-card h1 { font-size: 24px; margin-bottom: 4px; }
.login-card .subtitle { color: #888; font-size: 13px; margin-bottom: 24px; }
.login-card label { display: block; margin-bottom: 16px; font-size: 13px; color: #555; }
.login-card label span { display: block; margin-bottom: 6px; }
.login-card input {
  width: 100%;
  padding: 12px 14px;
  border: 1.5px solid #e0e0e0;
  border-radius: 8px;
  margin-top: 4px;
}
.login-card input:focus { outline: none; border-color: #667eea; }
.login-card .btn-primary {
  width: 100%;
  padding: 12px;
  background: linear-gradient(135deg, #667eea, #764ba2);
  color: white;
  border-radius: 8px;
  font-size: 16px;
  font-weight: 600;
  margin-top: 8px;
}
.login-card .btn-primary:disabled { opacity: 0.6; }
.login-card .error { color: #d32f2f; font-size: 14px; margin-top: 12px; min-height: 1em; text-align: center; }

/* ===== 顶部栏 ===== */
.app-header {
  background: white;
  border-bottom: 1px solid #e8e8e8;
  padding: 12px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 100;
}
.app-header .logo { font-size: 18px; font-weight: 600; }
.app-header .user-info { display: flex; gap: 12px; align-items: center; font-size: 14px; color: #666; }
.app-header .btn-link { color: #1976d2; padding: 4px 8px; }
.app-header .btn-link:hover { text-decoration: underline; }

/* ===== 主区 ===== */
.app-main { padding: 20px 20px 76px; max-width: 1200px; margin: 0 auto; }

/* ===== 底部导航 ===== */
.app-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: white;
  border-top: 1px solid #e8e8e8;
  display: flex;
  z-index: 100;
  box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.06);
  padding-bottom: env(safe-area-inset-bottom, 0);
}
.app-nav a {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 2px 10px;
  color: #999;
  font-size: 12px;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}
.app-nav a .nav-icon { font-size: 21px; line-height: 1; margin-bottom: 3px; }
.app-nav a.active { color: #1976d2; }
.app-nav a.active .nav-icon { transform: translateY(-1px); }
.welcome-card { background: white; padding: 28px; border-radius: 12px; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06); }
.welcome-card h2 { font-size: 22px; margin-bottom: 12px; color: #333; }
.welcome-card > p { color: #666; margin-bottom: 24px; }
.quick-links {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}
.quick-link {
  display: block;
  padding: 16px;
  background: #f0f4ff;
  border-radius: 8px;
  text-align: center;
  color: #1976d2;
  font-weight: 500;
}
.quick-link:hover { background: #e0eaff; text-decoration: none; }
.quick-link.disabled { background: #f5f5f5; color: #999; pointer-events: none; }

.m1-status { background: #f0fdf4; border-left: 4px solid #4caf50; padding: 16px 20px; border-radius: 6px; }
.m1-status h3 { color: #2e7d32; font-size: 16px; margin-bottom: 8px; }
.m1-status ul li { padding: 4px 0; color: #555; font-size: 14px; }
.m1-status ul li::before { content: '✓ '; color: #4caf50; font-weight: bold; }

/* ===== 通用按钮 ===== */
.btn { padding: 8px 16px; border-radius: 6px; font-size: 14px; transition: opacity 0.2s; }
.btn:hover { opacity: 0.85; }
.btn-primary { background: #1976d2; color: white; }
.btn-success { background: #2e7d32; color: white; }
.btn-danger { background: #d32f2f; color: white; }
.btn-secondary { background: #e0e0e0; color: #333; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-mini { padding: 5px 10px; font-size: 13px; background: #ffb300; color: #222; border-radius: 6px; border: none; cursor: pointer; white-space: nowrap; }
.btn-mini:hover { opacity: 0.85; }

/* ===== 通用卡片 ===== */
.card { background: white; padding: 20px; border-radius: 12px; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06); margin-bottom: 16px; }
.card h2, .card h3 { margin-bottom: 16px; color: #333; }

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%);
  padding: 12px 24px;
  border-radius: 8px;
  color: white;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
  opacity: 0;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 1000;
  pointer-events: none;
  max-width: 90%;
  text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast-info { background: #1976d2; }
.toast-success { background: #2e7d32; }
.toast-error { background: #d32f2f; }

/* ===== 表单 ===== */
.form-row { margin-bottom: 14px; }
.form-row label { display: block; font-size: 13px; color: #555; margin-bottom: 6px; }
.form-row input, .form-row select, .form-row textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid #e0e0e0;
  border-radius: 6px;
}
.form-row input:focus, .form-row select:focus, .form-row textarea:focus {
  outline: none;
  border-color: #1976d2;
}
.form-row .hint { font-size: 12px; color: #888; margin-top: 4px; }

/* ===== 页面框架 ===== */
.page-title { font-size: 22px; color: #222; }
.page-sub { color: #777; font-size: 13px; margin-top: 4px; }
.page-bar { display: flex; justify-content: space-between; align-items: flex-end; margin-bottom: 16px; gap: 12px; }
.empty { text-align: center; padding: 48px 20px; color: #999; background: white; border-radius: 12px; border: 1px dashed #ddd; }

/* ===== 模块导航 ===== */
.module-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; margin-top: 16px; }
.module-card { display: block; background: white; border: 1px solid #e8ebf0; border-radius: 12px; padding: 18px; transition: box-shadow .15s, transform .15s; }
.module-card:hover { box-shadow: 0 4px 16px rgba(0,0,0,.08); text-decoration: none; }
.module-card.disabled { background: #fafbfc; color: #999; cursor: default; }
.mod-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.mod-name { font-size: 16px; font-weight: 600; color: #222; }
.mod-tag { font-size: 11px; padding: 2px 8px; border-radius: 10px; white-space: nowrap; }
.mod-tag.ready { background: #e6f4ea; color: #2e7d32; }
.mod-tag.dev { background: #f1f3f4; color: #999; }
.mod-desc { font-size: 13px; color: #777; line-height: 1.5; }

/* ===== 柜子列表 ===== */
.cab-grid-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.cab-card { background: white; border: 1px solid #e8ebf0; border-radius: 12px; padding: 16px; display: flex; flex-direction: column; }
.cab-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.cab-title { font-size: 16px; font-weight: 600; color: #222; }
.cab-tags { display: flex; gap: 6px; flex-wrap: wrap; }
.tag { font-size: 11px; padding: 2px 8px; background: #eef2ff; color: #3949ab; border-radius: 10px; white-space: nowrap; }
.tag-gray { background: #f0f2f5; color: #777; }
.cab-meta { font-size: 13px; color: #666; margin: 6px 0; }
.cab-remark { font-size: 12px; color: #999; margin-bottom: 6px; word-break: break-all; }
.cab-actions { margin-top: 12px; display: flex; gap: 8px; }

/* ===== 二维网格 ===== */
.cab-grid { display: grid; gap: 3px; grid-template-columns: repeat(var(--cols, 4), 1fr); margin-top: 10px; max-width: 260px; }
.cell { aspect-ratio: 1 / 1; display: flex; align-items: center; justify-content: center; font-size: 10px; border-radius: 4px; padding: 2px; text-align: center; overflow: hidden; line-height: 1.1; }
.cell.empty { background: #f3f5f8; color: #b0b8c4; }
.cell.occupied { background: #e3f0ff; color: #1565c0; font-weight: 600; flex-direction: column; align-items: stretch; justify-content: flex-start; gap: 1px; cursor: pointer; }
.cell.occupied.has-low { border: 1.5px solid #ef9a9a; }
.cell .ci { display: flex; justify-content: space-between; align-items: center; width: 100%; font-size: 9px; line-height: 1.15; padding: 0 2px; }
.cell .ci.low { color: #d32f2f; }
.cell .ci-n { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-align: left; }
.cell .ci-q { flex-shrink: 0; margin-left: 2px; }
.cell .ci.more { color: #666; font-style: italic; justify-content: center; }

/* ===== 格内明细弹窗 ===== */
.cd-item { display: flex; gap: 12px; align-items: center; padding: 10px; border: 1px solid #eee; border-radius: 8px; margin-bottom: 10px; }
.cd-item.low { border-color: #efb8b8; background: #fff8f8; }
.cd-thumb { width: 48px; height: 48px; border-radius: 6px; object-fit: cover; flex-shrink: 0; background: #f0f2f5; display: flex; align-items: center; justify-content: center; color: #bbb; font-size: 10px; overflow: hidden; }
.cd-thumb img { width: 100%; height: 100%; object-fit: cover; }
.cd-info { flex: 1; min-width: 0; }
.cd-name { font-size: 15px; font-weight: 600; color: #222; }
.cd-qty { font-size: 13px; color: #555; margin-top: 2px; }
.cd-qty .tag { margin-left: 6px; }

/* ===== 弹窗 ===== */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex; align-items: center; justify-content: center; z-index: 500; padding: 16px; }
.modal.hidden { display: none; }
.modal-box { background: #fff; border-radius: 12px; width: 100%; max-width: 460px; max-height: 92vh; overflow: auto; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid #eee; }
.modal-head h3 { font-size: 18px; color: #222; }
.modal-x { font-size: 20px; color: #888; line-height: 1; padding: 4px; }
.modal-body { padding: 20px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 8px; }
.form-label { font-size: 13px; color: #555; display: block; margin-bottom: 6px; }
.form-row.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 14px; }

/* ===== 搜索条 ===== */
.search-bar { display: flex; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; align-items: center; }
.search-bar input[type=text] { flex: 1; min-width: 200px; padding: 10px 12px; border: 1.5px solid #e0e0e0; border-radius: 8px; }
.search-bar input[type=text]:focus { outline: none; border-color: #1976d2; }

/* ===== 统计条（总览）===== */
.stat-bar { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.stat-chip { background: white; border: 1px solid #e8ebf0; border-radius: 10px; padding: 12px 18px; min-width: 110px; }
.stat-chip .num { font-size: 24px; font-weight: 700; color: #1976d2; }
.stat-chip.warn .num { color: #d32f2f; }
.stat-chip .lbl { font-size: 12px; color: #777; margin-top: 2px; }

/* ===== 物品列表 ===== */
.item-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; }
.item-card { background: white; border: 1px solid #e8ebf0; border-radius: 12px; padding: 14px; display: flex; gap: 12px; position: relative; }
.item-card.low { border-color: #efb8b8; background: #fff8f8; }
.item-thumb { width: 64px; height: 64px; border-radius: 8px; background: #f0f2f5; object-fit: cover; flex-shrink: 0; display: flex; align-items: center; justify-content: center; color: #bbb; font-size: 11px; overflow: hidden; }
.item-thumb img { width: 100%; height: 100%; object-fit: cover; }
.item-info { flex: 1; min-width: 0; }
.item-name { font-size: 16px; font-weight: 600; color: #222; }
.item-loc { font-size: 12px; color: #888; margin: 2px 0; }
.item-meta { font-size: 13px; color: #555; display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.item-qty { font-weight: 700; color: #1976d2; }
.item-card.low .item-qty { color: #d32f2f; }
.badge { font-size: 11px; padding: 2px 8px; border-radius: 10px; white-space: nowrap; }
.badge-low { background: #fde0e0; color: #d32f2f; }
.badge-ok { background: #e6f4ea; color: #2e7d32; }
.item-actions { display: flex; gap: 6px; margin-top: 8px; }
.item-actions .btn { padding: 5px 12px; font-size: 13px; }

/* ===== 进库多行表单 ===== */
.inbound-list { display: flex; flex-direction: column; gap: 12px; margin-bottom: 16px; }
.inbound-row { background: white; border: 1px solid #e8ebf0; border-radius: 10px; padding: 12px; position: relative; }
.inbound-row .row-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.inbound-row .row-idx { font-size: 13px; color: #888; font-weight: 600; }
.inbound-row .row-fields { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 8px; }
.inbound-row .row-fields.wide { grid-template-columns: 2fr 1fr 1fr 1fr 1fr; }
.inbound-row label { font-size: 11px; color: #777; display: block; margin-bottom: 3px; }
.inbound-row input, .inbound-row select { width: 100%; padding: 8px 10px; border: 1.5px solid #e0e0e0; border-radius: 6px; font-size: 14px; }
.inbound-row input:focus, .inbound-row select:focus { outline: none; border-color: #1976d2; }
.inbound-row .locked { background: #f3f5f8; color: #999; }
.inbound-row .photo-row { margin-top: 8px; display: flex; align-items: center; gap: 10px; }
.inbound-row .photo-row input[type=file] { font-size: 13px; }
.inbound-row .thumb-prev { width: 40px; height: 40px; border-radius: 6px; object-fit: cover; display: none; }
.inbound-row .del-row { color: #d32f2f; font-size: 13px; }
.autofill-hint { font-size: 11px; color: #2e7d32; margin-top: 4px; }

/* ===== 总览紧凑网格 ===== */
.ov-grid-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; }
.ov-card { background: white; border: 1px solid #e8ebf0; border-radius: 12px; padding: 14px; }
.ov-card.hidden-by-search { display: none; }
.ov-card.match { border-color: #1976d2; box-shadow: 0 0 0 2px #1976d2 inset; }
.ov-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 4px; }
.ov-name { font-size: 15px; font-weight: 600; }
.ov-meta { font-size: 12px; color: #888; margin-bottom: 8px; }
.ov-cell-name { font-size: 9px; line-height: 1.05; word-break: break-all; }
.ov-cell.occupied { background: #e3f0ff; color: #1565c0; font-weight: 600; }
.ov-cell.occupied.low { background: #fde0e0; color: #d32f2f; }
.ov-cell .qty { display: block; font-size: 11px; }

/* ===== 首页提醒红点 ===== */
.mod-badge {
  position: absolute; top: 8px; right: 8px;
  min-width: 20px; height: 20px; padding: 0 6px;
  background: #d32f2f; color: #fff; border-radius: 10px;
  font-size: 12px; font-weight: 700; line-height: 20px; text-align: center;
}
.module-card { position: relative; }

/* ===== 物品卡片（库存/提醒复用）===== */
.item-body { flex: 1; min-width: 0; }
.item-thr { font-size: 12px; color: #999; margin-top: 4px; }
.item-thumb-empty { display: flex; align-items: center; justify-content: center; color: #bbb; font-size: 11px; }
.tag-red { background: #fde0e0; color: #d32f2f; }
.tag-orange { background: #fff0e0; color: #e65100; }
.card-warn { border-color: #f0c8a0; background: #fffaf3; }
.card-danger { border-color: #efb8b8; background: #fff8f8; }

/* ===== 出库表单 ===== */
.row-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.tbl-wrap { overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; background: white; border-radius: 10px; overflow: hidden; min-width: 640px; }
.tbl th, .tbl td { padding: 8px 6px; border-bottom: 1px solid #eee; text-align: left; font-size: 13px; vertical-align: middle; }
.tbl th { background: #f7f9fc; color: #555; font-weight: 600; }
.cell-in { width: 100%; padding: 7px 8px; border: 1.5px solid #e0e0e0; border-radius: 6px; font-size: 14px; box-sizing: border-box; }
.cell-in:focus { outline: none; border-color: #1976d2; }
.tbl input[type=date].cell-in { min-width: 130px; }
.btn-block { width: 100%; }
.photo-preview { margin-top: 10px; }
.photo-preview img { max-width: 160px; max-height: 160px; border-radius: 8px; border: 1px solid #eee; }
.result-box { margin-top: 16px; background: #f0fdf4; border: 1px solid #b7e4c7; border-radius: 10px; padding: 14px; display: none; }
.result-box.show { display: block; }
.result-title { font-weight: 600; color: #2e7d32; margin-bottom: 6px; }
.result-box ul { padding-left: 18px; font-size: 13px; color: #444; }
.result-box li { margin: 2px 0; }
.search-bar select { padding: 10px 12px; border: 1.5px solid #e0e0e0; border-radius: 8px; font-size: 14px; background: #fff; }

/* ===== 移动端 ===== */
@media (max-width: 640px) {
  .page-bar { flex-direction: column; align-items: stretch; }
  .cab-grid-list { grid-template-columns: 1fr; }
  .module-grid { grid-template-columns: 1fr; }
  .form-row.two { grid-template-columns: 1fr; }
  .cab-grid { max-width: 100%; }
}
@media (max-width: 640px) {
  .app-main { padding: 12px; }
  .welcome-card, .card { padding: 18px 14px; }
  .app-header { padding: 10px 14px; }
  .app-header .logo { font-size: 16px; }
  .quick-links { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .quick-link { padding: 12px 8px; font-size: 13px; }
}

/* ===== 历史页 / 报表页 ===== */
.filter-bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 14px; }
.filter-bar select, .filter-bar input[type=text], .filter-bar input[type=date] {
  padding: 9px 10px; border: 1.5px solid #e0e0e0; border-radius: 8px; font-size: 14px; background: #fff; min-width: 110px;
}
.filter-bar input[type=text] { flex: 1; min-width: 130px; }
.filter-bar .btn-link { margin-left: auto; }

.table-wrap { overflow-x: auto; background: #fff; border-radius: 12px; border: 1px solid #eee; }
.data-table { width: 100%; border-collapse: collapse; min-width: 880px; }
.data-table th, .data-table td { padding: 9px 8px; border-bottom: 1px solid #f0f0f0; text-align: left; font-size: 13px; vertical-align: middle; white-space: nowrap; }
.data-table th { background: #f7f9fc; color: #555; font-weight: 600; position: sticky; top: 0; }
.data-table tbody tr:hover { background: #fafcff; }
.thumb-mini { width: 38px; height: 38px; object-fit: cover; border-radius: 6px; border: 1px solid #eee; }
.tag-in { background: #e6f4ea; color: #2e7d32; }
.tag-out { background: #fdecea; color: #c0392b; }
.empty-tip { text-align: center; color: #aaa; padding: 28px; font-size: 14px; }

.report-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }
.report-card { background: #fff; border: 1px solid #eee; border-radius: 12px; padding: 14px 16px 18px; }
.report-title { font-size: 14px; font-weight: 600; color: #333; margin-bottom: 10px; }
.chart-box { position: relative; height: 260px; }
@media (max-width: 760px) {
  .report-grid { grid-template-columns: 1fr; }
  .filter-bar .btn-link { margin-left: 0; }
}