// Underwriter / Login — same composition as Investor/Login, repointed at
// the operator audience. Built fresh on the design system.
//
// Composition:
//   <NetworkMap>                  ambient US-city → vault → cities (calmer)
//   <Header surface="bare"
//           label="Underwriter">  floating wordmark + theme toggle
//   <Vignette>                    soft radial readability mask, wrapping…
//     <Hero>                      eyebrow + display headline + lede + 3 operator stats
//   <AuthPanel>                   glass panel: email + password + sign in
//   <Ticker>                      bottom marquee of recent underwriting decisions
//
// Page-level inline styles cover only: outer positioning and slot widths.
// Every visual atom (typography, chrome, padding, hairlines, icons,
// vignette gradient) lives in the design system or a primitive's variant.

// ─────────────────────────── Auth panel ───────────────────────────
// Operator sign-in is a plain firm credentials form — username + password.
// No wallets, no third-party providers; firms manage their own access.

function AuthPanel() {
  return (
    <div style={{
      position: "absolute",
      right: 80,
      top: "50%",
      transform: "translateY(-50%)",
      width: 420,
      zIndex: 3,
    }}>
      <Panel surface="glass" density="lg">
        <PanelHead
          title="Sign in"
          subtitle="Sign in with your credentials."
        />
        <PanelBody stack>
          <Field>
            <MailGlyph />
            <input type="email" placeholder="name@firm.com" />
          </Field>

          <Field>
            <LockGlyph />
            <input type="password" placeholder="Password" />
          </Field>

          <Button block>Sign in</Button>
        </PanelBody>
      </Panel>
    </div>
  );
}

// ─────────────────────────── Hero ───────────────────────────

function Hero() {
  return (
    <div style={{
      position: "absolute",
      left: 64,
      top: "50%",
      transform: "translateY(-54%)",
      maxWidth: 760,
      zIndex: 2,
    }}>
      <div style={{ marginBottom: 28 }}>
        <Eyebrow tone="brand" rule>Operator Access</Eyebrow>
      </div>

      <Display as="h1" size="xl">
        Credit decisions,<br />
        on the same rail.
      </Display>

      <Body lede style={{ margin: "26px 0 0", maxWidth: 520 }}>
        Score, condition, and approve loans alongside the originators and
        capital that fund them. Every decision verifiable, every condition
        enforced on-chain.
      </Body>

      <div style={{ marginTop: 40 }}>
        <KpiStripQuiet items={[
          { value: "11s",   label: "Median decision time" },
          { value: "$47M",  label: "Decisioned · 7d" },
          { value: "98.4%", label: "Conditions met · 30d" },
        ]} />
      </div>
    </div>
  );
}

// ─────────────────────────── Page assembly ───────────────────────────

function Login() {
  const [theme, setTheme] = useTheme();
  return (
    <div data-theme={theme} style={{
      width: "100vw", height: "100vh",
      position: "relative",
      overflow: "hidden",
      background: "var(--surface)",
      color: "var(--text)",
      fontFamily: "var(--font-sans)",
    }}>
      {/* US network map — calmer than the investor surface (operators
          don't need the same marketing energy). */}
      <NetworkMap opacity={0.45} theme={theme} />

      {/* Content frame — caps the composition at 1600 on ultrawide */}
      <div style={{ position: "absolute", inset: 0, maxWidth: 1600, margin: "0 auto" }}>
        {/* Floating header — page owns position, system owns chrome. */}
        <div style={{ position: "absolute", top: 0, left: 0, right: 0, zIndex: 4 }}>
          <Header
            surface="bare"
            label="Underwriter"
            theme={theme}
            onThemeChange={setTheme}
          />
        </div>

        <Vignette>
          <Hero />
        </Vignette>
        <AuthPanel />
      </div>
    </div>
  );
}

window.Login = Login;
