/* -- Interactive Cheatsheets ------------------------------------------------ */

/* Search */
.cs-search-wrap {
  position: relative;
  margin-top: 20px;
}
.cs-search {
  width: 100%;
  padding: 12px 16px 12px 40px;
  background: var(--surface2);
  border: 1px solid var(--border2);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  transition: border-color .2s, box-shadow .2s;
}
.cs-search:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow, rgba(99,102,241,.15));
}
.cs-search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 16px;
  opacity: .5;
  pointer-events: none;
}
.cs-search-count {
  position: absolute;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 12px;
  color: var(--muted);
}

/* Tabs */
.cs-tabs {
  display: flex;
  gap: 0;
  margin-top: 16px;
  border-bottom: 2px solid var(--border);
  position: relative;
}
.cs-tab {
  padding: 10px 24px;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted2);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  cursor: pointer;
  transition: color .2s, border-color .2s;
  font-family: inherit;
}
.cs-tab:hover {
  color: var(--text);
}
.cs-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* Panels */
.cs-panel {
  margin-top: 0;
  animation: csFadeIn .3s ease-out;
}
.cs-panel:not(.active) {
  display: none;
}
@keyframes csFadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Layout: sidebar + content */
.cs-layout {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 24px;
  max-width: 1200px;
  margin: 24px auto 0;
  padding: 0 16px;
  align-items: start;
}

/* Sidebar */
.cs-sidebar {
  position: sticky;
  top: 80px;
  max-height: calc(100vh - 100px);
  overflow-y: auto;
}
.cs-sidebar-toggle {
  display: none;
}
.cs-sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.cs-sidebar-link {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  font-size: 13px;
  color: var(--muted);
  text-decoration: none;
  border-radius: var(--radius-sm);
  transition: background .2s, color .2s;
}
.cs-sidebar-link:hover {
  background: var(--surface);
  color: var(--text);
}
.cs-sidebar-link.active {
  background: var(--surface2);
  color: var(--accent);
  font-weight: 600;
}
.cs-sidebar-count {
  font-size: 11px;
  color: var(--muted2);
  background: var(--surface2);
  padding: 1px 6px;
  border-radius: 10px;
  min-width: 20px;
  text-align: center;
}
.cs-sidebar-link.active .cs-sidebar-count {
  background: var(--accent);
  color: var(--white);
}

/* Content */
.cs-content {
  min-width: 0;
}

/* Category */
.cs-category {
  margin-bottom: 32px;
  scroll-margin-top: 80px;
}
.cs-cat-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  margin: 0 0 16px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

/* Snippet card */
.cs-snippet {
  margin-bottom: 16px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: border-color .2s;
}
.cs-snippet:hover {
  border-color: var(--border2);
}
.cs-snippet-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 6px;
}
.cs-snippet-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  margin: 0;
  line-height: 1.4;
}
.cs-snippet-desc {
  font-size: 13px;
  color: var(--muted);
  margin: 0 0 10px;
  line-height: 1.5;
}

/* Code block inside snippet */
.cs-snippet .cs-code {
  min-height: auto;
  max-height: 400px;
  padding: 14px 16px;
  background: var(--bg);
  border: 1px solid var(--border2);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.6;
  white-space: pre;
  overflow-x: auto;
  margin: 0;
  width: 100%;
  box-sizing: border-box;
}
.cs-snippet .cs-code code {
  font-family: inherit;
  font-size: inherit;
}

/* Copy button (in snippet header) */
.cs-copy-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 600;
  background: var(--surface2);
  border: 1px solid var(--border2);
  border-radius: 6px;
  color: var(--muted);
  cursor: pointer;
  transition: background .2s, color .2s, border-color .2s;
  white-space: nowrap;
  flex-shrink: 0;
  font-family: inherit;
}
.cs-copy-btn:hover {
  background: var(--accent);
  color: var(--white);
  border-color: var(--accent);
}
.cs-copy-btn.copied {
  background: var(--green, #22c55e);
  color: var(--white);
  border-color: var(--green, #22c55e);
}
.cs-copy-btn svg {
  flex-shrink: 0;
}

/* Syntax highlighting */
.hl-comment   { color: var(--muted2, #6b7280); font-style: italic; }
.hl-cmd       { color: var(--cyan, #22d3ee); font-weight: 600; }
.hl-flag      { color: var(--yellow, #facc15); }
.hl-url       { color: var(--green, #22c55e); }
.hl-string    { color: var(--orange, #fb923c); }
.hl-directive { color: var(--cyan, #22d3ee); font-weight: 600; }
.hl-var       { color: var(--purple, #a78bfa); }
.hl-num       { color: var(--orange, #fb923c); }

/* No results */
.cs-no-results {
  padding: 40px 20px;
  text-align: center;
  color: var(--muted);
  font-size: 15px;
}

/* ── Responsive ─────────────────────────────────────────────────────── */

@media (max-width: 768px) {
  .cs-layout {
    grid-template-columns: 1fr;
    gap: 16px;
    padding: 0 12px;
  }

  /* Sidebar becomes collapsible on mobile */
  .cs-sidebar {
    position: relative;
    top: auto;
    max-height: none;
    overflow: visible;
  }
  .cs-sidebar-toggle {
    display: block;
    width: 100%;
    padding: 10px 14px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 13px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    text-align: left;
  }
  .cs-sidebar-toggle::after {
    content: '\25BC';
    float: right;
    font-size: 10px;
    opacity: .5;
  }
  .cs-sidebar-nav {
    display: none;
    margin-top: 8px;
    padding: 8px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
  }
  .cs-sidebar.open .cs-sidebar-nav {
    display: flex;
  }
  .cs-sidebar.open .cs-sidebar-toggle::after {
    content: '\25B2';
  }

  .cs-tab {
    padding: 10px 14px;
    font-size: 13px;
  }
  .cs-snippet .cs-code {
    font-size: 11px;
    padding: 10px 12px;
  }
  .cs-snippet {
    padding: 12px;
  }
  .cs-cat-title {
    font-size: 16px;
  }
}

@media (max-width: 480px) {
  .cs-tabs {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .cs-tab {
    padding: 10px 12px;
    font-size: 12px;
    white-space: nowrap;
  }
  .cs-snippet-header {
    flex-direction: column;
    gap: 6px;
  }
  .cs-copy-btn {
    align-self: flex-start;
  }
}
