/* ---------------------------------------------------------------------------
   components.html — the component gallery.

   The page is a browse-then-drill-down surface: a filterable grid of preview
   tiles (one per component, live-rendered), and a detail drawer that carries
   everything a reference page normally shows — signature, prop table, a full
   preview and the source behind it.

   Everything here is scoped to `body[data-page="components"]` so the shared
   docs shell in site.css is untouched.
   --------------------------------------------------------------------------- */

body[data-page="components"] main {
  /* The grid manages its own rhythm; the shared prose max-width would squeeze
     it to a single column. */
  max-width: none;
}

/* --------------------------------------------------------------------------
   1. Hero + at-a-glance counts
   -------------------------------------------------------------------------- */

.cx-hero-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 4px;
}

.cx-hero-stat {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  font-size: 12.5px;
  color: var(--doc-text-muted);
  background: var(--doc-surface);
  border: 1px solid var(--doc-border);
  border-radius: var(--doc-radius-pill);
  padding: 4px 12px;
}
.cx-hero-stat b {
  font-size: 13px;
  color: var(--doc-text);
}

/* --------------------------------------------------------------------------
   2. Sticky toolbar — search + category filter
   -------------------------------------------------------------------------- */

.cx-toolbar {
  position: sticky;
  top: var(--doc-topbar-h);
  z-index: 30;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 14px 0 12px;
  margin-bottom: 18px;
  background: var(--doc-bg);
  border-bottom: 1px solid var(--doc-border);
}
/* A soft fade under the sticky bar so tiles scrolling beneath it don't appear
   to collide with the chips. */
.cx-toolbar::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 100%;
  height: 16px;
  background: linear-gradient(to bottom, var(--doc-bg), transparent);
  pointer-events: none;
}

.cx-search {
  position: relative;
  display: flex;
  align-items: center;
}

.cx-search-icon {
  position: absolute;
  left: 14px;
  width: 16px;
  height: 16px;
  color: var(--doc-text-subtle);
  pointer-events: none;
}

.cx-search input {
  width: 100%;
  font-family: inherit;
  font-size: 14.5px;
  color: var(--doc-text);
  background: var(--doc-surface);
  border: 1px solid var(--doc-border);
  border-radius: var(--doc-radius-lg);
  padding: 11px 108px 11px 40px;
  transition: border-color var(--doc-transition), box-shadow var(--doc-transition);
}
.cx-search input::placeholder { color: var(--doc-text-subtle); }
.cx-search input:focus {
  outline: none;
  border-color: var(--doc-primary);
  box-shadow: var(--doc-focus-ring);
}

.cx-search-hint {
  position: absolute;
  right: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
  pointer-events: none;
}
.cx-search-hint kbd {
  font-family: var(--doc-mono);
  font-size: 11px;
  color: var(--doc-text-subtle);
  background: var(--doc-bg-soft);
  border: 1px solid var(--doc-border);
  border-bottom-width: 2px;
  border-radius: var(--doc-radius-xs);
  padding: 1px 6px;
}
.cx-search-clear {
  pointer-events: auto;
  display: none;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border: none;
  border-radius: 50%;
  background: var(--doc-bg-soft);
  color: var(--doc-text-muted);
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
}
.cx-search-clear:hover { color: var(--doc-text); background: var(--doc-border); }
.cx-search[data-filled="true"] .cx-search-clear { display: inline-flex; }
.cx-search[data-filled="true"] .cx-search-hint kbd { display: none; }

.cx-chips {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 2px;
  scrollbar-width: thin;
  scrollbar-color: var(--doc-border-strong) transparent;
}
.cx-chips::-webkit-scrollbar { height: 5px; }
.cx-chips::-webkit-scrollbar-thumb { background: var(--doc-border-strong); border-radius: 3px; }

.cx-chip {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 500;
  white-space: nowrap;
  color: var(--doc-text-muted);
  background: var(--doc-surface);
  border: 1px solid var(--doc-border);
  border-radius: var(--doc-radius-pill);
  padding: 5px 13px;
  cursor: pointer;
  transition: color var(--doc-transition), background var(--doc-transition),
    border-color var(--doc-transition);
}
.cx-chip:hover { color: var(--doc-text); border-color: var(--doc-border-strong); }
.cx-chip:focus-visible { outline: none; box-shadow: var(--doc-focus-ring); }
.cx-chip[aria-pressed="true"] {
  color: var(--doc-primary);
  background: var(--doc-primary-soft);
  border-color: transparent;
  font-weight: 600;
}
.cx-chip-count {
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  color: var(--doc-text-subtle);
}
.cx-chip[aria-pressed="true"] .cx-chip-count { color: var(--doc-primary); }

/* --------------------------------------------------------------------------
   3. Result meta line
   -------------------------------------------------------------------------- */

.cx-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 8px;
  font-size: 13px;
  color: var(--doc-text-muted);
  margin: 0 0 14px;
}
.cx-meta b { color: var(--doc-text); font-variant-numeric: tabular-nums; }
.cx-meta-blurb {
  color: var(--doc-text-subtle);
  border-left: 1px solid var(--doc-border);
  padding-left: 8px;
}

/* --------------------------------------------------------------------------
   4. The grid of preview tiles
   -------------------------------------------------------------------------- */

.cx-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(268px, 1fr));
  gap: 16px;
  align-items: stretch;
}

.cx-group-label {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 16px 0 -4px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--doc-text-subtle);
}
.cx-group-label:first-child { margin-top: 0; }
.cx-group-label::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--doc-border);
}

.cx-card {
  display: flex;
  flex-direction: column;
  text-align: left;
  font-family: inherit;
  padding: 0;
  overflow: hidden;
  background: var(--doc-surface);
  border: 1px solid var(--doc-border);
  border-radius: var(--doc-radius-lg);
  box-shadow: var(--doc-shadow-sm);
  cursor: pointer;
  transition: border-color var(--doc-transition), box-shadow var(--doc-transition),
    transform var(--doc-transition);
}
.cx-card:hover {
  border-color: rgba(99, 102, 241, 0.42);
  box-shadow: var(--doc-shadow-lg);
  transform: translateY(-2px);
}
.cx-card:focus-visible { outline: none; box-shadow: var(--doc-focus-ring); }

/* The tile preview is a real, running program — shrunk to thumbnail scale and
   clipped. `pointer-events: none` keeps every click on the card itself, so an
   interactive sample can never swallow the tap that opens the detail. */
.cx-card-preview {
  position: relative;
  height: 158px;
  overflow: hidden;
  background: var(--doc-bg-soft);
  border-bottom: 1px solid var(--doc-border-subtle);
}
.cx-card-preview-inner {
  position: absolute;
  inset: 0;
  padding: 12px;
  transform: scale(0.74);
  transform-origin: top left;
  width: 135.1%;   /* 1 / 0.74 — so the scaled content still fills the tile */
  height: 135.1%;
  pointer-events: none;
}
.cx-card-preview aktion-app { display: block; }

.cx-card-preview-empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  color: var(--doc-text-subtle);
}

/* Fade the bottom of a tall preview so a clipped sample reads as "there is
   more", not as a rendering bug. */
.cx-card-preview::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 34px;
  background: linear-gradient(to bottom, transparent, var(--doc-bg-soft));
  pointer-events: none;
}

.cx-card-body {
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 12px 14px 14px;
  flex: 1;
}

.cx-card-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--doc-mono);
  font-size: 13.5px;
  font-weight: 600;
  color: var(--doc-text);
}
.cx-card-title mark {
  background: rgba(99, 102, 241, 0.22);
  color: inherit;
  border-radius: 3px;
  padding: 0 1px;
}

.cx-card-group {
  margin-left: auto;
  font-family: var(--doc-font);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.03em;
  color: var(--doc-text-subtle);
  background: var(--doc-bg-soft);
  border-radius: var(--doc-radius-pill);
  padding: 2px 8px;
  white-space: nowrap;
}

.cx-card-summary {
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--doc-text-muted);
}

.cx-empty {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 64px 24px;
  text-align: center;
  color: var(--doc-text-muted);
  background: var(--doc-surface);
  border: 1px dashed var(--doc-border-strong);
  border-radius: var(--doc-radius-lg);
}
.cx-empty b { color: var(--doc-text); font-size: 15px; }

.cx-loading {
  padding: 48px;
  text-align: center;
  font-size: 13px;
  color: var(--doc-text-muted);
  background: var(--doc-surface);
  border: 1px dashed var(--doc-border);
  border-radius: var(--doc-radius-lg);
}

/* --------------------------------------------------------------------------
   5. Detail drawer
   -------------------------------------------------------------------------- */

.cx-detail[hidden] { display: none; }

.cx-detail {
  position: fixed;
  inset: 0;
  z-index: 120;
}

.cx-detail-scrim {
  position: absolute;
  inset: 0;
  background: rgba(9, 9, 11, 0.42);
  backdrop-filter: blur(2px);
  animation: cx-fade 180ms ease;
}

.cx-detail-panel {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(920px, 96vw);
  display: flex;
  flex-direction: column;
  background: var(--doc-bg);
  border-left: 1px solid var(--doc-border);
  box-shadow: -24px 0 60px rgba(15, 23, 42, 0.18);
  animation: cx-slide-in 240ms cubic-bezier(0.32, 0.72, 0, 1);
}

@keyframes cx-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes cx-slide-in {
  from { transform: translateX(24px); opacity: 0; }
  to   { transform: translateX(0);    opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
  .cx-detail-panel, .cx-detail-scrim { animation: none; }
  .cx-card:hover { transform: none; }
}

.cx-detail-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 20px 14px;
  border-bottom: 1px solid var(--doc-border);
  background: var(--doc-surface);
}

.cx-detail-title {
  margin: 0;
  font-family: var(--doc-mono);
  font-size: 19px;
  font-weight: 700;
  color: var(--doc-text);
}

.cx-detail-group {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--doc-primary);
  background: var(--doc-primary-soft);
  border-radius: var(--doc-radius-pill);
  padding: 3px 10px;
}

.cx-detail-nav {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 4px;
}

.cx-iconbtn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border: 1px solid var(--doc-border);
  border-radius: var(--doc-radius-sm);
  background: var(--doc-surface);
  color: var(--doc-text-muted);
  cursor: pointer;
  transition: color var(--doc-transition), background var(--doc-transition),
    border-color var(--doc-transition);
}
.cx-iconbtn:hover:not(:disabled) {
  color: var(--doc-text);
  background: var(--doc-bg-soft);
  border-color: var(--doc-border-strong);
}
.cx-iconbtn:disabled { opacity: 0.35; cursor: default; }
.cx-iconbtn:focus-visible { outline: none; box-shadow: var(--doc-focus-ring); }
.cx-iconbtn svg { width: 15px; height: 15px; }

.cx-detail-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  scrollbar-width: thin;
  scrollbar-color: var(--doc-border-strong) transparent;
}
.cx-detail-body::-webkit-scrollbar { width: 8px; }
.cx-detail-body::-webkit-scrollbar-thumb { background: var(--doc-border-strong); border-radius: 4px; }

.cx-detail-summary {
  margin: 0 0 10px;
  font-size: 16px;
  line-height: 1.55;
  color: var(--doc-text);
}

.cx-detail-description {
  margin: 0 0 16px;
  font-size: 13.5px;
  line-height: 1.65;
  color: var(--doc-text-muted);
}
.cx-detail-description code {
  font-family: var(--doc-mono);
  font-size: 12.5px;
  background: var(--doc-code-bg-soft);
  color: var(--doc-code-fg-soft);
  border-radius: var(--doc-radius-xs);
  padding: 1px 5px;
}

.cx-detail-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin: 0 0 18px;
}
.cx-tag {
  font-size: 11.5px;
  color: var(--doc-text-muted);
  background: var(--doc-bg-soft);
  border: 1px solid var(--doc-border-subtle);
  border-radius: var(--doc-radius-pill);
  padding: 2px 9px;
}

.cx-section-title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 22px 0 8px;
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--doc-text-subtle);
}
.cx-section-title:first-child { margin-top: 0; }

.cx-signature {
  font-family: var(--doc-mono);
  font-size: 12.5px;
  line-height: 1.6;
  background: linear-gradient(180deg, #0b1020 0%, #0f172a 100%);
  color: #e2e8f0;
  padding: 12px 14px;
  border-radius: var(--doc-radius-md);
  border: 1px solid rgba(255, 255, 255, 0.05);
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0;
}
/* The signature surface keeps its dark gradient in both themes, so the global
   selection colours would leave highlighted text invisible in dark mode. */
.cx-signature ::selection,
.cx-signature::selection {
  background: rgba(99, 102, 241, 0.45);
  color: #f8fafc;
}
.cx-signature .cx-sig-name { color: #a5b4fc; font-weight: 600; }
.cx-signature .cx-sig-prop { color: #f8fafc; }
.cx-signature .cx-sig-type { color: #7dd3fc; }
.cx-signature .cx-sig-enum { color: #fca5a5; }
.cx-signature .cx-sig-punct { color: #64748b; }

/* Preview / source tabs inside the drawer */
.cx-tabs {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  background: var(--doc-bg-soft);
  border: 1px solid var(--doc-border);
  border-radius: var(--doc-radius-sm);
  margin-bottom: 10px;
}
.cx-tab {
  border: none;
  background: none;
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--doc-text-muted);
  padding: 5px 14px;
  border-radius: var(--doc-radius-xs);
  cursor: pointer;
  transition: background var(--doc-transition), color var(--doc-transition);
}
.cx-tab:hover { color: var(--doc-text); }
.cx-tab[aria-selected="true"] {
  color: var(--doc-text);
  background: var(--doc-surface);
  box-shadow: var(--doc-shadow-sm);
  font-weight: 600;
}
.cx-tab:focus-visible { outline: none; box-shadow: var(--doc-focus-ring); }

.cx-panel { display: none; }
.cx-panel[data-active="true"] { display: block; animation: doc-fade-in 200ms ease; }

.cx-preview-stage {
  padding: 16px;
  background: var(--doc-surface);
  border: 1px solid var(--doc-border);
  border-radius: var(--doc-radius-md);
  min-height: 120px;
}
/* Samples that open a fixed-position overlay (Modal, Sheet, Toasts…) need a
   containing block of their own, or the overlay escapes to the viewport. */
.cx-preview-stage[data-overlay="true"] {
  transform: translate(0);
  min-height: 340px;
}
.cx-preview-stage aktion-app { display: block; }

.cx-code {
  position: relative;
}
.cx-code pre {
  margin: 0;
  max-height: 460px;
  overflow: auto;
}
.cx-code-actions {
  position: absolute;
  top: 8px;
  right: 8px;
  display: flex;
  gap: 6px;
}
.cx-code-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: inherit;
  font-size: 11.5px;
  font-weight: 600;
  color: #cbd5e1;
  background: rgba(148, 163, 184, 0.16);
  border: 1px solid rgba(148, 163, 184, 0.24);
  border-radius: var(--doc-radius-xs);
  padding: 4px 9px;
  cursor: pointer;
  transition: background var(--doc-transition), color var(--doc-transition);
}
.cx-code-btn:hover { background: rgba(148, 163, 184, 0.28); color: #f8fafc; }
.cx-code-btn:focus-visible { outline: none; box-shadow: var(--doc-focus-ring); }

/* Prop table */
.cx-props {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.cx-props th,
.cx-props td {
  padding: 9px 10px;
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid var(--doc-border);
}
.cx-props th {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--doc-text-subtle);
  background: var(--doc-primary-softer);
  white-space: nowrap;
}
.cx-props tr:last-child td { border-bottom: none; }
.cx-props td:first-child { white-space: nowrap; }

.cx-prop-name {
  font-family: var(--doc-mono);
  font-weight: 600;
  color: var(--doc-text);
}
.cx-prop-req {
  display: inline-block;
  margin-left: 5px;
  font-family: var(--doc-font);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--doc-danger);
}
.cx-prop-slot {
  display: inline-block;
  margin-left: 5px;
  font-family: var(--doc-font);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--doc-primary);
}
.cx-prop-type {
  font-family: var(--doc-mono);
  font-size: 12px;
  color: var(--doc-primary-hover);
  background: var(--doc-primary-soft);
  border-radius: var(--doc-radius-xs);
  padding: 1px 7px;
  display: inline-block;
}
.cx-prop-enums {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 5px;
}
.cx-prop-enum {
  font-family: var(--doc-mono);
  font-size: 11px;
  color: var(--doc-primary-hover);
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.10), rgba(236, 72, 153, 0.08));
  border: 1px solid rgba(99, 102, 241, 0.20);
  border-radius: var(--doc-radius-pill);
  padding: 1px 8px;
}
.cx-prop-desc {
  color: var(--doc-text-muted);
  font-size: 12.5px;
  line-height: 1.55;
}
.cx-prop-desc code {
  font-family: var(--doc-mono);
  font-size: 11.5px;
  background: var(--doc-code-bg-soft);
  color: var(--doc-code-fg-soft);
  border-radius: 4px;
  padding: 0 4px;
}
.cx-no-props {
  font-size: 13px;
  color: var(--doc-text-muted);
  background: var(--doc-bg-soft);
  border: 1px dashed var(--doc-border);
  border-radius: var(--doc-radius-md);
  padding: 14px;
  margin: 0;
}

.cx-detail-foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  padding: 12px 20px;
  border-top: 1px solid var(--doc-border);
  background: var(--doc-surface);
  font-size: 12.5px;
  color: var(--doc-text-muted);
}
.cx-detail-foot .cx-detail-hint { margin-left: auto; }
.cx-detail-foot kbd {
  font-family: var(--doc-mono);
  font-size: 11px;
  background: var(--doc-bg-soft);
  border: 1px solid var(--doc-border);
  border-bottom-width: 2px;
  border-radius: var(--doc-radius-xs);
  padding: 1px 6px;
}

.cx-linkbtn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--doc-primary);
  background: var(--doc-primary-soft);
  border: 1px solid transparent;
  border-radius: var(--doc-radius-sm);
  padding: 5px 12px;
  cursor: pointer;
  font-family: inherit;
  transition: background var(--doc-transition);
}
.cx-linkbtn:hover { background: rgba(99, 102, 241, 0.18); }
.cx-linkbtn:focus-visible { outline: none; box-shadow: var(--doc-focus-ring); }

body.cx-detail-open { overflow: hidden; }

/* --------------------------------------------------------------------------
   6. Responsive
   -------------------------------------------------------------------------- */

@media (max-width: 900px) {
  .cx-detail-panel { width: 100vw; border-left: none; }
  .cx-grid { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; }
}

@media (max-width: 720px) {
  .cx-toolbar { top: 0; }
  .cx-search input { padding-right: 44px; }
  .cx-search-hint kbd { display: none; }
  .cx-card-preview { height: 132px; }
  .cx-detail-body { padding: 16px; }
}
