:root {
  --bg: #0e0f12;
  --panel: #16181d;
  --panel-2: #1c1f26;
  --border: #2a2d35;
  --text: #e8e9ed;
  --text-dim: #9a9ea8;
  --text-faint: #6b6f7a;
  --accent: #1e93ff;
  --accent-soft: rgba(30, 147, 255, 0.15);
  --accent-strong: #5cb3ff;
  --accent-contrast: #06213d;
  --radius: 12px;
  --radius-sm: 8px;
  --mono: "SF Mono", "JetBrains Mono", Consolas, Menlo, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
}

* {
  box-sizing: border-box;
  min-width: 0;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
  width: 100%;
}

img, svg {
  max-width: 100%;
}

/* ---------- Topbar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(14, 15, 18, 0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  gap: 20px;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.brand-logo {
  height: 28px;
  width: auto;
  flex-shrink: 0;
  display: block;
}

.brand-divider {
  width: 1px;
  height: 26px;
  background: var(--border);
  flex-shrink: 0;
}

.brand-text h1 {
  font-size: 17px;
  margin: 0;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.brand-text p {
  margin: 2px 0 0;
  font-size: 13px;
  color: var(--text-dim);
}

.search-wrap {
  flex: 1;
  min-width: 200px;
  display: flex;
  align-items: center;
  gap: 10px;
  position: relative;
}

#searchInput {
  width: 100%;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: var(--sans);
  outline: none;
  transition: border-color 0.15s ease;
  -webkit-appearance: none;
  appearance: none;
}

#searchInput:focus {
  border-color: var(--accent);
}

#searchInput::placeholder {
  color: var(--text-faint);
}

#searchInput::-webkit-search-cancel-button {
  cursor: pointer;
}

.search-count {
  font-size: 12px;
  color: var(--text-faint);
  white-space: nowrap;
  flex-shrink: 0;
}

/* Mobile "Filters" toggle button - hidden on desktop, shown at the same
   breakpoint where the sidebar becomes an off-canvas drawer. */
.filter-toggle {
  display: none;
  align-items: center;
  gap: 6px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 9px 14px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  flex-shrink: 0;
}

.filter-toggle-badge {
  background: var(--accent);
  color: var(--accent-contrast);
  font-size: 11px;
  font-weight: 700;
  border-radius: 999px;
  min-width: 18px;
  height: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 5px;
}

@media (max-width: 600px) {
  .topbar-inner {
    padding: 12px 16px;
    gap: 10px;
  }

  .brand-logo {
    height: 22px;
  }

  .brand-divider {
    display: none;
  }

  .brand-text h1 {
    font-size: 15px;
  }

  .brand-text p {
    display: none;
  }

  .search-wrap {
    order: 3;
    flex: 1 1 100%;
    min-width: 0;
  }

  .search-count {
    display: none;
  }
}

/* ---------- Layout ---------- */
.layout {
  max-width: 1400px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 240px 1fr;
  gap: 28px;
  padding: 24px;
  align-items: start;
}

@media (max-width: 900px) {
  .layout {
    grid-template-columns: 1fr;
    padding: 16px;
  }
}

/* ---------- Sidebar ---------- */
.sidebar {
  position: sticky;
  top: 90px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  max-height: calc(100vh - 110px);
  overflow-y: auto;
}

.sidebar-head {
  display: none;
  align-items: center;
  justify-content: space-between;
}

.sidebar-title {
  font-size: 16px;
  margin: 0;
  font-weight: 600;
}

.icon-btn {
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  padding: 2px 6px;
}

.sidebar-backdrop {
  display: none;
}

@media (max-width: 900px) {
  .sidebar {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    height: 100%;
    max-height: none;
    width: min(300px, 85vw);
    background: var(--panel);
    border-left: 1px solid var(--border);
    padding: 18px;
    z-index: 60;
    transform: translateX(100%);
    transition: transform 0.25s ease;
    overflow-y: auto;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-head {
    display: flex;
  }

  .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 50;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
  }

  .sidebar-backdrop.open {
    opacity: 1;
    pointer-events: auto;
  }

  .filter-toggle {
    display: inline-flex;
  }

  .clear-btn {
    width: 100%;
  }
}

.filter-group h2 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-faint);
  margin: 0 0 8px;
  font-weight: 600;
}

.chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  max-width: 100%;
}

.chip {
  font-size: 12.5px;
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text-dim);
  cursor: pointer;
  user-select: none;
  transition: all 0.12s ease;
  white-space: nowrap;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chip:hover {
  border-color: var(--accent);
  color: var(--text);
}

.chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-contrast);
  font-weight: 600;
}

.chip .count {
  opacity: 0.6;
  margin-left: 4px;
  font-size: 11px;
}

.clear-btn {
  align-self: flex-start;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.clear-btn:hover {
  border-color: var(--accent);
  color: var(--text);
}

/* ---------- Card grid ---------- */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 16px;
}

@media (max-width: 720px) {
  .card-grid {
    grid-template-columns: 1fr;
  }
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  transition: border-color 0.15s ease;
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
}

@media (max-width: 480px) {
  .card {
    padding: 14px;
  }
}

.card:hover {
  border-color: #3a3d47;
}

.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.card-title {
  font-size: 15px;
  font-weight: 600;
  margin: 0;
  line-height: 1.35;
  color: var(--text);
}

.badge-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.badge {
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 3px 8px;
  border-radius: 999px;
  white-space: nowrap;
}

.badge-cat {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.badge-phase {
  background: #24303a;
  color: #7fb8d6;
}

.prompt-box {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.55;
  color: #d9dbe0;
  white-space: pre-wrap;
  word-break: break-word;
}

.prompt-box .slot {
  color: var(--accent-strong);
  background: rgba(217, 119, 87, 0.12);
  border-radius: 4px;
  padding: 0 2px;
}

mark.hit {
  background: rgba(217, 119, 87, 0.35);
  color: #fff;
  border-radius: 3px;
  padding: 0 1px;
}

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

.copy-btn {
  background: var(--accent);
  color: var(--accent-contrast);
  border: none;
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: filter 0.12s ease;
  flex-shrink: 0;
}

@media (max-width: 380px) {
  .card-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .copy-btn,
  .why-toggle {
    width: 100%;
  }
}

.copy-btn:hover {
  filter: brightness(1.08);
}

.copy-btn.copied {
  background: #4caf7d;
  color: #052014;
}

.why-toggle {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.why-toggle:hover {
  border-color: var(--accent);
  color: var(--text);
}

.why-panel {
  display: none;
  background: var(--panel-2);
  border-left: 2px solid var(--accent);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  padding: 10px 14px;
  font-size: 13px;
  line-height: 1.55;
  color: var(--text-dim);
  word-break: break-word;
}

.why-panel a {
  color: var(--accent-strong);
}

.why-panel.open {
  display: block;
}

.why-panel .next-line {
  margin-top: 8px;
  color: var(--text-faint);
  font-size: 12.5px;
}

.why-panel code {
  background: rgba(255, 255, 255, 0.06);
  padding: 1px 5px;
  border-radius: 4px;
  font-family: var(--mono);
  font-size: 12px;
}

.footer-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: -2px;
  flex-wrap: wrap;
}

.role-tags {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  min-width: 0;
}

.role-tag {
  font-size: 10.5px;
  color: var(--text-faint);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 7px;
  white-space: nowrap;
}

.source-tag {
  font-size: 11px;
  color: var(--text-faint);
  text-decoration: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
  flex-shrink: 0;
}

.source-tag:hover {
  color: var(--accent-strong);
}

.empty-state {
  text-align: center;
  color: var(--text-faint);
  padding: 60px 0;
  font-size: 14px;
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translate(-50%, 20px);
  background: #1f2229;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 100;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  max-width: calc(100vw - 32px);
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

@media (max-width: 480px) {
  .toast {
    bottom: 16px;
    font-size: 13px;
  }
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}
