<template>
  <main class="login-page">
    <header class="page-brand">
      <LogoMark />
      <strong>星海科技</strong>
    </header>

    <section class="hero">
      <p class="eyebrow-text">Smart Expense Operations</p>
      <h1>企业报销智能运营台</h1>
      <p class="hero-lead">让报销审批更智能、更高效</p>
      <p class="hero-sub">智能审单 · 自动化审批 · 风险预警 · SLA 监控 · 数据驱动决策</p>

      <div class="hero-stage" aria-hidden="true">
        <span class="flow-line flow-a"></span>
        <span class="flow-line flow-b"></span>
        <span class="flow-line flow-c"></span>

        <div class="metric-card amount">
          <span>报销金额趋势</span>
          <strong>￥361,600</strong>
          <small>较昨日 <b class="up">↑ 8.3%</b></small>
          <div class="mini-bars"><i></i><i></i><i></i><i></i></div>
        </div>

        <div class="document-card">
          <span>报销单</span>
          <i></i><i></i><i></i>
          <b class="doc-check"><i class="pi pi-check"></i></b>
        </div>

        <img class="shield-art" src="../assets/security-shield.png" alt="" />

        <div class="round-badge ai">AI</div>

        <div class="metric-card risk">
          <span>风险预警</span>
          <strong><i class="pi pi-exclamation-triangle"></i> 14 单</strong>
          <small>较昨日 <b class="danger">↑ 16.7%</b></small>
        </div>

        <div class="metric-card audit">
          <span>审批效率</span>
          <strong>78%</strong>
          <small>较昨日 <b class="up">↑ 6.2%</b></small>
        </div>

        <div class="metric-card sla">
          <span>SLA 达成率</span>
          <strong>96%</strong>
          <small>较昨日 <b class="up">↑ 3.1%</b></small>
        </div>
      </div>

      <div class="feature-strip" aria-label="核心能力">
        <article v-for="item in features" :key="item.title">
          <span :class="item.tone"><i :class="item.icon"></i></span>
          <div>
            <strong>{{ item.title }}</strong>
            <p>{{ item.desc }}</p>
          </div>
        </article>
      </div>
    </section>

    <section class="login-card" aria-label="登录表单">
      <div class="card-brand">
        <LogoMark />
        <strong>星海科技</strong>
      </div>
      <header class="card-head">
        <h2>欢迎登录</h2>
        <p>登录企业报销智能运营台</p>
      </header>

      <form class="login-form" @submit.prevent="emit('login', { username, password })">
        <label class="field">
          <span class="sr-only">账号</span>
          <i class="pi pi-user"></i>
          <input v-model="username" type="text" placeholder="请输入账号 / 邮箱 / 手机号" autocomplete="username" required />
        </label>

        <label class="field">
          <span class="sr-only">密码</span>
          <i class="pi pi-lock"></i>
          <input
            v-model="password"
            :type="showPassword ? 'text' : 'password'"
            placeholder="请输入密码"
            autocomplete="current-password"
            required
          />
          <button
            class="field-icon-btn"
            type="button"
            :aria-label="showPassword ? '隐藏密码' : '显示密码'"
            @click="showPassword = !showPassword"
          >
            <i :class="showPassword ? 'pi pi-eye' : 'pi pi-eye-slash'"></i>
          </button>
        </label>

        <label class="field">
          <span class="sr-only">企业或租户</span>
          <i class="pi pi-building"></i>
          <input v-model="tenant" type="text" placeholder="请输入企业 / 租户（选填）" />
          <button class="field-icon-btn" type="button" aria-label="展开企业列表">
            <i class="pi pi-angle-down"></i>
          </button>
        </label>

        <div class="form-meta">
          <label class="remember">
            <input v-model="remember" type="checkbox" />
            <span>记住我</span>
          </label>
          <button type="button" class="link-btn" @click="emit('recover-password')">忘记密码?</button>
        </div>

        <button class="submit-btn" type="submit">登录</button>

        <div class="divider"><span>或</span></div>

        <button class="sso-btn" type="button" @click="emit('sso-login')">
          <i class="pi pi-shield"></i>
          <span>SSO 单点登录</span>
        </button>
      </form>

      <footer class="security-note">
        <i class="pi pi-lock"></i>
        <span>安全登录 · 数据加密传输 · 如需帮助请联系管理员</span>
      </footer>
    </section>
  </main>
</template>

<script setup>
import { ref } from 'vue'

const emit = defineEmits(['login', 'recover-password', 'sso-login'])

const username = ref('')
const password = ref('')
const tenant = ref('')
const remember = ref(true)
const showPassword = ref(false)

const features = [
  { title: '智能审单', desc: 'AI 自动识别票据与规则，提升准确率与效率', icon: 'pi pi-file', tone: 'green' },
  { title: '异常预警', desc: '多维风险识别与预警，主动防控风险', icon: 'pi pi-bell', tone: 'red' },
  { title: 'SLA 监控', desc: '实时监控服务水平协议，保障审批及时性', icon: 'pi pi-sync', tone: 'blue' }
]

const LogoMark = {
  template: `
    <span class="logo-mark" aria-hidden="true">
      <svg viewBox="0 0 36 36">
        <path d="M19.8 4.5c5.7 1.1 9.9 5.7 10.5 11.6-2.8-.9-5.5-.7-7.9.6-2.8 1.5-4.5 4.3-5.2 8.2-4.4-2.8-6.5-6.5-6.3-11.1.2-4.2 3.5-7.8 8.9-9.3Z" />
        <path d="M9 7.6c-3 3.5-4 7.3-2.9 11.2 1.2 4.2 4.6 7 10.1 8.5-2 1.8-4.6 2.6-7.6 2.3C5.1 26.7 3.5 23.1 3.7 19 4 14.4 5.7 10.6 9 7.6Z" />
      </svg>
    </span>
  `
}
</script>

<style scoped>
.login-page {
  position: relative;
  min-height: 100dvh;
  display: grid;
  grid-template-columns: minmax(620px, .96fr) minmax(520px, .84fr);
  justify-content: center;
  align-items: center;
  gap: clamp(32px, 4.8vw, 76px);
  padding: 48px clamp(40px, 5vw, 86px);
  overflow: hidden;
  background:
    linear-gradient(120deg, rgba(236,253,245,.72), transparent 34%),
    linear-gradient(105deg, #f8fafc 0%, #f4fbf8 44%, #f8fafc 100%);
}

.login-page::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 0;
  background:
    linear-gradient(90deg, rgba(15,23,42,.045) 1px, transparent 1px),
    linear-gradient(0deg, rgba(15,23,42,.04) 1px, transparent 1px),
    radial-gradient(circle at 28% 72%, rgba(16,185,129,.12), transparent 28%),
    radial-gradient(circle at 75% 22%, rgba(245,158,11,.08), transparent 30%);
  background-size: 72px 72px, 72px 72px, auto, auto;
  mask-image: linear-gradient(100deg, rgba(0,0,0,.7), rgba(0,0,0,.32) 48%, rgba(0,0,0,.16));
  pointer-events: none;
}

.login-page::after {
  content: "";
  position: absolute;
  left: -9vw;
  top: 13vh;
  z-index: 0;
  width: min(820px, 58vw);
  height: min(560px, 64vh);
  border: 1px solid rgba(148,163,184,.22);
  border-radius: 18px;
  background:
    linear-gradient(90deg, transparent 0 28%, rgba(15,23,42,.055) 28% calc(28% + 1px), transparent calc(28% + 1px)),
    repeating-linear-gradient(0deg, transparent 0 35px, rgba(15,23,42,.05) 36px),
    linear-gradient(135deg, rgba(255,255,255,.74), rgba(236,253,245,.32));
  box-shadow: 0 34px 80px rgba(15,23,42,.08);
  transform: rotate(-7deg);
  pointer-events: none;
}

.page-brand {
  position: absolute;
  top: 38px;
  left: clamp(42px, 6vw, 86px);
  z-index: 2;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: #111827;
  font-size: 22px;
  font-weight: 900;
}

:deep(.logo-mark) {
  width: 34px;
  height: 34px;
  display: inline-grid;
  place-items: center;
  color: #059669;
}

:deep(.logo-mark svg) {
  width: 34px;
  height: 34px;
  fill: currentColor;
}

.hero {
  position: relative;
  z-index: 1;
  align-self: stretch;
  display: grid;
  align-content: center;
  justify-items: start;
  padding-top: 40px;
  transform: translateX(34px);
}

.eyebrow-text {
  color: #059669;
  font-size: 14px;
  font-weight: 900;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.hero h1 {
  margin-top: 16px;
  color: #0f172a;
  font-size: clamp(38px, 3.8vw, 54px);
  line-height: 1.12;
  font-weight: 950;
}

.hero-lead {
  margin-top: 14px;
  color: #111827;
  font-size: clamp(23px, 2.15vw, 31px);
  font-weight: 800;
}

.hero-sub {
  margin-top: 14px;
  color: #64748b;
  font-size: 16px;
  font-weight: 600;
}

.hero-stage {
  position: relative;
  width: min(760px, 100%);
  height: 350px;
  margin-top: 22px;
  margin-left: 0;
}

.hero-stage::before {
  content: "";
  position: absolute;
  left: 285px;
  bottom: 38px;
  width: 230px;
  height: 62px;
  border-radius: 50%;
  background: linear-gradient(90deg, rgba(16,185,129,.16), rgba(245,158,11,.12));
  filter: blur(4px);
}

.flow-line {
  position: absolute;
  z-index: 0;
  display: block;
  border: 1px solid rgba(16,185,129,.18);
  border-left: 0;
  border-bottom: 0;
  border-radius: 0 22px 0 0;
}

.flow-line::after {
  content: "";
  position: absolute;
  right: -3px;
  top: -4px;
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: #10b981;
  box-shadow: 0 0 0 5px rgba(16,185,129,.12);
}

.flow-a {
  left: 190px;
  top: 76px;
  width: 170px;
  height: 72px;
}

.flow-b {
  left: 190px;
  bottom: 96px;
  width: 142px;
  height: 82px;
  transform: scaleY(-1);
}

.flow-c {
  right: 182px;
  top: 96px;
  width: 132px;
  height: 70px;
  transform: scaleX(-1);
}

.metric-card,
.document-card,
.round-badge {
  position: absolute;
  border: 1px solid rgba(215, 224, 234, .86);
  background: rgba(255,255,255,.78);
  box-shadow: 0 18px 36px rgba(65, 88, 110, .10);
  backdrop-filter: blur(16px);
}

.metric-card {
  z-index: 2;
  width: 166px;
  min-height: 110px;
  display: grid;
  gap: 7px;
  padding: 17px 18px;
  border-radius: 14px;
}

.metric-card span {
  color: #334155;
  font-size: 13px;
  font-weight: 800;
}

.metric-card strong {
  color: #0f172a;
  font-size: 25px;
  line-height: 1;
  font-weight: 900;
}

.metric-card small {
  color: #64748b;
  font-size: 12px;
  font-weight: 700;
}

.up { color: #059669; }
.danger { color: #ef4444; }

.amount { left: 20px; top: 20px; }
.risk { left: 42px; bottom: 24px; }
.audit { right: 22px; top: 24px; }
.sla { right: 40px; bottom: 20px; }

.mini-bars {
  height: 30px;
  display: flex;
  align-items: end;
  gap: 6px;
  margin-top: 2px;
}

.mini-bars i {
  width: 14px;
  border-radius: 4px 4px 0 0;
  background: linear-gradient(180deg, #93c5fd, #dbeafe);
}
.mini-bars i:nth-child(1) { height: 11px; }
.mini-bars i:nth-child(2) { height: 18px; }
.mini-bars i:nth-child(3) { height: 24px; }
.mini-bars i:nth-child(4) { height: 32px; }

.document-card {
  z-index: 1;
  left: 286px;
  top: 44px;
  width: 220px;
  height: 214px;
  padding: 28px 28px;
  border-radius: 16px;
  transform: rotate(2deg);
}

.document-card span {
  color: #1e293b;
  font-size: 18px;
  font-weight: 900;
}

.document-card > i {
  display: block;
  height: 10px;
  margin-top: 22px;
  border-radius: 999px;
  background: #e4ebf5;
}
.document-card > i:nth-of-type(2) { width: 78%; margin-top: 16px; }
.document-card > i:nth-of-type(3) { width: 54%; margin-top: 16px; }

.doc-check {
  position: absolute;
  right: -16px;
  bottom: -12px;
  width: 54px;
  height: 54px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: linear-gradient(135deg, #6ee7b7, #059669);
  color: #fff;
  font-size: 27px;
  box-shadow: 0 14px 28px rgba(5,150,105,.25);
}

.shield-art {
  position: absolute;
  z-index: 3;
  left: 316px;
  bottom: 0;
  width: 155px;
  height: 155px;
  object-fit: contain;
  filter: drop-shadow(0 22px 24px rgba(125, 91, 54, .16));
}

.round-badge {
  z-index: 4;
  width: 58px;
  height: 58px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  color: #3b82f6;
  font-size: 24px;
  font-weight: 950;
}

.round-badge.ai {
  left: 258px;
  top: 30px;
  width: 52px;
  height: 52px;
  color: #3b82f6;
  font-size: 21px;
  box-shadow: 0 14px 30px rgba(59,130,246,.14);
}

.feature-strip {
  width: min(760px, 100%);
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 18px;
  margin-top: 18px;
  margin-left: 0;
}

.feature-strip article {
  min-height: 78px;
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid rgba(215, 224, 234, .82);
  border-radius: 13px;
  background: rgba(255,255,255,.76);
  box-shadow: 0 12px 30px rgba(65, 88, 110, .08);
  backdrop-filter: blur(16px);
}

.feature-strip article > span {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 11px;
  font-size: 21px;
}

.feature-strip .green { background: #dff7ee; color: #059669; }
.feature-strip .red { background: #fee2e2; color: #ef4444; }
.feature-strip .blue { background: #dbeafe; color: #3b82f6; }

.feature-strip strong {
  color: #0f172a;
  font-size: 15px;
  font-weight: 900;
}

.feature-strip p {
  display: block;
  margin-top: 3px;
  color: #64748b;
  font-size: 11.5px;
  line-height: 1.45;
}

.login-card {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 560px;
  justify-self: center;
  display: grid;
  padding: 58px 60px 44px;
  border: 1px solid rgba(215, 224, 234, .96);
  border-radius: 20px;
  background: rgba(255,255,255,.86);
  box-shadow: 0 24px 64px rgba(65, 88, 110, .16);
  backdrop-filter: blur(18px);
}

.card-brand {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: #0f172a;
  font-size: 22px;
  font-weight: 950;
}

.card-head {
  margin-top: 24px;
  text-align: center;
}

.card-head h2 {
  color: #0f172a;
  font-size: 34px;
  line-height: 1.15;
  font-weight: 950;
}

.card-head p {
  margin-top: 12px;
  color: #64748b;
  font-size: 16px;
}

.login-form {
  display: grid;
  gap: 16px;
  margin-top: 30px;
}

.field {
  position: relative;
  display: flex;
  align-items: center;
  min-height: 52px;
}

.field > .pi {
  position: absolute;
  left: 16px;
  color: #64748b;
  font-size: 19px;
}

.field input {
  width: 100%;
  height: 52px;
  padding: 0 50px 0 48px;
  border: 1px solid #d7e0ea;
  border-radius: 8px;
  background: rgba(255,255,255,.86);
  color: #0f172a;
  font-size: 15px;
  transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
}

.field input::placeholder {
  color: #94a3b8;
}

.field input:focus {
  border-color: #10b981;
  background: #fff;
  box-shadow: 0 0 0 3px rgba(16,185,129,.13);
  outline: none;
}

.field-icon-btn {
  position: absolute;
  right: 12px;
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #64748b;
}

.field-icon-btn:hover {
  background: #f1f5f9;
  color: #059669;
}

.form-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: 2px;
}

.remember {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: #334155;
  font-size: 14px;
}

.remember input {
  width: 16px;
  height: 16px;
  accent-color: #059669;
}

.link-btn {
  border: 0;
  background: transparent;
  color: #2563eb;
  font-size: 14px;
  font-weight: 700;
}

.submit-btn,
.sso-btn {
  height: 52px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  border-radius: 8px;
  font-size: 17px;
  font-weight: 900;
}

.submit-btn {
  margin-top: 4px;
  border: 0;
  background: linear-gradient(135deg, #10b981, #059669);
  color: #fff;
  box-shadow: 0 16px 30px rgba(5,150,105,.20);
}

.submit-btn:hover {
  background: linear-gradient(135deg, #13c990, #047857);
}

.divider {
  position: relative;
  display: grid;
  place-items: center;
  height: 28px;
  color: #94a3b8;
  font-size: 13px;
}

.divider::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  height: 1px;
  background: #e2e8f0;
}

.divider span {
  position: relative;
  padding: 0 16px;
  background: rgba(255,255,255,.9);
}

.sso-btn {
  border: 1px solid #10b981;
  background: rgba(255,255,255,.78);
  color: #059669;
}

.sso-btn:hover {
  background: #ecfdf5;
}

.security-note {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 34px;
  color: #64748b;
  font-size: 13px;
}

.security-note .pi {
  color: #94a3b8;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 1280px) {
  .login-page {
    grid-template-columns: minmax(520px, 1fr) minmax(480px, 540px);
    gap: 44px;
    padding-inline: 48px;
  }

  .hero-stage {
    transform: scale(.88);
    transform-origin: left center;
    margin-bottom: -32px;
  }

  .feature-strip {
    width: 520px;
    gap: 14px;
    margin-left: 0;
  }

  .login-card { max-width: 500px; }
}

@media (max-height: 840px) and (min-width: 981px) {
  .hero {
    padding-top: 18px;
  }

  .hero-stage {
    margin-top: 16px;
    transform: scale(.9);
    transform-origin: left center;
    margin-bottom: -22px;
  }

  .login-card {
    padding-block: 38px 28px;
  }

  .card-head {
    margin-top: 18px;
  }

  .login-form {
    gap: 14px;
    margin-top: 24px;
  }

  .security-note {
    margin-top: 24px;
  }
}

@media (max-width: 980px) {
  .login-page {
    min-height: 100dvh;
    grid-template-columns: 1fr;
    padding: 92px 28px 28px;
    overflow: auto;
  }

  .page-brand {
    top: 24px;
    left: 24px;
  }

  .hero {
    display: none;
    transform: none;
  }

  .login-card {
    max-width: 520px;
    padding: 40px 28px 30px;
  }
}

@media (max-width: 520px) {
  .login-page {
    padding-inline: 22px;
  }

  .login-card {
    padding: 32px 22px 24px;
    border-radius: 14px;
  }

  .card-head h2 {
    font-size: 30px;
  }

  .form-meta {
    align-items: flex-start;
    flex-direction: column;
    gap: 10px;
  }
}
</style>
