/* GROW registry enhancements — Module 5.
   External stylesheet (CSP style-src 'self'; no inline styles).
   Tokens come from styles.css; only var() names are used here.
   Scope: wayfinding, filter bar + chips, status badges/legend,
   contract figure, row actions, JS row-hide hook. */

/* === Wayfinding — "Find the artifact you need" card grid === */
.wayfinding {
  width: min(var(--max), calc(100% - 32px));
  margin: 0 auto;
}
.wayfinding h2,
.wayfinding > h3 { margin-bottom: 1rem; }

.wayfinding-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
}
.wayfinding-card {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  min-height: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 1.1rem;
  color: var(--ink);
  text-decoration: none;
  transition: border-color 160ms ease, background 160ms ease, transform 160ms ease, box-shadow 160ms ease;
}
.wayfinding-card:hover,
.wayfinding-card:focus-visible {
  border-color: var(--brand);
  background: var(--surface-strong);
  transform: translateY(-2px);
}
.wayfinding-card .way-label {
  font-size: 1.04rem;
  font-weight: 800;
  line-height: 1.2;
  color: var(--ink);
}
.wayfinding-card .way-desc {
  margin: 0;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.4;
}

/* Recommended / "Start free" card emphasized with --brand. */
.wayfinding-card--recommended {
  border-color: var(--brand);
  border-width: 2px;
  background: var(--surface-brand);
  box-shadow: inset 4px 0 0 var(--brand);
}
.wayfinding-card--recommended .way-label { color: var(--brand-dark); }
.wayfinding-card .way-tag {
  display: inline-flex;
  width: fit-content;
  align-items: center;
  gap: 0.3rem;
  border: 1px solid rgba(36, 92, 70, 0.3);
  border-radius: 999px;
  background: var(--brand);
  color: #fff;
  padding: 0.18rem 0.55rem;
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

/* === Filter bar — progressive-enhancement controls + chips === */
.reg-filters {
  width: min(var(--max), calc(100% - 32px));
  margin: 0 auto;
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.9rem 1rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-strong);
  padding: 1.1rem;
}
.reg-filters .reg-field {
  display: grid;
  gap: 0.35rem;
  flex: 1 1 160px;
  min-width: 150px;
}
.reg-filters .reg-field--search { flex: 2 1 240px; }
.reg-filters label {
  color: var(--ink);
  font-size: 0.8rem;
  font-weight: 800;
}
.reg-filters select,
.reg-filters input[type="search"],
.reg-filters input[type="text"] {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 0.9rem;
  line-height: 1.4;
  padding: 0.55rem 0.65rem;
}
.reg-filters select[multiple] { min-height: 5.4rem; padding: 0.35rem; }
.reg-filters select:focus-visible,
.reg-filters input:focus-visible { border-color: var(--brand); }
.reg-filters .reg-actions-bar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex: 1 1 100%;
  flex-wrap: wrap;
}

/* Live result count (aria-live in markup). */
.reg-count {
  margin: 0;
  color: var(--brand-dark);
  font-size: 0.92rem;
  font-weight: 800;
}

/* Active-filter chip tray (populated by registry.js). */
.reg-active-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  width: 100%;
  margin: 0;
  padding: 0;
  list-style: none;
}
.reg-active-filters:empty { display: none; }
.reg-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink);
  padding: 0.22rem 0.5rem 0.22rem 0.6rem;
  font-size: 0.78rem;
  font-weight: 700;
  line-height: 1.3;
}
.reg-chip .reg-chip-facet {
  color: var(--muted);
  font-weight: 800;
  text-transform: uppercase;
  font-size: 0.68rem;
  letter-spacing: 0.03em;
}
.reg-chip button,
.reg-chip .reg-chip-x {
  display: inline-grid;
  place-items: center;
  width: 1.1rem;
  height: 1.1rem;
  border: 0;
  border-radius: 50%;
  background: var(--surface-warm);
  color: var(--accent);
  font-size: 0.82rem;
  font-weight: 900;
  line-height: 1;
  cursor: pointer;
  padding: 0;
}
.reg-chip button:hover,
.reg-chip button:focus-visible {
  background: var(--accent-soft);
  color: var(--brand-dark);
}

/* === Status badges ===
   Draft = outlined gold/earth; Gate-reviewed = solid --brand + check.
   Not color-alone: glyph + always-present text + border/fill shape.
   AA contrast: --gold-dark on --gold-soft; #fff on --brand/--brand-dark. */
.badge-draft,
.badge-reviewed,
.badge-shipped {
  display: inline-flex;
  width: fit-content;
  align-items: center;
  gap: 0.32rem;
  border-radius: 999px;
  padding: 0.2rem 0.55rem;
  font-size: 0.74rem;
  font-weight: 800;
  line-height: 1.2;
  white-space: nowrap;
}
.badge-draft {
  border: 1px solid var(--gold-dark);
  background: var(--gold-soft);
  color: var(--gold-dark);
}
.badge-reviewed {
  border: 1px solid var(--brand-dark);
  background: var(--brand);
  color: #fff;
}
.badge-shipped {
  border: 1px solid var(--brand-dark);
  background: var(--brand-dark);
  color: #fff;
}
/* Glyphs are decorative (aria-hidden in markup); text carries meaning. */
.badge-draft [aria-hidden="true"],
.badge-reviewed [aria-hidden="true"],
.badge-shipped [aria-hidden="true"] { font-size: 0.82em; line-height: 1; }

/* === Status legend — defines Draft + Gate-reviewed (proposed) === */
.reg-status-legend {
  width: min(var(--max), calc(100% - 32px));
  margin: 0 auto;
  display: grid;
  gap: 0.75rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-warm);
  padding: 1.1rem 1.15rem;
}
.reg-status-legend h2,
.reg-status-legend h3 { margin: 0; font-size: 1.05rem; }
.reg-status-legend dl { display: grid; gap: 0.6rem; margin: 0; }
.reg-status-legend dt { margin-bottom: 0.2rem; }
.reg-status-legend dd {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.45;
}
.reg-status-legend .reg-proposed-note {
  margin: 0;
  color: var(--gold-dark);
  font-size: 0.82rem;
  font-weight: 700;
}
.reg-status-legend a { color: var(--brand-dark); font-weight: 700; }

/* === Contract figure — responsive diagram img + caption + text-equiv === */
.contract-figure {
  width: min(var(--max), calc(100% - 32px));
  margin: 0 auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 1.15rem;
}
.contract-figure img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: var(--radius);
  background: var(--paper-tint);
}
.contract-figure figcaption {
  margin-top: 0.75rem;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.45;
}
.contract-figure details {
  margin-top: 0.85rem;
  border-top: 1px solid var(--line);
  padding-top: 0.85rem;
}
.contract-figure summary { cursor: pointer; font-weight: 800; color: var(--ink); }
.contract-figure details[open] summary { margin-bottom: 0.65rem; }
.contract-figure-table {
  max-width: 100%;
  overflow-x: auto;
  overscroll-behavior-inline: contain;
  -webkit-overflow-scrolling: touch;
}
.contract-figure table { min-width: 520px; }
.contract-figure a { color: var(--brand-dark); font-weight: 700; }
/* Highlight target when a C<n> token scrolls to the figure. */
.contract-figure:target { outline: 3px solid var(--brand); outline-offset: 3px; }

/* === Row actions — inline action links inside the registry table === */
.reg-actions {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 0.3rem 0.65rem;
  white-space: nowrap;
}
.reg-actions a {
  color: var(--brand-dark);
  font-size: 0.85rem;
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
}
.reg-actions a:hover,
.reg-actions a:focus-visible { color: var(--accent); text-decoration: underline; }
/* Contract C<n> token links rendered in table cells. */
.reg-contract-link { font-weight: 700; color: var(--brand-dark); white-space: nowrap; }

/* === JS hook — hide filtered-out rows === */
.reg-row-hidden { display: none; }

/* Empty-state shown by JS when no rows match. */
.reg-empty {
  margin: 1rem auto 0;
  width: min(var(--max), calc(100% - 32px));
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 1rem 1.15rem;
  color: var(--muted);
  font-weight: 700;
}
.reg-empty[hidden] { display: none; }

/* === Responsive === */
@media (max-width: 940px) {
  .wayfinding-cards { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
  .reg-filters .reg-field { flex: 1 1 45%; }
}
@media (max-width: 620px) {
  .wayfinding,
  .reg-filters,
  .reg-status-legend,
  .contract-figure,
  .reg-empty { width: min(100% - 24px, var(--max)); }
  .wayfinding-cards { grid-template-columns: 1fr; }
  .reg-filters { flex-direction: column; align-items: stretch; }
  .reg-filters .reg-field,
  .reg-filters .reg-field--search { flex: 1 1 auto; min-width: 0; }
  .reg-actions-bar { align-items: flex-start; flex-direction: column; }
  .reg-actions { flex-direction: column; gap: 0.2rem; }
}
@media (prefers-reduced-motion: reduce) {
  .wayfinding-card,
  .wayfinding-card:hover,
  .wayfinding-card:focus-visible { transform: none; }
}
