"use client";

import { useEffect, useState } from "react";
import { useSession } from "next-auth/react";

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 ContactPage() {
  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",
    },
    {
      name: "LinkedIn",
      url: contact?.linkedin,
      icon: "bi-linkedin",
    },
    {
      name: "Facebook",
      url: contact?.facebook,
      icon: "bi-facebook",
    },
    {
      name: "Instagram",
      url: contact?.instagram,
      icon: "bi-instagram",
    },
    {
      name: "Twitter / X",
      url: contact?.twitter,
      icon: "bi-twitter-x",
    },
    {
      name: "YouTube",
      url: contact?.youtube,
      icon: "bi-youtube",
    },
    {
      name: "TikTok",
      url: contact?.tiktok,
      icon: "bi-tiktok",
    },
  ];

  return (
    <>
      <main
        className="contact-page"
        id="contact"
      >
        <div className="contact-container">

          {/* =================================================
              HEADER
          ================================================== */}

          <div className="contact-header">

            <div className="contact-label">
              <span className="contact-label-line" />

              <span className="contact-label-text">
                <i
                  className="bi bi-envelope"
                  aria-hidden="true"
                />
                CONTACT
              </span>

              <span className="contact-label-line" />
            </div>

            <h1 className="contact-title">
              Get In <span>Touch</span>
            </h1>

            <div className="contact-title-line">
              <span />
            </div>

            <p className="contact-intro">
              Have a project idea, technology opportunity,
              or collaboration in mind? Feel free to get in
              touch and let&apos;s discuss how we can work
              together.
            </p>

          </div>

          {/* =================================================
              MAIN GRID
          ================================================== */}

          <div className="contact-grid">

            {/* =================================================
                CONTACT INFORMATION
            ================================================== */}

            <div className="contact-info-card">

              <div className="contact-card-top-line">
                <span />
              </div>

              <div className="contact-card-content">

                <div className="contact-section-heading">
                  <span className="contact-heading-icon">
                    <i
                      className="bi bi-person-lines-fill"
                      aria-hidden="true"
                    />
                  </span>

                  <div>
                    <span className="contact-heading-label">
                      LET&apos;S CONNECT
                    </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="contact-loading-line">
                      <span />
                    </div>

                    <div className="contact-loading-content">
                      <div
                        className="spinner-border text-success"
                        role="status"
                        aria-hidden="true"
                      />

                      <p>
                        Loading contact information...
                      </p>
                    </div>

                  </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">
                          <span className="contact-detail-label">
                            Email
                          </span>

                          <a
                            href={`mailto:${contact.email}`}
                            className="contact-detail-value"
                          >
                            {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">
                          <span className="contact-detail-label">
                            Phone
                          </span>

                          <a
                            href={`tel:${contact.phone}`}
                            className="contact-detail-value"
                          >
                            {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">
                          <span className="contact-detail-label">
                            Location
                          </span>

                          <span className="contact-detail-value">
                            {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">
                          <span className="contact-detail-label">
                            Website
                          </span>

                          <a
                            href={contact.website}
                            target="_blank"
                            rel="noopener noreferrer"
                            className="contact-detail-value"
                          >
                            {contact.website.replace(
                              /^https?:\/\//,
                              ""
                            )}
                          </a>
                        </div>

                      </div>
                    )}

                    {/* =================================================
                        SOCIAL MEDIA
                    ================================================== */}

                    <div className="contact-social-section">

                      <div className="contact-divider">
                        <span />
                      </div>

                      <div className="contact-social-header">
                        <span>
                          Follow Me
                        </span>

                        <i
                          className="bi bi-arrow-right"
                          aria-hidden="true"
                        />
                      </div>

                      <div className="contact-social-list">
                        {socialMedia
                          .filter(
                            (social) =>
                              social.url
                          )
                          .map((social) => (
                            <a
                              key={social.name}
                              href={social.url!}
                              target="_blank"
                              rel="noopener noreferrer"
                              className="contact-social-link"
                              title={social.name}
                              aria-label={social.name}
                            >
                              <i
                                className={`bi ${social.icon}`}
                                aria-hidden="true"
                              />
                            </a>
                          ))}
                      </div>

                    </div>

                  </>
                )}

              </div>
            </div>

            {/* =================================================
                CONTACT FORM
            ================================================== */}

            <div className="contact-form-card">

              <div className="contact-card-top-line">
                <span />
              </div>

              <div className="contact-card-content">

                <div className="contact-section-heading">
                  <span className="contact-heading-icon">
                    <i
                      className="bi bi-send"
                      aria-hidden="true"
                    />
                  </span>

                  <div>
                    <span className="contact-heading-label">
                      SEND A MESSAGE
                    </span>

                    <h2>
                      Let&apos;s Talk
                    </h2>
                  </div>
                </div>

                <p className="contact-form-intro">
                  Tell me about your project, idea, or
                  collaboration. I&apos;ll get back to you
                  as soon as possible.
                </p>

                {/* =================================================
                    LOGIN REQUIRED
                ================================================== */}

                {!session && (
                  <div
                    className="contact-alert contact-alert-warning"
                    role="alert"
                  >
                    <div className="contact-alert-icon">
                      <i
                        className="bi bi-lock-fill"
                        aria-hidden="true"
                      />
                    </div>

                    <div className="contact-alert-content">

                      <strong>
                        Login Required
                      </strong>

                      <p>
                        Please sign in with your Google
                        account before using the contact form.
                      </p>

                      <a
                        href="/login"
                        className="contact-login-button"
                      >
                        <i
                          className="bi bi-google"
                          aria-hidden="true"
                        />

                        Login with Google
                      </a>

                    </div>
                  </div>
                )}

                {/* =================================================
                    CONTACT DISABLED
                ================================================== */}

                {session &&
                  contactActive === false && (
                    <div
                      className="contact-alert contact-alert-warning"
                      role="alert"
                    >
                      <div className="contact-alert-icon">
                        <i
                          className="bi bi-lock-fill"
                          aria-hidden="true"
                        />
                      </div>

                      <div className="contact-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 contact-alert-warning"
                      role="alert"
                    >
                      <div className="contact-alert-icon">
                        <i
                          className="bi bi-lock-fill"
                          aria-hidden="true"
                        />
                      </div>

                      <div className="contact-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 contact-alert-info"
                      role="alert"
                    >
                      <div className="contact-alert-icon">
                        <i
                          className="bi bi-info-circle"
                          aria-hidden="true"
                        />
                      </div>

                      <div className="contact-alert-content">

                        <strong>
                          Contact Form Available
                        </strong>

                        <p>
                          You can still use the contact
                          form{" "}
                          <span>
                            {remainingUses} times
                          </span>.
                        </p>

                      </div>
                    </div>
                  )}

                {/* =================================================
                    ERROR
                ================================================== */}

                {error && (
                  <div
                    className="contact-alert contact-alert-error"
                    role="alert"
                  >
                    <div className="contact-alert-icon">
                      <i
                        className="bi bi-exclamation-circle"
                        aria-hidden="true"
                      />
                    </div>

                    <div className="contact-alert-content">

                      <strong>
                        Unable to Send Message
                      </strong>

                      <p>
                        {error}
                      </p>

                    </div>
                  </div>
                )}

                {/* =================================================
                    FORM
                ================================================== */}

                <form onSubmit={handleSubmit}>

                  <fieldset
                    disabled={
                      FORM_FROZEN ||
                      loading
                    }
                    className="contact-fieldset"
                  >

                    {/* NAME */}

                    <div className="contact-field">
                      <label
                        htmlFor="contact-name"
                        className="contact-form-label"
                      >
                        Name
                      </label>

                      <div className="contact-input-wrapper">

                        <i
                          className="bi bi-person"
                          aria-hidden="true"
                        />

                        <input
                          id="contact-name"
                          type="text"
                          className="contact-input"
                          placeholder="Your name"
                          value={name}
                          readOnly
                          onChange={(e) =>
                            setName(
                              e.target.value
                            )
                          }
                          required
                        />

                      </div>
                    </div>

                    {/* EMAIL */}

                    <div className="contact-field">
                      <label
                        htmlFor="contact-email"
                        className="contact-form-label"
                      >
                        Email
                      </label>

                      <div className="contact-input-wrapper">

                        <i
                          className="bi bi-envelope"
                          aria-hidden="true"
                        />

                        <input
                          id="contact-email"
                          type="email"
                          className="contact-input"
                          placeholder="Your email"
                          value={email}
                          readOnly
                          required
                        />

                      </div>
                    </div>

                    {/* MESSAGE */}

                    <div className="contact-field">
                      <label
                        htmlFor="contact-message"
                        className="contact-form-label"
                      >
                        Message
                      </label>

                      <div className="contact-textarea-wrapper">

                        <i
                          className="bi bi-chat-left-text"
                          aria-hidden="true"
                        />

                        <textarea
                          id="contact-message"
                          className="contact-textarea"
                          rows={6}
                          placeholder="Tell me about your project or idea..."
                          value={message}
                          onChange={(e) =>
                            setMessage(
                              e.target.value
                            )
                          }
                          required
                        />

                      </div>
                    </div>

                    {/* BUTTON */}

                    <button
                      type="submit"
                      className="contact-submit"
                      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 contact-submit-arrow"
                            aria-hidden="true"
                          />
                        </>
                      )}
                    </button>

                  </fieldset>
                </form>

              </div>
            </div>

          </div>
        </div>
      </main>

      {/* ==========================================================
          SUCCESS MODAL
      =========================================================== */}

      {showSuccessModal && (
        <div
          className={`contact-modal-overlay ${
            animateSuccessModal
              ? "contact-modal-visible"
              : ""
          }`}
        >
          <div
            className="contact-success-modal"
            role="dialog"
            aria-modal="true"
            aria-labelledby="contact-success-title"
          >

            <div className="contact-success-icon">
              <i
                className="bi bi-check-lg"
                aria-hidden="true"
              />
            </div>

            <span className="contact-success-label">
              MESSAGE SENT
            </span>

            <h3 id="contact-success-title">
              Message Sent Successfully
            </h3>

            <p>
              Your message has been sent successfully.
            </p>

            <button
              type="button"
              className="contact-modal-button"
              onClick={() => {
                setAnimateSuccessModal(false);

                setTimeout(() => {
                  setShowSuccessModal(false);
                  window.location.reload();
                }, 250);
              }}
            >
              <span>
                Continue
              </span>

              <i
                className="bi bi-arrow-right"
                aria-hidden="true"
              />
            </button>

          </div>
        </div>
      )}

      {/* ==========================================================
          COMPONENT CSS
      =========================================================== */}

      <style>{`

        /* =====================================================
           PAGE
        ====================================================== */

        .contact-page {
          width: 100%;
          min-height: 100%;
          padding: 95px 20px;
          background: #ffffff;
          overflow: hidden;
        }

        .contact-container {
          width: 100%;
          max-width: 1200px;
          margin: 0 auto;
        }

        /* =====================================================
           HEADER
        ====================================================== */

        .contact-header {
          max-width: 820px;
          margin: 0 auto 55px;
          text-align: center;
        }

        .contact-label {
          display: flex;
          align-items: center;
          justify-content: center;
          gap: 12px;
          margin-bottom: 14px;
        }

        .contact-label-line {
          width: 30px;
          height: 1px;
          background: #198754;
          opacity: 0.55;
        }

        .contact-label-text {
          display: inline-flex;
          align-items: center;
          gap: 7px;
          color: #198754;
          font-size: 0.72rem;
          font-weight: 700;
          letter-spacing: 0.17em;
        }

        .contact-label-text i {
          font-size: 0.8rem;
        }

        .contact-title {
          margin: 0;
          color: #17221c;
          font-size: clamp(2rem, 4vw, 3rem);
          font-weight: 700;
          line-height: 1.15;
          letter-spacing: -0.035em;
        }

        .contact-title span {
          color: #198754;
        }

        /* =====================================================
           TITLE ANIMATED LINE
        ====================================================== */

        .contact-title-line {
          position: relative;
          width: 125px;
          height: 3px;
          margin: 18px auto 20px;
          overflow: hidden;
          border-radius: 999px;
          background: rgba(25, 135, 84, 0.13);
        }

        .contact-title-line span {
          position: absolute;
          top: 0;
          left: -55%;
          width: 55%;
          height: 100%;
          border-radius: 999px;

          background: linear-gradient(
            90deg,
            transparent,
            #198754,
            #73c69a,
            #4aa977,
            #198754,
            transparent
          );

          box-shadow:
            0 0 8px rgba(25, 135, 84, 0.38);

          animation:
            contactTitleLine
            2.8s linear infinite;
        }

        @keyframes contactTitleLine {
          0% {
            left: -55%;
          }

          100% {
            left: 100%;
          }
        }

        .contact-intro {
          max-width: 720px;
          margin: 0 auto;
          color: #68746d;
          font-size: 0.96rem;
          line-height: 1.85;
          text-align: justify;
          text-align-last: center;
        }

        /* =====================================================
           GRID
        ====================================================== */

        .contact-grid {
          display: grid;
          grid-template-columns:
            minmax(0, 0.88fr)
            minmax(0, 1.12fr);
          gap: 25px;
          align-items: stretch;
        }

        /* =====================================================
           CARDS
        ====================================================== */

        .contact-info-card,
        .contact-form-card {
          position: relative;
          min-width: 0;
          overflow: hidden;

          background: #ffffff;

          border: 1.5px solid
            rgba(25, 135, 84, 0.48);

          border-radius: 18px;

          box-shadow:
            0 10px 30px
              rgba(25, 50, 38, 0.065),
            0 0 0 1px
              rgba(25, 135, 84, 0.03);

          transition:
            border-color 0.3s ease,
            box-shadow 0.3s ease,
            transform 0.3s ease;
        }

        .contact-info-card:hover,
        .contact-form-card:hover {
          border-color: #198754;

          box-shadow:
            0 18px 40px
              rgba(25, 50, 38, 0.09),
            0 0 0 1px
              rgba(25, 135, 84, 0.05);
        }

        /* =====================================================
           CARD TOP ANIMATED LINE
        ====================================================== */

        .contact-card-top-line {
          position: relative;
          width: 100%;
          height: 3px;
          overflow: hidden;
          background: rgba(25, 135, 84, 0.14);
        }

        .contact-card-top-line span {
          position: absolute;
          top: 0;
          left: -35%;
          width: 35%;
          height: 100%;

          border-radius: 999px;

          background: linear-gradient(
            90deg,
            transparent,
            #198754,
            #73c69a,
            #4aa977,
            #198754,
            transparent
          );

          box-shadow:
            0 0 10px
              rgba(25, 135, 84, 0.45);

          animation:
            contactCardLine
            3s linear infinite;
        }

        @keyframes contactCardLine {
          0% {
            left: -35%;
          }

          100% {
            left: 100%;
          }
        }

        .contact-card-content {
          height: 100%;
          padding: 31px 30px 28px;
        }

        /* =====================================================
           SECTION HEADING
        ====================================================== */

        .contact-section-heading {
          display: flex;
          align-items: center;
          gap: 14px;
          margin-bottom: 23px;
        }

        .contact-heading-icon {
          flex-shrink: 0;

          width: 48px;
          height: 48px;

          display: flex;
          align-items: center;
          justify-content: center;

          color: #198754;

          background:
            rgba(25, 135, 84, 0.08);

          border: 1px solid
            rgba(25, 135, 84, 0.22);

          border-radius: 12px;

          font-size: 1.2rem;
        }

        .contact-heading-label {
          display: block;
          margin-bottom: 3px;

          color: #198754;

          font-size: 0.62rem;
          font-weight: 700;

          letter-spacing: 0.12em;
        }

        .contact-section-heading h2 {
          margin: 0;

          color: #17221c;

          font-size: 1.25rem;
          font-weight: 700;
          line-height: 1.35;
        }

        /* =====================================================
           DESCRIPTION
           CLEAN - NO SIDE LINE
        ====================================================== */

        .contact-description {
          margin: 0 0 28px;

          padding: 0;

          color: #68746d;

          font-size: 0.89rem;
          line-height: 1.82;

          text-align: justify;
          text-justify: inter-word;

          overflow-wrap: anywhere;
        }

        /* =====================================================
           CONTACT DETAIL
        ====================================================== */

        .contact-detail {
          display: flex;
          align-items: flex-start;
          gap: 13px;

          min-width: 0;

          margin-bottom: 19px;
          padding: 13px 0;

          border-bottom:
            1px solid
            rgba(25, 135, 84, 0.09);

          transition:
            transform 0.25s ease;
        }

        .contact-detail:last-of-type {
          margin-bottom: 0;
        }

        .contact-detail:hover {
          transform: translateX(3px);
        }

        .contact-detail-icon {
          flex-shrink: 0;

          width: 43px;
          height: 43px;

          display: flex;
          align-items: center;
          justify-content: center;

          color: #198754;

          background:
            rgba(25, 135, 84, 0.075);

          border: 1px solid
            rgba(25, 135, 84, 0.17);

          border-radius: 11px;

          font-size: 1rem;
        }

        .contact-detail-content {
          min-width: 0;
          padding-top: 2px;
        }

        .contact-detail-label {
          display: block;
          margin-bottom: 3px;

          color: #8a948e;

          font-size: 0.68rem;
          font-weight: 600;

          letter-spacing: 0.03em;
        }

        .contact-detail-value {
          display: block;

          max-width: 100%;

          color: #27332d;

          font-size: 0.86rem;
          font-weight: 600;

          line-height: 1.5;

          text-decoration: none;

          overflow-wrap: anywhere;

          transition:
            color 0.25s ease;
        }

        a.contact-detail-value:hover {
          color: #198754;
        }

        /* =====================================================
           SOCIAL
        ====================================================== */

        .contact-social-section {
          margin-top: 24px;
        }

        .contact-divider {
          position: relative;

          width: 100%;
          height: 1px;

          margin-bottom: 19px;

          overflow: hidden;

          background:
            rgba(25, 135, 84, 0.12);
        }

        .contact-divider span {
          position: absolute;

          top: 0;
          left: -30%;

          width: 30%;
          height: 100%;

          background: #198754;

          animation:
            contactDividerLine
            3.5s linear infinite;
        }

        @keyframes contactDividerLine {
          0% {
            left: -30%;
          }

          100% {
            left: 100%;
          }
        }

        .contact-social-header {
          display: flex;
          align-items: center;
          justify-content: space-between;

          margin-bottom: 12px;

          color: #17221c;

          font-size: 0.78rem;
          font-weight: 700;
        }

        .contact-social-header i {
          color: #198754;
          font-size: 0.75rem;
        }

        .contact-social-list {
          display: flex;
          align-items: center;
          flex-wrap: wrap;
          gap: 8px;
        }

        .contact-social-link {
          width: 37px;
          height: 37px;

          display: flex;
          align-items: center;
          justify-content: center;

          color: #198754;

          background: #ffffff;

          border: 1px solid
            rgba(25, 135, 84, 0.25);

          border-radius: 10px;

          font-size: 0.88rem;

          text-decoration: none;

          transition:
            background 0.25s ease,
            color 0.25s ease,
            border-color 0.25s ease,
            transform 0.25s ease;
        }

        .contact-social-link:hover {
          background: #198754;
          color: #ffffff;

          border-color: #198754;

          transform: translateY(-2px);
        }

        /* =====================================================
           LOADING
        ====================================================== */

        .contact-loading {
          position: relative;

          min-height: 130px;

          overflow: hidden;

          background: #fafcfb;

          border: 1px solid
            rgba(25, 135, 84, 0.15);

          border-radius: 12px;
        }

        .contact-loading-line {
          position: relative;

          width: 100%;
          height: 2px;

          overflow: hidden;

          background:
            rgba(25, 135, 84, 0.10);
        }

        .contact-loading-line span {
          position: absolute;

          top: 0;
          left: -40%;

          width: 40%;
          height: 100%;

          background: linear-gradient(
            90deg,
            transparent,
            #198754,
            #73c69a,
            transparent
          );

          animation:
            contactLoadingLine
            2.4s linear infinite;
        }

        @keyframes contactLoadingLine {
          0% {
            left: -40%;
          }

          100% {
            left: 100%;
          }
        }

        .contact-loading-content {
          min-height: 128px;

          display: flex;
          flex-direction: column;
          align-items: center;
          justify-content: center;
        }

        .contact-loading-content p {
          margin: 11px 0 0;

          color: #7b8580;

          font-size: 0.78rem;
        }

        /* =====================================================
           FORM INTRO
        ====================================================== */

        .contact-form-intro {
          margin: -7px 0 25px;

          color: #68746d;

          font-size: 0.88rem;
          line-height: 1.75;

          text-align: justify;
        }

        /* =====================================================
           ALERT
        ====================================================== */

        .contact-alert {
          display: flex;
          align-items: flex-start;
          gap: 12px;

          margin-bottom: 21px;
          padding: 14px;

          border-radius: 12px;

          border: 1px solid;
        }

        .contact-alert-warning {
          background:
            rgba(255, 193, 7, 0.065);

          border-color:
            rgba(255, 193, 7, 0.25);
        }

        .contact-alert-info {
          background:
            rgba(13, 202, 240, 0.055);

          border-color:
            rgba(13, 202, 240, 0.20);
        }

        .contact-alert-error {
          background:
            rgba(220, 53, 69, 0.055);

          border-color:
            rgba(220, 53, 69, 0.20);
        }

        .contact-alert-icon {
          flex-shrink: 0;

          width: 35px;
          height: 35px;

          display: flex;
          align-items: center;
          justify-content: center;

          border-radius: 9px;

          background:
            rgba(255, 255, 255, 0.7);

          font-size: 0.9rem;
        }

        .contact-alert-warning
        .contact-alert-icon {
          color: #b58105;
        }

        .contact-alert-info
        .contact-alert-icon {
          color: #138496;
        }

        .contact-alert-error
        .contact-alert-icon {
          color: #c82333;
        }

        .contact-alert-content {
          min-width: 0;
          flex: 1;
        }

        .contact-alert-content strong {
          display: block;

          margin-bottom: 4px;

          color: #27332d;

          font-size: 0.82rem;
        }

        .contact-alert-content p {
          margin: 0;

          color: #68746d;

          font-size: 0.76rem;
          line-height: 1.65;

          text-align: justify;

          overflow-wrap: anywhere;
        }

        .contact-alert-content p span {
          color: #198754;
          font-weight: 700;
        }

        /* =====================================================
           LOGIN BUTTON
        ====================================================== */

        .contact-login-button {
          display: inline-flex;
          align-items: center;
          gap: 7px;

          margin-top: 12px;

          padding: 8px 12px;

          color: #ffffff;
          background: #198754;

          border-radius: 8px;

          font-size: 0.72rem;
          font-weight: 600;

          text-decoration: none;

          transition:
            background 0.25s ease,
            transform 0.25s ease;
        }

        .contact-login-button:hover {
          color: #ffffff;
          background: #157347;

          transform: translateY(-1px);
        }

        /* =====================================================
           FIELDSET
        ====================================================== */

        .contact-fieldset {
          min-width: 0;

          margin: 0;
          padding: 0;

          border: none;
        }

        /* =====================================================
           FORM FIELD
        ====================================================== */

        .contact-field {
          margin-bottom: 18px;
        }

        .contact-form-label {
          display: block;

          margin-bottom: 7px;

          color: #27332d;

          font-size: 0.76rem;
          font-weight: 700;

          letter-spacing: 0.01em;
        }

        .contact-input-wrapper,
        .contact-textarea-wrapper {
          position: relative;
        }

        .contact-input-wrapper > i,
        .contact-textarea-wrapper > i {
          position: absolute;

          top: 50%;
          left: 15px;

          z-index: 2;

          color: #8a948e;

          font-size: 0.88rem;

          transform:
            translateY(-50%);

          pointer-events: none;

          transition:
            color 0.25s ease;
        }

        .contact-textarea-wrapper > i {
          top: 17px;
          transform: none;
        }

        .contact-input-wrapper:focus-within > i,
        .contact-textarea-wrapper:focus-within > i {
          color: #198754;
        }

        .contact-input,
        .contact-textarea {
          display: block;

          width: 100%;

          color: #27332d;
          background: #ffffff;

          border: 1px solid
            rgba(25, 135, 84, 0.20);

          border-radius: 10px;

          outline: none;

          font-size: 0.85rem;
          line-height: 1.5;

          transition:
            border-color 0.25s ease,
            box-shadow 0.25s ease,
            background 0.25s ease;
        }

        .contact-input {
          height: 47px;

          padding:
            0 14px 0 42px;
        }

        .contact-textarea {
          min-height: 145px;

          padding:
            13px 14px 13px 42px;

          resize: vertical;
        }

        .contact-input::placeholder,
        .contact-textarea::placeholder {
          color: #a1aaa5;
        }

        .contact-input:focus,
        .contact-textarea:focus {
          background: #ffffff;

          border-color: #198754;

          box-shadow:
            0 0 0 3px
              rgba(25, 135, 84, 0.09);
        }

        .contact-input[readonly] {
          background: #f8faf9;
          cursor: default;
        }

        .contact-input:disabled,
        .contact-textarea:disabled {
          opacity: 0.72;
        }

        /* =====================================================
           SUBMIT BUTTON
        ====================================================== */

        .contact-submit {
          display: inline-flex;

          align-items: center;
          justify-content: center;

          gap: 9px;

          min-height: 45px;

          margin-top: 4px;

          padding: 0 18px;

          color: #ffffff;
          background: #198754;

          border: 1px solid #198754;
          border-radius: 9px;

          font-size: 0.78rem;
          font-weight: 700;

          box-shadow:
            0 7px 18px
              rgba(25, 135, 84, 0.16);

          transition:
            background 0.25s ease,
            border-color 0.25s ease,
            box-shadow 0.25s ease,
            transform 0.25s ease;
        }

        .contact-submit:hover:not(:disabled) {
          background: #157347;
          border-color: #157347;

          box-shadow:
            0 10px 22px
              rgba(25, 135, 84, 0.20);

          transform: translateY(-2px);
        }

        .contact-submit:disabled {
          opacity: 0.72;
          cursor: not-allowed;
        }

        .contact-submit-arrow {
          margin-left: 3px;
          font-size: 0.72rem;
        }

        /* =====================================================
           SUCCESS MODAL
        ====================================================== */

        .contact-modal-overlay {
          position: fixed;
          inset: 0;

          z-index: 9999;

          display: flex;
          align-items: center;
          justify-content: center;

          padding: 20px;

          background:
            rgba(12, 24, 18, 0.55);

          backdrop-filter: blur(7px);

          opacity: 0;

          transition:
            opacity 0.3s ease;
        }

        .contact-modal-visible {
          opacity: 1;
        }

        .contact-success-modal {
          position: relative;

          width: 100%;
          max-width: 410px;

          padding: 35px 30px 29px;

          text-align: center;

          background: #ffffff;

          border:
            1px solid
            rgba(25, 135, 84, 0.25);

          border-radius: 18px;

          box-shadow:
            0 25px 70px
              rgba(0, 0, 0, 0.18);

          transform:
            translateY(20px)
            scale(0.97);

          transition:
            transform 0.35s ease,
            opacity 0.35s ease;

          opacity: 0;
        }

        .contact-modal-visible
        .contact-success-modal {
          transform:
            translateY(0)
            scale(1);

          opacity: 1;
        }

        .contact-success-icon {
          width: 68px;
          height: 68px;

          display: flex;
          align-items: center;
          justify-content: center;

          margin: 0 auto 17px;

          color: #198754;

          background:
            rgba(25, 135, 84, 0.09);

          border:
            1px solid
            rgba(25, 135, 84, 0.20);

          border-radius: 50%;

          font-size: 2rem;

          box-shadow:
            0 0 0 7px
              rgba(25, 135, 84, 0.035);
        }

        .contact-success-label {
          display: block;

          margin-bottom: 6px;

          color: #198754;

          font-size: 0.62rem;
          font-weight: 700;

          letter-spacing: 0.14em;
        }

        .contact-success-modal h3 {
          margin: 0 0 9px;

          color: #17221c;

          font-size: 1.2rem;
          font-weight: 700;
        }

        .contact-success-modal p {
          margin: 0 0 23px;

          color: #68746d;

          font-size: 0.82rem;
          line-height: 1.65;
        }

        .contact-modal-button {
          display: inline-flex;

          align-items: center;
          justify-content: center;

          gap: 9px;

          min-width: 120px;
          min-height: 41px;

          padding: 0 17px;

          color: #ffffff;
          background: #198754;

          border: 1px solid #198754;
          border-radius: 9px;

          font-size: 0.75rem;
          font-weight: 700;

          transition:
            background 0.25s ease,
            transform 0.25s ease;
        }

        .contact-modal-button:hover {
          background: #157347;

          transform:
            translateY(-1px);
        }

        .contact-modal-button i {
          font-size: 0.72rem;
        }

        /* =====================================================
           TABLET
        ====================================================== */

        @media (max-width: 991.98px) {

          .contact-page {
            padding: 75px 18px;
          }

          .contact-header {
            margin-bottom: 45px;
          }

          .contact-grid {
            grid-template-columns: 1fr;
            gap: 22px;
          }

          .contact-card-content {
            padding: 28px 25px 25px;
          }

          .contact-info-card,
          .contact-form-card {
            width: 100%;
          }
        }

        /* =====================================================
           MOBILE
        ====================================================== */

        @media (max-width: 575.98px) {

          .contact-page {
            padding: 60px 15px;
          }

          .contact-header {
            margin-bottom: 38px;
          }

          .contact-label-text {
            font-size: 0.66rem;
            letter-spacing: 0.13em;
          }

          .contact-label-line {
            width: 21px;
          }

          .contact-title {
            font-size: 1.9rem;
          }

          .contact-title-line {
            width: 105px;

            margin-top: 15px;
            margin-bottom: 17px;
          }

          .contact-intro {
            font-size: 0.87rem;
            line-height: 1.76;

            text-align: justify;
            text-align-last: center;
          }

          .contact-grid {
            gap: 18px;
          }

          .contact-info-card,
          .contact-form-card {
            border-radius: 15px;
          }

          .contact-card-content {
            padding: 24px 19px 20px;
          }

          .contact-section-heading {
            gap: 11px;
            margin-bottom: 19px;
          }

          .contact-heading-icon {
            width: 44px;
            height: 44px;

            border-radius: 11px;

            font-size: 1.05rem;
          }

          .contact-heading-label {
            font-size: 0.57rem;
          }

          .contact-section-heading h2 {
            font-size: 1.12rem;
          }

          /* DESCRIPTION TANPA GARIS */

          .contact-description {
            padding: 0;

            margin-bottom: 23px;

            font-size: 0.84rem;
            line-height: 1.76;

            text-align: justify;
          }

          .contact-detail {
            gap: 11px;

            margin-bottom: 14px;
            padding: 11px 0;
          }

          .contact-detail-icon {
            width: 39px;
            height: 39px;

            border-radius: 10px;

            font-size: 0.88rem;
          }

          .contact-detail-label {
            font-size: 0.63rem;
          }

          .contact-detail-value {
            font-size: 0.8rem;
          }

          .contact-social-section {
            margin-top: 19px;
          }

          .contact-social-link {
            width: 35px;
            height: 35px;

            border-radius: 9px;

            font-size: 0.82rem;
          }

          .contact-form-intro {
            font-size: 0.83rem;
            line-height: 1.72;

            text-align: justify;
          }

          .contact-alert {
            gap: 10px;
            padding: 12px;
          }

          .contact-alert-icon {
            width: 32px;
            height: 32px;

            font-size: 0.82rem;
          }

          .contact-alert-content strong {
            font-size: 0.77rem;
          }

          .contact-alert-content p {
            font-size: 0.71rem;
            line-height: 1.6;
          }

          .contact-login-button {
            padding: 7px 10px;
            font-size: 0.68rem;
          }

          .contact-form-label {
            font-size: 0.72rem;
          }

          .contact-input {
            height: 45px;

            padding-left: 39px;

            font-size: 0.81rem;
          }

          .contact-textarea {
            min-height: 135px;

            padding-left: 39px;

            font-size: 0.81rem;
          }

          .contact-submit {
            width: 100%;
            min-height: 44px;
          }

          .contact-success-modal {
            padding: 30px 21px 24px;
            border-radius: 15px;
          }

          .contact-success-icon {
            width: 61px;
            height: 61px;

            font-size: 1.8rem;
          }

          .contact-success-modal h3 {
            font-size: 1.08rem;
          }

          .contact-success-modal p {
            font-size: 0.76rem;
          }
        }

        /* =====================================================
           VERY SMALL MOBILE
        ====================================================== */

        @media (max-width: 360px) {

          .contact-page {
            padding: 50px 12px;
          }

          .contact-title {
            font-size: 1.7rem;
          }

          .contact-intro {
            font-size: 0.82rem;
          }

          .contact-card-content {
            padding: 22px 16px 18px;
          }

          .contact-section-heading h2 {
            font-size: 1.05rem;
          }

          .contact-description {
            padding: 0;
            font-size: 0.81rem;
          }

          .contact-detail-value {
            font-size: 0.76rem;
          }

          .contact-social-link {
            width: 33px;
            height: 33px;
          }
        }

        /* =====================================================
           REDUCED MOTION
        ====================================================== */

        @media (prefers-reduced-motion: reduce) {

          .contact-title-line span,
          .contact-card-top-line span,
          .contact-divider span,
          .contact-loading-line span {
            animation: none !important;
          }

          .contact-info-card,
          .contact-form-card,
          .contact-detail,
          .contact-social-link,
          .contact-login-button,
          .contact-submit,
          .contact-modal-overlay,
          .contact-success-modal,
          .contact-modal-button {
            transition: none !important;
          }
        }

      `}</style>
    </>
  );
}