<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Amrita Dashboard - Login</title>
    <script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
    <style>
      :root {
        --primary-color: #8a2be2;
        --secondary-color: #9370db;
        --accent-color: #ba55d3;
        --bg-color: #f8f9fa;
        --text-color: #333;
        --text-light: #fff;
        --card-bg: #ffffff;
        --border-color: #e0d6ff;
        --input-bg: rgba(255, 255, 255, 0.8);

        --dark-bg-color: #1a1a1a;
        --dark-text-color: #f0f0f0;
        --dark-card-bg: #252525;
        --dark-border-color: #444;
        --dark-input-bg: rgba(37, 37, 37, 0.8);
      }

      * {
        margin: 0;
        padding: 0;
        box-sizing: border-box;
        font-family: "Segoe UI", "Microsoft YaHei", sans-serif;
      }

      body {
        background: linear-gradient(-45deg, #ff9a9e, #fad0c4, #fbc2eb, #a6c1ee);
        background-size: 400% 400%;
        height: 100vh;
        display: flex;
        justify-content: center;
        align-items: center;
        animation: gradientBG 15s ease infinite;
        overflow: hidden;
      }

      body.dark-mode {
        background: linear-gradient(-45deg, #2c1a2c, #2a1f2a, #251a25, #1a1a2c);
        background-size: 400% 400%;
      }

      @keyframes gradientBG {
        0% {
          background-position: 0% 50%;
        }
        50% {
          background-position: 100% 50%;
        }
        100% {
          background-position: 0% 50%;
        }
      }

      @keyframes popup {
        0% {
          transform: scale(0.1) translateY(100px);
          opacity: 0;
        }
        70% {
          transform: scale(1.1) translateY(-20px);
          opacity: 1;
        }
        100% {
          transform: scale(1) translateY(0);
          opacity: 1;
        }
      }

      .acgn-decoration {
        position: absolute;
        z-index: 0;
      }

      .decoration-1 {
        top: 10%;
        left: 10%;
        width: 80px;
        height: 80px;
        background: rgba(255, 255, 255, 0.2);
        border-radius: 50%;
        animation: float 6s ease-in-out infinite;
      }

      .decoration-2 {
        bottom: 15%;
        right: 15%;
        width: 60px;
        height: 60px;
        background: rgba(255, 218, 185, 0.3);
        border-radius: 30% 70% 70% 30% / 30% 30% 70% 70%;
        animation: float 8s ease-in-out infinite 1s;
      }

      .decoration-3 {
        top: 20%;
        right: 20%;
        width: 40px;
        height: 40px;
        background: rgba(173, 216, 230, 0.3);
        border-radius: 50%;
        animation: float 7s ease-in-out infinite 0.5s;
      }

      @keyframes float {
        0% {
          transform: translateY(0) rotate(0deg);
        }
        50% {
          transform: translateY(-20px) rotate(10deg);
        }
        100% {
          transform: translateY(0) rotate(0deg);
        }
      }

      .login-container {
        background-color: rgba(255, 255, 255, 0.9);
        border-radius: 20px;
        box-shadow: 0 10px 30px rgba(164, 93, 181, 0.3);
        width: 100%;
        max-width: 420px;
        padding: 35px;
        position: relative;
        z-index: 1;
        backdrop-filter: blur(5px);
        border: 1px solid rgba(255, 255, 255, 0.5);

        animation: popup 0.8s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
        opacity: 0;
        transform: scale(0.1) translateY(100px);
      }

      body.dark-mode .login-container {
        background-color: rgba(37, 37, 37, 0.9);
        box-shadow: 0 10px 30px rgba(100, 50, 120, 0.3);
        border: 1px solid rgba(100, 100, 100, 0.5);
      }

      .logo-section {
        text-align: center;
        margin-bottom: 30px;
      }

      .logo-circle {
        width: 110px;
        height: 110px;
        background: linear-gradient(135deg, #ff7eb3, #ff758c);
        color: white;
        border-radius: 50%;
        display: flex;
        justify-content: center;
        align-items: center;
        margin: 0 auto 20px;
        font-size: 32px;
        font-weight: bold;
        box-shadow: 0 5px 15px rgba(255, 117, 140, 0.4);
        position: relative;
        overflow: hidden;
      }

      .logo-circle::after {
        content: "";
        position: absolute;
        top: -10px;
        left: -10px;
        right: -10px;
        bottom: -10px;
        background: linear-gradient(
          45deg,
          transparent,
          rgba(255, 255, 255, 0.3),
          transparent
        );
        transform: rotate(45deg);
        animation: shine 3s infinite;
      }

      body.dark-mode .logo-circle::after {
        background: linear-gradient(
          45deg,
          transparent,
          rgba(100, 100, 100, 0.3),
          transparent
        );
      }

      @keyframes shine {
        0% {
          transform: translateX(-100%) rotate(45deg);
        }
        100% {
          transform: translateX(100%) rotate(45deg);
        }
      }

      h1 {
        color: #6a40bf;
        font-size: 28px;
        font-weight: 700;
        margin-bottom: 5px;
        text-shadow: 1px 1px 3px rgba(0, 0, 0, 0.1);
      }

      body.dark-mode h1 {
        color: #ba55d3;
        text-shadow: 1px 1px 3px rgba(0, 0, 0, 0.3);
      }

      .subtitle {
        color: #888;
        font-size: 14px;
        margin-bottom: 10px;
      }

      body.dark-mode .subtitle {
        color: #aaa;
      }

      .form-group {
        margin-bottom: 25px;
        position: relative;
      }

      label {
        display: block;
        margin-bottom: 8px;
        color: #6a40bf;
        font-weight: 500;
        font-size: 14px;
      }

      body.dark-mode label {
        color: #ba55d3;
      }

      input[type="text"],
      input[type="password"] {
        width: 100%;
        padding: 14px 18px;
        border: 2px solid #e0d6ff;
        border-radius: 10px;
        font-size: 16px;
        transition: all 0.3s ease;
        background-color: rgba(255, 255, 255, 0.8);
      }

      body.dark-mode input[type="text"],
      body.dark-mode input[type="password"] {
        border: 2px solid #444;
        background-color: rgba(37, 37, 37, 0.8);
        color: #f0f0f0;
      }

      input[type="text"]:focus,
      input[type="password"]:focus {
        border-color: #9f78ff;
        outline: none;
        box-shadow: 0 0 0 3px rgba(159, 120, 255, 0.2);
      }

      body.dark-mode input[type="text"]:focus,
      body.dark-mode input[type="password"]:focus {
        border-color: #ba55d3;
        box-shadow: 0 0 0 3px rgba(186, 85, 211, 0.2);
      }

      .login-btn {
        background: linear-gradient(to right, #9f78ff, #6a40bf);
        color: white;
        border: none;
        padding: 15px;
        width: 100%;
        border-radius: 10px;
        font-size: 16px;
        cursor: pointer;
        transition: all 0.3s ease;
        font-weight: 600;
        box-shadow: 0 4px 10px rgba(159, 120, 255, 0.4);
        position: relative;
        overflow: hidden;
      }

      body.dark-mode .login-btn {
        background: linear-gradient(to right, #ba55d3, #8a2be2);
        box-shadow: 0 4px 10px rgba(186, 85, 211, 0.4);
      }

      .login-btn:hover {
        transform: translateY(-2px);
        box-shadow: 0 6px 15px rgba(159, 120, 255, 0.5);
      }

      body.dark-mode .login-btn:hover {
        box-shadow: 0 6px 15px rgba(186, 85, 211, 0.5);
      }

      .login-btn:active {
        transform: translateY(0);
      }

      .login-btn::after {
        content: "";
        position: absolute;
        top: -50%;
        left: -60%;
        width: 20%;
        height: 200%;
        background: rgba(255, 255, 255, 0.3);
        transform: rotate(25deg);
        transition: all 0.6s;
      }

      body.dark-mode .login-btn::after {
        background: rgba(100, 100, 100, 0.3);
      }

      .login-btn:hover::after {
        left: 120%;
      }

      .button-extensions {
        margin-top: 25px;
        display: flex;
        justify-content: space-between;
      }

      .extension-btn {
        background: none;
        border: none;
        color: #9f78ff;
        cursor: pointer;
        font-size: 14px;
        padding: 8px 12px;
        border-radius: 6px;
        transition: all 0.3s ease;
      }

      body.dark-mode .extension-btn {
        color: #ba55d3;
      }

      .extension-btn:hover {
        color: #6a40bf;
        background-color: rgba(159, 120, 255, 0.1);
        transform: translateY(-2px);
      }

      body.dark-mode .extension-btn:hover {
        color: #8a2be2;
        background-color: rgba(186, 85, 211, 0.1);
      }

      .footer {
        text-align: center;
        margin-top: 30px;
        color: #aaa;
        font-size: 13px;
      }

      body.dark-mode .footer {
        color: #888;
      }

      @media (max-width: 480px) {
        .login-container {
          padding: 25px;
          margin: 0 15px;
        }

        .logo-circle {
          width: 90px;
          height: 90px;
          font-size: 26px;
        }

        h1 {
          font-size: 24px;
        }
      }
    </style>
  </head>
  <body>
    <div class="acgn-decoration decoration-1"></div>
    <div class="acgn-decoration decoration-2"></div>
    <div class="acgn-decoration decoration-3"></div>
    <div class="login-container">
      <div class="logo-section">
        {% if logo_url %}
        <img
          src="{{ logo_url }}"
          alt="Amrita Logo"
          class="logo"
          height="150"
          width="150"
        />
        {% else %}
        <div class="logo-circle">A</div>
        {% endif %}
        <h1>Amrita Dashboard</h1>
        <div class="subtitle">Hello from Amrita</div>
      </div>
      <form action="/login" method="post">
        <div class="form-group">
          <label for="username">用户名</label>
          <input
            type="text"
            id="username"
            name="username"
            placeholder="请输入您的用户名"
            required
          />
        </div>
        <div class="form-group">
          <label for="password">密码</label>
          <input
            type="password"
            id="password"
            name="password"
            placeholder="请输入您的密码"
            required
          />
        </div>
        <button type="submit" class="login-btn">登录</button>
        <div class="button-extensions">
          <a href="/password-help" class="extension-btn">忘记密码?</a>
        </div>
      </form>
      <div class="footer">
        &copy; 2023-2025 Amrita Dashboard. 使用GPL-3.0许可证。
      </div>
    </div>
    <script>
      document.addEventListener("DOMContentLoaded", function () {
        const loginContainer = document.querySelector(".login-container");
        setTimeout(() => {
          loginContainer.style.opacity = "1";
        }, 100);

        const inputs = document.querySelectorAll("input");
        inputs.forEach((input) => {
          input.addEventListener("focus", function () {
            this.parentElement.style.transform = "translateY(-5px)";
            this.parentElement.style.transition = "transform 0.3s ease";
          });

          input.addEventListener("blur", function () {
            this.parentElement.style.transform = "translateY(0)";
          });
        });

        const urlParams = new URLSearchParams(window.location.search);
        if (urlParams.get("error") === "invalid_credentials") {
          Swal.fire({
            title: "登录失败",
            text: "用户名或密码错误，请重试。",
            icon: "error",
            confirmButtonText: "确定",
          });
        }

        function setTheme(theme) {
          if (theme === "dark") {
            document.body.classList.add("dark-mode");
            localStorage.setItem("theme", "dark");
          } else {
            document.body.classList.remove("dark-mode");
            localStorage.setItem("theme", "light");
          }
        }

        function detectSystemTheme() {
          if (
            window.matchMedia &&
            window.matchMedia("(prefers-color-scheme: dark)").matches
          ) {
            return "dark";
          }
          return "light";
        }

        function initTheme() {
          const savedTheme = localStorage.getItem("theme");

          if (savedTheme) {
            setTheme(savedTheme);
          } else {
            const systemTheme = detectSystemTheme();
            setTheme(systemTheme);
          }

          window
            .matchMedia("(prefers-color-scheme: dark)")
            .addEventListener("change", (e) => {
              if (!localStorage.getItem("theme")) {
                setTheme(e.matches ? "dark" : "light");
              }
            });
        }

        initTheme();
      });
    </script>
  </body>
</html>
