// ============================================================
// chrome.jsx — Sidebar, Top action bar, Composer dock, Settings modal
// ============================================================

const { useState, useRef, useEffect, useCallback } = React;

// ---------- icon helpers ----------
const Ico = {
  Spark: (p) => <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" {...p}><path d="M12 2l2.6 7.4L22 12l-7.4 2.6L12 22l-2.6-7.4L2 12l7.4-2.6L12 2z"/></svg>,
  Bot:   (p) => <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" {...p}><rect x="3" y="8" width="18" height="12" rx="2"/><path d="M12 4v4M8 14h.01M16 14h.01M9 18h6"/></svg>,
  Lamp:  (p) => <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" {...p}><path d="M9 18h6M10 22h4M12 2a7 7 0 0 0-4 12.7c1 .8 1.5 2 1.5 3.3h5c0-1.3.5-2.5 1.5-3.3A7 7 0 0 0 12 2z"/></svg>,
  Plus:  (p) => <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.5" strokeLinecap="round" strokeLinejoin="round" {...p}><path d="M12 5v14M5 12h14"/></svg>,
  Clock: (p) => <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" {...p}><circle cx="12" cy="12" r="9"/><path d="M12 7v5l3 2"/></svg>,
  Caret: (p) => <svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.5" strokeLinecap="round" strokeLinejoin="round" {...p}><path d="M6 9l6 6 6-6"/></svg>,
  ArrowRight: (p) => <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" {...p}><path d="M5 12h14M13 6l6 6-6 6"/></svg>,
  ArrowUp: (p) => <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" {...p}><path d="M12 19V5M6 11l6-6 6 6"/></svg>,
  Copy:  (p) => <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" {...p}><rect x="9" y="9" width="13" height="13" rx="2"/><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/></svg>,
  Check: (p) => <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="3" strokeLinecap="round" strokeLinejoin="round" {...p}><path d="M5 12l5 5L20 7"/></svg>,
  X:     (p) => <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" {...p}><path d="M6 6l12 12M18 6L6 18"/></svg>,
  Gear:  (p) => <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" {...p}><circle cx="12" cy="12" r="3"/><path d="M19.4 15a1.7 1.7 0 0 0 .3 1.8l.1.1a2 2 0 1 1-2.8 2.8l-.1-.1a1.7 1.7 0 0 0-1.8-.3 1.7 1.7 0 0 0-1 1.5V21a2 2 0 1 1-4 0v-.1A1.7 1.7 0 0 0 9 19.4a1.7 1.7 0 0 0-1.8.3l-.1.1a2 2 0 1 1-2.8-2.8l.1-.1a1.7 1.7 0 0 0 .3-1.8 1.7 1.7 0 0 0-1.5-1H3a2 2 0 1 1 0-4h.1A1.7 1.7 0 0 0 4.6 9a1.7 1.7 0 0 0-.3-1.8l-.1-.1a2 2 0 1 1 2.8-2.8l.1.1a1.7 1.7 0 0 0 1.8.3H9a1.7 1.7 0 0 0 1-1.5V3a2 2 0 1 1 4 0v.1a1.7 1.7 0 0 0 1 1.5 1.7 1.7 0 0 0 1.8-.3l.1-.1a2 2 0 1 1 2.8 2.8l-.1.1a1.7 1.7 0 0 0-.3 1.8V9c.4.1.7.4 1 .7a2 2 0 0 1 0 2.6c-.3.3-.6.6-1 .7z"/></svg>,
  Info:  (p) => <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" {...p}><circle cx="12" cy="12" r="9"/><path d="M12 8v.01M11 12h1v4h1"/></svg>,
  Image: (p) => <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" {...p}><rect x="3" y="3" width="18" height="18" rx="2"/><circle cx="9" cy="9" r="2"/><path d="M21 15l-5-5L5 21"/></svg>,
  Grid:  (p) => <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" {...p}><rect x="3" y="3" width="7" height="7" rx="1"/><rect x="14" y="3" width="7" height="7" rx="1"/><rect x="3" y="14" width="7" height="7" rx="1"/><rect x="14" y="14" width="7" height="7" rx="1"/></svg>,
  Layers:(p) => <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" {...p}><path d="M12 2L2 7l10 5 10-5-10-5z"/><path d="M2 17l10 5 10-5"/><path d="M2 12l10 5 10-5"/></svg>,
  Chat:  (p) => <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" {...p}><path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2v10z"/></svg>,
  Cube:  (p) => <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" {...p}><path d="M21 16V8a2 2 0 0 0-1-1.7l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.7l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16z"/><path d="M3.3 7L12 12l8.7-5M12 22V12"/></svg>,
  Frame: (p) => <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" {...p}><path d="M22 12H2M12 2v20"/><rect x="6" y="6" width="12" height="12" rx="1"/></svg>,
  Cart:  (p) => <svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" {...p}><circle cx="9" cy="21" r="1"/><circle cx="20" cy="21" r="1"/><path d="M1 1h4l2.7 13.4a2 2 0 0 0 2 1.6h9.7a2 2 0 0 0 2-1.6L23 6H6"/></svg>,
  Bolt:  (p) => <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" {...p}><path d="M13 2L3 14h9l-1 8 10-12h-9l1-8z"/></svg>,
  Wallet:(p) => <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" {...p}><path d="M3 7a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V7z"/><path d="M16 12h2M3 9h18"/></svg>,
  Target:(p) => <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" {...p}><circle cx="12" cy="12" r="9"/><circle cx="12" cy="12" r="5"/><circle cx="12" cy="12" r="1"/></svg>,
  Wave:  (p) => <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" {...p}><path d="M2 12h3l3-9 4 18 3-9h7"/></svg>,
  Stack: (p) => <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" {...p}><rect x="4" y="4" width="14" height="14" rx="2"/><rect x="8" y="8" width="14" height="14" rx="2"/></svg>,
  Refresh:(p) => <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" {...p}><path d="M3 12a9 9 0 0 1 15-6.7L21 8M21 3v5h-5M21 12a9 9 0 0 1-15 6.7L3 16M3 21v-5h5"/></svg>,
  Edit:  (p) => <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" {...p}><path d="M12 20h9M16.5 3.5a2 2 0 1 1 3 3L7 19l-4 1 1-4 12.5-12.5z"/></svg>,
  Brain: (p) => <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" {...p}><path d="M12 4a3 3 0 0 0-3 3 3 3 0 0 0-3 5 3 3 0 0 0 0 4 3 3 0 0 0 3 4 3 3 0 0 0 6 0 3 3 0 0 0 3-4 3 3 0 0 0 0-4 3 3 0 0 0-3-5 3 3 0 0 0-3-3z"/><path d="M9 9v6M15 9v6"/></svg>,
};

// ============================================================
// Brand mark — replaces 元启 logo, our own "Singularity core"
// ============================================================
function BrandLogo() {
  return (
    <div className="sidebar-brand">
      <div className="brand-mark"></div>
      <div>
        <div className="brand-name">
          <span className="brand-name-cjk">奇点引擎</span>
          <span style={{fontSize: 12, color: 'var(--text-2)', letterSpacing: 1}}>SINGULARITY</span>
        </div>
        <div className="brand-sub">多模型聚合 · 智能体创作平台</div>
      </div>
    </div>
  );
}

// ============================================================
// Sidebar
// ============================================================

const AGENTS = [
  { id: 'api', name: 'API开放接口', icon: '⚡', chips: [['API','chip-api']],
    desc: '下载 Skill 文件，让 AI 编程工具自动接入全部模型能力，无需阅读…' },
  { id: 'canvas', name: '无限画布', icon: '◇', chips: [['多模态','chip-multi']],
    desc: '无限延展的 AI 创意空间，自由排布图文视频，所想即所得' },
  { id: 'ecom', name: '电商一键生图', icon: '🛒', chips: [['图片','chip-image']], active: true,
    desc: '上传商品图片和信息，AI 多轮对话补全需求，智能推荐出图方案…' },
  { id: 'general', name: '通用一键生图', icon: '🎨', chips: [['图片','chip-image']],
    desc: '上传任意图片和描述，AI 智能分析需求，多轮对话规划方案，一键…' },
  { id: 'oc', name: 'OpenClaw', icon: '🐦', chips: [['多模态','chip-multi']],
    desc: '免费一键部署全中文 AI 大模型，ChatGPT / Gemini / Claude 本…' },
  { id: 'manhua', name: 'AI 漫剧 - S2.0', icon: '🎭', chips: [['视频','chip-video']],
    desc: '专为参考图打造的超级智能体，多种玩法一键生成高质量视频' },
  { id: 'manhua2', name: 'AI 漫剧 · 剧情版', icon: '🎬', chips: [['视频','chip-video']],
    desc: '基于剧本自动分镜，逐镜生成漫剧风格画面，可导出长视频' },
  { id: 'voice', name: 'AI 配音工坊', icon: '🎙', chips: [['新','chip-new']],
    desc: '上传文字脚本一键生成多角色配音，支持情绪与韵律调节' },
  { id: 'writer', name: 'AI 写作工作台', icon: '✎', chips: [['文本','chip-text']],
    desc: '多模型协作长文写作，支持大纲生成、续写与多角度润色' },
];

function Sidebar({ activeAgent, onPickAgent }) {
  return (
    <aside className="sidebar">
      <BrandLogo />
      <div className="sidebar-tabs">
        <button className="tab"><div className="tab-ico"><Ico.Cube /></div>大模型</button>
        <button className="tab active"><div className="tab-ico"><Ico.Bot /></div>智能体</button>
        <button className="tab"><div className="tab-ico"><Ico.Lamp /></div>灵感广场</button>
      </div>
      <div className="agent-list">
        {AGENTS.map(a => (
          <div key={a.id}
               className={'agent-row ' + (a.id === activeAgent ? 'active' : '')}
               onClick={() => onPickAgent && onPickAgent(a.id)}>
            <div className="agent-icon" style={{fontSize: 18}}>{a.icon}</div>
            <div className="agent-meta">
              <div className="agent-title-row">
                <span className="agent-name">{a.name}</span>
                {a.chips.map(([t, cls], i) =>
                  <span key={i} className={'chip ' + cls}>{t}</span>
                )}
              </div>
              <div className="agent-desc">{a.desc}</div>
            </div>
          </div>
        ))}
      </div>
      <div className="sidebar-user">
        <div className="avatar">桃</div>
        <div className="user-meta">
          <div className="user-name">桃红小鱼</div>
          <div className="user-status">在线</div>
        </div>
        <button className="btn-recharge"><Ico.Wallet /> 充值</button>
      </div>
    </aside>
  );
}

// ============================================================
// Top action bar with 新任务 / 历史 + top-right product strip
// ============================================================

function TopBar({ onNewTask, productThumbs, showProductStrip, currentLabel }) {
  return (
    <>
      <div className="top-actions">
        <button className="btn btn-primary" onClick={onNewTask}>
          <Ico.Plus /> 新任务
        </button>
        <button className="btn btn-ghost">
          <Ico.Clock /> 历史 <Ico.Caret />
        </button>
      </div>
      <div className="top-right-cluster">
        {showProductStrip && productThumbs && (
          <div className="product-strip">
            <div className="product-strip-row">
              {productThumbs.slice(0, 6).map((t, i) =>
                <ProductThumb key={i} src={t} active={i === 2} />
              )}
            </div>
            {currentLabel && <div className="product-strip-label">{currentLabel}</div>}
          </div>
        )}
        <div className="invite-glyph"></div>
      </div>
    </>
  );
}

// Chibi-style placeholder thumb (CSS-drawn) — no real image
function ProductThumb({ active, kind }) {
  return (
    <div className={'product-thumb ' + (active ? 'active' : '')}>
      <ChibiPlaceholder kind={kind} />
    </div>
  );
}

function ChibiPlaceholder({ kind, size = 40 }) {
  // CSS-only stylized "chibi product" placeholder; varied looks based on kind
  const v = (kind || 0) % 4;
  return (
    <svg width={size} height={size} viewBox="0 0 40 40" style={{display: 'block'}}>
      <defs>
        <linearGradient id={'cg' + v} x1="0" y1="0" x2="1" y2="1">
          <stop offset="0" stopColor={v === 3 ? "#1a1a2e" : "#f4f1ea"} />
          <stop offset="1" stopColor={v === 3 ? "#0a0a16" : "#c8c0a8"} />
        </linearGradient>
      </defs>
      <rect width="40" height="40" fill={'url(#cg' + v + ')'} />
      {/* hair */}
      <path d="M8 18 Q8 6 20 6 Q32 6 32 18 L30 32 Q26 36 20 36 Q14 36 10 32 Z"
            fill={v === 3 ? "#fff" : "#ebe5d3"} opacity="0.85"/>
      {/* face */}
      <ellipse cx="20" cy="20" rx="8" ry="9" fill="#f7e9d5" opacity="0.85"/>
      {/* eyes */}
      <circle cx="17" cy="20" r="1.2" fill="#2a1f15"/>
      <circle cx="23" cy="20" r="1.2" fill="#2a1f15"/>
      {/* bow ribbons */}
      <path d="M10 12 L7 9 L9 14 Z" fill="#1a1a2e"/>
      <path d="M30 12 L33 9 L31 14 Z" fill="#1a1a2e"/>
      {/* black bunny */}
      <ellipse cx="20" cy="32" rx="4" ry="3.5" fill="#1a1a2e"/>
      <path d="M17 30 L17 26 M23 30 L23 26" stroke="#1a1a2e" strokeWidth="1.5" strokeLinecap="round"/>
    </svg>
  );
}

// Rocket-doodle variant (one of the source images)
function RocketDoodle({ size = 40 }) {
  return (
    <svg width={size} height={size} viewBox="0 0 40 40">
      <rect width="40" height="40" fill="#f5efde"/>
      <path d="M20 8 L24 18 L24 26 L16 26 L16 18 Z" fill="#fff" stroke="#1a1a2e" strokeWidth="1"/>
      <circle cx="20" cy="20" r="1.5" fill="#3a7bd5"/>
      <path d="M18 26 L17 30 M22 26 L23 30" stroke="#d9534f" strokeWidth="1.2"/>
      <text x="20" y="34" textAnchor="middle" fontSize="6" fill="#1a1a2e" fontFamily="monospace">W392</text>
      <circle cx="10" cy="10" r="0.8" fill="#1a1a2e"/>
      <circle cx="30" cy="14" r="0.8" fill="#3a7bd5"/>
      <circle cx="32" cy="28" r="0.8" fill="#1a1a2e"/>
    </svg>
  );
}

// ============================================================
// Composer (bottom dock with upload + input + mode toggle)
// ============================================================

function Composer({ placeholder = '输入商品名称和详细信息…', mode, setMode, productThumbs, showStack = true, expanded, onToggleExpand }) {
  return (
    <div className="composer">
      {!showStack && (
        <div className="composer-upload" title="上传商品图">
          <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" style={{color: 'var(--text-2)'}}>
            <path d="M12 5v14M5 12h14"/>
          </svg>
          <div className="composer-upload-label">商品图</div>
        </div>
      )}
      {showStack && productThumbs && (
        <div className="composer-stack" onClick={onToggleExpand}>
          {productThumbs.slice(0,3).map((_, i) => (
            <div key={i} className={'stack-card stack-' + (i+1)}>
              <ChibiPlaceholder kind={i} size={42}/>
            </div>
          ))}
        </div>
      )}
      <input className="composer-input" placeholder={placeholder} />
      <div className="composer-actions">
        <div className="composer-mode">
          <button
            className={'mode-btn ' + (mode === 'step' ? 'active' : '')}
            onClick={() => setMode && setMode('step')}>
            <Ico.ArrowUp /> 逐步确认
          </button>
          <button
            className={'mode-btn ' + (mode === 'auto' ? 'active' : '')}
            onClick={() => setMode && setMode('auto')}>
            <Ico.Bolt /> 智能托管
          </button>
        </div>
      </div>
    </div>
  );
}

// ============================================================
// Settings modal — model fallback chain etc.
// ============================================================

function SettingsModal({ open, onClose }) {
  const [planCount, setPlanCount] = useState(30);
  const [strategy, setStrategy] = useState('price');
  const [models, setModels] = useState([
    { tag: '主', name: 'GPT-5.4', deep: '开启', web: '开启', primary: true },
    { tag: '备1', name: 'Gemini 3.1 Pro', deep: '开启', web: '开启' },
    { tag: '备2', name: '豆包 Seed 2.0 Pro', deep: '开启', web: '开启' },
  ]);

  if (!open) return null;

  const STRATEGIES = [
    ['price', '💰', '价格优先'],
    ['speed', '⚡', '速度优先'],
    ['quality', '🎯', '成功率优先'],
  ];

  return (
    <div className="modal-backdrop" onClick={onClose}>
      <div className="modal" onClick={e => e.stopPropagation()}>
        <div className="modal-head">
          <div className="modal-head-icon"><Ico.Gear /></div>
          <div className="modal-head-body">
            <div className="modal-head-title">电商生图配置</div>
            <div className="modal-head-sub">配置对话模型、图片模型和出图参数</div>
          </div>
          <button className="modal-close" onClick={onClose}><Ico.X /></button>
        </div>
        <div className="modal-body">
          <div style={{display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 14}}>
            <div className="modal-section">
              <div className="modal-section-head">
                <div className="modal-section-title">
                  <Ico.Grid /> 规划图片上限
                </div>
                <button className="section-help">规则说明</button>
              </div>
              <div className="row-between" style={{padding: '4px 0'}}>
                <span style={{fontSize: 13, color: 'var(--text-1)'}}>AI 最多规划图片方案数</span>
                <div className="stepper-num">
                  <button className="stepper-num-btn" onClick={() => setPlanCount(Math.max(1, planCount - 1))}>−</button>
                  <span className="stepper-num-value">{planCount}</span>
                  <button className="stepper-num-btn" onClick={() => setPlanCount(planCount + 1)}>+</button>
                </div>
              </div>
            </div>
            <div className="modal-section">
              <div className="modal-section-head">
                <div className="modal-section-title">
                  <Ico.Bolt /> 渠道策略
                </div>
                <button className="section-help">规则说明</button>
              </div>
              <div className="strategy-list">
                {STRATEGIES.map(([id, ico, label]) => (
                  <div key={id}
                       className={'strategy-option ' + (strategy === id ? 'selected' : '')}
                       onClick={() => setStrategy(id)}>
                    <span className="strategy-option-ico">{ico}</span>
                    {label}
                  </div>
                ))}
              </div>
            </div>
          </div>

          <div className="modal-section">
            <div className="modal-section-head">
              <div className="modal-section-title">
                <Ico.Image /> 图片模型
              </div>
              <button className="section-help">规则说明</button>
            </div>
            <div className="row" style={{gap: 10}}>
              <button className="select-control">
                <span style={{width: 18, height: 18, display: 'grid', placeItems: 'center', background: '#FFF3C4', borderRadius: 4, fontSize: 12}}>🍌</span>
                Nano Banana Pro
                <Ico.Caret className="caret" />
              </button>
              <button className="select-control">
                <Ico.Frame />
                2K 高清
                <Ico.Caret className="caret" />
              </button>
            </div>
          </div>

          <div className="modal-section">
            <div className="modal-section-head">
              <div className="modal-section-title">
                <Ico.Chat /> 对话模型
              </div>
              <button className="section-help">规则说明</button>
              <span className="section-meta-right">按顺序自动切换，首个为主力模型</span>
            </div>
            {models.map((m, i) => (
              <div key={i} className="model-row">
                <span className={'model-row-tag ' + (m.primary ? '' : 'backup')}>{m.tag}</span>
                <button className="select-control">
                  <span style={{width: 16, height: 16, borderRadius: 4, background: m.name.includes('Gemini') ? '#4285F4' : m.name.includes('豆包') ? '#0084FF' : '#10A37F', display: 'inline-block'}}></span>
                  {m.name}
                  <Ico.Caret className="caret" />
                </button>
                <button className="select-control" style={{fontSize: 11}}>
                  <Ico.Brain /> {m.deep} <Ico.Caret className="caret" />
                </button>
                <button className="select-control" style={{fontSize: 11}}>
                  <Ico.Target /> {m.web} <Ico.Caret className="caret" />
                </button>
                <button className="model-row-x"
                        onClick={() => setModels(models.filter((_, j) => j !== i))}>
                  <Ico.X />
                </button>
              </div>
            ))}
            <button className="model-row-add"
                    onClick={() => setModels([...models, { tag: '备' + models.length, name: 'GPT-5.4', deep: '关闭', web: '关闭' }])}>
              <Ico.Plus /> 添加备用模型
            </button>
          </div>
        </div>
        <div className="modal-footer">
          <button className="btn-save-large" onClick={onClose}>保存设置</button>
        </div>
      </div>
    </div>
  );
}

// ============================================================
// Settings FAB (gear at left bottom of main area)
// ============================================================

function SettingsFab({ onClick }) {
  return (
    <button className="btn-icon"
            style={{position: 'absolute', bottom: 100, left: 24, zIndex: 4}}
            onClick={onClick}>
      <Ico.Gear />
    </button>
  );
}

function PlaybookFab() {
  return (
    <button className="btn-cyan"
            style={{position: 'absolute', bottom: 100, left: 76, zIndex: 4, height: 38}}>
      <Ico.Info /> 玩法说明
    </button>
  );
}

// ============================================================
// Export
// ============================================================

Object.assign(window, {
  Ico, Sidebar, TopBar, Composer, SettingsModal, SettingsFab, PlaybookFab,
  ProductThumb, ChibiPlaceholder, RocketDoodle,
  AGENTS,
});
