// NEXUS PLATFORM — shared tokens (fuchsia accent · "the connection layer")
const Tn = window.ArbiterTokens;

const nx = {
  // Accent — fuchsia "linkage" palette
  fuchsia: '#C026D3',
  fuchsiaDeep: '#A21CAF',
  fuchsiaLight: '#E879F9',
  fuchsiaBg: 'rgba(192,38,211,0.06)',
  fuchsiaBorder: 'rgba(192,38,211,0.22)',
  // Entity-type palette (stable colors used across Graph, Canvas, Chains)
  person: '#A855F7',        // purple
  personBg: 'rgba(168,85,247,0.08)',
  org: '#3B82F6',           // blue
  orgBg: 'rgba(59,130,246,0.08)',
  doc: '#0D9488',           // teal
  docBg: 'rgba(13,148,136,0.08)',
  event: '#F59E0B',         // amber
  eventBg: 'rgba(245,158,11,0.08)',
  issue: '#C23030',         // red
  issueBg: 'rgba(194,48,48,0.08)',
  artifact: '#059669',      // emerald
  artifactBg: 'rgba(5,150,105,0.08)',
  // Link-type palette
  linkReferences: '#3B82F6',
  linkContradicts: '#C23030',
  linkCorroborates: '#059669',
  linkSentTo: '#C026D3',
  linkOwns: '#A855F7',
  linkOccurredBefore: '#F59E0B',
  linkAuthored: '#0D9488',
  linkIdentifiedAs: '#6E7D9E',

  slate: '#475569',
  slateBg: 'rgba(71,85,105,0.06)',
  crimson: '#B91C1C',
  crimsonBg: 'rgba(185,28,28,0.06)',

  container: { flex: 1, overflow: 'auto', background: Tn.color.bg.primary },
  header: {
    padding: '16px 24px', borderBottom: `1px solid ${Tn.color.border.light}`,
    background: Tn.color.bg.card, display: 'flex', alignItems: 'center', justifyContent: 'space-between',
  },
  headerTitle: { display: 'flex', alignItems: 'center', gap: '12px' },
  nxIcon: {
    width: '32px', height: '32px', borderRadius: '6px',
    background: 'linear-gradient(135deg, #C026D3 0%, #A21CAF 100%)',
    display: 'flex', alignItems: 'center', justifyContent: 'center',
    fontSize: '16px', fontWeight: 700, color: '#fff',
  },
  title: { fontSize: '18px', fontWeight: 700, color: Tn.color.text.primary, letterSpacing: '-0.02em' },
  subtitle: { fontSize: '12px', color: Tn.color.text.tertiary, marginTop: '1px' },
  tabs: {
    display: 'flex', gap: '0', borderBottom: `1px solid ${Tn.color.border.light}`,
    background: Tn.color.bg.card, padding: '0 24px',
  },
  tab: {
    padding: '10px 16px', fontSize: '12px', fontWeight: 500,
    color: Tn.color.text.tertiary, cursor: 'pointer', border: 'none', background: 'none',
    borderBottom: '2px solid transparent', fontFamily: Tn.font.family,
    transition: 'all 0.15s', marginBottom: '-1px', whiteSpace: 'nowrap',
  },
  tabActive: { color: '#C026D3', borderBottom: '2px solid #C026D3', fontWeight: 600 },
  body: { padding: '20px 24px' },

  card: { background: Tn.color.bg.card, border: `1px solid ${Tn.color.border.light}`, borderRadius: Tn.radius.lg, overflow: 'hidden', marginBottom: '16px' },
  cardH: { padding: '10px 16px', borderBottom: `1px solid ${Tn.color.border.light}`, fontSize: '12px', fontWeight: 600, color: Tn.color.text.primary, display: 'flex', alignItems: 'center', justifyContent: 'space-between' },

  stat: { display: 'flex', flexDirection: 'column', gap: '2px', padding: '12px 16px', background: Tn.color.bg.secondary, borderRadius: '6px', border: `1px solid ${Tn.color.border.light}` },
  statLabel: { fontSize: '10px', fontWeight: 600, color: Tn.color.text.tertiary, textTransform: 'uppercase', letterSpacing: '0.08em' },
  statValue: { fontSize: '22px', fontWeight: 700, letterSpacing: '-0.02em', lineHeight: 1.1, color: Tn.color.text.primary },
  statDelta: { fontSize: '10px', fontWeight: 500, marginTop: '2px' },

  tag: { display: 'inline-flex', alignItems: 'center', padding: '2px 8px', borderRadius: '10px', fontSize: '10px', fontWeight: 600 },
  pill: { display: 'inline-flex', alignItems: 'center', padding: '3px 10px', borderRadius: '12px', fontSize: '11px', fontWeight: 500, gap: '4px' },

  th: { fontSize: '10px', fontWeight: 600, color: Tn.color.text.tertiary, textTransform: 'uppercase', letterSpacing: '0.08em', padding: '8px 12px', textAlign: 'left', background: Tn.color.bg.secondary, borderBottom: `1px solid ${Tn.color.border.light}` },
  td: { fontSize: '12px', color: Tn.color.text.primary, padding: '10px 12px', borderBottom: `1px solid ${Tn.color.border.light}`, verticalAlign: 'middle' },

  btnPrimary: { padding: '6px 14px', borderRadius: '6px', background: '#C026D3', border: 'none', color: '#fff', fontSize: '12px', fontWeight: 700, cursor: 'pointer', fontFamily: Tn.font.family },
  btnSecondary: { padding: '5px 12px', borderRadius: '6px', border: `1px solid ${Tn.color.border.light}`, background: Tn.color.bg.card, fontSize: '11px', fontWeight: 500, color: Tn.color.text.secondary, cursor: 'pointer', fontFamily: Tn.font.family },
  btnGhost: { padding: '4px 10px', borderRadius: '5px', border: 'none', background: 'transparent', fontSize: '11px', fontWeight: 500, color: '#C026D3', cursor: 'pointer', fontFamily: Tn.font.family },

  // Entity-type color + icon helper
  typeStyle: (t) => {
    const map = {
      person: { bg: 'rgba(168,85,247,0.08)', color: '#A855F7', icon: '●', label: 'Person' },
      org: { bg: 'rgba(59,130,246,0.08)', color: '#3B82F6', icon: '◆', label: 'Organization' },
      document: { bg: 'rgba(13,148,136,0.08)', color: '#0D9488', icon: '▤', label: 'Document' },
      event: { bg: 'rgba(245,158,11,0.08)', color: '#F59E0B', icon: '◎', label: 'Event' },
      issue: { bg: 'rgba(194,48,48,0.08)', color: '#C23030', icon: '*', label: 'Issue' },
      artifact: { bg: 'rgba(5,150,105,0.08)', color: '#059669', icon: '▢', label: 'Artifact' },
      amount: { bg: 'rgba(5,150,105,0.08)', color: '#059669', icon: '$', label: 'Amount' },
      date: { bg: 'rgba(245,158,11,0.08)', color: '#F59E0B', icon: '▦', label: 'Date' },
    };
    return map[t] || { bg: Tn.color.bg.secondary, color: Tn.color.text.secondary, icon: '·', label: t };
  },

  // Link-type color + verb
  linkStyle: (t) => {
    const map = {
      references: { color: '#3B82F6', label: 'references' },
      contradicts: { color: '#C23030', label: 'contradicts' },
      corroborates: { color: '#059669', label: 'corroborates' },
      'sent-to': { color: '#C026D3', label: 'sent to' },
      owns: { color: '#A855F7', label: 'owns / controls' },
      'occurred-before': { color: '#F59E0B', label: 'occurred before' },
      authored: { color: '#0D9488', label: 'authored' },
      'identified-as': { color: '#6E7D9E', label: 'identified as' },
      'supports': { color: '#059669', label: 'supports' },
      'rebuts': { color: '#C23030', label: 'rebuts' },
      'caused': { color: '#F59E0B', label: 'caused' },
      'produced': { color: '#F59E0B', label: 'produced' },
    };
    return map[t] || { color: '#6E7D9E', label: t };
  },

  num: (n) => n == null ? '—' : n.toLocaleString(),
};

window.__nx = nx;
