// CRIMINAL JUSTICE PLATFORM — shared tokens (burgundy accent)
const Tcj = window.ArbiterTokens;

const cj = {
  // Accent — burgundy / gravity
  burgundy: '#9F1239',
  burgundyDeep: '#881337',
  burgundyLight: '#BE123C',
  burgundyBg: 'rgba(159,18,57,0.06)',
  burgundyBorder: 'rgba(159,18,57,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)',
  emerald: '#059669',
  emeraldBg: 'rgba(5,150,105,0.08)',
  teal: '#0D9488',
  tealBg: 'rgba(13,148,136,0.08)',
  violet: '#7C3AED',
  violetBg: 'rgba(124,58,237,0.08)',
  cobalt: '#1D4ED8',
  cobaltBg: 'rgba(29,78,216,0.06)',

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

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

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

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

  // Charge-class color (felony severity)
  classColor: (cls) => {
    const map = {
      'A':  { bg: 'rgba(185,28,28,0.12)', color: '#881337', label: 'Class A (life/death)' },
      'B':  { bg: 'rgba(159,18,57,0.10)', color: '#9F1239', label: 'Class B (25y-life)' },
      'C':  { bg: 'rgba(234,88,12,0.10)', color: '#EA580C', label: 'Class C (10-25y)' },
      'D':  { bg: 'rgba(180,83,9,0.10)',  color: '#B45309', label: 'Class D (5-10y)' },
      'E':  { bg: 'rgba(124,58,237,0.10)',color: '#7C3AED', label: 'Class E (1-5y)' },
      'Misd': { bg: 'rgba(71,85,105,0.08)', color: '#475569', label: 'Misdemeanor' },
    };
    return map[cls] || { bg: Tcj.color.bg.secondary, color: Tcj.color.text.secondary, label: cls };
  },

  // Case stage color
  stageColor: (s) => {
    const map = {
      'Investigation':     { bg: 'rgba(71,85,105,0.08)', color: '#475569' },
      'Charged — Pretrial':{ bg: 'rgba(29,78,216,0.08)', color: '#1D4ED8' },
      'Pretrial':          { bg: 'rgba(29,78,216,0.08)', color: '#1D4ED8' },
      'Plea Negotiations': { bg: 'rgba(124,58,237,0.08)',color: '#7C3AED' },
      'Trial':             { bg: 'rgba(159,18,57,0.08)', color: '#9F1239' },
      'Sentencing':        { bg: 'rgba(234,88,12,0.10)', color: '#EA580C' },
      'Appeal':            { bg: 'rgba(180,83,9,0.10)',  color: '#B45309' },
      'Post-Conviction':   { bg: 'rgba(13,148,136,0.08)',color: '#0D9488' },
      'Closed':            { bg: 'rgba(5,150,105,0.08)', color: '#059669' },
    };
    return map[s] || { bg: Tcj.color.bg.secondary, color: Tcj.color.text.secondary };
  },

  // Bail status color
  bailColor: (s) => {
    const map = {
      'Released O.R.':    { bg: 'rgba(5,150,105,0.08)', color: '#059669' },
      'Released — Bond':  { bg: 'rgba(5,150,105,0.08)', color: '#059669' },
      'Released — Conditions': { bg: 'rgba(13,148,136,0.08)', color: '#0D9488' },
      'Detained':         { bg: 'rgba(185,28,28,0.08)', color: '#B91C1C' },
      'Home Detention':   { bg: 'rgba(180,83,9,0.08)',  color: '#B45309' },
      'GPS Monitoring':   { bg: 'rgba(180,83,9,0.08)',  color: '#B45309' },
    };
    return map[s] || { bg: Tcj.color.bg.secondary, color: Tcj.color.text.secondary };
  },

  // Motion status color
  motionStatus: (s) => {
    const map = {
      'Filed':            { bg: 'rgba(29,78,216,0.08)', color: '#1D4ED8' },
      'Under Submission': { bg: 'rgba(124,58,237,0.08)',color: '#7C3AED' },
      'Granted':          { bg: 'rgba(5,150,105,0.08)', color: '#059669' },
      'Denied':           { bg: 'rgba(185,28,28,0.08)', color: '#B91C1C' },
      'Granted in Part':  { bg: 'rgba(180,83,9,0.10)',  color: '#B45309' },
      'Drafting':         { bg: 'rgba(71,85,105,0.08)', color: '#475569' },
    };
    return map[s] || { bg: Tcj.color.bg.secondary, color: Tcj.color.text.secondary };
  },

  // Format USSG range as "37-46 months" etc.
  guideline: (low, high) => `${low}-${high} mo`,
  // Criminal History Category I-VI colors
  chcColor: (cat) => {
    const v = { I: '#059669', II: '#0D9488', III: '#B45309', IV: '#EA580C', V: '#BE123C', VI: '#881337' };
    return v[cat] || '#475569';
  },
};

window.__cj = cj;
