/* bnb_agent design system — DESIGN.md is the single source of truth.
 * Hand-rolled plain CSS: no Tailwind, no preprocessor (project constraint).
 * Dark theme is the design basis (D4); light tokens are kept under
 * [data-theme="light"] for the migration period. */

/* ---------------------------------------------------------------------------
 * Design tokens
 * ------------------------------------------------------------------------ */

:root {
  /* Colors — dark theme (PRIMARY, design basis) */
  --color-bg: #0f172a;
  --color-surface: #1e293b;
  --color-surface-hover: #243044;
  --color-surface-muted: #334155;
  --color-border: #2a3a4a;
  --color-border-strong: #3a4a5a;
  --color-text: #ffffff;
  --color-text-secondary: #94a3b8;
  --color-text-muted: #64748b;
  --color-accent: #14b8a6;
  --color-accent-alt: #38bdf8;
  --color-bnb: #f0b90b;
  --color-success: #22c55e;
  --color-warning: #f59e0b;
  --color-danger: #ef4444;
  --color-danger-bg: #3a1215;

  /* Typography */
  --font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-family-display: "Inter", system-ui, sans-serif;
  --text-xs: 0.75rem;
  --text-sm: 0.875rem;
  --text-base: 1rem;
  --text-lg: 1.25rem;
  --text-xl: 1.5rem;
  --text-2xl: 2rem;
  --weight-normal: 400;
  --weight-semibold: 600;
  --weight-bold: 700;
  --line-height: 1.5;

  /* Spacing, radii, shadows */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-6: 24px;
  --space-8: 32px;
  --space-12: 48px;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-full: 9999px;
  --shadow-card: 0 1px 3px rgba(0, 0, 0, 0.08);
  --shadow-card-hover: 0 4px 12px rgba(0, 0, 0, 0.10);
}

/* Light theme — legacy, until migration to dark (D4). Do not build new UI
 * here; only the tokens the current app already used. */
[data-theme="light"] {
  --color-bg: #fafafa;
  --color-surface: #ffffff;
  --color-surface-muted: #f0f0f0;
  --color-text: #1a1a1a;
  --color-text-secondary: #555555;
  --color-text-muted: #666666;
  --color-border: #eeeeee;
  --color-border-strong: #dddddd;
  --color-brand: #f0b90b;
  --color-success: #2dbe60;
  --color-warning: #f59e0b;
  --color-danger: #b91c1c;
  --color-danger-bg: #ffeeee;
}

/* ---------------------------------------------------------------------------
 * Base
 * ------------------------------------------------------------------------ */

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: var(--font-family);
  font-size: var(--text-base);
  line-height: var(--line-height);
  color: var(--color-text);
  background: var(--color-bg);
}

a { color: var(--color-accent-alt); }

main {
  padding: var(--space-6) 1.25rem var(--space-8);
  max-width: 1200px;
  margin: 0 auto;
}

footer {
  text-align: center;
  padding: var(--space-4);
  color: var(--color-text-muted);
  font-size: var(--text-xs);
}

/* Focus visible: 2px accent ring on every interactive element (a11y). */
:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

/* ---------------------------------------------------------------------------
 * Header / navbar (sticky, ~64px, surface bg + border bottom)
 * ------------------------------------------------------------------------ */

header {
  position: sticky;
  top: 0;
  z-index: 10;
  height: 64px;
  display: flex;
  align-items: center;
  gap: 1.5rem;
  padding: 0 1.25rem;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
}

header .brand {
  font-weight: var(--weight-bold);
  font-size: var(--text-lg);
  color: var(--color-bnb);
  text-decoration: none;
}

header nav {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-left: auto;
}

header nav a,
header nav .user-address {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  padding: 0 var(--space-3);
  text-decoration: none;
  color: var(--color-text-secondary);
  font-size: var(--text-sm);
}

header nav a:hover { color: var(--color-text); }
header nav .user-address { color: var(--color-text); cursor: default; }

/* ---------------------------------------------------------------------------
 * Buttons (.btn always combined with a variant)
 * ------------------------------------------------------------------------ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 10px 18px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: var(--text-base);
  font-weight: var(--weight-semibold);
  line-height: 1.2;
  cursor: pointer;
  text-decoration: none;
  transition: background-color 0.15s ease, border-color 0.15s ease,
    color 0.15s ease, filter 0.15s ease;
}

.btn-primary { background: var(--color-accent); color: #062a26; }
.btn-primary:hover { filter: brightness(1.1); }

.btn-outline {
  border: 1px solid var(--color-accent);
  color: var(--color-accent);
  background: transparent;
}
.btn-outline:hover { background: rgba(20, 184, 166, 0.08); }

.btn-danger { background: var(--color-danger); color: #fff; }
.btn-danger:hover { filter: brightness(1.1); }

.btn[disabled],
.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ---------------------------------------------------------------------------
 * Badges
 * ------------------------------------------------------------------------ */

.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 2px 8px;
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  line-height: 1.4;
  white-space: nowrap;
}

.badge.verified { color: var(--color-success); }
.badge.x402 { background: var(--color-bnb); color: #062a26; }
.badge.category { background: var(--color-surface-muted); color: var(--color-text); }
.badge.risk { color: var(--color-danger); }

/* ---------------------------------------------------------------------------
 * Agent card (anatomy from DESIGN.md — shared by plain + HTMX variants)
 * ------------------------------------------------------------------------ */

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

.agent-card:hover {
  background: var(--color-surface-hover);
  box-shadow: var(--shadow-card-hover);
}

.agent-card-image {
  position: relative;
  display: block;
}

.agent-card img {
  display: block;
  width: 100%;
  height: 140px;
  object-fit: cover;
  background: var(--color-surface-muted);
}

.agent-card .badge.category {
  position: absolute;
  top: var(--space-2);
  right: var(--space-2);
}

.agent-card-body {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-3);
  flex: 1;
}

.agent-card-name {
  margin: 0;
  font-size: var(--text-lg);
  font-weight: var(--weight-semibold);
}

.agent-card-name a { color: var(--color-text); text-decoration: none; }
.agent-card-name a:hover { color: var(--color-accent-alt); }

.agent-card-badges {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin: 0;
}

.agent-card-description {
  margin: 0;
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.agent-card .meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  margin: 0;
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
}

.agent-card .meta .price { font-weight: var(--weight-bold); color: var(--color-text); }
.agent-card .meta .creator { color: var(--color-accent-alt); text-decoration: none; }
.agent-card .meta .creator:hover { text-decoration: underline; }

.agent-card .ratings {
  margin: 0;
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}

.agent-card .card-cta { margin-top: auto; }

/* ---------------------------------------------------------------------------
 * Score (D7 — numeric value + context label, never a bare judgment)
 * ------------------------------------------------------------------------ */

.score {
  font-weight: var(--weight-bold);
  color: var(--color-text);
}

.score-label {
  font-weight: var(--weight-normal);
  color: var(--color-text-secondary);
  font-size: var(--text-xs);
}

/* ---------------------------------------------------------------------------
 * Listing + filters (one row, wraps on mobile)
 * ------------------------------------------------------------------------ */

.listing {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.filters h2 { margin: 0 0 var(--space-3); font-size: var(--text-lg); }

.filter-form {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-3);
}

.filter-form .check {
  display: inline-flex;
  flex-direction: row;
  align-items: center;
  gap: var(--space-1);
  min-height: 40px;
  cursor: pointer;
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
}

.filter-form input[type="text"],
.filter-form select {
  min-height: 40px;
  padding: 8px 10px;
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-text);
  font-family: inherit;
  font-size: var(--text-base);
}

.grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-4);
}

/* ---------------------------------------------------------------------------
 * Hero + category cards (D6 — lightweight layer, full page only)
 * ------------------------------------------------------------------------ */

.hero {
  padding: var(--space-12) 0 var(--space-8);
  text-align: center;
}

.hero h1 {
  margin: 0 0 var(--space-3);
  font-size: var(--text-2xl);
  font-weight: var(--weight-bold);
}

.hero p {
  margin: 0 auto var(--space-6);
  max-width: 560px;
  font-size: var(--text-lg);
  color: var(--color-text-secondary);
}

.category-grid {
  /* 10 cards: horizontal scroll below desktop, 2×5 grid ≥1024px (design D7) */
  display: flex;
  gap: var(--space-4);
  margin-bottom: var(--space-8);
  overflow-x: auto;
  padding-bottom: var(--space-2);
  scroll-snap-type: x proximity;
  -webkit-overflow-scrolling: touch;
}

.category-card {
  display: block;
  flex: 0 0 240px;
  scroll-snap-align: start;
  padding: var(--space-4);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  text-decoration: none;
  color: var(--color-text);
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.category-card:hover {
  background: var(--color-surface-hover);
  border-color: var(--color-accent);
}

.category-card .cat-icon { color: var(--color-accent); }
.category-card .cat-icon svg { width: 28px; height: 28px; display: block; }
.category-card h3 { margin: var(--space-2) 0 0; font-size: var(--text-lg); font-weight: var(--weight-semibold); }
.category-card .tagline { margin: var(--space-1) 0 0; font-size: var(--text-sm); color: var(--color-text-secondary); }
.category-card .example { margin: var(--space-2) 0 0; font-size: var(--text-xs); color: var(--color-text-muted); }

/* ---------------------------------------------------------------------------
 * Agent detail
 * ------------------------------------------------------------------------ */

.agent-detail { max-width: 720px; margin: 0 auto; }

.agent-detail .agent-hero {
  display: block;
  width: 100%;
  height: 220px;
  object-fit: cover;
  border-radius: var(--radius-lg);
  background: var(--color-surface-muted);
}

.agent-detail h1 { margin: var(--space-4) 0 var(--space-2); font-size: var(--text-xl); font-weight: var(--weight-bold); }

.agent-detail-badges {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin: 0 0 var(--space-4);
}

.agent-detail-description {
  margin: 0 0 var(--space-6);
  color: var(--color-text-secondary);
}

.agent-detail dl {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: var(--space-2) var(--space-4);
  margin: 0;
  font-size: var(--text-sm);
}

.agent-detail dt { color: var(--color-text-secondary); font-weight: var(--weight-semibold); }
.agent-detail dd { margin: 0; }

/* ---------------------------------------------------------------------------
 * Agent profile (technical sheet — category study §8)
 * ------------------------------------------------------------------------ */

.agent-profile {
  margin-top: var(--space-8);
  padding: var(--space-6);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
}

.agent-profile h2 {
  margin: 0 0 var(--space-4);
  font-size: var(--text-lg);
  font-weight: var(--weight-semibold);
}

.agent-profile dl {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: var(--space-2) var(--space-4);
  margin: 0;
  font-size: var(--text-sm);
}

.agent-profile dt { color: var(--color-text-secondary); font-weight: var(--weight-semibold); }
.agent-profile dd { margin: 0; }

.agent-profile code {
  padding: 2px 6px;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: var(--text-xs);
  word-break: break-all;
}

.agent-profile .tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1);
}

.agent-profile ul {
  margin: var(--space-1) 0 0;
  padding-left: var(--space-4);
}

.agent-profile li { margin-bottom: var(--space-1); }

.evoevo-avatar {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-sm);
  vertical-align: middle;
}

.offchain-service {
  margin-bottom: var(--space-3);
  padding: var(--space-2);
  background: var(--color-surface);
  border-radius: var(--radius-sm);
}

.offchain-service strong {
  color: var(--color-text);
}

.attr-list {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: var(--space-1) var(--space-3);
}

.attr-list dt {
  font-weight: var(--weight-semibold);
  color: var(--color-text-secondary);
}

.attr-list dd {
  margin: 0;
}

.mcp-tools-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: var(--space-3);
}

.mcp-category {
  padding: var(--space-2);
  background: var(--color-surface);
  border-radius: var(--radius-sm);
}

.mcp-category strong {
  color: var(--color-text);
  text-transform: capitalize;
}

.mcp-category ul {
  margin: var(--space-1) 0 0;
  padding-left: var(--space-4);
  font-size: var(--text-sm);
}

.mcp-category li {
  margin-bottom: var(--space-1);
}

.mcp-tools-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  max-height: 400px;
  overflow-y: auto;
  padding: var(--space-2);
  background: var(--color-surface);
  border-radius: var(--radius-sm);
}

.oasf-skills-grid {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.oasf-skill {
  display: flex;
  flex-direction: column;
  padding: var(--space-2);
  background: var(--color-surface);
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-border);
}

.oasf-skill-category {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  text-transform: uppercase;
}

.oasf-skill-name {
  font-weight: var(--weight-semibold);
  color: var(--color-text);
}

.social-links {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.social-link {
  display: inline-flex;
  align-items: center;
  padding: var(--space-1) var(--space-3);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  color: var(--color-text);
  text-decoration: none;
  font-size: var(--text-sm);
}

.social-link:hover {
  border-color: var(--color-accent);
  color: var(--color-accent);
}

.mcp-tool-item {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  padding: var(--space-2);
  border-bottom: 1px solid var(--color-border);
}

.mcp-tool-item:last-child {
  border-bottom: none;
}

.mcp-tool-item code {
  font-weight: var(--weight-semibold);
  color: var(--color-accent);
}

.mcp-tool-desc {
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
}

/* ---------------------------------------------------------------------------
 * Hire panel (agent detail)
 * ------------------------------------------------------------------------ */

.hire-panel {
  margin-top: var(--space-8);
  padding: var(--space-6);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
}

.hire-panel h2 { margin: 0 0 var(--space-2); font-size: var(--text-lg); font-weight: var(--weight-semibold); }

.hire-price {
  margin: 0 0 var(--space-4);
  font-size: var(--text-lg);
  font-weight: var(--weight-bold);
}

.hint {
  margin: var(--space-3) 0 0;
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
}

/* On-chain metrics */
.onchain-metrics {
  display: flex;
  gap: var(--space-4);
  flex-wrap: wrap;
}
.onchain-metric {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 60px;
}
.onchain-metric-value {
  font-size: var(--text-lg);
  font-weight: var(--weight-bold);
  color: var(--color-text);
  font-variant-numeric: tabular-nums;
}
.onchain-metric-label {
  font-size: var(--text-xs);
  color: var(--color-text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.text-muted {
  color: var(--color-text-secondary);
  font-size: var(--text-sm);
}

/* Status line: all states hidden by default; the `is-*` class on the
 * container (driven by payment.js) reveals the matching one. */
#hire-status {
  margin-top: var(--space-4);
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
}

#hire-status .status-idle,
#hire-status .status-pending,
#hire-status .status-paid,
#hire-status .status-failed { display: none; }

#hire-status.is-idle .status-idle { display: inline; }
#hire-status.is-pending .status-pending { display: inline; }
#hire-status.is-paid .status-paid { display: inline; }
#hire-status.is-failed .status-failed { display: inline; color: var(--color-danger); }

/* ---------------------------------------------------------------------------
 * Feedback states
 * ------------------------------------------------------------------------ */

#errors .toast {
  padding: 0.5rem 1rem;
  border-radius: var(--radius-sm);
  margin-bottom: var(--space-2);
  font-size: var(--text-sm);
}

#errors .toast.error { background: var(--color-danger-bg); color: var(--color-danger); }
#errors .toast.success { color: var(--color-success); }

.empty-state {
  padding: var(--space-12) var(--space-4);
  text-align: center;
  background: var(--color-surface);
  border: 1px dashed var(--color-border);
  border-radius: var(--radius-md);
  color: var(--color-text-secondary);
}

.empty-state p { margin: 0 0 var(--space-4); font-size: var(--text-lg); }

/* HTMX indicator: hidden until the request class lands on it. */
.loading {
  display: none;
  width: 20px;
  height: 20px;
  border: 2px solid var(--color-text-muted);
  border-top-color: transparent;
  border-radius: 50%;
  animation: loading-spin 0.8s linear infinite;
}

.loading.htmx-request { display: inline-block; }

@keyframes loading-spin {
  to { transform: rotate(360deg); }
}

/* ---------------------------------------------------------------------------
 * Pagination (aria-label stays on the nav)
 * ------------------------------------------------------------------------ */

.pagination {
  margin-top: var(--space-6);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
}

.pagination a,
.pagination button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  min-width: 40px;
  padding: 0 var(--space-3);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-text-secondary);
  font-family: inherit;
  font-size: var(--text-sm);
  text-decoration: none;
  cursor: pointer;
}

.pagination a:hover,
.pagination button:hover {
  color: var(--color-text);
  border-color: var(--color-accent);
}

.pagination a.active {
  background: var(--color-accent);
  border-color: var(--color-accent);
  color: #062a26;
  font-weight: var(--weight-semibold);
}

.pagination .ellipsis { color: var(--color-text-muted); padding: 0 var(--space-1); }

/* ---------------------------------------------------------------------------
 * Favorites
 * ------------------------------------------------------------------------ */

.favorites {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.fav-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-3) var(--space-4);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
}

.fav-card .fav-name { font-weight: var(--weight-semibold); }

/* ---------------------------------------------------------------------------
 * Auth
 * ------------------------------------------------------------------------ */

.auth { max-width: 640px; margin: 0 auto; }

.auth ol li { margin-bottom: var(--space-2); }

.auth code {
  padding: 2px 6px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
}

.warning { color: var(--color-warning); }

/* ---------------------------------------------------------------------------
 * Breakpoints (DESIGN.md: mobile <640, tablet 640–1023, desktop ≥1024)
 * ------------------------------------------------------------------------ */

@media (min-width: 640px) {
  .grid { grid-template-columns: repeat(2, 1fr); }
}

@media (min-width: 1024px) {
  .grid { grid-template-columns: repeat(3, 1fr); }
  /* 10 category cards in a 2×5 desktop grid (design D7; sdd/doc-refresh DSG-2) */
  .category-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    overflow-x: visible;
    padding-bottom: 0;
  }
  .category-card { flex: none; }
}

@media (min-width: 1280px) {
  .grid { grid-template-columns: repeat(4, 1fr); }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .loading { animation: none; }
}