/* ── Reset & base ──────────────────────────────────────────── */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg: #040714;
  --surface-1: rgba(255,255,255,.03);
  --surface-2: rgba(255,255,255,.06);
  --border-subtle: rgba(255,255,255,.07);
  --border: rgba(255,255,255,.1);
  --border-strong: rgba(255,255,255,.22);
  --text-primary: #f9f9f9;
  --text-secondary: #cacaca;
  --text-muted: rgba(255,255,255,.55);
  --accent: #facc15;
  --accent-dim: rgba(250,204,21,.15);
  --accent-glow: rgba(250,204,21,.25);
  --cat-shell: #facc15;
  --cat-macos: #a78bfa;
  --cat-data: #34d399;
  --cat-text: #38bdf8;
  --cat-git: #f05032;
  --cat-config: #a3e635;
  --cat-docker: #2496ed;
  --cat-k8s: #326ce5;
  --cat-devops: #e879f9;
  --cat-claude: #f97316;
  --font: 'Avenir Next', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  --text-xs: 0.75rem; --text-sm: 0.875rem; --text-base: 1rem;
  --text-lg: 1.125rem; --text-xl: 1.25rem; --text-2xl: 1.5rem;
  --space-1: 4px; --space-2: 8px; --space-3: 12px; --space-4: 16px;
  --space-6: 24px; --space-8: 32px;
  --radius-sm: 6px; --radius: 10px; --radius-lg: 15px;
  --ease-snap: cubic-bezier(0.34, 1.56, 0.64, 1);
  --dur-fast: 120ms; --dur: 200ms;
}

body {
  font-family: var(--font);
  background: var(--bg);
  min-height: 100vh;
  color: var(--text-primary);
  display: flex; flex-direction: column;
}

/* ── Header ────────────────────────────────────────────────── */
.header-bar {
  background: linear-gradient(135deg, #B015B0 0%, #3D0080 50%, #040714 100%);
  background: linear-gradient(in oklch 135deg, #B015B0 0%, #3D0080 50%, #040714 100%);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-subtle);
  padding: 0 var(--space-6);
  height: 68px;
  position: sticky;
  top: 0;
  z-index: 200;
  display: flex;
  align-items: center;
}

.header-logo { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }

.header-logo-img {
  height: 36px; width: auto; flex-shrink: 0;
  filter: brightness(0) invert(1);
  transition: transform 0.3s var(--ease-snap);
  display: block;
}
.header-logo-img:hover { transform: scale(1.14) rotate(-9deg); }

.header-logo h1 { font-size: 1.2em; font-weight: 600; color: var(--text-primary); letter-spacing: .5px; }
.header-subtitle { font-size: .82em; color: rgba(255,255,255,.72); font-weight: 500; margin-top: 3px; }

.header-home {
  display: flex; align-items: center;
  margin-left: auto;
  padding: 5px;
  color: rgba(255,255,255,0.9); text-decoration: none;
  border-radius: var(--radius-sm);
  transition: color var(--dur), background var(--dur); flex-shrink: 0;
}
.header-home:hover { color: #fff; background: rgba(255,255,255,0.12); }
.header-home svg { width: 34px; height: 34px; display: block; }

/* ── Layout ────────────────────────────────────────────────── */
.container {
  max-width: 1440px;
  width: 100%;
  margin: 0 auto;
  padding: 30px;
  flex: 1;
}

#snippets-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-4);
}

#snippets-grid .snippet-card { margin-bottom: 0; }

/* ── Motto ─────────────────────────────────────────────────── */
.motto {
  text-align: center;
  margin-bottom: var(--space-6);
  color: var(--text-muted);
  font-size: var(--text-sm);
  letter-spacing: 0.3px;
}
.motto strong {
  color: var(--accent);
  font-weight: 600;
}

/* ── Search bar ────────────────────────────────────────────── */
.search-bar {
  display: flex;
  gap: var(--space-2);
  margin-bottom: var(--space-4);
}

.search-wrap {
  flex: 1;
  position: relative;
}

.search-wrap svg {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  width: 18px; height: 18px;
  color: var(--text-muted);
  pointer-events: none;
}

.search-input {
  width: 100%;
  padding: 12px 14px 12px 42px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: var(--text-base);
  outline: none;
  transition: border-color var(--dur), box-shadow var(--dur);
}
.search-input::placeholder { color: var(--text-muted); }
.search-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

.clear-btn {
  padding: 0 16px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-secondary);
  font-family: var(--font);
  font-size: var(--text-sm);
  cursor: pointer;
  transition: background var(--dur), border-color var(--dur);
  white-space: nowrap;
}
.clear-btn:hover {
  background: rgba(255,255,255,.08);
  border-color: var(--border-strong);
}

/* ── Filter row (dropdowns) ────────────────────────────────── */
.filter-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-bottom: var(--space-6);
  flex-wrap: wrap;
}

.result-count {
  font-size: var(--text-sm);
  color: var(--text-muted);
  margin-left: auto;
  white-space: nowrap;
}

/* ── Dropdown ─────────────────────────────────────────────── */
.dropdown {
  position: relative;
}

.dropdown-toggle {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 8px 12px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: var(--text-sm);
  cursor: pointer;
  transition: border-color var(--dur), background var(--dur);
  white-space: nowrap;
  min-width: 140px;
}
.dropdown-toggle:hover {
  background: var(--surface-2);
  border-color: var(--border-strong);
}
.dropdown.open .dropdown-toggle {
  border-color: var(--accent);
  background: var(--surface-2);
}

.dropdown-label {
  font-size: var(--text-xs);
  color: var(--text-muted);
  margin-right: var(--space-1);
}

.dropdown-value {
  flex: 1;
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
}

.dropdown-arrow {
  width: 14px; height: 14px;
  flex-shrink: 0;
  color: var(--text-muted);
  transition: transform var(--dur);
}
.dropdown.open .dropdown-arrow {
  transform: rotate(180deg);
}

.dropdown-menu {
  display: none;
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  min-width: 100%;
  max-height: 300px;
  overflow-y: auto;
  background: #0d0f1a;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-1) 0;
  list-style: none;
  z-index: 100;
  box-shadow: 0 8px 24px rgba(0,0,0,.5);
  scrollbar-color: rgba(255,255,255,.15) transparent;
  scrollbar-width: thin;
}
.dropdown.open .dropdown-menu { display: block; }

.dd-search-wrap {
  position: sticky;
  top: 0;
  padding: 6px 8px;
  background: #0d0f1a;
  z-index: 1;
}
.dd-search {
  width: 100%;
  padding: 6px 10px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: var(--text-xs);
  outline: none;
  transition: border-color var(--dur);
}
.dd-search::placeholder { color: var(--text-muted); }
.dd-search:focus { border-color: var(--accent); }

.dropdown-item.hidden { display: none; }
.dd-no-match {
  padding: 10px 14px;
  font-size: var(--text-xs);
  color: var(--text-muted);
  text-align: center;
}

.dropdown-menu::-webkit-scrollbar { width: 6px; }
.dropdown-menu::-webkit-scrollbar-track { background: transparent; }
.dropdown-menu::-webkit-scrollbar-thumb { background: rgba(255,255,255,.15); border-radius: 3px; }

.dropdown-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 8px 14px;
  font-size: var(--text-sm);
  color: var(--text-secondary);
  cursor: pointer;
  transition: background var(--dur-fast), color var(--dur-fast);
  white-space: nowrap;
}
.dropdown-item:hover {
  background: rgba(255,255,255,.06);
  color: var(--text-primary);
}
.dropdown-item.selected {
  color: var(--accent);
  font-weight: 500;
}

/* ── Checkbox for multi-select ────────────────────────────── */
.check-box {
  width: 14px; height: 14px;
  border: 1.5px solid var(--border-strong);
  border-radius: 3px;
  flex-shrink: 0;
  position: relative;
  transition: all var(--dur-fast);
}
.check-box.checked {
  background: var(--accent);
  border-color: var(--accent);
}
.check-box.checked::after {
  content: '';
  position: absolute;
  left: 3px; top: 1px;
  width: 5px; height: 8px;
  border: solid #000;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

/* ── Snippet cards ─────────────────────────────────────────── */
.snippet-card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-left: 3px solid var(--card-cat, var(--accent));
  border-radius: var(--radius);
  padding: var(--space-6);
  margin-bottom: var(--space-4);
  display: flex;
  flex-direction: column;
  animation: fadeIn 0.3s ease-out both;
  transition: transform var(--dur) ease-out, box-shadow var(--dur) ease-out;
}
.snippet-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(0,0,0,0.2);
}

.snippet-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: var(--space-3);
  margin-bottom: var(--space-2);
}

.snippet-title {
  font-size: var(--text-lg);
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.3;
}

.snippet-platform {
  font-size: var(--text-xs);
  color: var(--accent);
  background: var(--accent-dim);
  padding: 3px 10px;
  border-radius: 12px;
  white-space: nowrap;
  flex-shrink: 0;
  font-weight: 500;
}

.snippet-desc {
  font-size: var(--text-sm);
  color: var(--text-muted);
  margin-bottom: var(--space-4);
  line-height: 1.5;
}

.snippet-desc { flex-shrink: 0; }

/* ── Code block ────────────────────────────────────────────── */
.snippet-code-wrap {
  position: relative;
  margin-bottom: var(--space-3);
  flex: 1;
}

.snippet-code {
  background: rgba(0,0,0,.4);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 14px 50px 14px 16px;
  overflow-x: auto;
  overflow-y: auto;
  max-height: 320px;
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', 'JetBrains Mono', Consolas, monospace;
  font-size: 0.82rem;
  line-height: 1.6;
  color: #e2e8f0;
  white-space: pre-wrap;
  word-break: break-word;
}

.snippet-card.expanded .snippet-code {
  max-height: none;
}

.expand-btn {
  display: none;
  width: 100%;
  padding: 6px;
  background: linear-gradient(to bottom, transparent, rgba(0,0,0,.4) 40%);
  border: none;
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
  color: var(--accent);
  font-family: var(--font);
  font-size: var(--text-xs);
  cursor: pointer;
  margin-top: -1px;
  transition: color var(--dur);
}
.expand-btn:hover { color: var(--text-primary); }
.expand-btn.visible { display: block; }

.copy-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 34px; height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--dur);
}
.copy-btn svg { width: 16px; height: 16px; }
.copy-btn:hover {
  color: var(--accent);
  background: var(--accent-dim);
  border-color: var(--accent);
}
.copy-btn.copied {
  color: #4ade80;
  border-color: #4ade80;
}

/* ── Snippet meta (tags row) ───────────────────────────────── */
.snippet-meta {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
}

.snippet-category {
  font-size: var(--text-xs);
  color: var(--text-secondary);
  background: var(--surface-2);
  padding: 2px 10px;
  border-radius: 10px;
  font-weight: 500;
}

.snippet-tag {
  font-size: 0.7rem;
  color: var(--text-muted);
  background: var(--surface-1);
  border: 1px solid var(--border-subtle);
  padding: 2px 8px;
  border-radius: 10px;
}

/* ── Category accent colors ────────────────────────────────── */
.snippet-card[data-cat="shell"]  { --card-cat: var(--cat-shell); }
.snippet-card[data-cat="macos"]  { --card-cat: var(--cat-macos); }
.snippet-card[data-cat="data"]   { --card-cat: var(--cat-data); }
.snippet-card[data-cat="text"]   { --card-cat: var(--cat-text); }
.snippet-card[data-cat="git"]    { --card-cat: var(--cat-git); }
.snippet-card[data-cat="config"] { --card-cat: var(--cat-config); }
.snippet-card[data-cat="docker"] { --card-cat: var(--cat-docker); }
.snippet-card[data-cat="k8s"]    { --card-cat: var(--cat-k8s); }
.snippet-card[data-cat="devops"] { --card-cat: var(--cat-devops); }
.snippet-card[data-cat="claude"] { --card-cat: var(--cat-claude); }

/* ── Empty state ───────────────────────────────────────────── */
.empty-state {
  grid-column: 1 / -1;
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
  font-size: var(--text-sm);
}

/* ── Suggest button ────────────────────────────────────────── */
.suggest-bar {
  text-align: center;
  margin-top: var(--space-6);
  padding-bottom: var(--space-8);
}

.suggest-trigger {
  padding: 10px 24px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-secondary);
  font-family: var(--font);
  font-size: var(--text-sm);
  cursor: pointer;
  transition: all var(--dur);
}
.suggest-trigger:hover {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--accent);
}

/* ── Suggest modal ─────────────────────────────────────────── */
.suggest-modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 300;
  background: rgba(0,0,0,.6);
  backdrop-filter: blur(4px);
  align-items: center;
  justify-content: center;
}
.suggest-modal.open { display: flex; }

.suggest-panel {
  background: #0d0f1a;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-8);
  width: 90%;
  max-width: 480px;
  animation: fadeIn 0.2s ease-out;
}

.suggest-panel h3 {
  font-size: var(--text-lg);
  margin-bottom: var(--space-4);
  color: var(--text-primary);
}

.suggest-panel label {
  display: block;
  font-size: var(--text-sm);
  color: var(--text-secondary);
  margin-bottom: var(--space-1);
  margin-top: var(--space-3);
}

.suggest-panel input,
.suggest-panel textarea {
  width: 100%;
  padding: 10px 14px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: var(--text-sm);
  outline: none;
  transition: border-color var(--dur);
}
.suggest-panel input:focus,
.suggest-panel textarea:focus {
  border-color: var(--accent);
}

.suggest-panel textarea {
  font-family: 'SF Mono', 'Fira Code', Consolas, monospace;
  font-size: 0.82rem;
  resize: vertical;
  min-height: 60px;
}

.suggest-actions {
  display: flex;
  gap: var(--space-2);
  margin-top: var(--space-6);
  justify-content: flex-end;
}

.suggest-actions button {
  padding: 8px 20px;
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: var(--text-sm);
  cursor: pointer;
  transition: all var(--dur);
}

.btn-secondary {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-secondary);
}
.btn-secondary:hover { background: rgba(255,255,255,.08); }

.btn-primary {
  background: var(--accent);
  border: 1px solid var(--accent);
  color: #000;
  font-weight: 600;
}
.btn-primary:hover { filter: brightness(1.1); }

/* ── Keyboard hint ─────────────────────────────────────────── */
.kbd {
  display: inline-block;
  padding: 1px 6px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-family: 'SF Mono', Consolas, monospace;
  font-size: 0.7rem;
  color: var(--text-muted);
  vertical-align: middle;
  margin-left: 6px;
}

/* ── Entrance animation ───────────────────────────────────────── */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Button press feedback ────────────────────────────────────── */
.copy-btn:active,
.dropdown-toggle:active,
.clear-btn:active,
.suggest-trigger:active,
.suggest-actions button:active { transform: scale(0.97); transition-duration: var(--dur-fast); }

/* ── Dark scrollbar ───────────────────────────────────────────── */
.snippet-code::-webkit-scrollbar { width: 6px; height: 6px; }
.snippet-code::-webkit-scrollbar-track { background: transparent; }
.snippet-code::-webkit-scrollbar-thumb { background: rgba(255,255,255,.15); border-radius: 3px; }
.snippet-code::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,.25); }
.snippet-code { scrollbar-color: rgba(255,255,255,.15) transparent; scrollbar-width: thin; }

/* ── Toast ─────────────────────────────────────────────────── */
.toast {
  position: fixed; bottom: 24px; right: 24px; z-index: 999;
  background: #1a1730; border: 1px solid rgba(255,255,255,0.15);
  border-radius: 8px; padding: 10px 16px;
  font-size: 0.84rem; color: var(--text-primary);
  box-shadow: 0 4px 20px rgba(0,0,0,0.55);
  pointer-events: none;
  transform: translateY(8px); opacity: 0;
  transition: opacity 0.18s, transform 0.18s;
}
.toast.visible { opacity: 1; transform: translateY(0); }

/* ── Focus styles ──────────────────────────────────────────── */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ── Skip link ─────────────────────────────────────────────── */
.skip-link {
  position: absolute;
  top: -100%;
  left: var(--space-4);
  z-index: 1000;
  padding: var(--space-2) var(--space-4);
  background: var(--accent);
  color: #000;
  font-weight: 600;
  font-size: var(--text-sm);
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
  text-decoration: none;
  transition: top var(--dur);
}
.skip-link:focus { top: 0; }

/* ── Reduced motion ────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* ── Responsive ────────────────────────────────────────────── */
@media (max-width: 1100px) {
  #snippets-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 700px) {
  #snippets-grid { grid-template-columns: 1fr; }
  .header-bar { padding: 0 var(--space-4); }
  .container { padding: var(--space-4); }
  .filter-row { gap: var(--space-2); }
  .dropdown { flex: 1; min-width: 0; }
  .dropdown-toggle { min-width: 0; width: 100%; }
  .dropdown-menu { min-width: 180px; }
  .result-count { width: 100%; text-align: center; margin-left: 0; }
  .snippet-header { flex-direction: column; gap: var(--space-1); }
  .snippet-platform { align-self: flex-start; }
  .snippet-code { font-size: 0.75rem; padding: 12px 44px 12px 12px; }
  .suggest-panel { padding: var(--space-6); }
}
