:root {
  color-scheme: light;
  font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #1d252c;
  background: #f4f6f7;
  font-synthesis: none;
  --surface: #ffffff;
  --line: #dce2e5;
  --line-soft: #edf0f2;
  --muted: #68747d;
  --text: #1d252c;
  --green: #147a5a;
  --green-soft: #e8f4ef;
  --blue: #3478b8;
  --red: #d43d3d;
  --red-soft: #fcecec;
  --amber: #9a6212;
  --amber-soft: #fff4dc;
}

* { box-sizing: border-box; }
html { min-width: 320px; background: #f4f6f7; }
body { margin: 0; min-height: 100vh; background: #f4f6f7; }
button, input { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.topbar { height: 72px; background: #fff; border-bottom: 1px solid var(--line); }
.topbar__inner {
  max-width: 1480px;
  height: 100%;
  margin: 0 auto;
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand__mark {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 6px;
  background: #1f735b;
  color: #fff;
  font-size: 13px;
  font-weight: 800;
}
.brand h1 { margin: 0; font-size: 18px; line-height: 1.3; letter-spacing: 0; }
.brand p { margin: 2px 0 0; color: var(--muted); font-size: 12px; }
.sync-state { display: flex; align-items: center; gap: 10px; flex: 0 0 auto; }
.sync-state > div { display: grid; gap: 2px; }
.sync-state strong { font-size: 13px; font-weight: 650; }
.sync-state span:not(.status-dot) { color: var(--muted); font-size: 11px; }
.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #97a1a8;
  box-shadow: 0 0 0 4px #eef0f2;
}
.sync-state.is-healthy .status-dot { background: #27a273; box-shadow: 0 0 0 4px #e5f5ef; }
.sync-state.is-error .status-dot { background: var(--red); box-shadow: 0 0 0 4px var(--red-soft); }

.page-shell { max-width: 1480px; margin: 0 auto; padding: 22px 24px 40px; }
.summary-strip {
  display: grid;
  grid-template-columns: repeat(5, minmax(130px, 1fr)) minmax(210px, 1.3fr);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 7px;
  margin-bottom: 18px;
  overflow: hidden;
}
.summary-item { min-height: 82px; padding: 16px 20px; display: grid; align-content: center; gap: 5px; border-right: 1px solid var(--line-soft); }
.summary-item:last-child { border-right: 0; }
.summary-item span { color: var(--muted); font-size: 12px; }
.summary-item strong { font-size: 23px; line-height: 1.1; letter-spacing: 0; font-variant-numeric: tabular-nums; }
.summary-item--alert strong { color: var(--red); }
.summary-item--wide strong { font-size: 15px; font-weight: 650; }

.workspace { background: var(--surface); border: 1px solid var(--line); border-radius: 7px; overflow: hidden; }
.workspace__toolbar {
  min-height: 77px;
  padding: 15px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  border-bottom: 1px solid var(--line);
}
.workspace__toolbar h2 { margin: 0; font-size: 16px; letter-spacing: 0; }
.workspace__toolbar p, .section-heading p { margin: 4px 0 0; color: var(--muted); font-size: 12px; }
.toolbar-actions { display: flex; align-items: center; justify-content: flex-end; gap: 10px; flex-wrap: wrap; }
.search-field {
  width: min(260px, 30vw);
  height: 36px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 11px;
  border: 1px solid #cbd3d7;
  border-radius: 5px;
  background: #fff;
  color: #738089;
}
.search-field:focus-within { border-color: var(--green); box-shadow: 0 0 0 3px rgba(20, 122, 90, 0.12); }
.search-field svg { width: 16px; height: 16px; flex: 0 0 auto; }
.search-field input { min-width: 0; width: 100%; border: 0; outline: 0; color: var(--text); background: transparent; font-size: 13px; }
.segment-control { display: inline-flex; border: 1px solid #cbd3d7; border-radius: 5px; overflow: hidden; background: #fff; }
.segment-control button { min-height: 34px; padding: 0 12px; border: 0; border-right: 1px solid #d8dee1; background: #fff; color: #59666f; font-size: 12px; }
.segment-control button:last-child { border-right: 0; }
.segment-control button:hover { background: #f5f7f8; }
.segment-control button.is-active { background: #e9f3ef; color: #0e684c; font-weight: 700; }
.icon-button {
  width: 36px;
  height: 36px;
  padding: 0;
  display: grid;
  place-items: center;
  border: 1px solid #cbd3d7;
  border-radius: 5px;
  background: #fff;
  color: #4e5b64;
}
.icon-button:hover { background: #f4f7f7; color: var(--green); }
.icon-button:focus-visible, .segment-control button:focus-visible, tr[data-asin]:focus-visible { outline: 3px solid rgba(20, 122, 90, 0.22); outline-offset: -2px; }
.icon-button svg { width: 17px; height: 17px; }
.icon-button.is-loading svg { animation: spin 0.8s linear infinite; }
.icon-button--quiet { border-color: transparent; background: #f2f4f5; }

.table-wrap { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; table-layout: fixed; }
th { height: 39px; padding: 0 14px; text-align: left; background: #f7f8f9; border-bottom: 1px solid var(--line); color: #69757d; font-size: 11px; font-weight: 650; white-space: nowrap; }
td { height: 67px; padding: 8px 14px; border-bottom: 1px solid var(--line-soft); font-size: 13px; vertical-align: middle; }
th:nth-child(1) { width: 31%; }
th:nth-child(2) { width: 10%; }
th:nth-child(3) { width: 11%; }
th:nth-child(4) { width: 12%; }
th:nth-child(5) { width: 14%; }
th:nth-child(6) { width: 10%; }
th:nth-child(7) { width: 10%; }
th:nth-child(8) { width: 42px; }
tr[data-asin], tr[data-parent] { cursor: pointer; transition: background 120ms ease; }
tr[data-asin]:hover, tr[data-parent]:hover { background: #f7faf9; }
tr[data-asin]:last-child td, tr[data-parent]:last-child td { border-bottom: 0; }
.number-cell { text-align: right; font-variant-numeric: tabular-nums; }
.action-cell { padding-left: 4px; padding-right: 10px; text-align: center; }
.action-cell svg { width: 17px; height: 17px; color: #89949a; }
.product-cell { display: flex; align-items: center; min-width: 0; gap: 11px; }
.product-cell--child { padding-left: 38px; }
.parent-row { background: #f1f6f4; }
.parent-row:hover { background: #eaf2ef !important; }
.parent-row td { height: 62px; border-bottom-color: #d8e4df; }
.parent-row .product-meta strong { color: #155f49; font-size: 14px; }
.parent-row .metric-value { font-size: 17px; }
.parent-row .action-cell svg { color: #4d7467; }
.tree-toggle {
  width: 28px;
  height: 28px;
  margin-right: -4px;
  padding: 0;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: #48675d;
}
.tree-toggle:hover { background: #dceae5; }
.tree-toggle svg { width: 16px; height: 16px; }
.parent-badge {
  width: 45px;
  height: 45px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border: 1px solid #c9ded6;
  border-radius: 5px;
  background: #fff;
  color: #17654e;
  font-size: 12px;
  font-weight: 800;
}
.parent-label { display: inline-flex; align-items: center; gap: 6px; }
.parent-label .tag { min-height: 18px; padding-top: 0; padding-bottom: 0; }
.product-thumb { width: 45px; height: 45px; flex: 0 0 auto; border: 1px solid #e1e5e7; border-radius: 5px; overflow: hidden; background: #f2f4f5; display: grid; place-items: center; }
.product-thumb img { width: 100%; height: 100%; object-fit: contain; background: #fff; }
.product-thumb span { color: #78848b; font-size: 11px; font-weight: 700; }
.product-meta { min-width: 0; display: grid; gap: 3px; }
.product-meta strong { font-size: 13px; line-height: 1.2; letter-spacing: 0; }
.product-meta span { max-width: 100%; color: var(--muted); font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.metric-value { display: block; font-size: 16px; font-weight: 750; }
.metric-note { display: block; margin-top: 2px; color: var(--muted); font-size: 10px; }
.danger-text, .inventory-zero { color: var(--red) !important; }
.inventory-low { color: var(--amber) !important; }
.progress-cell { display: flex; align-items: center; gap: 10px; }
.progress-track { width: min(110px, 8vw); height: 5px; border-radius: 2px; background: #e8ecee; overflow: hidden; }
.progress-track i { display: block; height: 100%; background: var(--green); }
.progress-cell span { min-width: 40px; color: #4f5a62; font-size: 11px; font-variant-numeric: tabular-nums; }
.stockout-count { color: var(--red); font-weight: 700; }
.snapshot-date { color: #4f5a62; font-size: 12px; white-space: nowrap; }
.tag { display: inline-flex; align-items: center; min-height: 21px; padding: 2px 7px; border-radius: 4px; font-size: 10px; font-weight: 700; white-space: nowrap; }
.tag--ready { background: var(--green-soft); color: #0c694d; }
.tag--pending { background: var(--amber-soft); color: #82520d; }
.tag--danger { background: var(--red-soft); color: #b82f2f; }
.tag--neutral { background: #eef1f2; color: #5c6870; }
.loading-row td { height: 240px; text-align: center; color: var(--muted); }
.empty-state { min-height: 250px; display: grid; place-content: center; justify-items: center; gap: 8px; color: var(--muted); }
.empty-state svg { width: 24px; height: 24px; }
.empty-state strong { color: #536068; font-size: 13px; }
.table-footer { min-height: 43px; padding: 0 17px; display: flex; align-items: center; justify-content: space-between; border-top: 1px solid var(--line); color: var(--muted); font-size: 11px; }
.writeback-off { color: var(--amber); }

.detail-dialog { width: min(1180px, calc(100vw - 40px)); max-width: none; max-height: calc(100vh - 32px); padding: 0; border: 0; border-radius: 7px; background: #fff; box-shadow: 0 24px 80px rgba(19, 31, 38, 0.25); overflow: hidden; }
.detail-dialog::backdrop { background: rgba(21, 30, 35, 0.54); }
.dialog-frame { display: flex; flex-direction: column; max-height: calc(100vh - 32px); }
.dialog-header { min-height: 78px; padding: 13px 18px; display: flex; align-items: center; justify-content: space-between; gap: 18px; border-bottom: 1px solid var(--line); }
.dialog-product { min-width: 0; display: flex; align-items: center; gap: 12px; }
.product-thumb--large { width: 50px; height: 50px; }
.dialog-product > div:last-child { min-width: 0; }
.dialog-heading-row { display: flex; align-items: center; gap: 8px; }
.dialog-heading-row h2 { margin: 0; font-size: 18px; letter-spacing: 0; }
.dialog-product p { max-width: 800px; margin: 4px 0 0; color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dialog-content { overflow-y: auto; padding-bottom: 24px; }
.detail-metrics { display: grid; grid-template-columns: repeat(4, 1fr); border-bottom: 1px solid var(--line); background: #fafbfb; }
.detail-metrics > div { min-height: 74px; padding: 14px 20px; display: grid; align-content: center; gap: 4px; border-right: 1px solid var(--line-soft); }
.detail-metrics > div:last-child { border-right: 0; }
.detail-metrics span { color: var(--muted); font-size: 11px; }
.detail-metrics strong { font-size: 20px; letter-spacing: 0; font-variant-numeric: tabular-nums; }
.calculation-section, .chart-section, .daily-section { padding: 20px 20px 0; }
.section-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 12px; }
.section-heading h3 { margin: 0; font-size: 14px; letter-spacing: 0; }
.formula-total { padding-top: 1px; color: var(--green); font-size: 12px; font-weight: 700; font-variant-numeric: tabular-nums; }
.weight-grid { display: grid; grid-template-columns: repeat(4, 1fr); border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.weight-item { min-height: 95px; padding: 13px 15px; border-right: 1px solid var(--line); }
.weight-item:last-child { border-right: 0; }
.weight-title { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 9px; }
.weight-title strong { font-size: 12px; }
.weight-title span { color: var(--green); font-size: 12px; font-weight: 750; }
.weight-value { font-size: 16px; font-weight: 750; font-variant-numeric: tabular-nums; }
.weight-meta { margin-top: 5px; color: var(--muted); font-size: 10px; line-height: 1.45; }
.section-heading--chart { align-items: center; }
.chart-legend { display: flex; align-items: center; gap: 16px; margin-top: 7px; color: #647078; font-size: 10px; }
.chart-legend span { display: inline-flex; align-items: center; gap: 5px; }
.legend-line { width: 18px; height: 2px; background: var(--green); }
.legend-line--inventory { background: var(--blue); }
.legend-line--average { height: 0; border-top: 2px dashed var(--amber); background: transparent; }
.legend-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--red); }
.range-picker { width: 100%; margin-top: 10px; padding: 0 8px; }
.range-summary { min-height: 24px; display: flex; align-items: center; justify-content: space-between; gap: 12px; color: #46545c; font-size: 11px; font-variant-numeric: tabular-nums; }
.range-summary strong { font-size: 11px; }
.range-day-count { padding: 2px 6px; border-radius: 4px; background: #edf4f1; color: #126149; font-weight: 700; white-space: nowrap; }
.dual-range { position: relative; height: 24px; margin: 1px 8px 0; }
.dual-range__track { position: absolute; top: 10px; right: 0; left: 0; height: 5px; border-radius: 2px; background: #dfe5e7; overflow: hidden; }
.dual-range__selection { position: absolute; top: 0; bottom: 0; left: 0; width: 100%; background: var(--green); }
.dual-range input[type="range"] {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 2;
  width: 100%;
  height: 24px;
  margin: 0;
  padding: 0;
  appearance: none;
  -webkit-appearance: none;
  pointer-events: none;
  background: transparent;
  outline: 0;
}
.dual-range input[type="range"]:last-child { z-index: 3; }
.dual-range input[type="range"]::-webkit-slider-runnable-track { height: 5px; background: transparent; }
.dual-range input[type="range"]::-webkit-slider-thumb {
  width: 18px;
  height: 18px;
  margin-top: -7px;
  appearance: none;
  -webkit-appearance: none;
  border: 3px solid var(--green);
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 4px rgba(19, 52, 42, 0.25);
  pointer-events: auto;
  cursor: ew-resize;
}
.dual-range input[type="range"]::-moz-range-track { height: 5px; background: transparent; }
.dual-range input[type="range"]::-moz-range-thumb {
  width: 13px;
  height: 13px;
  border: 3px solid var(--green);
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 4px rgba(19, 52, 42, 0.25);
  pointer-events: auto;
  cursor: ew-resize;
}
.dual-range input[type="range"]:focus-visible::-webkit-slider-thumb { box-shadow: 0 0 0 4px rgba(20, 122, 90, 0.2); }
.dual-range input[type="range"]:focus-visible::-moz-range-thumb { box-shadow: 0 0 0 4px rgba(20, 122, 90, 0.2); }
.dual-range input[type="range"]:disabled::-webkit-slider-thumb { border-color: #9aa5aa; cursor: default; }
.dual-range input[type="range"]:disabled::-moz-range-thumb { border-color: #9aa5aa; cursor: default; }
.range-boundaries { display: flex; justify-content: space-between; padding: 0 7px; color: #8a949a; font-size: 9px; font-variant-numeric: tabular-nums; }
.chart-scroll { min-height: 350px; overflow: hidden; border: 1px solid var(--line); border-radius: 6px; background: #fff; }
.chart-canvas-wrap { width: 100%; height: 348px; min-width: 0; padding: 10px 8px 4px; }
.chart-canvas-wrap canvas { display: block; }
.daily-table-wrap { max-height: 280px; overflow: auto; border: 1px solid var(--line); border-radius: 6px; }
.daily-table { min-width: 650px; table-layout: auto; }
.daily-table th { position: sticky; top: 0; z-index: 1; height: 34px; }
.daily-table td { height: 38px; padding-top: 5px; padding-bottom: 5px; font-size: 11px; }
.daily-table th:nth-child(n) { width: auto; }
.valid-day { color: var(--green); font-weight: 650; }
.unknown-value { color: #a0a8ad; }
.toast { position: fixed; right: 20px; bottom: 20px; z-index: 20; max-width: min(360px, calc(100vw - 40px)); padding: 11px 14px; border-radius: 5px; background: #29343a; color: #fff; font-size: 12px; box-shadow: 0 8px 30px rgba(0,0,0,.18); }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 1000px) {
  .summary-strip { grid-template-columns: repeat(3, 1fr); }
  .summary-item { border-bottom: 1px solid var(--line-soft); }
  .summary-item--wide { grid-column: span 2; }
  .workspace__toolbar { align-items: flex-start; flex-direction: column; }
  .toolbar-actions { width: 100%; justify-content: flex-start; }
  .search-field { width: min(330px, 100%); }
  table { min-width: 1120px; }
  .weight-grid { grid-template-columns: repeat(2, 1fr); }
  .weight-item:nth-child(2) { border-right: 0; }
  .weight-item:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
  .daily-table { min-width: 650px; }
}

@media (max-width: 640px) {
  .topbar { height: 66px; }
  .topbar__inner { padding: 0 14px; }
  .brand__mark { width: 34px; height: 34px; }
  .brand h1 { font-size: 15px; }
  .brand p { font-size: 10px; }
  .sync-state span:not(.status-dot) { display: none; }
  .sync-state strong { font-size: 11px; }
  .page-shell { padding: 12px 10px 24px; }
  .summary-strip { grid-template-columns: repeat(2, 1fr); margin-bottom: 12px; }
  .summary-item { min-height: 69px; padding: 12px; }
  .summary-item:nth-child(even) { border-right: 0; }
  .summary-item strong { font-size: 19px; }
  .summary-item--wide { grid-column: span 2; border-bottom: 0; }
  .workspace__toolbar { padding: 13px; }
  .toolbar-actions { gap: 8px; }
  .search-field { width: calc(100% - 46px); order: -2; }
  #refresh-button { order: -1; }
  #status-filter { width: 100%; }
  #status-filter button { flex: 1; }
  .table-footer { align-items: flex-start; flex-direction: column; justify-content: center; gap: 3px; }
  .detail-dialog { width: 100vw; max-height: 100dvh; height: 100dvh; border-radius: 0; }
  .dialog-frame { max-height: 100dvh; height: 100%; }
  .dialog-header { min-height: 72px; padding: 10px 12px; }
  .product-thumb--large { width: 44px; height: 44px; }
  .dialog-heading-row h2 { font-size: 16px; }
  .dialog-product p { max-width: calc(100vw - 145px); }
  .detail-metrics { grid-template-columns: repeat(2, 1fr); }
  .detail-metrics > div { min-height: 64px; padding: 11px 14px; }
  .detail-metrics > div:nth-child(2) { border-right: 0; }
  .detail-metrics > div:nth-child(-n+2) { border-bottom: 1px solid var(--line-soft); }
  .calculation-section, .chart-section, .daily-section { padding: 16px 12px 0; }
  .weight-grid { grid-template-columns: 1fr; }
  .weight-item { min-height: 82px; border-right: 0; border-bottom: 1px solid var(--line); }
  .weight-item:last-child { border-bottom: 0; }
  .section-heading--chart { align-items: flex-start; flex-direction: column; }
  #range-control { width: 100%; }
  .chart-scroll { min-height: 330px; }
  .chart-canvas-wrap { height: 328px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
