import Link from "next/link";
import Image from "next/image";

export default function AnalyticsPage() {
  return (
    <div className="bg-[#131313] text-[#e5e2e1] font-body min-h-screen selection:bg-[#c3f400] selection:text-on-primary-fixed pb-24 md:pb-0">
      {/* TopAppBar */}
      <header className="bg-[#131313] fixed top-0 z-50 w-full transition-colors duration-200 border-b border-[#1C1B1B]">
        <div className="flex justify-between items-center w-full px-6 py-4 max-w-7xl mx-auto">
          <div className="text-2xl font-bold tracking-tight text-white uppercase italic font-headline">VIVAFIT 50+</div>
          
          <nav className="hidden md:flex items-center gap-8 font-lexend font-semibold text-lg">
            <Link href="/dashboard" className="text-white opacity-80 hover:text-[#C3F400] transition-colors font-headline">Home</Link>
            <Link href="/workout/builder" className="text-white opacity-80 hover:text-[#C3F400] transition-colors font-headline">Treinos</Link>
            <Link href="/library" className="text-white opacity-80 hover:text-[#C3F400] transition-colors font-headline">Biblioteca</Link>
            <Link href="/analytics" className="text-[#C3F400] font-bold transition-colors font-headline">Insights</Link>
          </nav>
          
          <div className="flex items-center gap-4">
            <button className="material-symbols-outlined text-white opacity-80 hover:opacity-100 p-2">notifications</button>
            <Link href="/profile" className="w-10 h-10 rounded-full bg-surface-container-high overflow-hidden border-2 border-[#c3f400] cursor-pointer">
              <img alt="User Profile" src="https://lh3.googleusercontent.com/aida-public/AB6AXuCcIwZnve6YK63nrflES4h2NjUJukouVYw2HDPdlKkKm3dA0vAA4cUS14lg50qMUnwYXG-l9HPTf7THs1P5TMldITvmi0NcgdBXXoPC3gPUt1y7NlWp-rGwGWXYkg1H6omdi4W_-E6a-4fZts9k2O9VTTW2PX2Zwv4PHcp8s118cWtQSTwfUUdEHlPhirUFl_0PFSuYP3UcrGk10OLj7xBdzgqaZ0LVCWUlsRvsFkB8SYWJpTI0H_N_D0nODvmULCRL0fAmlWreCVs" />
            </Link>
          </div>
        </div>
      </header>

      <main className="max-w-7xl mx-auto px-4 sm:px-6 pt-24 pb-12">
        {/* Page Header */}
        <div className="mb-12 text-center md:text-left">
          <h1 className="text-4xl sm:text-5xl md:text-6xl font-extrabold text-white tracking-tight mb-2 font-headline italic">Seus Insights</h1>
          <p className="text-white/70 text-lg sm:text-xl font-medium">Acompanhe seu progresso e vitalidade.</p>
        </div>

        {/* Overview Bento Grid */}
        <div className="grid grid-cols-1 md:grid-cols-3 gap-6 mb-12">
          {/* Atividades na Semana */}
          <div className="bg-surface-container-low p-6 sm:p-8 rounded-xl flex flex-col justify-between group transition-all border border-white/5 hover:border-white/10">
            <div className="flex justify-between items-start mb-4">
              <span className="text-white/70 font-semibold uppercase tracking-wider text-sm font-headline">Atividades na Semana</span>
              <span className="material-symbols-outlined text-[#c3f400]" style={{ fontVariationSettings: "'FILL' 1" }}>calendar_today</span>
            </div>
            <div className="flex items-baseline gap-2">
              <span className="text-5xl sm:text-6xl font-bold text-white font-headline">5</span>
              <span className="text-xl text-white/70 font-medium">sessões</span>
            </div>
            <div className="mt-6 h-2 bg-[#353534] rounded-full overflow-hidden">
              <div className="h-full bg-[#c3f400] w-[71%] rounded-full shadow-[0_0_15px_rgba(195,244,0,0.3)]"></div>
            </div>
            <p className="mt-4 text-[#c3f400] font-bold text-sm">+2 que na semana passada</p>
          </div>

          {/* Total de Minutos */}
          <div className="bg-surface-container-low p-6 sm:p-8 rounded-xl flex flex-col justify-between transition-all border border-white/5 hover:border-white/10">
            <div className="flex justify-between items-start mb-4">
              <span className="text-white/70 font-semibold uppercase tracking-wider text-sm font-headline">Total de Minutos</span>
              <span className="material-symbols-outlined text-[#c3f400]" style={{ fontVariationSettings: "'FILL' 1" }}>timer</span>
            </div>
            <div className="flex items-baseline gap-2">
              <span className="text-5xl sm:text-6xl font-bold text-white font-headline">340</span>
              <span className="text-xl text-white/70 font-medium">min</span>
            </div>
            <div className="mt-6 flex gap-1 items-end h-8">
              <div className="bg-[#353534] w-full h-1/2 rounded-t-sm"></div>
              <div className="bg-[#353534] w-full h-2/3 rounded-t-sm"></div>
              <div className="bg-[#c3f400] w-full h-full rounded-t-sm shadow-[0_0_10px_rgba(195,244,0,0.2)]"></div>
              <div className="bg-[#353534] w-full h-1/3 rounded-t-sm"></div>
              <div className="bg-[#c3f400] w-full h-[80%] rounded-t-sm shadow-[0_0_10px_rgba(195,244,0,0.2)]"></div>
            </div>
            <p className="mt-4 text-white/70 font-medium text-sm text-right">Meta diária: 45 min</p>
          </div>

          {/* Peso Atual */}
          <div className="bg-surface-container-low p-6 sm:p-8 rounded-xl flex flex-col justify-between transition-all border border-white/5 hover:border-white/10">
            <div className="flex justify-between items-start mb-4">
              <span className="text-white/70 font-semibold uppercase tracking-wider text-sm font-headline">Peso Atual</span>
              <span className="material-symbols-outlined text-[#ffb4ab]" style={{ fontVariationSettings: "'FILL' 1" }}>monitor_weight</span>
            </div>
            <div className="flex items-baseline gap-2">
              <span className="text-5xl sm:text-6xl font-bold text-white font-headline">74.5</span>
              <span className="text-xl text-white/70 font-medium">kg</span>
            </div>
            <div className="mt-6 flex items-center gap-2 text-[#c3f400]">
              <span className="material-symbols-outlined">trending_down</span>
              <span className="font-bold">-0.8 kg este mês</span>
            </div>
            <p className="mt-4 text-white/70 font-medium text-sm">Última pesagem: Hoje, 08:30</p>
          </div>
        </div>

        <div className="grid grid-cols-1 lg:grid-cols-3 gap-8 mb-12">
          {/* Activity Graph (Large) */}
          <div className="lg:col-span-2 bg-surface-container-low p-6 sm:p-8 rounded-xl border border-white/5">
            <div className="flex flex-col sm:flex-row justify-between items-start sm:items-center mb-8 sm:mb-10 gap-4">
              <h2 className="text-2xl font-bold text-white font-headline italic">Minutos de Atividade</h2>
              <div className="flex gap-4">
                <button className="text-xs font-bold uppercase tracking-widest text-[#c3f400] border-b-2 border-[#c3f400] pb-1 font-headline">7 Dias</button>
                <button className="text-xs font-bold uppercase tracking-widest text-white/50 hover:text-white transition-colors font-headline">30 Dias</button>
              </div>
            </div>

            {/* Chart Mockup */}
            <div className="relative h-64 w-full mt-4 flex items-end justify-between gap-1 sm:gap-2 px-1 sm:px-2">
              {/* Grid Lines */}
              <div className="absolute inset-0 flex flex-col justify-between pointer-events-none opacity-10">
                <div className="h-px w-full bg-white"></div>
                <div className="h-px w-full bg-white"></div>
                <div className="h-px w-full bg-white"></div>
                <div className="h-px w-full bg-white"></div>
              </div>

              {/* Bars */}
              <div className="flex flex-col items-center gap-2 w-full group">
                <div className="w-full bg-surface-container-high rounded-t-lg h-32 group-hover:bg-[#c3f400]/20 transition-colors"></div>
                <span className="text-[10px] sm:text-xs font-bold text-white/50 uppercase">Seg</span>
              </div>
              <div className="flex flex-col items-center gap-2 w-full group">
                <div className="w-full bg-surface-container-high rounded-t-lg h-48 group-hover:bg-[#c3f400]/20 transition-colors"></div>
                <span className="text-[10px] sm:text-xs font-bold text-white/50 uppercase">Ter</span>
              </div>
              <div className="flex flex-col items-center gap-2 w-full group">
                <div className="w-full bg-[#c3f400] rounded-t-lg h-56 shadow-[0_0_20px_rgba(195,244,0,0.15)] relative">
                  <div className="absolute -top-8 left-1/2 -translate-x-1/2 bg-[#353534] py-1 px-2 rounded text-xs font-bold text-white opacity-0 group-hover:opacity-100 transition-opacity">45m</div>
                </div>
                <span className="text-[10px] sm:text-xs font-bold text-white uppercase">Qua</span>
              </div>
              <div className="flex flex-col items-center gap-2 w-full group">
                <div className="w-full bg-surface-container-high rounded-t-lg h-24 group-hover:bg-[#c3f400]/20 transition-colors"></div>
                <span className="text-[10px] sm:text-xs font-bold text-white/50 uppercase">Qui</span>
              </div>
              <div className="flex flex-col items-center gap-2 w-full group">
                <div className="w-full bg-surface-container-high rounded-t-lg h-40 group-hover:bg-[#c3f400]/20 transition-colors"></div>
                <span className="text-[10px] sm:text-xs font-bold text-white/50 uppercase">Sex</span>
              </div>
              <div className="flex flex-col items-center gap-2 w-full group">
                <div className="w-full bg-[#c3f400] rounded-t-lg h-64 shadow-[0_0_20px_rgba(195,244,0,0.15)] relative">
                  <div className="absolute -top-8 left-1/2 -translate-x-1/2 bg-[#353534] py-1 px-2 rounded text-xs font-bold text-white opacity-0 group-hover:opacity-100 transition-opacity">60m</div>
                </div>
                <span className="text-[10px] sm:text-xs font-bold text-white uppercase">Sáb</span>
              </div>
              <div className="flex flex-col items-center gap-2 w-full group">
                <div className="w-full bg-surface-container-high rounded-t-lg h-16 group-hover:bg-[#c3f400]/20 transition-colors"></div>
                <span className="text-[10px] sm:text-xs font-bold text-white/50 uppercase">Dom</span>
              </div>
            </div>
          </div>

          {/* Health Highlights & Badges */}
          <div className="bg-surface-container-low p-6 sm:p-8 rounded-xl flex flex-col border border-white/5">
            <h2 className="text-2xl font-bold text-white mb-8 font-headline italic">Conquistas</h2>
            
            <div className="space-y-4 sm:space-y-6">
              <div className="flex items-center gap-4 sm:gap-5 p-4 bg-surface-container-high rounded-xl border-l-4 border-[#c3f400]">
                <div className="w-12 h-12 sm:w-14 sm:h-14 rounded-full bg-[#c3f400]/10 flex items-center justify-center shrink-0">
                  <span className="material-symbols-outlined text-[#c3f400] text-2xl sm:text-3xl" style={{ fontVariationSettings: "'FILL' 1" }}>local_fire_department</span>
                </div>
                <div>
                  <p className="text-white font-bold text-base sm:text-lg leading-tight font-headline">3 Dias Seguidos</p>
                  <p className="text-white/50 text-xs sm:text-sm mt-1">Mantendo o ritmo!</p>
                </div>
              </div>

              <div className="flex items-center gap-4 sm:gap-5 p-4 bg-surface-container-high rounded-xl border-l-4 border-[#ffb4ab]">
                <div className="w-12 h-12 sm:w-14 sm:h-14 rounded-full bg-[#ffb4ab]/10 flex items-center justify-center shrink-0">
                  <span className="material-symbols-outlined text-[#ffb4ab] text-2xl sm:text-3xl" style={{ fontVariationSettings: "'FILL' 1" }}>favorite</span>
                </div>
                <div>
                  <p className="text-white font-bold text-base sm:text-lg leading-tight font-headline">Meta de Cardio</p>
                  <p className="text-white/50 text-xs sm:text-sm mt-1">Coração em dia.</p>
                </div>
              </div>

              <div className="flex items-center gap-4 sm:gap-5 p-4 bg-surface-container-high rounded-xl border-l-4 border-[#b6c9d8]">
                <div className="w-12 h-12 sm:w-14 sm:h-14 rounded-full bg-white/10 flex items-center justify-center shrink-0">
                  <span className="material-symbols-outlined text-white text-2xl sm:text-3xl" style={{ fontVariationSettings: "'FILL' 1" }}>workspace_premium</span>
                </div>
                <div>
                  <p className="text-white font-bold text-base sm:text-lg leading-tight font-headline">Superação Mensal</p>
                  <p className="text-white/50 text-xs sm:text-sm mt-1">Mais 15% de atividade.</p>
                </div>
              </div>
            </div>

            <button className="mt-8 w-full py-4 text-[#c3f400] font-bold flex items-center justify-center gap-2 group hover:opacity-80 transition-opacity active:scale-95 duration-150">
              Ver todos os emblemas
              <span className="material-symbols-outlined group-hover:translate-x-1 transition-transform">arrow_forward</span>
            </button>
          </div>
        </div>

        {/* Weight Evolution */}
        <div className="bg-surface-container-low p-6 sm:p-8 rounded-xl mb-12 border border-white/5 overflow-hidden">
          <div className="flex flex-col md:flex-row justify-between items-start md:items-center mb-8 gap-4">
            <div>
              <h2 className="text-2xl font-bold text-white font-headline italic">Evolução do Peso</h2>
              <p className="text-white/50">Variação nos últimos 30 dias</p>
            </div>
            <div className="flex bg-surface-container-high p-1 rounded-lg w-full md:w-auto">
              <button className="flex-1 md:flex-none px-6 py-2 bg-[#353534] text-white font-bold rounded-md shadow-sm">Lista</button>
              <button className="flex-1 md:flex-none px-6 py-2 text-white/50 font-bold hover:text-white transition-colors">Gráfico</button>
            </div>
          </div>

          <div className="overflow-x-auto custom-scrollbar pb-4">
            <table className="w-full border-collapse min-w-[600px]">
              <thead>
                <tr className="text-left border-b border-[#353534]">
                  <th className="pb-4 font-bold text-white/50 uppercase text-xs tracking-widest font-headline">Data</th>
                  <th className="pb-4 font-bold text-white/50 uppercase text-xs tracking-widest font-headline">Peso</th>
                  <th className="pb-4 font-bold text-white/50 uppercase text-xs tracking-widest font-headline">Diferença</th>
                  <th className="pb-4 font-bold text-white/50 uppercase text-xs tracking-widest font-headline text-right">Status</th>
                </tr>
              </thead>
              <tbody className="divide-y divide-[#353534]/50">
                <tr className="group hover:bg-[#2a2a2a]/50 transition-colors">
                  <td className="py-5 font-medium text-white">Hoje, 12 Mai</td>
                  <td className="py-5 font-bold text-white">74.5 kg</td>
                  <td className="py-5 text-[#c3f400] font-bold">- 0.2 kg</td>
                  <td className="py-5 text-right"><span className="bg-[#c3f400]/10 text-[#c3f400] px-3 py-1 rounded-full text-xs font-bold uppercase font-headline">Consistente</span></td>
                </tr>
                <tr className="group hover:bg-[#2a2a2a]/50 transition-colors">
                  <td className="py-5 font-medium text-white">05 Mai</td>
                  <td className="py-5 font-bold text-white">74.7 kg</td>
                  <td className="py-5 text-[#c3f400] font-bold">- 0.3 kg</td>
                  <td className="py-5 text-right"><span className="bg-[#c3f400]/10 text-[#c3f400] px-3 py-1 rounded-full text-xs font-bold uppercase font-headline">Consistente</span></td>
                </tr>
                <tr className="group hover:bg-[#2a2a2a]/50 transition-colors">
                  <td className="py-5 font-medium text-white">28 Abr</td>
                  <td className="py-5 font-bold text-white">75.0 kg</td>
                  <td className="py-5 text-[#c3f400] font-bold">- 0.5 kg</td>
                  <td className="py-5 text-right"><span className="bg-[#c3f400]/20 text-[#c3f400] px-3 py-1 rounded-full text-xs font-bold uppercase font-headline border border-[#c3f400]/30">Meta Atingida</span></td>
                </tr>
                <tr className="group hover:bg-[#2a2a2a]/50 transition-colors">
                  <td className="py-5 font-medium text-white">21 Abr</td>
                  <td className="py-5 font-bold text-white">75.5 kg</td>
                  <td className="py-5 text-white/50 font-bold">--</td>
                  <td className="py-5 text-right"><span className="bg-[#353534] text-white/70 px-3 py-1 rounded-full text-xs font-bold uppercase font-headline">Inicial</span></td>
                </tr>
              </tbody>
            </table>
          </div>
        </div>

        {/* Call to Action */}
        <div className="relative overflow-hidden rounded-2xl bg-gradient-to-br from-[#1c1b1b] to-[#0e0e0e] p-8 sm:p-10 md:p-16 text-center border border-white/5">
          <div className="absolute top-0 right-0 -translate-y-1/2 translate-x-1/4 w-96 h-96 bg-[#c3f400]/5 blur-[100px] rounded-full pointer-events-none"></div>
          <h3 className="text-3xl sm:text-4xl md:text-5xl font-bold text-white mb-6 leading-tight font-headline italic">
            Mantenha o Ritmo, <br className="hidden md:block"/>Você está indo muito bem!
          </h3>
          <p className="text-white/70 text-lg sm:text-xl mb-10 max-w-2xl mx-auto">
            Sua consistência está gerando resultados visíveis na sua saúde cardiovascular e disposição diária.
          </p>
          <button className="bg-[#c3f400] text-on-primary-fixed font-black px-6 sm:px-10 py-4 sm:py-5 rounded-xl text-base sm:text-lg hover:shadow-[0_0_30px_rgba(195,244,0,0.3)] transition-all active:scale-95 uppercase tracking-tighter w-full sm:w-auto font-headline">
            Registrar Atividade de Hoje
          </button>
        </div>
      </main>

      {/* BottomNavBar (Mobile only) */}
      <nav className="md:hidden fixed bottom-0 left-0 w-full bg-surface-container-low flex justify-around items-center px-4 pb-6 pt-3 z-50 rounded-t-xl shadow-[0_-4px_20px_0px_rgba(195,244,0,0.05)] border-t border-white/5">
        <Link href="/dashboard" className="flex flex-col items-center justify-center text-white/50 px-4 py-2 hover:text-white transition-all active:scale-90 duration-150">
          <span className="material-symbols-outlined mb-1">home</span>
          <span className="text-[10px] font-semibold uppercase tracking-widest font-headline">Home</span>
        </Link>
        <Link href="/workout/builder" className="flex flex-col items-center justify-center text-white/50 px-4 py-2 hover:text-white transition-all active:scale-90 duration-150">
          <span className="material-symbols-outlined mb-1">fitness_center</span>
          <span className="text-[10px] font-semibold uppercase tracking-widest font-headline">Treinos</span>
        </Link>
        <Link href="/library" className="flex flex-col items-center justify-center text-white/50 px-4 py-2 hover:text-white transition-all active:scale-90 duration-150">
          <span className="material-symbols-outlined mb-1">menu_book</span>
          <span className="text-[10px] font-semibold uppercase tracking-widest font-headline">Biblioteca</span>
        </Link>
        <Link href="/analytics" className="flex flex-col items-center justify-center bg-[#c3f400] text-on-primary-fixed rounded-xl px-6 py-2 active:scale-90 transition-transform duration-150 shadow-[0_0_15px_rgba(195,244,0,0.1)]">
          <span className="material-symbols-outlined mb-1" style={{ fontVariationSettings: "'FILL' 1" }}>monitoring</span>
          <span className="text-[10px] font-bold uppercase tracking-widest font-headline">Insights</span>
        </Link>
      </nav>

      <style dangerouslySetInnerHTML={{__html: `
        .custom-scrollbar::-webkit-scrollbar { height: 6px; width: 6px; }
        .custom-scrollbar::-webkit-scrollbar-track { background: transparent; }
        .custom-scrollbar::-webkit-scrollbar-thumb { background: #353534; border-radius: 10px; }
      `}} />
    </div>
  );
}
