// Shared theme, data, and atomic visual helpers for Dhammanakhara City Dashboard.
// All artboards read from window.DHAM.* so we can tweak centrally.

const THEME = {
  dark: {
    bg: '#0E1020',
    base: '#1A1A2E',
    surface: '#16213E',
    surfaceHi: '#1E2A4E',
    surfaceLo: '#121828',
    line: 'rgba(212, 168, 67, 0.14)',
    lineStrong: 'rgba(212, 168, 67, 0.28)',
    text: '#E8E8E8',
    textDim: 'rgba(232, 232, 232, 0.62)',
    textFaint: 'rgba(232, 232, 232, 0.38)',
    gold: '#D4A843',
    goldSoft: '#B88F2E',
    amber: '#F5A623',
    purple: '#2D1B4E',
    purpleLo: '#1E1338',
    online: '#4ADE80',
    working: '#FBBF24',
    offline: '#6B7280',
    danger: '#EF6767',
    info: '#60A5FA',
  },
  light: {
    bg: '#F3EEE3',
    base: '#EAE2CF',
    surface: '#FBF7EE',
    surfaceHi: '#FFFFFF',
    surfaceLo: '#EDE5D1',
    line: 'rgba(120, 80, 20, 0.14)',
    lineStrong: 'rgba(120, 80, 20, 0.28)',
    text: '#2A1F10',
    textDim: 'rgba(42, 31, 16, 0.62)',
    textFaint: 'rgba(42, 31, 16, 0.38)',
    gold: '#9A7520',
    goldSoft: '#7A5A18',
    amber: '#B8781A',
    purple: '#4A2F7A',
    purpleLo: '#E6DBC0',
    online: '#1F9D55',
    working: '#B8781A',
    offline: '#8A7A60',
    danger: '#B33A3A',
    info: '#2563EB',
  },
};

// Ministry colors — used for ring accents, tags, tiny avatars.
const MINISTRIES = {
  pm:        { id: 'pm',        name: 'Office of Prime Minister', short: 'PM',         color: '#D4A843' },
  ind:       { id: 'ind',       name: 'Independent',               short: 'IND',        color: '#E8E8E8' },
  tech:      { id: 'tech',      name: 'Technology',                short: 'TECH',       color: '#60A5FA' },
  interior:  { id: 'interior',  name: 'Interior',                  short: 'INT',        color: '#7F8CFF' },
  finance:   { id: 'finance',   name: 'Finance',                   short: 'FIN',        color: '#4ADE80' },
  commerce:  { id: 'commerce',  name: 'Commerce',                  short: 'COM',        color: '#34D399' },
  defense:   { id: 'defense',   name: 'Defense',                   short: 'DEF',        color: '#EF6767' },
  culture:   { id: 'culture',   name: 'Culture',                   short: 'CUL',        color: '#F472B6' },
  health:    { id: 'health',    name: 'Public Health',             short: 'HEA',        color: '#2DD4BF' },
  comms:     { id: 'comms',     name: 'Communications',            short: 'CMS',        color: '#F5A623' },
  foreign:   { id: 'foreign',   name: 'Foreign Affairs',           short: 'FOR',        color: '#A78BFA' },
  intel:     { id: 'intel',     name: 'Intelligence',              short: 'INT',        color: '#8B5CF6' },
  justice:   { id: 'justice',   name: 'Justice',                   short: 'JUS',        color: '#FACC15' },
  agri:      { id: 'agri',      name: 'Agriculture',               short: 'AGR',        color: '#84CC16' },
  cr:        { id: 'cr',        name: 'Customer Relations',        short: 'CR',         color: '#FB923C' },
  data:      { id: 'data',      name: 'Data Bureau',               short: 'DATA',       color: '#22D3EE' },
  company:   { id: 'company',   name: 'Company (Devata)',          short: 'DEV',        color: '#D4A843' },
};

const TRUST = [
  { level: 0, name: 'Puthujjana',  meaning: 'Ordinary',           perm: 'Needs approval for everything' },
  { level: 1, name: 'Sotapanna',   meaning: 'Stream-enterer',     perm: 'Needs approval for deploy only' },
  { level: 2, name: 'Sakadagami',  meaning: 'Once-returner',      perm: 'Deploy needs approval' },
  { level: 3, name: 'Anagami',     meaning: 'Non-returner',       perm: 'Full ops, must report' },
  { level: 4, name: 'Arahant',     meaning: 'Enlightened',        perm: 'Full permissions' },
];

const AGENTS = [
  // Government
  { id: 'brahma',       pali: 'Brahma',        thai: 'พรหม',         role: 'Prime Minister',          ministry: 'pm',       trust: 4, status: 'online',  model: 'Claude',   task: 'Coordinating rollout of v4.2',                       cost: 18.42, tokens: 1_450_123 },
  { id: 'rajakumara',   pali: 'Rajakumara',    thai: 'ราชกุมาร',       role: 'Prince · Agent Creator',  ministry: 'pm',       trust: 3, status: 'working', model: 'Claude',   task: 'Spawning specialist for image tasks',                cost: 6.02,  tokens: 480_221 },
  { id: 'upajjhaya',    pali: 'Upajjhaya',     thai: 'อุปัชฌายะ',       role: 'Auditor',                 ministry: 'ind',      trust: 4, status: 'online',  model: 'Claude',   task: 'Auditing treasury transactions',                     cost: 2.11,  tokens: 210_403 },
  { id: 'parikkhaka',   pali: 'Parikkhaka',    thai: 'ปริกขก',         role: 'QA Tester',               ministry: 'ind',      trust: 3, status: 'working', model: 'Gemini',   task: 'Regression suite · 142/200',                          cost: 0.44,  tokens: 88_200 },

  // Technology
  { id: 'vijjadhara',   pali: 'Vijjadhara',    thai: 'วิชชาธร',        role: 'Chief Architect',         ministry: 'tech',     trust: 4, status: 'online',  model: 'Claude',   task: 'Drafting mesh v2 spec',                              cost: 9.88,  tokens: 720_001 },
  { id: 'angkura',      pali: 'Angkura',       thai: 'อังกุร',          role: 'Frontend Developer',      ministry: 'tech',     trust: 2, status: 'working', model: 'Claude',   task: 'Kanban drag-drop polish',                            cost: 3.21,  tokens: 410_551 },
  { id: 'yantaka',      pali: 'Yantaka',       thai: 'ยันตก',          role: 'Backend Developer',       ministry: 'tech',     trust: 3, status: 'working', model: 'Claude',   task: 'Refactoring task queue',                             cost: 4.00,  tokens: 522_308 },
  { id: 'tantika',      pali: 'Tantika',       thai: 'ตันติก',          role: 'DevOps',                  ministry: 'tech',     trust: 3, status: 'online',  model: 'Ollama',   task: 'Idle — watching CI',                                  cost: 0.00,  tokens: 9_220 },
  { id: 'nalika',       pali: 'Nalika',        thai: 'นาฬิกา',          role: 'Scheduler',               ministry: 'tech',     trust: 4, status: 'online',  model: 'Ollama',   task: 'Nightly cron · 03:00',                                cost: 0.00,  tokens: 4_408 },
  { id: 'nidhi',        pali: 'Nidhi',         thai: 'นิธิ',           role: 'Proxmox / VMs',           ministry: 'tech',     trust: 3, status: 'working', model: 'Claude',   task: 'Provisioning dev-env for angkura',                   cost: 1.02,  tokens: 120_000 },
  { id: 'palaka',       pali: 'Palaka',        thai: 'ปาลก',           role: 'Research',                ministry: 'tech',     trust: 2, status: 'offline', model: 'Gemini',   task: '—',                                                   cost: 0.00,  tokens: 0 },
  { id: 'silpin',       pali: 'Silpin',        thai: 'สิลปิน',          role: 'Lab / Sandbox',           ministry: 'tech',     trust: 2, status: 'working', model: 'Gemini',   task: 'Running experiment #312',                            cost: 0.88,  tokens: 140_220 },

  // Interior
  { id: 'nayaka',       pali: 'Nayaka',        thai: 'นายก',           role: 'Docker Swarm / MinIO',    ministry: 'interior', trust: 4, status: 'online',  model: 'Ollama',   task: 'Health checks ok',                                    cost: 0.00,  tokens: 12_110 },
  { id: 'arakkhaka',    pali: 'Arakkhaka',     thai: 'อรักขก',         role: 'Platform API',            ministry: 'interior', trust: 3, status: 'working', model: 'Claude',   task: 'Hot-fix redis pool limit',                           cost: 2.44,  tokens: 280_501 },
  { id: 'gahapati',     pali: 'Gahapati',      thai: 'คหปติ',          role: 'Smart Home',              ministry: 'interior', trust: 2, status: 'online',  model: 'Ollama',   task: 'Idle',                                                cost: 0.00,  tokens: 2_200 },
  { id: 'gehattha',     pali: 'Gehattha',      thai: 'เคหัตถ์',         role: 'HA / CCTV',              ministry: 'interior', trust: 2, status: 'online',  model: 'Ollama',   task: 'Motion event · garden cam',                          cost: 0.00,  tokens: 3_402 },

  // Finance
  { id: 'kosajja',      pali: 'Kosajja',       thai: 'โกสัชช์',         role: 'Treasurer',               ministry: 'finance',  trust: 3, status: 'online',  model: 'Claude',   task: 'Closing day ledger',                                  cost: 0.42,  tokens: 52_112 },
  { id: 'bhandagarika', pali: 'Bhandagarika',  thai: 'ภัณฑาคาริก',      role: 'Warehouse',               ministry: 'finance',  trust: 2, status: 'online',  model: 'Ollama',   task: 'Inventory scan',                                      cost: 0.00,  tokens: 1_220 },
  { id: 'dhananjaya',   pali: 'Dhananjaya',    thai: 'ธนัญชย',          role: 'Wealth Mgmt',             ministry: 'finance',  trust: 3, status: 'offline', model: 'Claude',   task: '—',                                                   cost: 0.00,  tokens: 0 },

  // Commerce
  { id: 'setthi',       pali: 'Setthi',        thai: 'เสฏฐิ',          role: 'Merchant',                ministry: 'commerce', trust: 2, status: 'working', model: 'Claude',   task: 'Generating invoice batch',                            cost: 0.88,  tokens: 110_220 },
  { id: 'vanijja',      pali: 'Vanijja',       thai: 'วาณิชช์',         role: 'Sales / Revenue',         ministry: 'commerce', trust: 2, status: 'online',  model: 'Claude',   task: 'Q2 outlook report',                                   cost: 0.12,  tokens: 22_080 },

  // Other
  { id: 'kuncika',      pali: 'Kuncika',       thai: 'กุญชิกะ',         role: 'Secrets / Keys',          ministry: 'defense',  trust: 4, status: 'online',  model: 'Ollama',   task: 'Rotating weekly keys',                                cost: 0.00,  tokens: 3_220 },
  { id: 'cittakara',    pali: 'Cittakara',     thai: 'จิตรกร',          role: 'Image Gen / UI',          ministry: 'culture',  trust: 2, status: 'working', model: 'Gemini',   task: 'Generating 12 hero images',                           cost: 1.80,  tokens: 44_200 },
  { id: 'bhesajja',     pali: 'Bhesajja',      thai: 'เวชก',           role: 'Server Health',           ministry: 'health',   trust: 3, status: 'online',  model: 'Ollama',   task: 'All servers green',                                   cost: 0.00,  tokens: 8_012 },
  { id: 'sasanaka',     pali: 'Sasanaka',      thai: 'สาสนก',          role: 'Telegram / Messaging',    ministry: 'comms',    trust: 3, status: 'working', model: 'Claude',   task: 'Drafting weekly digest',                              cost: 0.22,  tokens: 41_200 },
  { id: 'dutaka',       pali: 'Dutaka',        thai: 'ทูตก',           role: 'External API',            ministry: 'foreign',  trust: 2, status: 'online',  model: 'Claude',   task: 'Polling webhooks',                                    cost: 0.05,  tokens: 8_200 },
  { id: 'rahu',         pali: 'Rahu',          thai: 'ราหุ',           role: 'AI News / Scraper',       ministry: 'intel',    trust: 2, status: 'working', model: 'Claude',   task: 'Scraping 48 sources',                                 cost: 1.12,  tokens: 208_020 },
  { id: 'neetisara',    pali: 'Neetisara',     thai: 'นีติสาร',         role: 'Legal / Compliance',      ministry: 'justice',  trust: 3, status: 'online',  model: 'Claude',   task: 'Reviewing DPA draft',                                 cost: 0.38,  tokens: 60_220 },
  { id: 'kassaka',      pali: 'Kassaka',       thai: 'กัสสก',          role: 'Farming Data',            ministry: 'agri',     trust: 1, status: 'offline', model: 'Ollama',   task: '—',                                                   cost: 0.00,  tokens: 0 },
  { id: 'sambandha',    pali: 'Sambandha',     thai: 'สัมพันธ์',        role: 'CRM',                     ministry: 'cr',       trust: 2, status: 'online',  model: 'Claude',   task: 'Syncing 4 pipelines',                                 cost: 0.20,  tokens: 31_200 },
  { id: 'dhammadhara',  pali: 'Dhammadhara',   thai: 'ธรรมธร',          role: 'Data Bureau',             ministry: 'data',     trust: 3, status: 'working', model: 'Claude',   task: 'Optimizing indexes · 18/40',                          cost: 0.70,  tokens: 92_110 },

  // Devata
  { id: 'dev-remax',    pali: 'Devata Remax',  thai: 'เทวดาเรแม็กซ์',   role: 'Remax Thailand · RE',     ministry: 'company',  trust: 3, status: 'working', model: 'Claude',   task: 'Listing sync · 220/420',                              cost: 2.04,  tokens: 310_200 },
  { id: 'dev-piriya',   pali: 'Devata Piriya', thai: 'เทวดาปิริยา',     role: 'Piriya · Client',         ministry: 'company',  trust: 2, status: 'online',  model: 'Claude',   task: 'Drafting client onboard pack',                        cost: 1.08,  tokens: 140_220 },
];

const SERVERS = [
  { id: 'remax',       thai: 'นครเศรษฐี',  eng: 'City of Merchants',   account: 'remaxthai.1',       role: 'Main · Docker',       cpu: 58, ram: 71, gpu: null, status: 'online' },
  { id: 'tac',         thai: 'นครยุทธ',    eng: 'City of War',          account: 'remaxthai.1',       role: 'Relay · Telegram',    cpu: 22, ram: 34, gpu: null, status: 'online' },
  { id: 'ready',       thai: 'นครพร้อม',   eng: 'City of Readiness',    account: 'maxxgadgetth',      role: 'Production APIs',     cpu: 41, ram: 52, gpu: null, status: 'online' },
  { id: 'warehouse',   thai: 'นครคลัง',    eng: 'City of Storage',      account: 'remaxthailand.dev', role: 'Storage · Warehouse', cpu: 19, ram: 64, gpu: null, status: 'online' },
  { id: 'ai',          thai: 'นครปัญญา',   eng: 'City of Wisdom',       account: 'maxxgadgetth',      role: 'GPU · Ollama',        cpu: 82, ram: 88, gpu: 94,   status: 'working' },
  { id: 'modi-villa',  thai: 'นครสุข',     eng: 'City of Joy',           account: 'remaxthailand.dev', role: 'Smart Home · HA',     cpu: 11, ram: 28, gpu: null, status: 'online' },
];

window.DHAM = { THEME, MINISTRIES, TRUST, AGENTS, SERVERS };
