<template>
  <div class="login-overlay">
    <div class="login-card">
      <div class="login-logo">
        <span class="login-icon">🌱</span>
        <h1 class="login-title">萌芽 SSH</h1>
        <p class="login-sub">MengyaConnect</p>
      </div>
      <form class="login-form" @submit.prevent="submitLogin">
        <label class="login-label">
          访问密码
          <input
            v-model="loginPassword"
            type="password"
            class="login-input"
            placeholder="请输入访问密码"
            autofocus
            autocomplete="current-password"
          />
        </label>
        <p v-if="loginError" class="login-error">{{ loginError }}</p>
        <button type="submit" class="login-btn" :disabled="loginLoading || !loginPassword">
          {{ loginLoading ? "验证中…" : "进入" }}
        </button>
      </form>
    </div>
  </div>
</template>

<script setup>
import { useAuth } from "../composables/useAuth";
const { loginPassword, loginError, loginLoading, submitLogin } = useAuth();
</script>

<style>
.login-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-1);
  z-index: 9999;
  padding: 16px;
}

.login-card {
  width: 100%;
  max-width: 340px;
  padding: 2.2rem 1.8rem;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.7);
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.login-logo { text-align: center; }
.login-icon { font-size: 2.2rem; }
.login-title {
  margin: 0.4rem 0 0.1rem;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-1);
}
.login-sub {
  margin: 0;
  font-size: 0.78rem;
  color: var(--text-3);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.login-form { display: flex; flex-direction: column; gap: 1rem; }
.login-label { display: flex; flex-direction: column; gap: 0.4rem; font-size: 0.83rem; color: var(--text-2); }

.login-input {
  width: 100%;
  padding: 0.65rem 0.9rem;
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-1);
  font-size: 1rem;
  outline: none;
  transition: border-color 0.2s;
  box-sizing: border-box;
}
.login-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(63, 185, 80, 0.12);
}

.login-error { margin: 0; font-size: 0.8rem; color: #ff7b72; text-align: center; }

.login-btn {
  width: 100%;
  padding: 0.7rem;
  background: #238636;
  border: 1px solid rgba(63, 185, 80, 0.5);
  border-radius: 6px;
  color: #fff;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
  font-family: inherit;
}
.login-btn:hover:not(:disabled) { background: #2ea043; }
.login-btn:active:not(:disabled) { transform: scale(0.98); }
.login-btn:disabled { opacity: 0.4; cursor: not-allowed; }
</style>
