/* ============================================================
   PDP Highlights — Dashboard (revamped)
   Self-contained styles. Reuses the brand tokens / topbar / form
   controls from styles.css; everything metric-related is scoped
   under the `db-` namespace so it never collides with other pages.
   Layout uses CSS multi-column masonry: each card is only as tall
   as its own content — cards are never stretched to match a row.
   ============================================================ */

/* Width intentionally matches .app-shell (styles.css) so the top bar / nav stays
   the same size across every page. */
.db-shell {
  width: min(1360px, 100%);
}

/* ---------- Hero / controls ---------- */
.db-hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(300px, 0.85fr);
  gap: 28px;
  align-items: end;
  padding: 30px 32px;
  margin-bottom: 22px;
  border-radius: var(--radius-xl);
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.92), rgba(255, 244, 235, 0.7));
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.db-eyebrow {
  margin: 0 0 8px;
  font-family: var(--mono);
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent-strong);
}

.db-hero__title {
  margin: 0 0 10px;
  font-size: clamp(1.8rem, 3vw, 2.8rem);
  line-height: 1.04;
}

.db-hero__lead {
  margin: 0;
  max-width: 54ch;
  color: var(--muted);
  line-height: 1.6;
}

.db-controls {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  align-items: end;
}

.db-field {
  display: grid;
  gap: 8px;
  min-width: 0;
}

.db-field__label {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--ink);
}

.db-controls .product-input {
  min-width: 0;
}

.db-controls .accent-button {
  grid-column: 1 / -1;
}

.db-status {
  margin: 0 0 22px;
  min-height: 1.4em;
  color: var(--muted);
  line-height: 1.5;
}

.db-status--error {
  color: var(--accent-strong);
}

/* ---------- KPI strip ---------- */
.db-kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 18px;
  margin-bottom: 24px;
}

.db-kpi {
  position: relative;
  display: grid;
  gap: 7px;
  padding: 20px 22px 20px 26px;
  border-radius: var(--radius-lg);
  background: var(--surface-strong);
  border: 1px solid var(--border);
  box-shadow: 0 16px 40px rgba(23, 37, 56, 0.08);
  overflow: hidden;
}

.db-kpi::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 4px;
  background: linear-gradient(180deg, var(--accent), var(--secondary));
}

.db-kpi__label {
  font-family: var(--mono);
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}

.db-kpi__value {
  font-size: clamp(1.7rem, 2.4vw, 2.4rem);
  line-height: 1;
}

.db-kpi__meta {
  font-size: 0.8rem;
  color: var(--muted);
  line-height: 1.45;
}

/* ---------- Card shell ---------- */
.db-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 22px 22px 24px;
  border-radius: var(--radius-lg);
  background: var(--surface-strong);
  border: 1px solid var(--border);
  box-shadow: 0 18px 44px rgba(23, 37, 56, 0.07);
}

.db-card__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.db-card__heading {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.db-tag {
  flex: 0 0 auto;
  font-family: var(--mono);
  font-size: 0.66rem;
  letter-spacing: 0.06em;
  padding: 4px 8px;
  border-radius: 8px;
  background: rgba(219, 106, 69, 0.12);
  color: var(--accent-strong);
}

.db-card__title {
  margin: 0;
  font-size: 1.05rem;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.db-card__sub {
  margin: -4px 0 0;
  color: var(--muted);
  font-size: 0.83rem;
  line-height: 1.45;
}

.db-card__body {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.db-scope {
  position: relative;
  flex: 0 0 auto;
  max-width: 46%;
  text-align: right;
  font-family: var(--mono);
  font-size: 0.66rem;
  line-height: 1.3;
  padding: 5px 9px;
  border-radius: 999px;
  background: rgba(47, 125, 117, 0.12);
  color: var(--secondary);
}

.db-scope--warn {
  background: rgba(219, 106, 69, 0.14);
  color: var(--accent-strong);
}

.db-scope--info {
  cursor: help;
  outline: none;
}

/* ---------- Info icon + hover popover (insight / clamp explanation) ---------- */
.db-info {
  position: relative;
  display: inline-flex;
  flex: 0 0 auto;
  cursor: help;
  outline: none;
}

.db-info__icon {
  display: grid;
  place-items: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: rgba(23, 37, 56, 0.08);
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.66rem;
  line-height: 1;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.db-info:hover .db-info__icon,
.db-info:focus-visible .db-info__icon {
  background: rgba(47, 125, 117, 0.18);
  color: var(--secondary);
}

.db-info--sm .db-info__icon {
  width: 14px;
  height: 14px;
  font-size: 0.56rem;
}

.db-pop {
  position: absolute;
  z-index: 30;
  width: max-content;
  max-width: 240px;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--ink);
  color: #fff9f4;
  font-family: var(--sans);
  font-size: 0.78rem;
  font-weight: 400;
  line-height: 1.45;
  letter-spacing: normal;
  text-transform: none;
  text-align: left;
  box-shadow: 0 14px 34px rgba(23, 37, 56, 0.28);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.14s ease, transform 0.14s ease;
}

.db-pop::after {
  content: "";
  position: absolute;
  width: 10px;
  height: 10px;
  background: var(--ink);
  transform: rotate(45deg);
}

/* info icon: popover centered below the icon */
.db-info .db-pop {
  top: calc(100% + 9px);
  left: 50%;
  transform: translate(-50%, 4px);
}

.db-info .db-pop::after {
  top: -5px;
  left: 50%;
  margin-left: -5px;
}

.db-info:hover .db-pop,
.db-info:focus-within .db-pop {
  opacity: 1;
  visibility: visible;
  transform: translate(-50%, 0);
}

/* scope chip: popover anchored to the chip's right edge, opening down-left */
.db-scope .db-pop {
  top: calc(100% + 9px);
  right: 0;
  transform: translateY(4px);
}

.db-scope .db-pop::after {
  top: -5px;
  right: 14px;
}

.db-scope--info:hover .db-pop,
.db-scope--info:focus-within .db-pop {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.db-card.is-loading {
  opacity: 0.55;
}

/* ---------- Feature row + masonry ---------- */
.db-feature {
  margin-bottom: 20px;
}

.db-masonry {
  columns: 3 360px;
  column-gap: 20px;
}

.db-masonry > .db-card {
  width: 100%;
  margin: 0 0 20px;
  break-inside: avoid;
  -webkit-column-break-inside: avoid;
}

/* ---------- Stat tiles ---------- */
.db-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.db-stat {
  flex: 1 1 110px;
  min-width: 0;
  display: grid;
  gap: 3px;
  padding: 12px 14px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.62);
  border: 1px solid var(--border);
}

.db-stat__label {
  display: flex;
  align-items: center;
  gap: 5px;
  font-family: var(--mono);
  font-size: 0.7rem;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.db-stat__value {
  font-size: 1.1rem;
  font-weight: 700;
  overflow-wrap: anywhere;
}

/* ---------- Horizontal ranked bars ---------- */
.db-bars {
  display: grid;
  gap: 14px;
  max-height: 440px;
  overflow-y: auto;
  padding-right: 6px;
  scrollbar-width: thin;
  overscroll-behavior: contain;
}

.db-bar {
  display: grid;
  grid-template-columns: 26px minmax(0, 1fr);
  gap: 12px;
  align-items: start;
}

.db-bars--norank .db-bar {
  grid-template-columns: minmax(0, 1fr);
}

.db-bars--norank .db-bar__rank {
  display: none;
}

.db-bar__rank {
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  font-family: var(--mono);
  font-size: 0.74rem;
  background: rgba(23, 37, 56, 0.07);
  color: var(--muted);
}

.db-bar__main {
  min-width: 0;
  display: grid;
  gap: 7px;
}

.db-bar__top {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: baseline;
}

.db-bar__label {
  min-width: 0;
  font-size: 0.9rem;
  line-height: 1.3;
  overflow-wrap: anywhere;
}

.db-bar__value {
  flex: 0 0 auto;
  font-family: var(--mono);
  font-size: 0.8rem;
  color: var(--accent-strong);
}

.db-bar__track {
  height: 9px;
  border-radius: 999px;
  background: rgba(23, 37, 56, 0.08);
  overflow: hidden;
}

.db-bar__fill {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--secondary), var(--accent));
}

/* ---------- Vertical bar chart ---------- */
.db-vchart {
  display: grid;
  gap: 10px;
}

.db-vplot {
  display: flex;
  align-items: flex-end;
  gap: 14px;
  height: 180px;
}

.db-vcol {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  height: 100%;
}

.db-vcol__val {
  font-family: var(--mono);
  font-size: 0.74rem;
  color: var(--ink);
}

.db-vcol__bar {
  width: min(100%, 48px);
  height: var(--h, 0%);
  min-height: 3px;
  border-radius: 8px 8px 3px 3px;
  background: linear-gradient(180deg, var(--accent), var(--secondary));
}

.db-xlabels {
  display: flex;
  gap: 14px;
}

.db-xlab {
  flex: 1 1 0;
  min-width: 0;
  text-align: center;
  font-size: 0.74rem;
  line-height: 1.25;
  color: var(--muted);
}

/* ---------- Donut + legend ---------- */
.db-donut {
  display: flex;
  gap: 20px;
  align-items: center;
  flex-wrap: wrap;
}

.db-donut__svg {
  flex: 0 0 auto;
}

.db-legend {
  flex: 1 1 170px;
  min-width: 0;
  display: grid;
  gap: 11px;
}

.db-legend__item {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.86rem;
}

.db-legend__dot {
  flex: 0 0 auto;
  width: 12px;
  height: 12px;
  border-radius: 4px;
}

.db-legend__txt {
  color: var(--muted);
  min-width: 0;
}

.db-legend__txt strong {
  color: var(--ink);
}

/* ---------- Radial gauge ---------- */
.db-gauge {
  display: flex;
  gap: 20px;
  align-items: center;
  flex-wrap: wrap;
}

.db-gauge__svg {
  flex: 0 0 auto;
}

.db-gauge__ring-bg {
  fill: none;
  stroke: rgba(23, 37, 56, 0.1);
}

.db-gauge__ring-fg {
  fill: none;
  stroke: url(#dbGaugeGradient);
  stroke-linecap: round;
}

.db-gauge__pct {
  fill: var(--ink);
  font-family: var(--sans);
  font-weight: 700;
}

.db-gauge__cap {
  fill: var(--muted);
  font-family: var(--mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.db-gauge__side {
  flex: 1 1 150px;
  min-width: 0;
  display: grid;
  gap: 10px;
}

/* ---------- Co-click pairs ---------- */
.db-pairs {
  display: grid;
  gap: 12px;
  max-height: 520px;
  overflow-y: auto;
  padding-right: 6px;
  scrollbar-width: thin;
  overscroll-behavior: contain;
}

.db-pair {
  display: grid;
  gap: 9px;
  padding: 14px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.6);
  border: 1px solid var(--border);
}

.db-pair__q {
  display: flex;
  gap: 9px;
  align-items: flex-start;
  font-size: 0.87rem;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.db-pair__bullet {
  flex: 0 0 auto;
  color: var(--accent-strong);
  font-family: var(--mono);
  font-size: 0.78rem;
  line-height: 1.5;
}

.db-pair__qmain {
  min-width: 0;
  display: grid;
  gap: 2px;
}

.db-pair__qprod {
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--muted);
}

.db-pair__foot {
  display: flex;
  align-items: center;
  gap: 10px;
}

.db-pair__count {
  flex: 0 0 auto;
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--accent-strong);
}

.db-pair__track {
  flex: 1 1 auto;
  height: 7px;
  border-radius: 999px;
  background: rgba(23, 37, 56, 0.08);
  overflow: hidden;
}

.db-pair__fill {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--secondary), var(--accent));
}

/* ---------- ROI comparison ---------- */
.db-roi {
  display: grid;
  gap: 16px;
}

.db-roi__cols {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.db-roi__col {
  display: grid;
  gap: 3px;
  padding: 16px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.6);
}

.db-roi__col--win {
  border-color: rgba(47, 125, 117, 0.32);
  background: linear-gradient(135deg, rgba(47, 125, 117, 0.14), rgba(219, 106, 69, 0.08));
}

.db-roi__name {
  font-family: var(--mono);
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.db-roi__rate {
  font-size: 1.7rem;
  line-height: 1;
}

.db-roi__unit {
  font-size: 0.72rem;
  color: var(--muted);
}

.db-roi__sub {
  margin-top: 5px;
  font-size: 0.76rem;
  color: var(--muted);
}

.db-roi__lift {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  border-radius: 14px;
  background: rgba(219, 106, 69, 0.1);
}

.db-roi__lift strong {
  font-size: 1.6rem;
  line-height: 1;
}

.db-roi__lift span {
  font-size: 0.82rem;
  color: var(--muted);
  line-height: 1.4;
}

/* ---------- Lists ---------- */
.db-list {
  display: grid;
  gap: 8px;
  max-height: 440px;
  overflow-y: auto;
  padding-right: 6px;
  scrollbar-width: thin;
  overscroll-behavior: contain;
}

.db-list__row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.58);
  border: 1px solid var(--border);
}

.db-list__row.is-zero {
  background: rgba(219, 106, 69, 0.08);
  border-color: rgba(219, 106, 69, 0.22);
}

.db-list__main {
  min-width: 0;
  display: grid;
  gap: 2px;
}

.db-list__title {
  font-size: 0.87rem;
  line-height: 1.3;
  overflow-wrap: anywhere;
}

.db-list__meta {
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--muted);
}

.db-list__badge {
  flex: 0 0 auto;
  font-family: var(--mono);
  font-size: 0.76rem;
  padding: 4px 9px;
  border-radius: 8px;
  background: rgba(23, 37, 56, 0.06);
  color: var(--ink);
}

.db-list__badge.is-zero {
  background: rgba(219, 106, 69, 0.16);
  color: var(--accent-strong);
}

/* ---------- Product chip grid (A11) ---------- */
.db-prodgrid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  max-height: 320px;
  overflow-y: auto;
  padding-right: 6px;
  scrollbar-width: thin;
  overscroll-behavior: contain;
}

.db-prodchip {
  display: grid;
  gap: 2px;
  padding: 9px 13px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.6);
  border: 1px solid var(--border);
}

.db-prodchip__id {
  font-family: var(--mono);
  font-size: 0.84rem;
}

.db-prodchip__cat {
  font-size: 0.7rem;
  color: var(--muted);
}

/* ---------- Area / line chart ---------- */
.db-chart-wrap {
  position: relative;
  width: 100%;
}

.db-chart-wrap svg {
  display: block;
  width: 100%;
  height: auto;
}

.db-grid-line {
  stroke: rgba(23, 37, 56, 0.08);
  stroke-width: 1;
}

.db-axis-text {
  fill: var(--muted);
  font-family: var(--mono);
  font-size: 11px;
}

.db-axis-text--end {
  text-anchor: end;
}

.db-axis-text--mid {
  text-anchor: middle;
}

.db-area {
  fill: url(#dbAreaGradient);
}

.db-line {
  fill: none;
  stroke: var(--secondary);
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.db-dot {
  fill: #fffaf5;
  stroke: var(--accent);
  stroke-width: 3;
  opacity: 0;
  transition: opacity 0.12s ease;
}

.db-dot--show {
  opacity: 1;
}

.db-peak-dot {
  fill: var(--accent);
  stroke: #fffaf5;
  stroke-width: 2;
}

.db-hover-line {
  stroke: rgba(23, 37, 56, 0.28);
  stroke-width: 1;
  stroke-dasharray: 4 4;
  opacity: 0;
}

.db-hover-line--show {
  opacity: 1;
}

.db-tooltip {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none;
  transform: translate(-50%, -130%);
  padding: 6px 10px;
  border-radius: 8px;
  background: var(--ink);
  color: #fff9f4;
  font-size: 0.74rem;
  line-height: 1.3;
  white-space: nowrap;
  box-shadow: 0 10px 24px rgba(23, 37, 56, 0.28);
  opacity: 0;
  transition: opacity 0.12s ease;
}

.db-tooltip strong {
  font-family: var(--mono);
}

.db-tooltip--show {
  opacity: 1;
}

/* ---------- Empty / error ---------- */
.db-empty {
  margin: 0;
  padding: 18px;
  text-align: center;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.5;
  border: 1px dashed var(--border);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.38);
}

.db-empty--error {
  color: var(--accent-strong);
  border-color: rgba(219, 106, 69, 0.4);
  background: rgba(219, 106, 69, 0.06);
}

.db-skeleton {
  height: 120px;
  border-radius: 14px;
  background: linear-gradient(100deg, rgba(23, 37, 56, 0.05) 30%, rgba(23, 37, 56, 0.1) 50%, rgba(23, 37, 56, 0.05) 70%);
  background-size: 200% 100%;
  animation: db-shimmer 1.2s linear infinite;
}

@keyframes db-shimmer {
  from { background-position: 200% 0; }
  to { background-position: -200% 0; }
}

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .db-hero {
    grid-template-columns: 1fr;
    align-items: start;
  }
}

@media (max-width: 540px) {
  .db-hero {
    padding: 24px 20px;
  }

  .db-controls {
    grid-template-columns: 1fr 1fr;
  }

  .db-roi__cols {
    grid-template-columns: 1fr;
  }
}
