* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: #FAF7F4;
  color: #2A2520;
  line-height: 1.5;
  min-height: 100vh;
}
/* 弹窗打开时锁定底层页面滚动 */
body.modal-open {
  overflow: hidden !important;
  /* 不用 position:fixed，改用 touch-action 防止 iOS 穿透 */
  touch-action: none;
  height: 100vh;
  height: 100dvh;
}
.app {
  max-width: 1280px;
  margin: 0 auto;
  padding: 24px;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 20px;
  margin-bottom: 24px;
  border-bottom: 1px solid #E8DDD4;
  flex-wrap: wrap;
  gap: 12px;
}
.logo { display: flex; align-items: center; gap: 12px; }
.logo-mark {
  width: 38px; height: 38px;
  background: linear-gradient(135deg, #E8A09A, #C77B6F);
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 18px;
}
.logo h1 { font-size: 18px; font-weight: 600; }
.logo p { font-size: 12px; color: #8B7B6E; }
.actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.btn {
  padding: 8px 14px;
  border: 1px solid #D4C5B8;
  background: #fff;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  color: #4A3F35;
  font-family: inherit;
  transition: all 0.15s;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.btn:hover:not(:disabled) { background: #FAF4EE; border-color: #B89F8A; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary {
  background: #2A2520; color: #fff; border-color: #2A2520;
}
.btn-primary:hover:not(:disabled) { background: #1A1510; color: #fff; }
.btn-danger {
  background: #fff; color: #C0392B; border-color: #E8C5C0;
}
.btn-danger:hover:not(:disabled) { background: #FDF1EF; }
.btn-success {
  background: #fff; color: #27632A; border-color: #C0DD97;
}
.btn-sm { padding: 4px 10px; font-size: 12px; }

.role-badge {
  display: inline-flex; align-items: center;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 500;
  margin-right: 6px;
}
.role-boss { background: linear-gradient(135deg, #FFD700, #FFA500); color: #4A3000; }
.role-manager { background: #E8DAF7; color: #5B3B8C; }
.role-tech { background: #D7EBFA; color: #1D5A8C; }
.role-reception { background: #FCE4D6; color: #8C4A1D; }

.store-select {
  padding: 8px 12px;
  border: 1px solid #D4C5B8;
  border-radius: 8px;
  background: #fff;
  font-size: 13px;
  font-family: inherit;
  color: #4A3F35;
  cursor: pointer;
}

.user-menu, .dropdown { position: relative; display: inline-block; }
.dropdown-menu {
  display: none;
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  background: #fff;
  border: 1px solid #E8DDD4;
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(42, 37, 32, 0.12);
  min-width: 200px;
  z-index: 50;
  overflow: hidden;
}
.dropdown-menu.show { display: block; }
.dropdown-menu button {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  padding: 10px 14px;
  font-size: 13px;
  font-family: inherit;
  color: #2A2520;
  cursor: pointer;
}
.dropdown-menu button:hover { background: #FAF4EE; }
.dropdown-menu button + button { border-top: 1px solid #F4ECE2; }

nav {
  display: flex; gap: 4px;
  background: #fff;
  padding: 6px;
  border-radius: 12px;
  margin-bottom: 24px;
  border: 1px solid #E8DDD4;
  overflow-x: auto;
}

/* 移动端底部 nav 默认隐藏，由媒体查询控制 */
#mobileNav { display: none; }
nav button {
  background: transparent;
  border: none;
  padding: 9px 16px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  color: #6B5D52;
  font-family: inherit;
  white-space: nowrap;
  transition: all 0.15s;
  display: inline-flex; align-items: center; gap: 6px;
}
nav button:hover { background: #FAF4EE; color: #2A2520; }
nav button.active { background: #2A2520; color: #fff; }
nav button .badge-num {
  background: #C0392B;
  color: #fff;
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 10px;
  font-weight: 600;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.stat-card {
  background: #fff;
  border: 1px solid #E8DDD4;
  border-radius: 14px;
  padding: 18px 20px;
}
.stat-card .label { font-size: 12px; color: #8B7B6E; margin-bottom: 8px; }
.stat-card .value { font-size: 26px; font-weight: 600; color: #2A2520; }
.stat-card .sub { font-size: 11px; color: #8B7B6E; margin-top: 4px; }
.stat-card.urgent { background: #FDF1EF; border-color: #F0CFC9; }
.stat-card.urgent .value { color: #C0392B; }
.stat-card.warn { background: #FFFBF0; border-color: #F0E1C4; }
.stat-card.warn .value { color: #B7791F; }
.stat-card.ok { background: #F0F9E8; border-color: #C0DD97; }
.stat-card.ok .value { color: #27632A; }

.panel {
  background: #fff;
  border: 1px solid #E8DDD4;
  border-radius: 14px;
  overflow: hidden;
}
.panel-header {
  padding: 16px 20px;
  border-bottom: 1px solid #F0E8DE;
  display: flex; justify-content: space-between; align-items: center;
  flex-wrap: wrap; gap: 12px;
}
.panel-header h2 { font-size: 15px; font-weight: 600; }
.panel-tools { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
th {
  background: #FAF4EE;
  color: #6B5D52;
  font-weight: 500;
  text-align: left;
  padding: 10px 14px;
  border-bottom: 1px solid #E8DDD4;
  font-size: 12px;
  white-space: nowrap;
}
td {
  padding: 11px 14px;
  border-bottom: 1px solid #F4ECE2;
  vertical-align: middle;
}
tbody tr:hover { background: #FBF7F2; }
tbody tr:last-child td { border-bottom: none; }

.badge {
  display: inline-flex; align-items: center;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 500;
}
.badge.urgent { background: #FDEBE8; color: #C0392B; }
.badge.warn { background: #FFF6E0; color: #B7791F; }
.badge.ok { background: #E8F5EA; color: #27632A; }
.badge.cat { background: #F4ECE2; color: #6B5D52; }
.badge.pending { background: #E3F0FB; color: #1B6CA8; }
.badge.approved { background: #EDE7F6; color: #5E35B1; }
.badge.pending { background: #FFF6E0; color: #B7791F; }
.badge.approved { background: #E8F5EA; color: #27632A; }
.badge.rejected { background: #FDEBE8; color: #C0392B; }
.badge.received { background: #E8EFF7; color: #1D5A8C; }
.badge.cancelled { background: #F0F0F0; color: #6B5D52; }

input, select, textarea {
  font-family: inherit;
  font-size: 13px;
  padding: 8px 12px;
  border: 1px solid #D4C5B8;
  border-radius: 8px;
  background: #fff;
  color: #2A2520;
  outline: none;
}
input:focus, select:focus { border-color: #2A2520; }
input.search { width: 220px; }

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  padding: 20px;
  background: #FBF7F2;
  border-bottom: 1px solid #F0E8DE;
}
.form-grid label {
  display: flex; flex-direction: column; gap: 4px;
  font-size: 11px; color: #8B7B6E;
}
.form-grid .full { grid-column: 1 / -1; }
.form-actions {
  grid-column: 1 / -1;
  display: flex; gap: 8px; justify-content: flex-end;
}

.empty {
  padding: 60px 20px;
  text-align: center;
  color: #B0A091;
  font-size: 13px;
}

.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(42, 37, 32, 0.4);
  display: none;
  align-items: center; justify-content: center;
  z-index: 100;
  padding: 20px;
  /* 拦截底层滚动 */
  overflow: hidden;
  touch-action: none;
}
.modal-backdrop.show {
  display: flex;
  cursor: default;
}
.modal {
  background: #fff;
  border-radius: 14px;
  max-width: 540px;
  width: 100%;
  max-height: 90vh;
  max-height: 90dvh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  /* 关键：modal 内部恢复触摸滚动 */
  touch-action: pan-y;
}
.modal-lg { max-width: 720px; }
.modal-header {
  padding: 18px 22px;
  border-bottom: 1px solid #F0E8DE;
  display: flex; justify-content: space-between; align-items: center;
}
.modal-header h3 { font-size: 16px; font-weight: 600; }
.modal-close {
  background: none; border: none; font-size: 22px;
  cursor: pointer; color: #8B7B6E;
}

.toast {
  position: fixed;
  bottom: 24px; left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: #2A2520;
  color: #fff;
  padding: 10px 20px;
  border-radius: 24px;
  font-size: 13px;
  z-index: 200;
  transition: transform 0.3s;
}
.toast.show { transform: translateX(-50%) translateY(0); }

.purchase-line {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr 1.2fr 1.5fr 32px;
  gap: 8px;
  margin-bottom: 8px;
  align-items: center;
}
.purchase-line input, .purchase-line select { font-size: 12px; padding: 6px 10px; }
.purchase-line .line-subtotal {
  text-align: right;
  font-size: 13px;
  font-weight: 600;
  color: #C0392B;
  padding: 6px 10px;
  background: #FBF7F2;
  border-radius: 6px;
  font-variant-numeric: tabular-nums;
}
.purchase-line .remove {
  background: #FDEBE8;
  border: none;
  width: 28px; height: 28px;
  border-radius: 6px;
  cursor: pointer;
  color: #C0392B;
  font-size: 16px;
}

.review-detail {
  background: #FBF7F2;
  padding: 12px;
  border-radius: 8px;
  margin-bottom: 12px;
}
.review-detail .row {
  display: flex; justify-content: space-between;
  padding: 4px 0;
  font-size: 13px;
}
.review-detail .row span:first-child { color: #8B7B6E; }
.review-items table { background: #fff; border-radius: 8px; }

.num { text-align: right; font-variant-numeric: tabular-nums; }
.muted { color: #8B7B6E; font-size: 12px; }

.hidden { display: none !important; }

.month-picker { display: flex; gap: 8px; align-items: center; }
.month-picker select { padding: 6px 10px; }

/* ============================================================
   移动端适配 (≤ 768px)
   策略：底部导航栏 + 卡片化表格 + 大触控区域
   ============================================================ */
@media (max-width: 768px) {

  /* === 基础布局 === */
  body { padding-bottom: 70px; } /* 给底部 nav 留空间 */
  .app { padding: 12px 12px 0; max-width: 100%; }

  /* === 顶部 header：精简 === */
  header {
    padding-bottom: 12px;
    margin-bottom: 16px;
    gap: 8px;
  }
  .logo-mark { width: 32px; height: 32px; font-size: 15px; border-radius: 9px; }
  #appName { font-size: 15px; }
  #storeIndicator { font-size: 11px; }

  /* header 右侧：门店选择 + 用户菜单，隐藏导出按钮 */
  .actions { gap: 6px; }
  #exportBtn { display: none; } /* 移动端隐藏 Excel 导出 */
  .store-select { padding: 6px 8px; font-size: 12px; max-width: 100px; }
  .user-menu .btn { padding: 6px 10px; font-size: 12px; }
  .role-badge { margin-right: 3px; }

  /* === 顶部横向 nav：隐藏，改用底部 tab bar === */
  #mainNav { display: none; }

  /* === 底部 tab bar === */
  #mobileNav {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    height: 60px;
    background: #fff;
    border-top: 1px solid #E8DDD4;
    display: flex;
    z-index: 200;
    box-shadow: 0 -2px 12px rgba(42, 37, 32, 0.08);
    /* safe area for iPhone 底部刘海 */
    padding-bottom: env(safe-area-inset-bottom, 0);
  }
  #mobileNav button {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    cursor: pointer;
    font-family: inherit;
    color: #8B7B6E;
    font-size: 10px;
    gap: 3px;
    padding: 6px 2px;
    position: relative;
    transition: color 0.15s;
    -webkit-tap-highlight-color: transparent;
  }
  #mobileNav button .nav-icon { font-size: 20px; line-height: 1; }
  #mobileNav button.active { color: #2A2520; font-weight: 600; }
  #mobileNav button.active::after {
    content: '';
    position: absolute;
    top: 0; left: 25%; right: 25%;
    height: 2px;
    background: #2A2520;
    border-radius: 0 0 3px 3px;
  }
  #mobileNav .badge-num {
    position: absolute;
    top: 4px; right: calc(50% - 18px);
    background: #C0392B;
    color: #fff;
    font-size: 9px;
    padding: 1px 5px;
    border-radius: 10px;
    font-weight: 700;
  }

  /* === 桌面 nav 的 badge 也更新 === */
  nav button .badge-num { font-size: 9px; padding: 1px 5px; }

  /* === section 间距 === */
  section[id^="tab-"] { padding-bottom: 8px; }

  /* === KPI 卡片：2 列 === */
  .stats-grid {
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 16px;
  }
  .stat-card { padding: 14px 14px; border-radius: 12px; }
  .stat-card .label { font-size: 11px; }
  .stat-card .value { font-size: 22px; }
  .stat-card .sub { font-size: 10px; }

  /* === Panel === */
  .panel { border-radius: 12px; margin-bottom: 14px; }
  .panel-header { padding: 12px 14px; flex-wrap: wrap; gap: 8px; }
  .panel-header h2 { font-size: 14px; }

  /* === 按钮尺寸加大方便触控 === */
  .btn { padding: 9px 14px; font-size: 13px; }
  .btn-sm { padding: 7px 12px; font-size: 12px; }

  /* === 表格改卡片式 === */
  #productsTable table,
  #inboundTable table,
  #outboundTable table,
  #usersTable table,
  #storesTable table,
  #categoriesTable table,
  #urgentList table,
  #pendingList table,
  #alertsTable table,
  #purchasesList table {
    display: block;
  }
  #productsTable thead,
  #inboundTable thead,
  #outboundTable thead,
  #usersTable thead,
  #storesTable thead,
  #categoriesTable thead,
  #urgentList thead,
  #pendingList thead,
  #alertsTable thead,
  #purchasesList thead { display: none; }

  #productsTable tbody,
  #inboundTable tbody,
  #outboundTable tbody,
  #usersTable tbody,
  #storesTable tbody,
  #categoriesTable tbody,
  #urgentList tbody,
  #pendingList tbody,
  #alertsTable tbody,
  #purchasesList tbody { display: block; }

  #productsTable tr,
  #inboundTable tr,
  #outboundTable tr,
  #usersTable tr,
  #storesTable tr,
  #categoriesTable tr,
  #urgentList tr,
  #pendingList tr,
  #alertsTable tr,
  #purchasesList tr {
    display: flex;
    flex-wrap: wrap;
    padding: 12px 14px;
    border-bottom: 1px solid #F0E8DE;
    gap: 4px 10px;
    align-items: center;
  }
  #productsTable tr:last-child,
  #inboundTable tr:last-child,
  #outboundTable tr:last-child,
  #usersTable tr:last-child,
  #storesTable tr:last-child,
  #categoriesTable tr:last-child,
  #urgentList tr:last-child,
  #pendingList tr:last-child,
  #alertsTable tr:last-child,
  #purchasesList tr:last-child { border-bottom: none; }

  #productsTable td,
  #inboundTable td,
  #outboundTable td,
  #usersTable td,
  #storesTable td,
  #categoriesTable td,
  #urgentList td,
  #pendingList td,
  #alertsTable td,
  #purchasesList td {
    display: inline;
    padding: 0;
    border: none;
    font-size: 13px;
  }

  /* 操作按钮独占一行 */
  #productsTable td:last-child,
  #inboundTable td:last-child,
  #outboundTable td:last-child,
  #usersTable td:last-child,
  #storesTable td:last-child,
  #categoriesTable td:last-child,
  #pendingList td:last-child,
  #purchasesList td:last-child {
    display: block;
    width: 100%;
    margin-top: 8px;
  }
  /* 待审批/采购列表的操作按钮区域 */
  #pendingList td:last-child .btn,
  #purchasesList td:last-child .btn {
    margin-right: 6px;
  }

  /* 紧急补货 / 进货提醒里的按钮靠右且不换行 */
  #urgentList .btn,
  #alertsTable .btn {
    white-space: nowrap;
    font-size: 12px;
    padding: 6px 12px;
  }
  #urgentList td:last-child,
  #alertsTable td:last-child {
    margin-left: auto;
  }

  /* === 搜索框宽度 === */
  input.search { width: 100%; margin-bottom: 8px; }
  .panel-header { flex-direction: column; align-items: flex-start; }
  .panel-header > * { width: 100%; }
  .panel-header > button, .panel-header > .btn { width: auto; }

  /* === 采购 modal 明细 === */
  .purchase-line {
    grid-template-columns: 1fr 1fr;
    gap: 6px;
  }
  .purchase-line select { grid-column: 1 / -1; }
  .purchase-line .line-subtotal { grid-column: 1 / -1; text-align: center; }
  #purchaseLinesHeader { display: none !important; }

  /* === 表单 === */
  .form-grid { gap: 12px; }
  .form-grid label { font-size: 13px; }
  .form-grid input, .form-grid select, .form-grid textarea {
    padding: 10px 12px;
    font-size: 14px; /* 防止 iOS 自动缩放 */
  }

  /* === modal === */
  .modal-backdrop { align-items: flex-end; padding: 0; }
  .modal {
    max-width: 100%;
    border-radius: 20px 20px 0 0;
    /* 减掉底部导航栏高度 */
    max-height: calc(100vh - 65px);
    max-height: calc(100dvh - 65px);
    margin: 0;
    margin-bottom: calc(60px + env(safe-area-inset-bottom, 0px));
    animation: slideUp 0.25s ease;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    touch-action: pan-y;
  }
  /* 底部操作按钮粘在弹窗可视区域底部 */
  .modal .form-actions {
    position: sticky;
    bottom: 0;
    background: #fff;
    padding: 12px 20px;
    padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
    border-top: 1px solid #F0E8DE;
    z-index: 5;
    margin: 0 -22px -22px;
    /* 加宽让它贴满 modal 两边 */
    width: calc(100% + 44px);
  }
  @keyframes slideUp {
    from { transform: translateY(60px); opacity: 0.7; }
    to { transform: translateY(0); opacity: 1; }
  }
  .modal-lg { max-width: 100%; }

  /* === 月份选择器 === */
  .month-picker { flex-wrap: wrap; gap: 6px; }
  .month-picker select { padding: 8px 10px; }

  /* === 进货提醒按类别分组：隐藏部分列 === */
  #alertsTable td:nth-child(3),
  #alertsTable td:nth-child(4) { display: none; } /* 规格、当前库存 在别处有 */

  /* === 最近活动 === */
  #recentActivity table { display: block; }
  #recentActivity thead { display: none; }
  #recentActivity tbody { display: block; }
  #recentActivity tr {
    display: flex; flex-wrap: wrap;
    padding: 10px 14px;
    border-bottom: 1px solid #F0E8DE;
    gap: 4px 10px;
    align-items: center;
  }
  #recentActivity td { display: inline; padding: 0; border: none; font-size: 12px; }
}

/* 超小屏幕 (≤ 400px) 进一步精简 */
@media (max-width: 400px) {
  .stats-grid { gap: 8px; }
  .stat-card .value { font-size: 20px; }
  #appName { font-size: 14px; }
  .actions { gap: 4px; }
}
