:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-soft: #eef2ff;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow-md: 0 10px 25px -5px rgba(15, 23, 42, 0.08), 0 4px 10px -6px rgba(15, 23, 42, 0.05);
  --radius: 14px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

.hidden { display: none !important; }

.container {
  max-width: 1440px;
  margin: 0 auto;
  padding: 0 20px;
}

/* Topbar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  display: flex;
  align-items: center;
  gap: 18px;
  min-height: 70px;
  padding-top: 10px;
  padding-bottom: 10px;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 220px;
}

.brand-icon {
  width: 40px;
  height: 40px;
  border-radius: 11px;
  background: linear-gradient(135deg, #4f46e5, #06b6d4);
  color: #fff;
  font-weight: 800;
  font-size: 18px;
  display: grid;
  place-items: center;
  box-shadow: 0 6px 16px rgba(79, 70, 229, 0.25);
}

.brand-title {
  font-weight: 700;
  font-size: 16px;
  letter-spacing: -0.01em;
}

.brand-sub {
  font-size: 12px;
  color: var(--muted);
}

.search-wrap {
  position: relative;
  flex: 1;
  min-width: 240px;
}

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

#searchInput {
  width: 100%;
  height: 42px;
  padding: 0 16px 0 42px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #f1f5f9;
  font-size: 14px;
  color: var(--text);
  outline: none;
  transition: all 0.15s ease;
}

#searchInput:focus {
  background: #fff;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.12);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.toggle-preview {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
}

.toggle-preview input { accent-color: var(--primary); cursor: pointer; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 38px;
  padding: 0 14px;
  border-radius: 9px;
  font-size: 13px;
  font-weight: 600;
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}
.btn-primary:hover { background: var(--primary-hover); }

.btn-outline {
  background: #fff;
  color: var(--text);
  border-color: var(--border);
}
.btn-outline:hover { background: #f8fafc; border-color: #cbd5e1; }

.btn-ghost {
  background: transparent;
  color: var(--text);
}
.btn-ghost:hover { background: #f1f5f9; }

.select {
  height: 36px;
  padding: 0 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #fff;
  font-size: 13px;
  color: var(--text);
}

/* Layout */
.layout {
  display: grid;
  grid-template-columns: 270px 1fr;
  gap: 24px;
  padding-top: 24px;
  padding-bottom: 48px;
}

.sidebar-card {
  position: sticky;
  top: 90px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow-sm);
  max-height: calc(100vh - 110px);
  overflow-y: auto;
}

.sidebar-title {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin-bottom: 12px;
  padding: 0 8px;
}

.category-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.cat-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 9px 12px;
  border: none;
  border-radius: 9px;
  background: transparent;
  color: var(--text);
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  transition: all 0.12s ease;
}

.cat-btn:hover { background: #f1f5f9; }
.cat-btn.active {
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 600;
}

.cat-count {
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 999px;
  background: #f1f5f9;
  color: var(--muted);
}
.cat-btn.active .cat-count {
  background: #fff;
  color: var(--primary);
}

/* Content */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}

.toolbar-info {
  display: flex;
  align-items: baseline;
  gap: 12px;
}

.toolbar-info h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.result-count {
  font-size: 13px;
  color: var(--muted);
  font-weight: 500;
}

/* Grid */
.demo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(310px, 1fr));
  gap: 20px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
}

.card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-md);
  border-color: #cbd5e1;
}

.thumb-box {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 10;
  background: linear-gradient(135deg, #f1f5f9, #e2e8f0);
  overflow: hidden;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}

.thumb-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: top center;
  display: block;
  background: #fff;
}

.thumb-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 16px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  gap: 6px;
}

.thumb-placeholder strong {
  color: var(--text);
  font-size: 15px;
}

.thumb-overlay {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.35);
  opacity: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.15s ease;
}

.thumb-box:hover .thumb-overlay { opacity: 1; }

.card-body {
  padding: 14px 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex: 1;
}

.card-title {
  font-weight: 650;
  font-size: 15px;
  color: var(--text);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  min-height: 44px;
}

.card-slug {
  font-size: 12px;
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tag {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary);
  cursor: pointer;
}

.card-actions {
  margin-top: auto;
  padding-top: 8px;
  display: flex;
  gap: 8px;
}

.card-actions .btn { flex: 1; height: 36px; font-size: 12.5px; }

/* Pagination */
.pagination {
  margin-top: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
}

.page-btn {
  min-width: 38px;
  height: 38px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: #fff;
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.page-btn:hover:not(:disabled) { background: #f1f5f9; }
.page-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
.page-btn:disabled { opacity: 0.45; cursor: not-allowed; }

/* Empty State */
.empty-state {
  background: #fff;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 48px 24px;
  text-align: center;
}
.empty-title { font-size: 17px; font-weight: 700; margin-bottom: 6px; }
.empty-desc { font-size: 14px; color: var(--muted); margin-bottom: 16px; }

/* Preview Modal */
.preview-modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: #0f172a;
  display: flex;
  flex-direction: column;
}

.preview-bar {
  height: 60px;
  background: #1e293b;
  color: #f8fafc;
  border-bottom: 1px solid #334155;
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.preview-bar .btn-ghost { color: #e2e8f0; }
.preview-bar .btn-ghost:hover { background: #334155; }
.preview-bar .btn-outline { background: transparent; color: #f8fafc; border-color: #475569; }
.preview-bar .btn-outline:hover { background: #334155; }

.preview-meta {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.preview-title-wrap { min-width: 0; }
.preview-title {
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 340px;
}
.preview-cats { font-size: 11.5px; color: #94a3b8; }

.device-switcher {
  display: flex;
  background: #0f172a;
  padding: 4px;
  border-radius: 9px;
  gap: 4px;
}

.device-btn {
  border: none;
  background: transparent;
  color: #94a3b8;
  font-size: 12.5px;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
}
.device-btn.active { background: var(--primary); color: #fff; }

.preview-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.preview-stage {
  flex: 1;
  overflow: auto;
  display: flex;
  justify-content: center;
  align-items: stretch;
  padding: 0;
  background: #0f172a;
}

.preview-frame-wrap {
  width: 100%;
  height: 100%;
  background: #fff;
  transition: width 0.2s ease;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
}

#previewIframe {
  width: 100%;
  height: 100%;
  border: none;
  display: block;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 200;
  background: #0f172a;
  color: #fff;
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 500;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
}

@media (max-width: 960px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar-card { position: static; max-height: none; }
  .category-list { flex-direction: row; flex-wrap: wrap; }
  .cat-btn { width: auto; }
  .device-switcher { display: none; }
}
