/* ═══════════════════════════════════════════════════════════════════════════
   css/component-library.css  —  Component Library Viewer
   Bergantung pada token.css yang harus dimuat lebih dulu.
   ═══════════════════════════════════════════════════════════════════════════ */

/* ── Reset minimal ────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: var(--font-body, system-ui, sans-serif);
  background: #fff;
  color: #0d0d0d;
  -webkit-font-smoothing: antialiased;
}

/* ── Layout shell ─────────────────────────────────────────────────────────── */

.cl-layout {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

.cl-main-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

/* ── Sidebar ──────────────────────────────────────────────────────────────── */

.cl-sidebar {
  width: 210px;
  flex-shrink: 0;
  border-right: 1px solid #f4f4f5;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 1.5rem 0 2rem;
  transition: width 220ms cubic-bezier(0.4, 0, 0.2, 1),
              border-color 220ms ease;
}

.cl-sidebar.cl-sidebar--hidden {
  width: 0;
  border-right-color: transparent;
}

.cl-sidebar-label {
  display: block;
  font-family: var(--font-sans, system-ui, sans-serif);
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #a1a1aa;
  padding: 0 1.25rem;
  margin: 0.75rem 0 0.5rem;
}

.cl-nav-item {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0.3rem 1.25rem;
  font-family: var(--font-sans, system-ui, sans-serif);
  font-size: 0.875rem;
  color: #52525b;
  text-decoration: none;
  transition: background-color 120ms ease, color 120ms ease;
  user-select: none;
}

.cl-nav-item:hover,
.cl-nav-item.is-active {
  background-color: #f4f4f5;
  color: #18181b;
  text-decoration: none;
}

.cl-nav-item.is-active { font-weight: 500; }

.cl-nav-icon {
  width: 14px;
  height: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: #a1a1aa;
  transition: color 120ms ease;
}

.cl-nav-item:hover .cl-nav-icon,
.cl-nav-item.is-active .cl-nav-icon { color: #52525b; }

.cl-nav-icon svg { width: 14px; height: 14px; display: block; }

/* ── Nav group (level 1 row + level 2 list) ───────────────────────────────── */

.cl-nav-group { display: flex; flex-direction: column; }

.cl-nav-row {
  display: flex;
  align-items: center;
}

.cl-nav-row .cl-nav-item {
  flex: 1;
  min-width: 0;
}

/* Chevron toggle button */
.cl-nav-chevron {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: none;
  cursor: pointer;
  color: #c4c4c9;
  border-radius: var(--radius-sm, 0.375rem);
  padding: 0;
  margin-right: 0.375rem;
  transition: color 120ms ease, background-color 120ms ease;
}

.cl-nav-chevron:hover {
  color: #71717a;
  background-color: #f4f4f5;
}

.cl-nav-chevron svg {
  width: 12px;
  height: 12px;
  display: block;
  transition: transform 200ms cubic-bezier(0.4, 0, 0.2, 1);
}

.cl-nav-chevron.is-open svg {
  transform: rotate(180deg);
}

/* Level 2: sub-nav list */
.cl-subnav {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow: hidden;
  max-height: 0;
  /* opacity tambahan agar transisi lebih halus */
  opacity: 0;
  transition: max-height 220ms cubic-bezier(0.4, 0, 0.2, 1),
              opacity 180ms ease;
}

.cl-subnav.is-open {
  max-height: 1200px; /* nilai besar — JS tidak perlu hitung tinggi */
  opacity: 1;
  transition: max-height 280ms cubic-bezier(0.4, 0, 0.2, 1),
              opacity 200ms ease 40ms;
}

.cl-subnav li { margin: 0; padding: 0; }

.cl-subnav-item {
  display: block;
  padding: 0.225rem 1.25rem 0.225rem 2.875rem;
  font-family: var(--font-sans, system-ui, sans-serif);
  font-size: 0.8125rem;
  color: #71717a;
  text-decoration: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: background-color 120ms ease, color 120ms ease;
  user-select: none;
}

.cl-subnav-item:hover {
  background-color: #f4f4f5;
  color: #18181b;
  text-decoration: none;
}

.cl-subnav-item.is-active {
  color: #18181b;
  font-weight: 500;
  background-color: #f4f4f5;
}

/* Spacer tipis di bawah tiap group yang sedang open */
.cl-nav-group:has(.cl-subnav.is-open) { margin-bottom: 0.125rem; }

/* ── Toolbar / Search ─────────────────────────────────────────────────────── */

.cl-toolbar {
  position: relative;
  padding: 0.75rem 1.5rem;
  border-bottom: 1px solid #f4f4f5;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  background: #fff;
}

/* ── Sidebar Toggle Button ────────────────────────────────────────────────── */

.cl-sidebar-toggle {
  position: absolute;
  left: 1rem;
  top: 50%;
  transform: translateY(-50%);
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: none;
  cursor: pointer;
  color: #a1a1aa;
  border-radius: var(--radius-sm, 0.375rem);
  padding: 0;
  transition: color 120ms ease, background-color 120ms ease;
  flex-shrink: 0;
}

.cl-sidebar-toggle:hover {
  color: #52525b;
  background-color: #f4f4f5;
}

.cl-sidebar-toggle svg {
  width: 16px;
  height: 16px;
  display: block;
  transition: transform 220ms cubic-bezier(0.4, 0, 0.2, 1);
}

.cl-sidebar-toggle.is-collapsed svg {
  transform: scaleX(-1);
}

.cl-search-wrap {
  position: relative;
  width: 300px;
}

.cl-search-icon {
  position: absolute;
  left: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  width: 14px;
  height: 14px;
  color: #a1a1aa;
  pointer-events: none;
  display: flex;
  align-items: center;
}

.cl-search-icon svg { width: 14px; height: 14px; display: block; }

.cl-search-input {
  width: 100%;
  padding: 0.45rem 2.25rem;
  border: 1px solid #e4e4e7;
  border-radius: var(--radius-md, 0.75rem);
  font-family: var(--font-body, system-ui, sans-serif);
  font-size: 0.875rem;
  color: #18181b;
  background: #fff;
  outline: none;
  transition: border-color 150ms ease, box-shadow 150ms ease;
  -webkit-appearance: none;
  appearance: none;
}

.cl-search-input::placeholder { color: #a1a1aa; }

.cl-search-input:focus {
  border-color: #d4d4d8;
  box-shadow: 0 0 0 3px rgb(161 161 170 / 0.12);
}

.cl-search-input::-webkit-search-cancel-button { display: none; }

.cl-search-clear {
  position: absolute;
  right: 0.6rem;
  top: 50%;
  transform: translateY(-50%);
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: none;
  cursor: pointer;
  color: #a1a1aa;
  padding: 0;
  border-radius: 50%;
  transition: color 120ms ease, background-color 120ms ease;
}

.cl-search-clear:hover { color: #52525b; background-color: #f4f4f5; }
.cl-search-clear svg { width: 12px; height: 12px; display: block; }

/* ── Main Content ─────────────────────────────────────────────────────────── */

.cl-content {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem 1.5rem 4rem;
  scroll-behavior: smooth;
}

/* ── Content Group Label ──────────────────────────────────────────────────── */

.cl-content-group-label {
  font-family: var(--font-sans, system-ui, sans-serif);
  font-size: 1.6875rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #a1a1aa;
  margin: 4rem 0 1rem;
  padding: 0 0.125rem;
}

.cl-content-group-label:first-child {
  margin-top: 0;
}

/* ── Section ──────────────────────────────────────────────────────────────── */

.cl-section {
  margin-bottom: 2.5rem;
  scroll-margin-top: 1rem;
}

.cl-section-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 0.875rem;
  padding: 0 0.125rem;
}

.cl-section-title {
  font-family: var(--font-sans, system-ui, sans-serif);
  font-size: 1.0625rem;
  font-weight: 600;
  color: #18181b;
  letter-spacing: -0.01em;
  line-height: 1.3;
  margin: 1rem 0 0.25rem;
}

.cl-section-desc {
  font-size: 0.875rem;
  color: #a1a1aa;
  margin: 0.15rem 0 0;
  line-height: 1.4;
}

.cl-section-count {
  font-family: var(--font-sans, system-ui, sans-serif);
  font-size: 0.875rem;
  color: #a1a1aa;
  padding-top: 0.15rem;
  flex-shrink: 0;
}

/* ── Cards Grid ───────────────────────────────────────────────────────────── */

.cl-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  /* Teknik gap+background: container berwarna #e4e4e7, card berwarna putih.
     Gap 1px + padding 1px menciptakan "border" yang tidak terpengaruh
     oleh display:none saat filter — tidak perlu nth-child sama sekali. */
  gap: 1px;
  padding: 1px;
  background-color: #f3f4f5;
  border-radius: var(--radius-md, 0.75rem);
  overflow: hidden;
}

a.cl-card {
  text-decoration: none;
  color: inherit;
  display: block;
}

.cl-card {
  background-color: #ffffff;
  padding: 1.125rem 1.25rem;
  transition: background-color 100ms ease, box-shadow 100ms ease;
  cursor: pointer;
  min-height: 96px;
}

.cl-card:hover {
  background-color: #fafafa;
  box-shadow: inset 0 0 0 1.5px #e4e4e7;
}

.cl-card-name {
  font-family: var(--font-sans, system-ui, sans-serif);
  font-size: 0.875rem;
  font-weight: 500;
  color: #18181b;
  margin: 0 0 0.3rem;
  line-height: 1.3;
}

.cl-card-desc {
  font-size: 0.8125rem;
  color: #a1a1aa;
  line-height: 1.5;
  margin: 0;
}

.cl-card-plugin {
  margin-top: 0.625rem;
  font-family: var(--font-mono, monospace);
  font-size: 0.6875rem;
  color: #c4c4c4;
  line-height: 1;
}

.cl-card-placeholder {
  background-color: #f4f4f5;
  pointer-events: none;
}

/* ── Empty state ──────────────────────────────────────────────────────────── */

.cl-empty {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 5rem 2rem;
  text-align: center;
}

.cl-empty.is-visible { display: flex; }

.cl-empty-icon { width: 40px; height: 40px; color: #d4d4d8; margin-bottom: 1rem; }

.cl-empty-title {
  font-family: var(--font-sans, system-ui, sans-serif);
  font-size: 0.875rem;
  font-weight: 500;
  color: #52525b;
  margin: 0 0 0.25rem;
}

.cl-empty-sub {
  font-size: 0.8125rem;
  color: #a1a1aa;
  margin: 0;
}

/* ── Sidebar Footer (expand-all / collapse-all) ───────────────────────────── */

.cl-sidebar-footer {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
  padding: 0.625rem 0.75rem;
  margin-top: 0.5rem;
  border-top: 1px solid #f4f4f5;
  position: sticky;
  bottom: 0;
  background: #fff;
}

.cl-sidebar-footer-btn {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: none;
  cursor: pointer;
  color: #c4c4c9;
  border-radius: var(--radius-sm, 0.375rem);
  padding: 0;
  transition: color 120ms ease, background-color 120ms ease;
}

.cl-sidebar-footer-btn:hover {
  color: #52525b;
  background-color: #f4f4f5;
}

.cl-sidebar-footer-btn svg {
  width: 14px;
  height: 14px;
  display: block;
}

/* ── Sidebar Resize Handle ────────────────────────────────────────────────── */

.cl-sidebar-resizer {
  flex-shrink: 0;
  width: 5px;
  margin-left: -1px;          /* overlap the sidebar's right border */
  cursor: col-resize;
  position: relative;
  background: transparent;
  transition: background-color 150ms ease;
  z-index: 5;
}

/* Extended hit-area without widening the visible element */
.cl-sidebar-resizer::before {
  content: '';
  position: absolute;
  inset: 0 -4px;
}

/* Grip dots visible on hover / drag */
.cl-sidebar-resizer::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 2px;
  height: 24px;
  background-image: radial-gradient(circle, #b1b1ba 1px, transparent 1px);
  background-size: 2px 6px;
  background-repeat: repeat-y;
  opacity: 0;
  transition: opacity 150ms ease;
}

.cl-sidebar-resizer:hover {
  background-color: #e9e9ed;
}

.cl-sidebar-resizer:hover::after,
.cl-sidebar-resizer.is-dragging::after {
  opacity: 1;
}

.cl-sidebar-resizer.is-dragging {
  background-color: #d4d4d8;
}

/* Hide resizer when sidebar is collapsed */
.cl-sidebar.cl-sidebar--hidden ~ .cl-sidebar-resizer {
  opacity: 0;
  pointer-events: none;
}

/* ── Scrollbar ────────────────────────────────────────────────────────────── */

.cl-sidebar::-webkit-scrollbar,
.cl-content::-webkit-scrollbar  { width: 4px; }

.cl-sidebar::-webkit-scrollbar-track,
.cl-content::-webkit-scrollbar-track { background: transparent; }

.cl-sidebar::-webkit-scrollbar-thumb,
.cl-content::-webkit-scrollbar-thumb { background: #e4e4e7; border-radius: 9999px; }

/* ═══════════════════════════════════════════════════════════════════════════
   AJAX Navigation — loading states & content transitions
   ═══════════════════════════════════════════════════════════════════════════ */

/* ── Content loading indicator ────────────────────────────────────────────── */

/**
 * Thin progress bar at the top of cl-content during AJAX navigation.
 * Purely CSS — Alpine.js toggles the class, no JS animation loop needed.
 */
#cl-content-inner {
  /* Isolate stacking context so the progress bar sits above content */
  position: relative;
  min-height: 100%;
}

.cl-loading-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  z-index: 100;
  pointer-events: none;
  overflow: hidden;
  opacity: 0;
  transition: opacity 120ms ease;
}

.cl-loading-bar.is-loading {
  opacity: 1;
}

.cl-loading-bar::after {
  content: '';
  position: absolute;
  top: 0;
  left: -60%;
  width: 60%;
  height: 100%;
  background: linear-gradient(90deg, transparent, #18181b 50%, transparent);
  animation: cl-bar-slide 800ms ease-in-out infinite;
}

@keyframes cl-bar-slide {
  0%   { left: -60%; }
  100% { left: 110%; }
}

/* ── Content fade transition ──────────────────────────────────────────────── */

/**
 * Why not CSS transition on cl-content?
 * cl-content is the scroll container — animating it would cause layout shift.
 * We animate cl-content-inner (the inner wrapper) instead.
 */
#cl-content-inner {
  transition: opacity 160ms ease;
}

#cl-content-inner.is-transitioning {
  opacity: 0;
  pointer-events: none;
}

/* ── Breadcrumb bar ───────────────────────────────────────────────────────── */

/**
 * The breadcrumb nav already exists inside layout-header.php via .sc-breadcrumb.
 * On AJAX navigation, we inject breadcrumb into #cl-breadcrumb which sits
 * between the toolbar and the scrollable cl-content.
 *
 * Custom CSS here only because:
 * 1. The breadcrumb container needs a fixed height (no layout shift)
 * 2. It needs border-bottom separator consistent with toolbar
 */
#cl-breadcrumb-bar {
  flex-shrink: 0;
  height: 0;
  overflow: hidden;
  border-bottom: 1px solid transparent;
  transition: height 200ms ease, border-color 200ms ease;
  background: #fff;
}

#cl-breadcrumb-bar.is-visible {
  height: 38px;
  border-bottom-color: #f4f4f5;
}

#cl-breadcrumb-bar .sc-breadcrumb {
  /* Reset margin from sc-breadcrumb default (applied inside component pages) */
  margin: 0;
  padding: 0.625rem 1.5rem;
  line-height: 1;
}

/* ── Search bar visibility ────────────────────────────────────────────────── */

/**
 * Hide search when viewing a component page (search is only useful on home).
 * The toolbar container keeps its height so layout doesn't shift.
 * Transition handled by opacity+pointer-events (no height change).
 */
.cl-search-wrap {
  transition: opacity 160ms ease;
}

.cl-search-wrap.is-hidden {
  opacity: 0;
  pointer-events: none;
}

/* ── Subnav active state — updated by JS on AJAX nav ─────────────────────── */

/**
 * No new CSS needed — we reuse existing .is-active on .cl-subnav-item.
 * JS handles adding/removing the class after each navigation.
 */

/* ── Error state ──────────────────────────────────────────────────────────── */

.cl-ajax-error {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 5rem 2rem;
  text-align: center;
}

.cl-ajax-error-title {
  font-family: var(--font-sans, system-ui, sans-serif);
  font-size: 0.875rem;
  font-weight: 500;
  color: #52525b;
  margin: 0 0 0.5rem;
}

.cl-ajax-error-sub {
  font-size: 0.8125rem;
  color: #a1a1aa;
  margin: 0 0 1rem;
}

.cl-ajax-error-retry {
  font-size: 0.8125rem;
  color: #18181b;
  text-decoration: underline;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  font-family: inherit;
}

.cl-ajax-error-retry:hover { color: #52525b; }
