// Willow shared components — icons, atoms, layout primitives
// All sage/charcoal/cream — calm consumer healthcare aesthetic.

// ─────────────────────────────────────────────────────────────
// Icons — single-stroke 24px line set. Pass color + size.
// ─────────────────────────────────────────────────────────────
const Icon = ({ name, size = 22, color = 'currentColor', stroke = 1.5, style }) => {
  const p = { fill: 'none', stroke: color, strokeWidth: stroke, strokeLinecap: 'round', strokeLinejoin: 'round' };
  const paths = {
    home:      <><path {...p} d="M4 11l8-7 8 7v8a2 2 0 01-2 2h-3v-6h-6v6H6a2 2 0 01-2-2v-8z"/></>,
    timeline:  <><circle cx="6" cy="6" r="2" {...p}/><circle cx="6" cy="18" r="2" {...p}/><path {...p} d="M6 8v8M11 6h9M11 12h6M11 18h9"/></>,
    pill:      <><rect x="3" y="9" width="18" height="6" rx="3" {...p}/><path {...p} d="M12 9v6"/></>,
    stethoscope:<><path {...p} d="M5 3v6a4 4 0 008 0V3M9 3h-4M9 3h4M9 13v3a4 4 0 004 4 4 4 0 004-4v-2"/><circle cx="17" cy="11" r="2" {...p}/></>,
    activity:  <><path {...p} d="M3 12h4l3-8 4 16 3-8h4"/></>,
    user:      <><circle cx="12" cy="8" r="4" {...p}/><path {...p} d="M4 21c0-4 4-7 8-7s8 3 8 7"/></>,
    userRound: <><circle cx="12" cy="8" r="5" {...p}/><path {...p} d="M20 21a8 8 0 00-16 0"/></>,
    users:     <><circle cx="9" cy="8" r="3.5" {...p}/><path {...p} d="M2 20c0-3.5 3-6 7-6s7 2.5 7 6"/><circle cx="17" cy="6" r="2.5" {...p}/><path {...p} d="M18 14c3 .3 4 2.5 4 5"/></>,
    sparkle:   <><path {...p} d="M12 3v4M12 17v4M3 12h4M17 12h4M6 6l2.5 2.5M15.5 15.5L18 18M6 18l2.5-2.5M15.5 8.5L18 6"/></>,
    bell:      <><path {...p} d="M6 9a6 6 0 0112 0c0 5 2 6 2 6H4s2-1 2-6zM10 19a2 2 0 004 0"/></>,
    shield:    <><path {...p} d="M12 3l8 3v6c0 5-4 8-8 9-4-1-8-4-8-9V6l8-3z"/></>,
    plus:      <><path {...p} d="M12 5v14M5 12h14"/></>,
    mic:       <><rect x="9" y="3" width="6" height="11" rx="3" {...p}/><path {...p} d="M5 11a7 7 0 0014 0M12 18v3"/></>,
    play:      <><path {...p} d="M7 5l11 7-11 7V5z" fill={color}/></>,
    pause:     <><rect x="6" y="5" width="4" height="14" {...p}/><rect x="14" y="5" width="4" height="14" {...p}/></>,
    chevron:   <><path {...p} d="M9 6l6 6-6 6"/></>,
    chevDown:  <><path {...p} d="M6 9l6 6 6-6"/></>,
    back:      <><path {...p} d="M15 6l-6 6 6 6"/></>,
    close:     <><path {...p} d="M6 6l12 12M18 6L6 18"/></>,
    search:    <><circle cx="11" cy="11" r="6" {...p}/><path {...p} d="M16 16l4 4"/></>,
    check:     <><path {...p} d="M5 12l5 5L20 6"/></>,
    checkCheck:<><path {...p} d="M2 12l4 4 8-8"/><path {...p} d="M10 16l4 4L22 8"/></>,
    phone:     <><path {...p} d="M5 4h4l2 5-3 2a12 12 0 005 5l2-3 5 2v4a2 2 0 01-2 2A16 16 0 013 6a2 2 0 012-2z"/></>,
    pin:       <><path {...p} d="M12 22s7-7 7-12a7 7 0 10-14 0c0 5 7 12 7 12z"/><circle cx="12" cy="10" r="2.5" {...p}/></>,
    calendar:  <><rect x="3" y="5" width="18" height="16" rx="3" {...p}/><path {...p} d="M3 10h18M8 3v4M16 3v4"/></>,
    note:      <><path {...p} d="M6 3h9l4 4v12a2 2 0 01-2 2H6a2 2 0 01-2-2V5a2 2 0 012-2zM14 3v5h5"/></>,
    camera:    <><path {...p} d="M4 8h3l2-3h6l2 3h3a1 1 0 011 1v9a2 2 0 01-2 2H5a2 2 0 01-2-2V9a1 1 0 011-1z"/><circle cx="12" cy="13" r="3.5" {...p}/></>,
    arrow:     <><path {...p} d="M5 12h14M13 6l6 6-6 6"/></>,
    leaf:      <><path {...p} d="M4 20c0-9 7-16 16-16-1 9-7 16-16 16zM4 20l8-8"/></>,
    spark:     <><path {...p} d="M12 3l1.8 5.2L19 10l-5.2 1.8L12 17l-1.8-5.2L5 10l5.2-1.8L12 3z"/></>,
    droplet:   <><path {...p} d="M12 3l6 9a6 6 0 11-12 0l6-9z"/></>,
    moon:      <><path {...p} d="M20 14A8 8 0 1110 4a6 6 0 0010 10z"/></>,
    sun:       <><circle cx="12" cy="12" r="4" {...p}/><path {...p} d="M12 3v2M12 19v2M3 12h2M19 12h2M5.6 5.6l1.4 1.4M17 17l1.4 1.4M5.6 18.4L7 17M17 7l1.4-1.4"/></>,
    heart:     <><path {...p} d="M12 20s-7-4-7-10a4 4 0 017-2 4 4 0 017 2c0 6-7 10-7 10z"/></>,
    refill:    <><path {...p} d="M4 12a8 8 0 0114-5l2-2v6h-6M20 12a8 8 0 01-14 5l-2 2v-6h6"/></>,
    falls:     <><circle cx="9" cy="5" r="2" {...p}/><path {...p} d="M7 11l3-2 4 2 4 7M11 11l-1 5-5 3"/></>,
    settings:  <><circle cx="12" cy="12" r="3" {...p}/><path {...p} d="M12 3v2M12 19v2M3 12h2M19 12h2M5.6 5.6l1.4 1.4M17 17l1.4 1.4M5.6 18.4L7 17M17 7l1.4-1.4"/></>,
    lock:      <><rect x="5" y="11" width="14" height="9" rx="2" {...p}/><path {...p} d="M8 11V8a4 4 0 018 0v3"/></>,
    send:      <><path {...p} d="M4 12l16-8-6 17-3-7-7-2z"/></>,
    waveform:  <><path {...p} d="M3 12h2M7 8v8M11 5v14M15 8v8M19 11v2"/></>,
    tag:       <><path {...p} d="M3 12V4h8l10 10-8 8L3 12z"/><circle cx="8" cy="9" r="1.5" fill={color}/></>,
    clock:     <><circle cx="12" cy="12" r="9" {...p}/><path {...p} d="M12 7v5l3 2"/></>,
    sliders:   <><path {...p} d="M4 6h10M18 6h2M4 12h2M10 12h10M4 18h14M20 18h0"/><circle cx="16" cy="6" r="2" {...p}/><circle cx="8" cy="12" r="2" {...p}/></>,
    book:      <><path {...p} d="M4 5a2 2 0 012-2h6v18H6a2 2 0 01-2-2V5zM20 5a2 2 0 00-2-2h-6v18h6a2 2 0 002-2V5z"/></>,
    eye:       <><path {...p} d="M2 12s4-7 10-7 10 7 10 7-4 7-10 7-10-7-10-7z"/><circle cx="12" cy="12" r="3" {...p}/></>,
    qr:        <><rect x="3" y="3" width="7" height="7" rx="1" {...p}/><rect x="14" y="3" width="7" height="7" rx="1" {...p}/><rect x="3" y="14" width="7" height="7" rx="1" {...p}/><path {...p} d="M14 14h3v3M21 14v3M14 21h3M21 17v4"/></>,
    list:      <><path {...p} d="M4 6h16M4 12h16M4 18h10"/></>,
    mail:      <><rect x="3" y="5" width="18" height="14" rx="2" {...p}/><path {...p} d="M3 7l9 6 9-6"/></>,
    grip:      <><circle cx="9" cy="6" r="1.2" fill={color}/><circle cx="15" cy="6" r="1.2" fill={color}/><circle cx="9" cy="12" r="1.2" fill={color}/><circle cx="15" cy="12" r="1.2" fill={color}/><circle cx="9" cy="18" r="1.2" fill={color}/><circle cx="15" cy="18" r="1.2" fill={color}/></>,
    vault:     <><path {...p} d="M12 3l8 3.5V12c0 5-3.5 8.5-8 9.5C7.5 20.5 4 17 4 12V6.5L12 3z"/></>,
    edit:      <><path {...p} d="M4 20h4l10-10-4-4L4 16v4z"/><path {...p} d="M14 6l4 4"/></>,
  };
  return (
    <svg width={size} height={size} viewBox="0 0 24 24" style={{ display: 'inline-block', flexShrink: 0, ...style }}>
      {paths[name] || null}
    </svg>
  );
};

// ─────────────────────────────────────────────────────────────
// Status bar (in-app — slim, used inside iOS frame area)
// ─────────────────────────────────────────────────────────────
const WStatusBar = ({ time = '8:24', tone = 'light' }) => {
  const c = tone === 'light' ? 'var(--ink)' : '#fff';
  return (
    <div style={{
      display: 'flex', justifyContent: 'space-between', alignItems: 'center',
      padding: '14px 28px 4px', fontSize: 15, fontWeight: 600,
      color: c, fontFamily: '-apple-system, "SF Pro Text", system-ui',
      letterSpacing: -0.2,
    }}>
      <span>{time}</span>
      <span style={{ width: 100 }} />
      <span style={{ display: 'inline-flex', gap: 5, alignItems: 'center' }}>
        <svg width="17" height="11" viewBox="0 0 17 11"><path fill={c} d="M14.5 2h1A.5.5 0 0116 2.5v6a.5.5 0 01-.5.5h-1a.5.5 0 01-.5-.5v-6a.5.5 0 01.5-.5zM10.5 4h1a.5.5 0 01.5.5v4a.5.5 0 01-.5.5h-1a.5.5 0 01-.5-.5v-4a.5.5 0 01.5-.5zM6.5 6h1a.5.5 0 01.5.5v2a.5.5 0 01-.5.5h-1a.5.5 0 01-.5-.5v-2a.5.5 0 01.5-.5zM2.5 7h1a.5.5 0 01.5.5v1a.5.5 0 01-.5.5h-1a.5.5 0 01-.5-.5v-1a.5.5 0 01.5-.5z"/></svg>
        <svg width="15" height="11" viewBox="0 0 15 11"><path fill={c} d="M7.5 1.5C4.5 1.5 2 2.6.3 4.3a.5.5 0 000 .7l.7.7a.5.5 0 00.7 0C3.1 4.2 5.2 3.3 7.5 3.3s4.4.9 5.8 2.4a.5.5 0 00.7 0l.7-.7a.5.5 0 000-.7c-1.7-1.7-4.2-2.8-7.2-2.8z M7.5 5C5.6 5 3.9 5.7 2.7 7a.5.5 0 000 .7l.7.7a.5.5 0 00.7 0c.9-.9 2.1-1.4 3.4-1.4s2.5.5 3.4 1.4a.5.5 0 00.7 0l.7-.7a.5.5 0 000-.7c-1.2-1.3-2.9-2-4.8-2zM7.5 8.5a1.5 1.5 0 100 3 1.5 1.5 0 000-3z"/></svg>
        <svg width="25" height="11" viewBox="0 0 25 11"><rect x="0.5" y="0.5" width="21" height="10" rx="2.5" fill="none" stroke={c} strokeOpacity=".4"/><rect x="2" y="2" width="18" height="7" rx="1.2" fill={c}/><rect x="22.5" y="3.5" width="1.5" height="4" rx=".5" fill={c} fillOpacity=".4"/></svg>
      </span>
    </div>
  );
};

// ─────────────────────────────────────────────────────────────
// Card — soft elevated surface
// ─────────────────────────────────────────────────────────────
const Card = ({ children, pad = 18, radius = 'var(--r-md)', tone = 'surface', style, ...rest }) => {
  const bg = tone === 'sage' ? 'var(--sage-soft)' :
             tone === 'clay' ? 'var(--clay-soft)' :
             tone === 'plum' ? 'var(--plum-soft)' :
             tone === 'amber' ? 'var(--amber-soft)' :
             tone === 'soft' ? 'var(--surface-2)' :
             'var(--surface)';
  return (
    <div style={{
      background: bg, borderRadius: radius, padding: pad,
      boxShadow: tone === 'surface' ? 'var(--sh-1)' : 'none',
      border: tone === 'surface' ? '0.5px solid var(--hairline-soft)' : 'none',
      ...style,
    }} {...rest}>{children}</div>
  );
};

// ─────────────────────────────────────────────────────────────
// Pill / Tag
// ─────────────────────────────────────────────────────────────
const Pill = ({ children, tone = 'sage', size = 'sm', icon, style }) => {
  const map = {
    sage:  ['var(--sage-soft)', 'var(--sage-ink)'],
    clay:  ['var(--clay-soft)', 'oklch(0.42 0.10 40)'],
    amber: ['var(--amber-soft)', 'oklch(0.45 0.08 70)'],
    plum:  ['var(--plum-soft)', 'oklch(0.38 0.08 320)'],
    ink:   ['var(--ink)', 'var(--bg)'],
    muted: ['var(--bg-soft)', 'var(--ink-2)'],
  };
  const [bg, fg] = map[tone] || map.sage;
  const isSm = size === 'sm';
  return (
    <span style={{
      display: 'inline-flex', alignItems: 'center', gap: 5,
      background: bg, color: fg, borderRadius: 999,
      padding: isSm ? '3px 9px' : '5px 11px',
      fontSize: isSm ? 11.5 : 13, fontWeight: 500,
      letterSpacing: 0.1,
      ...style,
    }}>
      {icon}{children}
    </span>
  );
};

// ─────────────────────────────────────────────────────────────
// Avatar — initials, soft tinted bg
// ─────────────────────────────────────────────────────────────
const Avatar = ({ name = '', size = 36, tone = 'sage', style }) => {
  const initials = name.split(' ').map(s => s[0]).slice(0, 2).join('').toUpperCase();
  const tones = {
    sage: ['var(--sage-soft)', 'var(--sage-ink)'],
    clay: ['var(--clay-soft)', 'oklch(0.42 0.10 40)'],
    plum: ['var(--plum-soft)', 'oklch(0.38 0.08 320)'],
    amber:['var(--amber-soft)', 'oklch(0.45 0.08 70)'],
    ink:  ['var(--ink)', 'var(--bg)'],
  };
  const [bg, fg] = tones[tone] || tones.sage;
  return (
    <div style={{
      width: size, height: size, borderRadius: '50%',
      background: bg, color: fg,
      display: 'inline-flex', alignItems: 'center', justifyContent: 'center',
      fontSize: size * 0.34, fontWeight: 600, letterSpacing: 0.4,
      flexShrink: 0,
      ...style,
    }}>{initials}</div>
  );
};

// ─────────────────────────────────────────────────────────────
// Patient avatar — persistent multi-patient context indicator.
// Always sits in the top-left of primary screens. Tappable —
// opens the patient detail view. Future-ready for a switcher
// (long-press or chevron) when multi-patient lands.
// ─────────────────────────────────────────────────────────────
const PatientAvatar = ({ name = 'Margaret Chen', tone = 'sage', size = 36, onTap }) => (
  <button
    onClick={onTap}
    title={`${name} · tap to view details`}
    aria-label={`Open ${name}'s details`}
    style={{
      background: 'transparent', border: 'none', padding: 0, cursor: 'pointer',
      borderRadius: '50%',
      display: 'inline-flex',
    }}>
    <Avatar name={name} size={size} tone={tone} />
  </button>
);

// ─────────────────────────────────────────────────────────────
// Bottom navigation bar
// ─────────────────────────────────────────────────────────────
const BottomNav = ({ active = 'home', onChange }) => {
  const items = [
    { id: 'home',      label: 'Home',      icon: 'home' },
    { id: 'meds',      label: 'Meds',      icon: 'pill' },
    { id: 'visits',    label: 'Visits',    icon: 'note' },
    { id: 'providers', label: 'Providers', icon: 'stethoscope' },
    { id: 'vault',     label: 'Vault',     icon: 'vault' },
  ];
  return (
    <div style={{
      position: 'absolute', bottom: 0, left: 0, right: 0,
      padding: '10px 14px 28px',
      background: 'linear-gradient(to top, var(--bg) 65%, transparent)',
      display: 'flex', justifyContent: 'space-around', alignItems: 'center',
      zIndex: 20,
    }}>
      {items.map(it => {
        const isActive = active === it.id;
        return (
          <button key={it.id} onClick={() => onChange && onChange(it.id)}
            style={{
              flex: 1, display: 'flex', flexDirection: 'column', alignItems: 'center', gap: 4,
              background: 'transparent', border: 'none', cursor: 'pointer',
              color: isActive ? 'var(--sage-deep)' : 'var(--ink-3)',
              padding: '6px 0',
            }}>
            <Icon name={it.icon} size={22} color="currentColor" stroke={isActive ? 1.8 : 1.5} />
            <span style={{ fontSize: 11, fontWeight: isActive ? 600 : 500, letterSpacing: 0.1 }}>{it.label}</span>
          </button>
        );
      })}
    </div>
  );
};

// ─────────────────────────────────────────────────────────────
// Top nav bar (in-app — large title or compact)
// ─────────────────────────────────────────────────────────────
const TopBar = ({ title, eyebrow, leading, trailing, dense = false, serif = false }) => (
  <div style={{ padding: dense ? '6px 22px 12px' : '4px 22px 18px' }}>
    <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', minHeight: 36 }}>
      <div>{leading}</div>
      <div style={{ display: 'flex', gap: 10 }}>{trailing}</div>
    </div>
    {(title || eyebrow) && (
      <div style={{ marginTop: dense ? 6 : 14 }}>
        {eyebrow && <div style={{
          fontSize: 11.5, fontWeight: 500, color: 'var(--ink-3)',
          textTransform: 'uppercase', letterSpacing: 0.8, marginBottom: 4,
        }}>{eyebrow}</div>}
        {title && <div style={{
          fontSize: dense ? 22 : 28,
          fontFamily: serif ? 'var(--font-serif)' : 'var(--font-sans)',
          fontStyle: serif ? 'italic' : 'normal',
          fontWeight: serif ? 400 : 600,
          letterSpacing: serif ? '-0.02em' : '-0.025em',
          color: 'var(--ink)', lineHeight: 1.1,
        }}>{title}</div>}
      </div>
    )}
  </div>
);

const IconBtn = ({ name, onClick, tone = 'ghost' }) => {
  const styles = {
    ghost: { background: 'transparent', color: 'var(--ink-2)' },
    soft: { background: 'var(--surface-2)', color: 'var(--ink)' },
  };
  return (
    <button onClick={onClick} style={{
      width: 36, height: 36, borderRadius: 999, border: 'none', cursor: 'pointer',
      display: 'flex', alignItems: 'center', justifyContent: 'center',
      ...styles[tone],
    }}>
      <Icon name={name} size={20} />
    </button>
  );
};

// ─────────────────────────────────────────────────────────────
// Screen — full iPhone-shaped surface (used inside DCArtboard)
// ─────────────────────────────────────────────────────────────
const PHONE_W = 390;
const PHONE_H = 844;

const Screen = ({ children, bg = 'var(--bg)', statusTone = 'light', time = '8:24', hideNav, navActive = 'home', onNav, hideStatus }) => (
  <div className="w-app" style={{
    width: PHONE_W, height: PHONE_H, background: bg,
    position: 'relative', overflow: 'hidden',
    fontFamily: 'var(--font-sans)',
  }}>
    {!hideStatus && <WStatusBar time={time} tone={statusTone} />}
    <div style={{ position: 'absolute', top: hideStatus ? 0 : 44, left: 0, right: 0, bottom: 0, overflow: 'hidden' }}>
      {children}
    </div>
    {!hideNav && <BottomNav active={navActive} onChange={onNav} />}
    {/* home indicator */}
    <div style={{
      position: 'absolute', bottom: 8, left: '50%', transform: 'translateX(-50%)',
      width: 134, height: 5, borderRadius: 100, background: 'var(--ink)', opacity: 0.28,
      zIndex: 30, pointerEvents: 'none',
    }} />
  </div>
);

// ─────────────────────────────────────────────────────────────
// Hairline row — list item with bottom border
// ─────────────────────────────────────────────────────────────
const Row = ({ children, onClick, last, pad = '14px 0' }) => (
  <div onClick={onClick} style={{
    display: 'flex', alignItems: 'center', gap: 12,
    padding: pad, borderBottom: last ? 'none' : '0.5px solid var(--hairline-soft)',
    cursor: onClick ? 'pointer' : 'default',
  }}>{children}</div>
);

// ─────────────────────────────────────────────────────────────
// Image placeholder — striped, monospace label
// ─────────────────────────────────────────────────────────────
const ImgSlot = ({ label, w = '100%', h = 100, radius = 'var(--r-sm)', tone = 'sage', style }) => {
  const colors = {
    sage: ['oklch(0.88 0.025 150)', 'oklch(0.83 0.030 150)'],
    warm: ['oklch(0.92 0.018 75)', 'oklch(0.88 0.022 75)'],
    plum: ['oklch(0.88 0.022 320)', 'oklch(0.83 0.028 320)'],
  };
  const [c1, c2] = colors[tone] || colors.sage;
  return (
    <div style={{
      width: w, height: h, borderRadius: radius, overflow: 'hidden',
      background: `repeating-linear-gradient(135deg, ${c1} 0 12px, ${c2} 12px 24px)`,
      display: 'flex', alignItems: 'center', justifyContent: 'center',
      ...style,
    }}>
      {label && <span style={{
        fontFamily: 'ui-monospace, "SF Mono", Menlo, monospace',
        fontSize: 10, color: 'var(--sage-deep)', opacity: 0.75,
        background: 'rgba(255,255,255,0.6)', padding: '3px 8px', borderRadius: 4,
        letterSpacing: 0.4,
      }}>{label}</span>}
    </div>
  );
};

// ─────────────────────────────────────────────────────────────
// Sparkline / Trend mini-chart
// ─────────────────────────────────────────────────────────────
const Sparkline = ({ data = [], w = 120, h = 32, color = 'var(--sage-deep)', fill = true }) => {
  if (!data.length) return null;
  const min = Math.min(...data), max = Math.max(...data);
  const r = max - min || 1;
  const pts = data.map((v, i) => [
    (i / (data.length - 1)) * w,
    h - 4 - ((v - min) / r) * (h - 8),
  ]);
  const d = pts.map((p, i) => `${i ? 'L' : 'M'}${p[0].toFixed(1)} ${p[1].toFixed(1)}`).join(' ');
  const area = `${d} L${w} ${h} L0 ${h} Z`;
  return (
    <svg width={w} height={h} style={{ display: 'block' }}>
      {fill && <path d={area} fill={color} opacity="0.10" />}
      <path d={d} fill="none" stroke={color} strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round"/>
      <circle cx={pts[pts.length - 1][0]} cy={pts[pts.length - 1][1]} r="2.5" fill={color}/>
    </svg>
  );
};

// ─────────────────────────────────────────────────────────────
// Corda wordmark / logomark — Triskele (three-lobed bond)
// ─────────────────────────────────────────────────────────────
const Wordmark = ({ size = 22, color = 'var(--ink)' }) => (
  <span style={{
    fontFamily: 'var(--font-sans)',
    fontSize: size, fontWeight: 600, color, letterSpacing: '-0.04em',
  }}>corda</span>
);

// Corda mark — stroked triskele. Three balanced teardrop lobes rotating
// from a shared center. Single stroke weight; round caps/joins.
// Bare by default; pass container="sage" | "ink" | "cream" for an
// app-icon style rounded square.
const Logomark = ({ size = 32, color = 'var(--sage)', container = null }) => {
  const inner = container ? size * 0.62 : size;
  const strokeColor = container === 'sage' ? '#F4F1EA'
                    : container === 'ink'  ? '#6E8B7B'
                    : container === 'cream' ? '#6E8B7B'
                    : color;
  const mark = (
    <svg width={inner} height={inner} viewBox="0 0 100 100" fill="none" aria-label="corda">
      <g transform="translate(50 50)">
        <g transform="rotate(0)"><path d="M 0 0 C -16 -10, -16 -34, 0 -36 C 16 -34, 16 -10, 0 0 Z"
          stroke={strokeColor} strokeWidth="10" strokeLinecap="round" strokeLinejoin="round" fill="none"/></g>
        <g transform="rotate(120)"><path d="M 0 0 C -16 -10, -16 -34, 0 -36 C 16 -34, 16 -10, 0 0 Z"
          stroke={strokeColor} strokeWidth="10" strokeLinecap="round" strokeLinejoin="round" fill="none"/></g>
        <g transform="rotate(240)"><path d="M 0 0 C -16 -10, -16 -34, 0 -36 C 16 -34, 16 -10, 0 0 Z"
          stroke={strokeColor} strokeWidth="10" strokeLinecap="round" strokeLinejoin="round" fill="none"/></g>
      </g>
    </svg>
  );
  if (!container) return mark;
  const bg = container === 'ink'   ? 'var(--ink)'
           : container === 'cream' ? 'var(--bg)'
           : 'var(--sage)';
  return (
    <div style={{
      width: size, height: size, borderRadius: size * 0.28,
      background: bg, display: 'inline-flex', alignItems: 'center', justifyContent: 'center',
      border: container === 'cream' ? '1px solid var(--hairline)' : 'none',
    }}>{mark}</div>
  );
};

Object.assign(window, {
  Icon, WStatusBar, Card, Pill, Avatar, PatientAvatar, BottomNav, TopBar, IconBtn,
  Screen, Row, ImgSlot, Sparkline, Wordmark, Logomark,
  PHONE_W, PHONE_H,
});
