// Sidebar + secondary views (Customers, Services, Statistics)

const Sidebar = ({ active, onChange, unreadCount, onBell, onSettings }) => {
  const items = [
    { id: 'calendar', icon: IconCalendar, label: 'Kalender' },
    { id: 'customers', icon: IconUsers, label: 'Kunder' },
    { id: 'staff', icon: IconUser, label: 'Medarbejdere' },
    { id: 'services', icon: IconScissors, label: 'Ydelser' },
    { id: 'register', icon: IconGrid, label: 'Kasse' },
    { id: 'stats', icon: IconChart, label: 'Statistik' },
  ];
  return (
    <div style={{
      width: 64, background: 'linear-gradient(180deg, #1F2A2E 0%, #14191C 100%)',
      display: 'flex', flexDirection: 'column', alignItems: 'center',
      padding: '16px 0', flexShrink: 0,
      borderRight: '1px solid #0A0E10',
    }}>
      <div style={{
        width: 36, height: 36, borderRadius: 10,
        background: '#7B8A6B', display: 'flex', alignItems: 'center', justifyContent: 'center',
        color: '#fff', fontSize: 18, fontWeight: 700,
        marginBottom: 24, fontFamily: 'Fraunces, serif',
      }}>K</div>

      {items.map(it => {
        const Ic = it.icon;
        const isActive = active === it.id;
        return (
          <button key={it.id} onClick={() => onChange(it.id)} title={it.label} style={{
            width: 44, height: 44, borderRadius: 10,
            background: isActive ? 'rgba(255,255,255,0.1)' : 'transparent',
            border: 'none', cursor: 'pointer',
            display: 'flex', alignItems: 'center', justifyContent: 'center',
            color: isActive ? '#fff' : 'rgba(255,255,255,0.55)',
            marginBottom: 6, transition: 'all 120ms',
            position: 'relative',
          }} onMouseEnter={e => { if (!isActive) e.currentTarget.style.color = '#fff'; }}
             onMouseLeave={e => { if (!isActive) e.currentTarget.style.color = 'rgba(255,255,255,0.55)'; }}>
            <Ic size={20} />
            {isActive && <div style={{ position: 'absolute', left: -8, top: 10, bottom: 10, width: 3, borderRadius: 3, background: '#C9D8B5' }} />}
          </button>
        );
      })}

      <div style={{ flex: 1 }} />

      <button onClick={onBell} title="Notifikationer" style={{
        width: 44, height: 44, borderRadius: 10, background: 'transparent',
        border: 'none', cursor: 'pointer', position: 'relative',
        color: 'rgba(255,255,255,0.55)', display: 'flex', alignItems: 'center', justifyContent: 'center',
        marginBottom: 6,
      }} onMouseEnter={e => e.currentTarget.style.color = '#fff'}
         onMouseLeave={e => e.currentTarget.style.color = 'rgba(255,255,255,0.55)'}>
        <IconBell size={20} />
        {unreadCount > 0 && (
          <div style={{ position: 'absolute', top: 6, right: 6, background: '#D4654E', color: '#fff', fontSize: 9, fontWeight: 700, borderRadius: 8, padding: '1px 5px', minWidth: 16, textAlign: 'center' }}>{unreadCount}</div>
        )}
      </button>
      <button onClick={onSettings} title="Indstillinger" style={{
        width: 44, height: 44, borderRadius: 10, background: 'transparent',
        border: 'none', cursor: 'pointer',
        color: 'rgba(255,255,255,0.55)', display: 'flex', alignItems: 'center', justifyContent: 'center',
      }} onMouseEnter={e => e.currentTarget.style.color = '#fff'}
         onMouseLeave={e => e.currentTarget.style.color = 'rgba(255,255,255,0.55)'}>
        <IconSettings size={20} />
      </button>
    </div>
  );
};

// ---------- Customers list with detail panel ----------
const CustomersView = ({ customers, onUpdateCustomer }) => {
  const [search, setSearch] = React.useState('');
  const [selectedId, setSelectedId] = React.useState(customers[0]?.id);
  const filtered = customers.filter(c =>
    c.name.toLowerCase().includes(search.toLowerCase()) ||
    c.phone.includes(search) ||
    c.email.toLowerCase().includes(search.toLowerCase())
  );
  const selected = customers.find(c => c.id === selectedId);

  return (
    <div style={{ display: 'flex', height: '100%', background: '#FBFAF6', overflow: 'hidden' }}>
      {/* List */}
      <div style={{ width: 420, flexShrink: 0, borderRight: '1px solid #EFEDE5', display: 'flex', flexDirection: 'column', background: '#fff' }}>
        <div style={{ padding: '20px 24px 16px', borderBottom: '1px solid #EFEDE5' }}>
          <h1 style={{ fontFamily: 'Fraunces, serif', fontSize: 22, fontWeight: 500, margin: '0 0 12px 0', color: '#1a1a1a' }}>Kunder</h1>
          <div style={{ position: 'relative' }}>
            <div style={{ position: 'absolute', left: 12, top: 11, color: '#999' }}><IconSearch size={16} /></div>
            <input value={search} onChange={e => setSearch(e.target.value)} placeholder="Søg navn, telefon, email…"
              style={{ ...inputStyle, paddingLeft: 36, width: '100%' }} />
          </div>
        </div>
        <div style={{ flex: 1, overflow: 'auto' }}>
          {filtered.map(c => {
            const fav = STAFF.find(s => s.id === c.favoriteStaffId);
            const isActive = c.id === selectedId;
            return (
              <button key={c.id} onClick={() => setSelectedId(c.id)} style={{
                display: 'flex', alignItems: 'center', gap: 12,
                width: '100%', textAlign: 'left',
                padding: '12px 24px', borderBottom: '1px solid #F4F2EA',
                background: isActive ? '#F4F2EA' : 'transparent',
                border: 'none', cursor: 'pointer', fontFamily: 'inherit',
                borderLeft: isActive ? '3px solid #7B8A6B' : '3px solid transparent',
                paddingLeft: isActive ? 21 : 24,
              }} onMouseEnter={e => { if (!isActive) e.currentTarget.style.background = '#FBFAF6'; }}
                 onMouseLeave={e => { if (!isActive) e.currentTarget.style.background = 'transparent'; }}>
                <Avatar name={c.name} tone="#E8DBC8" size={36} />
                <div style={{ flex: 1, minWidth: 0 }}>
                  <div style={{ fontSize: 14, fontWeight: 500, color: '#1a1a1a', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>{c.name}</div>
                  <div style={{ fontSize: 12, color: '#888', marginTop: 2 }}>{c.phone}</div>
                </div>
                <div style={{ textAlign: 'right' }}>
                  <div style={{ fontSize: 11, color: '#888' }}>{c.visits} besøg</div>
                  {fav && <div style={{ fontSize: 11, color: '#7B8A6B', fontWeight: 500, marginTop: 2 }}>♥ {fav.name.split(' ')[0]}</div>}
                </div>
              </button>
            );
          })}
        </div>
      </div>

      {/* Detail panel */}
      {selected ? (
        <CustomerDetail
          customer={selected}
          onUpdate={(patch) => onUpdateCustomer(selected.id, patch)}
        />
      ) : (
        <div style={{ flex: 1, display: 'flex', alignItems: 'center', justifyContent: 'center', color: '#888' }}>
          Vælg en kunde
        </div>
      )}
    </div>
  );
};

const CustomerDetail = ({ customer, onUpdate }) => {
  const [notes, setNotes] = React.useState(customer.notes || '');
  const [favStaff, setFavStaff] = React.useState(customer.favoriteStaffId || '');
  const [savedFlash, setSavedFlash] = React.useState(false);
  const dirtyRef = React.useRef(false);

  // When switching customer, reload local state
  React.useEffect(() => {
    setNotes(customer.notes || '');
    setFavStaff(customer.favoriteStaffId || '');
    dirtyRef.current = false;
  }, [customer.id]);

  // Auto-save notes after debounce
  React.useEffect(() => {
    if (!dirtyRef.current) return;
    const t = setTimeout(() => {
      onUpdate({ notes, favoriteStaffId: favStaff || null });
      setSavedFlash(true);
      setTimeout(() => setSavedFlash(false), 1600);
      dirtyRef.current = false;
    }, 500);
    return () => clearTimeout(t);
  }, [notes, favStaff]);

  const fav = STAFF.find(s => s.id === favStaff);

  return (
    <div style={{ flex: 1, overflow: 'auto', padding: '32px 40px', maxWidth: 720 }}>
      {/* Header */}
      <div style={{ display: 'flex', alignItems: 'center', gap: 18, marginBottom: 28 }}>
        <Avatar name={customer.name} tone="#E8DBC8" size={64} />
        <div style={{ flex: 1 }}>
          <h2 style={{ fontFamily: 'Fraunces, serif', fontSize: 28, fontWeight: 500, margin: 0, color: '#1a1a1a' }}>{customer.name}</h2>
          <div style={{ display: 'flex', gap: 16, marginTop: 6, fontSize: 13, color: '#666' }}>
            <span style={{ display: 'flex', alignItems: 'center', gap: 6 }}><IconPhone size={13} /> {customer.phone}</span>
            <span style={{ display: 'flex', alignItems: 'center', gap: 6 }}><IconMail size={13} /> {customer.email}</span>
          </div>
        </div>
        {savedFlash && (
          <div style={{ display: 'flex', alignItems: 'center', gap: 6, fontSize: 12, color: '#3F5A30', background: '#F4F7F0', padding: '6px 12px', borderRadius: 16, border: '1px solid #DCE6CC' }}>
            <IconCheck size={12} stroke="#3F5A30" /> Gemt
          </div>
        )}
      </div>

      {/* Stats strip */}
      <div style={{ display: 'grid', gridTemplateColumns: 'repeat(3, 1fr)', gap: 12, marginBottom: 28 }}>
        <MiniStat label="Besøg i alt" value={customer.visits} />
        <MiniStat label="Sidste service" value={SERVICE_BY_ID[customer.lastService]?.name || '—'} />
        <MiniStat label="Foretrukken frisør" value={fav ? fav.name.split(' ')[0] : '—'} />
      </div>

      {/* Favorite stylist */}
      <div style={{ marginBottom: 28 }}>
        <div style={{ fontSize: 13, fontWeight: 600, color: '#1a1a1a', marginBottom: 4 }}>Foretrukken frisør</div>
        <div style={{ fontSize: 12, color: '#888', marginBottom: 12 }}>
          Vælges automatisk når kunden bookes ind.
        </div>
        <div style={{ display: 'flex', flexWrap: 'wrap', gap: 8 }}>
          <FavChip
            active={!favStaff}
            onClick={() => { setFavStaff(''); dirtyRef.current = true; }}
            label="Ingen præference"
          />
          {STAFF.map(s => (
            <FavChip
              key={s.id}
              active={favStaff === s.id}
              onClick={() => { setFavStaff(s.id); dirtyRef.current = true; }}
              tone={s.tone}
              label={s.name}
            />
          ))}
        </div>
      </div>

      {/* Notes */}
      <div style={{ marginBottom: 28 }}>
        <div style={{ fontSize: 13, fontWeight: 600, color: '#1a1a1a', marginBottom: 4 }}>Noter</div>
        <div style={{ fontSize: 12, color: '#888', marginBottom: 10 }}>
          Synlig for alle medarbejdere. Brug fx til allergi, foretrukne produkter, særlige ønsker.
        </div>
        <textarea
          value={notes}
          onChange={e => { setNotes(e.target.value); dirtyRef.current = true; }}
          placeholder="Skriv noter om kunden…"
          rows={6}
          style={{
            ...inputStyle,
            width: '100%', resize: 'vertical', lineHeight: 1.5,
            fontSize: 14, background: '#fff',
            minHeight: 120,
          }}
        />
        <div style={{ fontSize: 11, color: '#999', marginTop: 6, fontStyle: 'italic' }}>
          Gemmes automatisk
        </div>
      </div>

      {/* History placeholder */}
      <div>
        <div style={{ fontSize: 13, fontWeight: 600, color: '#1a1a1a', marginBottom: 12 }}>Seneste besøg</div>
        <div style={{ background: '#fff', border: '1px solid #EFEDE5', borderRadius: 10, padding: 16, fontSize: 13, color: '#666' }}>
          {SERVICE_BY_ID[customer.lastService]?.name} hos {fav ? fav.name : 'salonen'} — for 4 uger siden
        </div>
      </div>
    </div>
  );
};

const FavChip = ({ active, onClick, tone, label }) => (
  <button onClick={onClick} style={{
    display: 'flex', alignItems: 'center', gap: 8,
    padding: '8px 12px 8px 8px',
    background: active ? '#3F4A3A' : '#fff',
    color: active ? '#fff' : '#1a1a1a',
    border: `1px solid ${active ? '#3F4A3A' : '#DDD9CE'}`,
    borderRadius: 22, cursor: 'pointer',
    fontSize: 13, fontWeight: 500, fontFamily: 'inherit',
    transition: 'all 120ms',
  }}>
    {tone && (
      <span style={{
        width: 22, height: 22, borderRadius: '50%',
        background: tone, fontSize: 10, fontWeight: 700,
        color: '#3a2e22',
        display: 'flex', alignItems: 'center', justifyContent: 'center',
      }}>{label.split(' ').map(w => w[0]).slice(0,2).join('')}</span>
    )}
    {!tone && (
      <span style={{ width: 22, height: 22, borderRadius: '50%', background: active ? 'rgba(255,255,255,0.2)' : '#F4F2EA', display: 'flex', alignItems: 'center', justifyContent: 'center', fontSize: 11 }}>—</span>
    )}
    <span style={{ paddingRight: 4 }}>{label}</span>
  </button>
);

const MiniStat = ({ label, value }) => (
  <div style={{ background: '#fff', border: '1px solid #EFEDE5', borderRadius: 10, padding: '14px 16px' }}>
    <div style={{ fontSize: 11, color: '#888', textTransform: 'uppercase', letterSpacing: '0.05em', fontWeight: 600 }}>{label}</div>
    <div style={{ fontSize: 18, fontWeight: 600, color: '#1a1a1a', marginTop: 4, fontFamily: 'Fraunces, serif' }}>{value}</div>
  </div>
);

// ---------- Services ----------
const ServicesView = ({ services, onEdit, onAdd }) => (
  <div style={{ padding: '24px 32px', height: '100%', overflow: 'auto', background: '#FBFAF6' }}>
    <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: 20 }}>
      <div>
        <h1 style={{ fontFamily: 'Fraunces, serif', fontSize: 28, fontWeight: 500, margin: 0 }}>Ydelser</h1>
        <div style={{ fontSize: 13, color: '#888', marginTop: 4 }}>Klik på en ydelse for at redigere · varighed, pris, mellemrum efter</div>
      </div>
      <button onClick={onAdd} style={{
        background: '#3F4A3A', color: '#fff', border: 'none', borderRadius: 8,
        padding: '10px 18px', fontSize: 14, fontWeight: 600, cursor: 'pointer',
        fontFamily: 'inherit', display: 'flex', alignItems: 'center', gap: 8,
      }}>
        <span style={{ fontSize: 18, lineHeight: 1 }}>+</span> Ny ydelse
      </button>
    </div>
    <div style={{ display: 'grid', gridTemplateColumns: 'repeat(auto-fill, minmax(260px, 1fr))', gap: 16 }}>
      {services.map(s => {
        const c = SERVICE_COLORS.pastel[s.color];
        return (
          <div key={s.id} onClick={() => onEdit(s)} style={{
            background: '#fff', borderRadius: 12, border: '1px solid #EFEDE5',
            overflow: 'hidden', cursor: 'pointer', transition: 'transform 120ms, box-shadow 120ms',
          }}
          onMouseEnter={e => { e.currentTarget.style.transform = 'translateY(-2px)'; e.currentTarget.style.boxShadow = '0 6px 16px rgba(0,0,0,0.08)'; }}
          onMouseLeave={e => { e.currentTarget.style.transform = 'none'; e.currentTarget.style.boxShadow = 'none'; }}
          >
            <div style={{ background: c.bg, padding: 16, borderBottom: `3px solid ${c.border}` }}>
              <div style={{ fontSize: 11, color: c.text, opacity: 0.7, fontWeight: 600, letterSpacing: '0.08em', textTransform: 'uppercase' }}>Service</div>
              <div style={{ fontSize: 20, fontWeight: 600, color: c.text, marginTop: 4 }}>{s.name}</div>
            </div>
            <div style={{ padding: 16 }}>
              <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: s.pauseAfter ? 10 : 0 }}>
                <div>
                  <div style={{ fontSize: 12, color: '#888' }}>Varighed</div>
                  <div style={{ fontSize: 16, fontWeight: 500 }}>{s.duration} min</div>
                </div>
                <div style={{ textAlign: 'right' }}>
                  <div style={{ fontSize: 12, color: '#888' }}>Pris</div>
                  <div style={{ fontSize: 16, fontWeight: 500 }}>{s.price} kr</div>
                </div>
              </div>
              {s.pauseAfter > 0 && (
                <div style={{ marginTop: 10, padding: '8px 10px', background: '#FBFAF6', border: '1px dashed #DDD9CE', borderRadius: 6, fontSize: 12, color: '#666' }}>
                  + <strong>{s.pauseAfter} min mellemrum</strong> efter
                </div>
              )}
            </div>
          </div>
        );
      })}
    </div>
  </div>
);

// ---------- Stats ----------
const StatsView = ({ bookings, customers }) => {
  const totalRevenue = bookings.reduce((sum, b) => sum + getBookingPrice(b), 0);
  const byService = SERVICES.map(s => ({
    ...s,
    count: bookings.filter(b => (b.serviceIds || [b.serviceId]).includes(s.id)).length,
  }));
  const maxCount = Math.max(1, ...byService.map(b => b.count));

  return (
    <div style={{ padding: '24px 32px', height: '100%', overflow: 'auto', background: '#FBFAF6' }}>
      <h1 style={{ fontFamily: 'Fraunces, serif', fontSize: 28, fontWeight: 500, margin: '0 0 20px 0' }}>Statistik · denne uge</h1>

      <div style={{ display: 'grid', gridTemplateColumns: 'repeat(4, 1fr)', gap: 16, marginBottom: 24 }}>
        <StatCard label="Bookinger" value={bookings.length} />
        <StatCard label="Omsætning" value={`${totalRevenue.toLocaleString('da-DK')} kr`} />
        <StatCard label="Aktive kunder" value={customers.length} />
        <StatCard label="Fyldningsgrad" value="78%" />
      </div>

      <div style={{ background: '#fff', borderRadius: 12, border: '1px solid #EFEDE5', padding: 24 }}>
        <div style={{ fontSize: 14, fontWeight: 600, marginBottom: 18 }}>Ydelser fordelt</div>
        <div style={{ display: 'flex', flexDirection: 'column', gap: 12 }}>
          {byService.map(s => {
            const c = SERVICE_COLORS.pastel[s.color];
            return (
              <div key={s.id} style={{ display: 'grid', gridTemplateColumns: '160px 1fr 60px', gap: 12, alignItems: 'center' }}>
                <div style={{ fontSize: 13, fontWeight: 500 }}>{s.name}</div>
                <div style={{ background: '#F4F2EA', borderRadius: 4, height: 20, position: 'relative', overflow: 'hidden' }}>
                  <div style={{ background: c.border, height: '100%', width: `${(s.count / maxCount) * 100}%`, transition: 'width 400ms' }} />
                </div>
                <div style={{ fontSize: 13, fontWeight: 600, textAlign: 'right' }}>{s.count}</div>
              </div>
            );
          })}
        </div>
      </div>
    </div>
  );
};

const StatCard = ({ label, value }) => (
  <div style={{ background: '#fff', borderRadius: 12, border: '1px solid #EFEDE5', padding: 20 }}>
    <div style={{ fontSize: 12, color: '#888', fontWeight: 500, marginBottom: 6, textTransform: 'uppercase', letterSpacing: '0.04em' }}>{label}</div>
    <div style={{ fontSize: 26, fontWeight: 600, color: '#1a1a1a', fontFamily: 'Fraunces, serif' }}>{value}</div>
  </div>
);

const PlaceholderView = ({ title }) => (
  <div style={{ padding: 32, height: '100%', background: '#FBFAF6', display: 'flex', alignItems: 'center', justifyContent: 'center' }}>
    <div style={{ textAlign: 'center', color: '#888' }}>
      <div style={{ fontFamily: 'Fraunces, serif', fontSize: 28, color: '#1a1a1a', marginBottom: 8 }}>{title}</div>
      <div>Denne sektion er ikke en del af denne prototype.</div>
    </div>
  </div>
);

// ---------- Staff ----------
const StaffAvatar = ({ s, size }) => {
  if (s.photo) {
    return (
      <div style={{
        width: size, height: size, borderRadius: '50%',
        background: `url(${s.photo}) center/cover`, border: '1px solid #E5E2D5',
        flexShrink: 0,
      }} />
    );
  }
  return <Avatar name={s.name} tone={s.tone} size={size} />;
};

const StaffView = ({ bookings, customers, staff, onSelectStaff, onEditStaff, onAddStaff }) => {
  const list = staff || STAFF;
  const [selectedId, setSelectedId] = React.useState(list[0]?.id);
  const selected = list.find(s => s.id === selectedId) || list[0];
  if (!selected) return null;

  const staffStats = (id) => {
    const sb = bookings.filter(b => b.staffId === id);
    const revenue = sb.reduce((sum, b) => sum + getBookingPrice(b), 0);
    const minutes = sb.reduce((sum, b) => sum + getBookingDuration(b), 0);
    const fans = customers.filter(c => c.favoriteStaffId === id).length;
    return { count: sb.length, revenue, minutes, fans };
  };

  React.useEffect(() => {
    if (!list.find(s => s.id === selectedId)) setSelectedId(list[0]?.id);
  }, [list, selectedId]);

  const sStats = staffStats(selected.id);
  const todayBookings = bookings.filter(b => b.staffId === selected.id).sort((a,b) => a.start - b.start);
  const fans = customers.filter(c => c.favoriteStaffId === selected.id);
  const utilization = Math.min(100, Math.round((sStats.minutes / (8*60)) * 100));

  return (
    <div style={{ display: 'flex', height: '100%', background: '#FBFAF6', overflow: 'hidden' }}>
      <div style={{ width: 320, flexShrink: 0, borderRight: '1px solid #EFEDE5', display: 'flex', flexDirection: 'column', background: '#fff' }}>
        <div style={{ padding: '20px 24px 16px', borderBottom: '1px solid #EFEDE5', display: 'flex', justifyContent: 'space-between', alignItems: 'flex-start' }}>
          <div>
            <h1 style={{ fontFamily: 'Fraunces, serif', fontSize: 22, fontWeight: 500, margin: 0, color: '#1a1a1a' }}>Medarbejdere</h1>
            <div style={{ fontSize: 12, color: '#888', marginTop: 4 }}>{list.length} aktive · Klipperiet Østerbro</div>
          </div>
          <button onClick={onAddStaff} title="Ny medarbejder" style={{
            background: '#3F4A3A', color: '#fff', border: 'none', borderRadius: 8,
            padding: '8px 12px', fontSize: 12, fontWeight: 600, cursor: 'pointer', fontFamily: 'inherit',
            display: 'flex', alignItems: 'center', gap: 6,
          }}>
            <IconPlus size={12} /> Ny
          </button>
        </div>
        <div style={{ flex: 1, overflow: 'auto' }}>
          {list.map(s => {
            const st = staffStats(s.id);
            const isActive = s.id === selectedId;
            return (
              <button key={s.id} onClick={() => setSelectedId(s.id)} style={{
                display: 'flex', alignItems: 'center', gap: 12,
                width: '100%', textAlign: 'left',
                padding: '14px 24px', borderBottom: '1px solid #F4F2EA',
                background: isActive ? '#F4F2EA' : 'transparent',
                border: 'none', cursor: 'pointer', fontFamily: 'inherit',
                borderLeft: isActive ? '3px solid #7B8A6B' : '3px solid transparent',
                paddingLeft: isActive ? 21 : 24,
              }} onMouseEnter={e => { if (!isActive) e.currentTarget.style.background = '#FBFAF6'; }}
                 onMouseLeave={e => { if (!isActive) e.currentTarget.style.background = 'transparent'; }}>
                <StaffAvatar s={s} size={40} />
                <div style={{ flex: 1, minWidth: 0 }}>
                  <div style={{ fontSize: 14, fontWeight: 500, color: '#1a1a1a' }}>{s.name}</div>
                  <div style={{ fontSize: 12, color: '#888', marginTop: 2 }}>{s.role}</div>
                </div>
                <div style={{ textAlign: 'right' }}>
                  <div style={{ fontSize: 13, fontWeight: 600, color: '#1a1a1a' }}>{st.count}</div>
                  <div style={{ fontSize: 11, color: '#888' }}>i dag</div>
                </div>
              </button>
            );
          })}
        </div>
      </div>

      <div style={{ flex: 1, overflow: 'auto', padding: '32px 40px', maxWidth: 880 }}>
        <div style={{ display: 'flex', alignItems: 'center', gap: 20, marginBottom: 28 }}>
          <StaffAvatar s={selected} size={72} />
          <div style={{ flex: 1 }}>
            <h2 style={{ fontFamily: 'Fraunces, serif', fontSize: 30, fontWeight: 500, margin: 0, color: '#1a1a1a' }}>{selected.name}</h2>
            <div style={{ display: 'flex', gap: 16, marginTop: 6, fontSize: 13, color: '#666', flexWrap: 'wrap' }}>
              <span>{selected.role}</span>
              {selected.phone && <span style={{ display: 'flex', alignItems: 'center', gap: 6 }}><IconPhone size={13} /> {selected.phone}</span>}
              {selected.email && <span style={{ display: 'flex', alignItems: 'center', gap: 6 }}><IconMail size={13} /> {selected.email}</span>}
            </div>
          </div>
          <button onClick={() => onEditStaff(selected)} style={{
            background: '#fff', color: '#3F4A3A', border: '1.5px solid #DDD9CE', borderRadius: 8,
            padding: '10px 14px', fontSize: 13, fontWeight: 600, cursor: 'pointer', fontFamily: 'inherit',
            display: 'flex', alignItems: 'center', gap: 8,
          }}>
            <IconEdit size={14} /> Rediger
          </button>
          <button onClick={() => onSelectStaff(selected.id)} style={{
            background: '#3F4A3A', color: '#fff', border: 'none', borderRadius: 8,
            padding: '10px 16px', fontSize: 13, fontWeight: 600, cursor: 'pointer', fontFamily: 'inherit',
            display: 'flex', alignItems: 'center', gap: 8,
          }}>
            <IconCalendar size={14} /> Vis kalender
          </button>
        </div>

        <div style={{ display: 'grid', gridTemplateColumns: 'repeat(4, 1fr)', gap: 12, marginBottom: 28 }}>
          <MiniStat label="Bookinger i dag" value={sStats.count} />
          <MiniStat label="Omsætning i dag" value={`${sStats.revenue.toLocaleString('da-DK')} kr`} />
          <MiniStat label="Belastning" value={`${utilization}%`} />
          <MiniStat label="Stamkunder" value={sStats.fans} />
        </div>

        <div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 20, marginBottom: 24 }}>
          <div style={{ background: '#fff', border: '1px solid #EFEDE5', borderRadius: 12, padding: 20 }}>
            <div style={{ fontSize: 13, fontWeight: 600, marginBottom: 12 }}>Specialer</div>
            <div style={{ display: 'flex', flexWrap: 'wrap', gap: 6 }}>
              {selected.specialties.map(sp => (
                <span key={sp} style={{ background: '#F4F2EA', borderRadius: 14, padding: '5px 12px', fontSize: 12, color: '#3F4A3A', fontWeight: 500 }}>{sp}</span>
              ))}
            </div>
          </div>
          <div style={{ background: '#fff', border: '1px solid #EFEDE5', borderRadius: 12, padding: 20 }}>
            <div style={{ fontSize: 13, fontWeight: 600, marginBottom: 12 }}>Ugentlig vagtplan</div>
            <div style={{ display: 'grid', gridTemplateColumns: 'repeat(6, 1fr)', gap: 6 }}>
              {[['man','Man'],['tir','Tir'],['ons','Ons'],['tor','Tor'],['fre','Fre'],['lor','Lør']].map(([k,l]) => {
                const v = selected.schedule[k];
                const off = v === 'Fri';
                return (
                  <div key={k} style={{ background: off ? '#F4F2EA' : '#F4F7F0', border: `1px solid ${off ? '#E5E2D5' : '#DCE6CC'}`, borderRadius: 8, padding: '8px 6px', textAlign: 'center' }}>
                    <div style={{ fontSize: 10, color: '#888', fontWeight: 600, textTransform: 'uppercase' }}>{l}</div>
                    <div style={{ fontSize: 12, fontWeight: 600, color: off ? '#999' : '#3F5A30', marginTop: 3 }}>{v}</div>
                  </div>
                );
              })}
            </div>
          </div>
        </div>

        <div style={{ background: '#fff', border: '1px solid #EFEDE5', borderRadius: 12, padding: 20, marginBottom: 24 }}>
          <div style={{ fontSize: 13, fontWeight: 600, marginBottom: 12 }}>Aftaler i dag</div>
          {todayBookings.length === 0 ? (
            <div style={{ fontSize: 13, color: '#888', padding: '12px 0' }}>Ingen aftaler i dag.</div>
          ) : (
            <div style={{ display: 'flex', flexDirection: 'column' }}>
              {todayBookings.map(b => {
                const primary = getBookingPrimary(b);
                const dur = getBookingDuration(b);
                const c = SERVICE_COLORS.pastel[primary.color];
                const cust = customers.find(x => x.id === b.customerId);
                return (
                  <div key={b.id} style={{ display: 'flex', alignItems: 'center', gap: 14, padding: '10px 0', borderBottom: '1px solid #F4F2EA' }}>
                    <div style={{ width: 90, fontSize: 12, color: '#666', fontWeight: 500 }}>
                      {fmtTime(b.start)}–{fmtTime(b.start + dur)}
                    </div>
                    <div style={{ width: 8, height: 32, borderRadius: 4, background: c.border }} />
                    <div style={{ flex: 1 }}>
                      <div style={{ fontSize: 14, fontWeight: 500 }}>{cust?.name || 'Ukendt'}</div>
                      <div style={{ fontSize: 12, color: '#888' }}>{getBookingTitle(b)} · {dur} min</div>
                    </div>
                    <div style={{ fontSize: 13, fontWeight: 600, color: '#1a1a1a' }}>{getBookingPrice(b)} kr</div>
                  </div>
                );
              })}
            </div>
          )}
        </div>

        <div style={{ background: '#fff', border: '1px solid #EFEDE5', borderRadius: 12, padding: 20 }}>
          <div style={{ fontSize: 13, fontWeight: 600, marginBottom: 12 }}>Stamkunder ({fans.length})</div>
          {fans.length === 0 ? (
            <div style={{ fontSize: 13, color: '#888' }}>Ingen kunder har valgt {selected.name.split(' ')[0]} som foretrukken frisør endnu.</div>
          ) : (
            <div style={{ display: 'flex', flexWrap: 'wrap', gap: 8 }}>
              {fans.map(c => (
                <div key={c.id} style={{ display: 'flex', alignItems: 'center', gap: 8, background: '#F4F2EA', borderRadius: 18, padding: '6px 12px 6px 6px' }}>
                  <Avatar name={c.name} tone="#E8DBC8" size={24} />
                  <span style={{ fontSize: 12, fontWeight: 500 }}>{c.name}</span>
                  <span style={{ fontSize: 11, color: '#888' }}>· {c.visits} besøg</span>
                </div>
              ))}
            </div>
          )}
        </div>
      </div>
    </div>
  );
};

Object.assign(window, { Sidebar, StaffAvatar, CustomersView, ServicesView, StatsView, PlaceholderView, StaffView });
