/*!
 * © 2026 Paulo Oliveira · All Rights Reserved
 * Fingerprint: pf-paulo-2026-r5-projects-7c41ab
 *
 * /projects route — freelance portfolio with high-fidelity interactive demos.
 * Demos copy the visual style of the real apps (intranet, Branca, e-reader,
 * transcribe, jobs) but use ONLY mock English data — no real API calls,
 * no customer information.
 */
/* global React, PROFILE, TopBar, FooterBlock */

(function () {
  const { useState, useEffect, useMemo, useRef } = React;

  /* ───────── shared atoms ───────── */
  function Tag({ children }) {
    return (
      <span style={{
        fontSize: 10, letterSpacing: "0.2em", textTransform: "uppercase",
        color: "var(--accent)", fontFamily: "JetBrains Mono, monospace",
        padding: "3px 8px", border: "1px solid var(--accent)", borderRadius: 3,
      }}>{children}</span>
    );
  }

  /* ═══════════════════════════════════════════════════════════════════
     PROJECTS HERO — name + portrait + cert + nav links
     ═══════════════════════════════════════════════════════════════════ */
  function ProjectsHero() {
    const [i, setI] = useState(0);
    // URLs sincronizadas com HERO_CERTS em src/sections.jsx — cada cert
    // aponta pra credencial específica no Microsoft Learn (não pra index
    // genérica). Atualizar nos dois lugares se mudar.
    const certs = [
      {
        label: "Azure Solutions Architect",
        ribbon: "EXPERT",
        url: "https://learn.microsoft.com/api/credentials/share/en-us/goncalves/7CDD13E96A0B7115?sharingId=ABCF060CC0240657",
      },
      {
        label: "DevOps Engineer Expert",
        ribbon: "EXPERT",
        url: "https://learn.microsoft.com/api/credentials/share/en-us/goncalves/D6BB088068EF1599?sharingId=ABCF060CC0240657",
      },
      {
        label: "Azure Security Engineer",
        ribbon: "ASSOC",
        url: "https://learn.microsoft.com/en-us/users/goncalves/credentials/certification/azure-security-engineer?tab=credentials-tab",
      },
    ];
    useEffect(() => {
      const id = setInterval(() => setI((x) => (x + 1) % certs.length), 4500);
      return () => clearInterval(id);
    }, []);
    const c = certs[i];

    return (
      <section style={{ padding: "48px 28px 36px", maxWidth: 1280, margin: "0 auto" }}>
        <div className="projects-hero-grid" style={{
          display: "grid",
          gridTemplateColumns: "auto 1fr auto",
          gap: 28, alignItems: "center",
          flexWrap: "wrap",
        }}>
          <div style={{ display: "flex", alignItems: "center", gap: 22 }}>
            <div style={{
              position: "relative", width: 96, height: 96,
              borderRadius: "50%", overflow: "hidden",
              border: "1px solid var(--line-strong)",
              boxShadow: "0 0 0 6px color-mix(in oklab, var(--accent) 8%, transparent)",
              background: "var(--bg-1)", flexShrink: 0,
            }}>
              <img src="/assets/paulo.png" alt="Paulo Oliveira"
                style={{ width: "100%", height: "100%", objectFit: "cover", filter: "grayscale(0.2) contrast(1.05)" }} />
            </div>
            <div>
              <div className="label" style={{ marginBottom: 6 }}>// IDENTITY</div>
              <div className="display" style={{ fontSize: 28, fontWeight: 700, lineHeight: 1.05, letterSpacing: "-0.02em" }}>
                Paulo Oliveira
              </div>
              <div className="ink-mute" style={{ fontSize: 13, marginTop: 4 }}>
                Cloud &amp; IT Infrastructure Engineer · Vancouver, BC
              </div>
            </div>
          </div>

          <a href={c.url}
            target="_blank" rel="noopener noreferrer" key={i}
            style={{
              display: "flex", alignItems: "center", gap: 18,
              padding: "15px 21px",
              border: "1px solid var(--line-strong)", borderRadius: 12,
              background: "color-mix(in oklab, var(--accent) 6%, var(--bg-1))",
              textDecoration: "none", color: "inherit",
              maxWidth: 420, justifySelf: "center",
              animation: "certFadeIn .45s ease",
            }}>
            <svg width="60" height="60" viewBox="0 0 64 64" fill="none" style={{ flexShrink: 0 }}>
              <path d="M32 2 L58 17 L58 47 L32 62 L6 47 L6 17 Z" fill="rgba(0,0,0,0.35)" stroke="var(--accent)" strokeWidth="1.5" />
              <g transform="translate(20, 18)">
                <rect x="0" y="0" width="10" height="10" fill="#f25022" />
                <rect x="12" y="0" width="10" height="10" fill="#7fba00" />
                <rect x="0" y="12" width="10" height="10" fill="#00a4ef" />
                <rect x="12" y="12" width="10" height="10" fill="#ffb900" />
              </g>
              <text x="32" y="52" textAnchor="middle" fontSize="7" fontWeight="700" fill="var(--accent)" fontFamily="JetBrains Mono, monospace">{c.ribbon}</text>
            </svg>
            <div style={{ minWidth: 0, flex: 1 }}>
              <div className="ink-dim" style={{ fontSize: 14, letterSpacing: "0.18em", textTransform: "uppercase" }}>Microsoft Certified</div>
              <div className="display" style={{ fontSize: 20, fontWeight: 600, lineHeight: 1.25, marginTop: 3 }}>{c.label}</div>
              <div style={{ fontSize: 15, color: "var(--accent)", letterSpacing: "0.2em", marginTop: 4, textTransform: "uppercase" }}>✓ Verify ↗</div>
            </div>
          </a>

          <div style={{ display: "flex", flexDirection: "column", gap: 10, alignItems: "stretch" }}>
            <a className="btn primary" href={"mailto:" + PROFILE.email} style={{ justifyContent: "center" }}>↗ Contact</a>
            <a className="btn" href={PROFILE.linkedinUrl} target="_blank" rel="noopener" style={{ justifyContent: "center" }}>LinkedIn</a>
            <a className="btn" href="/" style={{ justifyContent: "center" }}>← Home</a>
          </div>
        </div>

        <style>{`
          @keyframes certFadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }
          @media (max-width: 900px) {
            .projects-hero-grid { grid-template-columns: 1fr !important; justify-items: start; }
          }
        `}</style>
      </section>
    );
  }

  function PortfolioDivider() {
    return (
      <section style={{ maxWidth: 1280, margin: "0 auto", padding: "8px 28px 0" }}>
        <div style={{
          display: "flex", alignItems: "center", gap: 18,
          borderTop: "1px solid var(--line-strong)", paddingTop: 28,
        }}>
          <span className="cmd mono" style={{ color: "var(--accent)", fontSize: 13 }}>$ ls ~/portfolio</span>
          <h2 className="display" style={{ margin: 0, fontSize: "clamp(32px, 5vw, 56px)", fontWeight: 700, letterSpacing: "-0.03em" }}>Portfolio</h2>
          <span className="ink-dim" style={{ marginLeft: "auto", fontSize: 11, letterSpacing: "0.18em", textTransform: "uppercase" }}>// freelance proof-of-work</span>
        </div>
        <p className="ink-mute" style={{ marginTop: 14, fontSize: 14, maxWidth: 760, lineHeight: 1.6 }}>
          Selected demos across web development, Microsoft 365 administration and cybersecurity.
          Each demo is a faithful copy of the real product UI, running with mock English data — no customer information is exposed.
        </p>
      </section>
    );
  }

  function MenuTabs({ active, onChange }) {
    const tabs = [
      { id: "web", label: "Web Projects" },
      { id: "ms",  label: "Microsoft Projects" },
      { id: "sec", label: "Security Projects" },
    ];
    return (
      <section style={{ maxWidth: 1280, margin: "0 auto", padding: "32px 28px 0" }}>
        <div style={{
          display: "flex", flexWrap: "wrap", gap: 12,
          padding: 8, border: "1px solid var(--line)",
          background: "linear-gradient(180deg, rgba(10,18,12,0.6), rgba(6,10,8,0.4))",
          borderRadius: 14,
        }}>
          {tabs.map((t) => {
            const a = active === t.id;
            return (
              <button key={t.id} onClick={() => onChange(t.id)}
                style={{
                  flex: "1 1 200px", padding: "14px 18px",
                  border: "1px solid " + (a ? "var(--accent)" : "var(--line)"),
                  borderRadius: 10,
                  background: a ? "var(--accent)" : "transparent",
                  color: a ? "#02110a" : "var(--ink)",
                  fontFamily: "Space Grotesk, sans-serif",
                  fontSize: 16, fontWeight: 600, letterSpacing: "-0.01em",
                  cursor: "pointer", transition: "all .18s ease",
                  textAlign: "left",
                }}>
                <span style={{ display: "block", fontSize: 10, letterSpacing: "0.18em", textTransform: "uppercase", opacity: 0.7, marginBottom: 4 }}>
                  ▸ {t.id.toUpperCase()}
                </span>
                {t.label}
              </button>
            );
          })}
        </div>
      </section>
    );
  }

  /* ═══════════════════════════════════════════════════════════════════
     DEMO MODAL — full-screen overlay
     ═══════════════════════════════════════════════════════════════════ */
  function DemoModal({ open, title, onClose, children }) {
    useEffect(() => {
      if (!open) return;
      const onKey = (e) => { if (e.key === "Escape") onClose(); };
      window.addEventListener("keydown", onKey);
      document.body.style.overflow = "hidden";
      return () => {
        window.removeEventListener("keydown", onKey);
        document.body.style.overflow = "";
      };
    }, [open]);
    if (!open) return null;
    return (
      <div onClick={(e) => { if (e.target === e.currentTarget) onClose(); }}
        style={{
          position: "fixed", inset: 0, zIndex: 200,
          background: "rgba(0,0,0,0.78)", backdropFilter: "blur(6px)",
          padding: "20px",
          display: "flex", flexDirection: "column",
          animation: "fadeIn .25s ease",
        }}>
        <div style={{
          maxWidth: 1280, width: "100%", margin: "0 auto",
          display: "flex", alignItems: "center", justifyContent: "space-between",
          padding: "10px 14px",
          background: "var(--bg-1)", border: "1px solid var(--line-strong)",
          borderTopLeftRadius: 12, borderTopRightRadius: 12,
        }}>
          <div style={{ display: "flex", alignItems: "center", gap: 10, fontSize: 12, letterSpacing: "0.16em", textTransform: "uppercase", color: "var(--ink-mute)" }}>
            <span style={{ display: "flex", gap: 6 }}>
              <span style={{ width: 10, height: 10, borderRadius: "50%", background: "var(--danger)" }}></span>
              <span style={{ width: 10, height: 10, borderRadius: "50%", background: "var(--warn)" }}></span>
              <span style={{ width: 10, height: 10, borderRadius: "50%", background: "var(--accent)" }}></span>
            </span>
            <span>· demo · {title}</span>
          </div>
          <button onClick={onClose} style={{
            background: "transparent", border: "1px solid var(--line-strong)",
            color: "var(--ink)", fontFamily: "JetBrains Mono, monospace",
            fontSize: 11, letterSpacing: "0.16em", padding: "6px 12px",
            borderRadius: 6, cursor: "pointer",
          }}>✕ Close</button>
        </div>
        <div style={{
          maxWidth: 1280, width: "100%", margin: "0 auto",
          flex: 1, background: "#0b0f0d",
          border: "1px solid var(--line-strong)", borderTop: "none",
          borderBottomLeftRadius: 12, borderBottomRightRadius: 12,
          overflow: "auto",
        }}>
          {children}
        </div>
        <style>{`@keyframes fadeIn { from { opacity: 0 } to { opacity: 1 } }`}</style>
      </div>
    );
  }

  /* ═══════════════════════════════════════════════════════════════════
     DEMO 1 · Intranet (faithful to ABC+ real design system)
     Tokens: navy #0B2545, blue #1E5BA8, soft #f2f4f7, panel #fff,
     border #d7dde5, Inter font.
     ═══════════════════════════════════════════════════════════════════ */
  function DemoIntranetV1_Unused() {
    const [section, setSection] = useState("home");

    const NAV = [
      { group: "Main", items: [
        { id: "home",    label: "Home",                icon: HomeIcon, badge: null },
      ]},
      { group: "Modules", items: [
        { id: "hr",        label: "Time Clock",           icon: ClockIcon,  badge: null },
        { id: "at",        label: "Technical Service",    icon: WrenchIcon, badge: 38 },
        { id: "rental",    label: "Rentals",              icon: BoxIcon,    badge: null },
        { id: "commercial",label: "Commercial",           icon: TrendIcon,  badge: null },
        { id: "logistics", label: "Logistics",            icon: TruckIcon,  badge: null, accent: "#F97316" },
      ]},
      { group: "Communication", items: [
        { id: "comms",    label: "Suggestions",          icon: ChatIcon,   badge: 4 },
        { id: "policies", label: "Policies",             icon: BookIcon },
        { id: "training", label: "Training",             icon: CapIcon },
      ]},
      { group: "Administration", items: [
        { id: "clients",  label: "Client Database",      icon: DbIcon },
        { id: "users",    label: "User Management",      icon: UsersIcon },
        { id: "audit",    label: "Audit Log",            icon: ShieldIcon },
        { id: "settings", label: "Settings",             icon: GearIcon },
      ]},
    ];

    return (
      <div style={{ display: "grid", gridTemplateColumns: "240px 1fr", height: "100%", minHeight: 720, background: "#f2f4f7", color: "#1f2937", fontFamily: "Inter, system-ui, sans-serif", fontSize: 14 }}>
        {/* ───────── Sidebar ───────── */}
        <aside style={{ background: "#0B2545", color: "#ffffff", display: "flex", flexDirection: "column" }}>
          <div style={{ padding: "16px 18px", borderBottom: "1px solid rgba(255,255,255,0.08)", display: "flex", alignItems: "center", gap: 10 }}>
            <img src="/assets/logo-abc.png" alt="ABC+" style={{ height: 34, objectFit: "contain", filter: "brightness(0) invert(1)" }} />
            <span style={{ fontWeight: 700, fontSize: 15, letterSpacing: "-0.01em" }}>Intranet</span>
          </div>

          <nav style={{ padding: "10px 8px", overflowY: "auto", flex: 1 }}>
            {NAV.map((g) => (
              <div key={g.group} style={{ marginBottom: 14 }}>
                <div style={{ fontSize: 9.5, letterSpacing: "0.18em", textTransform: "uppercase", color: "rgba(255,255,255,0.45)", padding: "6px 12px 4px" }}>{g.group}</div>
                {g.items.map((it) => {
                  const a = section === it.id;
                  const Icon = it.icon;
                  return (
                    <button key={it.id} onClick={() => setSection(it.id)}
                      style={{
                        display: "flex", alignItems: "center", gap: 10,
                        width: "100%", textAlign: "left", border: "none", cursor: "pointer",
                        padding: "8px 12px", borderRadius: 6,
                        background: a ? "rgba(255,255,255,0.10)" : "transparent",
                        color: a ? "#fff" : "rgba(255,255,255,0.78)",
                        fontSize: 13, fontWeight: a ? 600 : 500,
                        marginBottom: 1,
                        borderLeft: a ? "3px solid #5ab7ff" : "3px solid transparent",
                        paddingLeft: a ? 9 : 12,
                      }}>
                      <Icon size={16} color={it.accent || (a ? "#5ab7ff" : "rgba(255,255,255,0.7)")} />
                      <span style={{ flex: 1 }}>{it.label}</span>
                      {it.badge && (
                        <span style={{ background: "#dc2626", color: "#fff", fontSize: 10, padding: "1px 6px", borderRadius: 999, fontWeight: 700 }}>{it.badge}</span>
                      )}
                    </button>
                  );
                })}
              </div>
            ))}
          </nav>

          <div style={{ padding: 12, borderTop: "1px solid rgba(255,255,255,0.08)", display: "flex", alignItems: "center", gap: 10, fontSize: 12 }}>
            <div style={{ width: 32, height: 32, borderRadius: "50%", background: "linear-gradient(135deg,#5ab7ff,#1e6fb0)", color: "#fff", display: "grid", placeItems: "center", fontWeight: 700, fontSize: 12 }}>DU</div>
            <div style={{ minWidth: 0, flex: 1 }}>
              <div style={{ fontWeight: 600, color: "#fff" }}>Demo User</div>
              <div style={{ color: "rgba(255,255,255,0.55)", fontSize: 11 }}>Administrator</div>
            </div>
          </div>
        </aside>

        {/* ───────── Body ───────── */}
        <div style={{ display: "flex", flexDirection: "column", minWidth: 0 }}>
          {/* Top bar */}
          <header style={{ background: "#fff", borderBottom: "1px solid #d7dde5", padding: "10px 22px", display: "flex", justifyContent: "space-between", alignItems: "center" }}>
            <div style={{ display: "flex", alignItems: "center", gap: 12, color: "#4b5563", fontSize: 13 }}>
              <SearchIcon size={15} color="#6b7280" />
              <span style={{ color: "#9ca3af" }}>Search clients, OS, contracts…</span>
            </div>
            <div style={{ display: "flex", gap: 14, alignItems: "center", fontSize: 13 }}>
              <span style={{ position: "relative", color: "#6b7280" }}>
                <BellIcon size={18} color="#6b7280" />
                <span style={{ position: "absolute", top: -4, right: -4, width: 14, height: 14, background: "#dc2626", borderRadius: "50%", color: "#fff", fontSize: 9, display: "grid", placeItems: "center", fontWeight: 700 }}>3</span>
              </span>
              <span style={{ width: 1, height: 22, background: "#d7dde5" }}></span>
              <span style={{ color: "#1f2937", fontWeight: 500 }}>Demo User</span>
              <div style={{ width: 30, height: 30, borderRadius: "50%", background: "linear-gradient(135deg,#5ab7ff,#1e6fb0)", color: "#fff", display: "grid", placeItems: "center", fontWeight: 700, fontSize: 12 }}>DU</div>
            </div>
          </header>

          <main style={{ padding: "20px 24px", overflowY: "auto", flex: 1 }}>
            {section === "home" && <IntranetHome />}
            {section === "at"   && <IntranetAT />}
            {section !== "home" && section !== "at" && <IntranetPlaceholder section={section} />}
          </main>
        </div>
      </div>
    );
  }

  /* ───────── Intranet · Home dashboard ───────── */
  function IntranetHome() {
    return (
      <div style={{ display: "flex", flexDirection: "column", gap: 16 }}>
        {/* Greeting */}
        <div>
          <h1 style={{ margin: 0, fontSize: 28, fontWeight: 800, color: "#0B2545", letterSpacing: "-0.015em", lineHeight: 1.1 }}>
            Good morning, Demo! <span aria-hidden>👋</span>
          </h1>
          <p style={{ margin: "4px 0 0", color: "#64748b", textTransform: "capitalize", fontSize: 13.5 }}>
            Tuesday, April 30, 2026
          </p>
        </div>

        {/* Hero gradient cards */}
        <div className="ihome-hero" style={{ display: "grid", gridTemplateColumns: "repeat(3, minmax(0,1fr))", gap: 16 }}>
          <HeroCardI title="Clock In" subtitle="Click to register your work day" icon={<ClockIcon size={32} color="#fff" />} gradient="linear-gradient(135deg, #10B981 0%, #047857 100%)" shadow="0 14px 28px -10px rgba(5,150,105,0.45)" />
          <HeroCardI title="Logistics" subtitle="4 drivers active" icon={<TruckIcon size={32} color="#fff" />} gradient="linear-gradient(135deg, #F97316 0%, #C2410C 100%)" shadow="0 14px 28px -10px rgba(249,115,22,0.45)" />
          <HeroCardI title="Training" subtitle="Quizzes, modules & basics" icon={<CapIcon size={32} color="#fff" />} gradient="linear-gradient(135deg, #3B82F6 0%, #1D4ED8 100%)" shadow="0 14px 28px -10px rgba(29,78,216,0.45)" />
        </div>

        <div style={{ height: 1, background: "#e5e7eb" }}></div>

        {/* Calendar + Notices */}
        <div style={{ display: "grid", gridTemplateColumns: "2fr 1fr", gap: 16 }}>
          <div className="i-card" style={{ padding: 0, overflow: "hidden" }}>
            <div style={{ display: "flex", alignItems: "center", padding: "10px 16px", borderBottom: "1px solid #e6eaf0" }}>
              <button style={iIconBtn}><ChevronLeftIcon size={16} /></button>
              <div style={{ flex: 1, textAlign: "center" }}>
                <span style={{ fontWeight: 700, fontSize: 14, color: "#1f2937" }}>04/30</span>
                <span style={{ marginLeft: 6, fontSize: 10, fontWeight: 600, background: "#059669", color: "#fff", borderRadius: 10, padding: "2px 7px", verticalAlign: "middle" }}>Today</span>
                <span style={{ fontSize: 12, color: "#6b7280", marginLeft: 8 }}>Tuesday</span>
              </div>
              <button style={iIconBtn}><ChevronRightIcon size={16} /></button>
            </div>

            <div style={{ display: "grid", gridTemplateColumns: "1fr 1fr" }}>
              {/* Mini calendar */}
              <div style={{ padding: "14px 16px", borderRight: "1px solid #e6eaf0" }}>
                <div style={{ display: "flex", justifyContent: "space-between", alignItems: "center", marginBottom: 8 }}>
                  <button style={iIconBtn}><ChevronLeftIcon size={13} /></button>
                  <div style={{ fontSize: 11, fontWeight: 700, color: "#1f2937", textTransform: "uppercase", letterSpacing: "0.05em" }}>April 2026</div>
                  <button style={iIconBtn}><ChevronRightIcon size={13} /></button>
                </div>
                <div style={{ display: "grid", gridTemplateColumns: "repeat(7,1fr)", gap: 2, marginBottom: 4 }}>
                  {["S","M","T","W","T","F","S"].map((d,i) => (<div key={i} style={{ textAlign: "center", fontSize: 9, color: "#6b7280", fontWeight: 600, padding: "2px 0" }}>{d}</div>))}
                  {Array.from({ length: 35 }, (_, i) => {
                    const day = i - 2;
                    if (day < 1 || day > 30) return <div key={i}/>;
                    const isToday = day === 30;
                    const hasTasks = [3, 7, 12, 18, 22, 25, 30].includes(day);
                    const hasEvt = [5, 14, 21, 28].includes(day);
                    return (
                      <div key={i} style={{
                        textAlign: "center", fontSize: 11, padding: "3px 1px 7px", borderRadius: 5, cursor: "pointer",
                        background: isToday ? "#0B2545" : "transparent",
                        color: isToday ? "#fff" : "#1f2937", fontWeight: isToday ? 700 : 400,
                        position: "relative",
                      }}>
                        {day}
                        {(hasTasks || hasEvt) && (
                          <span style={{ position: "absolute", bottom: 2, left: "50%", transform: "translateX(-50%)", display: "flex", gap: 2 }}>
                            {hasTasks && <span style={{ width: 4, height: 4, background: isToday ? "#fff" : "#059669", borderRadius: "50%" }}></span>}
                            {hasEvt   && <span style={{ width: 4, height: 4, background: isToday ? "#fff" : "#3B82F6", borderRadius: "50%" }}></span>}
                          </span>
                        )}
                      </div>
                    );
                  })}
                </div>
              </div>

              {/* Tasks */}
              <div style={{ padding: "14px 16px", display: "flex", flexDirection: "column", gap: 8 }}>
                <div style={{ display: "flex", justifyContent: "space-between", alignItems: "center" }}>
                  <div style={{ fontSize: 11, fontWeight: 700, color: "#1f2937", textTransform: "uppercase", letterSpacing: "0.05em" }}>Today's Tasks</div>
                  <span style={{ fontSize: 10, color: "#6b7280" }}>3 done · 2 pending</span>
                </div>
                {[
                  { text: "Call Northwest Power — quote follow-up", tag: "commercial", done: false },
                  { text: "Approve Yukon Mining repeater repair", tag: "at", done: false },
                  { text: "Send invoice to Pacific Logistics", tag: "rental", done: true },
                  { text: "Verify driver Carlos route #4", tag: "logistics", done: true },
                  { text: "Schedule monthly retro with Lucas", tag: "commercial", done: true },
                ].map((t, i) => (
                  <div key={i} style={{ display: "flex", alignItems: "flex-start", gap: 8, fontSize: 12.5, color: t.done ? "#9ca3af" : "#1f2937", textDecoration: t.done ? "line-through" : "none" }}>
                    <span style={{ width: 14, height: 14, marginTop: 2, border: "1.5px solid " + (t.done ? "#9ca3af" : "#0B2545"), borderRadius: 3, background: t.done ? "#0B2545" : "transparent", color: "#fff", display: "grid", placeItems: "center", fontSize: 9, flexShrink: 0 }}>
                      {t.done ? "✓" : ""}
                    </span>
                    <span style={{ fontSize: 9.5, fontWeight: 700, color: TASK_TAG[t.tag].color, background: TASK_TAG[t.tag].bg, border: "1px solid " + TASK_TAG[t.tag].border, borderRadius: 999, padding: "1px 7px", textTransform: "uppercase", letterSpacing: "0.04em", flexShrink: 0, marginTop: 1 }}>
                      {TASK_TAG[t.tag].label}
                    </span>
                    <span style={{ flex: 1 }}>{t.text}</span>
                  </div>
                ))}
              </div>
            </div>
          </div>

          {/* Notices column */}
          <div className="i-card" style={{ padding: 0, overflow: "hidden" }}>
            <div style={{ padding: "10px 16px", borderBottom: "1px solid #e6eaf0", display: "flex", alignItems: "center", gap: 8 }}>
              <MegaIcon size={15} color="#4338CA" />
              <span style={{ fontSize: 14, fontWeight: 700, color: "#1f2937", flex: 1 }}>Important Notices</span>
            </div>
            {[
              { ic: MegaIcon,    bg: "rgba(99,102,241,.14)",  fg: "#4338CA", title: "New Q3 Branding Guidelines",      sub: "Please review the updated logo and color palette by next Monday.",   t: "2 h ago" },
              { ic: ShieldIcon2, bg: "rgba(16,185,129,.14)",  fg: "#047857", title: "Security Training Mandatory",     sub: "Phishing simulation results shared — module #3 expires May 15.",       t: "yesterday" },
              { ic: CalIcon,     bg: "rgba(249,115,22,.14)",  fg: "#C2410C", title: "Office Closed · Victoria Day",     sub: "Monday, May 19 — emergency line will remain available 24h.",            t: "2 d ago" },
            ].map((n, i) => {
              const Ic = n.ic;
              return (
                <div key={i} style={{ padding: "12px 16px", borderBottom: i < 2 ? "1px solid #e6eaf0" : "none", display: "flex", gap: 10 }}>
                  <div style={{ width: 32, height: 32, borderRadius: 8, background: n.bg, color: n.fg, display: "grid", placeItems: "center", flexShrink: 0 }}>
                    <Ic size={16} color={n.fg} />
                  </div>
                  <div style={{ minWidth: 0, flex: 1 }}>
                    <div style={{ fontSize: 12.5, fontWeight: 600, color: "#1f2937", lineHeight: 1.3 }}>{n.title}</div>
                    <div style={{ fontSize: 11.5, color: "#6b7280", marginTop: 3, lineHeight: 1.4 }}>{n.sub}</div>
                    <div style={{ fontSize: 10, color: "#9ca3af", marginTop: 4 }}>{n.t}</div>
                  </div>
                </div>
              );
            })}
          </div>
        </div>

        <div style={{ height: 1, background: "#e5e7eb" }}></div>

        {/* Rentals + Upcoming Events */}
        <div className="i-card" style={{ padding: 0, overflow: "hidden" }}>
          <div style={{ padding: "10px 16px", borderBottom: "1px solid #e6eaf0", display: "flex", alignItems: "center", gap: 8 }}>
            <FileIcon size={15} color="#0B2545" />
            <span style={{ fontSize: 14, fontWeight: 700, color: "#1f2937", flex: 1 }}>Rentals</span>
            <span style={{ fontSize: 22, fontWeight: 800, color: "#0B2545" }}>142</span>
            <span style={{ fontSize: 12, color: "#6b7280" }}>active</span>
          </div>
          <div style={{ display: "grid", gridTemplateColumns: "1fr 1fr" }}>
            <div style={{ padding: "12px 16px", borderRight: "1px solid #e6eaf0" }}>
              <div style={{ fontSize: 11, fontWeight: 700, textTransform: "uppercase", letterSpacing: "0.05em", marginBottom: 8 }}>Recent Contracts</div>
              {[
                { c: "Pacific Logistics", d: "04/22" },
                { c: "Northwest Power Co.", d: "04/19" },
                { c: "Granite Construction", d: "04/15" },
                { c: "Coast Security Ltd.", d: "04/11" },
              ].map((r) => (
                <div key={r.c} style={{ fontSize: 12.5, display: "flex", justifyContent: "space-between", padding: "5px 0", borderBottom: "1px solid #e6eaf0" }}>
                  <span style={{ overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap", maxWidth: "65%" }}>{r.c}</span>
                  <span style={{ color: "#6b7280" }}>{r.d}</span>
                </div>
              ))}
              <div style={{ fontSize: 11, fontWeight: 700, textTransform: "uppercase", letterSpacing: "0.05em", marginTop: 14, marginBottom: 6, color: "#1f2937" }}>Renewal</div>
              {[
                { c: "Pacific Logistics", days: 12, danger: true },
                { c: "Coast Security Ltd.", days: 27, danger: false },
                { c: "Yukon Mining Group", days: 41, danger: false },
              ].map((r) => (
                <div key={r.c} style={{ fontSize: 12.5, display: "flex", justifyContent: "space-between", padding: "5px 0", borderBottom: "1px solid #e6eaf0", alignItems: "center" }}>
                  <span style={{ fontWeight: 500, overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap", maxWidth: "65%" }}>{r.c}</span>
                  <span style={{ fontSize: 10, fontWeight: 700, color: r.danger ? "#DC2626" : "#D97706" }}>{r.days}d</span>
                </div>
              ))}
            </div>
            <div style={{ padding: "12px 16px" }}>
              <div style={{ fontSize: 11, fontWeight: 700, textTransform: "uppercase", letterSpacing: "0.05em", marginBottom: 8 }}>Upcoming Customer Events</div>
              {[
                { src: "rental", t: "Northwest Power Co.", d: "05/04" },
                { src: "comms",  t: "Granite — quarterly review",  d: "05/06" },
                { src: "rental", t: "Coast Security pickup",        d: "05/09" },
                { src: "comms",  t: "Pacific Logistics retro",      d: "05/12" },
                { src: "rental", t: "Yukon Mining radio audit",     d: "05/14" },
              ].map((e, i) => (
                <div key={i} style={{ display: "flex", alignItems: "center", gap: 6, padding: "5px 0", borderBottom: "1px solid #e6eaf0" }}>
                  <span style={{ fontSize: 9, fontWeight: 700, color: "#fff", background: e.src === "rental" ? "#3B82F6" : "#F97316", borderRadius: 3, padding: "1px 5px" }}>
                    {e.src === "rental" ? "Rental" : "Suggestion"}
                  </span>
                  <span style={{ flex: 1, fontSize: 12.5, fontWeight: 500 }}>{e.t}</span>
                  <span style={{ fontSize: 10, color: "#6b7280" }}>{e.d}</span>
                </div>
              ))}
            </div>
          </div>
        </div>

        {/* Daily Tip */}
        <div className="i-card" style={{ padding: "12px 16px", display: "flex", alignItems: "center", gap: 12, borderLeft: "4px solid #f59e0b" }}>
          <BulbIcon size={18} color="#f59e0b" />
          <div style={{ flex: 1 }}>
            <div style={{ display: "flex", alignItems: "center", gap: 8, marginBottom: 4 }}>
              <span style={{ fontSize: 10, fontWeight: 700, color: "#6b7280", textTransform: "uppercase", letterSpacing: "0.07em" }}>Daily Tip</span>
              <span style={{ fontSize: 10, fontWeight: 700, color: "#7C3AED", background: "rgba(124,58,237,0.08)", border: "1px solid rgba(124,58,237,0.2)", borderRadius: 999, padding: "2px 8px", textTransform: "uppercase", letterSpacing: "0.05em" }}>📡 Radio Communications</span>
            </div>
            <div style={{ fontWeight: 700, fontSize: 13, color: "#1f2937", marginBottom: 2 }}>Check the battery before delivery</div>
            <div style={{ fontSize: 12, color: "#4b5563", lineHeight: 1.5 }}>
              Always confirm full charge and run a transmission test before handing a radio over to the customer. Prevents avoidable support calls.
            </div>
          </div>
          <span style={{ fontSize: 12, color: "#6b7280" }}>3 / 12</span>
        </div>

        <style>{`
          .i-card {
            background: #fff;
            border: 1px solid #d7dde5;
            border-radius: 4px;
            padding: 18px;
            box-shadow: 0 1px 2px rgba(16,24,40,.05);
          }
          @media (max-width: 1100px) { .ihome-hero { grid-template-columns: 1fr 1fr !important; } }
          @media (max-width: 720px)  { .ihome-hero { grid-template-columns: 1fr !important; } }
        `}</style>
      </div>
    );
  }

  /* ───────── Intranet · Technical Service module ───────── */
  function IntranetAT() {
    const tickets = [
      { id: "1187", client: "Northwest Power Co.", radio: "MOTOTRBO XPR3500e", status: "In Diagnostic",   color: "#F59E0B", days: 3 },
      { id: "1188", client: "Pacific Logistics",   radio: "DEM 400 (Mobile)",   status: "Awaiting Quote",  color: "#0891B2", days: 5 },
      { id: "1189", client: "Yukon Mining Group",  radio: "SLR 5700 Repeater",  status: "In Repair",       color: "#7C3AED", days: 8 },
      { id: "1190", client: "Coast Security Ltd.", radio: "CP200d (Portable)",  status: "Ready for Pickup",color: "#059669", days: 1 },
      { id: "1191", client: "Granite Construction",radio: "SL 2600 (UHF)",      status: "Approved",        color: "#0B2545", days: 2 },
      { id: "1192", client: "Aurora Logistics",    radio: "XPR 7550e",          status: "Awaiting Parts",  color: "#DC2626", days: 12 },
    ];
    return (
      <div style={{ display: "flex", flexDirection: "column", gap: 16 }}>
        <div>
          <h1 style={{ margin: 0, fontSize: 26, fontWeight: 800, color: "#0B2545", letterSpacing: "-0.015em" }}>Technical Service · Tickets</h1>
          <p style={{ margin: "4px 0 0", color: "#64748b", fontSize: 13 }}>38 open tickets across 22 customers</p>
        </div>
        <div className="i-card" style={{ padding: 0, overflow: "hidden" }}>
          <div style={{ padding: "12px 16px", borderBottom: "1px solid #e6eaf0", display: "flex", justifyContent: "space-between", alignItems: "center" }}>
            <strong style={{ fontSize: 13 }}>Open service orders</strong>
            <div style={{ display: "flex", gap: 8 }}>
              <button style={iBtnSec}>Filter</button>
              <button style={iBtnPrim}>+ New OS</button>
            </div>
          </div>
          <table style={{ width: "100%", borderCollapse: "collapse", fontSize: 13 }}>
            <thead style={{ background: "#f7f8fa" }}>
              <tr style={{ color: "#6b7280", textAlign: "left" }}>
                <th style={iTh}>OS #</th>
                <th style={iTh}>Client</th>
                <th style={iTh}>Equipment</th>
                <th style={iTh}>Days</th>
                <th style={iTh}>Status</th>
                <th style={iTh}></th>
              </tr>
            </thead>
            <tbody>
              {tickets.map((t) => (
                <tr key={t.id} style={{ borderTop: "1px solid #e6eaf0" }}>
                  <td style={iTd}><span style={{ fontFamily: "JetBrains Mono, monospace", fontWeight: 600, color: "#0B2545" }}>OS-2026-{t.id}</span></td>
                  <td style={iTd}><span style={{ fontWeight: 500 }}>{t.client}</span></td>
                  <td style={{ ...iTd, color: "#4b5563" }}>{t.radio}</td>
                  <td style={iTd}><span style={{ color: t.days > 7 ? "#DC2626" : t.days > 3 ? "#D97706" : "#059669", fontWeight: 600 }}>{t.days}d</span></td>
                  <td style={iTd}>
                    <span style={{ background: t.color + "15", color: t.color, border: "1px solid " + t.color + "33", padding: "3px 9px", borderRadius: 999, fontSize: 11, fontWeight: 600 }}>● {t.status}</span>
                  </td>
                  <td style={{ ...iTd, textAlign: "right" }}><span style={{ color: "#1E5BA8", cursor: "pointer", fontSize: 12 }}>open ↗</span></td>
                </tr>
              ))}
            </tbody>
          </table>
        </div>
        <style>{`.i-card { background:#fff; border:1px solid #d7dde5; border-radius:4px; box-shadow:0 1px 2px rgba(16,24,40,.05); }`}</style>
      </div>
    );
  }

  function IntranetPlaceholder({ section }) {
    const labels = {
      hr: "Time Clock", rental: "Rentals", commercial: "Commercial",
      logistics: "Logistics", comms: "Suggestions", policies: "Policies",
      training: "Training", clients: "Client Database",
      users: "User Management", audit: "Audit Log", settings: "Settings",
    };
    return (
      <div className="i-card" style={{ padding: 36, textAlign: "center", background: "#fff", border: "1px solid #d7dde5", borderRadius: 4 }}>
        <div style={{ fontSize: 11, letterSpacing: "0.18em", textTransform: "uppercase", color: "#6b7280" }}>Demo · placeholder</div>
        <div style={{ fontFamily: "Inter, sans-serif", fontSize: 24, fontWeight: 700, color: "#0B2545", marginTop: 8 }}>
          {labels[section] || section}
        </div>
        <p style={{ color: "#4b5563", maxWidth: 520, margin: "10px auto 0", lineHeight: 1.6, fontSize: 14 }}>
          Fully wired in the real intranet (mobile-friendly forms, RBAC, kanban, CSV imports, real-time tracking).
          Demo focuses on Home + Technical Service to keep the preview snappy.
        </p>
      </div>
    );
  }

  function HeroCardI({ title, subtitle, icon, gradient, shadow, onClick }) {
    return (
      <button onClick={onClick} style={{
        background: gradient, color: "#fff", border: 0,
        borderRadius: 12, padding: "20px 22px",
        boxShadow: shadow,
        position: "relative", overflow: "hidden",
        display: "flex", alignItems: "center", gap: 16,
        cursor: "pointer", transition: "transform .2s ease",
        textAlign: "left", width: "100%",
        fontFamily: "Inter, sans-serif",
      }} onMouseEnter={(e) => e.currentTarget.style.transform = "translateY(-2px)"}
         onMouseLeave={(e) => e.currentTarget.style.transform = "translateY(0)"}>
        <div style={{ background: "rgba(255,255,255,0.18)", borderRadius: 10, padding: 12, display: "grid", placeItems: "center" }}>{icon}</div>
        <div style={{ flex: 1, minWidth: 0 }}>
          <div style={{ fontWeight: 700, fontSize: 18, letterSpacing: "-0.01em", color: "#fff" }}>{title}</div>
          <div style={{ fontSize: 12.5, opacity: 0.92, marginTop: 4, color: "#fff" }}>{subtitle}</div>
        </div>
        <div style={{ position: "absolute", right: -20, bottom: -20, width: 120, height: 120, borderRadius: "50%", background: "rgba(255,255,255,0.08)" }}></div>
      </button>
    );
  }

  const TASK_TAG = {
    at:         { label: "Service",    color: "#DC2626", bg: "#FEF2F2", border: "#FCA5A5" },
    rental:     { label: "Rental",     color: "#2563EB", bg: "#EFF6FF", border: "#BFDBFE" },
    logistics:  { label: "Logistics",  color: "#F97316", bg: "#FFF7ED", border: "#FED7AA" },
    commercial: { label: "Commercial", color: "#059669", bg: "#ECFDF5", border: "#6EE7B7" },
  };

  const iIconBtn = { background: "transparent", border: "none", cursor: "pointer", padding: 4, color: "#1f2937", display: "grid", placeItems: "center" };
  const iBtnPrim = { background: "#0B2545", color: "#fff", border: "none", borderRadius: 4, padding: "7px 14px", fontWeight: 600, fontSize: 12, cursor: "pointer", fontFamily: "Inter,sans-serif" };
  const iBtnSec  = { background: "#fff", color: "#4b5563", border: "1px solid #d7dde5", borderRadius: 4, padding: "7px 14px", fontWeight: 500, fontSize: 12, cursor: "pointer", fontFamily: "Inter,sans-serif" };
  const iTh = { padding: "10px 16px", fontSize: 11, fontWeight: 600, textTransform: "uppercase", letterSpacing: "0.04em" };
  const iTd = { padding: "12px 16px", color: "#1f2937" };

  /* ═══════════════════════════════════════════════════════════════════
     DEMO 2 · Branca Languages (faithful red + white + Branca image)
     ═══════════════════════════════════════════════════════════════════ */
  function DemoLanguageSchool() {
    const [step, setStep] = useState("login"); // login | lang | grammar | lesson
    const [activeMode, setActiveMode] = useState("revisao"); // revisao | celpip | entrevista
    const [nbTab, setNbTab] = useState("notes"); // notes | rules | cards | glossary
    const [nbColor, setNbColor] = useState("#1e3a5f");
    const [nbText, setNbText]   = useState("Simple Present — habits & routines.\nShe drinks coffee every morning.\nI work in tech support, I help users every day.\n\nTime markers: always, usually, often, sometimes, rarely, never.\nThey come between the subject and the verb.\n\nThird person singular adds -s in the affirmative,\nbut uses do/does in negatives & questions.\n");

    if (step === "login") {
      return (
        <div style={{ background: "#fff", color: "#1F2937", minHeight: 720, display: "flex", flexDirection: "column", alignItems: "center", justifyContent: "center", padding: 40, fontFamily: "Inter, system-ui, sans-serif" }}>
          <h1 style={{ fontSize: 56, fontWeight: 800, color: "#c0392b", letterSpacing: "-0.025em", margin: 0, lineHeight: 1 }}>Language School</h1>
          <p style={{ color: "#444", fontSize: 18, marginTop: 14 }}>Learn languages with someone who truly cares 🐾</p>

          <img src="/assets/branca.png" alt="Mascot" style={{ width: 280, height: 280, objectFit: "contain", margin: "20px 0" }} />

          <button onClick={() => setStep("lang")} style={{
            background: "#c0392b", color: "#fff", border: "none", borderRadius: 10,
            padding: "12px 44px", fontSize: 16, fontWeight: 600, cursor: "pointer",
            boxShadow: "0 4px 14px rgba(192,57,43,0.35)",
            transition: "all .15s ease",
          }} onMouseEnter={(e) => e.currentTarget.style.background = "#e74c3c"}
             onMouseLeave={(e) => e.currentTarget.style.background = "#c0392b"}>
            Demo Login
          </button>

          <p style={{ color: "#9e9e9e", fontSize: 12.5, marginTop: 24, textAlign: "center" }}>
            Language School · English · French · Spanish · Italian · Demo session — no real account needed
          </p>
        </div>
      );
    }

    if (step === "lang") {
      const langs = [
        { id: "en", flag: "🇨🇦", name: "English",  sub: "CELPIP · Mock Interview · Grammar", active: true },
        { id: "fr", flag: "🇫🇷", name: "Français", sub: "Coming soon", active: false },
        { id: "es", flag: "🇪🇸", name: "Español",  sub: "Coming soon", active: false },
        { id: "it", flag: "🇮🇹", name: "Italiano", sub: "Coming soon", active: false },
      ];
      return (
        <div style={{ background: "#f5f6f8", color: "#1f2937", minHeight: 720, padding: "60px 24px", fontFamily: "Inter, system-ui, sans-serif" }}>
          <div style={{ textAlign: "center", marginBottom: 36 }}>
            <h2 style={{ fontSize: 30, fontWeight: 800, color: "#1a1a1a", letterSpacing: "-0.02em", margin: 0 }}>Who's studying?</h2>
            <p style={{ color: "#9e9e9e", fontSize: 14, marginTop: 6 }}>Pick a language to keep separate notes &amp; progress</p>
          </div>
          <div style={{ maxWidth: 880, margin: "0 auto", display: "grid", gridTemplateColumns: "repeat(4, 1fr)", gap: 18 }}>
            {langs.map((L) => {
              const baseStyle = {
                borderRadius: 24,
                padding: "32px 18px 26px",
                textAlign: "center",
                display: "flex", flexDirection: "column", alignItems: "center", gap: 8,
                transition: "all .2s ease",
                position: "relative",
                overflow: "hidden",
              };
              if (L.active) {
                return (
                  <button key={L.id} onClick={() => { setStep("grammar"); setActiveMode("revisao"); }} style={{
                    ...baseStyle,
                    background: "linear-gradient(135deg, #0f4c81 0%, #0e7490 100%)",
                    border: "none", color: "#fff", cursor: "pointer",
                    boxShadow: "0 12px 32px rgba(15,76,129,0.25)",
                  }} onMouseEnter={(e) => { e.currentTarget.style.transform = "translateY(-4px)"; e.currentTarget.style.boxShadow = "0 18px 40px rgba(15,76,129,0.35)"; }}
                     onMouseLeave={(e) => { e.currentTarget.style.transform = "translateY(0)"; e.currentTarget.style.boxShadow = "0 12px 32px rgba(15,76,129,0.25)"; }}>
                    <div style={{ fontSize: 64, lineHeight: 1 }}>{L.flag}</div>
                    <div style={{ fontSize: 22, fontWeight: 800, letterSpacing: "-0.01em" }}>{L.name}</div>
                    <div style={{ fontSize: 11, color: "rgba(255,255,255,0.85)", lineHeight: 1.4 }}>{L.sub}</div>
                    <div style={{ marginTop: 6, fontSize: 11, fontWeight: 700, color: "#1a1a1a", background: "#fff", padding: "3px 10px", borderRadius: 999 }}>B1</div>
                  </button>
                );
              }
              return (
                <div key={L.id} style={{
                  ...baseStyle,
                  background: "linear-gradient(135deg, #e5e7eb 0%, #9ca3af 100%)",
                  border: "1px solid #d1d5db", color: "#6b7280",
                  cursor: "not-allowed", filter: "grayscale(1)",
                  opacity: 0.7,
                }}>
                  <div style={{ fontSize: 64, lineHeight: 1, filter: "grayscale(1)" }}>{L.flag}</div>
                  <div style={{ fontSize: 22, fontWeight: 800, letterSpacing: "-0.01em", color: "#374151" }}>{L.name}</div>
                  <div style={{ fontSize: 11, color: "#6b7280" }}>{L.sub}</div>
                  <span style={{ position: "absolute", top: 10, right: 10, fontSize: 10, fontWeight: 700, color: "#fff", background: "#374151", padding: "3px 8px", borderRadius: 999, letterSpacing: "0.06em" }}>SOON</span>
                </div>
              );
            })}
          </div>
          <p style={{ textAlign: "center", color: "#9ca3af", fontSize: 12, marginTop: 36 }}>
            Demo: only English is unlocked. Other languages are wired and waiting for content release.
          </p>
        </div>
      );
    }

    /* Grammar topic list — full Branca-style layout
       Modes: Grammar (revisao) | CELPIP | Interview
       Only the first topic per mode is clickable; rest are grayed (preview) */
    const TOPICS = {
      revisao: [
        { id: "simple-present",     title: "Simple Present",      subtitle: "Facts, habits & routines",         lvl: ["A1","A2","B1"], icon: "🌟", c: "#10B981" },
        { id: "present-continuous", title: "Present Continuous",  subtitle: "Actions happening right now",      lvl: ["A1","A2"], icon: "🎬", c: "#3B82F6" },
        { id: "simple-past",        title: "Simple Past",         subtitle: "Completed actions in the past",    lvl: ["A2","B1"], icon: "📜", c: "#8B5CF6" },
        { id: "past-continuous",    title: "Past Continuous",     subtitle: "Actions in progress in the past",  lvl: ["B1"],      icon: "⏪", c: "#EC4899" },
        { id: "future",             title: "Future Tenses",       subtitle: "Will, going to & present continuous", lvl: ["A2","B1"], icon: "🚀", c: "#F59E0B" },
        { id: "present-perfect",    title: "Present Perfect",     subtitle: "Past with present relevance",      lvl: ["B1","B2"], icon: "🔗", c: "#EF4444" },
        { id: "modal-verbs",        title: "Modal Verbs",         subtitle: "Can, should, must, might…",        lvl: ["B1","B2"], icon: "🔑", c: "#0891B2" },
        { id: "passive-voice",      title: "Passive Voice",       subtitle: "Focus on the action, not the actor", lvl: ["B2"],   icon: "🔄", c: "#7C3AED" },
        { id: "conditionals",       title: "Conditionals",        subtitle: "Real & hypothetical situations",   lvl: ["B1","B2"], icon: "🧠", c: "#F97316" },
        { id: "phrasal-verbs",      title: "Phrasal Verbs",       subtitle: "Common multi-word verbs",          lvl: ["B1","B2","C1"], icon: "🧩", c: "#0EA5E9" },
        { id: "reported-speech",    title: "Reported Speech",     subtitle: "Indirect speech with backshift",   lvl: ["B2","C1"], icon: "💬", c: "#84CC16" },
        { id: "advanced-register",  title: "Advanced Register",   subtitle: "Formal vs informal in context",    lvl: ["C1"],      icon: "🎓", c: "#6366F1" },
      ],
      celpip: [
        { id: "celpip-overview",    title: "CELPIP — Exam Overview", subtitle: "Format, scoring & strategy",   lvl: ["Test"], icon: "📋", c: "#0B2545" },
        { id: "celpip-reading",     title: "CELPIP Reading",        subtitle: "Skimming, scanning, distractors", lvl: ["Test"], icon: "📖", c: "#3B82F6" },
        { id: "celpip-listening",   title: "CELPIP Listening",      subtitle: "Audio strategy & note-taking",   lvl: ["Test"], icon: "🎧", c: "#8B5CF6" },
        { id: "celpip-speaking",    title: "CELPIP Speaking",       subtitle: "Fluency, pace and templates",    lvl: ["Test"], icon: "🎤", c: "#EF4444" },
        { id: "celpip-writing-email",  title: "CELPIP Writing · Email",  subtitle: "Email task structure",       lvl: ["Test"], icon: "✉️", c: "#F59E0B" },
        { id: "celpip-writing-survey", title: "CELPIP Writing · Survey", subtitle: "Opinion task structure",     lvl: ["Test"], icon: "📊", c: "#10B981" },
        { id: "celpip-vocabulary",  title: "CELPIP High-Yield Vocab", subtitle: "Topic clusters and synonyms",   lvl: ["Test"], icon: "📚", c: "#0891B2" },
        { id: "celpip-supertips",   title: "CELPIP Super-Tips",       subtitle: "Common pitfalls and shortcuts", lvl: ["Test"], icon: "💡", c: "#7C3AED" },
      ],
      entrevista: [
        { id: "iv-tellme",   title: "Tell Me About Yourself",     subtitle: "Opening pitch · 60 sec script",  lvl: ["IT","SLP","General"], icon: "👋", c: "#10B981" },
        { id: "iv-strength", title: "Strengths & Weaknesses",     subtitle: "STAR-method answers",            lvl: ["IT","SLP","General"], icon: "💪", c: "#3B82F6" },
        { id: "iv-conflict", title: "Conflict Resolution",        subtitle: "Difficult coworker scenarios",   lvl: ["IT","SLP","General"], icon: "⚖️", c: "#F59E0B" },
        { id: "iv-tech",     title: "Technical Deep-Dive",        subtitle: "Stack & system design",           lvl: ["IT"],          icon: "🛠", c: "#7C3AED" },
        { id: "iv-clinical", title: "Clinical Case Study",        subtitle: "Patient scenarios · SLP track",   lvl: ["SLP"],          icon: "🩺", c: "#EF4444" },
        { id: "iv-behavior", title: "Behavioral Questions",       subtitle: "STAR · 7 common patterns",        lvl: ["IT","SLP","General"], icon: "🧠", c: "#0891B2" },
        { id: "iv-money",    title: "Salary Negotiation",         subtitle: "Anchoring and counter-offers",    lvl: ["IT","SLP","General"], icon: "💰", c: "#84CC16" },
        { id: "iv-questions",title: "Smart Questions to Ask",     subtitle: "What to ask the interviewer",     lvl: ["IT","SLP","General"], icon: "❓", c: "#6366F1" },
      ],
    };

    const modeMeta = {
      revisao:    { label: "Grammar",    desc: "Lessons & paged exercises",   color: "#0f4c81", count: 38, complete: 12 },
      celpip:     { label: "CELPIP",     desc: "Official Canadian test prep",  color: "#c0392b", count: 8,  complete: 1  },
      entrevista: { label: "Interview",  desc: "Mock interview with AI coach", color: "#7C3AED", count: 8,  complete: 2  },
    };

    const list = TOPICS[activeMode];
    const meta = modeMeta[activeMode];

    if (step === "lesson") {
      const NB_TABS = [
        { id: "notes",     label: "Notes",       icon: "📝", count: 6 },
        { id: "rules",     label: "Rules",       icon: "📋", count: 1 },
        { id: "cards",     label: "Flashcards",  icon: "🃏", count: 12 },
        { id: "glossary",  label: "Glossary",    icon: "📖", count: 8 },
      ];
      return (
        <div style={{ background: "#f5f6f8", color: "#1F2937", minHeight: 720, fontFamily: "Inter, system-ui, sans-serif" }}>
          {/* Topbar */}
          <header style={{ background: "#0f4c81", color: "#fff", padding: "10px 22px", display: "flex", alignItems: "center", gap: 14 }}>
            <button onClick={() => setStep("grammar")} style={{ background: "rgba(255,255,255,0.12)", border: "1px solid rgba(255,255,255,0.25)", color: "#fff", padding: "5px 12px", borderRadius: 6, fontSize: 12, cursor: "pointer" }}>← all topics</button>
            <div style={{ display: "flex", alignItems: "center", gap: 10, fontSize: 13 }}>
              <span style={{ background: "#10B981", color: "#fff", padding: "3px 10px", borderRadius: 999, fontSize: 11, fontWeight: 700 }}>GRAMMAR</span>
              <strong style={{ fontSize: 14 }}>Simple Present</strong>
              <span style={{ opacity: 0.65, fontSize: 12 }}>· Facts, habits & routines</span>
            </div>
            <div style={{ marginLeft: "auto", display: "flex", gap: 8, fontSize: 12 }}>
              <span style={{ background: "rgba(255,255,255,0.18)", padding: "4px 10px", borderRadius: 999 }}>🔥 4-day streak</span>
              <span style={{ background: "#fff", color: "#0f4c81", padding: "4px 12px", borderRadius: 999, fontWeight: 800 }}>B1</span>
            </div>
          </header>

          {/* 2-column body — lesson + notebook */}
          <div style={{ display: "grid", gridTemplateColumns: "1.45fr 1fr", gap: 20, padding: "24px 24px 36px", maxWidth: 1280, margin: "0 auto" }}>

            {/* Lesson column */}
            <div style={{ display: "flex", flexDirection: "column", gap: 16 }}>
              {/* Hero */}
              <div style={{
                background: "linear-gradient(135deg,#10B981 0%,#059669 100%)", color: "#fff",
                borderRadius: 16, padding: "22px 24px",
                boxShadow: "0 10px 24px rgba(16,185,129,0.25)",
              }}>
                <span style={{ display: "inline-block", background: "rgba(255,255,255,0.2)", padding: "3px 10px", borderRadius: 999, fontSize: 10, fontWeight: 700, letterSpacing: "0.08em", textTransform: "uppercase" }}>Lesson 1 · Grammar</span>
                <h1 style={{ margin: "10px 0 4px", color: "#fff", fontSize: 30, fontWeight: 800, letterSpacing: "-0.02em" }}>Simple Present</h1>
                <p style={{ margin: 0, fontSize: 14, color: "rgba(255,255,255,0.92)", lineHeight: 1.5 }}>
                  Used for <strong>habits, routines, general truths and scheduled facts</strong>. The most common tense in everyday English.
                </p>
              </div>

              {/* When to use */}
              <div className="icard" style={{ padding: 20, background: "#fff", borderRadius: 14, border: "1px solid #e5e7eb" }}>
                <div style={{ fontSize: 12, color: "#10B981", fontWeight: 800, letterSpacing: "0.06em", textTransform: "uppercase" }}>When to use it</div>
                <ul style={{ margin: "10px 0 0", padding: "0 0 0 18px", fontSize: 14, lineHeight: 1.7, color: "#1f2937" }}>
                  <li>Daily habits — <em style={{ color: "#475569" }}>I take the train every morning.</em></li>
                  <li>Repeated actions — <em style={{ color: "#475569" }}>She works from home on Fridays.</em></li>
                  <li>General facts — <em style={{ color: "#475569" }}>Water boils at 100°C.</em></li>
                  <li>Schedules and timetables — <em style={{ color: "#475569" }}>The flight leaves at 6:40.</em></li>
                </ul>
              </div>

              {/* Conjugation table */}
              <div className="icard" style={{ padding: 20, background: "#fff", borderRadius: 14, border: "1px solid #e5e7eb" }}>
                <div style={{ fontSize: 12, color: "#0f4c81", fontWeight: 800, letterSpacing: "0.06em", textTransform: "uppercase", marginBottom: 12 }}>Conjugation — verb "to work"</div>
                <div style={{ display: "grid", gridTemplateColumns: "1fr 1fr 1fr", gap: 8, fontSize: 13 }}>
                  <div style={{ background: "#f0fdf4", padding: 10, borderRadius: 8, borderLeft: "3px solid #10B981" }}>
                    <div style={{ fontSize: 10, fontWeight: 800, color: "#059669", letterSpacing: "0.06em" }}>AFFIRMATIVE</div>
                    <div style={{ marginTop: 6, lineHeight: 1.7 }}>I <strong>work</strong><br/>You <strong>work</strong><br/>He / She <strong>works</strong><br/>We <strong>work</strong><br/>They <strong>work</strong></div>
                  </div>
                  <div style={{ background: "#fef2f2", padding: 10, borderRadius: 8, borderLeft: "3px solid #DC2626" }}>
                    <div style={{ fontSize: 10, fontWeight: 800, color: "#DC2626", letterSpacing: "0.06em" }}>NEGATIVE</div>
                    <div style={{ marginTop: 6, lineHeight: 1.7 }}>I <strong>don't work</strong><br/>You <strong>don't work</strong><br/>He / She <strong>doesn't work</strong><br/>We <strong>don't work</strong><br/>They <strong>don't work</strong></div>
                  </div>
                  <div style={{ background: "#eff6ff", padding: 10, borderRadius: 8, borderLeft: "3px solid #1d4ed8" }}>
                    <div style={{ fontSize: 10, fontWeight: 800, color: "#1d4ed8", letterSpacing: "0.06em" }}>QUESTION</div>
                    <div style={{ marginTop: 6, lineHeight: 1.7 }}><strong>Do</strong> I work?<br/><strong>Do</strong> you work?<br/><strong>Does</strong> he/she work?<br/><strong>Do</strong> we work?<br/><strong>Do</strong> they work?</div>
                  </div>
                </div>
                <div style={{ marginTop: 14, padding: "10px 12px", background: "#fffbeb", border: "1px solid #fde68a", borderRadius: 8, fontSize: 12.5, color: "#92400e" }}>
                  💡 <strong>Watch out:</strong> third-person singular always adds <code style={{ background: "#fff", padding: "1px 4px", borderRadius: 3 }}>-s</code> in the affirmative, but <code style={{ background: "#fff", padding: "1px 4px", borderRadius: 3 }}>does/doesn't</code> takes the -s in negatives and questions.
                </div>
              </div>

              {/* Time markers */}
              <div className="icard" style={{ padding: 20, background: "#fff", borderRadius: 14, border: "1px solid #e5e7eb" }}>
                <div style={{ fontSize: 12, color: "#7C3AED", fontWeight: 800, letterSpacing: "0.06em", textTransform: "uppercase", marginBottom: 10 }}>Common time markers</div>
                <div style={{ display: "flex", flexWrap: "wrap", gap: 6 }}>
                  {["always", "usually", "often", "sometimes", "rarely", "never", "every day", "on Mondays", "twice a week", "in the morning"].map((w) => (
                    <span key={w} style={{ background: "#f5f3ff", color: "#5b21b6", border: "1px solid #ddd6fe", padding: "4px 10px", borderRadius: 999, fontSize: 12, fontWeight: 600 }}>{w}</span>
                  ))}
                </div>
              </div>

              {/* Try it */}
              <div className="icard" style={{ padding: 20, background: "linear-gradient(180deg,#fff,#f5f3ff)", borderRadius: 14, border: "1px solid #ddd6fe" }}>
                <div style={{ display: "flex", justifyContent: "space-between", alignItems: "center", marginBottom: 10 }}>
                  <div style={{ fontSize: 12, color: "#5b21b6", fontWeight: 800, letterSpacing: "0.06em", textTransform: "uppercase" }}>Quick check</div>
                  <span style={{ fontSize: 11, color: "#94a3b8" }}>Exercise 1 of 8</span>
                </div>
                <p style={{ fontSize: 14, margin: "4px 0 12px" }}>Complete: <em>"She _______ (drink) coffee every morning."</em></p>
                <div style={{ display: "flex", gap: 8, flexWrap: "wrap" }}>
                  {["drink", "drinks", "is drinking", "drinked"].map((opt, i) => (
                    <button key={opt} style={{
                      padding: "8px 14px", fontSize: 13,
                      border: "1.5px solid " + (i === 1 ? "#10B981" : "#e5e7eb"),
                      background: i === 1 ? "#dcfce7" : "#fff",
                      color: i === 1 ? "#065f46" : "#1f2937",
                      borderRadius: 10, cursor: "pointer", fontWeight: 600,
                      fontFamily: "Inter, sans-serif",
                    }}>{opt} {i === 1 && "✓"}</button>
                  ))}
                </div>
              </div>

              {/* Exercises section — fictional listening + reading */}
              <div style={{ marginTop: 6, paddingTop: 14, borderTop: "2px dashed #e5e7eb" }}>
                <div style={{ display: "flex", alignItems: "center", justifyContent: "space-between", marginBottom: 14 }}>
                  <div>
                    <div style={{ fontSize: 12, color: "#0f4c81", fontWeight: 800, letterSpacing: "0.06em", textTransform: "uppercase" }}>Exercises</div>
                    <div style={{ fontSize: 13, color: "#64748b", marginTop: 2 }}>Practice with audio and a short reading. Demo content.</div>
                  </div>
                  <span style={{ fontSize: 11, color: "#94a3b8" }}>2 / 8 completed</span>
                </div>

                {/* Listening card */}
                <div className="icard" style={{ padding: 18, background: "#fff", borderRadius: 14, border: "1px solid #e5e7eb" }}>
                  <div style={{ display: "flex", alignItems: "center", gap: 10, marginBottom: 12 }}>
                    <span style={{ width: 32, height: 32, borderRadius: 10, background: "#e0f2fe", color: "#0369a1", display: "grid", placeItems: "center", fontSize: 16 }}>🎧</span>
                    <div style={{ flex: 1 }}>
                      <div style={{ fontWeight: 700, fontSize: 14 }}>Listening — Maya's Morning</div>
                      <div style={{ fontSize: 11, color: "#94a3b8" }}>0:38 · narrated · slow pace</div>
                    </div>
                    <button style={{
                      width: 38, height: 38, borderRadius: "50%",
                      background: "#0369a1", color: "#fff", border: 0, cursor: "pointer",
                      display: "grid", placeItems: "center", fontSize: 14,
                      boxShadow: "0 4px 10px rgba(3,105,161,0.3)",
                    }} title="Play (demo)">▶</button>
                  </div>
                  {/* Mock waveform */}
                  <div style={{ display: "flex", alignItems: "center", gap: 2, height: 32, padding: "4px 0" }}>
                    {Array.from({ length: 64 }, (_, i) => {
                      const h = 4 + ((i * 31) % 24);
                      const passed = i < 18;
                      return <span key={i} style={{ flex: 1, height: h, background: passed ? "#0369a1" : "#cbd5e1", borderRadius: 1 }}></span>;
                    })}
                  </div>
                  <div style={{ display: "flex", justifyContent: "space-between", fontSize: 10, color: "#94a3b8", fontFamily: "JetBrains Mono, monospace", marginTop: 4 }}>
                    <span>0:11</span><span>0:38</span>
                  </div>
                </div>

                {/* Reading card */}
                <div className="icard" style={{ padding: 18, background: "#fff", borderRadius: 14, border: "1px solid #e5e7eb", marginTop: 10 }}>
                  <div style={{ display: "flex", alignItems: "center", gap: 10, marginBottom: 10 }}>
                    <span style={{ width: 32, height: 32, borderRadius: 10, background: "#f0fdf4", color: "#059669", display: "grid", placeItems: "center", fontSize: 16 }}>📄</span>
                    <div style={{ flex: 1 }}>
                      <div style={{ fontWeight: 700, fontSize: 14 }}>Reading — Same scene, in writing</div>
                      <div style={{ fontSize: 11, color: "#94a3b8" }}>~ 60 words · A2–B1</div>
                    </div>
                  </div>
                  <p style={{ margin: 0, fontFamily: "Lora, Georgia, serif", fontSize: 14.5, lineHeight: 1.7, color: "#1f2937", background: "#fafaf9", padding: 14, borderRadius: 8, border: "1px dashed #e5e7eb" }}>
                    Maya lives in Vancouver. She wakes up at six o'clock every weekday. She drinks black coffee, reads the news for ten minutes and walks her dog around the block. She doesn't take the bus — she rides her bike to the office. On Fridays she works from home and finishes her week with a long video call.
                  </p>
                </div>

                {/* Questions */}
                <div className="icard" style={{ padding: 18, background: "#fff", borderRadius: 14, border: "1px solid #e5e7eb", marginTop: 10 }}>
                  <div style={{ fontSize: 12, color: "#7C3AED", fontWeight: 800, letterSpacing: "0.06em", textTransform: "uppercase", marginBottom: 12 }}>Comprehension · 4 questions</div>
                  {[
                    {
                      q: "1. What time does Maya wake up on weekdays?",
                      opts: ["At five o'clock", "At six o'clock", "At seven o'clock", "She doesn't say"],
                      correct: 1, src: "🎧 + 📄",
                    },
                    {
                      q: "2. How does she go to work?",
                      opts: ["She drives", "She takes the bus", "She rides her bike", "She walks"],
                      correct: 2, src: "📄",
                    },
                    {
                      q: "3. The verb \"drinks\" in the reading is in the…",
                      opts: ["Simple Present", "Present Continuous", "Simple Past", "Future"],
                      correct: 0, src: "grammar focus",
                    },
                    {
                      q: "4. What does Maya do on Fridays?",
                      opts: ["She goes to a meeting downtown", "She works from home", "She takes the day off", "She rides longer"],
                      correct: 1, src: "🎧 + 📄",
                    },
                  ].map((row, i) => (
                    <div key={i} style={{ marginBottom: i < 3 ? 14 : 0, paddingBottom: i < 3 ? 14 : 0, borderBottom: i < 3 ? "1px dashed #e5e7eb" : "none" }}>
                      <div style={{ display: "flex", justifyContent: "space-between", alignItems: "baseline", marginBottom: 8 }}>
                        <strong style={{ fontSize: 13.5 }}>{row.q}</strong>
                        <span style={{ fontSize: 10, color: "#94a3b8", fontFamily: "JetBrains Mono, monospace" }}>{row.src}</span>
                      </div>
                      <div style={{ display: "flex", gap: 6, flexWrap: "wrap" }}>
                        {row.opts.map((opt, j) => (
                          <button key={j} style={{
                            padding: "6px 12px", fontSize: 12,
                            border: "1.5px solid " + (j === row.correct ? "#10B981" : "#e5e7eb"),
                            background: j === row.correct ? "#dcfce7" : "#fff",
                            color: j === row.correct ? "#065f46" : "#475569",
                            borderRadius: 999, cursor: "pointer", fontWeight: 600,
                            fontFamily: "Inter, sans-serif",
                          }}>{opt} {j === row.correct && "✓"}</button>
                        ))}
                      </div>
                    </div>
                  ))}
                  <div style={{ marginTop: 14, padding: "10px 12px", background: "#fef3c7", borderRadius: 8, fontSize: 12, color: "#92400e", border: "1px solid #fde68a" }}>
                    💡 Tip — both the audio and the text describe a routine. Notice how every action uses Simple Present.
                  </div>
                </div>
              </div>
            </div>

            {/* Notebook column */}
            <div style={{
              background: "#fff", borderRadius: 14, border: "1px solid #e5e7eb",
              boxShadow: "0 6px 18px rgba(15,76,129,0.06)",
              display: "flex", flexDirection: "column",
              position: "sticky", top: 16, alignSelf: "flex-start",
              maxHeight: "calc(100vh - 100px)",
            }}>
              {/* Notebook header */}
              <div style={{ padding: "14px 16px", borderBottom: "1px solid #e8e8e8", background: "#f8f9fa", borderRadius: "14px 14px 0 0" }}>
                <div style={{ display: "flex", alignItems: "center", gap: 8, marginBottom: 10 }}>
                  <span style={{ fontSize: 18 }}>📓</span>
                  <strong style={{ fontSize: 14, color: "#1e3a5f" }}>My Notebook</strong>
                  <span style={{ marginLeft: "auto", fontSize: 10, color: "#94a3b8", letterSpacing: "0.06em" }}>SAVED · 2s ago</span>
                </div>
                <input
                  placeholder="Search across all your notes…"
                  style={{ width: "100%", fontSize: 12, padding: "7px 10px", border: "1px solid #e0e0e0", borderRadius: 8, fontFamily: "Inter, sans-serif", outline: "none" }}
                />
              </div>

              {/* Tabs */}
              <div style={{ display: "flex", borderBottom: "1px solid #e8e8e8", background: "#f8f9fa" }}>
                {NB_TABS.map((t) => {
                  const a = nbTab === t.id;
                  return (
                    <button key={t.id} onClick={() => setNbTab(t.id)} style={{
                      flex: 1, border: 0, padding: "10px 4px", cursor: "pointer",
                      background: "transparent", color: a ? "#1e3a5f" : "#9e9e9e",
                      fontWeight: a ? 700 : 500, fontSize: 11, position: "relative",
                      fontFamily: "Inter, sans-serif",
                      display: "flex", flexDirection: "column", alignItems: "center", gap: 2,
                    }}>
                      <span style={{ fontSize: 18 }}>{t.icon}</span>
                      <span>{t.label} <span style={{ fontSize: 10, color: a ? "#1e3a5f" : "#94a3b8" }}>· {t.count}</span></span>
                      {a && <span style={{ position: "absolute", bottom: 0, left: 16, right: 16, height: 2, background: "#1e3a5f", borderRadius: 2 }}></span>}
                    </button>
                  );
                })}
              </div>

              {/* Tab content */}
              <div style={{ padding: 14, flex: 1, overflow: "auto", maxHeight: 460 }}>
                {nbTab === "notes" && (
                  <div style={{ display: "flex", flexDirection: "column", gap: 10 }}>
                    {/* Topic header pill */}
                    <div style={{ display: "flex", alignItems: "center", gap: 6, fontSize: 11, color: "#10B981", fontWeight: 700, letterSpacing: "0.06em", textTransform: "uppercase" }}>
                      <span style={{ width: 6, height: 6, borderRadius: "50%", background: "#10B981" }}></span>
                      Topic · Simple Present
                    </div>
                    {/* Color picker */}
                    <div style={{ display: "flex", alignItems: "center", gap: 6, fontSize: 10, color: "#64748b" }}>
                      <span style={{ letterSpacing: "0.06em", textTransform: "uppercase", fontWeight: 700 }}>Color</span>
                      {[
                        { c: "#1e3a5f", n: "navy" },
                        { c: "#dc2626", n: "red" },
                        { c: "#059669", n: "green" },
                        { c: "#7c3aed", n: "purple" },
                        { c: "#d97706", n: "amber" },
                        { c: "#0f172a", n: "ink" },
                      ].map((p) => (
                        <button key={p.c} type="button" onClick={() => setNbColor(p.c)} title={p.n}
                          style={{
                            width: 18, height: 18, borderRadius: "50%",
                            background: p.c,
                            border: "2px solid " + (nbColor === p.c ? "#0f172a" : "#fff"),
                            boxShadow: "0 0 0 1px #cbd5e1",
                            cursor: "pointer", padding: 0,
                          }}></button>
                      ))}
                    </div>
                    {/* Lined paper notebook */}
                    <textarea
                      value={nbText}
                      onChange={(e) => setNbText(e.target.value)}
                      spellCheck={false}
                      style={{
                        width: "100%", minHeight: 320,
                        padding: "8px 14px 14px 42px",
                        background:
                          "repeating-linear-gradient(transparent 0px, transparent 23px, #c7d2fe 23px, #c7d2fe 24px)," +
                          "linear-gradient(to right, transparent 0, transparent 28px, #fca5a5 28px, #fca5a5 29px, transparent 29px)," +
                          "#fffef7",
                        backgroundAttachment: "local",
                        color: nbColor,
                        fontFamily: "'Caveat', 'Segoe Script', cursive",
                        fontSize: 18, lineHeight: "24px",
                        border: "1px solid #e5e7eb",
                        borderRadius: 6,
                        boxShadow: "inset 0 2px 4px rgba(0,0,0,0.04)",
                        resize: "vertical", outline: "none",
                      }}
                    />
                    <div style={{ fontSize: 10, color: "#94a3b8", textAlign: "right", fontStyle: "italic" }}>
                      Demo notepad · changes are not saved
                    </div>
                  </div>
                )}

                {nbTab === "rules" && (
                  <div style={{ display: "flex", flexDirection: "column", gap: 10 }}>
                    <div style={{ background: "#eff6ff", border: "1px solid #bfdbfe", borderRadius: 8, padding: 12 }}>
                      <div style={{ fontSize: 11, fontWeight: 800, color: "#1d4ed8", textTransform: "uppercase", letterSpacing: "0.06em" }}>Rule · Simple Present</div>
                      <div style={{ fontSize: 13, fontWeight: 700, marginTop: 4 }}>Add -s on the third person singular</div>
                      <div style={{ fontSize: 12, color: "#475569", marginTop: 6, lineHeight: 1.5 }}>
                        He / She / It → verb + s.<br/>
                        ‘play’ → ‘plays’, ‘watch’ → ‘watches’.<br/>
                        Doesn't apply to negatives or questions: those use <em>does</em>.
                      </div>
                      <div style={{ marginTop: 8, fontSize: 10, color: "#1d4ed8", fontWeight: 700 }}>Saved Apr 30 · auto-generated from your lesson</div>
                    </div>
                    <button style={{ background: "transparent", color: "#1e3a5f", border: "1px dashed #cbd5e1", borderRadius: 8, padding: "10px", fontSize: 12, cursor: "pointer", fontWeight: 600 }}>+ Add custom rule</button>
                  </div>
                )}

                {nbTab === "cards" && (
                  <div style={{ display: "flex", flexDirection: "column", gap: 10 }}>
                    <div style={{ fontSize: 11, color: "#94a3b8", textAlign: "center", letterSpacing: "0.06em" }}>3 DUE TODAY · spaced repetition</div>
                    <div style={{
                      background: "linear-gradient(135deg,#0f4c81,#0e7490)", color: "#fff",
                      borderRadius: 12, padding: "20px 16px", textAlign: "center",
                      boxShadow: "0 6px 14px rgba(15,76,129,0.25)",
                    }}>
                      <div style={{ fontSize: 11, color: "rgba(255,255,255,0.7)", letterSpacing: "0.08em" }}>FRONT · 1 / 12</div>
                      <div style={{ fontSize: 18, fontWeight: 800, marginTop: 8 }}>She ___ tea every morning.</div>
                      <button style={{ marginTop: 14, background: "#fff", color: "#0f4c81", border: 0, padding: "6px 16px", borderRadius: 999, fontSize: 12, cursor: "pointer", fontWeight: 700 }}>Flip ↻</button>
                    </div>
                    <div style={{ display: "flex", gap: 6 }}>
                      <button style={{ flex: 1, background: "#fef2f2", color: "#dc2626", border: "1px solid #fecaca", borderRadius: 8, padding: "8px", fontSize: 12, cursor: "pointer", fontWeight: 700 }}>Hard</button>
                      <button style={{ flex: 1, background: "#fffbeb", color: "#d97706", border: "1px solid #fde68a", borderRadius: 8, padding: "8px", fontSize: 12, cursor: "pointer", fontWeight: 700 }}>Medium</button>
                      <button style={{ flex: 1, background: "#f0fdf4", color: "#059669", border: "1px solid #bbf7d0", borderRadius: 8, padding: "8px", fontSize: 12, cursor: "pointer", fontWeight: 700 }}>Easy</button>
                    </div>
                  </div>
                )}

                {nbTab === "glossary" && (
                  <div style={{ display: "flex", flexDirection: "column", gap: 8 }}>
                    {[
                      { w: "routine",    pron: "/ruːˈtiːn/",    pt: "rotina",     ex: "I follow a strict morning routine." },
                      { w: "schedule",   pron: "/ˈskɛdʒuːl/",   pt: "agenda",     ex: "The flight is on schedule." },
                      { w: "habit",      pron: "/ˈhæbɪt/",      pt: "hábito",     ex: "Reading is a healthy habit." },
                      { w: "occur",      pron: "/əˈkɜːr/",      pt: "ocorrer",    ex: "Storms occur often in summer." },
                      { w: "nowadays",   pron: "/ˈnaʊədeɪz/",   pt: "hoje em dia", ex: "People work remotely nowadays." },
                    ].map((g, i) => (
                      <div key={i} style={{ background: "#f8fafc", border: "1px solid #e2e8f0", borderRadius: 8, padding: 10 }}>
                        <div style={{ display: "flex", justifyContent: "space-between", alignItems: "baseline" }}>
                          <strong style={{ fontSize: 13, color: "#0f4c81" }}>{g.w}</strong>
                          <span style={{ fontSize: 10, color: "#94a3b8", fontFamily: "JetBrains Mono" }}>{g.pron}</span>
                        </div>
                        <div style={{ fontSize: 11, color: "#7c3aed", fontWeight: 600, marginTop: 2 }}>PT — {g.pt}</div>
                        <div style={{ fontSize: 11, color: "#475569", marginTop: 4, fontStyle: "italic" }}>{g.ex}</div>
                      </div>
                    ))}
                  </div>
                )}
              </div>
            </div>
          </div>
        </div>
      );
    }

    return (
      <div style={{ background: "#f5f6f8", color: "#1F2937", minHeight: 720, padding: "0 0 48px", fontFamily: "Inter, system-ui, sans-serif" }}>
        {/* Topbar — navy like real Branca app */}
        <header style={{ background: "#0f4c81", color: "#fff", padding: "10px 22px", display: "flex", alignItems: "center", gap: 14 }}>
          <button onClick={() => setStep("lang")} style={{ background: "rgba(255,255,255,0.12)", border: "1px solid rgba(255,255,255,0.25)", color: "#fff", padding: "5px 12px", borderRadius: 6, fontSize: 12, cursor: "pointer" }}>← change language</button>
          <div style={{ display: "flex", alignItems: "center", gap: 10 }}>
            <div style={{ width: 30, height: 30, borderRadius: "50%", background: "linear-gradient(135deg,#0f4c81,#0e7490)", color: "#fff", display: "grid", placeItems: "center", fontWeight: 700, border: "2px solid #fff" }}>💻</div>
            <div style={{ lineHeight: 1.1 }}>
              <div style={{ fontWeight: 700, fontSize: 14 }}>Demo</div>
              <div style={{ fontSize: 11, opacity: 0.8 }}>IT Support · 🇧🇷 → 🇨🇦</div>
            </div>
          </div>
          <div style={{ marginLeft: "auto", display: "flex", alignItems: "center", gap: 10, fontSize: 12 }}>
            <span style={{ background: "rgba(255,255,255,0.18)", padding: "4px 10px", borderRadius: 999, display: "flex", alignItems: "center", gap: 6 }}><span>🔥</span>4 day streak</span>
            <span style={{ background: "#fff", color: "#0f4c81", padding: "4px 12px", borderRadius: 999, fontWeight: 800 }}>B1</span>
          </div>
        </header>

        {/* Content */}
        <div style={{ padding: "32px 24px", maxWidth: 1080, margin: "0 auto" }}>
          {/* Hello banner */}
          <div style={{ marginBottom: 24 }}>
            <h1 style={{ fontSize: 28, fontWeight: 800, color: "#1a1a1a", letterSpacing: "-0.02em", margin: 0 }}>Hello, Demo 👋</h1>
            <p style={{ color: "#9e9e9e", fontSize: 14, marginTop: 4 }}>Pick a track and a topic to start studying</p>
          </div>

          {/* Mode tabs */}
          <div style={{ display: "grid", gridTemplateColumns: "repeat(3, 1fr)", gap: 12, marginBottom: 28 }}>
            {Object.entries(modeMeta).map(([id, m]) => {
              const a = id === activeMode;
              return (
                <button key={id} onClick={() => setActiveMode(id)} style={{
                  background: a ? m.color : "#fff",
                  color: a ? "#fff" : "#1f2937",
                  border: "1px solid " + (a ? m.color : "#e5e7eb"),
                  borderRadius: 14, padding: "16px 18px", textAlign: "left",
                  cursor: "pointer", fontFamily: "Inter, sans-serif",
                  transition: "all .15s ease",
                  boxShadow: a ? "0 8px 18px rgba(0,0,0,0.12)" : "none",
                }}>
                  <div style={{ display: "flex", justifyContent: "space-between", alignItems: "baseline" }}>
                    <span style={{ fontSize: 18, fontWeight: 800, letterSpacing: "-0.01em" }}>{m.label}</span>
                    <span style={{ fontSize: 11, opacity: 0.85 }}>{m.complete}/{m.count}</span>
                  </div>
                  <div style={{ fontSize: 12, marginTop: 4, opacity: a ? 0.95 : 0.6 }}>{m.desc}</div>
                  <div style={{ marginTop: 10, height: 4, background: a ? "rgba(255,255,255,0.25)" : "#f3f4f6", borderRadius: 2, overflow: "hidden" }}>
                    <div style={{ height: "100%", width: (m.complete / m.count * 100) + "%", background: a ? "#fff" : m.color }}></div>
                  </div>
                </button>
              );
            })}
          </div>

          {/* Topic count summary */}
          <div style={{ display: "flex", justifyContent: "space-between", alignItems: "center", marginBottom: 14 }}>
            <div style={{ fontSize: 15, fontWeight: 700, color: meta.color }}>
              {meta.label} topics <span style={{ color: "#9ca3af", fontWeight: 400, fontSize: 13 }}>· {list.length} available · only the first topic is unlocked in this demo</span>
            </div>
            <span style={{ fontSize: 11, color: "#9ca3af", letterSpacing: "0.06em", textTransform: "uppercase" }}>Sort: recommended</span>
          </div>

          {/* Topic grid */}
          <div style={{ display: "grid", gridTemplateColumns: "repeat(auto-fill, minmax(260px, 1fr))", gap: 14 }}>
            {list.map((t, i) => {
              const unlocked = i === 0;
              if (unlocked) {
                return (
                  <button key={t.id} onClick={() => setStep("lesson")} style={{
                    background: "#fff",
                    border: "2px solid " + t.c,
                    borderRadius: 16, padding: 18,
                    textAlign: "left", cursor: "pointer",
                    fontFamily: "Inter, sans-serif",
                    boxShadow: "0 6px 16px rgba(0,0,0,0.06)",
                    transition: "all .15s ease",
                    position: "relative",
                  }} onMouseEnter={(e) => { e.currentTarget.style.transform = "translateY(-3px)"; e.currentTarget.style.boxShadow = "0 12px 24px rgba(0,0,0,0.12)"; }}
                     onMouseLeave={(e) => { e.currentTarget.style.transform = "translateY(0)"; e.currentTarget.style.boxShadow = "0 6px 16px rgba(0,0,0,0.06)"; }}>
                    <div style={{ display: "flex", alignItems: "flex-start", justifyContent: "space-between" }}>
                      <div style={{ background: t.c + "22", color: t.c, fontSize: 24, width: 44, height: 44, borderRadius: 12, display: "grid", placeItems: "center" }}>{t.icon}</div>
                      <span style={{ fontSize: 10, fontWeight: 800, color: "#fff", background: t.c, padding: "3px 9px", borderRadius: 999, letterSpacing: "0.06em" }}>UNLOCKED</span>
                    </div>
                    <div style={{ fontSize: 17, fontWeight: 800, marginTop: 12, letterSpacing: "-0.01em", color: "#111827" }}>{t.title}</div>
                    <div style={{ fontSize: 12.5, color: "#6b7280", marginTop: 4, lineHeight: 1.4 }}>{t.subtitle}</div>
                    <div style={{ display: "flex", gap: 4, flexWrap: "wrap", marginTop: 10 }}>
                      {t.lvl.map((L) => (
                        <span key={L} style={{ fontSize: 10, color: t.c, background: t.c + "12", border: "1px solid " + t.c + "44", padding: "2px 8px", borderRadius: 999, fontWeight: 700 }}>{L}</span>
                      ))}
                    </div>
                    <div style={{ marginTop: 12, paddingTop: 10, borderTop: "1px dashed #e5e7eb", fontSize: 12, color: t.c, fontWeight: 700, letterSpacing: "0.04em" }}>▶ Start lesson →</div>
                  </button>
                );
              }
              return (
                <div key={t.id} style={{
                  background: "#f9fafb",
                  border: "1px solid #e5e7eb",
                  borderRadius: 16, padding: 18,
                  cursor: "not-allowed",
                  filter: "grayscale(1)",
                  opacity: 0.65,
                  position: "relative",
                }}>
                  <div style={{ display: "flex", alignItems: "flex-start", justifyContent: "space-between" }}>
                    <div style={{ background: "#e5e7eb", color: "#6b7280", fontSize: 22, width: 44, height: 44, borderRadius: 12, display: "grid", placeItems: "center", filter: "grayscale(1)" }}>{t.icon}</div>
                    <span style={{ fontSize: 14 }}>🔒</span>
                  </div>
                  <div style={{ fontSize: 17, fontWeight: 700, marginTop: 12, color: "#374151" }}>{t.title}</div>
                  <div style={{ fontSize: 12.5, color: "#9ca3af", marginTop: 4, lineHeight: 1.4 }}>{t.subtitle}</div>
                  <div style={{ display: "flex", gap: 4, flexWrap: "wrap", marginTop: 10 }}>
                    {t.lvl.map((L) => (
                      <span key={L} style={{ fontSize: 10, color: "#6b7280", background: "#f3f4f6", border: "1px solid #d1d5db", padding: "2px 8px", borderRadius: 999, fontWeight: 700 }}>{L}</span>
                    ))}
                  </div>
                  <div style={{ marginTop: 12, paddingTop: 10, borderTop: "1px dashed #e5e7eb", fontSize: 11, color: "#9ca3af" }}>Locked in demo · available in production</div>
                </div>
              );
            })}
          </div>
        </div>
      </div>
    );
  }

  function brancaCard(bg1, bg2, accent) {
    return {
      background: `linear-gradient(135deg, ${bg1} 0%, ${bg2} 100%)`,
      border: "1px solid " + bg2,
      borderRadius: 18,
      padding: 24,
      boxShadow: "0 4px 14px rgba(0,0,0,0.04)",
    };
  }

  /* ═══════════════════════════════════════════════════════════════════
     DEMO 3 · Web E-Reader (faithful navy/beige + Lora)
     ═══════════════════════════════════════════════════════════════════ */
  function DemoEReader() {
    const [bookId, setBookId] = useState(null);
    const [pageIdx, setPageIdx] = useState(0);
    const [isPlaying, setIsPlaying] = useState(false);
    const [showTranslation, setShowTranslation] = useState(false);
    const [showWords, setShowWords] = useState(false);
    const [savedWords, setSavedWords] = useState([]);
    const [highlightWord, setHighlightWord] = useState(-1);
    const audioRef = useRef(null);
    const highlightTimerRef = useRef(null);

    const books = [
      {
        id: "divine", title: "The Divine Comedy", author: "Dante Alighieri",
        cover: "/assets/cover-divine.jpg",
        chapter: "Chapter 1",
        pages: [
          { en: "As he stepped into the city he barely knew, the traveler felt the silent weight of the empty streets. Lanterns along the canal cast small circles of warm yellow over the cobblestones, and he walked slowly, as one who measures each step before taking it.",
            pt: "Ao entrar na cidade que mal conhecia, o viajante sentiu o peso silencioso das ruas vazias. As lanternas ao longo do canal lançavam pequenos círculos de amarelo morno sobre o paralelepípedo, e ele caminhava devagar, como quem mede cada passo antes de o dar." },
          { en: "He carried no map, asked for no directions. He had been told the path would reveal itself, so long as he kept walking and did not stop to listen to the louder voices coming from the lit windows.",
            pt: "Não levava mapa, não pedia indicações. Tinham-lhe dito que o caminho se revelaria por si próprio, bastando que continuasse a andar e não parasse para ouvir as vozes mais altas que vinham das janelas iluminadas." },
          { en: "When the bells of a distant tower rang the half hour, he had already crossed three small bridges and a square where a single tree leaned over the water, as if listening to something on the other bank.",
            pt: "Quando os sinos de uma torre distante tocaram a meia hora, ele já tinha cruzado três pontes pequenas e uma praça onde uma única árvore se inclinava sobre a água, como se escutasse algo na outra margem." },
        ],
      },
      {
        id: "crime", title: "Crime and Punishment", author: "Fyodor Dostoevsky",
        cover: "/assets/cover-crime.jpg",
        chapter: "Chapter 1",
        pages: [
          { en: "A young man, thin and tired in the eyes, stepped out of the small room he rented under the roof and went down the narrow staircase, treading each step as if it might give way beneath his feet.",
            pt: "Um jovem, magro e cansado nos olhos, saiu do quartinho que alugava sob o telhado e desceu a escada estreita pisando cada degrau como se este pudesse ceder sob os seus pés." },
          { en: "He had not slept well for a week. The streets outside stirred with the rush of late afternoon, with carts and quick conversations that did not concern him, and yet he felt part of none of it.",
            pt: "Não dormia bem havia uma semana. As ruas lá fora movimentavam-se com a correria do fim da tarde, com carroças e conversas rápidas que não lhe interessavam, e, ainda assim, sentia-se parte de nada daquilo." },
          { en: "There was a small errand he had promised himself to attempt that day, and the closer he came to the bridge, the heavier the task seemed to him, until every step had to be justified, and every justification was lost.",
            pt: "Havia uma pequena diligência que tinha prometido a si mesmo tentar naquele dia, e quanto mais se aproximava da ponte, mais pesada lhe parecia a tarefa, até que cada passo tinha de ser justificado, e cada justificativa, perdida." },
        ],
      },
    ];

    const cleanWord = (raw) => (raw || "").replace(/[^A-Za-z'’-]+/g, "").toLowerCase();
    const addWord = (raw) => {
      const w = cleanWord(raw);
      if (!w) return;
      setSavedWords((prev) => prev.find((x) => x.word === w) ? prev : [...prev, { word: w, hint: "Tap to view meaning later." }]);
    };

    const clearHighlightTimer = () => {
      if (highlightTimerRef.current) {
        clearInterval(highlightTimerRef.current);
        highlightTimerRef.current = null;
      }
    };

    const stopAudio = () => {
      if (audioRef.current) {
        audioRef.current.onended = null;
        audioRef.current.pause();
        audioRef.current = null;
      }
      clearHighlightTimer();
      setHighlightWord(-1);
      setIsPlaying(false);
    };

    const startHighlight = (totalWords) => {
      clearHighlightTimer();
      setHighlightWord(0);
      let i = 0;
      highlightTimerRef.current = setInterval(() => {
        i += 1;
        if (i >= totalWords) {
          clearHighlightTimer();
          setHighlightWord(-1);
          setIsPlaying(false);
          if (audioRef.current) { audioRef.current.pause(); audioRef.current = null; }
          return;
        }
        setHighlightWord(i);
      }, 280);
    };

    const togglePlay = () => {
      if (isPlaying) { stopAudio(); return; }
      if (pageIdx === 0) return; // cover has no audio
      const bk = books.find((x) => x.id === bookId);
      const totalWords = bk ? bk.pages.reduce((acc, p) => acc + p.en.split(/\s+/).filter(Boolean).length, 0) : 0;
      try {
        const a = new Audio("/assets/audio/sample-" + ((pageIdx % 4) + 1) + ".mp3");
        audioRef.current = a;
        a.onended = () => { audioRef.current = null; };
        a.play().catch(() => {}); // best-effort; the highlight runs regardless
      } catch (e) {}
      setIsPlaying(true);
      startHighlight(totalWords);
    };

    const goPrev = () => { stopAudio(); setPageIdx((i) => Math.max(0, i - 1)); };
    const goNext = (total) => { stopAudio(); setPageIdx((i) => Math.min(total - 1, i + 1)); };

    /* ── Library view ── */
    if (!bookId) {
      return (
        <div style={{
          background: "#f5efe4", height: 580, maxHeight: 580,
          display: "flex", flexDirection: "column", overflow: "hidden",
          fontFamily: "Lora, Georgia, serif",
        }}>
          <header style={{
            background: "#1e3a5f", color: "#fff",
            padding: "16px 24px",
            display: "flex", alignItems: "center", gap: 14,
            boxShadow: "0 2px 8px rgba(0,0,0,0.15)",
          }}>
            <div style={{ fontFamily: "Lora, Georgia, serif", fontWeight: 700, fontSize: 20 }}>Library</div>
            <div style={{ marginLeft: "auto", color: "rgba(255,255,255,0.7)", fontSize: 12, fontStyle: "italic" }}>Demo</div>
          </header>
          <main style={{
            flex: 1, padding: "48px 24px",
            display: "flex", alignItems: "center", justifyContent: "center",
            gap: 32, flexWrap: "wrap",
          }}>
            {books.map((b) => (
              <article key={b.id} style={{
                background: "#fff", borderRadius: 12,
                border: "1px solid #ececec",
                width: 240, overflow: "hidden",
                boxShadow: "0 2px 10px rgba(0,0,0,0.06)",
                transition: "transform 200ms ease, box-shadow 200ms ease",
                display: "flex", flexDirection: "column",
              }} onMouseEnter={(e) => { e.currentTarget.style.transform = "translateY(-4px)"; e.currentTarget.style.boxShadow = "0 8px 24px rgba(0,0,0,0.12)"; }}
                 onMouseLeave={(e) => { e.currentTarget.style.transform = "translateY(0)"; e.currentTarget.style.boxShadow = "0 2px 10px rgba(0,0,0,0.06)"; }}>
                <div style={{ aspectRatio: "2 / 3", background: "#f5f1e6", overflow: "hidden" }}>
                  <img src={b.cover} alt={"Capa de " + b.title} style={{ width: "100%", height: "100%", objectFit: "cover", display: "block" }} />
                </div>
                <div style={{ padding: "14px 16px 16px", display: "flex", flexDirection: "column", gap: 8, flex: 1 }}>
                  <h3 style={{ fontFamily: "Lora, Georgia, serif", fontSize: 17, fontWeight: 700, margin: 0, lineHeight: 1.2, color: "#2a2a2a" }}>{b.title}</h3>
                  <p style={{ fontSize: 12.5, color: "#888", margin: 0 }}>{b.author}</p>
                  <button onClick={() => { setBookId(b.id); setPageIdx(0); setIsPlaying(false); }} style={{
                    marginTop: "auto", background: "#1e3a5f", color: "#fff",
                    border: "1px solid #1e3a5f", borderRadius: 999,
                    padding: "8px 14px", fontSize: 13, fontWeight: 600,
                    cursor: "pointer", textAlign: "center", fontFamily: "Inter, sans-serif",
                  }}>▶ Read chapter 1</button>
                </div>
              </article>
            ))}
          </main>
        </div>
      );
    }

    /* ── Reading view: paginated chapter 1 ── */
    const b = books.find((x) => x.id === bookId);
    // Page 0 = cover, pages 1..N = content paragraphs (joined into a single rich page)
    const total = 2;
    const atFirst = pageIdx <= 0;
    const atLast = pageIdx >= total - 1;
    const isCover = pageIdx === 0;

    const headerIconBtn = (active) => ({
      width: 34, height: 34, borderRadius: "50%",
      background: active ? "#fff" : "rgba(255,255,255,0.14)",
      color: active ? "#1e3a5f" : "#fff",
      border: active ? "none" : "1px solid rgba(255,255,255,0.35)",
      cursor: "pointer", display: "grid", placeItems: "center",
      fontFamily: "Inter, sans-serif", fontWeight: 700, fontSize: 14,
      transition: "background 160ms ease, color 160ms ease",
    });

    const renderTokens = (text, startWordIdx) => {
      const tokens = text.split(/(\s+)/);
      let wIdx = startWordIdx;
      return tokens.map((tok, i) => {
        if (/^\s+$/.test(tok)) return tok;
        const word = cleanWord(tok);
        if (!word) return tok;
        const myIdx = wIdx;
        wIdx += 1;
        const isSaved = savedWords.some((x) => x.word === word);
        const isHL = isPlaying && highlightWord === myIdx;
        const wasHL = isPlaying && highlightWord > myIdx && highlightWord !== -1;
        let bg = "transparent";
        if (isHL) bg = "#ffe566";
        else if (wasHL) bg = "rgba(255,229,102,0.35)";
        else if (isSaved) bg = "rgba(200,155,60,0.12)";
        return (
          <span
            key={i}
            onClick={() => addWord(tok)}
            style={{
              cursor: "pointer",
              borderBottom: isSaved ? "2px solid #c89b3c" : "1px dashed transparent",
              background: bg,
              boxShadow: isHL ? "0 0 0 2px #ffe566" : "none",
              borderRadius: 3, padding: "0 1px",
              transition: "background 180ms ease, box-shadow 180ms ease",
            }}
            onMouseEnter={(e) => { if (!isSaved && !isHL && !wasHL) e.currentTarget.style.background = "rgba(30,58,95,0.08)"; }}
            onMouseLeave={(e) => { if (!isSaved && !isHL && !wasHL) e.currentTarget.style.background = "transparent"; }}
          >
            {tok}
          </span>
        );
      });
    };

    return (
      <div style={{
        background: "#f5efe4", color: "#1f2a3a",
        height: 580, maxHeight: 580,
        display: "flex", flexDirection: "column", overflow: "hidden",
        fontFamily: "Lora, Georgia, serif",
      }}>
        {/* Navy header */}
        <header style={{
          background: "#1e3a5f", color: "#fff",
          padding: "14px 22px",
          display: "flex", alignItems: "center", gap: 12,
          boxShadow: "0 2px 8px rgba(0,0,0,0.15)",
        }}>
          <button onClick={() => { stopAudio(); setBookId(null); setShowTranslation(false); setShowWords(false); }} title="Back to library"
            style={{ background: "transparent", border: "none", color: "#fff", cursor: "pointer", padding: 6, display: "grid", placeItems: "center" }}>
            <svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.5" strokeLinecap="round" strokeLinejoin="round"><line x1="19" y1="12" x2="5" y2="12"/><polyline points="12 19 5 12 12 5"/></svg>
          </button>
          <div style={{ flex: 1, textAlign: "center", lineHeight: 1.15 }}>
            <div style={{ fontFamily: "Lora, Georgia, serif", fontWeight: 700, fontSize: 17 }}>{b.title}</div>
            <div style={{ fontSize: 12, fontStyle: "italic", color: "rgba(255,255,255,0.78)" }}>{b.author}</div>
          </div>
          <button onClick={() => setShowTranslation((v) => !v)} title={showTranslation ? "Hide PT subtitle" : "Show PT subtitle"} style={headerIconBtn(showTranslation)}>
            <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><circle cx="12" cy="12" r="9"/><path d="M3 12h18"/><path d="M12 3a14 14 0 0 1 0 18"/><path d="M12 3a14 14 0 0 0 0 18"/></svg>
          </button>
          <button onClick={() => setShowWords((v) => !v)} title={showWords ? "Hide saved words" : "Show saved words"} style={headerIconBtn(showWords)}>
            W{savedWords.length > 0 && <sup style={{ marginLeft: 1, fontSize: 9, fontWeight: 700 }}>{savedWords.length}</sup>}
          </button>
        </header>

        {/* Reading body */}
        <main style={{ flex: 1, overflow: "auto", maxWidth: 720, width: "100%", margin: "0 auto", padding: "1.6rem 2rem 1.4rem", boxSizing: "border-box" }}>
          {isCover ? (
            <div style={{ display: "flex", flexDirection: "column", alignItems: "center", justifyContent: "center", height: "100%", textAlign: "center", padding: "0.6rem 0" }}>
              <div style={{ width: 150, aspectRatio: "2 / 3", borderRadius: 8, overflow: "hidden", boxShadow: "0 12px 32px rgba(0,0,0,0.2)", marginBottom: 18 }}>
                <img src={b.cover} alt={"Cover of " + b.title} style={{ width: "100%", height: "100%", objectFit: "cover", display: "block" }} />
              </div>
              <h2 style={{ fontFamily: "Lora, Georgia, serif", fontSize: 22, fontWeight: 700, margin: "0 0 4px", color: "#1f2a3a" }}>{b.title}</h2>
              <div style={{ fontSize: 13, fontStyle: "italic", color: "#6b5f4a", marginBottom: 12 }}>{b.author}</div>
              <div style={{ fontSize: 11, letterSpacing: "0.32em", textTransform: "uppercase", color: "#9a8966" }}>{b.chapter}</div>
            </div>
          ) : (
            <>
              <div style={{ fontSize: 11, letterSpacing: "0.32em", textTransform: "uppercase", color: "#9a8966", textAlign: "center", marginBottom: 18 }}>
                {b.chapter}
              </div>
              {(() => {
                let offset = 0;
                return b.pages.map((p, idx) => {
                  const start = offset;
                  offset += p.en.split(/\s+/).filter(Boolean).length;
                  return (
                    <div key={idx} style={{ marginBottom: "1.4rem" }}>
                      <p style={{
                        fontFamily: "Lora, Georgia, serif", fontSize: 19, lineHeight: 1.85, color: "#1f2a3a",
                        margin: 0, textAlign: "justify", textIndent: "1.4em",
                      }}>
                        {renderTokens(p.en, start)}
                      </p>
                      {showTranslation && (
                        <p style={{
                          fontFamily: "Inter, sans-serif", fontSize: 13.5, lineHeight: 1.55,
                          color: "#7a6a3f", margin: "6px 0 0", paddingLeft: "1.4em",
                          fontStyle: "italic", borderLeft: "2px solid #e9d8a6",
                        }}>
                          {p.pt}
                        </p>
                      )}
                    </div>
                  );
                });
              })()}
            </>
          )}

          {/* Words panel (collapsible) */}
          {showWords && (
            <div style={{
              marginTop: 18, padding: "12px 14px",
              background: "#fffaf0", border: "1px solid #e6dcc6",
              borderRadius: 8, fontFamily: "Inter, sans-serif",
              fontSize: 13, lineHeight: 1.55, color: "#3a2f14",
            }}>
              <div style={{ display: "flex", alignItems: "center", justifyContent: "space-between", marginBottom: 8 }}>
                <div style={{ fontSize: 10, letterSpacing: "0.2em", textTransform: "uppercase", color: "#9a8966" }}>Words ({savedWords.length})</div>
                {savedWords.length > 0 && (
                  <button onClick={() => setSavedWords([])} style={{ background: "transparent", border: "none", color: "#9a8966", fontSize: 11, cursor: "pointer", textDecoration: "underline" }}>Clear</button>
                )}
              </div>
              {savedWords.length === 0 ? (
                <div style={{ color: "#9a8966", fontStyle: "italic" }}>Click any word in the text to save it here.</div>
              ) : (
                <div style={{ display: "flex", flexWrap: "wrap", gap: 6 }}>
                  {savedWords.map((w) => (
                    <span key={w.word} title={w.hint} style={{
                      background: "#fff", border: "1px solid #d9caa3",
                      borderRadius: 999, padding: "3px 10px", fontSize: 12, color: "#3a2f14",
                    }}>{w.word}</span>
                  ))}
                </div>
              )}
            </div>
          )}
        </main>

        {/* Navy footer: prev / play / next + counter + notice */}
        <div style={{
          background: "#1e3a5f", color: "#fff",
          padding: "12px 22px 10px",
          display: "flex", flexDirection: "column", gap: 6, alignItems: "center",
          boxShadow: "0 -4px 16px rgba(0,0,0,0.18)",
        }}>
          <div style={{ display: "flex", alignItems: "center", gap: 14 }}>
            <button onClick={goPrev} disabled={atFirst} title="Previous page" style={{
              width: 40, height: 40, borderRadius: "50%",
              background: atFirst ? "rgba(255,255,255,0.15)" : "rgba(255,255,255,0.92)",
              color: atFirst ? "rgba(255,255,255,0.5)" : "#1e3a5f",
              border: "none", cursor: atFirst ? "default" : "pointer",
              display: "grid", placeItems: "center",
            }}>
              <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.5" strokeLinecap="round" strokeLinejoin="round"><polyline points="15 18 9 12 15 6"/></svg>
            </button>
            <button onClick={togglePlay} title={isPlaying ? "Stop" : "Play page"} style={{
              width: 52, height: 52, borderRadius: "50%",
              background: "#fff", color: "#1e3a5f", border: "none",
              cursor: "pointer", display: "grid", placeItems: "center",
              boxShadow: "0 4px 14px rgba(0,0,0,0.25)",
            }}>
              {isPlaying
                ? <svg width="20" height="20" viewBox="0 0 24 24" fill="currentColor"><rect x="6" y="5" width="4" height="14"/><rect x="14" y="5" width="4" height="14"/></svg>
                : <svg width="22" height="22" viewBox="0 0 24 24" fill="currentColor"><path d="M8 5v14l11-7z"/></svg>}
            </button>
            <button onClick={() => goNext(total)} disabled={atLast} title="Next page" style={{
              width: 40, height: 40, borderRadius: "50%",
              background: atLast ? "rgba(255,255,255,0.15)" : "rgba(255,255,255,0.92)",
              color: atLast ? "rgba(255,255,255,0.5)" : "#1e3a5f",
              border: "none", cursor: atLast ? "default" : "pointer",
              display: "grid", placeItems: "center",
            }}>
              <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.5" strokeLinecap="round" strokeLinejoin="round"><polyline points="9 18 15 12 9 6"/></svg>
            </button>
            <div style={{ fontFamily: "Inter, sans-serif", fontSize: 12, color: "rgba(255,255,255,0.85)", minWidth: 64, textAlign: "center" }}>
              {isCover ? "Cover" : "Page " + pageIdx} / {total - 1}
            </div>
          </div>
          <div style={{ fontSize: 11.5, color: "#ff6b6b", letterSpacing: "0.04em", fontFamily: "Inter, sans-serif", textAlign: "center", fontStyle: "italic", fontWeight: 600 }}>
            This is an example. I used this technique in a real project.
          </div>
        </div>
      </div>
    );
  }

  function readerRoot(theme) {
    return {
      background: theme === "night" ? "#14181d" : "#f5efe4",
      color: theme === "night" ? "#e5e0d6" : "#2a2a2a",
      minHeight: 720, height: "100%", position: "relative",
      fontFamily: "Lora, Georgia, serif",
      display: "flex", flexDirection: "column",
    };
  }
  const readerNavyBar = {
    background: "#1e3a5f", color: "#fff",
    padding: "0.6rem 1.2rem",
    display: "flex", alignItems: "center", gap: 12,
    boxShadow: "0 2px 8px rgba(0,0,0,0.15)",
    position: "sticky", top: 0, zIndex: 5,
  };
  const readerNavyBtn = {
    width: 40, height: 40, color: "#fff",
    background: "transparent", border: "none",
    borderRadius: 8, cursor: "pointer",
    display: "grid", placeItems: "center",
    transition: "background 150ms ease",
  };
  function readerSelectNavy(active) {
    return {
      background: active ? "#fff" : "rgba(255,255,255,0.1)",
      color: active ? "#1e3a5f" : "#fff",
      border: "1px solid rgba(255,255,255,0.25)",
      borderRadius: 999, padding: "5px 12px",
      fontSize: 12, cursor: "pointer", fontFamily: "Inter, system-ui",
    };
  }
  function readerNavArrow(disabled) {
    return {
      background: "transparent", border: "none",
      color: disabled ? "rgba(255,255,255,0.3)" : "#fff",
      cursor: disabled ? "default" : "pointer",
      display: "grid", placeItems: "center",
      padding: 4,
    };
  }
  const readerVocabBtn = {
    appearance: "none",
    border: "1px solid #ececec",
    background: "#fff", color: "#2a2a2a",
    fontFamily: "system-ui, sans-serif", fontSize: 12,
    padding: "5px 12px", borderRadius: 999, cursor: "pointer",
  };

  /* ═══════════════════════════════════════════════════════════════════
     DEMO 4 · Live Transcribe (refined dark UI with waveform)
     ═══════════════════════════════════════════════════════════════════ */
  function DemoLiveTranscribe() {
    /* Progressive chat-style transcription. Sentences appear one by one, each
       paired EN+PT. After 5 sentences, the Idea button auto-clicks and a panel
       slides in from the right showing Question → Suggested Answer → Follow-up →
       Explanation in chat-bubble harmony. */
    const segments = [
      { en: "Thanks for joining us today, Paulo.",                                                                  pt: "Obrigado por se juntar a nós hoje, Paulo.",                                                              ts: "00:01", spk: "Interviewer" },
      { en: "Could you walk me through how you'd design identity governance for a multi-tenant Azure environment?", pt: "Você poderia me explicar como projetaria governança de identidade num ambiente Azure multi-tenant?",     ts: "00:04", spk: "Interviewer" },
      { en: "Sure. I'd start by aligning tenants under one Entra ID hierarchy with PIM for privileged roles.",      pt: "Claro. Começaria alinhando os tenants sob uma hierarquia única do Entra ID com PIM nos papéis privilegiados.", ts: "00:14", spk: "You" },
      { en: "Then layer Conditional Access on top, tied to device compliance from Intune.",                          pt: "Depois colocaria Conditional Access acima, vinculado à conformidade de dispositivos do Intune.",        ts: "00:22", spk: "You" },
      { en: "What about cross-tenant collaboration after an acquisition?",                                           pt: "E quanto à colaboração entre tenants depois de uma aquisição?",                                          ts: "00:33", spk: "Interviewer" },
      { en: "Cross-tenant access settings plus entitlement management with quarterly access reviews.",               pt: "Configurações de acesso entre tenants mais entitlement management com revisões trimestrais de acesso.", ts: "00:42", spk: "You" },
      { en: "Got it. How would you measure success in the first six months?",                                        pt: "Entendi. Como você mediria sucesso nos primeiros seis meses?",                                           ts: "00:54", spk: "Interviewer" },
      { en: "Three KPIs: median PIM expiration time, zero standing admin access, and 100% compliant sign-ins.",      pt: "Três KPIs: tempo mediano de expiração do PIM, zero acesso administrativo permanente e 100% de logins conformes.", ts: "01:04", spk: "You" },
    ];

    const ideaQA = {
      q: "How would you measure success of this identity governance design over the first 6 months?",
      a: "Anchor on three measurable outcomes: (1) median time to remove a privileged role under 24h via PIM expiration policies, (2) zero standing admin access — verified via weekly access reviews, (3) 100% of conditional-access-enforced sign-ins from compliant devices, tracked in a KQL dashboard fed by SigninLogs.",
      followUp: "What KQL query would you run on day one to baseline standing privileged access?",
      explain:  "The interviewer is checking whether you treat governance as a measurable program (not a one-off setup). Frame your answer around metrics that can be charted weekly, and tie each metric to a concrete control already in your design.",
    };

    const [revealed, setRevealed] = useState(0);
    const [ideaOpen, setIdeaOpen] = useState(false);
    const [autoTriggered, setAutoTriggered] = useState(false);
    const [ideaStage, setIdeaStage] = useState(0); // 0..3 progressively reveals Q/A/Follow/Explain
    const [pulse, setPulse] = useState(true);
    const [tick, setTick] = useState(0);
    const [btnFlash, setBtnFlash] = useState(false);
    const transcriptRef = useRef(null);
    const ptRef = useRef(null);

    /* Reveal one segment every ~1.6s */
    useEffect(() => {
      if (revealed >= segments.length) return;
      const t = setTimeout(() => setRevealed((r) => r + 1), revealed === 0 ? 600 : 1700);
      return () => clearTimeout(t);
    }, [revealed]);

    /* Auto-scroll both panes after each segment renders. Using rAF (twice)
       so we run *after* the DOM commits — scrollHeight is otherwise stale. */
    useEffect(() => {
      let raf2 = 0;
      const raf1 = requestAnimationFrame(() => {
        raf2 = requestAnimationFrame(() => {
          [transcriptRef.current, ptRef.current].forEach((el) => {
            if (el) el.scrollTo({ top: el.scrollHeight, behavior: "smooth" });
          });
        });
      });
      return () => { cancelAnimationFrame(raf1); cancelAnimationFrame(raf2); };
    }, [revealed]);

    /* After 5 segments revealed, flash the Idea button to invite the user to click.
       Do NOT auto-open — the user must click it themselves. */
    useEffect(() => {
      if (revealed >= 5 && !autoTriggered) {
        setAutoTriggered(true);
        setBtnFlash(true);
        setTimeout(() => setBtnFlash(false), 1400);
      }
    }, [revealed, autoTriggered]);

    /* Once idea panel is open, progressively populate the 4 stages */
    useEffect(() => {
      if (!ideaOpen) { setIdeaStage(0); return; }
      if (ideaStage >= 4) return;
      const t = setTimeout(() => setIdeaStage((s) => s + 1), ideaStage === 0 ? 350 : 900);
      return () => clearTimeout(t);
    }, [ideaOpen, ideaStage]);

    /* Idea button gentle pulse */
    useEffect(() => {
      const a = setInterval(() => setPulse((p) => !p), 1100);
      const b = setInterval(() => setTick((t) => t + 1), 80);
      return () => { clearInterval(a); clearInterval(b); };
    }, []);

    const speakerColor = (spk) => spk === "You" ? "#38bdf8" : "#cbd5e1";
    const visibleSegs = segments.slice(0, revealed);

    return (
      <div style={{ background: "#0F172A", color: "#E2E8F0", height: 580, maxHeight: 580, padding: "14px 18px", fontFamily: "Inter, system-ui, sans-serif", display: "flex", flexDirection: "column", gap: 10, position: "relative", overflow: "hidden" }}>
        {/* Top bar */}
        <header style={{ display: "flex", alignItems: "center", gap: 18, paddingBottom: 12, borderBottom: "1px solid #1e293b", flexWrap: "wrap" }}>
          <div style={{ display: "flex", alignItems: "center", gap: 10 }}>
            <span style={{ width: 10, height: 10, background: "#ef4444", borderRadius: "50%", animation: "rec 1.2s infinite" }}></span>
            <span style={{ fontSize: 13, color: "#94a3b8", letterSpacing: "0.08em" }}>RECORDING · 01:24</span>
          </div>
          <div style={{ width: 1, height: 22, background: "#1e293b" }}></div>
          <div style={{ fontFamily: "Space Grotesk, sans-serif", fontSize: 22, fontWeight: 700, letterSpacing: "-0.01em" }}>Live Transcribe <span style={{ color: "#94a3b8", fontWeight: 500, fontSize: 18 }}>Simulation</span></div>
          <div style={{ marginLeft: "auto", display: "flex", gap: 8, fontSize: 11, color: "#64748b" }}>
            <span style={{ padding: "4px 10px", border: "1px solid #1e293b", borderRadius: 999 }}>EN-US · 99% confidence</span>
            <span style={{ padding: "4px 10px", border: "1px solid #1e293b", borderRadius: 999 }}>auto-save 5s</span>
          </div>
          {/* Idea button — pulses; user must click to open the AI Coach */}
          <div style={{ position: "relative" }}>
            {!ideaOpen && revealed >= 5 && (
              <div style={{
                position: "absolute", top: "calc(100% + 10px)", right: 0,
                background: "#fbbf24", color: "#1f2937",
                padding: "8px 12px", borderRadius: 10,
                fontSize: 12, fontWeight: 700, whiteSpace: "nowrap",
                boxShadow: "0 6px 18px rgba(251,191,36,0.35)",
                animation: "rec 1.6s infinite",
                zIndex: 5,
              }}>
                <span style={{
                  position: "absolute", top: -6, right: 22,
                  width: 12, height: 12, background: "#fbbf24",
                  transform: "rotate(45deg)",
                }}></span>
                👆 Click <strong>Idea</strong> to open the AI Coach
              </div>
            )}
            <button onClick={() => { setIdeaOpen((o) => !o); }} style={{
              background: btnFlash ? "#facc15" : (pulse ? "#fbbf24" : "#f59e0b"),
              color: "#1f2937", border: "none",
              padding: "8px 18px", borderRadius: 999,
              fontSize: 12, fontWeight: 800, letterSpacing: "0.08em", textTransform: "uppercase",
              cursor: "pointer", display: "flex", alignItems: "center", gap: 8,
              boxShadow: btnFlash ? "0 0 0 12px rgba(250,204,21,0.45)" : (pulse ? "0 0 0 6px rgba(251,191,36,0.25)" : "0 0 0 2px rgba(251,191,36,0.15)"),
              transform: btnFlash ? "scale(1.06)" : "scale(1)",
              transition: "all .35s ease",
            }}>💡 Idea {ideaOpen ? "◀" : "▶"}</button>
          </div>
        </header>

        {/* Waveform strip */}
        <div style={{ display: "flex", gap: 3, alignItems: "center", height: 22, justifyContent: "center", padding: "4px 0" }}>
          {Array.from({ length: 60 }, (_, i) => {
            const h = 3 + Math.abs(Math.sin((tick + i * 2) * 0.35)) * 18;
            return <span key={i} style={{ width: 2, height: h, background: "#38bdf8", borderRadius: 1, opacity: 0.55 + (h / 30) }}></span>;
          })}
        </div>

        {/* Body — full-width chat by default; splits 50/50 when Idea is open */}
        <div style={{
          flex: 1, display: "grid",
          gridTemplateColumns: ideaOpen ? "1fr 1fr" : "1fr",
          gap: 14, minHeight: 0,
          transition: "grid-template-columns .35s ease",
        }}>
          {/* Stacked transcript panes (EN top, PT bottom) */}
          <div style={{ display: "grid", gridTemplateRows: "1fr 1fr", gap: 12, minHeight: 0 }}>
            {/* English */}
            <div style={transcribePanel}>
              <div style={transcribeHead}>
                <span style={{ background: "rgba(56,189,248,0.18)", color: "#38bdf8", width: 26, height: 26, borderRadius: 6, display: "grid", placeItems: "center" }}>EN</span>
                <span>English · live</span>
                <span style={{ marginLeft: "auto", fontSize: 11, color: "#64748b" }}>{revealed} / {segments.length} segments</span>
              </div>
              <div ref={transcriptRef} style={{ display: "flex", flexDirection: "column", gap: 10, padding: 16, overflowY: "auto", flex: 1, fontSize: 14, lineHeight: 1.55, scrollBehavior: "smooth" }}>
                {visibleSegs.map((s, i) => {
                  const isYou = s.spk === "You";
                  return (
                    <div key={i} style={{
                      alignSelf: isYou ? "flex-end" : "flex-start",
                      maxWidth: "82%",
                      animation: "msgIn .35s ease both",
                    }}>
                      <div style={{ fontSize: 10, color: "#64748b", marginBottom: 3, fontFamily: "JetBrains Mono, monospace", textAlign: isYou ? "right" : "left" }}>
                        <span style={{ color: speakerColor(s.spk), fontWeight: 700 }}>{isYou ? "You" : "Interviewer"}</span> · {s.ts}
                      </div>
                      <div style={{
                        background: isYou ? "linear-gradient(135deg,#0ea5e9,#0369a1)" : "#1e293b",
                        color: isYou ? "#f0f9ff" : "#e2e8f0",
                        padding: "9px 13px",
                        borderRadius: isYou ? "14px 14px 4px 14px" : "14px 14px 14px 4px",
                        boxShadow: "0 2px 6px rgba(0,0,0,0.18)",
                      }}>{s.en}</div>
                    </div>
                  );
                })}
                {revealed < segments.length && (
                  <div style={{ fontSize: 12, color: "#64748b", fontStyle: "italic", display: "flex", alignItems: "center", gap: 6, alignSelf: "flex-start" }}>
                    <span style={{ width: 6, height: 6, borderRadius: "50%", background: "#38bdf8", animation: "rec 1.2s infinite" }}></span>
                    transcribing…
                  </div>
                )}
              </div>
            </div>

            {/* Portuguese */}
            <div style={transcribePanel}>
              <div style={transcribeHead}>
                <span style={{ background: "rgba(167,139,250,0.18)", color: "#a78bfa", width: 26, height: 26, borderRadius: 6, display: "grid", placeItems: "center" }}>PT</span>
                <span>Translation · pt-BR</span>
                <span style={{ marginLeft: "auto", fontSize: 11, color: "#64748b" }}>auto-translated · ~150 ms latency</span>
              </div>
              <div ref={ptRef} style={{ display: "flex", flexDirection: "column", gap: 10, padding: 16, overflowY: "auto", flex: 1, fontSize: 13.5, lineHeight: 1.55, color: "#cbd5e1", fontStyle: "italic", scrollBehavior: "smooth" }}>
                {visibleSegs.map((s, i) => {
                  const isYou = s.spk === "You";
                  return (
                    <div key={i} style={{
                      alignSelf: isYou ? "flex-end" : "flex-start",
                      maxWidth: "82%",
                      animation: "msgIn .35s ease both",
                    }}>
                      <div style={{
                        background: isYou ? "rgba(167,139,250,0.22)" : "rgba(148,163,184,0.10)",
                        color: "#e2e8f0",
                        padding: "8px 12px",
                        borderRadius: isYou ? "12px 12px 4px 12px" : "12px 12px 12px 4px",
                        border: "1px solid " + (isYou ? "rgba(167,139,250,0.4)" : "rgba(148,163,184,0.18)"),
                      }}>{s.pt}</div>
                    </div>
                  );
                })}
              </div>
            </div>
          </div>

          {/* Idea panel — only rendered when the user opens it */}
          {ideaOpen && (
          <div style={{
            background: "linear-gradient(180deg,#1c1917 0%,#0c0a09 100%)",
            borderLeft: "1px solid rgba(251,191,36,0.4)",
            borderRadius: 14, overflow: "hidden",
            display: "flex", flexDirection: "column", minHeight: 0,
            animation: "msgIn .35s ease both",
          }}>
            <div style={{
              display: "flex", alignItems: "center", justifyContent: "space-between",
              padding: "14px 18px", borderBottom: "1px solid rgba(251,191,36,0.25)",
              background: "linear-gradient(180deg,rgba(251,191,36,0.08),transparent)",
            }}>
              <div style={{ display: "flex", alignItems: "center", gap: 10 }}>
                <span style={{ background: "rgba(251,191,36,0.2)", color: "#fbbf24", width: 32, height: 32, borderRadius: 10, display: "grid", placeItems: "center", fontSize: 16 }}>💡</span>
                <div>
                  <div style={{ fontSize: 13, fontWeight: 800, color: "#fbbf24", letterSpacing: "0.04em" }}>AI Coach</div>
                  <div style={{ fontSize: 11, color: "#a8a29e" }}>Suggestion based on the latest exchange</div>
                </div>
              </div>
              <button onClick={() => setIdeaOpen(false)} style={{ background: "transparent", color: "#fde68a", border: "1px solid rgba(251,191,36,0.4)", borderRadius: 999, padding: "4px 10px", fontSize: 11, cursor: "pointer", fontWeight: 700 }}>✕ close</button>
            </div>

            {/* Chat-style stages */}
            <div style={{ padding: "16px 18px", overflowY: "auto", flex: 1, display: "flex", flexDirection: "column", gap: 12 }}>
              {/* Stage 1 — Question detected */}
              {ideaStage >= 1 && (
                <div style={{ animation: "msgIn .35s ease both" }}>
                  <div style={{ fontSize: 10, color: "#fbbf24", fontWeight: 800, letterSpacing: "0.14em", textTransform: "uppercase", marginBottom: 4 }}>📩 Question detected</div>
                  <div style={{ background: "rgba(251,191,36,0.10)", border: "1px solid rgba(251,191,36,0.3)", borderRadius: "12px 12px 12px 4px", padding: "10px 13px", color: "#fef3c7", fontSize: 13, lineHeight: 1.5 }}>
                    {ideaQA.q}
                  </div>
                </div>
              )}

              {/* Stage 2 — Suggested answer */}
              {ideaStage >= 2 && (
                <div style={{ animation: "msgIn .35s ease both", alignSelf: "flex-end", maxWidth: "92%" }}>
                  <div style={{ fontSize: 10, color: "#10b981", fontWeight: 800, letterSpacing: "0.14em", textTransform: "uppercase", marginBottom: 4, textAlign: "right" }}>✨ Suggested answer</div>
                  <div style={{ background: "linear-gradient(135deg,rgba(16,185,129,0.20),rgba(5,150,105,0.10))", border: "1px solid rgba(16,185,129,0.4)", borderRadius: "12px 12px 4px 12px", padding: "10px 13px", color: "#d1fae5", fontSize: 13, lineHeight: 1.55 }}>
                    {ideaQA.a}
                  </div>
                </div>
              )}

              {/* Stage 3 — Follow-up question */}
              {ideaStage >= 3 && (
                <div style={{ animation: "msgIn .35s ease both" }}>
                  <div style={{ fontSize: 10, color: "#a78bfa", fontWeight: 800, letterSpacing: "0.14em", textTransform: "uppercase", marginBottom: 4 }}>↪ Likely follow-up</div>
                  <div style={{ background: "rgba(167,139,250,0.15)", border: "1px solid rgba(167,139,250,0.4)", borderRadius: "12px 12px 12px 4px", padding: "10px 13px", color: "#ddd6fe", fontSize: 13, lineHeight: 1.5, fontStyle: "italic" }}>
                    {ideaQA.followUp}
                  </div>
                </div>
              )}

              {/* Stage 4 — Explanation */}
              {ideaStage >= 4 && (
                <div style={{ animation: "msgIn .35s ease both" }}>
                  <div style={{ fontSize: 10, color: "#38bdf8", fontWeight: 800, letterSpacing: "0.14em", textTransform: "uppercase", marginBottom: 4 }}>🧭 What they're really asking</div>
                  <div style={{ background: "rgba(56,189,248,0.10)", border: "1px solid rgba(56,189,248,0.3)", borderRadius: "12px 12px 12px 4px", padding: "10px 13px", color: "#bae6fd", fontSize: 12.5, lineHeight: 1.55 }}>
                    {ideaQA.explain}
                  </div>
                </div>
              )}

              {/* Typing indicator while stages stream in */}
              {ideaOpen && ideaStage < 4 && (
                <div style={{ display: "flex", gap: 4, alignItems: "center", color: "#a8a29e", fontSize: 11, fontStyle: "italic", paddingLeft: 4 }}>
                  <span style={{ width: 6, height: 6, borderRadius: "50%", background: "#fbbf24", animation: "rec .8s infinite" }}></span>
                  <span style={{ width: 6, height: 6, borderRadius: "50%", background: "#fbbf24", animation: "rec .8s infinite .15s" }}></span>
                  <span style={{ width: 6, height: 6, borderRadius: "50%", background: "#fbbf24", animation: "rec .8s infinite .3s" }}></span>
                  <span style={{ marginLeft: 6 }}>Coach is thinking…</span>
                </div>
              )}
            </div>

            {/* Footer */}
            <div style={{ padding: "10px 18px", borderTop: "1px dashed rgba(251,191,36,0.2)", fontSize: 11, color: "#78716c", display: "flex", justifyContent: "space-between" }}>
              <span>Whisper + Groq · context: last 6 segments</span>
              <span>● live</span>
            </div>
          </div>
          )}
        </div>

        <style>{`
          @keyframes rec    { 50% { opacity: 0.3 } }
          @keyframes msgIn  { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
        `}</style>
      </div>
    );
  }
  const transcribePanel = {
    background: "#1E293B", borderRadius: 12,
    border: "1px solid #334155",
    display: "flex", flexDirection: "column",
    overflow: "hidden", minHeight: 0,
  };
  const transcribeHead = {
    padding: "12px 18px",
    borderBottom: "1px solid #334155",
    display: "flex", alignItems: "center", gap: 8,
    fontFamily: "Space Grotesk, sans-serif", fontSize: 16, fontWeight: 700,
  };

  /* ═══════════════════════════════════════════════════════════════════
     DEMO 5 · Jobs (kanban + resume preview drawer)
     ═══════════════════════════════════════════════════════════════════ */
  function DemoJobs() {
    const [openJob, setOpenJob] = useState(null);
    const [features, setFeatures] = useState({ resume: true, cover: true, qa: true, autoApply: false });

    const jobs = [
      { id: 1, co: "Northwind Cloud",  role: "Cloud Engineer · Azure",   loc: "Vancouver, BC",    match: 92, salary: "$ 95k–115k", stage: "ready",    tags: ["Azure", "Entra ID", "PowerShell"] },
      { id: 2, co: "PolarOps Inc.",    role: "M365 Administrator",        loc: "Remote (Canada)",  match: 88, salary: "$ 82k–96k",  stage: "ready",    tags: ["Intune", "Defender", "Exchange"] },
      { id: 3, co: "Granite Tech",     role: "DevOps Engineer",           loc: "Burnaby, BC",      match: 81, salary: "$ 90k–110k", stage: "tailored", tags: ["Pipelines", "Bicep", "GitHub"] },
      { id: 4, co: "Coast Security",   role: "Security Engineer",         loc: "Vancouver, BC",    match: 79, salary: "$ 100k–125k",stage: "tailored", tags: ["Sentinel", "KQL", "Zero Trust"] },
      { id: 5, co: "Aurora Logistics", role: "IT Infrastructure Lead",    loc: "Hybrid · BC",      match: 74, salary: "$ 88k–105k", stage: "search",   tags: ["VMware", "AD", "Networking"] },
      { id: 6, co: "Maple Ledger",     role: "Junior Network Tech",       loc: "Surrey, BC",       match: 41, salary: "$ 52k–60k",  stage: "skipped",  tags: ["Cisco", "L1 Support"] },
    ];

    const stages = [
      { id: "search",   label: "Searched",        desc: "Daily crawl across 14 boards",       color: "#3b82f6", icon: "🔎" },
      { id: "tailored", label: "Tailored",        desc: "Resume + cover letter generated",    color: "#8b5cf6", icon: "✍️" },
      { id: "ready",    label: "Ready to Apply",  desc: "Awaiting your green light",          color: "#10b981", icon: "📨" },
      { id: "skipped",  label: "Skipped",         desc: "Below match threshold",              color: "#94a3b8", icon: "✕" },
    ];

    const sites = [
      { name: "LinkedIn",  found: 42, c: "#0a66c2" },
      { name: "Indeed",    found: 31, c: "#003a9b" },
      { name: "Glassdoor", found: 14, c: "#0caa41" },
      { name: "Monster",   found: 12, c: "#7d4ed5" },
      { name: "BCJobs",    found:  9, c: "#e11d2e" },
      { name: "Workopolis",found:  6, c: "#f59e0b" },
      { name: "Job Bank",  found:  4, c: "#0078d4" },
    ];

    const keywords = ["Cloud Engineer", "Azure", "Entra ID", "M365", "Intune", "Defender", "PowerShell", "Vancouver / Hybrid"];
    const excluded = ["junior · entry-level", "< $ 70k", "shift work"];

    const Toggle = ({ on, onChange, label, desc }) => (
      <button onClick={() => onChange(!on)} style={{
        display: "flex", alignItems: "center", gap: 12, padding: "10px 12px",
        background: "#1e293b", border: "1px solid " + (on ? "#10b981" : "#334155"),
        borderRadius: 10, cursor: "pointer", textAlign: "left", flex: 1,
        fontFamily: "Inter, sans-serif", color: "#E2E8F0",
      }}>
        <span style={{
          width: 36, height: 20, borderRadius: 999, background: on ? "#10b981" : "#475569",
          position: "relative", transition: "all .2s ease", flexShrink: 0,
        }}>
          <span style={{ position: "absolute", top: 2, left: on ? 18 : 2, width: 16, height: 16, background: "#fff", borderRadius: "50%", transition: "all .2s ease" }}></span>
        </span>
        <span style={{ flex: 1, minWidth: 0 }}>
          <div style={{ fontWeight: 600, fontSize: 13 }}>{label}</div>
          <div style={{ fontSize: 11, color: "#94a3b8", marginTop: 2 }}>{desc}</div>
        </span>
      </button>
    );

    return (
      <div style={{ background: "#0B1220", color: "#E2E8F0", minHeight: 720, padding: 24, fontFamily: "Inter, system-ui, sans-serif", display: "flex", flexDirection: "column", gap: 16 }}>
        {/* Top */}
        <header style={{ display: "flex", justifyContent: "space-between", alignItems: "center", padding: "0 0 14px", borderBottom: "1px solid #1e293b", flexWrap: "wrap", gap: 16 }}>
          <div>
            <div style={{ fontFamily: "Space Grotesk, sans-serif", fontSize: 26, fontWeight: 700, letterSpacing: "-0.01em" }}>Automated Job Search</div>
            <div style={{ fontSize: 13, color: "#94a3b8", marginTop: 2 }}>Crawl · score · tailor · approve — fully on autopilot until you hit Apply</div>
          </div>
          <div style={{ display: "flex", gap: 14, alignItems: "center" }}>
            <div style={{ display: "flex", flexDirection: "column", alignItems: "flex-end" }}>
              <div style={{ fontSize: 22, fontWeight: 800, color: "#10b981", lineHeight: 1 }}>118</div>
              <div style={{ fontSize: 10, color: "#64748b", letterSpacing: "0.16em", textTransform: "uppercase" }}>scanned today</div>
            </div>
            <div style={{ width: 1, height: 36, background: "#1e293b" }}></div>
            <div style={{ display: "flex", flexDirection: "column", alignItems: "flex-end" }}>
              <div style={{ fontSize: 22, fontWeight: 800, color: "#fbbf24", lineHeight: 1 }}>2</div>
              <div style={{ fontSize: 10, color: "#64748b", letterSpacing: "0.16em", textTransform: "uppercase" }}>ready · awaiting you</div>
            </div>
            <button style={{ background: "#1e293b", border: "1px solid #334155", color: "#cbd5e1", borderRadius: 8, padding: "8px 14px", fontSize: 12, cursor: "pointer", fontFamily: "Inter,sans-serif" }}>🔄 sync now</button>
          </div>
        </header>

        {/* Profile + sites + keywords + features */}
        <div style={{ display: "grid", gridTemplateColumns: "1.1fr 1fr 1fr", gap: 14 }}>
          {/* Profile */}
          <div style={{ background: "#0F172A", border: "1px solid #1e293b", borderRadius: 12, padding: 16 }}>
            <div style={{ fontSize: 11, color: "#64748b", letterSpacing: "0.14em", textTransform: "uppercase", marginBottom: 10 }}>● Active profile</div>
            <div style={{ display: "flex", alignItems: "center", gap: 12, marginBottom: 12 }}>
              <div style={{ width: 48, height: 48, borderRadius: "50%", background: "linear-gradient(135deg,#0f4c81,#0e7490)", color: "#fff", display: "grid", placeItems: "center", fontWeight: 800, fontSize: 16 }}>D</div>
              <div>
                <div style={{ fontWeight: 700, fontSize: 15 }}>Demo Profile</div>
                <div style={{ fontSize: 12, color: "#94a3b8" }}>Cloud &amp; IT Infrastructure · 9 yrs · BC, Canada</div>
              </div>
            </div>
            <div style={{ display: "grid", gridTemplateColumns: "1fr 1fr", gap: 8, fontSize: 12 }}>
              <div style={{ background: "#1e293b", borderRadius: 6, padding: "8px 10px" }}><div style={{ color: "#64748b", fontSize: 10, textTransform: "uppercase" }}>Salary floor</div><div style={{ fontWeight: 700, color: "#cbd5e1" }}>$ 90,000 / yr</div></div>
              <div style={{ background: "#1e293b", borderRadius: 6, padding: "8px 10px" }}><div style={{ color: "#64748b", fontSize: 10, textTransform: "uppercase" }}>Work style</div><div style={{ fontWeight: 700, color: "#cbd5e1" }}>Hybrid · Remote</div></div>
              <div style={{ background: "#1e293b", borderRadius: 6, padding: "8px 10px" }}><div style={{ color: "#64748b", fontSize: 10, textTransform: "uppercase" }}>Languages</div><div style={{ fontWeight: 700, color: "#cbd5e1" }}>EN · PT · FR (B1)</div></div>
              <div style={{ background: "#1e293b", borderRadius: 6, padding: "8px 10px" }}><div style={{ color: "#64748b", fontSize: 10, textTransform: "uppercase" }}>Min match</div><div style={{ fontWeight: 700, color: "#cbd5e1" }}>≥ 70%</div></div>
            </div>
            <div style={{ marginTop: 12 }}>
              <div style={{ fontSize: 11, color: "#64748b", textTransform: "uppercase", letterSpacing: "0.1em", marginBottom: 6 }}>Keywords (8)</div>
              <div style={{ display: "flex", gap: 4, flexWrap: "wrap" }}>
                {keywords.map((k) => (<span key={k} style={{ fontSize: 11, color: "#7dd3fc", background: "rgba(56,189,248,0.10)", border: "1px solid rgba(56,189,248,0.3)", borderRadius: 999, padding: "3px 9px", fontWeight: 600 }}>{k}</span>))}
              </div>
            </div>
            <div style={{ marginTop: 10 }}>
              <div style={{ fontSize: 11, color: "#64748b", textTransform: "uppercase", letterSpacing: "0.1em", marginBottom: 6 }}>Excluded (3)</div>
              <div style={{ display: "flex", gap: 4, flexWrap: "wrap" }}>
                {excluded.map((k) => (<span key={k} style={{ fontSize: 11, color: "#fca5a5", background: "rgba(252,165,165,0.08)", border: "1px solid rgba(252,165,165,0.3)", borderRadius: 999, padding: "3px 9px", textDecoration: "line-through" }}>{k}</span>))}
              </div>
            </div>
          </div>

          {/* Sites scanned */}
          <div style={{ background: "#0F172A", border: "1px solid #1e293b", borderRadius: 12, padding: 16 }}>
            <div style={{ fontSize: 11, color: "#64748b", letterSpacing: "0.14em", textTransform: "uppercase", marginBottom: 4 }}>Sites scanned · last 24h</div>
            <div style={{ fontSize: 28, fontWeight: 800, color: "#10b981", lineHeight: 1 }}>118 <span style={{ fontSize: 12, fontWeight: 500, color: "#94a3b8" }}>postings · {sites.length} sources</span></div>
            <div style={{ display: "flex", flexDirection: "column", gap: 6, marginTop: 12 }}>
              {sites.map((s) => (
                <div key={s.name} style={{ display: "flex", alignItems: "center", gap: 10, fontSize: 12 }}>
                  <span style={{ width: 8, height: 8, borderRadius: "50%", background: s.c }}></span>
                  <span style={{ flex: 1, color: "#cbd5e1" }}>{s.name}</span>
                  <span style={{ width: 90, height: 4, background: "#1e293b", borderRadius: 2, overflow: "hidden" }}><span style={{ display: "block", height: "100%", width: (s.found / 42 * 100) + "%", background: s.c }}></span></span>
                  <span style={{ minWidth: 24, textAlign: "right", fontWeight: 700, color: "#7dd3fc" }}>{s.found}</span>
                </div>
              ))}
            </div>
          </div>

          {/* Feature toggles */}
          <div style={{ background: "#0F172A", border: "1px solid #1e293b", borderRadius: 12, padding: 16, display: "flex", flexDirection: "column", gap: 10 }}>
            <div style={{ fontSize: 11, color: "#64748b", letterSpacing: "0.14em", textTransform: "uppercase" }}>Automation pipeline</div>
            <Toggle on={features.resume}    onChange={(v) => setFeatures({ ...features, resume: v })}    label="Auto-tailored resume"      desc="One PDF per job · keywords matched to JD" />
            <Toggle on={features.cover}     onChange={(v) => setFeatures({ ...features, cover: v })}     label="Auto cover letter"          desc="Personalized for company & role" />
            <Toggle on={features.qa}        onChange={(v) => setFeatures({ ...features, qa: v })}        label="Q&A simulation from JD"         desc="Mock interview questions generated from each posting" />
            <Toggle on={features.autoApply} onChange={(v) => setFeatures({ ...features, autoApply: v })} label="Auto-apply (off by default)" desc="Send applications without manual approval" />
          </div>
        </div>

        {/* Pipeline */}
        <div style={{ display: "grid", gridTemplateColumns: "repeat(4, 1fr)", gap: 12, flex: 1 }}>
          {stages.map((s) => {
            const list = jobs.filter((j) => j.stage === s.id);
            return (
              <div key={s.id} style={{ background: "#0F172A", border: "1px solid #1e293b", borderRadius: 12, padding: 14, display: "flex", flexDirection: "column", gap: 10 }}>
                <div style={{ display: "flex", alignItems: "center", gap: 8 }}>
                  <span style={{ background: s.color + "22", color: s.color, width: 28, height: 28, borderRadius: 6, display: "grid", placeItems: "center", fontSize: 14 }}>{s.icon}</span>
                  <div>
                    <div style={{ fontWeight: 600, fontSize: 13 }}>{s.label}</div>
                    <div style={{ fontSize: 10, color: "#64748b" }}>{s.desc}</div>
                  </div>
                  <span style={{ marginLeft: "auto", background: s.color + "22", color: s.color, fontSize: 11, padding: "2px 10px", borderRadius: 999, fontWeight: 700 }}>{list.length}</span>
                </div>
                <div style={{ display: "flex", flexDirection: "column", gap: 8 }}>
                  {list.map((j) => (
                    <button key={j.id} onClick={() => setOpenJob(j)} style={{
                      background: "#1e293b", border: "1px solid #334155",
                      borderRadius: 10, padding: 12, textAlign: "left", cursor: "pointer",
                      color: "#E2E8F0", fontFamily: "Inter, sans-serif",
                      transition: "all .15s ease",
                    }} onMouseEnter={(e) => { e.currentTarget.style.borderColor = s.color; e.currentTarget.style.background = "#243144"; }}
                       onMouseLeave={(e) => { e.currentTarget.style.borderColor = "#334155"; e.currentTarget.style.background = "#1e293b"; }}>
                      <div style={{ fontWeight: 600, fontSize: 13 }}>{j.role}</div>
                      <div style={{ fontSize: 11, color: "#94a3b8", marginTop: 2 }}>{j.co} · {j.loc}</div>
                      <div style={{ display: "flex", gap: 4, flexWrap: "wrap", marginTop: 8 }}>
                        {j.tags.map((tg) => (
                          <span key={tg} style={{ fontSize: 9.5, color: "#cbd5e1", background: "rgba(255,255,255,0.04)", border: "1px solid #334155", padding: "2px 6px", borderRadius: 4 }}>{tg}</span>
                        ))}
                      </div>
                      <div style={{ display: "flex", justifyContent: "space-between", alignItems: "center", marginTop: 10 }}>
                        <span style={{ display: "flex", alignItems: "center", gap: 6 }}>
                          <span style={{ width: 36, height: 4, background: "#1e293b", borderRadius: 2, overflow: "hidden" }}>
                            <span style={{ display: "block", height: "100%", width: j.match + "%", background: j.match >= 80 ? "#10b981" : j.match >= 60 ? "#f59e0b" : "#94a3b8" }}></span>
                          </span>
                          <span style={{ fontSize: 11, color: j.match >= 80 ? "#10b981" : j.match >= 60 ? "#f59e0b" : "#94a3b8", fontWeight: 600 }}>{j.match}%</span>
                        </span>
                        <span style={{ fontSize: 11, color: "#94a3b8" }}>{j.salary}</span>
                      </div>
                      {s.id === "ready" && (
                        <div style={{ display: "flex", gap: 6, marginTop: 10 }}>
                          <span style={{ flex: 1, background: "#10b981", color: "#0b1220", borderRadius: 6, padding: "7px 8px", fontSize: 11, fontWeight: 700, textAlign: "center" }}>Apply</span>
                          <span style={{ flex: 1, background: "transparent", color: "#94a3b8", border: "1px solid #334155", borderRadius: 6, padding: "7px 8px", fontSize: 11, textAlign: "center" }}>Skip</span>
                        </div>
                      )}
                    </button>
                  ))}
                </div>
              </div>
            );
          })}
        </div>

        <div style={{ padding: 14, background: "#0F172A", border: "1px solid #1e293b", borderRadius: 12, fontSize: 12, color: "#94a3b8", display: "flex", justifyContent: "space-between", alignItems: "center", gap: 12 }}>
          <div><strong style={{ color: "#cbd5e1" }}>How it works:</strong> bot crawls boards, scores each posting against your registered experience, generates a tailored resume + cover letter, queues a one-click apply that you approve manually.</div>
          <span style={{ color: "#fbbf24", fontSize: 11, whiteSpace: "nowrap" }}>● Demo · engine in active development</span>
        </div>

        {/* Resume drawer */}
        {openJob && <JobResumeDrawer job={openJob} onClose={() => setOpenJob(null)} />}
      </div>
    );
  }

  function JobResumeDrawer({ job, onClose }) {
    return (
      <div onClick={(e) => { if (e.target === e.currentTarget) onClose(); }} style={{
        position: "fixed", inset: 0, zIndex: 250,
        background: "rgba(0,0,0,0.6)",
        display: "flex", justifyContent: "flex-end",
        animation: "fadeIn .2s ease",
      }}>
        <div style={{
          width: "min(640px, 100%)", height: "100%",
          background: "#fff", color: "#1f2937", overflowY: "auto",
          fontFamily: "Inter, system-ui, sans-serif",
          animation: "slideIn .3s ease",
        }}>
          <header style={{ background: "#0B2545", color: "#fff", padding: "14px 20px", display: "flex", justifyContent: "space-between", alignItems: "center" }}>
            <div>
              <div style={{ fontWeight: 700, fontSize: 16 }}>{job.role}</div>
              <div style={{ fontSize: 12, color: "rgba(255,255,255,0.75)", marginTop: 2 }}>{job.co} · {job.loc}</div>
            </div>
            <button onClick={onClose} style={{ background: "rgba(255,255,255,0.1)", border: "1px solid rgba(255,255,255,0.25)", color: "#fff", padding: "6px 12px", borderRadius: 6, fontSize: 12, cursor: "pointer" }}>✕ close</button>
          </header>

          <div style={{ padding: 22 }}>
            <div style={{ display: "flex", gap: 12, marginBottom: 18 }}>
              <JobMetric label="Match"  value={job.match + "%"} color={job.match >= 80 ? "#10b981" : "#f59e0b"} />
              <JobMetric label="Salary" value={job.salary}      color="#0B2545" />
              <JobMetric label="Stage"  value={job.stage}       color="#7c3aed" />
            </div>

            <h3 style={{ fontSize: 13, fontWeight: 700, letterSpacing: "0.1em", textTransform: "uppercase", color: "#6b7280", margin: "16px 0 10px" }}>Tailored resume preview</h3>
            <div style={{ background: "#fafafa", border: "1px solid #e5e7eb", borderRadius: 10, padding: 18, fontSize: 13.5, lineHeight: 1.55 }}>
              <div style={{ fontFamily: "Space Grotesk, sans-serif", fontSize: 24, fontWeight: 700, color: "#0B2545" }}>Paulo Oliveira</div>
              <div style={{ fontSize: 12, color: "#6b7280" }}>Cloud &amp; IT Infrastructure Engineer · Vancouver, BC · paulo@example.com</div>
              <div style={{ height: 1, background: "#e5e7eb", margin: "10px 0" }}></div>
              <div style={{ fontWeight: 700, fontSize: 12.5, letterSpacing: "0.05em", textTransform: "uppercase", color: "#0B2545", marginTop: 10 }}>Summary · tailored for {job.role}</div>
              <p style={{ margin: "6px 0", color: "#374151" }}>
                9+ years across Microsoft 365, Azure identity &amp; security, Intune endpoint management and enterprise IT infrastructure.
                Operated environments at Carrefour scale (310 stores, 1,500 servers, 6,000 users). <strong>Highlight matched to this role:</strong> {job.tags.slice(0, 2).join(" + ")}.
              </p>
              <div style={{ fontWeight: 700, fontSize: 12.5, letterSpacing: "0.05em", textTransform: "uppercase", color: "#0B2545", marginTop: 12 }}>Highlighted skills</div>
              <div style={{ display: "flex", flexWrap: "wrap", gap: 6, marginTop: 6 }}>
                {job.tags.map((tg) => (
                  <span key={tg} style={{ background: "#dbeafe", color: "#1e40af", border: "1px solid #93c5fd", borderRadius: 999, padding: "3px 10px", fontSize: 11, fontWeight: 600 }}>{tg}</span>
                ))}
                {["Conditional Access", "PIM", "KQL", "Power Automate"].map((tg) => (
                  <span key={tg} style={{ background: "#f3f4f6", color: "#374151", border: "1px solid #e5e7eb", borderRadius: 999, padding: "3px 10px", fontSize: 11 }}>{tg}</span>
                ))}
              </div>
            </div>

            <h3 style={{ fontSize: 13, fontWeight: 700, letterSpacing: "0.1em", textTransform: "uppercase", color: "#6b7280", margin: "20px 0 10px" }}>Cover letter draft</h3>
            <div style={{ background: "#fafafa", border: "1px solid #e5e7eb", borderRadius: 10, padding: 18, fontSize: 13.5, lineHeight: 1.65, color: "#374151" }}>
              <p style={{ margin: 0 }}>Dear {job.co} Hiring Team,</p>
              <p>I'm reaching out about the {job.role} role. Over the last nine years I've operated Microsoft 365 and Azure environments at scale — including identity governance via Entra ID, Conditional Access, PIM, and endpoint compliance through Intune and Defender for Endpoint.</p>
              <p>The role's emphasis on {job.tags[0]} and {job.tags[1]} maps directly to recent work I've delivered, and I'd welcome the chance to bring that experience to {job.co}.</p>
              <p style={{ margin: "8px 0 0" }}>Best regards,<br/>Paulo Oliveira</p>
            </div>

            <div style={{ display: "flex", gap: 8, marginTop: 22 }}>
              <button style={{ flex: 1, background: "#10b981", color: "#0b1220", border: "none", borderRadius: 8, padding: "12px", fontSize: 13, fontWeight: 700, cursor: "pointer" }}>✓ Approve &amp; Apply</button>
              <button style={{ flex: 1, background: "#fff", color: "#374151", border: "1px solid #d1d5db", borderRadius: 8, padding: "12px", fontSize: 13, fontWeight: 600, cursor: "pointer" }}>↻ Re-tailor</button>
              <button style={{ flex: 0, background: "transparent", color: "#9ca3af", border: "1px solid #e5e7eb", borderRadius: 8, padding: "12px 18px", fontSize: 13, cursor: "pointer" }}>Skip</button>
            </div>
            <div style={{ marginTop: 14, fontSize: 11, color: "#9ca3af", textAlign: "center", letterSpacing: "0.06em" }}>● Demo — no email is sent</div>
          </div>
          <style>{`@keyframes slideIn { from { transform: translateX(40px); opacity: 0 } to { transform: translateX(0); opacity: 1 } }`}</style>
        </div>
      </div>
    );
  }
  function JobMetric({ label, value, color }) {
    return (
      <div style={{
        flex: 1, padding: "10px 14px",
        background: "#fafafa", border: "1px solid #e5e7eb",
        borderRadius: 10,
        borderLeft: "4px solid " + color,
        display: "flex", flexDirection: "column", gap: 4,
      }}>
        <span style={{ fontSize: 10, color: "#6b7280", letterSpacing: "0.14em", textTransform: "uppercase", fontWeight: 600 }}>{label}</span>
        <span style={{ fontSize: 16, fontWeight: 700, color, textTransform: label === "Stage" ? "capitalize" : "none" }}>{value}</span>
      </div>
    );
  }

  /* ═══════════════════════════════════════════════════════════════════
     Tiny inline SVG icons — keep dependencies zero
     ═══════════════════════════════════════════════════════════════════ */
  function svgIcon(d, props = {}) {
    return ({ size = 18, color = "currentColor", strokeWidth = 2 }) => (
      <svg width={size} height={size} viewBox="0 0 24 24" fill={props.fill || "none"} stroke={color} strokeWidth={strokeWidth} strokeLinecap="round" strokeLinejoin="round">
        {d}
      </svg>
    );
  }
  const HomeIcon    = svgIcon(<><path d="M3 9.5L12 3l9 6.5V20a2 2 0 01-2 2h-3v-7h-8v7H5a2 2 0 01-2-2V9.5z"/></>);
  const ClockIcon   = svgIcon(<><circle cx="12" cy="12" r="10"/><polyline points="12 6 12 12 16 14"/></>);
  const WrenchIcon  = svgIcon(<><path d="M14.7 6.3a4.5 4.5 0 00-6.4 6.4L3 18l3 3 5.3-5.3a4.5 4.5 0 006.4-6.4l-3 3-3-3 3-3z"/></>);
  const BoxIcon     = svgIcon(<><path d="M21 8L12 3 3 8v8l9 5 9-5z"/><polyline points="3 8 12 13 21 8"/><line x1="12" y1="13" x2="12" y2="21"/></>);
  const TrendIcon   = svgIcon(<><polyline points="3 17 9 11 13 15 21 7"/><polyline points="14 7 21 7 21 14"/></>);
  const TruckIcon   = svgIcon(<><path d="M1 3h13v13H1z"/><path d="M14 8h4l3 3v5h-7V8z"/><circle cx="5.5" cy="18.5" r="2.5"/><circle cx="17.5" cy="18.5" r="2.5"/></>);
  const ChatIcon    = svgIcon(<><path d="M21 15a2 2 0 01-2 2H7l-4 4V5a2 2 0 012-2h14a2 2 0 012 2z"/></>);
  const BookIcon    = svgIcon(<><path d="M4 19.5A2.5 2.5 0 016.5 17H20"/><path d="M6.5 2H20v20H6.5A2.5 2.5 0 014 19.5v-15A2.5 2.5 0 016.5 2z"/></>);
  const CapIcon     = svgIcon(<><path d="M22 10L12 4 2 10l10 6 10-6z"/><path d="M6 12v5c3 2 9 2 12 0v-5"/></>);
  const DbIcon      = svgIcon(<><ellipse cx="12" cy="5" rx="9" ry="3"/><path d="M3 5v14c0 1.7 4 3 9 3s9-1.3 9-3V5"/><path d="M3 12c0 1.7 4 3 9 3s9-1.3 9-3"/></>);
  const UsersIcon   = svgIcon(<><path d="M16 21v-2a4 4 0 00-4-4H6a4 4 0 00-4 4v2"/><circle cx="9" cy="7" r="4"/><path d="M22 21v-2a4 4 0 00-3-3.87"/><path d="M16 3.13a4 4 0 010 7.75"/></>);
  const ShieldIcon  = svgIcon(<><path d="M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z"/></>);
  const ShieldIcon2 = svgIcon(<><path d="M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z"/><polyline points="9 12 11 14 15 10"/></>);
  const GearIcon    = svgIcon(<><circle cx="12" cy="12" r="3"/><path d="M19.4 15a1.65 1.65 0 00.33 1.82l.06.06a2 2 0 11-2.83 2.83l-.06-.06a1.65 1.65 0 00-1.82-.33 1.65 1.65 0 00-1 1.51V21a2 2 0 11-4 0v-.09a1.65 1.65 0 00-1-1.51 1.65 1.65 0 00-1.82.33l-.06.06a2 2 0 11-2.83-2.83l.06-.06A1.65 1.65 0 005 15a1.65 1.65 0 00-1.51-1H3a2 2 0 110-4h.09A1.65 1.65 0 005 9 1.65 1.65 0 004.67 7.18l-.06-.06a2 2 0 112.83-2.83l.06.06A1.65 1.65 0 009 5a1.65 1.65 0 001-1.51V3a2 2 0 114 0v.09A1.65 1.65 0 0015 5c.62.25 1.32.13 1.82-.33l.06-.06a2 2 0 112.83 2.83l-.06.06A1.65 1.65 0 0019 9c.25.62.13 1.32-.33 1.82L18.61 11H21a2 2 0 110 4h-.09a1.65 1.65 0 00-1.51 1z"/></>);
  const SearchIcon  = svgIcon(<><circle cx="11" cy="11" r="8"/><line x1="21" y1="21" x2="16.65" y2="16.65"/></>);
  const BellIcon    = svgIcon(<><path d="M18 8a6 6 0 10-12 0c0 7-3 9-3 9h18s-3-2-3-9"/><path d="M13.73 21a2 2 0 01-3.46 0"/></>);
  const ChevronLeftIcon  = svgIcon(<><polyline points="15 18 9 12 15 6"/></>);
  const ChevronRightIcon = svgIcon(<><polyline points="9 18 15 12 9 6"/></>);
  const FileIcon    = svgIcon(<><path d="M14 2H6a2 2 0 00-2 2v16a2 2 0 002 2h12a2 2 0 002-2V8z"/><polyline points="14 2 14 8 20 8"/></>);
  const MegaIcon    = svgIcon(<><path d="M3 11l18-8v18l-18-8v-2z"/><path d="M11 11h2"/></>);
  const CalIcon     = svgIcon(<><rect x="3" y="4" width="18" height="18" rx="2"/><line x1="16" y1="2" x2="16" y2="6"/><line x1="8" y1="2" x2="8" y2="6"/><line x1="3" y1="10" x2="21" y2="10"/></>);
  const BulbIcon    = svgIcon(<><path d="M9 18h6"/><path d="M10 22h4"/><path d="M12 2a7 7 0 00-4 12.7c1 .8 1.5 1.6 1.5 3.3h5c0-1.7.5-2.5 1.5-3.3A7 7 0 0012 2z"/></>);
  const LeftArrowIcon = svgIcon(<><line x1="19" y1="12" x2="5" y2="12"/><polyline points="12 19 5 12 12 5"/></>, { strokeWidth: 2.5 });

  /* ═══════════════════════════════════════════════════════════════════
     WEB PROJECTS panel
     ═══════════════════════════════════════════════════════════════════ */
  const WEB_PROJECTS = [
    {
      id: "intranet", title: "ABC+ Intranet", tag: "INTRANET",
      summary: "Internal portal for a Motorola Solutions partner.",
      what: "Replaces 4 spreadsheets and 2 legacy tools with a single workspace: service tickets, rentals, contracts, time clock, suggestions and admin. Mobile-friendly, role-based, multi-branch.",
      stack: ["React + TS", "Vite", "Tailwind", "Supabase", "RBAC"],
      DemoComp: DemoIntranet,
    },
    {
      id: "school", title: "Language School", tag: "EDUCATION",
      summary: "Multi-language learning platform — English, French, Spanish, Italian.",
      what: "Grammar lessons with paged exercises, interview simulator with AI coach, audio reading and gamified review. Same engine across languages with shared content layer.",
      stack: ["Next.js", "Azure Neural TTS", "Groq", "Tailwind"],
      DemoComp: DemoLanguageSchool,
    },
    {
      id: "reader", title: "Web E-Reader", tag: "READER",
      summary: "Bilingual book reader with sentence-level audio and translation.",
      what: "Imports any PDF, splits into chapters, generates per-sentence translations and Azure Neural TTS audio. Click any word to study its grammar in context, save vocabulary and review later.",
      stack: ["Next.js", "Azure TTS", "Google Translate", "PostgreSQL"],
      DemoComp: DemoEReader,
    },
    {
      id: "transcribe", title: "Live Transcribe", tag: "AI",
      summary: "Real-time meeting transcription with an AI coach panel.",
      what: "Captures audio in the browser, streams to Whisper, surfaces context-aware suggestions for the next reply — useful for interviews, sales calls and bilingual meetings.",
      stack: ["Web Audio", "Whisper / Groq", "React", "Streaming"],
      DemoComp: DemoLiveTranscribe,
    },
    {
      id: "jobs", title: "Automated Job Search", tag: "AUTOMATION",
      summary: "Bot that searches, tailors and queues job applications.",
      what: "Crawls 14 job boards daily, scores each posting against your registered experience, generates a tailored resume + cover letter and a Q&A simulation from the JD. Waits for your one-click approval before applying.",
      stack: ["Node.js", "Playwright", "OpenAI / Groq", "Postgres"],
      DemoComp: DemoJobs,
    },
    {
      id: "seo", title: "SEO & SEM", tag: "MARKETING",
      summary: "10 years driving growth with Google Ads, GTM, Analytics, SEO and copywriting.",
      what: "End-to-end search marketing: technical SEO audits, content strategy, paid search campaigns (Google Ads), tag-based tracking (GTM), conversion analysis (GA4), and high-converting copywriting. Proven results across e-commerce, education and B2B.",
      stack: ["Google Ads", "GTM", "GA4", "Search Console", "Copywriting"],
      DemoComp: DemoSEO,
    },
  ];

  function ProjectRow({ p, onDemo }) {
    return (
      <div className="panel project-row" style={{
        padding: "26px 28px",
        display: "grid", gridTemplateColumns: "1.2fr 0.8fr",
        gap: 28, alignItems: "stretch",
      }}>
        <div style={{ display: "flex", flexDirection: "column", gap: 14, minWidth: 0 }}>
          <div style={{ display: "flex", alignItems: "center", gap: 10 }}>
            <Tag>{p.tag}</Tag>
            <span className="ink-dim mono" style={{ fontSize: 10.5, letterSpacing: "0.16em" }}>▸ ./{p.id}</span>
          </div>
          <h3 className="display" style={{ fontSize: "clamp(24px, 2.6vw, 32px)", fontWeight: 700, letterSpacing: "-0.02em", margin: 0, lineHeight: 1.05 }}>{p.title}</h3>
          <div className="ink-mute" style={{ fontSize: 14 }}>{p.summary}</div>
          <div style={{
            border: "1px dashed var(--line)", borderRadius: 10, padding: 16,
            background: "rgba(255,255,255,0.015)",
          }}>
            <div className="label" style={{ marginBottom: 6 }}>// what it is</div>
            <p style={{ margin: 0, fontSize: 13.5, lineHeight: 1.65, color: "var(--ink)" }}>{p.what}</p>
          </div>
          <div style={{ display: "flex", flexWrap: "wrap", gap: 6, marginTop: "auto" }}>
            {p.stack.map((s) => (
              <span key={s} className="mono" style={{
                fontSize: 10.5, letterSpacing: "0.06em",
                padding: "5px 10px", border: "1px solid var(--line)",
                borderRadius: 4, color: "var(--ink-mute)", background: "rgba(255,255,255,0.02)",
              }}>{s}</span>
            ))}
          </div>
        </div>

        <div style={{ display: "flex", flexDirection: "column", gap: 12 }}>
          <div style={{
            border: "1px solid var(--line-strong)", borderRadius: 10,
            background: "linear-gradient(180deg, color-mix(in oklab, var(--accent) 6%, var(--bg-1)), var(--bg-1))",
            position: "relative", overflow: "hidden",
            aspectRatio: "16 / 10",
            display: "grid", placeItems: "center",
          }}>
            <div className="display" style={{
              fontSize: "clamp(48px, 6vw, 80px)", fontWeight: 800,
              color: "var(--accent)", opacity: 0.85,
              letterSpacing: "-0.04em", textAlign: "center",
            }}>{p.tag}</div>
            <div style={{
              position: "absolute", inset: 0,
              backgroundImage: "radial-gradient(circle, color-mix(in oklab, var(--accent) 30%, transparent) 1px, transparent 1px)",
              backgroundSize: "16px 16px", opacity: 0.18,
              pointerEvents: "none",
            }}></div>
            <div className="mono" style={{
              position: "absolute", bottom: 8, left: 12, right: 12,
              display: "flex", justifyContent: "space-between",
              fontSize: 10, letterSpacing: "0.18em", color: "var(--ink-dim)",
            }}>
              <span>// preview</span>
              <span style={{ color: "var(--accent)" }}>● live</span>
            </div>
          </div>
          <button onClick={onDemo} className="btn primary" style={{ justifyContent: "center" }}>▶ Open Demo</button>
        </div>

        <style>{`
          @media (max-width: 760px) {
            .project-row { grid-template-columns: 1fr !important; gap: 18px !important; }
          }
        `}</style>
      </div>
    );
  }

  function WebProjectsPanel() {
    const [activeDemo, setActiveDemo] = useState(null);
    return (
      <section style={{ maxWidth: 1280, margin: "0 auto", padding: "32px 28px 0" }}>
        <div style={{ display: "grid", gap: 20 }}>
          {WEB_PROJECTS.map((p) => (
            <ProjectRow key={p.id} p={p} onDemo={() => setActiveDemo(p.id)} />
          ))}
        </div>
        {WEB_PROJECTS.map((p) => {
          const Comp = p.DemoComp;
          return (
            <DemoModal key={p.id} open={activeDemo === p.id} title={p.title} onClose={() => setActiveDemo(null)}>
              <Comp />
            </DemoModal>
          );
        })}
      </section>
    );
  }

  /* ═══════════════════════════════════════════════════════════════════
     MICROSOFT panel
     ═══════════════════════════════════════════════════════════════════ */
  function MsLogo({ kind }) {
    if (kind === "vsphere") {
      // VMware vSphere mark — dark navy rounded square + stylized v + orbit ring
      return (
        <svg width="64" height="64" viewBox="0 0 64 64">
          <defs>
            <linearGradient id="vsphereBg" x1="0" y1="0" x2="1" y2="1">
              <stop offset="0%" stopColor="#0b2545"/>
              <stop offset="100%" stopColor="#08182f"/>
            </linearGradient>
            <linearGradient id="vsphereV" x1="0" y1="0" x2="1" y2="1">
              <stop offset="0%" stopColor="#7ad7f0"/>
              <stop offset="100%" stopColor="#1c8fb8"/>
            </linearGradient>
          </defs>
          <rect x="2" y="2" width="60" height="60" rx="12" fill="url(#vsphereBg)" stroke="#1c8fb8" strokeWidth="1.5"/>
          <ellipse cx="32" cy="32" rx="22" ry="9" fill="none" stroke="#1c8fb8" strokeOpacity="0.45" strokeWidth="1.4" transform="rotate(-22 32 32)"/>
          <ellipse cx="32" cy="32" rx="22" ry="9" fill="none" stroke="#1c8fb8" strokeOpacity="0.25" strokeWidth="1.4" transform="rotate(22 32 32)"/>
          <path d="M16 18 L32 50 L48 18" fill="none" stroke="url(#vsphereV)" strokeWidth="6" strokeLinecap="round" strokeLinejoin="round"/>
          <circle cx="48" cy="18" r="2.6" fill="#7ad7f0"/>
        </svg>
      );
    }
    if (kind === "m365") {
      return (
        <div style={{ display: "grid", gridTemplateColumns: "1fr 1fr", gap: 4, width: 56, height: 56 }}>
          <div style={{ background: "#f25022" }}></div>
          <div style={{ background: "#7fba00" }}></div>
          <div style={{ background: "#00a4ef" }}></div>
          <div style={{ background: "#ffb900" }}></div>
        </div>
      );
    }
    if (kind === "server") {
      return (
        <svg width="56" height="56" viewBox="0 0 64 64">
          <rect x="6"  y="10" width="52" height="12" rx="2" fill="#5ab7ff"/>
          <rect x="6"  y="26" width="52" height="12" rx="2" fill="#3a8cd1"/>
          <rect x="6"  y="42" width="52" height="12" rx="2" fill="#1e6fb0"/>
          <circle cx="50" cy="16" r="2" fill="#39ff7a"/>
          <circle cx="50" cy="32" r="2" fill="#39ff7a"/>
          <circle cx="50" cy="48" r="2" fill="#ffbb33"/>
        </svg>
      );
    }
    return (
      <svg width="56" height="56" viewBox="0 0 64 64">
        <path d="M14 8 L40 8 L34 28 L48 28 L22 60 L28 36 L14 36 Z" fill="#742774"/>
        <path d="M14 8 L40 8 L34 28 L48 28 L22 60 L28 36 L14 36 Z" fill="url(#g1)"/>
        <defs><linearGradient id="g1" x1="0" y1="0" x2="1" y2="1"><stop offset="0%" stopColor="#9b59b6" stopOpacity="0.6"/><stop offset="100%" stopColor="#742774" stopOpacity="0"/></linearGradient></defs>
      </svg>
    );
  }

  function MicrosoftPanel() {
    const cards = [
      { kind: "vsphere", title: "VMware vSphere · Enterprise Datacenter (Brazil's Largest Wholesaler)", text: "N2 / N3 infrastructure support for Brazil's largest wholesaler — 1,500+ servers and 6,000+ user workstations across the national footprint. Centralized data center delivering RODC services to every store, with patching and configuration orchestrated through WSUS, GPO, PowerShell and a stack of supporting services.", bullets: ["VMware vSphere virtualization", "1,500+ servers · 6,000+ workstations", "RODC for store sites", "WSUS · GPO · PowerShell automation", "N2 / N3 incident & change management"] },
      { kind: "m365",   title: "Microsoft 365 Management", text: "End-to-end administration of Microsoft 365 tenants — user lifecycle, license assignment, Exchange Online, SharePoint, Teams, and DLP. Daily operations, troubleshooting, and tenant hardening.", bullets: ["Tenant provisioning & migration", "Exchange / SharePoint / Teams admin", "License optimization", "Audit, retention & DLP"] },
      { kind: "server", title: "On-Prem & Hybrid Server Administration", text: "Windows Server, Active Directory, GPO, DNS and VMware virtualization across on-premises and hybrid Azure environments. Patching, monitoring and incident response.", bullets: ["AD DS, GPO, DNS", "VMware vSphere & Hyper-V", "WSUS / patch automation", "Hybrid identity (AAD Connect)"] },
      { kind: "power",  title: "Power Apps & Power Automate", text: "Internal automations and lightweight intranet screens — service-order workflows, approvals, notifications, scheduled reports and integrations across M365, Dataverse and external APIs.", bullets: ["Approval flows", "Scheduled report jobs", "Custom forms & screens", "M365 / API integrations"] },
    ];
    return (
      <section style={{ maxWidth: 1280, margin: "0 auto", padding: "32px 28px 0" }}>
        <div style={{ display: "grid", gap: 20 }}>
          {cards.map((c) => (
            <div key={c.title} className="panel ms-row" style={{ padding: "26px 28px", display: "grid", gridTemplateColumns: "auto 1fr", gap: 28, alignItems: "center" }}>
              <div style={{ background: "rgba(255,255,255,0.02)", border: "1px solid var(--line)", borderRadius: 12, padding: 22, display: "grid", placeItems: "center", width: 140, height: 140 }}>
                <MsLogo kind={c.kind} />
              </div>
              <div>
                <h3 className="display" style={{ margin: 0, fontSize: 22, fontWeight: 600 }}>{c.title}</h3>
                <p className="ink-mute" style={{ fontSize: 14, lineHeight: 1.65, marginTop: 8 }}>{c.text}</p>
                <div style={{ display: "flex", flexWrap: "wrap", gap: 6, marginTop: 10 }}>
                  {c.bullets.map((b) => <span key={b} className="chip">{b}</span>)}
                </div>
              </div>
            </div>
          ))}
        </div>
        <style>{`@media (max-width: 720px) { .ms-row { grid-template-columns: 1fr !important; gap: 18px !important; } }`}</style>
      </section>
    );
  }

  /* ═══════════════════════════════════════════════════════════════════
     SECURITY panel
     ═══════════════════════════════════════════════════════════════════ */
  function SecLogo({ kind }) {
    if (kind === "intune") {
      return (
        <svg width="60" height="60" viewBox="0 0 64 64">
          <rect x="14" y="6"  width="36" height="52" rx="6" fill="#1e6fb0"/>
          <rect x="18" y="12" width="28" height="36" rx="2" fill="#5ab7ff"/>
          <circle cx="32" cy="54" r="2.5" fill="#39ff7a"/>
          <path d="M22 26 L30 34 L42 22" stroke="#fff" strokeWidth="2.5" fill="none" strokeLinecap="round" strokeLinejoin="round"/>
        </svg>
      );
    }
    if (kind === "purview") {
      return (
        <svg width="60" height="60" viewBox="0 0 64 64">
          <path d="M32 6 L54 18 L54 36 C54 48 44 56 32 60 C20 56 10 48 10 36 L10 18 Z" fill="#7e3ff2"/>
          <path d="M32 14 L46 22 L46 36 C46 44 40 50 32 53 C24 50 18 44 18 36 L18 22 Z" fill="#a06bff"/>
          <path d="M26 32 L30 36 L40 26" stroke="#fff" strokeWidth="2.5" fill="none" strokeLinecap="round"/>
        </svg>
      );
    }
    return (
      <svg width="60" height="60" viewBox="0 0 64 64">
        <path d="M32 4 L56 16 L56 36 C56 50 44 58 32 60 C20 58 8 50 8 36 L8 16 Z" fill="#0078d4"/>
        <circle cx="32" cy="32" r="14" fill="none" stroke="#5ab7ff" strokeWidth="2"/>
        <circle cx="32" cy="32" r="6" fill="#39ff7a"/>
        <line x1="32" y1="14" x2="32" y2="20" stroke="#5ab7ff" strokeWidth="2"/>
        <line x1="32" y1="44" x2="32" y2="50" stroke="#5ab7ff" strokeWidth="2"/>
        <line x1="14" y1="32" x2="20" y2="32" stroke="#5ab7ff" strokeWidth="2"/>
        <line x1="44" y1="32" x2="50" y2="32" stroke="#5ab7ff" strokeWidth="2"/>
      </svg>
    );
  }

  function SecurityPanel() {
    const cards = [
      { kind: "intune",   title: "Microsoft Intune & Advanced Endpoint", text: "Endpoint management at scale — Windows, macOS, iOS and Android — with compliance baselines, security policies, app protection and Autopilot zero-touch provisioning.", bullets: ["Compliance baselines", "App protection (MAM)", "Autopilot deployment", "Defender for Endpoint integration"] },
      { kind: "purview",  title: "Microsoft Purview · Governance",        text: "Information protection, data loss prevention, retention and insider risk. Sensitivity labels, eDiscovery, Communication Compliance and audit across the M365 estate.", bullets: ["Sensitivity labels & DLP", "Records management", "Insider risk & audit", "eDiscovery & holds"] },
      { kind: "sentinel", title: "Microsoft Sentinel & Defender",          text: "Cloud-native SIEM with KQL hunting, automated playbooks and full Microsoft 365 Defender stack — endpoint, identity, email and cloud apps in one correlated view.", bullets: ["Sentinel (KQL, analytics rules)", "Defender XDR (endpoint, identity, email)", "Automated playbooks", "Threat hunting & IR"] },
    ];
    return (
      <section style={{ maxWidth: 1280, margin: "0 auto", padding: "32px 28px 0" }}>
        <div style={{ display: "grid", gap: 20 }}>
          {cards.map((c) => (
            <div key={c.title} className="panel sec-row" style={{ padding: "26px 28px", display: "grid", gridTemplateColumns: "auto 1fr", gap: 28, alignItems: "center" }}>
              <div style={{ background: "rgba(255,255,255,0.02)", border: "1px solid var(--line)", borderRadius: 12, padding: 22, display: "grid", placeItems: "center", width: 140, height: 140 }}>
                <SecLogo kind={c.kind} />
              </div>
              <div>
                <h3 className="display" style={{ margin: 0, fontSize: 22, fontWeight: 600 }}>{c.title}</h3>
                <p className="ink-mute" style={{ fontSize: 14, lineHeight: 1.65, marginTop: 8 }}>{c.text}</p>
                <div style={{ display: "flex", flexWrap: "wrap", gap: 6, marginTop: 10 }}>
                  {c.bullets.map((b) => <span key={b} className="chip">{b}</span>)}
                </div>
              </div>
            </div>
          ))}
        </div>
        <style>{`@media (max-width: 720px) { .sec-row { grid-template-columns: 1fr !important; gap: 18px !important; } }`}</style>
      </section>
    );
  }

  /* ═══════════════════════════════════════════════════════════════════
     ProjectsPage root
     ═══════════════════════════════════════════════════════════════════ */
  function ProjectsPage() {
    const [tab, setTab] = useState("web");
    return (
      <React.Fragment>
        <TopBar prompt={PROFILE.prompt + " ~/portfolio"} />
        <ProjectsHero />
        <PortfolioDivider />
        <MenuTabs active={tab} onChange={setTab} />
        {tab === "web" && <WebProjectsPanel />}
        {tab === "ms"  && <MicrosoftPanel />}
        {tab === "sec" && <SecurityPanel />}
        <div style={{ height: 60 }}></div>
        <FooterBlock />
      </React.Fragment>
    );
  }

  /* ═══════════════════════════════════════════════════════════════════
     V2 — INTRANET with top-nav (matches real ABC+ layout)
     ═══════════════════════════════════════════════════════════════════ */
  function DemoIntranet() {
    const MODULES = [
      { id: "home",       label: "Home",              subs: [{ id: "home/main", label: "Dashboard", icon: HomeIcon }] },
      { id: "ponto",      label: "Time Clock",        subs: [
        { id: "ponto/me",        label: "My Time Clock",  icon: ClockIcon },
        { id: "ponto/history",   label: "History",        icon: HistoryIcon },
        { id: "ponto/approvals", label: "Approvals",      icon: ListChecksIcon },
      ]},
      { id: "at",         label: "Technical Service", subs: [
        { id: "at/kanban",   label: "Kanban",         icon: WrenchIcon },
        { id: "at/calendar", label: "Calendar",       icon: CalIcon },
        { id: "at/costs",    label: "Month Analysis", icon: BarsIcon },
        { id: "at/parts",    label: "Parts",          icon: PackageIcon },
        { id: "at/mgmt",     label: "Management",     icon: GridIcon },
        { id: "at/new",      label: "+ New OS",       icon: PlusIcon, cta: true },
      ]},
      { id: "rental",     label: "Rentals",           subs: [
        { id: "rental/dash",      label: "Dashboard",        icon: GridIcon },
        { id: "rental/contracts", label: "Contracts",        icon: FileIcon },
        { id: "rental/daily",     label: "Daily Rental",     icon: CalIcon },
        { id: "rental/schedule",  label: "Customer Schedule",icon: ClockIcon },
      ]},
      { id: "commercial", label: "Commercial",        subs: [
        { id: "commercial/overview", label: "Business Intelligence", icon: BarsIcon },
        { id: "commercial/opps",     label: "Opportunities",icon: TargetIcon },
        { id: "commercial/analysis", label: "Analyses",     icon: TrendIcon },
        { id: "commercial/cad",      label: "Records",      icon: UserCogIcon },
      ]},
      { id: "logistics",  label: "Logistics",         subs: [
        { id: "logistics/dash",    label: "Dashboard", icon: GridIcon },
        { id: "logistics/history", label: "History",   icon: HistoryIcon },
      ]},
      { id: "comms",      label: "Communication",     subs: [
        { id: "comms/announcements", label: "Announcements", icon: MegaIcon },
        { id: "comms/suggestions",   label: "Suggestions",   icon: ChatIcon },
        { id: "comms/policies",      label: "Policies",      icon: BookIcon },
        { id: "comms/training",      label: "Training",      icon: CapIcon },
      ]},
      { id: "admin",      label: "Administration",    subs: [
        { id: "admin/settings", label: "Settings",       icon: GearIcon },
        { id: "admin/clients",  label: "Client Records", icon: DbIcon },
        { id: "admin/users",    label: "Users",          icon: UsersIcon },
        { id: "admin/audit",    label: "Audit Log",      icon: ShieldIcon },
      ]},
    ];

    const [moduleId, setModuleId] = useState("home");
    const [subId, setSubId] = useState("home/main");

    const activeModule = MODULES.find((m) => m.id === moduleId) || MODULES[0];

    const handleModule = (m) => {
      setModuleId(m.id);
      setSubId(m.subs[0].id);
    };

    return (
      <div style={{ background: "#f2f4f7", color: "#1f2937", minHeight: 760, fontFamily: "Inter, system-ui, sans-serif", fontSize: 14, display: "flex", flexDirection: "column" }}>
        {/* Top white bar */}
        <header style={{
          background: "#fff", borderBottom: "1px solid #d7dde5",
          display: "flex", alignItems: "center", padding: "8px 18px", gap: 16,
          position: "sticky", top: 0, zIndex: 40,
        }}>
          <img src="/assets/logo-abc.png" alt="ABC+ Telecom" style={{ height: 30, objectFit: "contain" }} />
          <div style={{
            display: "flex", alignItems: "center", gap: 8,
            padding: "4px 12px", borderLeft: "1px solid #e6eaf0",
            color: "#0B2545", fontWeight: 600, fontSize: 12,
            letterSpacing: "0.06em", textTransform: "uppercase",
          }}>
            <span style={{ width: 6, height: 6, borderRadius: "50%", background: "#10B981" }}></span>
            Simplified Interface
          </div>
          <div style={{ display: "flex", alignItems: "center", gap: 10, flex: 1, color: "#9ca3af", fontSize: 13, padding: "6px 12px", background: "#f7f8fa", borderRadius: 6, border: "1px solid #e6eaf0", maxWidth: 380 }}>
            <SearchIcon size={14} color="#9ca3af" />
            Search clients, OS, contracts…
          </div>
          <div style={{ marginLeft: "auto", display: "flex", alignItems: "center", gap: 14 }}>
            <span style={{ position: "relative", color: "#6b7280", display: "grid", placeItems: "center" }}>
              <BellIcon size={18} color="#6b7280" />
              <span style={{ position: "absolute", top: -4, right: -4, width: 14, height: 14, background: "#dc2626", borderRadius: "50%", color: "#fff", fontSize: 9, display: "grid", placeItems: "center", fontWeight: 700 }}>3</span>
            </span>
            <div style={{ display: "flex", alignItems: "center", gap: 8, fontSize: 13 }}>
              <span style={{ color: "#1f2937", fontWeight: 500 }}>Demo User</span>
              <div style={{ width: 30, height: 30, borderRadius: "50%", background: "linear-gradient(135deg,#5ab7ff,#1e6fb0)", color: "#fff", display: "grid", placeItems: "center", fontWeight: 700, fontSize: 12 }}>DU</div>
            </div>
          </div>
        </header>

        {/* Navy primary nav */}
        <nav style={{
          background: "#0B2545", display: "flex", overflowX: "auto",
          padding: "0 16px", position: "sticky", top: 47, zIndex: 35,
          borderBottom: "1px solid #0B2545",
        }}>
          {MODULES.map((m) => {
            const a = m.id === moduleId;
            return (
              <button key={m.id} onClick={() => handleModule(m)}
                style={{
                  padding: "11px 16px", border: 0, cursor: "pointer",
                  background: a ? "#fff" : "transparent",
                  color: a ? "#0B2545" : "rgba(255,255,255,0.78)",
                  fontSize: 12, fontWeight: 600, whiteSpace: "nowrap",
                  borderBottom: "3px solid " + (a ? "#fff" : "transparent"),
                  fontFamily: "Inter, sans-serif",
                }}>
                {m.label}
              </button>
            );
          })}
        </nav>

        {/* White sub-nav */}
        {activeModule.subs.length > 1 && (
          <nav style={{
            background: "#fff", display: "flex", overflowX: "auto",
            padding: "0 18px", borderBottom: "1px solid #d7dde5",
            position: "sticky", top: 87, zIndex: 30, gap: 4, alignItems: "center",
          }}>
            {activeModule.subs.map((s) => {
              const a = s.id === subId;
              const Ic = s.icon;
              if (s.cta) {
                return (
                  <button key={s.id} onClick={() => setSubId(s.id)}
                    style={{
                      marginLeft: "auto", marginBlock: 7,
                      background: a ? "#1E40AF" : "#1E5BA8", color: "#fff",
                      borderRadius: 6, padding: "7px 14px", border: 0, cursor: "pointer",
                      fontSize: 12.5, fontWeight: 600, whiteSpace: "nowrap",
                      display: "flex", alignItems: "center", gap: 6,
                      fontFamily: "Inter, sans-serif",
                    }}>
                    <Ic size={14} color="#fff" /> {s.label}
                  </button>
                );
              }
              return (
                <button key={s.id} onClick={() => setSubId(s.id)}
                  style={{
                    padding: "13px 14px 11px", border: 0, cursor: "pointer", background: "transparent",
                    color: a ? "#1E5BA8" : "#6b7280",
                    fontSize: 12.5, fontWeight: 600, whiteSpace: "nowrap",
                    borderBottom: "3px solid " + (a ? "#1E5BA8" : "transparent"),
                    display: "flex", alignItems: "center", gap: 6,
                    fontFamily: "Inter, sans-serif",
                  }}>
                  <Ic size={14} color={a ? "#1E5BA8" : "#9ca3af"} /> {s.label}
                </button>
              );
            })}
          </nav>
        )}

        {/* Body */}
        <main style={{ padding: "20px 24px", flex: 1, overflowY: "auto", maxHeight: "calc(100vh - 200px)" }}>
          {subId === "home/main"          && <IntranetHome onShortcut={(id) => {
            setSubId(id);
            const m = id.split("/")[0];
            setModuleId(m === "ponto" ? "ponto" : m);
          }} />}
          {subId === "ponto/me"           && <IntranetPonto view="me" />}
          {subId === "ponto/history"      && <IntranetPonto view="history" />}
          {subId === "ponto/approvals"    && <IntranetPonto view="approvals" />}
          {subId === "at/kanban"          && <IntranetATKanban />}
          {subId === "at/calendar"        && <IntranetATCalendar />}
          {subId === "at/costs"           && <IntranetATCosts />}
          {subId === "at/parts"           && <IntranetATParts />}
          {subId === "at/mgmt"            && <IntranetATMgmt />}
          {subId === "at/new"             && <IntranetATNew />}
          {subId === "rental/dash"        && <IntranetRentalDash />}
          {subId === "rental/contracts"   && <IntranetRentalContracts />}
          {subId === "rental/daily"       && <IntranetRentalDaily />}
          {subId === "rental/schedule"    && <IntranetRentalSchedule />}
          {subId === "commercial/overview"&& <IntranetCommOverview />}
          {subId === "commercial/opps"    && <IntranetCommOpps />}
          {subId === "commercial/analysis"&& <IntranetCommAnalysis />}
          {subId === "commercial/cad"     && <IntranetCommCad />}
          {subId === "logistics/dash"     && <IntranetLogiDash />}
          {subId === "logistics/history"  && <IntranetLogiHistory />}
          {subId === "comms/suggestions"  && <IntranetCommsSugg />}
          {subId === "comms/announcements"&& <IntranetCommsAnn />}
          {subId === "comms/policies"     && <IntranetCommsPol />}
          {subId === "comms/training"     && <IntranetCommsTra />}
          {subId === "admin/clients"      && <IntranetAdminClients />}
          {subId === "admin/users"        && <IntranetAdminUsers />}
          {subId === "admin/audit"        && <IntranetAdminAudit />}
          {subId === "admin/settings"     && <IntranetAdminSettings />}
        </main>

        <style>{`
          .icard { background:#fff; border:1px solid #d7dde5; border-radius:4px; box-shadow:0 1px 2px rgba(16,24,40,.05); }
          .ipage h1 { margin:0 0 4px; font-size:26px; font-weight:800; color:#0B2545; letter-spacing:-0.015em; line-height:1.1; }
          .ipage h2 { margin:0; font-size:15px; font-weight:700; color:#0B2545; }
          .ipage p.lead { margin:0; color:#64748b; font-size:13px; }
          .ipill { display:inline-flex; align-items:center; gap:4px; font-size:11px; font-weight:600; padding:3px 9px; border-radius:999px; }
          .ibtn-prim { background:#0B2545; color:#fff; border:none; border-radius:4px; padding:7px 14px; font-weight:600; font-size:12px; cursor:pointer; font-family:Inter,sans-serif; }
          .ibtn-sec { background:#fff; color:#4b5563; border:1px solid #d7dde5; border-radius:4px; padding:7px 14px; font-weight:500; font-size:12px; cursor:pointer; font-family:Inter,sans-serif; }
          .ibtn-blue { background:#1E5BA8; color:#fff; border:none; border-radius:4px; padding:7px 14px; font-weight:600; font-size:12px; cursor:pointer; }
          .ibtn-green { background:#3fa055; color:#fff; border:none; border-radius:4px; padding:7px 14px; font-weight:600; font-size:12px; cursor:pointer; }
        `}</style>
      </div>
    );
  }

  /* ──── Helper SVGs added for Intranet V2 ──── */
  const HistoryIcon    = svgIcon(<><path d="M3 12a9 9 0 109-9"/><polyline points="3 4 3 12 11 12"/></>);
  const ListChecksIcon = svgIcon(<><polyline points="3 7 5 9 9 5"/><polyline points="3 14 5 16 9 12"/><line x1="13" y1="7" x2="21" y2="7"/><line x1="13" y1="14" x2="21" y2="14"/></>);
  const BarsIcon       = svgIcon(<><line x1="3" y1="20" x2="21" y2="20"/><rect x="5" y="10" width="3" height="10"/><rect x="11" y="6" width="3" height="14"/><rect x="17" y="13" width="3" height="7"/></>);
  const PackageIcon    = svgIcon(<><path d="M21 8L12 3 3 8v8l9 5 9-5z"/><line x1="3.27" y1="6.96" x2="12" y2="12.01"/><line x1="12" y1="22.08" x2="12" y2="12"/></>);
  const GridIcon       = svgIcon(<><rect x="3" y="3" width="7" height="7"/><rect x="14" y="3" width="7" height="7"/><rect x="14" y="14" width="7" height="7"/><rect x="3" y="14" width="7" height="7"/></>);
  const PlusIcon       = svgIcon(<><line x1="12" y1="5" x2="12" y2="19"/><line x1="5" y1="12" x2="19" y2="12"/></>, { strokeWidth: 2.5 });
  const TargetIcon     = svgIcon(<><circle cx="12" cy="12" r="10"/><circle cx="12" cy="12" r="6"/><circle cx="12" cy="12" r="2"/></>);
  const UserCogIcon    = svgIcon(<><circle cx="9" cy="7" r="4"/><path d="M3 21v-2a4 4 0 014-4h4"/><circle cx="18" cy="16" r="3"/><path d="M18 11v1m0 8v1m4.24-1.76l-.7-.7M14.46 11.46l-.7-.7m9.18 0l-.7.7M14.46 20.54l-.7.7"/></>);

  /* Rich mock content components for each Intranet sub-route */
  function IntranetHome({ onShortcut }) {
    const go = (id) => onShortcut && onShortcut(id);
    return (
      <div className="ipage" style={{ display: "flex", flexDirection: "column", gap: 16 }}>
        <div>
          <h1>Good morning, Demo! <span aria-hidden>👋</span></h1>
          <p className="lead" style={{ textTransform: "capitalize" }}>Tuesday, April 30, 2026</p>
        </div>
        <div className="ihome-hero" style={{ display: "grid", gridTemplateColumns: "repeat(3, minmax(0,1fr))", gap: 16 }}>
          <HeroCardI title="Clock In"  subtitle="Click to register your work day" onClick={() => go("ponto/me")}        icon={<ClockIcon size={32} color="#fff" />} gradient="linear-gradient(135deg, #10B981 0%, #047857 100%)" shadow="0 14px 28px -10px rgba(5,150,105,0.45)" />
          <HeroCardI title="Logistics" subtitle="4 drivers active"                 onClick={() => go("logistics/dash")}  icon={<TruckIcon size={32} color="#fff" />} gradient="linear-gradient(135deg, #F97316 0%, #C2410C 100%)" shadow="0 14px 28px -10px rgba(249,115,22,0.45)" />
          <HeroCardI title="Training"  subtitle="Quizzes, modules & basics"        onClick={() => go("comms/training")}  icon={<CapIcon size={32} color="#fff" />}   gradient="linear-gradient(135deg, #3B82F6 0%, #1D4ED8 100%)" shadow="0 14px 28px -10px rgba(29,78,216,0.45)" />
        </div>

        <div style={{ height: 1, background: "#e5e7eb" }}></div>

        <div style={{ display: "grid", gridTemplateColumns: "2fr 1fr", gap: 16 }}>
          <div className="icard" style={{ padding: 0, overflow: "hidden" }}>
            <div style={{ display: "flex", alignItems: "center", padding: "10px 16px", borderBottom: "1px solid #e6eaf0" }}>
              <button style={{ background:"transparent", border:0, cursor:"pointer", padding:4 }}><ChevronLeftIcon size={16} /></button>
              <div style={{ flex: 1, textAlign: "center" }}>
                <span style={{ fontWeight: 700, fontSize: 14 }}>04/30</span>
                <span style={{ marginLeft: 6, fontSize: 10, fontWeight: 600, background: "#059669", color: "#fff", borderRadius: 10, padding: "2px 7px", verticalAlign: "middle" }}>Today</span>
                <span style={{ fontSize: 12, color: "#6b7280", marginLeft: 8 }}>Tuesday</span>
              </div>
              <button style={{ background:"transparent", border:0, cursor:"pointer", padding:4 }}><ChevronRightIcon size={16} /></button>
            </div>
            <div style={{ display: "grid", gridTemplateColumns: "1fr 1fr" }}>
              <div style={{ padding: "14px 16px", borderRight: "1px solid #e6eaf0" }}>
                <div style={{ display: "flex", justifyContent: "space-between", alignItems: "center", marginBottom: 8 }}>
                  <button style={{ background:"transparent", border:0, cursor:"pointer", padding:2 }}><ChevronLeftIcon size={13} /></button>
                  <div style={{ fontSize: 11, fontWeight: 700, textTransform: "uppercase", letterSpacing: "0.05em" }}>April 2026</div>
                  <button style={{ background:"transparent", border:0, cursor:"pointer", padding:2 }}><ChevronRightIcon size={13} /></button>
                </div>
                <div style={{ display: "grid", gridTemplateColumns: "repeat(7,1fr)", gap: 2, marginBottom: 4 }}>
                  {["S","M","T","W","T","F","S"].map((d,i) => (<div key={i} style={{ textAlign: "center", fontSize: 9, color: "#6b7280", fontWeight: 600, padding: "2px 0" }}>{d}</div>))}
                  {Array.from({ length: 35 }, (_, i) => {
                    const day = i - 2;
                    if (day < 1 || day > 30) return <div key={i}/>;
                    const isToday = day === 30;
                    const hasTasks = [3, 7, 12, 18, 22, 25, 30].includes(day);
                    const hasEvt = [5, 14, 21, 28].includes(day);
                    return (
                      <div key={i} style={{ textAlign: "center", fontSize: 11, padding: "3px 1px 7px", borderRadius: 5, cursor: "pointer", background: isToday ? "#0B2545" : "transparent", color: isToday ? "#fff" : "#1f2937", fontWeight: isToday ? 700 : 400, position: "relative" }}>
                        {day}
                        {(hasTasks || hasEvt) && (
                          <span style={{ position: "absolute", bottom: 2, left: "50%", transform: "translateX(-50%)", display: "flex", gap: 2 }}>
                            {hasTasks && <span style={{ width: 4, height: 4, background: isToday ? "#fff" : "#059669", borderRadius: "50%" }}></span>}
                            {hasEvt && <span style={{ width: 4, height: 4, background: isToday ? "#fff" : "#3B82F6", borderRadius: "50%" }}></span>}
                          </span>
                        )}
                      </div>
                    );
                  })}
                </div>
              </div>
              <div style={{ padding: "14px 16px", display: "flex", flexDirection: "column", gap: 8 }}>
                <div style={{ display: "flex", justifyContent: "space-between", alignItems: "center" }}>
                  <div style={{ fontSize: 11, fontWeight: 700, textTransform: "uppercase", letterSpacing: "0.05em" }}>Today's Tasks</div>
                  <span style={{ fontSize: 10, color: "#6b7280" }}>3 done · 2 pending</span>
                </div>
                {[
                  { text: "Call Northwest Power — quote follow-up", tag: "commercial", done: false },
                  { text: "Approve Yukon Mining repeater repair",   tag: "at",         done: false },
                  { text: "Send invoice to Pacific Logistics",      tag: "rental",     done: true },
                  { text: "Verify driver Carlos route #4",           tag: "logistics",  done: true },
                  { text: "Schedule monthly retro with Lucas",       tag: "commercial", done: true },
                ].map((t, i) => (
                  <div key={i} style={{ display: "flex", alignItems: "flex-start", gap: 8, fontSize: 12.5, color: t.done ? "#9ca3af" : "#1f2937", textDecoration: t.done ? "line-through" : "none" }}>
                    <span style={{ width: 14, height: 14, marginTop: 2, border: "1.5px solid " + (t.done ? "#9ca3af" : "#0B2545"), borderRadius: 3, background: t.done ? "#0B2545" : "transparent", color: "#fff", display: "grid", placeItems: "center", fontSize: 9, flexShrink: 0 }}>{t.done ? "✓" : ""}</span>
                    <span style={{ fontSize: 9.5, fontWeight: 700, color: TASK_TAG[t.tag].color, background: TASK_TAG[t.tag].bg, border: "1px solid " + TASK_TAG[t.tag].border, borderRadius: 999, padding: "1px 7px", textTransform: "uppercase", letterSpacing: "0.04em", flexShrink: 0, marginTop: 1 }}>{TASK_TAG[t.tag].label}</span>
                    <span style={{ flex: 1 }}>{t.text}</span>
                  </div>
                ))}
              </div>
            </div>
          </div>

          <div className="icard" style={{ padding: 0, overflow: "hidden" }}>
            <div style={{ padding: "10px 16px", borderBottom: "1px solid #e6eaf0", display: "flex", alignItems: "center", gap: 8 }}>
              <MegaIcon size={15} color="#4338CA" />
              <span style={{ fontSize: 14, fontWeight: 700, flex: 1 }}>Important Notices</span>
            </div>
            {[
              { ic: MegaIcon,    bg: "rgba(99,102,241,.14)",  fg: "#4338CA", title: "New Q3 Branding Guidelines",      sub: "Please review the updated logo and color palette by next Monday.",   t: "2 h ago" },
              { ic: ShieldIcon2, bg: "rgba(16,185,129,.14)",  fg: "#047857", title: "Security Training Mandatory",     sub: "Phishing simulation results shared — module #3 expires May 15.",       t: "yesterday" },
              { ic: CalIcon,     bg: "rgba(249,115,22,.14)",  fg: "#C2410C", title: "Office Closed · Victoria Day",     sub: "Monday, May 19 — emergency line will remain available 24h.",            t: "2 d ago" },
            ].map((n, i) => {
              const Ic = n.ic;
              return (
                <div key={i} style={{ padding: "12px 16px", borderBottom: i < 2 ? "1px solid #e6eaf0" : "none", display: "flex", gap: 10 }}>
                  <div style={{ width: 32, height: 32, borderRadius: 8, background: n.bg, color: n.fg, display: "grid", placeItems: "center", flexShrink: 0 }}>
                    <Ic size={16} color={n.fg} />
                  </div>
                  <div style={{ minWidth: 0, flex: 1 }}>
                    <div style={{ fontSize: 12.5, fontWeight: 600, lineHeight: 1.3 }}>{n.title}</div>
                    <div style={{ fontSize: 11.5, color: "#6b7280", marginTop: 3, lineHeight: 1.4 }}>{n.sub}</div>
                    <div style={{ fontSize: 10, color: "#9ca3af", marginTop: 4 }}>{n.t}</div>
                  </div>
                </div>
              );
            })}
          </div>
        </div>

        <div style={{ height: 1, background: "#e5e7eb" }}></div>

        <div className="icard" style={{ padding: "12px 16px", display: "flex", alignItems: "center", gap: 12, borderLeft: "4px solid #f59e0b" }}>
          <BulbIcon size={18} color="#f59e0b" />
          <div style={{ flex: 1 }}>
            <div style={{ display: "flex", alignItems: "center", gap: 8, marginBottom: 4 }}>
              <span style={{ fontSize: 10, fontWeight: 700, color: "#6b7280", textTransform: "uppercase", letterSpacing: "0.07em" }}>Daily Tip</span>
              <span style={{ fontSize: 10, fontWeight: 700, color: "#7C3AED", background: "rgba(124,58,237,0.08)", border: "1px solid rgba(124,58,237,0.2)", borderRadius: 999, padding: "2px 8px", textTransform: "uppercase", letterSpacing: "0.05em" }}>📡 Radio Communications</span>
            </div>
            <div style={{ fontWeight: 700, fontSize: 13, marginBottom: 2 }}>Check the battery before delivery</div>
            <div style={{ fontSize: 12, color: "#4b5563", lineHeight: 1.5 }}>Always confirm full charge and run a transmission test before handing a radio over to the customer. Prevents avoidable support calls.</div>
          </div>
          <span style={{ fontSize: 12, color: "#6b7280" }}>3 / 12</span>
        </div>

        <style>{`
          @media (max-width: 1100px) { .ihome-hero { grid-template-columns: 1fr 1fr !important; } }
          @media (max-width: 720px) { .ihome-hero { grid-template-columns: 1fr !important; } }
        `}</style>
      </div>
    );
  }

  /* ──── Time Clock module ──── */
  function IntranetPonto({ view }) {
    if (view === "me") {
      const STEPS = [
        { id: "in",   label: "Clock In",     hint: "Start of day",       done: "08:42", color: "#10B981", grad: "linear-gradient(135deg,#10B981,#34d399)" },
        { id: "out",  label: "Lunch Out",    hint: "Pause for lunch",    done: "12:04", color: "#F97316", grad: "linear-gradient(135deg,#F97316,#fb923c)" },
        { id: "back", label: "Lunch Return", hint: "Back from lunch",    done: "13:01", color: "#3B82F6", grad: "linear-gradient(135deg,#3B82F6,#60a5fa)" },
        { id: "fin",  label: "Clock Out",    hint: "End of day",         done: null,    color: "#8B5CF6", grad: "linear-gradient(135deg,#8B5CF6,#a78bfa)" },
      ];
      const activeStepIdx = STEPS.findIndex((s) => !s.done);
      return (
        <div style={{
          position: "relative", margin: "-18px", padding: "40px 24px 60px",
          background: "linear-gradient(180deg,#f8fafc 0%,#eef2f7 100%)",
          minHeight: 720, overflow: "hidden",
        }}>
          {/* radial gradients (corners) */}
          <div style={{ position: "absolute", inset: 0, pointerEvents: "none",
            background:
              "radial-gradient(circle at 0% 0%, rgba(16,185,129,0.10), transparent 40%)," +
              "radial-gradient(circle at 100% 0%, rgba(249,115,22,0.10), transparent 40%)," +
              "radial-gradient(circle at 0% 100%, rgba(59,130,246,0.10), transparent 45%)," +
              "radial-gradient(circle at 100% 100%, rgba(139,92,246,0.10), transparent 45%)",
          }}></div>
          {/* dot pattern overlay */}
          <div style={{ position: "absolute", inset: 0, pointerEvents: "none", opacity: 0.4,
            backgroundImage: "radial-gradient(rgba(15,23,42,0.06) 1px, transparent 1px)",
            backgroundSize: "24px 24px",
          }}></div>

          <div style={{ position: "relative", maxWidth: 980, margin: "0 auto", display: "flex", flexDirection: "column", alignItems: "center", gap: 22 }}>
            {/* Greeting */}
            <div style={{ textAlign: "center" }}>
              <div style={{ fontFamily: "Space Grotesk, sans-serif", fontSize: 32, fontWeight: 800, letterSpacing: "-0.02em", color: "#0f172a" }}>Hello, Demo!</div>
              <div style={{ fontSize: 13, color: "#64748b", marginTop: 4 }}>Tuesday, April 30 · 2026</div>
            </div>

            {/* Status pill */}
            <div style={{
              display: "inline-flex", alignItems: "center", gap: 8,
              background: "linear-gradient(135deg,#10B981,#059669)", color: "#fff",
              padding: "6px 14px", borderRadius: 999, fontSize: 12, fontWeight: 600,
              boxShadow: "0 4px 12px rgba(16,185,129,0.25)",
            }}>
              <span style={{ width: 8, height: 8, borderRadius: "50%", background: "#fff", animation: "pulse 1.8s infinite ease-out" }}></span>
              System synchronized
            </div>

            {/* Live clock */}
            <div style={{ textAlign: "center", margin: "8px 0 4px" }}>
              <div style={{
                fontFamily: "JetBrains Mono, monospace", fontSize: 56, fontWeight: 700,
                color: "#0B2545", letterSpacing: "-0.03em", lineHeight: 1,
              }}>14:27:08</div>
              <div style={{ fontSize: 11, color: "#64748b", marginTop: 6, letterSpacing: "0.06em", display: "flex", alignItems: "center", justifyContent: "center", gap: 6 }}>
                <ClockIcon size={12} color="#64748b" /> Official local time · Vancouver, BC
              </div>
            </div>

            {/* 4 step cards */}
            <div style={{ display: "grid", gridTemplateColumns: "repeat(4, 1fr)", gap: 16, width: "100%" }}>
              {STEPS.map((s, i) => {
                const isDone = !!s.done;
                const isActive = i === activeStepIdx;
                return (
                  <div key={s.id} style={{
                    position: "relative",
                    background: "#fff",
                    border: "1px solid " + (isActive ? s.color : "#e5e7eb"),
                    borderRadius: 16, padding: 20,
                    boxShadow: isActive ? "0 12px 28px " + s.color + "33" : "0 2px 6px rgba(15,23,42,0.04)",
                    transform: isActive ? "translateY(-3px)" : "none",
                    transition: "all 200ms ease",
                  }}>
                    {isDone && (
                      <div style={{
                        position: "absolute", top: 10, right: 10,
                        width: 22, height: 22, borderRadius: "50%",
                        background: "#10B981", color: "#fff",
                        display: "grid", placeItems: "center", fontSize: 12, fontWeight: 800,
                        boxShadow: "0 2px 6px rgba(16,185,129,0.4)",
                      }}>✓</div>
                    )}
                    <div style={{
                      width: 46, height: 46, borderRadius: 12,
                      background: s.grad, color: "#fff",
                      display: "grid", placeItems: "center",
                      boxShadow: "0 6px 16px " + s.color + "44",
                      marginBottom: 14,
                    }}>
                      <ClockIcon size={22} color="#fff" />
                    </div>
                    <div style={{ fontSize: 12, color: s.color, fontWeight: 700, letterSpacing: "0.04em", textTransform: "uppercase" }}>{s.label}</div>
                    <div style={{
                      fontFamily: "JetBrains Mono, monospace",
                      fontSize: isDone ? 22 : 13,
                      fontWeight: 700, color: isDone ? "#0f172a" : "#94a3b8",
                      marginTop: 6,
                    }}>{isDone || s.hint}</div>
                    <div style={{
                      marginTop: 12, height: 4, borderRadius: 4,
                      background: "#e5e7eb", overflow: "hidden",
                    }}>
                      <div style={{
                        width: isDone ? "100%" : isActive ? "50%" : "0%",
                        height: "100%", borderRadius: 4,
                        background: s.grad,
                        transition: "width 600ms ease",
                      }}></div>
                    </div>
                  </div>
                );
              })}
            </div>

            {/* Status message */}
            <div style={{
              width: "100%", padding: "14px 18px",
              background: "linear-gradient(135deg,rgba(59,130,246,0.08),rgba(139,92,246,0.08))",
              border: "1px solid rgba(59,130,246,0.25)",
              borderRadius: 14, display: "flex", alignItems: "center", gap: 12, color: "#1e3a5f",
            }}>
              <div style={{ width: 32, height: 32, borderRadius: "50%", background: "#3B82F6", color: "#fff", display: "grid", placeItems: "center", fontWeight: 800 }}>i</div>
              <div style={{ flex: 1 }}>
                <div style={{ fontWeight: 700, fontSize: 14 }}>Currently working — 5h 26min logged today</div>
                <div style={{ fontSize: 12, color: "#475569", marginTop: 2 }}>Next action: Clock Out · target 18:00</div>
              </div>
            </div>

            {/* Absence button */}
            <button style={{
              background: "linear-gradient(135deg,#ef4444,#dc2626)", color: "#fff",
              border: "none", padding: "12px 24px", borderRadius: 12,
              fontSize: 13, fontWeight: 700, cursor: "pointer",
              boxShadow: "0 8px 20px rgba(220,38,38,0.25)",
              fontFamily: "Inter, sans-serif",
              display: "inline-flex", alignItems: "center", gap: 8,
            }}>
              <span>⊘</span> Register absence / medical certificate
            </button>

            {/* Security pill */}
            <div style={{
              display: "inline-flex", alignItems: "center", gap: 8,
              background: "rgba(59,130,246,0.08)", color: "#1d4ed8",
              padding: "6px 14px", borderRadius: 999, fontSize: 11, fontWeight: 600,
              border: "1px solid rgba(59,130,246,0.2)",
            }}>
              <ShieldIcon size={12} color="#1d4ed8" /> Your records are encrypted and tamper-proof
            </div>
          </div>
        </div>
      );
    }
    if (view === "history") {
      return (
        <div className="ipage" style={{ display: "flex", flexDirection: "column", gap: 16 }}>
          <div><h1>Time Clock History</h1><p className="lead">All your registered shifts · April 2026</p></div>
          <div className="icard" style={{ padding: 0, overflow: "hidden" }}>
            <table style={{ width: "100%", borderCollapse: "collapse", fontSize: 13 }}>
              <thead style={{ background: "#f7f8fa" }}><tr style={{ color: "#6b7280", textAlign: "left" }}>
                <th style={{ padding: "10px 16px" }}>Date</th><th style={{ padding: "10px 16px" }}>Clock-in</th><th style={{ padding: "10px 16px" }}>Clock-out</th><th style={{ padding: "10px 16px" }}>Total</th><th style={{ padding: "10px 16px" }}>Status</th>
              </tr></thead>
              <tbody>
                {[
                  { d: "Apr 29 (Mon)", i: "08:30", o: "17:42", h: "8h 12m", s: "OK", c: "#059669" },
                  { d: "Apr 26 (Fri)", i: "08:55", o: "18:05", h: "8h 10m", s: "OK", c: "#059669" },
                  { d: "Apr 25 (Thu)", i: "09:11", o: "18:33", h: "8h 22m", s: "Late start", c: "#D97706" },
                  { d: "Apr 24 (Wed)", i: "08:24", o: "17:30", h: "8h 06m", s: "OK", c: "#059669" },
                  { d: "Apr 23 (Tue)", i: "08:01", o: "16:58", h: "7h 57m", s: "Pending review", c: "#7C3AED" },
                ].map((r, i) => (
                  <tr key={i} style={{ borderTop: "1px solid #e6eaf0" }}>
                    <td style={{ padding: "11px 16px", fontWeight: 500 }}>{r.d}</td>
                    <td style={{ padding: "11px 16px", fontFamily: "JetBrains Mono" }}>{r.i}</td>
                    <td style={{ padding: "11px 16px", fontFamily: "JetBrains Mono" }}>{r.o}</td>
                    <td style={{ padding: "11px 16px", fontWeight: 600, color: "#0B2545" }}>{r.h}</td>
                    <td style={{ padding: "11px 16px" }}><span className="ipill" style={{ color: r.c, background: r.c + "15", border: "1px solid " + r.c + "33" }}>● {r.s}</span></td>
                  </tr>
                ))}
              </tbody>
            </table>
          </div>
        </div>
      );
    }
    return (
      <div className="ipage" style={{ display: "flex", flexDirection: "column", gap: 16 }}>
        <div><h1>Approvals · HR</h1><p className="lead">Manual time entries waiting for review</p></div>
        <div className="icard" style={{ padding: 0, overflow: "hidden" }}>
          {[
            { who: "Carlos Lopez",    role: "Driver",       d: "Apr 24",    reason: "Forgot clock-out — finished route at 18:00" },
            { who: "Mariana Souza",   role: "Tech Support", d: "Apr 22",    reason: "On-site at customer, no terminal access" },
            { who: "Hiroshi Tanaka",  role: "Account Mgr",  d: "Apr 19",    reason: "Travel day · approved by Lucas (verbal)" },
          ].map((p, i) => (
            <div key={i} style={{ display: "flex", gap: 14, padding: "14px 18px", borderTop: i ? "1px solid #e6eaf0" : "none", alignItems: "center" }}>
              <div style={{ width: 36, height: 36, borderRadius: "50%", background: "linear-gradient(135deg,#5ab7ff,#1e6fb0)", color: "#fff", display: "grid", placeItems: "center", fontWeight: 700, fontSize: 13 }}>{p.who.split(" ").map(x => x[0]).join("")}</div>
              <div style={{ flex: 1, minWidth: 0 }}>
                <div style={{ fontWeight: 600 }}>{p.who} <span style={{ color: "#6b7280", fontWeight: 400, fontSize: 12 }}>· {p.role}</span></div>
                <div style={{ fontSize: 12.5, color: "#4b5563", marginTop: 2 }}><strong>{p.d}</strong> · {p.reason}</div>
              </div>
              <div style={{ display: "flex", gap: 6 }}>
                <button className="ibtn-green">✓ Approve</button>
                <button className="ibtn-sec" style={{ color: "#dc2626", borderColor: "#fca5a5" }}>✕ Deny</button>
              </div>
            </div>
          ))}
        </div>
      </div>
    );
  }

  /* ──── Technical Service module ──── */
  function IntranetATKanban() {
    const [monthFilter, setMonthFilter] = useState("quote");
    const cols = [
      { id: "intake",  label: "Intake",            color: "#94a3b8", count: 4 },
      { id: "diag",    label: "In Diagnostic",     color: "#F59E0B", count: 6 },
      { id: "quote",   label: "Awaiting Quote",    color: "#0891B2", count: 3 },
      { id: "repair",  label: "In Repair",         color: "#7C3AED", count: 5 },
      { id: "ready",   label: "Ready for Pickup",  color: "#059669", count: 2 },
    ];
    const cards = [
      { col: "intake", id: "1198", c: "Pacific Logistics",  e: "MOTOTRBO XPR3500e",  age: 1 },
      { col: "intake", id: "1199", c: "Granite Construction", e: "DEM 400",          age: 0 },
      { col: "diag",   id: "1187", c: "Northwest Power Co.", e: "MOTOTRBO XPR3500e", age: 3 },
      { col: "diag",   id: "1192", c: "Aurora Logistics",   e: "XPR 7550e",          age: 12 },
      { col: "quote",  id: "1188", c: "Pacific Logistics",  e: "DEM 400 (Mobile)",   age: 5 },
      { col: "repair", id: "1189", c: "Yukon Mining Group", e: "SLR 5700 Repeater",  age: 8 },
      { col: "repair", id: "1191", c: "Granite Construction", e: "SL 2600 (UHF)",    age: 2 },
      { col: "ready",  id: "1190", c: "Coast Security Ltd.", e: "CP200d (Portable)", age: 1 },
    ];
    return (
      <div className="ipage" style={{ display: "flex", flexDirection: "column", gap: 16 }}>
        <div style={{ display: "flex", justifyContent: "space-between", alignItems: "flex-start" }}>
          <div><h1>Service Kanban</h1><p className="lead">Drag cards between columns to update status</p></div>
          <div style={{ display: "flex", gap: 8 }}><button className="ibtn-sec">Filter</button><button className="ibtn-blue">+ New OS</button></div>
        </div>
        <div style={{ display: "grid", gridTemplateColumns: "repeat(5, 1fr)", gap: 10 }}>
          {cols.map((col) => (
            <div key={col.id} style={{ background: "#f7f8fa", border: "1px solid #e6eaf0", borderRadius: 6, padding: 10, minHeight: 380 }}>
              <div style={{ display: "flex", alignItems: "center", justifyContent: "space-between", marginBottom: 10, paddingBottom: 10, borderBottom: "2px solid " + col.color }}>
                <span style={{ fontWeight: 700, fontSize: 12, color: col.color, textTransform: "uppercase", letterSpacing: "0.04em" }}>{col.label}</span>
                <span style={{ fontSize: 11, fontWeight: 700, background: col.color + "22", color: col.color, padding: "2px 8px", borderRadius: 999 }}>{col.count}</span>
              </div>
              <div style={{ display: "flex", flexDirection: "column", gap: 8 }}>
                {cards.filter((c) => c.col === col.id).map((c) => (
                  <div key={c.id} style={{ background: "#fff", border: "1px solid #e6eaf0", borderRadius: 6, padding: 10, fontSize: 12, boxShadow: "0 1px 2px rgba(16,24,40,.04)" }}>
                    <div style={{ fontFamily: "JetBrains Mono", color: "#0B2545", fontWeight: 600, fontSize: 11 }}>OS-2026-{c.id}</div>
                    <div style={{ fontWeight: 600, marginTop: 3 }}>{c.c}</div>
                    <div style={{ color: "#6b7280", fontSize: 11, marginTop: 2 }}>{c.e}</div>
                    <div style={{ marginTop: 8, fontSize: 10, color: c.age > 7 ? "#DC2626" : c.age > 3 ? "#D97706" : "#059669", fontWeight: 600 }}>● {c.age}d in queue</div>
                  </div>
                ))}
              </div>
            </div>
          ))}
        </div>

        {/* Bottom strip — Month-of-OS view + 4 KPI filter tabs + data table */}
        <div className="icard" style={{ padding: 0, overflow: "hidden", marginTop: 6 }}>
          {/* Dark navy header */}
          <div style={{
            background: "#0B2545", color: "#fff",
            padding: "12px 18px",
            display: "flex", alignItems: "center", justifyContent: "space-between", gap: 12,
          }}>
            <div style={{ display: "flex", alignItems: "center", gap: 12 }}>
              <button style={{ background: "rgba(255,255,255,0.1)", border: "none", color: "#fff", width: 28, height: 28, borderRadius: 6, cursor: "pointer", display: "grid", placeItems: "center" }} title="Previous month">‹</button>
              <strong style={{ fontFamily: "Space Grotesk, sans-serif", fontSize: 15, letterSpacing: "0.01em" }}>OS this Month — April 2026</strong>
              <button style={{ background: "rgba(255,255,255,0.1)", border: "none", color: "#fff", width: 28, height: 28, borderRadius: 6, cursor: "pointer", display: "grid", placeItems: "center" }} title="Next month">›</button>
            </div>
            <span style={{ fontSize: 12, color: "rgba(255,255,255,0.7)" }}>62 records</span>
          </div>

          {/* 4 KPI filter tabs */}
          <div style={{ display: "grid", gridTemplateColumns: "repeat(4, 1fr)" }}>
            {[
              { id: "quote",    label: "Generating Quote",    n: 12, color: "#0891B2" },
              { id: "approval", label: "Awaiting Approval",  n: 18, color: "#D97706" },
              { id: "approved", label: "Approved",            n: 24, color: "#059669" },
              { id: "rejected", label: "Rejected",            n: 8,  color: "#DC2626" },
            ].map((k) => {
              const a = monthFilter === k.id;
              return (
                <button key={k.id} onClick={() => setMonthFilter(k.id)} style={{
                  border: 0, padding: "14px 16px", cursor: "pointer",
                  background: a ? k.color + "10" : "#fff",
                  borderBottom: "3px solid " + (a ? k.color : "transparent"),
                  borderRight: "1px solid #e6eaf0",
                  textAlign: "left", fontFamily: "Inter, sans-serif",
                  display: "flex", flexDirection: "column", gap: 4,
                }}>
                  <span style={{ fontSize: 11, color: a ? k.color : "#6b7280", fontWeight: 700, letterSpacing: "0.06em", textTransform: "uppercase" }}>{k.label}</span>
                  <span style={{ fontSize: 22, fontWeight: 800, color: k.color, fontFamily: "Space Grotesk, sans-serif" }}>{k.n}</span>
                </button>
              );
            })}
          </div>

          {/* Data table */}
          <table style={{ width: "100%", borderCollapse: "collapse", fontSize: 13 }}>
            <thead style={{ background: "#f7f8fa" }}><tr style={{ color: "#6b7280", textAlign: "left" }}>
              <th style={{ padding: "10px 16px", width: 50 }}>#</th>
              <th style={{ padding: "10px 16px" }}>OS</th>
              <th style={{ padding: "10px 16px" }}>Client</th>
              <th style={{ padding: "10px 16px" }}>Equipment</th>
              <th style={{ padding: "10px 16px" }}>Status</th>
              <th style={{ padding: "10px 16px" }}>Date</th>
            </tr></thead>
            <tbody>
              {[
                { n: 1, os: "OS-2026-1198", c: "Pacific Logistics",     e: "MOTOTRBO XPR3500e",  s: "Generating Quote",  sc: "#0891B2", d: "Apr 28" },
                { n: 2, os: "OS-2026-1192", c: "Aurora Logistics",      e: "XPR 7550e",          s: "Awaiting Approval", sc: "#D97706", d: "Apr 24" },
                { n: 3, os: "OS-2026-1187", c: "Northwest Power Co.",   e: "MOTOTRBO XPR3500e",  s: "Awaiting Approval", sc: "#D97706", d: "Apr 22" },
                { n: 4, os: "OS-2026-1190", c: "Coast Security Ltd.",   e: "CP200d (Portable)",  s: "Approved",          sc: "#059669", d: "Apr 21" },
                { n: 5, os: "OS-2026-1188", c: "Pacific Logistics",     e: "DEM 400 (Mobile)",   s: "Generating Quote",  sc: "#0891B2", d: "Apr 19" },
                { n: 6, os: "OS-2026-1180", c: "Aurora Logistics",      e: "SLR 8000 Repeater",  s: "Approved",          sc: "#059669", d: "Apr 17" },
                { n: 7, os: "OS-2026-1175", c: "Granite Construction",  e: "DEM 400",            s: "Rejected",          sc: "#DC2626", d: "Apr 15" },
              ].map((r) => (
                <tr key={r.n} style={{ borderTop: "1px solid #e6eaf0" }}>
                  <td style={{ padding: "11px 16px", color: "#94a3b8", fontWeight: 600 }}>{r.n}</td>
                  <td style={{ padding: "11px 16px", fontFamily: "JetBrains Mono", color: "#0B2545", fontWeight: 600 }}>{r.os}</td>
                  <td style={{ padding: "11px 16px" }}>{r.c}</td>
                  <td style={{ padding: "11px 16px", color: "#475569" }}>{r.e}</td>
                  <td style={{ padding: "11px 16px" }}><span className="ipill" style={{ color: r.sc, background: r.sc + "15", border: "1px solid " + r.sc + "33" }}>● {r.s}</span></td>
                  <td style={{ padding: "11px 16px", color: "#6b7280", fontFamily: "JetBrains Mono", fontSize: 12 }}>{r.d}</td>
                </tr>
              ))}
            </tbody>
          </table>

          {/* Table pagination footer */}
          <div style={{
            background: "#f7f8fa", padding: "10px 16px",
            display: "flex", justifyContent: "space-between", alignItems: "center",
            fontSize: 12, color: "#6b7280", borderTop: "1px solid #e6eaf0",
          }}>
            <span>Showing 1–7 of 62 · Page 1 of 9</span>
            <div style={{ display: "flex", gap: 8 }}>
              <button className="ibtn-sec" disabled style={{ opacity: 0.5 }}>‹ Previous</button>
              <button className="ibtn-sec">Next ›</button>
            </div>
          </div>
        </div>
      </div>
    );
  }
  function IntranetATCalendar() {
    return (
      <div className="ipage" style={{ display: "flex", flexDirection: "column", gap: 16 }}>
        <div><h1>Service Calendar</h1><p className="lead">Scheduled diagnostics, deliveries and on-site visits</p></div>
        <div className="icard" style={{ padding: 0, overflow: "hidden" }}>
          <div style={{ display: "grid", gridTemplateColumns: "repeat(7, 1fr)", borderBottom: "1px solid #d7dde5", background: "#f7f8fa" }}>
            {["Mon 28", "Tue 29", "Wed 30", "Thu 01", "Fri 02", "Sat 03", "Sun 04"].map((d, i) => (
              <div key={i} style={{ padding: 10, fontSize: 11, fontWeight: 700, color: "#6b7280", textTransform: "uppercase", letterSpacing: "0.05em", borderRight: i < 6 ? "1px solid #e6eaf0" : "none", textAlign: "center" }}>{d}</div>
            ))}
          </div>
          <div style={{ display: "grid", gridTemplateColumns: "repeat(7, 1fr)", minHeight: 360 }}>
            {[
              [{ t: "10:00", l: "Northwest Power · diagnostic", c: "#F59E0B" }],
              [{ t: "09:30", l: "Pacific Logistics · pickup", c: "#059669" }, { t: "14:00", l: "Granite · on-site", c: "#7C3AED" }],
              [{ t: "11:15", l: "Yukon Mining · delivery", c: "#0891B2" }],
              [{ t: "08:45", l: "Coast Security · install", c: "#7C3AED" }],
              [{ t: "10:30", l: "Aurora Logistics · audit", c: "#F59E0B" }, { t: "15:30", l: "Demo training", c: "#3B82F6" }],
              [], [],
            ].map((day, i) => (
              <div key={i} style={{ padding: 8, borderRight: i < 6 ? "1px solid #e6eaf0" : "none", borderTop: "1px solid #e6eaf0", display: "flex", flexDirection: "column", gap: 6 }}>
                {day.map((ev, j) => (
                  <div key={j} style={{ background: ev.c + "15", border: "1px solid " + ev.c + "44", borderLeft: "3px solid " + ev.c, borderRadius: 4, padding: "5px 8px", fontSize: 11 }}>
                    <div style={{ fontWeight: 700, color: ev.c, fontSize: 10 }}>{ev.t}</div>
                    <div style={{ color: "#1f2937", marginTop: 2 }}>{ev.l}</div>
                  </div>
                ))}
              </div>
            ))}
          </div>
        </div>
      </div>
    );
  }
  function IntranetATCosts() {
    const months = [
      { m: "Jan", v: 12.4 }, { m: "Feb", v: 15.8 }, { m: "Mar", v: 18.2 }, { m: "Apr", v: 22.1 },
    ];
    return (
      <div className="ipage" style={{ display: "flex", flexDirection: "column", gap: 16 }}>
        <div><h1>Month Analysis</h1><p className="lead">Service revenue, costs and margin · year-to-date</p></div>
        <div style={{ display: "grid", gridTemplateColumns: "repeat(4, 1fr)", gap: 14 }}>
          {[
            { l: "Revenue YTD",  v: "$ 68.5k", sub: "+18% MoM", c: "#3fa055" },
            { l: "Parts Cost",   v: "$ 24.1k", sub: "-3% MoM",  c: "#0B2545" },
            { l: "Labor Hours",  v: "412h",    sub: "+22% MoM", c: "#F59E0B" },
            { l: "Margin",       v: "64.7%",   sub: "+2.4 pp",  c: "#7C3AED" },
          ].map((k) => (
            <div key={k.l} className="icard" style={{ padding: 18 }}>
              <div style={{ fontSize: 11, color: "#6b7280", letterSpacing: "0.08em", textTransform: "uppercase" }}>{k.l}</div>
              <div style={{ fontFamily: "Space Grotesk, sans-serif", fontSize: 28, fontWeight: 700, color: k.c, marginTop: 6, lineHeight: 1 }}>{k.v}</div>
              <div style={{ fontSize: 12, color: k.c, marginTop: 4 }}>{k.sub}</div>
            </div>
          ))}
        </div>
        <div className="icard" style={{ padding: 18 }}>
          <div style={{ fontWeight: 700, marginBottom: 14 }}>Revenue trend (k$)</div>
          <div style={{ display: "flex", alignItems: "flex-end", gap: 24, height: 200, padding: "0 10px" }}>
            {months.map((m, i) => (
              <div key={i} style={{ flex: 1, display: "flex", flexDirection: "column", alignItems: "center", gap: 8 }}>
                <div style={{ fontSize: 11, color: "#0B2545", fontWeight: 700 }}>{m.v}k</div>
                <div style={{ width: "100%", height: m.v * 7, background: "linear-gradient(180deg, #1E5BA8, #0B2545)", borderRadius: "4px 4px 0 0" }}></div>
                <div style={{ fontSize: 11, color: "#6b7280", fontWeight: 600 }}>{m.m}</div>
              </div>
            ))}
          </div>
        </div>
      </div>
    );
  }
  function IntranetATParts() {
    const parts = [
      { sku: "MOT-PMNN4407",   name: "Battery Li-Ion 2350mAh — XPR3500e", stock: 24, min: 8,  status: "OK" },
      { sku: "MOT-RLN6551",    name: "Antenna VHF 136-174 MHz",            stock: 6,  min: 8,  status: "Low" },
      { sku: "MOT-HKLN4604",   name: "Speaker mic w/ 3.5mm jack",          stock: 11, min: 5,  status: "OK" },
      { sku: "MOT-PMLN5868",   name: "Belt clip — XPR series",             stock: 2,  min: 6,  status: "Critical" },
      { sku: "MOT-PMUE4097",   name: "Front housing — DEM 400",            stock: 14, min: 4,  status: "OK" },
      { sku: "MOT-PMLN7260",   name: "Holster pouch CP200d",                stock: 8,  min: 4,  status: "OK" },
    ];
    return (
      <div className="ipage" style={{ display: "flex", flexDirection: "column", gap: 16 }}>
        <div style={{ display: "flex", justifyContent: "space-between" }}>
          <div><h1>Parts Inventory</h1><p className="lead">{parts.length} active SKUs · 1,287 total units</p></div>
          <button className="ibtn-blue">+ Receive parts</button>
        </div>
        <div className="icard" style={{ padding: 0, overflow: "hidden" }}>
          <table style={{ width: "100%", borderCollapse: "collapse", fontSize: 13 }}>
            <thead style={{ background: "#f7f8fa" }}><tr style={{ color: "#6b7280", textAlign: "left" }}>
              <th style={{ padding: "10px 16px" }}>SKU</th><th style={{ padding: "10px 16px" }}>Description</th><th style={{ padding: "10px 16px" }}>Stock</th><th style={{ padding: "10px 16px" }}>Min</th><th style={{ padding: "10px 16px" }}>Status</th>
            </tr></thead>
            <tbody>
              {parts.map((p) => {
                const c = p.status === "Critical" ? "#DC2626" : p.status === "Low" ? "#D97706" : "#059669";
                return (
                  <tr key={p.sku} style={{ borderTop: "1px solid #e6eaf0" }}>
                    <td style={{ padding: "11px 16px", fontFamily: "JetBrains Mono", fontWeight: 600, color: "#0B2545" }}>{p.sku}</td>
                    <td style={{ padding: "11px 16px" }}>{p.name}</td>
                    <td style={{ padding: "11px 16px", fontWeight: 700, color: c }}>{p.stock}</td>
                    <td style={{ padding: "11px 16px", color: "#6b7280" }}>{p.min}</td>
                    <td style={{ padding: "11px 16px" }}><span className="ipill" style={{ color: c, background: c + "15", border: "1px solid " + c + "44" }}>● {p.status}</span></td>
                  </tr>
                );
              })}
            </tbody>
          </table>
        </div>
      </div>
    );
  }
  function IntranetATMgmt() {
    return (
      <div className="ipage" style={{ display: "flex", flexDirection: "column", gap: 16 }}>
        <div><h1>Service Management</h1><p className="lead">Per-technician productivity and SLA compliance</p></div>
        <div style={{ display: "grid", gridTemplateColumns: "1fr 1fr", gap: 16 }}>
          <div className="icard" style={{ padding: 18 }}>
            <div style={{ fontWeight: 700, marginBottom: 12 }}>Technicians</div>
            {[
              { n: "Lucas Almeida", os: 24, sla: 96, h: 142 },
              { n: "Mariana Souza", os: 18, sla: 88, h: 128 },
              { n: "Hiroshi Tanaka", os: 22, sla: 91, h: 138 },
              { n: "Aisha Khan", os: 14, sla: 100, h: 96 },
            ].map((t, i) => (
              <div key={i} style={{ display: "flex", alignItems: "center", gap: 12, padding: "10px 0", borderTop: i ? "1px solid #e6eaf0" : "none" }}>
                <div style={{ width: 36, height: 36, borderRadius: "50%", background: "linear-gradient(135deg,#5ab7ff,#1e6fb0)", color: "#fff", display: "grid", placeItems: "center", fontWeight: 700, fontSize: 12 }}>{t.n.split(" ").map((x) => x[0]).join("")}</div>
                <div style={{ flex: 1, minWidth: 0 }}><div style={{ fontWeight: 600, fontSize: 13 }}>{t.n}</div><div style={{ fontSize: 11, color: "#6b7280" }}>{t.os} OS · {t.h}h logged</div></div>
                <div style={{ minWidth: 90 }}><div style={{ width: 80, height: 4, background: "#e6eaf0", borderRadius: 2, overflow: "hidden" }}><div style={{ width: t.sla + "%", height: "100%", background: t.sla >= 95 ? "#3fa055" : t.sla >= 85 ? "#F59E0B" : "#DC2626" }}></div></div><div style={{ fontSize: 10, color: "#6b7280", marginTop: 3 }}>SLA {t.sla}%</div></div>
              </div>
            ))}
          </div>
          <div className="icard" style={{ padding: 18 }}>
            <div style={{ fontWeight: 700, marginBottom: 12 }}>SLA breakdown</div>
            {[
              { l: "Within 24h",   v: 68, c: "#3fa055" },
              { l: "Within 48h",   v: 22, c: "#F59E0B" },
              { l: "Within 72h",   v: 7,  c: "#7C3AED" },
              { l: "Over 72h",     v: 3,  c: "#DC2626" },
            ].map((t, i) => (
              <div key={i} style={{ marginBottom: 14 }}>
                <div style={{ display: "flex", justifyContent: "space-between", fontSize: 12, marginBottom: 4 }}><span>{t.l}</span><span style={{ fontWeight: 700, color: t.c }}>{t.v}%</span></div>
                <div style={{ height: 8, background: "#e6eaf0", borderRadius: 4, overflow: "hidden" }}><div style={{ width: t.v + "%", height: "100%", background: t.c }}></div></div>
              </div>
            ))}
          </div>
        </div>
      </div>
    );
  }
  function IntranetATNew() {
    return (
      <div className="ipage" style={{ display: "flex", flexDirection: "column", gap: 16 }}>
        <div><h1>+ New Service Order</h1><p className="lead">Open a new ticket — required fields marked with *</p></div>
        <div className="icard" style={{ padding: 22, maxWidth: 720 }}>
          <div style={{ display: "grid", gridTemplateColumns: "1fr 1fr", gap: 14 }}>
            {[
              { l: "Client *",    v: "Pacific Logistics" },
              { l: "Contact",     v: "Aaron Brooks" },
              { l: "Equipment *", v: "MOTOTRBO XPR3500e" },
              { l: "Serial #",    v: "MX-22-198472" },
              { l: "Issue category *", v: "Battery / charging" },
              { l: "Priority",    v: "Normal" },
            ].map((f, i) => (
              <div key={i}>
                <div style={{ fontSize: 11, fontWeight: 600, color: "#6b7280", marginBottom: 5 }}>{f.l}</div>
                <input value={f.v} readOnly style={{ width: "100%", padding: "8px 10px", border: "1px solid #d7dde5", borderRadius: 4, fontSize: 13, fontFamily: "Inter, sans-serif", background: "#fff" }} />
              </div>
            ))}
            <div style={{ gridColumn: "1 / -1" }}>
              <div style={{ fontSize: 11, fontWeight: 600, color: "#6b7280", marginBottom: 5 }}>Description</div>
              <textarea readOnly rows={4} value="Customer reports radio not holding charge after ~3h of use. Already swapped charger and confirmed new battery doesn't solve. Suspect main board issue." style={{ width: "100%", padding: "10px 12px", border: "1px solid #d7dde5", borderRadius: 4, fontSize: 13, fontFamily: "Inter, sans-serif", background: "#fff", resize: "vertical" }} />
            </div>
          </div>
          <div style={{ display: "flex", justifyContent: "flex-end", gap: 8, marginTop: 18 }}>
            <button className="ibtn-sec">Cancel</button><button className="ibtn-blue">Save &amp; Open</button>
          </div>
        </div>
      </div>
    );
  }

  /* ──── Rentals module ──── */
  function IntranetRentalDash() {
    return (
      <div className="ipage" style={{ display: "flex", flexDirection: "column", gap: 16 }}>
        <div><h1>Rentals · Dashboard</h1><p className="lead">142 active contracts · $ 286,400 / mo</p></div>
        <div style={{ display: "grid", gridTemplateColumns: "repeat(4, 1fr)", gap: 14 }}>
          {[
            { l: "Active", v: "142",  c: "#3fa055" },
            { l: "Expiring 30d", v: "18", c: "#F59E0B" },
            { l: "MRR", v: "$ 286.4k", c: "#0B2545" },
            { l: "Avg ticket", v: "$ 2,017", c: "#7C3AED" },
          ].map((k) => (
            <div key={k.l} className="icard" style={{ padding: 18 }}>
              <div style={{ fontSize: 11, color: "#6b7280", letterSpacing: "0.08em", textTransform: "uppercase" }}>{k.l}</div>
              <div style={{ fontFamily: "Space Grotesk, sans-serif", fontSize: 28, fontWeight: 700, color: k.c, marginTop: 6, lineHeight: 1 }}>{k.v}</div>
            </div>
          ))}
        </div>
        <div className="icard" style={{ padding: 18 }}>
          <div style={{ fontWeight: 700, marginBottom: 12 }}>Renewal queue · next 60 days</div>
          {[
            { c: "Pacific Logistics",   d: 12, v: "$ 4,820 / mo" },
            { c: "Coast Security Ltd.", d: 27, v: "$ 1,310 / mo" },
            { c: "Yukon Mining Group",  d: 41, v: "$ 9,500 / mo" },
            { c: "Northwest Power Co.", d: 58, v: "$ 6,200 / mo" },
          ].map((r, i) => (
            <div key={i} style={{ display: "flex", alignItems: "center", padding: "10px 0", borderTop: i ? "1px solid #e6eaf0" : "none" }}>
              <span style={{ flex: 1, fontWeight: 500 }}>{r.c}</span>
              <span style={{ width: 90, fontSize: 12, color: r.d <= 15 ? "#DC2626" : r.d <= 30 ? "#D97706" : "#3fa055", fontWeight: 700 }}>{r.d} days</span>
              <span style={{ width: 110, fontWeight: 600, color: "#0B2545", textAlign: "right" }}>{r.v}</span>
              <button className="ibtn-blue" style={{ marginLeft: 14 }}>Open</button>
            </div>
          ))}
        </div>
      </div>
    );
  }
  function IntranetRentalContracts() {
    const rows = [
      { id: "C-2024-0832", c: "Pacific Logistics",     start: "2024-05-01", end: "2026-05-13", v: 4820, s: "Active",  col: "#3fa055" },
      { id: "C-2024-0901", c: "Northwest Power Co.",   start: "2024-06-15", end: "2026-06-27", v: 6200, s: "Active",  col: "#3fa055" },
      { id: "C-2025-0012", c: "Yukon Mining Group",    start: "2025-01-10", end: "2026-06-10", v: 9500, s: "Active",  col: "#3fa055" },
      { id: "C-2024-0744", c: "Coast Security Ltd.",   start: "2024-02-20", end: "2026-05-27", v: 1310, s: "Renewal", col: "#F59E0B" },
      { id: "C-2025-0103", c: "Granite Construction",  start: "2025-03-12", end: "2027-03-12", v: 3450, s: "Active",  col: "#3fa055" },
      { id: "C-2024-0512", c: "Aurora Logistics",      start: "2024-09-01", end: "2026-04-12", v: 2890, s: "Expired", col: "#DC2626" },
    ];
    return (
      <div className="ipage" style={{ display: "flex", flexDirection: "column", gap: 16 }}>
        <div style={{ display: "flex", justifyContent: "space-between" }}>
          <div><h1>Contracts</h1><p className="lead">Filter, search and edit rental contracts</p></div>
          <button className="ibtn-blue">+ New contract</button>
        </div>
        <div className="icard" style={{ padding: 0, overflow: "hidden" }}>
          <table style={{ width: "100%", borderCollapse: "collapse", fontSize: 13 }}>
            <thead style={{ background: "#f7f8fa" }}><tr style={{ color: "#6b7280", textAlign: "left" }}>
              <th style={{ padding: "10px 16px" }}>Contract #</th><th style={{ padding: "10px 16px" }}>Client</th><th style={{ padding: "10px 16px" }}>Start</th><th style={{ padding: "10px 16px" }}>End</th><th style={{ padding: "10px 16px" }}>Value</th><th style={{ padding: "10px 16px" }}>Status</th>
            </tr></thead>
            <tbody>
              {rows.map((r) => (
                <tr key={r.id} style={{ borderTop: "1px solid #e6eaf0" }}>
                  <td style={{ padding: "11px 16px", fontFamily: "JetBrains Mono", fontWeight: 600, color: "#0B2545" }}>{r.id}</td>
                  <td style={{ padding: "11px 16px", fontWeight: 500 }}>{r.c}</td>
                  <td style={{ padding: "11px 16px", color: "#6b7280" }}>{r.start}</td>
                  <td style={{ padding: "11px 16px", color: "#6b7280" }}>{r.end}</td>
                  <td style={{ padding: "11px 16px", fontWeight: 600 }}>$ {r.v.toLocaleString()} /mo</td>
                  <td style={{ padding: "11px 16px" }}><span className="ipill" style={{ color: r.col, background: r.col + "15", border: "1px solid " + r.col + "44" }}>● {r.s}</span></td>
                </tr>
              ))}
            </tbody>
          </table>
        </div>
      </div>
    );
  }
  function IntranetRentalDaily() {
    return (
      <div className="ipage" style={{ display: "flex", flexDirection: "column", gap: 16 }}>
        <div><h1>Daily Rental</h1><p className="lead">Walk-in, event and short-term rentals</p></div>
        <div style={{ display: "grid", gridTemplateColumns: "repeat(3, 1fr)", gap: 14 }}>
          {[
            { e: "Event · BC Open Tennis", c: "DXP Productions", radios: 24, days: "Apr 28 – May 2", revenue: 4800, c2: "#3fa055" },
            { e: "Construction site · 6 wks", c: "Granite Construction", radios: 18, days: "Apr 15 – May 27", revenue: 7560, c2: "#0B2545" },
            { e: "Wedding · weekend", c: "Vancouver Events Co.", radios: 8,  days: "May 17 – May 19", revenue: 720, c2: "#7C3AED" },
          ].map((r, i) => (
            <div key={i} className="icard" style={{ padding: 16, borderTop: "4px solid " + r.c2 }}>
              <div style={{ fontSize: 11, color: r.c2, fontWeight: 700, textTransform: "uppercase", letterSpacing: "0.06em" }}>{r.e}</div>
              <div style={{ fontWeight: 600, fontSize: 15, marginTop: 4 }}>{r.c}</div>
              <div style={{ display: "flex", justifyContent: "space-between", marginTop: 12, fontSize: 12, color: "#6b7280" }}>
                <span>{r.radios} radios</span><span>{r.days}</span>
              </div>
              <div style={{ marginTop: 10, paddingTop: 10, borderTop: "1px dashed #e6eaf0", display: "flex", justifyContent: "space-between" }}>
                <span style={{ fontSize: 11, color: "#6b7280" }}>Total</span><span style={{ fontWeight: 700, color: "#0B2545" }}>$ {r.revenue.toLocaleString()}</span>
              </div>
            </div>
          ))}
        </div>
      </div>
    );
  }
  function IntranetRentalSchedule() {
    return (
      <div className="ipage" style={{ display: "flex", flexDirection: "column", gap: 16 }}>
        <div><h1>Customer Schedule</h1><p className="lead">Upcoming follow-ups, on-site visits and renewals</p></div>
        <div className="icard" style={{ padding: 0, overflow: "hidden" }}>
          {[
            { d: "May 02", t: "10:00", c: "Pacific Logistics",   what: "Renewal call · Aaron Brooks", tag: "Renewal", color: "#F59E0B" },
            { d: "May 04", t: "14:30", c: "Granite Construction", what: "Quarterly business review",   tag: "QBR",     color: "#7C3AED" },
            { d: "May 09", t: "09:00", c: "Coast Security Ltd.",  what: "Equipment audit on-site",      tag: "On-site", color: "#0891B2" },
            { d: "May 14", t: "11:30", c: "Yukon Mining Group",   what: "Repeater inspection",          tag: "Service", color: "#3fa055" },
            { d: "May 17", t: "16:00", c: "Northwest Power Co.",  what: "Contract amendment review",    tag: "Legal",   color: "#0B2545" },
          ].map((r, i) => (
            <div key={i} style={{ display: "flex", gap: 16, padding: "14px 18px", borderTop: i ? "1px solid #e6eaf0" : "none", alignItems: "center" }}>
              <div style={{ width: 60, textAlign: "center" }}>
                <div style={{ fontSize: 11, color: "#6b7280", fontWeight: 600 }}>{r.d}</div>
                <div style={{ fontSize: 14, fontWeight: 700, color: "#0B2545", fontFamily: "JetBrains Mono" }}>{r.t}</div>
              </div>
              <div style={{ flex: 1 }}>
                <div style={{ fontWeight: 600 }}>{r.c}</div>
                <div style={{ fontSize: 12.5, color: "#6b7280", marginTop: 2 }}>{r.what}</div>
              </div>
              <span className="ipill" style={{ color: r.color, background: r.color + "15", border: "1px solid " + r.color + "44" }}>{r.tag}</span>
            </div>
          ))}
        </div>
      </div>
    );
  }

  /* ──── Commercial module ──── */
  function IntranetCommOverview() {
    return (
      <div className="ipage" style={{ display: "flex", flexDirection: "column", gap: 16 }}>
        <div style={{ display: "flex", justifyContent: "space-between", alignItems: "flex-start" }}>
          <div>
            <h1>Commercial</h1>
            <p className="lead">Commercial dashboard and business intelligence</p>
          </div>
          <button className="ibtn-blue">+ New Opportunity</button>
        </div>

        {/* Shiny KPI Row — Strategy card + 4 metrics */}
        <div style={{ display: "grid", gridTemplateColumns: "1.4fr 1fr 1fr 1fr 1fr", gap: 14 }}>
          {/* Strategy card (large purple) */}
          <div style={{
            position: "relative", overflow: "hidden",
            background: "linear-gradient(135deg,#7C3AED 0%,#5B21B6 100%)", color: "#fff",
            borderRadius: 14, padding: 18,
            display: "flex", flexDirection: "column", justifyContent: "space-between",
            boxShadow: "0 10px 24px rgba(124,58,237,0.28)",
          }}>
            <div style={{ position: "absolute", right: -20, bottom: -20, opacity: 0.18 }}>
              <svg width="120" height="120" viewBox="0 0 24 24" fill="none" stroke="#fff" strokeWidth="1.4"><circle cx="12" cy="12" r="10"/><circle cx="12" cy="12" r="6"/><circle cx="12" cy="12" r="2"/></svg>
            </div>
            <div style={{ position: "relative" }}>
              <span style={{ display: "inline-block", background: "rgba(255,255,255,0.22)", padding: "3px 10px", borderRadius: 999, fontSize: 10, fontWeight: 700, letterSpacing: "0.08em", textTransform: "uppercase" }}>Strategy</span>
              <div style={{ fontFamily: "Space Grotesk, sans-serif", fontSize: 20, fontWeight: 800, marginTop: 10, letterSpacing: "-0.01em", lineHeight: 1.15 }}>Pre-Sales and Post-Sales</div>
              <div style={{ fontSize: 12, marginTop: 6, opacity: 0.85 }}>Read this month's playbook on warming leads and retaining accounts.</div>
            </div>
            <button style={{
              alignSelf: "flex-start", marginTop: 14,
              background: "#fff", color: "#5B21B6", border: 0,
              padding: "7px 14px", borderRadius: 8,
              fontSize: 12, fontWeight: 700, cursor: "pointer",
              fontFamily: "Inter, sans-serif",
            }}>View article →</button>
          </div>

          {/* Active Clients (green) */}
          <div style={{
            background: "linear-gradient(135deg,rgba(5,150,105,0.10),rgba(5,150,105,0.02))",
            border: "1px solid rgba(5,150,105,0.25)",
            borderRadius: 14, padding: 16, display: "flex", flexDirection: "column", gap: 6,
          }}>
            <div style={{ display: "flex", alignItems: "center", gap: 8, color: "#059669" }}>
              <UsersIcon size={18} color="#059669" />
              <span style={{ fontSize: 11, fontWeight: 700, letterSpacing: "0.08em", textTransform: "uppercase" }}>Active Clients</span>
            </div>
            <div style={{ fontFamily: "Space Grotesk, sans-serif", fontSize: 30, fontWeight: 800, color: "#065f46", lineHeight: 1 }}>312</div>
            <div style={{ fontSize: 11, color: "#475569" }}>Unique in last 90 days</div>
          </div>

          {/* Proposals This Month (blue) */}
          <div style={{
            background: "linear-gradient(135deg,rgba(29,78,216,0.10),rgba(29,78,216,0.02))",
            border: "1px solid rgba(29,78,216,0.25)",
            borderRadius: 14, padding: 16, display: "flex", flexDirection: "column", gap: 6,
          }}>
            <div style={{ display: "flex", alignItems: "center", gap: 8, color: "#1d4ed8" }}>
              <FileIcon size={18} color="#1d4ed8" />
              <span style={{ fontSize: 11, fontWeight: 700, letterSpacing: "0.08em", textTransform: "uppercase" }}>Proposals · Apr</span>
            </div>
            <div style={{ display: "flex", alignItems: "baseline", gap: 6 }}>
              <span style={{ fontFamily: "Space Grotesk, sans-serif", fontSize: 30, fontWeight: 800, color: "#1e3a8a", lineHeight: 1 }}>48</span>
              <span style={{ fontSize: 12, fontWeight: 700, color: "#059669" }}>↑ 12%</span>
            </div>
            <div style={{ fontSize: 11, color: "#475569" }}>Prev month: 43 · Apr 2025: 36</div>
          </div>

          {/* Month vs Previous (purple) */}
          <div style={{
            background: "linear-gradient(135deg,rgba(124,58,237,0.10),rgba(124,58,237,0.02))",
            border: "1px solid rgba(124,58,237,0.25)",
            borderRadius: 14, padding: 16, display: "flex", flexDirection: "column", gap: 6,
          }}>
            <div style={{ display: "flex", alignItems: "center", gap: 8, color: "#7c3aed" }}>
              <BarsIcon size={18} color="#7c3aed" />
              <span style={{ fontSize: 11, fontWeight: 700, letterSpacing: "0.08em", textTransform: "uppercase" }}>Apr vs Mar</span>
            </div>
            <div style={{ fontFamily: "Space Grotesk, sans-serif", fontSize: 26, fontWeight: 800, color: "#5b21b6", lineHeight: 1 }}>48 / 43</div>
            <div style={{ fontSize: 11, color: "#475569" }}>Reference: previous month</div>
          </div>

          {/* Evolution % (orange) */}
          <div style={{
            background: "linear-gradient(135deg,rgba(217,119,6,0.10),rgba(217,119,6,0.02))",
            border: "1px solid rgba(217,119,6,0.25)",
            borderRadius: 14, padding: 16, display: "flex", flexDirection: "column", gap: 6,
          }}>
            <div style={{ display: "flex", alignItems: "center", gap: 8, color: "#d97706" }}>
              <span style={{ fontSize: 16 }}>📈</span>
              <span style={{ fontSize: 11, fontWeight: 700, letterSpacing: "0.08em", textTransform: "uppercase" }}>Evolution</span>
            </div>
            <div style={{ display: "flex", alignItems: "baseline", gap: 6 }}>
              <span style={{ fontFamily: "Space Grotesk, sans-serif", fontSize: 30, fontWeight: 800, color: "#92400e", lineHeight: 1 }}>+11.6%</span>
              <span style={{ fontSize: 12, fontWeight: 700, color: "#059669" }}>↑</span>
            </div>
            <div style={{ fontSize: 11, color: "#475569" }}>Apr 2025 same period: +5.2%</div>
          </div>
        </div>

        {/* Follow-up blocks (3 columns) */}
        <div style={{ display: "grid", gridTemplateColumns: "repeat(3, 1fr)", gap: 14 }}>
          <div className="icard" style={{ padding: 16 }}>
            <div style={{ fontSize: 11, color: "#6b7280", letterSpacing: "0.08em", textTransform: "uppercase", fontWeight: 700, marginBottom: 10 }}>Follow-ups due today</div>
            {[
              { c: "Pacific Logistics",      o: "Lucas",   t: "Send revised quote", color: "#DC2626" },
              { c: "Yukon Mining Group",     o: "Hiroshi", t: "Schedule on-site demo", color: "#D97706" },
              { c: "Coast Security Ltd.",    o: "Aisha",   t: "Confirm contract renewal", color: "#059669" },
            ].map((f, i) => (
              <div key={i} style={{ display: "flex", gap: 10, padding: "8px 0", borderTop: i ? "1px solid #e6eaf0" : "none", alignItems: "center" }}>
                <span style={{ width: 6, height: 6, borderRadius: "50%", background: f.color, flexShrink: 0 }}></span>
                <div style={{ flex: 1, minWidth: 0 }}>
                  <div style={{ fontWeight: 600, fontSize: 13 }}>{f.c}</div>
                  <div style={{ fontSize: 11, color: "#6b7280" }}>{f.t}</div>
                </div>
                <span style={{ fontSize: 11, color: "#94a3b8" }}>{f.o}</span>
              </div>
            ))}
          </div>

          <div className="icard" style={{ padding: 16 }}>
            <div style={{ fontSize: 11, color: "#6b7280", letterSpacing: "0.08em", textTransform: "uppercase", fontWeight: 700, marginBottom: 10 }}>Stale opportunities</div>
            {[
              { c: "Aurora Logistics",       d: "12 days no contact", v: "$ 38k" },
              { c: "Granite Construction",   d: "9 days no contact",  v: "$ 28.4k" },
              { c: "DXP Productions",        d: "7 days no contact",  v: "$ 9.8k" },
            ].map((f, i) => (
              <div key={i} style={{ display: "flex", gap: 10, padding: "8px 0", borderTop: i ? "1px solid #e6eaf0" : "none", alignItems: "center" }}>
                <div style={{ flex: 1 }}>
                  <div style={{ fontWeight: 600, fontSize: 13 }}>{f.c}</div>
                  <div style={{ fontSize: 11, color: "#DC2626" }}>{f.d}</div>
                </div>
                <span style={{ fontSize: 12, fontWeight: 700, color: "#0B2545" }}>{f.v}</span>
              </div>
            ))}
          </div>

          <div className="icard" style={{ padding: 16 }}>
            <div style={{ fontSize: 11, color: "#6b7280", letterSpacing: "0.08em", textTransform: "uppercase", fontWeight: 700, marginBottom: 10 }}>Closed won this month</div>
            {[
              { c: "Northwest Power Co.",  v: "$ 64,000", d: "Apr 12" },
              { c: "Coast Security Ltd.",  v: "$ 15,700", d: "Apr 18" },
              { c: "Granite Construction", v: "$ 22,300", d: "Apr 24" },
            ].map((f, i) => (
              <div key={i} style={{ display: "flex", gap: 10, padding: "8px 0", borderTop: i ? "1px solid #e6eaf0" : "none", alignItems: "center" }}>
                <div style={{ flex: 1 }}>
                  <div style={{ fontWeight: 600, fontSize: 13 }}>{f.c}</div>
                  <div style={{ fontSize: 11, color: "#94a3b8" }}>{f.d}</div>
                </div>
                <span style={{ fontSize: 12, fontWeight: 700, color: "#059669" }}>{f.v}</span>
              </div>
            ))}
          </div>
        </div>

        {/* Pipeline funnel */}
        <div style={{ display: "grid", gridTemplateColumns: "repeat(5, 1fr)", gap: 12 }}>
          {[
            { l: "Lead",      n: 24, c: "#94a3b8" },
            { l: "Qualified", n: 18, c: "#3B82F6" },
            { l: "Proposal",  n: 9,  c: "#7C3AED" },
            { l: "Negotiation", n: 5, c: "#F59E0B" },
            { l: "Won",       n: 3,  c: "#3fa055" },
          ].map((s) => (
            <div key={s.l} className="icard" style={{ padding: 14, borderTop: "4px solid " + s.c }}>
              <div style={{ fontSize: 11, color: s.c, fontWeight: 700, textTransform: "uppercase", letterSpacing: "0.06em" }}>{s.l}</div>
              <div style={{ fontSize: 24, fontWeight: 800, marginTop: 4 }}>{s.n}</div>
              <div style={{ fontSize: 11, color: "#6b7280" }}>opportunities</div>
            </div>
          ))}
        </div>
      </div>
    );
  }
  function IntranetCommOpps() {
    return (
      <div className="ipage" style={{ display: "flex", flexDirection: "column", gap: 16 }}>
        <div style={{ display: "flex", justifyContent: "space-between" }}><div><h1>Opportunities</h1><p className="lead">Open deals across all stages</p></div><button className="ibtn-blue">+ New opportunity</button></div>
        <div className="icard" style={{ padding: 0, overflow: "hidden" }}>
          <table style={{ width: "100%", borderCollapse: "collapse", fontSize: 13 }}>
            <thead style={{ background: "#f7f8fa" }}><tr style={{ color: "#6b7280", textAlign: "left" }}>
              <th style={{ padding: "10px 16px" }}>Deal</th><th style={{ padding: "10px 16px" }}>Client</th><th style={{ padding: "10px 16px" }}>Owner</th><th style={{ padding: "10px 16px" }}>Stage</th><th style={{ padding: "10px 16px" }}>Value</th><th style={{ padding: "10px 16px" }}>Close</th>
            </tr></thead>
            <tbody>
              {[
                { d: "Fleet upgrade · 80 radios",      c: "Pacific Logistics",     o: "Lucas",  s: "Negotiation", c2: "#F59E0B", v: 64000, dt: "May 18" },
                { d: "Repeater network · 4 sites",     c: "Yukon Mining Group",    o: "Hiroshi",s: "Proposal",    c2: "#7C3AED", v: 92000, dt: "May 24" },
                { d: "Renewal · annual contract",      c: "Coast Security Ltd.",   o: "Aisha",  s: "Negotiation", c2: "#F59E0B", v: 15700, dt: "May 27" },
                { d: "Pilot · construction site",      c: "Granite Construction",  o: "Lucas",  s: "Qualified",   c2: "#3B82F6", v: 28400, dt: "Jun 03" },
                { d: "Event production package",       c: "DXP Productions",       o: "Mariana",s: "Lead",        c2: "#94a3b8", v: 9800,  dt: "Jun 10" },
              ].map((r, i) => (
                <tr key={i} style={{ borderTop: "1px solid #e6eaf0" }}>
                  <td style={{ padding: "11px 16px", fontWeight: 500 }}>{r.d}</td>
                  <td style={{ padding: "11px 16px" }}>{r.c}</td>
                  <td style={{ padding: "11px 16px", color: "#6b7280" }}>{r.o}</td>
                  <td style={{ padding: "11px 16px" }}><span className="ipill" style={{ color: r.c2, background: r.c2 + "15", border: "1px solid " + r.c2 + "44" }}>{r.s}</span></td>
                  <td style={{ padding: "11px 16px", fontWeight: 700, color: "#0B2545" }}>$ {r.v.toLocaleString()}</td>
                  <td style={{ padding: "11px 16px", color: "#6b7280" }}>{r.dt}</td>
                </tr>
              ))}
            </tbody>
          </table>
        </div>
      </div>
    );
  }
  function IntranetCommAnalysis() {
    return (
      <div className="ipage" style={{ display: "flex", flexDirection: "column", gap: 16 }}>
        <div><h1>Sales Analyses</h1><p className="lead">Win/loss reasons and revenue mix</p></div>
        <div style={{ display: "grid", gridTemplateColumns: "1fr 1fr", gap: 16 }}>
          <div className="icard" style={{ padding: 18 }}>
            <div style={{ fontWeight: 700, marginBottom: 12 }}>Win reasons</div>
            {[{ l: "Better support", v: 38 }, { l: "Pricing", v: 27 }, { l: "Existing relationship", v: 18 }, { l: "Faster delivery", v: 11 }, { l: "Other", v: 6 }].map((r, i) => (
              <div key={i} style={{ marginBottom: 10 }}><div style={{ display: "flex", justifyContent: "space-between", fontSize: 12, marginBottom: 4 }}><span>{r.l}</span><strong style={{ color: "#3fa055" }}>{r.v}%</strong></div><div style={{ height: 6, background: "#e6eaf0", borderRadius: 3, overflow: "hidden" }}><div style={{ width: r.v + "%", height: "100%", background: "linear-gradient(90deg,#3fa055,#10B981)" }}></div></div></div>
            ))}
          </div>
          <div className="icard" style={{ padding: 18 }}>
            <div style={{ fontWeight: 700, marginBottom: 12 }}>Revenue by product line</div>
            {[
              { l: "Two-way radios",       v: 52, c: "#0B2545" },
              { l: "Repeater systems",     v: 24, c: "#1E5BA8" },
              { l: "Service & repairs",    v: 18, c: "#7C3AED" },
              { l: "Accessories",           v: 6, c: "#F59E0B" },
            ].map((r, i) => (
              <div key={i} style={{ marginBottom: 10 }}><div style={{ display: "flex", justifyContent: "space-between", fontSize: 12, marginBottom: 4 }}><span>{r.l}</span><strong style={{ color: r.c }}>{r.v}%</strong></div><div style={{ height: 6, background: "#e6eaf0", borderRadius: 3, overflow: "hidden" }}><div style={{ width: r.v + "%", height: "100%", background: r.c }}></div></div></div>
            ))}
          </div>
        </div>
      </div>
    );
  }
  function IntranetCommCad() {
    return (
      <div className="ipage" style={{ display: "flex", flexDirection: "column", gap: 16 }}>
        <div style={{ display: "flex", justifyContent: "space-between" }}><div><h1>Commercial Records</h1><p className="lead">Products, pricing tables and territories</p></div><button className="ibtn-blue">+ New record</button></div>
        <div style={{ display: "grid", gridTemplateColumns: "repeat(3, 1fr)", gap: 14 }}>
          {[
            { l: "Product catalog", n: "184 SKUs", c: "#0B2545" },
            { l: "Price lists",     n: "12 active", c: "#7C3AED" },
            { l: "Sales territories", n: "5 regions", c: "#3fa055" },
          ].map((c, i) => (
            <div key={i} className="icard" style={{ padding: 18 }}>
              <div style={{ fontSize: 11, color: "#6b7280", textTransform: "uppercase", letterSpacing: "0.08em" }}>{c.l}</div>
              <div style={{ fontSize: 22, fontWeight: 800, color: c.c, marginTop: 6 }}>{c.n}</div>
              <button className="ibtn-sec" style={{ marginTop: 10 }}>Manage →</button>
            </div>
          ))}
        </div>
      </div>
    );
  }

  /* ──── Logistics module ──── */
  function IntranetLogiDash() {
    return (
      <div className="ipage" style={{ display: "flex", flexDirection: "column", gap: 16 }}>
        <div style={{ display: "flex", justifyContent: "space-between", alignItems: "flex-start" }}>
          <div>
            <h1>Logistics</h1>
            <p className="lead">Real-time tracking and delivery management.</p>
          </div>
          <button className="ibtn-blue">+ New Delivery</button>
        </div>

        {/* KPI strip — 4 tonal cards */}
        <div style={{ display: "grid", gridTemplateColumns: "repeat(4, 1fr)", gap: 14 }}>
          {[
            { l: "Drivers on route",        v: 4,        s: "Active right now",      c: "#1d4ed8", bg: "rgba(29,78,216,0.10)",  ico: "🚚" },
            { l: "Deliveries in progress",  v: 11,       s: "ETA before 18:00",      c: "#F97316", bg: "rgba(249,115,22,0.10)", ico: "⏱" },
            { l: "Delivered today",         v: 23,       s: "Out of 34 scheduled",   c: "#059669", bg: "rgba(5,150,105,0.10)",  ico: "✓" },
            { l: "Total distance · today",  v: "412 km", s: "All vehicles combined", c: "#7C3AED", bg: "rgba(124,58,237,0.10)", ico: "↗" },
          ].map((k) => (
            <div key={k.l} style={{
              background: k.bg, border: "1px solid " + k.c + "33",
              borderRadius: 14, padding: 16, position: "relative",
            }}>
              <div style={{ display: "flex", alignItems: "center", gap: 8, color: k.c }}>
                <span style={{ width: 30, height: 30, borderRadius: 8, background: "#fff", display: "grid", placeItems: "center", fontSize: 14 }}>{k.ico}</span>
                <span style={{ fontSize: 11, fontWeight: 700, letterSpacing: "0.06em", textTransform: "uppercase" }}>{k.l}</span>
              </div>
              <div style={{ fontFamily: "Space Grotesk, sans-serif", fontSize: 30, fontWeight: 800, color: k.c, marginTop: 10, lineHeight: 1 }}>{k.v}</div>
              <div style={{ fontSize: 11, color: "#475569", marginTop: 6 }}>{k.s}</div>
              <div style={{ marginTop: 10, fontSize: 11, color: k.c, fontWeight: 700 }}>View detail →</div>
            </div>
          ))}
        </div>

        {/* Main grid — Map + Calendar */}
        <div style={{ display: "grid", gridTemplateColumns: "1.5fr 1fr", gap: 14 }}>
          {/* Map card */}
          <div className="icard" style={{ padding: 0, overflow: "hidden", display: "flex", flexDirection: "column" }}>
            <div style={{
              background: "#0B2545", color: "#fff",
              padding: "12px 16px", display: "flex", alignItems: "center", gap: 10,
            }}>
              <strong style={{ fontFamily: "Space Grotesk, sans-serif", fontSize: 14, flex: 1 }}>Delivery Map</strong>
              <span style={{ display: "inline-flex", alignItems: "center", gap: 6, background: "rgba(16,185,129,0.18)", color: "#10B981", padding: "3px 10px", borderRadius: 999, fontSize: 11, fontWeight: 700 }}>
                <span style={{ width: 7, height: 7, borderRadius: "50%", background: "#10B981", animation: "pulse 1.6s infinite ease-out" }}></span>
                Live
              </span>
            </div>
            {/* Mock map area */}
            <div style={{
              position: "relative", height: 360,
              background:
                "linear-gradient(135deg,#dbeafe 0%,#e0f2fe 40%,#f0fdf4 100%)",
              backgroundSize: "100% 100%", overflow: "hidden",
            }}>
              {/* Roads */}
              <svg width="100%" height="100%" viewBox="0 0 600 360" style={{ position: "absolute", inset: 0 }}>
                <defs>
                  <pattern id="grid" width="40" height="40" patternUnits="userSpaceOnUse"><path d="M40 0H0V40" fill="none" stroke="#cbd5e1" strokeWidth="0.5" opacity="0.5"/></pattern>
                </defs>
                <rect width="600" height="360" fill="url(#grid)"/>
                <path d="M40 280 Q 200 200, 320 220 T 560 100" fill="none" stroke="#1d4ed8" strokeWidth="3" strokeDasharray="6 4"/>
                <path d="M80 60 Q 220 120, 340 140 T 520 280" fill="none" stroke="#F97316" strokeWidth="3" strokeDasharray="6 4"/>
                <path d="M50 180 Q 200 150, 380 280" fill="none" stroke="#7C3AED" strokeWidth="3" strokeDasharray="6 4"/>
              </svg>
              {/* Vehicle pins */}
              {[
                { x: 32, y: 24, c: "#1d4ed8", n: "BC-7821" },
                { x: 56, y: 38, c: "#F97316", n: "BC-2174" },
                { x: 70, y: 70, c: "#059669", n: "BC-9904" },
                { x: 24, y: 60, c: "#7C3AED", n: "BC-3382" },
              ].map((p, i) => (
                <div key={i} style={{
                  position: "absolute", left: p.x + "%", top: p.y + "%",
                  transform: "translate(-50%,-50%)",
                  display: "flex", flexDirection: "column", alignItems: "center", gap: 2,
                }}>
                  <div style={{ width: 30, height: 30, borderRadius: "50%", background: p.c, color: "#fff", display: "grid", placeItems: "center", boxShadow: "0 4px 12px " + p.c + "55", border: "3px solid #fff" }}>🚚</div>
                  <span style={{ background: "#fff", color: "#0f172a", fontSize: 10, fontWeight: 700, padding: "1px 6px", borderRadius: 4, boxShadow: "0 1px 3px rgba(0,0,0,0.15)" }}>{p.n}</span>
                </div>
              ))}
            </div>
            <div style={{ padding: "10px 16px", borderTop: "1px solid #e6eaf0", display: "flex", justifyContent: "space-between", alignItems: "center", fontSize: 12 }}>
              <span style={{ color: "#6b7280" }}>4 vehicles · 11 stops remaining</span>
              <a href="#" style={{ color: "#1d4ed8", fontWeight: 700, textDecoration: "none" }}>View full route ↗</a>
            </div>
          </div>

          {/* Calendar card */}
          <div className="icard" style={{ padding: 0, overflow: "hidden" }}>
            <div style={{ padding: "12px 16px", display: "flex", justifyContent: "space-between", alignItems: "center", borderBottom: "1px solid #e6eaf0" }}>
              <button className="ibtn-sec" style={{ padding: "4px 10px" }}>‹</button>
              <strong style={{ fontFamily: "Space Grotesk, sans-serif", fontSize: 14 }}>April 2026</strong>
              <button className="ibtn-sec" style={{ padding: "4px 10px" }}>›</button>
            </div>
            <div style={{ display: "grid", gridTemplateColumns: "repeat(7, 1fr)", padding: "8px 12px", gap: 4, fontSize: 11 }}>
              {["S", "M", "T", "W", "T", "F", "S"].map((d, i) => (
                <div key={i} style={{ textAlign: "center", color: "#94a3b8", fontWeight: 700, padding: "4px 0" }}>{d}</div>
              ))}
              {Array.from({ length: 30 }, (_, i) => i + 1).map((day) => {
                const isToday = day === 30;
                const count = [3, 7, 12, 18, 22, 25, 27, 30].includes(day) ? Math.floor(Math.random() * 4) + 1 : 0;
                return (
                  <div key={day} style={{
                    position: "relative", textAlign: "center", padding: "6px 0",
                    borderRadius: 6, fontSize: 12,
                    background: isToday ? "#1d4ed8" : "transparent",
                    color: isToday ? "#fff" : "#1f2937",
                    fontWeight: isToday ? 700 : 500, cursor: "pointer",
                  }}>
                    {day}
                    {count > 0 && <div style={{ position: "absolute", bottom: 2, left: "50%", transform: "translateX(-50%)", width: 4, height: 4, borderRadius: "50%", background: isToday ? "#fff" : "#F97316" }}></div>}
                  </div>
                );
              })}
            </div>
            <div style={{ padding: "10px 16px", borderTop: "1px solid #e6eaf0", fontSize: 12, color: "#6b7280", display: "flex", justifyContent: "space-between" }}>
              <span>Selected: April 30</span>
              <strong style={{ color: "#1d4ed8" }}>11 deliveries</strong>
            </div>
          </div>
        </div>

        {/* Deliveries of the day */}
        <div className="icard" style={{ padding: 0, overflow: "hidden" }}>
          <div style={{ padding: "12px 16px", display: "flex", alignItems: "center", gap: 10, borderBottom: "1px solid #e6eaf0" }}>
            <span style={{ width: 28, height: 28, borderRadius: 8, background: "#1d4ed8", color: "#fff", display: "grid", placeItems: "center" }}>🚚</span>
            <strong style={{ flex: 1 }}>Deliveries of the day · April 30</strong>
            <span style={{ fontSize: 12, color: "#6b7280" }}>11 stops</span>
          </div>
          <table style={{ width: "100%", borderCollapse: "collapse", fontSize: 13 }}>
            <thead style={{ background: "#f7f8fa" }}><tr style={{ color: "#6b7280", textAlign: "left" }}>
              <th style={{ padding: "10px 16px" }}>Time</th>
              <th style={{ padding: "10px 16px" }}>Driver</th>
              <th style={{ padding: "10px 16px" }}>Route</th>
              <th style={{ padding: "10px 16px" }}>Client</th>
              <th style={{ padding: "10px 16px" }}>Status</th>
              <th style={{ padding: "10px 16px" }}></th>
            </tr></thead>
            <tbody>
              {[
                { t: "08:30", n: "Carlos Lopez",   v: "BC-7821", c: "Pacific Logistics",   s: "Delivered",    sc: "#059669" },
                { t: "10:15", n: "Hiroshi Tanaka", v: "BC-9904", c: "Northwest Power Co.", s: "Delivered",    sc: "#059669" },
                { t: "11:40", n: "Mateus Andrade", v: "BC-2174", c: "Aurora Logistics",    s: "In transit",   sc: "#F97316" },
                { t: "13:20", n: "Aisha Khan",     v: "BC-3382", c: "Granite Construction", s: "In transit",  sc: "#F97316" },
                { t: "14:50", n: "Carlos Lopez",   v: "BC-7821", c: "Coast Security Ltd.",  s: "Scheduled",    sc: "#94a3b8" },
                { t: "16:00", n: "Hiroshi Tanaka", v: "BC-9904", c: "Yukon Mining Group",   s: "Scheduled",    sc: "#94a3b8" },
              ].map((r, i) => (
                <tr key={i} style={{ borderTop: "1px solid #e6eaf0" }}>
                  <td style={{ padding: "11px 16px", fontFamily: "JetBrains Mono", color: "#0B2545", fontWeight: 600 }}>{r.t}</td>
                  <td style={{ padding: "11px 16px" }}>{r.n} <span style={{ color: "#94a3b8", fontSize: 11 }}>· {r.v}</span></td>
                  <td style={{ padding: "11px 16px", color: "#475569" }}>{r.v}</td>
                  <td style={{ padding: "11px 16px" }}>{r.c}</td>
                  <td style={{ padding: "11px 16px" }}><span className="ipill" style={{ color: r.sc, background: r.sc + "15", border: "1px solid " + r.sc + "33" }}>● {r.s}</span></td>
                  <td style={{ padding: "11px 16px", textAlign: "right" }}><button className="ibtn-sec" style={{ padding: "4px 10px" }}>Track</button></td>
                </tr>
              ))}
            </tbody>
          </table>
        </div>
      </div>
    );
  }
  function IntranetLogiHistory() {
    return (
      <div className="ipage" style={{ display: "flex", flexDirection: "column", gap: 16 }}>
        <div><h1>Delivery History</h1><p className="lead">Last 30 days · 412 deliveries · 99.3% on-time</p></div>
        <div className="icard" style={{ padding: 0, overflow: "hidden" }}>
          <table style={{ width: "100%", borderCollapse: "collapse", fontSize: 13 }}>
            <thead style={{ background: "#f7f8fa" }}><tr style={{ color: "#6b7280", textAlign: "left" }}>
              <th style={{ padding: "10px 16px" }}>Date</th><th style={{ padding: "10px 16px" }}>Driver</th><th style={{ padding: "10px 16px" }}>Route</th><th style={{ padding: "10px 16px" }}>Stops</th><th style={{ padding: "10px 16px" }}>On-time</th>
            </tr></thead>
            <tbody>
              {[
                { d: "Apr 29", n: "Carlos Lopez", r: "Vancouver → Surrey", s: 12, ot: "100%", c: "#3fa055" },
                { d: "Apr 29", n: "Mateus Andrade", r: "Burnaby → Coquitlam", s: 8, ot: "92%", c: "#F59E0B" },
                { d: "Apr 28", n: "Hiroshi Tanaka", r: "Vancouver → Squamish", s: 6, ot: "100%", c: "#3fa055" },
                { d: "Apr 28", n: "Aisha Khan", r: "Surrey → North Van", s: 14, ot: "86%", c: "#F59E0B" },
                { d: "Apr 27", n: "Carlos Lopez", r: "Vancouver → Richmond", s: 10, ot: "100%", c: "#3fa055" },
              ].map((r, i) => (
                <tr key={i} style={{ borderTop: "1px solid #e6eaf0" }}>
                  <td style={{ padding: "11px 16px", color: "#6b7280" }}>{r.d}</td>
                  <td style={{ padding: "11px 16px", fontWeight: 500 }}>{r.n}</td>
                  <td style={{ padding: "11px 16px" }}>{r.r}</td>
                  <td style={{ padding: "11px 16px" }}>{r.s}</td>
                  <td style={{ padding: "11px 16px", color: r.c, fontWeight: 700 }}>{r.ot}</td>
                </tr>
              ))}
            </tbody>
          </table>
        </div>
      </div>
    );
  }

  /* ──── Communication module ──── */
  function IntranetCommsSugg() {
    return (
      <div className="ipage" style={{ display: "flex", flexDirection: "column", gap: 16 }}>
        <div style={{ display: "flex", justifyContent: "space-between" }}><div><h1>Suggestions</h1><p className="lead">Internal feedback box · 4 new this week</p></div><button className="ibtn-blue">+ Submit</button></div>
        <div style={{ display: "grid", gap: 12 }}>
          {[
            { who: "Mariana Souza", t: "Add a 'reorder' shortcut on parts page", up: 14, status: "Under review", c: "#7C3AED" },
            { who: "Lucas Almeida", t: "Quick filter for OS by client on Kanban", up: 9,  status: "Planned",      c: "#3B82F6" },
            { who: "Anonymous",      t: "Coffee machine on the 2nd floor 🙏",      up: 22, status: "Won't fix",    c: "#94a3b8" },
            { who: "Aisha Khan",     t: "Driver app should beep on new route",    up: 6,  status: "Done",         c: "#3fa055" },
          ].map((s, i) => (
            <div key={i} className="icard" style={{ padding: 16, display: "flex", gap: 14, alignItems: "center" }}>
              <div style={{ background: "#f2f4f7", borderRadius: 6, padding: "8px 12px", textAlign: "center", minWidth: 50 }}>
                <div style={{ fontSize: 10, color: "#6b7280" }}>▲</div>
                <div style={{ fontWeight: 800, color: "#0B2545" }}>{s.up}</div>
              </div>
              <div style={{ flex: 1 }}>
                <div style={{ fontWeight: 600 }}>{s.t}</div>
                <div style={{ fontSize: 12, color: "#6b7280", marginTop: 2 }}>by {s.who}</div>
              </div>
              <span className="ipill" style={{ color: s.c, background: s.c + "15", border: "1px solid " + s.c + "44" }}>{s.status}</span>
            </div>
          ))}
        </div>
      </div>
    );
  }
  function IntranetCommsAnn() {
    const CATS = {
      info:    { label: "Information", c: "#1d4ed8", ico: "ℹ" },
      remind:  { label: "Reminder",    c: "#d97706", ico: "🔔" },
      urgent:  { label: "Urgent",      c: "#dc2626", ico: "⚠" },
      event:   { label: "Event",       c: "#7c3aed", ico: "📅" },
      success: { label: "Success",     c: "#059669", ico: "✓" },
    };
    const announcements = [
      { id: 1, cat: "urgent", pinned: true, title: "Office closed — Victoria Day", body: "Monday, May 19 the office will be closed. Emergency support line will remain available 24h. On-call rotation posted on the team channel.", who: "Operations team", date: "Apr 28, 2026", time: "09:14", ago: "2 days ago", unread: true },
      { id: 2, cat: "info",   pinned: true, title: "New Q3 Branding Guidelines",   body: "Please review the updated logo, color palette and email signature template by next Monday. Files in shared drive.", who: "Mariana Souza", date: "Apr 30, 2026", time: "08:42", ago: "2 hours ago", unread: true },
      { id: 3, cat: "remind", pinned: false, title: "Security Training Mandatory", body: "Phishing simulation results were shared. Module #3 of the security training expires May 15 — make sure you complete it before then.", who: "IT · Security", date: "Apr 29, 2026", time: "16:05", ago: "yesterday", unread: false },
      { id: 4, cat: "event",  pinned: false, title: "Town Hall · April Recap",     body: "Quarterly town hall on Friday May 9 at 14:00 — Q1 performance, hiring updates, and product roadmap. Recording will be posted afterward.", who: "Leadership", date: "Apr 26, 2026", time: "11:20", ago: "4 days ago", unread: false },
      { id: 5, cat: "success",pinned: false, title: "Welcome Aisha Khan",          body: "Aisha is joining the Logistics team as Driver Coordinator. Help us welcome her on Slack and at next week's Friday lunch.", who: "People & Culture", date: "Apr 25, 2026", time: "10:00", ago: "5 days ago", unread: false },
    ];
    return (
      <div className="ipage" style={{ display: "flex", flexDirection: "column", gap: 18 }}>
        {/* Hero */}
        <div style={{
          display: "flex", alignItems: "center", gap: 16,
          background: "linear-gradient(135deg,#1d4ed8 0%,#312e81 100%)", color: "#fff",
          borderRadius: 14, padding: "20px 24px",
          boxShadow: "0 10px 24px rgba(29,78,216,0.22)",
        }}>
          <div style={{ width: 56, height: 56, borderRadius: 14, background: "rgba(255,255,255,0.18)", display: "grid", placeItems: "center", flexShrink: 0 }}>
            <MegaIcon size={28} color="#fff" />
          </div>
          <div style={{ flex: 1 }}>
            <h1 style={{ margin: 0, color: "#fff", fontSize: 26 }}>Announcements</h1>
            <p style={{ margin: "4px 0 0", color: "rgba(255,255,255,0.85)", fontSize: 13 }}>
              Stay informed about company-wide news and updates.
            </p>
          </div>
          <button style={{
            background: "#fff", color: "#1e3a8a", border: 0,
            padding: "10px 18px", borderRadius: 10,
            fontSize: 13, fontWeight: 700, cursor: "pointer",
            fontFamily: "Inter, sans-serif",
          }}>+ New Announcement</button>
        </div>

        {/* Cards */}
        <div style={{ display: "flex", flexDirection: "column", gap: 12 }}>
          {announcements.map((a) => {
            const cat = CATS[a.cat];
            return (
              <div key={a.id} className="icard" style={{
                padding: 16,
                display: "grid", gridTemplateColumns: "44px 1fr auto",
                gap: 14, alignItems: "flex-start",
                borderLeft: "4px solid " + cat.c,
                background: a.pinned ? "linear-gradient(180deg,rgba(253,224,71,0.06),#fff)" : "#fff",
              }}>
                <div style={{
                  width: 44, height: 44, borderRadius: 10,
                  background: cat.c + "18", color: cat.c,
                  display: "grid", placeItems: "center", fontSize: 18,
                }}>{cat.ico}</div>

                <div style={{ minWidth: 0 }}>
                  <div style={{ display: "flex", alignItems: "center", gap: 10, flexWrap: "wrap" }}>
                    {a.unread && <span style={{ background: "#1d4ed8", color: "#fff", fontSize: 9, fontWeight: 800, padding: "2px 7px", borderRadius: 999, letterSpacing: "0.06em" }}>NEW</span>}
                    <div style={{ fontFamily: "Space Grotesk, sans-serif", fontSize: 16, fontWeight: 700, color: "#0f172a", display: "flex", alignItems: "center", gap: 8 }}>
                      {a.pinned && <span title="Pinned" style={{ color: "#d97706" }}>📌</span>}
                      {a.title}
                    </div>
                  </div>
                  <p style={{ fontSize: 13, color: "#475569", lineHeight: 1.5, margin: "6px 0 0" }}>{a.body}</p>
                  <div style={{ display: "flex", gap: 10, marginTop: 10, fontSize: 11, color: "#94a3b8", flexWrap: "wrap", alignItems: "center" }}>
                    <span style={{ fontWeight: 600, color: "#475569" }}>{a.who}</span>
                    <span>·</span>
                    <span>{a.date}</span>
                    <span>·</span>
                    <span>{a.time}</span>
                    <span style={{ marginLeft: "auto", color: "#94a3b8" }}>{a.ago}</span>
                  </div>
                </div>

                <div style={{ display: "flex", flexDirection: "column", alignItems: "flex-end", gap: 8 }}>
                  <span style={{
                    display: "inline-flex", alignItems: "center", gap: 6,
                    background: cat.c + "15", color: cat.c,
                    padding: "4px 10px", borderRadius: 999,
                    fontSize: 11, fontWeight: 700,
                  }}>
                    <span>{cat.ico}</span> {cat.label}
                  </span>
                  <div style={{ display: "flex", gap: 4 }}>
                    <button title="Edit" style={{ width: 26, height: 26, borderRadius: 6, border: "1px solid #e6eaf0", background: "#fff", color: "#6b7280", cursor: "pointer" }}>✎</button>
                    <button title="Delete" style={{ width: 26, height: 26, borderRadius: 6, border: "1px solid #e6eaf0", background: "#fff", color: "#dc2626", cursor: "pointer" }}>🗑</button>
                  </div>
                </div>
              </div>
            );
          })}
        </div>

        {/* Empty-state hint at bottom */}
        <div style={{
          textAlign: "center", padding: "30px 16px",
          color: "#94a3b8", fontSize: 13,
          border: "1px dashed #e6eaf0", borderRadius: 12,
        }}>
          <div style={{ fontSize: 26, marginBottom: 6 }}>📣</div>
          <div style={{ fontWeight: 700, color: "#475569" }}>You're all caught up!</div>
          <div style={{ marginTop: 4, fontSize: 12 }}>Older announcements are archived in the Policies section.</div>
        </div>
      </div>
    );
  }
  function IntranetCommsPol() {
    return (
      <div className="ipage" style={{ display: "flex", flexDirection: "column", gap: 16 }}>
        <div><h1>Policies</h1><p className="lead">Company handbook and SOPs</p></div>
        <div style={{ display: "grid", gridTemplateColumns: "repeat(3, 1fr)", gap: 12 }}>
          {[
            { t: "Code of Conduct",         u: "Updated Apr 12", v: "v3.2", c: "#0B2545" },
            { t: "Security & IT Acceptable Use", u: "Updated Mar 30", v: "v2.1", c: "#7C3AED" },
            { t: "Travel & Expense",        u: "Updated Feb 18", v: "v1.7", c: "#3fa055" },
            { t: "Workplace Safety",         u: "Updated Jan 10", v: "v4.0", c: "#F59E0B" },
            { t: "Privacy & Data Handling",  u: "Updated Dec 02", v: "v2.8", c: "#1E5BA8" },
            { t: "Procurement Policy",       u: "Updated Nov 14", v: "v1.4", c: "#DC2626" },
          ].map((p, i) => (
            <div key={i} className="icard" style={{ padding: 16 }}>
              <div style={{ display: "flex", alignItems: "center", gap: 10 }}>
                <div style={{ background: p.c + "22", color: p.c, width: 36, height: 36, borderRadius: 8, display: "grid", placeItems: "center" }}><BookIcon size={16} color={p.c} /></div>
                <div style={{ flex: 1, minWidth: 0 }}>
                  <div style={{ fontWeight: 700, fontSize: 13 }}>{p.t}</div>
                  <div style={{ fontSize: 11, color: "#6b7280" }}>{p.v} · {p.u}</div>
                </div>
              </div>
              <button className="ibtn-sec" style={{ marginTop: 10, width: "100%" }}>Read →</button>
            </div>
          ))}
        </div>
      </div>
    );
  }
  function IntranetCommsTra() {
    return (
      <div className="ipage" style={{ display: "flex", flexDirection: "column", gap: 16 }}>
        <div><h1>Training</h1><p className="lead">Modules, quizzes and certifications</p></div>
        <div style={{ display: "grid", gridTemplateColumns: "repeat(2, 1fr)", gap: 14 }}>
          {[
            { t: "MOTOTRBO Fundamentals",   p: 100, status: "Done",        c: "#3fa055", time: "1h 20m" },
            { t: "Customer Service 101",    p: 78,  status: "In progress", c: "#3B82F6", time: "45m left" },
            { t: "Cybersecurity Essentials",p: 33,  status: "In progress", c: "#7C3AED", time: "2h left"  },
            { t: "Workplace Safety 2026",   p: 0,   status: "Not started", c: "#94a3b8", time: "1h 30m" },
          ].map((m, i) => (
            <div key={i} className="icard" style={{ padding: 18 }}>
              <div style={{ display: "flex", justifyContent: "space-between", marginBottom: 10 }}>
                <div style={{ fontWeight: 700, fontSize: 15 }}>{m.t}</div>
                <span className="ipill" style={{ color: m.c, background: m.c + "15", border: "1px solid " + m.c + "44" }}>{m.status}</span>
              </div>
              <div style={{ height: 6, background: "#e6eaf0", borderRadius: 3, overflow: "hidden" }}><div style={{ width: m.p + "%", height: "100%", background: m.c }}></div></div>
              <div style={{ display: "flex", justifyContent: "space-between", marginTop: 8, fontSize: 11, color: "#6b7280" }}>
                <span>{m.p}% complete</span><span>{m.time}</span>
              </div>
              <button className="ibtn-blue" style={{ marginTop: 10, width: "100%" }}>{m.p === 100 ? "Review →" : m.p === 0 ? "Start →" : "Continue →"}</button>
            </div>
          ))}
        </div>
      </div>
    );
  }

  /* ──── Administration module ──── */
  function IntranetAdminClients() {
    return (
      <div className="ipage" style={{ display: "flex", flexDirection: "column", gap: 16 }}>
        <div style={{ display: "flex", justifyContent: "space-between" }}><div><h1>Client Records</h1><p className="lead">312 active clients · 18 inactive</p></div><button className="ibtn-blue">+ New client</button></div>
        <div className="icard" style={{ padding: 0, overflow: "hidden" }}>
          <table style={{ width: "100%", borderCollapse: "collapse", fontSize: 13 }}>
            <thead style={{ background: "#f7f8fa" }}><tr style={{ color: "#6b7280", textAlign: "left" }}>
              <th style={{ padding: "10px 16px" }}>Client</th><th style={{ padding: "10px 16px" }}>Industry</th><th style={{ padding: "10px 16px" }}>Contact</th><th style={{ padding: "10px 16px" }}>Contracts</th><th style={{ padding: "10px 16px" }}>Status</th>
            </tr></thead>
            <tbody>
              {[
                { c: "Pacific Logistics",      i: "Logistics",     ct: "Aaron Brooks · 604-555-0142",  n: 3, s: "Active",   col: "#3fa055" },
                { c: "Northwest Power Co.",    i: "Utilities",     ct: "Jenny Liu · 604-555-0238",     n: 2, s: "Active",   col: "#3fa055" },
                { c: "Yukon Mining Group",     i: "Mining",        ct: "Aaron Black · 867-555-0719",   n: 5, s: "Active",   col: "#3fa055" },
                { c: "Coast Security Ltd.",    i: "Security",      ct: "Mira Patel · 604-555-0481",    n: 2, s: "Renewal",  col: "#F59E0B" },
                { c: "Granite Construction",   i: "Construction",  ct: "Ben Schultz · 604-555-0613",   n: 4, s: "Active",   col: "#3fa055" },
                { c: "Aurora Logistics",       i: "Logistics",     ct: "Cara Diaz · 604-555-0995",     n: 0, s: "Inactive", col: "#94a3b8" },
              ].map((r, i) => (
                <tr key={i} style={{ borderTop: "1px solid #e6eaf0" }}>
                  <td style={{ padding: "11px 16px", fontWeight: 600 }}>{r.c}</td>
                  <td style={{ padding: "11px 16px", color: "#6b7280" }}>{r.i}</td>
                  <td style={{ padding: "11px 16px", fontSize: 12 }}>{r.ct}</td>
                  <td style={{ padding: "11px 16px" }}><strong style={{ color: "#0B2545" }}>{r.n}</strong></td>
                  <td style={{ padding: "11px 16px" }}><span className="ipill" style={{ color: r.col, background: r.col + "15", border: "1px solid " + r.col + "44" }}>● {r.s}</span></td>
                </tr>
              ))}
            </tbody>
          </table>
        </div>
      </div>
    );
  }
  function IntranetAdminUsers() {
    return (
      <div className="ipage" style={{ display: "flex", flexDirection: "column", gap: 16 }}>
        <div style={{ display: "flex", justifyContent: "space-between" }}><div><h1>User Management</h1><p className="lead">52 active users · 7 admins</p></div><button className="ibtn-blue">+ Invite user</button></div>
        <div className="icard" style={{ padding: 0, overflow: "hidden" }}>
          <table style={{ width: "100%", borderCollapse: "collapse", fontSize: 13 }}>
            <thead style={{ background: "#f7f8fa" }}><tr style={{ color: "#6b7280", textAlign: "left" }}>
              <th style={{ padding: "10px 16px" }}>Name</th><th style={{ padding: "10px 16px" }}>Email</th><th style={{ padding: "10px 16px" }}>Role</th><th style={{ padding: "10px 16px" }}>Last login</th><th style={{ padding: "10px 16px" }}>Status</th>
            </tr></thead>
            <tbody>
              {[
                { n: "Demo User",         e: "demo@abctelecom.example",       r: "Admin",       last: "Today 08:42",     s: "Active",  col: "#3fa055" },
                { n: "Lucas Almeida",     e: "lucas.almeida@abctelecom.example",     r: "Tech Lead",   last: "Today 09:11",     s: "Active",  col: "#3fa055" },
                { n: "Mariana Souza",     e: "mariana.souza@abctelecom.example",     r: "Tech Support",last: "Today 08:55",     s: "Active",  col: "#3fa055" },
                { n: "Hiroshi Tanaka",    e: "hiroshi.tanaka@abctelecom.example",    r: "Account Mgr", last: "Yesterday 17:30", s: "Active",  col: "#3fa055" },
                { n: "Aisha Khan",        e: "aisha.khan@abctelecom.example",        r: "Logistics",   last: "Today 07:48",     s: "Active",  col: "#3fa055" },
                { n: "Carlos Lopez",      e: "carlos.lopez@abctelecom.example",      r: "Driver",      last: "2 weeks ago",     s: "On leave",col: "#F59E0B" },
              ].map((u, i) => (
                <tr key={i} style={{ borderTop: "1px solid #e6eaf0" }}>
                  <td style={{ padding: "11px 16px", display: "flex", alignItems: "center", gap: 10 }}>
                    <div style={{ width: 28, height: 28, borderRadius: "50%", background: "linear-gradient(135deg,#5ab7ff,#1e6fb0)", color: "#fff", display: "grid", placeItems: "center", fontWeight: 700, fontSize: 11 }}>{u.n.split(" ").map((x) => x[0]).join("")}</div>
                    <span style={{ fontWeight: 600 }}>{u.n}</span>
                  </td>
                  <td style={{ padding: "11px 16px", fontSize: 12, color: "#6b7280" }}>{u.e}</td>
                  <td style={{ padding: "11px 16px" }}><span className="ipill" style={{ background: "#0B2545" + "15", color: "#0B2545", border: "1px solid #0B2545" + "44" }}>{u.r}</span></td>
                  <td style={{ padding: "11px 16px", color: "#6b7280", fontSize: 12 }}>{u.last}</td>
                  <td style={{ padding: "11px 16px" }}><span className="ipill" style={{ color: u.col, background: u.col + "15", border: "1px solid " + u.col + "44" }}>● {u.s}</span></td>
                </tr>
              ))}
            </tbody>
          </table>
        </div>
      </div>
    );
  }
  function IntranetAdminAudit() {
    return (
      <div className="ipage" style={{ display: "flex", flexDirection: "column", gap: 16 }}>
        <div><h1>Audit Log</h1><p className="lead">All sensitive actions are logged for 7 years</p></div>
        <div className="icard" style={{ padding: 0, overflow: "hidden" }}>
          {[
            { ts: "Today 09:11", who: "Lucas Almeida", action: "Closed OS-2026-1190", c: "#3fa055" },
            { ts: "Today 08:55", who: "Mariana Souza", action: "Updated client Pacific Logistics phone", c: "#3B82F6" },
            { ts: "Today 08:42", who: "Demo User", action: "Logged in", c: "#94a3b8" },
            { ts: "Yesterday 18:30", who: "Hiroshi Tanaka", action: "Created opportunity 'Fleet upgrade · 80 radios'", c: "#7C3AED" },
            { ts: "Yesterday 16:01", who: "Aisha Khan", action: "Approved manual time entry · Carlos Lopez", c: "#3fa055" },
            { ts: "Yesterday 14:22", who: "Demo User", action: "Permission change · Lucas → Tech Lead", c: "#DC2626" },
          ].map((a, i) => (
            <div key={i} style={{ padding: "10px 16px", borderTop: i ? "1px solid #e6eaf0" : "none", display: "flex", gap: 12, alignItems: "center", fontSize: 13 }}>
              <span style={{ width: 8, height: 8, borderRadius: "50%", background: a.c }}></span>
              <span style={{ fontFamily: "JetBrains Mono", fontSize: 11, color: "#6b7280", width: 120 }}>{a.ts}</span>
              <strong style={{ width: 160 }}>{a.who}</strong>
              <span style={{ flex: 1, color: "#4b5563" }}>{a.action}</span>
            </div>
          ))}
        </div>
      </div>
    );
  }
  function IntranetAdminSettings() {
    return (
      <div className="ipage" style={{ display: "flex", flexDirection: "column", gap: 16 }}>
        <div><h1>Settings</h1><p className="lead">Tenant configuration and integrations</p></div>
        <div style={{ display: "grid", gridTemplateColumns: "1fr 1fr", gap: 16 }}>
          {[
            { l: "General",          rows: [["Company name", "ABC Mais Telecom"], ["Time zone", "America/Vancouver (UTC-7)"], ["Currency", "CAD"], ["Language", "English (en-CA)"]] },
            { l: "Integrations",     rows: [["Microsoft 365", "Connected ✓"], ["Stripe", "Connected ✓"], ["WhatsApp Business", "Pending"], ["QuickBooks", "Disconnected"]] },
            { l: "Branding",         rows: [["Primary color", "#0B2545"], ["Accent", "#1E5BA8"], ["Logo", "logo-abc.png"], ["Favicon", "favicon.svg"]] },
            { l: "Security",         rows: [["MFA required", "Yes ✓"], ["Session timeout", "30 min"], ["IP allowlist", "12 entries"], ["Password rotation", "Every 90 days"]] },
          ].map((s, i) => (
            <div key={i} className="icard" style={{ padding: 18 }}>
              <div style={{ fontWeight: 700, marginBottom: 10 }}>{s.l}</div>
              {s.rows.map((r, j) => (
                <div key={j} style={{ display: "flex", justifyContent: "space-between", padding: "7px 0", borderTop: j ? "1px dashed #e6eaf0" : "none", fontSize: 13 }}>
                  <span style={{ color: "#6b7280" }}>{r[0]}</span><span style={{ fontWeight: 600 }}>{r[1]}</span>
                </div>
              ))}
            </div>
          ))}
        </div>
      </div>
    );
  }

  /* ═══════════════════════════════════════════════════════════════════
     DEMO 6 · SEO & SEM — marketing dashboard mock
     ═══════════════════════════════════════════════════════════════════ */
  function DemoSEO() {
    const [tab, setTab] = useState("overview");
    return (
      <div style={{ background: "#f8fafc", color: "#0f172a", minHeight: 720, fontFamily: "Inter, system-ui, sans-serif" }}>
        {/* Top bar */}
        <header style={{ background: "#fff", borderBottom: "1px solid #e2e8f0", padding: "14px 24px", display: "flex", alignItems: "center", gap: 16 }}>
          <div style={{ width: 40, height: 40, borderRadius: 10, background: "linear-gradient(135deg,#4285F4,#0F9D58,#F4B400,#DB4437)", display: "grid", placeItems: "center", color: "#fff", fontWeight: 800 }}>G</div>
          <div>
            <div style={{ fontWeight: 800, fontSize: 18, letterSpacing: "-0.01em" }}>SEO &amp; SEM Studio</div>
            <div style={{ fontSize: 12, color: "#64748b" }}>10 years of paid + organic growth · Google certified</div>
          </div>
          <div style={{ marginLeft: "auto", display: "flex", gap: 14, alignItems: "center", fontSize: 12, color: "#475569" }}>
            <span style={{ display: "flex", alignItems: "center", gap: 6 }}>● <strong style={{ color: "#0f9d58" }}>4 active campaigns</strong></span>
            <span>Last sync 2 min ago</span>
          </div>
        </header>

        {/* Tabs */}
        <nav style={{ background: "#fff", borderBottom: "1px solid #e2e8f0", padding: "0 24px", display: "flex", gap: 4 }}>
          {[
            { id: "overview", label: "Overview" },
            { id: "ads",      label: "Google Ads" },
            { id: "seo",      label: "Organic SEO" },
            { id: "ga",       label: "Analytics" },
          ].map((t) => {
            const a = tab === t.id;
            return (
              <button key={t.id} onClick={() => setTab(t.id)} style={{
                padding: "12px 16px", border: 0, background: "transparent", cursor: "pointer",
                color: a ? "#1a73e8" : "#64748b", fontWeight: 600, fontSize: 13,
                borderBottom: "3px solid " + (a ? "#1a73e8" : "transparent"),
                fontFamily: "Inter, sans-serif",
              }}>{t.label}</button>
            );
          })}
        </nav>

        <main style={{ padding: "20px 24px", display: "flex", flexDirection: "column", gap: 16 }}>
          {tab === "overview" && (
            <>
              <div style={{ display: "grid", gridTemplateColumns: "repeat(4, 1fr)", gap: 14 }}>
                {[
                  { l: "Years experience", v: "10+",   sub: "Search marketing", c: "#1a73e8" },
                  { l: "Avg CTR uplift",   v: "+38%",  sub: "After SEO audit",  c: "#0f9d58" },
                  { l: "Avg ROAS",         v: "5.2×",   sub: "Across paid",      c: "#fbbc05" },
                  { l: "Conversions / mo", v: "1,420", sub: "Last 90d avg",      c: "#ea4335" },
                ].map((k) => (
                  <div key={k.l} style={seoCard()}>
                    <div style={{ fontSize: 11, color: "#64748b", letterSpacing: "0.08em", textTransform: "uppercase" }}>{k.l}</div>
                    <div style={{ fontFamily: "Space Grotesk, sans-serif", fontSize: 30, fontWeight: 800, color: k.c, marginTop: 6, lineHeight: 1 }}>{k.v}</div>
                    <div style={{ fontSize: 12, color: "#64748b", marginTop: 4 }}>{k.sub}</div>
                  </div>
                ))}
              </div>

              <div style={{ display: "grid", gridTemplateColumns: "1.4fr 1fr", gap: 16 }}>
                <div style={{ ...seoCard(), padding: 18 }}>
                  <div style={{ fontWeight: 700, marginBottom: 12, color: "#0f172a" }}>Stack &amp; expertise</div>
                  <div style={{ display: "grid", gridTemplateColumns: "repeat(3, 1fr)", gap: 10 }}>
                    {[
                      { l: "Google Ads",       n: "Search · Display · YouTube · Performance Max", c: "#4285F4", g: "G" },
                      { l: "Google Tag Mgr.",  n: "Server-side & client-side tagging",                c: "#246FDB", g: "T" },
                      { l: "Google Analytics", n: "GA4 · UA migration · BigQuery export",         c: "#F9AB00", g: "A" },
                      { l: "Search Console",   n: "Indexing · Sitemaps · Core Web Vitals",         c: "#0F9D58", g: "S" },
                      { l: "SEO on-page",      n: "Schema · meta · internal linking · E-E-A-T",   c: "#1a73e8", g: "📈" },
                      { l: "Copywriting",      n: "Landing pages · ads · email sequences · UX",   c: "#DB4437", g: "✍" },
                    ].map((s) => (
                      <div key={s.l} style={{ background: "#f8fafc", border: "1px solid #e2e8f0", borderRadius: 10, padding: 12, display: "flex", gap: 10 }}>
                        <div style={{ width: 36, height: 36, borderRadius: 8, background: s.c, color: "#fff", display: "grid", placeItems: "center", fontWeight: 800, flexShrink: 0 }}>{s.g}</div>
                        <div style={{ minWidth: 0 }}>
                          <div style={{ fontWeight: 700, fontSize: 13 }}>{s.l}</div>
                          <div style={{ fontSize: 11, color: "#64748b", marginTop: 2, lineHeight: 1.4 }}>{s.n}</div>
                        </div>
                      </div>
                    ))}
                  </div>
                </div>
                <div style={{ ...seoCard(), padding: 18 }}>
                  <div style={{ fontWeight: 700, marginBottom: 12 }}>Proven results</div>
                  <div style={{ display: "flex", flexDirection: "column", gap: 12 }}>
                    {[
                      { t: "E-commerce · home goods", m: "ROAS 6.4× · Q3 2025", color: "#0f9d58" },
                      { t: "Language school", m: "Organic traffic +210% in 6 mo", color: "#1a73e8" },
                      { t: "B2B SaaS · scheduling", m: "CPA -42% with new ad copy", color: "#ea4335" },
                      { t: "Local services · Vancouver", m: "Top 3 for 18 keywords", color: "#fbbc05" },
                    ].map((r, i) => (
                      <div key={i} style={{ borderLeft: "3px solid " + r.color, padding: "6px 12px", background: r.color + "10", borderRadius: 4 }}>
                        <div style={{ fontWeight: 600, fontSize: 13 }}>{r.t}</div>
                        <div style={{ fontSize: 12, color: "#64748b" }}>{r.m}</div>
                      </div>
                    ))}
                  </div>
                </div>
              </div>
            </>
          )}

          {tab === "ads" && (
            <div style={{ ...seoCard(), padding: 0, overflow: "hidden" }}>
              <div style={{ padding: "12px 18px", borderBottom: "1px solid #e2e8f0", display: "flex", justifyContent: "space-between" }}>
                <strong>Active campaigns</strong>
                <span style={{ fontSize: 12, color: "#64748b" }}>Last 30 days</span>
              </div>
              <table style={{ width: "100%", borderCollapse: "collapse", fontSize: 13 }}>
                <thead style={{ background: "#f8fafc" }}><tr style={{ color: "#64748b", textAlign: "left" }}>
                  <th style={{ padding: "10px 18px" }}>Campaign</th><th style={{ padding: "10px 18px" }}>Type</th><th style={{ padding: "10px 18px" }}>Spend</th><th style={{ padding: "10px 18px" }}>CTR</th><th style={{ padding: "10px 18px" }}>Conv.</th><th style={{ padding: "10px 18px" }}>ROAS</th>
                </tr></thead>
                <tbody>
                  {[
                    { n: "Branded · Search", t: "Search", s: 4820, ctr: 12.4, c: 318, roas: 7.2 },
                    { n: "Generic · Cloud Eng.", t: "Search", s: 6210, ctr: 4.8, c: 142, roas: 3.6 },
                    { n: "Performance Max", t: "PMax", s: 3905, ctr: 2.1, c: 87, roas: 5.1 },
                    { n: "YouTube · Awareness", t: "Video", s: 1240, ctr: 1.4, c: 24, roas: 1.8 },
                    { n: "Retargeting · Display", t: "Display", s: 980, ctr: 0.8, c: 41, roas: 4.2 },
                  ].map((r, i) => (
                    <tr key={i} style={{ borderTop: "1px solid #e2e8f0" }}>
                      <td style={{ padding: "11px 18px", fontWeight: 600 }}>{r.n}</td>
                      <td style={{ padding: "11px 18px" }}><span style={{ background: "#e8f0fe", color: "#1a73e8", padding: "2px 8px", borderRadius: 999, fontSize: 11, fontWeight: 700 }}>{r.t}</span></td>
                      <td style={{ padding: "11px 18px" }}>${r.s.toLocaleString("en-US")}</td>
                      <td style={{ padding: "11px 18px", color: r.ctr >= 5 ? "#0f9d58" : "#64748b", fontWeight: 600 }}>{r.ctr}%</td>
                      <td style={{ padding: "11px 18px", fontWeight: 700 }}>{r.c}</td>
                      <td style={{ padding: "11px 18px", color: r.roas >= 4 ? "#0f9d58" : r.roas >= 2 ? "#fbbc05" : "#ea4335", fontWeight: 700 }}>{r.roas}×</td>
                    </tr>
                  ))}
                </tbody>
              </table>
            </div>
          )}

          {tab === "seo" && (
            <div style={{ display: "grid", gridTemplateColumns: "1fr 1fr", gap: 16 }}>
              <div style={{ ...seoCard(), padding: 18 }}>
                <div style={{ fontWeight: 700, marginBottom: 12 }}>Top organic keywords</div>
                {[
                  { k: "cloud engineer vancouver", pos: 2, vol: 880, ch: "+5" },
                  { k: "azure consultant bc",      pos: 3, vol: 590, ch: "+1" },
                  { k: "celpip prep online",       pos: 1, vol: 2400, ch: "—" },
                  { k: "m365 administrator jobs",  pos: 4, vol: 720, ch: "+2" },
                  { k: "intune deployment guide",  pos: 6, vol: 320, ch: "-1" },
                ].map((r, i) => (
                  <div key={i} style={{ display: "flex", alignItems: "center", padding: "8px 0", borderTop: i ? "1px dashed #e2e8f0" : "none", fontSize: 13 }}>
                    <span style={{ flex: 1 }}>{r.k}</span>
                    <span style={{ width: 50, textAlign: "right", fontWeight: 700, color: r.pos <= 3 ? "#0f9d58" : "#64748b" }}>#{r.pos}</span>
                    <span style={{ width: 70, textAlign: "right", color: "#64748b" }}>{r.vol.toLocaleString("en-US")}/mo</span>
                    <span style={{ width: 40, textAlign: "right", fontSize: 11, color: r.ch.startsWith("+") ? "#0f9d58" : r.ch === "—" ? "#94a3b8" : "#ea4335" }}>{r.ch}</span>
                  </div>
                ))}
              </div>
              <div style={{ ...seoCard(), padding: 18 }}>
                <div style={{ fontWeight: 700, marginBottom: 12 }}>Technical health</div>
                {[
                  { l: "Core Web Vitals", v: "92 / 100", c: "#0f9d58" },
                  { l: "Indexed pages",   v: "1,284 / 1,287", c: "#0f9d58" },
                  { l: "Crawl errors",    v: "3", c: "#fbbc05" },
                  { l: "Backlinks",       v: "412 (DA 38)", c: "#1a73e8" },
                  { l: "Schema coverage", v: "97%", c: "#0f9d58" },
                ].map((r, i) => (
                  <div key={i} style={{ display: "flex", justifyContent: "space-between", padding: "10px 0", borderTop: i ? "1px dashed #e2e8f0" : "none", fontSize: 13 }}>
                    <span style={{ color: "#64748b" }}>{r.l}</span>
                    <strong style={{ color: r.c }}>{r.v}</strong>
                  </div>
                ))}
              </div>
            </div>
          )}

          {tab === "ga" && (
            <div style={{ ...seoCard(), padding: 18 }}>
              <div style={{ fontWeight: 700, marginBottom: 14 }}>Acquisition by channel · last 30 days</div>
              <div style={{ display: "flex", alignItems: "flex-end", gap: 22, height: 220, padding: "0 10px" }}>
                {[
                  { l: "Organic Search", v: 38, c: "#0f9d58" },
                  { l: "Paid Search",    v: 28, c: "#1a73e8" },
                  { l: "Direct",         v: 14, c: "#fbbc05" },
                  { l: "Social",         v: 9,  c: "#ea4335" },
                  { l: "Referral",       v: 7,  c: "#7c3aed" },
                  { l: "Email",          v: 4,  c: "#0891b2" },
                ].map((b, i) => (
                  <div key={i} style={{ flex: 1, display: "flex", flexDirection: "column", alignItems: "center", gap: 8 }}>
                    <div style={{ fontSize: 12, fontWeight: 700, color: b.c }}>{b.v}%</div>
                    <div style={{ width: "100%", height: b.v * 4.5, background: b.c, borderRadius: "4px 4px 0 0", boxShadow: "0 4px 12px " + b.c + "44" }}></div>
                    <div style={{ fontSize: 11, color: "#64748b", fontWeight: 600, textAlign: "center" }}>{b.l}</div>
                  </div>
                ))}
              </div>
              <div style={{ marginTop: 16, paddingTop: 14, borderTop: "1px dashed #e2e8f0", display: "grid", gridTemplateColumns: "repeat(4, 1fr)", gap: 10, fontSize: 12 }}>
                {[
                  { l: "Sessions",      v: "184,210" },
                  { l: "Avg session",   v: "2 m 41 s" },
                  { l: "Bounce rate",   v: "38%" },
                  { l: "Conv. rate",    v: "3.8%" },
                ].map((s, i) => (
                  <div key={i}><div style={{ color: "#64748b", fontSize: 11, textTransform: "uppercase", letterSpacing: "0.08em" }}>{s.l}</div><div style={{ fontWeight: 700, color: "#1a73e8", fontSize: 16 }}>{s.v}</div></div>
                ))}
              </div>
            </div>
          )}
        </main>
      </div>
    );
  }
  function seoCard() {
    return { background: "#fff", border: "1px solid #e2e8f0", borderRadius: 10, padding: 18, boxShadow: "0 1px 2px rgba(16,24,40,.05)" };
  }

  window.ProjectsPage = ProjectsPage;
})();
