// Civic Modern — shared primitives: logo, section scaffolding, generic helpers.

function GPMark({ size = 40, hollow = 'currentColor', solid = 'currentColor', style }) {
  return (
    <svg width={size} height={size * 174.2 / 204} viewBox="0 0 204 174.2" style={style} aria-label="GovPilot mark">
      <path fill={hollow} d="M84.9,174.2h-36.3L0,87.2,49.3,0h35.9l48.7,86.9v.5l-49.1,86.9ZM67,143.6l31.8-56.6-31.2-55.8-.5-.4-31.8,56.2,31.7,56.6Z" />
      <path fill={solid} d="M155.3,0h-35.2l48.6,87.2-49.2,87h35.2l49.4-87.1L155.3,0Z" />
    </svg>
  );
}

function GPWordmark({ height = 28, hollow = 'currentColor', solid = 'currentColor', style }) {
  return (
    <svg height={height} viewBox="0 0 886 174.2" style={style} aria-label="GovPilot">
      <path fill={solid} d="M863,147.7c-10.2,0-18.4-2.6-24.6-7.9-6.1-5.3-9.1-13-9.1-23.3v-30.7h-19.8v-21.6h19.8v-25.1h24.9v25.1h24.8v21.6h-24.8v25.6c0,4.8,1,8.4,3,10.6,2,2.1,5.1,3.1,9.4,3.1s7.9-.9,11.2-2.6l7.4,20.3c-2.1,1.2-5.3,2.4-9.7,3.5-4.4,1-8.6,1.5-12.5,1.5Z" />
      <path fill={solid} d="M794.9,136.1c-8.5,8.2-18.7,12.4-30.7,12.4s-22.2-4.1-30.7-12.4c-8.5-8.4-12.7-18.6-12.7-30.7s4.2-22.3,12.7-30.5c8.5-8.4,18.7-12.5,30.7-12.5s22.2,4.2,30.7,12.5c8.5,8.2,12.7,18.4,12.7,30.5s-4.2,22.3-12.7,30.7ZM751,119.8c3.5,3.6,7.9,5.4,13.2,5.4s9.6-1.8,13-5.4c3.5-3.6,5.3-8.4,5.3-14.4s-1.8-10.7-5.3-14.4c-3.4-3.6-7.8-5.4-13-5.4s-9.7,1.8-13.2,5.4c-3.4,3.6-5.1,8.4-5.1,14.4s1.7,10.7,5.1,14.4Z" />
      <path fill={solid} d="M683.7,146.7V26.2h24.9v120.4h-24.9Z" />
      <path fill={solid} d="M654,56.3c-4.2,0-7.8-1.5-10.9-4.5-3.1-3.1-4.6-6.8-4.6-11.1s1.5-7.9,4.6-10.9c3.1-3.1,6.7-4.6,10.9-4.6s8.1,1.5,11.1,4.6c3.1,3,4.6,6.6,4.6,10.9s-1.5,8-4.6,11.1c-3,3-6.7,4.5-11.1,4.5ZM641.6,146.7v-82.5h24.9v82.5h-24.9Z" />
      <path fill={solid} d="M619.7,41.1c7.9,7.7,11.9,17.2,11.9,28.5s-4,20.8-11.9,28.5c-7.8,7.6-17.6,11.4-29.4,11.4h-13.5v37.1h-26.2V29.5h39.8c11.8,0,21.6,3.9,29.4,11.6ZM606.1,69.6c0-4.4-1.5-8-4.6-10.9-3-3-6.8-4.5-11.5-4.5h-13.2v30.7h13.2c4.6,0,8.5-1.5,11.5-4.5s4.6-6.6,4.6-10.9Z" />
      <path fill={solid} d="M482.4,146.7l-36.1-82.5h27.6l20,50.2,20.1-50.2h27.7l-36.1,82.5h-23.1Z" />
      <path fill={solid} d="M434.8,136.1c-8.5,8.2-18.7,12.4-30.7,12.4s-22.2-4.1-30.7-12.4c-8.5-8.4-12.7-18.6-12.7-30.7s4.2-22.3,12.7-30.5c8.5-8.4,18.7-12.5,30.7-12.5s22.2,4.2,30.7,12.5c8.5,8.2,12.7,18.4,12.7,30.5s-4.2,22.3-12.7,30.7ZM390.9,119.8c3.5,3.6,7.9,5.4,13.2,5.4s9.6-1.8,13-5.4c3.5-3.6,5.3-8.4,5.3-14.4s-1.8-10.7-5.3-14.4c-3.4-3.6-7.8-5.4-13-5.4s-9.7,1.8-13.2,5.4c-3.4,3.6-5.1,8.4-5.1,14.4s1.7,10.7,5.1,14.4Z" />
      <path fill={solid} d="M302.7,148.7c-18.1,0-33.3-5.8-45.5-17.3-12.1-11.7-18.1-26.1-18.1-43.2s5.8-31.2,17.3-42.9c11.7-11.8,26.5-17.7,44.4-17.7s36.1,6.7,48,20l-18.5,18c-7.8-8.4-17.7-12.5-29.5-12.5s-18.8,3.5-25.4,10.4c-6.6,6.8-9.9,15.1-9.9,24.8s3.4,18.5,10.1,25.2c6.7,6.6,15.7,9.9,26.9,9.9s17.9-1.9,22.8-5.6v-17.3h-22.9v-24.6h48.5v55.6c-5.1,5.7-11.8,10.1-20.3,13-8.5,2.9-17.7,4.3-27.7,4.3Z" />
      <path fill={hollow} d="M84.9,174.2h-36.3L0,87.2,49.3,0h35.9l48.7,86.9v.5l-49.1,86.9h.1ZM67,143.6l31.8-56.6-31.2-55.8-.5-.4-31.8,56.2,31.7,56.6Z" />
      <path fill={solid} d="M155.3,0h-35.2l48.6,87.2-49.2,87h35.2l49.4-87.1L155.3,0Z" />
    </svg>
  );
}

// A labelled band — "TYPOGRAPHY", "PALETTE", etc. Uses the orange accent bar.
function Band({ label, code, children, pad = '48px 56px', border = true }) {
  const t = window.tokens;
  return (
    <div style={{ padding: pad, borderTop: border ? `1px solid ${t.color.hair}` : 'none' }}>
      {label && (
        <div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', marginBottom: 28 }}>
          <div style={{ display: 'flex', alignItems: 'center', gap: 12 }}>
            <div style={{ width: 20, height: 2, background: t.color.action }} />
            <div style={{ fontFamily: t.font.mono, fontWeight: 500, fontSize: 11, letterSpacing: 2, textTransform: 'uppercase', color: t.color.muted }}>{label}</div>
          </div>
          {code && <div style={{ fontFamily: t.font.mono, fontSize: 10, color: t.color.dim, letterSpacing: 1.4, textTransform: 'uppercase' }}>{code}</div>}
        </div>
      )}
      {children}
    </div>
  );
}

// Small mono caption used as a sub-label.
function Caption({ children, color, style }) {
  const t = window.tokens;
  return (
    <div style={{ fontFamily: t.font.mono, fontSize: 10, letterSpacing: 1.4, textTransform: 'uppercase', color: color || t.color.muted, ...style }}>
      {children}
    </div>
  );
}

// Subtitle caption — plain sans, small, muted.
function SubLabel({ children, style }) {
  const t = window.tokens;
  return (
    <div style={{ fontSize: 12, fontWeight: 500, letterSpacing: 1.2, color: t.color.muted, textTransform: 'uppercase', marginBottom: 14, ...style }}>{children}</div>
  );
}

// Component showcase tile — each component sits in one of these so spacing is uniform.
function Tile({ label, children, style, pad = 24, minHeight = 160 }) {
  const t = window.tokens;
  return (
    <div style={{ background: t.color.bg, border: `1px solid ${t.color.hair}`, borderRadius: t.radius.lg, overflow: 'hidden', display: 'flex', flexDirection: 'column', ...style }}>
      {label && (
        <div style={{ padding: '12px 16px', borderBottom: `1px solid ${t.color.hair}`, background: t.color.paper, display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}>
          <div style={{ fontSize: 11, fontWeight: 500, letterSpacing: 1.2, textTransform: 'uppercase', color: t.color.muted, fontFamily: t.font.mono }}>{label}</div>
        </div>
      )}
      <div style={{ padding: pad, minHeight, display: 'flex', flexDirection: 'column', justifyContent: 'center', gap: 12 }}>
        {children}
      </div>
    </div>
  );
}

// Icon placeholder — real SVGs to be supplied later.
// Renders a mono-glyph in a subtle box so you can tell where an icon belongs.
function IconSlot({ label = 'icon', size = 16, color }) {
  const t = window.tokens;
  return (
    <span
      aria-label={`icon placeholder: ${label}`}
      style={{
        display: 'inline-flex',
        alignItems: 'center',
        justifyContent: 'center',
        width: size,
        height: size,
        border: `1px dashed ${color || t.color.strong}`,
        color: color || t.color.dim,
        borderRadius: 2,
        fontFamily: t.font.mono,
        fontSize: Math.max(7, size * 0.42),
        letterSpacing: 0,
        lineHeight: 1,
        flexShrink: 0,
      }}
    >
      {/* deliberately blank — the dashed box is the placeholder */}
    </span>
  );
}

Object.assign(window, { GPMark, GPWordmark, Band, Caption, SubLabel, Tile, IconSlot });
