// DISCOVERY PLATFORM — shared tokens (cobalt accent)
const Td = window.ArbiterTokens;

const dc = {
  // Accent — cobalt / deep dive blue
  cobalt: '#1D4ED8',
  cobaltDeep: '#1E3A8A',
  cobaltLight: '#3B82F6',
  cobaltBg: 'rgba(29,78,216,0.06)',
  cobaltBorder: 'rgba(29,78,216,0.22)',
  teal: '#0D9488',
  tealBg: 'rgba(13,148,136,0.08)',
  amber: '#B45309',
  amberBg: 'rgba(180,83,9,0.08)',
  orange: '#EA580C',
  orangeBg: 'rgba(234,88,12,0.08)',
  crimson: '#B91C1C',
  crimsonBg: 'rgba(185,28,28,0.08)',
  violet: '#7C3AED',
  violetBg: 'rgba(124,58,237,0.08)',
  emerald: '#059669',
  emeraldBg: 'rgba(5,150,105,0.08)',
  slate: '#475569',
  slateBg: 'rgba(71,85,105,0.06)',

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

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

  stat: { display: 'flex', flexDirection: 'column', gap: '2px', padding: '12px 16px', background: Td.color.bg.secondary, borderRadius: '6px', border: `1px solid ${Td.color.border.light}` },
  statLabel: { fontSize: '10px', fontWeight: 600, color: Td.color.text.tertiary, textTransform: 'uppercase', letterSpacing: '0.08em' },
  statValue: { fontSize: '22px', fontWeight: 700, letterSpacing: '-0.02em', lineHeight: 1.1, color: Td.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: Td.color.text.tertiary, textTransform: 'uppercase', letterSpacing: '0.08em', padding: '8px 12px', textAlign: 'left', background: Td.color.bg.secondary, borderBottom: `1px solid ${Td.color.border.light}` },
  td: { fontSize: '12px', color: Td.color.text.primary, padding: '10px 12px', borderBottom: `1px solid ${Td.color.border.light}`, verticalAlign: 'middle' },

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

  // EDRM-stage color helper
  edrmColor: (stage) => ({
    'Identify': { bg: 'rgba(71,85,105,0.08)', color: '#475569' },
    'Preserve': { bg: 'rgba(124,58,237,0.08)', color: '#7C3AED' },
    'Collect': { bg: 'rgba(13,148,136,0.08)', color: '#0D9488' },
    'Process': { bg: 'rgba(29,78,216,0.08)', color: '#1D4ED8' },
    'Review': { bg: 'rgba(180,83,9,0.08)', color: '#B45309' },
    'Analyze': { bg: 'rgba(234,88,12,0.08)', color: '#EA580C' },
    'Produce': { bg: 'rgba(5,150,105,0.08)', color: '#059669' },
    'Present': { bg: 'rgba(185,28,28,0.08)', color: '#B91C1C' },
  }[stage] || { bg: Td.color.bg.secondary, color: Td.color.text.secondary }),

  // Status color helpers
  statusColor: (s) => {
    const map = {
      'Complete': { bg: 'rgba(5,150,105,0.08)', color: '#059669' },
      'Complete ok': { bg: 'rgba(5,150,105,0.08)', color: '#059669' },
      'Active': { bg: 'rgba(29,78,216,0.08)', color: '#1D4ED8' },
      'In Progress': { bg: 'rgba(29,78,216,0.08)', color: '#1D4ED8' },
      'In Review': { bg: 'rgba(180,83,9,0.08)', color: '#B45309' },
      'Pending': { bg: 'rgba(180,83,9,0.08)', color: '#B45309' },
      'Queued': { bg: 'rgba(71,85,105,0.08)', color: '#475569' },
      'Blocked': { bg: 'rgba(185,28,28,0.08)', color: '#B91C1C' },
      'Failed': { bg: 'rgba(185,28,28,0.08)', color: '#B91C1C' },
      'Disputed': { bg: 'rgba(185,28,28,0.08)', color: '#B91C1C' },
      'Acknowledged': { bg: 'rgba(5,150,105,0.08)', color: '#059669' },
      'Released': { bg: 'rgba(71,85,105,0.08)', color: '#475569' },
      'Ready': { bg: 'rgba(13,148,136,0.08)', color: '#0D9488' },
      'Sent': { bg: 'rgba(5,150,105,0.08)', color: '#059669' },
      'Received': { bg: 'rgba(5,150,105,0.08)', color: '#059669' },
      'Draft': { bg: Td.color.bg.secondary, color: Td.color.text.secondary },
      'Served': { bg: 'rgba(29,78,216,0.08)', color: '#1D4ED8' },
      'Responded': { bg: 'rgba(5,150,105,0.08)', color: '#059669' },
      'Supplemented': { bg: 'rgba(234,88,12,0.08)', color: '#EA580C' },
      'Overdue': { bg: 'rgba(185,28,28,0.08)', color: '#B91C1C' },
    };
    return map[s] || { bg: Td.color.bg.secondary, color: Td.color.text.secondary };
  },

  // Number formatters
  num: (n) => n == null ? '—' : n.toLocaleString(),
  bytes: (gb) => {
    if (gb == null) return '—';
    if (gb >= 1024) return `${(gb / 1024).toFixed(2)} TB`;
    if (gb >= 1) return `${gb.toFixed(1)} GB`;
    return `${(gb * 1024).toFixed(0)} MB`;
  },
};

window.__dc = dc;
