// primitives.jsx — CSS injection, base components, and dummy data

// ── Inject CSS ────────────────────────────────────────────────────────────────
(function () {
  const el = document.createElement('style');
  el.textContent = `
    *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
    html, body, #root { height: 100%; }
    body { font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; font-size: 15px; line-height: 1.5; color: #1a1d23; background: #f5f7fa; }
    a { color: #3a5ca8; text-decoration: none; }
    input, select, textarea, button { font: inherit; }

    .app-wrapper { display: grid; grid-template-columns: 220px 1fr; grid-template-rows: 52px 1fr; height: 100vh; overflow: hidden; }
    .sidebar { grid-column: 1; grid-row: 1/-1; background: white; border-right: 1px solid #dde1e9; display: flex; flex-direction: column; overflow-y: auto; }
    .sidebar-brand { padding: 0 1rem; display: flex; align-items: center; gap: 0.5rem; height: 52px; border-bottom: 1px solid #dde1e9; flex-shrink: 0; }
    .brand-icon { width: 28px; height: 28px; background: #3a5ca8; border-radius: 6px; display: flex; align-items: center; justify-content: center; color: white; font-weight: 700; font-size: 0.85rem; flex-shrink: 0; }
    .brand-name { font-weight: 700; font-size: 0.95rem; }
    .sidebar-nav { padding: 0.5rem 0; flex: 1; }
    .nav-section { font-size: 0.7rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; color: #6b7280; padding: 0.875rem 1.25rem 0.25rem; }
    .nav-link { display: flex; align-items: center; gap: 0.5rem; padding: 0.55rem 1.25rem; color: #6b7280; text-decoration: none; font-size: 0.9rem; font-weight: 500; border-left: 3px solid transparent; cursor: pointer; transition: all 0.15s; }
    .nav-link:hover { color: #1a1d23; background: #f5f7fa; }
    .nav-link.active { color: #3a5ca8; border-left-color: #3a5ca8; background: #d0daf5; }
    .nav-icon { width: 18px; text-align: center; flex-shrink: 0; }
    .topbar { grid-column: 2; grid-row: 1; display: flex; align-items: center; justify-content: space-between; padding: 0 1.5rem; background: white; border-bottom: 1px solid #dde1e9; }
    .topbar-left { display: flex; align-items: center; gap: 0.75rem; }
    .topbar-title { font-size: 1.05rem; font-weight: 600; }
    .topbar-right { display: flex; align-items: center; gap: 1rem; }
    .main-content { grid-column: 2; grid-row: 2; padding: 2rem; background: #f5f7fa; overflow-y: auto; }

    .page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1.5rem; }
    .page-header h1 { font-size: 1.375rem; font-weight: 700; }

    .stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
    .stat-tile { background: white; border: 1px solid #dde1e9; border-radius: 12px; padding: 1.25rem; }
    .stat-label { font-size: 0.72rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.07em; color: #6b7280; margin-bottom: 0.35rem; }
    .stat-value { font-size: 1.875rem; font-weight: 700; color: #1a1d23; line-height: 1; }
    .stat-sub { font-size: 0.8rem; color: #6b7280; margin-top: 0.35rem; }

    .card { background: white; border: 1px solid #dde1e9; border-radius: 12px; padding: 1.25rem; margin-bottom: 1.25rem; }
    .card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; }
    .card-title { font-size: 1rem; font-weight: 600; }

    .table-wrap { background: white; border: 1px solid #dde1e9; border-radius: 12px; overflow: hidden; margin-bottom: 1.25rem; }
    table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
    thead th { background: #f5f7fa; padding: 0.55rem 1rem; text-align: left; font-size: 0.72rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: #6b7280; border-bottom: 1px solid #dde1e9; }
    tbody td { padding: 0.75rem 1rem; border-bottom: 1px solid #dde1e9; color: #1a1d23; vertical-align: middle; }
    tbody tr:last-child td { border-bottom: none; }
    tbody tr:hover { background: #f8f9fb; cursor: pointer; }
    tbody tr.no-hover:hover { background: transparent; cursor: default; }

    .btn { display: inline-flex; align-items: center; gap: 0.3rem; padding: 0.5rem 1rem; font-size: 0.875rem; font-weight: 500; border-radius: 8px; border: 1px solid transparent; cursor: pointer; white-space: nowrap; transition: all 0.15s; text-decoration: none; }
    .btn-primary { background: #3a5ca8; color: white; border-color: #3a5ca8; }
    .btn-primary:hover { background: #2e4a8a; border-color: #2e4a8a; }
    .btn-secondary { background: white; color: #1a1d23; border-color: #dde1e9; }
    .btn-secondary:hover { background: #f5f7fa; }
    .btn-danger { background: #dc2626; color: white; border-color: #dc2626; }
    .btn-danger:hover { background: #b91c1c; }
    .btn-ghost { background: transparent; color: #6b7280; border-color: transparent; }
    .btn-ghost:hover { background: #f5f7fa; color: #1a1d23; }
    .btn-success { background: #16a34a; color: white; border-color: #16a34a; }
    .btn-success:hover { background: #15803d; }
    .btn-sm { padding: 0.3rem 0.65rem; font-size: 0.8rem; }

    .badge { display: inline-flex; align-items: center; padding: 0.2rem 0.55rem; font-size: 0.75rem; font-weight: 500; border-radius: 999px; border: 1px solid; }
    .badge-green { background: #dcfce7; color: #16a34a; border-color: #86efac; }
    .badge-yellow { background: #fef3c7; color: #d97706; border-color: #fcd34d; }
    .badge-red { background: #fee2e2; color: #dc2626; border-color: #fca5a5; }
    .badge-blue { background: #d0daf5; color: #2e4a8a; border-color: #b3c4e8; }
    .badge-purple { background: #ede9fe; color: #7c3aed; border-color: #c4b5fd; }
    .badge-gray { background: #f3f4f6; color: #6b7280; border-color: #d1d5db; }

    .form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
    .form-group { margin-bottom: 1rem; }
    .form-group label { display: block; font-size: 0.85rem; font-weight: 500; color: #1a1d23; margin-bottom: 0.3rem; }
    .form-group input, .form-group select, .form-group textarea { width: 100%; padding: 0.5rem 0.75rem; border: 1px solid #dde1e9; border-radius: 8px; font-size: 0.9rem; color: #1a1d23; background: white; appearance: none; }
    .form-group input:focus, .form-group select:focus { outline: none; border-color: #3a5ca8; box-shadow: 0 0 0 3px rgba(58,92,168,0.15); }

    .drawer-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.3); z-index: 50; }
    .drawer { position: fixed; top: 0; right: 0; height: 100vh; width: 380px; background: white; box-shadow: -4px 0 24px rgba(0,0,0,0.12); z-index: 51; overflow-y: auto; transition: transform 0.25s ease; }
    .drawer-header { display: flex; align-items: center; justify-content: space-between; padding: 1.25rem 1.5rem; border-bottom: 1px solid #dde1e9; }
    .drawer-body { padding: 1.5rem; }
    .drawer-close { background: none; border: none; cursor: pointer; font-size: 1.25rem; color: #6b7280; line-height: 1; padding: 0.25rem; }

    .modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 100; display: flex; align-items: center; justify-content: center; }
    .modal { background: white; border-radius: 12px; box-shadow: 0 20px 60px rgba(0,0,0,0.2); width: 480px; max-width: 90vw; max-height: 85vh; overflow-y: auto; }
    .modal-header { display: flex; align-items: center; justify-content: space-between; padding: 1.25rem 1.5rem; border-bottom: 1px solid #dde1e9; }
    .modal-body { padding: 1.5rem; }
    .modal-footer { padding: 1rem 1.5rem; border-top: 1px solid #dde1e9; display: flex; gap: 0.75rem; justify-content: flex-end; }

    .avatar { width: 36px; height: 36px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 0.875rem; color: white; flex-shrink: 0; }
    .avatar-lg { width: 56px; height: 56px; font-size: 1.25rem; }

    .toggle-group { display: inline-flex; border: 1px solid #dde1e9; border-radius: 8px; overflow: hidden; }
    .toggle-btn { padding: 0.4rem 1rem; border: none; background: white; color: #6b7280; cursor: pointer; font-size: 0.875rem; font-weight: 500; transition: all 0.15s; }
    .toggle-btn.active { background: #3a5ca8; color: white; }

    .tab-bar { display: flex; border-bottom: 2px solid #dde1e9; margin-bottom: 1.5rem; gap: 0; }
    .tab-btn { padding: 0.65rem 1.25rem; border: none; background: transparent; color: #6b7280; cursor: pointer; font-size: 0.9rem; font-weight: 500; border-bottom: 2px solid transparent; margin-bottom: -2px; transition: all 0.15s; }
    .tab-btn.active { color: #3a5ca8; border-bottom-color: #3a5ca8; }

    .empty-state { text-align: center; padding: 3rem; color: #6b7280; }
    .empty-state p { margin-top: 0.5rem; font-size: 0.9rem; }

    .info-note { background: #d0daf5; color: #2e4a8a; border: 1px solid #b3c4e8; border-radius: 8px; padding: 0.65rem 1rem; font-size: 0.85rem; margin-top: 1rem; }

    .switch-label { display: flex; align-items: center; justify-content: space-between; padding: 0.75rem 0; border-bottom: 1px solid #dde1e9; }
    .switch-label:last-child { border-bottom: none; }
    .switch-text { font-size: 0.9rem; font-weight: 500; }
    .switch-sub { font-size: 0.8rem; color: #6b7280; margin-top: 0.1rem; }
    .switch { position: relative; width: 40px; height: 22px; flex-shrink: 0; }
    .switch input { opacity: 0; width: 0; height: 0; }
    .switch-track { position: absolute; inset: 0; border-radius: 999px; cursor: pointer; transition: 0.2s; }
    .switch-track.on { background: #3a5ca8; }
    .switch-track.off { background: #d1d5db; }
    .switch-thumb { position: absolute; top: 3px; width: 16px; height: 16px; background: white; border-radius: 50%; transition: 0.2s; box-shadow: 0 1px 3px rgba(0,0,0,0.2); }
    .switch-thumb.on { left: 21px; }
    .switch-thumb.off { left: 3px; }

    .toast { position: fixed; bottom: 5rem; right: 1.5rem; background: #1a1d23; color: white; padding: 0.65rem 1.25rem; border-radius: 8px; font-size: 0.875rem; font-weight: 500; z-index: 2000; box-shadow: 0 4px 12px rgba(0,0,0,0.2); animation: slideUp 0.2s ease; }
    @keyframes slideUp { from { transform: translateY(8px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

    .cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 1px; background: #dde1e9; border: 1px solid #dde1e9; border-radius: 8px; overflow: hidden; }
    .cal-dow { background: #f5f7fa; padding: 0.4rem; text-align: center; font-size: 0.72rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: #6b7280; }
    .cal-day { background: white; padding: 0.4rem; min-height: 80px; position: relative; }
    .cal-day.other-month { background: #fafafa; }
    .cal-day.today .cal-day-num { background: #3a5ca8; color: white; border-radius: 50%; width: 24px; height: 24px; display: flex; align-items: center; justify-content: center; }
    .cal-day-num { font-size: 0.8rem; font-weight: 500; color: #1a1d23; margin-bottom: 2px; width: 24px; height: 24px; display: flex; align-items: center; justify-content: center; }
    .cal-day.other-month .cal-day-num { color: #9ca3af; }
    .cal-event-chip { font-size: 0.72rem; background: #d0daf5; color: #2e4a8a; border-radius: 4px; padding: 0.1rem 0.3rem; margin-top: 2px; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    .cal-event-chip:hover { background: #3a5ca8; color: white; }

    .timeline-item { display: flex; gap: 1rem; margin-bottom: 0.75rem; }
    .timeline-date { width: 80px; flex-shrink: 0; font-size: 0.8rem; color: #6b7280; padding-top: 0.85rem; text-align: right; }
    .timeline-card { flex: 1; background: white; border: 1px solid #dde1e9; border-left: 3px solid; border-radius: 8px; padding: 0.85rem 1rem; }
    .timeline-card.fundraiser { border-left-color: #3a5ca8; }
    .timeline-card.regular { border-left-color: #d1d5db; }
    .timeline-card-title { font-weight: 600; font-size: 0.9rem; display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.25rem; }
    .timeline-card-meta { font-size: 0.8rem; color: #6b7280; display: flex; align-items: center; gap: 0.75rem; }

    .profit-positive { color: #16a34a; font-weight: 600; }
    .profit-negative { color: #dc2626; font-weight: 600; }
    .kind-revenue { color: #16a34a; font-weight: 500; }
    .kind-expense { color: #dc2626; font-weight: 500; }

    .section-title { font-size: 1rem; font-weight: 600; margin-bottom: 0.875rem; }
    .detail-row { display: flex; align-items: baseline; margin-bottom: 0.75rem; }
    .detail-label { width: 130px; font-size: 0.8rem; color: #6b7280; flex-shrink: 0; }
    .detail-value { font-size: 0.9rem; font-weight: 500; }
    .divider { border: none; border-top: 1px solid #dde1e9; margin: 1.25rem 0; }
    .btn-row { display: flex; gap: 0.5rem; margin-top: 1.25rem; }

    .matrix-check { color: #3a5ca8; font-weight: 700; font-size: 1rem; }
    .matrix-dash { color: #d1d5db; font-size: 0.875rem; }

    .hero-card { background: white; border: 1px solid #dde1e9; border-radius: 12px; padding: 1.5rem 2rem; margin-bottom: 1.25rem; display: flex; align-items: flex-start; justify-content: space-between; }
    .hero-amount { font-size: 2.75rem; font-weight: 700; line-height: 1; }
    .hero-label { font-size: 0.8rem; color: #6b7280; margin-top: 0.35rem; font-weight: 500; }
    .hero-badge { display: inline-flex; align-items: center; gap: 0.25rem; background: #dcfce7; color: #16a34a; border: 1px solid #86efac; border-radius: 999px; padding: 0.2rem 0.6rem; font-size: 0.8rem; font-weight: 600; margin-top: 0.5rem; }
  `;
  document.head.appendChild(el);
})();

// ── Dummy Data ────────────────────────────────────────────────────────────────
window.DATA = {
  members: [
    { id: 1, name: 'Margaret Osei',   email: 'margaret@thelions.org', chapter: 'Central', status: 'active',   role: 'admin',  eventsAttended: 12, joined: 'Jan 2023' },
    { id: 2, name: 'Brian Calloway',  email: 'brian@thelions.org',    chapter: 'North',   status: 'active',   role: 'editor', eventsAttended: 7,  joined: 'Mar 2023' },
    { id: 3, name: 'Linda Foust',     email: 'linda@thelions.org',    chapter: 'East',    status: 'active',   role: 'member', eventsAttended: 4,  joined: 'Jan 2024' },
    { id: 4, name: 'Tom Yuen',        email: 'tom@thelions.org',      chapter: 'Central', status: 'active',   role: 'member', eventsAttended: 9,  joined: 'Nov 2023' },
    { id: 5, name: 'Priya Mehta',     email: 'priya@thelions.org',    chapter: 'South',   status: 'inactive', role: 'viewer', eventsAttended: 2,  joined: 'May 2024' },
    { id: 6, name: 'Carlos Rivera',   email: 'carlos@thelions.org',   chapter: 'West',    status: 'invited',  role: 'member', eventsAttended: 0,  joined: null },
  ],
  events: [
    { id: 1, title: 'Annual Gala',      date: '2026-06-14', month: 5, day: 14, location: 'Grand Ballroom',   fundraiser: true,  revenue: 8400, expense: 2100 },
    { id: 2, title: 'Trivia Night',     date: '2026-05-02', month: 4, day: 2,  location: 'The Lions Den',    fundraiser: true,  revenue: 1200, expense: 300  },
    { id: 3, title: 'Volunteer Day',    date: '2026-04-19', month: 3, day: 19, location: 'City Park',        fundraiser: false, revenue: 0,    expense: 450  },
    { id: 4, title: 'BBQ Fundraiser',   date: '2026-03-08', month: 2, day: 8,  location: 'Riverside Oval',   fundraiser: true,  revenue: 3200, expense: 980  },
    { id: 5, title: 'Board Meeting',    date: '2026-02-15', month: 1, day: 15, location: 'Club House',       fundraiser: false, revenue: 0,    expense: 0    },
  ],
  money: [
    { id: 1, kind: 'revenue', source: 'Ticket Sales',  event: 'Annual Gala',    amount: 8400, status: 'approved', by: 'Brian C.', date: '14 Jun 2026' },
    { id: 2, kind: 'expense', source: 'Venue Hire',    event: 'Annual Gala',    amount: 2100, status: 'approved', by: 'Brian C.', date: '12 Jun 2026' },
    { id: 3, kind: 'revenue', source: 'Ticket Sales',  event: 'Trivia Night',   amount: 1200, status: 'approved', by: 'Brian C.', date: '02 May 2026' },
    { id: 4, kind: 'expense', source: 'Prizes',        event: 'Trivia Night',   amount:  300, status: 'approved', by: 'Brian C.', date: '02 May 2026' },
    { id: 5, kind: 'expense', source: 'Supplies',      event: 'Volunteer Day',  amount:  450, status: 'pending',  by: 'Brian C.', date: '19 Apr 2026' },
    { id: 6, kind: 'revenue', source: 'Ticket Sales',  event: 'BBQ Fundraiser', amount: 3200, status: 'approved', by: 'Brian C.', date: '08 Mar 2026' },
    { id: 7, kind: 'expense', source: 'Food & Drink',  event: 'BBQ Fundraiser', amount:  980, status: 'approved', by: 'Brian C.', date: '08 Mar 2026' },
  ],
  activity: [
    { id: 1, actor: 'Margaret O.', color: '#16a34a', verb: 'approved',         target: 'Annual Gala revenue entry',    time: '2h ago' },
    { id: 2, actor: 'Brian C.',    color: '#3a5ca8', verb: 'created event',    target: 'Annual Gala',                  time: '1d ago' },
    { id: 3, actor: 'Carlos R.',   color: '#d97706', verb: 'joined the club',  target: '',                             time: '2d ago' },
    { id: 4, actor: 'Brian C.',    color: '#dc2626', verb: 'added expense',    target: 'Volunteer Day supplies $450',  time: '3d ago' },
    { id: 5, actor: 'Linda F.',    color: '#7c3aed', verb: "RSVP'd going to", target: 'Trivia Night',                 time: '4d ago' },
  ]
};

// ── Helper: format currency ───────────────────────────────────────────────────
window.fmt = (cents) => '$' + cents.toLocaleString();

// ── Avatar colors ─────────────────────────────────────────────────────────────
const AV_COLORS = ['#3a5ca8','#7c3aed','#16a34a','#d97706','#dc2626','#0891b2'];
window.avatarColor = (name) => AV_COLORS[name.charCodeAt(0) % AV_COLORS.length];

// ── Components ────────────────────────────────────────────────────────────────

window.Btn = function Btn({ variant = 'secondary', size = 'md', onClick, children, disabled, style: s }) {
  return (
    <button
      className={`btn btn-${variant}${size === 'sm' ? ' btn-sm' : ''}`}
      onClick={onClick}
      disabled={disabled}
      style={s}
    >
      {children}
    </button>
  );
};

window.Badge = function Badge({ variant = 'gray', children }) {
  return <span className={`badge badge-${variant}`}>{children}</span>;
};

window.StatusBadge = function StatusBadge({ status }) {
  const map = { active: 'green', inactive: 'gray', invited: 'yellow', pending: 'yellow', approved: 'green', rejected: 'red' };
  return <Badge variant={map[status] || 'gray'}>{status}</Badge>;
};

window.RoleBadge = function RoleBadge({ role }) {
  const map = { admin: 'blue', editor: 'purple', member: 'gray', viewer: 'gray' };
  return <Badge variant={map[role] || 'gray'}>{role}</Badge>;
};

window.Avatar = function Avatar({ name, size = 'md' }) {
  return (
    <div className={`avatar${size === 'lg' ? ' avatar-lg' : ''}`} style={{ background: window.avatarColor(name) }}>
      {name.charAt(0)}
    </div>
  );
};

window.StatTile = function StatTile({ label, value, sub, accentValue }) {
  return (
    <div className="stat-tile">
      <div className="stat-label">{label}</div>
      <div className="stat-value" style={accentValue ? { color: '#3a5ca8' } : {}}>{value}</div>
      {sub && <div className="stat-sub">{sub}</div>}
    </div>
  );
};

window.Drawer = function Drawer({ open, onClose, title, children }) {
  return (
    <>
      {open && <div className="drawer-overlay" onClick={onClose} />}
      <div className="drawer" style={{ transform: open ? 'translateX(0)' : 'translateX(100%)' }}>
        <div className="drawer-header">
          <h2 style={{ fontSize: '1.05rem', fontWeight: 600 }}>{title}</h2>
          <button className="drawer-close" onClick={onClose}>×</button>
        </div>
        <div className="drawer-body">{children}</div>
      </div>
    </>
  );
};

window.Modal = function Modal({ open, onClose, title, children, footer }) {
  if (!open) return null;
  return (
    <div className="modal-overlay" onClick={(e) => e.target === e.currentTarget && onClose()}>
      <div className="modal">
        <div className="modal-header">
          <h2 style={{ fontSize: '1.05rem', fontWeight: 600 }}>{title}</h2>
          <button className="drawer-close" onClick={onClose}>×</button>
        </div>
        <div className="modal-body">{children}</div>
        {footer && <div className="modal-footer">{footer}</div>}
      </div>
    </div>
  );
};

window.EmptyState = function EmptyState({ icon = '✓', title, sub }) {
  return (
    <div className="empty-state">
      <div style={{ fontSize: '2rem', marginBottom: '0.5rem' }}>{icon}</div>
      <div style={{ fontWeight: 600 }}>{title}</div>
      {sub && <p>{sub}</p>}
    </div>
  );
};

window.Toggle = function Toggle({ on, onToggle }) {
  return (
    <div className="switch" onClick={onToggle} style={{ cursor: 'pointer' }}>
      <div className={`switch-track ${on ? 'on' : 'off'}`} />
      <div className={`switch-thumb ${on ? 'on' : 'off'}`} />
    </div>
  );
};

window.Toast = function Toast({ msg }) {
  if (!msg) return null;
  return <div className="toast">{msg}</div>;
};

window.AppShell = function AppShell({ screen, setScreen, role, children }) {
  const [sidebarOpen, setSidebarOpen] = React.useState(false);

  const pageTitles = {
    dashboard: 'Dashboard', members: 'Members', events: 'Events',
    money: 'Money', admin: 'Admin Console'
  };
  const mainLinks = [
    { id: 'dashboard', label: 'Dashboard', icon: '◈' },
    { id: 'members',   label: 'Members',   icon: '◉' },
    { id: 'events',    label: 'Events',    icon: '◷' },
    { id: 'money',     label: 'Money',     icon: '◎' },
  ];

  function navigate(id) {
    setScreen(id);
    setSidebarOpen(false);
  }

  return (
    <div className="app-wrapper">
      {/* Mobile overlay */}
      <div
        className={`sidebar-overlay${sidebarOpen ? ' open' : ''}`}
        onClick={() => setSidebarOpen(false)}
      />

      <aside className={`sidebar${sidebarOpen ? ' open' : ''}`}>
        <div className="sidebar-brand">
          <div className="brand-icon">S</div>
          <span className="brand-name">Savanna</span>
        </div>
        <nav className="sidebar-nav">
          {mainLinks.map(link => (
            <a key={link.id} href="#" className={`nav-link${screen === link.id ? ' active' : ''}`}
              onClick={e => { e.preventDefault(); navigate(link.id); }}>
              <span className="nav-icon">{link.icon}</span>
              {link.label}
            </a>
          ))}
          {role === 'admin' && (
            <>
              <div className="nav-section">Admin</div>
              <a href="#" className={`nav-link${screen === 'admin' ? ' active' : ''}`}
                onClick={e => { e.preventDefault(); navigate('admin'); }}>
                <span className="nav-icon">⚙</span>
                Console
              </a>
            </>
          )}
        </nav>
      </aside>

      <header className="topbar">
        <div className="topbar-left">
          <button className="hamburger" aria-label="Toggle navigation" onClick={() => setSidebarOpen(o => !o)}>
            <span></span>
            <span></span>
            <span></span>
          </button>
          <span className="topbar-title">{pageTitles[screen] || screen}</span>
        </div>
        <div className="topbar-right">
          <span style={{ fontSize: '0.85rem', color: '#6b7280' }}>Father · {role}</span>
          <Btn variant="ghost" size="sm" onClick={() => setScreen('login')}>Sign Out</Btn>
        </div>
      </header>

      <main className="main-content">{children}</main>
    </div>
  );
};
