/* Module: sections 07-10 of automation 12 (Competitor Price Monitor).
   #features (uses features.css tiles), #dashboard (price history, price position, latest changes),
   #stack and #industries. Every rule is scoped under its section id; every class invented here
   starts with pm-. Frames and shared pieces come from features.css, dashboard.css and site.css. */

/* Status colour for promotions, used by the dashboard's chips */
#dashboard {
  --pm-promo: hsl(28 88% 56%);
}

/* ---------- 07 / Features: every title reserves two lines, so each body starts on the same y ---------- */

#features .features-tile .cell-t {
  min-height: 2.3em;
  max-width: 14ch;
  text-wrap: pretty;
}

#features .features-tile .cell-p {
  text-wrap: pretty;
}

@media (min-width: 1280px) {
  #features .features-tile .cell-t {
    max-width: 20ch;
  }
}

/* ---------- 08 / Dashboard: window body (sidebar | main) ---------- */

#dashboard .pm-dash-body {
  display: block;
}

@media (min-width: 1280px) {
  #dashboard .pm-dash-body {
    display: grid;
    grid-template-columns: 168px minmax(0, 1fr);
  }
}

#dashboard .pm-dash-main {
  min-width: 0;
}

/* The rail ends with its nav, not with the full height of the window */
#dashboard .pm-dash-body > .dashboard-rail {
  align-self: start;
}

/* The window title's last segment ("This week") is hidden on phones; the text stays in the data */
@media (max-width: 480px) {
  #dashboard .pm-dash .pm-bar-extra {
    display: none;
  }
}

/* Labels and sub-lines wrap rather than truncate: the cards are narrow at 1280 and 390 */
#dashboard .pm-dash .dashboard-stat-l,
#dashboard .pm-dash .dashboard-stat-s,
#dashboard .pm-dash .dashboard-meta {
  white-space: normal;
  text-overflow: clip;
}

#dashboard .pm-dash .dashboard-stat-l {
  text-wrap: balance;
}

/* The window title may wrap on phones instead of being cut off */
#dashboard .pm-dash .dashboard-bar-title {
  white-space: normal;
  line-height: 1.4;
}

@media (max-width: 639px) {
  #dashboard .pm-dash .dashboard-bar {
    height: auto;
    min-height: 40px;
    padding-block: 10px;
  }
}

/* The footer keeps its sync note on phones too */
#dashboard .pm-dash .dashboard-foot-sync {
  display: inline;
}

/* ---------- Blocks: price history | price position, then the changes table ---------- */

#dashboard .pm-columns {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
}

#dashboard .pm-block {
  min-width: 0;
}

#dashboard .pm-block + .pm-block {
  border-top: 1px solid var(--line);
}

@media (min-width: 1024px) {
  #dashboard .pm-columns {
    grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr);
    grid-template-areas:
      "history position"
      "changes changes";
  }

  #dashboard .pm-history {
    grid-area: history;
    border-right: 1px solid var(--line);
  }

  #dashboard .pm-position {
    grid-area: position;
    border-top: 0;
  }

  #dashboard .pm-changes {
    grid-area: changes;
  }
}

/* Toolbar: title (and the product pill) on the left, mono caption on the right, wrapping on phones */
#dashboard .pm-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px 16px;
  padding: 20px 20px 14px;
}

#dashboard .pm-tb-start {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 14px;
  min-width: 0;
}

#dashboard .pm-tb-caption {
  white-space: normal;
  text-overflow: clip;
  text-align: left;
}

/* Non-functional select pill: looks like a control, does nothing, is skipped by Tab */
#dashboard .pm-select {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: 100%;
  min-height: 30px;
  padding: 4px 8px 4px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--elev);
  font: inherit;
  font-size: 14px;
  line-height: 1;
  color: var(--bone-80);
  cursor: default;
  pointer-events: none;
}

#dashboard .pm-select-text {
  min-width: 0;
  overflow-wrap: anywhere;
}

/* Tap target: 44px high on phones and tablets */
@media (max-width: 640px) {
  #dashboard .pm-select {
    min-height: 44px;
    padding-block: 10px;
  }
}

#dashboard .pm-select svg {
  width: 14px;
  height: 14px;
  flex: none;
  color: var(--ash);
}

/* Swatch: 8px dot in a series colour */
#dashboard .pm-swatch {
  display: inline-block;
  width: 8px;
  height: 8px;
  flex: none;
  border-radius: 50%;
}

/* ---------- Price history: legend and step chart ---------- */

#dashboard .pm-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 20px;
  margin: 0;
  padding: 0 20px 14px;
  list-style: none;
}

#dashboard .pm-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  line-height: 1.3;
  color: var(--ash);
}

#dashboard .pm-chart {
  position: relative;
  margin: 0 20px 20px;
}

#dashboard .pm-svg {
  display: block;
  overflow: visible;
  user-select: none;
}

#dashboard .pm-grid,
#dashboard .pm-base {
  stroke: var(--line);
  stroke-width: 1;
}

#dashboard .pm-axis {
  font-family: var(--font-mono);
  font-size: 11.5px;
  letter-spacing: 0.08em;
  fill: var(--ash);
  font-variant-numeric: tabular-nums;
}

#dashboard .pm-end {
  font-family: var(--font-sans);
  font-size: 14px;
  fill: var(--bone-70);
  font-variant-numeric: tabular-nums;
}

#dashboard .pm-line--oos {
  opacity: 0.4;
}

#dashboard .pm-note {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.04em;
  fill: var(--accent);
}

#dashboard .pm-note-dot {
  fill: var(--accent);
}

#dashboard .pm-cross {
  display: none;
}

#dashboard .pm-cross.is-on {
  display: inline;
}

#dashboard .pm-cross-line {
  stroke: var(--ash);
  stroke-width: 1;
  stroke-dasharray: 2 3;
}

/* Hover tooltip (pointer only) */
#dashboard .pm-tip {
  position: absolute;
  top: 0;
  left: 0;
  display: none;
  min-width: 176px;
  padding: 10px 12px;
  background: var(--elev);
  border: 1px solid var(--line);
  border-radius: 6px;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.5;
  letter-spacing: 0.06em;
  color: var(--bone);
  font-variant-numeric: tabular-nums;
  pointer-events: none;
  z-index: 2;
}

#dashboard .pm-tip.is-on {
  display: block;
}

#dashboard .pm-tip-date {
  margin-bottom: 6px;
  color: var(--ash);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

#dashboard .pm-tip-row {
  display: grid;
  grid-template-columns: 8px minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  padding: 2px 0;
}

#dashboard .pm-tip-name {
  color: var(--bone-70);
  white-space: nowrap;
}

#dashboard .pm-tip-val {
  color: var(--bone);
  white-space: nowrap;
}

/* Narrow: the end labels move under the plot as a 2 x 2 list */
#dashboard .pm-endlist {
  display: none;
  margin: 0;
  padding: 0;
  list-style: none;
}

#dashboard .pm-chart--narrow .pm-endlist {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 16px;
  margin-top: 12px;
}

#dashboard .pm-endlist-item {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  font-size: 14px;
  line-height: 1.3;
  color: var(--bone-70);
}

/* ---------- Price position: 100% stacked bar and three rows ---------- */

#dashboard .pm-pos-bar {
  display: flex;
  gap: 2px;
  height: 14px;
  margin: 0 20px;
  border-radius: 3px;
  overflow: hidden;
}

#dashboard .pm-pos-seg {
  display: block;
  flex: 0 1 0;
  min-width: 0;
  height: 100%;
  transform-origin: left center;
}

#dashboard .pm-pos-seg--cheap,
#dashboard .pm-pos-sw--cheap {
  background: var(--accent);
}

#dashboard .pm-pos-seg--mid,
#dashboard .pm-pos-sw--mid {
  background: var(--bone);
}

#dashboard .pm-pos-seg--mid,
#dashboard .pm-pos-sw--mid {
  opacity: 0.45;
}

#dashboard .pm-pos-seg--dear,
#dashboard .pm-pos-sw--dear {
  background: repeating-linear-gradient(135deg, hsl(42 30% 94% / 0.55) 0 2px, transparent 2px 6px);
  box-shadow: inset 0 0 0 1px hsl(42 30% 94% / 0.35);
}

#dashboard .pm-pos-list {
  display: grid;
  gap: 28px;
  margin: 0;
  padding: 30px 20px 28px;
  list-style: none;
}

#dashboard .pm-pos-row {
  display: grid;
  grid-template-columns: 10px minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

#dashboard .pm-pos-sw {
  display: block;
  width: 10px;
  height: 10px;
  border-radius: 2px;
}

#dashboard .pm-pos-label {
  min-width: 0;
  font-size: 15px;
  line-height: 1.3;
  color: var(--bone);
}

#dashboard .pm-pos-val {
  display: grid;
  justify-items: end;
  gap: 2px;
}

#dashboard .pm-pos-val b {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 500;
  line-height: 1;
  letter-spacing: -0.02em;
  color: var(--bone);
  font-variant-numeric: tabular-nums;
}

#dashboard .pm-pos-val small {
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.4;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ash);
  font-variant-numeric: tabular-nums;
}

/* ---------- Latest changes: a table on desktop, stacked rows on phones ---------- */

#dashboard .pm-table-wrap {
  overflow-x: auto;
}

#dashboard .pm-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

#dashboard .pm-table thead .pm-c-when { width: 15%; }
#dashboard .pm-table thead .pm-c-type { width: 16%; }
#dashboard .pm-table thead .pm-c-store { width: 19%; }
#dashboard .pm-table thead .pm-c-text { width: 30%; }
#dashboard .pm-table thead .pm-c-out { width: 20%; }

#dashboard .pm-table th {
  height: 36px;
  padding: 0 12px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 400;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  text-align: left;
  color: var(--ash);
  white-space: nowrap;
}

#dashboard .pm-table td {
  height: 48px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line-soft);
  color: var(--bone-80);
  vertical-align: middle;
  min-width: 0;
}

#dashboard .pm-table th:first-child,
#dashboard .pm-table td:first-child {
  padding-left: 20px;
}

#dashboard .pm-table th:last-child,
#dashboard .pm-table td:last-child {
  padding-right: 20px;
}

#dashboard .pm-table tbody tr:last-child td {
  border-bottom: 0;
}

#dashboard .pm-table tbody tr {
  transition: background-color 0.2s var(--ease-std);
}

#dashboard .pm-table tbody tr:hover {
  background: var(--elev);
}

#dashboard .pm-c-when {
  font-family: var(--font-mono);
  font-size: 12.5px;
  letter-spacing: 0.08em;
  color: var(--ash);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

#dashboard .pm-c-text {
  font-size: 15px;
  line-height: 1.4;
  color: var(--bone);
}

#dashboard .pm-c-store {
  font-size: 15px;
  white-space: nowrap;
}

/* Change chips: tinted by tone, 1px border at 45% */
#dashboard .pm-chip {
  display: inline-block;
  padding: 3px 7px 2px;
  border: 1px solid var(--line);
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.3;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  white-space: nowrap;
}

/* Text red is lighter than the fill red (--danger) so the label holds 4.5:1 on the dark card */
#dashboard .pm-chip--down {
  color: #f0705f;
  background: hsl(0 70% 56% / 0.12);
  border-color: hsl(0 70% 56% / 0.45);
}

#dashboard .pm-chip--promo {
  color: var(--pm-promo);
  background: hsl(28 88% 56% / 0.12);
  border-color: hsl(28 88% 56% / 0.45);
}

#dashboard .pm-chip--opp {
  color: var(--ok);
  background: hsl(152 60% 48% / 0.12);
  border-color: hsl(152 60% 48% / 0.45);
}

#dashboard .pm-chip--info {
  color: var(--info);
  background: hsl(214 85% 66% / 0.12);
  border-color: hsl(214 85% 66% / 0.45);
}

#dashboard .pm-chip--up {
  color: var(--ash);
  border-color: hsl(42 30% 94% / 0.2);
}

/* Monogram: neutral square on the dark surface; You is gold */
#dashboard .pm-mono {
  display: inline-grid;
  place-items: center;
  width: 20px;
  height: 20px;
  margin-right: 8px;
  vertical-align: middle;
  background: var(--elev);
  border: 1px solid var(--line);
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 500;
  line-height: 1;
  color: var(--bone);
}

#dashboard .pm-mono--you {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

#dashboard .pm-store-name {
  vertical-align: middle;
}

/* Outcome: status chip, then the mono detail */
#dashboard .pm-status {
  display: inline-block;
  padding: 3px 7px 2px;
  border: 1px solid var(--line);
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.3;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  white-space: nowrap;
}

#dashboard .pm-status--acted {
  color: var(--ok);
  background: hsl(152 60% 48% / 0.12);
  border-color: hsl(152 60% 48% / 0.45);
}

#dashboard .pm-status--held {
  color: var(--bone-70);
  border-color: var(--line);
}

#dashboard .pm-status--ignored {
  color: var(--ash);
  border-style: dashed;
  border-color: var(--ash);
}

#dashboard .pm-out-detail {
  display: inline-block;
  margin-left: 10px;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.4;
  letter-spacing: 0.1em;
  color: var(--ash);
  vertical-align: middle;
}

/* ---------- Phone: 2 x 2 cards, one-column blocks, changes as stacked rows ---------- */

@media (max-width: 639px) {
  #dashboard .pm-dash .dashboard-stat-n {
    font-size: 1.75rem;
  }

  /* Labels reserve two lines (10px mono, line-height 1.5) so the numbers share one baseline */
  #dashboard .pm-dash .dashboard-stat-l {
    min-height: 3em;
  }

  #dashboard .pm-toolbar {
    padding: 18px 14px 12px;
  }

  #dashboard .pm-legend {
    padding: 0 14px 12px;
  }

  #dashboard .pm-chart {
    margin: 0 14px 18px;
  }

  #dashboard .pm-pos-bar {
    margin: 0 14px;
  }

  #dashboard .pm-pos-list {
    padding: 20px 14px 22px;
  }

  #dashboard .pm-table,
  #dashboard .pm-table tbody {
    display: block;
    width: 100%;
  }

  #dashboard .pm-table thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
  }

  #dashboard .pm-table tbody tr {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    grid-template-areas:
      "when type"
      "store store"
      "text text"
      "out out";
    gap: 8px 12px;
    padding: 16px 14px;
    border-bottom: 1px solid var(--line-soft);
  }

  #dashboard .pm-table tbody tr:last-child {
    border-bottom: 0;
  }

  #dashboard .pm-table tbody tr:hover {
    background: none;
  }

  #dashboard .pm-table td {
    display: block;
    height: auto;
    padding: 0;
    border: 0;
  }

  #dashboard .pm-table td:first-child,
  #dashboard .pm-table td:last-child {
    padding: 0;
  }

  #dashboard .pm-c-when { grid-area: when; }
  #dashboard .pm-c-type { grid-area: type; justify-self: end; }
  #dashboard .pm-c-store { grid-area: store; }
  #dashboard .pm-c-text { grid-area: text; }
  #dashboard .pm-c-out { grid-area: out; }
}

/* Position segments grow once when the window is seen. Finished widths are already in the markup. */
#dashboard .pm-dash--play .pm-pos-seg {
  animation: pm-grow 0.9s var(--ease-out) both;
  animation-delay: var(--d, 0s);
}

@keyframes pm-grow {
  from {
    transform: scaleX(0);
  }
  to {
    transform: scaleX(1);
  }
}

/* ---------- 09 / Stack: seven tools on hairlines ----------
   Each cell draws its own hairlines, so any column count works. */

#stack .pm-stack {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

#stack .pm-stack > * {
  min-width: 0;
  padding: 28px 22px;
  border-left: 0;
  border-top: 0;
}

#stack .pm-stack .features-glyph {
  margin-bottom: 24px;
}

#stack .features-caption {
  margin-top: 24px;
}

#stack .pm-tool-text {
  display: grid;
  gap: 8px;
  min-width: 0;
}

#stack .pm-tool-r {
  font-size: 1rem;
  line-height: 1.55;
  color: var(--ash);
  text-wrap: pretty;
}

#stack .pm-stack > *:hover .pm-tool-r {
  color: var(--bone-70);
}

@media (min-width: 1280px) {
  #stack .pm-stack {
    grid-template-columns: repeat(7, minmax(0, 1fr));
  }

  #stack .pm-stack > *:nth-child(n + 2) {
    border-left: 1px solid var(--line);
  }
}

@media (min-width: 1024px) and (max-width: 1279px) {
  #stack .pm-stack > *:nth-child(4n + 2),
  #stack .pm-stack > *:nth-child(4n + 3),
  #stack .pm-stack > *:nth-child(4n + 4) {
    border-left: 1px solid var(--line);
  }

  #stack .pm-stack > *:nth-child(n + 5) {
    border-top: 1px solid var(--line);
  }
}

@media (min-width: 640px) and (max-width: 1023px) {
  #stack .pm-stack {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  #stack .pm-stack > *:nth-child(2n) {
    border-left: 1px solid var(--line);
  }

  #stack .pm-stack > *:nth-child(n + 3) {
    border-top: 1px solid var(--line);
  }
}

@media (max-width: 639px) {
  #stack .pm-stack {
    grid-template-columns: minmax(0, 1fr);
  }

  #stack .pm-stack > *:nth-child(n + 2) {
    border-top: 1px solid var(--line);
  }

  /* One tool per row: glyph on the left, name with its line of copy beside it */
  #stack .pm-stack > * {
    display: flex;
    flex-direction: row;
    align-items: flex-start;
    gap: 16px;
    padding: 20px 0;
  }

  #stack .pm-stack .features-glyph {
    flex: none;
    margin: 2px 0 0;
  }
}

/* ---------- 10 / Built for: name and one line per row ---------- */

#industries .pm-ind-row {
  grid-template-columns: 10px minmax(0, 1fr);
  align-items: start;
  padding: 24px 0;
}

#industries .pm-ind-text {
  display: grid;
  gap: 8px;
  min-width: 0;
}

#industries .pm-ind-row .features-hex {
  margin-top: 8px;
}

#industries .pm-ind-line {
  font-size: 1.0625rem;
  line-height: 1.55;
  color: var(--ash);
  text-wrap: pretty;
}

@media (max-width: 767px) {
  #industries .pm-ind-row {
    min-height: 0;
    padding: 20px 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  #dashboard .pm-dash--play .pm-pos-seg {
    animation: none;
  }
}
