@media (max-width: 1400px) and (min-width: 1101px) {
  .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
.wrap-cell { white-space: normal; min-width: 180px; max-width: 320px; }
.preline { white-space: pre-line; }

.base-products-page { margin: -18px -20px 0; }
.base-products-page header { margin-bottom: 12px; }
.base-products-page h1 { font-size: 27px; margin-bottom: 4px; }
.base-product-filters { padding: 8px 10px; margin-bottom: 6px; }
.base-product-filters input,
.base-product-filters select { padding: 7px 9px; }
.base-product-filters button { padding: 7px 13px; }
.table-scroll-top {
  height: 17px;
  overflow-x: auto;
  overflow-y: hidden;
  margin: 0 2px 6px;
  border-radius: 7px;
  background: #e8e6df;
}
.table-scroll-spacer { height: 1px; }
.base-products-table-wrap { max-height: calc(100vh - 190px); border-radius: 8px; }
.base-products-table { width: max-content; min-width: 100%; font-size: 12px; }
.base-products-table th,
.base-products-table td { padding: 7px 8px; line-height: 1.35; }
.base-products-table th { position: sticky; top: 0; z-index: 2; }
.base-products-table td small { font-size: 10px; }
.base-products-table .material-name-cell { white-space: normal; min-width: 140px; max-width: 175px; }
.base-products-table .wrap-cell { min-width: 115px; max-width: 185px; }
.base-products-table .spec-cell { min-width: 62px; max-width: 80px; }
.base-products-table .packaging-cell { min-width: 130px; max-width: 175px; }
.base-products-table .override-clear{display:block;margin-top:3px;color:var(--muted);font-size:10px;white-space:nowrap}
.base-products-table .override-clear input{width:auto;margin-right:3px}
.material-code-cell { position: relative; padding-right: 20px !important; }
.version-tip {
  position: absolute;
  top: 3px;
  right: 5px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #ead8b1;
  color: #7d5a22;
  font: 700 9px/14px Georgia, serif;
  text-align: center;
  cursor: help;
}
.version-tooltip {
  position: absolute;
  z-index: 8;
  right: -4px;
  top: 20px;
  display: none;
  width: max-content;
  max-width: 180px;
  padding: 6px 9px;
  border-radius: 7px;
  background: #20302b;
  color: #fff;
  font: 11px/1.35 Inter, "Microsoft YaHei", sans-serif;
  box-shadow: 0 5px 18px rgba(25, 42, 36, .18);
}
.version-tip:hover .version-tooltip,
.version-tip:focus .version-tooltip { display: block; }
.inline-edit { width: 100%; min-width: 115px; padding: 5px 7px; font-size: 12px; }
.sale-select { min-width: 58px; }
.inline-save { padding: 6px 10px; font-size: 12px; }

.dashboard-kpis { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.metric-kpi { position: relative; }
.metric-info {
  position: absolute;
  z-index: 5;
  top: 10px;
  right: 10px;
  width: 20px;
  height: 20px;
  border: 1px solid #b8c5c0;
  border-radius: 50%;
  color: #567069;
  font: 700 12px/18px Georgia, serif;
  text-align: center;
  cursor: help;
}
.metric-tooltip {
  position: absolute;
  z-index: 12;
  top: 26px;
  right: -4px;
  display: none;
  width: 280px;
  padding: 10px 12px;
  border-radius: 8px;
  background: #20302b;
  color: #fff;
  font: 12px/1.55 Inter, "Microsoft YaHei", sans-serif;
  text-align: left;
  box-shadow: 0 8px 24px rgba(25, 42, 36, .2);
}
.metric-info:hover .metric-tooltip,
.metric-info:focus .metric-tooltip,
.metric-info:focus-within .metric-tooltip { display: block; }
.expiry-alert-table {
  max-height: 420px;
  overflow-x: hidden;
}
.expiry-alert-table table {
  width: 100%;
  table-layout: fixed;
  white-space: normal;
}
.expiry-alert-table th,
.expiry-alert-table td {
  padding: 7px 5px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}
.expiry-alert-table th:nth-child(1) { width: 9%; }
.expiry-alert-table th:nth-child(2) { width: 16%; }
.expiry-alert-table th:nth-child(3) { width: 21%; }
.expiry-alert-table th:nth-child(4) { width: 11%; }
.expiry-alert-table th:nth-child(5) { width: 15%; }
.expiry-alert-table th:nth-child(6) { width: 16%; }
.expiry-alert-table th:nth-child(7) { width: 12%; }
.expiry-alert-table td:nth-child(2),
.expiry-alert-table td:nth-child(n+4) {
  font-size: 10px;
  white-space: nowrap;
}
.expiry-alert-table .badge { padding: 2px 4px; }
.expiry-alert-table th {
  position: sticky;
  z-index: 2;
  top: 0;
}
.brand-overview {
  margin-bottom: 18px;
  padding-bottom: 3px;
}
.brand-overview .panel-title {
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}
.brand-card-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 10px;
}
.brand-card {
  --brand-color: #315b4e;
  min-width: 0;
  min-height: 220px;
  padding: 15px 12px 14px;
  border: 1px solid var(--line);
  border-top: 4px solid var(--brand-color);
  border-radius: 12px;
  background: #fff;
}
.brand-card-1 { --brand-color: #c91d36; }
.brand-card-2 { --brand-color: #7857b5; }
.brand-card-3 { --brand-color: #06715b; }
.brand-card-4 { --brand-color: #191919; }
.brand-card-5 { --brand-color: #b52f51; }
.brand-card-6 { --brand-color: #5f605c; }
.brand-card-7 { --brand-color: #07569f; }
.brand-card-main-link {
  display: block;
  color: inherit;
  text-decoration: none;
}
.brand-card h3 {
  margin: 0 0 10px;
  color: var(--brand-color);
  font-size: 15px;
  font-weight: 600;
}
.brand-card-amount {
  display: flex;
  align-items: baseline;
  gap: 4px;
  min-height: 43px;
  color: var(--brand-color);
}
.brand-card-amount span { font-size: 20px; }
.brand-card-amount strong {
  overflow: hidden;
  font: 500 23px/1.25 Georgia, "Microsoft YaHei", serif;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.brand-card-amount small { color: var(--muted); }
.brand-card p {
  margin: 5px 0;
  color: var(--muted);
  font-size: 12px;
}
.brand-card-safety.good { color: #07845d; }
.brand-card-safety.warn { color: #b4762c; }
.brand-card-safety.danger { color: #c43b3b; }
.brand-card-alert {
  display: inline-block;
  margin-top: 8px;
  padding: 3px 8px;
  border: 1px solid #d8d8d2;
  border-radius: 6px;
  color: var(--muted);
  font-size: 11px;
  text-decoration: none;
}
.brand-card-alert.active {
  border-color: #e9aaa5;
  background: #fff3f1;
  color: #bf3b35;
}
.age-analysis-grid { grid-template-columns: minmax(320px, .8fr) minmax(520px, 1.7fr); }
.age-analysis-grid .panel canvas { height: 315px !important; }
.chart-note {
  margin-top: 10px;
  padding: 8px 10px;
  border-radius: 7px;
  background: #f6eee1;
  color: #88612d;
  font-size: 12px;
}
.trend-panel canvas { height: 360px !important; }
.dashboard-pair {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: start;
}
.dashboard-pair .panel {
  min-width: 0;
  margin-bottom: 0;
}
.dashboard-pair .mini-table,
.dashboard-pair .expiry-alert-table { max-height: 360px; }
.dashboard-pair table { font-size: 12px; }
.brand-page-header .brand-switcher {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
}
.brand-kpis {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}
.brand-kpis .kpi { min-width: 0; }
.benchmark-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}
.benchmark-grid > div {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #faf9f5;
}
.benchmark-grid small,
.benchmark-grid span { display: block; color: var(--muted); }
.benchmark-grid strong { display: block; margin: 5px 0; font: 500 23px/1.3 Georgia, serif; }
.brand-structure-grid,
.brand-analysis-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.brand-analysis-grid canvas { height: 300px !important; }
.brand-safety-table { max-height: 440px; }
.brand-product-table { max-height: 520px; }
.brand-replenishment-table { max-height: 620px; }
.brand-safety-table th,
.brand-product-table th,
.brand-replenishment-table th { position: sticky; top: 0; z-index: 2; }
.inline-action { display: flex; gap: 6px; }
.inline-action input { width: 90px; }
.inline-action button { padding: 7px 10px; }
.brand-replenishment-table input[type="number"] { width: 92px; }
.brand-replenishment-table input[type="date"] { width: 128px; }
.brand-replenishment-table input[name^="reason_"] { width: 150px; }
.brand-submit { margin-top: 14px; }
.readonly-note { margin-top: 12px; }
.brand-age-panel canvas { height: 330px !important; }
.age-inventory-pair { grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: stretch; }
.age-inventory-pair > .panel { min-width: 0; margin: 0; }
.age-inventory-pair #topInventoryChart { height: 330px !important; }
.panel-actions { display: flex; align-items: center; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.brand-header-actions { display: flex; align-items: end; gap: 12px; }
.analysis-export-dialog { width: min(560px, calc(100vw - 32px)); border: 0; border-radius: 14px; padding: 22px; box-shadow: 0 18px 60px rgba(25,45,38,.25); }
.analysis-export-dialog::backdrop { background: rgba(18,35,29,.42); }
.analysis-export-dialog .panel-title button { padding: 6px 10px; }
.export-section-list { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 9px; margin: 16px 0; }
.export-section-list label { display: flex; align-items: center; gap: 8px; padding: 10px; border: 1px solid var(--line); border-radius: 8px; }
.export-status { margin: 0 0 14px; font-size: 12px; }
.interactive-chart-legend { display: flex; justify-content: center; gap: 14px; flex-wrap: wrap; margin: 7px 0 0; }
.chart-legend-item { display: inline-flex; align-items: center; gap: 6px; padding: 3px 5px; background: transparent; color: var(--ink); font-size: 11px; }
.chart-legend-item i { width: 28px; height: 10px; border-radius: 2px; }
.chart-legend-item.is-hidden { opacity: .42; text-decoration: line-through; }
.chart-legend-item:focus-visible { outline: 2px solid #547d9b; outline-offset: 2px; }
.chart-toolbar { display: flex; justify-content: flex-end; margin: 0 0 8px; }
.chart-toolbar button { padding: 6px 10px; font-size: 12px; }
.comparison-toggle { padding: 6px 10px; border: 1px solid #b8c9c2; border-radius: 8px; background: #fff; color: #355a4d; font-size: 12px; cursor: pointer; }
.comparison-toggle[aria-pressed="true"] { color: #fff; background: #3d6659; border-color: #3d6659; }
.long-stock-groups { display: grid; gap: 10px; }
.long-stock-group { overflow: hidden; border: 1px solid var(--line); border-left: 4px solid #71817b; border-radius: 8px; background: #fff; }
.long-stock-group.expiry { border-left-color: #b85e4d; background: #fff9f7; }
.long-stock-group.experience { border-left-color: #d39b55; background: #fffbf3; }
.long-stock-group.standard { border-left-color: #3d6659; background: #f7fbf9; }
.long-stock-group h3 { display: flex; justify-content: space-between; margin: 0; padding: 8px 10px; font-size: 13px; }
.long-stock-group h3 span { min-width: 24px; padding: 1px 7px; border-radius: 12px; background: rgba(255,255,255,.8); text-align: center; color: var(--muted); }
.long-stock-panel { margin-top: 18px; }
.slow-selling-table { max-height: 420px; }
.slow-selling-table th { position: sticky; top: 0; z-index: 2; }
.inventory-age-line { display: block; white-space: nowrap; }
.long-stock-group .table-wrap { max-height: 220px; border: 0; border-radius: 0; }
.long-stock-group table { font-size: 12px; }
.long-stock-group th, .long-stock-group td { padding: 7px 8px; white-space: nowrap; }
.analysis-chart-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.analysis-chart-grid > div { min-width: 0; padding: 12px; border: 1px solid var(--line); border-radius: 10px; }
.analysis-chart-grid h3 { margin: 0 0 8px; font-size: 14px; }
.analysis-chart-grid canvas,
.box-turnover-chart,
.box-sales-chart,
.hot-product-market-chart { height: 340px !important; }
.analysis-summary { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.analysis-summary span { padding: 8px 11px; border-radius: 8px; background: #f5f3ed; color: var(--muted); }
.analysis-summary b { margin-left: 5px; color: var(--ink); }
.hot-product-sales-list { margin: 10px 0 16px; }
.hot-product-sales-list .table-wrap { max-height: 390px; }
.hot-product-sales-list th { position: sticky; top: 0; z-index: 2; }
.hot-product-sales-list th,
.hot-product-sales-list td { padding: 8px 10px; }
.hot-product-select { width: 100%; padding: 7px 9px; border: 1px solid #c8d5d0; border-radius: 7px; background: #f4f7f5; color: var(--accent); text-align: left; }
.hot-product-select.active { border-color: var(--green); background: var(--green); color: #fff; }
.test-badge { padding: 5px 9px; border-radius: 14px; background: #fff0dc; color: #8c5719; font-size: 12px; }

@media (max-width: 1400px) {
  .dashboard-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 900px) {
  .brand-card-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dashboard-pair { grid-template-columns: 1fr; }
  .brand-kpis,
  .benchmark-grid,
  .brand-structure-grid,
  .brand-analysis-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .analysis-chart-grid { grid-template-columns: 1fr; }
  .age-inventory-pair { grid-template-columns: 1fr; }
}

@media (max-width: 700px) {
  .brand-header-actions { flex-wrap: wrap; }
  .export-section-list { grid-template-columns: 1fr; }
  .dashboard-kpis { grid-template-columns: 1fr; }
  .brand-card-grid { grid-template-columns: 1fr; }
  .metric-tooltip { width: min(250px, calc(100vw - 64px)); }
  .age-analysis-grid { grid-template-columns: 1fr; }
  .brand-kpis,
  .benchmark-grid,
  .brand-structure-grid,
  .brand-analysis-grid { grid-template-columns: 1fr; }
  .base-products-page { margin: 0; }
  .base-products-table-wrap { max-height: none; }
}
