:root {
  --bg: #f4f6f9;
  --panel: #ffffff;
  --border: #e7ebf1;
  --text: #1f2937;
  --muted: #6b7280;
  --primary: #e1342b;        /* 拼多多红 */
  --primary-d: #c22a22;
  --primary-soft: #fdecea;
  --green: #16a34a;
  --red: #dc2626;
  --day-bg: #f3f8fd;         /* 最近一周列底色 */
  --day-head: #eaf2fb;
  --shadow-sm: 0 1px 2px rgba(16,24,40,.05), 0 1px 3px rgba(16,24,40,.06);
  --shadow-md: 0 4px 16px rgba(16,24,40,.08);
  --radius: 12px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Microsoft YaHei", "PingFang SC", "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.55;
  -webkit-text-size-adjust: 100%;
}

/* ---------------- 顶栏 / 标签页 ---------------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 22px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
  box-shadow: var(--shadow-sm);
}
.brand {
  display: flex; align-items: center; gap: 10px;
  font-weight: 700; font-size: 16px; letter-spacing: .3px;
}
.brand::before {
  content: ""; width: 24px; height: 24px; border-radius: 7px;
  background: linear-gradient(135deg, #e1342b, #ff7a6e);
  box-shadow: 0 2px 6px rgba(225,52,43,.35);
}
.topbar-actions { display: flex; gap: 8px; }

.tabs {
  display: flex; gap: 2px; padding: 0 16px;
  background: var(--panel); border-bottom: 1px solid var(--border);
}
.tab {
  border: none; background: none; padding: 13px 18px; cursor: pointer;
  color: var(--muted); font-size: 14px; font-weight: 500;
  border-bottom: 2px solid transparent; white-space: nowrap;
  transition: color .15s, border-color .15s;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }

main { padding: 22px; max-width: 1180px; margin: 0 auto; }
.panel { display: none; }
.panel.active { display: block; animation: fade .2s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ---------------- 工具栏 / 表单控件 ---------------- */
.toolbar { display: flex; gap: 16px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.toolbar label { color: var(--muted); font-size: 13px; }
select, input, textarea {
  border: 1px solid var(--border); border-radius: 8px; padding: 9px 12px; font-size: 14px;
  background: #fff; color: var(--text); font-family: inherit;
  transition: border-color .15s, box-shadow .15s;
}
select:focus, input:focus, textarea:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(225,52,43,.12);
}
.period-label { color: var(--muted); margin-left: auto; font-size: 13px; }

/* ---------------- 按钮 ---------------- */
.btn {
  border: 1px solid var(--border); background: #fff; color: var(--text); padding: 9px 16px;
  border-radius: 8px; cursor: pointer; font-size: 14px; font-weight: 500;
  transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover { background: #f3f5f8; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn.primary:hover { background: var(--primary-d); }
.btn.small { padding: 6px 12px; font-size: 12.5px; border-radius: 7px; }
.btn.danger { color: var(--red); border-color: #f3cdca; background: #fff; }
.btn.danger:hover { background: var(--primary-soft); }

/* ---------------- 表格 ---------------- */
table {
  width: 100%; border-collapse: separate; border-spacing: 0;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow-sm);
}
th, td { padding: 11px 14px; text-align: left; border-bottom: 1px solid var(--border); }
th { background: #fafbfc; color: var(--muted); font-weight: 600; font-size: 13px; }
tr:last-child td { border-bottom: none; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.up { color: var(--red); font-weight: 600; }      /* 涨 = 红（中国习惯） */
.down { color: var(--green); font-weight: 600; }  /* 跌 = 绿 */
.flat { color: var(--muted); }

/* ---------------- 卡片 ---------------- */
.card {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px; margin-bottom: 14px; box-shadow: var(--shadow-sm);
  transition: box-shadow .15s;
}
.card:hover { box-shadow: var(--shadow-md); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.card-title { font-weight: 600; font-size: 15px; }
.card-sub { color: var(--muted); font-size: 12.5px; }
.card-sub.stats-line { display: flex; gap: 16px; flex-wrap: wrap; align-items: center; margin-top: 8px; }
.card-sub.stats-line .muted-sep { margin-left: auto; }

.store-link { color: var(--primary); text-decoration: none; font-weight: 600; }
.store-link:hover { text-decoration: underline; }

.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 12px; background: #eef2f7; color: var(--muted); }
.mini-table { width: 100%; margin-top: 10px; font-size: 12.5px; }
.mini-table th, .mini-table td { padding: 6px 10px; }

/* ---------------- 快速录入 ---------------- */
.quick-entry {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px; margin-bottom: 18px; box-shadow: var(--shadow-sm);
}
.qe-title { font-weight: 600; margin-bottom: 12px; font-size: 15px; }
.qe-row { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.qe-row select { min-width: 180px; flex: 1 1 180px; }
.qe-row input[type="date"] { min-width: 150px; flex: 1 1 150px; }
.qe-row input[type="number"] { width: 150px; flex: 1 1 120px; }
.qe-actions { display: flex; gap: 8px; align-items: center; margin-top: 12px; flex-wrap: wrap; }
.qe-label { color: var(--muted); font-size: 13px; }
.qe-remind {
  color: #15532f; font-size: 13px; margin-left: auto;
  background: #eaf6ee; border: 1px solid #cdead6; border-radius: 999px; padding: 4px 12px;
}
.qe-remind b { color: #137a3f; }

.hint { color: var(--muted); font-size: 12.5px; margin: 8px 0 0; line-height: 1.6; }
.hint.err { color: var(--red); }
.msg { color: var(--green); font-size: 13px; margin-left: 10px; }
.msg.err { color: var(--red); }

.save-status { color: var(--green); font-size: 12.5px; white-space: nowrap; }
.save-status.err { color: var(--red); }
.qe-auto-tip {
  font-size: 11.5px; font-weight: 400; color: var(--muted);
  background: #f4f5f7; border: 1px solid #e5e7eb; border-radius: 999px;
  padding: 2px 9px; margin-left: 6px; vertical-align: middle;
}

/* ---------------- 弹窗 ---------------- */
.modal { position: fixed; inset: 0; background: rgba(17,24,39,.45); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px; }
.modal.hidden { display: none; }
.modal-box {
  background: #fff; border-radius: 14px; padding: 24px; width: 480px; max-width: 100%;
  box-shadow: 0 12px 40px rgba(0,0,0,.22); animation: pop .18s ease;
  max-height: 90vh; overflow-y: auto;
}
@keyframes pop { from { opacity: 0; transform: scale(.96); } to { opacity: 1; transform: none; } }
.modal-box h3 { margin: 0 0 16px; font-size: 17px; }
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; }
.field label { color: var(--muted); font-size: 13px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

.toast {
  position: fixed; bottom: 26px; left: 50%; transform: translateX(-50%);
  background: #1f2937; color: #fff; padding: 11px 20px; border-radius: 10px;
  z-index: 100; box-shadow: 0 6px 20px rgba(0,0,0,.3); font-size: 13.5px;
}
.toast.hidden { display: none; }
.toast.err { background: #b91c1c; }

/* ---------------- 访问密钥门禁 ---------------- */
.gate {
  position: fixed; inset: 0; z-index: 200;
  display: none; align-items: center; justify-content: center; padding: 20px;
  background: linear-gradient(150deg, #f7f9fc, #eef2f8);
}
body.locked .gate { display: flex; }
body.locked .topbar, body.locked .tabs, body.locked main { display: none; }
.gate-box {
  background: #fff; border: 1px solid var(--border); border-radius: 16px;
  padding: 28px 24px; width: 340px; max-width: 100%; text-align: center;
  box-shadow: 0 12px 40px rgba(16,24,40,.12); animation: pop .2s ease;
}
.gate-brand { font-weight: 700; font-size: 16px; margin-bottom: 6px; }
.gate-tip { color: var(--muted); font-size: 13px; margin: 0 0 14px; }
.gate-box input { width: 100%; text-align: center; letter-spacing: .18em; font-size: 16px; }
.gate-box .btn { width: 100%; margin-top: 12px; }
.gate-box .msg { margin: 8px 0 0; text-align: center; }
.gate-box .msg:empty { display: none; }

/* ---------------- 统计矩阵 ---------------- */
#statsTableWrap { overflow-x: auto; padding-bottom: 8px; -webkit-overflow-scrolling: touch; }
table.matrix { min-width: 720px; }
table.matrix th, table.matrix td { text-align: center; }
th.sticky-col, td.sticky-col {
  position: sticky; left: 0; background: var(--panel); z-index: 2; text-align: left;
  box-shadow: 1px 0 0 var(--border);
}
th.sticky-col { background: #fafbfc; }

.col-period { cursor: grab; user-select: none; background: #fafbfc; min-width: 96px; }
.col-period:hover { background: #eef2f7; }
.col-period.dragging { opacity: .5; cursor: grabbing; }
.th-label { font-weight: 600; color: var(--text); font-size: 13px; }
.th-sub { color: var(--muted); font-size: 11px; margin-top: 3px; }
.col-period-cell { font-size: 15px; font-weight: 600; }
.cell-sub { color: var(--muted); font-size: 11px; font-weight: 400; margin-top: 3px; }

/* 最近一周（昨天 ~ 7天前）固定列 */
.col-day { background: var(--day-head); min-width: 86px; border-left: 1px dashed var(--border); }
.col-day .th-label { color: #1f6fb2; }
.col-day-cell { font-size: 15px; font-weight: 600; background: var(--day-bg); border-left: 1px dashed var(--border); }
.col-day-cell.editable-day { background: #fff7e6; border-left: 2px solid #f0b429; } /* 昨天列高亮，可编辑 */
.col-day-cell.day-editable { cursor: pointer; }
.col-day-cell.day-editable:hover { background: #fff2cc; }
.col-day-cell .day-value { display: inline-block; min-width: 24px; }
.day-input {
  width: 78px; padding: 5px 7px; font-size: 14px; font-weight: 600;
  border: 1px solid #cbd5e1; border-radius: 7px; text-align: right;
  background: #fff; color: var(--text);
}
.day-input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(225,52,43,.15); }

/* ---------------- 响应式：手机 / 平板 ---------------- */
@media (max-width: 768px) {
  main { padding: 14px; }
  .topbar { padding: 12px 14px; flex-wrap: wrap; }
  .topbar-actions { width: 100%; }
  .topbar-actions .btn { flex: 1 1 auto; text-align: center; }

  .tabs { overflow-x: auto; flex-wrap: nowrap; padding: 0 12px; -webkit-overflow-scrolling: touch; }
  .tabs::-webkit-scrollbar { height: 0; }
  .tab { padding: 13px 14px; }

  .toolbar { gap: 10px; }
  .period-label { width: 100%; margin-left: 0; }

  .qe-row { flex-direction: column; align-items: stretch; }
  .qe-row select, .qe-row input { width: 100% !important; flex: 1 1 auto; }
  .qe-row .btn { width: 100%; }
  .save-status { white-space: normal; }
  .qe-remind { margin-left: 0; width: 100%; text-align: center; }

  .card { padding: 14px; }
  .card-head { gap: 8px; }
  .card-head > div:last-child { display: flex; flex-wrap: wrap; gap: 6px; width: 100%; }
  .card-head > div:last-child .btn { flex: 1 1 auto; }

  .modal { padding: 12px; }
  .modal-box { padding: 20px 16px; }
}

@media (max-width: 420px) {
  .brand { font-size: 15px; }
  th, td { padding: 9px 10px; }
}

@media (min-width: 1200px) {
  main { max-width: 1320px; }
}
