/* ═══════════════════════════════════════════════════════
   Kraft Templates — Design System
   Structured CSS inspired by shadcn/ui + Tailwind
   ═══════════════════════════════════════════════════════ */

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

/* ── Design Tokens ── */
:root {
  --bg: #000000;
  --bg-secondary: #0a0a0a;
  --bg-tertiary: #111111;
  --border: #222222;
  --border-hover: #333333;
  --text: #ededed;
  --text-secondary: #888888;
  --text-muted: #666666;
  --surface: #0a0a0a;
  --radius: 8px;
  --radius-sm: 6px;
  --radius-xs: 4px;
  --shadow: 0 8px 32px rgba(0,0,0,0.4);
}

.light {
  --bg: #ffffff;
  --bg-secondary: #fafafa;
  --bg-tertiary: #f5f5f5;
  --border: #eaeaea;
  --border-hover: #d0d0d0;
  --text: #171717;
  --text-secondary: #666666;
  --text-muted: #999999;
  --surface: #ffffff;
}

/* ── Base ── */
html {
  font-family: 'Geist', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
body {
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  /* GPU compositing for smooth scrolling */
  -webkit-overflow-scrolling: touch;
}
[x-cloak] { display: none !important; }

/* ── Layout ── */
.container { max-width: 1200px; margin: 0 auto; padding: 0 24px; }
.container--sm { max-width: 700px; margin: 0 auto; padding: 0 24px; }
.container--lg { max-width: 1400px; margin: 0 auto; padding: 0 24px; }
.section { padding: 40px 0; }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-1 { gap: 4px; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }
.flex-1 { flex: 1; }
.flex-shrink-0 { flex-shrink: 0; }
.flex-wrap { flex-wrap: wrap; }
.hidden { display: none; }

/* ── Navigation ── */
.nav {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 50;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  /* Promote to GPU layer for smooth blur */
  will-change: transform;
  contain: layout style;
}
.nav__inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 24px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.nav__brand {
  display: flex;
  align-items: center;
  gap: 10px;
}
.nav__title {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.nav__actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ── Hero ── */
.hero {
  padding-top: 120px;
  padding-bottom: 0;
}
.hero__title {
  font-size: 44px;
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.1;
}
.hero__subtitle {
  font-size: 16px;
  color: var(--text-secondary);
  margin-top: 12px;
  max-width: 540px;
  line-height: 1.6;
}

/* ── Search ── */
.search {
  padding-top: 48px;
  padding-bottom: 24px;
}
.search__header {
  display: flex;
  gap: 6px;
  align-items: center;
  margin-bottom: 10px;
}
.search__label {
  font-size: 13px;
  color: var(--text-secondary);
}
.search__count {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}
.search__input-wrap {
  position: relative;
}
.search__icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}
.search__clear {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  background: none;
  border: none;
  cursor: pointer;
  padding: 2px;
  display: flex;
  transition: color 0.15s;
}
.search__clear:hover { color: var(--text); }
.search__controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 14px;
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  cursor: pointer;
  font-family: inherit;
  font-weight: 500;
  transition: all 0.15s ease;
  white-space: nowrap;
}
.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.btn--primary {
  background: var(--text);
  color: var(--bg);
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
}
.btn--primary:hover:not(:disabled) { opacity: 0.85; }
.btn--outline {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
}
.btn--outline:hover:not(:disabled) {
  border-color: var(--border-hover);
  background: var(--bg-secondary);
}
.btn--ghost {
  background: transparent;
  color: var(--text);
  border: none;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  font-size: 13px;
}
.btn--ghost:hover:not(:disabled) { background: var(--bg-tertiary); }
.btn--sm {
  padding: 6px 12px;
  font-size: 12px;
  border-radius: var(--radius-xs);
}
.btn--icon {
  padding: 8px;
  border-radius: var(--radius-sm);
}
.btn--icon.btn--sm {
  padding: 6px;
}

/* ── Inputs ── */
.input {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  transition: border-color 0.15s;
}
.input:focus {
  outline: none;
  border-color: var(--text-secondary);
}
.input::placeholder { color: var(--text-muted); }
.input--lg {
  padding: 14px 44px;
  font-size: 15px;
}
.input--mono {
  font-family: 'SF Mono', 'Fira Code', 'Fira Mono', monospace;
  font-size: 13px;
}
.textarea {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
  resize: vertical;
  transition: border-color 0.15s;
}
.textarea:focus {
  outline: none;
  border-color: var(--text-secondary);
}
.textarea::placeholder { color: var(--text-muted); }
.textarea--mono {
  font-family: 'SF Mono', 'Fira Code', monospace;
  line-height: 1.6;
}

/* ── Labels ── */
.label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 6px;
}
.label__required {
  color: #ef4444;
  margin-left: 2px;
}

/* ── Cards ── */
.card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color 0.2s, box-shadow 0.2s;
  /* PERF: Contain layout + style so browser skips off-screen cards */
  contain: layout style;
  /* PERF: content-visibility skips rendering of off-screen cards */
  content-visibility: auto;
  contain-intrinsic-size: auto 120px;
}
.card:hover {
  border-color: var(--border-hover);
  /* PERF: will-change on hover only, not persistent */
  will-change: border-color;
}
.card__inner {
  padding: 16px;
}
.card__header {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}
.card__logo {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  background: var(--bg-tertiary);
  flex-shrink: 0;
  /* PERF: lazy loading handled in HTML, GPU decode hint */
  content-visibility: auto;
}
.card__logo--sm {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-xs);
}
.card__content { flex: 1; min-width: 0; }
.card__name {
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.card__name--sm { font-size: 13px; }
.card__desc {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 4px;
  line-height: 1.4;
}
.card__desc--sm { font-size: 13px; margin-top: 0; }
.card__footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 12px;
}
.card__tags { display: flex; gap: 4px; flex-wrap: wrap; }
.card__version {
  font-size: 11px;
  color: var(--text-muted);
  flex-shrink: 0;
}

/* ── Grid ── */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
  /* PERF: contain layout so grid reflow is scoped */
  contain: layout style;
}
.grid--list {
  display: flex;
  flex-direction: column;
  gap: 1px;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.grid__item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: var(--bg);
  cursor: pointer;
  transition: background 0.15s;
  /* PERF: each list item is independently containable */
  contain: layout style;
  content-visibility: auto;
  contain-intrinsic-size: auto 48px;
}
.grid__item:hover { background: var(--bg-tertiary); }

/* ── Tags ── */
.tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: var(--radius-xs);
  font-size: 11px;
  font-weight: 500;
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: all 0.15s;
}
.tag:hover {
  color: var(--text);
  border-color: var(--border-hover);
}
.tag--active {
  background: var(--text);
  color: var(--bg);
  border-color: var(--text);
}
.tag--sm {
  padding: 2px 8px;
  font-size: 10px;
}
.tag--xs {
  padding: 2px 6px;
  font-size: 10px;
}
.selected-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  margin-top: 16px;
}
.selected-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: var(--radius-xs);
  font-size: 12px;
  font-weight: 500;
  background: var(--text);
  color: var(--bg);
}
.selected-tag__remove {
  background: none;
  border: none;
  color: var(--bg);
  cursor: pointer;
  padding: 0;
  line-height: 1;
  font-size: 14px;
  opacity: 0.6;
  transition: opacity 0.15s;
}
.selected-tag__remove:hover { opacity: 1; }

/* ── View Toggle ── */
.view-toggle {
  display: flex;
  align-items: center;
  gap: 2px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 2px;
}
.view-toggle__btn {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 5px 10px;
  border-radius: var(--radius-xs);
  border: none;
  cursor: pointer;
  font-size: 11px;
  font-family: inherit;
  color: var(--text-muted);
  background: transparent;
  transition: all 0.15s;
}
.view-toggle__btn--active {
  background: var(--text);
  color: var(--bg);
}

/* ── Popover ── */
.popover {
  position: relative;
}
.popover__content {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  width: 240px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  z-index: 60;
  overflow: hidden;
  /* PERF: GPU composite layer for popover */
  will-change: transform, opacity;
}
.popover__search {
  padding: 8px;
  border-bottom: 1px solid var(--border);
}
.popover__list {
  max-height: 260px;
  overflow-y: auto;
  /* PERF: contain scroll so it doesn't affect outer layout */
  contain: layout style;
}
.popover__item {
  width: 100%;
  text-align: left;
  padding: 7px 12px;
  font-size: 12px;
  background: none;
  border: none;
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: inherit;
  transition: background 0.1s;
}
.popover__item:hover { background: var(--bg-tertiary); }
.popover__item-check {
  width: 14px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.popover__empty {
  padding: 16px;
  text-align: center;
  font-size: 12px;
  color: var(--text-muted);
}

/* ── Modal ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.8);
  z-index: 50;
  /* PERF: promote to GPU layer for smooth fade */
  will-change: opacity;
}
.light .modal-overlay { background: rgba(0,0,0,0.4); }
.modal-container {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 50;
  pointer-events: none;
}
.modal {
  pointer-events: auto;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: 100%;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: var(--shadow);
  /* PERF: GPU composite for modal */
  will-change: transform;
}
.modal--lg { max-width: 720px; }
.modal--md { max-width: 600px; }
.modal__header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.modal__header--between {
  justify-content: space-between;
}
.modal__title {
  font-size: 16px;
  font-weight: 600;
}
.modal__subtitle {
  font-size: 12px;
  color: var(--text-muted);
}
.modal__body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 20px;
  /* PERF: contained scroll */
  contain: layout style;
}
.modal__body--p-0 { padding: 0; }
.modal__footer {
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}
.modal__actions {
  display: flex;
  gap: 6px;
}

/* ── Tabs ── */
.tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  padding: 0 20px;
}
.tabs--form { padding: 0 20px; gap: 16px; }
.tab {
  padding: 10px 0;
  margin-right: 20px;
  font-size: 13px;
  font-weight: 500;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-family: inherit;
  transition: all 0.15s;
}
.tab:hover { color: var(--text-secondary); }
.tab--active {
  color: var(--text);
  border-bottom-color: var(--text);
}

/* ── Code Block ── */
.code-block {
  position: relative;
}
.code-block pre {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  font-size: 13px;
  line-height: 1.6;
  overflow-x: auto;
  margin: 0;
  color: var(--text-secondary);
  /* PERF: contain layout for large code blocks */
  contain: layout style;
}
.code-block__copy {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 1;
}

/* ── Markdown ── */
.markdown-body h1 { font-size: 1.5em; font-weight: 700; margin: 20px 0 10px; color: var(--text); }
.markdown-body h2 { font-size: 1.25em; font-weight: 600; margin: 16px 0 8px; color: var(--text); }
.markdown-body h3 { font-size: 1.1em; font-weight: 600; margin: 14px 0 6px; color: var(--text); }
.markdown-body p { margin: 10px 0; line-height: 1.7; }
.markdown-body ul, .markdown-body ol { padding-left: 24px; margin: 10px 0; }
.markdown-body li { margin: 4px 0; line-height: 1.6; }
.markdown-body code {
  background: var(--bg-tertiary);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.88em;
  font-family: 'SF Mono', 'Fira Code', monospace;
}
.markdown-body pre {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  overflow-x: auto;
  margin: 12px 0;
}
.markdown-body pre code { background: none; padding: 0; font-size: 13px; }
.markdown-body a { color: var(--text-secondary); text-decoration: underline; text-underline-offset: 2px; }
.markdown-body a:hover { color: var(--text); }
.markdown-body blockquote {
  border-left: 3px solid var(--border);
  padding-left: 14px;
  margin: 10px 0;
  color: var(--text-muted);
}
.markdown-body table { border-collapse: collapse; width: 100%; margin: 10px 0; }
.markdown-body th, .markdown-body td {
  border: 1px solid var(--border);
  padding: 8px 12px;
  text-align: left;
  font-size: 13px;
}
.markdown-body th { background: var(--bg-tertiary); font-weight: 500; }
.markdown-body hr { border: none; border-top: 1px solid var(--border); margin: 16px 0; }
.markdown-body img { max-width: 100%; border-radius: var(--radius); }

/* ── Skeleton Loading ── */
.skeleton {
  background: var(--bg-tertiary);
  border-radius: var(--radius-xs);
  animation: pulse 1.5s ease-in-out infinite;
}
.skeleton--circle { border-radius: 50%; }
.skeleton--rounded { border-radius: var(--radius-sm); }

/* ── Error Banner ── */
.error-banner {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  margin-bottom: 16px;
  border: 1px solid #f87171;
  color: #f87171;
  background: rgba(248,113,113,0.08);
}

/* ── Success State ── */
.success-icon {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--bg-tertiary);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 16px;
}

/* ── Spinner ── */
.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--text);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  /* PERF: GPU animation */
  will-change: transform;
}
.spinner--sm { width: 14px; height: 14px; border-width: 2px; }
.spinner--lg { width: 28px; height: 28px; border-width: 3px; }
.spinner--white { border-color: var(--bg); border-top-color: transparent; }

/* ── Utilities ── */
.line-clamp-2 {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.scrollbar-thin::-webkit-scrollbar { width: 5px; }
.scrollbar-thin::-webkit-scrollbar-track { background: transparent; }
.scrollbar-thin::-webkit-scrollbar-thumb { background: #333; border-radius: 3px; }
.text-center { text-align: center; }
.text-right { text-align: right; }
.font-mono { font-family: 'SF Mono', 'Fira Code', monospace; }
.truncate { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.w-full { width: 100%; }
.relative { position: relative; }
.absolute { position: absolute; }
.pointer-events-none { pointer-events: none; }

/* ── Animations ── */
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 0%, 100% { opacity: 0.4; } 50% { opacity: 0.8; } }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }
