:root {
  --bg: #f5f7f6;
  --panel: #ffffff;
  --ink: #1f2933;
  --muted: #697586;
  --line: #d9e1e7;
  --brand: #24745b;
  --brand-dark: #155d49;
  --accent: #c45824;
  --danger: #b42318;
  --warn: #a15c07;
  --ok: #1f7a4d;
  font-family: Inter, "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  -webkit-text-size-adjust: 100%;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 0;
  border-radius: 6px;
  background: var(--brand);
  color: #fff;
  min-height: 40px;
  padding: 0 14px;
  cursor: pointer;
  touch-action: manipulation;
}

button:hover {
  background: var(--brand-dark);
}

button:disabled,
button:disabled:hover {
  background: #b8c5c9;
  color: #ffffff;
  cursor: not-allowed;
}

button.secondary {
  background: #e8eef0;
  color: var(--ink);
}

button.danger {
  background: var(--danger);
}

input,
select,
textarea {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  padding: 8px 10px;
}

input:disabled,
select:disabled,
textarea:disabled {
  background: #f2f5f6;
  color: var(--muted);
}

textarea {
  min-height: 76px;
  resize: vertical;
}

input[type="checkbox"] {
  width: auto;
  min-height: auto;
  accent-color: var(--brand);
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: linear-gradient(135deg, #eef6f0, #f7f1e8);
}

.login-card {
  width: min(460px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 28px;
  box-shadow: 0 20px 50px rgba(31, 41, 51, 0.12);
}

.login-card h1 {
  margin: 0 0 8px;
  font-size: 28px;
}

.login-card p,
.muted {
  color: var(--muted);
}

.login-grid {
  display: grid;
  gap: 14px;
  margin-top: 24px;
}

.app-shell {
  display: grid;
  grid-template-columns: 238px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: #173f35;
  color: #f5fbf8;
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.brand {
  padding: 6px 8px 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.14);
}

.brand strong {
  display: block;
  font-size: 20px;
}

.brand span {
  color: rgba(255, 255, 255, 0.72);
  font-size: 13px;
}

.nav {
  display: grid;
  gap: 6px;
}

.nav button {
  justify-content: flex-start;
  text-align: left;
  background: transparent;
  color: #f5fbf8;
  padding: 10px 12px;
}

.nav button.active,
.nav button:hover {
  background: rgba(255, 255, 255, 0.14);
}

.user-box {
  margin-top: auto;
  padding: 12px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  font-size: 13px;
}

.main {
  min-width: 0;
  padding: 24px;
}

.topbar {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 18px;
}

/* v2.4.0：第一块（h1 + p）占满左侧，右侧 actions 自然贴右；
   去掉 space-between 依赖，让没有 actions 的页面 h1 也稳稳贴左。 */
.topbar > div:first-child {
  flex: 1;
  min-width: 0;
}

.topbar-actions {
  flex-shrink: 0;
}

.topbar h1 {
  margin: 0;
  font-size: 26px;
}

.grid {
  display: grid;
  gap: 16px;
}

.grid.two {
  grid-template-columns: minmax(280px, 390px) 1fr;
}

.stats {
  grid-template-columns: repeat(3, minmax(150px, 1fr));
}

.panel,
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.panel {
  padding: 18px;
}

.panel h2 {
  margin: 0 0 14px;
  font-size: 18px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(160px, 1fr));
  gap: 12px;
}

.form-grid .wide {
  grid-column: 1 / -1;
}

.batch-head {
  margin-bottom: 12px;
}

.batch-actions {
  margin-top: 12px;
}

.import-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 10px;
}

.file-upload {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: auto;
  /* v2.4.0：与标准 button 的 min-height: 40px 对齐，topbar-actions 里三按钮等高。 */
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid var(--ink);
  border-radius: 6px;
  background: var(--ink);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
  overflow: hidden;
}

.file-upload input {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  opacity: 0;
  pointer-events: none;
}

.import-message {
  min-height: 20px;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 13px;
}

.import-message.error {
  color: var(--danger);
}

.section-gap {
  /* v2.4.0：与 .topbar / .panel 的 18px 同档，间距收敛到 12/18px 两档。 */
  margin-top: 18px;
}

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

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

.transfer-stock {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f8faf9;
  color: var(--muted);
  font-size: 13px;
}

.filters {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 12px;
}

/* v2.4.0：筛选条里 select / input / date 统一高度，覆盖 input 默认 padding 差异；
   不用 min-height（让 date 控件不会比 select 高几像素）。 */
.filters select,
.filters input {
  height: 40px;
  width: min(220px, 100%);
}

/* v2.4.0：筛选条内 label（"从 [date]" "至 [date]"）改为横向 inline-flex，
   覆盖全局 label { display: grid } 的纵向布局；
   color/font-size 跟随正文（取消 muted 灰），与同行 select 视觉同档。 */
.filters label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: inherit;
  font-size: inherit;
}

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.batch-table {
  margin-top: 8px;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 720px;
}

.entry-table {
  min-width: 980px;
}

/* v2.5.0：食材列表新增「档口」列后变成 11 列，min-width 提升 ~110px 让档口 / 状态 select 不再被挤成只剩箭头。 */
#ingredientTable table {
  min-width: 1290px;
}

#ingredientTable th {
  white-space: nowrap;
}

#ingredientTable td[data-label="食材"] input,
#ingredientTable td[data-label="分类"] input {
  min-width: 140px;
}

#ingredientTable td[data-label="供应商"] select {
  min-width: 140px;
}

#ingredientTable td[data-label="单位"] input {
  min-width: 72px;
}

#ingredientTable td[data-label="单价"] input,
#ingredientTable td[data-label="库存"] input,
#ingredientTable td[data-label="预警"] input {
  min-width: 88px;
}

/* v2.5.0：「档口」select 要放下「未指定」/「后厨-凉菜」等中文 + 箭头；
   「状态」select 要放下「启用」/「停用」+ 箭头。给 min-width 让原本只显示箭头的 select 露出文字。 */
#ingredientTable td[data-label="档口"] select {
  min-width: 100px;
}

#ingredientTable td[data-label="状态"] select {
  min-width: 76px;
}

/* v2.4.0 修补：admin 兼任盘点员 + 出库员两身份时库存列表有 10 列，
   默认全局 table min-width: 720px 不够，列被挤导致：
   - 表头"分类"/"库存"/"预警线"竖排
   - 实盘 / 出库数量列 input 后跟的单位文本（"瓶"、"袋"等）被换到下一行
   - 操作列两个按钮"保存盘点"/"保存出库"换行
   解法：撑开表格 min-width 让 .table-wrap 触发横向滚动，
   关键 cell 标 nowrap，input 给固定宽度释放剩余空间给单位文本。 */
#inventoryTable table {
  min-width: 1180px;
}

#inventoryTable th {
  white-space: nowrap;
}

#inventoryTable td[data-label="实盘"],
#inventoryTable td[data-label="出库数量"],
#inventoryTable td[data-label="操作"] {
  white-space: nowrap;
}

#inventoryTable td[data-label="实盘"] input,
#inventoryTable td[data-label="出库数量"] input {
  width: 96px;
  min-width: 80px;
  display: inline-block;
  vertical-align: middle;
}

th,
td {
  padding: 11px 10px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  background: #f8faf9;
}

.entry-table td {
  vertical-align: middle;
}

.entry-table button {
  white-space: nowrap;
}

.quantity-tools {
  display: grid;
  grid-template-columns: minmax(110px, 1fr) auto;
  gap: 8px;
  align-items: center;
}

.quick-qty {
  display: flex;
  gap: 5px;
}

.quick-qty button {
  /* v2.4.0：与 .pagination button 对齐 32px，所有"小辅助按钮"同档。 */
  min-height: 32px;
  padding: 0 8px;
}

.mode-toggle {
  display: inline-flex;
  margin-bottom: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
}

.mode-toggle button {
  min-height: 34px;
  padding: 0 14px;
  border-radius: 0;
  background: #fff;
  color: var(--muted);
  font-size: 13px;
}

.mode-toggle button:hover {
  background: #f2f5f6;
}

.mode-toggle button.active {
  background: var(--brand);
  color: #fff;
}

.mode-toggle button.active:hover {
  background: var(--brand-dark);
}

.consolidated .group-row td {
  background: #eef4f1;
}

/* v2.0.0：供应商作为外层分组（采购页/合并视图） */
.consolidated .supplier-group-row td {
  background: #1f3a2e;
  color: #fff;
}

.supplier-group-head {
  display: flex;
  align-items: baseline;
  gap: 12px;
  padding: 4px 0;
}

.supplier-group-head strong {
  font-size: 15px;
}

.supplier-group-head .muted {
  color: rgba(255, 255, 255, 0.75);
  font-size: 12px;
}

.consolidated .group-row td {
  padding-left: 18px;
}

.group-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 14px;
}

.group-head .group-name {
  font-weight: 600;
  font-size: 15px;
}

.group-head .group-total {
  color: var(--muted);
  font-size: 13px;
}

.group-head .group-select-label,
.group-head .group-field {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--ink);
  font-size: 13px;
}

.group-head .group-field input {
  width: 130px;
  min-height: 34px;
}

.consolidated .demand-row td:first-child {
  padding-left: 26px;
}

.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 3px 9px;
  font-size: 12px;
  background: #e8eef0;
  color: var(--ink);
  white-space: nowrap;
}

.badge.warn {
  background: #fff2d6;
  color: var(--warn);
}

.badge.ok {
  background: #e5f6ed;
  color: var(--ok);
}

.badge.danger {
  background: #ffe7e5;
  color: var(--danger);
}

.badge.scope.main {
  background: #e8f1f7;
  color: #1d5f7a;
}

.badge.scope.branch {
  background: #f0ebfa;
  color: #5b3b91;
}

.badge.scope.airport {
  background: #e4f5ef;
  color: #25705b;
}

.stat {
  padding: 18px;
}

.stat span {
  color: var(--muted);
  font-size: 13px;
}

.stat strong {
  display: block;
  margin-top: 8px;
  font-size: 32px;
}

.message {
  margin-bottom: 14px;
  padding: 10px 12px;
  border-radius: 6px;
  background: #eaf4ee;
  color: var(--ok);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.message.error {
  background: #ffe7e5;
  color: var(--danger);
}

.message-action {
  flex: 0 0 auto;
  min-height: 32px;
  background: #ffffff;
  color: var(--danger);
  border: 1px solid rgba(180, 35, 24, 0.25);
}

.message-action:hover {
  background: #fff7f6;
}

.empty {
  padding: 20px;
  color: var(--muted);
  text-align: center;
}

@media (max-width: 860px) {
  .app-shell {
    grid-template-columns: 1fr;
    padding-bottom: calc(78px + env(safe-area-inset-bottom));
  }

  .sidebar {
    position: fixed;
    inset: auto 0 0;
    z-index: 10;
    display: block;
    padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
    border-top: 1px solid rgba(255, 255, 255, 0.12);
    box-shadow: 0 -12px 26px rgba(23, 63, 53, 0.22);
  }

  .brand,
  .user-box {
    display: none;
  }

  .nav {
    display: flex;
    overflow-x: auto;
    gap: 6px;
    scrollbar-width: none;
  }

  .nav::-webkit-scrollbar {
    display: none;
  }

  .nav button {
    flex: 0 0 auto;
    min-width: 78px;
    min-height: 48px;
    text-align: center;
    justify-content: center;
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 14px;
    white-space: nowrap;
  }

  .nav button.active {
    background: #ffffff;
    color: #173f35;
    font-weight: 700;
  }

  .main {
    padding: 18px 14px 20px;
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 14px;
  }

  .topbar h1 {
    font-size: 24px;
    line-height: 1.2;
  }

  .topbar p {
    margin: 6px 0 0;
  }

  .grid.two,
  .stats {
    grid-template-columns: 1fr;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .panel {
    padding: 14px;
  }

  .panel h2 {
    margin-bottom: 12px;
    font-size: 17px;
  }

  .stats {
    gap: 10px;
  }

  .stat {
    padding: 14px;
  }

  .stat strong {
    font-size: 28px;
  }

  .filters {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .filters select,
  .filters input,
  .filters button,
  .actions button {
    width: 100%;
  }

  .actions {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .row-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .message {
    align-items: stretch;
    flex-direction: column;
    font-size: 14px;
  }

  .message-action {
    width: 100%;
  }
}

@media (max-width: 640px) {
  .login-shell {
    align-items: start;
    min-height: 100svh;
    padding: 16px;
  }

  .login-card {
    margin-top: 9vh;
    padding: 22px 18px;
    box-shadow: 0 14px 34px rgba(31, 41, 51, 0.12);
  }

  .login-card h1 {
    font-size: 25px;
  }

  .login-grid {
    gap: 12px;
    margin-top: 20px;
  }

  input,
  select,
  textarea,
  button {
    min-height: 44px;
  }

  label {
    gap: 7px;
    font-size: 14px;
  }

  .table-wrap:not(.batch-table) {
    overflow: visible;
  }

  .table-wrap:not(.batch-table) table,
  .table-wrap:not(.batch-table) thead,
  .table-wrap:not(.batch-table) tbody,
  .table-wrap:not(.batch-table) tr,
  .table-wrap:not(.batch-table) th,
  .table-wrap:not(.batch-table) td {
    display: block;
    width: 100%;
    min-width: 0;
  }

  .table-wrap:not(.batch-table) table {
    border-collapse: separate;
    border-spacing: 0;
  }

  .table-wrap:not(.batch-table) thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
  }

  .table-wrap:not(.batch-table) tr {
    margin-bottom: 10px;
    padding: 11px 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #ffffff;
  }

  .table-wrap:not(.batch-table) td {
    display: grid;
    grid-template-columns: minmax(72px, 32%) minmax(0, 1fr);
    gap: 10px;
    align-items: start;
    padding: 7px 0;
    border-bottom: 0;
    line-height: 1.45;
    word-break: break-word;
  }

  .table-wrap:not(.batch-table) td:empty {
    display: none;
  }

  .table-wrap:not(.batch-table) td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 13px;
    line-height: 1.6;
  }

  .table-wrap:not(.batch-table) td[data-label="操作"] {
    grid-template-columns: 1fr;
  }

  .table-wrap:not(.batch-table) td[data-label="操作"]::before {
    display: none;
  }

  .table-wrap:not(.batch-table) td[data-label="操作"] button,
  .table-wrap:not(.batch-table) td[data-label="选择"] input[type="checkbox"] {
    justify-self: start;
  }

  .table-wrap:not(.batch-table) .badge {
    justify-self: start;
  }

  .batch-table {
    overflow: visible;
  }

  .batch-table table,
  .batch-table thead,
  .batch-table tbody,
  .batch-table tr,
  .batch-table th,
  .batch-table td {
    display: block;
    width: 100%;
    min-width: 0;
  }

  .batch-table thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
  }

  .batch-table tr {
    display: grid;
    gap: 10px;
    margin-bottom: 10px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fbfcfb;
  }

  .batch-table td {
    display: grid;
    gap: 6px;
    padding: 0;
    border-bottom: 0;
  }

  .batch-table td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 13px;
  }

  .batch-table td[data-label="选择"] {
    grid-template-columns: auto 1fr;
    align-items: center;
  }

  .batch-table td[data-label="选择"]::before {
    order: 2;
    color: var(--ink);
    font-size: 14px;
  }

  .batch-table input[type="checkbox"] {
    width: 22px;
    height: 22px;
    margin: 0;
  }

  .batch-table button {
    width: 100%;
  }

  .batch-table .quick-qty button {
    width: auto;
    flex: 1 1 0;
  }

  .batch-actions {
    position: sticky;
    bottom: calc(70px + env(safe-area-inset-bottom));
    z-index: 4;
    margin: 12px -14px -14px;
    padding: 10px 14px;
    border-top: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.96);
  }
}

@media (max-width: 420px) {
  .main {
    padding-right: 10px;
    padding-left: 10px;
  }

  .panel {
    padding: 12px;
  }

  .topbar h1 {
    font-size: 22px;
  }

  .nav button {
    min-width: 72px;
    padding-right: 10px;
    padding-left: 10px;
  }

  .table-wrap:not(.batch-table) td {
    grid-template-columns: minmax(68px, 34%) minmax(0, 1fr);
  }

  .batch-actions {
    margin-right: -12px;
    margin-left: -12px;
  }
}

/* v2.0.0 采购记录表头全选 checkbox */
.receive-all-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

/* v2.0.0 派单视图组卡片 */
.dispatch-group + .dispatch-group {
  margin-top: 18px;
}

.dispatch-group-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
}

.dispatch-group-head h2 {
  margin: 0;
}

.dispatch-group-head .muted {
  margin-top: 2px;
}

/* v2.2.0 派单页类别小标题行（供应商组内按 ingredients.category 二级分段） */
.dispatch-category-row td {
  background: #f4f6f5;
  font-weight: 600;
  color: #2f6b4e;
  font-size: 13px;
  padding: 6px 12px;
}

/* v2.0.0 PDF 打印页 */
.print-page {
  max-width: 760px;
  margin: 0 auto;
  padding: 32px 24px;
  color: #111;
  background: #fff;
}

.print-header h1 {
  margin: 0 0 6px;
}

.print-table {
  width: 100%;
  border-collapse: collapse;
}

.print-table th,
.print-table td {
  border: 1px solid #999;
  padding: 6px 8px;
  text-align: left;
}

/* v2.2.0 PDF 表格里的类别小标题行 */
.print-table .print-category-row td {
  background: #eef2ef;
  font-weight: 600;
  padding: 4px 8px;
}

.print-footer {
  margin-top: 18px;
}

.print-footer p {
  margin: 4px 0;
}

.print-controls {
  margin-top: 24px;
}

@media print {
  /* 打印时隐藏导航 / 顶栏 / 操作按钮 / 筛选条 */
  .nav,
  .topbar,
  .filters,
  .actions,
  .row-actions,
  .quick-qty,
  .import-tools,
  .print-controls,
  .message,
  button {
    display: none !important;
  }

  body {
    background: #fff !important;
    color: #000 !important;
  }

  .print-page {
    padding: 0;
    max-width: none;
  }

  .print-table th,
  .print-table td {
    border-color: #000;
  }

  .table-wrap {
    overflow: visible !important;
  }
}

.pagination {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0 4px;
  flex-wrap: wrap;
}

.pagination button {
  /* v2.4.0：显式 32px，避免继承全局 button min-height: 40px 太大，与小辅助按钮成档。 */
  min-height: 32px;
  padding: 4px 12px;
  font-size: 13px;
}

.pagination button[disabled] {
  opacity: 0.4;
  cursor: not-allowed;
}

/* v2.1.0：库存页顶部按钮区（导出 / 导入 CSV）。 */
.topbar-actions {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

/* v2.1.0：admin 看到的"0 数据"轻提示。 */
.banner {
  padding: 10px 14px;
  border-radius: 6px;
  margin-bottom: 14px;
  font-size: 14px;
}
.banner.warn {
  background: #fff5da;
  border: 1px solid #f5cf6e;
  color: #6a4a09;
}
.banner code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  background: rgba(0, 0, 0, 0.06);
  padding: 1px 6px;
  border-radius: 4px;
}

/* 导入预览页：原因输入框 100% 宽 */
.full-width-input {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
}
.full-width-input input {
  width: 100%;
  min-height: 38px;
  padding: 0 12px;
  border: 1px solid #d6d8de;
  border-radius: 6px;
  font-size: 14px;
}

/* "实盘"输入框窄一些，避免破坏行高 */
[data-stocktake-input] {
  width: 90px;
}

/* v2.6.0：数据看板 — 折线图 + 图例 + 空态。SVG 自适应宽度，图例可换行。 */
.chart-card svg { width: 100%; height: auto; display: block; }
.chart-card .chart-legend { display: flex; gap: 16px; flex-wrap: wrap; margin-top: 12px; font-size: 13px; }
.chart-card .chart-legend .swatch { display: inline-block; width: 12px; height: 12px; border-radius: 2px; margin-right: 6px; vertical-align: middle; }
.chart-card .chart-empty { padding: 40px 12px; text-align: center; color: var(--muted); }
