/* ==========================================================================
   FINICHE: OBSERVED FACTS AND THE NICHE OPPORTUNITY ESTIMATE
   Same grammar as data-honesty.css, on the styles.css tokens:
     observed facts   solid lines, pin ink (BSR + category, bought lower bound, brand, USPTO slips)
     the estimate     lavender model ink, a dashed gauge ring and a dashed frame, labelled Estimate
     no basis         a plain dash; the reason is spoken (visually hidden) or listed under "Why"
   CSP-safe: no inline styles. Popovers are native [popover]; facts-view.js only sets their position.
   ========================================================================== */

/* ---------------------------------------------------------------------------
   Product cards: sub-lines under observed metrics
   --------------------------------------------------------------------------- */
.metric-sub {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-top: 1px;
  font-size: 11px;
  line-height: 1.3;
  color: var(--text-muted);
}

.metric-box--bought .metric-sub {
  font-style: italic;
}

/* A miss in the index is not "safe": neutral ink, solid outline, never green. */
.badge.tmi-badge--none {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border-strong);
}

.badge.tmi-badge {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------------------------------------------------------------------------
   Drawer: observed facts list and the USPTO evidence slips
   --------------------------------------------------------------------------- */
.fact-list {
  display: grid;
  gap: 0;
  margin: 8px 0 0;
}

.fact-row {
  display: grid;
  grid-template-columns: minmax(118px, 34%) 1fr;
  gap: 4px 12px;
  padding: 7px 0;
  border-top: 1px solid var(--border-subtle);
}

.fact-row:first-child {
  border-top: 0;
}

.fact-row dt {
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding-top: 2px;
}

.fact-row dd {
  margin: 0;
  min-width: 0;
  font-size: 13.5px;
  color: var(--text-primary);
  overflow-wrap: anywhere;
}

.fact-strong {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.fact-aside {
  color: var(--text-muted);
  font-size: 12px;
}

.fact-mono {
  font-family: var(--font-mono);
  font-size: 12px;
}

.tmi-section--found {
  border-inline-start: 3px solid var(--amber-border);
}

.tmi-note {
  margin: 8px 0 0;
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--text-secondary);
}

.tmi-list {
  display: grid;
  gap: 8px;
  margin: 10px 0 0;
  padding: 0;
  list-style: none;
}

/* Each mark is an index slip: solid frame (an observed record), the mark set large, numbers in mono. */
.tmi-mark {
  padding: 9px 11px 10px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-inline-start: 3px solid var(--amber-text);
  border-radius: var(--radius-sm);
}

.tmi-mark-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 4px 10px;
}

.tmi-mark-name {
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.01em;
  overflow-wrap: anywhere;
}

.tmi-match {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--amber-text);
}

.tmi-facts {
  display: flex;
  flex-wrap: wrap;
  gap: 2px 14px;
  margin-top: 4px;
  font-size: 12px;
  color: var(--text-secondary);
}

.tmi-num {
  font-family: var(--font-mono);
  color: var(--text-primary);
}

.tmi-disclaimer {
  margin: 10px 0 0;
  padding-top: 8px;
  border-top: 1px dotted var(--border-strong);
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-secondary);
}

/* ---------------------------------------------------------------------------
   Keyword rows: suggestion rank and trend
   --------------------------------------------------------------------------- */
.kw-rank {
  font-family: var(--font-mono);
  font-weight: 600;
  color: var(--pin);
}

.kw-trend {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 28px;
  padding: 2px 10px 2px 8px;
  font: inherit;
  font-size: 12.5px;
  font-weight: 600;
  white-space: nowrap;
  color: var(--text-secondary);
  background: transparent;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-pill);
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition);
}

button.kw-trend:hover {
  background: var(--bg-hover);
  border-color: var(--border-strong);
}

button.kw-trend:focus-visible,
.opp-why:focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: 2px;
}

.kw-trend-arrow {
  font-family: var(--font-mono);
  font-size: 15px;
  line-height: 1;
}

.kw-trend--rising .kw-trend-arrow { color: var(--emerald-text); }
.kw-trend--falling .kw-trend-arrow { color: var(--danger-text); }
.kw-trend--flat .kw-trend-arrow { color: var(--text-muted); }

.kw-trend--none {
  border-color: transparent;
  color: var(--text-muted);
  cursor: default;
}

/* ---------------------------------------------------------------------------
   Popovers (native [popover]): basis of a trend, "Why" of an estimate
   --------------------------------------------------------------------------- */
.fact-pop {
  margin: auto;
  max-width: min(340px, var(--pop-room, calc(100vw - 16px)));
  padding: 11px 13px 12px;
  font-size: 12.5px;
  line-height: 1.45;
  color: var(--text-primary);
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-inline-start: 3px solid var(--pin);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-float);
}

/* Only when open: the UA hides a closed popover, an author display value would override that. */
.fact-pop:popover-open {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.fact-pop.is-anchored {
  position: fixed;
  inset: auto;
  margin: 0;
}

.fact-pop::backdrop {
  background: transparent;
}

@media (prefers-reduced-motion: no-preference) {
  .fact-pop:popover-open {
    animation: est-pop-in 140ms var(--ease-out);
  }
}

.fact-pop-title {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--pin);
}

.fact-pop-note {
  font-size: 11.5px;
  color: var(--text-muted);
}

.why-pop {
  max-width: min(380px, var(--pop-room, calc(100vw - 16px)));
  max-height: min(72vh, 540px);
  overflow: auto;
  border-color: var(--est-line);
  border-inline-start-color: var(--est-ink);
}

.why-pop .fact-pop-title {
  color: var(--est-ink);
}

.why-list {
  display: grid;
  gap: 8px;
  margin: 2px 0 0;
}

.why-row dt {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--est-ink);
}

.why-row dd {
  display: grid;
  gap: 1px;
  margin: 1px 0 0;
}

.why-sub {
  margin: 6px 0 0;
  font-size: 11.5px;
  font-weight: 700;
  color: var(--text-secondary);
}

.why-reasons,
.why-evidence {
  display: grid;
  gap: 3px;
  margin: 2px 0 0;
  padding: 0;
  list-style: none;
}

.why-reasons li,
.why-evidence li {
  position: relative;
  padding-inline-start: 14px;
}

.why-reasons li::before {
  content: '\2013';
  position: absolute;
  inset-inline-start: 0;
  color: var(--amber-text);
  font-weight: 700;
}

.why-evidence li {
  font-size: 11.5px;
  color: var(--text-secondary);
}

.why-evidence li::before {
  content: '';
  position: absolute;
  inset-inline-start: 2px;
  top: 0.55em;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--pin);
}

.why-formula {
  margin: 6px 0 0;
  padding: 6px 8px;
  font-family: var(--font-mono);
  font-size: 11px;
  background: var(--est-wash);
  border: 1px dashed var(--est-line);
  border-radius: var(--radius-sm);
}

.why-caveat {
  margin: 0;
  font-size: 11.5px;
  color: var(--text-muted);
}

/* ---------------------------------------------------------------------------
   Niche cards: gauge, Why, brand share
   --------------------------------------------------------------------------- */
.niche-toolbar {
  align-items: flex-end;
}

.niche-grid {
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr));
}

.niche-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.niche-head-text .card-title {
  margin: 0;
}

.niche-meta {
  margin: 2px 0 0;
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--text-muted);
}

.opp-block {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  background: var(--est-wash);
  border: 1px dashed var(--est-line);
  border-radius: var(--radius-md);
}

.opp-block--absent {
  grid-template-columns: 1fr;
  font-size: 12.5px;
}

.opp-gauge {
  display: block;
  flex: none;
}

/* The ring is dashed: the same "not measured" mark as the Estimate tag, at gauge size. */
.opp-ring {
  fill: none;
  stroke: var(--est-line);
  stroke-width: 3;
  stroke-dasharray: 2 3;
}

.opp-arc {
  fill: none;
  stroke: var(--est-ink);
  stroke-width: 4.5;
  stroke-linecap: round;
}

.opp-num {
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 700;
  fill: var(--est-ink);
  font-variant-numeric: tabular-nums;
}

.opp-approx {
  font-size: 10px;
  font-weight: 500;
}

.opp-gauge--none .opp-num {
  fill: var(--text-muted);
  font-weight: 500;
}

.opp-side {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 8px;
  min-width: 0;
}

.opp-name {
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
}

.opp-status {
  flex-basis: 100%;
  font-size: 12px;
  color: var(--text-secondary);
}

.opp-why {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 28px;
  padding: 2px 11px;
  font: inherit;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--pin);
  background: transparent;
  border: 1px solid var(--pin-line);
  border-radius: var(--radius-pill);
  cursor: pointer;
  transition: background var(--transition);
}

.opp-why::after {
  content: '?';
  display: inline-grid;
  place-items: center;
  width: 15px;
  height: 15px;
  font-size: 10px;
  font-weight: 700;
  border: 1px solid currentColor;
  border-radius: 50%;
}

.opp-why:hover,
.opp-why[aria-expanded='true'] {
  background: var(--pin-wash);
}

.brand-share-title {
  margin: 0 0 6px;
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.share-bar {
  display: block;
  width: 100%;
  height: 10px;
  border-radius: 3px;
  overflow: hidden;
  background: var(--bg-elevated);
}

.share-bar rect {
  stroke: var(--bg-surface);
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
}

.bar-b1, .swatch-b1 { fill: var(--pin); background: var(--pin); }
.bar-b2, .swatch-b2 { fill: color-mix(in srgb, var(--pin) 62%, var(--bg-surface)); background: color-mix(in srgb, var(--pin) 62%, var(--bg-surface)); }
.bar-b3, .swatch-b3 { fill: color-mix(in srgb, var(--pin) 34%, var(--bg-surface)); background: color-mix(in srgb, var(--pin) 34%, var(--bg-surface)); }
.bar-other, .swatch-other { fill: var(--text-muted); background: var(--text-muted); opacity: 0.45; }
.bar-none, .swatch-none { fill: var(--bg-elevated); background: var(--bg-elevated); }

.brand-legend {
  display: grid;
  gap: 3px;
  margin: 8px 0 0;
  padding: 0;
  list-style: none;
  font-size: 12.5px;
}

.brand-legend li {
  display: grid;
  grid-template-columns: 10px minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
}

.swatch {
  width: 10px;
  height: 10px;
  border-radius: 2px;
}

.swatch-none {
  border: 1px solid var(--border-strong);
}

.brand-legend-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.brand-num {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}

.brand-share-note,
.brand-share-empty {
  margin: 6px 0 0;
  font-size: 11px;
  color: var(--text-muted);
}

.niche-rec {
  margin: 0;
}

.niche-card .arb-coverage {
  margin: 0;
}

/* Small phones: facts stack, controls keep a comfortable touch size. */
@media (max-width: 480px) {
  .fact-row {
    grid-template-columns: 1fr;
  }

  .kw-trend,
  .opp-why {
    min-height: 32px;
  }

  .opp-block {
    gap: 10px;
    padding: 9px 10px;
  }
}

/* Visually hidden labels in table cells are absolutely positioned: without a positioned scroll
   wrapper they escape it and widen the page on tablets. Keep them inside the wrapper. */
.table-wrap {
  position: relative;
}
