:root {
  --bg: #f7f3ed;
  --surface: #fffdf9;
  --surface-2: #fff;
  --ink: #17110d;
  --muted: #3f332c;
  --line: #e8dccc;
  --grid: #efe5dc;
  --orange: #f97316;
  --amber: #f59e0b;
  --coral: #dc5b42;
  --brown: #9a5a2e;
  --green: #5c8a4b;
  --blue: #477f9c;
  --plum: #89577b;
  --sage: #7b8d56;
  --shadow: 0 18px 45px rgba(84, 50, 22, 0.1);
  --shadow-soft: 0 8px 20px rgba(84, 50, 22, 0.07);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", sans-serif;
  line-height: 1.45;
}

button,
input,
select,
textarea {
  font: inherit;
}

.skip-link {
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 20;
  transform: translateY(-140%);
  border-radius: 999px;
  background: var(--ink);
  color: var(--surface);
  padding: 10px 14px;
  text-decoration: none;
}

.skip-link:focus {
  transform: translateY(0);
}

.loading {
  position: fixed;
  inset: 0;
  z-index: 15;
  display: grid;
  place-items: center;
  background: rgba(248, 244, 238, 0.88);
  backdrop-filter: blur(12px);
}

.loading.is-hidden {
  display: none;
}

.loading-card {
  display: flex;
  align-items: center;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  padding: 16px 18px;
  box-shadow: var(--shadow);
  color: var(--muted);
  font-weight: 700;
}

.spinner {
  width: 18px;
  height: 18px;
  border: 3px solid #f2d8bf;
  border-top-color: var(--orange);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(1turn);
  }
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(250px, 284px) minmax(0, 1fr);
  isolation: isolate;
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  z-index: 12;
  height: 100vh;
  overflow-y: auto;
  padding: 28px 22px;
  border-right: 1px solid var(--line);
  background: rgba(255, 250, 244, 0.98);
  backdrop-filter: blur(20px);
}

.brand {
  display: flex;
  gap: 13px;
  align-items: center;
  margin-bottom: 34px;
}

.brand-mark {
  display: grid;
  flex: 0 0 auto;
  width: 82px;
  height: 82px;
  place-items: center;
  border: 1px solid #ecd4bf;
  border-radius: 18px;
  background:
    linear-gradient(#fffdfa, #fffdfa) padding-box,
    linear-gradient(145deg, rgba(255, 176, 92, 0.75), rgba(154, 90, 46, 0.36)) border-box;
  padding: 6px;
  box-shadow: 0 12px 24px rgba(84, 50, 22, 0.14), inset 0 0 0 1px rgba(255, 255, 255, 0.74);
}

.brand-mark img {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 13px;
  object-fit: contain;
  object-position: center;
}

.brand h1,
.brand p,
.topbar h2,
.topbar p,
.panel h3,
.panel p {
  margin: 0;
}

.brand h1 {
  font-size: 19px;
  letter-spacing: 0;
}

.brand p,
.panel p,
.note p {
  color: var(--muted);
  font-size: 14px;
}

.filters {
  margin: 0;
}

.control-group {
  margin-bottom: 18px;
}

.control-group label {
  display: block;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 750;
}

select,
input,
textarea {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.74);
  color: var(--ink);
  font-size: 16px;
  padding: 0 12px;
  outline: none;
  transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
}

.scope-switch {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  margin-top: 8px;
}

.scope-switch button {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.62);
  color: var(--muted);
  padding: 7px 10px;
  font-size: 13px;
  font-weight: 800;
}

.scope-switch button[aria-pressed="true"] {
  border-color: #efc6a5;
  background: #fff1df;
  color: var(--brown);
  box-shadow: inset 0 0 0 1px rgba(249, 115, 22, 0.1), 0 6px 14px rgba(84, 50, 22, 0.07);
}

textarea {
  min-height: 76px;
  resize: vertical;
  padding-top: 10px;
  line-height: 1.35;
}

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

select:focus,
input:focus,
textarea:focus,
button:focus-visible {
  border-color: var(--orange);
  box-shadow: 0 0 0 3px rgba(249, 115, 22, 0.18);
}

button {
  min-height: 44px;
  cursor: pointer;
  transition: transform 160ms ease, border-color 160ms ease, background 160ms ease;
}

button:hover {
  border-color: #e8bc98;
  background: #fff5eb;
}

button:active {
  transform: scale(0.98);
}

.upload-panel {
  margin-top: 8px;
  padding: 15px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.58);
}

.upload-panel span {
  color: var(--brown);
  font-size: 14px;
  font-weight: 750;
}

.upload-panel p {
  margin: 4px 0 12px;
  color: var(--muted);
  font-size: 13px;
}

.upload-button,
.upload-panel button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fffaf4;
  color: var(--brown);
  padding: 8px 12px;
  font-size: 15px;
  font-weight: 750;
  cursor: pointer;
}

.upload-button:hover,
.upload-panel button:hover {
  border-color: #e8bc98;
  background: #fff5eb;
}

.upload-check {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 10px 0;
  color: var(--muted);
  min-height: 44px;
  font-size: 13px;
  font-weight: 700;
}

.upload-check input {
  box-sizing: border-box;
  flex: 0 0 18px;
  width: 18px;
  height: 18px;
  min-height: 18px;
  padding: 0;
  accent-color: var(--orange);
}

.control-group .toggle-row {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr);
  align-items: start;
  gap: 9px;
  min-height: 44px;
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  font-weight: 750;
  line-height: 1.35;
  cursor: pointer;
}

.control-group .toggle-row input {
  box-sizing: border-box;
  flex: 0 0 18px;
  width: 18px;
  height: 18px;
  min-height: 18px;
  margin-top: 2px;
  padding: 0;
  accent-color: var(--orange);
}

.special-rules-group {
  margin-top: -6px;
}

.control-group .special-toggle-row {
  margin-top: 10px;
}

.rule-mode {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 4px;
  margin: 10px 0 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.62);
  padding: 4px;
}

.rule-mode legend {
  grid-column: 1 / -1;
  margin: 0 0 2px 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.rule-mode label {
  position: relative;
  display: grid;
  overflow: hidden;
  min-height: 44px;
  place-items: center;
  border-radius: 9px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  line-height: 1.15;
  text-align: center;
  cursor: pointer;
  transition: background 160ms ease, color 160ms ease, box-shadow 160ms ease;
}

.rule-mode input {
  position: absolute;
  inset: 0;
  box-sizing: border-box;
  width: 100%;
  height: 100%;
  min-height: 0;
  margin: 0;
  padding: 0;
  opacity: 0;
  cursor: pointer;
}

.rule-mode span {
  position: relative;
  pointer-events: none;
}

.rule-mode label:has(input:checked) {
  background: #fff1df;
  color: var(--brown);
  box-shadow: inset 0 0 0 1px #efc6a5, 0 4px 10px rgba(84, 50, 22, 0.06);
}

.rule-mode label:has(input:focus-visible) {
  box-shadow: 0 0 0 3px rgba(249, 115, 22, 0.18);
}

.field-hint {
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.upload-status {
  margin: 10px 0 0 !important;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

.active-filters {
  margin-top: 24px;
}

.active-filters > span {
  display: block;
  margin-bottom: 9px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 750;
}

#activeFilters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.filter-chip {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  border: 1px solid #ead2bc;
  border-radius: 999px;
  background: #fff7ee;
  color: var(--brown);
  padding: 5px 10px;
  font-size: 13px;
  font-weight: 700;
}

.filter-chip small {
  margin-right: 2px;
}

.filter-chip small::after {
  content: ": ";
}

.note {
  margin-top: 28px;
  padding: 15px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.58);
}

.note span {
  color: var(--brown);
  font-size: 14px;
  font-weight: 750;
}

.special-panel {
  margin-top: 18px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.58);
}

.special-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.special-head span {
  color: var(--brown);
  font-size: 14px;
  font-weight: 750;
}

.special-head button {
  min-height: 40px;
  padding: 7px 11px;
  font-size: 13px;
}

.special-head button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.special-summary {
  display: grid;
  gap: 8px;
}

.special-summary p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.special-mode-note {
  border-radius: 10px;
  background: #fff7ee;
  padding: 8px 9px;
  color: var(--brown) !important;
  font-weight: 750;
}

.special-mode-note.only {
  background: rgba(92, 138, 75, 0.12);
  color: #496f3d !important;
}

.special-mode-note.all {
  background: rgba(71, 127, 156, 0.11);
  color: #3f6f87 !important;
}

.special-rule-line {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.special-stat {
  display: grid;
  gap: 2px;
}

.special-stat strong {
  color: var(--ink);
  font-size: 19px;
}

.special-stat span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.special-summary ul {
  display: grid;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.special-summary li {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.special-summary li span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.special-summary li em {
  color: var(--brown);
  font-style: normal;
  font-weight: 750;
}

.pin-panel {
  margin-top: 18px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.58);
}

.pin-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.pin-head span {
  color: var(--brown);
  font-size: 14px;
  font-weight: 750;
}

.pin-head button {
  min-height: 40px;
  padding: 7px 11px;
  font-size: 13px;
}

.pin-list {
  display: grid;
  gap: 8px;
}

.pin-empty {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.pin-chip {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-height: 42px;
  border-radius: 12px;
  text-align: left;
  white-space: normal;
}

.pin-chip span {
  overflow: hidden;
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pin-chip strong {
  color: var(--ink);
  font-size: 13px;
}

.dashboard {
  position: relative;
  z-index: 0;
  min-width: 0;
  padding: 30px clamp(18px, 2.6vw, 34px) 42px;
}

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

.eyebrow {
  color: var(--brown);
  font-size: 14px;
  font-weight: 750;
  text-transform: uppercase;
}

.topbar h2 {
  margin-top: 3px;
  font-size: 34px;
  letter-spacing: 0;
}

.date-pill,
button {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fffaf4;
  color: var(--brown);
  padding: 9px 13px;
  font-size: 15px;
  font-weight: 700;
  white-space: nowrap;
}

.insight-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.insight {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 72px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.62);
  padding: 14px 16px;
  box-shadow: var(--shadow-soft);
}

.insight-mark {
  display: grid;
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: 11px;
  background: #fff1df;
  color: var(--brown);
  font-weight: 900;
}

.insight strong {
  display: block;
  font-size: 18px;
}

.insight small {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

.insight p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.alert-rail {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 0;
  margin: -2px 0 14px;
}

.alert-chip {
  min-height: 40px;
  border-radius: 999px;
  padding: 6px 11px;
  font-size: 13px;
}

.alert-chip.positive {
  border-color: rgba(92, 138, 75, 0.3);
  background: rgba(92, 138, 75, 0.1);
  color: #496f3d;
}

.alert-chip.negative {
  border-color: rgba(220, 91, 66, 0.3);
  background: rgba(220, 91, 66, 0.1);
  color: #a94330;
}

.alert-chip.warm {
  border-color: rgba(245, 158, 11, 0.34);
  background: rgba(245, 158, 11, 0.11);
  color: #8a5608;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(162px, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.kpi {
  position: relative;
  min-height: 116px;
  padding: 15px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255, 250, 244, 0.9);
  box-shadow: 0 10px 28px rgba(84, 50, 22, 0.06);
  cursor: default;
  overflow: hidden;
  outline: none;
  transition: transform 180ms ease, box-shadow 180ms ease, border-color 180ms ease, background 180ms ease;
}

.kpi::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.55), rgba(249, 115, 22, 0.08) 48%, transparent 72%);
  opacity: 0;
  transition: opacity 180ms ease;
}

.kpi > * {
  position: relative;
  z-index: 1;
}

.kpi:hover,
.kpi:focus-within,
.kpi:focus-visible {
  transform: translateY(-4px);
  border-color: #e7bc99;
  background: #fffbf6;
  box-shadow: 0 18px 38px rgba(84, 50, 22, 0.13);
}

.kpi:hover::after,
.kpi:focus-within::after,
.kpi:focus-visible::after {
  opacity: 1;
}

.kpi-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.kpi span,
.kpi-add span {
  color: var(--muted);
  font-size: 14px;
  font-weight: 650;
}

.kpi-remove {
  display: grid;
  flex: 0 0 auto;
  width: 44px;
  min-width: 44px;
  height: 44px;
  min-height: 44px;
  place-items: center;
  border: 1px solid transparent;
  border-radius: 50%;
  background: transparent;
  color: #9a6a4f;
  padding: 0;
  font-size: 19px;
  line-height: 1;
  opacity: 0.58;
}

.kpi-remove:hover,
.kpi-remove:focus-visible {
  border-color: #ead2bc;
  background: #fff1df;
  opacity: 1;
}

.kpi strong {
  display: block;
  margin-top: 9px;
  font-size: clamp(24px, 2.1vw, 31px);
  letter-spacing: 0;
  white-space: nowrap;
  transform-origin: left center;
  transition: color 180ms ease, transform 180ms ease;
}

.kpi:hover strong,
.kpi:focus-within strong,
.kpi:focus-visible strong {
  color: #100b08;
  transform: scale(1.025);
}

.kpi em {
  display: block;
  margin-top: 6px;
  color: var(--brown);
  font-size: 14px;
  font-style: normal;
}

.kpi-add {
  border-style: dashed;
  background: rgba(255, 255, 255, 0.48);
  cursor: pointer;
}

.kpi-add select {
  margin-top: 10px;
  min-height: 44px;
  font-size: 14px;
  padding: 0 10px;
}

.chart-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 14px;
}

.stage-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin: 16px 0 10px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255, 253, 249, 0.72);
  padding: 12px 14px;
  box-shadow: var(--shadow-soft);
}

.stage-toolbar .eyebrow {
  margin: 0 0 2px;
  font-size: 12px;
}

.stage-toolbar strong {
  display: block;
  font-size: 17px;
}

.stage-switch {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.stage-switch button {
  min-height: 42px;
  border-color: #ead8c6;
  background: rgba(255, 250, 244, 0.88);
}

.stage-switch button[aria-pressed="true"] {
  border-color: #efc6a5;
  background: #fff1df;
  color: var(--brown);
  box-shadow: inset 0 0 0 1px rgba(249, 115, 22, 0.12);
}

.dashboard.has-product-selection .stage-toolbar,
.dashboard.has-product-selection .analysis-stage,
.dashboard.has-product-selection .diagnostic-grid {
  display: none;
}

.selected-products-focus {
  display: block;
  margin: 16px 0 14px;
  border: 1px solid #e8d7c5;
  border-radius: 20px;
  background: rgba(255, 253, 249, 0.74);
  padding: 18px;
  box-shadow: var(--shadow-soft);
}

.selected-products-focus[hidden] {
  display: none;
}

.selected-products-focus .section-head {
  margin-bottom: 14px;
}

.selected-products-focus .section-head button {
  min-width: 118px;
}

.selected-product-summary {
  margin: 0 0 14px;
}

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

.selected-product-grid .wide {
  grid-column: 1 / -1;
}

.selected-products-focus.has-many-products .selected-product-grid {
  grid-template-columns: 1fr;
}

.selected-chart {
  height: 520px;
  min-height: 520px;
  overflow: auto;
  overscroll-behavior: contain;
}

.chart.selected-chart svg {
  display: block;
  width: 100%;
  min-width: 900px;
  height: auto;
  min-height: 100%;
}

.chart-expand-button {
  flex: 0 0 auto;
  min-height: 38px;
  border-color: #ead8c6;
  background: #fffaf4;
  color: var(--brown);
  padding: 7px 12px;
  font-size: 13px;
  font-weight: 800;
}

.momentum-switch {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
}

.momentum-switch button {
  min-height: 38px;
  border-color: #ead8c6;
  background: rgba(255, 250, 244, 0.9);
  padding: 0 14px;
  font-size: 13px;
}

.momentum-switch button[aria-pressed="true"] {
  border-color: #efc6a5;
  background: #fff1df;
  color: var(--brown);
  box-shadow: inset 0 0 0 1px rgba(249, 115, 22, 0.12);
}

.analysis-stage {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 14px;
  align-items: start;
  margin: 0 0 14px;
  transition: grid-template-columns 220ms ease;
}

.analysis-stage[data-stage-mode="date"] {
  grid-template-columns: minmax(0, 1.38fr) minmax(330px, 0.62fr);
}

.analysis-stage[data-stage-mode="rolling"] {
  grid-template-columns: minmax(0, 1.38fr) minmax(330px, 0.62fr);
}

.analysis-stage[data-stage-mode="rolling"] .rolling-stage {
  order: 1;
}

.analysis-stage[data-stage-mode="rolling"] .inweek-section {
  order: 2;
}

.analysis-stage .inweek-section {
  margin: 0;
}

.rolling-stage {
  position: sticky;
  top: 16px;
  align-self: start;
  max-height: calc(100vh - 32px);
  overflow: auto;
  overscroll-behavior: contain;
  padding-right: 2px;
}

.analysis-stage[data-stage-mode="split"] .rolling-stage .chart,
.analysis-stage[data-stage-mode="date"] .rolling-stage .chart {
  height: 340px;
}

.analysis-stage[data-stage-mode="rolling"] .rolling-stage .chart {
  height: 430px;
}

.analysis-stage[data-stage-mode="rolling"] .rolling-stage .chart.tall {
  height: 520px;
}

.analysis-stage[data-stage-mode="rolling"] .inweek-section .chart {
  height: 340px;
}

.rolling-stage .panel-head {
  padding: 15px 16px 6px;
}

.rolling-stage .panel h3 {
  font-size: 19px;
}

.rolling-stage .panel p {
  font-size: 13px;
}

.rolling-stage .chart {
  height: 340px;
  padding: 8px 14px 18px;
}

.rolling-stage .chart.tall {
  height: 420px;
}

.inweek-section {
  margin: 16px 0;
  border: 1px solid #e8d7c5;
  border-radius: 20px;
  background: rgba(255, 253, 249, 0.72);
  padding: 18px;
  box-shadow: var(--shadow-soft);
}

.section-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 12px;
}

.section-head h3 {
  margin: 2px 0 0;
  font-size: 24px;
}

.section-head button {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fffaf4;
  color: var(--brown);
  padding: 7px 13px;
  font-size: 14px;
  font-weight: 800;
}

.section-head button[aria-pressed="true"] {
  background: #fff1df;
  box-shadow: inset 0 0 0 1px #efc6a5;
}

.range-toolbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto;
  gap: 10px;
  align-items: end;
  margin: 6px 0 12px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.54);
  padding: 12px;
}

.range-toolbar label {
  display: grid;
  gap: 6px;
}

.range-toolbar span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.range-toolbar button,
.range-toolbar select {
  min-height: 44px;
}

.day-chip-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(96px, 1fr));
  gap: 8px;
}

.day-chip {
  display: grid;
  gap: 2px;
  min-height: 70px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.68);
  color: var(--muted);
  padding: 8px 9px;
  text-align: left;
  transition: transform 160ms ease, border-color 160ms ease, background 160ms ease, box-shadow 160ms ease;
}

.day-chip:hover,
.day-chip:focus-visible {
  transform: translateY(-2px);
  border-color: #e7bc99;
  background: #fffaf4;
  box-shadow: 0 12px 22px rgba(84, 50, 22, 0.1);
}

.day-chip.is-active {
  border-color: #efc6a5;
  background: #fff5eb;
  box-shadow: 0 8px 18px rgba(84, 50, 22, 0.08);
}

.day-chip span {
  overflow: hidden;
  font-size: clamp(11px, 0.75vw, 12px);
  font-weight: 850;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.day-chip strong {
  color: var(--ink);
  font-size: clamp(16px, 1.08vw, 18px);
  line-height: 1.05;
  white-space: nowrap;
}

.day-chip em {
  color: var(--brown);
  overflow: hidden;
  font-size: clamp(11px, 0.75vw, 12px);
  font-style: normal;
  font-weight: 750;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.range-summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(108px, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.range-summary-card {
  min-height: 86px;
  border: 1px solid #ead8c6;
  border-radius: 15px;
  background: rgba(255, 250, 244, 0.9);
  padding: 11px;
  box-shadow: 0 8px 18px rgba(84, 50, 22, 0.05);
}

.range-summary-card span {
  display: block;
  overflow: hidden;
  color: var(--muted);
  font-size: clamp(11px, 0.78vw, 13px);
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.range-summary-card strong {
  display: block;
  margin-top: 6px;
  color: var(--ink);
  font-size: clamp(20px, 1.45vw, 24px);
  line-height: 1.05;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.range-summary-card em {
  display: block;
  overflow: hidden;
  margin-top: 6px;
  color: var(--brown);
  font-size: clamp(10px, 0.72vw, 12px);
  font-style: normal;
  font-weight: 750;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.inweek-grid {
  margin-top: 12px;
}

.diagnostic-grid {
  margin-top: 14px;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 250, 244, 0.92);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.panel-highlight {
  animation: panelPulse 1300ms cubic-bezier(0.2, 0.8, 0.2, 1);
}

.panel.wide {
  grid-column: auto;
}

.panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  padding: 18px 20px 8px;
}

.panel h3 {
  font-size: 22px;
}

.chart {
  position: relative;
  height: 430px;
  padding: 10px 22px 22px;
}

.chart.tall {
  height: 520px;
}

.adaptive-donut-chart {
  height: 430px;
  padding: 2px 14px 14px;
}

.adaptive-donut-chart.is-compact-donut {
  height: 520px;
}

.chart svg {
  width: 100%;
  height: 100%;
  overflow: visible;
}

.axis-label,
.tick,
.legend {
  fill: var(--muted);
  font-size: 16px;
  font-weight: 750;
}

.product-axis-label {
  fill: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.chart-title-note {
  fill: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

.series-label {
  fill: var(--ink);
  font-size: 14px;
  font-weight: 800;
}

.chart-value-label {
  fill: var(--ink);
  font-size: 14px;
  font-weight: 850;
  pointer-events: none;
  paint-order: stroke;
  stroke: #fffaf4;
  stroke-linejoin: round;
  stroke-width: 5px;
}

.chart-value-label.small {
  font-size: 12px;
  stroke-width: 4px;
}

.chart-value-label.tiny {
  font-size: 11px;
  stroke-width: 3px;
}

.chart-value-label.light {
  fill: #fffaf4;
  stroke: rgba(61, 43, 31, 0.42);
  stroke-width: 3px;
}

.empty-chart-label {
  fill: var(--muted);
  font-size: 17px;
  font-weight: 750;
}

.donut-total {
  fill: var(--ink);
  font-size: 32px;
  font-weight: 850;
}

.donut-center-sub {
  fill: var(--muted);
  font-size: 16px;
  font-weight: 800;
}

.donut-scope-label {
  fill: var(--muted);
  font-size: 16px;
  font-weight: 850;
}

.donut-legend-label {
  fill: var(--ink);
  font-size: 17px;
  font-weight: 850;
}

.bubble-rank {
  fill: #fffaf4;
  font-size: 13px;
  font-weight: 900;
  pointer-events: none;
}

.heatmap-label {
  fill: var(--ink);
  font-size: 14px;
  font-weight: 850;
  pointer-events: none;
}

.heatmap-label.light {
  fill: #fffaf4;
}

.chart-hotspot {
  cursor: crosshair;
  outline: none;
  transform-box: fill-box;
  transform-origin: center;
  transition: opacity 160ms ease, filter 160ms ease, stroke-width 160ms ease, transform 160ms ease;
}

.chart-action {
  cursor: pointer;
}

.chart-hotspot:hover,
.chart-hotspot:focus-visible {
  opacity: 0.94;
  filter: saturate(1.18) drop-shadow(0 8px 12px rgba(84, 50, 22, 0.24));
  stroke: #fffaf4;
  stroke-width: 3;
}

.chart-hotspot.chart-dot:hover,
.chart-hotspot.chart-dot:focus-visible {
  transform: scale(1.18);
}

.animated-slice.chart-hotspot:hover,
.animated-slice.chart-hotspot:focus-visible {
  transform: scale(1.035);
}

.line-hit-area {
  pointer-events: stroke;
}

.line-hit-area:hover,
.line-hit-area:focus-visible {
  opacity: 1;
  filter: drop-shadow(0 8px 12px rgba(84, 50, 22, 0.18));
  stroke-width: 28;
}

.animated-bar {
  animation: fadeInUp 520ms cubic-bezier(0.2, 0.8, 0.2, 1) both;
  transform-box: fill-box;
  transform-origin: center bottom;
}

.animated-bar[data-animate-axis="x"] {
  transform-origin: left center;
}

.animated-line {
  transform-box: fill-box;
  transform-origin: center;
}

.chart-dot {
  animation: popIn 520ms cubic-bezier(0.2, 0.8, 0.2, 1) both;
  transform-box: fill-box;
  transform-origin: center;
}

.animated-slice {
  animation: sliceIn 620ms cubic-bezier(0.2, 0.8, 0.2, 1) both;
  transform-box: fill-box;
  transform-origin: center;
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes drawLine {
  to {
    stroke-dashoffset: 0;
  }
}

@keyframes popIn {
  from {
    opacity: 0;
    transform: scale(0.4);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes sliceIn {
  from {
    opacity: 0;
    transform: scale(0.86);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes panelPulse {
  0% {
    border-color: var(--orange);
    box-shadow: 0 0 0 0 rgba(249, 115, 22, 0.28), var(--shadow);
  }
  54% {
    border-color: var(--orange);
    box-shadow: 0 0 0 8px rgba(249, 115, 22, 0.08), var(--shadow);
  }
  100% {
    border-color: var(--line);
    box-shadow: var(--shadow);
  }
}

.table-section {
  margin-top: 14px;
  display: grid;
  gap: 14px;
}

.table-panel {
  min-height: 420px;
}

.table-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.table-actions button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.split-table {
  min-height: 0;
}

.table-wrap {
  position: relative;
  z-index: 0;
  max-height: 520px;
  overflow: auto;
  padding: 0 20px 20px;
}

.table-wrap.compact {
  max-height: 340px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 15px;
  font-variant-numeric: tabular-nums;
}

th,
td {
  padding: 12px 10px;
  border-bottom: 1px solid var(--line);
  text-align: right;
  vertical-align: top;
}

th:first-child,
td:first-child {
  width: 56%;
  text-align: left;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface);
  color: var(--muted);
  font-size: 14px;
  font-weight: 750;
}

.sort-button {
  all: unset;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  box-sizing: border-box;
  cursor: pointer;
  border-radius: 8px;
  color: var(--muted);
  padding: 6px 8px;
  font: inherit;
  font-weight: 750;
}

.sort-button:hover,
.sort-button:focus-visible {
  background: #fff1df;
  color: var(--brown);
  outline: none;
}

.sort-button[aria-sort="ascending"]::after {
  content: " ↑";
}

.sort-button[aria-sort="descending"]::after {
  content: " ↓";
}

.product-name {
  display: -webkit-box;
  overflow: hidden;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.product-leaders-table th:first-child,
.product-leaders-table td:first-child {
  width: 58px;
  text-align: center;
}

.product-leaders-table th {
  vertical-align: middle;
}

.product-leaders-table th:nth-child(2),
.product-leaders-table td:nth-child(2) {
  width: 38%;
  text-align: left;
  white-space: normal;
}

.product-leaders-table .sort-button,
.table-head-label {
  min-height: 38px;
  line-height: 1;
}

.table-head-label {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  border-radius: 8px;
  color: var(--muted);
  padding: 6px 8px;
  font: inherit;
  font-weight: 750;
}

.product-leaders-table th:not(:first-child):not(:nth-child(2)),
.product-leaders-table td:not(:first-child):not(:nth-child(2)) {
  white-space: nowrap;
}

.select-cell {
  vertical-align: middle;
}

.product-select {
  position: relative;
  overflow: hidden;
  isolation: isolate;
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border: 1px solid #ead2bc;
  border-radius: 8px;
  background: #fffaf4;
  cursor: pointer;
  touch-action: manipulation;
}

.product-select:hover,
.product-select:focus-within {
  border-color: var(--orange);
  box-shadow: 0 0 0 3px rgba(249, 115, 22, 0.14);
}

.product-select input {
  position: absolute;
  inset: 0;
  box-sizing: border-box;
  width: 100%;
  height: 100%;
  min-height: 0;
  margin: 0;
  padding: 0;
  opacity: 0;
  cursor: pointer;
}

.product-check {
  display: grid;
  width: 18px;
  height: 18px;
  place-items: center;
  border: 1.5px solid #d5bba3;
  border-radius: 5px;
  background: #fffdf9;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.8);
  pointer-events: none;
  transition: border-color 140ms ease, background 140ms ease, box-shadow 140ms ease;
}

.product-check::after {
  width: 8px;
  height: 5px;
  border-bottom: 2px solid #fffaf4;
  border-left: 2px solid #fffaf4;
  content: "";
  opacity: 0;
  transform: translateY(-1px) rotate(-45deg) scale(0.85);
  transition: opacity 120ms ease, transform 120ms ease;
}

.product-select input:checked + .product-check {
  border-color: var(--orange);
  background: var(--orange);
  box-shadow: 0 0 0 3px rgba(249, 115, 22, 0.13);
}

.product-select input:checked + .product-check::after {
  opacity: 1;
  transform: translateY(-1px) rotate(-45deg) scale(1);
}

.product-select input:focus-visible + .product-check {
  outline: 2px solid rgba(249, 115, 22, 0.45);
  outline-offset: 3px;
}

.product-row {
  cursor: pointer;
  outline: none;
  transition: background 140ms ease;
}

.product-row:hover,
.product-row:focus-visible {
  background: #fff4e8;
}

.positive {
  color: var(--green);
}

.negative {
  color: var(--coral);
}

.empty-state {
  color: var(--muted);
  padding: 28px 10px;
  text-align: center;
}

.tooltip {
  position: fixed;
  z-index: 30;
  max-width: 260px;
  pointer-events: none;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(36, 29, 24, 0.94);
  color: var(--surface);
  padding: 9px 11px;
  font-size: 15px;
  line-height: 1.45;
  box-shadow: 0 18px 40px rgba(36, 29, 24, 0.22);
  opacity: 0;
  transform: translate3d(-50%, -110%, 0);
  transition: opacity 120ms ease;
}

.tooltip.is-visible {
  opacity: 1;
}

.drawer-scrim {
  position: fixed;
  inset: 0;
  z-index: 24;
  pointer-events: none;
  background: rgba(23, 17, 13, 0.18);
  opacity: 0;
  transition: opacity 180ms ease;
}

.drawer-scrim.is-visible {
  pointer-events: auto;
  opacity: 1;
}

.chart-modal-scrim {
  position: fixed;
  inset: 0;
  z-index: 1000;
  pointer-events: none;
  background: rgba(23, 17, 13, 0.38);
  backdrop-filter: blur(5px);
  opacity: 0;
  transition: opacity 180ms ease;
}

.chart-modal-scrim.is-visible {
  pointer-events: auto;
  opacity: 1;
}

.chart-modal {
  position: fixed;
  inset: 4vh 3vw;
  z-index: 1001;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--surface);
  box-shadow: 0 30px 80px rgba(36, 29, 24, 0.28);
  opacity: 0;
  pointer-events: none;
  transform: translateY(18px) scale(0.985);
  transition: opacity 180ms ease, transform 180ms ease;
}

.chart-modal.is-open {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0) scale(1);
}

.chart-modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--line);
  padding: 20px 22px 14px;
}

.chart-modal-head span {
  color: var(--brown);
  font-size: 12px;
  font-weight: 850;
  text-transform: uppercase;
}

.chart-modal-head h2 {
  margin: 3px 0 2px;
  font-size: 25px;
  line-height: 1.12;
}

.chart-modal-head p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  font-weight: 650;
}

#closeChartModal {
  display: grid;
  width: 44px;
  min-width: 44px;
  height: 44px;
  min-height: 44px;
  place-items: center;
  padding: 0;
  font-size: 24px;
  line-height: 1;
}

.chart-modal-body {
  min-height: 0;
  overflow: auto;
  background: var(--surface);
  padding: 20px 24px 26px;
}

.chart-modal-canvas {
  min-height: 620px;
  border: 1px solid #ead8c6;
  border-radius: 16px;
  background: #fffaf4;
  padding: 12px;
}

.expanded-chart-svg {
  display: block;
  width: 100%;
  min-width: 900px;
  height: auto;
}

.drilldown {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 25;
  width: min(460px, 92vw);
  border-left: 1px solid var(--line);
  background: rgba(255, 253, 249, 0.96);
  box-shadow: -18px 0 44px rgba(84, 50, 22, 0.15);
  transform: translateX(104%);
  transition: transform 220ms cubic-bezier(0.2, 0.8, 0.2, 1);
  backdrop-filter: blur(18px);
}

.drilldown.is-open {
  transform: translateX(0);
}

.drilldown-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  padding: 22px 22px 14px;
  border-bottom: 1px solid var(--line);
}

.drilldown-head span {
  color: var(--brown);
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
}

.drilldown-head h2 {
  margin: 4px 0 0;
  font-size: 24px;
  line-height: 1.16;
}

#closeDrilldown {
  display: grid;
  width: 44px;
  min-width: 44px;
  height: 44px;
  min-height: 44px;
  place-items: center;
  padding: 0;
  font-size: 24px;
  line-height: 1;
}

.drilldown-body {
  height: calc(100% - 92px);
  overflow: auto;
  padding: 18px 22px 28px;
}

.drill-metrics {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.drill-metrics div {
  min-height: 74px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fffaf4;
  padding: 12px;
}

.drill-metrics span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
}

.drill-metrics strong {
  display: block;
  margin-top: 5px;
  font-size: 21px;
}

.drill-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 14px 0 18px;
}

.drill-actions button {
  min-height: 38px;
  padding: 7px 12px;
}

.drilldown-body h3 {
  margin: 0 0 10px;
  font-size: 18px;
}

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

.drill-table table {
  min-width: 420px;
  font-size: 14px;
}

.drill-table th,
.drill-table td {
  padding: 10px;
}

.drill-table th:first-child,
.drill-table td:first-child {
  width: 48%;
}

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

@media (max-width: 1220px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .analysis-stage {
    grid-template-columns: 1fr;
  }

  .analysis-stage[data-stage-mode="date"],
  .analysis-stage[data-stage-mode="rolling"] {
    grid-template-columns: 1fr;
  }

  .analysis-stage[data-stage-mode="rolling"] .rolling-stage,
  .analysis-stage[data-stage-mode="rolling"] .inweek-section {
    order: initial;
  }

  .rolling-stage {
    position: static;
    max-height: none;
    overflow: visible;
    padding-right: 0;
  }

  .sidebar {
    position: static;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

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

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

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

  .panel.wide {
    grid-column: auto;
  }
}

@media (max-width: 680px) {
  .stage-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .selected-products-focus {
    padding: 14px;
  }

  .selected-products-focus .section-head {
    align-items: stretch;
    flex-direction: column;
  }

  .selected-products-focus .panel-head {
    flex-direction: column;
    gap: 10px;
  }

  .chart-expand-button {
    width: 100%;
  }

  .stage-switch {
    display: grid;
    grid-template-columns: 1fr;
  }

  .range-toolbar {
    grid-template-columns: 1fr;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .topbar h2 {
    font-size: 24px;
  }

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

  .chart {
    height: 360px;
    padding-left: 6px;
    padding-right: 6px;
  }

  .adaptive-donut-chart {
    height: 520px;
    padding: 0 4px 12px;
  }

  .selected-chart {
    height: 460px;
    min-height: 460px;
  }

  .chart-modal {
    inset: 2vh 1.5vw;
    border-radius: 14px;
  }

  .chart-modal-head {
    position: relative;
    min-height: 92px;
    padding: 16px 64px 12px 16px;
  }

  .chart-modal-head h2 {
    font-size: 21px;
  }

  #closeChartModal {
    position: absolute;
    top: 12px;
    right: 12px;
  }

  .chart-modal-body {
    padding: 12px;
  }

  .chart-modal-canvas {
    min-height: 500px;
    padding: 8px;
  }

  .expanded-chart-svg {
    min-width: 760px;
  }

  th:first-child,
  td:first-child {
    width: 48%;
  }
}
