/* Michael Style — Prototype · OWNER app (Michael's tool, not the client's).
   Tabs: Hoy · Citas · Clientes · Trabajo · Yo. Loaded via browser Babel.
   Uses global React, the DS namespace, and AppShell bits. */

const OWN = window.MichaelStyleDesignSystem_7fd21b;

/* —— shared small bits (dark surfaces, owner flavor) —— */
function OStat({ value, caption, accent }) {
  return (
    <div style={{
      display: 'flex', flexDirection: 'column', justifyContent: 'center',
      background: 'var(--card)', border: '1px solid var(--bd-d)', borderRadius: 'var(--radius-md)', padding: '12px 13px',
    }}>
      <div style={{ fontFamily: 'var(--font-display)', fontWeight: 900, fontSize: '1.55rem', letterSpacing: '-0.04em', lineHeight: 0.9, color: accent ? 'var(--accent)' : 'var(--bone)' }}>{value}</div>
      <div style={{ fontFamily: 'var(--font-mono)', fontSize: '0.49rem', textTransform: 'uppercase', letterSpacing: '0.12em', color: 'var(--muted-2)', marginTop: '5px' }}>{caption}</div>
    </div>
  );
}

/* Sample owner notifications shown in the bell dropdown. */
const OWNER_NOTIFS = [
  { icon: 'bell', title: '2 solicitudes de reserva', sub: 'Erick Santos · Pedro Lima', unread: true, action: 'citas' },
  { icon: 'star', title: 'Nueva reseña · 5.0 ★', sub: 'Giovannis T. te calificó', unread: true },
  { icon: 'dollar', title: 'Pago recibido · $250', sub: 'Zelle · Andrés Peña', unread: false },
  { icon: 'clock', title: 'Seguimiento SMP · Andrés P.', sub: 'Día 4 de 10 · envía cuidado', unread: false },
];

/* Shared owner top bar — brand wordmark on the left (the page name is
   already in the nav), standard notification bell + profile avatar on the
   right. The bell opens a notifications dropdown. Present on every tab. */
function OwnerTopBar({ onBell }) {
  const [open, setOpen] = React.useState(false);
  const unread = OWNER_NOTIFS.filter((n) => n.unread).length;
  const tap = (n) => { setOpen(false); if (n.action === 'citas' && onBell) onBell(); };
  return (
    <div style={{ position: 'relative', display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: '12px' }}>
      <div style={{ fontFamily: 'var(--font-display)', fontWeight: 900, fontSize: '0.92rem', letterSpacing: '-0.02em', textTransform: 'uppercase', color: 'var(--bone)', lineHeight: 1 }}>
        MICHAEL<span style={{ color: 'var(--accent)' }}>/</span>STYLE
      </div>
      <div style={{ display: 'flex', alignItems: 'center', gap: '8px', flex: 'none' }}>
        <button onClick={() => setOpen((o) => !o)} aria-label="Notificaciones" aria-expanded={open} style={{
          position: 'relative', width: '38px', height: '38px', borderRadius: '50%', flex: 'none',
          display: 'flex', alignItems: 'center', justifyContent: 'center', cursor: 'pointer',
          background: open ? 'color-mix(in srgb,var(--accent) 16%,var(--card))' : 'var(--card)',
          border: `1px solid ${open ? 'var(--accent)' : 'var(--bd-d)'}`, color: open ? 'var(--accent)' : 'var(--bone)',
        }}>
          <window.Icon name="bell" size={17} />
          {unread > 0 && <span style={{ position: 'absolute', top: '7px', right: '8px', width: '8px', height: '8px', borderRadius: '50%', background: 'var(--accent)', border: '2px solid var(--ink)' }} />}
        </button>
        <div style={{ width: '38px', height: '38px', borderRadius: '50%', flex: 'none', background: 'color-mix(in srgb,var(--accent) 22%,var(--card))', color: 'var(--accent)', display: 'flex', alignItems: 'center', justifyContent: 'center', fontFamily: 'var(--font-display)', fontWeight: 900, fontSize: '0.9rem' }}>MA</div>
      </div>

      {open && (
        <>
          <div onClick={() => setOpen(false)} style={{ position: 'fixed', inset: 0, zIndex: 80 }} />
          <div role="menu" aria-label="Notificaciones" style={{
            position: 'absolute', top: '46px', right: 0, width: '248px', zIndex: 81,
            background: 'var(--ink-2)', border: '1px solid var(--bd-d2)', borderRadius: 'var(--radius-md)',
            boxShadow: '0 24px 60px -24px #000', overflow: 'hidden',
          }}>
            <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', padding: '12px 13px', borderBottom: '1px solid var(--bd-d)' }}>
              <span style={{ fontFamily: 'var(--font-mono)', fontSize: '0.55rem', letterSpacing: '0.13em', textTransform: 'uppercase', color: 'var(--accent)' }}>Notificaciones</span>
              <span style={{ fontFamily: 'var(--font-mono)', fontSize: '0.5rem', letterSpacing: '0.08em', textTransform: 'uppercase', color: 'var(--muted-2)' }}>{unread} nuevas</span>
            </div>
            <div style={{ maxHeight: '252px', overflowY: 'auto' }} className="ms-noscroll">
              {OWNER_NOTIFS.map((n, i) => (
                <button key={i} onClick={() => tap(n)} style={{
                  width: '100%', textAlign: 'left', display: 'flex', alignItems: 'center', gap: '10px', cursor: 'pointer',
                  background: 'none', border: 'none', borderBottom: i === OWNER_NOTIFS.length - 1 ? 'none' : '1px solid var(--bd-d)', padding: '11px 13px',
                }}>
                  <span style={{ width: '30px', height: '30px', borderRadius: '50%', flex: 'none', display: 'flex', alignItems: 'center', justifyContent: 'center', background: 'color-mix(in srgb,var(--accent) 14%,var(--card))', color: 'var(--accent)' }}><window.Icon name={n.icon} size={15} /></span>
                  <div style={{ flex: 1, minWidth: 0 }}>
                    <div style={{ fontSize: '0.73rem', color: 'var(--bone)', fontWeight: 600, whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' }}>{n.title}</div>
                    <div style={{ fontSize: '0.6rem', color: 'var(--muted)', marginTop: '2px', whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' }}>{n.sub}</div>
                  </div>
                  {n.unread && <span style={{ width: '7px', height: '7px', borderRadius: '50%', flex: 'none', background: 'var(--accent)' }} />}
                </button>
              ))}
            </div>
          </div>
        </>
      )}
    </div>
  );
}

/* one appointment row */
function ApptRow({ time, name, svc, status, last }) {
  const dot = status === 'now' ? 'var(--accent)' : status === 'done' ? 'var(--muted-2)' : 'var(--bone)';
  return (
    <div style={{ display: 'flex', alignItems: 'center', gap: '12px', padding: '11px 0', borderBottom: last ? 'none' : '1px solid var(--bd-d)', opacity: status === 'done' ? 0.55 : 1 }}>
      <div style={{ fontFamily: 'var(--font-mono)', fontSize: '0.62rem', letterSpacing: '0.04em', color: status === 'now' ? 'var(--accent)' : 'var(--muted)', width: '52px', flex: 'none' }}>{time}</div>
      <span style={{ width: '7px', height: '7px', borderRadius: '50%', background: dot, flex: 'none', boxShadow: status === 'now' ? '0 0 0 4px color-mix(in srgb,var(--accent) 22%,transparent)' : 'none' }} />
      <div style={{ flex: 1, minWidth: 0 }}>
        <div style={{ fontSize: '0.78rem', color: 'var(--bone)', fontWeight: 600, whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' }}>{name}</div>
        <div style={{ fontFamily: 'var(--font-mono)', fontSize: '0.52rem', letterSpacing: '0.07em', textTransform: 'uppercase', color: 'var(--muted-2)', marginTop: '2px' }}>{svc}</div>
      </div>
      {status === 'now' && <span style={{ fontFamily: 'var(--font-mono)', fontSize: '0.5rem', letterSpacing: '0.1em', textTransform: 'uppercase', color: 'var(--accent)', flex: 'none' }}>Ahora</span>}
    </div>
  );
}

const TODAY = [
  { time: '9:00A', name: 'Luis Reyes', svc: '#1 fade · línea', status: 'done' },
  { time: '10:15', name: 'David Ortiz', svc: 'Beard sculpt', status: 'done' },
  { time: '11:30', name: 'Andrés P.', svc: 'SMP · sesión 2', status: 'now' },
  { time: '1:00P', name: 'Marco Díaz', svc: '#2 fade · sharp line', status: 'up' },
  { time: '2:30P', name: 'Jay Carrillo', svc: 'Kids cut', status: 'up' },
  { time: '5:30P', name: 'Carlos M.', svc: '#2 fade · the usual', status: 'up' },
];

/* ——— HOY · dashboard (mixed) with layout variations ——— */
function OwnerHome({ layout = 'Mixto', period = 'Hoy', goCitas, goClientes, goPagos }) {
  const { Card, Pill, Button } = OWN;
  const money = period === 'Semana' ? '$X,XXX' : '$XXX';
  const moneyCap = period === 'Semana' ? 'Ingresos · semana' : 'Ingresos · hoy';

  const NextCard = (
    <Card variant="accent" style={{ marginBottom: '11px' }}>
      <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}>
        <Pill variant="accent">Próximo · Next up</Pill>
        <span style={{ fontFamily: 'var(--font-mono)', fontSize: '0.58rem', letterSpacing: '0.06em', color: 'var(--accent)' }}>11:30</span>
      </div>
      <div style={{ fontFamily: 'var(--font-display)', fontWeight: 900, fontSize: '1.45rem', textTransform: 'uppercase', letterSpacing: '-0.03em', margin: '11px 0 2px', color: 'var(--bone)' }}>Andrés P.</div>
      <div style={{ fontSize: '0.72rem', color: 'var(--muted)' }}>SMP · sesión 2 de 3 · cicatrizando bien</div>
      <div style={{ display: 'flex', gap: '8px', marginTop: '13px' }}>
        <Button variant="fill" size="sm" style={{ flex: 1 }} onClick={goClientes}>Ver ficha</Button>
        <Button variant="line" size="sm" style={{ flex: 1 }}>Mensaje</Button>
      </div>
    </Card>
  );

  const IncomeStrip = (
    <div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: '8px', marginBottom: '11px' }}>
      <button onClick={goPagos} style={{ textAlign: 'left', padding: 0, border: 'none', background: 'none', cursor: 'pointer' }}>
        <OStat value={money} caption={moneyCap + ' →'} accent />
      </button>
      <OStat value="6" caption="Citas hoy · booked" />
    </div>
  );

  const TodayList = (
    <Card style={{ marginBottom: '11px' }}>
      <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'baseline', marginBottom: '4px' }}>
        <div style={{ fontFamily: 'var(--font-mono)', fontSize: '0.55rem', letterSpacing: '0.13em', textTransform: 'uppercase', color: 'var(--muted-2)' }}>La agenda · Today</div>
        <button onClick={goCitas} style={{ background: 'none', border: 'none', cursor: 'pointer', fontFamily: 'var(--font-mono)', fontSize: '0.52rem', letterSpacing: '0.1em', textTransform: 'uppercase', color: 'var(--accent)', padding: 0 }}>Ver todo →</button>
      </div>
      {TODAY.slice(2, 6).map((a, i, arr) => <ApptRow key={i} {...a} last={i === arr.length - 1} />)}
    </Card>
  );

  const Alerts = (
    <Card>
      <div style={{ fontFamily: 'var(--font-mono)', fontSize: '0.55rem', letterSpacing: '0.13em', textTransform: 'uppercase', color: 'var(--muted-2)', marginBottom: '4px' }}>Pendientes · Needs you</div>
      <button onClick={goCitas} style={{ width: '100%', textAlign: 'left', background: 'none', border: 'none', cursor: 'pointer', display: 'flex', alignItems: 'center', gap: '11px', padding: '11px 0', borderBottom: '1px solid var(--bd-d)' }}>
        <span style={{ width: '30px', height: '30px', borderRadius: '50%', flex: 'none', display: 'flex', alignItems: 'center', justifyContent: 'center', background: 'color-mix(in srgb,var(--accent) 16%,var(--card))', color: 'var(--accent)' }}><window.Icon name="bell" size={15} /></span>
        <div style={{ flex: 1 }}><div style={{ fontSize: '0.74rem', color: 'var(--bone)', fontWeight: 600 }}>2 solicitudes de reserva</div><div style={{ fontSize: '0.62rem', color: 'var(--muted)' }}>Confirma o rechaza</div></div>
        <span style={{ color: 'var(--muted-2)' }}><window.Icon name="chevron" size={15} /></span>
      </button>
      <button onClick={goClientes} style={{ width: '100%', textAlign: 'left', background: 'none', border: 'none', cursor: 'pointer', display: 'flex', alignItems: 'center', gap: '11px', padding: '11px 0' }}>
        <span style={{ width: '30px', height: '30px', borderRadius: '50%', flex: 'none', display: 'flex', alignItems: 'center', justifyContent: 'center', background: 'color-mix(in srgb,var(--accent) 16%,var(--card))', color: 'var(--accent)' }}><window.Icon name="clock" size={15} /></span>
        <div style={{ flex: 1 }}><div style={{ fontSize: '0.74rem', color: 'var(--bone)', fontWeight: 600 }}>Andrés P. · seguimiento SMP</div><div style={{ fontSize: '0.62rem', color: 'var(--muted)' }}>Día 4 de 10 · enviar nota de cuidado</div></div>
        <span style={{ color: 'var(--muted-2)' }}><window.Icon name="chevron" size={15} /></span>
      </button>
    </Card>
  );

  let body;
  if (layout === 'Agenda') {
    body = (<>
      {NextCard}
      <Card style={{ marginBottom: '11px' }}>
        <div style={{ fontFamily: 'var(--font-mono)', fontSize: '0.55rem', letterSpacing: '0.13em', textTransform: 'uppercase', color: 'var(--muted-2)', marginBottom: '2px' }}>El día completo · Full day</div>
        {TODAY.map((a, i, arr) => <ApptRow key={i} {...a} last={i === arr.length - 1} />)}
      </Card>
      <div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: '8px' }}>
        <OStat value={money} caption={moneyCap} accent />
        <OStat value="2" caption="Por confirmar" />
      </div>
    </>);
  } else if (layout === 'Ingresos') {
    body = (<>
      <Card variant="accent" style={{ marginBottom: '11px' }}>
        <div style={{ fontFamily: 'var(--font-mono)', fontSize: '0.55rem', letterSpacing: '0.13em', textTransform: 'uppercase', color: 'var(--accent)' }}>{moneyCap}</div>
        <div style={{ fontFamily: 'var(--font-display)', fontWeight: 900, fontSize: '3rem', letterSpacing: '-0.04em', lineHeight: 0.92, color: 'var(--bone)', margin: '6px 0 2px' }}>{money}</div>
        <div style={{ fontSize: '0.68rem', color: 'var(--muted)' }}>{period === 'Semana' ? '32 citas · 4 nuevos clientes' : '6 citas · 1 SMP · 1 nuevo'}</div>
        <div style={{ display: 'flex', alignItems: 'flex-end', gap: '5px', height: '46px', marginTop: '14px' }}>
          {[40, 62, 35, 78, 90, 55, 70].map((h, i) => (
            <div key={i} style={{ flex: 1, height: h + '%', borderRadius: '3px 3px 0 0', background: i === 4 ? 'var(--accent)' : 'color-mix(in srgb,var(--accent) 28%,var(--card))' }} />
          ))}
        </div>
        <div style={{ display: 'flex', justifyContent: 'space-between', fontFamily: 'var(--font-mono)', fontSize: '0.45rem', letterSpacing: '0.08em', color: 'var(--muted-2)', marginTop: '5px' }}>{['L', 'M', 'M', 'J', 'V', 'S', 'D'].map((d, i) => <span key={i}>{d}</span>)}</div>
      </Card>
      <div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr 1fr', gap: '8px', marginBottom: '11px' }}>
        <OStat value="$XX" caption="Promedio" />
        <OStat value="5.0" caption="Rating ★" accent />
        <OStat value="6" caption="Citas hoy" />
      </div>
      {NextCard}
    </>);
  } else {
    body = (<>{IncomeStrip}{NextCard}{TodayList}{Alerts}</>);
  }

  return (
    <window.ScreenBody label={'App Dueño · Hoy (' + layout + ')'}>
      <OwnerTopBar onBell={goCitas} />
      <window.Eyebrow>Lunes 30 jun</window.Eyebrow>
      <window.AppH>Buenas, Michael</window.AppH>
      <window.ASub>{TODAY.filter((a) => a.status !== 'done').length} citas por delante · Dios primero</window.ASub>
      {body}
    </window.ScreenBody>
  );
}

/* ——— CITAS · day agenda + pending requests (accept/reject) ——— */
function OwnerCitas({ onBell }) {
  const { Card, Button } = OWN;
  const [day, setDay] = React.useState('Hoy');
  const days = ['Hoy', 'Mar', 'Mié', 'Jue', 'Vie'];
  const [reqs, setReqs] = React.useState([
    { id: 1, name: 'Erick Santos', svc: 'Solicita · #2 fade', when: 'Jue · 4:00P' },
    { id: 2, name: 'Pedro Lima', svc: 'Solicita · consulta SMP', when: 'Vie · 11:00A' },
  ]);
  const [resolved, setResolved] = React.useState({});
  const act = (id, kind) => { setResolved((r) => ({ ...r, [id]: kind })); };
  return (
    <window.ScreenBody label="App Dueño · Citas">
      <OwnerTopBar onBell={onBell} />
      <window.ASub>Tu día · at a glance.</window.ASub>

      <div style={{ display: 'flex', gap: '7px', marginBottom: '13px', overflowX: 'auto' }} className="ms-noscroll">
        {days.map((d) => {
          const on = d === day;
          return (
            <button key={d} onClick={() => setDay(d)} aria-pressed={on} style={{
              fontFamily: 'var(--font-mono)', fontSize: '0.58rem', letterSpacing: '0.08em', textTransform: 'uppercase', padding: '8px 14px',
              borderRadius: 'var(--radius-pill)', cursor: 'pointer', flex: 'none',
              border: `1px solid ${on ? 'var(--accent)' : 'var(--bd-d)'}`,
              background: on ? 'var(--accent)' : 'transparent', color: on ? 'var(--on-accent)' : 'var(--muted)',
            }}>{d}</button>
          );
        })}
      </div>

      <Card style={{ marginBottom: '13px' }}>
        {TODAY.map((a, i, arr) => <ApptRow key={i} {...a} last={i === arr.length - 1} />)}
      </Card>

      <div style={{ fontFamily: 'var(--font-mono)', fontSize: '0.56rem', letterSpacing: '0.14em', textTransform: 'uppercase', color: 'var(--accent)', marginBottom: '9px' }}>Solicitudes · Requests</div>
      {reqs.map((r) => {
        const st = resolved[r.id];
        return (
          <div key={r.id} style={{
            background: 'var(--card)', border: `1px solid ${st === 'ok' ? 'color-mix(in srgb,var(--accent) 45%,transparent)' : 'var(--bd-d)'}`,
            borderRadius: 'var(--radius-md)', padding: '13px', marginBottom: '9px', opacity: st === 'no' ? 0.5 : 1,
          }}>
            <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'baseline' }}>
              <div style={{ fontSize: '0.82rem', color: 'var(--bone)', fontWeight: 600 }}>{r.name}</div>
              <div style={{ fontFamily: 'var(--font-mono)', fontSize: '0.55rem', letterSpacing: '0.06em', color: 'var(--muted)' }}>{r.when}</div>
            </div>
            <div style={{ fontFamily: 'var(--font-mono)', fontSize: '0.52rem', letterSpacing: '0.07em', textTransform: 'uppercase', color: 'var(--muted-2)', marginTop: '3px' }}>{r.svc}</div>
            {!st ? (
              <div style={{ display: 'flex', gap: '8px', marginTop: '12px' }}>
                <button onClick={() => act(r.id, 'ok')} style={{ flex: 1, display: 'inline-flex', alignItems: 'center', justifyContent: 'center', gap: '6px', fontFamily: 'var(--font-mono)', fontSize: '0.56rem', letterSpacing: '0.1em', textTransform: 'uppercase', padding: '10px', borderRadius: 'var(--radius-pill)', border: 'none', cursor: 'pointer', background: 'var(--accent)', color: 'var(--on-accent)' }}><window.Icon name="check" size={14} /> Aceptar</button>
                <button onClick={() => act(r.id, 'no')} style={{ flex: 1, display: 'inline-flex', alignItems: 'center', justifyContent: 'center', gap: '6px', fontFamily: 'var(--font-mono)', fontSize: '0.56rem', letterSpacing: '0.1em', textTransform: 'uppercase', padding: '10px', borderRadius: 'var(--radius-pill)', cursor: 'pointer', background: 'transparent', color: 'var(--muted)', border: '1px solid var(--bd-d)' }}><window.Icon name="x" size={14} /> Rechazar</button>
              </div>
            ) : (
              <div style={{ marginTop: '10px', fontFamily: 'var(--font-mono)', fontSize: '0.54rem', letterSpacing: '0.1em', textTransform: 'uppercase', color: st === 'ok' ? 'var(--accent)' : 'var(--muted-2)' }}>{st === 'ok' ? '✓ Confirmada' : '✕ Rechazada'}</div>
            )}
          </div>
        );
      })}
    </window.ScreenBody>
  );
}

/* ——— CLIENTES · CRM list + detail ——— */
const CLIENTS = [
  { in: 'CM', name: 'Carlos Martínez', last: 'hace 18 días', tag: 'Regular', cuts: 5, smp: true, note: '#2 fade, línea marcada. Sensible en la nuca — máquina suave.' },
  { in: 'AP', name: 'Andrés Peña', last: 'sesión 2 · hoy', tag: 'SMP', cuts: 2, smp: true, note: 'Serie SMP de 3. Entradas. Día 4 de cicatrización, va bien.' },
  { in: 'LR', name: 'Luis Reyes', last: 'hoy', tag: 'Regular', cuts: 12, smp: false, note: '#1 fade siempre. Le gusta rápido, poco hablar.' },
  { in: 'DO', name: 'David Ortiz', last: 'hoy', tag: 'Barba', cuts: 7, smp: false, note: 'Beard sculpt cada 3 semanas. Aceite al final.' },
  { in: 'JC', name: 'Jay Carrillo', last: 'hace 1 mes', tag: 'Niños', cuts: 3, smp: false, note: 'Hijo de Ana. Paciente, premio al final 😊 — sin emoji en factura.' },
];
function OwnerClientes({ onBell }) {
  const { Card, Pill, Button } = OWN;
  const [q, setQ] = React.useState('');
  const [open, setOpen] = React.useState(null);
  const list = CLIENTS.filter((c) => c.name.toLowerCase().includes(q.toLowerCase()));
  const sel = CLIENTS.find((c) => c.name === open);
  return (
    <window.ScreenBody label="App Dueño · Clientes">
      <OwnerTopBar onBell={onBell} />
      <window.ASub>{CLIENTS.length} activos · Houston, TX</window.ASub>

      <input value={q} onChange={(e) => setQ(e.target.value)} placeholder="Buscar · Search" style={{
        width: '100%', boxSizing: 'border-box', fontFamily: 'var(--font-body)', fontSize: '0.8rem',
        padding: '11px 14px', borderRadius: 'var(--radius-input)', border: '1px solid var(--bd-d)',
        background: 'var(--card)', color: 'var(--bone)', marginBottom: '13px', outline: 'none',
      }} />

      {sel && (
        <Card variant="accent" style={{ marginBottom: '13px' }}>
          <div style={{ display: 'flex', alignItems: 'center', gap: '12px' }}>
            <div style={{ width: '44px', height: '44px', borderRadius: '50%', flex: 'none', background: 'color-mix(in srgb,var(--accent) 22%,var(--card))', color: 'var(--accent)', display: 'flex', alignItems: 'center', justifyContent: 'center', fontFamily: 'var(--font-display)', fontWeight: 900 }}>{sel.in}</div>
            <div style={{ flex: 1 }}>
              <div style={{ fontSize: '0.86rem', color: 'var(--bone)', fontWeight: 600 }}>{sel.name}</div>
              <div style={{ fontFamily: 'var(--font-mono)', fontSize: '0.52rem', letterSpacing: '0.08em', textTransform: 'uppercase', color: 'var(--muted)', marginTop: '3px' }}>{sel.cuts} cortes{sel.smp ? ' · 1 serie SMP' : ''}</div>
            </div>
            <button onClick={() => setOpen(null)} style={{ background: 'none', border: 'none', cursor: 'pointer', color: 'var(--muted-2)' }}><window.Icon name="x" size={16} /></button>
          </div>
          <div style={{ fontFamily: 'var(--font-mono)', fontSize: '0.5rem', letterSpacing: '0.13em', textTransform: 'uppercase', color: 'var(--accent)', margin: '13px 0 6px' }}>Nota · Notes</div>
          <p style={{ fontSize: '0.74rem', color: 'var(--bone)', lineHeight: 1.5, margin: 0 }}>{sel.note}</p>
          <div style={{ fontFamily: 'var(--font-mono)', fontSize: '0.5rem', letterSpacing: '0.13em', textTransform: 'uppercase', color: 'var(--accent)', margin: '13px 0 6px' }}>Fotos · Photos</div>
          <div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr 1fr', gap: '6px' }}>
            {[0, 1, 2].map((i) => <div key={i} className="ms-work-texture" style={{ aspectRatio: '1/1', borderRadius: '10px' }} />)}
          </div>
          <Button variant="fill" size="sm" style={{ width: '100%', marginTop: '13px' }}>Nueva cita</Button>
        </Card>
      )}

      {list.map((c) => (
        <button key={c.name} onClick={() => setOpen(c.name)} style={{
          width: '100%', textAlign: 'left', display: 'flex', alignItems: 'center', gap: '12px', cursor: 'pointer',
          background: 'var(--card)', border: `1px solid ${open === c.name ? 'color-mix(in srgb,var(--accent) 40%,transparent)' : 'var(--bd-d)'}`,
          borderRadius: 'var(--radius-md)', padding: '11px', marginBottom: '8px',
        }}>
          <div style={{ width: '38px', height: '38px', borderRadius: '50%', flex: 'none', background: 'color-mix(in srgb,var(--bone) 8%,var(--card))', color: 'var(--bone)', display: 'flex', alignItems: 'center', justifyContent: 'center', fontFamily: 'var(--font-display)', fontWeight: 900, fontSize: '0.82rem' }}>{c.in}</div>
          <div style={{ flex: 1, minWidth: 0 }}>
            <div style={{ fontSize: '0.78rem', color: 'var(--bone)', fontWeight: 600 }}>{c.name}</div>
            <div style={{ fontFamily: 'var(--font-mono)', fontSize: '0.5rem', letterSpacing: '0.07em', textTransform: 'uppercase', color: 'var(--muted-2)', marginTop: '2px' }}>Última visita · {c.last}</div>
          </div>
          <Pill variant={c.smp ? 'accent' : 'line'}>{c.tag}</Pill>
        </button>
      ))}
    </window.ScreenBody>
  );
}

/* ——— TRABAJO · portfolio management ——— */
function OwnerTrabajo({ onBell }) {
  const { FilterTabs } = OWN;
  const [f, setF] = React.useState('Todo');
  const tiles = [
    { span: 'tall', tag: 'Fade', img: 'assets/work-fade.png' }, { span: 'wide', tag: 'Beard', img: 'assets/work-beard.png' },
    { span: '', tag: 'Niños', img: 'assets/work-kids.png' }, { span: '', tag: 'SMP' },
    { span: 'wide', tag: 'Barba', img: 'assets/work-beard-lineup.png' }, { span: '', tag: 'Diseño' },
  ];
  return (
    <window.ScreenBody label="App Dueño · Trabajo">
      <OwnerTopBar onBell={onBell} />
      <window.ASub>Sube y organiza · the proof.</window.ASub>
      <div style={{ marginBottom: '12px' }}>
        <FilterTabs items={['Todo', 'Fades', 'Barbas', 'SMP', 'Diseños']} value={f} onChange={setF} />
      </div>
      <button style={{
        width: '100%', display: 'flex', alignItems: 'center', justifyContent: 'center', gap: '9px', cursor: 'pointer',
        border: '1px dashed var(--bd-d2)', background: 'transparent', color: 'var(--accent)',
        borderRadius: 'var(--radius-md)', padding: '15px', marginBottom: '11px',
        fontFamily: 'var(--font-mono)', fontSize: '0.6rem', letterSpacing: '0.1em', textTransform: 'uppercase',
      }}><window.Icon name="camera" size={17} /> Subir foto · Add work</button>
      <div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gridAutoRows: '88px', gap: '7px' }}>
        {tiles.map((t, i) => (
          <div key={i} style={{
            borderRadius: '12px', position: 'relative', overflow: 'hidden', border: '1px solid var(--bd-d)',
            gridColumn: t.span === 'wide' ? 'span 2' : 'span 1', gridRow: t.span === 'tall' ? 'span 2' : 'span 1',
          }}>
            {t.img
              ? <img src={t.img} alt={t.tag} style={{ position: 'absolute', inset: 0, width: '100%', height: '100%', objectFit: 'cover', filter: 'grayscale(1)' }} />
              : <div className="ms-work-texture" style={{ position: 'absolute', inset: 0 }} />}
            {t.tag && <span style={{ position: 'absolute', bottom: '8px', left: '10px', fontFamily: 'var(--font-mono)', fontSize: '0.48rem', letterSpacing: '0.14em', textTransform: 'uppercase', color: 'var(--accent)', zIndex: 2 }}>{t.tag}</span>}
          </div>
        ))}
      </div>
    </window.ScreenBody>
  );
}

/* ——— YO · Michael's profile + business settings ——— */
function OwnerYo({ accent, setAccent, goCobrar, goPagos, onBell, payments }) {
  const { Button, Card } = OWN;
  const [lang, setLang] = React.useState('EN');
  const [mkt, setMkt] = React.useState(false);
  const feed = payments || PAYMENTS;
  const weekTotal = feed.reduce((s, p) => s + p.amount, 0);
  const weekClients = new Set(feed.map((p) => p.name)).size;
  const trend = [40, 62, 35, 78, 90, 55, 70];
  const row = { display: 'flex', alignItems: 'center', justifyContent: 'space-between', padding: '13px 0', borderBottom: '1px solid var(--bd-d)' };
  const rowLabel = { display: 'flex', alignItems: 'center', gap: '10px', color: 'var(--bone)', fontSize: '0.76rem' };
  const mktTools = [
    { icon: 'share', title: 'Compartir trabajo · Share to IG', sub: 'Postea fades y antes/después a @michaelstyle23' },
    { icon: 'megaphone', title: 'Promoción · Run a promo', sub: 'Crea una oferta — ej. 1ra consulta SMP gratis' },
    { icon: 'star', title: 'Pedir reseñas · Ask for reviews', sub: 'Envía link de Google a clientes recientes' },
    { icon: 'users', title: 'Referidos · Referral card', sub: 'Trae un amigo · ambos ahorran' },
  ];
  return (
    <window.ScreenBody label="App Dueño · Yo">
      <OwnerTopBar onBell={onBell} />
      <window.ASub>Dominican barber · SMP artist · Houston, TX</window.ASub>

      {/* —— Ingresos · big income card → opens the income detail page —— */}
      <div style={{ fontFamily: 'var(--font-mono)', fontSize: '0.56rem', letterSpacing: '0.14em', textTransform: 'uppercase', color: 'var(--accent)', marginBottom: '9px' }}>Dinero · Money</div>
      <button onClick={goPagos} aria-label="Ver detalle de ingresos" style={{ width: '100%', textAlign: 'left', background: 'none', border: 'none', padding: 0, cursor: 'pointer', marginBottom: '10px' }}>
        <Card variant="accent">
          <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', gap: '10px' }}>
            <span style={{ fontFamily: 'var(--font-mono)', fontSize: '0.55rem', letterSpacing: '0.13em', textTransform: 'uppercase', color: 'var(--accent)' }}>Ingresos</span>
            <span style={{ display: 'inline-flex', alignItems: 'center', gap: '4px', fontFamily: 'var(--font-mono)', fontSize: '0.52rem', letterSpacing: '0.1em', textTransform: 'uppercase', color: 'var(--accent)' }}>Ver detalle <window.Icon name="chevron" size={12} /></span>
          </div>
          <div style={{ fontFamily: 'var(--font-display)', fontWeight: 900, fontSize: '3.7rem', letterSpacing: '-0.04em', lineHeight: 0.92, color: 'var(--bone)', margin: '8px 0 2px' }}>{money(weekTotal)}</div>
          <div style={{ fontSize: '0.68rem', color: 'var(--muted)' }}>Esta semana · {feed.length} pagos · {weekClients} clientes</div>
          <div style={{ display: 'flex', alignItems: 'flex-end', gap: '6px', height: '60px', marginTop: '16px' }}>
            {trend.map((h, i) => (
              <div key={i} style={{ flex: 1, height: h + '%', borderRadius: '3px 3px 0 0', background: i === 4 ? 'var(--accent)' : 'color-mix(in srgb,var(--accent) 28%,var(--card))' }} />
            ))}
          </div>
          <div style={{ display: 'flex', justifyContent: 'space-between', fontFamily: 'var(--font-mono)', fontSize: '0.46rem', letterSpacing: '0.08em', color: 'var(--muted-2)', marginTop: '6px' }}>{['L', 'M', 'M', 'J', 'V', 'S', 'D'].map((d, i) => <span key={i}>{d}</span>)}</div>
        </Card>
      </button>
      <Button variant="fill" style={{ width: '100%', marginBottom: '18px', display: 'inline-flex', alignItems: 'center', justifyContent: 'center', gap: '8px' }} onClick={goCobrar}>
        <window.Icon name="plus" size={16} /> Cobrar · Charge
      </Button>

      <div style={{ ...row, borderTop: '1px solid var(--bd-d)' }}>
        <span style={rowLabel}><window.Icon name="clock" size={17} /> Horario · Hours</span>
        <span style={{ fontFamily: 'var(--font-mono)', fontSize: '0.55rem', letterSpacing: '0.08em', color: 'var(--muted)' }}>9–7 · L–S</span>
      </div>
      <div style={row}>
        <span style={rowLabel}><window.Icon name="scissors" size={17} /> Servicios y precios</span>
        <span style={{ color: 'var(--muted-2)' }}><window.Icon name="chevron" size={15} /></span>
      </div>
      <button onClick={() => setMkt((v) => !v)} aria-expanded={mkt} style={{ ...row, width: '100%', textAlign: 'left', background: 'none', border: 'none', borderBottom: '1px solid var(--bd-d)', cursor: 'pointer' }}>
        <span style={rowLabel}><window.Icon name="megaphone" size={17} /> Marketing · Grow</span>
        <span style={{ color: 'var(--muted-2)', transform: mkt ? 'rotate(90deg)' : 'none', transition: 'transform var(--dur-fast,.18s)' }}><window.Icon name="chevron" size={15} /></span>
      </button>
      {mkt && (
        <div style={{ padding: '11px 0 4px' }}>
          {mktTools.map((m) => (
            <button key={m.title} style={{
              width: '100%', textAlign: 'left', display: 'flex', alignItems: 'center', gap: '11px', cursor: 'pointer',
              background: 'var(--card)', border: '1px solid var(--bd-d)', borderRadius: 'var(--radius-md)', padding: '11px', marginBottom: '8px',
            }}>
              <span style={{ width: '32px', height: '32px', borderRadius: '50%', flex: 'none', display: 'flex', alignItems: 'center', justifyContent: 'center', background: 'color-mix(in srgb,var(--accent) 16%,var(--card))', color: 'var(--accent)' }}><window.Icon name={m.icon} size={16} /></span>
              <div style={{ flex: 1, minWidth: 0 }}>
                <div style={{ fontSize: '0.74rem', color: 'var(--bone)', fontWeight: 600 }}>{m.title}</div>
                <div style={{ fontSize: '0.61rem', color: 'var(--muted)', marginTop: '2px' }}>{m.sub}</div>
              </div>
              <span style={{ color: 'var(--muted-2)' }}><window.Icon name="chevron" size={14} /></span>
            </button>
          ))}
        </div>
      )}
      <div style={row}>
        <span style={rowLabel}><window.Icon name="globe" size={17} /> Idioma · Language</span>
        <window.LangToggle value={lang} onChange={setLang} />
      </div>
      <div style={{ ...row, borderBottom: 'none' }}>
        <span style={rowLabel}><window.Icon name="bell" size={17} /> Notificaciones</span>
        <span style={{ fontFamily: 'var(--font-mono)', fontSize: '0.55rem', letterSpacing: '0.1em', color: 'var(--accent)' }}>ON</span>
      </div>

      <div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: '8px', marginTop: '16px' }}>
        <OStat value="5.0" caption="Rating ★" accent />
        <OStat value="@23" caption="michaelstyle" />
      </div>

      <div style={{ textAlign: 'center', fontStyle: 'italic', color: 'var(--muted-2)', fontSize: '0.68rem', margin: '22px 0 4px' }}>Dios primero.</div>
    </window.ScreenBody>
  );
}

/* ——— PAGOS · receive payments + full history by method ——— */
/* Payment methods — kept on-brand (mono + single accent, no vendor colors). */
const PAY_METHODS = [
  { id: 'tarjeta', label: 'Tarjeta', en: 'Card', icon: 'card' },
  { id: 'zelle', label: 'Zelle', en: 'Zelle', icon: 'send' },
  { id: 'efectivo', label: 'Efectivo', en: 'Cash · pago directo', icon: 'cash' },
  { id: 'cashapp', label: 'CashApp', en: 'CashApp', icon: 'dollar' },
  { id: 'applepay', label: 'Apple Pay', en: 'Apple Pay', icon: 'phone' },
];
const PM = Object.fromEntries(PAY_METHODS.map((m) => [m.id, m]));

const PAYMENTS = [
  { id: 9, name: 'Luis Reyes', svc: '#1 fade · línea', amount: 35, method: 'efectivo', detail: 'En persona', when: '9:10A', day: 'Hoy' },
  { id: 8, name: 'David Ortiz', svc: 'Beard sculpt', amount: 40, method: 'tarjeta', detail: 'Visa ·· 4242', when: '10:40A', day: 'Hoy' },
  { id: 7, name: 'Andrés Peña', svc: 'SMP · sesión 2 de 3', amount: 250, method: 'zelle', detail: 'michaelstyle@…', when: 'Ayer · 4:20P', day: 'Ayer' },
  { id: 6, name: 'Marco Díaz', svc: '#2 fade · sharp line', amount: 35, method: 'cashapp', detail: '$michaelstyle23', when: 'Ayer · 1:05P', day: 'Ayer' },
  { id: 5, name: 'Carlos Martínez', svc: '#2 fade · the usual', amount: 35, method: 'applepay', detail: 'iPhone tap', when: 'Sáb · 5:30P', day: 'Sem' },
  { id: 4, name: 'Jay Carrillo', svc: 'Kids cut', amount: 25, method: 'efectivo', detail: 'En persona', when: 'Sáb · 2:30P', day: 'Sem' },
  { id: 3, name: 'Erick Santos', svc: 'Beard line-up', amount: 20, method: 'tarjeta', detail: 'Mastercard ·· 8810', when: 'Vie · 6:00P', day: 'Sem' },
  { id: 2, name: 'Pedro Lima', svc: 'Consulta SMP', amount: 50, method: 'zelle', detail: 'michaelstyle@…', when: 'Vie · 11:30A', day: 'Sem' },
];
window.MS_PAYMENTS = PAYMENTS; // seed shared payment feed (lifted to the app root)

const QUICK_AMOUNTS = [25, 35, 40, 60, 250];
const money = (n) => '$' + n.toLocaleString('en-US');

function MethodBadge({ id, size = 30 }) {
  const m = PM[id];
  return (
    <span style={{
      width: size + 'px', height: size + 'px', borderRadius: '50%', flex: 'none',
      display: 'flex', alignItems: 'center', justifyContent: 'center',
      background: 'color-mix(in srgb,var(--accent) 14%,var(--card))', color: 'var(--accent)',
    }}><window.Icon name={m ? m.icon : 'dollar'} size={Math.round(size * 0.52)} /></span>
  );
}

function PayRow({ p, last }) {
  const m = PM[p.method];
  return (
    <div style={{ display: 'flex', alignItems: 'center', gap: '11px', padding: '11px 0', borderBottom: last ? 'none' : '1px solid var(--bd-d)' }}>
      <MethodBadge id={p.method} />
      <div style={{ flex: 1, minWidth: 0 }}>
        <div style={{ fontSize: '0.78rem', color: 'var(--bone)', fontWeight: 600, whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' }}>{p.name}</div>
        <div style={{ fontFamily: 'var(--font-mono)', fontSize: '0.5rem', letterSpacing: '0.07em', textTransform: 'uppercase', color: 'var(--muted-2)', marginTop: '2px', whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' }}>{(m ? m.label : p.method) + ' · ' + p.svc}</div>
      </div>
      <div style={{ textAlign: 'right', flex: 'none' }}>
        <div style={{ fontFamily: 'var(--font-display)', fontWeight: 900, fontSize: '0.98rem', letterSpacing: '-0.02em', color: 'var(--bone)' }}>{money(p.amount)}</div>
        <div style={{ fontFamily: 'var(--font-mono)', fontSize: '0.46rem', letterSpacing: '0.06em', textTransform: 'uppercase', color: 'var(--muted-2)', marginTop: '2px' }}>{p.when}</div>
      </div>
    </div>
  );
}

/* Back chevron used by the pay sub-screens that live under "Yo". */
function BackToYo({ onBack }) {
  return (
    <button onClick={onBack} style={{
      display: 'inline-flex', alignItems: 'center', gap: '6px', background: 'none', border: 'none', cursor: 'pointer',
      color: 'var(--muted)', padding: 0, marginBottom: '10px',
      fontFamily: 'var(--font-mono)', fontSize: '0.52rem', letterSpacing: '0.1em', textTransform: 'uppercase',
    }}>
      <span style={{ transform: 'rotate(180deg)', display: 'inline-flex' }}><window.Icon name="chevron" size={13} /></span> Yo · Back
    </button>
  );
}

/* ——— PAGOS · summary + full history (OWNER-ONLY — never shown to a client) ——— */
function OwnerPagos({ onBack, payments }) {
  const { Card } = OWN;
  const [period, setPeriod] = React.useState('Semana');
  const feed = payments || PAYMENTS;

  const periods = ['Hoy', 'Semana', 'Mes'];
  const inPeriod = (p) => period === 'Hoy' ? p.day === 'Hoy' : true; // Semana/Mes show all sample data
  const shown = feed.filter(inPeriod);
  const total = shown.reduce((s, p) => s + p.amount, 0);
  const byMethod = PAY_METHODS
    .map((m) => ({ ...m, sum: shown.filter((p) => p.method === m.id).reduce((s, p) => s + p.amount, 0) }))
    .filter((m) => m.sum > 0)
    .sort((a, b) => b.sum - a.sum);
  const periodCap = period === 'Hoy' ? 'Cobrado · hoy' : period === 'Mes' ? 'Cobrado · este mes' : 'Cobrado · esta semana';

  return (
    <window.ScreenBody label="App Dueño · Historial de pagos">
      {onBack && <BackToYo onBack={onBack} />}
      <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'flex-start' }}>
        <div>
          <window.Eyebrow>El dinero · Income</window.Eyebrow>
          <window.AppH>Ingresos</window.AppH>
        </div>
        <span style={{ marginTop: '4px', color: 'var(--accent)' }}><window.Icon name="wallet" size={26} /></span>
      </div>
      <window.ASub>Solo para ti · your records.</window.ASub>

      {/* period control */}
      <div style={{ display: 'flex', gap: '7px', marginBottom: '12px' }}>
        {periods.map((d) => {
          const on = d === period;
          return (
            <button key={d} onClick={() => setPeriod(d)} aria-pressed={on} style={{
              fontFamily: 'var(--font-mono)', fontSize: '0.55rem', letterSpacing: '0.08em', textTransform: 'uppercase', padding: '7px 14px',
              borderRadius: 'var(--radius-pill)', cursor: 'pointer', flex: 'none',
              border: `1px solid ${on ? 'var(--accent)' : 'var(--bd-d)'}`,
              background: on ? 'var(--accent)' : 'transparent', color: on ? 'var(--on-accent)' : 'var(--muted)',
            }}>{d}</button>
          );
        })}
      </div>

      {/* total + breakdown by method */}
      <Card variant="accent" style={{ marginBottom: '11px' }}>
        <div style={{ fontFamily: 'var(--font-mono)', fontSize: '0.55rem', letterSpacing: '0.13em', textTransform: 'uppercase', color: 'var(--accent)' }}>{periodCap}</div>
        <div style={{ fontFamily: 'var(--font-display)', fontWeight: 900, fontSize: '3rem', letterSpacing: '-0.04em', lineHeight: 0.92, color: 'var(--bone)', margin: '6px 0 2px' }}>{money(total)}</div>
        <div style={{ fontSize: '0.66rem', color: 'var(--muted)' }}>{shown.length} pagos · {new Set(shown.map((p) => p.name)).size} clientes</div>

        {/* trend chart (representative) */}
        <div style={{ display: 'flex', alignItems: 'flex-end', gap: '5px', height: '48px', marginTop: '14px' }}>
          {[40, 62, 35, 78, 90, 55, 70].map((h, i) => (
            <div key={i} style={{ flex: 1, height: h + '%', borderRadius: '3px 3px 0 0', background: i === 4 ? 'var(--accent)' : 'color-mix(in srgb,var(--accent) 28%,var(--card))' }} />
          ))}
        </div>
        <div style={{ display: 'flex', justifyContent: 'space-between', fontFamily: 'var(--font-mono)', fontSize: '0.45rem', letterSpacing: '0.08em', color: 'var(--muted-2)', marginTop: '5px' }}>{['L', 'M', 'M', 'J', 'V', 'S', 'D'].map((d, i) => <span key={i}>{d}</span>)}</div>

        {/* proportion bar (shades of accent) */}
        <div style={{ display: 'flex', height: '8px', borderRadius: '4px', overflow: 'hidden', marginTop: '14px', background: 'color-mix(in srgb,var(--accent) 12%,var(--card))' }}>
          {byMethod.map((m, i) => (
            <div key={m.id} title={m.label} style={{ width: (m.sum / total * 100) + '%', background: `color-mix(in srgb,var(--accent) ${88 - i * 16}%,var(--card))` }} />
          ))}
        </div>
        {/* legend */}
        <div style={{ marginTop: '11px', display: 'flex', flexDirection: 'column', gap: '7px' }}>
          {byMethod.map((m, i) => (
            <div key={m.id} style={{ display: 'flex', alignItems: 'center', gap: '8px' }}>
              <span style={{ width: '8px', height: '8px', borderRadius: '2px', flex: 'none', background: `color-mix(in srgb,var(--accent) ${88 - i * 16}%,var(--card))` }} />
              <span style={{ flex: 1, fontFamily: 'var(--font-mono)', fontSize: '0.52rem', letterSpacing: '0.08em', textTransform: 'uppercase', color: 'var(--muted)' }}>{m.label}</span>
              <span style={{ fontFamily: 'var(--font-mono)', fontSize: '0.56rem', color: 'var(--bone)' }}>{money(m.sum)}</span>
            </div>
          ))}
        </div>
      </Card>

      {/* full history */}
      <div style={{ fontFamily: 'var(--font-mono)', fontSize: '0.56rem', letterSpacing: '0.14em', textTransform: 'uppercase', color: 'var(--accent)', margin: '4px 0 9px' }}>Historial · History</div>
      <Card>
        {shown.map((p, i) => <PayRow key={p.id} p={p} last={i === shown.length - 1} />)}
      </Card>
    </window.ScreenBody>
  );
}

/* ——— COBRAR · the charge experience (CLIENT-SAFE — no history on screen) ——— */
function OwnerCobrar({ onBack, onCharge, onDone }) {
  const { Card, Button } = OWN;
  const [amount, setAmount] = React.useState(35);
  const [method, setMethod] = React.useState('tarjeta');
  const [name, setName] = React.useState('');
  const [done, setDone] = React.useState(null);

  const submit = () => {
    const p = {
      id: Date.now(), name: name.trim() || 'Cliente directo', svc: 'Cobro rápido',
      amount, method, detail: PM[method].en, when: 'Ahora', day: 'Hoy',
    };
    if (onCharge) onCharge(p);
    setDone(p);
  };
  const reset = () => { setDone(null); setAmount(35); setMethod('tarjeta'); setName(''); };

  /* —— success / receipt — safe to show the client —— */
  if (done) {
    return (
      <window.ScreenBody label="App Dueño · Cobrado">
        <div style={{ display: 'flex', flexDirection: 'column', alignItems: 'center', justifyContent: 'center', textAlign: 'center', minHeight: '100%', padding: '24px 4px' }}>
          <span style={{
            width: '64px', height: '64px', borderRadius: '50%', display: 'flex', alignItems: 'center', justifyContent: 'center',
            background: 'color-mix(in srgb,var(--accent) 18%,var(--card))', color: 'var(--accent)', marginBottom: '16px',
          }}><window.Icon name="check" size={32} /></span>
          <div style={{ fontFamily: 'var(--font-mono)', fontSize: '0.56rem', letterSpacing: '0.14em', textTransform: 'uppercase', color: 'var(--accent)' }}>Pago recibido · Paid</div>
          <div style={{ fontFamily: 'var(--font-display)', fontWeight: 900, fontSize: '3.4rem', letterSpacing: '-0.04em', color: 'var(--bone)', margin: '8px 0 4px' }}>{money(done.amount)}</div>
          <div style={{ display: 'inline-flex', alignItems: 'center', gap: '7px', color: 'var(--muted)', fontFamily: 'var(--font-mono)', fontSize: '0.6rem', letterSpacing: '0.08em', textTransform: 'uppercase' }}>
            <window.Icon name={PM[done.method].icon} size={14} /> {PM[done.method].label} · {done.name}
          </div>
          <div style={{ display: 'flex', gap: '8px', marginTop: '26px', width: '100%', maxWidth: '260px' }}>
            <Button variant="line" size="sm" style={{ flex: 1 }} onClick={reset}>Nuevo cobro</Button>
            <Button variant="fill" size="sm" style={{ flex: 1 }} onClick={onDone}>Listo</Button>
          </div>
          <div style={{ fontStyle: 'italic', color: 'var(--muted-2)', fontSize: '0.66rem', marginTop: '20px' }}>Gracias · thank you. Dios primero.</div>
        </div>
      </window.ScreenBody>
    );
  }

  /* —— charge form —— */
  return (
    <window.ScreenBody label="App Dueño · Cobrar">
      {onBack && <BackToYo onBack={onBack} />}
      <window.Eyebrow>Cobrar · Charge</window.Eyebrow>
      <window.AppH>Nuevo cobro</window.AppH>
      <window.ASub>Monto y método · then collect.</window.ASub>

      <div style={{ textAlign: 'center', fontFamily: 'var(--font-display)', fontWeight: 900, fontSize: '3.2rem', letterSpacing: '-0.04em', color: 'var(--bone)', margin: '4px 0 14px' }}>{money(amount)}</div>
      <div style={{ display: 'flex', flexWrap: 'wrap', gap: '7px', justifyContent: 'center', marginBottom: '18px' }}>
        {QUICK_AMOUNTS.map((a) => {
          const on = a === amount;
          return (
            <button key={a} onClick={() => setAmount(a)} aria-pressed={on} style={{
              fontFamily: 'var(--font-mono)', fontSize: '0.62rem', letterSpacing: '0.04em', padding: '9px 14px',
              borderRadius: 'var(--radius-pill)', cursor: 'pointer',
              border: `1px solid ${on ? 'var(--accent)' : 'var(--bd-d)'}`,
              background: on ? 'color-mix(in srgb,var(--accent) 16%,var(--card))' : 'transparent', color: on ? 'var(--accent)' : 'var(--muted)',
            }}>{money(a)}</button>
          );
        })}
      </div>

      <div style={{ fontFamily: 'var(--font-mono)', fontSize: '0.5rem', letterSpacing: '0.13em', textTransform: 'uppercase', color: 'var(--muted-2)', marginBottom: '8px' }}>Método · Method</div>
      <div style={{ display: 'flex', flexWrap: 'wrap', gap: '7px', marginBottom: '16px' }}>
        {PAY_METHODS.map((m) => {
          const on = m.id === method;
          return (
            <button key={m.id} onClick={() => setMethod(m.id)} aria-pressed={on} style={{
              display: 'inline-flex', alignItems: 'center', gap: '6px',
              fontFamily: 'var(--font-mono)', fontSize: '0.54rem', letterSpacing: '0.06em', textTransform: 'uppercase', padding: '9px 12px',
              borderRadius: 'var(--radius-pill)', cursor: 'pointer',
              border: `1px solid ${on ? 'var(--accent)' : 'var(--bd-d)'}`,
              background: on ? 'var(--accent)' : 'transparent', color: on ? 'var(--on-accent)' : 'var(--muted)',
            }}><window.Icon name={m.icon} size={13} /> {m.label}</button>
          );
        })}
      </div>

      <input value={name} onChange={(e) => setName(e.target.value)} placeholder="Cliente (opcional) · Customer" style={{
        width: '100%', boxSizing: 'border-box', fontFamily: 'var(--font-body)', fontSize: '0.8rem',
        padding: '11px 14px', borderRadius: 'var(--radius-input)', border: '1px solid var(--bd-d)',
        background: 'var(--card)', color: 'var(--bone)', marginBottom: '14px', outline: 'none',
      }} />

      <Button variant="fill" style={{ width: '100%', display: 'inline-flex', alignItems: 'center', justifyContent: 'center', gap: '8px' }} onClick={submit}>
        <window.Icon name="check" size={16} /> Cobrar {money(amount)}
      </Button>
    </window.ScreenBody>
  );
}

/* —— Owner tab bar (relabeled, owner icons) —— */
function OwnerTabBar({ active, onChange }) {
  const tabs = [
    { id: 'hoy', label: 'Hoy', icon: 'home' }, { id: 'citas', label: 'Citas', icon: 'book' },
    { id: 'clientes', label: 'Clientes', icon: 'users' }, { id: 'trabajo', label: 'Trabajo', icon: 'work' },
    { id: 'yo', label: 'Yo', icon: 'me' },
  ];
  // Pay sub-screens (pagos/cobrar) live under "Yo" — keep that tab lit while they're open.
  const litTab = (active === 'pagos' || active === 'cobrar') ? 'yo' : active;
  return (
    <div style={{
      display: 'flex', justifyContent: 'space-around', padding: '11px 0 16px', flex: 'none',
      borderTop: '1px solid var(--bd-d)', background: 'var(--scrim-dark)', backdropFilter: 'var(--blur-glass)',
    }}>
      {tabs.map((t) => {
        const on = t.id === litTab;
        return (
          <button key={t.id} onClick={() => onChange && onChange(t.id)} aria-current={on ? 'page' : undefined} style={{
            display: 'flex', flexDirection: 'column', alignItems: 'center', gap: '4px',
            fontFamily: 'var(--font-mono)', fontSize: '0.49rem', letterSpacing: '0.05em',
            textTransform: 'uppercase', color: on ? 'var(--accent)' : 'var(--muted-2)',
            background: 'none', border: 'none', cursor: 'pointer',
          }}>
            <window.Icon name={t.icon} /> {t.label}
          </button>
        );
      })}
    </div>
  );
}

Object.assign(window, { OwnerHome, OwnerCitas, OwnerClientes, OwnerTrabajo, OwnerYo, OwnerPagos, OwnerCobrar, OwnerTabBar });
