:root {
  --bg: #f6f4f1;
  --card: #ffffff;
  --ink: #1b1917;
  --ink-2: #57524c;
  --ink-3: #948b81;
  --line: #e8e2da;
  --line-strong: #d8d0c5;
  --accent: #b02a1f;
  --accent-dark: #8d1f16;
  --accent-soft: #fbeeec;
  --ok: #146c43;
  --ok-soft: #e9f5ee;
  --warn: #a15c07;
  --warn-soft: #fdf3e3;
  --blue: #1f5f8b;
  --blue-soft: #eaf2f8;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(28, 25, 23, 0.04), 0 8px 24px -12px rgba(28, 25, 23, 0.18);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei',
    'Helvetica Neue', Arial, sans-serif;
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

h1,
h2,
h3,
h4 {
  margin: 0;
  font-weight: 650;
  letter-spacing: -0.01em;
}

a {
  color: var(--accent);
  text-decoration: none;
}

button,
input,
select,
textarea {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

.mono {
  font-variant-numeric: tabular-nums;
  font-feature-settings: 'tnum';
}

/* ---------------- 布局 ---------------- */

.wrap {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 20px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  background: rgba(246, 244, 241, 0.88);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--line);
}

.topbar-inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  gap: 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 16px;
  white-space: nowrap;
}

.brand-mark {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: linear-gradient(140deg, #b02a1f, #7c1a12);
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 15px;
  flex: none;
}

.brand-sub {
  font-size: 12px;
  font-weight: 500;
  color: var(--ink-3);
  letter-spacing: 0;
}

.topbar-spacer {
  flex: 1;
}

.section {
  margin: 26px 0;
}

.section-head {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 12px;
}

.section-head h2 {
  font-size: 17px;
  flex: none;
}

.section-head .hint {
  font-size: 12.5px;
  color: var(--ink-3);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.filter-range {
  display: flex;
  gap: 6px;
  align-items: center;
}

.filter-range .input {
  width: 148px;
  height: 38px;
}

.filter-range .btn {
  height: 38px;
}

@media (max-width: 640px) {
  .filter-range {
    width: 100%;
  }

  .filter-range .input {
    width: auto;
    flex: 1;
    min-width: 0;
    padding: 0 8px;
    font-size: 13.5px;
  }

  .filter-range .btn {
    flex: none;
    padding: 0 10px;
  }
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.card-pad {
  padding: 20px;
}

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

/* ---------------- 按钮 ---------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 40px;
  padding: 0 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line-strong);
  background: #fff;
  color: var(--ink);
  font-size: 14px;
  font-weight: 550;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.08s;
  white-space: nowrap;
}

.btn:hover {
  background: #faf8f6;
  border-color: #c9bfb2;
}

.btn:active {
  transform: translateY(1px);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.btn-primary:hover {
  background: var(--accent-dark);
  border-color: var(--accent-dark);
}

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--ink-2);
}

.btn-ghost:hover {
  background: rgba(0, 0, 0, 0.04);
  border-color: transparent;
}

.btn-sm {
  height: 32px;
  padding: 0 11px;
  font-size: 13px;
  border-radius: 8px;
}

.btn-block {
  width: 100%;
  height: 46px;
  font-size: 15.5px;
}

.btn-link {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font-size: 13px;
  padding: 0;
}

/* ---------------- 表单 ---------------- */

.field {
  margin-bottom: 16px;
}

.field > label {
  display: block;
  font-size: 13px;
  font-weight: 550;
  color: var(--ink-2);
  margin-bottom: 6px;
}

.field .req {
  color: var(--accent);
  margin-left: 2px;
}

.input,
.select,
.textarea {
  width: 100%;
  height: 44px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: #fff;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  -webkit-appearance: none;
  appearance: none;
}

.textarea {
  height: auto;
  min-height: 76px;
  padding: 10px 12px;
  resize: vertical;
  line-height: 1.55;
}

.select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5L6 6.5L11 1.5' stroke='%23948b81' stroke-width='1.6' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 13px center;
  padding-right: 34px;
}

.input:focus,
.select:focus,
.textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(176, 42, 31, 0.1);
}

.input:disabled {
  background: #f4f1ed;
  color: var(--ink-3);
}

.select:disabled {
  background-color: #f4f1ed;
  background-image: none;
  color: var(--ink-2);
  padding-right: 12px;
  border-color: var(--line);
  opacity: 1;
  -webkit-text-fill-color: var(--ink-2);
}

.input-unit {
  position: relative;
}

.input-unit .input {
  padding-right: 46px;
}

.input-unit .unit {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 13px;
  color: var(--ink-3);
  pointer-events: none;
}

.field-hint {
  font-size: 12px;
  color: var(--ink-3);
  margin-top: 5px;
  line-height: 1.5;
}

.field-error {
  font-size: 12.5px;
  color: var(--accent);
  margin-top: 5px;
}

.row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.row-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

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

/* ---------------- 结果条 / KPI ---------------- */

.result-bar {
  background: var(--accent-soft);
  border: 1px solid rgba(176, 42, 31, 0.16);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.result-bar .label {
  font-size: 13px;
  color: var(--ink-2);
}

.result-bar .value {
  font-size: 26px;
  font-weight: 700;
  color: var(--accent);
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
}

/* 分组内部的指标网格。
   这里必须是「自适应横向铺开」而不是固定三列：
   固定三列时，每个分组里 4-10 个指标会被压成 2-3 行窄卡，整页看起来像竖排列表，
   一屏看不到一组，读起来很累。auto-fit + 最小宽度能保证一屏横向铺开、窄屏自动折。 */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(168px, 1fr));
  gap: 12px;
}

/* 指标分组（成本 / 营收 / 渠道 / 敏感 / 人群） */
.kpi-groups {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.kpi-group {
  min-width: 0;
}

.kg-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 10px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--line);
}

.kg-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.kg-title::before {
  content: '';
  display: inline-block;
  width: 3px;
  height: 14px;
  border-radius: 2px;
  background: var(--accent);
}

.kg-desc {
  font-size: 12px;
  color: var(--ink-3);
}

.k-bar {
  margin-top: 8px;
  height: 4px;
  border-radius: 99px;
  background: #ece5dd;
  overflow: hidden;
}

.k-bar i {
  display: block;
  height: 100%;
  background: var(--accent);
  opacity: 0.55;
  border-radius: 99px;
}

@media (max-width: 1080px) {
  .kpi-grid {
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  }
}

@media (max-width: 620px) {
  .kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 9px;
  }
  /* 窄屏时分组间距收紧，否则一屏只能看到一组 */
  .kpi-groups {
    gap: 14px;
  }
  .kg-head {
    margin-bottom: 8px;
  }
}

.kpi {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 15px 13px;
  box-shadow: var(--shadow);
  min-width: 0;
}

.kpi .k-label {
  font-size: 12.5px;
  color: var(--ink-3);
  display: flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.kpi .k-value {
  font-size: 24px;
  font-weight: 700;
  margin-top: 6px;
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

.kpi .k-value small {
  font-size: 12.5px;
  font-weight: 550;
  color: var(--ink-3);
  margin-left: 2px;
}

.kpi .k-foot {
  font-size: 12px;
  color: var(--ink-3);
  margin-top: 4px;
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 18px;
}

.delta-up {
  color: var(--accent);
  font-weight: 600;
}

.delta-down {
  color: var(--ok);
  font-weight: 600;
}

.delta-flat {
  color: var(--ink-3);
  font-weight: 600;
}

/* ---------------- 分段控件 ---------------- */

.segmented {
  display: inline-flex;
  background: #efeae4;
  border-radius: 10px;
  padding: 3px;
  gap: 2px;
}

.segmented button {
  border: none;
  background: transparent;
  padding: 0 13px;
  height: 32px;
  border-radius: 8px;
  font-size: 13.5px;
  font-weight: 550;
  color: var(--ink-2);
  cursor: pointer;
  transition: background 0.15s, color 0.15s, box-shadow 0.15s;
  white-space: nowrap;
}

.segmented button.active {
  background: #fff;
  color: var(--ink);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}

/* ---------------- 表格 ---------------- */

.table-wrap {
  overflow-x: auto;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: #fff;
}

table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
  white-space: nowrap;
}

table.data th {
  text-align: left;
  font-weight: 600;
  font-size: 12.5px;
  color: var(--ink-3);
  padding: 11px 14px;
  background: #faf8f5;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
}

table.data td {
  padding: 11px 14px;
  border-bottom: 1px solid #f1ede7;
  font-variant-numeric: tabular-nums;
}

table.data tr:last-child td {
  border-bottom: none;
}

table.data tbody tr:hover {
  background: #fcfaf8;
}

/* 导入预览：手动改过的行，左侧加一条绿色标识，方便回溯哪些是自己改的 */
table.data tbody tr.row-edited {
  box-shadow: inset 3px 0 0 rgba(31, 95, 45, 0.45);
  background: #fbfdfb;
}

/* 导入预览：可编辑单元格的提示态。不加边框（上千行会花），只在悬停时提示可改 */
#previewTable td[contenteditable] {
  cursor: text;
  transition: background 0.12s;
}

#previewTable td[contenteditable]:hover {
  background: #fdfaf6;
  box-shadow: inset 0 0 0 1px rgba(176, 42, 31, 0.16);
  border-radius: 4px;
}

#previewTable td[contenteditable]:focus {
  outline: none;
  background: #fffdfa;
  box-shadow: inset 0 0 0 2px rgba(176, 42, 31, 0.35);
  border-radius: 4px;
}

table.data .num {
  text-align: right;
}

table.data th.num {
  text-align: right;
}

table.data .strong {
  font-weight: 650;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 22px;
  padding: 0 8px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  background: var(--blue-soft);
  color: var(--blue);
}

.badge.good {
  background: var(--ok-soft);
  color: var(--ok);
}

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

.badge.bad {
  background: var(--accent-soft);
  color: var(--accent);
}

/* ---------------- 图表 ---------------- */

.chart-box {
  padding: 6px 4px 0;
}

.chart-svg {
  width: 100%;
  height: auto;
  display: block;
  overflow: visible;
}

.chart-empty {
  height: 180px;
  display: grid;
  place-items: center;
  color: var(--ink-3);
  font-size: 13px;
}

.legend {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  font-size: 12.5px;
  color: var(--ink-2);
  padding: 0 16px 12px;
}

.legend i {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 3px;
  margin-right: 6px;
}

/* ---------------- 杂项 ---------------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 32px;
  transform: translateX(-50%) translateY(12px);
  background: #221f1c;
  color: #fff;
  padding: 11px 18px;
  border-radius: 10px;
  font-size: 13.5px;
  box-shadow: 0 12px 30px -8px rgba(0, 0, 0, 0.4);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 200;
  max-width: 86vw;
  text-align: center;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.toast.err {
  background: #8d1f16;
}

.modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(28, 25, 23, 0.44);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 120;
}

.modal-mask.open {
  display: flex;
}

.modal {
  background: #fff;
  border-radius: 16px;
  width: 100%;
  max-width: 460px;
  max-height: 86vh;
  overflow: auto;
  box-shadow: 0 24px 60px -18px rgba(0, 0, 0, 0.4);
}

.modal-head {
  padding: 18px 20px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-head h3 {
  font-size: 16px;
}

.modal-body {
  padding: 16px 20px 20px;
}

.modal-foot {
  padding: 0 20px 20px;
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

.icon-btn {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: var(--ink-3);
  cursor: pointer;
  display: grid;
  place-items: center;
  font-size: 18px;
  line-height: 1;
}

.icon-btn:hover {
  background: rgba(0, 0, 0, 0.05);
  color: var(--ink);
}

.empty {
  padding: 44px 20px;
  text-align: center;
  color: var(--ink-3);
  font-size: 13.5px;
}

.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

.spinner.dark {
  border-color: rgba(0, 0, 0, 0.15);
  border-top-color: var(--ink-2);
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.loading-block {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 48px;
  color: var(--ink-3);
  font-size: 13.5px;
}

.divider {
  height: 1px;
  background: var(--line);
  margin: 16px 0;
}

.qr-box {
  display: grid;
  place-items: center;
  padding: 16px;
  background: #fff;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
}

.qr-box img {
  width: 200px;
  height: 200px;
  display: block;
}

.link-box {
  display: flex;
  gap: 8px;
  align-items: center;
  background: #faf8f5;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 12.5px;
  color: var(--ink-2);
  word-break: break-all;
}

.note {
  font-size: 12.5px;
  color: var(--ink-3);
  background: #faf8f5;
  border-left: 3px solid var(--line-strong);
  padding: 10px 12px;
  border-radius: 0 8px 8px 0;
  line-height: 1.65;
}

.parts-row {
  display: grid;
  grid-template-columns: 1fr 110px 34px;
  gap: 8px;
  margin-bottom: 8px;
  align-items: center;
}

@media (max-width: 640px) {
  .parts-row {
    grid-template-columns: 1fr 92px 32px;
  }
}

/* ---------- 填报入口 / 响应式 ---------- */

.qr-grid {
  grid-template-columns: 240px 1fr;
}

@media (max-width: 780px) {
  .qr-grid {
    grid-template-columns: 1fr;
  }
}

.link-box {
  min-width: 0;
}

.link-box > span {
  min-width: 0;
  word-break: break-all;
}

#chartGrid {
  grid-template-columns: 1fr 1fr;
}

@media (max-width: 900px) {
  #chartGrid {
    grid-template-columns: 1fr !important;
  }
}

@media (max-width: 640px) {
  .topbar-inner {
    flex-wrap: wrap;
    gap: 8px;
  }

  table.data th,
  table.data td {
    padding: 9px 10px;
  }
}

/* ---------- 成本区块 ---------- */

.cost-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}

.cost-main {
  min-width: 0;
}

.cost-detail {
  flex: none;
  font-size: 11.5px;
  color: var(--ink-2);
  text-align: right;
  line-height: 1.65;
  white-space: nowrap;
}

@media (max-width: 520px) {
  .cost-row {
    flex-direction: column;
    align-items: stretch;
  }

  .cost-detail {
    text-align: left;
    margin-top: 6px;
    white-space: normal;
  }
}

/* ---------- 品牌与页脚 ---------- */

.brand-line {
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
}

.brand-name {
  font-size: 15px;
  font-weight: 650;
  letter-spacing: 0.02em;
  color: var(--ink);
}

.brand-tag {
  font-size: 11px;
  color: var(--ink-3);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 1px 6px;
  font-weight: 500;
  white-space: nowrap;
}

.site-foot {
  margin-top: 34px;
  padding: 18px 4px 8px;
  border-top: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 6px;
  font-size: 11.5px;
  color: var(--ink-3);
  letter-spacing: 0.01em;
}

@media (max-width: 520px) {
  .site-foot {
    flex-direction: column;
    gap: 4px;
  }
}

/* ===== 窄屏适配（2026-11-18）=====
   问题：顶栏、筛选条不换行导致横向溢出；表格列被压扁，数字重叠看不清。
   做法：顶栏与筛选条允许换行，表格给最小宽度交给 .table-wrap 横向滚动。 */
@media (max-width: 900px) {
  .topbar-inner {
    flex-wrap: wrap;
    row-gap: 8px;
    padding: 10px 14px;
  }
  .topbar-inner .brand { flex: 1 1 100%; min-width: 0; }
  .topbar-inner .topbar-spacer { display: none; }
  .filter-range { flex-wrap: wrap; width: 100%; }
  .filter-range .input { flex: 1 1 0; min-width: 0; width: auto; }
  .filter-range .btn { flex: 0 0 auto; }
}

/* 表格最小宽度：不足时由 .table-wrap 横向滚动，而不是把列压到重叠 */
.table-wrap table.data,
.table-wrap table.wide { min-width: 720px; }
.table-wrap table.xwide { min-width: 980px; }

/* 关键：宽表格不能把卡片/栅格容器撑破，否则整页横向溢出、
   KPI 与维度卡片会被挤到屏幕外。表格滚动只在 .table-wrap 内部发生。 */
.card,
.table-wrap,
.section,
.grid,
.kpi-grid,
.dim-grid { min-width: 0; max-width: 100%; }

/* 手机端筛选条改为竖排：日期控件有固有宽度，横排必然溢出 */
@media (max-width: 640px) {
  .filter-range {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }
  .filter-range .input,
  .filter-range .select,
  .filter-range .btn { width: 100%; }
  .filter-range > span { display: none; }
  .card { max-width: 100%; }
  .wrap { padding-left: 12px; padding-right: 12px; }
  /* 门店下拉是内联 min-width:170px，窄屏必须提权覆盖，否则整行溢出 */
  #storeFilter,
  #fromDate,
  #toDate { width: 100% !important; min-width: 0 !important; }
  .segmented { width: 100%; }
}
