//
// METRICS CARDS — light
// =====================
// Per-metric cards on the page detail "Metrics" tab. Currently used by:
// - Long Animation Frame entries (LOAF) — 5-phase stacked bar + script
//   attribution
// - Interaction to Next Paint (INP) — hero latency number + event metadata
//

//
// LOAF — palette per timing phase. Keep these distinct enough to read in
// the stacked bar and the legend swatches without relying on hue alone.
//
$loaf--blocking: #b91c1c;        // red — the "bad" portion (input-blocked)
$loaf--work: #d97706;            // amber — script work
$loaf--render: #16a34a;          // green — rendering
$loaf--pre-layout: #0095d2;      // brand blue — pre-layout overhead
$loaf--style-layout: #7c3aed;    // violet — style + layout

.loaf-card {
  background: $color--surface-card;
  border: 1px solid $color--border;
  border-radius: $radius--md;
  padding: 16px 18px;
  margin-bottom: 18px;
  box-shadow: $shadow--sm;
}

.loaf-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.loaf-rank {
  font-weight: $font--weight--semibold;
  color: $color--text-secondary;
  font-size: 0.95rem;
}

.loaf-bar {
  display: flex;
  width: 100%;
  height: 14px;
  border-radius: $radius--sm;
  overflow: hidden;
  background: $color--surface;
  border: 1px solid $color--border;
  margin-bottom: 12px;
}

.loaf-bar-segment {
  display: block;
  height: 100%;

  &.loaf-blocking { background: $loaf--blocking; }
  &.loaf-work { background: $loaf--work; }
  &.loaf-render { background: $loaf--render; }
  &.loaf-pre-layout { background: $loaf--pre-layout; }
  &.loaf-style-layout { background: $loaf--style-layout; }
}

.loaf-legend {
  list-style: none;
  margin: 0 0 14px 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  font-size: 0.85rem;

  li {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin: 0;
  }
}

.loaf-legend-swatch {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  display: inline-block;
  flex: 0 0 auto;

  &.loaf-blocking { background: $loaf--blocking; }
  &.loaf-work { background: $loaf--work; }
  &.loaf-render { background: $loaf--render; }
  &.loaf-pre-layout { background: $loaf--pre-layout; }
  &.loaf-style-layout { background: $loaf--style-layout; }
}

.loaf-legend-label {
  color: $color--text-secondary;
}

.loaf-legend-value {
  color: $color--text;
  font-weight: $font--weight--medium;
  font-variant-numeric: tabular-nums;
}

.loaf-scripts-heading {
  font-size: 0.95rem;
  font-weight: $font--weight--semibold;
  color: $color--text-secondary;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin: 12px 0 8px 0;
}

.loaf-script {
  margin-bottom: 12px;
  padding: 10px 12px;
  background: $color--surface;
  border-radius: $radius--sm;
  border: 1px solid $color--border;

  &:last-child {
    margin-bottom: 0;
  }
}

.loaf-script-url {
  margin-bottom: 6px;
  word-break: break-all;
  font-family: $font--mono;
  font-size: 0.85rem;
}

.loaf-script-meta {
  display: grid;
  grid-template-columns: auto 1fr;
  column-gap: 16px;
  row-gap: 4px;
  margin: 0;
  font-size: 0.85rem;

  dt {
    color: $color--text-muted;
    font-weight: $font--weight--medium;
  }

  dd {
    margin: 0;
    color: $color--text;
    word-break: break-word;
  }
}

.loaf-no-scripts {
  margin-top: 8px;
  color: $color--text-muted;
  font-style: italic;
  font-size: 0.9rem;
}

//
// INP card — hero latency + event metadata
//
.inp-card {
  background: $color--surface-card;
  border: 1px solid $color--border;
  border-radius: $radius--md;
  padding: 18px 20px;
  margin-bottom: 18px;
  box-shadow: $shadow--sm;
}

.inp-headline {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 16px;
  padding-bottom: 14px;
  border-bottom: 1px solid $color--border;
}

.inp-latency {
  font-size: 2.5rem;
  font-weight: $font--weight--semibold;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  padding: 4px 14px;
  border-radius: $radius--md;
  line-height: 1.1;

  &.ok {
    color: $color--ok;
    background: $color--ok-bg;
    border: 1px solid $color--ok-border;
  }
  &.warning {
    color: $color--warning;
    background: $color--warning-bg;
    border: 1px solid $color--warning-border;
  }
  &.error {
    color: $color--error;
    background: $color--error-bg;
    border: 1px solid $color--error-border;
  }
}

.inp-headline-sub {
  color: $color--text-muted;
  font-size: 0.95rem;
}

.inp-meta {
  display: grid;
  grid-template-columns: minmax(180px, auto) 1fr;
  column-gap: 16px;
  row-gap: 8px;
  margin: 0;
  font-size: 0.95rem;

  // Stack the dt/dd pairs on narrow viewports — the 180px label
  // column and 1fr value column squeeze unreadably below ~480px.
  @media (max-width: 480px) {
    grid-template-columns: 1fr;
    row-gap: 2px;

    dt { margin-top: 4px; }
  }

  dt {
    color: $color--text-muted;
    font-weight: $font--weight--medium;
  }

  dd {
    margin: 0;
    color: $color--text;
    word-break: break-word;
  }

  code {
    font-size: 0.85em;
  }
}

//
// LCP card — hero render time + phase breakdown + element / DOM-path
// metadata, side-by-side with the screenshot column.
//
$lcp--ttfb: #b91c1c;
$lcp--resource-delay: #d97706;
$lcp--resource-load: #0095d2;
$lcp--render-delay: #7c3aed;

.lcp-card {
  background: $color--surface-card;
  border: 1px solid $color--border;
  border-radius: $radius--md;
  padding: 18px 20px;
  margin-bottom: 18px;
  box-shadow: $shadow--sm;
}

.lcp-headline {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 16px;
  padding-bottom: 14px;
  border-bottom: 1px solid $color--border;
}

.lcp-render-time {
  font-size: 2.5rem;
  font-weight: $font--weight--semibold;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  padding: 4px 14px;
  border-radius: $radius--md;
  line-height: 1.1;

  &.ok {
    color: $color--ok;
    background: $color--ok-bg;
    border: 1px solid $color--ok-border;
  }
  &.warning {
    color: $color--warning;
    background: $color--warning-bg;
    border: 1px solid $color--warning-border;
  }
  &.error {
    color: $color--error;
    background: $color--error-bg;
    border: 1px solid $color--error-border;
  }
}

.lcp-headline-sub {
  color: $color--text-muted;
  font-size: 0.95rem;
}

.lcp-phases-heading,
.lcp-section-heading {
  font-size: 0.95rem;
  font-weight: $font--weight--semibold;
  color: $color--text-secondary;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin: 14px 0 8px 0;
}

.lcp-bar {
  display: flex;
  width: 100%;
  height: 14px;
  border-radius: $radius--sm;
  overflow: hidden;
  background: $color--surface;
  border: 1px solid $color--border;
  margin-bottom: 10px;
}

.lcp-bar-segment {
  display: block;
  height: 100%;
  &.lcp-ttfb { background: $lcp--ttfb; }
  &.lcp-resource-delay { background: $lcp--resource-delay; }
  &.lcp-resource-load { background: $lcp--resource-load; }
  &.lcp-render-delay { background: $lcp--render-delay; }
}

.lcp-legend {
  list-style: none;
  margin: 0 0 12px 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
  font-size: 0.85rem;

  li {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin: 0;
  }
}

.lcp-legend-swatch {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  display: inline-block;
  flex: 0 0 auto;
  &.lcp-ttfb { background: $lcp--ttfb; }
  &.lcp-resource-delay { background: $lcp--resource-delay; }
  &.lcp-resource-load { background: $lcp--resource-load; }
  &.lcp-render-delay { background: $lcp--render-delay; }
}

.lcp-legend-label {
  color: $color--text-secondary;
}

.lcp-legend-value {
  color: $color--text;
  font-weight: $font--weight--medium;
  font-variant-numeric: tabular-nums;
}

.lcp-meta {
  display: grid;
  grid-template-columns: minmax(160px, auto) 1fr;
  column-gap: 16px;
  row-gap: 6px;
  margin: 0 0 8px 0;
  font-size: 0.95rem;

  @media (max-width: 480px) {
    grid-template-columns: 1fr;
    row-gap: 2px;

    dt { margin-top: 4px; }
  }

  dt {
    color: $color--text-muted;
    font-weight: $font--weight--medium;
  }

  dd {
    margin: 0;
    color: $color--text;
    word-break: break-word;
  }

  code {
    font-size: 0.85em;
  }
}

.lcp-dompath {
  background: $color--surface;
  border: 1px solid $color--border;
  border-radius: $radius--sm;
  padding: 10px 12px;
  margin: 0;
  white-space: pre-wrap;
  word-break: break-all;
  font-size: 0.8rem;
  font-family: $font--mono;
  color: $color--text;
  overflow-x: auto;
}

.lcp-screenshot {
  max-width: 100%;
  // Cap the height so portrait captures from emulated-mobile / iOS
  // device runs don't dominate the card. Aspect ratio is preserved
  // (browser scales to fit both max-width and max-height); full image
  // stays one click away via the wrapping anchor.
  max-height: 480px;
  width: auto;
  height: auto;
  border-radius: $radius--sm;
  border: 1px solid $color--border;
  margin-bottom: 8px;
}

// The matched LCP element image is the actual asset (often the original
// 1200×800+ hero photo); cap its preview so it stops dwarfing the rest
// of the column. The full asset is still one click away via the wrapping
// anchor.
.lcp-element-image {
  display: block;
  max-width: 240px;
  max-height: 180px;
  width: auto;
  height: auto;
  border-radius: $radius--sm;
  border: 1px solid $color--border;
  margin-bottom: 8px;
  object-fit: contain;

  // On narrow viewports the column itself is tiny, so the 240px cap
  // can overflow horizontally. Switch to fluid-width and cap height
  // proportionally.
  @media (max-width: 600px) {
    max-width: 100%;
    max-height: 220px;
  }
  background: $color--surface;
}

//
// CLS card — hero score (with web-vitals threshold colour) +
// per-element shift list, paired with the layout-shift screenshot.
//
.cls-card {
  background: $color--surface-card;
  border: 1px solid $color--border;
  border-radius: $radius--md;
  padding: 18px 20px;
  margin-bottom: 18px;
  box-shadow: $shadow--sm;
}

.cls-headline {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 16px;
  padding-bottom: 14px;
  border-bottom: 1px solid $color--border;
}

.cls-score {
  font-size: 2.5rem;
  font-weight: $font--weight--semibold;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  padding: 4px 14px;
  border-radius: $radius--md;
  line-height: 1.1;

  &.ok { color: $color--ok; background: $color--ok-bg; border: 1px solid $color--ok-border; }
  &.warning { color: $color--warning; background: $color--warning-bg; border: 1px solid $color--warning-border; }
  &.error { color: $color--error; background: $color--error-bg; border: 1px solid $color--error-border; }
}

.cls-headline-sub {
  color: $color--text-muted;
  font-size: 0.95rem;
}

.cls-no-shifts {
  color: $color--text-muted;
  font-style: italic;
}

.cls-section-heading {
  font-size: 0.95rem;
  font-weight: $font--weight--semibold;
  color: $color--text-secondary;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin: 0 0 4px 0;
}

.cls-section-help {
  color: $color--text-muted;
  font-size: 0.9rem;
  margin-bottom: 12px;
}

.cls-shifts {
  list-style: none;
  margin: 0;
  padding: 0;
}

.cls-shift {
  margin-bottom: 12px;
  padding: 10px 12px;
  background: $color--surface;
  border: 1px solid $color--border;
  border-radius: $radius--sm;
  min-width: 0;          // allow shrinking inside the .one-half.column
  overflow: hidden;
  overflow-wrap: anywhere;

  &:last-child {
    margin-bottom: 0;
  }
}

.cls-shift-row {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 6px;
  flex-wrap: wrap;
  min-width: 0;
}

.cls-shift-rank {
  color: $color--text-muted;
  font-weight: $font--weight--medium;
  font-variant-numeric: tabular-nums;
  font-size: 0.85rem;
  flex: 0 0 auto;
}

.cls-shift-score {
  color: $color--text;
  font-weight: $font--weight--semibold;
  font-variant-numeric: tabular-nums;
  font-size: 1rem;
  flex: 0 0 auto;
}

.cls-shift-tags {
  flex: 1 1 0;
  min-width: 0;
  font-size: 0.85rem;
  color: $color--text-secondary;
  word-break: break-word;
  overflow-wrap: anywhere;

  code {
    // Override the global `code { white-space: nowrap }` so a long tag
    // string (`<div class="...">,<div ...>,…`) wraps inside the card
    // instead of pushing the whole .one-half.column wider than its
    // 48% slot.
    white-space: normal;
    word-break: break-word;
    overflow-wrap: anywhere;
    font-size: 1em;
  }
}

.cls-shift-dompath {
  background: $color--surface-card;
  border: 1px solid $color--border;
  border-radius: $radius--sm;
  padding: 8px 10px;
  margin: 0;
  white-space: pre-wrap;
  word-break: break-all;
  overflow-wrap: anywhere;
  font-size: 0.78rem;
  font-family: $font--mono;
  color: $color--text;
  overflow-x: auto;

  code {
    // Same override — without it the global `code { white-space: nowrap }`
    // re-collapses the wrapping the wrapper `pre` already enabled.
    white-space: inherit;
    word-break: inherit;
    overflow-wrap: inherit;
    background: transparent;
    border: 0;
    padding: 0;
    font-size: inherit;
  }
}

.cls-screenshot {
  max-width: 100%;
  max-height: 480px;
  width: auto;
  height: auto;
  border-radius: $radius--sm;
  border: 1px solid $color--border;
  margin-bottom: 8px;
}

//
// Render-phase gap bar — stacked bar above the metrics tab that splits
// the page-load timeline into the phases the developer can act on
// (network, render-blocking, hero paint, tail). Segment widths are
// proportional to ms; the legend underneath restates each segment with
// the absolute ms and percentage so a too-narrow segment is still
// readable.
//
.render-phase {
  margin-bottom: 18px;
}

.render-phase-body {
  padding: 12px 14px 14px 14px;
}

.render-phase-bar {
  display: flex;
  height: 32px;
  width: 100%;
  border-radius: $radius--sm;
  overflow: hidden;
  border: 1px solid $color--border;
  background: $color--surface;
}

.render-phase-segment {
  background: var(--rp-color, $color--text-muted);
  display: flex;
  align-items: center;
  justify-content: flex-start;
  padding: 0 8px;
  min-width: 0;
  cursor: help;

  &:not(:last-child) {
    border-right: 1px solid rgba(255, 255, 255, 0.5);
  }
}

.render-phase-segment-label {
  font-size: 0.78rem;
  font-weight: $font--weight--medium;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.25);
}

.render-phase-legend {
  list-style: none;
  margin: 12px 0 0 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 6px 16px;

  li {
    font-size: 0.85rem;
    line-height: 1.5;
  }

  strong {
    color: $color--text;
    font-weight: $font--weight--semibold;
  }
}

// Swatch is inline-aligned with the strong label so it stays on the
// first line of text even when the meta text wraps. vertical-align:
// middle puts the box at the line center; the negative margin-top is a
// 1px optical nudge so the box reads as centred against capital letters.
.render-phase-swatch {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 2px;
  vertical-align: middle;
  margin-right: 8px;
  margin-top: -2px;
}

.render-phase-legend-meta {
  color: $color--text-muted;
  font-variant-numeric: tabular-nums;
  font-size: 0.8rem;
}

//
// Web Vitals hero — the headline scoreboard at the top of the metrics
// tab. One tile per Vital with a colour-coded dot, the value, the metric
// short name (LCP, INP, ...) and a status word (Good / Needs improvement
// / Poor) tied to Google's p75 cutoffs. The whole card replaces the old
// metric-tile pill layout the Vitals used to share with the lower
// browser-metrics tables.
//
.web-vitals-hero {
  margin-bottom: 18px;
}

.web-vitals-hero-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
  padding: 14px;
}

.web-vital {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 14px 12px 14px;
  background: $color--surface-card;
  border: 1px solid $color--border;
  border-radius: $radius--md;

  &.web-vital--ok {
    background: $color--ok-bg;
    border-color: $color--ok-border;
  }
  &.web-vital--warning {
    background: $color--warning-bg;
    border-color: $color--warning-border;
  }
  &.web-vital--error {
    background: $color--error-bg;
    border-color: $color--error-border;
  }
}

.web-vital-dot {
  flex: 0 0 auto;
  width: 14px;
  height: 14px;
  margin-top: 6px;
  border-radius: 50%;
  background: $color--text-muted;

  .web-vital--ok & { background: $color--ok; }
  .web-vital--warning & { background: #facc15; }
  .web-vital--error & { background: $color--error; }
}

.web-vital-body {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  flex: 1;
}

.web-vital-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.web-vital-value {
  font-size: 1.6rem;
  font-weight: $font--weight--semibold;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
  color: $color--text;
}

.web-vital-short {
  font-family: $font--mono;
  font-size: 0.75rem;
  letter-spacing: 0.05em;
  color: $color--text-muted;
  text-transform: uppercase;
}

.web-vital-name {
  font-size: 0.9rem;
  color: $color--text-secondary;
  word-break: break-word;

  a {
    color: inherit;
    border-bottom: 1px dotted $color--border;
    text-decoration: none;
  }
  a:hover {
    border-bottom-color: $color--text-muted;
  }
}

.web-vital-status {
  font-size: 0.78rem;
  font-weight: $font--weight--medium;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: $color--text-muted;

  .web-vital--ok & { color: $color--ok; }
  .web-vital--warning & { color: #a16207; }
  .web-vital--error & { color: $color--error; }
}
