/* ==========================================================================
   COMPONENT: COMPONENT EXPLORER (Clastix case study)
   A live specimen of rebuilt library components, themed with the
   public Clastix brand tokens and framed in the portfolio's own UI.
   ========================================================================== */

/* ---------- Clastix library tokens ---------- */
.cx-canvas {
  /* Brand Dark Blue (digital primary) */
  --cx-blue-50: #E6E6F2;  --cx-blue-100: #CCCCE6; --cx-blue-200: #9999CC;
  --cx-blue-300: #6666B3; --cx-blue-400: #333399; --cx-blue-500: #000080;
  --cx-blue-600: #000066; --cx-blue-700: #00004D; --cx-blue-800: #000033;
  /* Brand Magenta */
  --cx-magenta-50: #FBE8EE;  --cx-magenta-100: #F7D2DD; --cx-magenta-200: #EFA5BB;
  --cx-magenta-300: #E77999; --cx-magenta-400: #E04C78; --cx-magenta-500: #D81D56;
  --cx-magenta-600: #AD1745; --cx-magenta-700: #821134; --cx-magenta-800: #560C22;
  /* Gray (Tailwind v4) */
  --cx-gray-50: #F9FAFB;  --cx-gray-100: #F3F4F6; --cx-gray-200: #E5E7EB;
  --cx-gray-300: #D1D5DB; --cx-gray-400: #9CA3AF; --cx-gray-500: #6B7280;
  --cx-gray-700: #374151; --cx-gray-800: #1F2937; --cx-gray-900: #111827;
  /* Status (Tailwind v4): error red, warning yellow, success green */
  --cx-red-50: #FEF2F2;    --cx-red-600: #DC2626;    --cx-red-700: #B91C1C;
  --cx-yellow-50: #FEFCE8; --cx-yellow-500: #EAB308; --cx-yellow-700: #A16207;
  --cx-green-50: #F0FDF4;  --cx-green-600: #16A34A;  --cx-green-700: #15803D;

  /* semantic roles: light */
  --cx-bg: var(--cx-gray-50);
  --cx-surface: #FFFFFF;
  --cx-border: var(--cx-gray-200);
  --cx-heading: var(--cx-gray-900);
  --cx-body: var(--cx-gray-700);
  --cx-muted: var(--cx-gray-500);
  --cx-primary: var(--cx-blue-500);
  --cx-track: var(--cx-gray-100);
  --cx-fill: var(--cx-blue-500);
  --cx-info-bg: var(--cx-blue-50);
  --cx-cta: var(--cx-magenta-500);
  --cx-cta-hover: var(--cx-magenta-700);
  --cx-on-cta: #FFFFFF;
  --cx-sec-bg: #FFFFFF;
  --cx-sec-bg-hover: var(--cx-gray-50);
  --cx-sec-border: var(--cx-gray-300);
  --cx-sec-text: var(--cx-gray-700);
  --cx-sec-text-hover: var(--cx-gray-800);
  --cx-sec-disabled: var(--cx-gray-400);
  --cx-ring-gap: #FFFFFF;
  --cx-ring: var(--cx-blue-500);
  --cx-ok-bg: var(--cx-green-50);   --cx-ok-text: var(--cx-green-700);   --cx-ok-dot: var(--cx-green-600);
  --cx-warn-bg: var(--cx-yellow-50); --cx-warn-text: var(--cx-yellow-700); --cx-warn-fill: var(--cx-yellow-500);
  --cx-err-bg: var(--cx-red-50);    --cx-err-text: var(--cx-red-700);    --cx-err-fill: var(--cx-red-600);
  --cx-skeleton: var(--cx-gray-100);
  --cx-skeleton-hi: var(--cx-gray-50);
  --cx-row-hover: var(--cx-gray-50);

  font-family: 'Montserrat', Arial, Helvetica, sans-serif;
  container-type: inline-size;
  container-name: cx;
  width: 100%;
  max-width: 640px;
  margin-inline: auto;
  padding: clamp(16px, 3vw, 28px);
  background: var(--cx-bg);
  color: var(--cx-body);
  border-radius: 10px;
  transition: max-width 0.45s cubic-bezier(0.16, 1, 0.3, 1), background-color 0.3s ease;
}

.cx-canvas[data-theme='dark'] {
  --cx-bg: var(--cx-blue-800);
  --cx-surface: var(--cx-blue-700);
  --cx-border: rgba(204, 204, 230, 0.16);
  --cx-heading: #FFFFFF;
  --cx-body: var(--cx-blue-100);
  --cx-muted: var(--cx-blue-200);
  --cx-primary: var(--cx-blue-100);
  --cx-track: rgba(204, 204, 230, 0.14);
  --cx-fill: var(--cx-blue-100);
  --cx-info-bg: rgba(204, 204, 230, 0.12);
  --cx-cta-hover: var(--cx-magenta-600);
  --cx-sec-bg: transparent;
  --cx-sec-bg-hover: rgba(204, 204, 230, 0.08);
  --cx-sec-border: rgba(204, 204, 230, 0.35);
  --cx-sec-text: var(--cx-blue-50);
  --cx-sec-text-hover: #FFFFFF;
  --cx-sec-disabled: var(--cx-blue-300);
  --cx-ring-gap: var(--cx-blue-700);
  --cx-ring: var(--cx-blue-100);
  --cx-ok-bg: rgba(34, 197, 94, 0.14);  --cx-ok-text: #4ADE80;  --cx-ok-dot: #4ADE80;
  --cx-warn-bg: rgba(234, 179, 8, 0.14); --cx-warn-text: #FACC15;
  --cx-err-bg: rgba(239, 68, 68, 0.16);  --cx-err-text: #F87171; --cx-err-fill: #EF4444;
  --cx-skeleton: rgba(204, 204, 230, 0.10);
  --cx-skeleton-hi: rgba(204, 204, 230, 0.20);
  --cx-row-hover: rgba(204, 204, 230, 0.06);
}

.cx-canvas[data-component='button'] { max-width: 760px; }
.cx-canvas[data-width='mobile'] { max-width: 360px; }

/* ---------- Explorer frame (portfolio UI) ---------- */
.cx-explorer {
  margin: 0;
  background-color: var(--color-bg-surface);
  border: var(--border-cyber);
  border-radius: 4px;
  overflow: hidden;
}

.cx-explorer__toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm) var(--space-md);
  padding: var(--space-sm) var(--space-md);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.cx-explorer__group {
  display: grid;
  row-gap: 6px;
  border: 0;
  margin: 0;
  padding: 0;
  min-width: 0;
}

.cx-explorer__label {
  font-family: var(--font-mono);
  font-size: var(--font-size-2xs);
  letter-spacing: var(--letter-spacing-mono);
  color: var(--color-text-muted);
  text-transform: uppercase;
  padding: 0;
}

.cx-explorer__options {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.cx-chip {
  font-family: var(--font-mono);
  font-size: var(--font-size-2xs);
  letter-spacing: 0.04em;
  color: var(--color-text-secondary);
  background: var(--color-bg-subtle);
  border: var(--border-subtle);
  border-radius: 2px;
  padding: 6px 10px;
  cursor: pointer;
  transition: var(--transition-snap-fast);
}

.cx-chip:hover { color: var(--color-text-primary); border-color: rgba(255, 255, 255, 0.3); }

.cx-chip[aria-pressed='true'] {
  color: var(--color-text-inverse);
  background: var(--color-accent-purple);
  border-color: var(--color-accent-purple);
  box-shadow: var(--shadow-purple-hard);
  transform: translate(-1px, -1px);
}

.cx-chip[aria-pressed='true']:active { box-shadow: var(--shadow-active); transform: translate(1px, 1px); }

.cx-chip--inspect[aria-pressed='true'] {
  background: var(--color-accent-pink);
  border-color: var(--color-accent-pink);
  box-shadow: var(--shadow-pink-hard);
}

.cx-chip:focus-visible { outline: 2px solid var(--color-accent-purple); outline-offset: 2px; }

.cx-explorer__stage {
  padding: clamp(16px, 4vw, 48px) clamp(12px, 3vw, 40px);
  min-height: 420px;
  display: grid;
  align-items: start;
  background-color: var(--color-bg-base);
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.035) 1px, transparent 1px);
  background-size: 24px 24px;
}

.cx-explorer__bar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: var(--space-xs);
  padding: var(--space-sm) var(--space-md);
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  font-family: var(--font-mono);
  font-size: var(--font-size-2xs);
  letter-spacing: var(--letter-spacing-mono);
  color: var(--color-text-muted);
}

.cx-explorer__readout { color: var(--color-accent-purple); }

/* ---------- Shared component primitives ---------- */
.cx-card {
  position: relative;
  background: var(--cx-surface);
  border: 1px solid var(--cx-border);
  border-radius: 8px;
  padding: 20px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.cx-card:hover { box-shadow: 0 6px 24px -12px rgba(0, 0, 51, 0.35); }

.cx-card__head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 16px;
}

.cx-eyebrow {
  font-size: 12px;
  font-weight: 600;
  color: var(--cx-muted);
  margin-bottom: 2px;
}

.cx-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--cx-heading);
  line-height: 1.3;
}

.cx-text { font-size: 14px; line-height: 1.55; color: var(--cx-body); }
.cx-small { font-size: 12px; color: var(--cx-muted); }

.cx-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--cx-info-bg);
  color: var(--cx-primary);
}

.cx-badge::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.cx-badge--ok { background: var(--cx-ok-bg); color: var(--cx-ok-text); }
.cx-badge--ok::before { background: var(--cx-ok-dot); }
.cx-badge--warn { background: var(--cx-warn-bg); color: var(--cx-warn-text); }
.cx-badge--err { background: var(--cx-err-bg); color: var(--cx-err-text); }

.cx-badge--pending::before { animation: cx-pulse 1.2s ease-in-out infinite; }

/* Buttons: primary (magenta) + secondary (outline), five sizes, icon-only */
.cx-btn {
  --h: 40px; --px: 14px; --fs: 14px; --gap: 6px; --ic: 20px; --r: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--gap);
  font-family: inherit;
  font-size: var(--fs);
  font-weight: 600;
  line-height: 1;
  white-space: nowrap;
  height: var(--h);
  padding: 0 var(--px);
  border-radius: var(--r);
  border: 1px solid transparent;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.05);
  transition: background-color 0.18s ease, color 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease, transform 0.12s ease;
}

.cx-btn--sm  { --h: 36px; --px: 12px; --fs: 14px; --ic: 20px; }
.cx-btn--md  { --h: 40px; --px: 14px; --fs: 14px; --ic: 20px; }
.cx-btn--lg  { --h: 44px; --px: 16px; --fs: 16px; --ic: 20px; }
.cx-btn--xl  { --h: 48px; --px: 18px; --fs: 16px; --ic: 20px; --gap: 8px; }
.cx-btn--2xl { --h: 60px; --px: 22px; --fs: 18px; --ic: 24px; --gap: 10px; --r: 10px; }
.cx-btn--icon { width: var(--h); padding: 0; }

.cx-btn--primary { background: var(--cx-cta); border-color: var(--cx-cta); color: var(--cx-on-cta); }
.cx-btn--primary:hover, .cx-btn--primary.is-hover,
.cx-btn--primary[aria-busy='true'] { background: var(--cx-cta-hover); border-color: var(--cx-cta-hover); }

.cx-btn--secondary { background: var(--cx-sec-bg); border-color: var(--cx-sec-border); color: var(--cx-sec-text); }
.cx-btn--secondary:hover, .cx-btn--secondary.is-hover { background: var(--cx-sec-bg-hover); color: var(--cx-sec-text-hover); }

.cx-btn:active { transform: translateY(1px); }
.cx-btn:focus-visible, .cx-btn.is-focus {
  outline: none;
  box-shadow: 0 0 0 2px var(--cx-ring-gap), 0 0 0 4px var(--cx-ring);
}

.cx-btn--primary[disabled] { opacity: 0.5; cursor: not-allowed; transform: none; }
.cx-btn--secondary[disabled] { color: var(--cx-sec-disabled); border-color: var(--cx-border); background: var(--cx-sec-bg); cursor: not-allowed; transform: none; }
.cx-btn[aria-busy='true'] { cursor: progress; }

.cx-btn__ic { width: var(--ic); height: var(--ic); flex: none; }
.cx-btn__arrow { transition: transform 0.18s ease; }
.cx-btn:not([disabled]):hover .cx-btn__arrow, .cx-btn.is-hover .cx-btn__arrow { transform: translateX(2px); }

.cx-spinner {
  width: var(--ic, 16px);
  height: var(--ic, 16px);
  flex: none;
  border-radius: 50%;
  border: 2px solid currentColor;
  border-color: rgba(255, 255, 255, 0.25);
  border-top-color: currentColor;
  animation: cx-spin 0.8s linear infinite;
}

.cx-btn--secondary .cx-spinner { border-color: var(--cx-border); border-top-color: currentColor; }

/* Quota card */
.cx-quota__figure {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 12px;
}

.cx-quota__pct {
  font-size: 40px;
  font-weight: 600;
  line-height: 1;
  color: var(--cx-heading);
  font-variant-numeric: tabular-nums;
}

.cx-meter {
  height: 8px;
  border-radius: 999px;
  background: var(--cx-track);
  overflow: hidden;
  margin-bottom: 16px;
}

.cx-meter__fill {
  height: 100%;
  border-radius: inherit;
  background: var(--cx-fill);
  transform-origin: left;
  animation: cx-grow 0.9s cubic-bezier(0.16, 1, 0.3, 1) both;
}

.cx-meter__fill--warn { background: var(--cx-warn-fill); }

.cx-quota__rows { display: grid; gap: 8px; border-top: 1px solid var(--cx-border); padding-top: 14px; }

.cx-quota__row {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  color: var(--cx-body);
  font-variant-numeric: tabular-nums;
}

.cx-quota__row strong { color: var(--cx-heading); font-weight: 600; }

/* Empty + error blocks */
.cx-state {
  display: grid;
  justify-items: start;
  gap: 8px;
  padding: 8px 0 4px;
}

.cx-state__icon {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--cx-info-bg);
  color: var(--cx-primary);
  margin-bottom: 4px;
}

.cx-state__icon--err { background: var(--cx-err-bg); color: var(--cx-err-text); }
.cx-state .cx-btn { margin-top: 8px; }

/* Skeleton */
.cx-skel {
  display: block;
  height: 12px;
  border-radius: 4px;
  background: linear-gradient(90deg, var(--cx-skeleton) 0%, var(--cx-skeleton-hi) 50%, var(--cx-skeleton) 100%);
  background-size: 200% 100%;
  animation: cx-shimmer 1.3s linear infinite;
}

/* VPC table */
.cx-table-wrap { padding: 0; overflow: hidden; }
.cx-table-wrap .cx-card__head { padding: 20px 20px 0; }

.cx-table { width: 100%; border-collapse: collapse; font-size: 13px; }

.cx-table th {
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  color: var(--cx-muted);
  padding: 10px 20px;
  border-bottom: 1px solid var(--cx-border);
  background: var(--cx-bg);
}

.cx-table td {
  padding: 12px 20px;
  border-bottom: 1px solid var(--cx-border);
  color: var(--cx-body);
  font-variant-numeric: tabular-nums;
}

.cx-table tr:last-child td { border-bottom: 0; }
.cx-table tbody tr { transition: background-color 0.15s ease; }
.cx-table tbody tr:hover { background: var(--cx-row-hover); }
.cx-table td:first-child { color: var(--cx-heading); font-weight: 600; }

.cx-mono { font-family: 'DM Mono', var(--font-mono); font-size: 12px; }

.cx-banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 16px 20px 0;
  padding: 10px 14px;
  border-radius: 6px;
  background: var(--cx-warn-bg);
  color: var(--cx-warn-text);
  font-size: 13px;
  font-weight: 500;
}


.cx-table-wrap .cx-state { padding: 20px; }

/* Narrow container: table rows become stacked records */
@container cx (max-width: 480px) {
  .cx-table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .cx-table, .cx-table tbody, .cx-table tr, .cx-table td { display: block; }
  .cx-table tr { padding: 12px 20px; border-bottom: 1px solid var(--cx-border); }
  .cx-table tr:last-child { border-bottom: 0; }
  .cx-table td { padding: 3px 0; border: 0; display: flex; justify-content: space-between; gap: 12px; }
  .cx-table td::before { content: attr(data-label); font-family: 'Montserrat', Arial, sans-serif; font-size: 12px; font-weight: 600; color: var(--cx-muted); }
  .cx-table td:first-child { font-size: 14px; margin-bottom: 4px; }
  .cx-table td:first-child::before { content: none; }
  .cx-quota__pct { font-size: 34px; }
}

/* Button set */
.cx-btnset { display: grid; gap: 18px; }
.cx-btnset__row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.cx-sizerow { display: grid; grid-template-columns: 36px 1fr 1fr; gap: 12px; align-items: center; }
.cx-sizerow__label { font-size: 11px; font-weight: 600; color: var(--cx-muted); }
.cx-sizerow__pair { display: flex; gap: 8px; align-items: center; }
.cx-sizerow--head { font-size: 11px; font-weight: 600; color: var(--cx-muted); letter-spacing: 0.02em; padding-bottom: 6px; border-bottom: 1px solid var(--cx-border); }
@container cx (max-width: 560px) {
  .cx-sizerow { grid-template-columns: minmax(0, 1fr); row-gap: 8px; }
  .cx-sizerow__pair { flex-wrap: wrap; }
  .cx-sizerow--head { display: none; }
}
.cx-btnset__label { font-size: 11px; font-weight: 600; color: var(--cx-muted); letter-spacing: 0.02em; margin-bottom: -8px; }

/* ---------- Inspect mode: show the token behind each part ---------- */
.cx-canvas[data-inspect='true'] [data-tok] {
  position: relative;
  outline: 1px dashed rgba(244, 114, 182, 0.9);
  outline-offset: 2px;
}

.cx-canvas[data-inspect='true'] [data-tok]::after {
  content: attr(data-tok);
  position: absolute;
  top: -9px;
  left: 0;
  z-index: 2;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.02em;
  line-height: 1;
  white-space: nowrap;
  padding: 3px 5px;
  border-radius: 2px;
  background: #F472B6;
  color: #09090B;
  pointer-events: none;
}

.cx-canvas[data-inspect='true'] td[data-tok]::after { top: 2px; }
.cx-canvas[data-inspect='true'] .cx-btn[data-tok]::after { top: -18px; }

/* Swap-in animation when the specimen re-renders */
.cx-specimen { animation: cx-in 0.35s cubic-bezier(0.16, 1, 0.3, 1) both; }

@keyframes cx-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes cx-grow { from { transform: scaleX(0); } to { transform: scaleX(1); } }
@keyframes cx-shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
@keyframes cx-spin { to { transform: rotate(360deg); } }
@keyframes cx-pulse { 50% { opacity: 0.3; } }

@media (prefers-reduced-motion: reduce) {
  .cx-specimen, .cx-meter__fill, .cx-skel, .cx-spinner, .cx-badge--pending::before { animation: none; }
  .cx-canvas { transition: none; }
}

/* ---------- Gallery slots that hide until an image exists ---------- */
.cx-gallery { display: grid; gap: var(--space-md); }
.cx-gallery figure[hidden] { display: none; }

/* Token strip in the system section */
.cx-tokens {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 92px), 1fr));
  gap: 6px;
}

.cx-token {
  display: grid;
  gap: 6px;
  font-family: var(--font-mono);
  font-size: var(--font-size-2xs);
  color: var(--color-text-muted);
}

.cx-token__swatch {
  height: 44px;
  border-radius: 3px;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.cx-token strong { color: var(--color-text-primary); font-weight: 500; }

/* Scale rows with live contrast labels */
.cx-scales { display: grid; gap: var(--space-sm); }
.cx-scale { display: grid; gap: 6px; }
.cx-scale__name { font-family: var(--font-mono); font-size: var(--font-size-2xs); letter-spacing: var(--letter-spacing-mono); color: var(--color-text-muted); text-transform: uppercase; }
.cx-scale__row { display: grid; grid-template-columns: repeat(9, minmax(0, 1fr)); gap: 3px; }
.cx-sw { display: grid; align-content: space-between; min-height: 58px; padding: 6px; border-radius: 3px; font-family: var(--font-mono); font-size: 10px; line-height: 1.3; }
.cx-sw b { font-weight: 500; }
@media (max-width: 560px) { .cx-sw { min-height: 46px; padding: 4px; font-size: 9px; } .cx-sw span { display: none; } }
