/* lib.jsx — tokens, data, shared primitives for 加油站法律 AI 助手 */

const C = {
  brand:'#3B6EF6', brandStrong:'#2D5FF0', brandSoft:'#A9C7F5',
  hero:'linear-gradient(168deg,#4B7BF7 0%,#3B6EF6 60%,#2D5FF0 100%)',
  avatarGrad:'linear-gradient(150deg,#6E7BF0 0%,#7B5BE8 100%)',
  ai:'#7B5BE8',
  bg:'#EEF2F9', card:'#FFFFFF', chip:'#F0F2F5', line:'#E6EAF1',
  ink:'#1B1F27', ink2:'#6B7280', ink3:'#9AA3B2', onBrand:'#FFFFFF',
};

const GRADS = [
  'linear-gradient(150deg,#6E7BF0 0%,#7B5BE8 100%)',
  'linear-gradient(150deg,#4B7BF7 0%,#2D5FF0 100%)',
  'linear-gradient(150deg,#56B0E6 0%,#3B6EF6 100%)',
  'linear-gradient(150deg,#8A8DF2 0%,#9B6BE8 100%)',
  'linear-gradient(150deg,#4FC6D8 0%,#4B7BF7 100%)',
];

// ── Agent / lawyer-team data ───────────────────────────────────────────────
const AGENTS = [
  {
    id:'wtk', char:'汪', name:'汪天可律师团队', person:'汪天可',
    subtitle:'加油站 · 律师AI分身', org:'金牌律所', level:'一级律所',
    firm:'北京盈科（油气）律师事务所',
    field:'加油站合规', team:true, plainAvatar:true,
    tags:['加油站合规','安全生产','环保管理'],
    skill:'专注于加油站全生命周期合规、风险管理和法律服务。涵盖加油站设立审批、运营合规、安全检查、环保要求、消防管理等各环节法律风险防控。',
    intro:'团队由 12 名资深律师组成，平均执业年限 15 年，长期服务于中石油、中石化等大型能源企业，累计办理油气领域案件 800+ 起，常年法律顾问单位 60 余家。',
    awards:'2023 年度「能源行业最佳法律服务团队」；连续五年获评钱伯斯能源与基础设施领域推荐律师团队；多个案例入选最高人民法院典型案例。',
    consults:'12.8 万人咨询',
    questions:['加油站设立需要哪些行政审批？','油站消防检查不合格怎么整改？','危化品经营许可证如何办理？'],
  },
  {
    id:'ljg', char:'李', name:'李建国律师团队', person:'李建国',
    subtitle:'安全生产 · 律师AI分身', org:'司法部认证', level:'一级律所',
    firm:'中油安全法律服务中心', field:'安全生产',
    tags:['安全生产','消防管理','应急处置'],
    skill:'专注于安全生产责任认定、消防安全管理、危化品储运合规，以及生产安全事故的应急法律处置与责任划分。',
    intro:'团队深耕能源安全合规十余年，参与多项行业安全标准起草，为大型油气企业提供常态化安全合规体系建设。',
    awards:'应急管理领域优秀法律服务机构；多名律师受聘为省级安全生产专家。',
    consults:'9.6 万人咨询',
    questions:['油站发生安全事故如何划分责任？','安全生产许可证到期怎么续办？','员工违规操作企业要担责吗？'],
  },
  {
    id:'zhm', char:'张', name:'张慧敏律师团队', person:'张慧敏',
    subtitle:'环保管理 · 律师AI分身', org:'中华全国律协', level:'一级律所',
    firm:'北京环达律师事务所', field:'环保管理',
    tags:['环保管理','危废处置','环评合规'],
    skill:'专注于环境影响评价、土壤与地下水污染防治、危险废物处置合规，以及环保行政处罚的应对与行政复议。',
    intro:'团队聚焦能源与化工环保合规，拥有环境工程与法律复合背景顾问，提供从环评到验收的全流程支持。',
    awards:'环境资源法律服务示范团队；多起油气污染纠纷代理获评行业典型。',
    consults:'7.3 万人咨询',
    questions:['加油站油气回收不达标会被罚吗？','土壤检测超标如何应对处罚？','危废处置合同要注意什么？'],
  },
  {
    id:'czy', char:'陈', name:'陈志远律师团队', person:'陈志远',
    subtitle:'劳动用工 · 律师AI分身', org:'金牌律所', level:'一级律所',
    firm:'大成（能源）律师事务所', field:'劳动用工',
    tags:['劳动用工','工伤认定','争议仲裁'],
    skill:'专注于油站员工劳动合同管理、工伤认定、用工风险防控，以及劳动争议的仲裁与诉讼代理。',
    intro:'团队为连锁油站及能源企业提供用工合规体检与争议批量处理，年均处理劳动争议案件 200+ 起。',
    awards:'劳动与社会保障领域推荐律师团队；多次为大型企业完成用工合规改造。',
    consults:'6.1 万人咨询',
    questions:['油站员工工伤怎么认定和赔偿？','劳务派遣用工有什么风险？','员工旷工能否直接辞退？'],
  },
  {
    id:'wlj', char:'王', name:'王立军律师团队', person:'王立军',
    subtitle:'合同纠纷 · 律师AI分身', org:'司法部认证', level:'一级律所',
    firm:'京师律师事务所', field:'合同纠纷',
    tags:['合同纠纷','特许经营','诉讼仲裁'],
    skill:'专注于成品油购销合同、特许经营协议、土地租赁合同审查，以及商业纠纷的诉讼与仲裁代理。',
    intro:'团队擅长能源领域商事合同全周期管理与争议解决，标的过亿案件代理经验丰富。',
    awards:'商事争议解决推荐团队；多起重大合同纠纷案件成功代理。',
    consults:'5.4 万人咨询',
    questions:['成品油购销合同违约怎么索赔？','特许经营协议被单方解除怎么办？','土地租赁到期不续租如何处理？'],
  },
];
AGENTS.forEach((a,i)=>{ a.grad = a.plainAvatar ? null : GRADS[i%GRADS.length]; });

const CATEGORIES = ['律师分身','政企法务','合规专区','法律生活'];
const FILTERS = ['全部','加油站合规','安全生产','环保管理','劳动用工','合同纠纷'];

// ── small icon set ──────────────────────────────────────────────────────────
const Icon = {
  close:(c='#3a3a3a')=>(<svg width="22" height="22" viewBox="0 0 24 24"><path d="M6 6l12 12M18 6L6 18" stroke={c} strokeWidth="2.2" strokeLinecap="round"/></svg>),
  dots:(c='#3a3a3a')=>(<svg width="22" height="6" viewBox="0 0 22 6"><circle cx="3" cy="3" r="2.4" fill={c}/><circle cx="11" cy="3" r="2.4" fill={c}/><circle cx="19" cy="3" r="2.4" fill={c}/></svg>),
  circle:(c='#3a3a3a')=>(<svg width="20" height="20" viewBox="0 0 24 24"><circle cx="12" cy="12" r="9" fill="none" stroke={c} strokeWidth="2"/><circle cx="12" cy="12" r="2" fill={c}/></svg>),
  back:(c='#1B1F27')=>(<svg width="22" height="22" viewBox="0 0 24 24"><path d="M15 4l-8 8 8 8" stroke={c} strokeWidth="2.4" fill="none" strokeLinecap="round" strokeLinejoin="round"/></svg>),
  people:(c='#1B1F27')=>(<svg width="20" height="20" viewBox="0 0 24 24" fill="none"><circle cx="9" cy="8" r="3.2" stroke={c} strokeWidth="1.8"/><path d="M3.5 19c0-3 2.5-5 5.5-5s5.5 2 5.5 5" stroke={c} strokeWidth="1.8" strokeLinecap="round"/><path d="M16 6.2a3 3 0 010 5.6M17.5 19c0-2.2-1-3.8-2.5-4.6" stroke={c} strokeWidth="1.8" strokeLinecap="round"/></svg>),
  send:(c='#fff')=>(<svg width="22" height="22" viewBox="0 0 24 24" fill="none"><path d="M21 4L3 11l6 2.2L11.5 21 21 4z" stroke={c} strokeWidth="1.7" strokeLinejoin="round" fill="none"/></svg>),
  search:(c='#9AA3B2')=>(<svg width="20" height="20" viewBox="0 0 24 24" fill="none"><circle cx="11" cy="11" r="6.5" stroke={c} strokeWidth="2"/><path d="M16 16l4 4" stroke={c} strokeWidth="2" strokeLinecap="round"/></svg>),
  lock:(c='#9AA3B2')=>(<svg width="14" height="14" viewBox="0 0 24 24" fill="none"><rect x="5" y="11" width="14" height="9" rx="2" stroke={c} strokeWidth="1.8"/><path d="M8 11V8a4 4 0 018 0v3" stroke={c} strokeWidth="1.8"/></svg>),
  hash:(c='#3B6EF6')=>(<svg width="20" height="20" viewBox="0 0 24 24" fill="none"><path d="M9 4L7 20M17 4l-2 16M4 9h16M3 15h16" stroke={c} strokeWidth="2" strokeLinecap="round"/></svg>),
  scale:(c='#fff')=>(<svg width="40" height="40" viewBox="0 0 24 24" fill="none"><path d="M12 3v17M6 20h12M5 7l-3 6a3 3 0 006 0L5 7zM19 7l-3 6a3 3 0 006 0l-3-6zM5 7h14M5 7L4 6m15 1l1-1" stroke={c} strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round"/><circle cx="12" cy="5" r="1.6" fill={c}/></svg>),
};

// ── Avatar ───────────────────────────────────────────────────────────────────
function Avatar({ agent, size=48, ai=true, ring=false }){
  const isPlain = agent.plainAvatar;
  const badge = Math.round(size*0.42);
  return (
    <div style={{position:'relative', width:size, height:size, flexShrink:0}}>
      <div style={{
        width:size, height:size, borderRadius:'50%',
        background:isPlain ? '#E7EAF2' : agent.grad,
        display:'flex', alignItems:'center', justifyContent:'center',
        color:isPlain ? '#5B6273' : '#fff',
        fontSize:size*0.42, fontWeight:600,
        boxShadow: ring ? '0 0 0 3px rgba(255,255,255,0.9), 0 0 0 5px rgba(123,91,232,0.18)' : 'none',
      }}>{agent.char}</div>
      {ai && (
        <div style={{
          position:'absolute', top:-badge*0.18, right:-badge*0.18,
          width:badge, height:badge, borderRadius:'50%',
          background:C.ai, border:'2px solid #fff',
          display:'flex', alignItems:'center', justifyContent:'center',
          color:'#fff', fontSize:badge*0.46, fontWeight:700, fontStyle:'italic',
          fontFamily:'Georgia, serif', letterSpacing:'-0.5px',
        }}>AI</div>
      )}
    </div>
  );
}

// ── Badges used on directory cards ────────────────────────────────────────────
function RibbonBadge({ children }){
  return (
    <span style={{
      display:'inline-flex', alignItems:'center', gap:4, height:22,
      padding:'0 9px', borderRadius:5,
      background:'linear-gradient(90deg,#2B3A7A 0%,#3B6EF6 100%)',
      color:'#fff', fontSize:12.5, fontWeight:600, whiteSpace:'nowrap',
    }}><span style={{opacity:.7,fontSize:10}}>✦</span>{children}<span style={{opacity:.7,fontSize:10}}>✦</span></span>
  );
}
function GoldBadge({ children }){
  return (
    <span style={{
      display:'inline-flex', alignItems:'center', height:22, padding:'0 9px',
      borderRadius:5, background:'#FBEECF', color:'#B07D1E',
      fontSize:12.5, fontWeight:600, whiteSpace:'nowrap',
    }}>{children}</span>
  );
}
function OutlineChip({ children }){
  return (
    <span style={{
      display:'inline-flex', alignItems:'center', height:22, padding:'0 9px',
      borderRadius:5, border:`1px solid ${C.brand}`, color:C.brand,
      fontSize:12.5, fontWeight:500, whiteSpace:'nowrap',
    }}>{children}</span>
  );
}
function LevelTag({ children }){
  return (
    <span style={{
      display:'inline-flex', alignItems:'center', height:21, padding:'0 7px',
      borderRadius:4, background:'#E8F0FE', color:C.brand,
      fontSize:12.5, fontWeight:600, whiteSpace:'nowrap',
    }}>{children}</span>
  );
}

Object.assign(window, {
  C, GRADS, AGENTS, CATEGORIES, FILTERS, Icon,
  Avatar, RibbonBadge, GoldBadge, OutlineChip, LevelTag,
});
