:root {
  color-scheme: light;
  --ink: #201e1f;
  --muted: #6f686b;
  --paper: #f5f3f3;
  --white: #ffffff;
  --red: #cf1647;
  --red-dark: #9e1136;
  --pink: #f7dce5;
  --green: #177a54;
  --green-soft: #dff3e9;
  --amber: #a45b00;
  --amber-soft: #fff0d5;
  --line: #ded9db;
  --shadow: 0 18px 45px rgba(42, 24, 31, .08);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; background: var(--paper); color: var(--ink); font-size: 16px; }
button, input, select { font: inherit; }
a { color: inherit; }

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 76px;
  padding: 10px clamp(20px, 4vw, 64px);
  background: rgba(255, 255, 255, .94);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(14px);
}

.brand { display: flex; gap: 14px; align-items: center; text-decoration: none; }
.brand img { width: 54px; height: 45px; object-fit: contain; object-position: left center; }
.brand span { display: grid; gap: 2px; }
.brand strong { font-size: 1.05rem; letter-spacing: -.02em; }
.brand small { color: var(--muted); font-size: .78rem; }
.header-actions { display: flex; align-items: center; gap: 22px; }
.status { display: inline-flex; gap: 8px; align-items: center; color: var(--muted); font-size: .85rem; }
.status i, .legend i { width: 8px; height: 8px; border-radius: 50%; background: var(--green); }
.hub-link { font-weight: 700; font-size: .9rem; text-decoration-thickness: 1px; text-underline-offset: 4px; }

main { width: min(1540px, calc(100% - 40px)); margin: 0 auto; padding: 64px 0 56px; }
.toolbar { display: flex; justify-content: space-between; align-items: end; gap: 30px; margin-bottom: 24px; }
.eyebrow { margin: 0 0 7px; color: var(--red); font-size: .75rem; font-weight: 800; letter-spacing: .14em; text-transform: uppercase; }
h1, h2 { margin: 0; letter-spacing: -.045em; line-height: 1.02; }
h1 { font-size: clamp(2.15rem, 4vw, 4.4rem); max-width: 760px; }
h2 { font-size: clamp(1.45rem, 2.1vw, 2.2rem); }

.date-control, .search-control, .sort-control { display: grid; gap: 7px; color: var(--muted); font-size: .78rem; font-weight: 700; }
select, input {
  min-height: 44px;
  padding: 0 14px;
  background: var(--white);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 9px;
  outline: none;
}
select {
  padding-right: 42px;
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}
.date-control select { min-width: 150px; font-weight: 700; }
select:focus, input:focus { border-color: var(--red); box-shadow: 0 0 0 3px rgba(207, 22, 71, .12); }

.metrics { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 12px; }
.metric { min-height: 142px; padding: 22px; background: var(--white); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); }
.metric span { display: block; min-height: 34px; color: var(--muted); font-size: .85rem; font-weight: 700; }
.metric strong { display: block; margin: 7px 0 9px; font-size: clamp(2rem, 3.5vw, 3.25rem); letter-spacing: -.055em; }
.metric small { color: var(--muted); font-size: .78rem; }
.metric-primary { background: var(--red); color: var(--white); border-color: var(--red); }
.metric-primary span, .metric-primary small { color: rgba(255,255,255,.78); }
.metric-gm { background: var(--green-soft); border-color: #b9e0cf; }
.metric-nm { background: var(--ink); color: var(--white); border-color: var(--ink); }
.metric-nm span, .metric-nm small { color: #d8d2d4; }

.panel { background: var(--white); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); }
.panel-heading { display: flex; align-items: end; justify-content: space-between; gap: 18px; padding: 22px 24px; border-bottom: 1px solid var(--line); }
.legend { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: .8rem; }
.legend i { background: var(--red); }
.trend-legends { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 14px; }
.legend-gm i { background: var(--green); }
.legend-nm i { background: var(--ink); }
.trend-panel { margin-bottom: 12px; }
.trend-wrap { position: relative; min-height: 260px; padding: 14px 22px 20px; }
#trendChart { display: block; width: 100%; height: 230px; overflow: visible; }
.trend-empty { position: absolute; inset: 25px; display: flex; flex-direction: column; justify-content: center; align-items: center; gap: 7px; text-align: center; color: var(--muted); }
.trend-empty strong { color: var(--ink); font-size: 1.05rem; }

.dashboard-grid { display: grid; grid-template-columns: minmax(0, 2.3fr) minmax(290px, .7fr); gap: 12px; margin-bottom: 12px; }
.shop-panel { min-width: 0; }
.search-control input { width: min(240px, 30vw); }
.table-wrap { overflow: auto; max-height: 610px; }
table { width: 100%; border-collapse: collapse; }
th { position: sticky; top: 0; z-index: 2; padding: 12px 16px; background: #faf9f9; color: var(--muted); border-bottom: 1px solid var(--line); font-size: .75rem; letter-spacing: .04em; text-align: left; text-transform: uppercase; }
td { padding: 13px 16px; border-bottom: 1px solid #eee9eb; font-size: .9rem; }
.numeric { text-align: right; font-variant-numeric: tabular-nums; }
.shop-row { cursor: pointer; transition: background .16s ease; }
.shop-row:hover, .shop-row:focus { background: #fff5f8; outline: none; }
.shop-row.active { background: var(--pink); }
.shop-name { display: flex; align-items: center; gap: 10px; font-weight: 750; }
.rank { display: grid; place-items: center; width: 26px; height: 26px; flex: 0 0 26px; border-radius: 50%; background: #eee9eb; color: var(--muted); font-size: .72rem; }
.pct-cell { min-width: 150px; }
.margin-cell { font-weight: 800; }
.nm-cell { color: var(--red-dark); }
.pct-wrap { display: grid; grid-template-columns: minmax(75px, 1fr) 54px; align-items: center; gap: 10px; }
.bar { height: 8px; background: #eee9eb; border-radius: 999px; overflow: hidden; }
.bar span { display: block; height: 100%; border-radius: inherit; background: var(--red); }
.pct-good .bar span { background: var(--green); }
.pct-high .bar span { background: #dd7a17; }

.insight-panel { padding-bottom: 20px; }
.insight-panel > .eyebrow, .insight-panel > h2 { margin-left: 24px; margin-right: 24px; }
.insight-panel > .eyebrow { padding-top: 24px; }
#dailyRead { display: grid; gap: 12px; padding: 24px; }
.insight { padding: 15px; border-radius: 10px; background: #f6f4f5; }
.insight span { display: block; color: var(--muted); font-size: .77rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; }
.insight strong { display: block; margin-top: 6px; font-size: 1rem; line-height: 1.35; }
.insight small { display: block; margin-top: 7px; color: var(--muted); font-size: .78rem; line-height: 1.4; }
.method-note { margin: 8px 24px 0; padding: 18px; border-radius: 10px; background: var(--ink); color: white; }
.method-note strong { color: #ff7599; }
.method-note p { margin: 8px 0 0; color: #d8d2d4; font-size: .82rem; line-height: 1.5; }

.products-panel { scroll-margin-top: 94px; }
.product-heading { align-items: center; }
#productSubtitle { margin: 7px 0 0; color: var(--muted); font-size: .9rem; }
.sort-control select { min-width: 200px; }
.product-actions { display: flex; align-items: end; gap: 10px; }
#allShopsButton { min-height: 44px; padding: 0 16px; color: var(--red); background: var(--pink); border: 1px solid transparent; border-radius: 9px; font-weight: 800; cursor: pointer; }
#allShopsButton:hover, #allShopsButton:focus { border-color: var(--red); outline: none; }
#allShopsButton:disabled { color: var(--muted); background: #eee9eb; cursor: default; }
.empty-cell { padding: 60px 20px; color: var(--muted); text-align: center; }
.product-name { font-weight: 720; }
.cost-pill { display: inline-block; min-width: 66px; padding: 5px 8px; border-radius: 999px; background: var(--pink); color: var(--red-dark); font-weight: 800; text-align: center; }

footer { display: flex; justify-content: space-between; gap: 24px; padding: 22px 4px 0; color: var(--muted); font-size: .78rem; }
.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; }

@media (max-width: 980px) {
  .metrics { grid-template-columns: repeat(2, 1fr); }
  .dashboard-grid { grid-template-columns: 1fr; }
  .insight-panel { min-height: auto; }
}

@media (max-width: 680px) {
  .app-header { padding: 9px 16px; }
  .brand img { width: 44px; height: 38px; }
  .status { display: none; }
  main { width: min(100% - 24px, 1540px); padding-top: 42px; }
  .toolbar { align-items: stretch; flex-direction: column; }
  .metrics { grid-template-columns: 1fr; }
  .metric { min-height: 122px; }
  .panel-heading { align-items: stretch; flex-direction: column; padding: 18px; }
  .search-control input, .sort-control select { width: 100%; min-width: 0; }
  .product-actions { align-items: stretch; flex-direction: column-reverse; }
  .trend-wrap { min-height: 220px; padding: 8px 10px 12px; }
  #trendChart { height: 200px; }
  th, td { padding: 12px 11px; }
  .pct-cell { min-width: 150px; }
  footer { flex-direction: column; }
}
