:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-soft: #eff6ff;
  --bg: #d4dcea;
  --card: #ffffff;
  --border: #e5e7eb;
  --text: #1f2937;
  --muted: #6b7280;
  --success: #16a34a;
  --danger: #dc2626;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .05);
  --shadow: 0 1px 3px rgba(16, 24, 40, .07), 0 1px 2px rgba(16, 24, 40, .05);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, .12);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", "Microsoft YaHei", "PingFang SC", sans-serif;
  background: var(--bg);
  background-image:
    radial-gradient(1200px 620px at 6% -8%, rgba(59, 130, 246, 0.18) 0%, rgba(59, 130, 246, 0) 60%),
    radial-gradient(1000px 560px at 100% -4%, rgba(139, 92, 246, 0.16) 0%, rgba(139, 92, 246, 0) 58%),
    radial-gradient(920px 520px at 50% 118%, rgba(34, 211, 238, 0.14) 0%, rgba(34, 211, 238, 0) 56%),
    radial-gradient(760px 440px at -2% 102%, rgba(236, 72, 153, 0.08) 0%, rgba(236, 72, 153, 0) 56%);
  background-attachment: fixed;
  color: var(--text);
  line-height: 1.6;
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
}

/* 导航栏 */
.navbar {
  background: rgba(255, 255, 255, 0.78);
  backdrop-filter: blur(14px) saturate(1.4);
  -webkit-backdrop-filter: blur(14px) saturate(1.4);
  border-bottom: 1px solid rgba(229, 231, 235, 0.7);
  box-shadow: var(--shadow-sm);
  position: sticky; top: 0; z-index: 50;
}
.navbar-inner {
  max-width: 1060px; margin: 0 auto;
  display: flex; align-items: center; gap: 20px;
  padding: 0 20px; height: 60px;
}
.brand { font-weight: 800; color: var(--primary); font-size: 17px; white-space: nowrap; letter-spacing: .2px; }
.nav-collapse { display: flex; align-items: center; gap: 20px; flex: 1; min-width: 0; }
.nav-links { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
.nav-links a {
  padding: 7px 13px; border-radius: 9px;
  color: var(--text); text-decoration: none; font-size: 14px; font-weight: 500;
  transition: background .12s, color .12s;
}
.nav-links a:hover { background: var(--primary-soft); color: var(--primary); }
.nav-links a.active {
  background: linear-gradient(135deg, #2563eb, #1d4ed8); color: #fff;
  box-shadow: 0 2px 6px rgba(37, 99, 235, .3);
}
.nav-links a.active:hover { background: linear-gradient(135deg, #1d4ed8, #1e40af); color: #fff; }
.nav-user { display: flex; align-items: center; gap: 12px; font-size: 14px; white-space: nowrap; color: var(--muted); }
.nav-name { font-weight: 600; color: var(--text); }
.nav-user a { color: var(--muted); text-decoration: none; transition: color .12s; }
.nav-user a:hover { color: var(--danger); }

/* 汉堡按钮（移动端） */
.nav-toggle {
  display: none; width: 40px; height: 40px; padding: 0;
  background: none; border: none; cursor: pointer; position: relative; border-radius: 8px;
}
.nav-toggle span {
  position: absolute; left: 10px; right: 10px; height: 2px;
  background: var(--text); border-radius: 2px; transition: transform .18s, opacity .18s, top .18s;
}
.nav-toggle span:nth-child(1) { top: 13px; }
.nav-toggle span:nth-child(2) { top: 19px; }
.nav-toggle span:nth-child(3) { top: 25px; }
.navbar.open .nav-toggle span:nth-child(1) { top: 19px; transform: rotate(45deg); }
.navbar.open .nav-toggle span:nth-child(2) { opacity: 0; }
.navbar.open .nav-toggle span:nth-child(3) { top: 19px; transform: rotate(-45deg); }

/* 容器 */
.container { max-width: 1060px; margin: 24px auto 48px; padding: 0 20px; animation: fadeIn .35s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* 页头 */
.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; gap: 14px; flex-wrap: wrap; }
.page-head h2 { margin: 0; font-size: 22px; position: relative; padding-left: 14px; }
.page-head h2::before { content: ''; position: absolute; left: 0; top: 50%; transform: translateY(-50%); width: 4px; height: 1.1em; border-radius: 2px; background: linear-gradient(180deg, #2563eb, #7c3aed); }
.page-head h2 small { color: var(--muted); font-weight: normal; font-size: 14px; margin-left: 10px; }

.month-nav {
  display: flex; align-items: center; gap: 2px;
  background: #fff; border: 1px solid var(--border); border-radius: 10px;
  padding: 3px; box-shadow: var(--shadow-sm);
}
.month-nav a { color: var(--primary); text-decoration: none; font-size: 14px; padding: 5px 11px; border-radius: 8px; font-weight: 500; }
.month-nav a:hover { background: var(--primary-soft); }
.month-label { font-weight: 600; font-size: 15px; padding: 0 8px; font-variant-numeric: tabular-nums; }

/* 卡片 */
.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px 20px; margin-bottom: 18px;
  box-shadow: var(--shadow);
  transition: box-shadow .18s ease;
}
.card:hover { box-shadow: 0 10px 24px rgba(16, 24, 40, .10); }
.card h3 { margin: 0 0 16px; font-size: 16px; font-weight: 700; }

/* 统计卡片 */
.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 20px; }
.stat-card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 18px;
  display: flex; flex-direction: column; gap: 4px; box-shadow: var(--shadow-sm);
  border-left: 4px solid var(--primary);
}
.stat-card.stat-highlight {
  border-color: transparent; border-left-color: transparent;
  background: linear-gradient(135deg, #2563eb, #4f46e5);
  box-shadow: 0 8px 18px rgba(37, 99, 235, .28);
}
.stat-label { font-size: 13px; color: var(--muted); }
.stat-value { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.2; }
.stat-card.stat-highlight .stat-label { color: rgba(255, 255, 255, .85); }
.stat-card.stat-highlight .stat-value { color: #fff; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; align-items: start; }
@media (max-width: 820px) { .grid-2 { grid-template-columns: 1fr; } }

/* 表单 */
label { display: block; font-size: 13px; color: var(--muted); margin: 12px 0 5px; font-weight: 500; }
input, select {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border);
  border-radius: var(--radius-sm); font-size: 14px; font-family: inherit;
  background: #fff; color: var(--text); transition: border-color .12s, box-shadow .12s;
}
input:focus, select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37, 99, 235, .13); }
.form-inline { display: flex; gap: 8px; align-items: center; }
.form-inline select { flex: 2; }
.form-inline input { flex: 1; }
.inline-form { display: inline-flex; gap: 6px; align-items: center; }
.inline-form input { width: 90px; }

/* 搜索框 */
.search-input {
  padding: 10px 12px; border-radius: var(--radius-sm);
  background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='15' height='15' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m21 21-4-4'/%3E%3C/svg%3E") no-repeat 12px center;
  padding-left: 36px;
}

/* 产品选择网格（今日录入） */
.chip-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px; max-height: 340px; overflow-y: auto; padding: 2px;
}
.chip {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px;
  padding: 12px 14px; border: 1px solid var(--border); border-radius: 12px;
  background: #fff; cursor: pointer; text-align: left;
  font: inherit; color: inherit; transition: border-color .12s, background .12s, box-shadow .12s, transform .08s;
}
.chip:hover { border-color: var(--primary); background: var(--primary-soft); }
.chip.selected { border-color: var(--primary); background: var(--primary-soft); box-shadow: inset 0 0 0 1px var(--primary); }
.chip:active { transform: scale(.98); }
.chip-name { font-weight: 600; font-size: 14px; }
.chip-price { font-size: 12px; color: var(--muted); }
.chip-grid::-webkit-scrollbar { width: 8px; }
.chip-grid::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 4px; }

/* 产品卡片删除（仅管理员可见） */
.chip-wrap { position: relative; display: flex; }
.chip-wrap .chip { flex: 1; }
.chip-del-form { position: absolute; top: 6px; right: 6px; margin: 0; }
.chip-del {
  width: 22px; height: 22px; padding: 0; border: none; border-radius: 50%;
  background: #fee2e2; color: var(--danger); font-size: 15px; line-height: 22px;
  cursor: pointer; text-align: center; transition: background .12s, color .12s;
}
.chip-del:hover { background: var(--danger); color: #fff; }
.chip-del.armed { width: auto; height: auto; padding: 3px 11px; border-radius: 999px; font-size: 12px; line-height: 1.4; }

/* 二次确认（armed）状态 */
.btn-danger.armed { background: var(--danger); border-color: var(--danger); color: #fff; }

/* 录入行 */
.entry-row { display: flex; gap: 10px; margin-top: 14px; }
.entry-row input[type="number"] { flex: 1; }

/* 列表工具条（搜索 + 计数） */
.list-toolbar { display: flex; gap: 12px; align-items: center; justify-content: space-between; margin-bottom: 14px; flex-wrap: wrap; }
.list-toolbar .search-input { max-width: 260px; flex: 1; min-width: 160px; }

/* 状态徽章 */
.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 500; white-space: nowrap; }
.badge-success { background: #ecfdf5; color: var(--success); }
.badge-muted { background: #f3f4f6; color: var(--muted); }

/* 提交行 */
.submit-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }

/* 按钮 */
.btn {
  display: inline-block; padding: 9px 16px; border: 1px solid var(--border);
  background: #fff; color: var(--text); border-radius: var(--radius-sm); cursor: pointer;
  font-size: 14px; font-family: inherit; text-decoration: none; font-weight: 500;
  transition: background .12s, border-color .12s, box-shadow .12s, transform .06s;
}
.btn:hover { background: #f3f4f6; border-color: #d1d5db; }
.btn:active { transform: translateY(1px); }
.btn-primary {
  background: linear-gradient(135deg, #2563eb, #1d4ed8); border-color: transparent; color: #fff;
  box-shadow: 0 3px 8px rgba(37, 99, 235, .25);
}
.btn-primary:hover { background: linear-gradient(135deg, #1d4ed8, #1e40af); border-color: transparent; }
.btn-danger { color: var(--danger); border-color: #fecaca; }
.btn-danger:hover { background: #fef2f2; border-color: #fca5a5; }
.btn-sm { padding: 5px 12px; font-size: 13px; border-radius: 8px; }
.btn-block { width: 100%; }

/* 产品卡片网格（管理员产品管理） */
.product-grid { display: grid; grid-template-columns: 1fr; gap: 10px; }
.product-card {
  background: #fff; border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 14px; display: flex; flex-direction: column; gap: 4px;
  transition: border-color .12s, box-shadow .12s;
}
.product-card:hover { border-color: var(--primary); box-shadow: var(--shadow); }
.product-card label { margin: 8px 0 3px; }
.product-card input { padding: 8px 10px; }
.product-card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.product-card-actions { display: flex; gap: 6px; margin-top: 10px; }
.product-card-actions .btn { flex: 1; }

/* 员工卡片列表（员工管理） */
.employee-list { display: flex; flex-direction: column; gap: 10px; }
.employee-card {
  background: #fff; border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 14px; display: flex; flex-direction: column; gap: 10px;
  transition: border-color .12s, box-shadow .12s;
}
.employee-card:hover { border-color: var(--primary); box-shadow: var(--shadow); }
.employee-main { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.employee-name { font-weight: 700; font-size: 15px; }
.employee-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; border-top: 1px dashed var(--border); padding-top: 10px; }
.employee-actions .inline-form { display: inline-flex; }
.employee-actions .inline-form input { width: 100px; }

/* 表格 */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table-wrap table { min-width: 100%; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 11px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { color: var(--muted); font-weight: 600; font-size: 13px; background: #fafafa; white-space: nowrap; }
tbody tr:nth-child(even) { background: #fafbfc; }
tbody tr:hover { background: var(--primary-soft); }
td.strong { font-weight: 700; }
td.actions { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
td.actions .inline-form { display: inline-flex; }
.dim { opacity: 0.55; }
.empty { color: var(--muted); text-align: center; padding: 28px; }
.muted { color: var(--muted); font-size: 13px; }

/* 响应式表格：手机端每行变成一张卡片 */
@media (max-width: 720px) {
  .resp-table thead { display: none; }
  .resp-table, .resp-table tbody, .resp-table tr, .resp-table td { display: block; width: 100%; }
  .resp-table tr {
    background: #fff; border: 1px solid var(--border); border-radius: 12px;
    padding: 12px 14px; margin-bottom: 12px;
  }
  .resp-table tr:last-child { margin-bottom: 0; }
  .resp-table tbody tr:nth-child(even) { background: #fff; }
  .resp-table td {
    display: flex; justify-content: space-between; align-items: center; gap: 12px;
    border: none; padding: 7px 0; text-align: right;
  }
  .resp-table td::before {
    content: attr(data-label);
    font-weight: 600; font-size: 13px; color: var(--muted);
    text-align: left; flex-shrink: 0;
  }
  .resp-table td.actions { justify-content: flex-start; flex-wrap: wrap; border-top: 1px dashed var(--border); padding-top: 10px; margin-top: 2px; }
  .resp-table td.actions::before { content: none; }
}

/* 提示消息 */
.flashes { margin-bottom: 16px; }
.flash { padding: 11px 15px; border-radius: var(--radius-sm); margin-bottom: 8px; font-size: 14px; }
.flash-success { background: #ecfdf5; color: var(--success); border: 1px solid #a7f3d0; }
.flash-error { background: #fef2f2; color: var(--danger); border: 1px solid #fecaca; }

/* 登录页 */
.login-card {
  max-width: 400px; margin: 8vh auto 0; background: linear-gradient(180deg, #ffffff, #f8fafc);
  border: 1px solid var(--border); border-radius: 20px; padding: 40px 34px 34px;
  box-shadow: var(--shadow-lg);
  position: relative; overflow: hidden;
}
.login-card::before {
  content: ''; position: absolute; top: 0; left: 0; right: 0; height: 5px;
  background: linear-gradient(90deg, #2563eb, #7c3aed, #ec4899);
}
.login-card h1 { margin: 0 0 6px; text-align: center; font-size: 22px; color: var(--primary); }
.login-card h1 + p { text-align: center; color: var(--muted); margin: 0 0 22px; font-size: 14px; }

/* 数据导入 */
.import-actions { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.import-actions .form-inline { flex: 1; min-width: 320px; }
.head-actions { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }

/* 图表 */
.viz svg { width: 100%; height: auto; display: block; }
.viz .tick { font-size: 11px; fill: #898781; }
.viz .bar-label { font-size: 13px; fill: #0b0b0b; }
.viz .bar-value { font-size: 12px; fill: #52514e; font-variant-numeric: tabular-nums; }
.chart-empty { color: #6b7280; text-align: center; padding: 40px; }
.chart-tip { position: fixed; display: none; background: #0b0b0b; color: #fff; padding: 6px 10px; border-radius: 6px; font-size: 13px; pointer-events: none; z-index: 999; box-shadow: 0 2px 8px rgba(0,0,0,0.2); }

/* 二次确认弹窗 */
.modal-overlay {
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.modal-overlay[hidden] { display: none; }
.modal-box {
  background: #fff; border-radius: 18px; padding: 26px 26px 22px;
  max-width: 340px; width: 100%; text-align: center;
  box-shadow: 0 24px 60px rgba(16, 24, 40, .25);
  animation: modalIn .18s ease;
}
@keyframes modalIn {
  from { opacity: 0; transform: translateY(10px) scale(.97); }
  to { opacity: 1; transform: none; }
}
.modal-icon { font-size: 34px; line-height: 1; margin-bottom: 6px; }
.modal-title { margin: 0 0 4px; font-size: 17px; font-weight: 700; }
.modal-message { margin: 0 0 22px; color: var(--muted); font-size: 14px; }
.modal-actions { display: flex; gap: 10px; justify-content: center; }
.modal-actions .btn {
  min-width: 96px; padding: 10px 0; border: none; border-radius: 10px;
  font-weight: 600; font-size: 14px; transition: filter .12s, transform .06s;
}
.modal-actions .btn:active { transform: translateY(1px); }
#confirm-cancel { background: #eef0f4; color: #4b5563; }
#confirm-cancel:hover { background: #e2e6ec; }
#confirm-ok { background: linear-gradient(135deg, #2563eb, #1d4ed8); color: #fff; box-shadow: 0 3px 10px rgba(37, 99, 235, .3); }
#confirm-ok:hover { filter: brightness(1.05); }

/* ===== 移动端适配 ===== */
@media (max-width: 720px) {
  body { font-size: 15px; }

  .navbar-inner { flex-wrap: wrap; height: auto; padding: 10px 14px; gap: 6px; }
  .brand { flex: 1; }
  .nav-toggle { display: block; }
  .nav-collapse {
    display: none; flex-basis: 100%; flex-direction: column; align-items: stretch; gap: 4px;
    padding-top: 8px; border-top: 1px solid var(--border);
  }
  .navbar.open .nav-collapse { display: flex; }
  .nav-links { flex-direction: column; width: 100%; gap: 2px; }
  .nav-links a { padding: 12px 12px; font-size: 15px; border-radius: 10px; }
  .nav-user {
    flex-direction: column; align-items: flex-start; gap: 2px;
    padding: 10px 12px 2px; border-top: 1px dashed var(--border); margin-top: 4px;
  }
  .nav-user a { padding: 6px 0; font-size: 15px; }

  .container { margin: 14px auto 40px; padding: 0 14px; }
  .page-head h2 { font-size: 18px; }
  .page-head { gap: 10px; }

  .card { padding: 14px 14px; border-radius: 12px; margin-bottom: 14px; }
  .stat-row { grid-template-columns: 1fr 1fr; gap: 8px; }
  .stat-card { padding: 12px 12px; }
  .stat-value { font-size: 18px; }

  .chip-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); max-height: 300px; }
  .chip { padding: 10px 10px; min-width: 0; }
  .chip-name { font-size: 13px; overflow-wrap: anywhere; }

  .product-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
  .product-card { padding: 10px; }
  .product-card label { font-size: 12px; }
  .product-card input { padding: 7px 8px; }
  .product-card-head { flex-direction: column; align-items: flex-start; gap: 6px; }
  .product-card-actions { flex-direction: column; }
  .table-wrap table { min-width: 560px; }

  /* 防止 iOS 聚焦时自动放大 */
  input, select { font-size: 16px; }

  /* 主操作按钮铺满整行，方便点按 */
  .card form > .btn-primary { width: 100%; }
  .btn { min-height: 40px; }
  .btn-sm { min-height: 36px; padding: 6px 12px; }
  .modal-actions .btn { min-height: 42px; }

  .login-card { margin: 5vh 12px 0; padding: 32px 22px 26px; }
  .form-inline { flex-wrap: wrap; }
  .import-actions .form-inline { min-width: 0; width: 100%; }
  .entry-row input[type="number"] { min-width: 0; }
}

@media (max-width: 360px) {
  .stat-row { grid-template-columns: 1fr; }
}
