// Civic Modern — individual content sections, pickable per page.
// Each section is a self-contained Band that can be dropped into any page layout.

const { useState: useSectionState } = React;

// ─────────────────── shared helpers ───────────────────
function TypeRow({ size, weight, family, letterSpacing = 0, lineHeight = 1.1, sample, role }) {
  const t = window.tokens;
  return (
    <div style={{ display: 'grid', gridTemplateColumns: '140px 1fr', gap: 32, alignItems: 'baseline', borderBottom: `1px solid ${t.color.hair}`, padding: '16px 0' }}>
      <div style={{ fontFamily: t.font.mono, fontSize: 10, letterSpacing: 1.2, textTransform: 'uppercase', color: t.color.muted }}>
        {size}px · {weight}
        <div style={{ color: t.color.dim, marginTop: 2 }}>{role}</div>
      </div>
      <div style={{ fontFamily: family, fontSize: size, fontWeight: weight, letterSpacing, lineHeight, color: t.color.text }}>
        {sample}
      </div>
    </div>
  );
}

function Swatch({ name, hex, border, token }) {
  const t = window.tokens;
  return (
    <div>
      <div style={{ width: '100%', aspectRatio: '1.6 / 1', background: hex, border: border ? `1px solid ${border}` : 'none', borderRadius: 4 }} />
      <div style={{ marginTop: 10, fontSize: 12, fontWeight: 500, color: t.color.text }}>{name}</div>
      <div style={{ fontFamily: t.font.mono, fontSize: 10, color: t.color.muted, marginTop: 2, letterSpacing: 0.3 }}>{token}</div>
      <div style={{ fontFamily: t.font.mono, fontSize: 10, color: t.color.dim, letterSpacing: 0.3 }}>{hex.toUpperCase()}</div>
    </div>
  );
}

// ─────────────────── COVER ───────────────────
function CoverSection() {
  const t = window.tokens;
  return (
    <div style={{ padding: '56px 56px 48px' }}>
      <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'flex-start' }}>
        <div>
          <div style={{ marginBottom: 36 }}><GPWordmark height={24} hollow={t.color.action} solid={t.color.text} /></div>
          <Caption style={{ color: t.color.action, marginBottom: 20 }}>Civic Modern · v0.1 · Figtree system</Caption>
          <div style={{ fontSize: 72, lineHeight: 1, fontWeight: 500, letterSpacing: -3, marginBottom: 22, maxWidth: 900 }}>
            Plainly modern, <span style={{ color: t.color.muted }}>for government.</span>
          </div>
          <div style={{ fontSize: 19, lineHeight: 1.5, maxWidth: 680, color: t.color.body }}>
            The quiet confidence of contemporary software, translated for residents and municipal staff. White space does the talking; one orange does the pointing. This is the live spec sheet: tokens, type, color, and components in one place.
          </div>
        </div>
        <div style={{ textAlign: 'right' }}>
          <Caption>Canvas · White</Caption>
          <Caption style={{ marginTop: 6 }}>Primary · Action Orange</Caption>
          <Caption style={{ marginTop: 6 }}>Support · Blueprint</Caption>
          <Caption style={{ marginTop: 6 }}>Type · Figtree + IBM Plex Mono</Caption>
        </div>
      </div>
    </div>
  );
}

// ─────────────────── PRINCIPLES ───────────────────
function PrinciplesSection() {
  const t = window.tokens;
  return (
    <Band label="Foundations · Principles" code="01">
      <div style={{ display: 'grid', gridTemplateColumns: 'repeat(3, 1fr)', gap: 32 }}>
        {[
          { n: '01', t: 'One action at a time', d: 'Orange is reserved for the single thing that needs a person. Everything else recedes.' },
          { n: '02', t: 'Plain verbs, no jargon', d: 'Write like you\'re talking to someone on the phone. No "endpoint," no "submit entity."' },
          { n: '03', t: 'Quiet by default', d: 'Soft backgrounds, thin hairlines, generous whitespace. Fidelity through restraint, not decoration.' },
        ].map((p) => (
          <div key={p.n}>
            <div style={{ fontFamily: t.font.mono, fontSize: 11, color: t.color.action, marginBottom: 14, letterSpacing: 0.5 }}>{p.n}</div>
            <div style={{ fontSize: 19, fontWeight: 500, color: t.color.text, marginBottom: 8, letterSpacing: -0.3 }}>{p.t}</div>
            <div style={{ fontSize: 14, color: t.color.muted, lineHeight: 1.55 }}>{p.d}</div>
          </div>
        ))}
      </div>
    </Band>
  );
}

// ─────────────────── TYPOGRAPHY ───────────────────
function TypographySection() {
  const t = window.tokens;
  return (
    <Band label="Typography" code="02">
      <div style={{ display: 'grid', gridTemplateColumns: '1fr 320px', gap: 48 }}>
        <div>
          <TypeRow size={72} weight={500} family={t.font.sans} letterSpacing={-3} sample="Plainly modern." role="Display · XL" />
          <TypeRow size={56} weight={500} family={t.font.sans} letterSpacing={-2.4} sample="Tell us what you need." role="Display" />
          <TypeRow size={44} weight={500} family={t.font.sans} letterSpacing={-1.6} lineHeight={1.1} sample="One thing needs you today" role="H1" />
          <TypeRow size={36} weight={500} family={t.font.sans} letterSpacing={-1.0} lineHeight={1.15} sample="Your requests this month" role="H2" />
          <TypeRow size={28} weight={500} family={t.font.sans} letterSpacing={-0.6} lineHeight={1.2} sample="Building permits" role="H3" />
          <TypeRow size={22} weight={500} family={t.font.sans} letterSpacing={-0.3} lineHeight={1.3} sample="Inspection scheduled" role="H4" />
          <TypeRow size={17} weight={500} family={t.font.sans} letterSpacing={-0.1} lineHeight={1.35} sample="Required documents" role="H5" />
          <TypeRow size={13} weight={500} family={t.font.sans} letterSpacing={0.4} lineHeight={1.4} sample="PROPERTY DETAILS" role="H6 · All-caps label" />
          <TypeRow size={19} weight={400} family={t.font.sans} lineHeight={1.5} letterSpacing={-0.1} sample="Permits, licenses, payments, records, one place." role="Subhead" />
          <TypeRow size={16} weight={400} family={t.font.sans} lineHeight={1.5} sample="The workhorse size for paragraphs, descriptions, and long-form reading. Comfortable on desktop, accessible on mobile." role="Body" />
          <TypeRow size={13} weight={400} family={t.font.sans} lineHeight={1.5} sample="Small body for help text, captions, and secondary information in dense UI." role="Body · Small" />
          <TypeRow size={12} weight={500} family={t.font.mono} letterSpacing={1.4} sample="STEP 01 · OPTIONAL MONO MOMENTS" role="Mono · Label" />
        </div>
        <div>
          <SubLabel>Families</SubLabel>
          <Card variant="soft" pad={20} style={{ marginBottom: 16 }}>
            <div style={{ fontSize: 32, fontWeight: 500, letterSpacing: -0.8, marginBottom: 4 }}>Figtree</div>
            <Caption style={{ marginBottom: 10 }}>Primary · Display + UI</Caption>
            <div style={{ fontSize: 13, color: t.color.muted, lineHeight: 1.5 }}>Weights 400, 500. Medium for display and emphasis; Regular for everything else.</div>
          </Card>
          <Card variant="soft" pad={20} style={{ marginBottom: 16 }}>
            <div style={{ fontFamily: t.font.mono, fontSize: 20, fontWeight: 500, marginBottom: 4 }}>IBM Plex Mono</div>
            <Caption style={{ marginBottom: 10 }}>Accent · Labels + steps</Caption>
            <div style={{ fontSize: 13, color: t.color.muted, lineHeight: 1.5 }}>Never voice. Only step numbers, eyebrows, microlabels, and timestamps.</div>
          </Card>
          <Alert tone="info" title="Weight policy">
            Figtree Medium (500) for display and emphasis. Regular (400) for body and UI. No other weights.
          </Alert>
        </div>
      </div>
    </Band>
  );
}

// ─────────────────── COLOR ───────────────────
function ColorSection() {
  const t = window.tokens;
  return (
    <Band label="Color" code="03">
      <SubLabel>Surfaces + text</SubLabel>
      <div style={{ display: 'grid', gridTemplateColumns: 'repeat(6, 1fr)', gap: 16, marginBottom: 40 }}>
        <Swatch name="Canvas" hex={t.color.bg} border={t.color.hair} token="color.bg" />
        <Swatch name="Paper" hex={t.color.paper} border={t.color.hair} token="color.paper" />
        <Swatch name="Surface Hi" hex={t.color.surfaceHi} token="color.surfaceHi" />
        <Swatch name="Hair" hex={t.color.hair} token="color.hair" />
        <Swatch name="Strong" hex={t.color.strong} token="color.strong" />
        <Swatch name="Ink" hex={t.color.text} token="color.text" />
      </div>

      <SubLabel>Text</SubLabel>
      <div style={{ display: 'grid', gridTemplateColumns: 'repeat(4, 1fr)', gap: 16, marginBottom: 40 }}>
        <Swatch name="Text" hex={t.color.text} token="color.text" />
        <Swatch name="Body" hex={t.color.body} token="color.body" />
        <Swatch name="Muted" hex={t.color.muted} token="color.muted" />
        <Swatch name="Dim" hex={t.color.dim} token="color.dim" />
      </div>

      <SubLabel>Action · Primary</SubLabel>
      <div style={{ display: 'grid', gridTemplateColumns: 'repeat(4, 1fr)', gap: 16, marginBottom: 40 }}>
        <Swatch name="Action" hex={t.color.action} token="color.action" />
        <Swatch name="Action Hi" hex={t.color.actionHi} token="color.actionHi" />
        <Swatch name="Action Soft" hex={t.color.actionSoft} border={t.color.actionEdge} token="color.actionSoft" />
        <Swatch name="Action Edge" hex={t.color.actionEdge} token="color.actionEdge" />
      </div>

      <SubLabel>Status · Base</SubLabel>
      <div style={{ display: 'grid', gridTemplateColumns: 'repeat(4, 1fr)', gap: 16, marginBottom: 24 }}>
        <Swatch name="Blueprint" hex={t.color.bp} token="color.bp" />
        <Swatch name="Success" hex={t.color.ok} token="color.ok" />
        <Swatch name="Warn" hex={t.color.warn} token="color.warn" />
        <Swatch name="Error" hex={t.color.err} token="color.err" />
      </div>

      <SubLabel>Status · Light · Backgrounds + fills</SubLabel>
      <div style={{ display: 'grid', gridTemplateColumns: 'repeat(4, 1fr)', gap: 16, marginBottom: 28 }}>
        <Swatch name="Blueprint Light" hex={t.color.bpLight} border={t.color.hair} token="color.bpLight" />
        <Swatch name="Success Light" hex={t.color.okLight} border={t.color.hair} token="color.okLight" />
        <Swatch name="Warn Light" hex={t.color.warnLight} border={t.color.hair} token="color.warnLight" />
        <Swatch name="Error Light" hex={t.color.errLight} border={t.color.hair} token="color.errLight" />
      </div>

      <div style={{ marginTop: 8 }}>
        <Alert tone="action" title="One orange, one purpose">
          Action Orange (#D63600) only appears on the single thing that needs a person. Never for decoration, never for two things on the same screen. Status lights are for passive surfaces like pills, banner backgrounds, and timeline fills, not for calls to action.
        </Alert>
      </div>
    </Band>
  );
}

// ─────────────────── SPACING + RADII ───────────────────
function SpacingSection() {
  const t = window.tokens;
  return (
    <Band label="Spacing + Radii" code="04">
      <div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 48 }}>
        <div>
          <SubLabel>Spacing scale · 4px base</SubLabel>
          <div style={{ display: 'flex', flexDirection: 'column', gap: 10 }}>
            {t.space.slice(1).map((s) => (
              <div key={s} style={{ display: 'flex', alignItems: 'center', gap: 16 }}>
                <div style={{ fontFamily: t.font.mono, fontSize: 11, color: t.color.muted, width: 48, letterSpacing: 0.5 }}>{s}px</div>
                <div style={{ height: 8, width: s, background: t.color.action, borderRadius: 1 }} />
                <div style={{ fontFamily: t.font.mono, fontSize: 10, color: t.color.dim }}>space[{t.space.indexOf(s)}]</div>
              </div>
            ))}
          </div>
        </div>
        <div>
          <SubLabel>Radii</SubLabel>
          <div style={{ display: 'grid', gridTemplateColumns: 'repeat(3, 1fr)', gap: 16 }}>
            {[
              ['xs', 4], ['sm', 6], ['md', 8], ['lg', 10], ['xl', 12], ['pill', 999],
            ].map(([k, v]) => (
              <div key={k}>
                <div style={{ height: 64, background: t.color.surfaceHi, border: `1px solid ${t.color.hair}`, borderRadius: v }} />
                <div style={{ fontSize: 12, fontWeight: 500, marginTop: 8 }}>{k}</div>
                <div style={{ fontFamily: t.font.mono, fontSize: 10, color: t.color.muted }}>{v}px</div>
              </div>
            ))}
          </div>
          <div style={{ marginTop: 28 }}>
            <SubLabel>Elevation</SubLabel>
            <div style={{ display: 'grid', gridTemplateColumns: 'repeat(3, 1fr)', gap: 16 }}>
              <div style={{ padding: 18, background: t.color.bg, border: `1px solid ${t.color.hair}`, borderRadius: t.radius.lg, boxShadow: t.shadow.raised }}>
                <div style={{ fontSize: 13, fontWeight: 500 }}>Raised</div>
                <div style={{ fontFamily: t.font.mono, fontSize: 10, color: t.color.muted }}>shadow.raised</div>
              </div>
              <div style={{ padding: 18, background: t.color.bg, border: `1px solid ${t.color.strong}`, borderRadius: t.radius.lg, boxShadow: t.shadow.card }}>
                <div style={{ fontSize: 13, fontWeight: 500 }}>Card</div>
                <div style={{ fontFamily: t.font.mono, fontSize: 10, color: t.color.muted }}>shadow.card</div>
              </div>
              <div style={{ padding: 18, background: t.color.bg, border: `1px solid ${t.color.strong}`, borderRadius: t.radius.lg, boxShadow: t.shadow.pop }}>
                <div style={{ fontSize: 13, fontWeight: 500 }}>Pop</div>
                <div style={{ fontFamily: t.font.mono, fontSize: 10, color: t.color.muted }}>shadow.pop</div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </Band>
  );
}

// ─────────────────── COMPONENTS · BUTTONS ───────────────────
function ComponentsButtonsSection() {
  const t = window.tokens;

  const variants = [
    {
      key: 'primary',
      name: 'Primary',
      use: 'The single most important action on a screen. Reserved for the one thing that needs a person: submit, confirm, continue.',
      rule: 'One per screen, maximum.',
    },
    {
      key: 'secondary',
      name: 'Secondary',
      use: 'Supporting action next to a primary. Save for later, go back, view details. Outlined so it recedes.',
      rule: 'Use when a primary is also on screen.',
    },
    {
      key: 'tertiary',
      name: 'Tertiary',
      use: 'Low-emphasis action inside dense layouts, toolbars, and cards. No fill, no border, just a label.',
      rule: 'Use for repeated or inline actions where buttons would otherwise crowd each other.',
    },
    {
      key: 'destructive',
      name: 'Destructive',
      use: 'Irreversible or data-losing actions. Delete a request, revoke a license, cancel an application.',
      rule: 'Always pair with a confirmation step. Never use for routine actions.',
    },
    {
      key: 'link',
      name: 'Link',
      use: 'Inline navigation inside body copy or footnotes. Reads as text with an orange tint.',
      rule: 'Use for cross-references, not for actions.',
    },
  ];

  return (
    <Band label="Components · Buttons" code="05">
      <div style={{ display: 'flex', flexDirection: 'column', gap: 12, marginBottom: 28 }}>
        {variants.map((v) => (
          <div key={v.key} style={{
            display: 'grid',
            gridTemplateColumns: '220px 1fr',
            gap: 32,
            alignItems: 'center',
            padding: '20px 24px',
            border: `1px solid ${t.color.hair}`,
            borderRadius: t.radius.lg,
            background: t.color.bg,
          }}>
            <div style={{ display: 'flex', alignItems: 'center' }}>
              <Button variant={v.key}>
                {v.key === 'link' ? `${v.name} →` : v.name}
              </Button>
            </div>
            <div>
              <div style={{ display: 'flex', alignItems: 'baseline', gap: 12, marginBottom: 4 }}>
                <div style={{ fontSize: 15, fontWeight: 500, letterSpacing: -0.2 }}>{v.name}</div>
                <div style={{ fontFamily: t.font.mono, fontSize: 10, color: t.color.dim, letterSpacing: 0.8, textTransform: 'uppercase' }}>variant="{v.key}"</div>
              </div>
              <div style={{ fontSize: 13, color: t.color.body, lineHeight: 1.55, marginBottom: 4 }}>{v.use}</div>
              <div style={{ fontSize: 12, color: t.color.muted, lineHeight: 1.5, fontStyle: 'italic' }}>{v.rule}</div>
            </div>
          </div>
        ))}
      </div>

      <div style={{ display: 'grid', gridTemplateColumns: 'repeat(3, 1fr)', gap: 20 }}>
        <Tile label="Interaction states">
          <div style={{ display: 'grid', gridTemplateColumns: 'auto 1fr', gap: '10px 14px', alignItems: 'center' }}>
            <div style={{ fontSize: 11, color: t.color.muted, fontFamily: t.font.mono, letterSpacing: 0.8, textTransform: 'uppercase' }}>Default</div>
            <div><Button variant="primary">Submit</Button></div>

            <div style={{ fontSize: 11, color: t.color.muted, fontFamily: t.font.mono, letterSpacing: 0.8, textTransform: 'uppercase' }}>Hover</div>
            <div>
              <button className="cm-btn" data-variant="primary" style={{
                display: 'inline-flex', alignItems: 'center', gap: 6,
                background: '#B02C00', color: '#fff',
                border: '1px solid transparent', borderRadius: 6,
                padding: '9px 16px', fontSize: 14, fontFamily: t.font.sans,
                fontWeight: 500, letterSpacing: -0.1, cursor: 'pointer',
              }}>Submit</button>
            </div>

            <div style={{ fontSize: 11, color: t.color.muted, fontFamily: t.font.mono, letterSpacing: 0.8, textTransform: 'uppercase' }}>Focus</div>
            <div style={{ paddingLeft: 4 }}>
              <button style={{
                display: 'inline-flex', alignItems: 'center', gap: 6,
                background: t.color.action, color: '#fff',
                border: '1px solid transparent', borderRadius: 6,
                padding: '9px 16px', fontSize: 14, fontFamily: t.font.sans,
                fontWeight: 500, letterSpacing: -0.1, cursor: 'pointer',
                outline: `2px solid ${t.color.action}`,
                outlineOffset: 2,
              }}>Submit</button>
            </div>
          </div>
          <div style={{ fontSize: 12, color: t.color.muted, lineHeight: 1.5, marginTop: 4 }}>
            Hover darkens fills and background-tints ghost variants. Focus uses a 2px Action Orange ring with 2px offset — the same token as the primary button, so keyboard users see the brand as the focus signal.
          </div>
        </Tile>
        <Tile label="Sizes">
          <div style={{ display: 'flex', gap: 8, alignItems: 'center', flexWrap: 'wrap' }}>
            <Button variant="primary" size="sm">Small</Button>
            <Button variant="primary" size="md">Medium</Button>
            <Button variant="primary" size="lg">Large</Button>
          </div>
          <div style={{ display: 'flex', gap: 8, alignItems: 'center', flexWrap: 'wrap' }}>
            <Button variant="secondary" size="sm">Small</Button>
            <Button variant="secondary" size="md">Medium</Button>
            <Button variant="secondary" size="lg">Large</Button>
          </div>
        </Tile>
        <Tile label="Disabled">
          <div style={{ display: 'flex', gap: 8, alignItems: 'center', flexWrap: 'wrap' }}>
            <Button variant="primary" disabled>Primary</Button>
            <Button variant="secondary" disabled>Secondary</Button>
            <Button variant="tertiary" disabled>Tertiary</Button>
            <Button variant="destructive" disabled>Destructive</Button>
          </div>
          <div style={{ fontSize: 12, color: t.color.muted, lineHeight: 1.5 }}>
            Disabled states fade to 50% opacity. Only use when the action is temporarily unavailable, not as a way to hide it.
          </div>
        </Tile>
      </div>
    </Band>
  );
}

// ─────────────────── COMPONENTS · PILLS ───────────────────
function ComponentsPillsSection() {
  const colors = [
    { tone: 'neutral', name: 'Neutral' },
    { tone: 'action',  name: 'Orange' },
    { tone: 'info',    name: 'Blueprint' },
    { tone: 'ok',      name: 'Green' },
    { tone: 'warn',    name: 'Amber' },
    { tone: 'err',     name: 'Red' },
  ];
  return (
    <Band label="Components · Pills" code="06">
      <div style={{ display: 'grid', gridTemplateColumns: '1fr', gap: 20 }}>
        <Tile label="Pill · Light">
          <div style={{ display: 'flex', gap: 8, flexWrap: 'wrap' }}>
            {colors.map((c) => (
              <Pill key={c.tone} tone={c.tone} variant="light">{c.name}</Pill>
            ))}
          </div>
        </Tile>
        <Tile label="Pill · Dark">
          <div style={{ display: 'flex', gap: 8, flexWrap: 'wrap' }}>
            {colors.map((c) => (
              <Pill key={c.tone} tone={c.tone} variant="dark">{c.name}</Pill>
            ))}
          </div>
        </Tile>
      </div>
    </Band>
  );
}

// ─────────────────── COMPONENTS · FORMS ───────────────────
function ComponentsFormsSection() {
  const t = window.tokens;
  const [checked, setChecked] = useSectionState(true);
  const [radio, setRadio] = useSectionState('email');
  const [on, setOn] = useSectionState(true);

  const controls = [
    {
      key: 'input',
      name: 'Text input',
      use: 'Single-line typed entry. Names, addresses, reference numbers, short answers, anything that fits on one line.',
      rule: 'Always pair with a Field label. Use help text for format hints, error text only when the value is rejected.',
      sample: (
        <Field label="Property address" help="We'll use this to find your permits.">
          <Input defaultValue="218 Maple Street" />
        </Field>
      ),
    },
    {
      key: 'textarea',
      name: 'Textarea',
      use: 'Multi-line typed entry. Descriptions of an issue, explanations, longer-form answers.',
      rule: 'Size the default height to the expected answer: 3 rows for a sentence, 6 for a paragraph.',
      sample: (
        <Field label="Describe the issue">
          <Textarea defaultValue="The permit portal won't accept my property photo." />
        </Field>
      ),
    },
    {
      key: 'select',
      name: 'Select',
      use: 'Pick one from a known, bounded list. Municipalities, departments, document types.',
      rule: 'Use when the list is 4+ items or grows. For ≤3 fixed options, use Radio instead.',
      sample: (
        <Field label="Municipality">
          <Select defaultValue="Montclair">
            <option>Montclair</option><option>Bloomfield</option><option>Glen Ridge</option>
          </Select>
        </Field>
      ),
    },
    {
      key: 'checkbox',
      name: 'Checkbox',
      use: 'Independent on/off choices. Toggle a preference, agree to terms, select several items from a list.',
      rule: 'Each checkbox is its own answer. If the choices are mutually exclusive, use Radio.',
      sample: <Checkbox checked={checked} onChange={() => setChecked(!checked)} label="Email me status updates" />,
    },
    {
      key: 'radio',
      name: 'Radio',
      use: 'Pick exactly one from a small, visible set. Contact preference, payment method, yes/no/maybe.',
      rule: 'Always show all options at once. For long lists, use Select. Always have a default selection unless truly optional.',
      sample: (
        <div style={{ display: 'flex', flexDirection: 'column', gap: 8 }}>
          <Radio checked={radio === 'email'} onChange={() => setRadio('email')} label="Contact by email" />
          <Radio checked={radio === 'phone'} onChange={() => setRadio('phone')} label="Contact by phone" />
        </div>
      ),
    },
    {
      key: 'switch',
      name: 'Switch',
      use: 'Turn a setting on or off with immediate effect. Notifications, data sharing, feature toggles.',
      rule: 'Use when the change applies the moment it flips. If the choice is only saved on submit, use Checkbox.',
      sample: <Switch checked={on} onChange={() => setOn(!on)} label="Send me weekly digest" />,
    },
  ];

  const practices = [
    {
      title: 'No placeholder text by default',
      body: 'Placeholder text disappears the moment the field is focused, takes focus away from the label, and is often mistaken for a pre-filled value. Put guidance in the label or helper text instead.',
      exceptions: 'Date fields that show the expected format, and search fields where the placeholder invites interaction.',
    },
  ];

  return (
    <Band label="Components · Forms" code="06">
      <div style={{ display: 'flex', flexDirection: 'column', gap: 12, marginBottom: 28 }}>
        {controls.map((v) => (
          <div key={v.key} style={{
            display: 'grid',
            gridTemplateColumns: '280px 1fr',
            gap: 32,
            alignItems: 'center',
            padding: '24px',
            border: `1px solid ${t.color.hair}`,
            borderRadius: t.radius.lg,
            background: t.color.bg,
          }}>
            <div style={{ display: 'flex', alignItems: 'center' }}>{v.sample}</div>
            <div>
              <div style={{ display: 'flex', alignItems: 'baseline', gap: 12, marginBottom: 4 }}>
                <div style={{ fontSize: 15, fontWeight: 500, letterSpacing: -0.2 }}>{v.name}</div>
                <div style={{ fontFamily: t.font.mono, fontSize: 10, color: t.color.dim, letterSpacing: 0.8, textTransform: 'uppercase' }}>&lt;{v.key}&gt;</div>
              </div>
              <div style={{ fontSize: 13, color: t.color.body, lineHeight: 1.55, marginBottom: 4 }}>{v.use}</div>
              <div style={{ fontSize: 12, color: t.color.muted, lineHeight: 1.5, fontStyle: 'italic' }}>{v.rule}</div>
            </div>
          </div>
        ))}
      </div>

      {/* ─── CHECKBOX STATES + SIZES ─── */}
      <div style={{ display: 'flex', alignItems: 'baseline', gap: 12, marginBottom: 12 }}>
        <div style={{ fontSize: 15, fontWeight: 500, letterSpacing: -0.2 }}>Checkbox</div>
        <div style={{ fontFamily: t.font.mono, fontSize: 10, color: t.color.dim, letterSpacing: 0.8, textTransform: 'uppercase' }}>States &amp; sizes</div>
      </div>
      <div style={{ display: 'grid', gridTemplateColumns: 'repeat(2, 1fr)', gap: 20, marginBottom: 28 }}>
        <Tile label="States">
          <div style={{ display: 'grid', gridTemplateColumns: 'auto 1fr', gap: '14px 20px', alignItems: 'center' }}>
            <div style={{ fontSize: 11, color: t.color.muted, fontFamily: t.font.mono, letterSpacing: 0.8, textTransform: 'uppercase' }}>Unselected</div>
            <div><Checkbox checked={false} onChange={() => {}} label="Email me status updates" /></div>

            <div style={{ fontSize: 11, color: t.color.muted, fontFamily: t.font.mono, letterSpacing: 0.8, textTransform: 'uppercase' }}>Selected</div>
            <div><Checkbox checked={true} onChange={() => {}} label="Email me status updates" /></div>

            <div style={{ fontSize: 11, color: t.color.muted, fontFamily: t.font.mono, letterSpacing: 0.8, textTransform: 'uppercase' }}>Disabled</div>
            <div><Checkbox checked={false} disabled label="Email me status updates" /></div>

            <div style={{ fontSize: 11, color: t.color.muted, fontFamily: t.font.mono, letterSpacing: 0.8, textTransform: 'uppercase' }}>Disabled · on</div>
            <div><Checkbox checked={true} disabled label="Email me status updates" /></div>
          </div>
        </Tile>
        <Tile label="Sizes">
          <div style={{ display: 'grid', gridTemplateColumns: 'auto 1fr', gap: '14px 20px', alignItems: 'center' }}>
            <div style={{ fontSize: 11, color: t.color.muted, fontFamily: t.font.mono, letterSpacing: 0.8, textTransform: 'uppercase' }}>Default · md</div>
            <div><Checkbox checked={true} onChange={() => {}} label="Email me status updates" /></div>

            <div style={{ fontSize: 11, color: t.color.muted, fontFamily: t.font.mono, letterSpacing: 0.8, textTransform: 'uppercase' }}>Small · sm</div>
            <div><Checkbox size="sm" checked={true} onChange={() => {}} label="Email me status updates" /></div>
          </div>
          <div style={{ fontSize: 12, color: t.color.muted, lineHeight: 1.5, marginTop: 12 }}>
            Default (20px box / 15px label) is the everyday size. Use <span style={{ fontFamily: t.font.mono }}>size="sm"</span> (16px / 14px) only inside dense UI like tables, filter panels, and settings rows.
          </div>
        </Tile>
      </div>

      {/* ─── RADIO STATES + SIZES ─── */}
      <div style={{ display: 'flex', alignItems: 'baseline', gap: 12, marginBottom: 12 }}>
        <div style={{ fontSize: 15, fontWeight: 500, letterSpacing: -0.2 }}>Radio</div>
        <div style={{ fontFamily: t.font.mono, fontSize: 10, color: t.color.dim, letterSpacing: 0.8, textTransform: 'uppercase' }}>States &amp; sizes</div>
      </div>
      <div style={{ display: 'grid', gridTemplateColumns: 'repeat(2, 1fr)', gap: 20, marginBottom: 28 }}>
        <Tile label="States">
          <div style={{ display: 'grid', gridTemplateColumns: 'auto 1fr', gap: '14px 20px', alignItems: 'center' }}>
            <div style={{ fontSize: 11, color: t.color.muted, fontFamily: t.font.mono, letterSpacing: 0.8, textTransform: 'uppercase' }}>Unselected</div>
            <div><Radio checked={false} onChange={() => {}} label="Contact by email" /></div>

            <div style={{ fontSize: 11, color: t.color.muted, fontFamily: t.font.mono, letterSpacing: 0.8, textTransform: 'uppercase' }}>Selected</div>
            <div><Radio checked={true} onChange={() => {}} label="Contact by email" /></div>

            <div style={{ fontSize: 11, color: t.color.muted, fontFamily: t.font.mono, letterSpacing: 0.8, textTransform: 'uppercase' }}>Disabled</div>
            <div><Radio checked={false} disabled label="Contact by email" /></div>

            <div style={{ fontSize: 11, color: t.color.muted, fontFamily: t.font.mono, letterSpacing: 0.8, textTransform: 'uppercase' }}>Disabled · on</div>
            <div><Radio checked={true} disabled label="Contact by email" /></div>
          </div>
        </Tile>
        <Tile label="Sizes">
          <div style={{ display: 'grid', gridTemplateColumns: 'auto 1fr', gap: '14px 20px', alignItems: 'center' }}>
            <div style={{ fontSize: 11, color: t.color.muted, fontFamily: t.font.mono, letterSpacing: 0.8, textTransform: 'uppercase' }}>Default · md</div>
            <div><Radio checked={true} onChange={() => {}} label="Contact by email" /></div>

            <div style={{ fontSize: 11, color: t.color.muted, fontFamily: t.font.mono, letterSpacing: 0.8, textTransform: 'uppercase' }}>Small · sm</div>
            <div><Radio size="sm" checked={true} onChange={() => {}} label="Contact by email" /></div>
          </div>
          <div style={{ fontSize: 12, color: t.color.muted, lineHeight: 1.5, marginTop: 12 }}>
            Match checkbox sizing. Default in forms and settings; small inside dense filter rows or multi-column tables.
          </div>
        </Tile>
      </div>

      {/* ─── INPUT · INVALID (kept as a tile since it's a state not a variant) ─── */}
      <div style={{ display: 'grid', gridTemplateColumns: 'repeat(2, 1fr)', gap: 20 }}>
        <Tile label="Error state">
          <Field label="Email" help="We'll send status updates to this address." error="This email isn't registered with the state.">
            <Input defaultValue="resident@examle.co" invalid />
          </Field>
          <div style={{ fontSize: 12, color: t.color.muted, lineHeight: 1.5, marginTop: 12 }}>
            The input border thickens to 2px and shifts to red. Error text appears below in red with a leading icon. Helper text stays put above the input. Use specific, human language. Never just "Invalid entry."
          </div>
        </Tile>
        <Tile label="Field anatomy">
          <Field label="Property address" help="We'll use this to find your permits.">
            <Input defaultValue="218 Maple Street" />
          </Field>
          <div style={{ fontSize: 12, color: t.color.muted, lineHeight: 1.5, marginTop: 12 }}>
            Label (15px, title case) sits 8px above helper text (12px, muted), which sits 8px above the input. Helper text always stays visible. Error text, when set, appears below the input in red.
          </div>
        </Tile>
      </div>

      {/* ─── BEST PRACTICES ─── */}
      <div style={{ marginTop: 28 }}>
        <div style={{ display: 'flex', alignItems: 'baseline', gap: 12, marginBottom: 12 }}>
          <div style={{ fontSize: 15, fontWeight: 500, letterSpacing: -0.2 }}>Best practices</div>
          <div style={{ fontFamily: t.font.mono, fontSize: 10, color: t.color.dim, letterSpacing: 0.8, textTransform: 'uppercase' }}>Rules that apply to every field</div>
        </div>
        <div style={{ display: 'flex', flexDirection: 'column', gap: 12 }}>
          {practices.map((p, i) => (
            <div key={i} style={{
              display: 'grid',
              gridTemplateColumns: '40px 1fr',
              gap: 20,
              padding: '20px 24px',
              border: `1px solid ${t.color.hair}`,
              borderRadius: t.radius.lg,
              background: t.color.bg,
            }}>
              <div style={{ fontFamily: t.font.mono, fontSize: 11, color: t.color.muted, letterSpacing: 0.8 }}>
                {String(i + 1).padStart(2, '0')}
              </div>
              <div>
                <div style={{ fontSize: 14, fontWeight: 500, color: t.color.text, marginBottom: 6 }}>{p.title}</div>
                <div style={{ fontSize: 13, color: t.color.body, lineHeight: 1.55, marginBottom: p.exceptions ? 6 : 0 }}>{p.body}</div>
                {p.exceptions && (
                  <div style={{ fontSize: 12, color: t.color.muted, lineHeight: 1.5, fontStyle: 'italic' }}>
                    Exceptions: {p.exceptions}
                  </div>
                )}
              </div>
            </div>
          ))}
        </div>
      </div>
    </Band>
  );
}

// ─────────────────── COMPONENTS · CONTAINERS ───────────────────
function ComponentsContainersSection() {
  const t = window.tokens;
  return (
    <Band label="Components · Containers" code="07">
      <div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 20 }}>
        <Tile label="Card · Default" pad={0} minHeight={0}>
          <div style={{ padding: 24 }}>
            <Card>
              <div style={{ fontSize: 15, fontWeight: 500, marginBottom: 6 }}>Building permit</div>
              <div style={{ fontSize: 13, color: t.color.muted, lineHeight: 1.5 }}>218 Maple Street · In review since April 18.</div>
            </Card>
          </div>
        </Tile>
        <Tile label="Card · Raised" pad={0} minHeight={0}>
          <div style={{ padding: 24 }}>
            <Card variant="raised">
              <div style={{ fontSize: 15, fontWeight: 500, marginBottom: 6 }}>Final inspection</div>
              <div style={{ fontSize: 13, color: t.color.muted, lineHeight: 1.5 }}>Thursday at 10:00 AM. Rick Cuffe.</div>
            </Card>
          </div>
        </Tile>
        <Tile label="Service card" pad={0} minHeight={0}>
          <div style={{ padding: 24 }}>
            <ServiceCard title="Building permits" desc="Apply, amend, or schedule an inspection." />
          </div>
        </Tile>
        <Tile label="Empty state" pad={0} minHeight={0}>
          <div style={{ padding: 24 }}>
            <EmptyState
              title="No requests yet"
              desc="Your active requests and applications will show up here."
              action={<Button variant="primary" size="sm">Start a request</Button>}
            />
          </div>
        </Tile>
      </div>
    </Band>
  );
}

// ─────────────────── COMPONENTS · ALERTS ───────────────────
function ComponentsAlertsSection() {
  const t = window.tokens;

  const tones = [
    {
      key: 'info',
      name: 'Info',
      use: 'Passive context. Average wait times, process explanations, status without urgency.',
      rule: 'Never demands action. If the reader must do something, use Action instead.',
      sample: (
        <Alert tone="info" title="Your permit is under review">
          Average review time for Montclair is 7 business days.
        </Alert>
      ),
    },
    {
      key: 'action',
      name: 'Action',
      use: 'A person needs to do one specific thing before the process can move forward.',
      rule: 'Always pair with a concrete action button. One Action alert per screen.',
      sample: (
        <Alert tone="action" title="Business license needs a signed W-9" action={<Button variant="primary" size="sm">Upload</Button>}>
          Upload it here and we'll send it to the Clerk's office.
        </Alert>
      ),
    },
    {
      key: 'ok',
      name: 'Success',
      use: 'Something completed cleanly. A renewal went through, a payment cleared, a form was accepted.',
      rule: 'Confirms a past event. Does not ask for anything.',
      sample: (
        <Alert tone="ok" title="Dog license renewed">
          Expires April 22, 2027.
        </Alert>
      ),
    },
    {
      key: 'warn',
      name: 'Warning',
      use: 'Something changed that the reader should know about, but no immediate action is required.',
      rule: 'Use for schedule changes, policy updates, weather disruptions. Escalate to Action if a response is needed.',
      sample: (
        <Alert tone="warn" title="Inspection rescheduled">
          Moved from Wed to Thu 10:00 AM due to weather.
        </Alert>
      ),
    },
  ];

  return (
    <Band label="Components · Alerts" code="08">
      <div style={{ display: 'flex', flexDirection: 'column', gap: 12 }}>
        {tones.map((v) => (
          <div key={v.key} style={{
            display: 'grid',
            gridTemplateColumns: '360px 1fr',
            gap: 32,
            alignItems: 'center',
            padding: '20px 24px',
            border: `1px solid ${t.color.hair}`,
            borderRadius: t.radius.lg,
            background: t.color.bg,
          }}>
            <div>{v.sample}</div>
            <div>
              <div style={{ display: 'flex', alignItems: 'baseline', gap: 12, marginBottom: 4 }}>
                <div style={{ fontSize: 15, fontWeight: 500, letterSpacing: -0.2 }}>{v.name}</div>
                <div style={{ fontFamily: t.font.mono, fontSize: 10, color: t.color.dim, letterSpacing: 0.8, textTransform: 'uppercase' }}>tone="{v.key}"</div>
              </div>
              <div style={{ fontSize: 13, color: t.color.body, lineHeight: 1.55, marginBottom: 4 }}>{v.use}</div>
              <div style={{ fontSize: 12, color: t.color.muted, lineHeight: 1.5, fontStyle: 'italic' }}>{v.rule}</div>
            </div>
          </div>
        ))}
      </div>
    </Band>
  );
}

// ─────────────────── COMPONENTS · COMPOSER ───────────────────
function ComponentsComposerSection() {
  const t = window.tokens;

  const variants = [
    {
      key: 'full',
      name: 'Full',
      use: 'The signature entry point on the home page and at the top of each service hub. Invites a resident to describe what they need in their own words.',
      rule: 'One per screen. Primary button reads "Get Started" on the home page and can shift to the specific next step on contextual pages.',
      sample: <Composer />,
    },
    {
      key: 'compact',
      name: 'Compact',
      use: 'A one-line composer for inline asks inside a flow: refining an in-progress request, asking a follow-up question on a record page, or replying to staff.',
      rule: 'Single line only. No attach or voice affordances. Primary button reads "Send".',
      sample: <Composer variant="compact" placeholder="Send a message or ask a follow-up…" />,
    },
  ];

  return (
    <Band label="Components · Composer" code="09">
      <div style={{ display: 'flex', flexDirection: 'column', gap: 12 }}>
        {variants.map((v) => (
          <div key={v.key} style={{
            display: 'grid',
            gridTemplateColumns: '1fr',
            gap: 20,
            padding: '24px',
            border: `1px solid ${t.color.hair}`,
            borderRadius: t.radius.lg,
            background: t.color.bg,
          }}>
            <div>{v.sample}</div>
            <div style={{ paddingTop: 16, borderTop: `1px solid ${t.color.hair}` }}>
              <div style={{ display: 'flex', alignItems: 'baseline', gap: 12, marginBottom: 4 }}>
                <div style={{ fontSize: 15, fontWeight: 500, letterSpacing: -0.2 }}>{v.name}</div>
                <div style={{ fontFamily: t.font.mono, fontSize: 10, color: t.color.dim, letterSpacing: 0.8, textTransform: 'uppercase' }}>variant="{v.key}"</div>
              </div>
              <div style={{ fontSize: 13, color: t.color.body, lineHeight: 1.55, marginBottom: 4 }}>{v.use}</div>
              <div style={{ fontSize: 12, color: t.color.muted, lineHeight: 1.5, fontStyle: 'italic' }}>{v.rule}</div>
            </div>
          </div>
        ))}
      </div>
    </Band>
  );
}

// ─────────────────── COMPONENTS · BREADCRUMBS ───────────────────
function ComponentsBreadcrumbsSection() {
  const t = window.tokens;
  return (
    <Band label="Components · Breadcrumbs" code="10">
      <div style={{
        display: 'grid',
        gridTemplateColumns: '1fr',
        gap: 20,
        padding: '24px',
        border: `1px solid ${t.color.hair}`,
        borderRadius: t.radius.lg,
        background: t.color.bg,
      }}>
        <Breadcrumbs items={['Services', 'Licenses', 'Business', 'Apply']} />
        <div style={{ paddingTop: 16, borderTop: `1px solid ${t.color.hair}` }}>
          <div style={{ fontSize: 15, fontWeight: 500, letterSpacing: -0.2, marginBottom: 4 }}>When to use</div>
          <div style={{ fontSize: 13, color: t.color.body, lineHeight: 1.55, marginBottom: 10 }}>
            Show the path from the section home down to the current page, once the user is three or more levels deep. Residents need to know where they are and how to step back.
          </div>
          <div style={{ fontSize: 15, fontWeight: 500, letterSpacing: -0.2, marginBottom: 4 }}>Rules</div>
          <div style={{ fontSize: 13, color: t.color.body, lineHeight: 1.55 }}>
            Every segment except the last is a link. The current page is plain text. Never use breadcrumbs as the only way to navigate up. Do not shorten or abbreviate segment names.
          </div>
        </div>
      </div>
    </Band>
  );
}

// ─────────────────── COMPONENTS · TABS ───────────────────
function ComponentsTabsSection() {
  const t = window.tokens;
  const [tab, setTab] = useSectionState(0);
  return (
    <Band label="Components · Tabs" code="11">
      <div style={{
        padding: '24px',
        border: `1px solid ${t.color.hair}`,
        borderRadius: t.radius.lg,
        background: t.color.bg,
      }}>
        <Tabs items={['All requests', 'In review', 'Action needed', 'Completed']} active={tab} onChange={setTab} />
        <div style={{ padding: '16px 0 24px', fontSize: 13, color: t.color.muted }}>
          Showing {['4 requests', '1 in review', '1 needs action', '1 completed'][tab]}.
        </div>
        <div style={{ paddingTop: 16, borderTop: `1px solid ${t.color.hair}` }}>
          <div style={{ fontSize: 15, fontWeight: 500, letterSpacing: -0.2, marginBottom: 4 }}>When to use</div>
          <div style={{ fontSize: 13, color: t.color.body, lineHeight: 1.55, marginBottom: 10 }}>
            Switch between peer views of the same underlying data. Status filters on a request list, sections of a record detail page, or time ranges on a dashboard.
          </div>
          <div style={{ fontSize: 15, fontWeight: 500, letterSpacing: -0.2, marginBottom: 4 }}>Rules</div>
          <div style={{ fontSize: 13, color: t.color.body, lineHeight: 1.55 }}>
            Two to six tabs. Never more. If the set grows, move to a filter or dropdown. The first tab is always selected by default. Tab labels are short nouns or noun phrases.
          </div>
        </div>
      </div>
    </Band>
  );
}

// ─────────────────── COMPONENTS · AVATAR ───────────────────
function ComponentsAvatarSection() {
  const t = window.tokens;

  const variants = [
    {
      key: 'initials',
      name: 'Initials',
      use: 'The default. Works when you have a name but no photo on file — which is most residents and most staff. Reads cleanly at every size.',
      rule: 'Two letters, uppercase, drawn from the person\u2019s given and family name. Sizes follow the type scale: 24 / 28 / 32 / 40.',
      sample: (
        <div style={{ display: 'flex', gap: 16, alignItems: 'center' }}>
          <Avatar initials="RC" size={24} />
          <Avatar initials="AM" size={28} />
          <Avatar initials="JT" size={32} />
          <Avatar initials="DB" size={40} />
        </div>
      ),
    },
    {
      key: 'photo',
      name: 'Photo',
      use: 'When a real portrait is on file and identity matters: an inspector or clerk shown on a resident-facing status page, or a staff directory.',
      rule: 'Square source, cropped to a circle. Never stretch. Fall back to initials when the image fails to load or is missing.',
      sample: (
        <div style={{ display: 'flex', gap: 16, alignItems: 'center' }}>
          <Avatar src="assets/avatar-sample-01.svg" alt="Rick Cuffe" size={24} />
          <Avatar src="assets/avatar-sample-02.svg" alt="Amina Marshall" size={28} />
          <Avatar src="assets/avatar-sample-01.svg" alt="Jamie Torres" size={32} />
          <Avatar src="assets/avatar-sample-02.svg" alt="Dana Brooks" size={40} />
        </div>
      ),
    },
  ];

  return (
    <Band label="Components · Avatar" code="12">
      <div style={{ display: 'flex', flexDirection: 'column', gap: 12 }}>
        {variants.map((v) => (
          <div key={v.key} style={{
            display: 'grid',
            gridTemplateColumns: '280px 1fr',
            gap: 32,
            alignItems: 'center',
            padding: '24px',
            border: `1px solid ${t.color.hair}`,
            borderRadius: t.radius.lg,
            background: t.color.bg,
          }}>
            <div style={{ display: 'flex', alignItems: 'center' }}>{v.sample}</div>
            <div>
              <div style={{ display: 'flex', alignItems: 'baseline', gap: 12, marginBottom: 4 }}>
                <div style={{ fontSize: 15, fontWeight: 500, letterSpacing: -0.2 }}>{v.name}</div>
                <div style={{ fontFamily: t.font.mono, fontSize: 10, color: t.color.dim, letterSpacing: 0.8, textTransform: 'uppercase' }}>{v.key === 'photo' ? 'src="…"' : 'initials="…"'}</div>
              </div>
              <div style={{ fontSize: 13, color: t.color.body, lineHeight: 1.55, marginBottom: 4 }}>{v.use}</div>
              <div style={{ fontSize: 12, color: t.color.muted, lineHeight: 1.5, fontStyle: 'italic' }}>{v.rule}</div>
            </div>
          </div>
        ))}
      </div>
    </Band>
  );
}

// ─────────────────── COMPONENTS · PROGRESS ───────────────────
function ComponentsProgressSection() {
  const t = window.tokens;
  return (
    <Band label="Components · Progress" code="13">
      <div style={{
        padding: '24px',
        border: `1px solid ${t.color.hair}`,
        borderRadius: t.radius.lg,
        background: t.color.bg,
      }}>
        <div style={{ display: 'flex', flexDirection: 'column', gap: 16, marginBottom: 24 }}>
          <Progress value={35} label="Application progress" />
          <Progress value={72} label="Inspections scheduled" />
          <Progress value={100} label="Payments reconciled" />
        </div>
        <div style={{ paddingTop: 16, borderTop: `1px solid ${t.color.hair}` }}>
          <div style={{ fontSize: 15, fontWeight: 500, letterSpacing: -0.2, marginBottom: 4 }}>When to use</div>
          <div style={{ fontSize: 13, color: t.color.body, lineHeight: 1.55, marginBottom: 10 }}>
            Show how much of a known, bounded quantity is complete. Application completion, inspection coverage, payment reconciliation.
          </div>
          <div style={{ fontSize: 15, fontWeight: 500, letterSpacing: -0.2, marginBottom: 4 }}>Rules</div>
          <div style={{ fontSize: 13, color: t.color.body, lineHeight: 1.55 }}>
            Always pair with a label and a numeric value. Only use when the denominator is known. For indeterminate or process-state progress, use a Stepper instead.
          </div>
        </div>
      </div>
    </Band>
  );
}

// ─────────────────── COMPONENTS · STEPPER ───────────────────
function ComponentsStepperSection() {
  const t = window.tokens;
  return (
    <Band label="Components · Stepper" code="14">
      <div style={{
        padding: '24px',
        border: `1px solid ${t.color.hair}`,
        borderRadius: t.radius.lg,
        background: t.color.bg,
      }}>
        <div style={{ marginBottom: 24 }}>
          <Stepper steps={['Identify', 'Documents', 'Review', 'Pay', 'Done']} current={2} />
        </div>
        <div style={{ paddingTop: 16, borderTop: `1px solid ${t.color.hair}` }}>
          <div style={{ fontSize: 15, fontWeight: 500, letterSpacing: -0.2, marginBottom: 4 }}>When to use</div>
          <div style={{ fontSize: 13, color: t.color.body, lineHeight: 1.55, marginBottom: 10 }}>
            Show where a resident is inside a multi-step flow: a permit application, a license renewal, an inspection booking. Each step is a discrete, named stage.
          </div>
          <div style={{ fontSize: 15, fontWeight: 500, letterSpacing: -0.2, marginBottom: 4 }}>Rules</div>
          <div style={{ fontSize: 13, color: t.color.body, lineHeight: 1.55 }}>
            Three to six steps. Step labels are verbs or short nouns. A step is only marked complete when the user can no longer change it without going back. Never use a Stepper for percentage progress.
          </div>
        </div>
      </div>
    </Band>
  );
}

// ─────────────────── COMPONENTS · DATA TABLE ───────────────────
function ComponentsDataSection() {
  const t = window.tokens;
  return (
    <Band label="Components · Data Table" code="09">
      <DataTable
        columns={[
          { key: 'title', label: 'Request', width: '1.4fr' },
          { key: 'where', label: 'Where', width: '1.4fr' },
          { key: 'status', label: 'Status', width: '1fr' },
          { key: 'when', label: 'Updated', width: '160px' },
        ]}
        rows={[
          { title: 'Building permit', where: '218 Maple Street', status: <Pill tone="neutral">In review</Pill>, when: <span style={{ fontSize: 13, color: t.color.muted }}>2 days ago</span> },
          { title: 'Final inspection', where: '218 Maple Street', status: <Pill tone="info">Scheduled · Thu</Pill>, when: <span style={{ fontSize: 13, color: t.color.muted }}>5 days ago</span> },
          { title: 'Business license', where: 'Maple & Orange LLC', status: <Pill tone="action">Action needed</Pill>, when: <span style={{ fontSize: 13, color: t.color.muted }}>6 days ago</span> },
          { title: 'Dog license renewal', where: 'Household · Bowie', status: <Pill tone="ok">Completed</Pill>, when: <span style={{ fontSize: 13, color: t.color.muted }}>Apr 22</span> },
        ]}
      />
    </Band>
  );
}

// ─────────────────── APPLIED · RESIDENT DASHBOARD ───────────────────
function ResidentDashboardSection() {
  const t = window.tokens;
  return (
    <Band label="Applied · Resident dashboard" code="10">
      <div style={{ border: `1px solid ${t.color.hair}`, borderRadius: t.radius.lg, overflow: 'hidden' }}>
        <div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', padding: '18px 28px', borderBottom: `1px solid ${t.color.hair}` }}>
          <div style={{ display: 'flex', alignItems: 'center', gap: 20 }}>
            <GPWordmark height={18} hollow={t.color.action} solid={t.color.text} />
            <div style={{ width: 1, height: 14, background: t.color.hair }} />
            <div style={{ fontSize: 13, color: t.color.muted }}>State of New Jersey</div>
          </div>
          <div style={{ display: 'flex', gap: 24, fontSize: 13, color: t.color.body, alignItems: 'center' }}>
            <span>Services</span>
            <span style={{ color: t.color.text, fontWeight: 500 }}>Track a request</span>
            <span>Help</span>
            <Avatar initials="RC" size={28} />
          </div>
        </div>

        <div style={{ padding: '40px 28px 28px' }}>
          <Caption style={{ marginBottom: 10 }}>Your requests</Caption>
          <div style={{ fontSize: 40, lineHeight: 1.1, letterSpacing: -1.4, fontWeight: 500, marginBottom: 6 }}>One thing needs you today.</div>
          <div style={{ fontSize: 15, color: t.color.muted, maxWidth: 560, lineHeight: 1.5 }}>Your building permit is ready for review, and your final inspection is on Thursday at 10:00 AM.</div>
        </div>

        <div style={{ padding: '0 28px 24px' }}>
          <Alert tone="action" title="Business license needs a signed W-9" action={<Button variant="primary">Upload W-9</Button>}>
            Upload it here and we'll send it to the Clerk's office. Takes about a minute.
          </Alert>
        </div>

        <div style={{ padding: '0 28px 32px' }}>
          <div style={{ display: 'flex', alignItems: 'baseline', justifyContent: 'space-between', padding: '14px 0', borderBottom: `1px solid ${t.color.hair}` }}>
            <div style={{ fontSize: 13, fontWeight: 500 }}>All requests</div>
            <div style={{ fontSize: 12, color: t.color.muted }}>4 total</div>
          </div>
          {[
            { title: 'Building permit', where: '218 Maple Street', status: ['neutral', 'In review'], when: '2 days ago' },
            { title: 'Final inspection', where: '218 Maple Street', status: ['info', 'Scheduled · Thu 10:00 AM'], when: '5 days ago' },
            { title: 'Business license', where: 'Maple & Orange LLC', status: ['action', 'Action needed'], when: '6 days ago' },
            { title: 'Dog license renewal', where: 'Household · Bowie', status: ['ok', 'Completed'], when: 'Apr 22' },
          ].map((r, i) => (
            <div key={i} style={{ display: 'grid', gridTemplateColumns: '1.4fr 1.4fr 1fr 160px', gap: 16, alignItems: 'center', padding: '16px 0', borderBottom: `1px solid ${t.color.hair}` }}>
              <div style={{ fontSize: 15, fontWeight: 500 }}>{r.title}</div>
              <div style={{ fontSize: 13, color: t.color.muted }}>{r.where}</div>
              <div><Pill tone={r.status[0]}>{r.status[1]}</Pill></div>
              <div style={{ fontSize: 12, color: t.color.muted, textAlign: 'right' }}>{r.when}</div>
            </div>
          ))}
        </div>
      </div>
    </Band>
  );
}

// ─────────────────── ICONS ───────────────────
function IconsSection() {
  const t = window.tokens;
  const [query, setQuery] = useSectionState('');
  const [weight, setWeight] = useSectionState('regular');
  const [copied, setCopied] = useSectionState(null);

  // Curated set of Fluent icons that map to our product surfaces.
  // Grouped by purpose so the library is legible, not just a dump.
  const groups = [
    {
      label: 'Navigation',
      items: [
        'home', 'compass_northwest', 'grid', 'apps_list', 'navigation',
        'chevron_left', 'chevron_right', 'chevron_up', 'chevron_down',
        'arrow_left', 'arrow_right', 'arrow_up', 'arrow_down',
        'search', 'filter', 'sort',
      ],
    },
    {
      label: 'Status + feedback',
      items: [
        'checkmark', 'checkmark_circle', 'dismiss', 'dismiss_circle',
        'warning', 'info', 'error_circle', 'question_circle',
        'clock', 'hourglass', 'shield_checkmark', 'shield',
      ],
    },
    {
      label: 'Actions',
      items: [
        'add', 'subtract', 'edit', 'delete',
        'save', 'copy', 'share', 'print',
        'arrow_download', 'arrow_upload', 'arrow_sync',
        'attach', 'pin', 'bookmark', 'star',
      ],
    },
    {
      label: 'Civic + records',
      items: [
        'building', 'building_government', 'building_home', 'building_bank',
        'document', 'document_text', 'folder', 'receipt',
        'payment', 'wallet_credit_card', 'signature',
        'calendar_ltr', 'calendar_checkmark', 'calendar_clock',
        'location', 'map', 'vehicle_car', 'wrench',
      ],
    },
    {
      label: 'People + comms',
      items: [
        'person', 'people', 'person_circle', 'mail',
        'phone', 'chat', 'chat_multiple', 'megaphone',
        'alert', 'alert_on', 'eye', 'eye_off',
      ],
    },
    {
      label: 'Controls',
      items: [
        'more_horizontal', 'more_vertical', 'settings',
        'lock_closed', 'lock_open', 'key',
        'arrow_exit', 'arrow_enter', 'link', 'open',
      ],
    },
  ];

  const allIcons = groups.flatMap((g) => g.items);
  const q = query.trim().toLowerCase();
  const visibleGroups = q
    ? [{
        label: `Matches for "${query}"`,
        items: allIcons.filter((n) => n.includes(q.replace(/\s+/g, '_'))),
      }]
    : groups;

  const copyName = (name) => {
    const snippet = `<FluentIcon name="${name}" />`;
    try {
      navigator.clipboard?.writeText(snippet);
      setCopied(name);
      setTimeout(() => setCopied((c) => c === name ? null : c), 1400);
    } catch (e) { /* noop */ }
  };

  return (
    <Band label="Icons" code="05">
      {/* ─── INTRO ─── */}
      <div style={{ display: 'grid', gridTemplateColumns: '1fr 360px', gap: 48, marginBottom: 40 }}>
        <div>
          <div style={{ fontSize: 28, fontWeight: 500, letterSpacing: -0.6, lineHeight: 1.2, marginBottom: 14, color: t.color.text }}>
            Fluent, set in our voice.
          </div>
          <div style={{ fontSize: 15, lineHeight: 1.6, color: t.color.body, marginBottom: 14 }}>
            We use Microsoft's <a href="https://github.com/microsoft/fluentui-system-icons" target="_blank" rel="noreferrer" style={{ color: t.color.action, textDecoration: 'none', borderBottom: `1px solid ${t.color.actionEdge}` }}>Fluent UI System Icons</a> — a comprehensive, MIT-licensed library with thousands of glyphs drawn on consistent grids at 12, 16, 20, 24, 28, 32, and 48 px. Every icon comes in two weights: <strong style={{ fontWeight: 500 }}>Regular</strong> (outlined) and <strong style={{ fontWeight: 500 }}>Filled</strong>.
          </div>
          <div style={{ fontSize: 15, lineHeight: 1.6, color: t.color.body }}>
            Icons are loaded live from unpkg, so the full library is available without checking anything into the repo. Use the <span style={{ fontFamily: t.font.mono, fontSize: 13, background: t.color.surfaceHi, padding: '1px 5px', borderRadius: 3 }}>&lt;FluentIcon&gt;</span> component — never paste raw SVG.
          </div>
        </div>
        <div>
          <Alert tone="info" title="License">
            MIT. Free for commercial and civic use. Attribution not required but appreciated. No design changes — we use glyphs as-drawn.
          </Alert>
        </div>
      </div>

      {/* ─── SIZES ─── */}
      <SubLabel>Sizes · Match the type scale</SubLabel>
      <div style={{
        display: 'grid',
        gridTemplateColumns: 'repeat(7, 1fr)',
        gap: 12,
        marginBottom: 32,
      }}>
        {[12, 16, 20, 24, 28, 32, 48].map((s) => (
          <div key={s} style={{
            padding: '20px 16px',
            border: `1px solid ${t.color.hair}`,
            borderRadius: t.radius.lg,
            background: t.color.bg,
            display: 'flex',
            flexDirection: 'column',
            alignItems: 'center',
            gap: 12,
          }}>
            <div style={{ height: 48, display: 'flex', alignItems: 'center' }}>
              <FluentIcon name="building_government" size={s} />
            </div>
            <div style={{ fontFamily: t.font.mono, fontSize: 10, color: t.color.muted, letterSpacing: 0.6 }}>{s}px</div>
          </div>
        ))}
      </div>

      <div style={{ display: 'grid', gridTemplateColumns: 'repeat(3, 1fr)', gap: 20, marginBottom: 40 }}>
        <Tile label="Body · 16px">
          <div style={{ display: 'flex', alignItems: 'center', gap: 10, fontSize: 15, color: t.color.body }}>
            <FluentIcon name="document_text" size={16} />
            <span>Inline with body copy, help text, and table cells.</span>
          </div>
          <div style={{ fontSize: 12, color: t.color.muted, lineHeight: 1.5 }}>
            Paired with 15px body or 13px small. Default weight: regular.
          </div>
        </Tile>
        <Tile label="UI · 20px">
          <div style={{ display: 'flex', alignItems: 'center', gap: 10, fontSize: 15, color: t.color.text }}>
            <FluentIcon name="home" size={20} />
            <span>Nav items, buttons, form controls.</span>
          </div>
          <div style={{ fontSize: 12, color: t.color.muted, lineHeight: 1.5 }}>
            The workhorse size. Use inside buttons, menu rows, pill leading glyphs.
          </div>
        </Tile>
        <Tile label="Prominence · 24px">
          <div style={{ display: 'flex', alignItems: 'center', gap: 10, fontSize: 17, color: t.color.text }}>
            <FluentIcon name="building_government" size={24} />
            <span>Service card eyebrows.</span>
          </div>
          <div style={{ fontSize: 12, color: t.color.muted, lineHeight: 1.5 }}>
            For leading glyphs on cards, section headers, and empty states.
          </div>
        </Tile>
      </div>

      {/* ─── WEIGHTS ─── */}
      <SubLabel>Weights · Regular by default</SubLabel>
      <div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 20, marginBottom: 40 }}>
        <div style={{
          padding: 24,
          border: `1px solid ${t.color.hair}`,
          borderRadius: t.radius.lg,
          background: t.color.bg,
        }}>
          <div style={{ display: 'flex', gap: 20, alignItems: 'center', marginBottom: 20 }}>
            {['home', 'document_text', 'calendar_ltr', 'person', 'checkmark_circle'].map((n) => (
              <FluentIcon key={n} name={n} size={24} weight="regular" />
            ))}
          </div>
          <div style={{ fontSize: 13, fontWeight: 500, color: t.color.text, marginBottom: 4 }}>Regular · the default</div>
          <div style={{ fontSize: 12, color: t.color.muted, lineHeight: 1.55 }}>
            Outlined, 1.5px stroke. Use everywhere by default. Pairs with our hairlines and soft surfaces. Quieter, reads as supporting.
          </div>
        </div>
        <div style={{
          padding: 24,
          border: `1px solid ${t.color.hair}`,
          borderRadius: t.radius.lg,
          background: t.color.bg,
        }}>
          <div style={{ display: 'flex', gap: 20, alignItems: 'center', marginBottom: 20 }}>
            {['home', 'document_text', 'calendar_ltr', 'person', 'checkmark_circle'].map((n) => (
              <FluentIcon key={n} name={n} size={24} weight="filled" />
            ))}
          </div>
          <div style={{ fontSize: 13, fontWeight: 500, color: t.color.text, marginBottom: 4 }}>Filled · earned emphasis</div>
          <div style={{ fontSize: 12, color: t.color.muted, lineHeight: 1.55 }}>
            Solid glyph. Reserved for the <em>active</em> state in navigation, the current step in a stepper, and status indicators where the fill carries meaning.
          </div>
        </div>
      </div>

      {/* ─── COLOR RULES ─── */}
      <SubLabel>Color rules</SubLabel>
      <div style={{ display: 'grid', gridTemplateColumns: 'repeat(4, 1fr)', gap: 16, marginBottom: 40 }}>
        {[
          { color: t.color.text, token: 'color.text', label: 'Default', desc: 'Primary icons paired with primary text.' },
          { color: t.color.muted, token: 'color.muted', label: 'Muted', desc: 'Supporting icons in dense UI and table cells.' },
          { color: t.color.action, token: 'color.action', label: 'Action', desc: 'The single active item. One per screen, same as buttons.' },
          { color: t.color.dim, token: 'color.dim', label: 'Dim', desc: 'Disabled or deliberately de-emphasized.' },
        ].map((r) => (
          <div key={r.token} style={{
            padding: 20,
            border: `1px solid ${t.color.hair}`,
            borderRadius: t.radius.lg,
            background: t.color.bg,
            display: 'flex', flexDirection: 'column', gap: 10,
          }}>
            <FluentIcon name="pin" size={28} color={r.color} />
            <div>
              <div style={{ fontSize: 13, fontWeight: 500, color: t.color.text }}>{r.label}</div>
              <div style={{ fontFamily: t.font.mono, fontSize: 10, color: t.color.muted, marginTop: 2, letterSpacing: 0.4 }}>{r.token}</div>
              <div style={{ fontSize: 12, color: t.color.muted, lineHeight: 1.5, marginTop: 6 }}>{r.desc}</div>
            </div>
          </div>
        ))}
      </div>

      {/* ─── IN CONTEXT ─── */}
      <SubLabel>In context</SubLabel>
      <div style={{ display: 'grid', gridTemplateColumns: 'repeat(3, 1fr)', gap: 20, marginBottom: 40 }}>
        <Tile label="Buttons">
          <Button variant="primary" iconBefore={<FluentIcon name="add" size={16} />}>New request</Button>
          <Button variant="secondary" iconBefore={<FluentIcon name="arrow_download" size={16} />}>Export</Button>
          <Button variant="tertiary" iconAfter={<FluentIcon name="chevron_right" size={16} />}>View all</Button>
        </Tile>
        <Tile label="Pills">
          <div style={{ display: 'flex', flexWrap: 'wrap', gap: 6 }}>
            <Pill tone="ok" variant="light"><FluentIcon name="checkmark_circle" size={14} /> Approved</Pill>
            <Pill tone="warn" variant="light"><FluentIcon name="clock" size={14} /> Pending</Pill>
            <Pill tone="err" variant="light"><FluentIcon name="error_circle" size={14} /> Rejected</Pill>
            <Pill tone="info" variant="light"><FluentIcon name="info" size={14} /> In review</Pill>
          </div>
          <div style={{ fontSize: 12, color: t.color.muted, lineHeight: 1.5 }}>
            14px glyphs inside pills. Same tone as the pill fill — never override to Action Orange.
          </div>
        </Tile>
        <Tile label="Nav item">
          <div style={{ display: 'flex', flexDirection: 'column', gap: 4 }}>
            <NavItem icon="home" label="Overview" />
            <NavItem icon="document_text" label="Requests" active />
            <NavItem icon="calendar_ltr" label="Inspections" />
            <NavItem icon="person" label="Account" />
          </div>
        </Tile>
      </div>

      {/* ─── LIBRARY ─── */}
      <SubLabel>Library · {allIcons.length} curated icons</SubLabel>
      <div style={{
        display: 'flex',
        gap: 12,
        alignItems: 'center',
        marginBottom: 16,
        flexWrap: 'wrap',
      }}>
        <div style={{
          display: 'flex', alignItems: 'center', gap: 8,
          border: `1px solid ${t.color.strong}`, borderRadius: t.radius.sm,
          padding: '8px 12px', background: t.color.bg,
          flex: '1 1 260px', maxWidth: 420,
        }}>
          <FluentIcon name="search" size={16} color={t.color.muted} />
          <input
            type="text"
            value={query}
            onChange={(e) => setQuery(e.target.value)}
            placeholder="Search icons by name…"
            style={{
              border: 'none', outline: 'none', background: 'transparent',
              flex: 1, fontSize: 14, fontFamily: t.font.sans, color: t.color.text,
            }}
          />
          {query && (
            <button onClick={() => setQuery('')} style={{
              border: 'none', background: 'transparent', padding: 0, cursor: 'pointer',
              color: t.color.muted, display: 'inline-flex',
            }}>
              <FluentIcon name="dismiss_circle" size={16} />
            </button>
          )}
        </div>
        <div style={{
          display: 'inline-flex', gap: 0,
          border: `1px solid ${t.color.strong}`, borderRadius: t.radius.sm, overflow: 'hidden',
        }}>
          {['regular', 'filled'].map((w) => (
            <button key={w} onClick={() => setWeight(w)} style={{
              border: 'none', padding: '8px 14px', cursor: 'pointer',
              background: weight === w ? t.color.text : t.color.bg,
              color: weight === w ? '#fff' : t.color.body,
              fontSize: 13, fontFamily: t.font.sans, fontWeight: 500,
              textTransform: 'capitalize',
            }}>{w}</button>
          ))}
        </div>
        <div style={{ fontSize: 12, color: t.color.muted, fontStyle: 'italic' }}>
          Click any icon to copy its <span style={{ fontFamily: t.font.mono }}>&lt;FluentIcon&gt;</span> snippet.
        </div>
      </div>

      <div style={{
        border: `1px solid ${t.color.hair}`,
        borderRadius: t.radius.lg,
        background: t.color.bg,
        overflow: 'hidden',
      }}>
        {visibleGroups.map((g, gi) => (
          <div key={g.label} style={{ borderTop: gi === 0 ? 'none' : `1px solid ${t.color.hair}` }}>
            <div style={{
              padding: '10px 20px',
              background: t.color.paper,
              borderBottom: `1px solid ${t.color.hair}`,
              fontFamily: t.font.mono, fontSize: 10, letterSpacing: 1.4,
              textTransform: 'uppercase', color: t.color.muted, fontWeight: 500,
              display: 'flex', justifyContent: 'space-between',
            }}>
              <span>{g.label}</span>
              <span style={{ color: t.color.dim }}>{g.items.length}</span>
            </div>
            {g.items.length === 0 ? (
              <div style={{ padding: 32, fontSize: 13, color: t.color.muted, textAlign: 'center' }}>
                No matches. Try a different word — the names use underscores, e.g. <span style={{ fontFamily: t.font.mono }}>calendar_ltr</span>.
              </div>
            ) : (
              <div style={{
                display: 'grid',
                gridTemplateColumns: 'repeat(auto-fill, minmax(116px, 1fr))',
                gap: 0,
              }}>
                {g.items.map((name) => {
                  const isCopied = copied === name;
                  return (
                    <button
                      key={name}
                      onClick={() => copyName(name)}
                      title={`Click to copy <FluentIcon name="${name}" />`}
                      style={{
                        display: 'flex',
                        flexDirection: 'column',
                        alignItems: 'center',
                        gap: 10,
                        padding: '20px 8px 14px',
                        border: 'none',
                        borderRight: `1px solid ${t.color.hair}`,
                        borderBottom: `1px solid ${t.color.hair}`,
                        background: isCopied ? t.color.actionSoft : t.color.bg,
                        cursor: 'pointer',
                        fontFamily: t.font.sans,
                        transition: 'background 0.12s',
                      }}
                      onMouseEnter={(e) => { if (!isCopied) e.currentTarget.style.background = t.color.surfaceLo; }}
                      onMouseLeave={(e) => { if (!isCopied) e.currentTarget.style.background = t.color.bg; }}
                    >
                      <FluentIcon name={name} size={24} weight={weight} color={isCopied ? t.color.action : t.color.text} />
                      <div style={{
                        fontFamily: t.font.mono, fontSize: 10,
                        color: isCopied ? t.color.action : t.color.muted,
                        letterSpacing: 0.2,
                        textAlign: 'center',
                        wordBreak: 'break-word',
                        lineHeight: 1.3,
                      }}>
                        {isCopied ? 'copied ✓' : name}
                      </div>
                    </button>
                  );
                })}
              </div>
            )}
          </div>
        ))}
      </div>

      {/* ─── HOW TO ADD MORE ─── */}
      <div style={{ marginTop: 40 }}>
        <SubLabel>Finding + adding more</SubLabel>
        <div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 20 }}>
          <div style={{
            padding: 24,
            border: `1px solid ${t.color.hair}`,
            borderRadius: t.radius.lg,
            background: t.color.bg,
          }}>
            <div style={{ fontSize: 14, fontWeight: 500, color: t.color.text, marginBottom: 10 }}>Browse the full library</div>
            <div style={{ fontSize: 13, color: t.color.body, lineHeight: 1.6, marginBottom: 14 }}>
              The entire set is searchable at <a href="https://react.fluentui.dev/?path=/docs/icons-catalog--docs" target="_blank" rel="noreferrer" style={{ color: t.color.action, textDecoration: 'none', borderBottom: `1px solid ${t.color.actionEdge}` }}>react.fluentui.dev → Icons Catalog</a>. Each entry shows its name in Pascal Case (e.g. <span style={{ fontFamily: t.font.mono, fontSize: 12 }}>CalendarLtr24Regular</span>).
            </div>
            <div style={{ fontSize: 13, color: t.color.body, lineHeight: 1.6 }}>
              To use that in our system, lowercase it and drop the size + weight suffix:
            </div>
            <div style={{
              marginTop: 12,
              padding: '12px 16px',
              background: t.color.surfaceHi,
              border: `1px solid ${t.color.hair}`,
              borderRadius: t.radius.sm,
              fontFamily: t.font.mono, fontSize: 12,
              color: t.color.text,
              lineHeight: 1.7,
            }}>
              <div style={{ color: t.color.muted }}>// from the catalog:</div>
              <div>CalendarLtr24Regular</div>
              <div style={{ color: t.color.muted, marginTop: 6 }}>// in our code:</div>
              <div>&lt;FluentIcon name=<span style={{ color: t.color.action }}>"calendar_ltr"</span> size=<span style={{ color: t.color.action }}>{'{24}'}</span> /&gt;</div>
            </div>
          </div>

          <div style={{
            padding: 24,
            border: `1px solid ${t.color.hair}`,
            borderRadius: t.radius.lg,
            background: t.color.bg,
          }}>
            <div style={{ fontSize: 14, fontWeight: 500, color: t.color.text, marginBottom: 10 }}>Component API</div>
            <div style={{
              padding: '14px 16px',
              background: t.color.surfaceHi,
              border: `1px solid ${t.color.hair}`,
              borderRadius: t.radius.sm,
              fontFamily: t.font.mono, fontSize: 12,
              color: t.color.text,
              lineHeight: 1.7,
              marginBottom: 14,
            }}>
              <div>&lt;FluentIcon</div>
              <div style={{ paddingLeft: 16 }}>name=<span style={{ color: t.color.action }}>"home"</span>       <span style={{ color: t.color.muted }}>// required, snake_case</span></div>
              <div style={{ paddingLeft: 16 }}>size=<span style={{ color: t.color.action }}>{'{20}'}</span>         <span style={{ color: t.color.muted }}>// 12·16·20·24·28·32·48</span></div>
              <div style={{ paddingLeft: 16 }}>weight=<span style={{ color: t.color.action }}>"regular"</span>  <span style={{ color: t.color.muted }}>// or "filled"</span></div>
              <div style={{ paddingLeft: 16 }}>color=<span style={{ color: t.color.action }}>{'{t.color.muted}'}</span>  <span style={{ color: t.color.muted }}>// defaults to currentColor</span></div>
              <div style={{ paddingLeft: 16 }}>title=<span style={{ color: t.color.action }}>"Home"</span>        <span style={{ color: t.color.muted }}>// for screen readers</span></div>
              <div>/&gt;</div>
            </div>
            <div style={{ fontSize: 12, color: t.color.muted, lineHeight: 1.55 }}>
              Icons inherit <span style={{ fontFamily: t.font.mono }}>currentColor</span>, so setting the parent's <span style={{ fontFamily: t.font.mono }}>color</span> tints the glyph. If a name 404s from the CDN, the component renders a dashed placeholder so layout holds.
            </div>
          </div>
        </div>
      </div>

      {/* ─── RULES ─── */}
      <div style={{ marginTop: 40 }}>
        <SubLabel>Rules</SubLabel>
        <div style={{ display: 'flex', flexDirection: 'column', gap: 12 }}>
          {[
            { t: 'Never paste raw SVG', d: 'Always use <FluentIcon>. Raw SVG drifts from our color and sizing tokens and bloats pages.' },
            { t: 'Match icon size to type size', d: '16 next to 13–15px text, 20 inside buttons and nav, 24 for card eyebrows. Never eyeball it.' },
            { t: 'Regular by default, Filled only for active states', d: 'The current nav item, the active step, the checked indicator. Never both weights of the same icon on one screen.' },
            { t: 'Don\u2019t mix icon families', d: 'No Material, no Feather, no emoji. Fluent only, so line weight and corner radius stay consistent.' },
            { t: 'Icon-only buttons need a label', d: 'Always pass title or aria-label on icon-only actions. Screen readers and tooltips both depend on it.' },
          ].map((r, i) => (
            <div key={i} style={{
              display: 'grid',
              gridTemplateColumns: '40px 1fr',
              gap: 20,
              padding: '18px 24px',
              border: `1px solid ${t.color.hair}`,
              borderRadius: t.radius.lg,
              background: t.color.bg,
            }}>
              <div style={{ fontFamily: t.font.mono, fontSize: 11, color: t.color.muted, letterSpacing: 0.8 }}>
                {String(i + 1).padStart(2, '0')}
              </div>
              <div>
                <div style={{ fontSize: 14, fontWeight: 500, color: t.color.text, marginBottom: 4 }}>{r.t}</div>
                <div style={{ fontSize: 13, color: t.color.body, lineHeight: 1.55 }}>{r.d}</div>
              </div>
            </div>
          ))}
        </div>
      </div>
    </Band>
  );
}

// ─────────────────── COMPONENTS · NAV ITEM ───────────────────
function ComponentsNavItemSection() {
  const t = window.tokens;
  const [active, setActive] = useSectionState('requests');

  const variants = [
    {
      key: 'default',
      name: 'Default',
      use: 'Resting row. Leading Fluent icon in Regular weight, label in body color, transparent background.',
      rule: 'Reserve active state for the one item the user is currently on. Never two active items in one menu.',
      sample: (
        <div style={{ width: 260 }}>
          <NavItem icon="document_text" label="Requests" />
        </div>
      ),
    },
    {
      key: 'active',
      name: 'Active',
      use: 'The current destination. Filled icon, Action Orange tint, soft orange background, medium weight label.',
      rule: 'Exactly one per menu surface. The filled icon + orange tint is the signal — do not recreate with borders or underlines.',
      sample: (
        <div style={{ width: 260 }}>
          <NavItem icon="document_text" label="Requests" active />
        </div>
      ),
    },
    {
      key: 'badge',
      name: 'With badge',
      use: 'Use when a count communicates something actionable: unread messages, items needing review, pending approvals.',
      rule: 'Only integers. No "99+" styling — if the count exceeds 99 the problem is the inbox, not the label. Never use badges for decoration.',
      sample: (
        <div style={{ width: 260, display: 'flex', flexDirection: 'column', gap: 4 }}>
          <NavItem icon="mail" label="Messages" badge={3} />
          <NavItem icon="alert" label="Action needed" badge={1} active />
        </div>
      ),
    },
    {
      key: 'small',
      name: 'Small · size="sm"',
      use: 'Dense menus: account popover, secondary filter column, settings sub-pages.',
      rule: 'Never mix sizes in the same group. A section is all default or all small.',
      sample: (
        <div style={{ width: 220, display: 'flex', flexDirection: 'column', gap: 2 }}>
          <NavItem icon="person" label="Profile" size="sm" />
          <NavItem icon="lock_closed" label="Security" size="sm" active />
          <NavItem icon="arrow_exit" label="Sign out" size="sm" />
        </div>
      ),
    },
  ];

  return (
    <Band label="Components · Nav Item" code="13">
      <div style={{ display: 'flex', flexDirection: 'column', gap: 12, marginBottom: 28 }}>
        {variants.map((v) => (
          <div key={v.key} style={{
            display: 'grid',
            gridTemplateColumns: '300px 1fr',
            gap: 32,
            alignItems: 'center',
            padding: '24px',
            border: `1px solid ${t.color.hair}`,
            borderRadius: t.radius.lg,
            background: t.color.bg,
          }}>
            <div style={{ display: 'flex', alignItems: 'center' }}>{v.sample}</div>
            <div>
              <div style={{ display: 'flex', alignItems: 'baseline', gap: 12, marginBottom: 4 }}>
                <div style={{ fontSize: 15, fontWeight: 500, letterSpacing: -0.2 }}>{v.name}</div>
                <div style={{ fontFamily: t.font.mono, fontSize: 10, color: t.color.dim, letterSpacing: 0.8, textTransform: 'uppercase' }}>&lt;NavItem&gt;</div>
              </div>
              <div style={{ fontSize: 13, color: t.color.body, lineHeight: 1.55, marginBottom: 4 }}>{v.use}</div>
              <div style={{ fontSize: 12, color: t.color.muted, lineHeight: 1.5, fontStyle: 'italic' }}>{v.rule}</div>
            </div>
          </div>
        ))}
      </div>

      <div style={{ display: 'grid', gridTemplateColumns: 'repeat(2, 1fr)', gap: 20, marginBottom: 28 }}>
        <Tile label="Grouped menu · NavGroup">
          <div style={{ width: '100%', padding: '8px 0' }}>
            <NavGroup label="Services">
              <NavItem icon="home" label="Overview" onClick={() => setActive('overview')} active={active === 'overview'} />
              <NavItem icon="document_text" label="Requests" onClick={() => setActive('requests')} active={active === 'requests'} badge={3} />
              <NavItem icon="calendar_ltr" label="Inspections" onClick={() => setActive('inspections')} active={active === 'inspections'} />
              <NavItem icon="payment" label="Payments" onClick={() => setActive('payments')} active={active === 'payments'} />
            </NavGroup>
            <div style={{ height: 12 }} />
            <NavGroup label="Account">
              <NavItem icon="person" label="Profile" onClick={() => setActive('profile')} active={active === 'profile'} />
              <NavItem icon="settings" label="Settings" onClick={() => setActive('settings')} active={active === 'settings'} />
            </NavGroup>
          </div>
          <div style={{ fontSize: 12, color: t.color.muted, lineHeight: 1.5 }}>
            <span style={{ fontFamily: t.font.mono }}>&lt;NavGroup&gt;</span> adds a mono eyebrow label and spacing. Click any row above to move the active state.
          </div>
        </Tile>
        <Tile label="Interactive states">
          <div style={{ width: '100%', display: 'grid', gridTemplateColumns: 'auto 1fr', gap: '10px 16px', alignItems: 'center' }}>
            <div style={{ fontSize: 11, color: t.color.muted, fontFamily: t.font.mono, letterSpacing: 0.8, textTransform: 'uppercase' }}>Default</div>
            <div><NavItem icon="home" label="Overview" /></div>
            <div style={{ fontSize: 11, color: t.color.muted, fontFamily: t.font.mono, letterSpacing: 0.8, textTransform: 'uppercase' }}>Hover</div>
            <div><div style={{
              display: 'flex', alignItems: 'center', gap: 10, padding: '8px 12px',
              borderRadius: t.radius.sm, background: t.color.surfaceLo,
              color: t.color.body, fontSize: 14,
            }}><FluentIcon name="home" size={20} /><span>Overview</span></div></div>
            <div style={{ fontSize: 11, color: t.color.muted, fontFamily: t.font.mono, letterSpacing: 0.8, textTransform: 'uppercase' }}>Active</div>
            <div><NavItem icon="home" label="Overview" active /></div>
          </div>
          <div style={{ fontSize: 12, color: t.color.muted, lineHeight: 1.5, marginTop: 12 }}>
            Hover tints the row with <span style={{ fontFamily: t.font.mono }}>surfaceLo</span>. Active fills with <span style={{ fontFamily: t.font.mono }}>actionSoft</span> and flips the icon to filled.
          </div>
        </Tile>
      </div>

      <Alert tone="info" title="Where you'll see this">
        Sidebar navigation (like the one on your left), mobile drawers, account popovers, filter rails, stepper side panels. Anywhere you have a vertical list of destinations with leading glyphs.
      </Alert>
    </Band>
  );
}

// ─────────────────── FOOTER ───────────────────
function PageFooter() {
  const t = window.tokens;
  return (
    <div style={{ padding: '32px 56px 64px', borderTop: `1px solid ${t.color.hair}`, display: 'flex', justifyContent: 'space-between', fontSize: 12, color: t.color.muted, fontFamily: t.font.mono, letterSpacing: 1 }}>
      <span>GOVPILOT · CIVIC MODERN · v0.1</span>
      <span>LAST UPDATED · APR 2026</span>
    </div>
  );
}

Object.assign(window, {
  CoverSection,
  PrinciplesSection,
  TypographySection,
  ColorSection,
  SpacingSection,
  IconsSection,  ComponentsButtonsSection,
  ComponentsPillsSection,
  ComponentsFormsSection,
  ComponentsContainersSection,
  ComponentsAlertsSection,
  ComponentsComposerSection,
  ComponentsBreadcrumbsSection,
  ComponentsNavItemSection,
  ComponentsTabsSection,
  ComponentsAvatarSection,
  ComponentsProgressSection,
  ComponentsStepperSection,
  ComponentsDataSection,
  ResidentDashboardSection,
  PageFooter,
});
