:root {
  --bg: #0b0d10;
  --card: #14181d;
  --fg: #e6e9ef;
  --muted: #8a93a3;
  --accent: #4ade80;
  --danger: #ef4444;
  --nav-height: 56px;
}
* { box-sizing: border-box; }

/* ═══════════════════════════════════════════
   SHARED NAV — responsive, all pages
   ═══════════════════════════════════════════ */
.site-nav {
  position: sticky; top: 0; z-index: 900;
  background: rgba(11, 13, 16, 0.95);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid #1f242c;
}
.site-nav-inner {
  max-width: 960px; margin: 0 auto;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 1.5rem; height: var(--nav-height);
}

/* Brand: Browser(white) Server(green) */
.site-nav-brand {
  font-family: ui-monospace, 'SF Mono', 'Fira Code', monospace;
  font-size: 1.25rem; font-weight: 700; text-decoration: none;
  white-space: nowrap; letter-spacing: -0.02em;
}
.brand-browser { color: var(--fg); }
.brand-server { color: var(--accent); }

/* Links */
.site-nav-links {
  display: flex; align-items: center; gap: 1.75rem;
}
.site-nav-link {
  color: var(--muted); text-decoration: none; font-size: 0.85rem;
  position: relative; padding-bottom: 2px;
  transition: color 0.2s;
}
.site-nav-link::after {
  content: ''; position: absolute; left: 0; bottom: -2px;
  width: 0; height: 1.5px; background: var(--accent);
  transition: width 0.2s ease;
}
.site-nav-link:hover { color: var(--fg); text-decoration: none; }
.site-nav-link:hover::after { width: 100%; }
.site-nav-link.active { color: var(--fg); }
.site-nav-link.active::after { width: 100%; }

/* Points balance pill in nav */
.site-nav-points {
  display: inline-flex; align-items: baseline; gap: 0.3rem;
  padding: 0.3rem 0.65rem; border-radius: 5px;
  background: rgba(74, 222, 128, 0.1); border: 1px solid rgba(74, 222, 128, 0.25);
  text-decoration: none; transition: all 0.15s;
  font-family: ui-monospace, 'SF Mono', monospace;
}
.site-nav-points:hover { background: rgba(74, 222, 128, 0.15); border-color: var(--accent); text-decoration: none; }
.site-nav-points strong { color: var(--accent); font-size: 0.9rem; font-weight: 700; }
.site-nav-points-lbl { color: var(--muted); font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.05em; }
.site-nav-points::after { display: none; }

@media (max-width: 640px) {
  .site-nav-points { font-size: 0.75rem; padding: 0.25rem 0.5rem; }
}

/* User avatar + dropdown in nav */
.site-nav-user-wrap { position: relative; }
.site-nav-user-btn {
  background: none; border: none; cursor: pointer; padding: 2px;
  border-radius: 50%; transition: box-shadow 0.15s;
}
.site-nav-user-btn:hover { box-shadow: 0 0 0 2px var(--accent); }
.site-nav-avatar {
  width: 28px; height: 28px; border-radius: 50%; vertical-align: middle;
  border: 1.5px solid #333; display: block;
}
.site-nav-avatar-fallback {
  width: 28px; height: 28px; border-radius: 50%; display: flex;
  align-items: center; justify-content: center;
  background: var(--accent); color: var(--bg); font-weight: 700;
  font-size: 0.75rem; border: 1.5px solid #333;
}

/* User dropdown */
.site-nav-user-dropdown {
  display: none; position: absolute; top: calc(100% + 0.5rem); right: 0;
  background: var(--card); border: 1px solid #1f242c; border-radius: 8px;
  min-width: 240px; z-index: 1000; overflow: hidden;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}
.site-nav-user-dropdown.open { display: block; }
.user-dropdown-header {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 1rem; border-bottom: 1px solid #1f242c;
}
.user-dropdown-avatar {
  width: 36px; height: 36px; border-radius: 50%; border: 1px solid #333;
}
.user-dropdown-name { font-size: 0.85rem; font-weight: 600; color: var(--fg); }
.user-dropdown-email { font-size: 0.72rem; color: var(--muted); margin-top: 1px; }
.user-dropdown-item {
  display: block; padding: 0.6rem 1rem; font-size: 0.82rem;
  color: var(--muted); text-decoration: none; transition: background 0.15s;
}
.user-dropdown-item:hover { background: #1f242c; color: var(--fg); text-decoration: none; }
.user-dropdown-signout:hover { color: var(--danger); }

/* Sign-in dropdown */
.site-nav-signin-wrap { position: relative; }
.site-nav-signin {
  background: var(--accent); color: var(--bg); padding: 0.4rem 1rem;
  border-radius: 5px; font-weight: 600; font-size: 0.82rem;
  border: none; cursor: pointer; font-family: inherit;
}
.site-nav-signin:hover { opacity: 0.9; }
.site-nav-signin-dropdown {
  display: none; position: absolute; top: calc(100% + 0.5rem); right: 0;
  background: var(--card); border: 1px solid #1f242c; border-radius: 8px;
  padding: 0.5rem; min-width: 220px; z-index: 1000;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}
.site-nav-signin-dropdown.open { display: block; }
.signin-option {
  display: flex; align-items: center; gap: 0.6rem;
  padding: 0.6rem 0.75rem; border-radius: 6px; text-decoration: none;
  color: var(--fg); font-size: 0.85rem; transition: background 0.15s;
}
.signin-option:hover { background: #1f242c; text-decoration: none; }

/* Sign out */
.site-nav-signout { opacity: 0.5; font-size: 0.78rem; }
.site-nav-signout::after { display: none; }
.site-nav-signout:hover { opacity: 1; color: var(--danger); }

/* Icons show on both desktop and mobile. Desktop keeps the text label
   next to the icon; mobile hides the label to save room for the avatar
   (see media query below). */
.site-nav-link { display: inline-flex; align-items: center; gap: 0.4rem; }
.nav-icon {
  display: inline-block; width: 16px; height: 16px;
  vertical-align: middle; flex-shrink: 0;
}

/* Mobile — same layout as desktop, just tighter. No hamburger.
   Generate / Use / points / avatar all stay in the top bar. Links
   swap their text label for an icon so the avatar stays in view. */
@media (max-width: 640px) {
  .site-nav-inner { padding: 0 0.75rem; gap: 0.5rem; }
  .site-nav-brand { font-size: 0.95rem; letter-spacing: -0.01em; }
  .site-nav-links { gap: 0.6rem; }
  .site-nav-link { padding: 0.4rem; font-size: 0.82rem; gap: 0; }
  .site-nav-link::after { display: none; }
  .nav-icon { width: 20px; height: 20px; }
  .nav-label { display: none; }
  .site-nav-points { font-size: 0.75rem; padding: 0.25rem 0.5rem; gap: 0.25rem; }
  .site-nav-points-lbl { display: none; }
  .site-nav-avatar, .site-nav-avatar-fallback { width: 26px; height: 26px; }
  /* Keep dropdowns anchored to their button and readable at narrow widths */
  .site-nav-user-dropdown, .site-nav-signin-dropdown {
    min-width: 220px; max-width: calc(100vw - 1.5rem);
  }
}

/* Narrower phones — shave further so the brand doesn't wrap. */
@media (max-width: 400px) {
  .site-nav-brand { font-size: 0.88rem; }
  .brand-server { display: none; }
}

body {
  margin: 0;
  font-family: -apple-system, system-ui, sans-serif;
  background: var(--bg);
  color: var(--fg);
  min-height: 100vh;
}
main { width: min(720px, 92vw); margin: 0 auto; padding: 1.5rem 1rem; }
header { text-align: center; margin-bottom: 1.5rem; }
h1 { margin: 0; font-size: 2rem; letter-spacing: -0.02em; }
.tagline { color: var(--muted); margin: 0.25rem 0 0; }
.card {
  background: var(--card);
  border-radius: 12px;
  padding: 1.5rem;
  border: 1px solid #1f242c;
}
.row {
  display: flex;
  gap: 1.5rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
  align-items: center;
}
.label { color: var(--muted); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em; }
.value { font-size: 1.25rem; font-weight: 600; }
button {
  background: var(--accent);
  color: #0b0d10;
  border: 0;
  padding: 0.6rem 1.1rem;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
}
button.danger { background: var(--danger); color: white; }
button:disabled { opacity: 0.5; cursor: not-allowed; }
.log {
  background: #0b0d10;
  border: 1px solid #1f242c;
  border-radius: 8px;
  padding: 0.75rem;
  font-family: ui-monospace, monospace;
  font-size: 0.75rem;
  color: var(--muted);
  height: 12rem;
  overflow-y: auto;
  white-space: pre-wrap;
}
footer { text-align: center; color: var(--muted); margin-top: 1rem; }

/* ---- supplier model status ------------------------------------------- */
.model-status {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  padding: 0.6rem 0.85rem;
  background: #0b0d10;
  border: 1px solid #1f242c;
  border-radius: 8px;
  min-height: 48px;
  margin-bottom: 0.75rem;
}
.model-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.82rem;
}
.model-badge {
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  white-space: nowrap;
}
.model-badge.ready { background: rgba(74,222,128,0.15); color: var(--accent); }
.model-badge.loading { background: rgba(251,191,36,0.12); color: #fbbf24; }
.model-badge.skipped { background: rgba(138,147,163,0.12); color: var(--muted); }
.model-badge.error { background: rgba(239,68,68,0.12); color: var(--danger); }
.model-bar {
  flex: 1;
  height: 6px;
  background: #1f242c;
  border-radius: 999px;
  overflow: hidden;
  min-width: 60px;
}
.model-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #fbbf24, #f59e0b);
  border-radius: 999px;
  transition: width 400ms ease;
}
.model-pct {
  font-size: 0.72rem;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  min-width: 2.5rem;
  text-align: right;
}

/* ---- supplier capacity sliders ---------------------------------------- */
.sliders {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  background: #0b0d10;
  border: 1px solid #1f242c;
  border-radius: 8px;
  margin-bottom: 1rem;
}
.slider-row {
  display: grid;
  grid-template-columns: 9rem 1fr 5rem;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.85rem;
}
.slider-row label {
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-size: 0.7rem;
}
.slider-row input[type="range"] {
  appearance: none;
  -webkit-appearance: none;
  height: 4px;
  background: #1f242c;
  border-radius: 999px;
  outline: none;
}
.slider-row input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  box-shadow: 0 0 0 3px rgba(74,222,128,0.15);
}
.slider-row input[type="range"]::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
}
.slider-row output {
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: var(--fg);
  font-weight: 600;
  font-size: 0.85rem;
}
.slider-row select {
  background: #14181d;
  color: var(--fg);
  border: 1px solid #1f242c;
  padding: 0.35rem 0.5rem;
  border-radius: 6px;
  font-size: 0.8rem;
}

/* ---- buyer page ------------------------------------------------------- */
.buy-main { width: min(960px, 94vw); }
.row.between { justify-content: space-between; width: 100%; }
.muted { color: var(--muted); font-size: 0.85rem; }
button.ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid #1f242c;
}
button.ghost:hover { color: var(--fg); border-color: #2d333d; }

.auth-tabs { display: flex; gap: 0.5rem; margin: 0.75rem 0 1rem; }
.tab-btn {
  background: transparent;
  color: var(--muted);
  border: 1px solid #1f242c;
  padding: 0.4rem 0.9rem;
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
}
.tab-btn.active {
  background: #14181d;
  color: var(--fg);
  border-color: #2d333d;
}

.auth-form { display: flex; flex-direction: column; gap: 0.75rem; }
.form-row {
  display: grid;
  grid-template-columns: 8rem 1fr auto;
  gap: 0.75rem;
  align-items: center;
  margin-bottom: 0.75rem;
}
.form-row > span {
  color: var(--muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.form-row input[type="text"],
.form-row input[type="number"],
.form-row input[type="password"],
.form-row select,
.form-row textarea {
  background: #0b0d10;
  color: var(--fg);
  border: 1px solid #1f242c;
  padding: 0.55rem 0.75rem;
  border-radius: 8px;
  font-size: 0.9rem;
  font-family: inherit;
  width: 100%;
}
.form-row textarea { font-family: ui-monospace, monospace; resize: vertical; }
.form-row output {
  color: var(--muted);
  font-size: 0.75rem;
  white-space: nowrap;
}
.hint { color: var(--muted); font-size: 0.75rem; }

.payload-input { display: flex; flex-direction: column; gap: 0.4rem; }

.key-banner {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: #0f1f12;
  border-color: #1d3d23;
}
.key-banner code {
  flex: 1;
  font-family: ui-monospace, monospace;
  font-size: 0.85rem;
  word-break: break-all;
  color: var(--accent);
}

/* --- chunk cards (live job view) --- */
.chunks {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 0.75rem;
  margin: 0.75rem 0;
}
.chunk-card {
  background: #0b0d10;
  border: 1px solid #1f242c;
  border-radius: 8px;
  padding: 0.7rem 0.85rem;
}
.chunk-seq { font-size: 0.7rem; color: var(--muted); text-transform: uppercase; }
.chunk-status {
  font-size: 0.9rem;
  font-weight: 600;
  margin: 0.3rem 0;
}
.chunk-status[data-status="completed"],
.chunk-status[data-status="accepted"] { color: var(--accent); }
.chunk-status[data-status="disputed"],
.chunk-status[data-status="failed"],
.chunk-status[data-status="slashed"] { color: var(--danger); }
.chunk-status[data-status="pending"],
.chunk-status[data-status="needs_tiebreaker"] { color: #fbbf24; }
.chunk-attempts { display: flex; gap: 4px; margin-top: 0.3rem; }
.slot {
  flex: 1;
  height: 4px;
  background: #1f242c;
  border-radius: 999px;
  transition: background 200ms ease;
}
.slot[data-status="completed"],
.slot[data-status="accepted"],
.slot[data-status="ok"] { background: var(--accent); }
.slot[data-status="disputed"],
.slot[data-status="failed"],
.slot[data-status="slashed"] { background: var(--danger); }
.slot[data-status="pending"] { background: #fbbf24; }

/* --- history table --- */
.history {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
  margin-top: 0.75rem;
}
.history th {
  text-align: left;
  color: var(--muted);
  text-transform: uppercase;
  font-size: 0.7rem;
  letter-spacing: 0.04em;
  padding: 0.5rem 0.5rem;
  border-bottom: 1px solid #1f242c;
}
.history td {
  padding: 0.5rem 0.5rem;
  border-bottom: 1px solid #141820;
  font-variant-numeric: tabular-nums;
}
.history code {
  font-family: ui-monospace, monospace;
  color: var(--muted);
}
.badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.badge-completed { background: rgba(74,222,128,0.15); color: var(--accent); }
.badge-running   { background: rgba(251,191,36,0.15); color: #fbbf24; }
.badge-failed    { background: rgba(239,68,68,0.15); color: var(--danger); }
.badge-queued    { background: rgba(138,147,163,0.15); color: var(--muted); }

/* ---- chat history --------------------------------------------------- */
.chat-history {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  padding: 0.75rem 0.25rem;
  max-height: 26rem;
  overflow-y: auto;
  margin-bottom: 0.75rem;
  border-bottom: 1px solid #1f242c;
}
.chat-msg {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}
.chat-msg .who {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}
.chat-msg .bubble {
  background: #14181d;
  border: 1px solid #1f242c;
  border-radius: 10px;
  padding: 0.7rem 0.9rem;
  font-size: 0.92rem;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}
.chat-msg.user .bubble {
  background: #0f1f12;
  border-color: #1d3d23;
}
.chat-msg.pending .bubble {
  color: var(--muted);
  font-style: italic;
}
.sources {
  margin-top: 0.4rem;
  font-size: 0.8rem;
}
.llm-pending {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  margin-bottom: 0.3rem;
  background: rgba(251,191,36,0.12);
  color: #fbbf24;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  animation: pulse 1.6s ease-in-out infinite;
}
.sources summary {
  cursor: pointer;
  color: var(--muted);
  padding: 0.2rem 0;
}
.sources ol {
  margin: 0.4rem 0 0 1.2rem;
  padding: 0;
  color: var(--fg);
}
.sources li { margin-bottom: 0.25rem; }

/* ---- live dashboard (stats.html) -------------------------------------- */
.dash-main { width: min(960px, 94vw); margin: 0 auto; padding: 1.5rem 1rem; }
.nav { display: flex; gap: 1rem; justify-content: center; margin-bottom: 1rem; }
.nav a { color: var(--muted); text-decoration: none; font-size: 0.85rem; padding: 0.35rem 0.75rem; border-radius: 6px; }
.nav a.active { color: var(--fg); background: #1f242c; }
.nav a:hover { color: var(--fg); }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 1rem;
}
.stat {
  background: var(--card);
  border: 1px solid #1f242c;
  border-radius: 12px;
  padding: 1.1rem 1.25rem;
  position: relative;
}
.stat .label { margin-bottom: 0.35rem; }
.stat .big {
  font-size: 2.1rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
  transition: color 180ms ease;
}
.stat .sub {
  color: var(--muted);
  font-size: 0.75rem;
  margin-top: 0.2rem;
}
.stat.flash .big { color: var(--accent); }

.histogram {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 0.6rem;
}
.bar-row { display: flex; align-items: center; gap: 0.6rem; font-size: 0.8rem; }
.bar-row .tier-label {
  width: 5.5rem;
  color: var(--muted);
  text-transform: uppercase;
  font-size: 0.7rem;
  letter-spacing: 0.04em;
}
.bar-track {
  flex: 1;
  height: 8px;
  background: #0b0d10;
  border: 1px solid #1f242c;
  border-radius: 999px;
  overflow: hidden;
}
.bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #22c55e, #4ade80);
  border-radius: 999px;
  transition: width 500ms cubic-bezier(.2,.8,.2,1);
}
.bar-row .n {
  width: 2rem;
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: var(--fg);
}

.freshness {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--muted);
  font-size: 0.75rem;
  margin-top: 0.5rem;
  justify-content: center;
}
.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent);
  animation: pulse 1.6s ease-in-out infinite;
}
.dot.stale { background: var(--danger); box-shadow: 0 0 8px var(--danger); animation: none; }
@keyframes pulse {
  0%, 100% { opacity: 0.45; }
  50%      { opacity: 1; }
}
