:root {
  color-scheme: light;
  --bg: #f7f6f2;
  --panel: #ffffff;
  --ink: #1e2930;
  --muted: #66727d;
  --line: #dfe5e4;
  --accent: #1f7a6b;
  --accent-dark: #145e55;
  --warn: #b84a35;
  --soft: #edf5f2;
  --shadow: 0 18px 45px rgba(27, 42, 45, 0.09);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
}

.app-shell {
  width: min(1280px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 48px;
}

.topbar,
.control-panel,
.chart-section,
.table-section {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 24px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
}

h1 {
  font-size: clamp(26px, 4vw, 40px);
  line-height: 1.15;
}

h2 {
  font-size: 20px;
}

.subtext {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.control-panel {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(220px, 1fr) auto;
  align-items: end;
  gap: 16px;
  margin-top: 18px;
  padding: 18px;
}

.admin-panel {
  grid-template-columns: minmax(220px, 1fr) minmax(220px, 1fr) auto auto;
}

.field-group {
  display: grid;
  gap: 8px;
}

.product-filter {
  max-width: 480px;
  margin-bottom: 16px;
}

label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

input,
select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--ink);
  font: inherit;
  padding: 0 12px;
}

input:focus,
select:focus {
  border-color: var(--accent);
  outline: 3px solid rgba(31, 122, 107, 0.14);
}

.primary-button,
.ghost-button,
.small-button {
  min-height: 42px;
  border-radius: 8px;
  border: 1px solid transparent;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}

.primary-button {
  padding: 0 18px;
  background: var(--accent);
  color: #ffffff;
}

.primary-button:hover {
  background: var(--accent-dark);
}

.ghost-button {
  padding: 0 14px;
  background: var(--soft);
  color: var(--accent-dark);
  border-color: #c6ddd8;
}

.small-button {
  min-height: 34px;
  padding: 0 12px;
  background: var(--soft);
  color: var(--accent-dark);
  border-color: #c6ddd8;
}

.status-message {
  margin: 14px 0;
  color: var(--muted);
  font-size: 14px;
}

.status-message.error {
  color: var(--warn);
  font-weight: 700;
}

.data-meta,
.notice {
  margin: 14px 0;
  padding: 12px 14px;
  border: 1px solid #cfe1dc;
  border-radius: 8px;
  background: #f1faf7;
  color: var(--accent-dark);
  font-size: 14px;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin: 18px 0;
}

.metric-card {
  min-height: 116px;
  padding: 18px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
}

.metric-card span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.metric-card strong {
  display: block;
  margin-top: 14px;
  font-size: clamp(28px, 4vw, 42px);
  line-height: 1;
}

.metric-card.urgent strong,
.danger-text {
  color: var(--warn);
  font-weight: 700;
}

.chart-section,
.table-section {
  padding: 20px;
}

.table-section {
  margin-top: 18px;
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.row-count {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.empty-state {
  display: grid;
  min-height: 240px;
  place-items: center;
  border: 1px dashed #c8d2d0;
  border-radius: 8px;
  color: var(--muted);
  text-align: center;
  padding: 24px;
}

.chart-wrap {
  overflow-x: auto;
  padding-bottom: 8px;
}

#barChart {
  display: block;
  min-width: 860px;
  width: 100%;
  height: 430px;
}

.grid-line {
  stroke: #dfe5e4;
  stroke-width: 1;
}

.axis-line {
  stroke: #8ea09c;
  stroke-width: 1.2;
}

.tick-label,
.date-label,
.axis-label {
  fill: #66727d;
  font-size: 12px;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  margin-top: 12px;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
}

.legend-swatch {
  width: 12px;
  height: 12px;
  border-radius: 3px;
}

.table-scroll {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

table {
  width: 100%;
  min-width: 860px;
  border-collapse: collapse;
  background: #ffffff;
}

th,
td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  font-size: 14px;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f1f5f4;
  color: #425058;
  font-size: 12px;
  text-transform: uppercase;
}

td:nth-child(4),
td:nth-child(5),
td:nth-child(6),
td:nth-child(7) {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.table-empty {
  color: var(--muted);
  text-align: center;
}

@media (max-width: 860px) {
  .control-panel,
  .admin-panel {
    grid-template-columns: 1fr;
  }

  .summary-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 560px) {
  .app-shell {
    width: min(100% - 20px, 1280px);
    padding-top: 16px;
  }

  .topbar,
  .control-panel,
  .chart-section,
  .table-section {
    padding: 16px;
  }

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

  h1 {
    font-size: 28px;
  }
}

/* 隐藏图表空状态大白框 */
.empty-state {
  display: none !important;
  min-height: 0 !important;
  padding: 0 !important;
  border: 0 !important;
}

/* 图表显示优化 */
.chart-section {
  padding-top: 18px;
}

.chart-wrap {
  margin-top: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
}

#barChart {
  height: 340px !important;
}

.value-label {
  fill: #425058;
  font-size: 11px;
  font-weight: 700;
}

.date-label {
  fill: #66727d;
  font-size: 11px;
}

.tick-label,
.axis-label {
  fill: #66727d;
  font-size: 11px;
}

.legend {
  margin-top: 6px !important;
  gap: 8px 12px !important;
}

.legend-item {
  font-size: 11px !important;
}

.product-filter {
  margin-bottom: 8px !important;
}

@media (max-width: 760px) {
  #barChart {
    height: 320px !important;
  }

  .chart-section {
    padding: 16px;
  }
}

/* 方案 A：横向日期多产品柱状图优化 */
.chart-section {
  padding: 26px 28px 24px !important;
}

.chart-wrap {
  margin-top: 14px !important;
  overflow-x: auto !important;
  padding: 8px 0 10px !important;
  border: 1px solid #dfe5e4;
  border-radius: 12px;
  background: linear-gradient(180deg, #ffffff 0%, #fbfcfc 100%);
}

#barChart {
  height: 460px !important;
}

.chart-bar {
  cursor: pointer;
  transition: opacity 0.16s ease, filter 0.16s ease;
}

.chart-bar:hover {
  opacity: 0.86;
  filter: drop-shadow(0 4px 8px rgba(15, 23, 42, 0.2));
}

.latest-bg {
  pointer-events: none;
}

.latest-label {
  fill: #145e55;
  font-size: 12px;
  font-weight: 800;
}

.value-label {
  fill: #1e2930;
  font-size: 11px;
  font-weight: 800;
}

.date-label {
  fill: #52616b;
  font-size: 12px;
  font-weight: 700;
}

.tick-label,
.axis-label {
  fill: #66727d;
  font-size: 12px;
  font-weight: 700;
}

.grid-line {
  stroke: #e4e9e8;
  stroke-width: 1;
}

.axis-line {
  stroke: #7f928d;
  stroke-width: 1.2;
}

.legend {
  margin-top: 14px !important;
  gap: 10px 16px !important;
}

.legend-item {
  padding: 6px 9px;
  border: 1px solid #dfe5e4;
  border-radius: 999px;
  background: #ffffff;
  font-size: 12px !important;
  font-weight: 700;
}

.legend-swatch {
  width: 13px !important;
  height: 13px !important;
  border-radius: 4px !important;
}

.chart-tooltip {
  position: fixed;
  z-index: 9999;
  max-width: 320px;
  padding: 12px 14px;
  border-radius: 12px;
  background: rgba(15, 23, 42, 0.94);
  color: #ffffff;
  box-shadow: 0 18px 38px rgba(15, 23, 42, 0.28);
  pointer-events: none;
  font-size: 13px;
  line-height: 1.45;
}

.chart-tooltip-title {
  font-size: 14px;
  font-weight: 900;
  color: #ffffff;
  margin-bottom: 4px;
}

.chart-tooltip-name {
  color: #dbeafe;
  margin-bottom: 10px;
  word-break: break-word;
}

.chart-tooltip-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding-top: 8px;
  border-top: 1px solid rgba(255,255,255,0.18);
}

.chart-tooltip-row span {
  color: #cbd5e1;
}

.chart-tooltip-row strong {
  font-size: 20px;
  color: #ffffff;
}

.chart-tooltip-date {
  margin-top: 8px;
  color: #a7f3d0;
  font-size: 12px;
  font-weight: 700;
}

@media (max-width: 760px) {
  .chart-section {
    padding: 18px !important;
  }

  #barChart {
    height: 420px !important;
  }
}

/* 堆叠柱状图优化 */
.chart-section {
  padding: 28px 30px 26px !important;
}

.chart-wrap {
  margin-top: 16px !important;
  overflow-x: auto !important;
  padding: 10px 0 12px !important;
  border: 1px solid #dfe5e4;
  border-radius: 14px;
  background: linear-gradient(180deg, #ffffff 0%, #fbfcfc 100%);
}

#barChart {
  height: 500px !important;
}

.chart-bar {
  cursor: pointer;
  transition: opacity 0.16s ease, filter 0.16s ease;
}

.chart-bar:hover {
  opacity: 0.9;
  filter: drop-shadow(0 6px 10px rgba(15, 23, 42, 0.24));
}

.stacked-segment {
  stroke: rgba(255, 255, 255, 0.8);
  stroke-width: 1;
}

.latest-bg {
  pointer-events: none;
}

.latest-label {
  fill: #145e55;
  font-size: 12px;
  font-weight: 900;
}

.stack-total-label {
  fill: #1e2930;
  font-size: 13px;
  font-weight: 900;
}

.date-label {
  fill: #52616b;
  font-size: 12px;
  font-weight: 800;
}

.tick-label,
.axis-label {
  fill: #66727d;
  font-size: 12px;
  font-weight: 800;
}

.grid-line {
  stroke: #e4e9e8;
  stroke-width: 1;
}

.axis-line {
  stroke: #7f928d;
  stroke-width: 1.2;
}

.legend {
  margin-top: 16px !important;
  gap: 10px 14px !important;
}

.legend-item {
  padding: 7px 10px;
  border: 1px solid #dfe5e4;
  border-radius: 999px;
  background: #ffffff;
  font-size: 12px !important;
  font-weight: 800;
}

.legend-item em {
  margin-left: 5px;
  color: #66727d;
  font-style: normal;
  font-weight: 700;
}

.legend-swatch {
  width: 13px !important;
  height: 13px !important;
  border-radius: 4px !important;
}

.chart-tooltip {
  position: fixed;
  z-index: 9999;
  max-width: 340px;
  padding: 12px 14px;
  border-radius: 12px;
  background: rgba(15, 23, 42, 0.95);
  color: #ffffff;
  box-shadow: 0 18px 38px rgba(15, 23, 42, 0.28);
  pointer-events: none;
  font-size: 13px;
  line-height: 1.45;
}

.chart-tooltip-date {
  margin-bottom: 6px;
  color: #a7f3d0;
  font-size: 12px;
  font-weight: 800;
}

.chart-tooltip-title {
  font-size: 14px;
  font-weight: 900;
  color: #ffffff;
  margin-bottom: 4px;
}

.chart-tooltip-name {
  color: #dbeafe;
  margin-bottom: 10px;
  word-break: break-word;
}

.chart-tooltip-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding-top: 8px;
  border-top: 1px solid rgba(255,255,255,0.18);
}

.chart-tooltip-row span {
  color: #cbd5e1;
}

.chart-tooltip-row strong {
  font-size: 22px;
  color: #ffffff;
}

@media (max-width: 760px) {
  .chart-section {
    padding: 18px !important;
  }

  #barChart {
    height: 440px !important;
  }
}

/* 图表高度二次优化 */
.chart-section {
  padding: 22px 28px 22px !important;
}

.chart-wrap {
  margin-top: 10px !important;
  padding: 4px 0 6px !important;
}

#barChart {
  height: 410px !important;
}

.stack-total-label {
  font-size: 12px !important;
}

.date-label {
  font-size: 12px !important;
}

.legend {
  margin-top: 10px !important;
}

@media (max-width: 760px) {
  #barChart {
    height: 380px !important;
  }
}

/* 图表高度调整：更大气版本 */
#barChart {
  height: 470px !important;
}

.chart-wrap {
  padding-top: 8px !important;
  padding-bottom: 10px !important;
}

@media (max-width: 760px) {
  #barChart {
    height: 420px !important;
  }
}


/* 图表高度调整为 550 */
#barChart {
  height: 550px !important;
}

@media (max-width: 760px) {
  #barChart {
    height: 460px !important;
  }
}


/* 点击日期后的当日横向明细表 */
.selected-date-section {
  margin-top: 18px;
  padding: 20px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
}

.selected-date-section .section-heading {
  margin-bottom: 14px;
}

.small-clear-button {
  min-height: 36px !important;
  padding: 0 12px !important;
  font-size: 13px !important;
}

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

.compact-table th {
  background: #eef5f3;
}

.compact-table td,
.compact-table th {
  padding: 11px 14px;
}

.compact-table tr:hover td {
  background: #f8fbfa;
}

/* 让可点击柱子有更明确的交互感 */
.chart-bar {
  cursor: pointer;
}

.chart-bar:hover {
  opacity: 0.9;
  filter: drop-shadow(0 6px 10px rgba(15, 23, 42, 0.28));
}

/* 点击日期展开表格后的性能优化 */
.selected-date-section {
  margin-top: 18px;
  contain: layout paint;
}

.selected-date-section .table-scroll {
  max-height: 420px;
  overflow: auto;
}

.selected-date-section table {
  min-width: 980px;
}

.selected-date-section tr:hover td {
  background: #f6faf9;
}

/* 避免 hover 阴影造成 SVG 大量重绘 */
.chart-bar,
.chart-bar:hover,
.stacked-segment,
.stacked-segment:hover {
  filter: none !important;
}

.chart-tooltip {
  pointer-events: none !important;
  will-change: transform;
}
