"use client";

import { useEffect, useState } from "react";
import { useSession } from "next-auth/react";

import Navbar from "@/components/Navbar";
import Footer from "@/components/Footer";

type ContactInfo = {
  id: number;
  description: string | null;
  email: string | null;
  phone: string | null;
  location: string | null;
  website: string | null;
  github: string | null;
  linkedin: string | null;
  facebook: string | null;
  instagram: string | null;
  twitter: string | null;
  youtube: string | null;
  tiktok: string | null;
  active: boolean;
};

export default function ContactFormPage() {
  const { data: session } = useSession();

  const [remainingUses, setRemainingUses] =
    useState<number | null>(null);

  const [contactActive, setContactActive] =
    useState<boolean | null>(null);

  const FORM_FROZEN =
    !session ||
    contactActive === false ||
    remainingUses === 0;

  const [contact, setContact] =
    useState<ContactInfo | null>(null);

  const [name, setName] = useState("");
  const [email, setEmail] = useState("");
  const [message, setMessage] = useState("");

  const [loading, setLoading] = useState(false);
  const [contactLoading, setContactLoading] =
    useState(true);

  const [error, setError] = useState("");

  const [showSuccessModal, setShowSuccessModal] =
    useState(false);

  const [animateSuccessModal, setAnimateSuccessModal] =
    useState(false);

  // =====================================================
  // AUTO FILL GOOGLE ACCOUNT
  // =====================================================
  useEffect(() => {
    if (session?.user) {
      setName(session.user.name || "");
      setEmail(session.user.email || "");
    }
  }, [session]);

  // =====================================================
  // LOAD CONTACT FORM USAGE
  // =====================================================
  useEffect(() => {
    const loadUsage = async () => {
      if (!session?.user) {
        setRemainingUses(null);
        setContactActive(null);
        return;
      }

      try {
        const response = await fetch(
          "/api/contact/usage"
        );

        if (!response.ok) {
          return;
        }

        const data = await response.json();

        setRemainingUses(data.remainingUses);
        setContactActive(data.active);
      } catch (error) {
        console.error(
          "LOAD CONTACT USAGE ERROR:",
          error
        );
      }
    };

    loadUsage();
  }, [session]);

  // =====================================================
  // LOAD CONTACT INFORMATION
  // =====================================================
  useEffect(() => {
    const loadContact = async () => {
      try {
        const response = await fetch(
          "/api/contact-info",
          {
            cache: "no-store",
          }
        );

        const result = await response.json();

        if (response.ok && result.data) {
          setContact(result.data);
        }
      } catch (error) {
        console.error(
          "LOAD CONTACT ERROR:",
          error
        );
      } finally {
        setContactLoading(false);
      }
    };

    loadContact();
  }, []);

  // =====================================================
  // HANDLE SUBMIT
  // =====================================================
  const handleSubmit = async (
    e: React.FormEvent<HTMLFormElement>
  ) => {
    e.preventDefault();

    if (FORM_FROZEN) {
      return;
    }

    setLoading(true);
    setError("");

    try {
      const response = await fetch(
        "/api/contact",
        {
          method: "POST",
          headers: {
            "Content-Type": "application/json",
          },
          body: JSON.stringify({
            name,
            email,
            message,
          }),
        }
      );

      const data = await response.json();

      if (!response.ok) {
        throw new Error(
          data.message ||
            "Failed to send message."
        );
      }

      setShowSuccessModal(true);

      setTimeout(() => {
        setAnimateSuccessModal(true);
      }, 50);
    } catch (err) {
      setError(
        err instanceof Error
          ? err.message
          : "An error occurred."
      );
    } finally {
      setLoading(false);
    }
  };

  // =====================================================
  // SOCIAL MEDIA
  // =====================================================
  const socialMedia = [
    {
      name: "GitHub",
      url: contact?.github,
      icon: "bi-github",
      className: "social-github",
    },
    {
      name: "LinkedIn",
      url: contact?.linkedin,
      icon: "bi-linkedin",
      className: "social-linkedin",
    },
    {
      name: "Facebook",
      url: contact?.facebook,
      icon: "bi-facebook",
      className: "social-facebook",
    },
    {
      name: "Instagram",
      url: contact?.instagram,
      icon: "bi-instagram",
      className: "social-instagram",
    },
    {
      name: "Twitter / X",
      url: contact?.twitter,
      icon: "bi-twitter-x",
      className: "social-twitter",
    },
    {
      name: "YouTube",
      url: contact?.youtube,
      icon: "bi-youtube",
      className: "social-youtube",
    },
    {
      name: "TikTok",
      url: contact?.tiktok,
      icon: "bi-tiktok",
      className: "social-tiktok",
    },
  ];

  return (
    <>
      <Navbar />

      <div className="contact-page">
        <main
          className="contact-container"
          id="contact-form"
        >
          {/* =================================================
              HEADER
          ================================================== */}
          <div className="contact-header">
            <span className="contact-label">
              <i
                className="bi bi-envelope"
                aria-hidden="true"
              />
              Contact
            </span>

            <h1 className="contact-heading">
              Get In Touch
            </h1>

            <div className="contact-heading-line">
              <span />
            </div>

            <p className="contact-intro">
              Have a project idea or want to work
              together? Feel free to reach out.
            </p>
          </div>

          <div className="contact-grid">
            {/* =================================================
                CONTACT INFORMATION
            ================================================== */}
            <div className="contact-info-column">
              <section className="contact-card">
                <div className="card-top-line">
                  <span />
                </div>

                <div className="contact-card-body">
                  <div className="card-heading">
                    <span className="card-heading-icon">
                      <i
                        className="bi bi-person-lines-fill"
                        aria-hidden="true"
                      />
                    </span>

                    <div>
                      <span className="card-heading-label">
                        CONTACT
                      </span>

                      <h2>
                        Contact Information
                      </h2>
                    </div>
                  </div>

                  {/* DESCRIPTION */}
                  <p className="contact-description">
                    {contact?.description ||
                      "Have a technology project, engineering opportunity, or collaboration in mind? Feel free to get in touch. I am open to discussing engineering leadership, technology development, and innovative digital solutions."}
                  </p>

                  {contactLoading ? (
                    <div className="contact-loading">
                      <div
                        className="spinner-border text-success"
                        role="status"
                        aria-hidden="true"
                      />

                      <p>
                        Loading contact information...
                      </p>
                    </div>
                  ) : (
                    <>
                      {/* EMAIL */}
                      {contact?.email && (
                        <div className="contact-detail">
                          <div className="contact-detail-icon">
                            <i
                              className="bi bi-envelope"
                              aria-hidden="true"
                            />
                          </div>

                          <div className="contact-detail-content">
                            <small>
                              Email
                            </small>

                            <a
                              href={`mailto:${contact.email}`}
                            >
                              {contact.email}
                            </a>
                          </div>
                        </div>
                      )}

                      {/* PHONE */}
                      {contact?.phone && (
                        <div className="contact-detail">
                          <div className="contact-detail-icon">
                            <i
                              className="bi bi-telephone"
                              aria-hidden="true"
                            />
                          </div>

                          <div className="contact-detail-content">
                            <small>
                              Phone
                            </small>

                            <a
                              href={`tel:${contact.phone}`}
                            >
                              {contact.phone}
                            </a>
                          </div>
                        </div>
                      )}

                      {/* LOCATION */}
                      {contact?.location && (
                        <div className="contact-detail">
                          <div className="contact-detail-icon">
                            <i
                              className="bi bi-geo-alt"
                              aria-hidden="true"
                            />
                          </div>

                          <div className="contact-detail-content">
                            <small>
                              Location
                            </small>

                            <span>
                              {contact.location}
                            </span>
                          </div>
                        </div>
                      )}

                      {/* WEBSITE */}
                      {contact?.website && (
                        <div className="contact-detail">
                          <div className="contact-detail-icon">
                            <i
                              className="bi bi-globe"
                              aria-hidden="true"
                            />
                          </div>

                          <div className="contact-detail-content">
                            <small>
                              Website
                            </small>

                            <a
                              href={contact.website}
                              target="_blank"
                              rel="noopener noreferrer"
                            >
                              {contact.website.replace(
                                /^https?:\/\//,
                                ""
                              )}
                            </a>
                          </div>
                        </div>
                      )}

                      {/* SOCIAL MEDIA */}
                      <div className="social-section">
                        <div className="social-divider">
                          <span />
                        </div>

                        <div className="social-title">
                          <i
                            className="bi bi-share"
                            aria-hidden="true"
                          />
                          <span>
                            Follow Me
                          </span>
                        </div>

                        <div className="social-list">
                          {socialMedia
                            .filter(
                              (social) =>
                                social.url
                            )
                            .map((social) => (
                              <a
                                key={social.name}
                                href={
                                  social.url!
                                }
                                target="_blank"
                                rel="noopener noreferrer"
                                className={`social-button ${social.className}`}
                                title={
                                  social.name
                                }
                                aria-label={
                                  social.name
                                }
                              >
                                <i
                                  className={`bi ${social.icon}`}
                                  aria-hidden="true"
                                />
                              </a>
                            ))}
                        </div>
                      </div>
                    </>
                  )}
                </div>
              </section>
            </div>

            {/* =================================================
                CONTACT FORM
            ================================================== */}
            <div className="contact-form-column">
              <section className="contact-card">
                <div className="card-top-line">
                  <span />
                </div>

                <div className="contact-card-body">
                  <div className="card-heading">
                    <span className="card-heading-icon">
                      <i
                        className="bi bi-send"
                        aria-hidden="true"
                      />
                    </span>

                    <div>
                      <span className="card-heading-label">
                        MESSAGE
                      </span>

                      <h2>
                        Send Me a Message
                      </h2>
                    </div>
                  </div>

                  {/* LOGIN REQUIRED */}
                  {!session && (
                    <div
                      className="contact-alert alert-warning-custom"
                      role="alert"
                    >
                      <div className="alert-icon">
                        <i
                          className="bi bi-lock-fill"
                          aria-hidden="true"
                        />
                      </div>

                      <div className="alert-content">
                        <strong>
                          Login Required
                        </strong>

                        <p>
                          Please sign in with your
                          Google account before
                          using the contact form.
                        </p>

                        <a
                          href="/login"
                          className="login-button"
                        >
                          <i
                            className="bi bi-google"
                            aria-hidden="true"
                          />
                          <span>
                            Login with Google
                          </span>
                        </a>
                      </div>
                    </div>
                  )}

                  {/* ADMIN DISABLED */}
                  {session &&
                    contactActive === false && (
                      <div
                        className="contact-alert alert-warning-custom"
                        role="alert"
                      >
                        <div className="alert-icon">
                          <i
                            className="bi bi-lock-fill"
                            aria-hidden="true"
                          />
                        </div>

                        <div className="alert-content">
                          <strong>
                            Contact Form Disabled
                          </strong>

                          <p>
                            The contact form has
                            been temporarily
                            disabled by the
                            administrator.
                          </p>
                        </div>
                      </div>
                    )}

                  {/* LIMIT REACHED */}
                  {session &&
                    contactActive !== false &&
                    remainingUses === 0 && (
                      <div
                        className="contact-alert alert-warning-custom"
                        role="alert"
                      >
                        <div className="alert-icon">
                          <i
                            className="bi bi-lock-fill"
                            aria-hidden="true"
                          />
                        </div>

                        <div className="alert-content">
                          <strong>
                            Contact Form Limit
                            Reached
                          </strong>

                          <p>
                            You have used all 3
                            contact form
                            submissions. Please
                            contact the
                            administrator if you
                            need access again.
                          </p>
                        </div>
                      </div>
                    )}

                  {/* REMAINING USES */}
                  {session &&
                    contactActive !== false &&
                    remainingUses !== null &&
                    remainingUses > 0 && (
                      <div
                        className="contact-alert alert-info-custom"
                        role="alert"
                      >
                        <div className="alert-icon">
                          <i
                            className="bi bi-info-circle"
                            aria-hidden="true"
                          />
                        </div>

                        <div className="alert-content">
                          <p>
                            You can still use the
                            contact form{" "}
                            <strong>
                              {remainingUses} times
                            </strong>
                            .
                          </p>
                        </div>
                      </div>
                    )}

                  {/* ERROR */}
                  {error && (
                    <div
                      className="contact-alert alert-error-custom"
                      role="alert"
                    >
                      <div className="alert-icon">
                        <i
                          className="bi bi-exclamation-circle"
                          aria-hidden="true"
                        />
                      </div>

                      <div className="alert-content">
                        <strong>
                          Unable to Send
                        </strong>

                        <p>
                          {error}
                        </p>
                      </div>
                    </div>
                  )}

                  {/* FORM */}
                  <form
                    onSubmit={handleSubmit}
                    className="contact-form"
                  >
                    <fieldset
                      disabled={
                        FORM_FROZEN || loading
                      }
                      className="contact-fieldset"
                    >
                      {/* NAME */}
                      <div className="form-field">
                        <label htmlFor="contact-name">
                          <i
                            className="bi bi-person"
                            aria-hidden="true"
                          />
                          Name
                        </label>

                        <input
                          id="contact-name"
                          type="text"
                          placeholder="Your name"
                          value={name}
                          readOnly
                          onChange={(e) =>
                            setName(
                              e.target.value
                            )
                          }
                          required
                        />
                      </div>

                      {/* EMAIL */}
                      <div className="form-field">
                        <label htmlFor="contact-email">
                          <i
                            className="bi bi-envelope"
                            aria-hidden="true"
                          />
                          Email
                        </label>

                        <input
                          id="contact-email"
                          type="email"
                          value={email}
                          readOnly
                          required
                        />
                      </div>

                      {/* MESSAGE */}
                      <div className="form-field">
                        <label htmlFor="contact-message">
                          <i
                            className="bi bi-chat-left-text"
                            aria-hidden="true"
                          />
                          Message
                        </label>

                        <textarea
                          id="contact-message"
                          rows={6}
                          placeholder="Write your message..."
                          value={message}
                          onChange={(e) =>
                            setMessage(
                              e.target.value
                            )
                          }
                          required
                        />
                      </div>

                      {/* BUTTON */}
                      <button
                        type="submit"
                        className="send-button"
                        disabled={loading}
                      >
                        {loading ? (
                          <>
                            <span
                              className="spinner-border spinner-border-sm"
                              role="status"
                              aria-hidden="true"
                            />

                            <span>
                              Sending...
                            </span>
                          </>
                        ) : (
                          <>
                            <i
                              className="bi bi-send"
                              aria-hidden="true"
                            />

                            <span>
                              Send Message
                            </span>

                            <i
                              className="bi bi-arrow-up-right"
                              aria-hidden="true"
                            />
                          </>
                        )}
                      </button>
                    </fieldset>
                  </form>
                </div>
              </section>
            </div>
          </div>
        </main>
      </div>

      {/* =================================================
          SUCCESS MODAL
      ================================================== */}
      {showSuccessModal && (
        <div
          className={`success-overlay ${
            animateSuccessModal
              ? "success-overlay-visible"
              : ""
          }`}
        >
          <div
            className={`success-modal ${
              animateSuccessModal
                ? "success-modal-visible"
                : ""
            }`}
          >
            <div
              className={`success-icon ${
                animateSuccessModal
                  ? "success-icon-visible"
                  : ""
              }`}
            >
              <i
                className="bi bi-check-lg"
                aria-hidden="true"
              />
            </div>

            <span className="success-label">
              SUCCESS
            </span>

            <h4>
              Message Sent Successfully
            </h4>

            <p>
              Your message has been sent
              successfully.
            </p>

            <button
              type="button"
              className="success-button"
              onClick={() => {
                setShowSuccessModal(false);
                window.location.reload();
              }}
            >
              <span>OK</span>
              <i
                className="bi bi-check2"
                aria-hidden="true"
              />
            </button>
          </div>
        </div>
      )}

      <Footer />

      {/* =================================================
          PAGE CSS
      ================================================== */}
      <style>{`
        .contact-page {
          width: 100%;
          padding-top: 76px;
          background: #ffffff;
        }

        .contact-container {
          width: 100%;
          max-width: 1200px;
          margin: 0 auto;
          padding: 90px 20px;
        }

        /* =================================================
           HEADER
        ================================================== */

        .contact-header {
          max-width: 800px;
          margin: 0 auto 55px;
          text-align: center;
        }

        .contact-label {
          display: inline-flex;
          align-items: center;
          gap: 8px;
          margin-bottom: 12px;
          padding: 7px 13px;
          color: #198754;
          background: rgba(25, 135, 84, 0.08);
          border: 1px solid rgba(25, 135, 84, 0.16);
          border-radius: 999px;
          font-size: 0.72rem;
          font-weight: 700;
          letter-spacing: 1.5px;
          text-transform: uppercase;
        }

        .contact-label i {
          font-size: 0.78rem;
        }

        .contact-heading {
          margin: 0;
          color: #18251f;
          font-size: clamp(2rem, 4vw, 2.8rem);
          font-weight: 700;
          line-height: 1.2;
        }

        .contact-heading-line {
          position: relative;
          width: 130px;
          height: 2px;
          margin: 18px auto 20px;
          overflow: hidden;
          border-radius: 999px;
          background: rgba(25, 135, 84, 0.13);
        }

        .contact-heading-line span {
          position: absolute;
          top: 0;
          left: -55%;
          width: 55%;
          height: 100%;
          border-radius: 999px;
          background: linear-gradient(
            90deg,
            transparent,
            #198754,
            #55bd8a,
            #198754,
            transparent
          );
          box-shadow: 0 0 8px rgba(25, 135, 84, 0.35);
          animation: contactHeadingLine 2.8s linear infinite;
        }

        @keyframes contactHeadingLine {
          0% {
            left: -55%;
          }

          100% {
            left: 100%;
          }
        }

        .contact-intro {
          max-width: 650px;
          margin: 0 auto;
          color: #6c757d;
          font-size: 0.94rem;
          line-height: 1.8;
          text-align: center;
        }

        /* =================================================
           GRID
        ================================================== */

        .contact-grid {
          display: grid;
          grid-template-columns:
            minmax(0, 0.9fr)
            minmax(0, 1.1fr);
          gap: 25px;
          align-items: stretch;
        }

        .contact-info-column,
        .contact-form-column {
          min-width: 0;
        }

        /* =================================================
           CARD
        ================================================== */

        .contact-card {
          position: relative;
          display: flex;
          flex-direction: column;
          height: 100%;
          overflow: hidden;
          background: #ffffff;
          border: 1px solid rgba(25, 135, 84, 0.42);
          border-radius: 16px;
          box-shadow:
            0 10px 30px rgba(20, 50, 35, 0.055),
            0 0 0 1px rgba(25, 135, 84, 0.025);
          transition:
            border-color 0.3s ease,
            box-shadow 0.3s ease,
            transform 0.3s ease;
        }

        .contact-card:hover {
          border-color: rgba(25, 135, 84, 0.65);
          box-shadow:
            0 16px 35px rgba(20, 50, 35, 0.08);
          transform: translateY(-3px);
        }

        .card-top-line {
          position: relative;
          width: 100%;
          height: 2px;
          flex-shrink: 0;
          overflow: hidden;
          background: rgba(25, 135, 84, 0.12);
        }

        .card-top-line span {
          position: absolute;
          top: 0;
          left: -35%;
          width: 35%;
          height: 100%;
          border-radius: 999px;
          background: linear-gradient(
            90deg,
            transparent,
            #198754,
            #55bd8a,
            #198754,
            transparent
          );
          box-shadow: 0 0 9px rgba(25, 135, 84, 0.38);
          animation: contactTopLine 3s linear infinite;
        }

        @keyframes contactTopLine {
          0% {
            left: -35%;
          }

          100% {
            left: 100%;
          }
        }

        .contact-card-body {
          display: flex;
          flex-direction: column;
          flex: 1;
          min-width: 0;
          padding: 30px;
        }

        /* =================================================
           CARD HEADING
        ================================================== */

        .card-heading {
          display: flex;
          align-items: center;
          gap: 14px;
          margin-bottom: 24px;
        }

        .card-heading-icon {
          display: flex;
          align-items: center;
          justify-content: center;
          width: 48px;
          height: 48px;
          flex: 0 0 48px;
          color: #198754;
          background: rgba(25, 135, 84, 0.08);
          border: 1px solid rgba(25, 135, 84, 0.18);
          border-radius: 12px;
          font-size: 1.2rem;
        }

        .card-heading-label {
          display: block;
          margin-bottom: 3px;
          color: #198754;
          font-size: 0.65rem;
          font-weight: 700;
          letter-spacing: 1.5px;
        }

        .card-heading h2 {
          margin: 0;
          color: #18251f;
          font-size: 1.2rem;
          font-weight: 700;
          line-height: 1.4;
        }

        /* =================================================
           DESCRIPTION
        ================================================== */

        .contact-description {
          margin: 0 0 27px;
          padding: 0;
          color: #68746d;
          font-size: 0.9rem;
          line-height: 1.8;
          text-align: justify;
          overflow-wrap: anywhere;
        }

        /* =================================================
           CONTACT DETAILS
        ================================================== */

        .contact-detail {
          display: flex;
          align-items: flex-start;
          gap: 13px;
          min-width: 0;
          margin-bottom: 19px;
        }

        .contact-detail:last-of-type {
          margin-bottom: 0;
        }

        .contact-detail-icon {
          display: flex;
          align-items: center;
          justify-content: center;
          width: 42px;
          height: 42px;
          min-width: 42px;
          color: #198754;
          background: rgba(25, 135, 84, 0.07);
          border: 1px solid rgba(25, 135, 84, 0.15);
          border-radius: 11px;
          font-size: 0.95rem;
        }

        .contact-detail-content {
          display: flex;
          flex-direction: column;
          justify-content: center;
          min-width: 0;
          padding-top: 1px;
        }

        .contact-detail-content small {
          margin-bottom: 3px;
          color: #8a948f;
          font-size: 0.68rem;
          font-weight: 600;
          letter-spacing: 0.4px;
        }

        .contact-detail-content a,
        .contact-detail-content span {
          max-width: 100%;
          color: #26342d;
          font-size: 0.86rem;
          font-weight: 600;
          line-height: 1.55;
          overflow-wrap: anywhere;
          word-break: break-word;
        }

        .contact-detail-content a {
          text-decoration: none;
          transition: color 0.2s ease;
        }

        .contact-detail-content a:hover {
          color: #198754;
        }

        /* =================================================
           SOCIAL
        ================================================== */

        .social-section {
          margin-top: auto;
          padding-top: 8px;
        }

        .social-divider {
          position: relative;
          width: 100%;
          height: 1px;
          margin: 22px 0 20px;
          overflow: hidden;
          background: rgba(25, 135, 84, 0.12);
        }

        .social-divider span {
          position: absolute;
          top: 0;
          left: -30%;
          width: 30%;
          height: 1px;
          background: linear-gradient(
            90deg,
            transparent,
            #198754,
            transparent
          );
          animation: socialDivider 3.5s linear infinite;
        }

        @keyframes socialDivider {
          0% {
            left: -30%;
          }

          100% {
            left: 100%;
          }
        }

        .social-title {
          display: flex;
          align-items: center;
          gap: 8px;
          margin-bottom: 13px;
          color: #26342d;
          font-size: 0.8rem;
          font-weight: 700;
        }

        .social-title i {
          color: #198754;
          font-size: 0.82rem;
        }

        .social-list {
          display: flex;
          align-items: center;
          flex-wrap: wrap;
          gap: 8px;
        }

        .social-button {
          display: flex;
          align-items: center;
          justify-content: center;
          width: 38px;
          height: 38px;
          color: #6c757d;
          background: #ffffff;
          border: 1px solid rgba(25, 135, 84, 0.18);
          border-radius: 10px;
          text-decoration: none;
          transition:
            color 0.25s ease,
            background 0.25s ease,
            border-color 0.25s ease,
            transform 0.25s ease;
        }

        .social-button:hover {
          color: #ffffff;
          background: #198754;
          border-color: #198754;
          transform: translateY(-3px);
        }

        /* =================================================
           LOADING
        ================================================== */

        .contact-loading {
          display: flex;
          flex-direction: column;
          align-items: center;
          justify-content: center;
          min-height: 170px;
          color: #6c757d;
        }

        .contact-loading p {
          margin: 13px 0 0;
          font-size: 0.84rem;
        }

        /* =================================================
           ALERTS
        ================================================== */

        .contact-alert {
          display: flex;
          align-items: flex-start;
          gap: 13px;
          margin-bottom: 23px;
          padding: 15px;
          border-radius: 12px;
          border: 1px solid;
        }

        .alert-icon {
          display: flex;
          align-items: center;
          justify-content: center;
          width: 34px;
          height: 34px;
          min-width: 34px;
          border-radius: 9px;
          font-size: 0.9rem;
        }

        .alert-content {
          min-width: 0;
          flex: 1;
        }

        .alert-content strong {
          display: block;
          margin-bottom: 4px;
          color: #26342d;
          font-size: 0.82rem;
          font-weight: 700;
        }

        .alert-content p {
          margin: 0;
          color: #6c757d;
          font-size: 0.77rem;
          line-height: 1.65;
          text-align: justify;
          overflow-wrap: anywhere;
        }

        .alert-warning-custom {
          background: rgba(255, 193, 7, 0.07);
          border-color: rgba(255, 193, 7, 0.24);
        }

        .alert-warning-custom .alert-icon {
          color: #b58105;
          background: rgba(255, 193, 7, 0.12);
        }

        .alert-info-custom {
          background: rgba(13, 202, 240, 0.06);
          border-color: rgba(13, 202, 240, 0.2);
        }

        .alert-info-custom .alert-icon {
          color: #0c859e;
          background: rgba(13, 202, 240, 0.1);
        }

        .alert-error-custom {
          background: rgba(220, 53, 69, 0.06);
          border-color: rgba(220, 53, 69, 0.2);
        }

        .alert-error-custom .alert-icon {
          color: #c82333;
          background: rgba(220, 53, 69, 0.1);
        }

        /* =================================================
           LOGIN BUTTON
        ================================================== */

        .login-button {
          display: inline-flex;
          align-items: center;
          justify-content: center;
          gap: 8px;
          margin-top: 13px;
          padding: 8px 13px;
          color: #ffffff;
          background: #198754;
          border: 1px solid #198754;
          border-radius: 8px;
          font-size: 0.76rem;
          font-weight: 600;
          text-decoration: none;
          transition:
            background 0.25s ease,
            border-color 0.25s ease,
            transform 0.25s ease;
        }

        .login-button:hover {
          color: #ffffff;
          background: #157347;
          border-color: #157347;
          transform: translateY(-2px);
        }

        /* =================================================
           FORM
        ================================================== */

        .contact-form {
          width: 100%;
        }

        .contact-fieldset {
          min-width: 0;
          margin: 0;
          padding: 0;
          border: 0;
        }

        .contact-fieldset:disabled {
          opacity: 0.72;
        }

        .form-field {
          margin-bottom: 19px;
        }

        .form-field label {
          display: flex;
          align-items: center;
          gap: 7px;
          margin-bottom: 8px;
          color: #26342d;
          font-size: 0.78rem;
          font-weight: 700;
        }

        .form-field label i {
          color: #198754;
          font-size: 0.8rem;
        }

        .form-field input,
        .form-field textarea {
          display: block;
          width: 100%;
          min-width: 0;
          padding: 11px 13px;
          color: #26342d;
          background: #ffffff;
          border: 1px solid rgba(25, 135, 84, 0.2);
          border-radius: 10px;
          outline: none;
          font-family: inherit;
          font-size: 0.85rem;
          line-height: 1.6;
          box-shadow: none;
          transition:
            border-color 0.25s ease,
            box-shadow 0.25s ease,
            background 0.25s ease;
        }

        .form-field input {
          height: 45px;
        }

        .form-field textarea {
          min-height: 135px;
          resize: vertical;
        }

        .form-field input::placeholder,
        .form-field textarea::placeholder {
          color: #adb5bd;
        }

        .form-field input:focus,
        .form-field textarea:focus {
          border-color: #198754;
          background: #ffffff;
          box-shadow:
            0 0 0 3px rgba(25, 135, 84, 0.08);
        }

        .form-field input[readonly] {
          background: #f8faf9;
          cursor: default;
        }

        .contact-fieldset:disabled
          .form-field
          input,
        .contact-fieldset:disabled
          .form-field
          textarea {
          cursor: not-allowed;
        }

        /* =================================================
           SEND BUTTON
        ================================================== */

        .send-button {
          display: inline-flex;
          align-items: center;
          justify-content: center;
          gap: 9px;
          min-height: 43px;
          padding: 9px 16px;
          color: #ffffff;
          background: #198754;
          border: 1px solid #198754;
          border-radius: 9px;
          font-size: 0.8rem;
          font-weight: 600;
          cursor: pointer;
          transition:
            background 0.25s ease,
            border-color 0.25s ease,
            transform 0.25s ease,
            box-shadow 0.25s ease;
        }

        .send-button:hover:not(:disabled) {
          background: #157347;
          border-color: #157347;
          box-shadow:
            0 8px 18px rgba(25, 135, 84, 0.17);
          transform: translateY(-2px);
        }

        .send-button:disabled {
          opacity: 0.7;
          cursor: not-allowed;
        }

        .send-button i:last-child {
          font-size: 0.72rem;
          transition: transform 0.25s ease;
        }

        .send-button:hover:not(:disabled)
          i:last-child {
          transform: translate(2px, -2px);
        }

        /* =================================================
           SUCCESS MODAL
        ================================================== */

        .success-overlay {
          position: fixed;
          inset: 0;
          z-index: 9999;
          display: flex;
          align-items: center;
          justify-content: center;
          padding: 20px;
          background: rgba(12, 25, 19, 0.58);
          backdrop-filter: blur(5px);
          opacity: 0;
          transition: opacity 0.3s ease;
        }

        .success-overlay-visible {
          opacity: 1;
        }

        .success-modal {
          position: relative;
          width: 100%;
          max-width: 420px;
          padding: 36px 30px 30px;
          overflow: hidden;
          text-align: center;
          background: #ffffff;
          border: 1px solid rgba(25, 135, 84, 0.28);
          border-radius: 18px;
          box-shadow:
            0 25px 70px rgba(0, 0, 0, 0.18);
          transform: translateY(25px) scale(0.96);
          opacity: 0;
          transition:
            transform 0.35s ease,
            opacity 0.35s ease;
        }

        .success-modal::before {
          content: "";
          position: absolute;
          top: 0;
          left: -35%;
          width: 35%;
          height: 2px;
          background: linear-gradient(
            90deg,
            transparent,
            #198754,
            #55bd8a,
            #198754,
            transparent
          );
          box-shadow: 0 0 9px rgba(25, 135, 84, 0.38);
          animation: successTopLine 3s linear infinite;
        }

        @keyframes successTopLine {
          0% {
            left: -35%;
          }

          100% {
            left: 100%;
          }
        }

        .success-modal-visible {
          transform: translateY(0) scale(1);
          opacity: 1;
        }

        .success-icon {
          display: flex;
          align-items: center;
          justify-content: center;
          width: 76px;
          height: 76px;
          margin: 0 auto 18px;
          color: #198754;
          background: rgba(25, 135, 84, 0.08);
          border: 1px solid rgba(25, 135, 84, 0.2);
          border-radius: 50%;
          font-size: 2.2rem;
          transform: scale(0.4);
          opacity: 0;
          transition:
            transform 0.45s ease,
            opacity 0.45s ease;
        }

        .success-icon-visible {
          transform: scale(1);
          opacity: 1;
        }

        .success-label {
          display: block;
          margin-bottom: 6px;
          color: #198754;
          font-size: 0.65rem;
          font-weight: 700;
          letter-spacing: 1.5px;
        }

        .success-modal h4 {
          margin: 0 0 8px;
          color: #18251f;
          font-size: 1.2rem;
          font-weight: 700;
        }

        .success-modal p {
          margin: 0 0 23px;
          color: #6c757d;
          font-size: 0.84rem;
          line-height: 1.7;
        }

        .success-button {
          display: inline-flex;
          align-items: center;
          justify-content: center;
          gap: 8px;
          min-width: 82px;
          padding: 9px 17px;
          color: #ffffff;
          background: #198754;
          border: 1px solid #198754;
          border-radius: 9px;
          font-size: 0.8rem;
          font-weight: 600;
          cursor: pointer;
          transition:
            background 0.25s ease,
            transform 0.25s ease;
        }

        .success-button:hover {
          background: #157347;
          border-color: #157347;
          transform: translateY(-2px);
        }

        /* =================================================
           TABLET
        ================================================== */

        @media (max-width: 991.98px) {
          .contact-container {
            padding: 75px 18px;
          }

          .contact-grid {
            grid-template-columns: 1fr;
            gap: 20px;
          }

          .contact-info-column,
          .contact-form-column {
            width: 100%;
          }

          .contact-card-body {
            padding: 27px;
          }
        }

        /* =================================================
           MOBILE
        ================================================== */

        @media (max-width: 767.98px) {
          .contact-page {
            padding-top: 68px;
          }

          .contact-container {
            padding: 65px 15px;
          }

          .contact-header {
            margin-bottom: 40px;
          }

          .contact-label {
            font-size: 0.66rem;
            letter-spacing: 1.4px;
          }

          .contact-heading {
            font-size: 1.85rem;
          }

          .contact-heading-line {
            width: 105px;
            margin-top: 15px;
            margin-bottom: 17px;
          }

          .contact-intro {
            font-size: 0.86rem;
            line-height: 1.75;
          }

          .contact-grid {
            gap: 18px;
          }

          .contact-card {
            border-radius: 14px;
          }

          .contact-card-body {
            padding: 23px 20px;
          }

          .card-heading {
            gap: 12px;
            margin-bottom: 21px;
          }

          .card-heading-icon {
            width: 44px;
            height: 44px;
            flex-basis: 44px;
            border-radius: 11px;
            font-size: 1.05rem;
          }

          .card-heading h2 {
            font-size: 1.08rem;
          }

          .card-heading-label {
            font-size: 0.6rem;
          }

          .contact-description {
            margin-bottom: 24px;
            font-size: 0.86rem;
            line-height: 1.75;
          }

          .contact-detail {
            gap: 11px;
            margin-bottom: 17px;
          }

          .contact-detail-icon {
            width: 39px;
            height: 39px;
            min-width: 39px;
            border-radius: 10px;
            font-size: 0.88rem;
          }

          .contact-detail-content a,
          .contact-detail-content span {
            font-size: 0.82rem;
          }

          .social-divider {
            margin-top: 20px;
            margin-bottom: 18px;
          }

          .social-button {
            width: 36px;
            height: 36px;
            border-radius: 9px;
          }

          .contact-alert {
            padding: 13px;
            gap: 10px;
          }

          .alert-icon {
            width: 31px;
            height: 31px;
            min-width: 31px;
          }

          .alert-content strong {
            font-size: 0.78rem;
          }

          .alert-content p {
            font-size: 0.74rem;
            line-height: 1.6;
          }

          .form-field {
            margin-bottom: 17px;
          }

          .form-field input {
            height: 43px;
          }

          .form-field textarea {
            min-height: 125px;
          }

          .send-button {
            width: 100%;
          }

          .success-modal {
            max-width: calc(100% - 10px);
            padding: 32px 23px 26px;
            border-radius: 16px;
          }
        }

        /* =================================================
           SMALL MOBILE
        ================================================== */

        @media (max-width: 420px) {
          .contact-container {
            padding: 55px 12px;
          }

          .contact-heading {
            font-size: 1.65rem;
          }

          .contact-intro {
            font-size: 0.82rem;
          }

          .contact-card-body {
            padding: 21px 17px;
          }

          .card-heading {
            gap: 10px;
          }

          .card-heading-icon {
            width: 41px;
            height: 41px;
            flex-basis: 41px;
          }

          .card-heading h2 {
            font-size: 1rem;
          }

          .contact-description {
            font-size: 0.83rem;
            line-height: 1.7;
          }

          .contact-detail-content a,
          .contact-detail-content span {
            font-size: 0.79rem;
          }

          .social-list {
            gap: 6px;
          }

          .social-button {
            width: 34px;
            height: 34px;
          }

          .success-icon {
            width: 68px;
            height: 68px;
            font-size: 2rem;
          }

          .success-modal h4 {
            font-size: 1.08rem;
          }

          .success-modal p {
            font-size: 0.8rem;
          }
        }

        /* =================================================
           REDUCED MOTION
        ================================================== */

        @media (prefers-reduced-motion: reduce) {
          .contact-heading-line span,
          .card-top-line span,
          .social-divider span,
          .success-modal::before {
            animation: none !important;
          }

          .contact-card,
          .social-button,
          .login-button,
          .send-button,
          .success-button {
            transition: none !important;
          }
        }
      `}</style>
    </>
  );
}