// AUTOMATION PLATFORM — shared tokens (lime-green accent · flow / triggers / workflows)
const Tau = window.ArbiterTokens;

const au = {
  // Accent — lime / flow energy
  lime: '#65A30D',
  limeDeep: '#3F6212',
  limeLight: '#84CC16',
  limeBg: 'rgba(101,163,13,0.06)',
  limeBorder: 'rgba(101,163,13,0.22)',
  // Palette
  slate: '#475569',
  slateBg: 'rgba(71,85,105,0.06)',
  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)',
  emerald: '#059669',
  emeraldBg: 'rgba(5,150,105,0.08)',
  teal: '#0D9488',
  tealBg: 'rgba(13,148,136,0.06)',
  cobalt: '#1D4ED8',
  cobaltBg: 'rgba(29,78,216,0.06)',
  violet: '#7C3AED',
  violetBg: 'rgba(124,58,237,0.06)',
  fuchsia: '#C026D3',
  fuchsiaBg: 'rgba(192,38,211,0.06)',

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

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

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

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

  // Task / run status color
  statusColor: (s) => {
    const map = {
      'To Do':        { bg: 'rgba(71,85,105,0.08)',  color: '#475569' },
      'In Progress':  { bg: 'rgba(29,78,216,0.08)',  color: '#1D4ED8' },
      'Running':      { bg: 'rgba(101,163,13,0.08)', color: '#65A30D' },
      'Waiting':      { bg: 'rgba(180,83,9,0.08)',   color: '#B45309' },
      'Blocked':      { bg: 'rgba(185,28,28,0.08)',  color: '#B91C1C' },
      'Completed':    { bg: 'rgba(5,150,105,0.08)',  color: '#059669' },
      'Succeeded':    { bg: 'rgba(5,150,105,0.08)',  color: '#059669' },
      'Cancelled':    { bg: Tau.color.bg.secondary,   color: Tau.color.text.tertiary },
      'Failed':       { bg: 'rgba(185,28,28,0.08)',  color: '#B91C1C' },
      'Scheduled':    { bg: 'rgba(124,58,237,0.08)', color: '#7C3AED' },
      'Paused':       { bg: 'rgba(180,83,9,0.08)',   color: '#B45309' },
      'Active':       { bg: 'rgba(101,163,13,0.08)', color: '#65A30D' },
      'Draft':        { bg: Tau.color.bg.secondary,  color: Tau.color.text.secondary },
      'Deprecated':   { bg: Tau.color.bg.secondary,  color: Tau.color.text.tertiary },
    };
    return map[s] || { bg: Tau.color.bg.secondary, color: Tau.color.text.secondary };
  },

  // Priority color
  priorityColor: (p) => {
    if (p === 'critical' || p === 'P0') return { bg: 'rgba(185,28,28,0.08)', color: '#B91C1C' };
    if (p === 'high' || p === 'P1')     return { bg: 'rgba(234,88,12,0.08)', color: '#EA580C' };
    if (p === 'medium' || p === 'P2')   return { bg: 'rgba(180,83,9,0.08)',  color: '#B45309' };
    if (p === 'low' || p === 'P3')      return { bg: Tau.color.bg.secondary,  color: Tau.color.text.secondary };
    return { bg: Tau.color.bg.secondary, color: Tau.color.text.secondary };
  },

  // Trigger kind icon + color
  triggerStyle: (k) => {
    const map = {
      'Schedule (cron)':      { bg: 'rgba(124,58,237,0.08)', color: '#7C3AED', icon: '▦' },
      'Event':                 { bg: 'rgba(101,163,13,0.08)', color: '#65A30D', icon: '◆' },
      'Webhook':               { bg: 'rgba(29,78,216,0.08)',  color: '#1D4ED8', icon: '↯' },
      'Document trigger':      { bg: 'rgba(13,148,136,0.08)', color: '#0D9488', icon: '▤' },
      'Manual':                { bg: Tau.color.bg.secondary,  color: Tau.color.text.secondary, icon: '▶' },
      'Deadline':              { bg: 'rgba(234,88,12,0.08)',  color: '#EA580C', icon: '◷' },
      'Matter stage change':   { bg: 'rgba(192,38,211,0.08)', color: '#C026D3', icon: '◑' },
      'Client action':         { bg: 'rgba(29,78,216,0.08)',  color: '#1D4ED8', icon: '●' },
      'Email received':        { bg: 'rgba(29,78,216,0.08)',  color: '#1D4ED8', icon: '▸' },
      'Approval granted':      { bg: 'rgba(5,150,105,0.08)',  color: '#059669', icon: 'ok' },
    };
    return map[k] || { bg: Tau.color.bg.secondary, color: Tau.color.text.secondary, icon: '◆' };
  },

  // Integration / connector icon
  integrationStyle: (kind) => {
    const map = {
      'Email':        { bg: 'rgba(29,78,216,0.08)',  color: '#1D4ED8', icon: '▸' },
      'Chat':         { bg: 'rgba(124,58,237,0.08)', color: '#7C3AED', icon: '▸' },
      'Cloud':        { bg: 'rgba(8,145,178,0.08)',  color: '#0891B2', icon: '◇' },
      'File Share':   { bg: 'rgba(8,145,178,0.08)',  color: '#0891B2', icon: '◇' },
      'DMS':          { bg: 'rgba(13,148,136,0.08)', color: '#0D9488', icon: '▤' },
      'Finance':      { bg: 'rgba(5,150,105,0.08)',  color: '#059669', icon: '$' },
      'Ticketing':    { bg: 'rgba(234,88,12,0.08)',  color: '#EA580C', icon: '•' },
      'Notification': { bg: 'rgba(180,83,9,0.08)',   color: '#B45309', icon: '◈' },
      'Identity':     { bg: 'rgba(192,38,211,0.08)', color: '#C026D3', icon: '◉' },
      'Calendar':     { bg: 'rgba(101,163,13,0.08)', color: '#65A30D', icon: '▦' },
      'API':          { bg: Tau.color.bg.secondary,  color: Tau.color.text.secondary, icon: 'cmd' },
    };
    return map[kind] || { bg: Tau.color.bg.secondary, color: Tau.color.text.secondary, icon: '◆' };
  },

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

window.__au = au;
