"use client";

import { useEffect, useState } from "react";
import Link from "next/link";
import { useParams } from "next/navigation";

import Navbar from "@/components/Navbar";
import Footer from "@/components/Footer";

type ArticleImage = {
  id: number;
  image: string;
  articleId: number;
  createdAt: string;
};

type Article = {
  id: number;
  title: string;
  slug: string;
  excerpt: string | null;
  content: string;
  thumbnail: string | null;
  category: string | null;
  published: boolean;
  publishedAt: string | null;

  author: {
    id: string;
    name: string | null;
    email: string | null;
    image: string | null;
  } | null;

  articleimage: ArticleImage[];
};

export default function ReadArticlePage() {
  const params = useParams();
  const slug = params.slug as string;

  const [article, setArticle] = useState<Article | null>(null);
  const [loading, setLoading] = useState(true);
  const [notFound, setNotFound] = useState(false);

  const [currentImage, setCurrentImage] = useState(0);
  const [showLightbox, setShowLightbox] = useState(false);

  useEffect(() => {
    const loadArticle = async () => {
      try {
        const response = await fetch("/api/articles", {
          cache: "no-store",
        });

        const result = await response.json();

        if (!response.ok || !result.success) {
          setNotFound(true);
          return;
        }

        const foundArticle = result.data.find(
          (item: Article) =>
            item.slug === slug &&
            item.published === true
        );

        if (!foundArticle) {
          setNotFound(true);
          return;
        }

        setArticle(foundArticle);
      } catch (error) {
        console.error("LOAD ARTICLE ERROR:", error);
        setNotFound(true);
      } finally {
        setLoading(false);
      }
    };

    if (slug) {
      loadArticle();
    }
  }, [slug]);

  const images =
    article?.articleimage &&
    article.articleimage.length > 0
      ? article.articleimage.map((item) => item.image)
      : article?.thumbnail
      ? [article.thumbnail]
      : [];

  const nextImage = () => {
    if (images.length <= 1) return;

    setCurrentImage((prev) =>
      prev === images.length - 1 ? 0 : prev + 1
    );
  };

  const previousImage = () => {
    if (images.length <= 1) return;

    setCurrentImage((prev) =>
      prev === 0 ? images.length - 1 : prev - 1
    );
  };

  const formatDate = (date: string | null) => {
    if (!date) return "";

    return new Date(date).toLocaleDateString("en-US", {
      year: "numeric",
      month: "long",
      day: "numeric",
    });
  };

  /*
  |--------------------------------------------------------------------------
  | LOADING
  |--------------------------------------------------------------------------
  */

  if (loading) {
    return (
      <>
        <Navbar />

        <main className="article-page">
          <div className="article-background-orb article-orb-one"></div>
          <div className="article-background-orb article-orb-two"></div>

          <div className="container">
            <div className="article-loading-card">
              <div className="article-shimmer article-loading-badge"></div>

              <div className="article-shimmer article-loading-title"></div>

              <div className="article-shimmer article-loading-title-small"></div>

              <div className="article-shimmer article-loading-excerpt"></div>

              <div className="article-shimmer article-loading-image"></div>

              <div className="article-shimmer article-loading-line"></div>

              <div className="article-shimmer article-loading-line medium"></div>

              <div className="article-shimmer article-loading-line short"></div>
            </div>
          </div>
        </main>

        <Footer />

        <style>{`
          .article-page {
            position: relative;
            overflow: hidden;
            padding: 115px 0 75px;
            background:
              radial-gradient(
                circle at 8% 8%,
                rgba(25, 135, 84, 0.08),
                transparent 28%
              ),
              radial-gradient(
                circle at 92% 20%,
                rgba(13, 110, 253, 0.045),
                transparent 26%
              ),
              #ffffff;
          }

          .article-background-orb {
            position: absolute;
            border-radius: 50%;
            pointer-events: none;
            filter: blur(2px);
            opacity: 0.6;
            animation: articleOrbFloat 12s ease-in-out infinite;
          }

          .article-orb-one {
            width: 180px;
            height: 180px;
            left: -80px;
            top: 240px;
            background: rgba(25, 135, 84, 0.07);
          }

          .article-orb-two {
            width: 150px;
            height: 150px;
            right: -60px;
            top: 600px;
            background: rgba(13, 110, 253, 0.045);
            animation-delay: -5s;
          }

          @keyframes articleOrbFloat {
            0%,
            100% {
              transform: translate3d(0, 0, 0);
            }

            50% {
              transform: translate3d(20px, -25px, 0);
            }
          }

          .article-loading-card {
            position: relative;
            max-width: 1100px;
            margin: 0 auto;
            padding: 45px;
            border-radius: 26px;
            background: #ffffff;

            /* SMOOTH GREEN BORDER */
            border: 1px solid rgba(25, 135, 84, 0.38);

            box-shadow:
              0 20px 60px rgba(0, 0, 0, 0.07),
              0 0 0 1px rgba(25, 135, 84, 0.04);

            overflow: hidden;
          }

          .article-loading-card::before {
            content: "";
            position: absolute;
            top: 0;
            left: -45%;
            width: 45%;
            height: 2px;
            background:
              linear-gradient(
                90deg,
                transparent,
                #198754,
                #42b883,
                #198754,
                transparent
              );
            animation: articleLoadingLine 3s linear infinite;
          }

          @keyframes articleLoadingLine {
            0% {
              left: -45%;
            }

            100% {
              left: 100%;
            }
          }

          .article-shimmer {
            background:
              linear-gradient(
                90deg,
                #f1f3f5 25%,
                #e6e9ec 50%,
                #f1f3f5 75%
              );
            background-size: 200% 100%;
            animation: articleShimmer 1.5s linear infinite;
          }

          @keyframes articleShimmer {
            0% {
              background-position: 200% 0;
            }

            100% {
              background-position: -200% 0;
            }
          }

          .article-loading-badge {
            width: 125px;
            height: 30px;
            border-radius: 999px;
            margin: 0 auto 28px;
          }

          .article-loading-title {
            width: 82%;
            height: 46px;
            border-radius: 10px;
            margin: 0 auto 14px;
          }

          .article-loading-title-small {
            width: 60%;
            height: 46px;
            border-radius: 10px;
            margin: 0 auto 24px;
          }

          .article-loading-excerpt {
            width: 72%;
            height: 22px;
            border-radius: 8px;
            margin: 0 auto 38px;
          }

          .article-loading-image {
            width: 100%;
            height: 450px;
            border-radius: 20px;
            margin-bottom: 40px;
          }

          .article-loading-line {
            width: 95%;
            height: 18px;
            border-radius: 8px;
            margin-bottom: 15px;
          }

          .article-loading-line.medium {
            width: 88%;
          }

          .article-loading-line.short {
            width: 70%;
          }

          @media (max-width: 768px) {
            .article-page {
              padding: 95px 0 55px;
            }

            .article-loading-card {
              padding: 28px 20px;
              border-radius: 20px;
              border-width: 1px;
            }

            .article-loading-image {
              height: 300px;
            }
          }

          @media (max-width: 576px) {
            .article-loading-card {
              padding: 24px 16px;
              border-width: 1px;
            }

            .article-loading-title {
              width: 100%;
            }

            .article-loading-title-small {
              width: 78%;
            }

            .article-loading-excerpt {
              width: 90%;
            }

            .article-loading-image {
              height: 240px;
            }
          }

          @media (prefers-reduced-motion: reduce) {
            .article-background-orb,
            .article-shimmer,
            .article-loading-card::before {
              animation: none !important;
            }
          }
        `}</style>
      </>
    );
  }

  /*
  |--------------------------------------------------------------------------
  | NOT FOUND
  |--------------------------------------------------------------------------
  */

  if (notFound || !article) {
    return (
      <>
        <Navbar />

        <main className="article-page article-not-found-page">
          <div className="article-background-orb article-orb-one"></div>
          <div className="article-background-orb article-orb-two"></div>

          <div className="container">
            <div className="article-not-found-card">
              <div className="article-not-found-icon">
                <i className="bi bi-file-earmark-text"></i>
              </div>

              <div className="article-eyebrow">
                <span className="article-eyebrow-dot"></span>
                ARTICLE
              </div>

              <h1>Article Not Found</h1>

              <p>
                The article you are looking for may have been
                removed, unpublished, or the URL may be incorrect.
              </p>

              <Link
                href="/blog"
                className="article-primary-button"
              >
                <span className="article-button-icon">
                  <i className="bi bi-arrow-left"></i>
                </span>

                <span>Back to Articles</span>

                <span className="article-button-arrow">
                  <i className="bi bi-arrow-right"></i>
                </span>
              </Link>
            </div>
          </div>
        </main>

        <Footer />

        <style>{`
          .article-page {
            position: relative;
            overflow: hidden;
            padding: 115px 0 75px;
            background:
              radial-gradient(
                circle at 8% 8%,
                rgba(25, 135, 84, 0.08),
                transparent 28%
              ),
              radial-gradient(
                circle at 92% 20%,
                rgba(13, 110, 253, 0.045),
                transparent 26%
              ),
              #ffffff;
          }

          .article-background-orb {
            position: absolute;
            border-radius: 50%;
            pointer-events: none;
            filter: blur(2px);
            opacity: 0.6;
            animation: articleOrbFloat 12s ease-in-out infinite;
          }

          .article-orb-one {
            width: 180px;
            height: 180px;
            left: -80px;
            top: 240px;
            background: rgba(25, 135, 84, 0.07);
          }

          .article-orb-two {
            width: 150px;
            height: 150px;
            right: -60px;
            top: 600px;
            background: rgba(13, 110, 253, 0.045);
            animation-delay: -5s;
          }

          @keyframes articleOrbFloat {
            0%,
            100% {
              transform: translate3d(0, 0, 0);
            }

            50% {
              transform: translate3d(20px, -25px, 0);
            }
          }

          .article-not-found-page {
            min-height: 70vh;
            display: flex;
            align-items: center;
          }

          .article-not-found-card {
            position: relative;
            max-width: 680px;
            margin: 0 auto;
            padding: 55px 45px;
            text-align: center;
            background: #ffffff;

            /* SMOOTH GREEN BORDER */
            border: 1px solid rgba(25, 135, 84, 0.42);

            border-radius: 26px;

            box-shadow:
              0 20px 60px rgba(0, 0, 0, 0.07),
              0 0 0 1px rgba(25, 135, 84, 0.04);

            overflow: hidden;
          }

          .article-not-found-card::before {
            content: "";
            position: absolute;
            top: 0;
            left: -45%;
            width: 45%;
            height: 2px;
            background:
              linear-gradient(
                90deg,
                transparent,
                #198754,
                #42b883,
                #198754,
                transparent
              );
            animation: articleTopLine 3.5s linear infinite;
          }

          .article-not-found-icon {
            width: 90px;
            height: 90px;
            margin: 0 auto 24px;
            display: flex;
            align-items: center;
            justify-content: center;
            border-radius: 50%;
            color: #198754;
            background: rgba(25, 135, 84, 0.09);
            font-size: 2.3rem;
            animation: articleIconFloat 4s ease-in-out infinite;
          }

          @keyframes articleIconFloat {
            0%,
            100% {
              transform: translateY(0);
            }

            50% {
              transform: translateY(-7px);
            }
          }

          .article-eyebrow {
            display: inline-flex;
            align-items: center;
            justify-content: center;
            gap: 8px;
            color: #198754;
            font-size: 0.76rem;
            font-weight: 700;
            letter-spacing: 0.16em;
            margin-bottom: 14px;
          }

          .article-eyebrow-dot {
            width: 7px;
            height: 7px;
            border-radius: 50%;
            background: #198754;
            box-shadow:
              0 0 0 0
              rgba(25, 135, 84, 0.4);
            animation: articleDotPulse 2s infinite;
          }

          @keyframes articleDotPulse {
            0% {
              box-shadow:
                0 0 0 0
                rgba(25, 135, 84, 0.4);
            }

            70% {
              box-shadow:
                0 0 0 8px
                rgba(25, 135, 84, 0);
            }

            100% {
              box-shadow:
                0 0 0 0
                rgba(25, 135, 84, 0);
            }
          }

          .article-not-found-card h1 {
            font-size: clamp(2rem, 5vw, 3rem);
            font-weight: 800;
            color: #212529;
            margin-bottom: 18px;
          }

          .article-not-found-card p {
            max-width: 560px;
            margin: 0 auto 30px;
            color: #6c757d;
            line-height: 1.8;
            text-align: justify;
          }

          .article-primary-button {
            position: relative;
            display: inline-flex;
            align-items: center;
            justify-content: center;
            gap: 12px;
            min-width: 230px;
            min-height: 52px;
            padding: 9px 17px 9px 10px;
            border: 1px solid rgba(25, 135, 84, 0.2);
            border-radius: 14px;
            background: linear-gradient(
              135deg,
              #198754,
              #157347
            );
            color: #ffffff;
            text-decoration: none;
            font-size: 0.92rem;
            font-weight: 700;
            box-shadow:
              0 10px 25px rgba(25, 135, 84, 0.2);
            transition:
              transform 0.3s ease,
              box-shadow 0.3s ease,
              background 0.3s ease;
            overflow: hidden;
          }

          .article-primary-button::before {
            content: "";
            position: absolute;
            inset: 0;
            background:
              linear-gradient(
                110deg,
                transparent 25%,
                rgba(255, 255, 255, 0.22) 50%,
                transparent 75%
              );
            transform: translateX(-120%);
            transition: transform 0.65s ease;
          }

          .article-primary-button:hover {
            color: #ffffff;
            transform: translateY(-3px);
            box-shadow:
              0 15px 32px rgba(25, 135, 84, 0.28);
          }

          .article-primary-button:hover::before {
            transform: translateX(120%);
          }

          .article-button-icon,
          .article-button-arrow {
            position: relative;
            z-index: 1;
            display: flex;
            align-items: center;
            justify-content: center;
          }

          .article-button-icon {
            width: 34px;
            height: 34px;
            flex: 0 0 34px;
            border-radius: 10px;
            background: rgba(255, 255, 255, 0.14);
          }

          .article-button-arrow {
            margin-left: auto;
            transition: transform 0.3s ease;
          }

          .article-primary-button:hover
            .article-button-arrow {
            transform: translateX(4px);
          }

          @media (max-width: 768px) {
            .article-page {
              padding: 95px 0 55px;
            }

            .article-not-found-card {
              padding: 40px 24px;
              border-width: 1px;
            }
          }
        `}</style>
      </>
    );
  }

  /*
  |--------------------------------------------------------------------------
  | ARTICLE PAGE
  |--------------------------------------------------------------------------
  */

  return (
    <>
      <Navbar />

      <main className="article-page">
        <div className="article-background-orb article-orb-one"></div>
        <div className="article-background-orb article-orb-two"></div>
        <div className="article-background-orb article-orb-three"></div>

        <div className="container">
          <article className="article-shell">
            <div className="article-shell-line"></div>

            <header className="article-header">
              <div className="article-eyebrow">
                <span className="article-eyebrow-dot"></span>
                ARTICLE INSIGHT
              </div>

              <div className="article-meta">
  {article.category && (
    <span className="article-category">
      <i className="bi bi-tag-fill"></i>
      {article.category}
    </span>
  )}

  {article.publishedAt && (
    <span className="article-date">
      <i className="bi bi-calendar3"></i>
      {formatDate(article.publishedAt)}
    </span>
  )}

  {article.author?.name && (
    <span className="article-author">
      <i className="bi bi-person-circle"></i>
      {article.author.name}
    </span>
  )}
</div>

              <h1 className="article-title">
                {article.title}
              </h1>

              {article.excerpt && (
                <p className="article-excerpt">
                  {article.excerpt}
                </p>
              )}
            </header>

            {images.length > 0 && (
              <section
                className="article-media-section"
                onClick={() => setShowLightbox(true)}
              >
                <div className="article-media-frame">
                  <div className="article-media-glow"></div>

                  <img
                    src={images[currentImage]}
                    alt={article.title}
                    className="article-main-image"
                  />

                  <div className="article-image-overlay">
                    <span>
                      <i className="bi bi-arrows-fullscreen"></i>
                      View Fullscreen
                    </span>
                  </div>

                  {images.length > 1 && (
                    <>
                      <button
                        type="button"
                        className="article-image-nav article-image-prev"
                        onClick={(e) => {
                          e.stopPropagation();
                          previousImage();
                        }}
                        aria-label="Previous image"
                      >
                        <i className="bi bi-chevron-left"></i>
                      </button>

                      <button
                        type="button"
                        className="article-image-nav article-image-next"
                        onClick={(e) => {
                          e.stopPropagation();
                          nextImage();
                        }}
                        aria-label="Next image"
                      >
                        <i className="bi bi-chevron-right"></i>
                      </button>

                      <div className="article-image-count">
                        <i className="bi bi-images me-1"></i>
                        {currentImage + 1} / {images.length}
                      </div>
                    </>
                  )}
                </div>

                {images.length > 1 && (
                  <div className="article-dots">
                    {images.map((image, index) => (
                      <button
                        key={`${image}-${index}`}
                        type="button"
                        onClick={(e) => {
                          e.stopPropagation();
                          setCurrentImage(index);
                        }}
                        className={`article-dot ${
                          index === currentImage
                            ? "active"
                            : ""
                        }`}
                        aria-label={`View image ${
                          index + 1
                        }`}
                      />
                    ))}
                  </div>
                )}
              </section>
            )}

            {/* Article Content */}
            <section className="article-content-section">
              <div className="article-content-card">
                <div className="article-content-line"></div>

                <div className="article-content-heading">
                  <div className="article-content-icon">
                    <i className="bi bi-journal-richtext"></i>
                  </div>

                  <div>
                    <span className="article-content-label">
                      ARTICLE CONTENT
                    </span>

                    <h2>Read the Full Story</h2>
                  </div>
                </div>

                <div
                  className="article-content"
                  dangerouslySetInnerHTML={{
                    __html: article.content,
                  }}
                />
              </div>
            </section>

            {/* Article Footer */}
            <section className="article-ending">
              <div className="article-ending-icon">
                <i className="bi bi-journal-check"></i>
              </div>

              <div className="article-ending-eyebrow">
                THANK YOU FOR READING
              </div>

              <h2>Thanks for Reading</h2>

              <p>
                We hope this article provides useful insights
                and information. Explore more articles and
                discover other technology, engineering, and
                digital solution insights from GloVaTech.
              </p>
            </section>
          </article>
        </div>
      </main>

      {/* Lightbox */}
      {showLightbox && images.length > 0 && (
        <div
          className="article-lightbox"
          onClick={() => setShowLightbox(false)}
        >
          <button
            type="button"
            className="article-lightbox-close"
            onClick={() => setShowLightbox(false)}
            aria-label="Close"
          >
            <i className="bi bi-x-lg"></i>
          </button>

          {images.length > 1 && (
            <button
              type="button"
              className="article-lightbox-nav article-lightbox-prev"
              onClick={(e) => {
                e.stopPropagation();
                previousImage();
              }}
              aria-label="Previous image"
            >
              <i className="bi bi-chevron-left"></i>
            </button>
          )}

          <img
            key={images[currentImage]}
            src={images[currentImage]}
            alt={article.title}
            className="article-lightbox-image"
            onClick={(e) => e.stopPropagation()}
          />

          {images.length > 1 && (
            <button
              type="button"
              className="article-lightbox-nav article-lightbox-next"
              onClick={(e) => {
                e.stopPropagation();
                nextImage();
              }}
              aria-label="Next image"
            >
              <i className="bi bi-chevron-right"></i>
            </button>
          )}

          <div className="article-lightbox-count">
            {currentImage + 1} / {images.length}
          </div>
        </div>
      )}

      <Footer />

      <style>{`
        /* =========================================================
           PAGE
        ========================================================= */

        .article-page {
          position: relative;
          overflow: hidden;
          padding: 112px 0 70px;
          background:
            radial-gradient(
              circle at 8% 5%,
              rgba(25, 135, 84, 0.085),
              transparent 28%
            ),
            radial-gradient(
              circle at 92% 22%,
              rgba(13, 110, 253, 0.045),
              transparent 25%
            ),
            #ffffff;
        }

        .article-background-orb {
          position: absolute;
          border-radius: 50%;
          pointer-events: none;
          filter: blur(2px);
          opacity: 0.55;
          animation:
            articleOrbFloat
            12s
            ease-in-out
            infinite;
        }

        .article-orb-one {
          width: 210px;
          height: 210px;
          left: -100px;
          top: 260px;
          background:
            rgba(25, 135, 84, 0.065);
        }

        .article-orb-two {
          width: 160px;
          height: 160px;
          right: -70px;
          top: 650px;
          background:
            rgba(13, 110, 253, 0.045);
          animation-delay: -4s;
        }

        .article-orb-three {
          width: 110px;
          height: 110px;
          left: 48%;
          top: 1000px;
          background:
            rgba(25, 135, 84, 0.035);
          animation-delay: -7s;
        }

        @keyframes articleOrbFloat {
          0%,
          100% {
            transform:
              translate3d(0, 0, 0);
          }

          50% {
            transform:
              translate3d(24px, -28px, 0);
          }
        }

        /* =========================================================
           MAIN ARTICLE CARD
        ========================================================= */

        .article-shell {
          position: relative;
          max-width: 1120px;
          margin: 0 auto;
          padding: 58px 55px 62px;
          background: #ffffff;

          /* SMOOTH GREEN BORDER */
          border: 1px solid rgba(25, 135, 84, 0.42);

          border-radius: 28px;

          box-shadow:
            0 24px 70px rgba(0, 0, 0, 0.075),
            0 0 0 1px rgba(25, 135, 84, 0.035);

          overflow: hidden;

          animation:
            articleShellReveal
            0.8s
            cubic-bezier(0.22, 1, 0.36, 1)
            both,
            articleShellShadow
            6s
            ease-in-out
            1s
            infinite;
        }

        @keyframes articleShellReveal {
          from {
            opacity: 0;
            transform:
              translateY(28px);
          }

          to {
            opacity: 1;
            transform:
              translateY(0);
          }
        }

        @keyframes articleShellShadow {
          0%,
          100% {
            box-shadow:
              0 24px 70px
              rgba(0, 0, 0, 0.075),
              0 0 0 1px
              rgba(25, 135, 84, 0.035);
          }

          50% {
            box-shadow:
              0 28px 78px
              rgba(25, 135, 84, 0.10),
              0 0 0 1px
              rgba(25, 135, 84, 0.07);
          }
        }

        /* RUNNING GREEN LINE */

        .article-shell-line {
          position: absolute;
          top: 0;
          left: -45%;
          width: 45%;
          height: 2px;
          background:
            linear-gradient(
              90deg,
              transparent,
              #198754,
              #42b883,
              #198754,
              transparent
            );
          animation:
            articleTopLine
            3.8s
            linear
            infinite;
          z-index: 5;
        }

        @keyframes articleTopLine {
          0% {
            left: -45%;
          }

          100% {
            left: 100%;
          }
        }

        /* =========================================================
           HEADER
        ========================================================= */

        .article-header {
          text-align: center;
          max-width: 950px;
          margin: 0 auto 48px;
          animation:
            articleHeaderReveal
            0.8s
            0.15s
            cubic-bezier(0.22, 1, 0.36, 1)
            both;
        }

        @keyframes articleHeaderReveal {
          from {
            opacity: 0;
            transform:
              translateY(20px);
          }

          to {
            opacity: 1;
            transform:
              translateY(0);
          }
        }

        .article-eyebrow {
          display: inline-flex;
          align-items: center;
          justify-content: center;
          gap: 9px;
          margin-bottom: 14px;
          color: #198754;
          font-size: 0.74rem;
          font-weight: 800;
          letter-spacing: 0.17em;
          text-align: center;
        }

        .article-eyebrow-dot {
          width: 7px;
          height: 7px;
          flex: 0 0 7px;
          border-radius: 50%;
          background: #198754;
          box-shadow:
            0 0 0 0
            rgba(25, 135, 84, 0.4);
          animation:
            articleDotPulse
            2s
            infinite;
        }

        @keyframes articleDotPulse {
          0% {
            box-shadow:
              0 0 0 0
              rgba(25, 135, 84, 0.4);
          }

          70% {
            box-shadow:
              0 0 0 8px
              rgba(25, 135, 84, 0);
          }

          100% {
            box-shadow:
              0 0 0 0
              rgba(25, 135, 84, 0);
          }
        }

        .article-meta {
          display: flex;
          justify-content: center;
          align-items: center;
          flex-wrap: wrap;
          gap: 10px;
          margin-bottom: 22px;
        }

        .article-category,
        .article-date {
          display: inline-flex;
          align-items: center;
          justify-content: center;
          gap: 7px;
          min-height: 34px;
          padding: 7px 13px;
          border-radius: 999px;
          font-size: 0.78rem;
          font-weight: 600;
        }

        .article-author {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 34px;
  padding: 7px 13px;
  border-radius: 999px;
  color: #198754;
  background: rgba(25, 135, 84, 0.06);
  border: 1px solid rgba(25, 135, 84, 0.25);
  font-size: 0.78rem;
  font-weight: 600;
}

.article-author i {
  font-size: 0.82rem;
}

        .article-category {
          color: #198754;
          background:
            rgba(25, 135, 84, 0.09);
          border:
            1px solid
            rgba(25, 135, 84, 0.3);
        }

        .article-date {
          color: #6c757d;
          background: #f8f9fa;
          border:
            1px solid
            rgba(0, 0, 0, 0.08);
        }

        .article-title {
          max-width: 920px;
          margin: 0 auto 22px;
          color: #171b1f;
          font-size:
            clamp(2.15rem, 5vw, 3.8rem);
          font-weight: 800;
          line-height: 1.1;
          letter-spacing: -0.035em;
          text-align: center;
        }

        .article-excerpt {
          max-width: 850px;
          margin: 0 auto;
          color: #6c757d;
          font-size:
            clamp(1rem, 1.7vw, 1.14rem);
          line-height: 1.9;
          text-align: justify;
        }

        /* =========================================================
           IMAGE
        ========================================================= */

        .article-media-section {
          position: relative;
          max-width: 1000px;
          margin: 0 auto 55px;
          cursor: zoom-in;
          animation:
            articleMediaReveal
            0.9s
            0.25s
            cubic-bezier(0.22, 1, 0.36, 1)
            both;
        }

        @keyframes articleMediaReveal {
          from {
            opacity: 0;
            transform:
              translateY(25px)
              scale(0.985);
          }

          to {
            opacity: 1;
            transform:
              translateY(0)
              scale(1);
          }
        }

        .article-media-frame {
          position: relative;
          isolation: isolate;
          overflow: hidden;
          min-height: 300px;
          display: flex;
          align-items: center;
          justify-content: center;
          background:
            linear-gradient(
              145deg,
              #f8faf9,
              #f5f7f6
            );

          /* SMOOTH GREEN BORDER */
          border:
            1px solid
            rgba(25, 135, 84, 0.36);

          border-radius: 22px;

          box-shadow:
            0 18px 45px
            rgba(0, 0, 0, 0.075);

          animation:
            articleMediaPulse
            5s
            ease-in-out
            infinite;
        }

        @keyframes articleMediaPulse {
          0%,
          100% {
            box-shadow:
              0 18px 45px
              rgba(0, 0, 0, 0.075);
          }

          50% {
            box-shadow:
              0 22px 52px
              rgba(25, 135, 84, 0.12);
          }
        }

        .article-media-glow {
          position: absolute;
          top: -80px;
          left: -30%;
          width: 35%;
          height: 150%;
          background:
            linear-gradient(
              90deg,
              transparent,
              rgba(255, 255, 255, 0.42),
              transparent
            );
          transform:
            skewX(-18deg);
          animation:
            articleMediaSweep
            6s
            ease-in-out
            infinite;
          pointer-events: none;
          z-index: 1;
        }

        @keyframes articleMediaSweep {
          0%,
          60% {
            left: -40%;
          }

          80%,
          100% {
            left: 120%;
          }
        }

        .article-main-image {
          position: relative;
          z-index: 0;
          display: block;
          width: 100%;
          height: auto;
          max-height: 650px;
          object-fit: contain;
          background: #f8f9fa;
        }

        .article-image-overlay {
          position: absolute;
          z-index: 3;
          left: 50%;
          bottom: 22px;
          transform:
            translateX(-50%)
            translateY(10px);
          opacity: 0;
          pointer-events: none;
          transition:
            opacity 0.3s ease,
            transform 0.3s ease;
        }

        .article-image-overlay span {
          display: inline-flex;
          align-items: center;
          gap: 8px;
          padding: 9px 16px;
          border-radius: 999px;
          background:
            rgba(0, 0, 0, 0.68);
          color: #ffffff;
          font-size: 0.78rem;
          font-weight: 600;
          white-space: nowrap;
          backdrop-filter: blur(6px);
        }

        .article-media-section:hover
          .article-image-overlay {
          opacity: 1;
          transform:
            translateX(-50%)
            translateY(0);
        }

        .article-image-nav {
          position: absolute;
          z-index: 4;
          top: 50%;
          transform: translateY(-50%);
          width: 46px;
          height: 46px;
          padding: 0;
          border: 1px solid
            rgba(255, 255, 255, 0.65);
          border-radius: 50%;
          display: flex;
          align-items: center;
          justify-content: center;
          background:
            rgba(255, 255, 255, 0.93);
          color: #198754;
          font-size: 1rem;
          box-shadow:
            0 8px 25px
            rgba(0, 0, 0, 0.14);
          transition:
            background 0.25s ease,
            color 0.25s ease,
            transform 0.25s ease;
        }

        .article-image-nav:hover {
          background: #198754;
          color: #ffffff;
          transform:
            translateY(-50%)
            scale(1.08);
        }

        .article-image-prev {
          left: 18px;
        }

        .article-image-next {
          right: 18px;
        }

        .article-image-count {
          position: absolute;
          z-index: 4;
          right: 18px;
          bottom: 18px;
          display: inline-flex;
          align-items: center;
          padding: 7px 12px;
          border-radius: 999px;
          background:
            rgba(0, 0, 0, 0.65);
          color: #ffffff;
          font-size: 0.75rem;
          font-weight: 600;
          backdrop-filter: blur(6px);
        }

        .article-dots {
          display: flex;
          justify-content: center;
          align-items: center;
          gap: 8px;
          margin-top: 17px;
        }

        .article-dot {
          width: 8px;
          height: 8px;
          padding: 0;
          border: none;
          border-radius: 50%;
          background: #d0d5d9;
          transition:
            transform 0.25s ease,
            background 0.25s ease;
        }

        .article-dot:hover {
          transform: scale(1.25);
          background: #82bca0;
        }

        .article-dot.active {
          background: #198754;
          transform: scale(1.25);
          animation:
            activeDotPulse
            2s
            ease-in-out
            infinite;
        }

        @keyframes activeDotPulse {
          0%,
          100% {
            box-shadow:
              0 0 0 0
              rgba(25, 135, 84, 0.28);
          }

          50% {
            box-shadow:
              0 0 0 5px
              rgba(25, 135, 84, 0);
          }
        }

        /* =========================================================
           CONTENT CARD
        ========================================================= */

        .article-content-section {
          max-width: 900px;
          margin: 0 auto;
          animation:
            articleContentReveal
            0.9s
            0.35s
            cubic-bezier(0.22, 1, 0.36, 1)
            both;
        }

        @keyframes articleContentReveal {
          from {
            opacity: 0;
            transform:
              translateY(25px);
          }

          to {
            opacity: 1;
            transform:
              translateY(0);
          }
        }

        .article-content-card {
          position: relative;
          overflow: hidden;
          padding: 42px 48px 48px;

          /* SMOOTH GREEN BORDER */
          border:
            1px solid
            rgba(25, 135, 84, 0.40);

          border-radius: 22px;

          background:
            linear-gradient(
              145deg,
              #ffffff,
              #fcfdfd
            );

          box-shadow:
            0 16px 42px
            rgba(0, 0, 0, 0.055),
            0 0 0 1px
            rgba(25, 135, 84, 0.035);
        }

        .article-content-line {
          position: absolute;
          top: 0;
          left: -45%;
          width: 45%;
          height: 2px;
          background:
            linear-gradient(
              90deg,
              transparent,
              #198754,
              #42b883,
              #198754,
              transparent
            );
          animation:
            articleContentLineMove
            3.2s
            linear
            infinite;
        }

        @keyframes articleContentLineMove {
          0% {
            left: -45%;
          }

          100% {
            left: 100%;
          }
        }

        .article-content-heading {
          display: flex;
          flex-direction: column;
          align-items: center;
          justify-content: center;
          text-align: center;
          margin-bottom: 35px;
        }

        .article-content-icon {
          width: 56px;
          height: 56px;
          margin-bottom: 15px;
          display: flex;
          align-items: center;
          justify-content: center;
          border-radius: 16px;
          color: #198754;
          background:
            rgba(25, 135, 84, 0.09);
          font-size: 1.35rem;
          animation:
            contentIconFloat
            4s
            ease-in-out
            infinite;
        }

        @keyframes contentIconFloat {
          0%,
          100% {
            transform:
              translateY(0);
          }

          50% {
            transform:
              translateY(-5px);
          }
        }

        .article-content-label {
          display: block;
          margin-bottom: 5px;
          color: #198754;
          font-size: 0.7rem;
          font-weight: 800;
          letter-spacing: 0.16em;
          text-align: center;
        }

        .article-content-heading h2 {
          margin: 0;
          color: #212529;
          font-size:
            clamp(1.45rem, 3vw, 1.9rem);
          font-weight: 800;
          text-align: center;
        }

        /* =========================================================
           ARTICLE BODY
        ========================================================= */

        .article-content {
          width: 100%;
          max-width: 100%;
          color: #343a40;
          font-size: 1.05rem;
          line-height: 1.95;
          overflow-wrap: anywhere;
          word-break: normal;
          text-align: justify;
        }

        .article-content p,
        .article-content div,
        .article-content span {
          max-width: 100%;
          text-align: justify;
          overflow-wrap: anywhere;
        }

        .article-content p {
          margin-top: 0;
          margin-bottom: 1.35rem;
        }

        .article-content > p:last-child {
          margin-bottom: 0;
        }

        .article-content h1,
        .article-content h2,
        .article-content h3,
        .article-content h4,
        .article-content h5,
        .article-content h6 {
          margin-top: 2.3rem;
          margin-bottom: 1rem;
          color: #212529;
          font-weight: 750;
          line-height: 1.35;
          text-align: center;
        }

        .article-content h1 {
          font-size: 2rem;
        }

        .article-content h2 {
          font-size: 1.7rem;
        }

        .article-content h3 {
          font-size: 1.45rem;
        }

        .article-content h4 {
          font-size: 1.25rem;
        }

        .article-content ul,
        .article-content ol {
          width: 100%;
          margin-top: 0;
          margin-bottom: 1.4rem;
          padding-left: 1.6rem;
        }

        .article-content li {
          margin-bottom: 0.55rem;
          text-align: justify;
          overflow-wrap: anywhere;
        }

        .article-content img {
          display: block;
          width: auto;
          max-width: 100%;
          height: auto;
          margin: 2.2rem auto;
          border-radius: 16px;
        }

        .article-content blockquote {
          margin: 2rem 0;
          padding: 1.1rem 1.3rem;
          border-left:
            4px solid #198754;
          border-radius:
            0 13px 13px 0;
          background:
            rgba(25, 135, 84, 0.045);
          color: #495057;
          text-align: justify;
        }

        .article-content blockquote p {
          text-align: justify;
        }

        .article-content a {
          color: #198754;
          font-weight: 650;
          text-decoration-thickness: 1px;
          text-underline-offset: 3px;
          overflow-wrap: anywhere;
        }

        .article-content a:hover {
          color: #146c43;
        }

        .article-content pre {
          width: 100%;
          max-width: 100%;
          overflow-x: auto;
          margin: 1.5rem 0;
          padding: 1rem;
          border-radius: 12px;
          background: #212529;
          color: #ffffff;
          text-align: left;
          white-space: pre;
        }

        .article-content code {
          overflow-wrap: anywhere;
          text-align: left;
        }

        .article-content hr {
          margin: 2.5rem 0;
          border: 0;
          border-top:
            1px solid
            rgba(0, 0, 0, 0.08);
        }

        /* =========================================================
           ENDING
        ========================================================= */

        .article-ending {
          max-width: 720px;
          margin: 58px auto 0;
          text-align: center;
          animation:
            articleEndingReveal
            0.9s
            0.45s
            cubic-bezier(0.22, 1, 0.36, 1)
            both;
        }

        @keyframes articleEndingReveal {
          from {
            opacity: 0;
            transform:
              translateY(20px);
          }

          to {
            opacity: 1;
            transform:
              translateY(0);
          }
        }

        .article-ending-icon {
          width: 58px;
          height: 58px;
          margin: 0 auto 15px;
          display: flex;
          align-items: center;
          justify-content: center;
          border-radius: 17px;
          background:
            rgba(25, 135, 84, 0.09);
          color: #198754;
          font-size: 1.35rem;
          animation:
            contentIconFloat
            4s
            ease-in-out
            infinite;
        }

        .article-ending-eyebrow {
          margin-bottom: 6px;
          color: #198754;
          font-size: 0.7rem;
          font-weight: 800;
          letter-spacing: 0.16em;
        }

        .article-ending h2 {
          margin-bottom: 13px;
          color: #212529;
          font-size:
            clamp(1.5rem, 3vw, 2rem);
          font-weight: 800;
          text-align: center;
        }

        .article-ending p {
          max-width: 620px;
          margin: 0 auto;
          color: #6c757d;
          line-height: 1.85;
          text-align: justify;
        }

        /* =========================================================
           LIGHTBOX
        ========================================================= */

        .article-lightbox {
          position: fixed;
          inset: 0;
          z-index: 99999;
          display: flex;
          align-items: center;
          justify-content: center;
          padding: 70px;
          background:
            rgba(8, 12, 10, 0.92);
          backdrop-filter: blur(10px);
          animation:
            lightboxFade
            0.25s
            ease;
        }

        @keyframes lightboxFade {
          from {
            opacity: 0;
          }

          to {
            opacity: 1;
          }
        }

        .article-lightbox-image {
          max-width: 92vw;
          max-height: 85vh;
          width: auto;
          height: auto;
          object-fit: contain;
          border-radius: 12px;
          box-shadow:
            0 25px 80px
            rgba(0, 0, 0, 0.35);
          animation:
            lightboxImage
            0.35s
            cubic-bezier(0.22, 1, 0.36, 1);
        }

        @keyframes lightboxImage {
          from {
            opacity: 0;
            transform:
              scale(0.94);
          }

          to {
            opacity: 1;
            transform:
              scale(1);
          }
        }

        .article-lightbox-close {
          position: absolute;
          top: 20px;
          right: 25px;
          width: 45px;
          height: 45px;
          padding: 0;
          border: 1px solid
            rgba(255, 255, 255, 0.14);
          border-radius: 50%;
          display: flex;
          align-items: center;
          justify-content: center;
          background:
            rgba(255, 255, 255, 0.1);
          color: #ffffff;
          font-size: 1rem;
          transition:
            background 0.25s ease,
            transform 0.25s ease;
        }

        .article-lightbox-close:hover {
          background:
            rgba(25, 135, 84, 0.85);
          transform:
            rotate(90deg);
        }

        .article-lightbox-nav {
          position: absolute;
          top: 50%;
          transform:
            translateY(-50%);
          width: 50px;
          height: 50px;
          padding: 0;
          border: 1px solid
            rgba(255, 255, 255, 0.14);
          border-radius: 50%;
          display: flex;
          align-items: center;
          justify-content: center;
          background:
            rgba(255, 255, 255, 0.1);
          color: #ffffff;
          font-size: 1.1rem;
          transition:
            background 0.25s ease,
            transform 0.25s ease;
        }

        .article-lightbox-nav:hover {
          background: #198754;
        }

        .article-lightbox-prev {
          left: 20px;
        }

        .article-lightbox-next {
          right: 20px;
        }

        .article-lightbox-count {
          position: absolute;
          bottom: 20px;
          left: 50%;
          transform:
            translateX(-50%);
          padding: 7px 14px;
          border-radius: 999px;
          background:
            rgba(0, 0, 0, 0.55);
          color: #ffffff;
          font-size: 0.78rem;
          font-weight: 600;
        }

        /* =========================================================
           RESPONSIVE
        ========================================================= */

        @media (max-width: 992px) {
          .article-shell {
            padding: 48px 35px 52px;
            border-width: 1px;
          }

          .article-title {
            font-size:
              clamp(2rem, 5vw, 3.1rem);
          }

          .article-media-section {
            margin-bottom: 45px;
          }

          .article-content-card {
            padding: 38px 35px 42px;
            border-width: 1px;
          }
        }

        @media (max-width: 768px) {
          .article-page {
            padding: 95px 0 55px;
          }

          .article-shell {
            padding: 40px 20px 45px;
            border-radius: 22px;
            border-width: 1px;
          }

          .article-header {
            margin-bottom: 35px;
          }

          .article-title {
            font-size:
              clamp(1.9rem, 8vw, 2.7rem);
            letter-spacing: -0.025em;
          }

          .article-excerpt {
            font-size: 1rem;
            line-height: 1.8;
          }

          .article-media-section {
            margin-bottom: 40px;
          }

          .article-media-frame {
            min-height: 230px;
            border-radius: 17px;
            border-width: 1px;
          }

          .article-main-image {
            max-height: 460px;
          }

          .article-image-nav {
            width: 39px;
            height: 39px;
            font-size: 0.9rem;
          }

          .article-image-prev {
            left: 10px;
          }

          .article-image-next {
            right: 10px;
          }

          .article-image-count {
            right: 10px;
            bottom: 10px;
            font-size: 0.7rem;
          }

          .article-image-overlay {
            display: none;
          }

          .article-content-card {
            padding: 32px 22px 36px;
            border-radius: 18px;
            border-width: 1px;
          }

          .article-content {
            font-size: 1rem;
            line-height: 1.85;
            text-align: justify;
          }

          .article-content p,
          .article-content div,
          .article-content span,
          .article-content li,
          .article-content blockquote,
          .article-content blockquote p {
            text-align: justify;
          }

          .article-content-heading {
            margin-bottom: 28px;
          }

          .article-ending {
            margin-top: 45px;
          }

          .article-lightbox {
            padding: 60px 15px;
          }

          .article-lightbox-image {
            max-width: 94vw;
            max-height: 78vh;
          }

          .article-lightbox-nav {
            width: 40px;
            height: 40px;
          }

          .article-lightbox-prev {
            left: 8px;
          }

          .article-lightbox-next {
            right: 8px;
          }
        }

        @media (max-width: 576px) {
          .article-page {
            padding-top: 88px;
          }

          .article-shell {
            padding: 34px 14px 38px;
            border-radius: 18px;
            border-width: 1px;
          }

          .article-meta {
            gap: 7px;
          }

          .article-category,
.article-date,
.article-author {
  font-size: 0.7rem;
  min-height: 31px;
  padding: 6px 10px;
}

          .article-title {
            font-size: 1.85rem;
          }

          .article-excerpt {
            font-size: 0.96rem;
          }

          .article-media-frame {
            min-height: 190px;
            border-radius: 15px;
            border-width: 1px;
          }

          .article-main-image {
            max-height: 330px;
          }

          .article-image-nav {
            width: 35px;
            height: 35px;
          }

          .article-content-card {
            padding: 28px 17px 30px;
            border-radius: 16px;
            border-width: 1px;
          }

          .article-content-label {
            font-size: 0.62rem;
          }

          .article-content-heading h2 {
            font-size: 1.35rem;
          }

          .article-content {
            font-size: 0.96rem;
            line-height: 1.8;
          }

          .article-content h1 {
            font-size: 1.65rem;
          }

          .article-content h2 {
            font-size: 1.45rem;
          }

          .article-content h3 {
            font-size: 1.25rem;
          }

          .article-ending p {
            font-size: 0.95rem;
            line-height: 1.8;
          }

          .article-lightbox-close {
            top: 12px;
            right: 12px;
            width: 40px;
            height: 40px;
          }

          .article-lightbox-count {
            bottom: 12px;
          }
        }

        /* =========================================================
           REDUCED MOTION
        ========================================================= */

        @media (prefers-reduced-motion: reduce) {
          .article-shell,
          .article-header,
          .article-media-section,
          .article-content-section,
          .article-ending {
            animation: none !important;
          }

          .article-background-orb,
          .article-shell-line,
          .article-content-line,
          .article-media-glow,
          .article-media-frame,
          .article-content-icon,
          .article-ending-icon,
          .article-eyebrow-dot,
          .article-dot.active {
            animation: none !important;
          }

          .article-image-nav,
          .article-dot,
          .article-lightbox-close {
            transition: none !important;
          }
        }
      `}</style>
    </>
  );
}